From 001547dbc2d1ab10d484a9ff1e3c2477a9a2868d Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Wed, 27 Nov 2024 20:48:34 +0100 Subject: [PATCH] vulkan: Rename name mistake to handle --- src/vulkan/vk_graphics_pipeline.rs | 4 ++-- src/vulkan/vk_render_context.rs | 2 +- src/vulkan/vk_shader_module.rs | 4 ++-- src/vulkan/vk_surface.rs | 16 ++++++++-------- src/vulkan/vk_swapchain.rs | 18 +++++++++--------- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/vulkan/vk_graphics_pipeline.rs b/src/vulkan/vk_graphics_pipeline.rs index 9e7d0ed..11335ab 100644 --- a/src/vulkan/vk_graphics_pipeline.rs +++ b/src/vulkan/vk_graphics_pipeline.rs @@ -22,7 +22,7 @@ impl VkGraphicsPipeline { let shader_entry_name = CStr::from_bytes_with_nul(b"main\0")?; let vert_shader_module = - VkShaderModule::from_spv_file(device.clone(), "res/shaders/main.vert.spv")?; + VkShaderModule::from_spv_file(device, "res/shaders/main.vert.spv")?; let vert_shader_info = vk::PipelineShaderStageCreateInfo::default() .module(vert_shader_module.handle) @@ -30,7 +30,7 @@ impl VkGraphicsPipeline { .stage(vk::ShaderStageFlags::VERTEX); let frag_shader_module = - VkShaderModule::from_spv_file(device.clone(), "res/shaders/main.frag.spv")?; + VkShaderModule::from_spv_file(device, "res/shaders/main.frag.spv")?; let frag_shader_info = vk::PipelineShaderStageCreateInfo::default() .module(frag_shader_module.handle) diff --git a/src/vulkan/vk_render_context.rs b/src/vulkan/vk_render_context.rs index e4a22f5..0fc7d8c 100644 --- a/src/vulkan/vk_render_context.rs +++ b/src/vulkan/vk_render_context.rs @@ -187,7 +187,7 @@ impl VkRenderContext { .queue_submit(*queue, &[submit_info], self.in_flight_fence.handle)? }; - let swapchains = [self.swapchain.swapchain.unwrap()]; + let swapchains = [self.swapchain.handle.unwrap()]; let indices = [index]; let present_info = vk::PresentInfoKHR::default() .wait_semaphores(&signal_semaphores) diff --git a/src/vulkan/vk_shader_module.rs b/src/vulkan/vk_shader_module.rs index 02f934b..0ed5f5b 100644 --- a/src/vulkan/vk_shader_module.rs +++ b/src/vulkan/vk_shader_module.rs @@ -10,7 +10,7 @@ pub struct VkShaderModule { } impl VkShaderModule { - pub fn from_spv_file>(device: Arc, path: P) -> anyhow::Result { + pub fn from_spv_file>(device: &Arc, path: P) -> anyhow::Result { let mut file = std::fs::File::open(&path)?; let frag_shader_str = ash::util::read_spv(&mut file)?; @@ -26,7 +26,7 @@ impl VkShaderModule { ); Ok(Self { - device, + device: device.clone(), handle: shader_module, }) } diff --git a/src/vulkan/vk_surface.rs b/src/vulkan/vk_surface.rs index 4a5a9bc..a1d35da 100644 --- a/src/vulkan/vk_surface.rs +++ b/src/vulkan/vk_surface.rs @@ -13,7 +13,7 @@ pub struct SwapchainSupportDetails( pub struct VkSurface { instance: Arc, - pub(super) surface: vk::SurfaceKHR, + pub(super) handle: vk::SurfaceKHR, } impl VkSurface { @@ -34,7 +34,7 @@ impl VkSurface { log::debug!("Surface created ({:?})", surface); - Ok(Self { instance, surface }) + Ok(Self { instance, handle: surface }) } pub fn physical_device_queue_supported( @@ -48,7 +48,7 @@ impl VkSurface { .get_physical_device_surface_support( physical_device.handle, queue_index, - self.surface, + self.handle, ) } } @@ -61,17 +61,17 @@ impl VkSurface { let formats = self .instance .surface_loader - .get_physical_device_surface_formats(physical_device.handle, self.surface)?; + .get_physical_device_surface_formats(physical_device.handle, self.handle)?; let capabilities = self .instance .surface_loader - .get_physical_device_surface_capabilities(physical_device.handle, self.surface)?; + .get_physical_device_surface_capabilities(physical_device.handle, self.handle)?; let present_modes = self .instance .surface_loader - .get_physical_device_surface_present_modes(physical_device.handle, self.surface)?; + .get_physical_device_surface_present_modes(physical_device.handle, self.handle)?; Ok(SwapchainSupportDetails( formats, @@ -87,8 +87,8 @@ impl Drop for VkSurface { unsafe { self.instance .surface_loader - .destroy_surface(self.surface, None); + .destroy_surface(self.handle, None); } - log::debug!("Surface destroyed ({:?})", self.surface); + log::debug!("Surface destroyed ({:?})", self.handle); } } diff --git a/src/vulkan/vk_swapchain.rs b/src/vulkan/vk_swapchain.rs index b60f1ed..3241b35 100644 --- a/src/vulkan/vk_swapchain.rs +++ b/src/vulkan/vk_swapchain.rs @@ -11,7 +11,7 @@ pub struct VkSwapchain { surface: Arc, device: Arc, - pub(super) swapchain: Option, + pub(super) handle: Option, swapchain_support_details: SwapchainSupportDetails, pub(super) desired_image_count: u32, @@ -64,7 +64,7 @@ impl VkSwapchain { surface: surface.clone(), device: device.clone(), - swapchain: None, + handle: None, new_requested_surface_resolution: None, swapchain_support_details, desired_image_count, @@ -89,7 +89,7 @@ impl VkSwapchain { let mut swapchain_create_info = self.create_swapchain_info(&self.surface); - if let Some(old_swapchain) = self.swapchain { + if let Some(old_swapchain) = self.handle { swapchain_create_info.old_swapchain = old_swapchain; } @@ -114,14 +114,14 @@ impl VkSwapchain { .collect::>(); if log::log_enabled!(log::Level::Debug) { - let label = match self.swapchain { + let label = match self.handle { None => "Swapchain created", Some(_) => "Swapchain updated", }; log::debug!("{label} ({swapchain:?}) : {swapchain_create_info:#?}"); } - self.swapchain = Some(swapchain); + self.handle = Some(swapchain); self.present_image_views = Some(present_images_view); self.present_images = Some(present_images); @@ -177,7 +177,7 @@ impl VkSwapchain { pub(super) fn acquire_next_image(&self, semaphore: &VkSemaphore) -> VkResult<(u32, bool)> { unsafe { self.device.swapchain_loader.acquire_next_image( - self.swapchain.unwrap(), + self.handle.unwrap(), u64::MAX, semaphore.handle, vk::Fence::null(), @@ -191,7 +191,7 @@ impl VkSwapchain { fn create_swapchain_info(&self, surface: &VkSurface) -> vk::SwapchainCreateInfoKHR { vk::SwapchainCreateInfoKHR::default() - .surface(surface.surface) + .surface(surface.handle) .min_image_count(self.desired_image_count) .image_color_space(self.surface_format.color_space) .image_format(self.surface_format.format) @@ -287,13 +287,13 @@ impl VkSwapchain { impl Drop for VkSwapchain { fn drop(&mut self) { - if let Some(swapchain) = self.swapchain { + if let Some(swapchain) = self.handle { unsafe { self.device .swapchain_loader .destroy_swapchain(swapchain, None); } - self.swapchain = None; + self.handle = None; log::debug!("Swapchain destroyed ({swapchain:?})"); } }