bevy_render/render_resource/
bind_group_layout.rs

1use crate::define_atomic_id;
2use crate::renderer::WgpuWrapper;
3use core::ops::Deref;
4
5define_atomic_id!(BindGroupLayoutId);
6
7/// Bind group layouts define the interface of resources (e.g. buffers, textures, samplers)
8/// for a shader. The actual resource binding is done via a [`BindGroup`](super::BindGroup).
9///
10/// This is a lightweight thread-safe wrapper around wgpu's own [`BindGroupLayout`](wgpu::BindGroupLayout),
11/// which can be cloned as needed to workaround lifetime management issues. It may be converted
12/// from and dereferences to wgpu's [`BindGroupLayout`](wgpu::BindGroupLayout).
13///
14/// Can be created via [`RenderDevice::create_bind_group_layout`](crate::RenderDevice::create_bind_group_layout).
15#[derive(Clone, Debug)]
16pub struct BindGroupLayout {
17    id: BindGroupLayoutId,
18    value: WgpuWrapper<wgpu::BindGroupLayout>,
19}
20
21impl PartialEq for BindGroupLayout {
22    fn eq(&self, other: &Self) -> bool {
23        self.id == other.id
24    }
25}
26
27impl Eq for BindGroupLayout {}
28
29impl core::hash::Hash for BindGroupLayout {
30    fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
31        self.id.0.hash(state);
32    }
33}
34
35impl BindGroupLayout {
36    /// Returns the [`BindGroupLayoutId`] representing the unique ID of the bind group layout.
37    #[inline]
38    pub fn id(&self) -> BindGroupLayoutId {
39        self.id
40    }
41
42    #[inline]
43    pub fn value(&self) -> &wgpu::BindGroupLayout {
44        &self.value
45    }
46}
47
48impl From<wgpu::BindGroupLayout> for BindGroupLayout {
49    fn from(value: wgpu::BindGroupLayout) -> Self {
50        BindGroupLayout {
51            id: BindGroupLayoutId::new(),
52            value: WgpuWrapper::new(value),
53        }
54    }
55}
56
57impl Deref for BindGroupLayout {
58    type Target = wgpu::BindGroupLayout;
59
60    #[inline]
61    fn deref(&self) -> &Self::Target {
62        &self.value
63    }
64}