rendy_chain/schedule/
submission.rs

1use super::queue::QueueId;
2use crate::Id;
3use std::collections::HashMap;
4
5/// Submission id.
6#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
7pub struct SubmissionId {
8    /// Queue id of the submission.
9    pub queue: QueueId,
10
11    /// Index of the queue.
12    pub index: usize,
13}
14
15impl SubmissionId {
16    /// Create new id from queue id and index.
17    pub fn new(queue: QueueId, index: usize) -> Self {
18        SubmissionId { queue, index }
19    }
20
21    /// Get family id.
22    pub fn family(&self) -> rendy_core::hal::queue::QueueFamilyId {
23        self.queue.family()
24    }
25
26    /// Get queue id.
27    pub fn queue(&self) -> QueueId {
28        self.queue
29    }
30
31    /// Get index.
32    pub fn index(&self) -> usize {
33        self.index
34    }
35}
36
37/// This type corresponds to commands that should be recorded into single primary command buffer.
38#[derive(Clone, Debug)]
39pub struct Submission<S> {
40    node: usize,
41    id: SubmissionId,
42    buffer_links: HashMap<Id, usize>,
43    image_links: HashMap<Id, usize>,
44    wait_factor: usize,
45    submit_order: usize,
46    sync: S,
47}
48
49impl<S> Submission<S> {
50    /// Get id of the `Node`.
51    pub fn node(&self) -> usize {
52        self.node
53    }
54
55    /// Get id of the `Submission`.
56    pub fn id(&self) -> SubmissionId {
57        self.id
58    }
59
60    /// Get synchronization for `Submission`.
61    pub fn sync(&self) -> &S {
62        &self.sync
63    }
64
65    /// Get wait factor for `Submission`
66    pub fn wait_factor(&self) -> usize {
67        self.wait_factor
68    }
69
70    /// Get submit order for `Submission`
71    pub fn submit_order(&self) -> usize {
72        self.submit_order
73    }
74
75    /// Get link index for resource by id.
76    pub fn buffer_link_index(&self, id: Id) -> usize {
77        self.buffer_links[&id]
78    }
79
80    /// Set link index for given chain.
81    pub fn set_buffer_link(&mut self, id: Id, link: usize) {
82        assert!(self.buffer_links.insert(id, link).is_none());
83    }
84
85    /// Get link index for resource by id.
86    pub fn image_link_index(&self, id: Id) -> usize {
87        self.image_links[&id]
88    }
89
90    /// Set link index for given chain.
91    pub fn set_image_link(&mut self, id: Id, link: usize) {
92        assert!(self.image_links.insert(id, link).is_none());
93    }
94
95    /// Create new submission with specified pass.
96    pub(crate) fn new(
97        node: usize,
98        wait_factor: usize,
99        submit_order: usize,
100        id: SubmissionId,
101        sync: S,
102    ) -> Self {
103        Submission {
104            node,
105            buffer_links: HashMap::default(),
106            image_links: HashMap::default(),
107            id,
108            wait_factor,
109            submit_order,
110            sync,
111        }
112    }
113
114    /// Set synchronization to the `Submission`.
115    pub fn set_sync<T>(&self, sync: T) -> Submission<T> {
116        Submission {
117            node: self.node,
118            buffer_links: self.buffer_links.clone(),
119            image_links: self.image_links.clone(),
120            id: self.id,
121            wait_factor: self.wait_factor,
122            submit_order: self.submit_order,
123            sync,
124        }
125    }
126}