From f49fbbfb88fe731273cdf29a5e065c2cc68ce234 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Tue, 26 Apr 2022 17:02:42 +0000 Subject: [PATCH] DawnTest: handle buffer readbacks not aligned to 4. Bug: None Change-Id: I69e8b9a9c0eae5d0287351cacbe21e550741cacc Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87861 Kokoro: Kokoro Reviewed-by: Loko Kung Reviewed-by: Austin Eng Commit-Queue: Corentin Wallez --- src/dawn/tests/DawnTest.cpp | 7 +++---- src/dawn/tests/DawnTest.h | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/dawn/tests/DawnTest.cpp b/src/dawn/tests/DawnTest.cpp index 1bbb61562e..cfc1b38f24 100644 --- a/src/dawn/tests/DawnTest.cpp +++ b/src/dawn/tests/DawnTest.cpp @@ -1085,12 +1085,13 @@ std::ostringstream& DawnTestBase::AddBufferExpectation(const char* file, uint64_t offset, uint64_t size, detail::Expectation* expectation) { - auto readback = ReserveReadback(size); + uint64_t alignedSize = Align(size, uint64_t(4)); + auto readback = ReserveReadback(alignedSize); // We need to enqueue the copy immediately because by the time we resolve the expectation, // the buffer might have been modified. wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); - encoder.CopyBufferToBuffer(buffer, offset, readback.buffer, readback.offset, size); + encoder.CopyBufferToBuffer(buffer, offset, readback.buffer, readback.offset, alignedSize); wgpu::CommandBuffer commands = encoder.Finish(); queue.Submit(1, &commands); @@ -1101,8 +1102,6 @@ std::ostringstream& DawnTestBase::AddBufferExpectation(const char* file, deferred.readbackSlot = readback.slot; deferred.readbackOffset = readback.offset; deferred.size = size; - deferred.rowBytes = size; - deferred.bytesPerRow = size; deferred.expectation.reset(expectation); mDeferredExpectations.push_back(std::move(deferred)); diff --git a/src/dawn/tests/DawnTest.h b/src/dawn/tests/DawnTest.h index c3c8402445..f171c68ef2 100644 --- a/src/dawn/tests/DawnTest.h +++ b/src/dawn/tests/DawnTest.h @@ -586,8 +586,8 @@ class DawnTestBase { size_t readbackSlot; uint64_t readbackOffset; uint64_t size; - uint32_t rowBytes; - uint32_t bytesPerRow; + uint32_t rowBytes = 0; + uint32_t bytesPerRow = 0; std::unique_ptr expectation; // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54316 // Use unique_ptr because of missing move/copy constructors on std::basic_ostringstream