From f00e6b70ea77074ee3cfd547901be2538503ac34 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Mon, 22 May 2023 13:54:20 -0700 Subject: [PATCH] wgpu-core: Move `Global` to new `global` module. --- deno_webgpu/lib.rs | 5 +- player/src/bin/play.rs | 2 +- player/src/lib.rs | 2 +- player/tests/test.rs | 4 +- wgpu-core/src/command/bundle.rs | 4 +- wgpu-core/src/command/clear.rs | 3 +- wgpu-core/src/command/compute.rs | 3 +- wgpu-core/src/command/mod.rs | 3 +- 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/mod.rs | 3 +- wgpu-core/src/device/queue.rs | 3 +- wgpu-core/src/error.rs | 5 +- wgpu-core/src/global.rs | 162 ++++++++++++++++++++++++++ wgpu-core/src/hub.rs | 182 +++--------------------------- wgpu-core/src/id.rs | 2 +- wgpu-core/src/instance.rs | 3 +- wgpu-core/src/lib.rs | 7 +- wgpu-core/src/present.rs | 3 +- wgpu-core/src/resource.rs | 3 +- wgpu/src/backend/direct.rs | 12 +- wgpu/src/lib.rs | 2 +- 23 files changed, 223 insertions(+), 199 deletions(-) create mode 100644 wgpu-core/src/global.rs diff --git a/deno_webgpu/lib.rs b/deno_webgpu/lib.rs index 2f73c4bef9..e102aff420 100644 --- a/deno_webgpu/lib.rs +++ b/deno_webgpu/lib.rs @@ -94,7 +94,8 @@ 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 { @@ -321,7 +322,7 @@ pub async fn op_webgpu_request_adapter( let instance = if let Some(instance) = state.try_borrow::() { instance } else { - state.put(std::sync::Arc::new(wgpu_core::hub::Global::new( + state.put(std::sync::Arc::new(wgpu_core::global::Global::new( "webgpu", wgpu_core::hub::IdentityManagerFactory, wgpu_types::InstanceDescriptor { diff --git a/player/src/bin/play.rs b/player/src/bin/play.rs index fb2665e3a3..a2b309acb1 100644 --- a/player/src/bin/play.rs +++ b/player/src/bin/play.rs @@ -43,7 +43,7 @@ fn main() { .build(&event_loop) .unwrap(); - let global = wgc::hub::Global::new( + let global = wgc::global::Global::new( "player", IdentityPassThroughFactory, wgt::InstanceDescriptor::default(), diff --git a/player/src/lib.rs b/player/src/lib.rs index 0ef6080b77..9ab6123568 100644 --- a/player/src/lib.rs +++ b/player/src/lib.rs @@ -51,7 +51,7 @@ pub trait GlobalPlay { ); } -impl GlobalPlay for wgc::hub::Global { +impl GlobalPlay for wgc::global::Global { fn encode_commands( &self, encoder: wgc::id::CommandEncoderId, diff --git a/player/tests/test.rs b/player/tests/test.rs index 750b823648..aae768159c 100644 --- a/player/tests/test.rs +++ b/player/tests/test.rs @@ -78,7 +78,7 @@ impl Test<'_> { fn run( self, dir: &Path, - global: &wgc::hub::Global, + global: &wgc::global::Global, adapter: wgc::id::AdapterId, test_num: u32, ) { @@ -178,7 +178,7 @@ impl Corpus { let dir = path.parent().unwrap(); let corpus: Corpus = ron::de::from_reader(File::open(&path).unwrap()).unwrap(); - let global = wgc::hub::Global::new( + let global = wgc::global::Global::new( "test", IdentityPassThroughFactory, wgt::InstanceDescriptor { diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index 34d7e84cf4..bb935ff189 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -71,8 +71,8 @@ called. It goes through the commands and issues them into the native command buffer. Thanks to isolation, it doesn't track any bind group invalidations or index format changes. -[Gdcrbe]: crate::hub::Global::device_create_render_bundle_encoder -[Grbef]: crate::hub::Global::render_bundle_encoder_finish +[Gdcrbe]: crate::global::Global::device_create_render_bundle_encoder +[Grbef]: crate::global::Global::render_bundle_encoder_finish [wrpeb]: crate::command::render_ffi::wgpu_render_pass_execute_bundles !*/ diff --git a/wgpu-core/src/command/clear.rs b/wgpu-core/src/command/clear.rs index de11258c42..53c7695034 100644 --- a/wgpu-core/src/command/clear.rs +++ b/wgpu-core/src/command/clear.rs @@ -5,7 +5,8 @@ use crate::device::trace::Command as TraceCommand; use crate::{ command::CommandBuffer, get_lowest_common_denom, - hub::{self, Global, GlobalIdentityHandlerFactory, HalApi, Token}, + global::Global, + hub::{self, GlobalIdentityHandlerFactory, HalApi, Token}, id::{BufferId, CommandEncoderId, DeviceId, TextureId, Valid}, init_tracker::{MemoryInitKind, TextureInitRange}, resource::{Texture, TextureClearMode}, diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index d5b514f194..6c9e4fb4bc 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -11,7 +11,8 @@ use crate::{ }, device::{MissingDownlevelFlags, MissingFeatures}, error::{ErrorFormatter, PrettyError}, - hub::{Global, GlobalIdentityHandlerFactory, HalApi, Storage, Token}, + global::Global, + hub::{GlobalIdentityHandlerFactory, HalApi, Storage, Token}, id, init_tracker::MemoryInitKind, pipeline, diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 8c5e5f2d40..30b45e9813 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -21,7 +21,8 @@ use crate::error::{ErrorFormatter, PrettyError}; use crate::init_tracker::BufferInitTrackerAction; use crate::track::{Tracker, UsageScope}; use crate::{ - hub::{Global, GlobalIdentityHandlerFactory, HalApi, Storage, Token}, + global::Global, + hub::{GlobalIdentityHandlerFactory, HalApi, Storage, Token}, id, resource::{Buffer, Texture}, Label, Stored, diff --git a/wgpu-core/src/command/query.rs b/wgpu-core/src/command/query.rs index 6181f83fa8..04648f9af7 100644 --- a/wgpu-core/src/command/query.rs +++ b/wgpu-core/src/command/query.rs @@ -4,7 +4,8 @@ use hal::CommandEncoder as _; use crate::device::trace::Command as TraceCommand; use crate::{ command::{CommandBuffer, CommandEncoderError}, - hub::{Global, GlobalIdentityHandlerFactory, HalApi, Storage, Token}, + global::Global, + hub::{GlobalIdentityHandlerFactory, HalApi, Storage, Token}, id::{self, Id, TypedId}, init_tracker::MemoryInitKind, resource::QuerySet, diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index b38e79c4b4..73d00a2015 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -14,7 +14,8 @@ use crate::{ RenderPassCompatibilityCheckType, RenderPassCompatibilityError, RenderPassContext, }, error::{ErrorFormatter, PrettyError}, - hub::{Global, GlobalIdentityHandlerFactory, HalApi, Storage, Token}, + global::Global, + hub::{GlobalIdentityHandlerFactory, HalApi, Storage, Token}, id, init_tracker::{MemoryInitKind, TextureInitRange, TextureInitTrackerAction}, pipeline::{self, PipelineFlags}, diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index 45b2684108..0be6d7220c 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -5,7 +5,8 @@ use crate::{ conv, device::{Device, MissingDownlevelFlags}, error::{ErrorFormatter, PrettyError}, - hub::{Global, GlobalIdentityHandlerFactory, HalApi, Storage, Token}, + global::Global, + hub::{GlobalIdentityHandlerFactory, HalApi, Storage, Token}, id::{BufferId, CommandEncoderId, TextureId, Valid}, init_tracker::{ has_copy_partial_init_tracker_coverage, MemoryInitKind, TextureInitRange, diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index d6927954fe..ec5e36c468 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -1,7 +1,8 @@ use crate::{ binding_model, command, conv, device::life::WaitIdleError, - hub::{Global, GlobalIdentityHandlerFactory, HalApi, Hub, Input, InvalidId, Storage, Token}, + global::Global, + hub::{GlobalIdentityHandlerFactory, HalApi, Hub, Input, InvalidId, Storage, Token}, id, init_tracker::{ BufferInitTracker, BufferInitTrackerAction, MemoryInitKind, TextureInitRange, diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index 8ee687269d..6ebf125047 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -8,7 +8,8 @@ use crate::{ conv, device::{DeviceError, WaitIdleError}, get_lowest_common_denom, - hub::{Global, GlobalIdentityHandlerFactory, HalApi, Input, Token}, + global::Global, + hub::{GlobalIdentityHandlerFactory, HalApi, Input, Token}, id, init_tracker::{has_copy_partial_init_tracker_coverage, TextureInitRange}, resource::{BufferAccessError, BufferMapState, StagingBuffer, TextureInner}, diff --git a/wgpu-core/src/error.rs b/wgpu-core/src/error.rs index 596595245b..f2e086cee4 100644 --- a/wgpu-core/src/error.rs +++ b/wgpu-core/src/error.rs @@ -1,10 +1,7 @@ use core::fmt; use std::error::Error; -use crate::{ - gfx_select, - hub::{Global, IdentityManagerFactory}, -}; +use crate::{gfx_select, global::Global, hub::IdentityManagerFactory}; pub struct ErrorFormatter<'a> { writer: &'a mut dyn fmt::Write, diff --git a/wgpu-core/src/global.rs b/wgpu-core/src/global.rs new file mode 100644 index 0000000000..4ea4bf22d9 --- /dev/null +++ b/wgpu-core/src/global.rs @@ -0,0 +1,162 @@ +use crate::{ + hub::GlobalIdentityHandlerFactory, + hub::HalApi, + hub::Registry, + hub::{Element, StorageReport}, + hub::{HubReport, Hubs}, + id, + instance::{Instance, Surface}, +}; + +#[derive(Debug)] +pub struct GlobalReport { + pub surfaces: StorageReport, + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] + pub vulkan: Option, + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] + pub metal: Option, + #[cfg(all(feature = "dx12", windows))] + pub dx12: Option, + #[cfg(all(feature = "dx11", windows))] + pub dx11: Option, + #[cfg(feature = "gles")] + pub gl: Option, +} + +pub struct Global { + pub instance: Instance, + pub surfaces: Registry, + pub(crate) hubs: Hubs, +} + +impl Global { + pub fn new(name: &str, factory: G, instance_desc: wgt::InstanceDescriptor) -> Self { + profiling::scope!("Global::new"); + Self { + instance: Instance::new(name, instance_desc), + surfaces: Registry::without_backend(&factory, "Surface"), + hubs: Hubs::new(&factory), + } + } + + /// # 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 { + profiling::scope!("Global::new"); + Self { + instance: A::create_instance_from_hal(name, hal_instance), + surfaces: Registry::without_backend(&factory, "Surface"), + hubs: Hubs::new(&factory), + } + } + + /// # Safety + /// + /// - The raw instance handle returned must not be manually destroyed. + pub unsafe fn instance_as_hal(&self) -> Option<&A::Instance> { + A::instance_as_hal(&self.instance) + } + + /// # Safety + /// + /// - The raw handles obtained from the Instance must not be manually destroyed + pub unsafe fn from_instance(factory: G, instance: Instance) -> Self { + profiling::scope!("Global::new"); + Self { + instance, + surfaces: Registry::without_backend(&factory, "Surface"), + hubs: Hubs::new(&factory), + } + } + + pub fn clear_backend(&self, _dummy: ()) { + let mut surface_guard = self.surfaces.data.write(); + let hub = A::hub(self); + // this is used for tests, which keep the adapter + hub.clear(&mut surface_guard, false); + } + + pub fn generate_report(&self) -> GlobalReport { + GlobalReport { + surfaces: self.surfaces.data.read().generate_report(), + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] + vulkan: if self.instance.vulkan.is_some() { + Some(self.hubs.vulkan.generate_report()) + } else { + None + }, + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] + metal: if self.instance.metal.is_some() { + Some(self.hubs.metal.generate_report()) + } else { + None + }, + #[cfg(all(feature = "dx12", windows))] + dx12: if self.instance.dx12.is_some() { + Some(self.hubs.dx12.generate_report()) + } else { + None + }, + #[cfg(all(feature = "dx11", windows))] + dx11: if self.instance.dx11.is_some() { + Some(self.hubs.dx11.generate_report()) + } else { + None + }, + #[cfg(feature = "gles")] + gl: if self.instance.gl.is_some() { + Some(self.hubs.gl.generate_report()) + } else { + None + }, + } + } +} + +impl Drop for Global { + fn drop(&mut self) { + profiling::scope!("Global::drop"); + log::info!("Dropping Global"); + let mut surface_guard = self.surfaces.data.write(); + + // destroy hubs before the instance gets dropped + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] + { + self.hubs.vulkan.clear(&mut surface_guard, true); + } + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] + { + self.hubs.metal.clear(&mut surface_guard, true); + } + #[cfg(all(feature = "dx12", windows))] + { + self.hubs.dx12.clear(&mut surface_guard, true); + } + #[cfg(all(feature = "dx11", windows))] + { + self.hubs.dx11.clear(&mut surface_guard, true); + } + #[cfg(feature = "gles")] + { + self.hubs.gl.clear(&mut surface_guard, true); + } + + // destroy surfaces + for element in surface_guard.map.drain(..) { + if let Element::Occupied(surface, _) = element { + self.instance.destroy_surface(surface); + } + } + } +} + +#[cfg(test)] +fn _test_send_sync(global: &Global) { + fn test_internal(_: T) {} + test_internal(global) +} diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index 0a3b5d954e..a6826d458d 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -153,6 +153,7 @@ use crate::{ binding_model::{BindGroup, BindGroupLayout, PipelineLayout}, command::{CommandBuffer, RenderBundle}, device::Device, + global::Global, id, instance::{Adapter, HalSurface, Instance, Surface}, pipeline::{ComputePipeline, RenderPipeline, ShaderModule}, @@ -243,7 +244,7 @@ impl IdentityManager { /// An entry in a `Storage::map` table. #[derive(Debug)] -enum Element { +pub(crate) enum Element { /// There are no live ids with this index. Vacant, @@ -282,7 +283,7 @@ pub(crate) struct InvalidId; /// that keeps the index values dense and close to zero. #[derive(Debug)] pub struct Storage { - map: Vec>, + pub(crate) map: Vec>, kind: &'static str, _phantom: PhantomData, } @@ -454,7 +455,7 @@ impl Storage { self.map.len() } - fn generate_report(&self) -> StorageReport { + pub(crate) fn generate_report(&self) -> StorageReport { let mut report = StorageReport { element_size: mem::size_of::(), ..Default::default() @@ -755,7 +756,7 @@ pub trait Resource { #[derive(Debug)] pub struct Registry> { identity: F::Filter, - data: RwLock>, + pub(crate) data: RwLock>, backend: Backend, } @@ -772,7 +773,7 @@ impl> Registry Self { + pub(crate) fn without_backend(factory: &F, kind: &'static str) -> Self { Self { identity: factory.spawn(), data: RwLock::new(Storage { @@ -1068,7 +1069,11 @@ impl Hub { //TODO: instead of having a hacky `with_adapters` parameter, // we should have `clear_device(device_id)` that specifically destroys // everything related to a logical device. - fn clear(&self, surface_guard: &mut Storage, with_adapters: bool) { + pub(crate) fn clear( + &self, + surface_guard: &mut Storage, + with_adapters: bool, + ) { use crate::resource::TextureInner; use hal::{Device as _, Surface as _}; @@ -1258,19 +1263,19 @@ impl Hub { pub struct Hubs { #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] - vulkan: Hub, + pub(crate) vulkan: Hub, #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] - metal: Hub, + pub(crate) metal: Hub, #[cfg(all(feature = "dx12", windows))] - dx12: Hub, + pub(crate) dx12: Hub, #[cfg(all(feature = "dx11", windows))] - dx11: Hub, + pub(crate) dx11: Hub, #[cfg(feature = "gles")] - gl: Hub, + pub(crate) gl: Hub, } impl Hubs { - fn new(factory: &F) -> Self { + pub(crate) fn new(factory: &F) -> Self { Self { #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] vulkan: Hub::new(factory), @@ -1286,153 +1291,6 @@ impl Hubs { } } -#[derive(Debug)] -pub struct GlobalReport { - pub surfaces: StorageReport, - #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] - pub vulkan: Option, - #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] - pub metal: Option, - #[cfg(all(feature = "dx12", windows))] - pub dx12: Option, - #[cfg(all(feature = "dx11", windows))] - pub dx11: Option, - #[cfg(feature = "gles")] - pub gl: Option, -} - -pub struct Global { - pub instance: Instance, - pub surfaces: Registry, - hubs: Hubs, -} - -impl Global { - pub fn new(name: &str, factory: G, instance_desc: wgt::InstanceDescriptor) -> Self { - profiling::scope!("Global::new"); - Self { - instance: Instance::new(name, instance_desc), - surfaces: Registry::without_backend(&factory, "Surface"), - hubs: Hubs::new(&factory), - } - } - - /// # 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 { - profiling::scope!("Global::new"); - Self { - instance: A::create_instance_from_hal(name, hal_instance), - surfaces: Registry::without_backend(&factory, "Surface"), - hubs: Hubs::new(&factory), - } - } - - /// # Safety - /// - /// - The raw instance handle returned must not be manually destroyed. - pub unsafe fn instance_as_hal(&self) -> Option<&A::Instance> { - A::instance_as_hal(&self.instance) - } - - /// # Safety - /// - /// - The raw handles obtained from the Instance must not be manually destroyed - pub unsafe fn from_instance(factory: G, instance: Instance) -> Self { - profiling::scope!("Global::new"); - Self { - instance, - surfaces: Registry::without_backend(&factory, "Surface"), - hubs: Hubs::new(&factory), - } - } - - pub fn clear_backend(&self, _dummy: ()) { - let mut surface_guard = self.surfaces.data.write(); - let hub = A::hub(self); - // this is used for tests, which keep the adapter - hub.clear(&mut surface_guard, false); - } - - pub fn generate_report(&self) -> GlobalReport { - GlobalReport { - surfaces: self.surfaces.data.read().generate_report(), - #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] - vulkan: if self.instance.vulkan.is_some() { - Some(self.hubs.vulkan.generate_report()) - } else { - None - }, - #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] - metal: if self.instance.metal.is_some() { - Some(self.hubs.metal.generate_report()) - } else { - None - }, - #[cfg(all(feature = "dx12", windows))] - dx12: if self.instance.dx12.is_some() { - Some(self.hubs.dx12.generate_report()) - } else { - None - }, - #[cfg(all(feature = "dx11", windows))] - dx11: if self.instance.dx11.is_some() { - Some(self.hubs.dx11.generate_report()) - } else { - None - }, - #[cfg(feature = "gles")] - gl: if self.instance.gl.is_some() { - Some(self.hubs.gl.generate_report()) - } else { - None - }, - } - } -} - -impl Drop for Global { - fn drop(&mut self) { - profiling::scope!("Global::drop"); - log::info!("Dropping Global"); - let mut surface_guard = self.surfaces.data.write(); - - // destroy hubs before the instance gets dropped - #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] - { - self.hubs.vulkan.clear(&mut surface_guard, true); - } - #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] - { - self.hubs.metal.clear(&mut surface_guard, true); - } - #[cfg(all(feature = "dx12", windows))] - { - self.hubs.dx12.clear(&mut surface_guard, true); - } - #[cfg(all(feature = "dx11", windows))] - { - self.hubs.dx11.clear(&mut surface_guard, true); - } - #[cfg(feature = "gles")] - { - self.hubs.gl.clear(&mut surface_guard, true); - } - - // destroy surfaces - for element in surface_guard.map.drain(..) { - if let Element::Occupied(surface, _) = element { - self.instance.destroy_surface(surface); - } - } - } -} - pub trait HalApi: hal::Api { const VARIANT: Backend; fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance; @@ -1582,12 +1440,6 @@ impl HalApi for hal::api::Gles { } } -#[cfg(test)] -fn _test_send_sync(global: &Global) { - fn test_internal(_: T) {} - test_internal(global) -} - #[test] fn test_epoch_end_of_life() { use id::TypedId as _; diff --git a/wgpu-core/src/id.rs b/wgpu-core/src/id.rs index 9c654e3ca9..412344000e 100644 --- a/wgpu-core/src/id.rs +++ b/wgpu-core/src/id.rs @@ -42,7 +42,7 @@ type Dummy = hal::api::Empty; /// `X` type with the resource type `X`, for some specific backend /// `A`. /// -/// [`Global`]: crate::hub::Global +/// [`Global`]: crate::global::Global /// [`Hub`]: crate::hub::Hub /// [`Hub`]: crate::hub::Hub /// [`Storage`]: crate::hub::Storage diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index c5989f4bf4..0c88128735 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -1,6 +1,7 @@ use crate::{ device::{Device, DeviceDescriptor}, - hub::{Global, GlobalIdentityHandlerFactory, HalApi, Input, Token}, + global::Global, + hub::{GlobalIdentityHandlerFactory, HalApi, Input, Token}, id::{AdapterId, DeviceId, SurfaceId, Valid}, present::Presentation, LabelHelpers, LifeGuard, Stored, DOWNLEVEL_WARNING_MESSAGE, diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index fc80f0017d..51c2a5f6ed 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -42,6 +42,7 @@ pub mod command; mod conv; pub mod device; pub mod error; +pub mod global; pub mod hub; pub mod id; mod init_tracker; @@ -355,7 +356,7 @@ define_backend_caller! { gfx_if_gles, gfx_if_gles_hidden, "gles" if feature = "g /// identifiers to select backends dynamically, even though many `wgpu_core` /// methods are compiled and optimized for a specific back end. /// -/// This macro is typically used to call methods on [`wgpu_core::hub::Global`], +/// This macro is typically used to call methods on [`wgpu_core::global::Global`], /// many of which take a single `hal::Api` type parameter. For example, to /// create a new buffer on the device indicated by `device_id`, one would say: /// @@ -375,13 +376,13 @@ define_backend_caller! { gfx_if_gles, gfx_if_gles_hidden, "gles" if feature = "g /// That `gfx_select!` call uses `device_id`'s backend to select the right /// backend type `A` for a call to `Global::device_create_buffer`. /// -/// However, there's nothing about this macro that is specific to `hub::Global`. +/// However, there's nothing about this macro that is specific to `global::Global`. /// For example, Firefox's embedding of `wgpu_core` defines its own types with /// methods that take `hal::Api` type parameters. Firefox uses `gfx_select!` to /// dynamically dispatch to the right specialization based on the resource's id. /// /// [`wgpu_types::Backend`]: wgt::Backend -/// [`wgpu_core::hub::Global`]: crate::hub::Global +/// [`wgpu_core::global::Global`]: crate::global::Global /// [`Id`]: id::Id #[macro_export] macro_rules! gfx_select { diff --git a/wgpu-core/src/present.rs b/wgpu-core/src/present.rs index f3989bdec6..f87e6def3a 100644 --- a/wgpu-core/src/present.rs +++ b/wgpu-core/src/present.rs @@ -16,7 +16,8 @@ use crate::device::trace::Action; use crate::{ conv, device::{DeviceError, MissingDownlevelFlags}, - hub::{Global, GlobalIdentityHandlerFactory, HalApi, Input, Token}, + global::Global, + hub::{GlobalIdentityHandlerFactory, HalApi, Input, Token}, id::{DeviceId, SurfaceId, TextureId, Valid}, init_tracker::TextureInitTracker, resource, track, LifeGuard, Stored, diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 6ea7b9cce0..a2b3320347 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -1,6 +1,7 @@ use crate::{ device::{DeviceError, HostMap, MissingDownlevelFlags, MissingFeatures}, - hub::{Global, GlobalIdentityHandlerFactory, HalApi, Resource, Token}, + global::Global, + hub::{GlobalIdentityHandlerFactory, HalApi, Resource, Token}, id::{AdapterId, DeviceId, SurfaceId, TextureId, Valid}, init_tracker::{BufferInitTracker, TextureInitTracker}, track::TextureSelector, diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 6d181043e8..731ca2489f 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -26,7 +26,7 @@ use wgc::id::TypedId; const LABEL: &str = "label"; -pub struct Context(wgc::hub::Global); +pub struct Context(wgc::global::Global); impl Drop for Context { fn drop(&mut self) { @@ -43,7 +43,7 @@ impl fmt::Debug for Context { impl Context { pub unsafe fn from_hal_instance(hal_instance: A::Instance) -> Self { Self(unsafe { - wgc::hub::Global::from_hal_instance::( + wgc::global::Global::from_hal_instance::( "wgpu", wgc::hub::IdentityManagerFactory, hal_instance, @@ -60,11 +60,11 @@ impl Context { pub unsafe fn from_core_instance(core_instance: wgc::instance::Instance) -> Self { Self(unsafe { - wgc::hub::Global::from_instance(wgc::hub::IdentityManagerFactory, core_instance) + wgc::global::Global::from_instance(wgc::hub::IdentityManagerFactory, core_instance) }) } - pub(crate) fn global(&self) -> &wgc::hub::Global { + pub(crate) fn global(&self) -> &wgc::global::Global { &self.0 } @@ -186,7 +186,7 @@ impl Context { } } - pub fn generate_report(&self) -> wgc::hub::GlobalReport { + pub fn generate_report(&self) -> wgc::global::GlobalReport { self.0.generate_report() } @@ -536,7 +536,7 @@ impl crate::Context for Context { type PopErrorScopeFuture = Ready>; fn init(instance_desc: wgt::InstanceDescriptor) -> Self { - Self(wgc::hub::Global::new( + Self(wgc::global::Global::new( "wgpu", wgc::hub::IdentityManagerFactory, instance_desc, diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index ca0c6ac50d..04cc8f5420 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -1698,7 +1698,7 @@ impl Instance { target_os = "emscripten", feature = "webgl" ))] - pub fn generate_report(&self) -> wgc::hub::GlobalReport { + pub fn generate_report(&self) -> wgc::global::GlobalReport { self.context .as_any() .downcast_ref::()