@@ -240,16 +240,11 @@ fn prepare_buffers(
240
240
match readback {
241
241
Readback :: Texture ( image) => {
242
242
if let Some ( gpu_image) = gpu_images. get ( image) {
243
- let layout = layout_data (
244
- gpu_image. size . width ,
245
- gpu_image. size . height ,
246
- gpu_image. texture_format ,
247
- ) ;
243
+ let layout = layout_data ( gpu_image. size , gpu_image. texture_format ) ;
248
244
let buffer = buffer_pool. get (
249
245
& render_device,
250
246
get_aligned_size (
251
- gpu_image. size . width ,
252
- gpu_image. size . height ,
247
+ gpu_image. size ,
253
248
gpu_image. texture_format . pixel_size ( ) as u32 ,
254
249
) as u64 ,
255
250
) ;
@@ -355,20 +350,32 @@ pub(crate) const fn align_byte_size(value: u32) -> u32 {
355
350
}
356
351
357
352
/// Get the size of a image when the size of each row has been rounded up to [`wgpu::COPY_BYTES_PER_ROW_ALIGNMENT`].
358
- pub ( crate ) const fn get_aligned_size ( width : u32 , height : u32 , pixel_size : u32 ) -> u32 {
359
- height * align_byte_size ( width * pixel_size)
353
+ pub ( crate ) const fn get_aligned_size ( extent : Extent3d , pixel_size : u32 ) -> u32 {
354
+ extent . height * align_byte_size ( extent . width * pixel_size) * extent . depth_or_array_layers
360
355
}
361
356
362
357
/// Get a [`ImageDataLayout`] aligned such that the image can be copied into a buffer.
363
- pub ( crate ) fn layout_data ( width : u32 , height : u32 , format : TextureFormat ) -> ImageDataLayout {
358
+ pub ( crate ) fn layout_data ( extent : Extent3d , format : TextureFormat ) -> ImageDataLayout {
364
359
ImageDataLayout {
365
- bytes_per_row : if height > 1 {
360
+ bytes_per_row : if extent . height > 1 || extent . depth_or_array_layers > 1 {
366
361
// 1 = 1 row
367
- Some ( get_aligned_size ( width, 1 , format. pixel_size ( ) as u32 ) )
362
+ Some ( get_aligned_size (
363
+ Extent3d {
364
+ width : extent. width ,
365
+ height : 1 ,
366
+ depth_or_array_layers : 1 ,
367
+ } ,
368
+ format. pixel_size ( ) as u32 ,
369
+ ) )
370
+ } else {
371
+ None
372
+ } ,
373
+ rows_per_image : if extent. depth_or_array_layers > 1 {
374
+ let ( _, block_dimension_y) = format. block_dimensions ( ) ;
375
+ Some ( extent. height / block_dimension_y)
368
376
} else {
369
377
None
370
378
} ,
371
- rows_per_image : None ,
372
- ..Default :: default ( )
379
+ offset : 0 ,
373
380
}
374
381
}
0 commit comments