From 7ca29aed72c0a3ce707f21696bace0e449f51a1c Mon Sep 17 00:00:00 2001 From: Speedy_Lex Date: Wed, 8 Jan 2025 22:17:29 +0100 Subject: [PATCH] vulkan device is now stored as a ref --- examples/vulkan-buffer.rs | 2 +- src/vulkan/mod.rs | 26 +++++++++++++------------- src/vulkan/visualizer.rs | 10 +++++----- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/examples/vulkan-buffer.rs b/examples/vulkan-buffer.rs index dcf0b9c..46a6a58 100644 --- a/examples/vulkan-buffer.rs +++ b/examples/vulkan-buffer.rs @@ -85,7 +85,7 @@ fn main() { // Setting up the allocator let mut allocator = Allocator::new(&AllocatorCreateDesc { instance: instance.clone(), - device: device.clone(), + device: &device, physical_device: pdevice, debug_settings: Default::default(), buffer_device_address: false, diff --git a/src/vulkan/mod.rs b/src/vulkan/mod.rs index 1e6a472..1a3990a 100644 --- a/src/vulkan/mod.rs +++ b/src/vulkan/mod.rs @@ -52,9 +52,9 @@ unsafe impl Send for SendSyncPtr {} // `mapped_ptr` themselves. unsafe impl Sync for SendSyncPtr {} -pub struct AllocatorCreateDesc { +pub struct AllocatorCreateDesc<'a> { pub instance: ash::Instance, - pub device: ash::Device, + pub device: &'a ash::Device, pub physical_device: vk::PhysicalDevice, pub debug_settings: AllocatorDebugSettings, pub buffer_device_address: bool, @@ -674,23 +674,23 @@ impl MemoryType { } } -pub struct Allocator { +pub struct Allocator<'a> { pub(crate) memory_types: Vec, pub(crate) memory_heaps: Vec, - device: ash::Device, + device: &'a ash::Device, pub(crate) buffer_image_granularity: u64, pub(crate) debug_settings: AllocatorDebugSettings, allocation_sizes: AllocationSizes, } -impl fmt::Debug for Allocator { +impl fmt::Debug for Allocator<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.generate_report().fmt(f) } } -impl Allocator { - pub fn new(desc: &AllocatorCreateDesc) -> Result { +impl<'a> Allocator<'a> { + pub fn new(desc: &AllocatorCreateDesc<'a>) -> Result { if desc.physical_device == vk::PhysicalDevice::null() { return Err(AllocationError::InvalidAllocatorCreateDesc( "AllocatorCreateDesc field `physical_device` is null.".into(), @@ -754,7 +754,7 @@ impl Allocator { Ok(Self { memory_types, memory_heaps, - device: desc.device.clone(), + device: desc.device, buffer_image_granularity: granularity, debug_settings: desc.debug_settings, allocation_sizes: desc.allocation_sizes, @@ -827,7 +827,7 @@ impl Allocator { Err(AllocationError::OutOfMemory) } else { memory_type.allocate( - &self.device, + self.device, desc, self.buffer_image_granularity, backtrace.clone(), @@ -849,7 +849,7 @@ impl Allocator { }; self.memory_types[memory_type_index].allocate( - &self.device, + self.device, desc, self.buffer_image_granularity, backtrace, @@ -877,7 +877,7 @@ impl Allocator { return Ok(()); } - self.memory_types[allocation.memory_type_index].free(allocation, &self.device)?; + self.memory_types[allocation.memory_type_index].free(allocation, self.device)?; Ok(()) } @@ -955,7 +955,7 @@ impl Allocator { } } -impl Drop for Allocator { +impl Drop for Allocator<'_> { fn drop(&mut self) { if self.debug_settings.log_leaks_on_shutdown { self.report_memory_leaks(Level::Warn); @@ -966,7 +966,7 @@ impl Drop for Allocator { for mem_block in mem_type.memory_blocks.iter_mut() { let block = mem_block.take(); if let Some(block) = block { - block.destroy(&self.device); + block.destroy(self.device); } } } diff --git a/src/vulkan/visualizer.rs b/src/vulkan/visualizer.rs index ab400db..6b26a2e 100644 --- a/src/vulkan/visualizer.rs +++ b/src/vulkan/visualizer.rs @@ -40,7 +40,7 @@ impl AllocatorVisualizer { self.color_scheme = color_scheme; } - pub fn render_memory_block_ui(&mut self, ui: &mut egui::Ui, alloc: &Allocator) { + pub fn render_memory_block_ui(&mut self, ui: &mut egui::Ui, alloc: &Allocator<'_>) { ui.label(format!( "buffer image granularity: {:?}", alloc.buffer_image_granularity @@ -145,7 +145,7 @@ impl AllocatorVisualizer { pub fn render_memory_block_window( &mut self, ctx: &egui::Context, - allocator: &Allocator, + allocator: &Allocator<'_>, open: &mut bool, ) { egui::Window::new("Allocator Memory Blocks") @@ -156,7 +156,7 @@ impl AllocatorVisualizer { pub fn render_memory_block_visualization_windows( &mut self, ctx: &egui::Context, - allocator: &Allocator, + allocator: &Allocator<'_>, ) { // Draw each window. let color_scheme = &self.color_scheme; @@ -200,7 +200,7 @@ impl AllocatorVisualizer { }); } - pub fn render_breakdown_ui(&mut self, ui: &mut egui::Ui, allocator: &Allocator) { + pub fn render_breakdown_ui(&mut self, ui: &mut egui::Ui, allocator: &Allocator<'_>) { render_allocation_reports_ui( ui, &mut self.breakdown_settings, @@ -216,7 +216,7 @@ impl AllocatorVisualizer { pub fn render_breakdown_window( &mut self, ctx: &egui::Context, - allocator: &Allocator, + allocator: &Allocator<'_>, open: &mut bool, ) { egui::Window::new("Allocator Breakdown")