2020-03-26 01:17:48 +00:00
|
|
|
use super::BindingDescriptor;
|
2020-03-10 06:08:09 +00:00
|
|
|
use std::{
|
|
|
|
collections::{hash_map::DefaultHasher, BTreeSet},
|
|
|
|
hash::{Hash, Hasher},
|
|
|
|
};
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
2020-03-26 01:17:48 +00:00
|
|
|
pub struct BindGroupDescriptor {
|
2020-03-10 06:08:09 +00:00
|
|
|
pub index: u32,
|
2020-03-26 01:17:48 +00:00
|
|
|
pub bindings: BTreeSet<BindingDescriptor>,
|
|
|
|
hash: Option<BindGroupDescriptorId>,
|
2020-03-10 06:08:09 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 01:17:48 +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(),
|
|
|
|
hash: None,
|
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
|
|
|
}
|
|
|
|
|
2020-03-26 01:17:48 +00:00
|
|
|
pub fn get_id(&self) -> Option<BindGroupDescriptorId> {
|
2020-03-10 06:08:09 +00:00
|
|
|
self.hash
|
|
|
|
}
|
|
|
|
|
2020-03-26 01:17:48 +00:00
|
|
|
pub fn get_or_update_id(&mut self) -> BindGroupDescriptorId {
|
2020-03-10 06:08:09 +00:00
|
|
|
if self.hash.is_none() {
|
2020-03-26 01:17:48 +00:00
|
|
|
self.update_id();
|
2020-03-10 06:08:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self.hash.unwrap()
|
|
|
|
}
|
|
|
|
|
2020-03-26 01:17:48 +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);
|
2020-03-26 01:17:48 +00:00
|
|
|
self.hash = Some(BindGroupDescriptorId(hasher.finish()));
|
2020-03-10 06:08:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 01:17:48 +00:00
|
|
|
impl Hash for BindGroupDescriptor {
|
2020-03-10 06:08:09 +00:00
|
|
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
|
|
|
self.index.hash(state);
|
|
|
|
self.bindings.hash(state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 01:17:48 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 01:17:48 +00:00
|
|
|
impl Eq for BindGroupDescriptor {}
|