From ec380e95896acec12b8782ebc9b357a154d7163b Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Wed, 14 Jul 2021 00:42:31 +0000 Subject: [PATCH] Fix Vulkan buffer barriers to use VK_WHOLE_SIZE Buffers are padded to be at least 4 bytes. Dawn would produce invalid barriers for buffers that were "zero" bytes large. The size for the barrier must be either non-zero or VK_WHOLE_SIZE. Since we always intend to transition the entire buffer, simply use VK_WHOLE_SIZE instead of GetSize() as the size. Fixed: dawn:969 Change-Id: Ifed4e8f9164bafa3c44917074fcf214e72919c56 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/57940 Reviewed-by: Jiawei Shao Commit-Queue: Austin Eng --- src/dawn_native/vulkan/BufferVk.cpp | 5 ++++- src/dawn_native/vulkan/BufferVk.h | 1 + src/tests/end2end/BufferTests.cpp | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/dawn_native/vulkan/BufferVk.cpp b/src/dawn_native/vulkan/BufferVk.cpp index 2763caf645..0a5d1aafb1 100644 --- a/src/dawn_native/vulkan/BufferVk.cpp +++ b/src/dawn_native/vulkan/BufferVk.cpp @@ -243,7 +243,10 @@ namespace dawn_native { namespace vulkan { barrier->dstQueueFamilyIndex = 0; barrier->buffer = mHandle; barrier->offset = 0; - barrier->size = GetSize(); + // Size must be non-zero or VK_WHOLE_SIZE. Use WHOLE_SIZE + // instead of GetSize() because the buffer allocation may + // be padded. + barrier->size = VK_WHOLE_SIZE; mLastUsage = usage; diff --git a/src/dawn_native/vulkan/BufferVk.h b/src/dawn_native/vulkan/BufferVk.h index 51c6993caa..e9a8951e30 100644 --- a/src/dawn_native/vulkan/BufferVk.h +++ b/src/dawn_native/vulkan/BufferVk.h @@ -52,6 +52,7 @@ namespace dawn_native { namespace vulkan { private: ~Buffer() override; using BufferBase::BufferBase; + MaybeError Initialize(bool mappedAtCreation); void InitializeToZero(CommandRecordingContext* recordingContext); void ClearBuffer(CommandRecordingContext* recordingContext, uint32_t clearValue); diff --git a/src/tests/end2end/BufferTests.cpp b/src/tests/end2end/BufferTests.cpp index 12ac22867e..74289c7e33 100644 --- a/src/tests/end2end/BufferTests.cpp +++ b/src/tests/end2end/BufferTests.cpp @@ -518,6 +518,17 @@ TEST_P(BufferMappingTests, MapWrite_InCallbackRange) { EXPECT_BUFFER_U32_EQ(myData, buffer, 0); } +// Regression test for crbug.com/dawn/969 where this test +// produced invalid barriers. +TEST_P(BufferMappingTests, MapWrite_ZeroSizedTwice) { + wgpu::Buffer buffer = CreateMapWriteBuffer(0); + + MapAsyncAndWait(buffer, wgpu::MapMode::Write, 0, 0); + buffer.Unmap(); + + MapAsyncAndWait(buffer, wgpu::MapMode::Write, 0, 0); +} + DAWN_INSTANTIATE_TEST(BufferMappingTests, D3D12Backend(), MetalBackend(),