diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 95ff7b506f..efdd79e059 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -473,6 +473,7 @@ pub struct BindGroupLayoutInner { } impl BindGroupLayout { + #[track_caller] pub(crate) fn assume_deduplicated(&self) -> &BindGroupLayoutInner { self.as_inner().unwrap() } diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index b8817146a2..e592d113ba 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -1924,7 +1924,24 @@ impl Global { None => break binding_model::GetBindGroupLayoutError::InvalidGroupIndex(index), }; - bgl_guard[*id].multi_ref_count.inc(); + let layout = &bgl_guard[*id]; + layout.multi_ref_count.inc(); + + if G::ids_are_generated_in_wgpu() { + return (id.0, None); + } + + // The ID is provided externally, so we must create a new bind group layout + // with the given ID as a duplicate of the existing one. + let new_layout = BindGroupLayout { + device_id: layout.device_id.clone(), + inner: crate::binding_model::BglOrDuplicate::::Duplicate(*id), + multi_ref_count: crate::MultiRefCount::new(), + }; + + let fid = hub.bind_group_layouts.prepare(id_in); + let id = fid.assign(new_layout, &mut Token::root()); + return (id.0, None); };