diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 5a083660bd..d1568d67c0 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -86,6 +86,7 @@ angle = ["wgc/angle"] webgl = ["wgc"] emscripten = ["webgl"] vulkan-portability = ["wgc/vulkan-portability"] +expose-ids = [] [target.'cfg(not(target_arch = "wasm32"))'.dependencies.wgc] workspace = true diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 6daab45c5d..7428b2e080 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -815,6 +815,49 @@ pub(crate) struct CommandEncoder { open: bool, } +pub(crate) type Id = (u32, u32, wgt::Backend); + +impl crate::GlobalId for T { + fn global_id(&self) -> Id { + self.unzip() + } +} + +impl crate::GlobalId for Surface { + fn global_id(&self) -> Id { + use wgc::id::TypedId; + self.id.unzip() + } +} + +impl crate::GlobalId for Device { + fn global_id(&self) -> Id { + use wgc::id::TypedId; + self.id.unzip() + } +} + +impl crate::GlobalId for Buffer { + fn global_id(&self) -> Id { + use wgc::id::TypedId; + self.id.unzip() + } +} + +impl crate::GlobalId for Texture { + fn global_id(&self) -> Id { + use wgc::id::TypedId; + self.id.unzip() + } +} + +impl crate::GlobalId for CommandEncoder { + fn global_id(&self) -> Id { + use wgc::id::TypedId; + self.id.unzip() + } +} + impl crate::Context for Context { type AdapterId = wgc::id::AdapterId; type DeviceId = Device; diff --git a/wgpu/src/backend/mod.rs b/wgpu/src/backend/mod.rs index d3f88c6928..1e5adc26e5 100644 --- a/wgpu/src/backend/mod.rs +++ b/wgpu/src/backend/mod.rs @@ -1,9 +1,9 @@ #[cfg(all(target_arch = "wasm32", not(feature = "webgl")))] mod web; #[cfg(all(target_arch = "wasm32", not(feature = "webgl")))] -pub(crate) use web::{BufferMappedRange, Context, QueueWriteBuffer}; +pub(crate) use web::{BufferMappedRange, Context, Id, QueueWriteBuffer}; #[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))] mod direct; #[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))] -pub(crate) use direct::{BufferMappedRange, Context, QueueWriteBuffer}; +pub(crate) use direct::{BufferMappedRange, Context, Id, QueueWriteBuffer}; diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index 01d454601e..38f2419a16 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -25,6 +25,41 @@ pub(crate) struct Sendable(T); unsafe impl Send for Sendable {} unsafe impl Sync for Sendable {} +#[derive(Clone, Debug)] +pub(crate) struct Identified(T, #[cfg(feature = "expose-ids")] u64); +unsafe impl Send for Identified {} +unsafe impl Sync for Identified {} + +impl crate::GlobalId for Identified { + #[cfg(not(feature = "expose-ids"))] + fn global_id(&self) -> Id { + 0 + } + + #[cfg(feature = "expose-ids")] + fn global_id(&self) -> Id { + self.1 + } +} + +pub(crate) type Id = u64; + +#[cfg(feature = "expose-ids")] +static NEXT_ID: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0); + +#[cfg(not(feature = "expose-ids"))] +fn create_identified(value: T) -> Identified { + Identified(value) +} + +#[cfg(feature = "expose-ids")] +fn create_identified(value: T) -> Identified { + Identified( + value, + NEXT_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed), + ) +} + pub(crate) struct Context(web_sys::Gpu); unsafe impl Send for Context {} unsafe impl Sync for Context {} @@ -93,13 +128,13 @@ impl MakeSendFuture { unsafe impl Send for MakeSendFuture {} impl crate::ComputePassInner for ComputePass { - fn set_pipeline(&mut self, pipeline: &Sendable) { + fn set_pipeline(&mut self, pipeline: &Identified) { self.0.set_pipeline(&pipeline.0); } fn set_bind_group( &mut self, index: u32, - bind_group: &Sendable, + bind_group: &Identified, offsets: &[wgt::DynamicOffset], ) { self.0 @@ -137,20 +172,24 @@ impl crate::ComputePassInner for ComputePass { } fn dispatch_workgroups_indirect( &mut self, - indirect_buffer: &Sendable, + indirect_buffer: &Identified, indirect_offset: wgt::BufferAddress, ) { self.0 .dispatch_workgroups_indirect_with_f64(&indirect_buffer.0, indirect_offset as f64); } - fn write_timestamp(&mut self, _query_set: &Sendable, _query_index: u32) { + fn write_timestamp( + &mut self, + _query_set: &Identified, + _query_index: u32, + ) { panic!("WRITE_TIMESTAMP_INSIDE_PASSES feature must be enabled to call write_timestamp in a compute pass") } fn begin_pipeline_statistics_query( &mut self, - _query_set: &Sendable, + _query_set: &Identified, _query_index: u32, ) { // Not available in gecko yet @@ -162,13 +201,13 @@ impl crate::ComputePassInner for ComputePass { } impl crate::RenderInner for RenderPass { - fn set_pipeline(&mut self, pipeline: &Sendable) { + fn set_pipeline(&mut self, pipeline: &Identified) { self.0.set_pipeline(&pipeline.0); } fn set_bind_group( &mut self, index: u32, - bind_group: &Sendable, + bind_group: &Identified, offsets: &[wgt::DynamicOffset], ) { self.0 @@ -182,7 +221,7 @@ impl crate::RenderInner for RenderPass { } fn set_index_buffer( &mut self, - buffer: &Sendable, + buffer: &Identified, index_format: wgt::IndexFormat, offset: wgt::BufferAddress, size: Option, @@ -208,7 +247,7 @@ impl crate::RenderInner for RenderPass { fn set_vertex_buffer( &mut self, slot: u32, - buffer: &Sendable, + buffer: &Identified, offset: wgt::BufferAddress, size: Option, ) { @@ -251,7 +290,7 @@ impl crate::RenderInner for RenderPass { } fn draw_indirect( &mut self, - indirect_buffer: &Sendable, + indirect_buffer: &Identified, indirect_offset: wgt::BufferAddress, ) { self.0 @@ -259,7 +298,7 @@ impl crate::RenderInner for RenderPass { } fn draw_indexed_indirect( &mut self, - indirect_buffer: &Sendable, + indirect_buffer: &Identified, indirect_offset: wgt::BufferAddress, ) { self.0 @@ -267,7 +306,7 @@ impl crate::RenderInner for RenderPass { } fn multi_draw_indirect( &mut self, - _indirect_buffer: &Sendable, + _indirect_buffer: &Identified, _indirect_offset: wgt::BufferAddress, _count: u32, ) { @@ -275,7 +314,7 @@ impl crate::RenderInner for RenderPass { } fn multi_draw_indexed_indirect( &mut self, - _indirect_buffer: &Sendable, + _indirect_buffer: &Identified, _indirect_offset: wgt::BufferAddress, _count: u32, ) { @@ -283,9 +322,9 @@ impl crate::RenderInner for RenderPass { } fn multi_draw_indirect_count( &mut self, - _indirect_buffer: &Sendable, + _indirect_buffer: &Identified, _indirect_offset: wgt::BufferAddress, - _count_buffer: &Sendable, + _count_buffer: &Identified, _count_buffer_offset: wgt::BufferAddress, _max_count: u32, ) { @@ -295,9 +334,9 @@ impl crate::RenderInner for RenderPass { } fn multi_draw_indexed_indirect_count( &mut self, - _indirect_buffer: &Sendable, + _indirect_buffer: &Identified, _indirect_offset: wgt::BufferAddress, - _count_buffer: &Sendable, + _count_buffer: &Identified, _count_buffer_offset: wgt::BufferAddress, _max_count: u32, ) { @@ -306,13 +345,13 @@ impl crate::RenderInner for RenderPass { } impl crate::RenderInner for RenderBundleEncoder { - fn set_pipeline(&mut self, pipeline: &Sendable) { + fn set_pipeline(&mut self, pipeline: &Identified) { self.0.set_pipeline(&pipeline.0); } fn set_bind_group( &mut self, index: u32, - bind_group: &Sendable, + bind_group: &Identified, offsets: &[wgt::DynamicOffset], ) { self.0 @@ -326,7 +365,7 @@ impl crate::RenderInner for RenderBundleEncoder { } fn set_index_buffer( &mut self, - buffer: &Sendable, + buffer: &Identified, index_format: wgt::IndexFormat, offset: wgt::BufferAddress, size: Option, @@ -352,7 +391,7 @@ impl crate::RenderInner for RenderBundleEncoder { fn set_vertex_buffer( &mut self, slot: u32, - buffer: &Sendable, + buffer: &Identified, offset: wgt::BufferAddress, size: Option, ) { @@ -395,7 +434,7 @@ impl crate::RenderInner for RenderBundleEncoder { } fn draw_indirect( &mut self, - indirect_buffer: &Sendable, + indirect_buffer: &Identified, indirect_offset: wgt::BufferAddress, ) { self.0 @@ -403,7 +442,7 @@ impl crate::RenderInner for RenderBundleEncoder { } fn draw_indexed_indirect( &mut self, - indirect_buffer: &Sendable, + indirect_buffer: &Identified, indirect_offset: wgt::BufferAddress, ) { self.0 @@ -411,7 +450,7 @@ impl crate::RenderInner for RenderBundleEncoder { } fn multi_draw_indirect( &mut self, - _indirect_buffer: &Sendable, + _indirect_buffer: &Identified, _indirect_offset: wgt::BufferAddress, _count: u32, ) { @@ -419,7 +458,7 @@ impl crate::RenderInner for RenderBundleEncoder { } fn multi_draw_indexed_indirect( &mut self, - _indirect_buffer: &Sendable, + _indirect_buffer: &Identified, _indirect_offset: wgt::BufferAddress, _count: u32, ) { @@ -427,9 +466,9 @@ impl crate::RenderInner for RenderBundleEncoder { } fn multi_draw_indirect_count( &mut self, - _indirect_buffer: &Sendable, + _indirect_buffer: &Identified, _indirect_offset: wgt::BufferAddress, - _count_buffer: &Sendable, + _count_buffer: &Identified, _count_buffer_offset: wgt::BufferAddress, _max_count: u32, ) { @@ -439,9 +478,9 @@ impl crate::RenderInner for RenderBundleEncoder { } fn multi_draw_indexed_indirect_count( &mut self, - _indirect_buffer: &Sendable, + _indirect_buffer: &Identified, _indirect_offset: wgt::BufferAddress, - _count_buffer: &Sendable, + _count_buffer: &Identified, _count_buffer_offset: wgt::BufferAddress, _max_count: u32, ) { @@ -488,7 +527,7 @@ impl crate::RenderPassInner for RenderPass { // self.0.pop_debug_group(); } - fn execute_bundles<'a, I: Iterator>>( + fn execute_bundles<'a, I: Iterator>>( &mut self, render_bundles: I, ) { @@ -498,13 +537,17 @@ impl crate::RenderPassInner for RenderPass { self.0.execute_bundles(&mapped); } - fn write_timestamp(&mut self, _query_set: &Sendable, _query_index: u32) { + fn write_timestamp( + &mut self, + _query_set: &Identified, + _query_index: u32, + ) { panic!("WRITE_TIMESTAMP_INSIDE_PASSES feature must be enabled to call write_timestamp in a compute pass") } fn begin_pipeline_statistics_query( &mut self, - _query_set: &Sendable, + _query_set: &Identified, _query_index: u32, ) { // Not available in gecko yet @@ -903,22 +946,28 @@ fn map_map_mode(mode: crate::MapMode) -> u32 { type JsFutureResult = Result; -fn future_request_adapter(result: JsFutureResult) -> Option> { +fn future_request_adapter(result: JsFutureResult) -> Option> { match result.and_then(wasm_bindgen::JsCast::dyn_into) { - Ok(adapter) => Some(Sendable(adapter)), + Ok(adapter) => Some(create_identified(adapter)), Err(_) => None, } } fn future_request_device( result: JsFutureResult, -) -> Result<(Sendable, Sendable), crate::RequestDeviceError> -{ +) -> Result< + ( + Identified, + Identified, + ), + crate::RequestDeviceError, +> { result .map(|js_value| { let device_id = web_sys::GpuDevice::from(js_value); let queue_id = device_id.queue(); - (Sendable(device_id), Sendable(queue_id)) + + (create_identified(device_id), create_identified(queue_id)) }) .map_err(|_| crate::RequestDeviceError) } @@ -984,7 +1033,7 @@ impl Context { Ok(Some(ctx)) => ctx.into(), _ => panic!("expected to get context from canvas"), }; - Sendable(context.into()) + create_identified(context.into()) } pub fn instance_create_surface_from_offscreen_canvas( @@ -995,12 +1044,12 @@ impl Context { Ok(Some(ctx)) => ctx.into(), _ => panic!("expected to get context from canvas"), }; - Sendable(context.into()) + create_identified(context.into()) } pub fn queue_copy_external_image_to_texture( &self, - queue: &Sendable, + queue: &Identified, image: &web_sys::ImageBitmap, texture: crate::ImageCopyTexture, size: wgt::Extent3d, @@ -1037,27 +1086,27 @@ extern "C" { pub struct SubmissionIndex; impl crate::Context for Context { - type AdapterId = Sendable; - type DeviceId = Sendable; - type QueueId = Sendable; - type ShaderModuleId = Sendable; - type BindGroupLayoutId = Sendable; - type BindGroupId = Sendable; - type TextureViewId = Sendable; - type SamplerId = Sendable; - type BufferId = Sendable; - type TextureId = Sendable; - type QuerySetId = Sendable; - type PipelineLayoutId = Sendable; - type RenderPipelineId = Sendable; - type ComputePipelineId = Sendable; + type AdapterId = Identified; + type DeviceId = Identified; + type QueueId = Identified; + type ShaderModuleId = Identified; + type BindGroupLayoutId = Identified; + type BindGroupId = Identified; + type TextureViewId = Identified; + type SamplerId = Identified; + type BufferId = Identified; + type TextureId = Identified; + type QuerySetId = Identified; + type PipelineLayoutId = Identified; + type RenderPipelineId = Identified; + type ComputePipelineId = Identified; type CommandEncoderId = Sendable; type ComputePassId = ComputePass; type RenderPassId = RenderPass; type CommandBufferId = Sendable; type RenderBundleEncoderId = RenderBundleEncoder; - type RenderBundleId = Sendable; - type SurfaceId = Sendable; + type RenderBundleId = Identified; + type SurfaceId = Identified; type SurfaceOutputDetail = SurfaceOutputDetail; type SubmissionIndex = SubmissionIndex; @@ -1338,7 +1387,7 @@ impl crate::Context for Context { Self::SurfaceOutputDetail, ) { ( - Some(Sendable(surface.0.get_current_texture())), + Some(create_identified(surface.0.get_current_texture())), wgt::SurfaceStatus::Good, (), ) @@ -1462,7 +1511,7 @@ impl crate::Context for Context { if let Some(label) = desc.label { descriptor.label(label); } - Sendable(device.0.create_shader_module(&descriptor)) + create_identified(device.0.create_shader_module(&descriptor)) } fn device_create_bind_group_layout( @@ -1560,7 +1609,7 @@ impl crate::Context for Context { if let Some(label) = desc.label { mapped_desc.label(label); } - Sendable(device.0.create_bind_group_layout(&mapped_desc)) + create_identified(device.0.create_bind_group_layout(&mapped_desc)) } unsafe fn device_create_shader_module_spirv( @@ -1618,7 +1667,7 @@ impl crate::Context for Context { if let Some(label) = desc.label { mapped_desc.label(label); } - Sendable(device.0.create_bind_group(&mapped_desc)) + create_identified(device.0.create_bind_group(&mapped_desc)) } fn device_create_pipeline_layout( @@ -1635,7 +1684,7 @@ impl crate::Context for Context { if let Some(label) = desc.label { mapped_desc.label(label); } - Sendable(device.0.create_pipeline_layout(&mapped_desc)) + create_identified(device.0.create_pipeline_layout(&mapped_desc)) } fn device_create_render_pipeline( @@ -1726,7 +1775,7 @@ impl crate::Context for Context { let mapped_primitive = map_primitive_state(&desc.primitive); mapped_desc.primitive(&mapped_primitive); - Sendable(device.0.create_render_pipeline(&mapped_desc)) + create_identified(device.0.create_render_pipeline(&mapped_desc)) } fn device_create_compute_pipeline( @@ -1747,7 +1796,7 @@ impl crate::Context for Context { if let Some(label) = desc.label { mapped_desc.label(label); } - Sendable(device.0.create_compute_pipeline(&mapped_desc)) + create_identified(device.0.create_compute_pipeline(&mapped_desc)) } fn device_create_buffer( @@ -1761,7 +1810,7 @@ impl crate::Context for Context { if let Some(label) = desc.label { mapped_desc.label(label); } - Sendable(device.0.create_buffer(&mapped_desc)) + create_identified(device.0.create_buffer(&mapped_desc)) } fn device_create_texture( @@ -1780,7 +1829,7 @@ impl crate::Context for Context { mapped_desc.dimension(map_texture_dimension(desc.dimension)); mapped_desc.mip_level_count(desc.mip_level_count); mapped_desc.sample_count(desc.sample_count); - Sendable(device.0.create_texture(&mapped_desc)) + create_identified(device.0.create_texture(&mapped_desc)) } fn device_create_sampler( @@ -1805,7 +1854,7 @@ impl crate::Context for Context { if let Some(label) = desc.label { mapped_desc.label(label); } - Sendable(device.0.create_sampler_with_descriptor(&mapped_desc)) + create_identified(device.0.create_sampler_with_descriptor(&mapped_desc)) } fn device_create_query_set( @@ -1822,7 +1871,7 @@ impl crate::Context for Context { if let Some(label) = desc.label { mapped_desc.label(label); } - Sendable(device.0.create_query_set(&mapped_desc)) + create_identified(device.0.create_query_set(&mapped_desc)) } fn device_create_command_encoder( @@ -1968,7 +2017,7 @@ impl crate::Context for Context { if let Some(label) = desc.label { mapped.label(label); } - Sendable(texture.0.create_view_with_descriptor(&mapped)) + create_identified(texture.0.create_view_with_descriptor(&mapped)) } fn surface_drop(&self, _surface: &Self::SurfaceId) { @@ -2048,7 +2097,7 @@ impl crate::Context for Context { pipeline: &Self::ComputePipelineId, index: u32, ) -> Self::BindGroupLayoutId { - Sendable(pipeline.0.get_bind_group_layout(index)) + create_identified(pipeline.0.get_bind_group_layout(index)) } fn render_pipeline_get_bind_group_layout( @@ -2056,7 +2105,7 @@ impl crate::Context for Context { pipeline: &Self::RenderPipelineId, index: u32, ) -> Self::BindGroupLayoutId { - Sendable(pipeline.0.get_bind_group_layout(index)) + create_identified(pipeline.0.get_bind_group_layout(index)) } fn command_encoder_copy_buffer_to_buffer( @@ -2305,7 +2354,7 @@ impl crate::Context for Context { encoder: Self::RenderBundleEncoderId, desc: &crate::RenderBundleDescriptor, ) -> Self::RenderBundleId { - Sendable(match desc.label { + create_identified(match desc.label { Some(label) => { let mut mapped_desc = web_sys::GpuRenderBundleDescriptor::new(); mapped_desc.label(label); diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 501a7486e9..b2e6ce8cee 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -43,7 +43,7 @@ pub use wgt::{ QUERY_RESOLVE_BUFFER_ALIGNMENT, QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT, }; -use backend::{BufferMappedRange, Context as C, QueueWriteBuffer}; +use backend::{BufferMappedRange, Context as C, Id as BackendId, QueueWriteBuffer}; /// Filter for error scopes. #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd)] @@ -164,28 +164,32 @@ trait RenderPassInner: RenderInner { ); } +trait GlobalId { + fn global_id(&self) -> BackendId; +} + trait Context: Debug + Send + Sized + Sync { - type AdapterId: Debug + Send + Sync + 'static; - type DeviceId: Debug + Send + Sync + 'static; - type QueueId: Debug + Send + Sync + 'static; - type ShaderModuleId: Debug + Send + Sync + 'static; - type BindGroupLayoutId: Debug + Send + Sync + 'static; - type BindGroupId: Debug + Send + Sync + 'static; - type TextureViewId: Debug + Send + Sync + 'static; - type SamplerId: Debug + Send + Sync + 'static; - type BufferId: Debug + Send + Sync + 'static; - type TextureId: Debug + Send + Sync + 'static; - type QuerySetId: Debug + Send + Sync + 'static; - type PipelineLayoutId: Debug + Send + Sync + 'static; - type RenderPipelineId: Debug + Send + Sync + 'static; - type ComputePipelineId: Debug + Send + Sync + 'static; + type AdapterId: GlobalId + Debug + Send + Sync + 'static; + type DeviceId: GlobalId + Debug + Send + Sync + 'static; + type QueueId: GlobalId + Debug + Send + Sync + 'static; + type ShaderModuleId: GlobalId + Debug + Send + Sync + 'static; + type BindGroupLayoutId: GlobalId + Debug + Send + Sync + 'static; + type BindGroupId: GlobalId + Debug + Send + Sync + 'static; + type TextureViewId: GlobalId + Debug + Send + Sync + 'static; + type SamplerId: GlobalId + Debug + Send + Sync + 'static; + type BufferId: GlobalId + Debug + Send + Sync + 'static; + type TextureId: GlobalId + Debug + Send + Sync + 'static; + type QuerySetId: GlobalId + Debug + Send + Sync + 'static; + type PipelineLayoutId: GlobalId + Debug + Send + Sync + 'static; + type RenderPipelineId: GlobalId + Debug + Send + Sync + 'static; + type ComputePipelineId: GlobalId + Debug + Send + Sync + 'static; type CommandEncoderId: Debug; type ComputePassId: Debug + ComputePassInner; type RenderPassId: Debug + RenderPassInner; type CommandBufferId: Debug + Send + Sync; type RenderBundleEncoderId: Debug + RenderInner; - type RenderBundleId: Debug + Send + Sync + 'static; - type SurfaceId: Debug + Send + Sync + 'static; + type RenderBundleId: GlobalId + Debug + Send + Sync + 'static; + type SurfaceId: GlobalId + Debug + Send + Sync + 'static; type SurfaceOutputDetail: Send; type SubmissionIndex: Debug + Copy + Clone + Send + 'static; @@ -3796,6 +3800,205 @@ impl Surface { } } +/// Opaque globally-unique identifier +#[cfg(feature = "expose-ids")] +#[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))] +#[repr(transparent)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub struct Id(BackendId); + +#[cfg(feature = "expose-ids")] +impl Adapter { + /// Returns a globally-unique identifier for this `Adapter`. + /// + /// Calling this method multiple times on the same object will always return the same value. + /// The returned value is guaranteed to be different for all resources created from the same `Instance`. + #[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))] + pub fn global_id(&self) -> Id { + Id(self.id.global_id()) + } +} + +#[cfg(feature = "expose-ids")] +impl Device { + /// Returns a globally-unique identifier for this `Device`. + /// + /// Calling this method multiple times on the same object will always return the same value. + /// The returned value is guaranteed to be different for all resources created from the same `Instance`. + #[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))] + pub fn global_id(&self) -> Id { + Id(self.id.global_id()) + } +} + +#[cfg(feature = "expose-ids")] +impl Queue { + /// Returns a globally-unique identifier for this `Queue`. + /// + /// Calling this method multiple times on the same object will always return the same value. + /// The returned value is guaranteed to be different for all resources created from the same `Instance`. + #[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))] + pub fn global_id(&self) -> Id { + Id(self.id.global_id()) + } +} + +#[cfg(feature = "expose-ids")] +impl ShaderModule { + /// Returns a globally-unique identifier for this `ShaderModule`. + /// + /// Calling this method multiple times on the same object will always return the same value. + /// The returned value is guaranteed to be different for all resources created from the same `Instance`. + #[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))] + pub fn global_id(&self) -> Id { + Id(self.id.global_id()) + } +} + +#[cfg(feature = "expose-ids")] +impl BindGroupLayout { + /// Returns a globally-unique identifier for this `BindGroupLayout`. + /// + /// Calling this method multiple times on the same object will always return the same value. + /// The returned value is guaranteed to be different for all resources created from the same `Instance`. + #[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))] + pub fn global_id(&self) -> Id { + Id(self.id.global_id()) + } +} + +#[cfg(feature = "expose-ids")] +impl BindGroup { + /// Returns a globally-unique identifier for this `BindGroup`. + /// + /// Calling this method multiple times on the same object will always return the same value. + /// The returned value is guaranteed to be different for all resources created from the same `Instance`. + #[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))] + pub fn global_id(&self) -> Id { + Id(self.id.global_id()) + } +} + +#[cfg(feature = "expose-ids")] +impl TextureView { + /// Returns a globally-unique identifier for this `TextureView`. + /// + /// Calling this method multiple times on the same object will always return the same value. + /// The returned value is guaranteed to be different for all resources created from the same `Instance`. + #[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))] + pub fn global_id(&self) -> Id { + Id(self.id.global_id()) + } +} + +#[cfg(feature = "expose-ids")] +impl Sampler { + /// Returns a globally-unique identifier for this `Sampler`. + /// + /// Calling this method multiple times on the same object will always return the same value. + /// The returned value is guaranteed to be different for all resources created from the same `Instance`. + #[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))] + pub fn global_id(&self) -> Id { + Id(self.id.global_id()) + } +} + +#[cfg(feature = "expose-ids")] +impl Buffer { + /// Returns a globally-unique identifier for this `Buffer`. + /// + /// Calling this method multiple times on the same object will always return the same value. + /// The returned value is guaranteed to be different for all resources created from the same `Instance`. + #[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))] + pub fn global_id(&self) -> Id { + Id(self.id.global_id()) + } +} + +#[cfg(feature = "expose-ids")] +impl Texture { + /// Returns a globally-unique identifier for this `Texture`. + /// + /// Calling this method multiple times on the same object will always return the same value. + /// The returned value is guaranteed to be different for all resources created from the same `Instance`. + #[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))] + pub fn global_id(&self) -> Id { + Id(self.id.global_id()) + } +} + +#[cfg(feature = "expose-ids")] +impl QuerySet { + /// Returns a globally-unique identifier for this `QuerySet`. + /// + /// Calling this method multiple times on the same object will always return the same value. + /// The returned value is guaranteed to be different for all resources created from the same `Instance`. + #[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))] + pub fn global_id(&self) -> Id { + Id(self.id.global_id()) + } +} + +#[cfg(feature = "expose-ids")] +impl PipelineLayout { + /// Returns a globally-unique identifier for this `PipelineLayout`. + /// + /// Calling this method multiple times on the same object will always return the same value. + /// The returned value is guaranteed to be different for all resources created from the same `Instance`. + #[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))] + pub fn global_id(&self) -> Id { + Id(self.id.global_id()) + } +} + +#[cfg(feature = "expose-ids")] +impl RenderPipeline { + /// Returns a globally-unique identifier for this `RenderPipeline`. + /// + /// Calling this method multiple times on the same object will always return the same value. + /// The returned value is guaranteed to be different for all resources created from the same `Instance`. + #[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))] + pub fn global_id(&self) -> Id { + Id(self.id.global_id()) + } +} + +#[cfg(feature = "expose-ids")] +impl ComputePipeline { + /// Returns a globally-unique identifier for this `ComputePipeline`. + /// + /// Calling this method multiple times on the same object will always return the same value. + /// The returned value is guaranteed to be different for all resources created from the same `Instance`. + #[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))] + pub fn global_id(&self) -> Id { + Id(self.id.global_id()) + } +} + +#[cfg(feature = "expose-ids")] +impl RenderBundle { + /// Returns a globally-unique identifier for this `RenderBundle`. + /// + /// Calling this method multiple times on the same object will always return the same value. + /// The returned value is guaranteed to be different for all resources created from the same `Instance`. + #[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))] + pub fn global_id(&self) -> Id { + Id(self.id.global_id()) + } +} + +#[cfg(feature = "expose-ids")] +impl Surface { + /// Returns a globally-unique identifier for this `Surface`. + /// + /// Calling this method multiple times on the same object will always return the same value. + /// The returned value is guaranteed to be different for all resources created from the same `Instance`. + #[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))] + pub fn global_id(&self) -> Id { + Id(self.id.global_id()) + } +} + /// Type for the callback of uncaptured error handler pub trait UncapturedErrorHandler: Fn(Error) + Send + 'static {} impl UncapturedErrorHandler for T where T: Fn(Error) + Send + 'static {}