Skip to content

Commit

Permalink
Code clean-up: remove render pass mutexes
Browse files Browse the repository at this point in the history
  • Loading branch information
attackgoat committed Feb 19, 2024
1 parent 1fe8fbe commit 0e52baa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
26 changes: 13 additions & 13 deletions src/driver/render_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use {
},
ash::vk,
log::{trace, warn},
parking_lot::Mutex,
std::{
collections::{hash_map::Entry, HashMap},
ops::Deref,
Expand Down Expand Up @@ -109,8 +108,8 @@ pub struct RenderPassInfo {
#[derive(Debug)]
pub struct RenderPass {
device: Arc<Device>,
framebuffer_cache: Mutex<HashMap<FramebufferInfo, vk::Framebuffer>>,
graphic_pipeline_cache: Mutex<HashMap<GraphicPipelineKey, vk::Pipeline>>,
framebuffers: HashMap<FramebufferInfo, vk::Framebuffer>,
graphic_pipelines: HashMap<GraphicPipelineKey, vk::Pipeline>,
pub info: RenderPassInfo,
render_pass: vk::RenderPass,
}
Expand Down Expand Up @@ -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<vk::Framebuffer, DriverError> {
pub fn framebuffer(
this: &mut Self,
info: FramebufferInfo,
) -> Result<vk::Framebuffer, DriverError> {
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());
}
Expand Down Expand Up @@ -310,15 +311,14 @@ impl RenderPass {

#[profiling::function]
pub fn graphic_pipeline(
this: &Self,
this: &mut Self,
pipeline: &Arc<GraphicPipeline>,
depth_stencil: Option<DepthStencilMode>,
subpass_idx: u32,
) -> Result<vk::Pipeline, DriverError> {
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(),
Expand Down Expand Up @@ -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);
}

Expand Down
10 changes: 5 additions & 5 deletions src/graph/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<DepthStencilMode>,
Expand Down Expand Up @@ -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 _,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0e52baa

Please sign in to comment.