enki_anu/recording/
queue.rs1use super::task::RawTask;
2use std::collections::hash_map::DefaultHasher;
3use std::hash::{Hash, Hasher};
4
5pub struct TaskQueue<'a> {
6 pub tasks: Vec<RawTask<'a>>,
7}
8
9impl<'a> TaskQueue<'a> {
10 pub fn new() -> Self {
11 Self {
12 tasks: Vec::with_capacity(16),
13 }
14 }
15
16 pub fn push(&mut self, task: RawTask<'a>) {
17 self.tasks.push(task);
18 }
19
20 pub fn clear(&mut self) {
21 self.tasks.clear();
22 }
23
24 pub fn len(&self) -> usize {
25 self.tasks.len()
26 }
27
28 pub fn is_empty(&self) -> bool {
29 self.tasks.is_empty()
30 }
31
32 pub fn calculate_structure_hash(&self) -> u64 {
33 let mut hasher = DefaultHasher::new();
34
35 for task in &self.tasks {
36 match task {
37 RawTask::Compute(t) => {
38 0u8.hash(&mut hasher);
39 t.grid_size.0.hash(&mut hasher);
40 t.grid_size.1.hash(&mut hasher);
41 t.grid_size.2.hash(&mut hasher);
42 t.local_size.0.hash(&mut hasher);
43 t.local_size.1.hash(&mut hasher);
44 t.local_size.2.hash(&mut hasher);
45
46 for desc in &t.args_ctx.descriptors {
47 desc.hash(&mut hasher);
48 }
49 }
50 RawTask::PresentBuffer(p) => {
51 1u8.hash(&mut hasher);
52 p.buffer_id.hash(&mut hasher);
53 p.width.hash(&mut hasher);
54 p.height.hash(&mut hasher);
55 }
56 RawTask::WriteTimestamp { query_index, stage } => {
57 4u8.hash(&mut hasher);
58 query_index.hash(&mut hasher);
59 stage.as_raw().hash(&mut hasher);
60 }
61 }
62 }
63
64 hasher.finish()
65 }
66}
67
68impl<'a> Default for TaskQueue<'a> {
69 fn default() -> Self {
70 Self::new()
71 }
72}