Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_render/src/render_resource/bind_group_layout.rs
9354 views
1
use crate::renderer::WgpuWrapper;
2
use bevy_utils::define_atomic_id;
3
use core::ops::Deref;
4
5
define_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::renderer::RenderDevice::create_bind_group_layout).
15
#[derive(Clone, Debug)]
16
pub struct BindGroupLayout {
17
id: BindGroupLayoutId,
18
value: WgpuWrapper<wgpu::BindGroupLayout>,
19
}
20
21
impl PartialEq for BindGroupLayout {
22
fn eq(&self, other: &Self) -> bool {
23
self.id == other.id
24
}
25
}
26
27
impl Eq for BindGroupLayout {}
28
29
impl 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
35
impl 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
48
impl 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
57
impl Deref for BindGroupLayout {
58
type Target = wgpu::BindGroupLayout;
59
60
#[inline]
61
fn deref(&self) -> &Self::Target {
62
&self.value
63
}
64
}
65
66