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) {