diff --git a/wgpu/src/api/command_encoder.rs b/wgpu/src/api/command_encoder.rs index cf9c9d1c1..112e11bad 100644 --- a/wgpu/src/api/command_encoder.rs +++ b/wgpu/src/api/command_encoder.rs @@ -442,3 +442,23 @@ impl CommandEncoder { ); } } + +#[cfg(wgpu_core)] +impl CommandEncoder { + /// Create a new command encoder of wgpu from a wgpu-core command encoder. + /// + /// # Arguments + /// + /// - `core_encoder` - wgpu-core command encoder. + pub fn from_core(core_encoder: alloc::sync::Arc) -> Self { + Self { + inner: crate::backend::wgpu_core::CoreCommandEncoder::from_core(core_encoder).into(), + actions: SharedDeferredCommandBufferActions::default(), + } + } + + /// Returns the underlying wgpu-core command encoder if this `CommandEncoder` is on the wgpu-core backend, otherwise `None`. + pub fn as_core(&self) -> Option> { + self.inner.as_core_opt().map(|cd| cd.as_core()) + } +} diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index 00bbb85a8..c83f65205 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -498,6 +498,16 @@ impl CoreCommandEncoder { .as_hal_mut::(hal_command_encoder_callback) } } + + pub(crate) fn from_core(core_encoder: Arc) -> Self { + Self { + wgpu_command_encoder: core_encoder, + } + } + + pub(crate) fn as_core(&self) -> Arc { + self.wgpu_command_encoder.clone() + } } #[derive(Debug, Clone)]