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