kazan 0.3.9+1.4.359

Vulkan bindings for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
//! <https://registry.khronos.org/vulkan/specs/latest/man/html/VK_EXT_debug_report.html>
#![allow(unused_imports)]
use crate::{vk::Result as VkResult, vk::*, *};
use core::ffi::{CStr, c_char, c_int, c_void};
use core::mem::transmute;
use core::ptr;

pub const EXTENSION_NAME: &CStr = c"VK_EXT_debug_report";

pub(super) mod defs {
    #![allow(non_camel_case_types, unused_imports)]
    use crate::{vk::*, *};
    use core::ffi::{CStr, c_char, c_int, c_void};
    use core::fmt;
    use core::marker::PhantomData;
    use core::ptr;

    handle_nondispatchable!(
        DebugReportCallbackEXT,
        DEBUG_REPORT_CALLBACK_EXT,
        doc = "<https://registry.khronos.org/vulkan/specs/latest/man/html/VkDebugReportCallbackEXT.html>"
    );

    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/VkDebugReportCallbackCreateInfoEXT.html>
    #[repr(C)]
    #[derive(Copy, Clone)]
    #[must_use]
    pub struct DebugReportCallbackCreateInfoEXT<'a> {
        pub s_type: StructureType,
        pub p_next: *const c_void,
        pub flags: DebugReportFlagsEXT,
        pub pfn_callback: Option<PFN_vkDebugReportCallbackEXT>,
        pub p_user_data: *mut c_void,
        pub _marker: PhantomData<&'a ()>,
    }

    #[cfg(feature = "debug")]
    impl fmt::Debug for DebugReportCallbackCreateInfoEXT<'_> {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            f.debug_struct("DebugReportCallbackCreateInfoEXT")
                .field("s_type", &self.s_type)
                .field("p_next", &self.p_next)
                .field("flags", &self.flags)
                .field("pfn_callback", &self.pfn_callback.map(|f| f as *const ()))
                .field("p_user_data", &self.p_user_data)
                .finish()
        }
    }

    unsafe impl<'a> TaggedStructure<'a> for DebugReportCallbackCreateInfoEXT<'a> {
        const STRUCTURE_TYPE: StructureType = StructureType::DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT;
    }

    unsafe impl Extends<InstanceCreateInfo<'_>> for DebugReportCallbackCreateInfoEXT<'_> {}

    impl Default for DebugReportCallbackCreateInfoEXT<'_> {
        fn default() -> Self {
            Self {
                s_type: Self::STRUCTURE_TYPE,
                p_next: ptr::null(),
                flags: Default::default(),
                pfn_callback: Default::default(),
                p_user_data: ptr::null_mut(),
                _marker: PhantomData,
            }
        }
    }

    impl<'a> DebugReportCallbackCreateInfoEXT<'a> {
        #[inline]
        pub fn flags(mut self, flags: DebugReportFlagsEXT) -> Self {
            self.flags = flags;
            self
        }

        #[inline]
        pub fn pfn_callback(mut self, pfn_callback: PFN_vkDebugReportCallbackEXT) -> Self {
            self.pfn_callback = Some(pfn_callback);
            self
        }

        #[inline]
        pub fn user_data(mut self, user_data: *mut c_void) -> Self {
            self.p_user_data = user_data;
            self
        }
    }

    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/VkDebugReportObjectTypeEXT.html>
    #[repr(transparent)]
    #[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub struct DebugReportObjectTypeEXT(i32);

    impl DebugReportObjectTypeEXT {
        #[inline]
        pub const fn from_raw(x: i32) -> Self {
            Self(x)
        }
        #[inline]
        pub const fn as_raw(self) -> i32 {
            self.0
        }

        pub const UNKNOWN_EXT: Self = Self(0);
        pub const INSTANCE_EXT: Self = Self(1);
        pub const PHYSICAL_DEVICE_EXT: Self = Self(2);
        pub const DEVICE_EXT: Self = Self(3);
        pub const QUEUE_EXT: Self = Self(4);
        pub const SEMAPHORE_EXT: Self = Self(5);
        pub const COMMAND_BUFFER_EXT: Self = Self(6);
        pub const FENCE_EXT: Self = Self(7);
        pub const DEVICE_MEMORY_EXT: Self = Self(8);
        pub const BUFFER_EXT: Self = Self(9);
        pub const IMAGE_EXT: Self = Self(10);
        pub const EVENT_EXT: Self = Self(11);
        pub const QUERY_POOL_EXT: Self = Self(12);
        pub const BUFFER_VIEW_EXT: Self = Self(13);
        pub const IMAGE_VIEW_EXT: Self = Self(14);
        pub const SHADER_MODULE_EXT: Self = Self(15);
        pub const PIPELINE_CACHE_EXT: Self = Self(16);
        pub const PIPELINE_LAYOUT_EXT: Self = Self(17);
        pub const RENDER_PASS_EXT: Self = Self(18);
        pub const PIPELINE_EXT: Self = Self(19);
        pub const DESCRIPTOR_SET_LAYOUT_EXT: Self = Self(20);
        pub const SAMPLER_EXT: Self = Self(21);
        pub const DESCRIPTOR_POOL_EXT: Self = Self(22);
        pub const DESCRIPTOR_SET_EXT: Self = Self(23);
        pub const FRAMEBUFFER_EXT: Self = Self(24);
        pub const COMMAND_POOL_EXT: Self = Self(25);
        pub const SURFACE_KHR_EXT: Self = Self(26);
        pub const SWAPCHAIN_KHR_EXT: Self = Self(27);
        pub const DEBUG_REPORT_CALLBACK_EXT_EXT: Self = Self(28);
        pub const DISPLAY_KHR_EXT: Self = Self(29);
        pub const DISPLAY_MODE_KHR_EXT: Self = Self(30);
        pub const VALIDATION_CACHE_EXT_EXT: Self = Self(33);

        // VK_EXT_debug_report
        pub const SAMPLER_YCBCR_CONVERSION_EXT: Self = Self(1000156000);
        pub const DESCRIPTOR_UPDATE_TEMPLATE_EXT: Self = Self(1000085000);

        // VK_FUCHSIA_buffer_collection
        pub const BUFFER_COLLECTION_FUCHSIA_EXT: Self = Self(1000366000);

        // VK_KHR_acceleration_structure
        pub const ACCELERATION_STRUCTURE_KHR_EXT: Self = Self(1000150000);

        // VK_KHR_descriptor_update_template
        pub const DESCRIPTOR_UPDATE_TEMPLATE_KHR_EXT: Self = Self::DESCRIPTOR_UPDATE_TEMPLATE_EXT;

        // VK_KHR_sampler_ycbcr_conversion
        pub const SAMPLER_YCBCR_CONVERSION_KHR_EXT: Self = Self::SAMPLER_YCBCR_CONVERSION_EXT;

        // VK_NVX_binary_import
        pub const CU_MODULE_NVX_EXT: Self = Self(1000029000);
        pub const CU_FUNCTION_NVX_EXT: Self = Self(1000029001);

        // VK_NV_cuda_kernel_launch
        #[cfg(feature = "provisional")]
        pub const CUDA_MODULE_NV_EXT: Self = Self(1000307000);
        #[cfg(feature = "provisional")]
        pub const CUDA_FUNCTION_NV_EXT: Self = Self(1000307001);

        // VK_NV_ray_tracing
        pub const ACCELERATION_STRUCTURE_NV_EXT: Self = Self(1000165000);
    }

    impl fmt::Debug for DebugReportObjectTypeEXT {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            let name = match *self {
                Self::UNKNOWN_EXT => Some("UNKNOWN_EXT"),
                Self::INSTANCE_EXT => Some("INSTANCE_EXT"),
                Self::PHYSICAL_DEVICE_EXT => Some("PHYSICAL_DEVICE_EXT"),
                Self::DEVICE_EXT => Some("DEVICE_EXT"),
                Self::QUEUE_EXT => Some("QUEUE_EXT"),
                Self::SEMAPHORE_EXT => Some("SEMAPHORE_EXT"),
                Self::COMMAND_BUFFER_EXT => Some("COMMAND_BUFFER_EXT"),
                Self::FENCE_EXT => Some("FENCE_EXT"),
                Self::DEVICE_MEMORY_EXT => Some("DEVICE_MEMORY_EXT"),
                Self::BUFFER_EXT => Some("BUFFER_EXT"),
                Self::IMAGE_EXT => Some("IMAGE_EXT"),
                Self::EVENT_EXT => Some("EVENT_EXT"),
                Self::QUERY_POOL_EXT => Some("QUERY_POOL_EXT"),
                Self::BUFFER_VIEW_EXT => Some("BUFFER_VIEW_EXT"),
                Self::IMAGE_VIEW_EXT => Some("IMAGE_VIEW_EXT"),
                Self::SHADER_MODULE_EXT => Some("SHADER_MODULE_EXT"),
                Self::PIPELINE_CACHE_EXT => Some("PIPELINE_CACHE_EXT"),
                Self::PIPELINE_LAYOUT_EXT => Some("PIPELINE_LAYOUT_EXT"),
                Self::RENDER_PASS_EXT => Some("RENDER_PASS_EXT"),
                Self::PIPELINE_EXT => Some("PIPELINE_EXT"),
                Self::DESCRIPTOR_SET_LAYOUT_EXT => Some("DESCRIPTOR_SET_LAYOUT_EXT"),
                Self::SAMPLER_EXT => Some("SAMPLER_EXT"),
                Self::DESCRIPTOR_POOL_EXT => Some("DESCRIPTOR_POOL_EXT"),
                Self::DESCRIPTOR_SET_EXT => Some("DESCRIPTOR_SET_EXT"),
                Self::FRAMEBUFFER_EXT => Some("FRAMEBUFFER_EXT"),
                Self::COMMAND_POOL_EXT => Some("COMMAND_POOL_EXT"),
                Self::SURFACE_KHR_EXT => Some("SURFACE_KHR_EXT"),
                Self::SWAPCHAIN_KHR_EXT => Some("SWAPCHAIN_KHR_EXT"),
                Self::DEBUG_REPORT_CALLBACK_EXT_EXT => Some("DEBUG_REPORT_CALLBACK_EXT_EXT"),
                Self::DISPLAY_KHR_EXT => Some("DISPLAY_KHR_EXT"),
                Self::DISPLAY_MODE_KHR_EXT => Some("DISPLAY_MODE_KHR_EXT"),
                Self::VALIDATION_CACHE_EXT_EXT => Some("VALIDATION_CACHE_EXT_EXT"),
                Self::SAMPLER_YCBCR_CONVERSION_EXT => Some("SAMPLER_YCBCR_CONVERSION_EXT"),
                Self::DESCRIPTOR_UPDATE_TEMPLATE_EXT => Some("DESCRIPTOR_UPDATE_TEMPLATE_EXT"),
                Self::BUFFER_COLLECTION_FUCHSIA_EXT => Some("BUFFER_COLLECTION_FUCHSIA_EXT"),
                Self::ACCELERATION_STRUCTURE_KHR_EXT => Some("ACCELERATION_STRUCTURE_KHR_EXT"),
                Self::CU_MODULE_NVX_EXT => Some("CU_MODULE_NVX_EXT"),
                Self::CU_FUNCTION_NVX_EXT => Some("CU_FUNCTION_NVX_EXT"),
                #[cfg(feature = "provisional")]
                Self::CUDA_MODULE_NV_EXT => Some("CUDA_MODULE_NV_EXT"),
                #[cfg(feature = "provisional")]
                Self::CUDA_FUNCTION_NV_EXT => Some("CUDA_FUNCTION_NV_EXT"),
                Self::ACCELERATION_STRUCTURE_NV_EXT => Some("ACCELERATION_STRUCTURE_NV_EXT"),
                _ => None,
            };
            if let Some(name) = name {
                f.write_str(name)
            } else {
                self.0.fmt(f)
            }
        }
    }

    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/VkDebugReportFlagsEXT.html>
    #[repr(transparent)]
    #[derive(Copy, Clone, PartialEq, Eq, Hash)]
    pub struct DebugReportFlagsEXT(Flags);
    vk_bitflags_wrapped!(DebugReportFlagsEXT, Flags, DebugReportFlagBitsEXT);

    impl fmt::Debug for DebugReportFlagsEXT {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            const KNOWN: &[(Flags, &str)] = &[
                (DebugReportFlagBitsEXT::INFORMATION_EXT.0, "INFORMATION_EXT"),
                (DebugReportFlagBitsEXT::WARNING_EXT.0, "WARNING_EXT"),
                (
                    DebugReportFlagBitsEXT::PERFORMANCE_WARNING_EXT.0,
                    "PERFORMANCE_WARNING_EXT",
                ),
                (DebugReportFlagBitsEXT::ERROR_EXT.0, "ERROR_EXT"),
                (DebugReportFlagBitsEXT::DEBUG_EXT.0, "DEBUG_EXT"),
            ];
            debug_flags(f, KNOWN, self.0)
        }
    }

    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/VkDebugReportFlagBitsEXT.html>
    #[repr(transparent)]
    #[derive(Copy, Clone, Default, PartialEq, Eq, Hash)]
    pub struct DebugReportFlagBitsEXT(u32);

    impl DebugReportFlagBitsEXT {
        pub const INFORMATION_EXT: Self = Self(1 << 0);
        pub const WARNING_EXT: Self = Self(1 << 1);
        pub const PERFORMANCE_WARNING_EXT: Self = Self(1 << 2);
        pub const ERROR_EXT: Self = Self(1 << 3);
        pub const DEBUG_EXT: Self = Self(1 << 4);
    }

    impl fmt::Debug for DebugReportFlagBitsEXT {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            let name = match *self {
                Self::INFORMATION_EXT => Some("INFORMATION_EXT"),
                Self::WARNING_EXT => Some("WARNING_EXT"),
                Self::PERFORMANCE_WARNING_EXT => Some("PERFORMANCE_WARNING_EXT"),
                Self::ERROR_EXT => Some("ERROR_EXT"),
                Self::DEBUG_EXT => Some("DEBUG_EXT"),
                _ => None,
            };
            if let Some(name) = name {
                f.write_str(name)
            } else {
                self.0.fmt(f)
            }
        }
    }

    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/PFN_vkDebugReportCallbackEXT.html>
    pub type PFN_vkDebugReportCallbackEXT = unsafe extern "system" fn(
        flags: DebugReportFlagsEXT,
        object_type: DebugReportObjectTypeEXT,
        object: u64,
        location: usize,
        message_code: i32,
        p_layer_prefix: *const c_char,
        p_message: *const c_char,
        p_user_data: *mut c_void,
    ) -> Bool32;

    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/vkCreateDebugReportCallbackEXT.html>
    pub type PFN_vkCreateDebugReportCallbackEXT = unsafe extern "system" fn(
        instance: Instance,
        p_create_info: *const DebugReportCallbackCreateInfoEXT<'_>,
        p_allocator: *const AllocationCallbacks<'_>,
        p_callback: *mut DebugReportCallbackEXT,
    ) -> vk::Result;
    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/vkDestroyDebugReportCallbackEXT.html>
    pub type PFN_vkDestroyDebugReportCallbackEXT = unsafe extern "system" fn(
        instance: Instance,
        callback: DebugReportCallbackEXT,
        p_allocator: *const AllocationCallbacks<'_>,
    );
    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/vkDebugReportMessageEXT.html>
    pub type PFN_vkDebugReportMessageEXT = unsafe extern "system" fn(
        instance: Instance,
        flags: DebugReportFlagsEXT,
        object_type: DebugReportObjectTypeEXT,
        object: u64,
        location: usize,
        message_code: i32,
        p_layer_prefix: *const c_char,
        p_message: *const c_char,
    );
}

