Skip to content

Commit

Permalink
Update texture_create_view logic to match spec (#2621)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinleili authored Apr 21, 2022
1 parent 5706263 commit 8feac35
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,10 +856,7 @@ impl<A: HalApi> Device<A> {
}
None => match texture.desc.dimension {
wgt::TextureDimension::D1 => wgt::TextureViewDimension::D1,
wgt::TextureDimension::D2
if texture.desc.size.depth_or_array_layers > 1
&& desc.range.array_layer_count.is_none() =>
{
wgt::TextureDimension::D2 if texture.desc.size.depth_or_array_layers > 1 => {
wgt::TextureViewDimension::D2Array
}
wgt::TextureDimension::D2 => wgt::TextureViewDimension::D2,
Expand All @@ -871,7 +868,13 @@ impl<A: HalApi> Device<A> {
desc.range.base_mip_level + desc.range.mip_level_count.map_or(1, |count| count.get());
let required_layer_count = match desc.range.array_layer_count {
Some(count) => desc.range.base_array_layer + count.get(),
None => texture.desc.array_layer_count(),
None => match view_dim {
wgt::TextureViewDimension::D1
| wgt::TextureViewDimension::D2
| wgt::TextureViewDimension::D3 => 1,
wgt::TextureViewDimension::Cube => 6,
_ => texture.desc.array_layer_count(),
},
};
let level_end = texture.full_range.levels.end;
let layer_end = texture.full_range.layers.end;
Expand Down
4 changes: 2 additions & 2 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3118,8 +3118,8 @@ impl<L> TextureDescriptor<L> {
/// Returns the number of array layers.
pub fn array_layer_count(&self) -> u32 {
match self.dimension {
TextureDimension::D1 | TextureDimension::D2 => self.size.depth_or_array_layers,
TextureDimension::D3 => 1,
TextureDimension::D1 | TextureDimension::D3 => 1,
TextureDimension::D2 => self.size.depth_or_array_layers,
}
}
}
Expand Down

0 comments on commit 8feac35

Please sign in to comment.