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
|
@ -13,6 +13,7 @@ use winit::raw_window_handle::{HasDisplayHandle, HasWindowHandle};
|
|||
pub struct VkInstance {
|
||||
pub(super) entry: Entry,
|
||||
pub(super) handle: Instance,
|
||||
pub(super) surface_loader: surface::Instance,
|
||||
}
|
||||
|
||||
impl VkInstance {
|
||||
|
@ -79,11 +80,14 @@ impl VkInstance {
|
|||
.expect("Instance creation error")
|
||||
};
|
||||
|
||||
log::debug!(target: LOG_TARGET, "Vulkan instance created");
|
||||
let surface_loader = surface::Instance::new(&entry, &instance);
|
||||
|
||||
log::debug!(target: LOG_TARGET, "Vulkan instance created ({:?})", instance.handle());
|
||||
|
||||
Self {
|
||||
entry,
|
||||
handle: instance,
|
||||
surface_loader
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,52 +98,12 @@ impl VkInstance {
|
|||
.iter().map(|physical_device| VkPhysicalDevice::new(&self.handle, *physical_device))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn create_surface(
|
||||
&self,
|
||||
window: &crate::display::Window,
|
||||
) -> anyhow::Result<VkSurface> {
|
||||
let window_handle = window.handle()
|
||||
.ok_or_else(|| anyhow::anyhow!("Window handle is not available."))?;
|
||||
|
||||
let surface_loader = surface::Instance::new(&self.entry, &self.handle);
|
||||
|
||||
let surface = unsafe {
|
||||
ash_window::create_surface(
|
||||
&self.entry,
|
||||
&self.handle,
|
||||
window_handle.display_handle()?.as_raw(),
|
||||
window_handle.window_handle()?.as_raw(),
|
||||
None,
|
||||
)?
|
||||
};
|
||||
|
||||
log::debug!(target: LOG_TARGET, "Surface created");
|
||||
|
||||
Ok(VkSurface::new(
|
||||
surface_loader,
|
||||
surface,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn create_device(
|
||||
&self,
|
||||
physical_device: &VkPhysicalDevice,
|
||||
create_info: &vk::DeviceCreateInfo,
|
||||
allocation_callbacks: Option<&vk::AllocationCallbacks>,
|
||||
) -> VkResult<ash::Device> {
|
||||
unsafe {
|
||||
self.handle.create_device(physical_device.handle, &create_info, allocation_callbacks)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for VkInstance {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
self.handle.destroy_instance(None);
|
||||
}
|
||||
log::debug!(target: LOG_TARGET, "Vulkan instance destroyed");
|
||||
unsafe { self.handle.destroy_instance(None); }
|
||||
log::debug!(target: LOG_TARGET, "Vulkan instance destroyed ({:?})", self.handle.handle());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue