From 1d683f8b5319862bff14cc1d53dc1763f36be47a Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Wed, 5 Aug 2026 16:02:44 +0200 Subject: [PATCH] [core] Do not use IDs as default types in `BindGroupDescriptor` and `BindGroupEntry` Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- deno_webgpu/device.rs | 13 ++++---- player/src/lib.rs | 8 ++--- wgpu-core/src/binding_model.rs | 46 ++++++++-------------------- wgpu-core/src/device/global.rs | 30 ++++++++++++++---- wgpu-core/src/device/resource.rs | 4 +-- wgpu-core/src/device/trace/record.rs | 2 +- 6 files changed, 50 insertions(+), 53 deletions(-) diff --git a/deno_webgpu/device.rs b/deno_webgpu/device.rs index 97804855f..9cfab48cf 100644 --- a/deno_webgpu/device.rs +++ b/deno_webgpu/device.rs @@ -394,7 +394,7 @@ impl GPUDevice { let entries = descriptor .entries .into_iter() - .map(|entry| wgpu_core::binding_model::ResolvedBindGroupEntry { + .map(|entry| wgpu_core::binding_model::BindGroupEntry { binding: entry.binding, resource: match entry.resource { GPUBindingResource::Sampler(sampler) => { @@ -429,12 +429,11 @@ impl GPUDevice { }) .collect::>(); - let wgpu_descriptor = - wgpu_core::binding_model::ResolvedBindGroupDescriptor { - label: crate::transform_label(descriptor.label.clone()), - layout: descriptor.layout.wgpu_bind_group_layout.clone(), - entries: Cow::Owned(entries), - }; + let wgpu_descriptor = wgpu_core::binding_model::BindGroupDescriptor { + label: crate::transform_label(descriptor.label.clone()), + layout: descriptor.layout.wgpu_bind_group_layout.clone(), + entries: Cow::Owned(entries), + }; let (wgpu_bind_group, err) = self.wgpu_device.create_bind_group(&wgpu_descriptor); diff --git a/player/src/lib.rs b/player/src/lib.rs index 252d18d38..0017fdf10 100644 --- a/player/src/lib.rs +++ b/player/src/lib.rs @@ -707,10 +707,10 @@ impl Player { fn resolve_bind_group_descriptor<'a>( &self, desc: wgc::device::trace::TraceBindGroupDescriptor<'a>, - ) -> wgc::binding_model::ResolvedBindGroupDescriptor<'a> { + ) -> wgc::binding_model::BindGroupDescriptor<'a> { let layout = self.resolve_bind_group_layout_id(desc.layout); - let entries: Vec = desc + let entries: Vec = desc .entries .to_vec() .into_iter() @@ -794,14 +794,14 @@ impl Player { } }; - wgc::binding_model::ResolvedBindGroupEntry { + wgc::binding_model::BindGroupEntry { binding: entry.binding, resource, } }) .collect(); - wgc::binding_model::ResolvedBindGroupDescriptor { + wgc::binding_model::BindGroupDescriptor { label: desc.label.clone(), layout, entries: entries.into(), diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 2b73aae89..090ece6da 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -20,7 +20,7 @@ use wgt::error::{ErrorType, WebGpuError}; use crate::{ api_log, device::{bgl, Device, DeviceError, MissingDownlevelFlags, MissingFeatures}, - id::{BindGroupLayoutId, BufferId, ExternalTextureId, SamplerId, TextureViewId, TlasId}, + id::{BufferId, ExternalTextureId, SamplerId, TextureViewId, TlasId}, init_tracker::{BufferInitTrackerAction, TextureInitTrackerAction}, pipeline::{ComputePipeline, RenderPipeline}, resource::{ @@ -645,11 +645,11 @@ impl BindingTypeMaxCountValidator { #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct BindGroupEntry< 'a, - B = BufferId, - S = SamplerId, - TV = TextureViewId, - TLAS = TlasId, - ET = ExternalTextureId, + B = Arc, + S = Arc, + TV = Arc, + TLAS = Arc, + ET = Arc, > where [BufferBinding]: ToOwned, [S]: ToOwned, @@ -671,27 +671,18 @@ pub struct BindGroupEntry< pub resource: BindingResource<'a, B, S, TV, TLAS, ET>, } -/// cbindgen:ignore -pub type ResolvedBindGroupEntry<'a> = BindGroupEntry< - 'a, - Arc, - Arc, - Arc, - Arc, - Arc, ->; - /// Describes a group of bindings and the resources to be bound. #[derive(Clone, Debug)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +/// cbindgen:ignore pub struct BindGroupDescriptor< 'a, - BGL = BindGroupLayoutId, - B = BufferId, - S = SamplerId, - TV = TextureViewId, - TLAS = TlasId, - ET = ExternalTextureId, + BGL = Arc, + B = Arc, + S = Arc, + TV = Arc, + TLAS = Arc, + ET = Arc, > where [BufferBinding]: ToOwned, [S]: ToOwned, @@ -721,17 +712,6 @@ pub struct BindGroupDescriptor< pub entries: Cow<'a, [BindGroupEntry<'a, B, S, TV, TLAS, ET>]>, } -/// cbindgen:ignore -pub type ResolvedBindGroupDescriptor<'a> = BindGroupDescriptor< - 'a, - Arc, - Arc, - Arc, - Arc, - Arc, - Arc, ->; - /// Describes a [`BindGroupLayout`]. #[derive(Clone, Debug)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index 927c15152..62b3331a7 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -5,8 +5,7 @@ use core::ptr::NonNull; use crate::device::trace; use crate::{ binding_model::{ - self, BindGroupEntry, BindingResource, BufferBinding, ResolvedBindGroupDescriptor, - ResolvedBindGroupEntry, ResolvedBindingResource, ResolvedBufferBinding, + self, BindingResource, BufferBinding, ResolvedBindingResource, ResolvedBufferBinding, }, command, device::{life::WaitIdleError, DeviceError, DeviceLostClosure}, @@ -28,6 +27,25 @@ use crate::{ use wgt::{BufferAddress, TextureFormat}; +pub type BindGroupDescriptor<'a> = binding_model::BindGroupDescriptor< + 'a, + id::BindGroupLayoutId, + id::BufferId, + id::SamplerId, + id::TextureViewId, + id::TlasId, + id::ExternalTextureId, +>; + +pub type BindGroupEntry<'a> = binding_model::BindGroupEntry< + 'a, + id::BufferId, + id::SamplerId, + id::TextureViewId, + id::TlasId, + id::ExternalTextureId, +>; + impl Global { pub fn adapter_is_surface_supported( &self, @@ -493,7 +511,7 @@ impl Global { pub fn device_create_bind_group( &self, device_id: DeviceId, - desc: &binding_model::BindGroupDescriptor, + desc: &BindGroupDescriptor, id_in: Option, ) -> (id::BindGroupId, Option) { let hub = &self.hub; @@ -510,7 +528,7 @@ impl Global { texture_view_storage: &Storage>, tlas_storage: &Storage>, external_texture_storage: &Storage>, - ) -> ResolvedBindGroupEntry<'a> { + ) -> binding_model::BindGroupEntry<'a> { let resolve_buffer = |bb: &BufferBinding| { let buffer = buffer_storage.get(bb.buffer); ResolvedBufferBinding { @@ -557,7 +575,7 @@ impl Global { ResolvedBindingResource::ExternalTexture(resolve_external_texture(et)) } }; - ResolvedBindGroupEntry { + binding_model::BindGroupEntry { binding: e.binding, resource, } @@ -585,7 +603,7 @@ impl Global { }; let entries = Cow::Owned(entries); - let desc = ResolvedBindGroupDescriptor { + let desc = binding_model::BindGroupDescriptor { label: desc.label.clone(), layout, entries, diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 5b6682040..c5e34b0f4 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -3585,7 +3585,7 @@ impl Device { pub fn create_bind_group( self: &Arc, - desc: &binding_model::ResolvedBindGroupDescriptor, + desc: &binding_model::BindGroupDescriptor, ) -> (Arc, Option) { profiling::scope!("Device::create_bind_group"); #[cfg(feature = "trace")] @@ -3619,7 +3619,7 @@ impl Device { // (not passing a duplicate) beforehand. pub fn create_bind_group_inner( self: &Arc, - desc: &binding_model::ResolvedBindGroupDescriptor, + desc: &binding_model::BindGroupDescriptor, ) -> Result, CreateBindGroupError> { use crate::binding_model::{CreateBindGroupError as Error, ResolvedBindingResource as Br}; diff --git a/wgpu-core/src/device/trace/record.rs b/wgpu-core/src/device/trace/record.rs index 44452ea75..21c00d1f0 100644 --- a/wgpu-core/src/device/trace/record.rs +++ b/wgpu-core/src/device/trace/record.rs @@ -672,7 +672,7 @@ impl IntoTrace for crate::binding_model::PipelineLayoutDescriptor<'_> { } } -impl<'a> IntoTrace for &'_ crate::binding_model::ResolvedBindGroupDescriptor<'a> { +impl<'a> IntoTrace for &'_ crate::binding_model::BindGroupDescriptor<'a> { type Output = TraceBindGroupDescriptor<'a>; fn into_trace(self) -> Self::Output {