Skip to content

Commit 6e99cd3

Browse files
nicalcwfitzgerald
andauthored
Fix calculation/validation of layer/mip ranges in create_texture_view (#2955)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
1 parent 96a85b3 commit 6e99cd3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ the same every time it is rendered, we now warn if it is missing.
113113
- Validate the number of color attachments in `create_render_pipeline` by @nical in [#2913](https://github.com/gfx-rs/wgpu/pull/2913)
114114
- Validate against the maximum binding index in `create_bind_group_layout` by @nical in [#2892](https://github.com/gfx-rs/wgpu/pull/2892)
115115
- Validate that map_async's range is not negative by @nical in [#2938](https://github.com/gfx-rs/wgpu/pull/2938)
116+
- Fix calculation/validation of layer/mip ranges in create_texture_view by @nical in [#2955](https://github.com/gfx-rs/wgpu/pull/2955)
116117
- Validate the sample count and mip level in `copy_texture_to_buffer` by @nical in [#2958](https://github.com/gfx-rs/wgpu/pull/2958)
117118

118119
#### DX12

wgpu-core/src/device/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -948,18 +948,21 @@ impl<A: HalApi> Device<A> {
948948
},
949949
};
950950

951-
let required_level_count =
952-
desc.range.base_mip_level + desc.range.mip_level_count.map_or(1, |count| count.get());
951+
let mip_count = desc.range.mip_level_count.map_or(1, |count| count.get());
952+
let required_level_count = desc.range.base_mip_level.saturating_add(mip_count);
953+
953954
let required_layer_count = match desc.range.array_layer_count {
954-
Some(count) => desc.range.base_array_layer + count.get(),
955+
Some(count) => desc.range.base_array_layer.saturating_add(count.get()),
955956
None => match view_dim {
956957
wgt::TextureViewDimension::D1
957958
| wgt::TextureViewDimension::D2
958959
| wgt::TextureViewDimension::D3 => 1,
959960
wgt::TextureViewDimension::Cube => 6,
960961
_ => texture.desc.array_layer_count(),
961-
},
962+
}
963+
.max(desc.range.base_array_layer.saturating_add(1)),
962964
};
965+
963966
let level_end = texture.full_range.mips.end;
964967
let layer_end = texture.full_range.layers.end;
965968
if required_level_count > level_end {

0 commit comments

Comments
 (0)