From f7e1304c38b1af49afec63c3035e2a8335bd7722 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Wed, 3 Mar 2021 15:43:55 -0500 Subject: [PATCH] Expose CA surface creation --- wgpu-core/src/hub.rs | 11 ++++++----- wgpu-core/src/instance.rs | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index 0760c6640..bdd461a7d 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -302,7 +302,7 @@ thread_local! { /// /// Note: there can only be one non-borrowed `Token` alive on a thread /// at a time, which is enforced by `ACTIVE_TOKEN`. -pub struct Token<'a, T: 'a> { +pub(crate) struct Token<'a, T: 'a> { level: PhantomData<&'a T>, } @@ -446,6 +446,7 @@ pub(crate) struct FutureId<'a, I: TypedId, T> { } impl FutureId<'_, I, T> { + #[cfg(feature = "trace")] pub fn id(&self) -> I { self.id } @@ -472,14 +473,14 @@ impl> Registry>( + pub(crate) fn read<'a, A: Access>( &'a self, _token: &'a mut Token, ) -> (RwLockReadGuard<'a, Storage>, Token<'a, T>) { (self.data.read(), Token::new()) } - pub fn write<'a, A: Access>( + pub(crate) fn write<'a, A: Access>( &'a self, _token: &'a mut Token, ) -> (RwLockWriteGuard<'a, Storage>, Token<'a, T>) { @@ -508,7 +509,7 @@ impl> Registry>( + pub(crate) fn register_error>( &self, id_in: >::Input, label: &str, @@ -525,7 +526,7 @@ impl> Registry>( + pub(crate) fn unregister<'a, A: Access>( &self, id: I, _token: &'a mut Token, diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 229eb5bdb..4379525ef 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -631,6 +631,28 @@ impl Global { id.0 } + #[cfg(metal)] + pub fn instance_create_surface_metal( + &self, + layer: *mut std::ffi::c_void, + id_in: Input, + ) -> SurfaceId { + span!(_guard, INFO, "Instance::instance_create_surface_metal"); + + let surface = + Surface { + #[cfg(feature = "vulkan-portability")] + vulkan: None, //TODO: create_surface_from_layer ? + metal: self.instance.metal.as_ref().map(|inst| { + inst.create_surface_from_layer(unsafe { std::mem::transmute(layer) }) + }), + }; + + let mut token = Token::root(); + let id = self.surfaces.register_identity(id_in, surface, &mut token); + id.0 + } + pub fn surface_drop(&self, id: SurfaceId) { span!(_guard, INFO, "Surface::drop"); let mut token = Token::root();