Skip to content

Commit

Permalink
Avoid breaking change: set_bind_group now takes Into<Option<...>>
Browse files Browse the repository at this point in the history
… rather than `Option<...>` (#6452)
  • Loading branch information
Wumpf authored Oct 23, 2024
1 parent a8c9356 commit e23146a
Show file tree
Hide file tree
Showing 41 changed files with 76 additions and 74 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ 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
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.
For convenience, the `set_bind_group` on compute/render passes & encoders takes `impl Into<Option<&BindGroup>>`,
so most code should still work the same.

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

Expand Down
2 changes: 1 addition & 1 deletion 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, Some(&self.bind_groups[dispatch_idx]), &[]);
compute_pass.set_bind_group(0, &self.bind_groups[dispatch_idx], &[]);
compute_pass.dispatch_workgroups(1, 1, 1);
}

Expand Down
2 changes: 1 addition & 1 deletion 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, Some(&self.bind_groups[draw_idx]), &[]);
render_pass.set_bind_group(0, &self.bind_groups[draw_idx], &[]);
for i in 0..VERTEX_BUFFERS_PER_DRAW {
render_pass.set_vertex_buffer(
i as u32,
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 @@ -292,7 +292,7 @@ impl crate::framework::Example for Example {
timestamp_writes: None,
});
cpass.set_pipeline(&self.compute_pipeline);
cpass.set_bind_group(0, Some(&self.particle_bind_groups[self.frame_num % 2]), &[]);
cpass.set_bind_group(0, &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, Some(&self.global_group), &[]);
rpass.set_bind_group(0, &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, Some(&self.local_group), &[offset]);
rpass.set_bind_group(1, &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 @@ -296,7 +296,7 @@ impl crate::framework::Example for Example {
});

rpass.set_pipeline(&self.pipeline_upscale);
rpass.set_bind_group(0, Some(&self.bind_group_upscale), &[]);
rpass.set_bind_group(0, &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 @@ -358,7 +358,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, Some(&self.bind_group), &[]);
rpass.set_bind_group(0, &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 @@ -132,7 +132,7 @@ async fn execute_gpu_inner(
timestamp_writes: None,
});
cpass.set_pipeline(&compute_pipeline);
cpass.set_bind_group(0, Some(&bind_group), &[]);
cpass.set_bind_group(0, &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 @@ -125,7 +125,7 @@ async fn execute(
timestamp_writes: None,
});
compute_pass.set_pipeline(&patient_pipeline);
compute_pass.set_bind_group(0, Some(&bind_group), &[]);
compute_pass.set_bind_group(0, &bind_group, &[]);
compute_pass.dispatch_workgroups(local_patient_workgroup_results.len() as u32, 1, 1);
}
queue.submit(Some(command_encoder.finish()));
Expand All @@ -147,7 +147,7 @@ async fn execute(
timestamp_writes: None,
});
compute_pass.set_pipeline(&hasty_pipeline);
compute_pass.set_bind_group(0, Some(&bind_group), &[]);
compute_pass.set_bind_group(0, &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 @@ -124,7 +124,7 @@ async fn run() {
timestamp_writes: None,
});
compute_pass.set_pipeline(&pipeline);
compute_pass.set_bind_group(0, Some(&bind_group), &[]);
compute_pass.set_bind_group(0, &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 @@ -177,7 +177,7 @@ impl Example {
);
}
rpass.set_pipeline(&pipeline);
rpass.set_bind_group(0, Some(&bind_group), &[]);
rpass.set_bind_group(0, &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 @@ -491,7 +491,7 @@ impl crate::framework::Example for Example {
occlusion_query_set: None,
});
rpass.set_pipeline(&self.draw_pipeline);
rpass.set_bind_group(0, Some(&self.bind_group), &[]);
rpass.set_bind_group(0, &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, Some(&context.bind_group), &[]);
compute_pass.set_bind_group(0, &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 @@ -776,10 +776,10 @@ impl crate::framework::Example for Example {
occlusion_query_set: None,
});
pass.set_pipeline(&self.shadow_pass.pipeline);
pass.set_bind_group(0, Some(&self.shadow_pass.bind_group), &[]);
pass.set_bind_group(0, &self.shadow_pass.bind_group, &[]);

