Skip to content

Commit

Permalink
Make bind group an Option for set_bind_group calls. (#6216)
Browse files Browse the repository at this point in the history
This is just an API change for all the "set_bind_group" calls. Calls
that pass a Some() argument should have unchanged behavior. The None
cases are left as TODOs.
  • Loading branch information
bradwerth authored Sep 6, 2024
1 parent c87717b commit 9b36a3e
Show file tree
Hide file tree
Showing 59 changed files with 283 additions and 169 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ traits that have now been implemented for `wgpu` resources.

By @teoxoy [#6134](https://github.com/gfx-rs/wgpu/pull/6134).

#### `set_bind_group` now takes an `Option` for the bind group argument.

https://gpuweb.github.io/gpuweb/#programmable-passes-bind-groups specifies that bindGroup
is nullable. This change is the start of implementing this part of the spec. Callers that
specify a `Some()` value should have unchanged behavior. Handling of `None` values still
needs to be implemented by backends.

By @bradwerth [#6216](https://github.com/gfx-rs/wgpu/pull/6216).

### New Features

#### Naga
Expand Down
4 changes: 2 additions & 2 deletions benches/benches/computepass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ impl ComputepassState {
let end_idx = start_idx + dispatch_per_pass;
for dispatch_idx in start_idx..end_idx {
compute_pass.set_pipeline(&self.pipeline);
compute_pass.set_bind_group(0, &self.bind_groups[dispatch_idx], &[]);
compute_pass.set_bind_group(0, Some(&self.bind_groups[dispatch_idx]), &[]);
compute_pass.dispatch_workgroups(1, 1, 1);
}

Expand All @@ -412,7 +412,7 @@ impl ComputepassState {
});

compute_pass.set_pipeline(self.bindless_pipeline.as_ref().unwrap());
compute_pass.set_bind_group(0, self.bindless_bind_group.as_ref().unwrap(), &[]);
compute_pass.set_bind_group(0, Some(self.bindless_bind_group.as_ref().unwrap()), &[]);
for _ in 0..dispatch_count_bindless {
compute_pass.dispatch_workgroups(1, 1, 1);
}
Expand Down
4 changes: 2 additions & 2 deletions benches/benches/renderpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ impl RenderpassState {
let end_idx = start_idx + draws_per_pass;
for draw_idx in start_idx..end_idx {
render_pass.set_pipeline(&self.pipeline);
render_pass.set_bind_group(0, &self.bind_groups[draw_idx], &[]);
render_pass.set_bind_group(0, Some(&self.bind_groups[draw_idx]), &[]);
for i in 0..VERTEX_BUFFERS_PER_DRAW {
render_pass.set_vertex_buffer(
i as u32,
Expand Down Expand Up @@ -410,7 +410,7 @@ impl RenderpassState {
});

render_pass.set_pipeline(self.bindless_pipeline.as_ref().unwrap());
render_pass.set_bind_group(0, self.bindless_bind_group.as_ref().unwrap(), &[]);
render_pass.set_bind_group(0, Some(self.bindless_bind_group.as_ref().unwrap()), &[]);
for i in 0..VERTEX_BUFFERS_PER_DRAW {
render_pass.set_vertex_buffer(i as u32, self.vertex_buffers[0].slice(..));
}
Expand Down
2 changes: 1 addition & 1 deletion deno_webgpu/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub fn op_webgpu_render_bundle_encoder_set_bind_group(
wgpu_core::command::bundle_ffi::wgpu_render_bundle_set_bind_group(
&mut render_bundle_encoder_resource.0.borrow_mut(),
index,
bind_group_resource.1,
Some(bind_group_resource.1),
dynamic_offsets_data.as_ptr(),
dynamic_offsets_data.len(),
);
Expand Down
2 changes: 1 addition & 1 deletion deno_webgpu/compute_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub fn op_webgpu_compute_pass_set_bind_group(
.compute_pass_set_bind_group(
&mut compute_pass_resource.0.borrow_mut(),
index,
bind_group_resource.1,
Some(bind_group_resource.1),
dynamic_offsets_data,
)?;

Expand Down
2 changes: 1 addition & 1 deletion deno_webgpu/render_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ pub fn op_webgpu_render_pass_set_bind_group(
.render_pass_set_bind_group(
&mut render_pass_resource.0.borrow_mut(),
index,
bind_group_resource.1,
Some(bind_group_resource.1),
dynamic_offsets_data,
)?;

Expand Down
2 changes: 1 addition & 1 deletion examples/src/boids/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl crate::framework::Example for Example {
timestamp_writes: None,
});
cpass.set_pipeline(&self.compute_pipeline);
cpass.set_bind_group(0, &self.particle_bind_groups[self.frame_num % 2], &[]);
cpass.set_bind_group(0, Some(&self.particle_bind_groups[self.frame_num % 2]), &[]);
cpass.dispatch_workgroups(self.work_group_count, 1, 1);
}
command_encoder.pop_debug_group();
Expand Down
4 changes: 2 additions & 2 deletions examples/src/bunnymark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ impl Example {
occlusion_query_set: None,
});
rpass.set_pipeline(&self.pipeline);
rpass.set_bind_group(0, &self.global_group, &[]);
rpass.set_bind_group(0, Some(&self.global_group), &[]);
for i in 0..self.bunnies.len() {
let offset =
(i as wgpu::DynamicOffset) * (uniform_alignment as wgpu::DynamicOffset);
rpass.set_bind_group(1, &self.local_group, &[offset]);
rpass.set_bind_group(1, Some(&self.local_group), &[offset]);
rpass.draw(0..4, 0..1);
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/src/conservative_raster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl crate::framework::Example for Example {
});

rpass.set_pipeline(&self.pipeline_upscale);
rpass.set_bind_group(0, &self.bind_group_upscale, &[]);
rpass.set_bind_group(0, Some(&self.bind_group_upscale), &[]);
rpass.draw(0..3, 0..1);

if let Some(pipeline_lines) = &self.pipeline_lines {
Expand Down
2 changes: 1 addition & 1 deletion examples/src/cube/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ impl crate::framework::Example for Example {
});
rpass.push_debug_group("Prepare data for draw.");
rpass.set_pipeline(&self.pipeline);
rpass.set_bind_group(0, &self.bind_group, &[]);
rpass.set_bind_group(0, Some(&self.bind_group), &[]);
rpass.set_index_buffer(self.index_buf.slice(..), wgpu::IndexFormat::Uint16);
rpass.set_vertex_buffer(0, self.vertex_buf.slice(..));
rpass.pop_debug_group();
Expand Down
2 changes: 1 addition & 1 deletion examples/src/hello_compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async fn execute_gpu_inner(
timestamp_writes: None,
});
cpass.set_pipeline(&compute_pipeline);
cpass.set_bind_group(0, &bind_group, &[]);
cpass.set_bind_group(0, Some(&bind_group), &[]);
cpass.insert_debug_marker("compute collatz iterations");
cpass.dispatch_workgroups(numbers.len() as u32, 1, 1); // Number of cells to run, the (x,y,z) size of item being processed
}
Expand Down
4 changes: 2 additions & 2 deletions examples/src/hello_synchronization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async fn execute(
timestamp_writes: None,
});
compute_pass.set_pipeline(&patient_pipeline);
compute_pass.set_bind_group(0, &bind_group, &[]);
compute_pass.set_bind_group(0, Some(&bind_group), &[]);
compute_pass.dispatch_workgroups(local_patient_workgroup_results.len() as u32, 1, 1);
}
queue.submit(Some(command_encoder.finish()));
Expand All @@ -150,7 +150,7 @@ async fn execute(
timestamp_writes: None,
});
compute_pass.set_pipeline(&hasty_pipeline);
compute_pass.set_bind_group(0, &bind_group, &[]);
compute_pass.set_bind_group(0, Some(&bind_group), &[]);
compute_pass.dispatch_workgroups(local_patient_workgroup_results.len() as u32, 1, 1);
}
queue.submit(Some(command_encoder.finish()));
Expand Down
2 changes: 1 addition & 1 deletion examples/src/hello_workgroups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ async fn run() {
timestamp_writes: None,
});
compute_pass.set_pipeline(&pipeline);
compute_pass.set_bind_group(0, &bind_group, &[]);
compute_pass.set_bind_group(0, Some(&bind_group), &[]);
/* Note that since each workgroup will cover both arrays, we only need to
cover the length of one array. */
compute_pass.dispatch_workgroups(local_a.len() as u32, 1, 1);
Expand Down
4 changes: 2 additions & 2 deletions examples/src/mipmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl Example {
);
}
rpass.set_pipeline(&pipeline);
rpass.set_bind_group(0, &bind_group, &[]);
rpass.set_bind_group(0, Some(&bind_group), &[]);
rpass.draw(0..3, 0..1);
if let Some(ref query_sets) = query_sets {
rpass.write_timestamp(&query_sets.timestamp, timestamp_query_index_base + 1);
Expand Down Expand Up @@ -497,7 +497,7 @@ impl crate::framework::Example for Example {
occlusion_query_set: None,
});
rpass.set_pipeline(&self.draw_pipeline);
rpass.set_bind_group(0, &self.bind_group, &[]);
rpass.set_bind_group(0, Some(&self.bind_group), &[]);
rpass.draw(0..4, 0..1);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/src/repeated_compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async fn compute(local_buffer: &mut [u32], context: &WgpuContext) {
timestamp_writes: None,
});
compute_pass.set_pipeline(&context.pipeline);
compute_pass.set_bind_group(0, &context.bind_group, &[]);
compute_pass.set_bind_group(0, Some(&context.bind_group), &[]);
compute_pass.dispatch_workgroups(local_buffer.len() as u32, 1, 1);
}
// We finish the compute pass by dropping it.
Expand Down
8 changes: 4 additions & 4 deletions examples/src/shadow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,10 +779,10 @@ impl crate::framework::Example for Example {
occlusion_query_set: None,
});
pass.set_pipeline(&self.shadow_pass.pipeline);
pass.set_bind_group(0, &self.shadow_pass.bind_group, &[]);
pass.set_bind_group(0, Some(&self.shadow_pass.bind_group), &[]);

