1 use crate::prelude::*; 2 use crate::vk; 3 use crate::RawPtr; 4 use crate::{Entry, Instance}; 5 use std::ffi::CStr; 6 use std::mem; 7 8 #[derive(Clone)] 9 pub struct DebugReport { 10 handle: vk::Instance, 11 fp: vk::ExtDebugReportFn, 12 } 13 14 impl DebugReport { new(entry: &Entry, instance: &Instance) -> Self15 pub fn new(entry: &Entry, instance: &Instance) -> Self { 16 let handle = instance.handle(); 17 let fp = vk::ExtDebugReportFn::load(|name| unsafe { 18 mem::transmute(entry.get_instance_proc_addr(handle, name.as_ptr())) 19 }); 20 Self { handle, fp } 21 } 22 23 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDestroyDebugReportCallbackEXT.html> 24 #[inline] destroy_debug_report_callback( &self, debug: vk::DebugReportCallbackEXT, allocation_callbacks: Option<&vk::AllocationCallbacks>, )25 pub unsafe fn destroy_debug_report_callback( 26 &self, 27 debug: vk::DebugReportCallbackEXT, 28 allocation_callbacks: Option<&vk::AllocationCallbacks>, 29 ) { 30 (self.fp.destroy_debug_report_callback_ext)( 31 self.handle, 32 debug, 33 allocation_callbacks.as_raw_ptr(), 34 ); 35 } 36 37 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCreateDebugReportCallbackEXT.html> 38 #[inline] create_debug_report_callback( &self, create_info: &vk::DebugReportCallbackCreateInfoEXT, allocation_callbacks: Option<&vk::AllocationCallbacks>, ) -> VkResult<vk::DebugReportCallbackEXT>39 pub unsafe fn create_debug_report_callback( 40 &self, 41 create_info: &vk::DebugReportCallbackCreateInfoEXT, 42 allocation_callbacks: Option<&vk::AllocationCallbacks>, 43 ) -> VkResult<vk::DebugReportCallbackEXT> { 44 let mut debug_cb = mem::zeroed(); 45 (self.fp.create_debug_report_callback_ext)( 46 self.handle, 47 create_info, 48 allocation_callbacks.as_raw_ptr(), 49 &mut debug_cb, 50 ) 51 .result_with_success(debug_cb) 52 } 53 54 #[inline] name() -> &'static CStr55 pub const fn name() -> &'static CStr { 56 vk::ExtDebugReportFn::name() 57 } 58 59 #[inline] fp(&self) -> &vk::ExtDebugReportFn60 pub fn fp(&self) -> &vk::ExtDebugReportFn { 61 &self.fp 62 } 63 64 #[inline] instance(&self) -> vk::Instance65 pub fn instance(&self) -> vk::Instance { 66 self.handle 67 } 68 } 69