Skip to main content

molgfx_gpu/descriptors/
pass.rs

1//! Render and compute pass descriptors.
2
3use crate::device::Device;
4
5/// How a color attachment starts the pass.
6#[derive(Clone, Copy, PartialEq, Debug)]
7pub enum LoadOp {
8    /// Clear to the given linear RGBA value.
9    Clear([f64; 4]),
10    /// Keep the existing contents.
11    Load,
12}
13
14/// How a depth attachment starts the pass.
15#[derive(Clone, Copy, PartialEq, Debug)]
16pub enum DepthLoadOp {
17    /// Clear to the given depth. Under reversed depth the empty scene
18    /// clears to 0.0 (the far plane).
19    Clear(f32),
20    /// Keep the existing contents.
21    Load,
22}
23
24/// One color attachment of a render pass.
25#[derive(Debug)]
26pub struct ColorAttachment<'a, D: Device> {
27    /// The target view.
28    pub view: &'a D::TextureView,
29    /// Load behavior.
30    pub load: LoadOp,
31}
32
33/// The depth attachment of a render pass.
34#[derive(Debug)]
35pub struct DepthAttachment<'a, D: Device> {
36    /// The target view.
37    pub view: &'a D::TextureView,
38    /// Load behavior.
39    pub load: DepthLoadOp,
40    /// Whether the pass only tests/samples depth and never stores it.
41    pub read_only: bool,
42}
43
44/// Everything needed to begin a render pass.
45#[derive(Debug)]
46pub struct RenderPassDesc<'a, D: Device> {
47    /// Debug label.
48    pub label: &'static str,
49    /// Color attachments in order.
50    pub colors: &'a [ColorAttachment<'a, D>],
51    /// Optional depth attachment.
52    pub depth: Option<DepthAttachment<'a, D>>,
53    /// Optional timestamps written at the actual pass boundaries.
54    pub timestamps: Option<TimestampWrites<'a, D>>,
55}
56
57/// Everything needed to begin a compute pass.
58#[derive(Debug)]
59pub struct ComputePassDesc<'a, D: Device> {
60    /// Debug label.
61    pub label: &'static str,
62    /// Optional timestamps written at the actual pass boundaries.
63    pub timestamps: Option<TimestampWrites<'a, D>>,
64}
65
66/// Timestamp query writes attached to one render or compute pass.
67#[derive(Debug)]
68pub struct TimestampWrites<'a, D: Device> {
69    /// Destination query set.
70    pub queries: &'a D::QuerySet,
71    /// Query written as the pass begins.
72    pub beginning: Option<u32>,
73    /// Query written as the pass ends.
74    pub end: Option<u32>,
75}
76
77impl<D: Device> Copy for TimestampWrites<'_, D> {}
78
79impl<D: Device> Clone for TimestampWrites<'_, D> {
80    fn clone(&self) -> Self {
81        *self
82    }
83}