Skip to content

Commit

Permalink
Fix calculation/validation of layer/mip ranges in create_texture_view (
Browse files Browse the repository at this point in the history
…#2955)

Co-authored-by: Connor Fitzgerald <[email protected]>
  • Loading branch information
nical and cwfitzgerald authored Aug 14, 2022
1 parent 96a85b3 commit 6e99cd3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6e99cd3

Please sign in to comment.