rendy_chain/
node.rs

1use std::collections::hash_map::{HashMap, Iter as HashMapIter};
2
3use crate::{
4    resource::{Buffer, Image, Resource},
5    Id,
6};
7
8/// State in which node uses resource and usage flags.
9#[derive(Clone, Copy, Debug)]
10pub struct State<R: Resource> {
11    /// Access performed by the node.
12    pub access: R::Access,
13
14    /// Optional layout in which node can use resource.
15    pub layout: R::Layout,
16
17    /// Stages at which resource is accessed.
18    pub stages: rendy_core::hal::pso::PipelineStage,
19
20    /// Usage flags required for resource.
21    pub usage: R::Usage,
22}
23
24/// Type alias for `State<Buffer>`
25pub type BufferState = State<Buffer>;
26
27/// Type alias for `State<Image>`
28pub type ImageState = State<Image>;
29
30/// Description of node.
31#[derive(Clone, Debug)]
32pub struct Node {
33    /// Id of the node.
34    pub id: usize,
35
36    /// Family required to execute the node.
37    pub family: rendy_core::hal::queue::QueueFamilyId,
38
39    /// Dependencies of the node.
40    /// Those are indices of other nodes in array.
41    pub dependencies: Vec<usize>,
42
43    /// Buffer category ids and required state.
44    pub buffers: HashMap<Id, State<Buffer>>,
45
46    /// Image category ids and required state.
47    pub images: HashMap<Id, State<Image>>,
48}
49
50impl Node {
51    /// Get family on which this node will be executed.
52    pub fn family(&self) -> rendy_core::hal::queue::QueueFamilyId {
53        self.family
54    }
55
56    /// Get indices of nodes this node depends on.
57    pub fn dependencies(&self) -> &[usize] {
58        &self.dependencies
59    }
60
61    /// Get iterator to buffer states this node accesses.
62    pub fn buffers(&self) -> HashMapIter<'_, Id, State<Buffer>> {
63        self.buffers.iter()
64    }
65
66    /// Get iterator to image states this node accesses.
67    pub fn images(&self) -> HashMapIter<'_, Id, State<Image>> {
68        self.images.iter()
69    }
70}