From 7564ae1defd46117488da23cdf38d1bb54bec817 Mon Sep 17 00:00:00 2001 From: Jiawei Shao Date: Thu, 25 Feb 2021 22:03:55 +0000 Subject: [PATCH] D3D12: Add test for the crash issue about T2T copy with Depth32Float Currently on D3D12 backend a device lost will occur when we do a T2T copy under the following situations: 1. with Depth32Float 2. only copy one row 3. bufferCopyOffset == 256 This is because in current implementation it is possible for us to do a copy with D3D12_SUBRESOURCE_FOOTPRINT.Depth > 1, which is not allowed with DXGI_FORMAT_D32_FLOAT because this format is not supported to be used as 3D textures. This patch adds a regression test for this bug and we will fix it later. BUG=dawn:693 TEST=dawn_end2end_tests Change-Id: Ib6fe70988b5b217d5f14d3f32999b3841e5d23b9 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/42600 Commit-Queue: Austin Eng Reviewed-by: Corentin Wallez Reviewed-by: Brandon Jones Reviewed-by: Austin Eng --- src/tests/end2end/CopyTests.cpp | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/tests/end2end/CopyTests.cpp b/src/tests/end2end/CopyTests.cpp index 37629b5e4d..052bff427e 100644 --- a/src/tests/end2end/CopyTests.cpp +++ b/src/tests/end2end/CopyTests.cpp @@ -1582,6 +1582,55 @@ TEST_P(CopyTests_T2T, MultipleMipSrcSingleMipDst) { } } +// A regression test for a bug on D3D12 backend that causes crash when doing texture-to-texture +// copy one row with the texture format Depth32Float. +TEST_P(CopyTests_T2B, CopyOneRowWithDepth32Float) { + // TODO(jiawei.shao@intel.com): enable this test when the bug on D3D12 is fixed. See dawn:693 + // for more details. + DAWN_SKIP_TEST_IF(IsD3D12()); + + constexpr wgpu::TextureFormat kFormat = wgpu::TextureFormat::Depth32Float; + constexpr uint32_t kPixelsPerRow = 4u; + + wgpu::TextureDescriptor textureDescriptor; + textureDescriptor.format = kFormat; + textureDescriptor.size = {kPixelsPerRow, 1, 1}; + textureDescriptor.usage = wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::OutputAttachment; + wgpu::Texture texture = device.CreateTexture(&textureDescriptor); + + wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); + + // Initialize the depth texture with 0.5f. + constexpr float kClearDepthValue = 0.5f; + utils::ComboRenderPassDescriptor renderPass({}, texture.CreateView()); + renderPass.cDepthStencilAttachmentInfo.clearDepth = kClearDepthValue; + renderPass.cDepthStencilAttachmentInfo.depthLoadOp = wgpu::LoadOp::Clear; + renderPass.cDepthStencilAttachmentInfo.depthStoreOp = wgpu::StoreOp::Store; + wgpu::RenderPassEncoder renderPassEncoder = encoder.BeginRenderPass(&renderPass); + renderPassEncoder.EndPass(); + + constexpr uint32_t kBufferCopyOffset = kTextureBytesPerRowAlignment; + const uint32_t kBufferSize = + kBufferCopyOffset + utils::GetTexelBlockSizeInBytes(kFormat) * kPixelsPerRow; + wgpu::BufferDescriptor bufferDescriptor; + bufferDescriptor.size = kBufferSize; + bufferDescriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst; + wgpu::Buffer buffer = device.CreateBuffer(&bufferDescriptor); + + wgpu::BufferCopyView bufferCopyView = + utils::CreateBufferCopyView(buffer, kBufferCopyOffset, kTextureBytesPerRowAlignment); + wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, {0, 0, 0}); + + wgpu::Extent3D copySize = textureDescriptor.size; + encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, ©Size); + wgpu::CommandBuffer commandBuffer = encoder.Finish(); + queue.Submit(1, &commandBuffer); + + std::array expectedValues; + std::fill(expectedValues.begin(), expectedValues.end(), kClearDepthValue); + EXPECT_BUFFER_FLOAT_RANGE_EQ(expectedValues.data(), buffer, kBufferCopyOffset, kPixelsPerRow); +} + DAWN_INSTANTIATE_TEST(CopyTests_T2T, D3D12Backend(), MetalBackend(),