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(),