Skip to main content

wgpu/api/
pipeline_layout.rs

1use crate::*;
2
3/// Handle to a pipeline layout.
4///
5/// A `PipelineLayout` object describes the available binding groups of a pipeline.
6/// It can be created with [`Device::create_pipeline_layout`].
7///
8/// Corresponds to [WebGPU `GPUPipelineLayout`](https://gpuweb.github.io/gpuweb/#gpupipelinelayout).
9#[derive(Debug, Clone)]
10pub struct PipelineLayout {
11    pub(crate) inner: dispatch::DispatchPipelineLayout,
12}
13#[cfg(send_sync)]
14static_assertions::assert_impl_all!(PipelineLayout: Send, Sync);
15
16crate::cmp::impl_eq_ord_hash_proxy!(PipelineLayout => .inner);
17
18impl PipelineLayout {
19    #[cfg(custom)]
20    /// Returns custom implementation of PipelineLayout (if custom backend and is internally T)
21    pub fn as_custom<T: custom::PipelineLayoutInterface>(&self) -> Option<&T> {
22        self.inner.as_custom()
23    }
24}
25
26#[cfg(wgpu_core)]
27impl PipelineLayout {
28    /// Create a new pipeline layout of wgpu from a wgpu-core pipeline layout.
29    ///
30    /// # Arguments
31    ///
32    /// - `core_pipeline_layout` - wgpu-core pipeline layout.
33    pub fn from_core(
34        core_pipeline_layout: alloc::sync::Arc<wgc::binding_model::PipelineLayout>,
35    ) -> Self {
36        Self {
37            inner: crate::backend::wgpu_core::CorePipelineLayout::from_core(core_pipeline_layout)
38                .into(),
39        }
40    }
41
42    /// Returns the underlying wgpu-core pipeline layout if this `PipelineLayout` is on the wgpu-core backend, otherwise `None`.
43    pub fn as_core(&self) -> Option<alloc::sync::Arc<wgc::binding_model::PipelineLayout>> {
44        self.inner.as_core_opt().map(|pl| pl.as_core())
45    }
46}
47
48/// Describes a [`PipelineLayout`].
49///
50/// For use with [`Device::create_pipeline_layout`].
51///
52/// Corresponds to [WebGPU `GPUPipelineLayoutDescriptor`](
53/// https://gpuweb.github.io/gpuweb/#dictdef-gpupipelinelayoutdescriptor).
54#[derive(Clone, Debug, Default)]
55pub struct PipelineLayoutDescriptor<'a> {
56    /// Debug label of the pipeline layout. This will show up in graphics debuggers for easy identification.
57    pub label: Label<'a>,
58    /// Bind groups that this pipeline uses. The first entry will provide all the bindings for
59    /// "set = 0", second entry will provide all the bindings for "set = 1" etc.
60    pub bind_group_layouts: &'a [Option<&'a BindGroupLayout>],
61    /// The number of bytes of immediate data that are allocated for use
62    /// in the shader. The `var<immediate>`s in the shader attached to
63    /// this pipeline must be equal or smaller than this size.
64    ///
65    /// If this value is non-zero, [`Features::IMMEDIATES`] must be enabled.
66    pub immediate_size: u32,
67}
68#[cfg(send_sync)]
69static_assertions::assert_impl_all!(PipelineLayoutDescriptor<'_>: Send, Sync);