for entity in &self.entities {
pass.set_bind_group(1, &self.entity_bind_group, &[entity.uniform_offset]);
pass.set_bind_group(1, Some(&self.entity_bind_group), &[entity.uniform_offset]);
pass.set_index_buffer(entity.index_buf.slice(..), entity.index_format);
pass.set_vertex_buffer(0, entity.vertex_buf.slice(..));
pass.draw_indexed(0..entity.index_count as u32, 0, 0..1);
Expand Down Expand Up @@ -823,10 +823,10 @@ impl crate::framework::Example for Example {
occlusion_query_set: None,
});
pass.set_pipeline(&self.forward_pass.pipeline);
pass.set_bind_group(0, &self.forward_pass.bind_group, &[]);
pass.set_bind_group(0, Some(&self.forward_pass.bind_group), &[]);

for entity in &self.entities {
pass.set_bind_group(1, &self.entity_bind_group, &[entity.uniform_offset]);
pass.set_bind_group(1, Some(&self.entity_bind_group), &[entity.uniform_offset]);
pass.set_index_buffer(entity.index_buf.slice(..), entity.index_format);
pass.set_vertex_buffer(0, entity.vertex_buf.slice(..));
pass.draw_indexed(0..entity.index_count as u32, 0, 0..1);
Expand Down
2 changes: 1 addition & 1 deletion examples/src/skybox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ impl crate::framework::Example for Example {
occlusion_query_set: None,
});

