use crate::resource::AccelerationStructure;
use crate::track::metadata::ResourceMetadata;
use crate::track::ResourceUses;
use hal::AccelerationStructureUses;
use std::sync::Arc;
use wgt::strict_assert;
pub(crate) struct AccelerationStructureTracker<T: AccelerationStructure> {
start: Vec<AccelerationStructureUses>,
end: Vec<AccelerationStructureUses>,
metadata: ResourceMetadata<Arc<T>>,
}
impl<T: AccelerationStructure> AccelerationStructureTracker<T> {
pub fn new() -> Self {
Self {
start: Vec::new(),
end: Vec::new(),
metadata: ResourceMetadata::new(),
}
}
fn tracker_assert_in_bounds(&self, index: usize) {
strict_assert!(index < self.start.len());
strict_assert!(index < self.end.len());
self.metadata.tracker_assert_in_bounds(index);
}
pub fn set_size(&mut self, size: usize) {
self.start.resize(size, AccelerationStructureUses::empty());
self.end.resize(size, AccelerationStructureUses::empty());
self.metadata.set_size(size);
}
fn allow_index(&mut self, index: usize) {
if index >= self.start.len() {
self.set_size(index + 1);
}
}
pub fn contains(&self, acceleration_structure: &T) -> bool {
self.metadata
.contains(acceleration_structure.tracker_index().as_usize())
}
pub fn set_single(&mut self, resource: Arc<T>) {
let index: usize = resource.tracker_index().as_usize();
self.allow_index(index);
self.tracker_assert_in_bounds(index);
}
}
impl ResourceUses for AccelerationStructureUses {
const EXCLUSIVE: Self = Self::empty();
type Selector = ();
fn bits(self) -> u16 {
Self::bits(&self) as u16
}
fn all_ordered(self) -> bool {
true
}
fn any_exclusive(self) -> bool {
self.intersects(Self::EXCLUSIVE)
}
}