bevy/crates/bevy_render/src/pipeline/bind_group.rs

45 lines
1.2 KiB
Rust
Raw Normal View History

use super::BindingDescriptor;
2020-03-10 06:08:09 +00:00
use std::{
2020-03-28 05:41:45 +00:00
collections::hash_map::DefaultHasher,
2020-03-10 06:08:09 +00:00
hash::{Hash, Hasher},
};
2020-03-28 05:41:45 +00:00
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct BindGroupDescriptor {
2020-03-10 06:08:09 +00:00
pub index: u32,
2020-03-28 05:41:45 +00:00
pub bindings: Vec<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,
2020-03-28 05:41:45 +00:00
bindings,
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);
}
}