#[cfg(feature = "ffi")]
pub(super) mod ffi {
    #![allow(non_camel_case_types)]
    use super::defs::*;

    pub type VkDebugReportCallbackEXT = DebugReportCallbackEXT;
    pub type VkDebugReportCallbackCreateInfoEXT = DebugReportCallbackCreateInfoEXT<'static>;
    pub type VkDebugReportObjectTypeEXT = DebugReportObjectTypeEXT;
    pub type VkDebugReportFlagsEXT = DebugReportFlagsEXT;
    pub type VkDebugReportFlagBitsEXT = DebugReportFlagBitsEXT;
    impl DebugReportCallbackCreateInfoEXT<'_> {
        #[inline]
        pub unsafe fn drop_lifetime_for_ffi(&self) -> &VkDebugReportCallbackCreateInfoEXT {
            unsafe { core::mem::transmute(self) }
        }
    }
}

pub struct InstanceFn {
    create_debug_report_callback: PFN_vkCreateDebugReportCallbackEXT,
    destroy_debug_report_callback: PFN_vkDestroyDebugReportCallbackEXT,
    debug_report_message: PFN_vkDebugReportMessageEXT,
}

impl LoadInstanceFn for InstanceFn {
    unsafe fn load_with(
        load: impl Fn(&CStr) -> Option<PFN_vkVoidFunction>,
    ) -> core::result::Result<Self, MissingEntryPointError> {
        unsafe {
            Ok(Self {
                create_debug_report_callback: transmute(
                    load(c"vkCreateDebugReportCallbackEXT").ok_or(MissingEntryPointError)?,
                ),
                destroy_debug_report_callback: transmute(
                    load(c"vkDestroyDebugReportCallbackEXT").ok_or(MissingEntryPointError)?,
                ),
                debug_report_message: transmute(
                    load(c"vkDebugReportMessageEXT").ok_or(MissingEntryPointError)?,
                ),
            })
        }
    }
}

