alpha2_render/
pipeline.rs1use std::sync::OnceLock;
2
3#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
5pub struct PipelineCacheStats {
6 pub runtime_effects: usize,
8 pub builtins: usize,
10}
11
12#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
14pub struct WarmupReport {
15 pub runtime_effects: usize,
17 pub builtins: usize,
19}
20
21#[derive(Debug, Default)]
22pub(crate) struct PipelineCache {
23 pub(crate) composite: OnceLock<CachedCompositePipeline>,
24 #[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 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 pub(crate) uv_nv12_pipeline: wgpu::RenderPipeline,
73}
74
75#[derive(Debug)]
77pub(crate) struct CachedYuvRepackPipeline {
78 pub(crate) bind_group_layout: wgpu::BindGroupLayout,
79 pub(crate) luma: wgpu::RenderPipeline,
81 pub(crate) interleaved_chroma: wgpu::RenderPipeline,
83 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}