Skip to content

Commit

Permalink
Layout cache key type
Browse files Browse the repository at this point in the history
  • Loading branch information
MDeiml committed Oct 13, 2022
1 parent d680b34 commit edd3247
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions crates/bevy_render/src/render_resource/pipeline_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use bevy_ecs::{event::EventReader, system::Resource};
use bevy_utils::{
default,
tracing::{debug, error},
Entry, HashMap, HashSet,
Entry, HashMap, HashSet, Hashed, PreHashMap,
};
use std::{hash::Hash, iter::FusedIterator, mem, ops::Deref, sync::Arc};
use thiserror::Error;
Expand Down Expand Up @@ -271,9 +271,11 @@ impl ShaderCache {
}
}

type LayoutKey = (Vec<BindGroupLayoutId>, Vec<PushConstantRange>);

#[derive(Default)]
struct LayoutCache {
layouts: HashMap<(Vec<BindGroupLayoutId>, Vec<PushConstantRange>), wgpu::PipelineLayout>,
layouts: PreHashMap<LayoutKey, wgpu::PipelineLayout>,
}

impl LayoutCache {
Expand All @@ -286,7 +288,7 @@ impl LayoutCache {
let bind_group_ids = bind_group_layouts.iter().map(|l| l.id()).collect();
let push_constant_ranges = push_constant_ranges.to_vec();
self.layouts
.entry((bind_group_ids, push_constant_ranges))
.entry(Hashed::new((bind_group_ids, push_constant_ranges)))
.or_insert_with_key(|key| {
let bind_group_layouts = bind_group_layouts
.iter()
Expand Down

0 comments on commit edd3247

Please sign in to comment.