use crate::error::Result;
use crate::pipeline_layouts::PipelineLayoutCacheKey;
use crate::pipelines::compute_pipeline::{ComputePipelineCacheKey, ComputePipelineKey};
use crate::render_passes::light_culling::{
bind_group::LightCullingBindGroups, buffers::DEFAULT_SLICE_COUNT,
shader::cache_key::ShaderCacheKeyLightCulling,
};
use crate::render_passes::RenderPassInitContext;
pub struct LightCullingPipelines {
pub pipeline_key: ComputePipelineKey,
pub tile_pipeline_key: ComputePipelineKey,
pub slice_count: u32,
}
impl LightCullingPipelines {
pub async fn new(
ctx: &mut RenderPassInitContext<'_>,
bind_groups: &LightCullingBindGroups,
) -> Result<Self> {
Self::build(ctx, bind_groups, DEFAULT_SLICE_COUNT).await
}
async fn build(
ctx: &mut RenderPassInitContext<'_>,
bind_groups: &LightCullingBindGroups,
slice_count: u32,
) -> Result<Self> {
let pipeline_layout_key = ctx.pipeline_layouts.get_key(
ctx.gpu,
ctx.bind_group_layouts,
PipelineLayoutCacheKey::new(vec![bind_groups.bind_group_layout_key]),
)?;
let shader_key = ctx
.shaders
.get_key(ctx.gpu, ShaderCacheKeyLightCulling { slice_count })
.await?;
let pipeline_key = ctx
.pipelines
.compute
.get_key(
ctx.gpu,
ctx.shaders,
ctx.pipeline_layouts,
ComputePipelineCacheKey::new(shader_key, pipeline_layout_key)
.with_entry_point("cs_main"),
)
.await?;
let tile_pipeline_key = ctx
.pipelines
.compute
.get_key(
ctx.gpu,
ctx.shaders,
ctx.pipeline_layouts,
ComputePipelineCacheKey::new(shader_key, pipeline_layout_key)
.with_entry_point("cs_tile"),
)
.await?;
Ok(Self {
pipeline_key,
tile_pipeline_key,
slice_count,
})
}
}