Refactor Vulkan device and instance handling
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s

Refactor Vulkan initialization to merge logical and physical device management into a unified `VkDevice` struct. Improved logging for Vulkan instance creation and surface management. Added methods to `VkPhysicalDevice` and `VkSurface` for more detailed querying of physical device capabilities.
This commit is contained in:
Florian RICHER 2024-11-11 12:09:52 +01:00
parent b91571e777
commit d0c6f31a1a
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
9 changed files with 233 additions and 59 deletions

View file

@ -1,22 +1,23 @@
use ash::prelude::VkResult;
use ash::vk;
use crate::vulkan::VkPhysicalDevice;
pub struct VkSurface {
surface_loader: ash::khr::surface::Instance,
surface: ash::vk::SurfaceKHR,
surface: vk::SurfaceKHR,
}
impl VkSurface {
pub fn new(
surface_loader: ash::khr::surface::Instance,
surface: ash::vk::SurfaceKHR,
surface: vk::SurfaceKHR,
) -> Self {
Self {
surface_loader,
surface
}
}
pub fn physical_device_queue_supported(&self, physical_device: &VkPhysicalDevice, queue_index: u32) -> VkResult<bool> {
unsafe {
self.surface_loader.get_physical_device_surface_support(
@ -26,4 +27,40 @@ impl VkSurface {
)
}
}
pub fn get_physical_device_surface_formats(&self, physical_device: &VkPhysicalDevice) -> VkResult<Vec<vk::SurfaceFormatKHR>> {
unsafe {
self.surface_loader.get_physical_device_surface_formats(
physical_device.handle,
self.surface
)
}
}
pub fn get_physical_device_surface_capabilities(&self, physical_device: &VkPhysicalDevice) -> VkResult<vk::SurfaceCapabilitiesKHR> {
unsafe {
self.surface_loader.get_physical_device_surface_capabilities(
physical_device.handle,
self.surface
)
}
}
pub fn get_physical_device_surface_present_modes(&self, physical_device: &VkPhysicalDevice) -> VkResult<Vec<vk::PresentModeKHR>> {
unsafe {
self.surface_loader.get_physical_device_surface_present_modes(
physical_device.handle,
self.surface
)
}
}
}
impl Drop for VkSurface {
fn drop(&mut self) {
unsafe {
self.surface_loader.destroy_surface(self.surface, None);
}
log::debug!("Surface destroyed");
}
}