Skip to content

Commit

Permalink
Add function to clear bindgroups from passes.
Browse files Browse the repository at this point in the history
Since the spec allows null BindGroups to be passed to setBindGroup, we
need a way to clear the bindGroup associated with an index/slot.
  • Loading branch information
bradwerth committed Jun 5, 2024
1 parent 583cc6a commit 436698b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions wgpu-core/src/command/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,14 @@ pub mod bundle_ffi {
});
}

#[no_mangle]
pub extern "C" fn wgpu_render_bundle_clear_bind_group(
bundle: &mut RenderBundleEncoder,
index: u32,
) {
bundle.current_bind_groups.clear_bind_group(index)
}

#[no_mangle]
pub extern "C" fn wgpu_render_bundle_set_pipeline(
bundle: &mut RenderBundleEncoder,
Expand Down
8 changes: 8 additions & 0 deletions wgpu-core/src/command/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,14 @@ impl Global {
Ok(())
}

pub fn wgpu_compute_pass_clear_bind_group<A: HalApi>(
&self,
pass: &mut ComputePass<A>,
index: u32,
) {
pass.current_bind_groups.clear_bind_group(index)
}

pub fn compute_pass_set_pipeline<A: HalApi>(
&self,
pass: &mut ComputePass<A>,
Expand Down
7 changes: 7 additions & 0 deletions wgpu-core/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,13 @@ impl BindGroupStateChange {
}
false
}

fn clear_bind_group(&mut self, index: u32) {
if let Some(current_bind_group) = self.last_states.get_mut(index as usize) {
current_bind_group.reset();
}
}

fn reset(&mut self) {
self.last_states = [StateChange::new(); hal::MAX_BIND_GROUPS];
}
Expand Down
4 changes: 4 additions & 0 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2488,6 +2488,10 @@ pub mod render_commands {
});
}

pub fn wgpu_render_pass_clear_bind_group(pass: &mut RenderPass, index: u32) {
pass.current_bind_groups.clear_bind_group(index)
}

pub fn wgpu_render_pass_set_pipeline(pass: &mut RenderPass, pipeline_id: id::RenderPipelineId) {
if pass.current_pipeline.set_and_check_redundant(pipeline_id) {
return;
Expand Down

0 comments on commit 436698b

Please sign in to comment.