diff --git a/src/driver/render_pass.rs b/src/driver/render_pass.rs index 87ed248..6e7fa85 100644 --- a/src/driver/render_pass.rs +++ b/src/driver/render_pass.rs @@ -4,7 +4,6 @@ use { }, ash::vk, log::{trace, warn}, - parking_lot::Mutex, std::{ collections::{hash_map::Entry, HashMap}, ops::Deref, @@ -109,8 +108,8 @@ pub struct RenderPassInfo { #[derive(Debug)] pub struct RenderPass { device: Arc, - framebuffer_cache: Mutex>, - graphic_pipeline_cache: Mutex>, + framebuffers: HashMap, + graphic_pipelines: HashMap, pub info: RenderPassInfo, render_pass: vk::RenderPass, } @@ -240,18 +239,20 @@ impl RenderPass { Ok(Self { info, device, - framebuffer_cache: Mutex::new(Default::default()), - graphic_pipeline_cache: Mutex::new(Default::default()), + framebuffers: Default::default(), + graphic_pipelines: Default::default(), render_pass, }) } #[profiling::function] - pub fn framebuffer(this: &Self, info: FramebufferInfo) -> Result { + pub fn framebuffer( + this: &mut Self, + info: FramebufferInfo, + ) -> Result { debug_assert!(!info.attachments.is_empty()); - let mut cache = this.framebuffer_cache.lock(); - let entry = cache.entry(info); + let entry = this.framebuffers.entry(info); if let Entry::Occupied(entry) = entry { return Ok(*entry.get()); } @@ -310,15 +311,14 @@ impl RenderPass { #[profiling::function] pub fn graphic_pipeline( - this: &Self, + this: &mut Self, pipeline: &Arc, depth_stencil: Option, subpass_idx: u32, ) -> Result { use std::slice::from_ref; - let mut cache = this.graphic_pipeline_cache.lock(); - let entry = cache.entry(GraphicPipelineKey { + let entry = this.graphic_pipelines.entry(GraphicPipelineKey { depth_stencil, layout: pipeline.layout, shader_modules: pipeline.shader_modules.clone(), @@ -450,11 +450,11 @@ impl Drop for RenderPass { } unsafe { - for framebuffer in self.framebuffer_cache.lock().values().copied() { + for (_, framebuffer) in self.framebuffers.drain() { self.device.destroy_framebuffer(framebuffer, None); } - for pipeline in self.graphic_pipeline_cache.lock().values().copied() { + for (_, pipeline) in self.graphic_pipelines.drain() { self.device.destroy_pipeline(pipeline, None); } diff --git a/src/graph/resolver.rs b/src/graph/resolver.rs index fe1bd24..7fce50d 100644 --- a/src/graph/resolver.rs +++ b/src/graph/resolver.rs @@ -390,12 +390,12 @@ impl Resolver { cmd_buf: &CommandBuffer, bindings: &[Binding], pass: &Pass, - physical_pass: &PhysicalPass, + physical_pass: &mut PhysicalPass, render_area: Area, ) -> Result<(), DriverError> { trace!(" begin render pass"); - let render_pass = physical_pass.render_pass.as_ref().unwrap(); + let render_pass = physical_pass.render_pass.as_mut().unwrap(); let attachment_count = render_pass.info.attachments.len(); let mut attachments = Vec::with_capacity(attachment_count); @@ -682,7 +682,7 @@ impl Resolver { #[profiling::function] fn bind_pipeline( cmd_buf: &mut CommandBuffer, - physical_pass: &PhysicalPass, + physical_pass: &mut PhysicalPass, exec_idx: usize, pipeline: &mut ExecutionPipeline, depth_stencil: Option, @@ -711,7 +711,7 @@ impl Resolver { let pipeline = match pipeline { ExecutionPipeline::Compute(pipeline) => ***pipeline, ExecutionPipeline::Graphic(pipeline) => RenderPass::graphic_pipeline( - physical_pass.render_pass.as_ref().unwrap(), + physical_pass.render_pass.as_mut().unwrap(), pipeline, depth_stencil, exec_idx as _, @@ -2244,7 +2244,7 @@ impl Resolver { profiling::scope!("Pass", &pass.name); - let physical_pass = &self.physical_passes[pass_idx]; + let physical_pass = &mut self.physical_passes[pass_idx]; let is_graphic = physical_pass.render_pass.is_some(); trace!("recording pass [{}: {}]", pass_idx, pass.name);