for entity in &self.entities {
pass.set_bind_group(1, Some(&self.entity_bind_group), &[entity.uniform_offset]);
pass.set_bind_group(1, &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 @@ -820,10 +820,10 @@ impl crate::framework::Example for Example {
occlusion_query_set: None,
});
pass.set_pipeline(&self.forward_pass.pipeline);
pass.set_bind_group(0, Some(&self.forward_pass.bind_group), &[]);
pass.set_bind_group(0, &self.forward_pass.bind_group, &[]);

for entity in &self.entities {
pass.set_bind_group(1, Some(&self.entity_bind_group), &[entity.uniform_offset]);
pass.set_bind_group(1, &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 @@ -448,7 +448,7 @@ impl crate::framework::Example for Example {
occlusion_query_set: None,
});

rpass.set_bind_group(0, Some(&self.bind_group), &[]);
rpass.set_bind_group(0, &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 @@ -199,7 +199,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, Some(&self.bind_group), &[]);
rpass.set_bind_group(0, &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 @@ -114,7 +114,7 @@ async fn run(_path: Option<String>) {
label: None,
timestamp_writes: None,
});
compute_pass.set_bind_group(0, Some(&bind_group), &[]);
compute_pass.set_bind_group(0, &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, Some(&self.bind_group), &[0]);
rpass.set_bind_group(0, &self.bind_group, &[0]);
rpass.draw_indexed(0..6, 0, 0..1);
rpass.set_bind_group(0, Some(&self.bind_group), &[256]);
rpass.set_bind_group(0, &self.bind_group, &[256]);
rpass.draw_indexed(6..12, 0, 0..1);
} else {
rpass.set_bind_group(0, Some(&self.bind_group), &[0]);
rpass.set_bind_group(0, &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 @@ -321,7 +321,7 @@ fn compute_pass(
});
*next_unused_query += 2;
cpass.set_pipeline(&compute_pipeline);
cpass.set_bind_group(0, Some(&bind_group), &[]);
cpass.set_bind_group(0, &bind_group, &[]);
cpass.dispatch_workgroups(1, 1, 1);
if device
.features()
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 @@ -624,7 +624,7 @@ impl crate::framework::Example for Example {
multiview: None,
});
encoder.set_pipeline(&terrain_pipeline);
encoder.set_bind_group(0, Some(&terrain_flipped_bind_group), &[]);
encoder.set_bind_group(0, &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 @@ -778,7 +778,7 @@ impl crate::framework::Example for Example {
occlusion_query_set: None,
});
rpass.set_pipeline(&self.terrain_pipeline);
rpass.set_bind_group(0, Some(&self.terrain_normal_bind_group), &[]);
rpass.set_bind_group(0, &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 @@ -805,7 +805,7 @@ impl crate::framework::Example for Example {
});

rpass.set_pipeline(&self.water_pipeline);
rpass.set_bind_group(0, Some(&self.water_bind_group), &[]);
rpass.set_bind_group(0, &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 tests/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ fn copy_via_compute(
let mut pass = encoder.begin_compute_pass(&ComputePassDescriptor::default());

pass.set_pipeline(&pipeline_copy);
pass.set_bind_group(0, Some(&bg), &[]);
pass.set_bind_group(0, &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, Some(&bg), &[]);
pass.set_bind_group(0, &bg, &[]);
pass.set_pipeline(&pipeline);
pass.dispatch_workgroups(256, 256, 1);
}
Expand Down
18 changes: 9 additions & 9 deletions tests/tests/bind_group_layout_dedup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ async fn bgl_dedupe(ctx: TestingContext) {
timestamp_writes: None,
});

pass.set_bind_group(0, Some(&bg_1b), &[]);
pass.set_bind_group(0, &bg_1b, &[]);
pass.set_pipeline(&pipeline);
pass.dispatch_workgroups(1, 1, 1);

pass.set_bind_group(0, Some(&bg_1a), &[]);
pass.set_bind_group(0, &bg_1a, &[]);
pass.dispatch_workgroups(1, 1, 1);

drop(pass);
Expand Down Expand Up @@ -179,7 +179,7 @@ fn bgl_dedupe_with_dropped_user_handle(ctx: TestingContext) {
timestamp_writes: None,
});

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

