mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-20 22:41:07 +01:00
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:
1 parent
aad2a00f4d
commit
e114d2f0a7
90 files changed
+567
-397
No files matched your search
@@ -522,17 +522,6 @@ fn set_bind_group(
|
||||
num_dynamic_offsets: usize,
|
||||
bind_group_id: Option<id::Id<id::markers::BindGroup>>,
|
||||
) -> Result<(), RenderBundleErrorInner> {
|
||||
if bind_group_id.is_none() {
|
||||
// TODO: do appropriate cleanup for null bind_group.
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let bind_group_id = bind_group_id.unwrap();
|
||||
|
||||
let bind_group = bind_group_guard.get(bind_group_id).get()?;
|
||||
|
||||
bind_group.same_device(&state.device)?;
|
||||
|
||||
let max_bind_groups = state.device.limits.max_bind_groups;
|
||||
if index >= max_bind_groups {
|
||||
return Err(
|
||||
@@ -549,14 +538,31 @@ fn set_bind_group(
|
||||
state.next_dynamic_offset = offsets_range.end;
|
||||
let offsets = &dynamic_offsets[offsets_range.clone()];
|
||||
|
||||
bind_group.validate_dynamic_bindings(index, offsets)?;
|
||||
let bind_group = bind_group_id.map(|id| bind_group_guard.get(id));
|
||||
|
||||
unsafe { state.trackers.merge_bind_group(&bind_group.used)? };
|
||||
let bind_group = state.trackers.bind_groups.insert_single(bind_group);
|
||||
if let Some(bind_group) = bind_group {
|
||||
let bind_group = bind_group.get()?;
|
||||
bind_group.same_device(&state.device)?;
|
||||
bind_group.validate_dynamic_bindings(index, offsets)?;
|
||||
|
||||
state
|
||||
.binder
|
||||
.assign_group(index as usize, bind_group, offsets);
|
||||
unsafe { state.trackers.merge_bind_group(&bind_group.used)? };
|
||||
let bind_group = state.trackers.bind_groups.insert_single(bind_group);
|
||||
|
||||
state
|
||||
.binder
|
||||
.assign_group(index as usize, bind_group, offsets);
|
||||
} else {
|
||||
if !offsets.is_empty() {
|
||||
return Err(RenderBundleErrorInner::Bind(
|
||||
BindError::DynamicOffsetCountNotZero {
|
||||
group: index,
|
||||
actual: offsets.len(),
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
state.binder.clear_group(index as usize);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -977,17 +983,12 @@ impl RenderBundle {
|
||||
num_dynamic_offsets,
|
||||
bind_group,
|
||||
} => {
|
||||
let mut bg = None;
|
||||
if bind_group.is_some() {
|
||||
let bind_group = bind_group.as_ref().unwrap();
|
||||
let raw_bg = bind_group.try_raw(snatch_guard)?;
|
||||
bg = Some(raw_bg);
|
||||
}
|
||||
let raw_bg = bind_group.as_ref().unwrap().try_raw(snatch_guard)?;
|
||||
unsafe {
|
||||
raw.set_bind_group(
|
||||
pipeline_layout.as_ref().unwrap().raw(),
|
||||
*index,
|
||||
bg,
|
||||
raw_bg,
|
||||
&offsets[..*num_dynamic_offsets],
|
||||
)
|
||||
};
|
||||
@@ -1435,26 +1436,24 @@ impl State {
|
||||
///
|
||||
/// This should be further deduplicated with similar code on render/compute passes.
|
||||
fn flush_bindings(&mut self) {
|
||||
let range = self.binder.take_rebind_range();
|
||||
let entries = self.binder.entries(range);
|
||||
let start = self.binder.take_rebind_start_index();
|
||||
let entries = self.binder.list_valid_with_start(start);
|
||||
|
||||
self.commands.extend(entries.map(|(i, entry)| {
|
||||
let bind_group = entry.group.as_ref().unwrap();
|
||||
self.commands
|
||||
.extend(entries.map(|(i, bind_group, dynamic_offsets)| {
|
||||
self.buffer_memory_init_actions
|
||||
.extend_from_slice(&bind_group.used_buffer_ranges);
|
||||
self.texture_memory_init_actions
|
||||
.extend_from_slice(&bind_group.used_texture_ranges);
|
||||
|
||||
self.buffer_memory_init_actions
|
||||
.extend_from_slice(&bind_group.used_buffer_ranges);
|
||||
self.texture_memory_init_actions
|
||||
.extend_from_slice(&bind_group.used_texture_ranges);
|
||||
self.flat_dynamic_offsets.extend_from_slice(dynamic_offsets);
|
||||
|
||||
self.flat_dynamic_offsets
|
||||
.extend_from_slice(&entry.dynamic_offsets);
|
||||
|
||||
ArcRenderCommand::SetBindGroup {
|
||||
index: i.try_into().unwrap(),
|
||||
bind_group: Some(bind_group.clone()),
|
||||
num_dynamic_offsets: entry.dynamic_offsets.len(),
|
||||
}
|
||||
}));
|
||||
ArcRenderCommand::SetBindGroup {
|
||||
index: i.try_into().unwrap(),
|
||||
bind_group: Some(bind_group.clone()),
|
||||
num_dynamic_offsets: dynamic_offsets.len(),
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
fn vertex_buffer_sizes(&self) -> impl Iterator<Item = Option<wgt::BufferAddress>> + '_ {
|
||||
|
||||
Reference in new issue
Block a user