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    pub(crate) vector: OnceLock<crate::vector::CachedVectorPipeline>,
32}
33
34#[derive(Debug)]
35pub(crate) struct CachedPipeline {
36    pub(crate) bind_group_layout: wgpu::BindGroupLayout,
37    pub(crate) pipeline: wgpu::RenderPipeline,
38}
39
40#[derive(Debug)]
41pub(crate) struct CachedYuvPipeline {
42    pub(crate) bind_group_layout: wgpu::BindGroupLayout,
43    pub(crate) pipeline: wgpu::RenderPipeline,
44    pub(crate) sampler: wgpu::Sampler,
45}
46
47#[derive(Debug)]
48pub(crate) struct CachedSampledPipeline {
49    pub(crate) bind_group_layout: wgpu::BindGroupLayout,
50    pub(crate) pipeline: wgpu::RenderPipeline,
51    pub(crate) sampler: wgpu::Sampler,
52}
53
54#[derive(Debug)]
55pub(crate) struct CachedCompositePipeline {
56    pub(crate) bind_group_layout: wgpu::BindGroupLayout,
57    pub(crate) sampler: wgpu::Sampler,
58    pub(crate) shader: wgpu::ShaderModule,
59    /// One pipeline per composite program (loop, then one-layer), built on first use.
60    pub(crate) programs: [std::sync::OnceLock<wgpu::RenderPipeline>; 2],
61}
62
63#[derive(Debug)]
64pub(crate) struct CachedYuvReadbackPipeline {
65    pub(crate) bind_group_layout: wgpu::BindGroupLayout,
66    pub(crate) y_pipeline: wgpu::RenderPipeline,
67    pub(crate) uv_pipeline: wgpu::RenderPipeline,
68    /// Writes both chroma channels into one half-size `Rg8Unorm` plane, the NV12 layout hardware
69    /// encoders expect.
70    pub(crate) uv_nv12_pipeline: wgpu::RenderPipeline,
71}
72
73/// Plane-for-plane copies of decoded 8-bit 4:2:0 frames into NV12 targets.
74#[derive(Debug)]
75pub(crate) struct CachedYuvRepackPipeline {
76    pub(crate) bind_group_layout: wgpu::BindGroupLayout,
77    /// Writes an `R8Unorm` luma target.
78    pub(crate) luma: wgpu::RenderPipeline,
79    /// Writes an `Rg8Unorm` chroma target from an interleaved UV plane.
80    pub(crate) interleaved_chroma: wgpu::RenderPipeline,
81    /// Writes an `Rg8Unorm` chroma target from separate U and V planes.
82    pub(crate) planar_chroma: wgpu::RenderPipeline,
83}
84
85impl PipelineCache {
86    pub(crate) fn builtin_count(&self) -> usize {
87        usize::from(self.composite.get().is_some())
88            + [&self.quad]
89                .into_iter()
90                .filter(|pipeline| pipeline.get().is_some())
91                .count()
92            + usize::from(self.yuv.get().is_some())
93            + usize::from(self.yuv16.get().is_some())
94            + usize::from(self.rgba_present.get().is_some())
95            + usize::from(self.readback_pack.get().is_some())
96            + usize::from(self.yuv_readback.get().is_some())
97            + usize::from(self.yuv_repack.get().is_some())
98            + self
99                .vector
100                .get()
101                .map_or(0, crate::vector::CachedVectorPipeline::pipeline_count)
102    }
103}