bevy/src/render/pipeline/bind_group.rs

53 lines
1.5 KiB
Rust
Raw Normal View History

use super::BindingDescriptor;
2020-03-10 06:08:09 +00:00
use std::{
collections::{hash_map::DefaultHasher, BTreeSet},
hash::{Hash, Hasher},
};
#[derive(Clone, Debug)]
pub struct BindGroupDescriptor {
2020-03-10 06:08:09 +00:00
pub index: u32,
pub bindings: BTreeSet<BindingDescriptor>,
pub id: BindGroupDescriptorId,
2020-03-10 06:08:09 +00:00
}
#[derive(Hash, Copy, Clone, Eq, PartialEq, Debug)]
pub struct BindGroupDescriptorId(u64);
impl BindGroupDescriptor {
pub fn new(index: u32, bindings: Vec<BindingDescriptor>) -> Self {
2020-03-26 02:20:52 +00:00
let mut descriptor = BindGroupDescriptor {
2020-03-10 06:08:09 +00:00
index,
bindings: bindings.iter().cloned().collect(),
id: BindGroupDescriptorId(0),
2020-03-26 02:20:52 +00:00
};
// TODO: remove all instances of get_or_update_id
descriptor.update_id();
descriptor
2020-03-10 06:08:09 +00:00
}
pub fn update_id(&mut self) {
2020-03-10 06:08:09 +00:00
let mut hasher = DefaultHasher::new();
self.hash(&mut hasher);
self.id = BindGroupDescriptorId(hasher.finish());
2020-03-10 06:08:09 +00:00
}
}
impl Hash for BindGroupDescriptor {
2020-03-10 06:08:09 +00:00
fn hash<H: Hasher>(&self, state: &mut H) {
// TODO: remove index from hash state (or at least id). index is not considered a part of a bind group on the gpu.
// bind groups are bound to indices in pipelines
2020-03-10 06:08:09 +00:00
self.index.hash(state);
self.bindings.hash(state);
}
}
impl PartialEq for BindGroupDescriptor {
fn eq(&self, other: &BindGroupDescriptor) -> bool {
2020-03-10 06:08:09 +00:00
self.index == other.index && self.bindings == other.bindings
}
}
impl Eq for BindGroupDescriptor {}