From 23abad4c909564d3313d698eea2f14e23fbdc6dc Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Fri, 6 Dec 2024 09:51:07 +0100 Subject: [PATCH] let `from_custom_instance` take generic instance Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- wgpu/src/api/instance.rs | 3 +-- wgpu/src/backend/custom.rs | 4 ++-- wgpu/src/dispatch.rs | 9 ++++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/wgpu/src/api/instance.rs b/wgpu/src/api/instance.rs index 38c0cd0d40..9fcf76989c 100644 --- a/wgpu/src/api/instance.rs +++ b/wgpu/src/api/instance.rs @@ -204,9 +204,8 @@ impl Instance { } //#[cfg(custom)] - #[doc(hidden)] /// Creates Instance from custom context implementation - pub fn from_custom_instance(instance: std::sync::Arc) -> Self { + pub fn from_custom_instance(instance: T) -> Self { Self { inner: dispatch::DispatchInstance::Custom(backend::custom::DynContext::new(instance)), } diff --git a/wgpu/src/backend/custom.rs b/wgpu/src/backend/custom.rs index dd27535198..a089f10a35 100644 --- a/wgpu/src/backend/custom.rs +++ b/wgpu/src/backend/custom.rs @@ -20,8 +20,8 @@ pub struct DynContext(Arc); crate::cmp::impl_eq_ord_hash_arc_address!(DynContext => .0); impl DynContext { - pub fn new(instance: Arc) -> Self { - Self(instance) + pub(crate) fn new(instance: T) -> Self { + Self(Arc::new(instance)) } #[cfg(wgpu_core)] diff --git a/wgpu/src/dispatch.rs b/wgpu/src/dispatch.rs index bb21ccb001..6b24f990b3 100644 --- a/wgpu/src/dispatch.rs +++ b/wgpu/src/dispatch.rs @@ -673,6 +673,14 @@ macro_rules! dispatch_types { } } + //#[cfg(custom)] + impl From<<$custom_context as InterfaceTypes>::$subtype> for $name { + #[inline] + fn from(value: <$custom_context as InterfaceTypes>::$subtype) -> Self { + Self::Custom(value) + } + } + impl std::ops::Deref for $name { type Target = dyn $trait; @@ -716,7 +724,6 @@ impl DispatchInstance { Self::Core(value) => backend::DynContext::from_core(value), #[cfg(webgpu)] Self::WebGPU(value) => backend::DynContext::from_webgpu(value), - //#[cfg(custom)] Self::Custom(value) => value, } }