Add logical device struct and surface handling for Vulkan
Introduce the VkLogicalDevice struct and add surface creation logic in VkInstance. Also, import necessary extensions and refine Vulkan physical device and window handling. Included a dependency on 'anyhow' for error management.
This commit is contained in:
parent
4048937a6c
commit
da0be47b14
14 changed files with 258 additions and 153 deletions
|
@ -1,10 +1,11 @@
|
|||
use std::cmp::Ordering;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use ash::vk;
|
||||
use crate::display::App;
|
||||
use crate::vulkan::vk_surface::VkSurface;
|
||||
|
||||
pub struct VkPhysicalDevice {
|
||||
// Vulkan properties
|
||||
handle: vk::PhysicalDevice,
|
||||
pub(super) handle: vk::PhysicalDevice,
|
||||
pub properties: vk::PhysicalDeviceProperties,
|
||||
pub features: vk::PhysicalDeviceFeatures,
|
||||
pub queue_family_properties: Vec<vk::QueueFamilyProperties>,
|
||||
|
@ -26,33 +27,16 @@ impl VkPhysicalDevice {
|
|||
}
|
||||
|
||||
pub fn priority(&self) -> usize {
|
||||
let mut priority = 0;
|
||||
|
||||
let has_graphics_support = self.queue_family_properties.iter().any(|qf| qf.queue_flags.contains(vk::QueueFlags::GRAPHICS));
|
||||
let has_compute_support = self.queue_family_properties.iter().any(|qf| qf.queue_flags.contains(vk::QueueFlags::COMPUTE));
|
||||
let has_transfer_support = self.queue_family_properties.iter().any(|qf| qf.queue_flags.contains(vk::QueueFlags::TRANSFER));
|
||||
let has_sparse_binding_support = self.queue_family_properties.iter().any(|qf| qf.queue_flags.contains(vk::QueueFlags::SPARSE_BINDING));
|
||||
let physical_device_type = self.properties.device_type;
|
||||
|
||||
priority |= has_graphics_support as usize;
|
||||
priority |= (has_sparse_binding_support as usize) << 1;
|
||||
priority |= (has_transfer_support as usize) << 2;
|
||||
priority |= (has_compute_support as usize) << 3;
|
||||
|
||||
let weight : usize = match physical_device_type {
|
||||
match self.properties.device_type {
|
||||
vk::PhysicalDeviceType::CPU => 1,
|
||||
vk::PhysicalDeviceType::VIRTUAL_GPU => 2,
|
||||
vk::PhysicalDeviceType::INTEGRATED_GPU => 3,
|
||||
vk::PhysicalDeviceType::DISCRETE_GPU => 4,
|
||||
_ => 0
|
||||
};
|
||||
priority |= weight << 4;
|
||||
|
||||
priority
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl Display for VkPhysicalDevice {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "\tNom: {:?}, Priorité: {}", self.properties.device_name_as_c_str().unwrap_or_default(), self.priority())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue