Use Arc to store reference and store dependencies for each vulkan types
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s

Arc it's used because later, i can use on multi-threaded programs
This commit is contained in:
Florian RICHER 2024-11-15 22:40:36 +01:00
parent 1cb9309a56
commit 174e12591c
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
5 changed files with 290 additions and 320 deletions

View file

@ -1,15 +1,18 @@
use crate::vulkan::{VkInstance, VkPhysicalDevice};
use std::sync::Arc;
use crate::vulkan::{VkInstance, VkPhysicalDevice, LOG_TARGET};
use ash::prelude::VkResult;
use ash::vk;
pub struct VkDevice {
instance: Arc<VkInstance>,
pub(super) handle: ash::Device,
pub(super) swapchain_loader: ash::khr::swapchain::Device,
queue_family_index: u32,
}
impl VkDevice {
pub(super) fn new_graphics_device(
instance: &VkInstance,
instance: Arc<VkInstance>,
physical_device: &VkPhysicalDevice,
queue_family_index: u32,
) -> anyhow::Result<Self> {
@ -33,11 +36,17 @@ impl VkDevice {
.enabled_extension_names(&device_extension_names_raw)
.enabled_features(&features);
let device = instance
.create_device(physical_device, &device_create_info, None)?;
let device = unsafe {
instance.handle.create_device(physical_device.handle, &device_create_info, None)?
};
log::debug!(target: LOG_TARGET, "Device created ({:?})", device.handle());
let swapchain_loader = ash::khr::swapchain::Device::new(&instance.handle, &device);
Ok(Self {
instance,
handle: device,
swapchain_loader,
queue_family_index,
})
}
@ -93,6 +102,7 @@ impl Drop for VkDevice {
fn drop(&mut self) {
unsafe {
self.handle.destroy_device(None);
log::debug!(target: LOG_TARGET, "Device destroyed ({:?})", self.handle.handle());
}
}
}