rpass.set_bind_group(0, &self.bind_group, &[]);
rpass.set_bind_group(0, Some(&self.bind_group), &[]);
rpass.set_pipeline(&self.entity_pipeline);

for entity in self.entities.iter() {
Expand Down
2 changes: 1 addition & 1 deletion examples/src/srgb_blend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl<const SRGB: bool> crate::framework::Example for Example<SRGB> {
});
rpass.push_debug_group("Prepare data for draw.");
rpass.set_pipeline(&self.pipeline);
rpass.set_bind_group(0, &self.bind_group, &[]);
rpass.set_bind_group(0, Some(&self.bind_group), &[]);
rpass.set_index_buffer(self.index_buf.slice(..), wgpu::IndexFormat::Uint16);
rpass.set_vertex_buffer(0, self.vertex_buf.slice(..));
rpass.pop_debug_group();
Expand Down
2 changes: 1 addition & 1 deletion examples/src/storage_texture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async fn run(_path: Option<String>) {
label: None,
timestamp_writes: None,
});
compute_pass.set_bind_group(0, &bind_group, &[]);
compute_pass.set_bind_group(0, Some(&bind_group), &[]);
compute_pass.set_pipeline(&pipeline);
compute_pass.dispatch_workgroups(TEXTURE_DIMS.0 as u32, TEXTURE_DIMS.1 as u32, 1);
}
Expand Down
6 changes: 3 additions & 3 deletions examples/src/texture_arrays/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,12 @@ impl crate::framework::Example for Example {
rpass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
rpass.set_index_buffer(self.index_buffer.slice(..), self.index_format);
if self.uniform_workaround {
rpass.set_bind_group(0, &self.bind_group, &[0]);
rpass.set_bind_group(0, Some(&self.bind_group), &[0]);
rpass.draw_indexed(0..6, 0, 0..1);
rpass.set_bind_group(0, &self.bind_group, &[256]);
rpass.set_bind_group(0, Some(&self.bind_group), &[256]);
rpass.draw_indexed(6..12, 0, 0..1);
} else {
rpass.set_bind_group(0, &self.bind_group, &[0]);
rpass.set_bind_group(0, Some(&self.bind_group), &[0]);
rpass.draw_indexed(0..12, 0, 0..1);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/src/timestamp_queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ fn compute_pass(
});
*next_unused_query += 2;
cpass.set_pipeline(&compute_pipeline);
cpass.set_bind_group(0, &bind_group, &[]);
cpass.set_bind_group(0, Some(&bind_group), &[]);
cpass.dispatch_workgroups(1, 1, 1);
if device
.features()
Expand Down
6 changes: 5 additions & 1 deletion examples/src/uniform_values/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,11 @@ async fn run(event_loop: EventLoop<()>, window: Arc<Window>) {
});
render_pass.set_pipeline(&wgpu_context_ref.pipeline);
// (9)
render_pass.set_bind_group(0, &wgpu_context_ref.bind_group, &[]);
render_pass.set_bind_group(
0,
Some(&wgpu_context_ref.bind_group),
&[],
);
render_pass.draw(0..3, 0..1);
}
wgpu_context_ref.queue.submit(Some(encoder.finish()));
Expand Down
6 changes: 3 additions & 3 deletions examples/src/water/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ impl crate::framework::Example for Example {
multiview: None,
});
encoder.set_pipeline(&terrain_pipeline);
encoder.set_bind_group(0, &terrain_flipped_bind_group, &[]);
encoder.set_bind_group(0, Some(&terrain_flipped_bind_group), &[]);
encoder.set_vertex_buffer(0, terrain_vertex_buf.slice(..));
encoder.draw(0..terrain_vertices.len() as u32, 0..1);
encoder.finish(&wgpu::RenderBundleDescriptor::default())
Expand Down Expand Up @@ -784,7 +784,7 @@ impl crate::framework::Example for Example {
occlusion_query_set: None,
});
rpass.set_pipeline(&self.terrain_pipeline);
rpass.set_bind_group(0, &self.terrain_normal_bind_group, &[]);
rpass.set_bind_group(0, Some(&self.terrain_normal_bind_group), &[]);
rpass.set_vertex_buffer(0, self.terrain_vertex_buf.slice(..));
rpass.draw(0..self.terrain_vertex_count as u32, 0..1);
}
Expand All @@ -811,7 +811,7 @@ impl crate::framework::Example for Example {
});

