From b40dbe66a925cc20c8b02c5f7059e9244a744da3 Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Tue, 28 Jul 2026 08:30:51 +0200 Subject: [PATCH] [wgpu] Use Arced resources instead of `Global` Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- wgpu/src/api/instance.rs | 4 +- wgpu/src/backend/wgpu_core.rs | 1471 +++++++++++++-------------------- 2 files changed, 568 insertions(+), 907 deletions(-) diff --git a/wgpu/src/api/instance.rs b/wgpu/src/api/instance.rs index 188b699fb..1d7926aa3 100644 --- a/wgpu/src/api/instance.rs +++ b/wgpu/src/api/instance.rs @@ -398,10 +398,10 @@ impl Instance { hal_adapter: hal::ExposedAdapter, ) -> Adapter { let core_instance = self.inner.as_core(); - let adapter = unsafe { core_instance.create_adapter_from_hal(hal_adapter) }; + let wgpu_adapter = unsafe { core_instance.create_adapter_from_hal(hal_adapter) }; let core = backend::wgpu_core::CoreAdapter { context: core_instance.clone(), - id: adapter, + wgpu_adapter, }; Adapter { inner: core.into() } diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index 8da00dcff..aea60b0b3 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -1,3 +1,4 @@ +use alloc::borrow::ToOwned; use alloc::{ borrow::Cow::{self, Borrowed}, boxed::Box, @@ -41,13 +42,7 @@ use crate::{dispatch::DispatchAdapter, util::Mutex}; mod thread_id; #[derive(Clone)] -pub struct ContextWgpuCore(Arc); - -impl Drop for ContextWgpuCore { - fn drop(&mut self) { - //nothing - } -} +pub struct ContextWgpuCore(Arc); impl fmt::Debug for ContextWgpuCore { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -59,27 +54,25 @@ impl fmt::Debug for ContextWgpuCore { impl ContextWgpuCore { pub unsafe fn from_hal_instance(hal_instance: A::Instance) -> Self { - Self(unsafe { - Arc::new(wgc::global::Global::from_hal_instance::( - "wgpu", - hal_instance, - )) - }) + Self(wgc::instance::Instance::from_hal_instance::( + "wgpu".to_owned(), + hal_instance, + )) } /// # Safety /// /// - The raw instance handle returned must not be manually destroyed. pub unsafe fn instance_as_hal(&self) -> Option<&A::Instance> { - unsafe { self.0.instance_as_hal::() } + unsafe { self.0.as_hal::() } } pub unsafe fn from_core_instance(core_instance: Arc) -> Self { - Self(unsafe { Arc::new(wgc::global::Global::from_instance(core_instance)) }) + Self(core_instance) } #[cfg(wgpu_core)] - pub fn enumerate_adapters(&self, backends: wgt::Backends) -> Vec { + pub fn enumerate_adapters(&self, backends: wgt::Backends) -> Vec> { self.0 .enumerate_adapters(backends, false /* no limit bucketing */) } @@ -87,22 +80,22 @@ impl ContextWgpuCore { pub unsafe fn create_adapter_from_hal( &self, hal_adapter: hal::ExposedAdapter, - ) -> wgc::id::AdapterId { - unsafe { self.0.create_adapter_from_hal(hal_adapter.into(), None) } + ) -> Arc { + unsafe { self.0.create_adapter_from_hal(hal_adapter.into()) } } pub unsafe fn adapter_as_hal( &self, adapter: &CoreAdapter, ) -> Option + WasmNotSendSync> { - unsafe { self.0.adapter_as_hal::(adapter.id) } + unsafe { adapter.wgpu_adapter.clone().as_hal::() } } pub unsafe fn buffer_as_hal( &self, buffer: &CoreBuffer, ) -> Option> { - unsafe { self.0.buffer_as_hal::(buffer.id) } + unsafe { buffer.wgpu_buffer.clone().as_hal::() } } pub unsafe fn create_device_from_hal( @@ -111,25 +104,22 @@ impl ContextWgpuCore { hal_device: hal::OpenDevice, desc: &crate::DeviceDescriptor<'_>, ) -> Result<(CoreDevice, CoreQueue), crate::RequestDeviceError> { - let (device_id, queue_id) = unsafe { - self.0.create_device_from_hal( - adapter.id, + let (device, queue) = unsafe { + adapter.wgpu_adapter.create_device_and_queue_from_hal( hal_device.into(), &desc.map_label(|l| l.map(Borrowed)), - None, - None, ) }?; let error_sink = Arc::new(Mutex::new(ErrorSinkRaw::new())); let device = CoreDevice { context: self.clone(), - id: device_id, + wgpu_device: device, error_sink: error_sink.clone(), features: desc.required_features, }; let queue = CoreQueue { context: self.clone(), - id: queue_id, + wgpu_queue: queue, error_sink, }; Ok((device, queue)) @@ -143,13 +133,11 @@ impl ContextWgpuCore { initial_state: wgt::TextureUses, ) -> CoreTexture { let descriptor = desc.map_label_and_view_formats(|l| l.map(Borrowed), |v| v.to_vec()); - let (id, error) = unsafe { - self.0.create_texture_from_hal( + let (wgpu_texture, error) = unsafe { + device.wgpu_device.create_texture_from_hal( Box::new(hal_texture), - device.id, &descriptor, initial_state, - None, ) }; if let Some(cause) = error { @@ -162,7 +150,7 @@ impl ContextWgpuCore { } CoreTexture { context: self.clone(), - id, + wgpu_texture, error_sink: Arc::clone(&device.error_sink), } } @@ -179,13 +167,10 @@ impl ContextWgpuCore { device: &CoreDevice, desc: &BufferDescriptor<'_>, ) -> CoreBuffer { - let (id, error) = unsafe { - self.0.create_buffer_from_hal::( - hal_buffer, - device.id, - &desc.map_label(|l| l.map(Borrowed)), - None, - ) + let (wgpu_buffer, error) = unsafe { + device + .wgpu_device + .create_buffer_from_hal(Box::new(hal_buffer), &desc.map_label(|l| l.map(Borrowed))) }; if let Some(cause) = error { self.handle_error( @@ -197,7 +182,7 @@ impl ContextWgpuCore { } CoreBuffer { context: self.clone(), - id, + wgpu_buffer, error_sink: Arc::clone(&device.error_sink), } } @@ -206,28 +191,28 @@ impl ContextWgpuCore { &self, device: &CoreDevice, ) -> Option> { - unsafe { self.0.device_as_hal::(device.id) } + unsafe { device.wgpu_device.clone().as_hal::() } } pub unsafe fn surface_as_hal( &self, surface: &CoreSurface, ) -> Option> { - unsafe { self.0.surface_as_hal::(surface.id) } + unsafe { surface.wgpu_surface.clone().as_hal::() } } pub unsafe fn texture_as_hal( &self, texture: &CoreTexture, ) -> Option> { - unsafe { self.0.texture_as_hal::(texture.id) } + unsafe { texture.wgpu_texture.clone().as_hal::() } } pub unsafe fn texture_view_as_hal( &self, texture_view: &CoreTextureView, ) -> Option> { - unsafe { self.0.texture_view_as_hal::(texture_view.id) } + unsafe { texture_view.wgpu_texture_view.clone().as_hal::() } } /// This method will start the wgpu_core level command recording. @@ -241,10 +226,9 @@ impl ContextWgpuCore { hal_command_encoder_callback: F, ) -> R { unsafe { - self.0.command_encoder_as_hal_mut::( - command_encoder.id, - hal_command_encoder_callback, - ) + command_encoder + .wgpu_command_encoder + .as_hal_mut::(hal_command_encoder_callback) } } @@ -252,18 +236,14 @@ impl ContextWgpuCore { &self, blas: &CoreBlas, ) -> Option> { - unsafe { self.0.blas_as_hal::(blas.id) } + unsafe { blas.wgpu_blas.clone().as_hal::() } } pub unsafe fn tlas_as_hal( &self, tlas: &CoreTlas, ) -> Option> { - unsafe { self.0.tlas_as_hal::(tlas.id) } - } - - pub fn generate_report(&self) -> wgc::global::GlobalReport { - self.0.generate_report() + unsafe { tlas.wgpu_tlas.clone().as_hal::() } } #[cold] @@ -383,24 +363,24 @@ impl ContextWgpuCore { &self, queue: &CoreQueue, ) -> Option + WasmNotSendSync> { - unsafe { self.0.queue_as_hal::(queue.id) } + unsafe { queue.wgpu_queue.clone().as_hal::() } } } fn map_buffer_copy_view( view: crate::TexelCopyBufferInfo<'_>, -) -> wgt::TexelCopyBufferInfo { +) -> wgt::TexelCopyBufferInfo> { wgt::TexelCopyBufferInfo { - buffer: view.buffer.inner.as_core().id, + buffer: view.buffer.inner.as_core().wgpu_buffer.clone(), layout: view.layout, } } fn map_texture_copy_view( view: crate::TexelCopyTextureInfo<'_>, -) -> wgt::TexelCopyTextureInfo { +) -> wgt::TexelCopyTextureInfo> { wgt::TexelCopyTextureInfo { - texture: view.texture.inner.as_core().id, + texture: view.texture.inner.as_core().wgpu_texture.clone(), mip_level: view.mip_level, origin: view.origin, aspect: view.aspect, @@ -410,9 +390,9 @@ fn map_texture_copy_view( #[cfg_attr(not(webgl), expect(unused))] fn map_texture_tagged_copy_view( view: crate::CopyExternalImageDestInfo<&api::Texture>, -) -> wgt::CopyExternalImageDestInfo { +) -> wgt::CopyExternalImageDestInfo> { wgt::CopyExternalImageDestInfo { - texture: view.texture.inner.as_core().id, + texture: view.texture.inner.as_core().wgpu_texture.clone(), mip_level: view.mip_level, origin: view.origin, aspect: view.aspect, @@ -444,28 +424,46 @@ fn map_pass_channel(ops: Option<&Operations>) -> wgc::command::PassC } } -#[derive(Debug)] pub struct CoreSurface { pub(crate) context: ContextWgpuCore, - id: wgc::id::SurfaceId, + pub(crate) wgpu_surface: Arc, /// Configured device is needed to know which backend /// code to execute when acquiring a new frame. - configured_device: Mutex>, + configured_device: Mutex>>, /// The error sink with which to report errors. /// `None` if the surface has not been configured. error_sink: Mutex>, } -#[derive(Debug)] +impl fmt::Debug for CoreSurface { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("CoreSurface") + .field("context", &self.context) + .field("wgpu_surface", &Arc::as_ptr(&self.wgpu_surface)) + .field("configured_device", &self.configured_device) + .field("error_sink", &self.error_sink) + .finish() + } +} + pub struct CoreAdapter { pub(crate) context: ContextWgpuCore, - pub(crate) id: wgc::id::AdapterId, + pub(crate) wgpu_adapter: Arc, +} + +impl fmt::Debug for CoreAdapter { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("CoreAdapter") + .field("context", &self.context) + .field("wgpu_adapter", &Arc::as_ptr(&self.wgpu_adapter)) + .finish() + } } #[derive(Debug)] pub struct CoreDevice { pub(crate) context: ContextWgpuCore, - id: wgc::id::DeviceId, + pub(crate) wgpu_device: Arc, error_sink: ErrorSink, features: Features, } @@ -473,76 +471,79 @@ pub struct CoreDevice { #[derive(Debug)] pub struct CoreBuffer { pub(crate) context: ContextWgpuCore, - id: wgc::id::BufferId, + pub(crate) wgpu_buffer: Arc, error_sink: ErrorSink, } #[derive(Debug)] pub struct CoreShaderModule { - pub(crate) context: ContextWgpuCore, - id: wgc::id::ShaderModuleId, + pub(crate) wgpu_shader_module: Arc, compilation_info: CompilationInfo, } #[derive(Debug)] pub struct CoreBindGroupLayout { - pub(crate) context: ContextWgpuCore, - id: wgc::id::BindGroupLayoutId, + pub(crate) wgpu_bind_group_layout: Arc, } #[derive(Debug)] pub struct CoreBindGroup { - pub(crate) context: ContextWgpuCore, - id: wgc::id::BindGroupId, + pub(crate) wgpu_bind_group: Arc, } #[derive(Debug)] pub struct CoreTexture { pub(crate) context: ContextWgpuCore, - id: wgc::id::TextureId, + pub(crate) wgpu_texture: Arc, error_sink: ErrorSink, } #[derive(Debug)] pub struct CoreTextureView { pub(crate) context: ContextWgpuCore, - id: wgc::id::TextureViewId, + pub(crate) wgpu_texture_view: Arc, } #[derive(Debug)] pub struct CoreExternalTexture { - pub(crate) context: ContextWgpuCore, - id: wgc::id::ExternalTextureId, + pub(crate) wgpu_external_texture: Arc, } #[derive(Debug)] pub struct CoreSampler { - pub(crate) context: ContextWgpuCore, - id: wgc::id::SamplerId, + pub(crate) wgpu_sampler: Arc, } #[derive(Debug)] pub struct CoreQuerySet { - pub(crate) context: ContextWgpuCore, - id: wgc::id::QuerySetId, + pub(crate) wgpu_query_set: Arc, } #[derive(Debug)] pub struct CorePipelineLayout { - pub(crate) context: ContextWgpuCore, - id: wgc::id::PipelineLayoutId, + pub(crate) wgpu_pipeline_layout: Arc, } #[derive(Debug)] pub struct CorePipelineCache { - pub(crate) context: ContextWgpuCore, - id: wgc::id::PipelineCacheId, + pub(crate) wgpu_pipeline_cache: Arc, } -#[derive(Debug)] pub struct CoreCommandBuffer { pub(crate) context: ContextWgpuCore, - id: wgc::id::CommandBufferId, + pub(crate) wgpu_command_buffer: Arc, +} + +impl fmt::Debug for CoreCommandBuffer { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("CoreCommandBuffer") + .field("context", &self.context) + .field( + "wgpu_command_buffer", + &Arc::as_ptr(&self.wgpu_command_buffer), + ) + .finish() + } } #[derive(Debug)] @@ -550,33 +551,40 @@ pub struct CoreRenderBundleEncoder { pub(crate) context: ContextWgpuCore, error_sink: ErrorSink, encoder: Box, - id: crate::cmp::Identifier, } #[derive(Debug)] pub struct CoreRenderBundle { - context: ContextWgpuCore, - id: wgc::id::RenderBundleId, + pub(crate) wgpu_render_bundle: Arc, } -#[derive(Debug)] pub struct CoreQueue { pub(crate) context: ContextWgpuCore, - id: wgc::id::QueueId, + pub(crate) wgpu_queue: Arc, error_sink: ErrorSink, } +impl fmt::Debug for CoreQueue { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("CoreQueue") + .field("context", &self.context) + .field("wgpu_queue", &Arc::as_ptr(&self.wgpu_queue)) + .field("error_sink", &self.error_sink) + .finish() + } +} + #[derive(Debug)] pub struct CoreComputePipeline { pub(crate) context: ContextWgpuCore, - id: wgc::id::ComputePipelineId, + pub(crate) wgpu_compute_pipeline: Arc, error_sink: ErrorSink, } #[derive(Debug)] pub struct CoreRenderPipeline { pub(crate) context: ContextWgpuCore, - id: wgc::id::RenderPipelineId, + pub(crate) wgpu_render_pipeline: Arc, error_sink: ErrorSink, } @@ -596,34 +604,55 @@ pub struct CoreRenderPass { id: crate::cmp::Identifier, } -#[derive(Debug)] pub struct CoreCommandEncoder { pub(crate) context: ContextWgpuCore, - id: wgc::id::CommandEncoderId, + pub(crate) wgpu_command_encoder: Arc, error_sink: ErrorSink, } +impl fmt::Debug for CoreCommandEncoder { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("CoreCommandEncoder") + .field("context", &self.context) + .field( + "wgpu_command_encoder", + &Arc::as_ptr(&self.wgpu_command_encoder), + ) + .field("error_sink", &self.error_sink) + .finish() + } +} + #[derive(Debug)] pub struct CoreBlas { pub(crate) context: ContextWgpuCore, - id: wgc::id::BlasId, + pub(crate) wgpu_blas: Arc, error_sink: ErrorSink, } #[derive(Debug)] pub struct CoreTlas { pub(crate) context: ContextWgpuCore, - id: wgc::id::TlasId, + pub(crate) wgpu_tlas: Arc, // error_sink: ErrorSink, } -#[derive(Debug)] pub struct CoreSurfaceOutputDetail { - context: ContextWgpuCore, - surface_id: wgc::id::SurfaceId, + pub(crate) context: ContextWgpuCore, + wgpu_surface: Arc, error_sink: ErrorSink, } +impl fmt::Debug for CoreSurfaceOutputDetail { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("CoreSurfaceOutputDetail") + .field("context", &self.context) + .field("wgpu_surface", &Arc::as_ptr(&self.wgpu_surface)) + .field("error_sink", &self.error_sink) + .finish() + } +} + type ErrorSink = Arc>; struct ErrorScope { @@ -726,7 +755,7 @@ impl From for CompilationInfo { #[derive(Debug)] pub struct CoreQueueWriteBuffer { - buffer_id: wgc::id::StagingBufferId, + wgpu_staging_buffer: wgc::resource::StagingBuffer, mapping: CoreBufferMappedRange, } @@ -749,32 +778,32 @@ impl Drop for CoreBufferMappedRange { } crate::cmp::impl_eq_ord_hash_arc_address!(ContextWgpuCore => .0); -crate::cmp::impl_eq_ord_hash_proxy!(CoreAdapter => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreDevice => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreQueue => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreShaderModule => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreBindGroupLayout => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreBindGroup => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreTextureView => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreSampler => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreBuffer => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreTexture => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreExternalTexture => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreBlas => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreTlas => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreQuerySet => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CorePipelineLayout => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreRenderPipeline => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreComputePipeline => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CorePipelineCache => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreCommandEncoder => .id); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreAdapter => .wgpu_adapter); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreDevice => .wgpu_device); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreQueue => .wgpu_queue); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreShaderModule => .wgpu_shader_module); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreBindGroupLayout => .wgpu_bind_group_layout); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreBindGroup => .wgpu_bind_group); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreTextureView => .wgpu_texture_view); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreSampler => .wgpu_sampler); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreBuffer => .wgpu_buffer); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreTexture => .wgpu_texture); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreExternalTexture => .wgpu_external_texture); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreBlas => .wgpu_blas); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreTlas => .wgpu_tlas); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreQuerySet => .wgpu_query_set); +crate::cmp::impl_eq_ord_hash_arc_address!(CorePipelineLayout => .wgpu_pipeline_layout); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreRenderPipeline => .wgpu_render_pipeline); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreComputePipeline => .wgpu_compute_pipeline); +crate::cmp::impl_eq_ord_hash_arc_address!(CorePipelineCache => .wgpu_pipeline_cache); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreCommandEncoder => .wgpu_command_encoder); crate::cmp::impl_eq_ord_hash_proxy!(CoreComputePass => .id); crate::cmp::impl_eq_ord_hash_proxy!(CoreRenderPass => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreCommandBuffer => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreRenderBundleEncoder => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreRenderBundle => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreSurface => .id); -crate::cmp::impl_eq_ord_hash_proxy!(CoreSurfaceOutputDetail => .surface_id); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreCommandBuffer => .wgpu_command_buffer); +crate::cmp::impl_eq_ord_hash_box_address!(CoreRenderBundleEncoder => .encoder); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreRenderBundle => .wgpu_render_bundle); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreSurface => .wgpu_surface); +crate::cmp::impl_eq_ord_hash_arc_address!(CoreSurfaceOutputDetail => .wgpu_surface); crate::cmp::impl_eq_ord_hash_proxy!(CoreQueueWriteBuffer => .mapping.ptr); crate::cmp::impl_eq_ord_hash_proxy!(CoreBufferMappedRange => .ptr); @@ -783,21 +812,18 @@ impl dispatch::InstanceInterface for ContextWgpuCore { where Self: Sized, { - Self(Arc::new(wgc::global::Global::new("wgpu", desc, None))) + Self(wgc::instance::Instance::new("wgpu", desc, None)) } unsafe fn create_surface( &self, target: crate::api::SurfaceTargetUnsafe, ) -> Result { - let id = match target { + let wgpu_surface = match target { SurfaceTargetUnsafe::RawHandle { raw_display_handle, raw_window_handle, - } => unsafe { - self.0 - .instance_create_surface(raw_display_handle, raw_window_handle, None) - }, + } => unsafe { self.0.create_surface(raw_display_handle, raw_window_handle) }, #[cfg(all(drm, not(target_os = "netbsd")))] SurfaceTargetUnsafe::Drm { @@ -808,20 +834,13 @@ impl dispatch::InstanceInterface for ContextWgpuCore { height, refresh_rate, } => unsafe { - self.0.instance_create_surface_from_drm( - fd, - plane, - connector_id, - width, - height, - refresh_rate, - None, - ) + self.0 + .create_surface_from_drm(fd, plane, connector_id, width, height, refresh_rate) }, #[cfg(metal)] SurfaceTargetUnsafe::CoreAnimationLayer(layer) => unsafe { - self.0.instance_create_surface_metal(layer, None) + self.0.create_surface_metal(layer) }, #[cfg(all(drm, target_os = "netbsd"))] @@ -831,25 +850,24 @@ impl dispatch::InstanceInterface for ContextWgpuCore { #[cfg(dx12)] SurfaceTargetUnsafe::CompositionVisual(visual) => unsafe { - self.0.instance_create_surface_from_visual(visual, None) + self.0.create_surface_from_visual(visual) }, #[cfg(dx12)] SurfaceTargetUnsafe::SurfaceHandle(surface_handle) => unsafe { - self.0 - .instance_create_surface_from_surface_handle(surface_handle, None) + self.0.create_surface_from_surface_handle(surface_handle) }, #[cfg(dx12)] SurfaceTargetUnsafe::SwapChainPanel(swap_chain_panel) => unsafe { self.0 - .instance_create_surface_from_swap_chain_panel(swap_chain_panel, None) + .create_surface_from_swap_chain_panel(swap_chain_panel) }, }?; Ok(CoreSurface { context: self.clone(), - id, + wgpu_surface, configured_device: Mutex::default(), error_sink: Mutex::default(), } @@ -860,22 +878,21 @@ impl dispatch::InstanceInterface for ContextWgpuCore { &self, options: &crate::api::RequestAdapterOptions<'_, '_>, ) -> Pin> { - let id = self.0.request_adapter( - &wgc::instance::RequestAdapterOptions { + let adapter = self.0.request_adapter( + &wgt::RequestAdapterOptions { power_preference: options.power_preference, force_fallback_adapter: options.force_fallback_adapter, compatible_surface: options .compatible_surface - .map(|surface| surface.inner.as_core().id), + .map(|surface| &*surface.inner.as_core().wgpu_surface), apply_limit_buckets: false, }, wgt::Backends::all(), - None, ); - let adapter = id.map(|id| { + let adapter = adapter.map(|wgpu_adapter| { let core = CoreAdapter { context: self.clone(), - id, + wgpu_adapter, }; let generic: dispatch::DispatchAdapter = core.into(); generic @@ -924,7 +941,7 @@ impl dispatch::InstanceInterface for ContextWgpuCore { .map(|adapter| { let core = crate::backend::wgpu_core::CoreAdapter { context: self.clone(), - id: adapter, + wgpu_adapter: adapter, }; core.into() }) @@ -938,13 +955,10 @@ impl dispatch::AdapterInterface for CoreAdapter { &self, desc: &crate::DeviceDescriptor<'_>, ) -> Pin> { - let res = self.context.0.adapter_request_device( - self.id, - &desc.map_label(|l| l.map(Borrowed)), - None, - None, - ); - let (device_id, queue_id) = match res { + let res = self + .wgpu_adapter + .request_device(&desc.map_label(|l| l.map(Borrowed))); + let (device, queue) = match res { Ok(ids) => ids, Err(err) => { return Box::pin(ready(Err(err.into()))); @@ -953,13 +967,13 @@ impl dispatch::AdapterInterface for CoreAdapter { let error_sink = Arc::new(Mutex::new(ErrorSinkRaw::new())); let device = CoreDevice { context: self.context.clone(), - id: device_id, + wgpu_device: device, error_sink: error_sink.clone(), features: desc.required_features, }; let queue = CoreQueue { context: self.context.clone(), - id: queue_id, + wgpu_queue: queue, error_sink, }; Box::pin(ready(Ok((device.into(), queue.into())))) @@ -968,64 +982,57 @@ impl dispatch::AdapterInterface for CoreAdapter { fn is_surface_supported(&self, surface: &dispatch::DispatchSurface) -> bool { let surface = surface.as_core(); - self.context - .0 - .adapter_is_surface_supported(self.id, surface.id) + self.wgpu_adapter + .is_surface_supported(&surface.wgpu_surface) } fn features(&self) -> crate::Features { - self.context.0.adapter_features(self.id) + self.wgpu_adapter.features() } fn limits(&self) -> crate::Limits { - self.context.0.adapter_limits(self.id) + self.wgpu_adapter.limits() } fn downlevel_capabilities(&self) -> crate::DownlevelCapabilities { - self.context.0.adapter_downlevel_capabilities(self.id) + self.wgpu_adapter.downlevel_capabilities() } fn get_info(&self) -> crate::AdapterInfo { - self.context.0.adapter_get_info(self.id) + self.wgpu_adapter.get_info() } fn get_texture_format_features( &self, format: crate::TextureFormat, ) -> crate::TextureFormatFeatures { - self.context - .0 - .adapter_get_texture_format_features(self.id, format) + self.wgpu_adapter.get_texture_format_features(format) } fn get_presentation_timestamp(&self) -> crate::PresentationTimestamp { - self.context.0.adapter_get_presentation_timestamp(self.id) + self.wgpu_adapter.get_presentation_timestamp() } fn cooperative_matrix_properties(&self) -> Vec { - self.context - .0 - .adapter_cooperative_matrix_properties(self.id) + self.wgpu_adapter.cooperative_matrix_properties() } } impl Drop for CoreAdapter { - fn drop(&mut self) { - self.context.0.adapter_drop(self.id) - } + fn drop(&mut self) {} } impl dispatch::DeviceInterface for CoreDevice { fn features(&self) -> crate::Features { - self.context.0.device_features(self.id) + *self.wgpu_device.features() } fn limits(&self) -> crate::Limits { - self.context.0.device_limits(self.id) + self.wgpu_device.limits().clone() } fn adapter_info(&self) -> crate::AdapterInfo { - self.context.0.device_adapter_info(self.id) + self.wgpu_device.adapter_info() } // If we have no way to create a shader module, we can't return one, and so most of the function is unreachable. @@ -1079,10 +1086,8 @@ impl dispatch::DeviceInterface for CoreDevice { ShaderSource::Naga(module) => wgc::pipeline::ShaderModuleSource::Naga(module), ShaderSource::Dummy(_) => panic!("found `ShaderSource::Dummy`"), }; - let (id, error) = - self.context - .0 - .device_create_shader_module(self.id, &descriptor, source, None); + let (wgpu_shader_module, error) = + self.wgpu_device.create_shader_module(&descriptor, source); let compilation_info = match error { Some(cause) => { self.context.handle_error( @@ -1097,8 +1102,7 @@ impl dispatch::DeviceInterface for CoreDevice { }; CoreShaderModule { - context: self.context.clone(), - id, + wgpu_shader_module, compilation_info, } .into() @@ -1109,11 +1113,8 @@ impl dispatch::DeviceInterface for CoreDevice { desc: &crate::ShaderModuleDescriptorPassthrough<'_>, ) -> dispatch::DispatchShaderModule { let desc = desc.map_label(|l| l.map(Cow::from)); - let (id, error) = unsafe { - self.context - .0 - .device_create_shader_module_passthrough(self.id, &desc, None) - }; + let (wgpu_shader_module, error) = + unsafe { self.wgpu_device.create_shader_module_passthrough(&desc) }; let compilation_info = match error { Some(cause) => { @@ -1129,8 +1130,7 @@ impl dispatch::DeviceInterface for CoreDevice { }; CoreShaderModule { - context: self.context.clone(), - id, + wgpu_shader_module, compilation_info, } .into() @@ -1144,10 +1144,8 @@ impl dispatch::DeviceInterface for CoreDevice { label: desc.label.map(Borrowed), entries: Borrowed(desc.entries), }; - let (id, error) = - self.context - .0 - .device_create_bind_group_layout(self.id, &descriptor, None); + let (wgpu_bind_group_layout, error) = + self.wgpu_device.create_bind_group_layout(&descriptor); if let Some(cause) = error { self.context.handle_error( &self.error_sink, @@ -1157,8 +1155,7 @@ impl dispatch::DeviceInterface for CoreDevice { ); } CoreBindGroupLayout { - context: self.context.clone(), - id, + wgpu_bind_group_layout, } .into() } @@ -1172,13 +1169,21 @@ impl dispatch::DeviceInterface for CoreDevice { let mut arrayed_texture_views = Vec::new(); let mut arrayed_samplers = Vec::new(); if self.features.contains(Features::TEXTURE_BINDING_ARRAY) { - // gather all the array view IDs first + // gather all the array view first for entry in desc.entries.iter() { if let BindingResource::TextureViewArray(array) = entry.resource { - arrayed_texture_views.extend(array.iter().map(|view| view.inner.as_core().id)); + arrayed_texture_views.extend( + array + .iter() + .map(|view| view.inner.as_core().wgpu_texture_view.clone()), + ); } if let BindingResource::SamplerArray(array) = entry.resource { - arrayed_samplers.extend(array.iter().map(|sampler| sampler.inner.as_core().id)); + arrayed_samplers.extend( + array + .iter() + .map(|sampler| sampler.inner.as_core().wgpu_sampler.clone()), + ); } } } @@ -1191,7 +1196,7 @@ impl dispatch::DeviceInterface for CoreDevice { for entry in desc.entries.iter() { if let BindingResource::BufferArray(array) = entry.resource { arrayed_buffer_bindings.extend(array.iter().map(|binding| bm::BufferBinding { - buffer: binding.buffer.inner.as_core().id, + buffer: binding.buffer.inner.as_core().wgpu_buffer.clone(), offset: binding.offset, size: binding.size.map(wgt::BufferSize::get), })); @@ -1208,8 +1213,11 @@ impl dispatch::DeviceInterface for CoreDevice { // Gather all the TLAS IDs used by TLAS arrays first (same pattern as other arrayed resources). for entry in desc.entries.iter() { if let BindingResource::AccelerationStructureArray(array) = entry.resource { - arrayed_acceleration_structures - .extend(array.iter().map(|tlas| tlas.inner.as_core().id)); + arrayed_acceleration_structures.extend( + array + .iter() + .map(|tlas| tlas.inner.as_core().wgpu_tlas.clone()), + ); } } } @@ -1226,7 +1234,7 @@ impl dispatch::DeviceInterface for CoreDevice { offset, size, }) => bm::BindingResource::Buffer(bm::BufferBinding { - buffer: buffer.inner.as_core().id, + buffer: buffer.inner.as_core().wgpu_buffer.clone(), offset, size: size.map(wgt::BufferSize::get), }), @@ -1237,16 +1245,16 @@ impl dispatch::DeviceInterface for CoreDevice { bm::BindingResource::BufferArray(Borrowed(slice)) } BindingResource::Sampler(sampler) => { - bm::BindingResource::Sampler(sampler.inner.as_core().id) + bm::BindingResource::Sampler(sampler.inner.as_core().wgpu_sampler.clone()) } BindingResource::SamplerArray(array) => { let slice = &remaining_arrayed_samplers[..array.len()]; remaining_arrayed_samplers = &remaining_arrayed_samplers[array.len()..]; bm::BindingResource::SamplerArray(Borrowed(slice)) } - BindingResource::TextureView(texture_view) => { - bm::BindingResource::TextureView(texture_view.inner.as_core().id) - } + BindingResource::TextureView(texture_view) => bm::BindingResource::TextureView( + texture_view.inner.as_core().wgpu_texture_view.clone(), + ), BindingResource::TextureViewArray(array) => { let slice = &remaining_arrayed_texture_views[..array.len()]; remaining_arrayed_texture_views = @@ -1255,7 +1263,7 @@ impl dispatch::DeviceInterface for CoreDevice { } BindingResource::AccelerationStructure(acceleration_structure) => { bm::BindingResource::AccelerationStructure( - acceleration_structure.inner.as_core().id, + acceleration_structure.inner.as_core().wgpu_tlas.clone(), ) } BindingResource::AccelerationStructureArray(array) => { @@ -1265,21 +1273,24 @@ impl dispatch::DeviceInterface for CoreDevice { bm::BindingResource::AccelerationStructureArray(Borrowed(slice)) } BindingResource::ExternalTexture(external_texture) => { - bm::BindingResource::ExternalTexture(external_texture.inner.as_core().id) + bm::BindingResource::ExternalTexture( + external_texture + .inner + .as_core() + .wgpu_external_texture + .clone(), + ) } }, }) .collect::>(); let descriptor = bm::BindGroupDescriptor { label: desc.label.as_ref().map(|label| Borrowed(&label[..])), - layout: desc.layout.inner.as_core().id, + layout: desc.layout.inner.as_core().wgpu_bind_group_layout.clone(), entries: Borrowed(&entries), }; - let (id, error) = self - .context - .0 - .device_create_bind_group(self.id, &descriptor, None); + let (wgpu_bind_group, error) = self.wgpu_device.create_bind_group(&descriptor); if let Some(cause) = error { self.context.handle_error( &self.error_sink, @@ -1288,11 +1299,7 @@ impl dispatch::DeviceInterface for CoreDevice { "Device::create_bind_group", ); } - CoreBindGroup { - context: self.context.clone(), - id, - } - .into() + CoreBindGroup { wgpu_bind_group }.into() } fn create_pipeline_layout( @@ -1311,7 +1318,7 @@ impl dispatch::DeviceInterface for CoreDevice { let temp_layouts = desc .bind_group_layouts .iter() - .map(|bgl| bgl.map(|bgl| bgl.inner.as_core().id)) + .map(|bgl| bgl.map(|bgl| bgl.inner.as_core().wgpu_bind_group_layout.clone())) .collect::>(); let descriptor = wgc::binding_model::PipelineLayoutDescriptor { label: desc.label.map(Borrowed), @@ -1319,10 +1326,7 @@ impl dispatch::DeviceInterface for CoreDevice { immediate_size: desc.immediate_size, }; - let (id, error) = self - .context - .0 - .device_create_pipeline_layout(self.id, &descriptor, None); + let (wgpu_pipeline_layout, error) = self.wgpu_device.create_pipeline_layout(&descriptor); if let Some(cause) = error { self.context.handle_error( &self.error_sink, @@ -1332,8 +1336,7 @@ impl dispatch::DeviceInterface for CoreDevice { ); } CorePipelineLayout { - context: self.context.clone(), - id, + wgpu_pipeline_layout, } .into() } @@ -1365,12 +1368,20 @@ impl dispatch::DeviceInterface for CoreDevice { .map(|&(key, value)| (String::from(key), value)) .collect(); - let descriptor = pipe::RenderPipelineDescriptor { + let descriptor = pipe::ResolvedGeneralRenderPipelineDescriptor { label: desc.label.map(Borrowed), - layout: desc.layout.map(|layout| layout.inner.as_core().id), - vertex: pipe::VertexState { + layout: desc + .layout + .map(|layout| layout.inner.as_core().wgpu_pipeline_layout.clone()), + vertex: wgc::pipeline::RenderPipelineVertexProcessor::Vertex(pipe::VertexState { stage: pipe::ProgrammableStageDescriptor { - module: desc.vertex.module.inner.as_core().id, + module: desc + .vertex + .module + .inner + .as_core() + .wgpu_shader_module + .clone(), entry_point: desc.vertex.entry_point.map(Borrowed), constants: vert_constants, zero_initialize_workgroup_memory: desc @@ -1379,7 +1390,7 @@ impl dispatch::DeviceInterface for CoreDevice { .zero_initialize_workgroup_memory, }, buffers: Borrowed(&vertex_buffers), - }, + }), primitive: desc.primitive, depth_stencil: desc.depth_stencil.clone(), multisample: desc.multisample, @@ -1392,7 +1403,7 @@ impl dispatch::DeviceInterface for CoreDevice { .collect(); pipe::FragmentState { stage: pipe::ProgrammableStageDescriptor { - module: frag.module.inner.as_core().id, + module: frag.module.inner.as_core().wgpu_shader_module.clone(), entry_point: frag.entry_point.map(Borrowed), constants: frag_constants, zero_initialize_workgroup_memory: frag @@ -1403,13 +1414,12 @@ impl dispatch::DeviceInterface for CoreDevice { } }), multiview_mask: desc.multiview_mask, - cache: desc.cache.map(|cache| cache.inner.as_core().id), + cache: desc + .cache + .map(|cache| cache.inner.as_core().wgpu_pipeline_cache.clone()), }; - let (id, error) = self - .context - .0 - .device_create_render_pipeline(self.id, &descriptor, None); + let (wgpu_render_pipeline, error) = self.wgpu_device.create_render_pipeline(descriptor); if let Some(cause) = error { if let wgc::pipeline::CreateRenderPipelineError::Internal { stage, ref error } = cause { log::error!("Shader translation error for stage {stage:?}: {error}"); @@ -1424,7 +1434,7 @@ impl dispatch::DeviceInterface for CoreDevice { } CoreRenderPipeline { context: self.context.clone(), - id, + wgpu_render_pipeline, error_sink: Arc::clone(&self.error_sink), } .into() @@ -1454,7 +1464,7 @@ impl dispatch::DeviceInterface for CoreDevice { .collect(); pipe::TaskState { stage: pipe::ProgrammableStageDescriptor { - module: task.module.inner.as_core().id, + module: task.module.inner.as_core().wgpu_shader_module.clone(), entry_point: task.entry_point.map(Borrowed), constants: task_constants, zero_initialize_workgroup_memory: desc @@ -1466,7 +1476,7 @@ impl dispatch::DeviceInterface for CoreDevice { }), mesh: pipe::MeshState { stage: pipe::ProgrammableStageDescriptor { - module: desc.mesh.module.inner.as_core().id, + module: desc.mesh.module.inner.as_core().wgpu_shader_module.clone(), entry_point: desc.mesh.entry_point.map(Borrowed), constants: mesh_constants, zero_initialize_workgroup_memory: desc @@ -1475,7 +1485,9 @@ impl dispatch::DeviceInterface for CoreDevice { .zero_initialize_workgroup_memory, }, }, - layout: desc.layout.map(|layout| layout.inner.as_core().id), + layout: desc + .layout + .map(|layout| layout.inner.as_core().wgpu_pipeline_layout.clone()), primitive: desc.primitive, depth_stencil: desc.depth_stencil.clone(), multisample: desc.multisample, @@ -1488,7 +1500,7 @@ impl dispatch::DeviceInterface for CoreDevice { .collect(); pipe::FragmentState { stage: pipe::ProgrammableStageDescriptor { - module: frag.module.inner.as_core().id, + module: frag.module.inner.as_core().wgpu_shader_module.clone(), entry_point: frag.entry_point.map(Borrowed), constants: frag_constants, zero_initialize_workgroup_memory: frag @@ -1499,13 +1511,13 @@ impl dispatch::DeviceInterface for CoreDevice { } }), multiview: desc.multiview, - cache: desc.cache.map(|cache| cache.inner.as_core().id), + cache: desc + .cache + .map(|cache| cache.inner.as_core().wgpu_pipeline_cache.clone()), }; - let (id, error) = self - .context - .0 - .device_create_mesh_pipeline(self.id, &descriptor, None); + let (wgpu_render_pipeline, error) = + self.wgpu_device.create_render_pipeline(descriptor.into()); if let Some(cause) = error { if let wgc::pipeline::CreateRenderPipelineError::Internal { stage, ref error } = cause { log::error!("Shader translation error for stage {stage:?}: {error}"); @@ -1520,7 +1532,7 @@ impl dispatch::DeviceInterface for CoreDevice { } CoreRenderPipeline { context: self.context.clone(), - id, + wgpu_render_pipeline, error_sink: Arc::clone(&self.error_sink), } .into() @@ -1541,22 +1553,23 @@ impl dispatch::DeviceInterface for CoreDevice { let descriptor = pipe::ComputePipelineDescriptor { label: desc.label.map(Borrowed), - layout: desc.layout.map(|pll| pll.inner.as_core().id), + layout: desc + .layout + .map(|pll| pll.inner.as_core().wgpu_pipeline_layout.clone()), stage: pipe::ProgrammableStageDescriptor { - module: desc.module.inner.as_core().id, + module: desc.module.inner.as_core().wgpu_shader_module.clone(), entry_point: desc.entry_point.map(Borrowed), constants, zero_initialize_workgroup_memory: desc .compilation_options .zero_initialize_workgroup_memory, }, - cache: desc.cache.map(|cache| cache.inner.as_core().id), + cache: desc + .cache + .map(|cache| cache.inner.as_core().wgpu_pipeline_cache.clone()), }; - let (id, error) = self - .context - .0 - .device_create_compute_pipeline(self.id, &descriptor, None); + let (wgpu_compute_pipeline, error) = self.wgpu_device.create_compute_pipeline(descriptor); if let Some(cause) = error { if let wgc::pipeline::CreateComputePipelineError::Internal(ref error) = cause { log::error!( @@ -1575,7 +1588,7 @@ impl dispatch::DeviceInterface for CoreDevice { } CoreComputePipeline { context: self.context.clone(), - id, + wgpu_compute_pipeline, error_sink: Arc::clone(&self.error_sink), } .into() @@ -1592,11 +1605,8 @@ impl dispatch::DeviceInterface for CoreDevice { data: desc.data.map(Borrowed), fallback: desc.fallback, }; - let (id, error) = unsafe { - self.context - .0 - .device_create_pipeline_cache(self.id, &descriptor, None) - }; + let (wgpu_pipeline_cache, error) = + unsafe { self.wgpu_device.create_pipeline_cache(&descriptor) }; if let Some(cause) = error { self.context.handle_error( &self.error_sink, @@ -1606,18 +1616,15 @@ impl dispatch::DeviceInterface for CoreDevice { ); } CorePipelineCache { - context: self.context.clone(), - id, + wgpu_pipeline_cache, } .into() } fn create_buffer(&self, desc: &crate::BufferDescriptor<'_>) -> dispatch::DispatchBuffer { - let (id, error) = self.context.0.device_create_buffer( - self.id, - &desc.map_label(|l| l.map(Borrowed)), - None, - ); + let (wgpu_buffer, error) = self + .wgpu_device + .create_buffer(&desc.map_label(|l| l.map(Borrowed))); if let Some(cause) = error { self.context .handle_error(&self.error_sink, cause, desc.label, "Device::create_buffer"); @@ -1625,7 +1632,7 @@ impl dispatch::DeviceInterface for CoreDevice { CoreBuffer { context: self.context.clone(), - id, + wgpu_buffer, error_sink: Arc::clone(&self.error_sink), } .into() @@ -1633,10 +1640,7 @@ impl dispatch::DeviceInterface for CoreDevice { fn create_texture(&self, desc: &crate::TextureDescriptor<'_>) -> dispatch::DispatchTexture { let wgt_desc = desc.map_label_and_view_formats(|l| l.map(Borrowed), |v| v.to_vec()); - let (id, error) = self - .context - .0 - .device_create_texture(self.id, &wgt_desc, None); + let (wgpu_texture, error) = self.wgpu_device.create_texture(&wgt_desc); if let Some(cause) = error { self.context.handle_error( &self.error_sink, @@ -1648,7 +1652,7 @@ impl dispatch::DeviceInterface for CoreDevice { CoreTexture { context: self.context.clone(), - id, + wgpu_texture, error_sink: Arc::clone(&self.error_sink), } .into() @@ -1662,12 +1666,10 @@ impl dispatch::DeviceInterface for CoreDevice { let wgt_desc = desc.map_label(|l| l.map(Borrowed)); let planes = planes .iter() - .map(|plane| plane.inner.as_core().id) + .map(|plane| plane.inner.as_core().wgpu_texture_view.clone()) .collect::>(); - let (id, error) = self - .context - .0 - .device_create_external_texture(self.id, &wgt_desc, &planes, None); + let (wgpu_external_texture, error) = + self.wgpu_device.create_external_texture(&wgt_desc, &planes); if let Some(cause) = error { self.context.handle_error( &self.error_sink, @@ -1678,8 +1680,7 @@ impl dispatch::DeviceInterface for CoreDevice { } CoreExternalTexture { - context: self.context.clone(), - id, + wgpu_external_texture, } .into() } @@ -1689,18 +1690,18 @@ impl dispatch::DeviceInterface for CoreDevice { desc: &crate::CreateBlasDescriptor<'_>, sizes: crate::BlasGeometrySizeDescriptors, ) -> (Option, dispatch::DispatchBlas) { - let global = &self.context.0; - let (id, handle, error) = - global.device_create_blas(self.id, &desc.map_label(|l| l.map(Borrowed)), sizes, None); + let (wgpu_blas, error) = self + .wgpu_device + .create_blas(&desc.map_label(|l| l.map(Borrowed)), sizes); if let Some(cause) = error { self.context .handle_error(&self.error_sink, cause, desc.label, "Device::create_blas"); } ( - handle, + wgpu_blas.handle(), CoreBlas { context: self.context.clone(), - id, + wgpu_blas, error_sink: Arc::clone(&self.error_sink), } .into(), @@ -1708,16 +1709,16 @@ impl dispatch::DeviceInterface for CoreDevice { } fn create_tlas(&self, desc: &crate::CreateTlasDescriptor<'_>) -> dispatch::DispatchTlas { - let global = &self.context.0; - let (id, error) = - global.device_create_tlas(self.id, &desc.map_label(|l| l.map(Borrowed)), None); + let (wgpu_tlas, error) = self + .wgpu_device + .create_tlas(&desc.map_label(|l| l.map(Borrowed))); if let Some(cause) = error { self.context .handle_error(&self.error_sink, cause, desc.label, "Device::create_tlas"); } CoreTlas { context: self.context.clone(), - id, + wgpu_tlas, // error_sink: Arc::clone(&self.error_sink), } .into() @@ -1741,10 +1742,7 @@ impl dispatch::DeviceInterface for CoreDevice { border_color: desc.border_color, }; - let (id, error) = self - .context - .0 - .device_create_sampler(self.id, &descriptor, None); + let (wgpu_sampler, error) = self.wgpu_device.create_sampler(&descriptor); if let Some(cause) = error { self.context.handle_error( &self.error_sink, @@ -1753,39 +1751,27 @@ impl dispatch::DeviceInterface for CoreDevice { "Device::create_sampler", ); } - CoreSampler { - context: self.context.clone(), - id, - } - .into() + CoreSampler { wgpu_sampler }.into() } fn create_query_set(&self, desc: &crate::QuerySetDescriptor<'_>) -> dispatch::DispatchQuerySet { - let (id, error) = self.context.0.device_create_query_set( - self.id, - &desc.map_label(|l| l.map(Borrowed)), - None, - ); + let (wgpu_query_set, error) = self + .wgpu_device + .create_query_set(&desc.map_label(|l| l.map(Borrowed))); if let Some(cause) = error { self.context .handle_error_nolabel(&self.error_sink, cause, "Device::create_query_set"); } - CoreQuerySet { - context: self.context.clone(), - id, - } - .into() + CoreQuerySet { wgpu_query_set }.into() } fn create_command_encoder( &self, desc: &crate::CommandEncoderDescriptor<'_>, ) -> dispatch::DispatchCommandEncoder { - let (id, error) = self.context.0.device_create_command_encoder( - self.id, - &desc.map_label(|l| l.map(Borrowed)), - None, - ); + let (wgpu_command_encoder, error) = self + .wgpu_device + .create_command_encoder(&desc.map_label(|l| l.map(Borrowed))); if let Some(cause) = error { self.context.handle_error( &self.error_sink, @@ -1797,7 +1783,7 @@ impl dispatch::DeviceInterface for CoreDevice { CoreCommandEncoder { context: self.context.clone(), - id, + wgpu_command_encoder, error_sink: Arc::clone(&self.error_sink), } .into() @@ -1814,10 +1800,7 @@ impl dispatch::DeviceInterface for CoreDevice { sample_count: desc.sample_count, multiview: desc.multiview, }; - let (encoder, error) = self - .context - .0 - .device_create_render_bundle_encoder(self.id, &descriptor); + let (encoder, error) = self.wgpu_device.create_render_bundle_encoder(&descriptor); if let Some(cause) = error { self.context.handle_error( &self.error_sink, @@ -1831,15 +1814,13 @@ impl dispatch::DeviceInterface for CoreDevice { context: self.context.clone(), error_sink: Arc::clone(&self.error_sink), encoder, - id: crate::cmp::Identifier::create(), } .into() } fn set_device_lost_callback(&self, device_lost_callback: dispatch::BoxDeviceLostCallback) { - self.context - .0 - .device_set_device_lost_closure(self.id, device_lost_callback); + self.wgpu_device + .set_device_lost_closure(device_lost_callback); } fn on_uncaptured_error(&self, handler: Arc) { @@ -1903,23 +1884,15 @@ impl dispatch::DeviceInterface for CoreDevice { } unsafe fn start_graphics_debugger_capture(&self) { - unsafe { - self.context - .0 - .device_start_graphics_debugger_capture(self.id) - }; + unsafe { self.wgpu_device.start_graphics_debugger_capture() }; } unsafe fn stop_graphics_debugger_capture(&self) { - unsafe { - self.context - .0 - .device_stop_graphics_debugger_capture(self.id) - }; + unsafe { self.wgpu_device.stop_graphics_debugger_capture() }; } fn poll(&self, poll_type: wgt::PollType) -> Result { - match self.context.0.device_poll(self.id, poll_type) { + match self.wgpu_device.poll(poll_type) { Ok(status) => Ok(status), Err(err) => { if let Some(poll_error) = err.to_poll_error() { @@ -1932,22 +1905,20 @@ impl dispatch::DeviceInterface for CoreDevice { } fn get_internal_counters(&self) -> crate::InternalCounters { - self.context.0.device_get_internal_counters(self.id) + self.wgpu_device.get_internal_counters() } fn generate_allocator_report(&self) -> Option { - self.context.0.device_generate_allocator_report(self.id) + self.wgpu_device.generate_allocator_report() } fn destroy(&self) { - self.context.0.device_destroy(self.id); + self.wgpu_device.destroy(); } } impl Drop for CoreDevice { - fn drop(&mut self) { - self.context.0.device_drop(self.id) - } + fn drop(&mut self) {} } impl dispatch::QueueInterface for CoreQueue { @@ -1960,9 +1931,8 @@ impl dispatch::QueueInterface for CoreQueue { let buffer = buffer.as_core(); match self - .context - .0 - .queue_write_buffer(self.id, buffer.id, offset, data) + .wgpu_queue + .write_buffer(buffer.wgpu_buffer.clone(), offset, data) { Ok(()) => (), Err(err) => { @@ -1976,14 +1946,10 @@ impl dispatch::QueueInterface for CoreQueue { &self, size: crate::BufferSize, ) -> Option { - match self - .context - .0 - .queue_create_staging_buffer(self.id, size, None) - { - Ok((buffer_id, ptr)) => Some( + match self.wgpu_queue.create_staging_buffer(size) { + Ok((wgpu_staging_buffer, ptr)) => Some( CoreQueueWriteBuffer { - buffer_id, + wgpu_staging_buffer, mapping: CoreBufferMappedRange { ptr, size: size.get() as usize, @@ -2011,9 +1977,8 @@ impl dispatch::QueueInterface for CoreQueue { let buffer = buffer.as_core(); match self - .context - .0 - .queue_validate_write_buffer(self.id, buffer.id, offset, size) + .wgpu_queue + .validate_write_buffer(buffer.wgpu_buffer.clone(), offset, size) { Ok(()) => Some(()), Err(err) => { @@ -2034,13 +1999,20 @@ impl dispatch::QueueInterface for CoreQueue { staging_buffer: dispatch::DispatchQueueWriteBuffer, ) { let buffer = buffer.as_core(); - let staging_buffer = staging_buffer.as_core(); + let staging_buffer = { + match staging_buffer { + dispatch::DispatchQueueWriteBuffer::Core(value) => value, + _ => panic!(concat!( + stringify!(DispatchQueueWriteBuffer), + " is not core" + )), + } + }; - match self.context.0.queue_write_staging_buffer( - self.id, - buffer.id, + match self.wgpu_queue.write_staging_buffer( + buffer.wgpu_buffer.clone(), offset, - staging_buffer.buffer_id, + staging_buffer.wgpu_staging_buffer, ) { Ok(()) => (), Err(err) => { @@ -2060,9 +2032,8 @@ impl dispatch::QueueInterface for CoreQueue { data_layout: crate::TexelCopyBufferLayout, size: crate::Extent3d, ) { - match self.context.0.queue_write_texture( - self.id, - &map_texture_copy_view(texture), + match self.wgpu_queue.write_texture( + map_texture_copy_view(texture), data, &data_layout, &size, @@ -2086,8 +2057,7 @@ impl dispatch::QueueInterface for CoreQueue { size: crate::Extent3d, ) { #[cfg(webgl)] - match self.context.0.queue_copy_external_image_to_texture( - self.id, + match self.wgpu_queue.copy_external_image_to_texture( source, map_texture_tagged_copy_view(dest), size, @@ -2106,12 +2076,12 @@ impl dispatch::QueueInterface for CoreQueue { command_buffers: &mut dyn Iterator, ) -> u64 { let temp_command_buffers = command_buffers.collect::>(); - let command_buffer_ids = temp_command_buffers + let command_buffers = temp_command_buffers .iter() - .map(|cmdbuf| cmdbuf.as_core().id) + .map(|cmdbuf| cmdbuf.as_core().wgpu_command_buffer.clone()) .collect::>(); - let index = match self.context.0.queue_submit(self.id, &command_buffer_ids) { + let index = match self.wgpu_queue.submit(&command_buffers) { Ok(index) => index, Err((index, err)) => { self.context @@ -2126,30 +2096,25 @@ impl dispatch::QueueInterface for CoreQueue { } fn get_timestamp_period(&self) -> f32 { - self.context.0.queue_get_timestamp_period(self.id) + self.wgpu_queue.get_timestamp_period() } fn on_submitted_work_done(&self, callback: dispatch::BoxSubmittedWorkDoneCallback) { - self.context - .0 - .queue_on_submitted_work_done(self.id, callback); + self.wgpu_queue.on_submitted_work_done(callback); } fn compact_blas(&self, blas: &dispatch::DispatchBlas) -> (Option, dispatch::DispatchBlas) { - let (id, handle, error) = - self.context - .0 - .queue_compact_blas(self.id, blas.as_core().id, None); + let (wgpu_blas, error) = self.wgpu_queue.compact_blas(&blas.as_core().wgpu_blas); if let Some(cause) = error { self.context .handle_error_nolabel(&self.error_sink, cause, "Queue::compact_blas"); } ( - handle, + wgpu_blas.handle(), CoreBlas { context: self.context.clone(), - id, + wgpu_blas, error_sink: Arc::clone(&self.error_sink), } .into(), @@ -2158,7 +2123,7 @@ impl dispatch::QueueInterface for CoreQueue { fn present(&self, detail: &dispatch::DispatchSurfaceOutputDetail) { let detail = detail.as_core(); - match self.context.0.surface_present(detail.surface_id) { + match detail.wgpu_surface.present() { Ok(_status) => (), Err(err) => { self.context @@ -2168,68 +2133,26 @@ impl dispatch::QueueInterface for CoreQueue { } } -impl Drop for CoreQueue { - fn drop(&mut self) { - self.context.0.queue_drop(self.id) - } -} - impl dispatch::ShaderModuleInterface for CoreShaderModule { fn get_compilation_info(&self) -> Pin> { Box::pin(ready(self.compilation_info.clone())) } } -impl Drop for CoreShaderModule { - fn drop(&mut self) { - self.context.0.shader_module_drop(self.id) - } -} - impl dispatch::BindGroupLayoutInterface for CoreBindGroupLayout {} -impl Drop for CoreBindGroupLayout { - fn drop(&mut self) { - self.context.0.bind_group_layout_drop(self.id) - } -} - impl dispatch::BindGroupInterface for CoreBindGroup {} -impl Drop for CoreBindGroup { - fn drop(&mut self) { - self.context.0.bind_group_drop(self.id) - } -} - impl dispatch::TextureViewInterface for CoreTextureView {} -impl Drop for CoreTextureView { - fn drop(&mut self) { - self.context.0.texture_view_drop(self.id); - } -} - impl dispatch::ExternalTextureInterface for CoreExternalTexture { fn destroy(&self) { - self.context.0.external_texture_destroy(self.id); - } -} - -impl Drop for CoreExternalTexture { - fn drop(&mut self) { - self.context.0.external_texture_drop(self.id); + self.wgpu_external_texture.destroy(); } } impl dispatch::SamplerInterface for CoreSampler {} -impl Drop for CoreSampler { - fn drop(&mut self) { - self.context.0.sampler_drop(self.id) - } -} - impl dispatch::BufferInterface for CoreBuffer { fn map_async( &self, @@ -2248,12 +2171,10 @@ impl dispatch::BufferInterface for CoreBuffer { })), }; - match self.context.0.buffer_map_async( - self.id, - range.start, - Some(range.end - range.start), - operation, - ) { + match self + .wgpu_buffer + .map_async(range.start, Some(range.end - range.start), operation) + { Ok(_) => (), Err(cause) => { self.context @@ -2267,9 +2188,8 @@ impl dispatch::BufferInterface for CoreBuffer { sub_range: Range, ) -> Result { let size = sub_range.end - sub_range.start; - self.context - .0 - .buffer_get_mapped_range(self.id, sub_range.start, Some(size)) + self.wgpu_buffer + .get_mapped_range(sub_range.start, Some(size)) .map(|(ptr, size)| { CoreBufferMappedRange { ptr, @@ -2281,7 +2201,7 @@ impl dispatch::BufferInterface for CoreBuffer { } fn unmap(&self) { - match self.context.0.buffer_unmap(self.id) { + match self.wgpu_buffer.unmap() { Ok(()) => (), Err(cause) => { self.context @@ -2291,13 +2211,7 @@ impl dispatch::BufferInterface for CoreBuffer { } fn destroy(&self) { - self.context.0.buffer_destroy(self.id); - } -} - -impl Drop for CoreBuffer { - fn drop(&mut self) { - self.context.0.buffer_drop(self.id) + self.wgpu_buffer.destroy(); } } @@ -2319,29 +2233,20 @@ impl dispatch::TextureInterface for CoreTexture { array_layer_count: desc.array_layer_count, }, }; - let (id, error) = self - .context - .0 - .texture_create_view(self.id, &descriptor, None); + let (wgpu_texture_view, error) = self.wgpu_texture.create_view(&descriptor); if let Some(cause) = error { self.context .handle_error(&self.error_sink, cause, desc.label, "Texture::create_view"); } CoreTextureView { context: self.context.clone(), - id, + wgpu_texture_view, } .into() } fn destroy(&self) { - self.context.0.texture_destroy(self.id); - } -} - -impl Drop for CoreTexture { - fn drop(&mut self) { - self.context.0.texture_drop(self.id) + self.wgpu_texture.destroy(); } } @@ -2353,7 +2258,7 @@ impl dispatch::BlasInterface for CoreBlas { callback(res); })); - match self.context.0.blas_prepare_compact_async(self.id, callback) { + match self.wgpu_blas.prepare_compact_async(callback) { Ok(_) => (), Err(cause) => self.context.handle_error_nolabel( &self.error_sink, @@ -2364,7 +2269,7 @@ impl dispatch::BlasInterface for CoreBlas { } fn ready_for_compaction(&self) -> bool { - match self.context.0.ready_for_compaction(self.id) { + match self.wgpu_blas.ready_for_compaction() { Ok(ready) => ready, Err(cause) => { self.context.handle_error_nolabel( @@ -2379,46 +2284,20 @@ impl dispatch::BlasInterface for CoreBlas { } } -impl Drop for CoreBlas { - fn drop(&mut self) { - self.context.0.blas_drop(self.id) - } -} - impl dispatch::TlasInterface for CoreTlas {} -impl Drop for CoreTlas { - fn drop(&mut self) { - self.context.0.tlas_drop(self.id) - } -} - impl dispatch::QuerySetInterface for CoreQuerySet { fn destroy(&self) { - self.context.0.query_set_destroy(self.id); - } -} - -impl Drop for CoreQuerySet { - fn drop(&mut self) { - self.context.0.query_set_drop(self.id) + self.wgpu_query_set.destroy(); } } impl dispatch::PipelineLayoutInterface for CorePipelineLayout {} -impl Drop for CorePipelineLayout { - fn drop(&mut self) { - self.context.0.pipeline_layout_drop(self.id) - } -} - impl dispatch::RenderPipelineInterface for CoreRenderPipeline { fn get_bind_group_layout(&self, index: u32) -> dispatch::DispatchBindGroupLayout { - let (id, error) = self - .context - .0 - .render_pipeline_get_bind_group_layout(self.id, index, None); + let (wgpu_bind_group_layout, error) = + self.wgpu_render_pipeline.get_bind_group_layout(index); if let Some(err) = error { self.context.handle_error_nolabel( &self.error_sink, @@ -2427,25 +2306,16 @@ impl dispatch::RenderPipelineInterface for CoreRenderPipeline { ) } CoreBindGroupLayout { - context: self.context.clone(), - id, + wgpu_bind_group_layout, } .into() } } -impl Drop for CoreRenderPipeline { - fn drop(&mut self) { - self.context.0.render_pipeline_drop(self.id) - } -} - impl dispatch::ComputePipelineInterface for CoreComputePipeline { fn get_bind_group_layout(&self, index: u32) -> dispatch::DispatchBindGroupLayout { - let (id, error) = self - .context - .0 - .compute_pipeline_get_bind_group_layout(self.id, index, None); + let (wgpu_bind_group_layout, error) = + self.wgpu_compute_pipeline.get_bind_group_layout(index); if let Some(err) = error { self.context.handle_error_nolabel( &self.error_sink, @@ -2454,28 +2324,15 @@ impl dispatch::ComputePipelineInterface for CoreComputePipeline { ) } CoreBindGroupLayout { - context: self.context.clone(), - id, + wgpu_bind_group_layout, } .into() } } -impl Drop for CoreComputePipeline { - fn drop(&mut self) { - self.context.0.compute_pipeline_drop(self.id) - } -} - impl dispatch::PipelineCacheInterface for CorePipelineCache { fn get_data(&self) -> Option> { - self.context.0.pipeline_cache_get_data(self.id) - } -} - -impl Drop for CorePipelineCache { - fn drop(&mut self) { - self.context.0.pipeline_cache_drop(self.id) + self.wgpu_pipeline_cache.get_data() } } @@ -2491,11 +2348,10 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { let source = source.as_core(); let destination = destination.as_core(); - if let Err(cause) = self.context.0.command_encoder_copy_buffer_to_buffer( - self.id, - source.id, + if let Err(cause) = self.wgpu_command_encoder.copy_buffer_to_buffer( + source.wgpu_buffer.clone(), source_offset, - destination.id, + destination.wgpu_buffer.clone(), destination_offset, copy_size, ) { @@ -2513,8 +2369,7 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { destination: crate::TexelCopyTextureInfo<'_>, copy_size: crate::Extent3d, ) { - if let Err(cause) = self.context.0.command_encoder_copy_buffer_to_texture( - self.id, + if let Err(cause) = self.wgpu_command_encoder.copy_buffer_to_texture( &map_buffer_copy_view(source), &map_texture_copy_view(destination), ©_size, @@ -2533,8 +2388,7 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { destination: crate::TexelCopyBufferInfo<'_>, copy_size: crate::Extent3d, ) { - if let Err(cause) = self.context.0.command_encoder_copy_texture_to_buffer( - self.id, + if let Err(cause) = self.wgpu_command_encoder.copy_texture_to_buffer( &map_texture_copy_view(source), &map_buffer_copy_view(destination), ©_size, @@ -2553,8 +2407,7 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { destination: crate::TexelCopyTextureInfo<'_>, copy_size: crate::Extent3d, ) { - if let Err(cause) = self.context.0.command_encoder_copy_texture_to_texture( - self.id, + if let Err(cause) = self.wgpu_command_encoder.copy_texture_to_texture( &map_texture_copy_view(source), &map_texture_copy_view(destination), ©_size, @@ -2575,18 +2428,17 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { desc.timestamp_writes .as_ref() .map(|tw| wgc::command::PassTimestampWrites { - query_set: tw.query_set.inner.as_core().id, + query_set: tw.query_set.inner.as_core().wgpu_query_set.clone(), beginning_of_pass_write_index: tw.beginning_of_pass_write_index, end_of_pass_write_index: tw.end_of_pass_write_index, }); - let (pass, err) = self.context.0.command_encoder_begin_compute_pass( - self.id, - &wgc::command::ComputePassDescriptor { - label: desc.label.map(Borrowed), - timestamp_writes, - }, - ); + let (pass, err) = + self.wgpu_command_encoder + .begin_compute_pass(&wgc::command::ComputePassDescriptor { + label: desc.label.map(Borrowed), + timestamp_writes, + }); if let Some(cause) = err { self.context.handle_error( @@ -2616,9 +2468,11 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { .map(|ca| { ca.as_ref() .map(|at| wgc::command::RenderPassColorAttachment { - view: at.view.inner.as_core().id, + view: at.view.inner.as_core().wgpu_texture_view.clone(), depth_slice: at.depth_slice, - resolve_target: at.resolve_target.map(|view| view.inner.as_core().id), + resolve_target: at + .resolve_target + .map(|view| view.inner.as_core().wgpu_texture_view.clone()), load_op: at.ops.load, store_op: at.ops.store, }) @@ -2627,7 +2481,7 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { let depth_stencil = desc.depth_stencil_attachment.as_ref().map(|dsa| { wgc::command::RenderPassDepthStencilAttachment { - view: dsa.view.inner.as_core().id, + view: dsa.view.inner.as_core().wgpu_texture_view.clone(), depth: map_pass_channel(dsa.depth_ops.as_ref()), stencil: map_pass_channel(dsa.stencil_ops.as_ref()), } @@ -2637,19 +2491,20 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { desc.timestamp_writes .as_ref() .map(|tw| wgc::command::PassTimestampWrites { - query_set: tw.query_set.inner.as_core().id, + query_set: tw.query_set.inner.as_core().wgpu_query_set.clone(), beginning_of_pass_write_index: tw.beginning_of_pass_write_index, end_of_pass_write_index: tw.end_of_pass_write_index, }); - let (pass, err) = self.context.0.command_encoder_begin_render_pass( - self.id, - &wgc::command::RenderPassDescriptor { + let (pass, err) = self.wgpu_command_encoder.begin_render_pass( + wgc::command::ResolvedRenderPassDescriptor { label: desc.label.map(Borrowed), timestamp_writes, color_attachments: Borrowed(&colors), depth_stencil_attachment: depth_stencil, - occlusion_query_set: desc.occlusion_query_set.map(|qs| qs.inner.as_core().id), + occlusion_query_set: desc + .occlusion_query_set + .map(|qs| qs.inner.as_core().wgpu_query_set.clone()), multiview_mask: desc.multiview_mask, }, ); @@ -2674,17 +2529,15 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { fn finish(&mut self) -> dispatch::DispatchCommandBuffer { let descriptor = wgt::CommandBufferDescriptor::default(); - let (id, opt_label_and_error) = - self.context - .0 - .command_encoder_finish(self.id, &descriptor, None); + let (wgpu_command_buffer, opt_label_and_error) = + self.wgpu_command_encoder.finish(&descriptor); if let Some((label, cause)) = opt_label_and_error { self.context .handle_error(&self.error_sink, cause, Some(&label), "a CommandEncoder"); } CoreCommandBuffer { context: self.context.clone(), - id, + wgpu_command_buffer, } .into() } @@ -2696,10 +2549,9 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { ) { let texture = texture.as_core(); - if let Err(cause) = - self.context - .0 - .command_encoder_clear_texture(self.id, texture.id, subresource_range) + if let Err(cause) = self + .wgpu_command_encoder + .clear_texture(texture.wgpu_texture.clone(), subresource_range) { self.context.handle_error_nolabel( &self.error_sink, @@ -2717,10 +2569,9 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { ) { let buffer = buffer.as_core(); - if let Err(cause) = self - .context - .0 - .command_encoder_clear_buffer(self.id, buffer.id, offset, size) + if let Err(cause) = + self.wgpu_command_encoder + .clear_buffer(buffer.wgpu_buffer.clone(), offset, size) { self.context.handle_error_nolabel( &self.error_sink, @@ -2731,11 +2582,7 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { } fn insert_debug_marker(&self, label: &str) { - if let Err(cause) = self - .context - .0 - .command_encoder_insert_debug_marker(self.id, label) - { + if let Err(cause) = self.wgpu_command_encoder.insert_debug_marker(label) { self.context.handle_error_nolabel( &self.error_sink, cause, @@ -2745,11 +2592,7 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { } fn push_debug_group(&self, label: &str) { - if let Err(cause) = self - .context - .0 - .command_encoder_push_debug_group(self.id, label) - { + if let Err(cause) = self.wgpu_command_encoder.push_debug_group(label) { self.context.handle_error_nolabel( &self.error_sink, cause, @@ -2759,7 +2602,7 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { } fn pop_debug_group(&self) { - if let Err(cause) = self.context.0.command_encoder_pop_debug_group(self.id) { + if let Err(cause) = self.wgpu_command_encoder.pop_debug_group() { self.context.handle_error_nolabel( &self.error_sink, cause, @@ -2771,10 +2614,9 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { fn write_timestamp(&self, query_set: &dispatch::DispatchQuerySet, query_index: u32) { let query_set = query_set.as_core(); - if let Err(cause) = - self.context - .0 - .command_encoder_write_timestamp(self.id, query_set.id, query_index) + if let Err(cause) = self + .wgpu_command_encoder + .write_timestamp(query_set.wgpu_query_set.clone(), query_index) { self.context.handle_error_nolabel( &self.error_sink, @@ -2795,12 +2637,11 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { let query_set = query_set.as_core(); let destination = destination.as_core(); - if let Err(cause) = self.context.0.command_encoder_resolve_query_set( - self.id, - query_set.id, + if let Err(cause) = self.wgpu_command_encoder.resolve_query_set( + query_set.wgpu_query_set.clone(), first_query, query_count, - destination.id, + destination.wgpu_buffer.clone(), destination_offset, ) { self.context.handle_error_nolabel( @@ -2817,15 +2658,14 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { tlas: &mut dyn Iterator, ) { let blas = blas - .map(|b| b.inner.as_core().id) + .map(|b| b.inner.as_core().wgpu_blas.clone()) .collect::>(); let tlas = tlas - .map(|t| t.inner.as_core().id) + .map(|t| t.inner.as_core().wgpu_tlas.clone()) .collect::>(); if let Err(cause) = self - .context - .0 - .command_encoder_mark_acceleration_structures_built(self.id, &blas, &tlas) + .wgpu_command_encoder + .mark_acceleration_structures_built(&blas, &tlas) { self.context.handle_error_nolabel( &self.error_sink, @@ -2845,9 +2685,13 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { crate::BlasGeometries::TriangleGeometries(ref triangle_geometries) => { let iter = triangle_geometries.iter().map(|tg| { wgc::ray_tracing::BlasTriangleGeometry { - vertex_buffer: tg.vertex_buffer.inner.as_core().id, - index_buffer: tg.index_buffer.map(|buf| buf.inner.as_core().id), - transform_buffer: tg.transform_buffer.map(|buf| buf.inner.as_core().id), + vertex_buffer: tg.vertex_buffer.inner.as_core().wgpu_buffer.clone(), + index_buffer: tg + .index_buffer + .map(|buf| buf.inner.as_core().wgpu_buffer.clone()), + transform_buffer: tg + .transform_buffer + .map(|buf| buf.inner.as_core().wgpu_buffer.clone()), size: tg.size, transform_buffer_offset: tg.transform_buffer_offset, first_vertex: tg.first_vertex, @@ -2862,7 +2706,7 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { aabb_geometries .iter() .map(|ag| wgc::ray_tracing::BlasAabbGeometry { - aabb_buffer: ag.aabb_buffer.inner.as_core().id, + aabb_buffer: ag.aabb_buffer.inner.as_core().wgpu_buffer.clone(), stride: ag.stride, size: ag.size, primitive_offset: ag.primitive_offset, @@ -2871,7 +2715,7 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { } }; wgc::ray_tracing::BlasBuildEntry { - blas: e.blas.inner.as_core().id, + blas: e.blas.inner.as_core().wgpu_blas.clone(), geometries, } }); @@ -2884,23 +2728,22 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { instance .as_ref() .map(|instance| wgc::ray_tracing::TlasInstance { - blas: instance.blas.as_core().id, + blas: instance.blas.as_core().wgpu_blas.clone(), transform: &instance.transform, custom_data: instance.custom_data, mask: instance.mask, }) }); wgc::ray_tracing::TlasPackage { - tlas: e.inner.as_core().id, + tlas: e.inner.as_core().wgpu_tlas.clone(), instances: Box::new(instances), lowest_unmodified: e.lowest_unmodified, } }); if let Err(cause) = self - .context - .0 - .command_encoder_build_acceleration_structures(self.id, blas, tlas) + .wgpu_command_encoder + .build_acceleration_structures(blas, tlas) { self.context.handle_error_nolabel( &self.error_sink, @@ -2919,14 +2762,13 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { Item = wgt::TextureTransition<&'a dispatch::DispatchTexture>, >, ) { - let result = self.context.0.command_encoder_transition_resources( - self.id, + let result = self.wgpu_command_encoder.transition_resources( buffer_transitions.map(|t| wgt::BufferTransition { - buffer: t.buffer.as_core().id, + buffer: t.buffer.as_core().wgpu_buffer.clone(), state: t.state, }), texture_transitions.map(|t| wgt::TextureTransition { - texture: t.texture.as_core().id, + texture: t.texture.as_core().wgpu_texture.clone(), selector: t.selector.clone(), state: t.state, }), @@ -2942,28 +2784,15 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { } } -impl Drop for CoreCommandEncoder { - fn drop(&mut self) { - self.context.0.command_encoder_drop(self.id) - } -} - impl dispatch::CommandBufferInterface for CoreCommandBuffer {} -impl Drop for CoreCommandBuffer { - fn drop(&mut self) { - self.context.0.command_buffer_drop(self.id) - } -} - impl dispatch::ComputePassInterface for CoreComputePass { fn set_pipeline(&mut self, pipeline: &dispatch::DispatchComputePipeline) { let pipeline = pipeline.as_core(); if let Err(cause) = self - .context - .0 - .compute_pass_set_pipeline(&mut self.pass, pipeline.id) + .pass + .set_pipeline(pipeline.wgpu_compute_pipeline.clone()) { self.context.handle_error( &self.error_sink, @@ -2980,13 +2809,9 @@ impl dispatch::ComputePassInterface for CoreComputePass { bind_group: Option<&dispatch::DispatchBindGroup>, offsets: &[crate::DynamicOffset], ) { - let bg = bind_group.map(|bg| bg.as_core().id); + let bg = bind_group.map(|bg| bg.as_core().wgpu_bind_group.clone()); - if let Err(cause) = - self.context - .0 - .compute_pass_set_bind_group(&mut self.pass, index, bg, offsets) - { + if let Err(cause) = self.pass.set_bind_group(index, bg, offsets) { self.context.handle_error( &self.error_sink, cause, @@ -2997,11 +2822,7 @@ impl dispatch::ComputePassInterface for CoreComputePass { } fn set_immediates(&mut self, offset: u32, data: &[u8]) { - if let Err(cause) = self - .context - .0 - .compute_pass_set_immediates(&mut self.pass, offset, data) - { + if let Err(cause) = self.pass.set_immediates(offset, data) { self.context.handle_error( &self.error_sink, cause, @@ -3012,11 +2833,7 @@ impl dispatch::ComputePassInterface for CoreComputePass { } fn insert_debug_marker(&mut self, label: &str) { - if let Err(cause) = - self.context - .0 - .compute_pass_insert_debug_marker(&mut self.pass, label, 0) - { + if let Err(cause) = self.pass.insert_debug_marker(label, 0) { self.context.handle_error( &self.error_sink, cause, @@ -3027,11 +2844,7 @@ impl dispatch::ComputePassInterface for CoreComputePass { } fn push_debug_group(&mut self, group_label: &str) { - if let Err(cause) = - self.context - .0 - .compute_pass_push_debug_group(&mut self.pass, group_label, 0) - { + if let Err(cause) = self.pass.push_debug_group(group_label, 0) { self.context.handle_error( &self.error_sink, cause, @@ -3042,7 +2855,7 @@ impl dispatch::ComputePassInterface for CoreComputePass { } fn pop_debug_group(&mut self) { - if let Err(cause) = self.context.0.compute_pass_pop_debug_group(&mut self.pass) { + if let Err(cause) = self.pass.pop_debug_group() { self.context.handle_error( &self.error_sink, cause, @@ -3055,10 +2868,9 @@ impl dispatch::ComputePassInterface for CoreComputePass { fn write_timestamp(&mut self, query_set: &dispatch::DispatchQuerySet, query_index: u32) { let query_set = query_set.as_core(); - if let Err(cause) = - self.context - .0 - .compute_pass_write_timestamp(&mut self.pass, query_set.id, query_index) + if let Err(cause) = self + .pass + .write_timestamp(query_set.wgpu_query_set.clone(), query_index) { self.context.handle_error( &self.error_sink, @@ -3076,11 +2888,10 @@ impl dispatch::ComputePassInterface for CoreComputePass { ) { let query_set = query_set.as_core(); - if let Err(cause) = self.context.0.compute_pass_begin_pipeline_statistics_query( - &mut self.pass, - query_set.id, - query_index, - ) { + if let Err(cause) = self + .pass + .begin_pipeline_statistics_query(query_set.wgpu_query_set.clone(), query_index) + { self.context.handle_error( &self.error_sink, cause, @@ -3091,11 +2902,7 @@ impl dispatch::ComputePassInterface for CoreComputePass { } fn end_pipeline_statistics_query(&mut self) { - if let Err(cause) = self - .context - .0 - .compute_pass_end_pipeline_statistics_query(&mut self.pass) - { + if let Err(cause) = self.pass.end_pipeline_statistics_query() { self.context.handle_error( &self.error_sink, cause, @@ -3106,11 +2913,7 @@ impl dispatch::ComputePassInterface for CoreComputePass { } fn dispatch_workgroups(&mut self, x: u32, y: u32, z: u32) { - if let Err(cause) = self - .context - .0 - .compute_pass_dispatch_workgroups(&mut self.pass, x, y, z) - { + if let Err(cause) = self.pass.dispatch_workgroups(x, y, z) { self.context.handle_error( &self.error_sink, cause, @@ -3127,11 +2930,10 @@ impl dispatch::ComputePassInterface for CoreComputePass { ) { let indirect_buffer = indirect_buffer.as_core(); - if let Err(cause) = self.context.0.compute_pass_dispatch_workgroups_indirect( - &mut self.pass, - indirect_buffer.id, - indirect_offset, - ) { + if let Err(cause) = self + .pass + .dispatch_workgroups_indirect(indirect_buffer.wgpu_buffer.clone(), indirect_offset) + { self.context.handle_error( &self.error_sink, cause, @@ -3150,14 +2952,13 @@ impl dispatch::ComputePassInterface for CoreComputePass { Item = wgt::TextureTransition<&'a dispatch::DispatchTextureView>, >, ) { - let result = self.context.0.compute_pass_transition_resources( - &mut self.pass, + let result = self.pass.transition_resources( buffer_transitions.map(|t| wgt::BufferTransition { - buffer: t.buffer.as_core().id, + buffer: t.buffer.as_core().wgpu_buffer.clone(), state: t.state, }), texture_transitions.map(|t| wgt::TextureTransition { - texture: t.texture.as_core().id, + texture: t.texture.as_core().wgpu_texture_view.clone(), selector: t.selector.clone(), state: t.state, }), @@ -3176,7 +2977,7 @@ impl dispatch::ComputePassInterface for CoreComputePass { impl Drop for CoreComputePass { fn drop(&mut self) { - if let Err(cause) = self.context.0.compute_pass_end(&mut self.pass) { + if let Err(cause) = self.pass.end() { self.context.handle_error( &self.error_sink, cause, @@ -3192,9 +2993,8 @@ impl dispatch::RenderPassInterface for CoreRenderPass { let pipeline = pipeline.as_core(); if let Err(cause) = self - .context - .0 - .render_pass_set_pipeline(&mut self.pass, pipeline.id) + .pass + .set_pipeline(pipeline.wgpu_render_pipeline.clone()) { self.context.handle_error( &self.error_sink, @@ -3211,13 +3011,9 @@ impl dispatch::RenderPassInterface for CoreRenderPass { bind_group: Option<&dispatch::DispatchBindGroup>, offsets: &[crate::DynamicOffset], ) { - let bg = bind_group.map(|bg| bg.as_core().id); + let bg = bind_group.map(|bg| bg.as_core().wgpu_bind_group.clone()); - if let Err(cause) = - self.context - .0 - .render_pass_set_bind_group(&mut self.pass, index, bg, offsets) - { + if let Err(cause) = self.pass.set_bind_group(index, bg, offsets) { self.context.handle_error( &self.error_sink, cause, @@ -3236,13 +3032,10 @@ impl dispatch::RenderPassInterface for CoreRenderPass { ) { let buffer = buffer.as_core(); - if let Err(cause) = self.context.0.render_pass_set_index_buffer( - &mut self.pass, - buffer.id, - index_format, - offset, - size, - ) { + if let Err(cause) = + self.pass + .set_index_buffer(buffer.wgpu_buffer.clone(), index_format, offset, size) + { self.context.handle_error( &self.error_sink, cause, @@ -3259,13 +3052,9 @@ impl dispatch::RenderPassInterface for CoreRenderPass { offset: crate::BufferAddress, size: Option, ) { - let buffer = buffer.map(|buffer| buffer.as_core().id); + let buffer = buffer.map(|buffer| buffer.as_core().wgpu_buffer.clone()); - if let Err(cause) = - self.context - .0 - .render_pass_set_vertex_buffer(&mut self.pass, slot, buffer, offset, size) - { + if let Err(cause) = self.pass.set_vertex_buffer(slot, buffer, offset, size) { self.context.handle_error( &self.error_sink, cause, @@ -3276,11 +3065,7 @@ impl dispatch::RenderPassInterface for CoreRenderPass { } fn set_immediates(&mut self, offset: u32, data: &[u8]) { - if let Err(cause) = self - .context - .0 - .render_pass_set_immediates(&mut self.pass, offset, data) - { + if let Err(cause) = self.pass.set_immediates(offset, data) { self.context.handle_error( &self.error_sink, cause, @@ -3291,11 +3076,7 @@ impl dispatch::RenderPassInterface for CoreRenderPass { } fn set_blend_constant(&mut self, color: crate::Color) { - if let Err(cause) = self - .context - .0 - .render_pass_set_blend_constant(&mut self.pass, color) - { + if let Err(cause) = self.pass.set_blend_constant(color) { self.context.handle_error( &self.error_sink, cause, @@ -3306,11 +3087,7 @@ impl dispatch::RenderPassInterface for CoreRenderPass { } fn set_scissor_rect(&mut self, x: u32, y: u32, width: u32, height: u32) { - if let Err(cause) = - self.context - .0 - .render_pass_set_scissor_rect(&mut self.pass, x, y, width, height) - { + if let Err(cause) = self.pass.set_scissor_rect(x, y, width, height) { self.context.handle_error( &self.error_sink, cause, @@ -3329,15 +3106,10 @@ impl dispatch::RenderPassInterface for CoreRenderPass { min_depth: f32, max_depth: f32, ) { - if let Err(cause) = self.context.0.render_pass_set_viewport( - &mut self.pass, - x, - y, - width, - height, - min_depth, - max_depth, - ) { + if let Err(cause) = self + .pass + .set_viewport(x, y, width, height, min_depth, max_depth) + { self.context.handle_error( &self.error_sink, cause, @@ -3348,11 +3120,7 @@ impl dispatch::RenderPassInterface for CoreRenderPass { } fn set_stencil_reference(&mut self, reference: u32) { - if let Err(cause) = self - .context - .0 - .render_pass_set_stencil_reference(&mut self.pass, reference) - { + if let Err(cause) = self.pass.set_stencil_reference(reference) { self.context.handle_error( &self.error_sink, cause, @@ -3363,8 +3131,7 @@ impl dispatch::RenderPassInterface for CoreRenderPass { } fn draw(&mut self, vertices: Range, instances: Range) { - if let Err(cause) = self.context.0.render_pass_draw( - &mut self.pass, + if let Err(cause) = self.pass.draw( vertices.end - vertices.start, instances.end - instances.start, vertices.start, @@ -3380,8 +3147,7 @@ impl dispatch::RenderPassInterface for CoreRenderPass { } fn draw_indexed(&mut self, indices: Range, base_vertex: i32, instances: Range) { - if let Err(cause) = self.context.0.render_pass_draw_indexed( - &mut self.pass, + if let Err(cause) = self.pass.draw_indexed( indices.end - indices.start, instances.end - instances.start, indices.start, @@ -3398,12 +3164,10 @@ impl dispatch::RenderPassInterface for CoreRenderPass { } fn draw_mesh_tasks(&mut self, group_count_x: u32, group_count_y: u32, group_count_z: u32) { - if let Err(cause) = self.context.0.render_pass_draw_mesh_tasks( - &mut self.pass, - group_count_x, - group_count_y, - group_count_z, - ) { + if let Err(cause) = self + .pass + .draw_mesh_tasks(group_count_x, group_count_y, group_count_z) + { self.context.handle_error( &self.error_sink, cause, @@ -3420,11 +3184,10 @@ impl dispatch::RenderPassInterface for CoreRenderPass { ) { let indirect_buffer = indirect_buffer.as_core(); - if let Err(cause) = self.context.0.render_pass_draw_indirect( - &mut self.pass, - indirect_buffer.id, - indirect_offset, - ) { + if let Err(cause) = self + .pass + .draw_indirect(indirect_buffer.wgpu_buffer.clone(), indirect_offset) + { self.context.handle_error( &self.error_sink, cause, @@ -3441,11 +3204,10 @@ impl dispatch::RenderPassInterface for CoreRenderPass { ) { let indirect_buffer = indirect_buffer.as_core(); - if let Err(cause) = self.context.0.render_pass_draw_indexed_indirect( - &mut self.pass, - indirect_buffer.id, - indirect_offset, - ) { + if let Err(cause) = self + .pass + .draw_indexed_indirect(indirect_buffer.wgpu_buffer.clone(), indirect_offset) + { self.context.handle_error( &self.error_sink, cause, @@ -3462,11 +3224,10 @@ impl dispatch::RenderPassInterface for CoreRenderPass { ) { let indirect_buffer = indirect_buffer.as_core(); - if let Err(cause) = self.context.0.render_pass_draw_mesh_tasks_indirect( - &mut self.pass, - indirect_buffer.id, - indirect_offset, - ) { + if let Err(cause) = self + .pass + .draw_mesh_tasks_indirect(indirect_buffer.wgpu_buffer.clone(), indirect_offset) + { self.context.handle_error( &self.error_sink, cause, @@ -3484,9 +3245,8 @@ impl dispatch::RenderPassInterface for CoreRenderPass { ) { let indirect_buffer = indirect_buffer.as_core(); - if let Err(cause) = self.context.0.render_pass_multi_draw_indirect( - &mut self.pass, - indirect_buffer.id, + if let Err(cause) = self.pass.multi_draw_indirect( + indirect_buffer.wgpu_buffer.clone(), indirect_offset, count, ) { @@ -3507,9 +3267,8 @@ impl dispatch::RenderPassInterface for CoreRenderPass { ) { let indirect_buffer = indirect_buffer.as_core(); - if let Err(cause) = self.context.0.render_pass_multi_draw_indexed_indirect( - &mut self.pass, - indirect_buffer.id, + if let Err(cause) = self.pass.multi_draw_indexed_indirect( + indirect_buffer.wgpu_buffer.clone(), indirect_offset, count, ) { @@ -3530,9 +3289,8 @@ impl dispatch::RenderPassInterface for CoreRenderPass { ) { let indirect_buffer = indirect_buffer.as_core(); - if let Err(cause) = self.context.0.render_pass_multi_draw_mesh_tasks_indirect( - &mut self.pass, - indirect_buffer.id, + if let Err(cause) = self.pass.multi_draw_mesh_tasks_indirect( + indirect_buffer.wgpu_buffer.clone(), indirect_offset, count, ) { @@ -3556,11 +3314,10 @@ impl dispatch::RenderPassInterface for CoreRenderPass { let indirect_buffer = indirect_buffer.as_core(); let count_buffer = count_buffer.as_core(); - if let Err(cause) = self.context.0.render_pass_multi_draw_indirect_count( - &mut self.pass, - indirect_buffer.id, + if let Err(cause) = self.pass.multi_draw_indirect_count( + indirect_buffer.wgpu_buffer.clone(), indirect_offset, - count_buffer.id, + count_buffer.wgpu_buffer.clone(), count_buffer_offset, max_count, ) { @@ -3584,18 +3341,13 @@ impl dispatch::RenderPassInterface for CoreRenderPass { let indirect_buffer = indirect_buffer.as_core(); let count_buffer = count_buffer.as_core(); - if let Err(cause) = self - .context - .0 - .render_pass_multi_draw_indexed_indirect_count( - &mut self.pass, - indirect_buffer.id, - indirect_offset, - count_buffer.id, - count_buffer_offset, - max_count, - ) - { + if let Err(cause) = self.pass.multi_draw_indexed_indirect_count( + indirect_buffer.wgpu_buffer.clone(), + indirect_offset, + count_buffer.wgpu_buffer.clone(), + count_buffer_offset, + max_count, + ) { self.context.handle_error( &self.error_sink, cause, @@ -3616,18 +3368,13 @@ impl dispatch::RenderPassInterface for CoreRenderPass { let indirect_buffer = indirect_buffer.as_core(); let count_buffer = count_buffer.as_core(); - if let Err(cause) = self - .context - .0 - .render_pass_multi_draw_mesh_tasks_indirect_count( - &mut self.pass, - indirect_buffer.id, - indirect_offset, - count_buffer.id, - count_buffer_offset, - max_count, - ) - { + if let Err(cause) = self.pass.multi_draw_mesh_tasks_indirect_count( + indirect_buffer.wgpu_buffer.clone(), + indirect_offset, + count_buffer.wgpu_buffer.clone(), + count_buffer_offset, + max_count, + ) { self.context.handle_error( &self.error_sink, cause, @@ -3638,11 +3385,7 @@ impl dispatch::RenderPassInterface for CoreRenderPass { } fn insert_debug_marker(&mut self, label: &str) { - if let Err(cause) = self - .context - .0 - .render_pass_insert_debug_marker(&mut self.pass, label, 0) - { + if let Err(cause) = self.pass.insert_debug_marker(label, 0) { self.context.handle_error( &self.error_sink, cause, @@ -3653,11 +3396,7 @@ impl dispatch::RenderPassInterface for CoreRenderPass { } fn push_debug_group(&mut self, group_label: &str) { - if let Err(cause) = - self.context - .0 - .render_pass_push_debug_group(&mut self.pass, group_label, 0) - { + if let Err(cause) = self.pass.push_debug_group(group_label, 0) { self.context.handle_error( &self.error_sink, cause, @@ -3668,7 +3407,7 @@ impl dispatch::RenderPassInterface for CoreRenderPass { } fn pop_debug_group(&mut self) { - if let Err(cause) = self.context.0.render_pass_pop_debug_group(&mut self.pass) { + if let Err(cause) = self.pass.pop_debug_group() { self.context.handle_error( &self.error_sink, cause, @@ -3681,10 +3420,9 @@ impl dispatch::RenderPassInterface for CoreRenderPass { fn write_timestamp(&mut self, query_set: &dispatch::DispatchQuerySet, query_index: u32) { let query_set = query_set.as_core(); - if let Err(cause) = - self.context - .0 - .render_pass_write_timestamp(&mut self.pass, query_set.id, query_index) + if let Err(cause) = self + .pass + .write_timestamp(query_set.wgpu_query_set.clone(), query_index) { self.context.handle_error( &self.error_sink, @@ -3696,11 +3434,7 @@ impl dispatch::RenderPassInterface for CoreRenderPass { } fn begin_occlusion_query(&mut self, query_index: u32) { - if let Err(cause) = self - .context - .0 - .render_pass_begin_occlusion_query(&mut self.pass, query_index) - { + if let Err(cause) = self.pass.begin_occlusion_query(query_index) { self.context.handle_error( &self.error_sink, cause, @@ -3711,11 +3445,7 @@ impl dispatch::RenderPassInterface for CoreRenderPass { } fn end_occlusion_query(&mut self) { - if let Err(cause) = self - .context - .0 - .render_pass_end_occlusion_query(&mut self.pass) - { + if let Err(cause) = self.pass.end_occlusion_query() { self.context.handle_error( &self.error_sink, cause, @@ -3732,11 +3462,10 @@ impl dispatch::RenderPassInterface for CoreRenderPass { ) { let query_set = query_set.as_core(); - if let Err(cause) = self.context.0.render_pass_begin_pipeline_statistics_query( - &mut self.pass, - query_set.id, - query_index, - ) { + if let Err(cause) = self + .pass + .begin_pipeline_statistics_query(query_set.wgpu_query_set.clone(), query_index) + { self.context.handle_error( &self.error_sink, cause, @@ -3747,11 +3476,7 @@ impl dispatch::RenderPassInterface for CoreRenderPass { } fn end_pipeline_statistics_query(&mut self) { - if let Err(cause) = self - .context - .0 - .render_pass_end_pipeline_statistics_query(&mut self.pass) - { + if let Err(cause) = self.pass.end_pipeline_statistics_query() { self.context.handle_error( &self.error_sink, cause, @@ -3766,13 +3491,9 @@ impl dispatch::RenderPassInterface for CoreRenderPass { render_bundles: &mut dyn Iterator, ) { let temp_render_bundles = render_bundles - .map(|rb| rb.as_core().id) + .map(|rb| rb.as_core().wgpu_render_bundle.clone()) .collect::>(); - if let Err(cause) = self - .context - .0 - .render_pass_execute_bundles(&mut self.pass, &temp_render_bundles) - { + if let Err(cause) = self.pass.execute_bundles(&temp_render_bundles) { self.context.handle_error( &self.error_sink, cause, @@ -3785,7 +3506,7 @@ impl dispatch::RenderPassInterface for CoreRenderPass { impl Drop for CoreRenderPass { fn drop(&mut self) { - if let Err(cause) = self.context.0.render_pass_end(&mut self.pass) { + if let Err(cause) = self.pass.end() { self.context.handle_error( &self.error_sink, cause, @@ -3800,9 +3521,8 @@ impl dispatch::RenderBundleEncoderInterface for CoreRenderBundleEncoder { fn set_pipeline(&mut self, pipeline: &dispatch::DispatchRenderPipeline) { let pipeline = pipeline.as_core(); - self.context - .0 - .render_bundle_encoder_set_pipeline(&mut self.encoder, pipeline.id) + self.encoder + .set_pipeline(pipeline.wgpu_render_pipeline.clone()) .expect("RenderBundleEncoder should not have ended") } @@ -3812,11 +3532,10 @@ impl dispatch::RenderBundleEncoderInterface for CoreRenderBundleEncoder { bind_group: Option<&dispatch::DispatchBindGroup>, offsets: &[crate::DynamicOffset], ) { - let bg = bind_group.map(|bg| bg.as_core().id); + let bg = bind_group.map(|bg| bg.as_core().wgpu_bind_group.clone()); - self.context - .0 - .render_bundle_encoder_set_bind_group(&mut self.encoder, index, bg, offsets) + self.encoder + .set_bind_group(index, bg, offsets) .expect("RenderBundleEncoder should not have ended"); } @@ -3829,15 +3548,8 @@ impl dispatch::RenderBundleEncoderInterface for CoreRenderBundleEncoder { ) { let buffer = buffer.as_core(); - self.context - .0 - .render_bundle_encoder_set_index_buffer( - &mut self.encoder, - buffer.id, - index_format, - offset, - size, - ) + self.encoder + .set_index_buffer(buffer.wgpu_buffer.clone(), index_format, offset, size) .expect("RenderBundleEncoder should not have ended"); } @@ -3848,11 +3560,10 @@ impl dispatch::RenderBundleEncoderInterface for CoreRenderBundleEncoder { offset: crate::BufferAddress, size: Option, ) { - let buffer = buffer.map(|buffer| buffer.as_core().id); + let buffer = buffer.map(|buffer| buffer.as_core().wgpu_buffer.clone()); - self.context - .0 - .render_bundle_encoder_set_vertex_buffer(&mut self.encoder, slot, buffer, offset, size) + self.encoder + .set_vertex_buffer(slot, buffer, offset, size) .expect("RenderBundleEncoder should not have ended"); } @@ -3870,17 +3581,14 @@ impl dispatch::RenderBundleEncoderInterface for CoreRenderBundleEncoder { return; } - self.context - .0 - .render_bundle_encoder_set_immediates(&mut self.encoder, offset, data) + self.encoder + .set_immediates(offset, data) .expect("RenderBundleEncoder should not have ended"); } fn draw(&mut self, vertices: Range, instances: Range) { - self.context - .0 - .render_bundle_encoder_draw( - &mut self.encoder, + self.encoder + .draw( vertices.end - vertices.start, instances.end - instances.start, vertices.start, @@ -3890,10 +3598,8 @@ impl dispatch::RenderBundleEncoderInterface for CoreRenderBundleEncoder { } fn draw_indexed(&mut self, indices: Range, base_vertex: i32, instances: Range) { - self.context - .0 - .render_bundle_encoder_draw_indexed( - &mut self.encoder, + self.encoder + .draw_indexed( indices.end - indices.start, instances.end - instances.start, indices.start, @@ -3910,13 +3616,8 @@ impl dispatch::RenderBundleEncoderInterface for CoreRenderBundleEncoder { ) { let indirect_buffer = indirect_buffer.as_core(); - self.context - .0 - .render_bundle_encoder_draw_indirect( - &mut self.encoder, - indirect_buffer.id, - indirect_offset, - ) + self.encoder + .draw_indirect(indirect_buffer.wgpu_buffer.clone(), indirect_offset) .expect("RenderBundleEncoder should not have ended"); } @@ -3927,13 +3628,8 @@ impl dispatch::RenderBundleEncoderInterface for CoreRenderBundleEncoder { ) { let indirect_buffer = indirect_buffer.as_core(); - self.context - .0 - .render_bundle_encoder_draw_indexed_indirect( - &mut self.encoder, - indirect_buffer.id, - indirect_offset, - ) + self.encoder + .draw_indexed_indirect(indirect_buffer.wgpu_buffer.clone(), indirect_offset) .expect("RenderBundleEncoder should not have ended"); } @@ -3942,11 +3638,7 @@ impl dispatch::RenderBundleEncoderInterface for CoreRenderBundleEncoder { Self: Sized, { let label = self.encoder.label().map(alloc::string::ToString::to_string); - let (id, error) = self.context.0.render_bundle_encoder_finish( - &mut self.encoder, - &desc.map_label(|l| l.map(Borrowed)), - None, - ); + let (wgpu_render_bundle, error) = self.encoder.finish(&desc.map_label(|l| l.map(Borrowed))); if let Some(err) = error { self.context.handle_error( &self.error_sink, @@ -3955,11 +3647,7 @@ impl dispatch::RenderBundleEncoderInterface for CoreRenderBundleEncoder { "RenderBundleEncoder::finish", ); } - CoreRenderBundle { - context: self.context.clone(), - id, - } - .into() + CoreRenderBundle { wgpu_render_bundle }.into() } #[cfg(custom)] @@ -3973,37 +3661,30 @@ impl dispatch::RenderBundleEncoderInterface for CoreRenderBundleEncoder { impl dispatch::RenderBundleInterface for CoreRenderBundle {} -impl Drop for CoreRenderBundle { - fn drop(&mut self) { - self.context.0.render_bundle_drop(self.id) - } -} - impl dispatch::SurfaceInterface for CoreSurface { fn get_capabilities(&self, adapter: &dispatch::DispatchAdapter) -> wgt::SurfaceCapabilities { let adapter = adapter.as_core(); - self.context - .0 - .surface_get_capabilities(self.id, adapter.id) + self.wgpu_surface + .get_capabilities(&adapter.wgpu_adapter) .unwrap_or_default() } fn display_hdr_info(&self, adapter: &dispatch::DispatchAdapter) -> wgt::DisplayHdrInfo { let adapter = adapter.as_core(); - self.context.0.surface_display_hdr_info(self.id, adapter.id) + self.wgpu_surface.display_hdr_info(&adapter.wgpu_adapter) } fn configure(&self, device: &dispatch::DispatchDevice, config: &crate::SurfaceConfiguration) { let device = device.as_core(); - let error = self.context.0.surface_configure(self.id, device.id, config); + let error = self.wgpu_surface.configure(&device.wgpu_device, config); if let Some(e) = error { self.context .handle_error_nolabel(&device.error_sink, e, "Surface::configure"); } else { - *self.configured_device.lock() = Some(device.id); + *self.configured_device.lock() = Some(device.wgpu_device.clone()); *self.error_sink.lock() = Some(device.error_sink.clone()); } } @@ -4023,20 +3704,20 @@ impl dispatch::SurfaceInterface for CoreSurface { let output_detail = CoreSurfaceOutputDetail { context: self.context.clone(), - surface_id: self.id, + wgpu_surface: self.wgpu_surface.clone(), error_sink: error_sink.clone(), } .into(); - match self.context.0.surface_get_current_texture(self.id, None) { + match self.wgpu_surface.get_current_texture() { Ok(wgc::present::SurfaceOutput { status, texture: texture_id, }) => { let data = texture_id - .map(|id| CoreTexture { + .map(|wgpu_texture| CoreTexture { context: self.context.clone(), - id, + wgpu_texture, error_sink, }) .map(Into::into); @@ -4063,15 +3744,9 @@ impl dispatch::SurfaceInterface for CoreSurface { } } -impl Drop for CoreSurface { - fn drop(&mut self) { - self.context.0.surface_drop(self.id) - } -} - impl dispatch::SurfaceOutputDetailInterface for CoreSurfaceOutputDetail { fn texture_discard(&self) { - match self.context.0.surface_texture_discard(self.surface_id) { + match self.wgpu_surface.discard() { Ok(_status) => (), Err(err) => { self.context @@ -4081,7 +3756,7 @@ impl dispatch::SurfaceOutputDetailInterface for CoreSurfaceOutputDetail { } fn texture_release(&self) { - match self.context.0.surface_texture_release(self.surface_id) { + match self.wgpu_surface.release() { Ok(_status) => (), Err(err) => { self.context @@ -4090,13 +3765,6 @@ impl dispatch::SurfaceOutputDetailInterface for CoreSurfaceOutputDetail { } } } -impl Drop for CoreSurfaceOutputDetail { - fn drop(&mut self) { - // Discard gets called by the api struct - - // no-op - } -} impl dispatch::QueueWriteBufferInterface for CoreQueueWriteBuffer { #[inline] @@ -4109,13 +3777,6 @@ impl dispatch::QueueWriteBufferInterface for CoreQueueWriteBuffer { unsafe { self.mapping.write_slice() } } } -impl Drop for CoreQueueWriteBuffer { - fn drop(&mut self) { - // The api struct calls queue.write_staging_buffer - - // no-op - } -} impl dispatch::BufferMappedRangeInterface for CoreBufferMappedRange { #[inline]