From ef4d18d4b297039749576aed45f05f836cba4af7 Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Mon, 31 Aug 2026 11:41:43 +0200 Subject: [PATCH] `Device::{as,from}_core` Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- wgpu/src/api/device.rs | 19 +++++++++++++++++++ wgpu/src/backend/wgpu_core.rs | 10 ++++++++++ 2 files changed, 29 insertions(+) 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)]