From a15b969423636571905f192c76e692d7d915c0d9 Mon Sep 17 00:00:00 2001 From: dtzxporter Date: Thu, 4 Jan 2024 17:23:49 -0500 Subject: [PATCH] The D3D12_SUBRESOURCE_FOOTPRINT was calculated incorrectly by multiplying the height by the block count. DirectX automatically takes format into account because it's passed into the footprint. Only the block width is necessary to compute the pitch or linear size. This prevents a crash when using `Queue::write_texture` with a block compressed texture. --- wgpu-hal/src/dx12/command.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/wgpu-hal/src/dx12/command.rs b/wgpu-hal/src/dx12/command.rs index c5d0d16b2c5..3d05813ed7b 100644 --- a/wgpu-hal/src/dx12/command.rs +++ b/wgpu-hal/src/dx12/command.rs @@ -20,7 +20,7 @@ impl crate::BufferTextureCopy { &self, format: wgt::TextureFormat, ) -> d3d12_ty::D3D12_PLACED_SUBRESOURCE_FOOTPRINT { - let (block_width, block_height) = format.block_dimensions(); + let (block_width, _) = format.block_dimensions(); d3d12_ty::D3D12_PLACED_SUBRESOURCE_FOOTPRINT { Offset: self.buffer_layout.offset, Footprint: d3d12_ty::D3D12_SUBRESOURCE_FOOTPRINT { @@ -30,10 +30,7 @@ impl crate::BufferTextureCopy { ) .unwrap(), Width: self.size.width, - Height: self - .buffer_layout - .rows_per_image - .map_or(self.size.height, |count| count * block_height), + Height: self.size.height, Depth: self.size.depth, RowPitch: { let actual = self.buffer_layout.bytes_per_row.unwrap_or_else(|| {