Expand Down Expand Up @@ -250,10 +250,10 @@ fn get_derived_bgl(ctx: TestingContext) {

pass.set_pipeline(&pipeline);

pass.set_bind_group(0, Some(&bg1), &[]);
pass.set_bind_group(0, &bg1, &[]);
pass.dispatch_workgroups(1, 1, 1);

pass.set_bind_group(0, Some(&bg2), &[]);
pass.set_bind_group(0, &bg2, &[]);
pass.dispatch_workgroups(1, 1, 1);

drop(pass);
Expand Down Expand Up @@ -313,7 +313,7 @@ fn separate_pipelines_have_incompatible_derived_bgls(ctx: TestingContext) {
pass.set_pipeline(&pipeline1);

// We use the wrong bind group for this pipeline here. This should fail.
pass.set_bind_group(0, Some(&bg2), &[]);
pass.set_bind_group(0, &bg2, &[]);
pass.dispatch_workgroups(1, 1, 1);

fail(
Expand Down Expand Up @@ -385,7 +385,7 @@ fn derived_bgls_incompatible_with_regular_bgls(ctx: TestingContext) {

pass.set_pipeline(&pipeline);

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

fail(
Expand Down Expand Up @@ -476,8 +476,8 @@ fn bgl_dedupe_derived(ctx: TestingContext) {
timestamp_writes: None,
});
pass.set_pipeline(&pipeline);
pass.set_bind_group(0, Some(&bind_group_0), &[]);
pass.set_bind_group(1, Some(&bind_group_1), &[]);
pass.set_bind_group(0, &bind_group_0, &[]);
pass.set_bind_group(1, &bind_group_1, &[]);
pass.dispatch_workgroups(1, 1, 1);

drop(pass);
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ static MINIMUM_BUFFER_BINDING_SIZE_DISPATCH: GpuTestConfiguration = GpuTestConfi
timestamp_writes: None,
});

pass.set_bind_group(0, Some(&bind_group), &[]);
pass.set_bind_group(0, &bind_group, &[]);
pass.set_pipeline(&pipeline);
pass.dispatch_workgroups(1, 1, 1);

Expand Down
8 changes: 4 additions & 4 deletions tests/tests/compute_pass_ownership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn compute_pass_resource_ownership(ctx: TestingContext) {
{
let mut cpass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor::default());
cpass.set_pipeline(&pipeline);
cpass.set_bind_group(0, Some(&bind_group), &[]);
cpass.set_bind_group(0, &bind_group, &[]);
cpass.dispatch_workgroups_indirect(&indirect_buffer, 0);

// Now drop all resources we set. Then do a device poll to make sure the resources are really not dropped too early, no matter what.
Expand Down Expand Up @@ -95,7 +95,7 @@ async fn compute_pass_query_set_ownership_pipeline_statistics(ctx: TestingContex
{
let mut cpass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor::default());
cpass.set_pipeline(&pipeline);
cpass.set_bind_group(0, Some(&bind_group), &[]);
cpass.set_bind_group(0, &bind_group, &[]);
cpass.begin_pipeline_statistics_query(&query_set, 0);
cpass.dispatch_workgroups(1, 1, 1);
cpass.end_pipeline_statistics_query();
Expand Down Expand Up @@ -153,7 +153,7 @@ async fn compute_pass_query_set_ownership_timestamps(ctx: TestingContext) {
}),
});
cpass.set_pipeline(&pipeline);
cpass.set_bind_group(0, Some(&bind_group), &[]);
cpass.set_bind_group(0, &bind_group, &[]);
cpass.write_timestamp(&query_set_write_timestamp, 0);
cpass.dispatch_workgroups(1, 1, 1);

Expand Down Expand Up @@ -203,7 +203,7 @@ async fn compute_pass_keep_encoder_alive(ctx: TestingContext) {

// Record some draw commands.
cpass.set_pipeline(&pipeline);
cpass.set_bind_group(0, Some(&bind_group), &[]);
cpass.set_bind_group(0, &bind_group, &[]);
cpass.dispatch_workgroups_indirect(&indirect_buffer, 0);

// Dropping the pass will still execute the pass, even though there's no way to submit it.
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/dispatch_workgroups_indirect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static RESET_BIND_GROUPS: GpuTestConfiguration = GpuTestConfiguration::new()
let mut compute_pass = encoder.begin_compute_pass(&Default::default());
compute_pass.set_pipeline(&test_resources.pipeline);
compute_pass.set_push_constants(0, &[0, 0, 0, 0]);
// compute_pass.set_bind_group(0, Some(&test_resources.bind_group), &[]);
// compute_pass.set_bind_group(0, &test_resources.bind_group, &[]);
compute_pass.dispatch_workgroups_indirect(&indirect_buffer, 0);
}
ctx.queue.submit(Some(encoder.finish()));
Expand Down Expand Up @@ -124,7 +124,7 @@ static ZERO_SIZED_BUFFER: GpuTestConfiguration = GpuTestConfiguration::new()
let mut compute_pass = encoder.begin_compute_pass(&Default::default());
compute_pass.set_pipeline(&test_resources.pipeline);
compute_pass.set_push_constants(0, &[0, 0, 0, 0]);
compute_pass.set_bind_group(0, Some(&test_resources.bind_group), &[]);
compute_pass.set_bind_group(0, &test_resources.bind_group, &[]);
compute_pass.dispatch_workgroups_indirect(&indirect_buffer, 0);
}
ctx.queue.submit(Some(encoder.finish()));
Expand Down Expand Up @@ -281,7 +281,7 @@ async fn run_test(ctx: &TestingContext, num_workgroups: &[u32; 3]) -> [u32; 3] {
let mut compute_pass = encoder.begin_compute_pass(&Default::default());
compute_pass.set_pipeline(&test_resources.pipeline);
compute_pass.set_push_constants(0, &[0, 0, 0, 0]);
compute_pass.set_bind_group(0, Some(&test_resources.bind_group), &[]);
compute_pass.set_bind_group(0, &test_resources.bind_group, &[]);
compute_pass.dispatch_workgroups_indirect(&indirect_buffer, indirect_offset);
}

Expand Down
Loading

0 comments on commit e23146a

Please sign in to comment.