fix: all clippy errors

This commit is contained in:
zack 2025-04-03 17:33:35 -04:00
parent 926515e6b2
commit 2501390225
No known key found for this signature in database
GPG key ID: EE8A2B709E2401D1
5 changed files with 30 additions and 67 deletions

View file

@ -568,7 +568,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.with_ansi(true) .with_ansi(true)
.with_file(false) .with_file(false)
.with_line_number(false) .with_line_number(false)
.with_filter(filter::LevelFilter::INFO); .with_filter(filter::LevelFilter::DEBUG);
let registry = tracing_subscriber::registry().with(fmt_layer); let registry = tracing_subscriber::registry().with(fmt_layer);

View file

@ -15,7 +15,7 @@ use crate::queue::Queue;
/// ///
/// Owns the `ash::Device` and provides access to device functions and queues. /// Owns the `ash::Device` and provides access to device functions and queues.
pub struct Device { pub struct Device {
instance: Arc<Instance>, _instance: Arc<Instance>,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
device: ash::Device, device: ash::Device,
queues: Mutex<HashMap<(u32, u32), Arc<Queue>>>, queues: Mutex<HashMap<(u32, u32), Arc<Queue>>>,
@ -33,6 +33,7 @@ impl Device {
/// - `queue_family_indicies` must be valid indicies obtained from the `physical_device_handle`. /// - `queue_family_indicies` must be valid indicies obtained from the `physical_device_handle`.
/// - `required_extensions` must be supported by the `physical_device_handle`. /// - `required_extensions` must be supported by the `physical_device_handle`.
/// - All feature structs passed must be supported by the `physical_device_handle`. /// - All feature structs passed must be supported by the `physical_device_handle`.
#[allow(clippy::too_many_arguments)]
pub(crate) unsafe fn new( pub(crate) unsafe fn new(
instance: Arc<Instance>, instance: Arc<Instance>,
physical_device_handle: vk::PhysicalDevice, physical_device_handle: vk::PhysicalDevice,
@ -113,7 +114,7 @@ impl Device {
// --- 4. Create the Device struct in an Arc (Stage 1) --- // --- 4. Create the Device struct in an Arc (Stage 1) ---
// Initialize the queues map as empty for now. // Initialize the queues map as empty for now.
let device_arc = Arc::new(Device { let device_arc = Arc::new(Device {
instance: instance.clone(), _instance: instance.clone(),
physical_device: physical_device_handle, physical_device: physical_device_handle,
device: ash_device, // Move the created ash::Device here device: ash_device, // Move the created ash::Device here
queues: Mutex::new(HashMap::new()), // Start with empty map queues: Mutex::new(HashMap::new()), // Start with empty map

View file

@ -1,5 +1,5 @@
use std::{ use std::{
ffi::{c_void, CStr}, ffi::c_void,
mem, mem,
sync::{Arc, Mutex}, sync::{Arc, Mutex},
time::Instant, time::Instant,
@ -127,6 +127,7 @@ pub struct Renderer {
} }
impl Renderer { impl Renderer {
#[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
instance: Arc<gfx_hal::instance::Instance>, // Needed for allocator instance: Arc<gfx_hal::instance::Instance>, // Needed for allocator
device: Arc<Device>, device: Arc<Device>,
@ -510,12 +511,6 @@ impl Renderer {
.command_buffers(&command_buffers) .command_buffers(&command_buffers)
.signal_semaphores(&signal_semaphores); .signal_semaphores(&signal_semaphores);
// assert_eq!(
// self.graphics_queue.device().raw().handle(), // Device from Queue
// self.device.raw().handle(), // Device stored in Renderer
// "Device handle mismatch between Renderer and Graphics Queue!"
// );
unsafe { unsafe {
// Need unsafe for queue submit // Need unsafe for queue submit
self.graphics_queue.submit( self.graphics_queue.submit(
@ -593,10 +588,6 @@ impl Renderer {
self.depth_image_handle = new_depth_handle; self.depth_image_handle = new_depth_handle;
self.depth_image_view = new_depth_view; 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!( info!(
"Swapchain recreated successfully ({}x{}).", "Swapchain recreated successfully ({}x{}).",
new_extent.width, new_extent.height new_extent.width, new_extent.height
@ -607,7 +598,7 @@ impl Renderer {
// --- Helper: Cleanup Swapchain Dependent Resources --- // --- Helper: Cleanup Swapchain Dependent Resources ---
fn cleanup_swapchain_resources(&mut self) { fn cleanup_swapchain_resources(&mut self) {
debug!("Cleaning up swapchain resources..."); debug!("Cleaning up swapchain resources...");
// Destroy depth buffer view
unsafe { unsafe {
self.device self.device
.raw() .raw()
@ -616,9 +607,8 @@ impl Renderer {
// Destroy depth buffer image via resource manager // Destroy depth buffer image via resource manager
if let Err(e) = self.resource_manager.destroy_image(self.depth_image_handle) { if let Err(e) = self.resource_manager.destroy_image(self.depth_image_handle) {
error!("Failed to destroy depth image: {}", e); error!("Failed to destroy depth image: {}", e);
// Continue cleanup even if this fails
} }
// Drop the old swapchain object (RAII in gfx_hal::Swapchain handles vkDestroySwapchainKHR)
self.swapchain = None; self.swapchain = None;
debug!("Swapchain resources cleaned up."); debug!("Swapchain resources cleaned up.");
} }
@ -665,38 +655,10 @@ impl Renderer {
let swapchain = let swapchain =
unsafe { Swapchain::new(device.clone(), surface.clone(), config, old_swapchain)? }; unsafe { Swapchain::new(device.clone(), surface.clone(), config, old_swapchain)? };
// Create Image Views
let image_views = swapchain let image_views = swapchain
.image_views() // Assuming Swapchain::new creates and stores these .image_views() // Assuming Swapchain::new creates and stores these
.to_vec(); // Clone the slice into a Vec .to_vec(); // Clone the slice into a Vec
// If Swapchain::new doesn't create views, we need to do it here:
/*
let images = swapchain.images()?; // Assuming this method exists
let mut image_views = Vec::with_capacity(images.len());
for &image in images.iter() {
let create_info = vk::ImageViewCreateInfo::default()
.image(image)
.view_type(vk::ImageViewType::TYPE_2D)
.format(surface_format.format)
.components(vk::ComponentMapping {
r: vk::ComponentSwizzle::IDENTITY,
g: vk::ComponentSwizzle::IDENTITY,
b: vk::ComponentSwizzle::IDENTITY,
a: vk::ComponentSwizzle::IDENTITY,
})
.subresource_range(vk::ImageSubresourceRange {
aspect_mask: vk::ImageAspectFlags::COLOR,
base_mip_level: 0,
level_count: 1,
base_array_layer: 0,
layer_count: 1,
});
let view = unsafe { device.raw().create_image_view(&create_info, None)? };
image_views.push(view);
}
*/
Ok((swapchain, surface_format, extent, image_views)) Ok((swapchain, surface_format, extent, image_views))
} }
@ -763,7 +725,7 @@ impl Renderer {
let vert_module = Self::create_shader_module(device, vert_shader_code)?; let vert_module = Self::create_shader_module(device, vert_shader_code)?;
let frag_module = Self::create_shader_module(device, frag_shader_code)?; let frag_module = Self::create_shader_module(device, frag_shader_code)?;
let main_function_name = CStr::from_bytes_with_nul(b"main\0").unwrap(); let main_function_name = c"main";
let vert_stage_info = vk::PipelineShaderStageCreateInfo::default() let vert_stage_info = vk::PipelineShaderStageCreateInfo::default()
.stage(vk::ShaderStageFlags::VERTEX) .stage(vk::ShaderStageFlags::VERTEX)
@ -911,7 +873,7 @@ impl Renderer {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// 3. Create the shader module // 3. Create the shader module
let create_info = vk::ShaderModuleCreateInfo::default().code(&code_slice_ref); // Pass the &[u32] slice let create_info = vk::ShaderModuleCreateInfo::default().code(code_slice_ref); // Pass the &[u32] slice
unsafe { unsafe {
device device
@ -1026,7 +988,7 @@ impl Renderer {
fn choose_swapchain_present_mode(available_modes: &[vk::PresentModeKHR]) -> vk::PresentModeKHR { fn choose_swapchain_present_mode(available_modes: &[vk::PresentModeKHR]) -> vk::PresentModeKHR {
*available_modes *available_modes
.iter() .iter()
.find(|&&mode| mode == vk::PresentModeKHR::MAILBOX) // Prefer Mailbox (low latency) .find(|&&mode| mode == vk::PresentModeKHR::FIFO) // Prefer Mailbox (low latency)
.unwrap_or(&vk::PresentModeKHR::FIFO) .unwrap_or(&vk::PresentModeKHR::FIFO)
} }
@ -1078,7 +1040,7 @@ impl Renderer {
} }
Err(RendererError::Vulkan( Err(RendererError::Vulkan(
vk::Result::ERROR_FORMAT_NOT_SUPPORTED, vk::Result::ERROR_FORMAT_NOT_SUPPORTED,
)) // Or custom error ))
} }
fn create_descriptor_sets_resources( fn create_descriptor_sets_resources(

View file

@ -1,6 +1,6 @@
use std::sync::Arc; use std::sync::Arc;
use ash::vk::{self, IndexType}; use ash::vk;
use gpu_allocator::MemoryLocation; use gpu_allocator::MemoryLocation;
use tracing::{debug, trace}; use tracing::{debug, trace};

View file

@ -57,7 +57,6 @@ struct InternalBufferInfo {
allocation: Option<Allocation>, // Option because it's taken in Drop allocation: Option<Allocation>, // Option because it's taken in Drop
size: vk::DeviceSize, size: vk::DeviceSize,
usage: vk::BufferUsageFlags, usage: vk::BufferUsageFlags,
mapped_ptr: Option<*mut u8>,
handle: BufferHandle, handle: BufferHandle,
} }
@ -135,8 +134,8 @@ pub struct ResourceManager {
_instance: Arc<Instance>, _instance: Arc<Instance>,
device: Arc<Device>, device: Arc<Device>,
allocator: Arc<Mutex<Allocator>>, allocator: Arc<Mutex<Allocator>>,
buffers: Mutex<HashMap<u64, InternalBufferInfo>>, buffers: Arc<Mutex<HashMap<u64, InternalBufferInfo>>>,
images: Mutex<HashMap<u64, InternalImageInfo>>, images: Arc<Mutex<HashMap<u64, InternalImageInfo>>>,
next_id: AtomicU64, next_id: AtomicU64,
transfer_setup: Arc<Mutex<TransferSetup>>, transfer_setup: Arc<Mutex<TransferSetup>>,
} }
@ -181,8 +180,8 @@ impl ResourceManager {
_instance: instance, _instance: instance,
device, device,
allocator: Arc::new(Mutex::new(allocator)), allocator: Arc::new(Mutex::new(allocator)),
buffers: Mutex::new(HashMap::new()), buffers: Arc::new(Mutex::new(HashMap::new())),
images: Mutex::new(HashMap::new()), images: Arc::new(Mutex::new(HashMap::new())),
next_id: AtomicU64::new(1), next_id: AtomicU64::new(1),
transfer_setup: Arc::new(Mutex::new(new_setup)), transfer_setup: Arc::new(Mutex::new(new_setup)),
}) })
@ -289,11 +288,6 @@ impl ResourceManager {
} }
trace!("Buffer memory bound."); trace!("Buffer memory bound.");
let mapped_ptr = allocation.mapped_ptr().map(|p| p.as_ptr() as *mut u8);
if mapped_ptr.is_some() {
trace!("Buffer memory is mapped.");
}
let id = self.next_id.fetch_add(1, Ordering::Relaxed); let id = self.next_id.fetch_add(1, Ordering::Relaxed);
let handle = BufferHandle(id); let handle = BufferHandle(id);
@ -304,7 +298,6 @@ impl ResourceManager {
allocation: Some(allocation), allocation: Some(allocation),
size, size,
usage, usage,
mapped_ptr,
handle, handle,
}; };
@ -503,12 +496,19 @@ impl ResourceManager {
let buffers_map = self.buffers.lock()?; let buffers_map = self.buffers.lock()?;
buffers_map buffers_map
.get(&handle.0) .get(&handle.0)
.map(|internal| BufferInfo { .map(|internal| {
handle: internal.handle, let mapped_ptr = internal
buffer: internal.buffer, .allocation
size: internal.size, .as_ref()
usage: internal.usage, .and_then(|a| a.mapped_ptr().map(|p| p.as_ptr() as *mut u8));
mapped_ptr: internal.mapped_ptr,
BufferInfo {
handle: internal.handle,
buffer: internal.buffer,
size: internal.size,
usage: internal.usage,
mapped_ptr,
}
}) })
.ok_or(ResourceManagerError::HandleNotFound(handle.0)) .ok_or(ResourceManagerError::HandleNotFound(handle.0))
} }