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    /// Test-only: the full-screen quad.
25    #[cfg(test)]
26    pub(crate) quad: OnceLock<CachedPipeline>,
27    pub(crate) readback_pack: OnceLock<CachedPipeline>,
28    pub(crate) rgba_present: OnceLock<CachedSampledPipeline>,
29    pub(crate) yuv_readback: OnceLock<CachedYuvReadbackPipeline>,
30    pub(crate) yuv: OnceLock<CachedYuvPipeline>,
31    pub(crate) yuv16: OnceLock<CachedYuvPipeline>,
32    pub(crate) yuv_repack: OnceLock<CachedYuvRepackPipeline>,
33    pub(crate) vector: OnceLock<crate::vector::CachedVectorPipeline>,
34}
35
36#[derive(Debug)]
37pub(crate) struct CachedPipeline {
38    pub(crate) bind_group_layout: wgpu::BindGroupLayout,
39    pub(crate) pipeline: wgpu::RenderPipeline,
40}
41
42#[derive(Debug)]
43pub(crate) struct CachedYuvPipeline {
44    pub(crate) bind_group_layout: wgpu::BindGroupLayout,
45    pub(crate) pipeline: wgpu::RenderPipeline,
46    pub(crate) sampler: wgpu::Sampler,
47}
48
49#[derive(Debug)]
50pub(crate) struct CachedSampledPipeline {
51    pub(crate) bind_group_layout: wgpu::BindGroupLayout,
52    pub(crate) pipeline: wgpu::RenderPipeline,
53    pub(crate) sampler: wgpu::Sampler,
54}
55
56#[derive(Debug)]
57pub(crate) struct CachedCompositePipeline {
58    pub(crate) bind_group_layout: wgpu::BindGroupLayout,
59    pub(crate) sampler: wgpu::Sampler,
60    pub(crate) shader: wgpu::ShaderModule,
61    /// One pipeline per composite program (loop, then one-layer), built on first use.
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, the NV12 layout hardware
71    /// encoders expect.
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        #[cfg(test)]
90        let quad = usize::from(self.quad.get().is_some());
91        #[cfg(not(test))]
92        let quad = 0;
93        usize::from(self.composite.get().is_some())
94            + quad
95            + usize::from(self.yuv.get().is_some())
96            + usize::from(self.yuv16.get().is_some())
97            + usize::from(self.rgba_present.get().is_some())
98            + usize::from(self.readback_pack.get().is_some())
99            + usize::from(self.yuv_readback.get().is_some())
100            + usize::from(self.yuv_repack.get().is_some())
101            + self
102                .vector
103                .get()
104                .map_or(0, crate::vector::CachedVectorPipeline::pipeline_count)
105    }
106}