Switch to default PartialEq implementation for RenderResourceBinding (#877)

* Switch to default PartialEq implementation for RenderResourceBinding
* Move specialized RenderResourceBinding Hash implementation to BindGroupBuilder
This commit is contained in:
Vladyslav Batyrenko 2020-11-21 21:52:44 +02:00 committed by GitHub
parent b4a864ba5a
commit d11be437cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 54 deletions

View File

@ -1,4 +1,4 @@
use super::{BufferId, RenderResourceBinding, SamplerId, TextureId};
use super::{BufferId, RenderResourceBinding, RenderResourceId, SamplerId, TextureId};
use bevy_utils::AHasher;
use std::{
hash::{Hash, Hasher},
@ -45,7 +45,7 @@ impl BindGroupBuilder {
self.dynamic_uniform_indices.push(dynamic_index);
}
binding.hash(&mut self.hasher);
self.hash_binding(&binding);
self.indexed_bindings.push(IndexedBindGroupEntry {
index,
entry: binding,
@ -102,4 +102,23 @@ impl BindGroupBuilder {
},
}
}
fn hash_binding(&mut self, binding: &RenderResourceBinding) {
match binding {
RenderResourceBinding::Buffer {
buffer,
range,
dynamic_index: _, // dynamic_index is not a part of the binding
} => {
RenderResourceId::from(*buffer).hash(&mut self.hasher);
range.hash(&mut self.hasher);
}
RenderResourceBinding::Texture(texture) => {
RenderResourceId::from(*texture).hash(&mut self.hasher);
}
RenderResourceBinding::Sampler(sampler) => {
RenderResourceId::from(*sampler).hash(&mut self.hasher);
}
}
}
}

View File

@ -1,13 +1,13 @@
use super::{BindGroup, BindGroupId, BufferId, RenderResourceId, SamplerId, TextureId};
use super::{BindGroup, BindGroupId, BufferId, SamplerId, TextureId};
use crate::{
pipeline::{BindGroupDescriptor, BindGroupDescriptorId, PipelineDescriptor},
renderer::RenderResourceContext,
};
use bevy_asset::{Asset, Handle, HandleUntyped};
use bevy_utils::{HashMap, HashSet};
use std::{hash::Hash, ops::Range};
use std::ops::Range;
#[derive(Clone, Eq, Debug)]
#[derive(Clone, PartialEq, Eq, Debug)]
pub enum RenderResourceBinding {
Buffer {
buffer: BufferId,
@ -51,55 +51,6 @@ impl RenderResourceBinding {
}
}
impl PartialEq for RenderResourceBinding {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(
RenderResourceBinding::Buffer {
buffer: self_buffer,
range: self_range,
dynamic_index: _,
},
RenderResourceBinding::Buffer {
buffer: other_buffer,
range: other_range,
dynamic_index: _,
},
) => self_buffer == other_buffer && self_range == other_range,
(
RenderResourceBinding::Texture(self_texture),
RenderResourceBinding::Texture(other_texture),
) => RenderResourceId::from(*self_texture) == RenderResourceId::from(*other_texture),
(
RenderResourceBinding::Sampler(self_sampler),
RenderResourceBinding::Sampler(other_sampler),
) => RenderResourceId::from(*self_sampler) == RenderResourceId::from(*other_sampler),
_ => false,
}
}
}
impl Hash for RenderResourceBinding {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
match self {
RenderResourceBinding::Buffer {
buffer,
range,
dynamic_index: _, // dynamic_index is not a part of the binding
} => {
RenderResourceId::from(*buffer).hash(state);
range.hash(state);
}
RenderResourceBinding::Texture(texture) => {
RenderResourceId::from(*texture).hash(state);
}
RenderResourceBinding::Sampler(sampler) => {
RenderResourceId::from(*sampler).hash(state);
}
}
}
}
#[derive(Eq, PartialEq, Debug)]
pub enum BindGroupStatus {
Changed(BindGroupId),