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 <jiawei.shao@intel.com>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng 2021-07-14 00:42:31 +00:00 committed by Dawn LUCI CQ
parent a145f37e7b
commit ec380e9589
3 changed files with 16 additions and 1 deletions

View File

@ -243,7 +243,10 @@ namespace dawn_native { namespace vulkan {
barrier->dstQueueFamilyIndex = 0; barrier->dstQueueFamilyIndex = 0;
barrier->buffer = mHandle; barrier->buffer = mHandle;
barrier->offset = 0; 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; mLastUsage = usage;

View File

@ -52,6 +52,7 @@ namespace dawn_native { namespace vulkan {
private: private:
~Buffer() override; ~Buffer() override;
using BufferBase::BufferBase; using BufferBase::BufferBase;
MaybeError Initialize(bool mappedAtCreation); MaybeError Initialize(bool mappedAtCreation);
void InitializeToZero(CommandRecordingContext* recordingContext); void InitializeToZero(CommandRecordingContext* recordingContext);
void ClearBuffer(CommandRecordingContext* recordingContext, uint32_t clearValue); void ClearBuffer(CommandRecordingContext* recordingContext, uint32_t clearValue);

View File

@ -518,6 +518,17 @@ TEST_P(BufferMappingTests, MapWrite_InCallbackRange) {
EXPECT_BUFFER_U32_EQ(myData, buffer, 0); 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, DAWN_INSTANTIATE_TEST(BufferMappingTests,
D3D12Backend(), D3D12Backend(),
MetalBackend(), MetalBackend(),