From 00a5be7f7b4ad1c179cc5b31f36a763a4c82395a Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Thu, 30 Jul 2020 16:58:29 -0400 Subject: [PATCH] Fix multi-layer copies --- wgpu-core/src/command/transfer.rs | 27 ++++++++++++++++----------- wgpu-core/src/device/queue.rs | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index 14ee9ca52d4..b0c0e73da3e 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -66,6 +66,7 @@ pub enum TransferError { // once only to get the aspect flags, which is unfortunate. pub(crate) fn texture_copy_view_to_hal( view: &TextureCopyView, + size: &wgt::Extent3d, texture_guard: &Storage, TextureId>, ) -> ( hal::image::SubresourceLayers, @@ -75,11 +76,13 @@ pub(crate) fn texture_copy_view_to_hal( let texture = &texture_guard[view.texture]; let aspects = texture.full_range.aspects; let level = view.mip_level as hal::image::Level; - let (layer, z) = match texture.dimension { - wgt::TextureDimension::D1 | wgt::TextureDimension::D2 => { - (view.origin.z as hal::image::Layer, 0) - } - wgt::TextureDimension::D3 => (0, view.origin.z as i32), + let (layer, layer_count, z) = match texture.dimension { + wgt::TextureDimension::D1 | wgt::TextureDimension::D2 => ( + view.origin.z as hal::image::Layer, + size.depth as hal::image::Layer, + 0, + ), + wgt::TextureDimension::D3 => (0, 1, view.origin.z as i32), }; // TODO: Can't satisfy clippy here unless we modify @@ -89,12 +92,12 @@ pub(crate) fn texture_copy_view_to_hal( hal::image::SubresourceLayers { aspects, level: view.mip_level as hal::image::Level, - layers: layer..layer + 1, + layers: layer..layer + layer_count, }, hal::image::SubresourceRange { aspects, levels: level..level + 1, - layers: layer..layer + 1, + layers: layer..layer + layer_count, }, hal::image::Offset { x: view.origin.x as i32, @@ -329,7 +332,7 @@ impl Global { let (buffer_guard, mut token) = hub.buffers.read(&mut token); let (texture_guard, _) = hub.textures.read(&mut token); let (dst_layers, dst_range, dst_offset) = - texture_copy_view_to_hal(destination, &*texture_guard); + texture_copy_view_to_hal(destination, copy_size, &*texture_guard); #[cfg(feature = "trace")] match cmb.commands { @@ -432,7 +435,8 @@ impl Global { let cmb = &mut cmb_guard[command_encoder_id]; let (buffer_guard, mut token) = hub.buffers.read(&mut token); let (texture_guard, _) = hub.textures.read(&mut token); - let (src_layers, src_range, src_offset) = texture_copy_view_to_hal(source, &*texture_guard); + let (src_layers, src_range, src_offset) = + texture_copy_view_to_hal(source, copy_size, &*texture_guard); #[cfg(feature = "trace")] match cmb.commands { @@ -539,9 +543,10 @@ impl Global { // we can't hold both src_pending and dst_pending in scope because they // borrow the buffer tracker mutably... let mut barriers = Vec::new(); - let (src_layers, src_range, src_offset) = texture_copy_view_to_hal(source, &*texture_guard); + let (src_layers, src_range, src_offset) = + texture_copy_view_to_hal(source, copy_size, &*texture_guard); let (dst_layers, dst_range, dst_offset) = - texture_copy_view_to_hal(destination, &*texture_guard); + texture_copy_view_to_hal(destination, copy_size, &*texture_guard); if src_layers.aspects != dst_layers.aspects { return Err(TransferError::MismatchedAspects); } diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index 581ca6785fa..43184228002 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -252,7 +252,7 @@ impl Global { let device = &mut device_guard[queue_id]; let (texture_guard, _) = hub.textures.read(&mut token); let (image_layers, image_range, image_offset) = - crate::command::texture_copy_view_to_hal(destination, &*texture_guard); + crate::command::texture_copy_view_to_hal(destination, size, &*texture_guard); #[cfg(feature = "trace")] match device.trace {