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>,
|
2020-03-26 08:57:36 +00:00
|
|
|
pub id: 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(),
|
2020-03-26 08:57:36 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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 08:57:36 +00:00
|
|
|
self.id = 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) {
|
2020-03-26 08:57:36 +00:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {}
|