Skip to main content

wgpu/api/
bind_group_layout.rs

1use crate::*;
2
3/// Handle to a binding group layout.
4///
5/// A `BindGroupLayout` is a handle to the GPU-side layout of a binding group. It can be used to
6/// create a [`BindGroupDescriptor`] object, which in turn can be used to create a [`BindGroup`]
7/// object with [`Device::create_bind_group`]. A series of `BindGroupLayout`s can also be used to
8/// create a [`PipelineLayoutDescriptor`], which can be used to create a [`PipelineLayout`].
9///
10/// It can be created with [`Device::create_bind_group_layout`].
11///
12/// Corresponds to [WebGPU `GPUBindGroupLayout`](
13/// https://gpuweb.github.io/gpuweb/#gpubindgrouplayout).
14#[derive(Debug, Clone)]
15pub struct BindGroupLayout {
16    pub(crate) inner: dispatch::DispatchBindGroupLayout,
17}
18#[cfg(send_sync)]
19static_assertions::assert_impl_all!(BindGroupLayout: Send, Sync);
20
21crate::cmp::impl_eq_ord_hash_proxy!(BindGroupLayout => .inner);
22
23impl BindGroupLayout {
24    #[cfg(custom)]
25    /// Returns custom implementation of BindGroupLayout (if custom backend and is internally T)
26    pub fn as_custom<T: custom::BindGroupLayoutInterface>(&self) -> Option<&T> {
27        self.inner.as_custom()
28    }
29}
30
31#[cfg(wgpu_core)]
32impl BindGroupLayout {
33    /// Create a new bind group layout of wgpu from a wgpu-core bind group layout.
34    ///
35    /// # Arguments
36    ///
37    /// - `core_bind_group_layout` - wgpu-core bind group layout.
38    pub fn from_core(
39        core_bind_group_layout: alloc::sync::Arc<wgc::binding_model::BindGroupLayout>,
40    ) -> Self {
41        Self {
42            inner: crate::backend::wgpu_core::CoreBindGroupLayout::from_core(
43                core_bind_group_layout,
44            )
45            .into(),
46        }
47    }
48
49    /// Returns the underlying wgpu-core bind group layout if this `BindGroupLayout` is on the wgpu-core backend, otherwise `None`.
50    pub fn as_core(&self) -> Option<alloc::sync::Arc<wgc::binding_model::BindGroupLayout>> {
51        self.inner.as_core_opt().map(|bgl| bgl.as_core())
52    }
53}
54
55/// Describes a [`BindGroupLayout`].
56///
57/// For use with [`Device::create_bind_group_layout`].
58///
59/// Corresponds to [WebGPU `GPUBindGroupLayoutDescriptor`](
60/// https://gpuweb.github.io/gpuweb/#dictdef-gpubindgrouplayoutdescriptor).
61#[derive(Clone, Debug)]
62pub struct BindGroupLayoutDescriptor<'a> {
63    /// Debug label of the bind group layout. This will show up in graphics debuggers for easy identification.
64    pub label: Label<'a>,
65
66    /// Array of entries in this BindGroupLayout
67    pub entries: &'a [BindGroupLayoutEntry],
68}
69static_assertions::assert_impl_all!(BindGroupLayoutDescriptor<'_>: Send, Sync);