From 6b7954f1c7a0342ca4dcbeb546af9e55dc994b18 Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Mon, 31 Aug 2026 16:26:44 +0200 Subject: [PATCH] `ComputePipeline::{as, from}_core` Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- wgpu/src/api/compute_pipeline.rs | 22 ++++++++++++++++++++++ wgpu/src/backend/wgpu_core.rs | 12 ++++++++++++ 2 files changed, 34 insertions(+) diff --git a/wgpu/src/api/compute_pipeline.rs b/wgpu/src/api/compute_pipeline.rs index 499f967b5..dfffe9fee 100644 --- a/wgpu/src/api/compute_pipeline.rs +++ b/wgpu/src/api/compute_pipeline.rs @@ -35,6 +35,28 @@ impl ComputePipeline { } } +#[cfg(wgpu_core)] +impl ComputePipeline { + /// Create a new compute pipeline of wgpu from a wgpu-core compute pipeline. + /// + /// # Arguments + /// + /// - `core_compute_pipeline` - wgpu-core compute pipeline. + pub fn from_core( + core_compute_pipeline: alloc::sync::Arc, + ) -> Self { + Self { + inner: crate::backend::wgpu_core::CoreComputePipeline::from_core(core_compute_pipeline) + .into(), + } + } + + /// Returns the underlying wgpu-core compute pipeline if this `ComputePipeline` is on the wgpu-core backend, otherwise `None`. + pub fn as_core(&self) -> Option> { + self.inner.as_core_opt().map(|cp| cp.as_core()) + } +} + /// Describes a compute pipeline. /// /// For use with [`Device::create_compute_pipeline`]. diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index dae8ec2e7..f8a0f9b58 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -513,6 +513,18 @@ pub struct CoreComputePipeline { pub(crate) wgpu_compute_pipeline: Arc, } +impl CoreComputePipeline { + pub(crate) fn from_core(core_compute_pipeline: Arc) -> Self { + Self { + wgpu_compute_pipeline: core_compute_pipeline, + } + } + + pub(crate) fn as_core(&self) -> Arc { + self.wgpu_compute_pipeline.clone() + } +} + #[derive(Debug, Clone)] pub struct CoreRenderPipeline { pub(crate) wgpu_render_pipeline: Arc,