ash/extensions/ext/
debug_report.rs

1use crate::prelude::*;
2use crate::vk;
3use crate::RawPtr;
4use crate::{Entry, Instance};
5use std::ffi::CStr;
6use std::mem;
7
8#[derive(Clone)]
9pub struct DebugReport {
10    handle: vk::Instance,
11    fp: vk::ExtDebugReportFn,
12}
13
14impl DebugReport {
15    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    pub unsafe fn destroy_debug_report_callback(
25        &self,
26        debug: vk::DebugReportCallbackEXT,
27        allocation_callbacks: Option<&vk::AllocationCallbacks>,
28    ) {
29        (self.fp.destroy_debug_report_callback_ext)(
30            self.handle,
31            debug,
32            allocation_callbacks.as_raw_ptr(),
33        );
34    }
35
36    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCreateDebugReportCallbackEXT.html>
37    pub unsafe fn create_debug_report_callback(
38        &self,
39        create_info: &vk::DebugReportCallbackCreateInfoEXT,
40        allocation_callbacks: Option<&vk::AllocationCallbacks>,
41    ) -> VkResult<vk::DebugReportCallbackEXT> {
42        let mut debug_cb = mem::zeroed();
43        (self.fp.create_debug_report_callback_ext)(
44            self.handle,
45            create_info,
46            allocation_callbacks.as_raw_ptr(),
47            &mut debug_cb,
48        )
49        .result_with_success(debug_cb)
50    }
51
52    pub const fn name() -> &'static CStr {
53        vk::ExtDebugReportFn::name()
54    }
55
56    pub fn fp(&self) -> &vk::ExtDebugReportFn {
57        &self.fp
58    }
59
60    pub fn instance(&self) -> vk::Instance {
61        self.handle
62    }
63}