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    /// The pipeline of each composite program (`composite::CompositeProgram`),
60    /// the loop then the one-layer program, each built the first time a pass
61    /// draws with it. Each serves every pass of its program: a small layer
62    /// drawn alone and a batch, the first pass and the later ones.
63    pub(crate) programs: [std::sync::OnceLock<wgpu::RenderPipeline>; 2],
64}
65
66#[derive(Debug)]
67pub(crate) struct CachedYuvReadbackPipeline {
68    pub(crate) bind_group_layout: wgpu::BindGroupLayout,
69    pub(crate) y_pipeline: wgpu::RenderPipeline,
70    pub(crate) uv_pipeline: wgpu::RenderPipeline,
71    /// Writes both chroma channels into one half-size `Rg8Unorm` plane, which
72    /// is the layout a hardware encoder's NV12 image expects.
73    pub(crate) uv_nv12_pipeline: wgpu::RenderPipeline,
74}
75
76/// Plane-for-plane copies of decoded 8-bit 4:2:0 frames into NV12 targets.
77#[derive(Debug)]
78pub(crate) struct CachedYuvRepackPipeline {
79    pub(crate) bind_group_layout: wgpu::BindGroupLayout,
80    /// Writes an `R8Unorm` luma target.
81    pub(crate) luma: wgpu::RenderPipeline,
82    /// Writes an `Rg8Unorm` chroma target from an interleaved UV plane.
83    pub(crate) interleaved_chroma: wgpu::RenderPipeline,
84    /// Writes an `Rg8Unorm` chroma target from separate U and V planes.
85    pub(crate) planar_chroma: wgpu::RenderPipeline,
86}
87
88impl PipelineCache {
89    pub(crate) fn builtin_count(&self) -> usize {
90        usize::from(self.composite.get().is_some())
91            + [&self.quad]
92                .into_iter()
93                .filter(|pipeline| pipeline.get().is_some())
94                .count()
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}