vulkan debug
This commit is contained in:
parent
e4916cafdf
commit
a124872895
1 changed files with 63 additions and 3 deletions
|
@ -4,7 +4,7 @@ use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use ash::{util::Align, vk, Entry, Instance};
|
use ash::{extensions::ext::DebugUtils, util::Align, vk, Entry, Instance};
|
||||||
use ash_window::enumerate_required_extensions;
|
use ash_window::enumerate_required_extensions;
|
||||||
use librashader::runtime::vk::{FilterChain, FilterChainOptions, FrameOptions, VulkanObjects};
|
use librashader::runtime::vk::{FilterChain, FilterChainOptions, FrameOptions, VulkanObjects};
|
||||||
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle};
|
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle};
|
||||||
|
@ -32,6 +32,8 @@ const VERTICES: [Vertex; 3] = [Vertex(-1.0, -1.0), Vertex(3.0, -1.0), Vertex(-1.
|
||||||
pub struct RendererBackendManager {
|
pub struct RendererBackendManager {
|
||||||
entry: Entry,
|
entry: Entry,
|
||||||
instance: Instance,
|
instance: Instance,
|
||||||
|
debug_utils_loader: DebugUtils,
|
||||||
|
debug_call_back: vk::DebugUtilsMessengerEXT,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RendererBackendManager {
|
impl RendererBackendManager {
|
||||||
|
@ -48,6 +50,8 @@ impl RendererBackendManager {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_vec();
|
.to_vec();
|
||||||
|
|
||||||
|
extension_names.push(DebugUtils::name().as_ptr());
|
||||||
|
|
||||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||||
{
|
{
|
||||||
#[cfg(not(feature = "vulkan-static"))]
|
#[cfg(not(feature = "vulkan-static"))]
|
||||||
|
@ -76,13 +80,41 @@ impl RendererBackendManager {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let instance = unsafe { entry.create_instance(&create_info, None) }.unwrap();
|
let instance = unsafe { entry.create_instance(&create_info, None) }.unwrap();
|
||||||
Self { entry, instance }
|
|
||||||
|
let debug_info = vk::DebugUtilsMessengerCreateInfoEXT::builder()
|
||||||
|
.message_severity(
|
||||||
|
vk::DebugUtilsMessageSeverityFlagsEXT::ERROR
|
||||||
|
| vk::DebugUtilsMessageSeverityFlagsEXT::WARNING
|
||||||
|
| vk::DebugUtilsMessageSeverityFlagsEXT::INFO,
|
||||||
|
)
|
||||||
|
.message_type(
|
||||||
|
vk::DebugUtilsMessageTypeFlagsEXT::GENERAL
|
||||||
|
| vk::DebugUtilsMessageTypeFlagsEXT::VALIDATION
|
||||||
|
| vk::DebugUtilsMessageTypeFlagsEXT::PERFORMANCE,
|
||||||
|
)
|
||||||
|
.pfn_user_callback(Some(vulkan_debug_callback))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let debug_utils_loader = DebugUtils::new(&entry, &instance);
|
||||||
|
let debug_call_back =
|
||||||
|
unsafe { debug_utils_loader.create_debug_utils_messenger(&debug_info, None) }.unwrap();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
entry,
|
||||||
|
instance,
|
||||||
|
debug_utils_loader,
|
||||||
|
debug_call_back,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for RendererBackendManager {
|
impl Drop for RendererBackendManager {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe { self.instance.destroy_instance(None) };
|
unsafe {
|
||||||
|
self.debug_utils_loader
|
||||||
|
.destroy_debug_utils_messenger(self.debug_call_back, None);
|
||||||
|
self.instance.destroy_instance(None);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -715,3 +747,31 @@ impl Drop for VulkanWindowInner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe extern "system" fn vulkan_debug_callback(
|
||||||
|
message_severity: vk::DebugUtilsMessageSeverityFlagsEXT,
|
||||||
|
message_type: vk::DebugUtilsMessageTypeFlagsEXT,
|
||||||
|
p_callback_data: *const vk::DebugUtilsMessengerCallbackDataEXT,
|
||||||
|
_user_data: *mut std::os::raw::c_void,
|
||||||
|
) -> vk::Bool32 {
|
||||||
|
let callback_data = *p_callback_data;
|
||||||
|
let message_id_number = callback_data.message_id_number;
|
||||||
|
|
||||||
|
let message_id_name = if callback_data.p_message_id_name.is_null() {
|
||||||
|
std::borrow::Cow::from("")
|
||||||
|
} else {
|
||||||
|
std::ffi::CStr::from_ptr(callback_data.p_message_id_name).to_string_lossy()
|
||||||
|
};
|
||||||
|
|
||||||
|
let message = if callback_data.p_message.is_null() {
|
||||||
|
std::borrow::Cow::from("")
|
||||||
|
} else {
|
||||||
|
std::ffi::CStr::from_ptr(callback_data.p_message).to_string_lossy()
|
||||||
|
};
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"{message_severity:?}:\n{message_type:?} [{message_id_name} ({message_id_number})] : {message}\n",
|
||||||
|
);
|
||||||
|
|
||||||
|
vk::FALSE
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue