diff --git a/wgpu/src/api/device.rs b/wgpu/src/api/device.rs index b9d90c94d..902ba7cd2 100644 --- a/wgpu/src/api/device.rs +++ b/wgpu/src/api/device.rs @@ -926,6 +926,25 @@ impl Device { } } +#[cfg(wgpu_core)] +impl Device { + /// Create a new device of wgpu from a wgpu-core device. + /// + /// # Arguments + /// + /// - `core_device` - wgpu-core device. + pub fn from_core(core_device: alloc::sync::Arc) -> Self { + Self { + inner: crate::backend::wgpu_core::CoreDevice::from_core(core_device).into(), + } + } + + /// Returns the underlying wgpu-core device if this `Device` is on the wgpu-core backend, otherwise `None`. + pub fn as_core(&self) -> Option> { + self.inner.as_core_opt().map(|cd| cd.as_core()) + } +} + /// The operation requires the GLES backend on WebGL, but this [`Device`] is /// using a different backend. /// diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index 6be047d3b..9471947f1 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -277,6 +277,16 @@ impl CoreDevice { use wgc::resource::ParentDevice as _; texture.wgpu_texture.same_device(&self.wgpu_device).is_ok() } + + pub(crate) fn from_core(core_device: Arc) -> Self { + Self { + wgpu_device: core_device, + } + } + + pub(crate) fn as_core(&self) -> Arc { + self.wgpu_device.clone() + } } #[derive(Debug, Clone)]