bevy_render/render_resource/
bind_group_layout.rs

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