Skip to content

Commit

Permalink
Validate against the maximum binding index (#2892)
Browse files Browse the repository at this point in the history
* Validate binding indices in create_bind_group_layout.

* Add an entry in the changelog
  • Loading branch information
nical authored Aug 1, 2022
1 parent 0dce58d commit e59c330
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ the same every time it is rendered, we now warn if it is missing.
- Fix bugs when mapping/unmapping zero-sized buffers and ranges by @nical in [#2877](https://github.com/gfx-rs/wgpu/pull/2877)
- Fix out-of-bound write in `map_buffer` with non-zero offset by @nical in [#2916](https://github.com/gfx-rs/wgpu/pull/2916)
- 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]

#### DX12
- `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)
Expand Down
2 changes: 2 additions & 0 deletions wgpu-core/src/binding_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub enum CreateBindGroupLayoutError {
},
#[error(transparent)]
TooManyBindings(BindingTypeMaxCountError),
#[error("Binding index {binding} is greater than the maximum index {maximum}")]
InvalidBindingIndex { binding: u32, maximum: u32 },
}

//TODO: refactor this to move out `enum BindingError`.
Expand Down
9 changes: 9 additions & 0 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ pub mod queue;
#[cfg(any(feature = "trace", feature = "replay"))]
pub mod trace;

// Per WebGPU specification.
pub const MAX_BINDING_INDEX: u32 = 65535;

pub const SHADER_STAGE_COUNT: usize = 3;
// Should be large enough for the largest possible texture row. This value is enough for a 16k texture with float4 format.
pub(crate) const ZERO_BUFFER_SIZE: BufferAddress = 512 << 10;
Expand Down Expand Up @@ -4083,6 +4086,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

let mut entry_map = FastHashMap::default();
for entry in desc.entries.iter() {
if entry.binding > MAX_BINDING_INDEX {
break 'outer binding_model::CreateBindGroupLayoutError::InvalidBindingIndex {
binding: entry.binding,
maximum: MAX_BINDING_INDEX,
};
}
if entry_map.insert(entry.binding, *entry).is_some() {
break 'outer binding_model::CreateBindGroupLayoutError::ConflictBinding(
entry.binding,
Expand Down

0 comments on commit e59c330

Please sign in to comment.