Skip to main content

molgfx_gpu/descriptors/
pipeline.rs

1//! Pipeline descriptors.
2
3use super::texture::TextureFormat;
4use crate::device::Device;
5
6/// Depth comparison functions.
7#[derive(Clone, Copy, PartialEq, Eq, Debug)]
8pub enum CompareFunction {
9    /// Pass when the fragment depth is greater or equal — the default under
10    /// reversed depth, where nearer means larger.
11    GreaterEqual,
12    /// Pass when strictly greater.
13    Greater,
14    /// Pass when less or equal (forward depth).
15    LessEqual,
16    /// Always pass.
17    Always,
18}
19
20/// How a color target blends its output.
21#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
22pub enum BlendMode {
23    /// Overwrite the destination.
24    #[default]
25    Replace,
26    /// Classic source-over alpha blending.
27    Alpha,
28    /// Additive accumulation.
29    Additive,
30    /// Multiply destination by (1 − source alpha); the revealage half of
31    /// weighted-blended transparency.
32    ReverseMultiply,
33}
34
35/// One color attachment a render pipeline writes.
36#[derive(Clone, Copy, PartialEq, Eq, Debug)]
37pub struct ColorTarget {
38    /// Attachment format.
39    pub format: TextureFormat,
40    /// Blend behavior.
41    pub blend: BlendMode,
42}
43
44/// Depth behavior of a render pipeline.
45#[derive(Clone, Copy, PartialEq, Eq, Debug)]
46pub struct DepthState {
47    /// Depth attachment format.
48    pub format: TextureFormat,
49    /// Whether the pipeline writes depth.
50    pub write: bool,
51    /// The comparison against stored depth.
52    pub compare: CompareFunction,
53}
54
55/// Primitive assembly.
56#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
57pub enum PrimitiveTopology {
58    /// Independent triangles — the only topology the impostor and mesh
59    /// paths need.
60    #[default]
61    TriangleList,
62}
63
64/// Everything needed to create a render pipeline. Pipelines are created at
65/// load and cached; never inside the frame loop.
66#[derive(Debug)]
67pub struct RenderPipelineDesc<'a, D: Device> {
68    /// Debug label.
69    pub label: &'static str,
70    /// Bind-group layouts by group index (0 = per-frame, 1 = per-pass,
71    /// 2 = per-representation, 3 = per-material); `None` leaves a
72    /// frequency slot unused without renumbering the groups after it.
73    pub layouts: &'a [Option<&'a D::BindGroupLayout>],
74    /// The compiled module holding both entry points; modules are created
75    /// once and shared across the pipelines that use them.
76    pub shader: &'a D::ShaderModule,
77    /// Vertex entry point name.
78    pub vs_entry: &'static str,
79    /// Fragment entry point name; `None` for depth-only pipelines.
80    pub fs_entry: Option<&'static str>,
81    /// Color targets, in attachment order.
82    pub color_targets: &'a [ColorTarget],
83    /// Depth behavior, if the pass has a depth attachment.
84    pub depth: Option<DepthState>,
85    /// Primitive assembly.
86    pub topology: PrimitiveTopology,
87    /// Values for the shader's `override` constants, by identifier.
88    ///
89    /// Specializing at pipeline creation is what lets a shader resolve a
90    /// shape, a sample count or a feature switch once, instead of branching
91    /// on it in every fragment. Empty leaves every override at its default.
92    pub constants: &'a [(&'static str, f64)],
93}
94
95/// Everything needed to create a compute pipeline.
96#[derive(Debug)]
97pub struct ComputePipelineDesc<'a, D: Device> {
98    /// Debug label.
99    pub label: &'static str,
100    /// Bind-group layouts by group index; `None` for unused slots.
101    pub layouts: &'a [Option<&'a D::BindGroupLayout>],
102    /// The compiled module.
103    pub shader: &'a D::ShaderModule,
104    /// Compute entry point name.
105    pub entry: &'static str,
106}