Skip to main content

alpha2_render/
pipeline.rs

1use std::sync::OnceLock;
2
3/// Current pipeline-cache occupancy.
4#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
5pub struct PipelineCacheStats {
6    /// Eagerly registered runtime-effect pipelines.
7    pub runtime_effects: usize,
8    /// Lazily initialized built-in pipelines.
9    pub builtins: usize,
10}
11
12/// Work completed by a graph warmup request.
13#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
14pub struct WarmupReport {
15    /// Runtime effect pipelines verified as present.
16    pub runtime_effects: usize,
17    /// Built-in pipelines required and initialized.
18    pub builtins: usize,
19}
20
21#[derive(Debug, Default)]
22pub(crate) struct PipelineCache {
23    pub(crate) composite: OnceLock<CachedCompositePipeline>,
24    pub(crate) quad: OnceLock<CachedPipeline>,
25    pub(crate) readback_pack: OnceLock<CachedPipeline>,
26    pub(crate) rgba_present: OnceLock<CachedSampledPipeline>,
27    pub(crate) yuv_readback: OnceLock<CachedYuvReadbackPipeline>,
28    pub(crate) yuv: OnceLock<CachedYuvPipeline>,
29    pub(crate) yuv16: OnceLock<CachedYuvPipeline>,
30    pub(crate) yuv_repack: OnceLock<CachedYuvRepackPipeline>,
31}
32
33#[derive(Debug)]
34pub(crate) struct CachedPipeline {
35    pub(crate) bind_group_layout: wgpu::BindGroupLayout,
36    pub(crate) pipeline: wgpu::RenderPipeline,
37}
38
39#[derive(Debug)]
40pub(crate) struct CachedYuvPipeline {
41    pub(crate) bind_group_layout: wgpu::BindGroupLayout,
42    pub(crate) pipeline: wgpu::RenderPipeline,
43    pub(crate) sampler: wgpu::Sampler,
44}
45
46#[derive(Debug)]
47pub(crate) struct CachedSampledPipeline {
48    pub(crate) bind_group_layout: wgpu::BindGroupLayout,
49    pub(crate) pipeline: wgpu::RenderPipeline,
50    pub(crate) sampler: wgpu::Sampler,
51}
52
53#[derive(Debug)]
54pub(crate) struct CachedCompositePipeline {
55    pub(crate) bind_group_layout: wgpu::BindGroupLayout,
56    pub(crate) sampler: wgpu::Sampler,
57    pub(crate) shader: wgpu::ShaderModule,
58    /// The pipeline of each composite program (`composite::CompositeProgram`),
59    /// the loop then the one-layer program, each built the first time a pass
60    /// draws with it. Each serves every pass of its program: a small layer
61    /// drawn alone and a batch, the first pass and the later ones.
62    pub(crate) programs: [std::sync::OnceLock<wgpu::RenderPipeline>; 2],
63}
64
65#[derive(Debug)]
66pub(crate) struct CachedYuvReadbackPipeline {
67    pub(crate) bind_group_layout: wgpu::BindGroupLayout,
68    pub(crate) y_pipeline: wgpu::RenderPipeline,
69    pub(crate) uv_pipeline: wgpu::RenderPipeline,
70    /// Writes both chroma channels into one half-size `Rg8Unorm` plane, which
71    /// is the layout a hardware encoder's NV12 image expects.
72    pub(crate) uv_nv12_pipeline: wgpu::RenderPipeline,
73}
74
75/// Plane-for-plane copies of decoded 8-bit 4:2:0 frames into NV12 targets.
76#[derive(Debug)]
77pub(crate) struct CachedYuvRepackPipeline {
78    pub(crate) bind_group_layout: wgpu::BindGroupLayout,
79    /// Writes an `R8Unorm` luma target.
80    pub(crate) luma: wgpu::RenderPipeline,
81    /// Writes an `Rg8Unorm` chroma target from an interleaved UV plane.
82    pub(crate) interleaved_chroma: wgpu::RenderPipeline,
83    /// Writes an `Rg8Unorm` chroma target from separate U and V planes.
84    pub(crate) planar_chroma: wgpu::RenderPipeline,
85}
86
87impl PipelineCache {
88    pub(crate) fn builtin_count(&self) -> usize {
89        usize::from(self.composite.get().is_some())
90            + [&self.quad]
91                .into_iter()
92                .filter(|pipeline| pipeline.get().is_some())
93                .count()
94            + usize::from(self.yuv.get().is_some())
95            + usize::from(self.yuv16.get().is_some())
96            + usize::from(self.rgba_present.get().is_some())
97            + usize::from(self.readback_pack.get().is_some())
98            + usize::from(self.yuv_readback.get().is_some())
99            + usize::from(self.yuv_repack.get().is_some())
100    }
101}