impl Eq + Hash for BindGroup/Layout (#17547)
# Objective Implement `Eq` and `Hash` for the `BindGroup` and `BindGroupLayout` wrappers. ## Solution Implement based on the same assumption that the ID is unique, for consistency with `PartialEq`. ## Testing None; this should be straightforward. If there's an issue that would be a design one.
This commit is contained in:
parent
1c765c9ae7
commit
499510489e
@ -21,7 +21,10 @@ define_atomic_id!(BindGroupId);
|
||||
/// to a [`TrackedRenderPass`](crate::render_phase::TrackedRenderPass).
|
||||
/// This makes them accessible in the pipeline (shaders) as uniforms.
|
||||
///
|
||||
/// May be converted from and dereferences to a wgpu [`BindGroup`](wgpu::BindGroup).
|
||||
/// This is a lightweight thread-safe wrapper around wgpu's own [`BindGroup`](wgpu::BindGroup),
|
||||
/// which can be cloned as needed to workaround lifetime management issues. It may be converted
|
||||
/// from and dereferences to wgpu's [`BindGroup`](wgpu::BindGroup).
|
||||
///
|
||||
/// Can be created via [`RenderDevice::create_bind_group`](RenderDevice::create_bind_group).
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BindGroup {
|
||||
@ -30,13 +33,27 @@ pub struct BindGroup {
|
||||
}
|
||||
|
||||
impl BindGroup {
|
||||
/// Returns the [`BindGroupId`].
|
||||
/// Returns the [`BindGroupId`] representing the unique ID of the bind group.
|
||||
#[inline]
|
||||
pub fn id(&self) -> BindGroupId {
|
||||
self.id
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for BindGroup {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.id == other.id
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for BindGroup {}
|
||||
|
||||
impl core::hash::Hash for BindGroup {
|
||||
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
|
||||
self.id.0.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl From<wgpu::BindGroup> for BindGroup {
|
||||
fn from(value: wgpu::BindGroup) -> Self {
|
||||
BindGroup {
|
||||
|
@ -5,6 +5,14 @@ use core::ops::Deref;
|
||||
|
||||
define_atomic_id!(BindGroupLayoutId);
|
||||
|
||||
/// Bind group layouts define the interface of resources (e.g. buffers, textures, samplers)
|
||||
/// for a shader. The actual resource binding is done via a [`BindGroup`](super::BindGroup).
|
||||
///
|
||||
/// This is a lightweight thread-safe wrapper around wgpu's own [`BindGroupLayout`](wgpu::BindGroupLayout),
|
||||
/// which can be cloned as needed to workaround lifetime management issues. It may be converted
|
||||
/// from and dereferences to wgpu's [`BindGroupLayout`](wgpu::BindGroupLayout).
|
||||
///
|
||||
/// Can be created via [`RenderDevice::create_bind_group_layout`](crate::RenderDevice::create_bind_group_layout).
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BindGroupLayout {
|
||||
id: BindGroupLayoutId,
|
||||
@ -17,7 +25,16 @@ impl PartialEq for BindGroupLayout {
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for BindGroupLayout {}
|
||||
|
||||
impl core::hash::Hash for BindGroupLayout {
|
||||
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
|
||||
self.id.0.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl BindGroupLayout {
|
||||
/// Returns the [`BindGroupLayoutId`] representing the unique ID of the bind group layout.
|
||||
#[inline]
|
||||
pub fn id(&self) -> BindGroupLayoutId {
|
||||
self.id
|
||||
|
Loading…
Reference in New Issue
Block a user