Skip to content

Commit

Permalink
Fix row calculation in Queue::write_texture.
Browse files Browse the repository at this point in the history
Fix row calculation in `Queue::write_texture`.

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.
  • Loading branch information
dtzxporter committed Jan 4, 2024
1 parent 31d50af commit 5596e0f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ Passing an owned value `window` to `Surface` will return a `Surface<'static>`. S
- Align `wgpu_types::CompositeAlphaMode` serde serialization to spec. By @littledivy in [#4940](https://github.com/gfx-rs/wgpu/pull/4940)
- Fix error message of `ConfigureSurfaceError::TooLarge`. By @Dinnerbone in [#4960](https://github.com/gfx-rs/wgpu/pull/4960)

#### DX12

- Fixed D3D12_SUBRESOURCE_FOOTPRINT calculation for block compressed textures which caused a crash with `Queue::write_texture` on DX12. By @DTZxPorter in [#4990](https://github.com/gfx-rs/wgpu/pull/4990)

#### Vulkan

- Use `VK_EXT_robustness2` only when not using an outdated intel iGPU driver. By @TheoDulka in [#4602](https://github.com/gfx-rs/wgpu/pull/4602).
Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/src/device/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
// doesn't really matter because we need this only if we copy
// more than one layer, and then we validate for this being not
// None
size.height,
height_blocks,
);

let block_size = dst
Expand All @@ -754,7 +754,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
wgt::math::align_to(block_size * width_blocks, bytes_per_row_alignment);

let block_rows_in_copy =
(size.depth_or_array_layers - 1) * block_rows_per_image + height_blocks;
(size.depth_or_array_layers - 1) * block_rows_per_image + block_rows_per_image;
let stage_size = stage_bytes_per_row as u64 * block_rows_in_copy as u64;

let mut pending_writes = device.pending_writes.lock();
Expand Down
4 changes: 3 additions & 1 deletion wgpu-hal/src/dx12/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ impl crate::BufferTextureCopy {
Height: self
.buffer_layout
.rows_per_image
.map_or(self.size.height, |count| count * block_height),
.map_or(self.size.height, |height_blocks| {
height_blocks * block_height
}),
Depth: self.size.depth,
RowPitch: {
let actual = self.buffer_layout.bytes_per_row.unwrap_or_else(|| {
Expand Down

0 comments on commit 5596e0f

Please sign in to comment.