Run cargo fmt
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s

This commit is contained in:
Florian RICHER 2024-11-16 22:45:22 +01:00
parent bc94b68c0c
commit e9ce480f96
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
10 changed files with 175 additions and 136 deletions

View file

@ -1,8 +1,8 @@
use std::sync::Arc;
use crate::display::Window;
use crate::vulkan::{VkDevice, VkPhysicalDevice, VkSurface, LOG_TARGET};
use ash::prelude::VkResult;
use ash::vk;
use crate::display::Window;
use std::sync::Arc;
pub struct VkSwapchain {
surface: Arc<VkSurface>,
@ -28,11 +28,8 @@ impl VkSwapchain {
) -> anyhow::Result<Self> {
log::debug!(target: LOG_TARGET, "Creating swapchain");
let (
surface_formats,
surface_capabilities,
present_modes
) = surface.get_physical_device_surface_infos(physical_device)?;
let (surface_formats, surface_capabilities, present_modes) =
surface.get_physical_device_surface_infos(physical_device)?;
log::debug!(target: LOG_TARGET, "Supported surface formats by physical device: {surface_formats:#?}");
log::debug!(target: LOG_TARGET, "Surface capabilities: {surface_capabilities:#?}");
@ -50,7 +47,8 @@ impl VkSwapchain {
}
log::debug!(target: LOG_TARGET, "Selected surface image count: {desired_image_count}");
let window_size = window.size()
let window_size = window
.size()
.ok_or_else(|| anyhow::anyhow!("Window size is not valid"))?
.to_physical::<u32>(1.0);
log::debug!(target: LOG_TARGET, "Window size: {window_size:?}");
@ -105,14 +103,21 @@ impl VkSwapchain {
}
let swapchain = unsafe {
self.device.swapchain_loader.create_swapchain(&swapchain_create_info, None)?
self.device
.swapchain_loader
.create_swapchain(&swapchain_create_info, None)?
};
let present_images = unsafe { self.device.swapchain_loader.get_swapchain_images(swapchain)? };
let present_images = unsafe {
self.device
.swapchain_loader
.get_swapchain_images(swapchain)?
};
let present_images_view = present_images
.iter()
.map(|i| {
self.device.create_image_view(*i, self.surface_format)
self.device
.create_image_view(*i, self.surface_format)
.expect("Failed to create image view")
})
.collect::<Vec<_>>();
@ -120,7 +125,7 @@ impl VkSwapchain {
if log::log_enabled!(target: LOG_TARGET, log::Level::Debug) {
let label = match self.swapchain {
None => "Swapchain created",
Some(_) => "Swapchain updated"
Some(_) => "Swapchain updated",
};
log::debug!(target: LOG_TARGET, "{label} ({swapchain:?}) : {swapchain_create_info:#?}");
}
@ -134,10 +139,7 @@ impl VkSwapchain {
pub(super) fn update_resolution(&mut self, width: u32, height: u32) -> VkResult<()> {
log::debug!(target: LOG_TARGET, "New resolution requested for swapchain {width}x{height}");
self.surface_resolution = vk::Extent2D {
width,
height,
};
self.surface_resolution = vk::Extent2D { width, height };
self.create_swapchain()?;
@ -164,9 +166,13 @@ impl VkSwapchain {
impl Drop for VkSwapchain {
fn drop(&mut self) {
if let Some(swapchain) = self.swapchain {
unsafe { self.device.swapchain_loader.destroy_swapchain(swapchain, None); }
unsafe {
self.device
.swapchain_loader
.destroy_swapchain(swapchain, None);
}
self.swapchain = None;
log::debug!(target: LOG_TARGET, "Swapchain destroyed ({swapchain:?})");
}
}
}
}