From fc90a3b2393c193348521d93c3a1f68bdb53af2c Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Mon, 31 Aug 2026 16:27:50 +0200 Subject: [PATCH] `PipelineLayout::{as, from}_core` Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- wgpu/src/api/pipeline_layout.rs | 22 ++++++++++++++++++++++ wgpu/src/backend/wgpu_core.rs | 12 ++++++++++++ 2 files changed, 34 insertions(+) diff --git a/wgpu/src/api/pipeline_layout.rs b/wgpu/src/api/pipeline_layout.rs index 7705ea75a..845c9a998 100644 --- a/wgpu/src/api/pipeline_layout.rs +++ b/wgpu/src/api/pipeline_layout.rs @@ -23,6 +23,28 @@ impl PipelineLayout { } } +#[cfg(wgpu_core)] +impl PipelineLayout { + /// Create a new pipeline layout of wgpu from a wgpu-core pipeline layout. + /// + /// # Arguments + /// + /// - `core_pipeline_layout` - wgpu-core pipeline layout. + pub fn from_core( + core_pipeline_layout: alloc::sync::Arc, + ) -> Self { + Self { + inner: crate::backend::wgpu_core::CorePipelineLayout::from_core(core_pipeline_layout) + .into(), + } + } + + /// Returns the underlying wgpu-core pipeline layout if this `PipelineLayout` is on the wgpu-core backend, otherwise `None`. + pub fn as_core(&self) -> Option> { + self.inner.as_core_opt().map(|pl| pl.as_core()) + } +} + /// Describes a [`PipelineLayout`]. /// /// For use with [`Device::create_pipeline_layout`]. diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index f8a0f9b58..9b11de3a1 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -436,6 +436,18 @@ pub struct CorePipelineLayout { pub(crate) wgpu_pipeline_layout: Arc, } +impl CorePipelineLayout { + pub(crate) fn from_core(core_pipeline_layout: Arc) -> Self { + Self { + wgpu_pipeline_layout: core_pipeline_layout, + } + } + + pub(crate) fn as_core(&self) -> Arc { + self.wgpu_pipeline_layout.clone() + } +} + #[derive(Debug, Clone)] pub struct CorePipelineCache { pub(crate) wgpu_pipeline_cache: Arc,