Skip to content

Commit e59c330

Browse files
authored
Validate against the maximum binding index (#2892)
* Validate binding indices in create_bind_group_layout. * Add an entry in the changelog
1 parent 0dce58d commit e59c330

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ the same every time it is rendered, we now warn if it is missing.
9797
- Fix bugs when mapping/unmapping zero-sized buffers and ranges by @nical in [#2877](https://github.com/gfx-rs/wgpu/pull/2877)
9898
- Fix out-of-bound write in `map_buffer` with non-zero offset by @nical in [#2916](https://github.com/gfx-rs/wgpu/pull/2916)
9999
- Validate the number of color attachments in `create_render_pipeline` by @nical in [#2913](https://github.com/gfx-rs/wgpu/pull/2913)
100+
- Validate against the maximum binding index in `create_bind_group_layout` by @nical in [#2892]
100101

101102
#### DX12
102103
- `DownlevelCapabilities::default()` now returns the `ANISOTROPIC_FILTERING` flag set to true so DX12 lists `ANISOTROPIC_FILTERING` as true again by @cwfitzgerald in [#2851](https://github.com/gfx-rs/wgpu/pull/2851)

wgpu-core/src/binding_model.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ pub enum CreateBindGroupLayoutError {
4848
},
4949
#[error(transparent)]
5050
TooManyBindings(BindingTypeMaxCountError),
51+
#[error("Binding index {binding} is greater than the maximum index {maximum}")]
52+
InvalidBindingIndex { binding: u32, maximum: u32 },
5153
}
5254

5355
//TODO: refactor this to move out `enum BindingError`.

wgpu-core/src/device/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ pub mod queue;
3131
#[cfg(any(feature = "trace", feature = "replay"))]
3232
pub mod trace;
3333

34+
// Per WebGPU specification.
35+
pub const MAX_BINDING_INDEX: u32 = 65535;
36+
3437
pub const SHADER_STAGE_COUNT: usize = 3;
3538
// Should be large enough for the largest possible texture row. This value is enough for a 16k texture with float4 format.
3639
pub(crate) const ZERO_BUFFER_SIZE: BufferAddress = 512 << 10;
@@ -4083,6 +4086,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
40834086

40844087
let mut entry_map = FastHashMap::default();
40854088
for entry in desc.entries.iter() {
4089+
if entry.binding > MAX_BINDING_INDEX {
4090+
break 'outer binding_model::CreateBindGroupLayoutError::InvalidBindingIndex {
4091+
binding: entry.binding,
4092+
maximum: MAX_BINDING_INDEX,
4093+
};
4094+
}
40864095
if entry_map.insert(entry.binding, *entry).is_some() {
40874096
break 'outer binding_model::CreateBindGroupLayoutError::ConflictBinding(
40884097
entry.binding,

0 commit comments

Comments
 (0)