Refactor Vulkan device and instance handling
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s
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:
parent
b91571e777
commit
d0c6f31a1a
9 changed files with 233 additions and 59 deletions
57
src/vulkan/vk_device.rs
Normal file
57
src/vulkan/vk_device.rs
Normal file
|
@ -0,0 +1,57 @@
|
|||
use ash::vk;
|
||||
use crate::vulkan::{VkInstance, VkPhysicalDevice};
|
||||
|
||||
pub struct VkDevice {
|
||||
handle: ash::Device,
|
||||
queue_family_index: u32
|
||||
}
|
||||
|
||||
impl VkDevice {
|
||||
pub fn new_graphics_device(
|
||||
instance: &VkInstance,
|
||||
physical_device: &VkPhysicalDevice,
|
||||
queue_family_index: u32,
|
||||
) -> anyhow::Result<Self> {
|
||||
let device_extension_names_raw = [
|
||||
ash::khr::swapchain::NAME.as_ptr(),
|
||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||
ash::khr::portability_subset::NAME.as_ptr(),
|
||||
];
|
||||
let features = vk::PhysicalDeviceFeatures {
|
||||
shader_clip_distance: 1,
|
||||
..Default::default()
|
||||
};
|
||||
let priorities = [1.0];
|
||||
|
||||
let queue_info = vk::DeviceQueueCreateInfo::default()
|
||||
.queue_family_index(queue_family_index)
|
||||
.queue_priorities(&priorities);
|
||||
|
||||
let device_create_info = vk::DeviceCreateInfo::default()
|
||||
.queue_create_infos(std::slice::from_ref(&queue_info))
|
||||
.enabled_extension_names(&device_extension_names_raw)
|
||||
.enabled_features(&features);
|
||||
|
||||
let device = instance
|
||||
.create_device(physical_device, &device_create_info, None)?;
|
||||
|
||||
Ok(Self {
|
||||
handle: device,
|
||||
queue_family_index
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_device_queue(&self, queue_index: u32) -> vk::Queue {
|
||||
unsafe {
|
||||
self.handle.get_device_queue(self.queue_family_index, queue_index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for VkDevice {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
self.handle.destroy_device(None);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue