From 8d766f6f735e8775272c251c9e468ff795c19c7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20S=C3=B8holm?= Date: Fri, 3 Apr 2026 03:01:28 +0200 Subject: [PATCH] Fix validation for bindings with different sizes (#9341) --- tests/tests/wgpu-gpu/bind_groups.rs | 3 +- wgpu-core/src/command/bind.rs | 61 ++++++++++++++++------------- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/tests/tests/wgpu-gpu/bind_groups.rs b/tests/tests/wgpu-gpu/bind_groups.rs index 51512629a..efc35011d 100644 --- a/tests/tests/wgpu-gpu/bind_groups.rs +++ b/tests/tests/wgpu-gpu/bind_groups.rs @@ -176,8 +176,7 @@ static MULTIPLE_BINDINGS_WITH_DIFFERENT_SIZES: GpuTestConfiguration = GpuTestCon .parameters( TestParameters::default() .limits(wgpu::Limits::downlevel_defaults()) - .expect_fail(FailureCase::always()) - .enable_noop(), // https://github.com/gfx-rs/wgpu/issues/7359 + .enable_noop(), ) .run_sync(multiple_bindings_with_differing_sizes); diff --git a/wgpu-core/src/command/bind.rs b/wgpu-core/src/command/bind.rs index f85c5ca92..c07339345 100644 --- a/wgpu-core/src/command/bind.rs +++ b/wgpu-core/src/command/bind.rs @@ -349,6 +349,8 @@ impl Binder { new: &Arc, late_sized_buffer_groups: &[LateSizedBufferGroup], ) -> bool { + self.update_late_buffer_bindings(late_sized_buffer_groups); + if let Some(old) = self.pipeline_layout.as_ref() { if old.is_equal(new) { return false; @@ -359,33 +361,6 @@ impl Binder { self.manager.update_expectations(&new.bind_group_layouts); - // Update the buffer binding sizes that are required by shaders. - - for (payload, late_group) in self.payloads.iter_mut().zip(late_sized_buffer_groups) { - payload.late_bindings_effective_count = late_group.shader_sizes.len(); - // Update entries that already exist as the bind group was bound before the pipeline - // was bound. - for (late_binding, &shader_expect_size) in payload - .late_buffer_bindings - .iter_mut() - .zip(late_group.shader_sizes.iter()) - { - late_binding.shader_expect_size = shader_expect_size; - } - // Add new entries for the bindings that were not known when the bind group was bound. - if late_group.shader_sizes.len() > payload.late_buffer_bindings.len() { - for &shader_expect_size in - late_group.shader_sizes[payload.late_buffer_bindings.len()..].iter() - { - payload.late_buffer_bindings.push(LateBufferBinding { - binding_index: 0, - shader_expect_size, - bound_size: 0, - }); - } - } - } - if let Some(old) = old { // root constants are the base compatibility property if old.immediate_size != new.immediate_size { @@ -524,4 +499,36 @@ impl Binder { } Ok(()) } + + /// This must be called even when a new pipeline has the same layout + /// as the previous one, because different pipelines can have different + /// shader-expected buffer sizes even with identical layouts. + fn update_late_buffer_bindings(&mut self, late_sized_buffer_groups: &[LateSizedBufferGroup]) { + for (payload, late_group) in self.payloads.iter_mut().zip(late_sized_buffer_groups) { + payload.late_bindings_effective_count = late_group.shader_sizes.len(); + + // Update entries that already exist as the bind group was bound before the pipeline + // was bound. + for (late_binding, &shader_expect_size) in payload + .late_buffer_bindings + .iter_mut() + .zip(late_group.shader_sizes.iter()) + { + late_binding.shader_expect_size = shader_expect_size; + } + + // Add new entries for the bindings that were not known when the bind group was bound. + if late_group.shader_sizes.len() > payload.late_buffer_bindings.len() { + for &shader_expect_size in + late_group.shader_sizes[payload.late_buffer_bindings.len()..].iter() + { + payload.late_buffer_bindings.push(LateBufferBinding { + binding_index: 0, + shader_expect_size, + bound_size: 0, + }); + } + } + } + } }