impl InstanceFn {
    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/vkCreateDebugReportCallbackEXT.html>
    #[inline]
    pub unsafe fn create_debug_report_callback(
        &self,
        instance: Instance,
        create_info: &DebugReportCallbackCreateInfoEXT<'_>,
        allocator: Option<&AllocationCallbacks<'_>>,
    ) -> crate::Result<DebugReportCallbackEXT> {
        unsafe {
            let mut callback = core::mem::MaybeUninit::uninit();
            let result = (self.create_debug_report_callback)(
                instance,
                create_info,
                allocator.to_raw_ptr(),
                callback.as_mut_ptr(),
            );

            match result {
                VkResult::SUCCESS => Ok(callback.assume_init()),
                err => Err(err),
            }
        }
    }

    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/vkDestroyDebugReportCallbackEXT.html>
    #[inline]
    pub unsafe fn destroy_debug_report_callback(
        &self,
        instance: Instance,
        callback: DebugReportCallbackEXT,
        allocator: Option<&AllocationCallbacks<'_>>,
    ) {
        unsafe { (self.destroy_debug_report_callback)(instance, callback, allocator.to_raw_ptr()) }
    }

    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/vkDebugReportMessageEXT.html>
    #[inline]
    pub unsafe fn debug_report_message(
        &self,
        instance: Instance,
        flags: DebugReportFlagsEXT,
        object_type: DebugReportObjectTypeEXT,
        object: u64,
        location: usize,
        message_code: i32,
        layer_prefix: &CStr,
        message: &CStr,
    ) {
        unsafe {
            (self.debug_report_message)(
                instance,
                flags,
                object_type,
                object,
                location,
                message_code,
                layer_prefix.as_ptr() as _,
                message.as_ptr() as _,
            )
        }
    }
}