Skip to main content

enki_anu/recording/
queue.rs

1use 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.pipeline.hash(&mut hasher);
40                    t.grid_size.0.hash(&mut hasher);
41                    t.grid_size.1.hash(&mut hasher);
42                    t.grid_size.2.hash(&mut hasher);
43                    t.local_size.0.hash(&mut hasher);
44                    t.local_size.1.hash(&mut hasher);
45                    t.local_size.2.hash(&mut hasher);
46
47                    for desc in &t.args_ctx.descriptors {
48                        desc.hash(&mut hasher);
49                    }
50                }
51                RawTask::PresentBuffer(p) => {
52                    1u8.hash(&mut hasher);
53                    p.buffer_id.hash(&mut hasher);
54                    p.width.hash(&mut hasher);
55                    p.height.hash(&mut hasher);
56                }
57                RawTask::WriteTimestamp { query_index, stage } => {
58                    4u8.hash(&mut hasher);
59                    query_index.hash(&mut hasher);
60                    stage.as_raw().hash(&mut hasher);
61                }
62            }
63        }
64
65        hasher.finish()
66    }
67}
68
69impl<'a> Default for TaskQueue<'a> {
70    fn default() -> Self {
71        Self::new()
72    }
73}