From 576b614527073d3d75e3a276dae9edc4c1a7ec2a Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Fri, 19 Feb 2016 08:01:02 +0100 Subject: [PATCH] Add debugging report --- vk-sys/src/enums.rs | 45 ++++++++++++++++++++++++++++++++++++++++- vk-sys/src/functions.rs | 3 +++ vk-sys/src/structs.rs | 22 ++++++++++++++------ vulkano/src/instance.rs | 38 +++++++++++++++++++++++++++++++++- 4 files changed, 100 insertions(+), 8 deletions(-) diff --git a/vk-sys/src/enums.rs b/vk-sys/src/enums.rs index 22cb4671..a49ce1b9 100644 --- a/vk-sys/src/enums.rs +++ b/vk-sys/src/enums.rs @@ -30,11 +30,11 @@ pub type DescriptorPool = u64; pub type DescriptorSet = u64; pub type Framebuffer = u64; pub type CommandPool = u64; - pub type SurfaceKHR = u64; pub type SwapchainKHR = u64; pub type DisplayKHR = u64; pub type DisplayModeKHR = u64; +pub type DebugReportCallbackEXT = u64; pub const LOD_CLAMP_NONE: f32 = 1000.0; pub const REMAINING_MIP_LEVELS: u32 = 0xffffffff; @@ -890,3 +890,46 @@ pub const COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR: u32 = 0x00000002; pub const COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR: u32 = 0x00000004; pub const COMPOSITE_ALPHA_INHERIT_BIT_KHR: u32 = 0x00000008; pub type CompositeAlphaFlagsKHR = Flags; + +pub type DebugReportObjectTypeEXT = u32; +pub const DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT: u32 = 0; +pub const DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT: u32 = 1; +pub const DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT: u32 = 2; +pub const DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT: u32 = 3; +pub const DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT: u32 = 4; +pub const DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT: u32 = 5; +pub const DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT: u32 = 6; +pub const DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT: u32 = 7; +pub const DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT: u32 = 8; +pub const DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT: u32 = 9; +pub const DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT: u32 = 10; +pub const DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT: u32 = 11; +pub const DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT: u32 = 12; +pub const DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT: u32 = 13; +pub const DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT: u32 = 14; +pub const DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT: u32 = 15; +pub const DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT: u32 = 16; +pub const DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT: u32 = 17; +pub const DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT: u32 = 18; +pub const DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT: u32 = 19; +pub const DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT: u32 = 20; +pub const DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT: u32 = 21; +pub const DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT: u32 = 22; +pub const DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT: u32 = 23; +pub const DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT: u32 = 24; +pub const DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT: u32 = 25; +pub const DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT: u32 = 26; +pub const DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT: u32 = 27; +pub const DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT: u32 = 28; + +pub type DebugReportErrorEXT = u32; +pub const DEBUG_REPORT_ERROR_NONE_EXT: u32 = 0; +pub const DEBUG_REPORT_ERROR_CALLBACK_REF_EXT: u32 = 1; + +pub type DebugReportFlagBitsEXT = u32; +pub const DEBUG_REPORT_INFORMATION_BIT_EXT: u32 = 0x00000001; +pub const DEBUG_REPORT_WARNING_BIT_EXT: u32 = 0x00000002; +pub const DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT: u32 = 0x00000004; +pub const DEBUG_REPORT_ERROR_BIT_EXT: u32 = 0x00000008; +pub const DEBUG_REPORT_DEBUG_BIT_EXT: u32 = 0x00000010; +pub type DebugReportFlagsEXT = Flags; diff --git a/vk-sys/src/functions.rs b/vk-sys/src/functions.rs index a958b872..a00445b6 100644 --- a/vk-sys/src/functions.rs +++ b/vk-sys/src/functions.rs @@ -96,6 +96,9 @@ ptrs!(InstancePointers, { GetPhysicalDeviceSurfaceCapabilitiesKHR => (physicalDevice: PhysicalDevice, surface: SurfaceKHR, pSurfaceCapabilities: *mut SurfaceCapabilitiesKHR) -> Result, GetPhysicalDeviceSurfaceFormatsKHR => (physicalDevice: PhysicalDevice, surface: SurfaceKHR, pSurfaceFormatCount: *mut u32, pSurfaceFormats: *mut SurfaceFormatKHR) -> Result, GetPhysicalDeviceSurfacePresentModesKHR => (physicalDevice: PhysicalDevice, surface: SurfaceKHR, pPresentModeCount: *mut u32, pPresentModes: *mut PresentModeKHR) -> Result, + CreateDebugReportCallbackEXT => (instance: Instance, pCreateInfo: *const DebugReportCallbackCreateInfoEXT, pAllocator: *const AllocationCallbacks, pCallback: *mut DebugReportCallbackEXT) -> Result, + DestroyDebugReportCallbackEXT => (instance: Instance, callback: DebugReportCallbackEXT, pAllocator: *const AllocationCallbacks) -> (), + DebugReportMessageEXT => (instance: Instance, flags: DebugReportFlagsEXT, objectType: DebugReportObjectTypeEXT, object: u64, location: usize, messageCode: i32, pLayerPrefix: *const c_char, pMessage: *const c_char) -> (), }); ptrs!(DevicePointers, { diff --git a/vk-sys/src/structs.rs b/vk-sys/src/structs.rs index a2fc636c..34486aff 100644 --- a/vk-sys/src/structs.rs +++ b/vk-sys/src/structs.rs @@ -1,12 +1,13 @@ use std::mem; -pub type PFN_vkAllocationFunction = extern fn(*mut c_void, usize, usize, SystemAllocationScope) -> *mut c_void; -pub type PFN_vkReallocationFunction = extern fn(*mut c_void, *mut c_void, usize, usize, SystemAllocationScope) -> *mut c_void; -pub type PFN_vkFreeFunction = extern fn(*mut c_void, *mut c_void); -pub type PFN_vkInternalAllocationNotification = extern fn(*mut c_void, usize, InternalAllocationType, SystemAllocationScope) -> *mut c_void; -pub type PFN_vkInternalFreeNotification = extern fn(*mut c_void, usize, InternalAllocationType, SystemAllocationScope) -> *mut c_void; +pub type PFN_vkAllocationFunction = extern "system" fn(*mut c_void, usize, usize, SystemAllocationScope) -> *mut c_void; +pub type PFN_vkReallocationFunction = extern "system" fn(*mut c_void, *mut c_void, usize, usize, SystemAllocationScope) -> *mut c_void; +pub type PFN_vkFreeFunction = extern "system" fn(*mut c_void, *mut c_void); +pub type PFN_vkInternalAllocationNotification = extern "system" fn(*mut c_void, usize, InternalAllocationType, SystemAllocationScope) -> *mut c_void; +pub type PFN_vkInternalFreeNotification = extern "system" fn(*mut c_void, usize, InternalAllocationType, SystemAllocationScope) -> *mut c_void; +pub type PFN_vkDebugReportCallbackEXT = extern "system" fn(DebugReportFlagsEXT, DebugReportObjectTypeEXT, u64, usize, i32, *const c_char, *const c_char, *mut c_void) -> Bool32; -pub type PFN_vkVoidFunction = extern fn() -> (); +pub type PFN_vkVoidFunction = extern "system" fn() -> (); #[repr(C)] pub struct ApplicationInfo { @@ -1400,3 +1401,12 @@ pub struct Win32SurfaceCreateInfoKHR { pub hwnd: *mut c_void, } + +#[repr(C)] +pub struct DebugReportCallbackCreateInfoEXT { + pub sType: StructureType, + pub pNext: *const c_void, + pub flags: DebugReportFlagsEXT, + pub pfnCallback: PFN_vkDebugReportCallbackEXT, + pub pUserData: *mut c_void, +} diff --git a/vulkano/src/instance.rs b/vulkano/src/instance.rs index b8f8a24d..08239764 100644 --- a/vulkano/src/instance.rs +++ b/vulkano/src/instance.rs @@ -32,6 +32,7 @@ use std::ffi::CStr; use std::ffi::CString; use std::fmt; use std::mem; +use std::os::raw::{c_void, c_char}; use std::ptr; use std::sync::Arc; @@ -52,6 +53,7 @@ pub use version::Version; /// application before everything else. pub struct Instance { instance: vk::Instance, + debug_report: Option, //alloc: Option>, physical_devices: Vec, vk: vk::InstancePointers, @@ -100,7 +102,7 @@ impl Instance { layer.as_ptr() }).collect::>(); - let extensions = ["VK_KHR_surface", "VK_KHR_win32_surface"].iter().map(|&ext| { + let extensions = ["VK_KHR_surface", "VK_KHR_win32_surface", "VK_EXT_debug_report"].iter().map(|&ext| { // FIXME: check whether each extension is supported CString::new(ext).unwrap() }).collect::>(); @@ -135,6 +137,35 @@ impl Instance { mem::transmute(VK_STATIC.GetInstanceProcAddr(instance, name.as_ptr())) }); + // Creating the debug report callback. + // TODO: should be optional + let debug_report = unsafe { + extern "system" fn callback(_: vk::DebugReportFlagsEXT, _: vk::DebugReportObjectTypeEXT, + _: u64, _: usize, _: i32, layer_prefix: *const c_char, + message: *const c_char, _: *mut c_void) -> u32 + { + unsafe { + let message = CStr::from_ptr(message).to_str() + .expect("debug callback message not utf-8"); + println!("Debug callback message: {:?}", message); + 0 // TODO: what's the meaning of that value + } + } + + let infos = vk::DebugReportCallbackCreateInfoEXT { + sType: vk::STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT, + pNext: ptr::null(), + flags: 0, // reserved + pfnCallback: callback, + pUserData: ptr::null_mut(), + }; + + let mut output = mem::uninitialized(); + try!(check_errors(vk.CreateDebugReportCallbackEXT(instance, &infos, + ptr::null(), &mut output))); + output + }; + // Enumerating all physical devices. let physical_devices: Vec = unsafe { let mut num = mem::uninitialized(); @@ -194,6 +225,7 @@ impl Instance { Ok(Arc::new(Instance { instance: instance, + debug_report: Some(debug_report), //alloc: None, physical_devices: physical_devices, vk: vk, @@ -238,6 +270,10 @@ impl Drop for Instance { #[inline] fn drop(&mut self) { unsafe { + if let Some(debug_report) = self.debug_report { + self.vk.DestroyDebugReportCallbackEXT(self.instance, debug_report, ptr::null()); + } + self.vk.DestroyInstance(self.instance, ptr::null()); } }