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
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:
parent
1cb9309a56
commit
174e12591c
5 changed files with 290 additions and 320 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue