Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,8 @@ bitflags!(
pub struct BindGroupLayoutFlags: u32 {
/// Allows for bind group binding arrays to be shorter than the array in the BGL.
const PARTIALLY_BOUND = 1 << 0;
/// Internal: remap bindings to a dense 0..N range in declaration order.
const INTERNAL_SEQUENTIAL_BINDINGS = 1 << 1;
Comment thread
dylanblokhuis marked this conversation as resolved.
}
);

Expand Down
42 changes: 28 additions & 14 deletions wgpu-hal/src/vulkan/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,9 @@ impl crate::Device for super::Device {
let mut binding_flags = Vec::new();
let mut binding_map = Vec::new();
let mut next_binding = 0;
let remap_to_sequential = desc
.flags
.contains(crate::BindGroupLayoutFlags::INTERNAL_SEQUENTIAL_BINDINGS);
let mut contains_binding_arrays = false;
let mut desc_count = gpu_descriptor::DescriptorTotalCount::default();
for entry in desc.entries {
Expand All @@ -1311,8 +1314,16 @@ impl crate::Device for super::Device {
match entry.ty {
wgt::BindingType::ExternalTexture => unimplemented!(),
_ => {
let binding = if remap_to_sequential {
let remapped = next_binding;
next_binding += 1;
remapped
} else {
entry.binding
};

vk_bindings.push(vk::DescriptorSetLayoutBinding {
binding: next_binding,
binding,
descriptor_type: conv::map_binding_type(entry.ty),
descriptor_count: count,
stage_flags: conv::map_shader_stage(entry.visibility),
Expand All @@ -1323,11 +1334,10 @@ impl crate::Device for super::Device {
binding_map.push((
entry.binding,
super::BindingInfo {
binding: next_binding,
binding,
binding_array_size: entry.count,
},
));
next_binding += 1;
}
}

Expand Down Expand Up @@ -1601,10 +1611,18 @@ impl crate::Device for super::Device {
.iter()
.find(|layout_entry| layout_entry.binding == entry.binding)
.expect("internal error: no layout entry found with binding slot");
(layout, entry)
let binding = desc
.layout
.binding_map
.iter()
.find_map(|&(mapped_binding, binding_info)| {
(mapped_binding == entry.binding).then_some(binding_info.binding)
})
.expect("internal error: no mapped binding found for layout entry");
(layout, entry, binding)
});
let mut next_binding = 0;
for (layout, entry) in layout_and_entry_iter {

for (layout, entry, binding) in layout_and_entry_iter {
let write = vk::WriteDescriptorSet::default().dst_set(*set.raw());

match layout.ty {
Expand All @@ -1618,11 +1636,10 @@ impl crate::Device for super::Device {
));
writes.push(
write
.dst_binding(next_binding)
.dst_binding(binding)
.descriptor_type(conv::map_binding_type(layout.ty))
.image_info(local_image_infos),
);
next_binding += 1;
}
wgt::BindingType::Texture { .. } | wgt::BindingType::StorageTexture { .. } => {
let start = entry.resource_index;
Expand All @@ -1640,11 +1657,10 @@ impl crate::Device for super::Device {
));
writes.push(
write
.dst_binding(next_binding)
.dst_binding(binding)
.descriptor_type(conv::map_binding_type(layout.ty))
.image_info(local_image_infos),
);
next_binding += 1;
}
wgt::BindingType::Buffer { .. } => {
let start = entry.resource_index;
Expand All @@ -1663,11 +1679,10 @@ impl crate::Device for super::Device {
));
writes.push(
write
.dst_binding(next_binding)
.dst_binding(binding)
.descriptor_type(conv::map_binding_type(layout.ty))
.buffer_info(local_buffer_infos),
);
next_binding += 1;
}
wgt::BindingType::AccelerationStructure { .. } => {
let start = entry.resource_index;
Expand All @@ -1694,12 +1709,11 @@ impl crate::Device for super::Device {

writes.push(
write
.dst_binding(next_binding)
.dst_binding(binding)
.descriptor_type(conv::map_binding_type(layout.ty))
.descriptor_count(entry.count)
.push_next(local_acceleration_structure_infos),
);
next_binding += 1;
}
wgt::BindingType::ExternalTexture => unimplemented!(),
}
Expand Down