From 950d765a4d18c79e5fde3655ef507f04bae58101 Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Mon, 29 Jan 2024 15:37:57 +0100 Subject: [PATCH] Remove G parameter in Global and generic IdentityHandlerFactory (#5159) --- deno_webgpu/binding.rs | 6 +- deno_webgpu/buffer.rs | 2 +- deno_webgpu/bundle.rs | 2 +- deno_webgpu/command_encoder.rs | 2 +- deno_webgpu/lib.rs | 12 ++-- deno_webgpu/pipeline.rs | 16 ++--- deno_webgpu/sampler.rs | 2 +- deno_webgpu/shader.rs | 2 +- deno_webgpu/surface.rs | 3 +- deno_webgpu/texture.rs | 4 +- player/src/bin/play.rs | 18 ++--- player/src/lib.rs | 54 ++++++--------- player/tests/test.rs | 13 ++-- wgpu-core/src/command/clear.rs | 3 +- wgpu-core/src/command/compute.rs | 3 +- wgpu-core/src/command/mod.rs | 7 +- wgpu-core/src/command/query.rs | 3 +- wgpu-core/src/command/render.rs | 3 +- wgpu-core/src/command/transfer.rs | 3 +- wgpu-core/src/device/global.rs | 106 ++++++++++++++--------------- wgpu-core/src/device/mod.rs | 20 +++--- wgpu-core/src/device/queue.rs | 8 +-- wgpu-core/src/error.rs | 6 +- wgpu-core/src/global.rs | 37 ++++------- wgpu-core/src/hal_api.rs | 13 ++-- wgpu-core/src/hub.rs | 62 ++++++++--------- wgpu-core/src/id.rs | 12 +++- wgpu-core/src/identity.rs | 72 ++------------------ wgpu-core/src/instance.rs | 107 ++++++++++++++---------------- wgpu-core/src/lib.rs | 2 +- wgpu-core/src/present.rs | 21 +++--- wgpu-core/src/registry.rs | 29 ++++---- wgpu-core/src/resource.rs | 4 +- wgpu/src/backend/wgpu_core.rs | 94 ++++++++++++-------------- 34 files changed, 299 insertions(+), 452 deletions(-) diff --git a/deno_webgpu/binding.rs b/deno_webgpu/binding.rs index 5f1abde2b..c0b9b5836 100644 --- a/deno_webgpu/binding.rs +++ b/deno_webgpu/binding.rs @@ -208,7 +208,7 @@ pub fn op_webgpu_create_bind_group_layout( gfx_put!(device => instance.device_create_bind_group_layout( device, &descriptor, - () + None ) => state, WebGpuBindGroupLayout) } @@ -243,7 +243,7 @@ pub fn op_webgpu_create_pipeline_layout( gfx_put!(device => instance.device_create_pipeline_layout( device, &descriptor, - () + None ) => state, super::pipeline::WebGpuPipelineLayout) } @@ -322,6 +322,6 @@ pub fn op_webgpu_create_bind_group( gfx_put!(device => instance.device_create_bind_group( device, &descriptor, - () + None ) => state, WebGpuBindGroup) } diff --git a/deno_webgpu/buffer.rs b/deno_webgpu/buffer.rs index b46ceb197..3cb9fdf83 100644 --- a/deno_webgpu/buffer.rs +++ b/deno_webgpu/buffer.rs @@ -64,7 +64,7 @@ pub fn op_webgpu_create_buffer( gfx_put!(device => instance.device_create_buffer( device, &descriptor, - () + None ) => state, WebGpuBuffer) } diff --git a/deno_webgpu/bundle.rs b/deno_webgpu/bundle.rs index 7e37bc649..d50359931 100644 --- a/deno_webgpu/bundle.rs +++ b/deno_webgpu/bundle.rs @@ -113,7 +113,7 @@ pub fn op_webgpu_render_bundle_encoder_finish( &wgpu_core::command::RenderBundleDescriptor { label: Some(label), }, - () + None ) => state, WebGpuRenderBundle) } diff --git a/deno_webgpu/command_encoder.rs b/deno_webgpu/command_encoder.rs index 33f271ce9..679ac3cab 100644 --- a/deno_webgpu/command_encoder.rs +++ b/deno_webgpu/command_encoder.rs @@ -61,7 +61,7 @@ pub fn op_webgpu_create_command_encoder( gfx_put!(device => instance.device_create_command_encoder( device, &descriptor, - () + None ) => state, WebGpuCommandEncoder) } diff --git a/deno_webgpu/lib.rs b/deno_webgpu/lib.rs index bc6d7a2ae..40e76e0fa 100644 --- a/deno_webgpu/lib.rs +++ b/deno_webgpu/lib.rs @@ -96,8 +96,7 @@ fn check_unstable(state: &OpState, api_name: &str) { } } -pub type Instance = - std::sync::Arc>; +pub type Instance = std::sync::Arc; struct WebGpuAdapter(Instance, wgpu_core::id::AdapterId); impl Resource for WebGpuAdapter { @@ -410,7 +409,6 @@ pub async fn op_webgpu_request_adapter( } else { state.put(std::sync::Arc::new(wgpu_core::global::Global::new( "webgpu", - wgpu_core::identity::IdentityManagerFactory, wgpu_types::InstanceDescriptor { backends, flags: wgpu_types::InstanceFlags::from_build_config(), @@ -428,7 +426,7 @@ pub async fn op_webgpu_request_adapter( }; let res = instance.request_adapter( &descriptor, - wgpu_core::instance::AdapterInputs::Mask(backends, |_| ()), + wgpu_core::instance::AdapterInputs::Mask(backends, |_| None), ); let adapter = match res { @@ -675,8 +673,8 @@ pub async fn op_webgpu_request_device( adapter, &descriptor, std::env::var("DENO_WEBGPU_TRACE").ok().as_ref().map(std::path::Path::new), - (), - () + None, + None )); if let Some(err) = maybe_err { return Err(DomExceptionOperationError::new(&err.to_string()).into()); @@ -773,6 +771,6 @@ pub fn op_webgpu_create_query_set( gfx_put!(device => instance.device_create_query_set( device, &descriptor, - () + None ) => state, WebGpuQuerySet) } diff --git a/deno_webgpu/pipeline.rs b/deno_webgpu/pipeline.rs index bf98b690b..9175fe207 100644 --- a/deno_webgpu/pipeline.rs +++ b/deno_webgpu/pipeline.rs @@ -118,8 +118,8 @@ pub fn op_webgpu_create_compute_pipeline( GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(_) => None, GPUPipelineLayoutOrGPUAutoLayoutMode::Auto(GPUAutoLayoutMode::Auto) => { Some(wgpu_core::device::ImplicitPipelineIds { - root_id: (), - group_ids: &[(); MAX_BIND_GROUPS], + root_id: None, + group_ids: &[None; MAX_BIND_GROUPS], }) } }; @@ -127,7 +127,7 @@ pub fn op_webgpu_create_compute_pipeline( let (compute_pipeline, maybe_err) = gfx_select!(device => instance.device_create_compute_pipeline( device, &descriptor, - (), + None, implicit_pipelines )); @@ -159,7 +159,7 @@ pub fn op_webgpu_compute_pipeline_get_bind_group_layout( .get::(compute_pipeline_rid)?; let compute_pipeline = compute_pipeline_resource.1; - let (bind_group_layout, maybe_err) = gfx_select!(compute_pipeline => instance.compute_pipeline_get_bind_group_layout(compute_pipeline, index, ())); + let (bind_group_layout, maybe_err) = gfx_select!(compute_pipeline => instance.compute_pipeline_get_bind_group_layout(compute_pipeline, index, None)); let label = gfx_select!(bind_group_layout => instance.bind_group_layout_label(bind_group_layout)); @@ -392,8 +392,8 @@ pub fn op_webgpu_create_render_pipeline( GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(_) => None, GPUPipelineLayoutOrGPUAutoLayoutMode::Auto(GPUAutoLayoutMode::Auto) => { Some(wgpu_core::device::ImplicitPipelineIds { - root_id: (), - group_ids: &[(); MAX_BIND_GROUPS], + root_id: None, + group_ids: &[None; MAX_BIND_GROUPS], }) } }; @@ -401,7 +401,7 @@ pub fn op_webgpu_create_render_pipeline( let (render_pipeline, maybe_err) = gfx_select!(device => instance.device_create_render_pipeline( device, &descriptor, - (), + None, implicit_pipelines )); @@ -425,7 +425,7 @@ pub fn op_webgpu_render_pipeline_get_bind_group_layout( .get::(render_pipeline_rid)?; let render_pipeline = render_pipeline_resource.1; - let (bind_group_layout, maybe_err) = gfx_select!(render_pipeline => instance.render_pipeline_get_bind_group_layout(render_pipeline, index, ())); + let (bind_group_layout, maybe_err) = gfx_select!(render_pipeline => instance.render_pipeline_get_bind_group_layout(render_pipeline, index, None)); let label = gfx_select!(bind_group_layout => instance.bind_group_layout_label(bind_group_layout)); diff --git a/deno_webgpu/sampler.rs b/deno_webgpu/sampler.rs index 5876498b2..0d65d727a 100644 --- a/deno_webgpu/sampler.rs +++ b/deno_webgpu/sampler.rs @@ -74,6 +74,6 @@ pub fn op_webgpu_create_sampler( gfx_put!(device => instance.device_create_sampler( device, &descriptor, - () + None ) => state, WebGpuSampler) } diff --git a/deno_webgpu/shader.rs b/deno_webgpu/shader.rs index f091b15f8..f4604a04a 100644 --- a/deno_webgpu/shader.rs +++ b/deno_webgpu/shader.rs @@ -49,6 +49,6 @@ pub fn op_webgpu_create_shader_module( device, &descriptor, source, - () + None ) => state, WebGpuShaderModule) } diff --git a/deno_webgpu/surface.rs b/deno_webgpu/surface.rs index 1ac9d8704..4d8412999 100644 --- a/deno_webgpu/surface.rs +++ b/deno_webgpu/surface.rs @@ -75,6 +75,7 @@ pub fn op_webgpu_surface_configure( present_mode: args.present_mode.unwrap_or_default(), alpha_mode: args.alpha_mode, view_formats: args.view_formats, + desired_maximum_frame_latency: 2, }; let err = gfx_select!(device => instance.surface_configure(surface, device, &conf)); @@ -97,7 +98,7 @@ pub fn op_webgpu_surface_get_current_texture( let surface_resource = state.resource_table.get::(surface_rid)?; let surface = surface_resource.1; - let output = gfx_select!(device => instance.surface_get_current_texture(surface, ()))?; + let output = gfx_select!(device => instance.surface_get_current_texture(surface, None))?; match output.status { SurfaceStatus::Good | SurfaceStatus::Suboptimal => { diff --git a/deno_webgpu/texture.rs b/deno_webgpu/texture.rs index 8e1afa492..a9be7b991 100644 --- a/deno_webgpu/texture.rs +++ b/deno_webgpu/texture.rs @@ -83,7 +83,7 @@ pub fn op_webgpu_create_texture( let (val, maybe_err) = gfx_select!(device => instance.device_create_texture( device, &descriptor, - () + None )); let rid = state.resource_table.add(WebGpuTexture { @@ -128,6 +128,6 @@ pub fn op_webgpu_create_texture_view( gfx_put!(texture => instance.texture_create_view( texture, &descriptor, - () + None ) => state, WebGpuTextureView) } diff --git a/player/src/bin/play.rs b/player/src/bin/play.rs index 5e87232d8..7e3cbad11 100644 --- a/player/src/bin/play.rs +++ b/player/src/bin/play.rs @@ -3,7 +3,7 @@ #[cfg(not(target_arch = "wasm32"))] fn main() { - use player::{GlobalPlay as _, IdentityPassThroughFactory}; + use player::GlobalPlay as _; use wgc::{device::trace, gfx_select}; use std::{ @@ -49,11 +49,7 @@ fn main() { .build(&event_loop) .unwrap(); - let global = wgc::global::Global::new( - "player", - IdentityPassThroughFactory, - wgt::InstanceDescriptor::default(), - ); + let global = wgc::global::Global::new("player", wgt::InstanceDescriptor::default()); let mut command_buffer_id_manager = wgc::identity::IdentityManager::new(); #[cfg(feature = "winit")] @@ -61,7 +57,7 @@ fn main() { global.instance_create_surface( window.display_handle().unwrap().into(), window.window_handle().unwrap().into(), - wgc::id::Id::zip(0, 1, wgt::Backend::Empty), + Some(wgc::id::Id::zip(0, 1, wgt::Backend::Empty)), ) } .unwrap(); @@ -79,9 +75,7 @@ fn main() { #[cfg(not(feature = "winit"))] compatible_surface: None, }, - wgc::instance::AdapterInputs::IdSet(&[wgc::id::Id::zip(0, 0, backend)], |id| { - id.backend() - }), + wgc::instance::AdapterInputs::IdSet(&[wgc::id::AdapterId::zip(0, 0, backend)]), ) .expect("Unable to find an adapter for selected backend"); @@ -92,8 +86,8 @@ fn main() { adapter, &desc, None, - id, - id.transmute() + Some(id), + Some(id.transmute()) )); if let Some(e) = error { panic!("{:?}", e); diff --git a/player/src/lib.rs b/player/src/lib.rs index 3062d6a85..eb89e43f7 100644 --- a/player/src/lib.rs +++ b/player/src/lib.rs @@ -12,21 +12,6 @@ use wgc::device::trace; use std::{borrow::Cow, fs, path::Path}; -pub struct IdentityPassThroughFactory; - -impl wgc::identity::IdentityHandlerFactory for IdentityPassThroughFactory { - type Input = wgc::id::Id; - - fn input_to_id(id_in: Self::Input) -> wgc::id::Id { - id_in - } - - fn autogenerate_ids() -> bool { - false - } -} -impl wgc::identity::GlobalIdentityHandlerFactory for IdentityPassThroughFactory {} - pub trait GlobalPlay { fn encode_commands( &self, @@ -42,7 +27,7 @@ pub trait GlobalPlay { ); } -impl GlobalPlay for wgc::global::Global { +impl GlobalPlay for wgc::global::Global { fn encode_commands( &self, encoder: wgc::id::CommandEncoderId, @@ -169,7 +154,7 @@ impl GlobalPlay for wgc::global::Global { } Action::CreateBuffer(id, desc) => { self.device_maintain_ids::(device).unwrap(); - let (_, error) = self.device_create_buffer::(device, &desc, id); + let (_, error) = self.device_create_buffer::(device, &desc, Some(id)); if let Some(e) = error { panic!("{e}"); } @@ -182,7 +167,7 @@ impl GlobalPlay for wgc::global::Global { } Action::CreateTexture(id, desc) => { self.device_maintain_ids::(device).unwrap(); - let (_, error) = self.device_create_texture::(device, &desc, id); + let (_, error) = self.device_create_texture::(device, &desc, Some(id)); if let Some(e) = error { panic!("{e}"); } @@ -199,7 +184,7 @@ impl GlobalPlay for wgc::global::Global { desc, } => { self.device_maintain_ids::(device).unwrap(); - let (_, error) = self.texture_create_view::(parent_id, &desc, id); + let (_, error) = self.texture_create_view::(parent_id, &desc, Some(id)); if let Some(e) = error { panic!("{e}"); } @@ -209,7 +194,7 @@ impl GlobalPlay for wgc::global::Global { } Action::CreateSampler(id, desc) => { self.device_maintain_ids::(device).unwrap(); - let (_, error) = self.device_create_sampler::(device, &desc, id); + let (_, error) = self.device_create_sampler::(device, &desc, Some(id)); if let Some(e) = error { panic!("{e}"); } @@ -219,13 +204,13 @@ impl GlobalPlay for wgc::global::Global { } Action::GetSurfaceTexture { id, parent_id } => { self.device_maintain_ids::(device).unwrap(); - self.surface_get_current_texture::(parent_id, id) + self.surface_get_current_texture::(parent_id, Some(id)) .unwrap() .texture_id .unwrap(); } Action::CreateBindGroupLayout(id, desc) => { - let (_, error) = self.device_create_bind_group_layout::(device, &desc, id); + let (_, error) = self.device_create_bind_group_layout::(device, &desc, Some(id)); if let Some(e) = error { panic!("{e}"); } @@ -235,7 +220,7 @@ impl GlobalPlay for wgc::global::Global { } Action::CreatePipelineLayout(id, desc) => { self.device_maintain_ids::(device).unwrap(); - let (_, error) = self.device_create_pipeline_layout::(device, &desc, id); + let (_, error) = self.device_create_pipeline_layout::(device, &desc, Some(id)); if let Some(e) = error { panic!("{e}"); } @@ -245,7 +230,7 @@ impl GlobalPlay for wgc::global::Global { } Action::CreateBindGroup(id, desc) => { self.device_maintain_ids::(device).unwrap(); - let (_, error) = self.device_create_bind_group::(device, &desc, id); + let (_, error) = self.device_create_bind_group::(device, &desc, Some(id)); if let Some(e) = error { panic!("{e}"); } @@ -264,7 +249,8 @@ impl GlobalPlay for wgc::global::Global { } else { panic!("Unknown shader {}", data); }; - let (_, error) = self.device_create_shader_module::(device, &desc, source, id); + let (_, error) = + self.device_create_shader_module::(device, &desc, source, Some(id)); if let Some(e) = error { println!("shader compilation error:\n---{code}\n---\n{e}"); } @@ -282,11 +268,11 @@ impl GlobalPlay for wgc::global::Global { implicit_context .as_ref() .map(|ic| wgc::device::ImplicitPipelineIds { - root_id: ic.root_id, - group_ids: &ic.group_ids, + root_id: Some(ic.root_id), + group_ids: wgc::id::as_option_slice(&ic.group_ids), }); let (_, error) = - self.device_create_compute_pipeline::(device, &desc, id, implicit_ids); + self.device_create_compute_pipeline::(device, &desc, Some(id), implicit_ids); if let Some(e) = error { panic!("{e}"); } @@ -304,11 +290,11 @@ impl GlobalPlay for wgc::global::Global { implicit_context .as_ref() .map(|ic| wgc::device::ImplicitPipelineIds { - root_id: ic.root_id, - group_ids: &ic.group_ids, + root_id: Some(ic.root_id), + group_ids: wgc::id::as_option_slice(&ic.group_ids), }); let (_, error) = - self.device_create_render_pipeline::(device, &desc, id, implicit_ids); + self.device_create_render_pipeline::(device, &desc, Some(id), implicit_ids); if let Some(e) = error { panic!("{e}"); } @@ -322,7 +308,7 @@ impl GlobalPlay for wgc::global::Global { let (_, error) = self.render_bundle_encoder_finish::( bundle, &wgt::RenderBundleDescriptor { label: desc.label }, - id, + Some(id), ); if let Some(e) = error { panic!("{e}"); @@ -333,7 +319,7 @@ impl GlobalPlay for wgc::global::Global { } Action::CreateQuerySet { id, desc } => { self.device_maintain_ids::(device).unwrap(); - let (_, error) = self.device_create_query_set::(device, &desc, id); + let (_, error) = self.device_create_query_set::(device, &desc, Some(id)); if let Some(e) = error { panic!("{e}"); } @@ -375,7 +361,7 @@ impl GlobalPlay for wgc::global::Global { let (encoder, error) = self.device_create_command_encoder::( device, &wgt::CommandEncoderDescriptor { label: None }, - comb_manager.process(device.backend()).transmute(), + Some(comb_manager.process(device.backend()).transmute()), ); if let Some(e) = error { panic!("{e}"); diff --git a/player/tests/test.rs b/player/tests/test.rs index bf6e0b315..e38de1cea 100644 --- a/player/tests/test.rs +++ b/player/tests/test.rs @@ -10,7 +10,7 @@ !*/ #![cfg(not(target_arch = "wasm32"))] -use player::{GlobalPlay, IdentityPassThroughFactory}; +use player::GlobalPlay; use std::{ fs::{read_to_string, File}, io::{Read, Seek, SeekFrom}, @@ -100,7 +100,7 @@ impl Test<'_> { fn run( self, dir: &Path, - global: &wgc::global::Global, + global: &wgc::global::Global, adapter: wgc::id::AdapterId, test_num: u32, ) { @@ -114,8 +114,8 @@ impl Test<'_> { required_limits: wgt::Limits::default(), }, None, - device_id, - device_id.transmute() + Some(device_id), + Some(device_id.transmute()) )); if let Some(e) = error { panic!("{:?}", e); @@ -203,7 +203,6 @@ impl Corpus { let global = wgc::global::Global::new( "test", - IdentityPassThroughFactory, wgt::InstanceDescriptor { backends: corpus.backends, flags: wgt::InstanceFlags::debugging(), @@ -221,9 +220,7 @@ impl Corpus { force_fallback_adapter: false, compatible_surface: None, }, - wgc::instance::AdapterInputs::IdSet(&[wgc::id::Id::zip(0, 0, backend)], |id| { - id.backend() - }), + wgc::instance::AdapterInputs::IdSet(&[wgc::id::Id::zip(0, 0, backend)]), ) { Ok(adapter) => adapter, Err(_) => continue, diff --git a/wgpu-core/src/command/clear.rs b/wgpu-core/src/command/clear.rs index 1a4b4cdeb..2569fea1a 100644 --- a/wgpu-core/src/command/clear.rs +++ b/wgpu-core/src/command/clear.rs @@ -10,7 +10,6 @@ use crate::{ global::Global, hal_api::HalApi, id::{BufferId, CommandEncoderId, DeviceId, TextureId}, - identity::GlobalIdentityHandlerFactory, init_tracker::{MemoryInitKind, TextureInitRange}, resource::{Resource, Texture, TextureClearMode}, track::{TextureSelector, TextureTracker}, @@ -71,7 +70,7 @@ whereas subesource range specified start {subresource_base_array_layer} and coun Device(#[from] DeviceError), } -impl Global { +impl Global { pub fn command_encoder_clear_buffer( &self, command_encoder_id: CommandEncoderId, diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index afd9c5204..c2d75f3b5 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -18,7 +18,6 @@ use crate::{ hal_api::HalApi, hal_label, id, id::DeviceId, - identity::GlobalIdentityHandlerFactory, init_tracker::MemoryInitKind, pipeline, resource::{self}, @@ -340,7 +339,7 @@ impl State { // Common routines between render/compute -impl Global { +impl Global { pub fn command_encoder_run_compute_pass( &self, encoder_id: id::CommandEncoderId, diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 1201e30f0..2d5fca200 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -27,10 +27,7 @@ use crate::snatch::SnatchGuard; use crate::init_tracker::BufferInitTrackerAction; use crate::resource::{Resource, ResourceInfo, ResourceType}; use crate::track::{Tracker, UsageScope}; -use crate::{ - api_log, global::Global, hal_api::HalApi, id, identity::GlobalIdentityHandlerFactory, - resource_log, Label, -}; +use crate::{api_log, global::Global, hal_api::HalApi, id, resource_log, Label}; use hal::CommandEncoder as _; use parking_lot::Mutex; @@ -410,7 +407,7 @@ pub enum CommandEncoderError { Device(#[from] DeviceError), } -impl Global { +impl Global { pub fn command_encoder_finish( &self, encoder_id: id::CommandEncoderId, diff --git a/wgpu-core/src/command/query.rs b/wgpu-core/src/command/query.rs index ab97cfc37..39d7a9cc9 100644 --- a/wgpu-core/src/command/query.rs +++ b/wgpu-core/src/command/query.rs @@ -8,7 +8,6 @@ use crate::{ global::Global, hal_api::HalApi, id::{self, Id}, - identity::GlobalIdentityHandlerFactory, init_tracker::MemoryInitKind, resource::QuerySet, storage::Storage, @@ -346,7 +345,7 @@ pub(super) fn end_pipeline_statistics_query( } } -impl Global { +impl Global { pub fn command_encoder_write_timestamp( &self, command_encoder_id: id::CommandEncoderId, diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 786342a90..ec550caf1 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -20,7 +20,6 @@ use crate::{ global::Global, hal_api::HalApi, hal_label, id, - identity::GlobalIdentityHandlerFactory, init_tracker::{MemoryInitKind, TextureInitRange, TextureInitTrackerAction}, pipeline::{self, PipelineFlags}, resource::{Buffer, QuerySet, Texture, TextureView, TextureViewNotRenderableReason}, @@ -1303,7 +1302,7 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> { // Common routines between render/compute -impl Global { +impl Global { pub fn command_encoder_run_render_pass( &self, encoder_id: id::CommandEncoderId, diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index 6bde17c64..e52a6882e 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -9,7 +9,6 @@ use crate::{ global::Global, hal_api::HalApi, id::{BufferId, CommandEncoderId, DeviceId, TextureId}, - identity::GlobalIdentityHandlerFactory, init_tracker::{ has_copy_partial_init_tracker_coverage, MemoryInitKind, TextureInitRange, TextureInitTrackerAction, @@ -554,7 +553,7 @@ fn handle_dst_texture_init( Ok(()) } -impl Global { +impl Global { pub fn command_encoder_copy_buffer_to_buffer( &self, command_encoder_id: CommandEncoderId, diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index 8db2db913..daa42fdde 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -8,9 +8,7 @@ use crate::{ }, global::Global, hal_api::HalApi, - id::markers, id::{self, AdapterId, DeviceId, QueueId, SurfaceId}, - identity::{GlobalIdentityHandlerFactory, Input}, init_tracker::TextureInitTracker, instance::{self, Adapter, Surface}, pipeline, present, @@ -36,7 +34,7 @@ use std::{ use super::{ImplicitPipelineIds, InvalidDevice, UserClosures}; -impl Global { +impl Global { pub fn adapter_is_surface_supported( &self, adapter_id: AdapterId, @@ -147,12 +145,12 @@ impl Global { &self, device_id: DeviceId, desc: &resource::BufferDescriptor, - id_in: Input, + id_in: Option, ) -> (id::BufferId, Option) { profiling::scope!("Device::create_buffer"); let hub = A::hub(self); - let fid = hub.buffers.prepare::(id_in); + let fid = hub.buffers.prepare(id_in); let mut to_destroy: ArrayVec, 2> = ArrayVec::new(); let error = loop { @@ -310,20 +308,20 @@ impl Global { /// [`device_create_buffer`]: Global::device_create_buffer /// [`usage`]: https://www.w3.org/TR/webgpu/#dom-gputexturedescriptor-usage /// [`wgpu_types::BufferUsages`]: wgt::BufferUsages - pub fn create_buffer_error(&self, id_in: Input, label: Label) { + pub fn create_buffer_error(&self, id_in: Option, label: Label) { let hub = A::hub(self); - let fid = hub.buffers.prepare::(id_in); + let fid = hub.buffers.prepare(id_in); fid.assign_error(label.borrow_or_default()); } pub fn create_render_bundle_error( &self, - id_in: Input, + id_in: Option, label: Label, ) { let hub = A::hub(self); - let fid = hub.render_bundles.prepare::(id_in); + let fid = hub.render_bundles.prepare(id_in); fid.assign_error(label.borrow_or_default()); } @@ -331,9 +329,9 @@ impl Global { /// Assign `id_in` an error with the given `label`. /// /// See `create_buffer_error` for more context and explaination. - pub fn create_texture_error(&self, id_in: Input, label: Label) { + pub fn create_texture_error(&self, id_in: Option, label: Label) { let hub = A::hub(self); - let fid = hub.textures.prepare::(id_in); + let fid = hub.textures.prepare(id_in); fid.assign_error(label.borrow_or_default()); } @@ -546,13 +544,13 @@ impl Global { &self, device_id: DeviceId, desc: &resource::TextureDescriptor, - id_in: Input, + id_in: Option, ) -> (id::TextureId, Option) { profiling::scope!("Device::create_texture"); let hub = A::hub(self); - let fid = hub.textures.prepare::(id_in); + let fid = hub.textures.prepare(id_in); let error = loop { let device = match hub.devices.get(device_id) { @@ -600,13 +598,13 @@ impl Global { hal_texture: A::Texture, device_id: DeviceId, desc: &resource::TextureDescriptor, - id_in: Input, + id_in: Option, ) -> (id::TextureId, Option) { profiling::scope!("Device::create_texture_from_hal"); let hub = A::hub(self); - let fid = hub.textures.prepare::(id_in); + let fid = hub.textures.prepare(id_in); let error = loop { let device = match hub.devices.get(device_id) { @@ -674,12 +672,12 @@ impl Global { hal_buffer: A::Buffer, device_id: DeviceId, desc: &resource::BufferDescriptor, - id_in: Input, + id_in: Option, ) -> (id::BufferId, Option) { profiling::scope!("Device::create_buffer"); let hub = A::hub(self); - let fid = hub.buffers.prepare::(id_in); + let fid = hub.buffers.prepare(id_in); let error = loop { let device = match hub.devices.get(device_id) { @@ -784,13 +782,13 @@ impl Global { &self, texture_id: id::TextureId, desc: &resource::TextureViewDescriptor, - id_in: Input, + id_in: Option, ) -> (id::TextureViewId, Option) { profiling::scope!("Texture::create_view"); let hub = A::hub(self); - let fid = hub.texture_views.prepare::(id_in); + let fid = hub.texture_views.prepare(id_in); let error = loop { let texture = match hub.textures.get(texture_id) { @@ -874,12 +872,12 @@ impl Global { &self, device_id: DeviceId, desc: &resource::SamplerDescriptor, - id_in: Input, + id_in: Option, ) -> (id::SamplerId, Option) { profiling::scope!("Device::create_sampler"); let hub = A::hub(self); - let fid = hub.samplers.prepare::(id_in); + let fid = hub.samplers.prepare(id_in); let error = loop { let device = match hub.devices.get(device_id) { @@ -935,7 +933,7 @@ impl Global { &self, device_id: DeviceId, desc: &binding_model::BindGroupLayoutDescriptor, - id_in: Input, + id_in: Option, ) -> ( id::BindGroupLayoutId, Option, @@ -943,7 +941,7 @@ impl Global { profiling::scope!("Device::create_bind_group_layout"); let hub = A::hub(self); - let fid = hub.bind_group_layouts.prepare::(id_in); + let fid = hub.bind_group_layouts.prepare(id_in); let error = loop { let device = match hub.devices.get(device_id) { @@ -1005,7 +1003,7 @@ impl Global { return (id.unwrap(), None); }; - let fid = hub.bind_group_layouts.prepare::(id_in); + let fid = hub.bind_group_layouts.prepare(id_in); let id = fid.assign_error(desc.label.borrow_or_default()); (id, Some(error)) } @@ -1034,7 +1032,7 @@ impl Global { &self, device_id: DeviceId, desc: &binding_model::PipelineLayoutDescriptor, - id_in: Input, + id_in: Option, ) -> ( id::PipelineLayoutId, Option, @@ -1042,7 +1040,7 @@ impl Global { profiling::scope!("Device::create_pipeline_layout"); let hub = A::hub(self); - let fid = hub.pipeline_layouts.prepare::(id_in); + let fid = hub.pipeline_layouts.prepare(id_in); let error = loop { let device = match hub.devices.get(device_id) { @@ -1095,12 +1093,12 @@ impl Global { &self, device_id: DeviceId, desc: &binding_model::BindGroupDescriptor, - id_in: Input, + id_in: Option, ) -> (id::BindGroupId, Option) { profiling::scope!("Device::create_bind_group"); let hub = A::hub(self); - let fid = hub.bind_groups.prepare::(id_in); + let fid = hub.bind_groups.prepare(id_in); let error = loop { let device = match hub.devices.get(device_id) { @@ -1179,7 +1177,7 @@ impl Global { device_id: DeviceId, desc: &pipeline::ShaderModuleDescriptor, source: pipeline::ShaderModuleSource, - id_in: Input, + id_in: Option, ) -> ( id::ShaderModuleId, Option, @@ -1187,7 +1185,7 @@ impl Global { profiling::scope!("Device::create_shader_module"); let hub = A::hub(self); - let fid = hub.shader_modules.prepare::(id_in); + let fid = hub.shader_modules.prepare(id_in); let error = loop { let device = match hub.devices.get(device_id) { @@ -1257,7 +1255,7 @@ impl Global { device_id: DeviceId, desc: &pipeline::ShaderModuleDescriptor, source: Cow<[u32]>, - id_in: Input, + id_in: Option, ) -> ( id::ShaderModuleId, Option, @@ -1265,7 +1263,7 @@ impl Global { profiling::scope!("Device::create_shader_module"); let hub = A::hub(self); - let fid = hub.shader_modules.prepare::(id_in); + let fid = hub.shader_modules.prepare(id_in); let error = loop { let device = match hub.devices.get(device_id) { @@ -1319,14 +1317,12 @@ impl Global { &self, device_id: DeviceId, desc: &wgt::CommandEncoderDescriptor) -> ImplicitPipelineContext { ImplicitPipelineContext { - root_id: hub.pipeline_layouts.prepare::(self.root_id).into_id(), + root_id: hub.pipeline_layouts.prepare(self.root_id).into_id(), group_ids: self .group_ids .iter() - .map(|id_in| hub.bind_group_layouts.prepare::(*id_in).into_id()) + .map(|id_in| hub.bind_group_layouts.prepare(*id_in).into_id()) .collect(), } } diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index 4bd004622..08c5b767b 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -12,9 +12,7 @@ use crate::{ global::Global, hal_api::HalApi, hal_label, - id::markers, id::{self, QueueId}, - identity::{GlobalIdentityHandlerFactory, Input}, init_tracker::{has_copy_partial_init_tracker_coverage, TextureInitRange}, resource::{ Buffer, BufferAccessError, BufferMapState, DestroyedBuffer, DestroyedTexture, Resource, @@ -365,7 +363,7 @@ pub enum QueueSubmitError { //TODO: move out common parts of write_xxx. -impl Global { +impl Global { pub fn queue_write_buffer( &self, queue_id: QueueId, @@ -439,7 +437,7 @@ impl Global { &self, queue_id: QueueId, buffer_size: wgt::BufferSize, - id_in: Input, + id_in: Option, ) -> Result<(id::StagingBufferId, *mut u8), QueueWriteError> { profiling::scope!("Queue::create_staging_buffer"); let hub = A::hub(self); @@ -454,7 +452,7 @@ impl Global { let (staging_buffer, staging_buffer_ptr) = prepare_staging_buffer(device, buffer_size.get(), device.instance_flags)?; - let fid = hub.staging_buffers.prepare::(id_in); + let fid = hub.staging_buffers.prepare(id_in); let (id, _) = fid.assign(staging_buffer); resource_log!("Queue::create_staging_buffer {id:?}"); diff --git a/wgpu-core/src/error.rs b/wgpu-core/src/error.rs index 4a33207ca..91b46261a 100644 --- a/wgpu-core/src/error.rs +++ b/wgpu-core/src/error.rs @@ -1,11 +1,11 @@ use core::fmt; use std::error::Error; -use crate::{gfx_select, global::Global, identity::IdentityManagerFactory}; +use crate::{gfx_select, global::Global}; pub struct ErrorFormatter<'a> { writer: &'a mut dyn fmt::Write, - global: &'a Global, + global: &'a Global, } impl<'a> ErrorFormatter<'a> { @@ -94,7 +94,7 @@ pub trait PrettyError: Error + Sized { pub fn format_pretty_any( writer: &mut dyn fmt::Write, - global: &Global, + global: &Global, error: &(dyn Error + 'static), ) { let mut fmt = ErrorFormatter { writer, global }; diff --git a/wgpu-core/src/global.rs b/wgpu-core/src/global.rs index 950fabe2d..9a8c43bf3 100644 --- a/wgpu-core/src/global.rs +++ b/wgpu-core/src/global.rs @@ -1,11 +1,10 @@ -use std::{marker::PhantomData, sync::Arc}; +use std::sync::Arc; use wgt::Backend; use crate::{ hal_api::HalApi, hub::{HubReport, Hubs}, - identity::GlobalIdentityHandlerFactory, instance::{Instance, Surface}, registry::{Registry, RegistryReport}, resource_log, @@ -44,38 +43,31 @@ impl GlobalReport { } } -pub struct Global { +pub struct Global { pub instance: Instance, pub surfaces: Registry, pub(crate) hubs: Hubs, - _phantom: PhantomData, } -impl Global { - pub fn new(name: &str, factory: G, instance_desc: wgt::InstanceDescriptor) -> Self { +impl Global { + pub fn new(name: &str, instance_desc: wgt::InstanceDescriptor) -> Self { profiling::scope!("Global::new"); Self { instance: Instance::new(name, instance_desc), - surfaces: Registry::without_backend(&factory), - hubs: Hubs::new(&factory), - _phantom: PhantomData, + surfaces: Registry::without_backend(), + hubs: Hubs::new(), } } /// # Safety /// /// Refer to the creation of wgpu-hal Instance for every backend. - pub unsafe fn from_hal_instance( - name: &str, - factory: G, - hal_instance: A::Instance, - ) -> Self { + pub unsafe fn from_hal_instance(name: &str, hal_instance: A::Instance) -> Self { profiling::scope!("Global::new"); Self { instance: A::create_instance_from_hal(name, hal_instance), - surfaces: Registry::without_backend(&factory), - hubs: Hubs::new(&factory), - _phantom: PhantomData, + surfaces: Registry::without_backend(), + hubs: Hubs::new(), } } @@ -89,13 +81,12 @@ impl Global { /// # Safety /// /// - The raw handles obtained from the Instance must not be manually destroyed - pub unsafe fn from_instance(factory: G, instance: Instance) -> Self { + pub unsafe fn from_instance(instance: Instance) -> Self { profiling::scope!("Global::new"); Self { instance, - surfaces: Registry::without_backend(&factory), - hubs: Hubs::new(&factory), - _phantom: PhantomData, + surfaces: Registry::without_backend(), + hubs: Hubs::new(), } } @@ -137,7 +128,7 @@ impl Global { } } -impl Drop for Global { +impl Drop for Global { fn drop(&mut self) { profiling::scope!("Global::drop"); resource_log!("Global::drop"); @@ -175,7 +166,7 @@ impl Drop for Global { } #[cfg(send_sync)] -fn _test_send_sync(global: &Global) { +fn _test_send_sync(global: &Global) { fn test_internal(_: T) {} test_internal(global) } diff --git a/wgpu-core/src/hal_api.rs b/wgpu-core/src/hal_api.rs index d1dee98ed..7de507379 100644 --- a/wgpu-core/src/hal_api.rs +++ b/wgpu-core/src/hal_api.rs @@ -3,7 +3,6 @@ use wgt::{Backend, WasmNotSendSync}; use crate::{ global::Global, hub::Hub, - identity::GlobalIdentityHandlerFactory, instance::{HalSurface, Instance, Surface}, }; @@ -11,7 +10,7 @@ pub trait HalApi: hal::Api + 'static + WasmNotSendSync { const VARIANT: Backend; fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance; fn instance_as_hal(instance: &Instance) -> Option<&Self::Instance>; - fn hub(global: &Global) -> &Hub; + fn hub(global: &Global) -> &Hub; fn get_surface(surface: &Surface) -> Option<&HalSurface>; } @@ -23,7 +22,7 @@ impl HalApi for hal::api::Empty { fn instance_as_hal(_: &Instance) -> Option<&Self::Instance> { unimplemented!("called empty api") } - fn hub(_: &Global) -> &Hub { + fn hub(_: &Global) -> &Hub { unimplemented!("called empty api") } fn get_surface(_: &Surface) -> Option<&HalSurface> { @@ -44,7 +43,7 @@ impl HalApi for hal::api::Vulkan { fn instance_as_hal(instance: &Instance) -> Option<&Self::Instance> { instance.vulkan.as_ref() } - fn hub(global: &Global) -> &Hub { + fn hub(global: &Global) -> &Hub { &global.hubs.vulkan } fn get_surface(surface: &Surface) -> Option<&HalSurface> { @@ -65,7 +64,7 @@ impl HalApi for hal::api::Metal { fn instance_as_hal(instance: &Instance) -> Option<&Self::Instance> { instance.metal.as_ref() } - fn hub(global: &Global) -> &Hub { + fn hub(global: &Global) -> &Hub { &global.hubs.metal } fn get_surface(surface: &Surface) -> Option<&HalSurface> { @@ -86,7 +85,7 @@ impl HalApi for hal::api::Dx12 { fn instance_as_hal(instance: &Instance) -> Option<&Self::Instance> { instance.dx12.as_ref() } - fn hub(global: &Global) -> &Hub { + fn hub(global: &Global) -> &Hub { &global.hubs.dx12 } fn get_surface(surface: &Surface) -> Option<&HalSurface> { @@ -108,7 +107,7 @@ impl HalApi for hal::api::Gles { fn instance_as_hal(instance: &Instance) -> Option<&Self::Instance> { instance.gl.as_ref() } - fn hub(global: &Global) -> &Hub { + fn hub(global: &Global) -> &Hub { &global.hubs.gl } fn get_surface(surface: &Surface) -> Option<&HalSurface> { diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index 8494bef2b..7829484aa 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -40,7 +40,7 @@ specify the id, and they all return the id used. For example, the declaration of `Global::device_create_buffer` looks like this: ```ignore -impl Global { +impl Global { /* ... */ pub fn device_create_buffer( &self, @@ -60,15 +60,7 @@ itself to choose ids always pass `()`. In either case, the id ultimately assigned is returned as the first element of the tuple. Producing true identifiers from `id_in` values is the job of an -[`crate::identity::IdentityManager`], but only if the `IdentityHandlerFactory` -create it and then generated by it, otherwise ids will be received from outside. - -`Global::new` expects a `factory` argument that -implements the [`GlobalIdentityHandlerFactory`] trait, which extends -[`crate::identity::IdentityHandlerFactory`] for each resource id type `I`. This -trait, in turn, has a `spawn` method that constructs an -`crate::identity::IdentityManager` for the `Global` to use, -if ids should be generated by wgpu or will return None otherwise. +[`crate::identity::IdentityManager`] or ids will be received from outside through `Option` arguments. ## Id allocation and streaming @@ -105,7 +97,6 @@ as much, allowing subsequent operations using that id to be properly flagged as errors as well. [`gfx_select`]: crate::gfx_select -[`Input`]: crate::identity::IdentityHandlerFactory::Input [`process`]: crate::identity::IdentityManager::process [`Id`]: crate::id::Id [wrapped in a mutex]: trait.IdentityHandler.html#impl-IdentityHandler%3CI%3E-for-Mutex%3CIdentityManager%3E @@ -118,7 +109,6 @@ use crate::{ command::{CommandBuffer, RenderBundle}, device::{queue::Queue, Device}, hal_api::HalApi, - identity::GlobalIdentityHandlerFactory, instance::{Adapter, HalSurface, Surface}, pipeline::{ComputePipeline, RenderPipeline, ShaderModule}, registry::{Registry, RegistryReport}, @@ -199,25 +189,25 @@ pub struct Hub { } impl Hub { - fn new(factory: &F) -> Self { + fn new() -> Self { Self { - adapters: Registry::new(A::VARIANT, factory), - devices: Registry::new(A::VARIANT, factory), - queues: Registry::new(A::VARIANT, factory), - pipeline_layouts: Registry::new(A::VARIANT, factory), - shader_modules: Registry::new(A::VARIANT, factory), - bind_group_layouts: Registry::new(A::VARIANT, factory), - bind_groups: Registry::new(A::VARIANT, factory), - command_buffers: Registry::new(A::VARIANT, factory), - render_bundles: Registry::new(A::VARIANT, factory), - render_pipelines: Registry::new(A::VARIANT, factory), - compute_pipelines: Registry::new(A::VARIANT, factory), - query_sets: Registry::new(A::VARIANT, factory), - buffers: Registry::new(A::VARIANT, factory), - staging_buffers: Registry::new(A::VARIANT, factory), - textures: Registry::new(A::VARIANT, factory), - texture_views: Registry::new(A::VARIANT, factory), - samplers: Registry::new(A::VARIANT, factory), + adapters: Registry::new(A::VARIANT), + devices: Registry::new(A::VARIANT), + queues: Registry::new(A::VARIANT), + pipeline_layouts: Registry::new(A::VARIANT), + shader_modules: Registry::new(A::VARIANT), + bind_group_layouts: Registry::new(A::VARIANT), + bind_groups: Registry::new(A::VARIANT), + command_buffers: Registry::new(A::VARIANT), + render_bundles: Registry::new(A::VARIANT), + render_pipelines: Registry::new(A::VARIANT), + compute_pipelines: Registry::new(A::VARIANT), + query_sets: Registry::new(A::VARIANT), + buffers: Registry::new(A::VARIANT), + staging_buffers: Registry::new(A::VARIANT), + textures: Registry::new(A::VARIANT), + texture_views: Registry::new(A::VARIANT), + samplers: Registry::new(A::VARIANT), } } @@ -313,18 +303,18 @@ pub struct Hubs { } impl Hubs { - pub(crate) fn new(factory: &F) -> Self { + pub(crate) fn new() -> Self { Self { #[cfg(vulkan)] - vulkan: Hub::new(factory), + vulkan: Hub::new(), #[cfg(metal)] - metal: Hub::new(factory), + metal: Hub::new(), #[cfg(dx12)] - dx12: Hub::new(factory), + dx12: Hub::new(), #[cfg(gles)] - gl: Hub::new(factory), + gl: Hub::new(), #[cfg(all(not(vulkan), not(metal), not(dx12), not(gles)))] - empty: Hub::new(factory), + empty: Hub::new(), } } } diff --git a/wgpu-core/src/id.rs b/wgpu-core/src/id.rs index 56eaf6105..0d5b1cb3f 100644 --- a/wgpu-core/src/id.rs +++ b/wgpu-core/src/id.rs @@ -71,9 +71,15 @@ impl RawId { } } -/// Coerce a slice of identifiers into a slice of raw identifiers. -pub fn into_raw_slice(ids: &[Id]) -> &[RawId] { - // SAFETY: Any Id is repr(transparent) over `RawId`. +/// Coerce a slice of identifiers into a slice of optional raw identifiers. +/// +/// There's two reasons why we know this is correct: +/// * `Option` is guarnateed to be niche-filled to 0's. +/// * The `T` in `Option` can inhabit any representation except 0's, since +/// its underlying representation is `NonZero*`. +pub fn as_option_slice(ids: &[Id]) -> &[Option>] { + // SAFETY: Any Id is repr(transparent) over `Option`, since both + // are backed by non-zero types. unsafe { std::slice::from_raw_parts(ids.as_ptr().cast(), ids.len()) } } diff --git a/wgpu-core/src/identity.rs b/wgpu-core/src/identity.rs index 44989a6d4..0e34055c7 100644 --- a/wgpu-core/src/identity.rs +++ b/wgpu-core/src/identity.rs @@ -2,10 +2,10 @@ use parking_lot::Mutex; use wgt::Backend; use crate::{ - id::{self, Id, Marker}, + id::{Id, Marker}, Epoch, FastHashMap, Index, }; -use std::{fmt::Debug, marker::PhantomData, sync::Arc}; +use std::{fmt::Debug, marker::PhantomData}; /// A simple structure to allocate [`Id`] identifiers. /// @@ -112,74 +112,10 @@ impl IdentityManager { } } -/// A type that can produce [`IdentityManager`] filters for ids of type `I`. -/// -/// See the module-level documentation for details. -pub trait IdentityHandlerFactory { - type Input: Copy; - /// Create an [`IdentityManager`] implementation that can - /// transform proto-ids into ids of type `I`. - /// It can return None if ids are passed from outside - /// and are not generated by wgpu - /// - /// [`IdentityManager`]: IdentityManager - fn spawn(&self) -> Arc> { - Arc::new(IdentityManager::new()) - } - fn autogenerate_ids() -> bool; - fn input_to_id(id_in: Self::Input) -> Id; -} - -/// A global identity handler factory based on [`IdentityManager`]. -/// -/// Each of this type's `IdentityHandlerFactory::spawn` methods -/// returns a `Mutex>`, which allocates fresh `I` -/// ids itself, and takes `()` as its proto-id type. -#[derive(Debug)] -pub struct IdentityManagerFactory; - -impl IdentityHandlerFactory for IdentityManagerFactory { - type Input = (); - fn autogenerate_ids() -> bool { - true - } - - fn input_to_id(_id_in: Self::Input) -> Id { - unreachable!("It should not be called") - } -} - -/// A factory that can build [`IdentityManager`]s for all resource -/// types. -pub trait GlobalIdentityHandlerFactory: - IdentityHandlerFactory - + IdentityHandlerFactory - + IdentityHandlerFactory - + IdentityHandlerFactory - + IdentityHandlerFactory - + IdentityHandlerFactory - + IdentityHandlerFactory - + IdentityHandlerFactory - + IdentityHandlerFactory - + IdentityHandlerFactory - + IdentityHandlerFactory - + IdentityHandlerFactory - + IdentityHandlerFactory - + IdentityHandlerFactory - + IdentityHandlerFactory - + IdentityHandlerFactory - + IdentityHandlerFactory - + IdentityHandlerFactory - + IdentityHandlerFactory -{ -} - -impl GlobalIdentityHandlerFactory for IdentityManagerFactory {} - -pub type Input = >::Input; - #[test] fn test_epoch_end_of_life() { + use crate::id; + let man = IdentityManager::::new(); let forced_id = man.mark_as_used(id::BufferId::zip(0, 1, Backend::Empty)); assert_eq!(forced_id.unzip().0, 0); diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index cb5871d6b..4c3134237 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -7,8 +7,7 @@ use crate::{ global::Global, hal_api::HalApi, id::markers, - id::{AdapterId, DeviceId, QueueId, SurfaceId}, - identity::{GlobalIdentityHandlerFactory, Input}, + id::{AdapterId, DeviceId, Id, Marker, QueueId, SurfaceId}, present::Presentation, resource::{Resource, ResourceInfo, ResourceType}, resource_log, LabelHelpers, DOWNLEVEL_WARNING_MESSAGE, @@ -157,7 +156,7 @@ pub struct Surface { impl Resource for Surface { const TYPE: ResourceType = "Surface"; - type Marker = crate::id::markers::Surface; + type Marker = markers::Surface; fn as_info(&self) -> &ResourceInfo { &self.info @@ -388,7 +387,7 @@ impl Adapter { impl Resource for Adapter { const TYPE: ResourceType = "Adapter"; - type Marker = crate::id::markers::Adapter; + type Marker = markers::Adapter; fn as_info(&self) -> &ResourceInfo { &self.info @@ -439,15 +438,15 @@ pub enum RequestDeviceError { UnsupportedFeature(wgt::Features), } -pub enum AdapterInputs<'a, I> { - IdSet(&'a [I], fn(&I) -> Backend), - Mask(Backends, fn(Backend) -> I), +pub enum AdapterInputs<'a, M: Marker> { + IdSet(&'a [Id]), + Mask(Backends, fn(Backend) -> Option>), } -impl AdapterInputs<'_, I> { - fn find(&self, b: Backend) -> Option { +impl AdapterInputs<'_, M> { + fn find(&self, b: Backend) -> Option>> { match *self { - Self::IdSet(ids, ref fun) => ids.iter().find(|id| fun(id) == b).copied(), + Self::IdSet(ids) => Some(Some(ids.iter().find(|id| id.backend() == b).copied()?)), Self::Mask(bits, ref fun) => { if bits.contains(b.into()) { Some(fun(b)) @@ -472,7 +471,7 @@ pub enum RequestAdapterError { InvalidSurface(SurfaceId), } -impl Global { +impl Global { /// # Safety /// /// - `display_handle` must be a valid object to create a surface upon. @@ -483,7 +482,7 @@ impl Global { &self, display_handle: raw_window_handle::RawDisplayHandle, window_handle: raw_window_handle::RawWindowHandle, - id_in: Input, + id_in: Option, ) -> Result { profiling::scope!("Instance::create_surface"); @@ -531,7 +530,7 @@ impl Global { raw: hal_surface, }; - let (id, _) = self.surfaces.prepare::(id_in).assign(surface); + let (id, _) = self.surfaces.prepare(id_in).assign(surface); Ok(id) } @@ -542,7 +541,7 @@ impl Global { pub unsafe fn instance_create_surface_metal( &self, layer: *mut std::ffi::c_void, - id_in: Input, + id_in: Option, ) -> SurfaceId { profiling::scope!("Instance::create_surface_metal"); @@ -566,7 +565,7 @@ impl Global { }, }; - let (id, _) = self.surfaces.prepare::(id_in).assign(surface); + let (id, _) = self.surfaces.prepare(id_in).assign(surface); id } @@ -577,7 +576,7 @@ impl Global { pub unsafe fn instance_create_surface_from_visual( &self, visual: *mut std::ffi::c_void, - id_in: Input, + id_in: Option, ) -> SurfaceId { profiling::scope!("Instance::instance_create_surface_from_visual"); @@ -597,7 +596,7 @@ impl Global { }, }; - let (id, _) = self.surfaces.prepare::(id_in).assign(surface); + let (id, _) = self.surfaces.prepare(id_in).assign(surface); id } @@ -608,7 +607,7 @@ impl Global { pub unsafe fn instance_create_surface_from_surface_handle( &self, surface_handle: *mut std::ffi::c_void, - id_in: Input, + id_in: Option, ) -> SurfaceId { profiling::scope!("Instance::instance_create_surface_from_surface_handle"); @@ -630,7 +629,7 @@ impl Global { }, }; - let (id, _) = self.surfaces.prepare::(id_in).assign(surface); + let (id, _) = self.surfaces.prepare(id_in).assign(surface); id } @@ -641,7 +640,7 @@ impl Global { pub unsafe fn instance_create_surface_from_swap_chain_panel( &self, swap_chain_panel: *mut std::ffi::c_void, - id_in: Input, + id_in: Option, ) -> SurfaceId { profiling::scope!("Instance::instance_create_surface_from_swap_chain_panel"); @@ -663,7 +662,7 @@ impl Global { }, }; - let (id, _) = self.surfaces.prepare::(id_in).assign(surface); + let (id, _) = self.surfaces.prepare(id_in).assign(surface); id } @@ -672,11 +671,7 @@ impl Global { api_log!("Surface::drop {id:?}"); - fn unconfigure( - global: &Global, - surface: &AnySurface, - present: &Presentation, - ) { + fn unconfigure(global: &Global, surface: &AnySurface, present: &Presentation) { let hub = HalApi::hub(global); if let Some(hal_surface) = surface.downcast_ref::() { if let Some(device) = present.device.downcast_ref::() { @@ -689,13 +684,13 @@ impl Global { if let Some(surface) = Arc::into_inner(surface.unwrap()) { if let Some(present) = surface.presentation.lock().take() { #[cfg(vulkan)] - unconfigure::<_, hal::api::Vulkan>(self, &surface.raw, &present); + unconfigure::(self, &surface.raw, &present); #[cfg(metal)] - unconfigure::<_, hal::api::Metal>(self, &surface.raw, &present); + unconfigure::(self, &surface.raw, &present); #[cfg(dx12)] - unconfigure::<_, hal::api::Dx12>(self, &surface.raw, &present); + unconfigure::(self, &surface.raw, &present); #[cfg(gles)] - unconfigure::<_, hal::api::Gles>(self, &surface.raw, &present); + unconfigure::(self, &surface.raw, &present); } self.instance.destroy_surface(surface); @@ -708,7 +703,7 @@ impl Global { &self, _: A, instance: &Option, - inputs: &AdapterInputs>, + inputs: &AdapterInputs, list: &mut Vec, ) { let inst = match *instance { @@ -727,15 +722,12 @@ impl Global { for raw in hal_adapters { let adapter = Adapter::new(raw); log::info!("Adapter {:?} {:?}", A::VARIANT, adapter.raw.info); - let (id, _) = hub.adapters.prepare::(id_backend).assign(adapter); + let (id, _) = hub.adapters.prepare(id_backend).assign(adapter); list.push(id); } } - pub fn enumerate_adapters( - &self, - inputs: AdapterInputs>, - ) -> Vec { + pub fn enumerate_adapters(&self, inputs: AdapterInputs) -> Vec { profiling::scope!("Instance::enumerate_adapters"); api_log!("Instance::enumerate_adapters"); @@ -766,7 +758,7 @@ impl Global { fn select( &self, selected: &mut usize, - new_id: Option>, + new_id: Option, mut list: Vec>, ) -> Option { match selected.checked_sub(list.len()) { @@ -777,10 +769,7 @@ impl Global { None => { let adapter = Adapter::new(list.swap_remove(*selected)); log::info!("Adapter {:?} {:?}", A::VARIANT, adapter.raw.info); - let (id, _) = HalApi::hub(self) - .adapters - .prepare::(new_id.unwrap()) - .assign(adapter); + let (id, _) = HalApi::hub(self).adapters.prepare(new_id).assign(adapter); Some(id) } } @@ -789,22 +778,22 @@ impl Global { pub fn request_adapter( &self, desc: &RequestAdapterOptions, - inputs: AdapterInputs>, + inputs: AdapterInputs, ) -> Result { profiling::scope!("Instance::request_adapter"); api_log!("Instance::request_adapter"); - fn gather( + fn gather( _: A, instance: Option<&A::Instance>, - inputs: &AdapterInputs, + inputs: &AdapterInputs, compatible_surface: Option<&Surface>, force_software: bool, device_types: &mut Vec, - ) -> (Option, Vec>) { + ) -> (Option>, Vec>) { let id = inputs.find(A::VARIANT); - match instance { - Some(inst) if id.is_some() => { + match (id, instance) { + (Some(id), Some(inst)) => { let mut adapters = unsafe { inst.enumerate_adapters() }; if force_software { adapters.retain(|exposed| exposed.info.device_type == wgt::DeviceType::Cpu); @@ -824,7 +813,7 @@ impl Global { device_types.extend(adapters.iter().map(|ad| ad.info.device_type)); (id, adapters) } - _ => (id, Vec::new()), + _ => (None, Vec::new()), } } @@ -955,11 +944,11 @@ impl Global { pub unsafe fn create_adapter_from_hal( &self, hal_adapter: hal::ExposedAdapter, - input: Input, + input: Option, ) -> AdapterId { profiling::scope!("Instance::create_adapter_from_hal"); - let fid = A::hub(self).adapters.prepare::(input); + let fid = A::hub(self).adapters.prepare(input); let (id, _adapter): (_, Arc>) = match A::VARIANT { #[cfg(vulkan)] @@ -1066,21 +1055,21 @@ impl Global { } } -impl Global { +impl Global { pub fn adapter_request_device( &self, adapter_id: AdapterId, desc: &DeviceDescriptor, trace_path: Option<&std::path::Path>, - device_id_in: Input, - queue_id_in: Input, + device_id_in: Option, + queue_id_in: Option, ) -> (DeviceId, QueueId, Option) { profiling::scope!("Adapter::request_device"); api_log!("Adapter::request_device"); let hub = A::hub(self); - let device_fid = hub.devices.prepare::(device_id_in); - let queue_fid = hub.queues.prepare::(queue_id_in); + let device_fid = hub.devices.prepare(device_id_in); + let queue_fid = hub.queues.prepare(queue_id_in); let error = loop { let adapter = match hub.adapters.get(adapter_id) { @@ -1121,14 +1110,14 @@ impl Global { hal_device: OpenDevice, desc: &DeviceDescriptor, trace_path: Option<&std::path::Path>, - device_id_in: Input, - queue_id_in: Input, + device_id_in: Option, + queue_id_in: Option, ) -> (DeviceId, QueueId, Option) { profiling::scope!("Global::create_device_from_hal"); let hub = A::hub(self); - let devices_fid = hub.devices.prepare::(device_id_in); - let queues_fid = hub.queues.prepare::(queue_id_in); + let devices_fid = hub.devices.prepare(device_id_in); + let queues_fid = hub.queues.prepare(queue_id_in); let error = loop { let adapter = match hub.adapters.get(adapter_id) { diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index 5413be6b6..33a288715 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -289,7 +289,7 @@ define_backend_caller! { gfx_if_empty, gfx_if_empty_hidden, "empty" if all( /// where the `device_create_buffer` method is defined like this: /// /// ```ignore -/// impl<...> Global<...> { +/// impl Global { /// pub fn device_create_buffer(&self, ...) -> ... /// { ... } /// } diff --git a/wgpu-core/src/present.rs b/wgpu-core/src/present.rs index 081ab736d..2452825ae 100644 --- a/wgpu-core/src/present.rs +++ b/wgpu-core/src/present.rs @@ -22,10 +22,7 @@ use crate::{ device::{DeviceError, MissingDownlevelFlags, WaitIdleError}, global::Global, hal_api::HalApi, - hal_label, - id::markers, - id::{SurfaceId, TextureId}, - identity::{GlobalIdentityHandlerFactory, Input}, + hal_label, id, init_tracker::TextureInitTracker, resource::{self, ResourceInfo}, snatch::Snatchable, @@ -43,7 +40,7 @@ const FRAME_TIMEOUT_MS: u32 = 1000; pub(crate) struct Presentation { pub(crate) device: AnyDevice, pub(crate) config: wgt::SurfaceConfiguration>, - pub(crate) acquired_texture: Option, + pub(crate) acquired_texture: Option, } #[derive(Clone, Debug, Error)] @@ -119,20 +116,20 @@ impl From for ConfigureSurfaceError { #[derive(Debug)] pub struct SurfaceOutput { pub status: Status, - pub texture_id: Option, + pub texture_id: Option, } -impl Global { +impl Global { pub fn surface_get_current_texture( &self, - surface_id: SurfaceId, - texture_id_in: Input, + surface_id: id::SurfaceId, + texture_id_in: Option, ) -> Result { profiling::scope!("SwapChain::get_next_texture"); let hub = A::hub(self); - let fid = hub.textures.prepare::(texture_id_in); + let fid = hub.textures.prepare(texture_id_in); let surface = self .surfaces @@ -281,7 +278,7 @@ impl Global { pub fn surface_present( &self, - surface_id: SurfaceId, + surface_id: id::SurfaceId, ) -> Result { profiling::scope!("SwapChain::present"); @@ -379,7 +376,7 @@ impl Global { pub fn surface_texture_discard( &self, - surface_id: SurfaceId, + surface_id: id::SurfaceId, ) -> Result<(), SurfaceError> { profiling::scope!("SwapChain::discard"); diff --git a/wgpu-core/src/registry.rs b/wgpu-core/src/registry.rs index c2b8c38d9..f55809770 100644 --- a/wgpu-core/src/registry.rs +++ b/wgpu-core/src/registry.rs @@ -4,8 +4,8 @@ use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; use wgt::Backend; use crate::{ - id::{self, Id, Marker}, - identity::{IdentityHandlerFactory, IdentityManager}, + id::Id, + identity::IdentityManager, resource::Resource, storage::{Element, InvalidId, Storage}, }; @@ -44,16 +44,16 @@ pub struct Registry { } impl Registry { - pub(crate) fn new>(backend: Backend, factory: &F) -> Self { + pub(crate) fn new(backend: Backend) -> Self { Self { - identity: factory.spawn(), + identity: Arc::new(IdentityManager::new()), storage: RwLock::new(Storage::new()), backend, } } - pub(crate) fn without_backend>(factory: &F) -> Self { - Self::new(Backend::Empty, factory) + pub(crate) fn without_backend() -> Self { + Self::new(Backend::Empty) } } @@ -108,17 +108,14 @@ impl FutureId<'_, T> { } impl Registry { - pub(crate) fn prepare(&self, id_in: F::Input) -> FutureId - where - F: IdentityHandlerFactory, - T::Marker: id::transmute::Transmute, - { + pub(crate) fn prepare(&self, id_in: Option>) -> FutureId { FutureId { - id: if F::autogenerate_ids() { - self.identity.process(self.backend) - } else { - self.identity - .mark_as_used(F::input_to_id(id_in).transmute()) + id: match id_in { + Some(id_in) => { + self.identity.mark_as_used(id_in); + id_in + } + None => self.identity.process(self.backend), }, identity: self.identity.clone(), data: &self.storage, diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index fad1aa610..07af19e14 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -9,7 +9,7 @@ use crate::{ global::Global, hal_api::HalApi, id::{AdapterId, BufferId, DeviceId, Id, Marker, SurfaceId, TextureId}, - identity::{GlobalIdentityHandlerFactory, IdentityManager}, + identity::IdentityManager, init_tracker::{BufferInitTracker, TextureInitTracker}, resource, resource_log, snatch::{ExclusiveSnatchGuard, SnatchGuard, Snatchable}, @@ -926,7 +926,7 @@ impl Texture { } } -impl Global { +impl Global { /// # Safety /// /// - The raw texture handle must not be manually destroyed diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index 3aec48fb6..6a9d9fa4f 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -28,7 +28,7 @@ use wgt::WasmNotSendSync; const LABEL: &str = "label"; -pub struct ContextWgpuCore(wgc::global::Global); +pub struct ContextWgpuCore(wgc::global::Global); impl Drop for ContextWgpuCore { fn drop(&mut self) { @@ -46,13 +46,7 @@ impl fmt::Debug for ContextWgpuCore { impl ContextWgpuCore { pub unsafe fn from_hal_instance(hal_instance: A::Instance) -> Self { - Self(unsafe { - wgc::global::Global::from_hal_instance::( - "wgpu", - wgc::identity::IdentityManagerFactory, - hal_instance, - ) - }) + Self(unsafe { wgc::global::Global::from_hal_instance::("wgpu", hal_instance) }) } /// # Safety @@ -63,25 +57,23 @@ impl ContextWgpuCore { } pub unsafe fn from_core_instance(core_instance: wgc::instance::Instance) -> Self { - Self(unsafe { - wgc::global::Global::from_instance(wgc::identity::IdentityManagerFactory, core_instance) - }) + Self(unsafe { wgc::global::Global::from_instance(core_instance) }) } - pub(crate) fn global(&self) -> &wgc::global::Global { + pub(crate) fn global(&self) -> &wgc::global::Global { &self.0 } pub fn enumerate_adapters(&self, backends: wgt::Backends) -> Vec { self.0 - .enumerate_adapters(wgc::instance::AdapterInputs::Mask(backends, |_| ())) + .enumerate_adapters(wgc::instance::AdapterInputs::Mask(backends, |_| None)) } pub unsafe fn create_adapter_from_hal( &self, hal_adapter: hal::ExposedAdapter, ) -> wgc::id::AdapterId { - unsafe { self.0.create_adapter_from_hal(hal_adapter, ()) } + unsafe { self.0.create_adapter_from_hal(hal_adapter, None) } } pub unsafe fn adapter_as_hal< @@ -112,8 +104,8 @@ impl ContextWgpuCore { hal_device, &desc.map_label(|l| l.map(Borrowed)), trace_dir, - (), - (), + None, + None, ) }; if let Some(err) = error { @@ -141,7 +133,7 @@ impl ContextWgpuCore { 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::(hal_texture, device.id, &descriptor, ()) + .create_texture_from_hal::(hal_texture, device.id, &descriptor, None) }; if let Some(cause) = error { self.handle_error( @@ -169,7 +161,7 @@ impl ContextWgpuCore { hal_buffer, device.id, &desc.map_label(|l| l.map(Borrowed)), - (), + None, ) }; if let Some(cause) = error { @@ -509,11 +501,7 @@ impl crate::Context for ContextWgpuCore { type PopErrorScopeFuture = Ready>; fn init(instance_desc: wgt::InstanceDescriptor) -> Self { - Self(wgc::global::Global::new( - "wgpu", - wgc::identity::IdentityManagerFactory, - instance_desc, - )) + Self(wgc::global::Global::new("wgpu", instance_desc)) } unsafe fn instance_create_surface( @@ -526,29 +514,29 @@ impl crate::Context for ContextWgpuCore { raw_window_handle, } => unsafe { self.0 - .instance_create_surface(raw_display_handle, raw_window_handle, ())? + .instance_create_surface(raw_display_handle, raw_window_handle, None)? }, #[cfg(metal)] SurfaceTargetUnsafe::CoreAnimationLayer(layer) => unsafe { - self.0.instance_create_surface_metal(layer, ()) + self.0.instance_create_surface_metal(layer, None) }, #[cfg(dx12)] SurfaceTargetUnsafe::CompositionVisual(visual) => unsafe { - self.0.instance_create_surface_from_visual(visual, ()) + self.0.instance_create_surface_from_visual(visual, None) }, #[cfg(dx12)] SurfaceTargetUnsafe::SurfaceHandle(surface_handle) => unsafe { self.0 - .instance_create_surface_from_surface_handle(surface_handle, ()) + .instance_create_surface_from_surface_handle(surface_handle, None) }, #[cfg(dx12)] SurfaceTargetUnsafe::SwapChainPanel(swap_chain_panel) => unsafe { self.0 - .instance_create_surface_from_swap_chain_panel(swap_chain_panel, ()) + .instance_create_surface_from_swap_chain_panel(swap_chain_panel, None) }, }; @@ -571,7 +559,7 @@ impl crate::Context for ContextWgpuCore { force_fallback_adapter: options.force_fallback_adapter, compatible_surface: options.compatible_surface.map(|surface| surface.id.into()), }, - wgc::instance::AdapterInputs::Mask(wgt::Backends::all(), |_| ()), + wgc::instance::AdapterInputs::Mask(wgt::Backends::all(), |_| None), ); ready(id.ok().map(|id| (id, ()))) } @@ -587,8 +575,8 @@ impl crate::Context for ContextWgpuCore { *adapter, &desc.map_label(|l| l.map(Borrowed)), trace_dir, - (), - () + None, + None )); if let Some(err) = error { return ready(Err(err.into())); @@ -741,7 +729,7 @@ impl crate::Context for ContextWgpuCore { .lock() .expect("Surface was not configured?"); match wgc::gfx_select!( - device_id => self.0.surface_get_current_texture(*surface, ()) + device_id => self.0.surface_get_current_texture(*surface, None) ) { Ok(wgc::present::SurfaceOutput { status, texture_id }) => { let (id, data) = { @@ -861,7 +849,7 @@ impl crate::Context for ContextWgpuCore { ShaderSource::Dummy(_) => panic!("found `ShaderSource::Dummy`"), }; let (id, error) = wgc::gfx_select!( - device => self.0.device_create_shader_module(*device, &descriptor, source, ()) + device => self.0.device_create_shader_module(*device, &descriptor, source, None) ); if let Some(cause) = error { self.handle_error( @@ -888,7 +876,7 @@ impl crate::Context for ContextWgpuCore { shader_bound_checks: unsafe { wgt::ShaderBoundChecks::unchecked() }, }; let (id, error) = wgc::gfx_select!( - device => self.0.device_create_shader_module_spirv(*device, &descriptor, Borrowed(&desc.source), ()) + device => self.0.device_create_shader_module_spirv(*device, &descriptor, Borrowed(&desc.source), None) ); if let Some(cause) = error { self.handle_error( @@ -913,7 +901,7 @@ impl crate::Context for ContextWgpuCore { entries: Borrowed(desc.entries), }; let (id, error) = wgc::gfx_select!( - device => self.0.device_create_bind_group_layout(*device, &descriptor, ()) + device => self.0.device_create_bind_group_layout(*device, &descriptor, None) ); if let Some(cause) = error { self.handle_error( @@ -1027,7 +1015,7 @@ impl crate::Context for ContextWgpuCore { let (id, error) = wgc::gfx_select!(device => self.0.device_create_bind_group( *device, &descriptor, - () + None )); if let Some(cause) = error { self.handle_error( @@ -1069,7 +1057,7 @@ impl crate::Context for ContextWgpuCore { let (id, error) = wgc::gfx_select!(device => self.0.device_create_pipeline_layout( *device, &descriptor, - () + None )); if let Some(cause) = error { self.handle_error( @@ -1104,8 +1092,8 @@ impl crate::Context for ContextWgpuCore { let implicit_pipeline_ids = match desc.layout { Some(_) => None, None => Some(wgc::device::ImplicitPipelineIds { - root_id: (), - group_ids: &[(); wgc::MAX_BIND_GROUPS], + root_id: None, + group_ids: &[None; wgc::MAX_BIND_GROUPS], }), }; let descriptor = pipe::RenderPipelineDescriptor { @@ -1134,7 +1122,7 @@ impl crate::Context for ContextWgpuCore { let (id, error) = wgc::gfx_select!(device => self.0.device_create_render_pipeline( *device, &descriptor, - (), + None, implicit_pipeline_ids )); if let Some(cause) = error { @@ -1163,8 +1151,8 @@ impl crate::Context for ContextWgpuCore { let implicit_pipeline_ids = match desc.layout { Some(_) => None, None => Some(wgc::device::ImplicitPipelineIds { - root_id: (), - group_ids: &[(); wgc::MAX_BIND_GROUPS], + root_id: None, + group_ids: &[None; wgc::MAX_BIND_GROUPS], }), }; let descriptor = pipe::ComputePipelineDescriptor { @@ -1179,7 +1167,7 @@ impl crate::Context for ContextWgpuCore { let (id, error) = wgc::gfx_select!(device => self.0.device_create_compute_pipeline( *device, &descriptor, - (), + None, implicit_pipeline_ids )); if let Some(cause) = error { @@ -1210,7 +1198,7 @@ impl crate::Context for ContextWgpuCore { let (id, error) = wgc::gfx_select!(device => self.0.device_create_buffer( *device, &desc.map_label(|l| l.map(Borrowed)), - () + None )); if let Some(cause) = error { self.handle_error( @@ -1238,7 +1226,7 @@ impl crate::Context for ContextWgpuCore { let (id, error) = wgc::gfx_select!(device => self.0.device_create_texture( *device, &wgt_desc, - () + None )); if let Some(cause) = error { self.handle_error( @@ -1283,7 +1271,7 @@ impl crate::Context for ContextWgpuCore { let (id, error) = wgc::gfx_select!(device => self.0.device_create_sampler( *device, &descriptor, - () + None )); if let Some(cause) = error { self.handle_error( @@ -1305,7 +1293,7 @@ impl crate::Context for ContextWgpuCore { let (id, error) = wgc::gfx_select!(device => self.0.device_create_query_set( *device, &desc.map_label(|l| l.map(Borrowed)), - () + None )); if let Some(cause) = error { self.handle_error_nolabel(&device_data.error_sink, cause, "Device::create_query_set"); @@ -1321,7 +1309,7 @@ impl crate::Context for ContextWgpuCore { let (id, error) = wgc::gfx_select!(device => self.0.device_create_command_encoder( *device, &desc.map_label(|l| l.map(Borrowed)), - () + None )); if let Some(cause) = error { self.handle_error( @@ -1520,7 +1508,7 @@ impl crate::Context for ContextWgpuCore { }, }; let (id, error) = wgc::gfx_select!( - texture => self.0.texture_create_view(*texture, &descriptor, ()) + texture => self.0.texture_create_view(*texture, &descriptor, None) ); if let Some(cause) = error { self.handle_error( @@ -1654,7 +1642,7 @@ impl crate::Context for ContextWgpuCore { _pipeline_data: &Self::ComputePipelineData, index: u32, ) -> (Self::BindGroupLayoutId, Self::BindGroupLayoutData) { - let (id, error) = wgc::gfx_select!(*pipeline => self.0.compute_pipeline_get_bind_group_layout(*pipeline, index, ())); + let (id, error) = wgc::gfx_select!(*pipeline => self.0.compute_pipeline_get_bind_group_layout(*pipeline, index, None)); if let Some(err) = error { panic!("Error reflecting bind group {index}: {err}"); } @@ -1667,7 +1655,7 @@ impl crate::Context for ContextWgpuCore { _pipeline_data: &Self::RenderPipelineData, index: u32, ) -> (Self::BindGroupLayoutId, Self::BindGroupLayoutData) { - let (id, error) = wgc::gfx_select!(*pipeline => self.0.render_pipeline_get_bind_group_layout(*pipeline, index, ())); + let (id, error) = wgc::gfx_select!(*pipeline => self.0.render_pipeline_get_bind_group_layout(*pipeline, index, None)); if let Some(err) = error { panic!("Error reflecting bind group {index}: {err}"); } @@ -2064,7 +2052,7 @@ impl crate::Context for ContextWgpuCore { let (id, error) = wgc::gfx_select!(encoder_data.parent() => self.0.render_bundle_encoder_finish( encoder_data, &desc.map_label(|l| l.map(Borrowed)), - () + None )); if let Some(err) = error { self.handle_error_fatal(err, "RenderBundleEncoder::finish"); @@ -2118,7 +2106,7 @@ impl crate::Context for ContextWgpuCore { size: wgt::BufferSize, ) -> Option> { match wgc::gfx_select!( - *queue => self.0.queue_create_staging_buffer(*queue, size, ()) + *queue => self.0.queue_create_staging_buffer(*queue, size, None) ) { Ok((buffer_id, ptr)) => Some(Box::new(QueueWriteBuffer { buffer_id,