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

+7
View File
@@ -2514,6 +2514,12 @@ impl super::Adapter {
let drop_guard = crate::DropGuard::from_option(drop_callback);
let empty_descriptor_set_layout = unsafe {
raw_device
.create_descriptor_set_layout(&vk::DescriptorSetLayoutCreateInfo::default(), None)
.map_err(super::map_host_device_oom_err)?
};
let shared = Arc::new(super::DeviceShared {
raw: raw_device,
family_index,
@@ -2544,6 +2550,7 @@ impl super::Adapter {
texture_identity_factory: super::ResourceIdentityFactory::new(),
texture_view_identity_factory: super::ResourceIdentityFactory::new(),
empty_descriptor_set_layout,
});
let relay_semaphores = super::RelaySemaphores::new(&shared)?;
+18 -2
View File
@@ -1420,7 +1420,19 @@ impl crate::Device for super::Device {
let vk_set_layouts = desc
.bind_group_layouts
.iter()
.map(|bgl| bgl.raw)
.map(|bgl| match bgl {
Some(bgl) => bgl.raw,
None => {
// `VUID-VkPipelineLayoutCreateInfo-pSetLayouts-parameter`
// says `VK_NULL_HANDLE` is allowed but
// `VUID-VkPipelineLayoutCreateInfo-graphicsPipelineLibrary-06753`
// says it's not, unless the `graphicsPipelineLibrary`
// feature is enabled.
//
// We use an empty descriptor set layout to work around this.
self.shared.empty_descriptor_set_layout
}
})
.collect::<Vec<_>>();
let vk_immediates_ranges: Option<vk::PushConstantRange> = if desc.immediate_size != 0 {
Some(vk::PushConstantRange {
@@ -1452,7 +1464,11 @@ impl crate::Device for super::Device {
}
let mut binding_map = BTreeMap::new();
for (group, &layout) in desc.bind_group_layouts.iter().enumerate() {
for (group, layout) in desc.bind_group_layouts.iter().enumerate() {
let Some(layout) = layout else {
continue;
};
for &(binding, binding_info) in &layout.binding_map {
binding_map.insert(
naga::ResourceBinding {
+6
View File
@@ -495,6 +495,8 @@ struct DeviceShared {
/// As above, for texture views.
texture_view_identity_factory: ResourceIdentityFactory<vk::ImageView>,
empty_descriptor_set_layout: vk::DescriptorSetLayout,
// The `drop_guard` field must be the last field of this struct so it is dropped last.
// Do not add new fields after it.
drop_guard: Option<crate::DropGuard>,
@@ -505,6 +507,10 @@ impl Drop for DeviceShared {
for &raw in self.render_passes.lock().values() {
unsafe { self.raw.destroy_render_pass(raw, None) };
}
unsafe {
self.raw
.destroy_descriptor_set_layout(self.empty_descriptor_set_layout, None)
};
if self.drop_guard.is_none() {
unsafe { self.raw.destroy_device(None) };
}