1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use super::BindingDescriptor;
use std::{
collections::hash_map::DefaultHasher,
hash::{Hash, Hasher},
};
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct BindGroupDescriptor {
pub index: u32,
pub bindings: Vec<BindingDescriptor>,
pub id: BindGroupDescriptorId,
}
#[derive(Hash, Copy, Clone, Eq, PartialEq, Debug)]
pub struct BindGroupDescriptorId(u64);
impl BindGroupDescriptor {
pub fn new(index: u32, bindings: Vec<BindingDescriptor>) -> Self {
let mut descriptor = BindGroupDescriptor {
index,
bindings,
id: BindGroupDescriptorId(0),
};
descriptor.update_id();
descriptor
}
pub fn update_id(&mut self) {
let mut hasher = DefaultHasher::new();
self.hash(&mut hasher);
self.id = BindGroupDescriptorId(hasher.finish());
}
}
impl Hash for BindGroupDescriptor {
fn hash<H: Hasher>(&self, state: &mut H) {
self.index.hash(state);
self.bindings.hash(state);
}
}