From 1ea3a22f521ef0e0c7ed4ba9f41ac56b5157a7f0 Mon Sep 17 00:00:00 2001 From: Tomek Ponitka Date: Mon, 3 Aug 2020 19:22:33 +0000 Subject: [PATCH] Adding a validation for destroyed textures in Queue::WriteTexture That was missing. There's a new validation test for that and two tests for submitting copy commands with destroyed buffer/texture (I think only a mapped buffer was covered so far). Also fixing some error state tests. Bug: dawn:483 Change-Id: I691f34722e96866a06465b4b3b0cae9d31c08a84 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/26161 Commit-Queue: Tomek Ponitka Reviewed-by: Austin Eng --- src/dawn_native/Queue.cpp | 6 +++++- .../CopyCommandsValidationTests.cpp | 10 ++++++---- .../QueueWriteTextureValidationTests.cpp | 19 ++++++++++++++----- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/dawn_native/Queue.cpp b/src/dawn_native/Queue.cpp index 9799842774..3afc18529f 100644 --- a/src/dawn_native/Queue.cpp +++ b/src/dawn_native/Queue.cpp @@ -251,7 +251,9 @@ namespace dawn_native { return DAWN_VALIDATION_ERROR("Buffer needs the CopyDst usage bit"); } - return buffer->ValidateCanUseOnQueueNow(); + DAWN_TRY(buffer->ValidateCanUseOnQueueNow()); + + return {}; } MaybeError QueueBase::ValidateWriteTexture(const TextureCopyView* destination, @@ -286,6 +288,8 @@ namespace dawn_native { *dataLayout, dataSize, destination->texture->GetFormat().GetTexelBlockInfo(destination->aspect), *writeSize)); + DAWN_TRY(destination->texture->ValidateCanUseInSubmitNow()); + return {}; } diff --git a/src/tests/unittests/validation/CopyCommandsValidationTests.cpp b/src/tests/unittests/validation/CopyCommandsValidationTests.cpp index f5443462c4..1edb39650b 100644 --- a/src/tests/unittests/validation/CopyCommandsValidationTests.cpp +++ b/src/tests/unittests/validation/CopyCommandsValidationTests.cpp @@ -282,11 +282,13 @@ TEST_F(CopyCommandTest_B2B, UnalignedOffset) { TEST_F(CopyCommandTest_B2B, BuffersInErrorState) { wgpu::BufferDescriptor errorBufferDescriptor; errorBufferDescriptor.size = 4; - errorBufferDescriptor.usage = wgpu::BufferUsage::MapRead | wgpu::BufferUsage::CopySrc; + errorBufferDescriptor.usage = + wgpu::BufferUsage::MapRead | wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst; ASSERT_DEVICE_ERROR(wgpu::Buffer errorBuffer = device.CreateBuffer(&errorBufferDescriptor)); constexpr uint64_t bufferSize = 4; - wgpu::Buffer validBuffer = CreateBuffer(bufferSize, wgpu::BufferUsage::CopySrc); + wgpu::Buffer validBuffer = + CreateBuffer(bufferSize, wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst); { wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); @@ -588,7 +590,7 @@ TEST_F(CopyCommandTest_B2T, BufferOrTextureInErrorState) { wgpu::TextureCopyView errorTextureCopyView = utils::CreateTextureCopyView(errorTexture, 0, {0, 0, 0}); - wgpu::Extent3D extent3D = {1, 1, 1}; + wgpu::Extent3D extent3D = {0, 0, 0}; { wgpu::Texture destination = Create2DTexture(16, 16, 1, 1, wgpu::TextureFormat::RGBA8Unorm, @@ -990,7 +992,7 @@ TEST_F(CopyCommandTest_T2B, BufferOrTextureInErrorState) { wgpu::TextureCopyView errorTextureCopyView = utils::CreateTextureCopyView(errorTexture, 0, {0, 0, 0}); - wgpu::Extent3D extent3D = {1, 1, 1}; + wgpu::Extent3D extent3D = {0, 0, 0}; { uint64_t bufferSize = BufferSizeForTextureCopy(4, 4, 1); diff --git a/src/tests/unittests/validation/QueueWriteTextureValidationTests.cpp b/src/tests/unittests/validation/QueueWriteTextureValidationTests.cpp index c689f58e05..a9dca68d30 100644 --- a/src/tests/unittests/validation/QueueWriteTextureValidationTests.cpp +++ b/src/tests/unittests/validation/QueueWriteTextureValidationTests.cpp @@ -280,6 +280,18 @@ namespace { TestWriteTexture(dataSize, 0, 256, 0, destination, 0, {0, 0, 0}, {2, 2, 1})); } + // Test that WriteTexture cannot be run with a destroyed texture. + TEST_F(QueueWriteTextureValidationTest, DestroyedTexture) { + const uint64_t dataSize = + utils::RequiredBytesInCopy(256, 4, {4, 4, 1}, wgpu::TextureFormat::RGBA8Unorm); + wgpu::Texture destination = Create2DTexture({16, 16, 4}, 5, wgpu::TextureFormat::RGBA8Unorm, + wgpu::TextureUsage::CopyDst); + destination.Destroy(); + + ASSERT_DEVICE_ERROR( + TestWriteTexture(dataSize, 0, 256, 4, destination, 0, {0, 0, 0}, {4, 4, 1})); + } + // Test WriteTexture with texture in error state causes errors. TEST_F(QueueWriteTextureValidationTest, TextureInErrorState) { wgpu::TextureDescriptor errorTextureDescriptor; @@ -289,14 +301,11 @@ namespace { wgpu::TextureCopyView errorTextureCopyView = utils::CreateTextureCopyView(errorTexture, 0, {0, 0, 0}); - wgpu::Extent3D extent3D = {1, 1, 1}; + wgpu::Extent3D extent3D = {0, 0, 0}; { std::vector data(4); - wgpu::TextureDataLayout textureDataLayout; - textureDataLayout.offset = 0; - textureDataLayout.bytesPerRow = 0; - textureDataLayout.rowsPerImage = 0; + wgpu::TextureDataLayout textureDataLayout = utils::CreateTextureDataLayout(0, 0, 0); ASSERT_DEVICE_ERROR(queue.WriteTexture(&errorTextureCopyView, data.data(), 4, &textureDataLayout, &extent3D));