Path: blob/main/crates/bevy_render/src/render_resource/bind_group_layout.rs
9354 views
use crate::renderer::WgpuWrapper;1use bevy_utils::define_atomic_id;2use core::ops::Deref;34define_atomic_id!(BindGroupLayoutId);56/// 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 converted11/// 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 {16id: BindGroupLayoutId,17value: WgpuWrapper<wgpu::BindGroupLayout>,18}1920impl PartialEq for BindGroupLayout {21fn eq(&self, other: &Self) -> bool {22self.id == other.id23}24}2526impl Eq for BindGroupLayout {}2728impl core::hash::Hash for BindGroupLayout {29fn hash<H: core::hash::Hasher>(&self, state: &mut H) {30self.id.0.hash(state);31}32}3334impl BindGroupLayout {35/// Returns the [`BindGroupLayoutId`] representing the unique ID of the bind group layout.36#[inline]37pub fn id(&self) -> BindGroupLayoutId {38self.id39}4041#[inline]42pub fn value(&self) -> &wgpu::BindGroupLayout {43&self.value44}45}4647impl From<wgpu::BindGroupLayout> for BindGroupLayout {48fn from(value: wgpu::BindGroupLayout) -> Self {49BindGroupLayout {50id: BindGroupLayoutId::new(),51value: WgpuWrapper::new(value),52}53}54}5556impl Deref for BindGroupLayout {57type Target = wgpu::BindGroupLayout;5859#[inline]60fn deref(&self) -> &Self::Target {61&self.value62}63}646566