rpass.set_pipeline(&self.water_pipeline);
rpass.set_bind_group(0, &self.water_bind_group, &[]);
rpass.set_bind_group(0, Some(&self.water_bind_group), &[]);
rpass.set_vertex_buffer(0, self.water_vertex_buf.slice(..));
rpass.draw(0..self.water_vertex_count as u32, 0..1);
}
Expand Down
2 changes: 1 addition & 1 deletion player/tests/data/bind-group.ron
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
SetBindGroup(
index: 0,
num_dynamic_offsets: 0,
bind_group_id: Id(0, 1, Empty),
bind_group_id: Some(Id(0, 1, Empty)),
),
SetPipeline(Id(0, 1, Empty)),
],
Expand Down
2 changes: 1 addition & 1 deletion player/tests/data/zero-init-buffer.ron
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
SetBindGroup(
index: 0,
num_dynamic_offsets: 0,
bind_group_id: Id(0, 1, Empty),
bind_group_id: Some(Id(0, 1, Empty)),
),
Dispatch((4, 1, 1)),
],
Expand Down
2 changes: 1 addition & 1 deletion player/tests/data/zero-init-texture-binding.ron
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
SetBindGroup(
index: 0,
num_dynamic_offsets: 0,
bind_group_id: Id(0, 1, Empty),
bind_group_id: Some(Id(0, 1, Empty)),
),
Dispatch((4, 1, 1)),
],
Expand Down
2 changes: 1 addition & 1 deletion tests/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ fn copy_via_compute(
let mut pass = encoder.begin_compute_pass(&ComputePassDescriptor::default());

pass.set_pipeline(&pipeline_copy);
pass.set_bind_group(0, &bg, &[]);
pass.set_bind_group(0, Some(&bg), &[]);
pass.dispatch_workgroups(1, 1, 1);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/tests/bgra8unorm_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static BGRA8_UNORM_STORAGE: GpuTestConfiguration = GpuTestConfiguration::new()
timestamp_writes: None,
});

pass.set_bind_group(0, &bg, &[]);
pass.set_bind_group(0, Some(&bg), &[]);
pass.set_pipeline(&pipeline);
pass.dispatch_workgroups(256, 256, 1);
}
Expand Down
Loading

0 comments on commit 9b36a3e

Please sign in to comment.