This commit is contained in:
parent
d0c6f31a1a
commit
caa79270db
5 changed files with 58 additions and 42 deletions
|
@ -1,13 +1,14 @@
|
|||
use std::ffi::{c_char, CStr, CString};
|
||||
use std::fmt::{Display, Formatter};
|
||||
use ash::{Instance, vk, Entry};
|
||||
use ash::khr::surface;
|
||||
use ash::prelude::VkResult;
|
||||
use winit::raw_window_handle::{HasDisplayHandle, HasWindowHandle};
|
||||
use crate::vulkan::utils::formatter::format_instance_layer;
|
||||
use crate::vulkan::utils::layers::{use_layers, LayersSelector};
|
||||
use crate::vulkan::vk_surface::VkSurface;
|
||||
use crate::vulkan::VkPhysicalDevice;
|
||||
use crate::vulkan::{VkPhysicalDevice, LOG_TARGET};
|
||||
use ash::khr::surface;
|
||||
use ash::prelude::VkResult;
|
||||
use ash::vk::QueueFlags;
|
||||
use ash::{vk, Entry, Instance};
|
||||
use std::ffi::{c_char, CStr, CString};
|
||||
use std::fmt::{Display, Formatter};
|
||||
use winit::raw_window_handle::{HasDisplayHandle, HasWindowHandle};
|
||||
|
||||
pub struct VkInstance {
|
||||
entry: Entry,
|
||||
|
@ -20,15 +21,15 @@ impl VkInstance {
|
|||
) -> Self {
|
||||
let entry = Entry::linked();
|
||||
|
||||
log::debug!("Initializing Vulkan instance");
|
||||
log::debug!(target: LOG_TARGET, "Initializing Vulkan instance");
|
||||
|
||||
if log::log_enabled!(log::Level::Debug) {
|
||||
{
|
||||
let required_extensions = required_extensions
|
||||
.iter()
|
||||
.map(|str| unsafe { CStr::from_ptr(*str) })
|
||||
.map(|cstr| cstr.to_string_lossy())
|
||||
.collect::<Vec<_>>();
|
||||
log::debug!("Required instance extensions: {}", required_extensions.join(", "));
|
||||
log::debug!(target: LOG_TARGET, "Required instance extensions: {}", required_extensions.join(", "));
|
||||
}
|
||||
|
||||
// Layers
|
||||
|
@ -38,14 +39,16 @@ impl VkInstance {
|
|||
"VK_LAYER_KHRONOS_validation",
|
||||
"VK_LAYER_MANGOHUD_overlay_x86_64",
|
||||
"VK_LAYER_NV_optimus"
|
||||
])
|
||||
]),
|
||||
);
|
||||
if log::log_enabled!(log::Level::Info) {
|
||||
|
||||
{
|
||||
let layers = layers.iter()
|
||||
.map(|layer| layer.to_string_lossy())
|
||||
.collect::<Vec<_>>();
|
||||
log::debug!("Selected debug layers : {}", layers.join(", "))
|
||||
log::debug!(target: LOG_TARGET, "Selected debug layers : {}", layers.join(", "))
|
||||
}
|
||||
|
||||
let layers_raw = layers.iter().map(|s| s.as_ptr()).collect::<Vec<_>>();
|
||||
|
||||
// App Info
|
||||
|
@ -76,11 +79,11 @@ impl VkInstance {
|
|||
.expect("Instance creation error")
|
||||
};
|
||||
|
||||
log::debug!("Vulkan instance created");
|
||||
log::debug!(target: LOG_TARGET, "Vulkan instance created");
|
||||
|
||||
Self {
|
||||
entry,
|
||||
handle: instance
|
||||
handle: instance,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,7 +97,7 @@ impl VkInstance {
|
|||
|
||||
pub fn create_surface(
|
||||
&self,
|
||||
window: &crate::display::Window
|
||||
window: &crate::display::Window,
|
||||
) -> anyhow::Result<VkSurface> {
|
||||
let window_handle = window.handle()
|
||||
.ok_or_else(|| anyhow::anyhow!("Window handle is not available."))?;
|
||||
|
@ -111,7 +114,7 @@ impl VkInstance {
|
|||
)?
|
||||
};
|
||||
|
||||
log::debug!("Surface created");
|
||||
log::debug!(target: LOG_TARGET, "Surface created");
|
||||
|
||||
Ok(VkSurface::new(
|
||||
surface_loader,
|
||||
|
@ -136,7 +139,7 @@ impl Drop for VkInstance {
|
|||
unsafe {
|
||||
self.handle.destroy_instance(None);
|
||||
}
|
||||
log::debug!("Vulkan instance destroyed");
|
||||
log::debug!(target: LOG_TARGET, "Vulkan instance destroyed");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue