Add support for gaps in bind group layouts & update relevant validation (#9034)

* [wgpu-core] add support for optional BG & BGL entries

* [wgpu] allow gaps in bind group layouts

And allow unbinding in the web backend.

* adapt tests

* add changelog entry

* [wgpu] remove generic from `PipelineLayoutDescriptor`
This commit is contained in:
Teodor Tanasoaia authored and GitHub committed 2026-02-25 19:47:36 +01:00
1 parent aad2a00f4d
commit e114d2f0a7
90 files changed
+567 -397

No files matched your search

+14 -15
View File
@@ -1,6 +1,7 @@
use alloc::{
boxed::Box,
string::{String, ToString as _},
sync::Arc,
vec::Vec,
};
use core::fmt;
@@ -1010,7 +1011,7 @@ pub fn check_texture_format(
}
}
pub enum BindingLayoutSource<'a> {
pub enum BindingLayoutSource {
/// The binding layout is derived from the pipeline layout.
///
/// This will be filled in by the shader binding validation, as it iterates the shader's interfaces.
@@ -1018,10 +1019,10 @@ pub enum BindingLayoutSource<'a> {
/// The binding layout is provided by the user in BGLs.
///
/// This will be validated against the shader's interfaces.
Provided(ArrayVec<&'a bgl::EntryMap, { hal::MAX_BIND_GROUPS }>),
Provided(Arc<crate::binding_model::PipelineLayout>),
}
impl<'a> BindingLayoutSource<'a> {
impl BindingLayoutSource {
pub fn new_derived(limits: &wgt::Limits) -> Self {
let mut array = ArrayVec::new();
for _ in 0..limits.max_bind_groups {
@@ -1247,7 +1248,7 @@ impl Interface {
/// <https://www.w3.org/TR/webgpu/#abstract-opdef-validating-inter-stage-interfaces>.
pub fn check_stage(
&self,
layouts: &mut BindingLayoutSource<'_>,
layouts: &mut BindingLayoutSource,
shader_binding_sizes: &mut FastHashMap<naga::ResourceBinding, wgt::BufferSize>,
entry_point_name: &str,
shader_stage: ShaderStageForValidation,
@@ -1269,7 +1270,7 @@ impl Interface {
let res = &self.resources[handle];
let result = 'err: {
match layouts {
BindingLayoutSource::Provided(layouts) => {
BindingLayoutSource::Provided(pipeline_layout) => {
// update the required binding size for this buffer
if let ResourceType::Buffer { size } = res.ty {
match shader_binding_sizes.entry(res.bind) {
@@ -1282,11 +1283,9 @@ impl Interface {
}
}
let Some(map) = layouts.get(res.bind.group as usize) else {
break 'err Err(BindingError::Missing);
};
let Some(entry) = map.get(res.bind.binding) else {
let Some(entry) =
pipeline_layout.get_bgl_entry(res.bind.group, res.bind.binding)
else {
break 'err Err(BindingError::Missing);
};
@@ -1340,15 +1339,15 @@ impl Interface {
//
// We only need to do this if the binding layout is provided by the user, as derived
// layouts will inherently be correctly tagged.
if let BindingLayoutSource::Provided(layouts) = layouts {
if let BindingLayoutSource::Provided(pipeline_layout) = layouts {
for &(texture_handle, sampler_handle) in entry_point.sampling_pairs.iter() {
let texture_bind = &self.resources[texture_handle].bind;
let sampler_bind = &self.resources[sampler_handle].bind;
let texture_layout = layouts[texture_bind.group as usize]
.get(texture_bind.binding)
let texture_layout = pipeline_layout
.get_bgl_entry(texture_bind.group, texture_bind.binding)
.unwrap();
let sampler_layout = layouts[sampler_bind.group as usize]
.get(sampler_bind.binding)
let sampler_layout = pipeline_layout
.get_bgl_entry(sampler_bind.group, sampler_bind.binding)
.unwrap();
assert!(texture_layout.visibility.contains(stage_bit));
assert!(sampler_layout.visibility.contains(stage_bit));