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 <noreply+kokoro@google.com>
Reviewed-by: Loko Kung <lokokung@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2022-04-26 17:02:42 +00:00 committed by Dawn LUCI CQ
parent 1c3f88eb0c
commit f49fbbfb88
2 changed files with 5 additions and 6 deletions

View File

@ -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));

View File

@ -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<detail::Expectation> expectation;
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54316
// Use unique_ptr because of missing move/copy constructors on std::basic_ostringstream