feat: switch away from parking_lot::Mutex

Switching away from `parking_lot::Mutex` as `std::sync::Mutex` performs
better in all scenarios on both of our targets (linux/windows).
This commit is contained in:
zack 2025-03-30 16:27:35 -04:00
parent 234e2ab78d
commit f71f0d8e10
No known key found for this signature in database
GPG key ID: EE8A2B709E2401D1
10 changed files with 66 additions and 38 deletions

View file

@ -13,7 +13,6 @@ gpu-allocator.workspace = true
egui.workspace = true
egui-ash-renderer.workspace = true
winit.workspace = true
parking_lot.workspace = true
gfx_hal = { path = "../gfx_hal" }
resource_manager = { path = "../resource_manager" }

View file

@ -1,12 +1,15 @@
use std::{ffi::CStr, sync::Arc};
use std::{
ffi::CStr,
sync::{Arc, Mutex},
};
use ash::vk;
use egui_ash_renderer::{DynamicRendering, Options, Renderer as EguiRenderer};
use gfx_hal::{
device::Device, error::GfxHalError, queue::Queue, surface::Surface, swapchain::Swapchain,
swapchain::SwapchainConfig, sync::Fence, sync::Semaphore,
};
use gpu_allocator::{vulkan::Allocator, MemoryLocation};
use parking_lot::Mutex;
use resource_manager::{ImageHandle, ResourceManager, ResourceManagerError};
use thiserror::Error;
use tracing::{debug, error, info, warn};
@ -79,6 +82,8 @@ pub struct Renderer {
swapchain_format: vk::SurfaceFormatKHR,
swapchain_extent: vk::Extent2D,
egui_renderer: EguiRenderer,
depth_image_handle: ImageHandle,
depth_image_view: vk::ImageView, // Store the view directly
depth_format: vk::Format,
@ -128,10 +133,21 @@ impl Renderer {
info!("Renderer initialized successfully.");
let egui_renderer = EguiRenderer::with_gpu_allocator(
resource_manager.allocator(),
device.raw().clone(),
DynamicRendering {
color_attachment_format: swapchain.format().format,
depth_attachment_format: Some(depth_format),
},
Options::default(),
)?;
Ok(Self {
device,
graphics_queue,
resource_manager,
egui_renderer,
allocator, // Store the allocator Arc
surface,
swapchain: Some(swapchain),
@ -465,6 +481,10 @@ impl Renderer {
self.depth_image_handle = new_depth_handle;
self.depth_image_view = new_depth_view;
// 4. Update Egui Renderer (if necessary, depends on its implementation)
// It might need the new extent or recreate internal resources.
// Assuming it handles extent changes via update_screen_descriptor called earlier.
info!(
"Swapchain recreated successfully ({}x{}).",
new_extent.width, new_extent.height