simple_wgpu/
pipeline_layout.rs1use crate::{bind_group::BindGroupLayout, context::Context};
2
3#[derive(Clone, Hash, PartialEq, Eq)]
4pub(crate) struct PipelineLayout {
5 pub(crate) bind_group_layouts: Vec<BindGroupLayout>,
6}
7
8impl PipelineLayout {
9 pub fn get_or_build(&self, context: &Context) -> wgpu::PipelineLayout {
10 let mut pipeline_layout_cache: std::cell::RefMut<
11 '_,
12 crate::keyed_cache::KeyedCache<PipelineLayout, wgpu::PipelineLayout>,
13 > = context.caches.pipeline_layout_cache.borrow_mut();
14
15 pipeline_layout_cache
16 .get_or_insert_with(self.clone(), || {
17 let bind_group_layouts = self
18 .bind_group_layouts
19 .iter()
20 .map(|layout| layout.get_or_build(context))
21 .collect::<Vec<_>>();
22 let bind_group_layout_refs = bind_group_layouts
23 .iter()
24 .map(|layout| layout)
25 .collect::<Vec<_>>();
26
27 context
28 .device()
29 .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
30 label: None,
31 bind_group_layouts: &bind_group_layout_refs,
32 push_constant_ranges: &[],
33 })
34 })
35 .clone()
36 }
37}