use std::sync::OnceLock;
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub struct PipelineCacheStats {
pub runtime_effects: usize,
pub builtins: usize,
}
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub struct WarmupReport {
pub runtime_effects: usize,
pub builtins: usize,
}
#[derive(Debug, Default)]
pub(crate) struct PipelineCache {
pub(crate) composite: OnceLock<CachedCompositePipeline>,
pub(crate) quad: OnceLock<CachedPipeline>,
pub(crate) readback_pack: OnceLock<CachedPipeline>,
pub(crate) rgba_present: OnceLock<CachedSampledPipeline>,
pub(crate) yuv_readback: OnceLock<CachedYuvReadbackPipeline>,
pub(crate) yuv: OnceLock<CachedYuvPipeline>,
pub(crate) yuv16: OnceLock<CachedYuvPipeline>,
pub(crate) yuv_repack: OnceLock<CachedYuvRepackPipeline>,
}
#[derive(Debug)]
pub(crate) struct CachedPipeline {
pub(crate) bind_group_layout: wgpu::BindGroupLayout,
pub(crate) pipeline: wgpu::RenderPipeline,
}
#[derive(Debug)]
pub(crate) struct CachedYuvPipeline {
pub(crate) bind_group_layout: wgpu::BindGroupLayout,
pub(crate) pipeline: wgpu::RenderPipeline,
pub(crate) sampler: wgpu::Sampler,
}
#[derive(Debug)]
pub(crate) struct CachedSampledPipeline {
pub(crate) bind_group_layout: wgpu::BindGroupLayout,
pub(crate) pipeline: wgpu::RenderPipeline,
pub(crate) sampler: wgpu::Sampler,
}
#[derive(Debug)]
pub(crate) struct CachedCompositePipeline {
pub(crate) bind_group_layout: wgpu::BindGroupLayout,
pub(crate) sampler: wgpu::Sampler,
pub(crate) shader: wgpu::ShaderModule,
pub(crate) programs: [std::sync::OnceLock<wgpu::RenderPipeline>; 2],
}
#[derive(Debug)]
pub(crate) struct CachedYuvReadbackPipeline {
pub(crate) bind_group_layout: wgpu::BindGroupLayout,
pub(crate) y_pipeline: wgpu::RenderPipeline,
pub(crate) uv_pipeline: wgpu::RenderPipeline,
pub(crate) uv_nv12_pipeline: wgpu::RenderPipeline,
}
#[derive(Debug)]
pub(crate) struct CachedYuvRepackPipeline {
pub(crate) bind_group_layout: wgpu::BindGroupLayout,
pub(crate) luma: wgpu::RenderPipeline,
pub(crate) interleaved_chroma: wgpu::RenderPipeline,
pub(crate) planar_chroma: wgpu::RenderPipeline,
}
impl PipelineCache {
pub(crate) fn builtin_count(&self) -> usize {
usize::from(self.composite.get().is_some())
+ [&self.quad]
.into_iter()
.filter(|pipeline| pipeline.get().is_some())
.count()
+ usize::from(self.yuv.get().is_some())
+ usize::from(self.yuv16.get().is_some())
+ usize::from(self.rgba_present.get().is_some())
+ usize::from(self.readback_pack.get().is_some())
+ usize::from(self.yuv_readback.get().is_some())
+ usize::from(self.yuv_repack.get().is_some())
}
}