Fix calculation/validation of layer/mip ranges in create_texture_view (#2955)

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
This commit is contained in:
Nicolas Silva
2022-08-14 02:01:19 +02:00
committed by GitHub
parent 96a85b3ac5
commit 6e99cd3a3e
2 changed files with 8 additions and 4 deletions

View File

@@ -113,6 +113,7 @@ the same every time it is rendered, we now warn if it is missing.
- Validate the number of color attachments in `create_render_pipeline` by @nical in [#2913](https://github.com/gfx-rs/wgpu/pull/2913)
- Validate against the maximum binding index in `create_bind_group_layout` by @nical in [#2892](https://github.com/gfx-rs/wgpu/pull/2892)
- Validate that map_async's range is not negative by @nical in [#2938](https://github.com/gfx-rs/wgpu/pull/2938)
- Fix calculation/validation of layer/mip ranges in create_texture_view by @nical in [#2955](https://github.com/gfx-rs/wgpu/pull/2955)
- Validate the sample count and mip level in `copy_texture_to_buffer` by @nical in [#2958](https://github.com/gfx-rs/wgpu/pull/2958)
#### DX12

View File

@@ -948,18 +948,21 @@ impl<A: HalApi> Device<A> {
},
};
let required_level_count =
desc.range.base_mip_level + desc.range.mip_level_count.map_or(1, |count| count.get());
let mip_count = desc.range.mip_level_count.map_or(1, |count| count.get());
let required_level_count = desc.range.base_mip_level.saturating_add(mip_count);
let required_layer_count = match desc.range.array_layer_count {
Some(count) => desc.range.base_array_layer + count.get(),
Some(count) => desc.range.base_array_layer.saturating_add(count.get()),
None => match view_dim {
wgt::TextureViewDimension::D1
| wgt::TextureViewDimension::D2
| wgt::TextureViewDimension::D3 => 1,
wgt::TextureViewDimension::Cube => 6,
_ => texture.desc.array_layer_count(),
},
}
.max(desc.range.base_array_layer.saturating_add(1)),
};
let level_end = texture.full_range.mips.end;
let layer_end = texture.full_range.layers.end;
if required_level_count > level_end {