use valo_geometry::Color;
use crate::host_buffer::{UniformSlot, VertexSlot};
use crate::pipelines::PipelineKey;
use crate::renderer::RenderStats;
pub(crate) struct FramePlan {
pub passes: Vec<PlannedPass>,
pub stats: RenderStats,
}
impl FramePlan {
pub fn pipeline_keys(&self) -> impl Iterator<Item = PipelineKey> + '_ {
self.passes
.iter()
.flat_map(|pass| pass.target.draws())
.flat_map(|draw| {
draw.stencil
.as_ref()
.map(|stencil| stencil.key)
.into_iter()
.chain([draw.key])
})
}
}
impl PassTarget {
pub fn draws(&self) -> &[Draw] {
match self {
PassTarget::Context { draws, .. } => draws,
PassTarget::Filter { draw, .. } => std::slice::from_ref(draw),
}
}
}
pub(crate) struct PlannedPass {
pub pre_copies: Vec<TextureCopy>,
pub target: PassTarget,
}
pub(crate) enum PassTarget {
Context {
attachments: ContextAttachments,
clear: Color,
draws: Vec<Draw>,
},
Filter { view: wgpu::TextureView, draw: Draw },
}
#[derive(Clone)]
pub(crate) struct ContextAttachments {
pub msaa: wgpu::TextureView,
pub depth: wgpu::TextureView,
pub resolve: wgpu::TextureView,
}
pub(crate) struct TextureCopy {
pub src: wgpu::Texture,
pub dst: wgpu::Texture,
pub size: [u32; 2],
}
#[derive(Clone)]
pub(crate) struct Draw {
pub stencil: Option<Stencil>,
pub key: PipelineKey,
pub uniforms: UniformSlot,
pub bindings: Bindings,
pub geometry: Geometry,
pub z: f32,
}
#[derive(Clone)]
pub(crate) struct Stencil {
pub key: PipelineKey,
pub uniforms: UniformSlot,
pub mesh: Mesh,
}
#[derive(Clone, Copy)]
pub(crate) enum Geometry {
Quad,
Mesh(Mesh),
}
#[derive(Clone, Copy)]
pub(crate) struct Mesh {
pub slot: VertexSlot,
pub vertices: u32,
}
#[derive(Clone)]
pub(crate) enum Bindings {
Plain,
Textured(wgpu::BindGroup),
Blurred {
texture: wgpu::BindGroup,
kernel: UniformSlot,
},
Runtime {
images: Option<wgpu::BindGroup>,
uniforms: Option<UniformSlot>,
source: Option<wgpu::BindGroup>,
},
}