Skip to content

Commit

Permalink
let from_custom_instance take generic instance
Browse files Browse the repository at this point in the history
Signed-off-by: sagudev <[email protected]>
  • Loading branch information
sagudev committed Dec 6, 2024
1 parent 4e44757 commit 23abad4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 1 addition & 2 deletions wgpu/src/api/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn InstanceInterface>) -> Self {
pub fn from_custom_instance<T: InstanceInterface>(instance: T) -> Self {
Self {
inner: dispatch::DispatchInstance::Custom(backend::custom::DynContext::new(instance)),
}
Expand Down
4 changes: 2 additions & 2 deletions wgpu/src/backend/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub struct DynContext(Arc<dyn InstanceInterface>);
crate::cmp::impl_eq_ord_hash_arc_address!(DynContext => .0);

impl DynContext {
pub fn new(instance: Arc<dyn InstanceInterface>) -> Self {
Self(instance)
pub(crate) fn new<T: InstanceInterface>(instance: T) -> Self {
Self(Arc::new(instance))
}

#[cfg(wgpu_core)]
Expand Down
9 changes: 8 additions & 1 deletion wgpu/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
}
}
Expand Down

0 comments on commit 23abad4

Please sign in to comment.