Refactor vk_swapchain
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s

This commit is contained in:
Florian RICHER 2024-11-13 13:56:22 +01:00
parent ee8b886aec
commit 96cb003174
3 changed files with 65 additions and 32 deletions

View file

@ -1,11 +1,11 @@
use crate::display::Window;
use crate::vulkan::{VkDevice, VkInstance, VkPhysicalDevice, VkSwapchain, LOG_TARGET};
use ash::prelude::VkResult;
use ash::vk;
use crate::display::Window;
pub struct VkSurface {
surface_loader: ash::khr::surface::Instance,
surface: vk::SurfaceKHR,
pub(super) surface: vk::SurfaceKHR,
}
impl VkSurface {
@ -68,7 +68,9 @@ impl VkSurface {
let surface_formats = self.get_physical_device_surface_formats(physical_device)?;
log::debug!(target: LOG_TARGET, "Supported surface formats by physical device: {surface_formats:#?}");
let surface_format = surface_formats.first()
let surface_format = surface_formats
.first()
.and_then(|f| Some(*f))
.ok_or_else(|| anyhow::anyhow!("No available surface formats"))?;
log::debug!(target: LOG_TARGET, "Selected surface format: {surface_format:?}");
@ -116,30 +118,18 @@ impl VkSurface {
.unwrap_or(vk::PresentModeKHR::FIFO);
let swapchain_loader = ash::khr::swapchain::Device::new(&instance.handle, &device.handle);
let swapchain_create_info = vk::SwapchainCreateInfoKHR::default()
.surface(self.surface)
.min_image_count(desired_image_count)
.image_color_space(surface_format.color_space)
.image_format(surface_format.format)
.image_extent(surface_resolution)
.image_usage(vk::ImageUsageFlags::COLOR_ATTACHMENT)
.image_sharing_mode(vk::SharingMode::EXCLUSIVE)
.pre_transform(pre_transform)
.composite_alpha(vk::CompositeAlphaFlagsKHR::OPAQUE)
.present_mode(present_mode)
.clipped(true)
.image_array_layers(1);
log::debug!(target: LOG_TARGET, "Swapchain info: {swapchain_create_info:#?}");
let swapchain = unsafe {
swapchain_loader.create_swapchain(&swapchain_create_info, None)?
};
log::debug!(target: LOG_TARGET, "Swapchain created");
Ok(VkSwapchain::new(
let mut swapchain = VkSwapchain::new(
swapchain_loader,
Some(swapchain)
))
desired_image_count,
surface_format,
surface_resolution,
present_mode,
pre_transform,
);
swapchain.create_swapchain(&self)?;
Ok(swapchain)
}
}