ash/extensions/nv/
device_diagnostic_checkpoints.rs

1use crate::vk;
2use crate::{Device, Instance};
3use std::ffi::CStr;
4use std::mem;
5use std::os::raw::c_void;
6
7/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_NV_device_diagnostic_checkpoints.html>
8#[derive(Clone)]
9pub struct DeviceDiagnosticCheckpoints {
10    fp: vk::NvDeviceDiagnosticCheckpointsFn,
11}
12
13impl DeviceDiagnosticCheckpoints {
14    pub fn new(instance: &Instance, device: &Device) -> Self {
15        let fp = vk::NvDeviceDiagnosticCheckpointsFn::load(|name| unsafe {
16            mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
17        });
18        Self { fp }
19    }
20
21    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdSetCheckpointNV.html>
22    pub unsafe fn cmd_set_checkpoint(
23        &self,
24        command_buffer: vk::CommandBuffer,
25        p_checkpoint_marker: *const c_void,
26    ) {
27        (self.fp.cmd_set_checkpoint_nv)(command_buffer, p_checkpoint_marker);
28    }
29
30    /// Retrieve the number of elements to pass to [`get_queue_checkpoint_data()`][Self::get_queue_checkpoint_data()]
31    pub unsafe fn get_queue_checkpoint_data_len(&self, queue: vk::Queue) -> usize {
32        let mut count = 0;
33        (self.fp.get_queue_checkpoint_data_nv)(queue, &mut count, std::ptr::null_mut());
34        count as usize
35    }
36
37    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetQueueCheckpointDataNV.html>
38    ///
39    /// Call [`get_queue_checkpoint_data_len()`][Self::get_queue_checkpoint_data_len()] to query the number of elements to pass to `out`.
40    /// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer.
41    pub unsafe fn get_queue_checkpoint_data(
42        &self,
43        queue: vk::Queue,
44        out: &mut [vk::CheckpointDataNV],
45    ) {
46        let mut count = out.len() as u32;
47        (self.fp.get_queue_checkpoint_data_nv)(queue, &mut count, out.as_mut_ptr());
48        assert_eq!(count as usize, out.len());
49    }
50
51    pub const fn name() -> &'static CStr {
52        vk::NvDeviceDiagnosticCheckpointsFn::name()
53    }
54
55    pub fn fp(&self) -> &vk::NvDeviceDiagnosticCheckpointsFn {
56        &self.fp
57    }
58}