Validate against the maximum binding index (#2892)

* Validate binding indices in create_bind_group_layout.

* Add an entry in the changelog
This commit is contained in:
Nicolas Silva
2022-08-01 22:25:32 +02:00
committed by GitHub
parent 0dce58dfbd
commit e59c33046b
3 changed files with 12 additions and 0 deletions

View File

@@ -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)

View File

@@ -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`.

View File

@@ -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;
@@ -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,