From 000843282731df19533acede347408fd2237d3eb Mon Sep 17 00:00:00 2001 From: Jiawei Shao Date: Wed, 17 Mar 2021 08:20:09 +0000 Subject: [PATCH] D3D12: Fix crash in the workaround for T2T copy issue on Intel GPUs This patch fixes a bug in the computation of temporary buffer size in the implementation of the workaround for the T2T copy issue on Intel GPUs. With this tests all the T2T operation tests in WebGPU CTS will be able to pass on Intel Gen9 and Gen9.5 GPUs. BUG=chromium:1161355 TEST=dawn_end2end_tests Change-Id: Ic4fb0c0056cf7b01720e47cc91c37a9f293cd194 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/44840 Reviewed-by: Corentin Wallez Commit-Queue: Jiawei Shao --- src/dawn_native/d3d12/CommandBufferD3D12.cpp | 10 +++++++--- src/tests/end2end/CopyTests.cpp | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.cpp b/src/dawn_native/d3d12/CommandBufferD3D12.cpp index 91b2f61793..0d8d83aaa5 100644 --- a/src/dawn_native/d3d12/CommandBufferD3D12.cpp +++ b/src/dawn_native/d3d12/CommandBufferD3D12.cpp @@ -230,11 +230,15 @@ namespace dawn_native { namespace d3d12 { uint32_t bytesPerRow = Align(blockInfo.byteSize * widthInBlocks, kTextureBytesPerRowAlignment); uint32_t rowsPerImage = heightInBlocks; - uint64_t tempBufferSize = bytesPerRow * (widthInBlocks * heightInBlocks - 1) + - Align(blockInfo.byteSize * widthInBlocks, 4); + + // The size of temporary buffer isn't needed to be a multiple of 4 because we don't + // need to set mappedAtCreation to be true. + auto tempBufferSize = + ComputeRequiredBytesInCopy(blockInfo, copySize, bytesPerRow, rowsPerImage); + BufferDescriptor tempBufferDescriptor; tempBufferDescriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst; - tempBufferDescriptor.size = tempBufferSize; + tempBufferDescriptor.size = tempBufferSize.AcquireSuccess(); Device* device = ToBackend(srcCopy.texture->GetDevice()); Ref tempBuffer = AcquireRef(ToBackend(device->CreateBuffer(&tempBufferDescriptor))); diff --git a/src/tests/end2end/CopyTests.cpp b/src/tests/end2end/CopyTests.cpp index 05e85a586f..f6d6a3dad3 100644 --- a/src/tests/end2end/CopyTests.cpp +++ b/src/tests/end2end/CopyTests.cpp @@ -1628,13 +1628,17 @@ TEST_P(CopyTests_T2T, CopyFromNonZeroMipLevelWithTexelBlockSizeLessThan4Bytes) { ASSERT_LE(kSrcSize, kTextureBytesPerRowAlignment); ASSERT_LE(kDstSize, kTextureBytesPerRowAlignment); + // The copyDepth to test: + // 1u (non-array texture), 3u (copyDepth < copyWidth), 5u (copyDepth > copyWidth) + constexpr std::array kTestTextureDepth = {1u, 3u, 5u}; + for (wgpu::TextureFormat format : kFormats) { if (HasToggleEnabled("disable_snorm_read") && (format == wgpu::TextureFormat::RG8Snorm || format == wgpu::TextureFormat::R8Snorm)) { continue; } - for (uint32_t textureDepth = 1; textureDepth < 3; ++textureDepth) { + for (uint32_t textureDepth : kTestTextureDepth) { const wgpu::Extent3D kUploadSize = {4u, 4u, textureDepth}; for (uint32_t srcLevel = 0; srcLevel < kSrcLevelCount; ++srcLevel) {