Skip to content

Commit

Permalink
[metal] set the image stride to zero when updating a single layer of …
Browse files Browse the repository at this point in the history
…a 3D texture
  • Loading branch information
teoxoy committed Sep 19, 2023
1 parent ca7abcb commit 2c5966e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions wgpu-hal/src/metal/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,16 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
.max_copy_size(&src.copy_size)
.min(&copy.size);
let bytes_per_row = copy.buffer_layout.bytes_per_row.unwrap_or(0) as u64;
let bytes_per_image = copy
.buffer_layout
.rows_per_image
.map_or(0, |v| v as u64 * bytes_per_row);
let image_byte_stride = if extent.depth > 1 {
copy.buffer_layout
.rows_per_image
.map_or(0, |v| v as u64 * bytes_per_row)
} else {
// Don't pass a stride when updating a single layer, otherwise metal validation
// fails when updating a subset of the image due to the stride being larger than
// the amount of data to copy.
0
};
encoder.copy_from_texture_to_buffer(
&src.raw,
copy.texture_base.array_layer as u64,
Expand All @@ -373,7 +379,7 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
&dst.raw,
copy.buffer_layout.offset,
bytes_per_row,
bytes_per_image,
image_byte_stride,
conv::get_blit_option(src.format, copy.texture_base.aspect),
);
}
Expand Down

0 comments on commit 2c5966e

Please sign in to comment.