From 103e7763a3c93d806b1831990cb430f293f8fa81 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Mon, 1 Mar 2021 11:08:17 -0500 Subject: [PATCH] Rename depth to depth_or_array_layers --- player/tests/data/quad.ron | 4 +-- wgpu-core/src/command/transfer.rs | 20 +++++++------- wgpu-core/src/conv.rs | 12 ++++---- wgpu-core/src/device/mod.rs | 4 +-- wgpu-core/src/device/queue.rs | 9 +++--- wgpu-core/src/swap_chain.rs | 2 +- wgpu-types/src/lib.rs | 46 +++++++++++++++---------------- 7 files changed, 49 insertions(+), 48 deletions(-) diff --git a/player/tests/data/quad.ron b/player/tests/data/quad.ron index b91ef58bf..e004d52e7 100644 --- a/player/tests/data/quad.ron +++ b/player/tests/data/quad.ron @@ -22,7 +22,7 @@ size: ( width: 64, height: 64, - depth: 1, + depth_or_array_layers: 1, ), mip_level_count: 1, sample_count: 1, @@ -127,7 +127,7 @@ size: ( width: 64, height: 64, - depth: 1, + depth_or_array_layers: 1, ), ), ]), diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index 92ed56214..9679d3c03 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -122,7 +122,7 @@ pub(crate) fn texture_copy_view_to_hal( 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, + size.depth_or_array_layers as hal::image::Layer, 0, ), wgt::TextureDimension::D3 => (0, 1, view.origin.z as i32), @@ -162,7 +162,7 @@ pub(crate) fn validate_linear_texture_data( // Convert all inputs to BufferAddress (u64) to prevent overflow issues let copy_width = copy_size.width as BufferAddress; let copy_height = copy_size.height as BufferAddress; - let copy_depth = copy_size.depth as BufferAddress; + let copy_depth = copy_size.depth_or_array_layers as BufferAddress; let offset = layout.offset; let rows_per_image = layout.rows_per_image as BufferAddress; @@ -244,7 +244,7 @@ pub(crate) fn validate_texture_copy_range( match texture_dimension { hal::image::Kind::D1(..) => { - if (copy_size.height, copy_size.depth) != (1, 1) { + if (copy_size.height, copy_size.depth_or_array_layers) != (1, 1) { return Err(TransferError::InvalidCopySize); } } @@ -274,7 +274,7 @@ pub(crate) fn validate_texture_copy_range( side: texture_side, }); } - let z_copy_max = texture_copy_view.origin.z + copy_size.depth; + let z_copy_max = texture_copy_view.origin.z + copy_size.depth_or_array_layers; if z_copy_max > extent.depth { return Err(TransferError::TextureOverrun { start_offset: texture_copy_view.origin.z, @@ -469,7 +469,7 @@ impl Global { }); } - if copy_size.width == 0 || copy_size.height == 0 || copy_size.depth == 0 { + if copy_size.width == 0 || copy_size.height == 0 || copy_size.depth_or_array_layers == 0 { tracing::trace!("Ignoring copy_buffer_to_texture of size 0"); return Ok(()); } @@ -564,7 +564,7 @@ impl Global { let image_extent = Extent3d { width: copy_size.width.min(max_image_extent.width), height: copy_size.height.min(max_image_extent.height), - depth: copy_size.depth, + depth_or_array_layers: copy_size.depth_or_array_layers, }; let buffer_width = (source.layout.bytes_per_row / bytes_per_block) * block_width as u32; @@ -620,7 +620,7 @@ impl Global { }); } - if copy_size.width == 0 || copy_size.height == 0 || copy_size.depth == 0 { + if copy_size.width == 0 || copy_size.height == 0 || copy_size.depth_or_array_layers == 0 { tracing::trace!("Ignoring copy_texture_to_buffer of size 0"); return Ok(()); } @@ -718,7 +718,7 @@ impl Global { let image_extent = Extent3d { width: copy_size.width.min(max_image_extent.width), height: copy_size.height.min(max_image_extent.height), - depth: copy_size.depth, + depth_or_array_layers: copy_size.depth_or_array_layers, }; let buffer_width = @@ -781,7 +781,7 @@ impl Global { }); } - if copy_size.width == 0 || copy_size.height == 0 || copy_size.depth == 0 { + if copy_size.width == 0 || copy_size.height == 0 || copy_size.depth_or_array_layers == 0 { tracing::trace!("Ignoring copy_texture_to_texture of size 0"); return Ok(()); } @@ -859,7 +859,7 @@ impl Global { height: copy_size .height .min(max_src_image_extent.height.min(max_dst_image_extent.height)), - depth: copy_size.depth, + depth_or_array_layers: copy_size.depth_or_array_layers, }; let region = hal::command::ImageCopy { diff --git a/wgpu-core/src/conv.rs b/wgpu-core/src/conv.rs index 1c2fa91ba..439e357f7 100644 --- a/wgpu-core/src/conv.rs +++ b/wgpu-core/src/conv.rs @@ -160,7 +160,7 @@ pub fn map_extent(extent: &wgt::Extent3d, dim: wgt::TextureDimension) -> hal::im height: extent.height, depth: match dim { wgt::TextureDimension::D1 | wgt::TextureDimension::D2 => 1, - wgt::TextureDimension::D3 => extent.depth, + wgt::TextureDimension::D3 => extent.depth_or_array_layers, }, } } @@ -518,7 +518,7 @@ pub fn map_texture_dimension_size( wgt::Extent3d { width, height, - depth, + depth_or_array_layers, }: wgt::Extent3d, sample_size: u32, ) -> Result { @@ -530,7 +530,7 @@ pub fn map_texture_dimension_size( Some(resource::TextureErrorDimension::X) } else if height == 0 { Some(resource::TextureErrorDimension::Y) - } else if depth == 0 { + } else if depth_or_array_layers == 0 { Some(resource::TextureErrorDimension::Z) } else { None @@ -547,21 +547,21 @@ pub fn map_texture_dimension_size( if sample_size != 1 { return Err(Tde::InvalidSampleCount(sample_size)); } - let layers = depth.try_into().unwrap_or(!0); + let layers = depth_or_array_layers.try_into().unwrap_or(!0); H::D1(width, layers) } D2 => { if sample_size > 32 || !is_power_of_two(sample_size) { return Err(Tde::InvalidSampleCount(sample_size)); } - let layers = depth.try_into().unwrap_or(!0); + let layers = depth_or_array_layers.try_into().unwrap_or(!0); H::D2(width, height, layers, sample_size as u8) } D3 => { if sample_size != 1 { return Err(Tde::InvalidSampleCount(sample_size)); } - H::D3(width, height, depth) + H::D3(width, height, depth_or_array_layers) } }) } diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 3fdd512d3..12aa0fb08 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -660,7 +660,7 @@ impl Device { let mut view_caps = hal::image::ViewCapabilities::empty(); // 2D textures with array layer counts that are multiples of 6 could be cubemaps // Following gpuweb/gpuweb#68 always add the hint in that case - if desc.dimension == TextureDimension::D2 && desc.size.depth % 6 == 0 { + if desc.dimension == TextureDimension::D2 && desc.size.depth_or_array_layers % 6 == 0 { view_caps |= hal::image::ViewCapabilities::KIND_CUBE; }; @@ -874,7 +874,7 @@ impl Device { extent: wgt::Extent3d { width: hal_extent.width, height: hal_extent.height, - depth: view_layer_count, + depth_or_array_layers: view_layer_count, }, samples: texture.kind.num_samples(), framebuffer_attachment: texture.framebuffer_attachment.clone(), diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index c93b45e0c..494e42e50 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -321,7 +321,7 @@ impl Global { }); } - if size.width == 0 || size.height == 0 || size.depth == 0 { + if size.width == 0 || size.height == 0 || size.depth_or_array_layers == 0 { tracing::trace!("Ignoring write_texture of size 0"); return Ok(()); } @@ -359,7 +359,8 @@ impl Global { ); let stage_bytes_per_row = align_to(bytes_per_block * width_blocks, bytes_per_row_alignment); - let block_rows_in_copy = (size.depth - 1) * block_rows_per_image + height_blocks; + let block_rows_in_copy = + (size.depth_or_array_layers - 1) * block_rows_per_image + height_blocks; let stage_size = stage_bytes_per_row as u64 * block_rows_in_copy as u64; let mut stage = device.prepare_stage(stage_size)?; @@ -403,7 +404,7 @@ impl Global { // Copy row by row into the optimal alignment. let copy_bytes_per_row = stage_bytes_per_row.min(data_layout.bytes_per_row) as usize; - for layer in 0..size.depth { + for layer in 0..size.depth_or_array_layers { let rows_offset = layer * block_rows_per_image; for row in 0..height_blocks { ptr::copy_nonoverlapping( @@ -432,7 +433,7 @@ impl Global { let image_extent = wgt::Extent3d { width: size.width.min(max_image_extent.width), height: size.height.min(max_image_extent.height), - depth: size.depth, + depth_or_array_layers: size.depth_or_array_layers, }; let region = hal::command::BufferImageCopy { diff --git a/wgpu-core/src/swap_chain.rs b/wgpu-core/src/swap_chain.rs index e8dfe31e2..65fa57149 100644 --- a/wgpu-core/src/swap_chain.rs +++ b/wgpu-core/src/swap_chain.rs @@ -193,7 +193,7 @@ impl Global { extent: wgt::Extent3d { width: sc.desc.width, height: sc.desc.height, - depth: 1, + depth_or_array_layers: 1, }, samples: 1, framebuffer_attachment: sc.framebuffer_attachment.clone(), diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index c8a11d49d..70d2e9b7f 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2164,7 +2164,7 @@ pub struct Extent3d { /// pub height: u32, /// - pub depth: u32, + pub depth_or_array_layers: u32, } impl Default for Extent3d { @@ -2172,7 +2172,7 @@ impl Default for Extent3d { Self { width: 1, height: 1, - depth: 1, + depth_or_array_layers: 1, } } } @@ -2187,18 +2187,18 @@ impl Extent3d { /// # use wgpu_types as wgpu; /// let format = wgpu::TextureFormat::Bc1RgbaUnormSrgb; // 4x4 blocks /// assert_eq!( - /// wgpu::Extent3d { width: 7, height: 7, depth: 1 }.physical_size(format), - /// wgpu::Extent3d { width: 8, height: 8, depth: 1 } + /// wgpu::Extent3d { width: 7, height: 7, depth_or_array_layers: 1 }.physical_size(format), + /// wgpu::Extent3d { width: 8, height: 8, depth_or_array_layers: 1 } /// ); /// // Doesn't change, already aligned /// assert_eq!( - /// wgpu::Extent3d { width: 8, height: 8, depth: 1 }.physical_size(format), - /// wgpu::Extent3d { width: 8, height: 8, depth: 1 } + /// wgpu::Extent3d { width: 8, height: 8, depth_or_array_layers: 1 }.physical_size(format), + /// wgpu::Extent3d { width: 8, height: 8, depth_or_array_layers: 1 } /// ); /// let format = wgpu::TextureFormat::Astc8x5RgbaUnorm; // 8x5 blocks /// assert_eq!( - /// wgpu::Extent3d { width: 7, height: 7, depth: 1 }.physical_size(format), - /// wgpu::Extent3d { width: 8, height: 10, depth: 1 } + /// wgpu::Extent3d { width: 7, height: 7, depth_or_array_layers: 1 }.physical_size(format), + /// wgpu::Extent3d { width: 8, height: 10, depth_or_array_layers: 1 } /// ); /// ``` /// @@ -2214,7 +2214,7 @@ impl Extent3d { Self { width, height, - depth: self.depth, + depth_or_array_layers: self.depth_or_array_layers, } } @@ -2225,12 +2225,12 @@ impl Extent3d { /// /// ```rust /// # use wgpu_types as wgpu; - /// assert_eq!(wgpu::Extent3d { width: 1, height: 1, depth: 1 }.max_mips(), 1); - /// assert_eq!(wgpu::Extent3d { width: 60, height: 60, depth: 1 }.max_mips(), 6); - /// assert_eq!(wgpu::Extent3d { width: 240, height: 1, depth: 1 }.max_mips(), 8); + /// assert_eq!(wgpu::Extent3d { width: 1, height: 1, depth_or_array_layers: 1 }.max_mips(), 1); + /// assert_eq!(wgpu::Extent3d { width: 60, height: 60, depth_or_array_layers: 1 }.max_mips(), 6); + /// assert_eq!(wgpu::Extent3d { width: 240, height: 1, depth_or_array_layers: 1 }.max_mips(), 8); /// ``` pub fn max_mips(&self) -> u8 { - let max_dim = self.width.max(self.height.max(self.depth)); + let max_dim = self.width.max(self.height.max(self.depth_or_array_layers)); let max_levels = 32 - max_dim.leading_zeros(); max_levels as u8 @@ -2245,15 +2245,15 @@ impl Extent3d { /// /// ```rust /// # use wgpu_types as wgpu; - /// let extent = wgpu::Extent3d { width: 100, height: 60, depth: 1 }; + /// let extent = wgpu::Extent3d { width: 100, height: 60, depth_or_array_layers: 1 }; /// - /// assert_eq!(extent.at_mip_level(0), Some(wgpu::Extent3d { width: 100, height: 60, depth: 1 })); - /// assert_eq!(extent.at_mip_level(1), Some(wgpu::Extent3d { width: 50, height: 30, depth: 1 })); - /// assert_eq!(extent.at_mip_level(2), Some(wgpu::Extent3d { width: 25, height: 15, depth: 1 })); - /// assert_eq!(extent.at_mip_level(3), Some(wgpu::Extent3d { width: 12, height: 7, depth: 1 })); - /// assert_eq!(extent.at_mip_level(4), Some(wgpu::Extent3d { width: 6, height: 3, depth: 1 })); - /// assert_eq!(extent.at_mip_level(5), Some(wgpu::Extent3d { width: 3, height: 1, depth: 1 })); - /// assert_eq!(extent.at_mip_level(6), Some(wgpu::Extent3d { width: 1, height: 1, depth: 1 })); + /// assert_eq!(extent.at_mip_level(0), Some(wgpu::Extent3d { width: 100, height: 60, depth_or_array_layers: 1 })); + /// assert_eq!(extent.at_mip_level(1), Some(wgpu::Extent3d { width: 50, height: 30, depth_or_array_layers: 1 })); + /// assert_eq!(extent.at_mip_level(2), Some(wgpu::Extent3d { width: 25, height: 15, depth_or_array_layers: 1 })); + /// assert_eq!(extent.at_mip_level(3), Some(wgpu::Extent3d { width: 12, height: 7, depth_or_array_layers: 1 })); + /// assert_eq!(extent.at_mip_level(4), Some(wgpu::Extent3d { width: 6, height: 3, depth_or_array_layers: 1 })); + /// assert_eq!(extent.at_mip_level(5), Some(wgpu::Extent3d { width: 3, height: 1, depth_or_array_layers: 1 })); + /// assert_eq!(extent.at_mip_level(6), Some(wgpu::Extent3d { width: 1, height: 1, depth_or_array_layers: 1 })); /// assert_eq!(extent.at_mip_level(7), None); /// ``` pub fn at_mip_level(&self, level: u8) -> Option { @@ -2263,10 +2263,10 @@ impl Extent3d { return None; } - Some(Extent3d { + Some(Self { width: u32::max(1, self.width >> level as u32), height: u32::max(1, self.height >> level as u32), - depth: u32::max(1, self.depth >> level as u32), + depth_or_array_layers: u32::max(1, self.depth_or_array_layers >> level as u32), }) } }