use crate::{debug_label::DebugLabel, RenderContext};
use super::{
bind_group_layout_pool::GpuBindGroupLayoutHandle,
static_resource_pool::{StaticResourcePool, StaticResourcePoolReadLockAccessor},
};
slotmap::new_key_type! { pub struct GpuPipelineLayoutHandle; }
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct PipelineLayoutDesc {
pub label: DebugLabel,
pub entries: Vec<GpuBindGroupLayoutHandle>,
}
#[derive(Default)]
pub struct GpuPipelineLayoutPool {
pool: StaticResourcePool<GpuPipelineLayoutHandle, PipelineLayoutDesc, wgpu::PipelineLayout>,
}
impl GpuPipelineLayoutPool {
pub fn get_or_create(
&self,
ctx: &RenderContext,
desc: &PipelineLayoutDesc,
) -> GpuPipelineLayoutHandle {
self.pool.get_or_create(desc, |desc| {
let bind_groups = ctx.gpu_resources.bind_group_layouts.resources();
ctx.device
.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: desc.label.get(),
bind_group_layouts: &desc
.entries
.iter()
.map(|handle| bind_groups.get(*handle).unwrap())
.collect::<Vec<_>>(),
push_constant_ranges: &[], })
})
}
pub fn resources(
&self,
) -> StaticResourcePoolReadLockAccessor<'_, GpuPipelineLayoutHandle, wgpu::PipelineLayout> {
self.pool.resources()
}
pub fn begin_frame(&mut self, frame_index: u64) {
self.pool.current_frame_index = frame_index;
}
pub fn num_resources(&self) -> usize {
self.pool.num_resources()
}
}