diff --git a/wgpu/src/api/adapter.rs b/wgpu/src/api/adapter.rs index 4a1f6ec75..3ae7a7353 100644 --- a/wgpu/src/api/adapter.rs +++ b/wgpu/src/api/adapter.rs @@ -216,3 +216,24 @@ impl Adapter { self.inner.cooperative_matrix_properties() } } + +#[cfg(wgpu_core)] +impl Adapter { + /// Create a new adapter of wgpu from a wgpu-core adapter. + /// + /// # Arguments + /// + /// - `core_adapter` - wgpu-core adapter. + pub fn from_core(core_adapter: alloc::sync::Arc) -> Self { + Self { + inner: crate::backend::wgpu_core::CoreAdapter::from_core(core_adapter).into(), + } + } + + /// Get the [`wgpu_core`] adapter from this `Adapter`. + /// + /// Returns `None` if the adapter is not from the `wgpu_core` backend + pub fn as_core(&self) -> Option> { + self.inner.as_core_opt().map(|adapter| adapter.as_core()) + } +} diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index b89c1da87..6be047d3b 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -204,6 +204,16 @@ impl CoreAdapter { let queue = CoreQueue { wgpu_queue: queue }; Ok((device, queue)) } + + pub(crate) fn from_core(core_adapter: Arc) -> Self { + Self { + wgpu_adapter: core_adapter, + } + } + + pub(crate) fn as_core(&self) -> Arc { + self.wgpu_adapter.clone() + } } #[derive(Debug, Clone)]