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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
//! <https://registry.khronos.org/vulkan/specs/latest/man/html/VK_KHR_performance_query.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_KHR_performance_query";

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;

    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/VkPhysicalDevicePerformanceQueryFeaturesKHR.html>
    #[repr(C)]
    #[derive(Copy, Clone)]
    #[must_use]
    pub struct PhysicalDevicePerformanceQueryFeaturesKHR<'a> {
        pub s_type: StructureType,
        pub p_next: *mut c_void,
        pub performance_counter_query_pools: Bool32,
        pub performance_counter_multiple_query_pools: Bool32,
        pub _marker: PhantomData<&'a ()>,
    }

    #[cfg(feature = "debug")]
    impl fmt::Debug for PhysicalDevicePerformanceQueryFeaturesKHR<'_> {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            f.debug_struct("PhysicalDevicePerformanceQueryFeaturesKHR")
                .field("s_type", &self.s_type)
                .field("p_next", &self.p_next)
                .field(
                    "performance_counter_query_pools",
                    &self.performance_counter_query_pools,
                )
                .field(
                    "performance_counter_multiple_query_pools",
                    &self.performance_counter_multiple_query_pools,
                )
                .finish()
        }
    }

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

    unsafe impl Extends<PhysicalDeviceFeatures2<'_>> for PhysicalDevicePerformanceQueryFeaturesKHR<'_> {}
    unsafe impl Extends<DeviceCreateInfo<'_>> for PhysicalDevicePerformanceQueryFeaturesKHR<'_> {}

    impl Default for PhysicalDevicePerformanceQueryFeaturesKHR<'_> {
        fn default() -> Self {
            Self {
                s_type: Self::STRUCTURE_TYPE,
                p_next: ptr::null_mut(),
                performance_counter_query_pools: Default::default(),
                performance_counter_multiple_query_pools: Default::default(),
                _marker: PhantomData,
            }
        }
    }

    impl<'a> PhysicalDevicePerformanceQueryFeaturesKHR<'a> {
        #[inline]
        pub fn performance_counter_query_pools(
            mut self,
            performance_counter_query_pools: bool,
        ) -> Self {
            self.performance_counter_query_pools = performance_counter_query_pools.into();
            self
        }

        #[inline]
        pub fn performance_counter_multiple_query_pools(
            mut self,
            performance_counter_multiple_query_pools: bool,
        ) -> Self {
            self.performance_counter_multiple_query_pools =
                performance_counter_multiple_query_pools.into();
            self
        }
    }

    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/VkPhysicalDevicePerformanceQueryPropertiesKHR.html>
    #[repr(C)]
    #[derive(Copy, Clone)]
    #[must_use]
    pub struct PhysicalDevicePerformanceQueryPropertiesKHR<'a> {
        pub s_type: StructureType,
        pub p_next: *mut c_void,
        pub allow_command_buffer_query_copies: Bool32,
        pub _marker: PhantomData<&'a ()>,
    }

    #[cfg(feature = "debug")]
    impl fmt::Debug for PhysicalDevicePerformanceQueryPropertiesKHR<'_> {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            f.debug_struct("PhysicalDevicePerformanceQueryPropertiesKHR")
                .field("s_type", &self.s_type)
                .field("p_next", &self.p_next)
                .field(
                    "allow_command_buffer_query_copies",
                    &self.allow_command_buffer_query_copies,
                )
                .finish()
        }
    }

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

    unsafe impl Extends<PhysicalDeviceProperties2<'_>>
        for PhysicalDevicePerformanceQueryPropertiesKHR<'_>
    {
    }

    impl Default for PhysicalDevicePerformanceQueryPropertiesKHR<'_> {
        fn default() -> Self {
            Self {
                s_type: Self::STRUCTURE_TYPE,
                p_next: ptr::null_mut(),
                allow_command_buffer_query_copies: Default::default(),
                _marker: PhantomData,
            }
        }
    }

    impl<'a> PhysicalDevicePerformanceQueryPropertiesKHR<'a> {
        #[inline]
        pub fn allow_command_buffer_query_copies(
            mut self,
            allow_command_buffer_query_copies: bool,
        ) -> Self {
            self.allow_command_buffer_query_copies = allow_command_buffer_query_copies.into();
            self
        }
    }

    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/VkPerformanceCounterKHR.html>
    #[repr(C)]
    #[derive(Copy, Clone)]
    #[must_use]
    pub struct PerformanceCounterKHR<'a> {
        pub s_type: StructureType,
        pub p_next: *mut c_void,
        pub unit: PerformanceCounterUnitKHR,
        pub scope: PerformanceCounterScopeKHR,
        pub storage: PerformanceCounterStorageKHR,
        pub uuid: [u8; UUID_SIZE as usize],
        pub _marker: PhantomData<&'a ()>,
    }

    #[cfg(feature = "debug")]
    impl fmt::Debug for PerformanceCounterKHR<'_> {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            f.debug_struct("PerformanceCounterKHR")
                .field("s_type", &self.s_type)
                .field("p_next", &self.p_next)
                .field("unit", &self.unit)
                .field("scope", &self.scope)
                .field("storage", &self.storage)
                .field("uuid", &self.uuid)
                .finish()
        }
    }

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

    impl Default for PerformanceCounterKHR<'_> {
        fn default() -> Self {
            Self {
                s_type: Self::STRUCTURE_TYPE,
                p_next: ptr::null_mut(),
                unit: Default::default(),
                scope: Default::default(),
                storage: Default::default(),
                uuid: [Default::default(); _],
                _marker: PhantomData,
            }
        }
    }

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

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

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

        #[inline]
        pub fn uuid(mut self, uuid: [u8; UUID_SIZE as usize]) -> Self {
            self.uuid = uuid;
            self
        }
    }

    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/VkPerformanceCounterDescriptionKHR.html>
    #[repr(C)]
    #[derive(Copy, Clone)]
    #[must_use]
    pub struct PerformanceCounterDescriptionKHR<'a> {
        pub s_type: StructureType,
        pub p_next: *mut c_void,
        pub flags: PerformanceCounterDescriptionFlagsKHR,
        pub name: ArrayCStr<{ MAX_DESCRIPTION_SIZE as usize }>,
        pub category: ArrayCStr<{ MAX_DESCRIPTION_SIZE as usize }>,
        pub description: ArrayCStr<{ MAX_DESCRIPTION_SIZE as usize }>,
        pub _marker: PhantomData<&'a ()>,
    }

    #[cfg(feature = "debug")]
    impl fmt::Debug for PerformanceCounterDescriptionKHR<'_> {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            f.debug_struct("PerformanceCounterDescriptionKHR")
                .field("s_type", &self.s_type)
                .field("p_next", &self.p_next)
                .field("flags", &self.flags)
                .field("name", &self.name)
                .field("category", &self.category)
                .field("description", &self.description)
                .finish()
        }
    }

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

    impl Default for PerformanceCounterDescriptionKHR<'_> {
        fn default() -> Self {
            Self {
                s_type: Self::STRUCTURE_TYPE,
                p_next: ptr::null_mut(),
                flags: Default::default(),
                name: Default::default(),
                category: Default::default(),
                description: Default::default(),
                _marker: PhantomData,
            }
        }
    }

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

        #[inline]
        pub fn name(
            mut self,
            name: &CStr,
        ) -> core::result::Result<Self, CStrTooLargeForStaticArray> {
            self.name.write_c_str(name)?;
            Ok(self)
        }

        #[inline]
        pub fn category(
            mut self,
            category: &CStr,
        ) -> core::result::Result<Self, CStrTooLargeForStaticArray> {
            self.category.write_c_str(category)?;
            Ok(self)
        }

        #[inline]
        pub fn description(
            mut self,
            description: &CStr,
        ) -> core::result::Result<Self, CStrTooLargeForStaticArray> {
            self.description.write_c_str(description)?;
            Ok(self)
        }
    }

    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/VkQueryPoolPerformanceCreateInfoKHR.html>
    #[repr(C)]
    #[derive(Copy, Clone)]
    #[must_use]
    pub struct QueryPoolPerformanceCreateInfoKHR<'a> {
        pub s_type: StructureType,
        pub p_next: *const c_void,
        pub queue_family_index: u32,
        pub counter_index_count: u32,
        pub p_counter_indices: *const u32,
        pub _marker: PhantomData<&'a ()>,
    }

    #[cfg(feature = "debug")]
    impl fmt::Debug for QueryPoolPerformanceCreateInfoKHR<'_> {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            f.debug_struct("QueryPoolPerformanceCreateInfoKHR")
                .field("s_type", &self.s_type)
                .field("p_next", &self.p_next)
                .field("queue_family_index", &self.queue_family_index)
                .field("counter_index_count", &self.counter_index_count)
                .field("p_counter_indices", &self.p_counter_indices)
                .finish()
        }
    }

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

    unsafe impl Extends<QueryPoolCreateInfo<'_>> for QueryPoolPerformanceCreateInfoKHR<'_> {}

    impl Default for QueryPoolPerformanceCreateInfoKHR<'_> {
        fn default() -> Self {
            Self {
                s_type: Self::STRUCTURE_TYPE,
                p_next: ptr::null(),
                queue_family_index: Default::default(),
                counter_index_count: Default::default(),
                p_counter_indices: ptr::null(),
                _marker: PhantomData,
            }
        }
    }

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

        #[inline]
        pub fn counter_indices(mut self, counter_indices: &'a [u32]) -> Self {
            self.counter_index_count = counter_indices.len().try_into().unwrap();
            self.p_counter_indices = counter_indices.as_ptr() as _;
            self
        }
    }

    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/VkAcquireProfilingLockInfoKHR.html>
    #[repr(C)]
    #[derive(Copy, Clone)]
    #[must_use]
    pub struct AcquireProfilingLockInfoKHR<'a> {
        pub s_type: StructureType,
        pub p_next: *const c_void,
        pub flags: AcquireProfilingLockFlagsKHR,
        pub timeout: u64,
        pub _marker: PhantomData<&'a ()>,
    }

    #[cfg(feature = "debug")]
    impl fmt::Debug for AcquireProfilingLockInfoKHR<'_> {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            f.debug_struct("AcquireProfilingLockInfoKHR")
                .field("s_type", &self.s_type)
                .field("p_next", &self.p_next)
                .field("flags", &self.flags)
                .field("timeout", &self.timeout)
                .finish()
        }
    }

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

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

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

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

    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/VkPerformanceQuerySubmitInfoKHR.html>
    #[repr(C)]
    #[derive(Copy, Clone)]
    #[must_use]
    pub struct PerformanceQuerySubmitInfoKHR<'a> {
        pub s_type: StructureType,
        pub p_next: *const c_void,
        pub counter_pass_index: u32,
        pub _marker: PhantomData<&'a ()>,
    }

    #[cfg(feature = "debug")]
    impl fmt::Debug for PerformanceQuerySubmitInfoKHR<'_> {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            f.debug_struct("PerformanceQuerySubmitInfoKHR")
                .field("s_type", &self.s_type)
                .field("p_next", &self.p_next)
                .field("counter_pass_index", &self.counter_pass_index)
                .finish()
        }
    }

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

    unsafe impl Extends<SubmitInfo<'_>> for PerformanceQuerySubmitInfoKHR<'_> {}
    unsafe impl Extends<SubmitInfo2<'_>> for PerformanceQuerySubmitInfoKHR<'_> {}

    impl Default for PerformanceQuerySubmitInfoKHR<'_> {
        fn default() -> Self {
            Self {
                s_type: Self::STRUCTURE_TYPE,
                p_next: ptr::null(),
                counter_pass_index: Default::default(),
                _marker: PhantomData,
            }
        }
    }

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

    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/VkPerformanceCounterResultKHR.html>
    #[repr(C)]
    #[derive(Copy, Clone)]
    pub union PerformanceCounterResultKHR {
        pub int32: i32,
        pub int64: i64,
        pub uint32: u32,
        pub uint64: u64,
        pub float32: f32,
        pub float64: f64,
    }

    #[cfg(feature = "debug")]
    impl fmt::Debug for PerformanceCounterResultKHR {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            f.debug_struct("PerformanceCounterResultKHR").finish()
        }
    }

    impl Default for PerformanceCounterResultKHR {
        fn default() -> Self {
            unsafe { core::mem::zeroed() }
        }
    }

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

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

        pub const COMMAND_BUFFER_KHR: Self = Self(0);
        pub const RENDER_PASS_KHR: Self = Self(1);
        pub const COMMAND_KHR: Self = Self(2);
    }

    impl fmt::Debug for PerformanceCounterScopeKHR {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            let name = match *self {
                Self::COMMAND_BUFFER_KHR => Some("COMMAND_BUFFER_KHR"),
                Self::RENDER_PASS_KHR => Some("RENDER_PASS_KHR"),
                Self::COMMAND_KHR => Some("COMMAND_KHR"),
                _ => None,
            };
            if let Some(name) = name {
                f.write_str(name)
            } else {
                self.0.fmt(f)
            }
        }
    }

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

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

        pub const GENERIC_KHR: Self = Self(0);
        pub const PERCENTAGE_KHR: Self = Self(1);
        pub const NANOSECONDS_KHR: Self = Self(2);
        pub const BYTES_KHR: Self = Self(3);
        pub const BYTES_PER_SECOND_KHR: Self = Self(4);
        pub const KELVIN_KHR: Self = Self(5);
        pub const WATTS_KHR: Self = Self(6);
        pub const VOLTS_KHR: Self = Self(7);
        pub const AMPS_KHR: Self = Self(8);
        pub const HERTZ_KHR: Self = Self(9);
        pub const CYCLES_KHR: Self = Self(10);
    }

    impl fmt::Debug for PerformanceCounterUnitKHR {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            let name = match *self {
                Self::GENERIC_KHR => Some("GENERIC_KHR"),
                Self::PERCENTAGE_KHR => Some("PERCENTAGE_KHR"),
                Self::NANOSECONDS_KHR => Some("NANOSECONDS_KHR"),
                Self::BYTES_KHR => Some("BYTES_KHR"),
                Self::BYTES_PER_SECOND_KHR => Some("BYTES_PER_SECOND_KHR"),
                Self::KELVIN_KHR => Some("KELVIN_KHR"),
                Self::WATTS_KHR => Some("WATTS_KHR"),
                Self::VOLTS_KHR => Some("VOLTS_KHR"),
                Self::AMPS_KHR => Some("AMPS_KHR"),
                Self::HERTZ_KHR => Some("HERTZ_KHR"),
                Self::CYCLES_KHR => Some("CYCLES_KHR"),
                _ => None,
            };
            if let Some(name) = name {
                f.write_str(name)
            } else {
                self.0.fmt(f)
            }
        }
    }

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

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

        pub const INT32_KHR: Self = Self(0);
        pub const INT64_KHR: Self = Self(1);
        pub const UINT32_KHR: Self = Self(2);
        pub const UINT64_KHR: Self = Self(3);
        pub const FLOAT32_KHR: Self = Self(4);
        pub const FLOAT64_KHR: Self = Self(5);
    }

    impl fmt::Debug for PerformanceCounterStorageKHR {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            let name = match *self {
                Self::INT32_KHR => Some("INT32_KHR"),
                Self::INT64_KHR => Some("INT64_KHR"),
                Self::UINT32_KHR => Some("UINT32_KHR"),
                Self::UINT64_KHR => Some("UINT64_KHR"),
                Self::FLOAT32_KHR => Some("FLOAT32_KHR"),
                Self::FLOAT64_KHR => Some("FLOAT64_KHR"),
                _ => None,
            };
            if let Some(name) = name {
                f.write_str(name)
            } else {
                self.0.fmt(f)
            }
        }
    }

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

    impl fmt::Debug for PerformanceCounterDescriptionFlagsKHR {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            const KNOWN: &[(Flags, &str)] = &[
                (
                    PerformanceCounterDescriptionFlagBitsKHR::PERFORMANCE_IMPACTING_KHR.0,
                    "PERFORMANCE_IMPACTING_KHR",
                ),
                (
                    PerformanceCounterDescriptionFlagBitsKHR::CONCURRENTLY_IMPACTED_KHR.0,
                    "CONCURRENTLY_IMPACTED_KHR",
                ),
            ];
            debug_flags(f, KNOWN, self.0)
        }
    }

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

    impl PerformanceCounterDescriptionFlagBitsKHR {
        pub const PERFORMANCE_IMPACTING_KHR: Self = Self(1 << 0);
        pub const CONCURRENTLY_IMPACTED_KHR: Self = Self(1 << 1);
    }

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

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

    impl fmt::Debug for AcquireProfilingLockFlagsKHR {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            const KNOWN: &[(Flags, &str)] = &[];
            debug_flags(f, KNOWN, self.0)
        }
    }

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

    impl AcquireProfilingLockFlagBitsKHR {}

    impl fmt::Debug for AcquireProfilingLockFlagBitsKHR {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            let name = match *self {
                _ => None,
            };
            if let Some(name) = name {
                f.write_str(name)
            } else {
                self.0.fmt(f)
            }
        }
    }

    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR.html>
    pub type PFN_vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR =
        unsafe extern "system" fn(
            physical_device: PhysicalDevice,
            queue_family_index: u32,
            p_counter_count: *mut u32,
            p_counters: *mut PerformanceCounterKHR<'_>,
            p_counter_descriptions: *mut PerformanceCounterDescriptionKHR<'_>,
        ) -> vk::Result;
    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR.html>
    pub type PFN_vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR =
        unsafe extern "system" fn(
            physical_device: PhysicalDevice,
            p_performance_query_create_info: *const QueryPoolPerformanceCreateInfoKHR<'_>,
            p_num_passes: *mut u32,
        );
    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/vkAcquireProfilingLockKHR.html>
    pub type PFN_vkAcquireProfilingLockKHR = unsafe extern "system" fn(
        device: Device,
        p_info: *const AcquireProfilingLockInfoKHR<'_>,
    ) -> vk::Result;
    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/vkReleaseProfilingLockKHR.html>
    pub type PFN_vkReleaseProfilingLockKHR = unsafe extern "system" fn(device: Device);
}

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

    pub type VkPhysicalDevicePerformanceQueryFeaturesKHR =
        PhysicalDevicePerformanceQueryFeaturesKHR<'static>;
    pub type VkPhysicalDevicePerformanceQueryPropertiesKHR =
        PhysicalDevicePerformanceQueryPropertiesKHR<'static>;
    pub type VkPerformanceCounterKHR = PerformanceCounterKHR<'static>;
    pub type VkPerformanceCounterDescriptionKHR = PerformanceCounterDescriptionKHR<'static>;
    pub type VkQueryPoolPerformanceCreateInfoKHR = QueryPoolPerformanceCreateInfoKHR<'static>;
    pub type VkAcquireProfilingLockInfoKHR = AcquireProfilingLockInfoKHR<'static>;
    pub type VkPerformanceQuerySubmitInfoKHR = PerformanceQuerySubmitInfoKHR<'static>;
    pub type VkPerformanceCounterResultKHR = PerformanceCounterResultKHR;
    pub type VkPerformanceCounterScopeKHR = PerformanceCounterScopeKHR;
    pub type VkPerformanceCounterUnitKHR = PerformanceCounterUnitKHR;
    pub type VkPerformanceCounterStorageKHR = PerformanceCounterStorageKHR;
    pub type VkPerformanceCounterDescriptionFlagsKHR = PerformanceCounterDescriptionFlagsKHR;
    pub type VkPerformanceCounterDescriptionFlagBitsKHR = PerformanceCounterDescriptionFlagBitsKHR;
    pub type VkAcquireProfilingLockFlagsKHR = AcquireProfilingLockFlagsKHR;
    pub type VkAcquireProfilingLockFlagBitsKHR = AcquireProfilingLockFlagBitsKHR;
    impl PhysicalDevicePerformanceQueryFeaturesKHR<'_> {
        #[inline]
        pub unsafe fn drop_lifetime_for_ffi(&self) -> &VkPhysicalDevicePerformanceQueryFeaturesKHR {
            unsafe { core::mem::transmute(self) }
        }
    }
    impl PhysicalDevicePerformanceQueryPropertiesKHR<'_> {
        #[inline]
        pub unsafe fn drop_lifetime_for_ffi(
            &self,
        ) -> &VkPhysicalDevicePerformanceQueryPropertiesKHR {
            unsafe { core::mem::transmute(self) }
        }
    }
    impl PerformanceCounterKHR<'_> {
        #[inline]
        pub unsafe fn drop_lifetime_for_ffi(&self) -> &VkPerformanceCounterKHR {
            unsafe { core::mem::transmute(self) }
        }
    }
    impl PerformanceCounterDescriptionKHR<'_> {
        #[inline]
        pub unsafe fn drop_lifetime_for_ffi(&self) -> &VkPerformanceCounterDescriptionKHR {
            unsafe { core::mem::transmute(self) }
        }
    }
    impl QueryPoolPerformanceCreateInfoKHR<'_> {
        #[inline]
        pub unsafe fn drop_lifetime_for_ffi(&self) -> &VkQueryPoolPerformanceCreateInfoKHR {
            unsafe { core::mem::transmute(self) }
        }
    }
    impl AcquireProfilingLockInfoKHR<'_> {
        #[inline]
        pub unsafe fn drop_lifetime_for_ffi(&self) -> &VkAcquireProfilingLockInfoKHR {
            unsafe { core::mem::transmute(self) }
        }
    }
    impl PerformanceQuerySubmitInfoKHR<'_> {
        #[inline]
        pub unsafe fn drop_lifetime_for_ffi(&self) -> &VkPerformanceQuerySubmitInfoKHR {
            unsafe { core::mem::transmute(self) }
        }
    }
}

pub struct InstanceFn {
    enumerate_physical_device_queue_family_performance_query_counters:
        PFN_vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR,
    get_physical_device_queue_family_performance_query_passes:
        PFN_vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR,
}

impl LoadInstanceFn for InstanceFn {
    unsafe fn load_with(
        load: impl Fn(&CStr) -> Option<PFN_vkVoidFunction>,
    ) -> core::result::Result<Self, MissingEntryPointError> {
        unsafe {
            Ok(Self {
                enumerate_physical_device_queue_family_performance_query_counters: transmute(
                    load(c"vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR")
                        .ok_or(MissingEntryPointError)?,
                ),
                get_physical_device_queue_family_performance_query_passes: transmute(
                    load(c"vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR")
                        .ok_or(MissingEntryPointError)?,
                ),
            })
        }
    }
}

impl InstanceFn {
    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR.html>
    #[inline]
    pub unsafe fn enumerate_physical_device_queue_family_performance_query_counters<'a>(
        &self,
        physical_device: PhysicalDevice,
        queue_family_index: u32,
        mut counters: impl EnumerateInto<PerformanceCounterKHR<'a>>,
        mut counter_descriptions: impl EnumerateInto<PerformanceCounterDescriptionKHR<'a>>,
    ) -> crate::Result<()> {
        unsafe {
            let call = |counter_count, counters, counter_descriptions| {
                let result = (self
                    .enumerate_physical_device_queue_family_performance_query_counters)(
                    physical_device,
                    queue_family_index,
                    counter_count,
                    counters as _,
                    counter_descriptions as _,
                );

                match result {
                    VkResult::SUCCESS => Ok(()),
                    VkResult::INCOMPLETE => Ok(()),
                    err => Err(err),
                }
            };
            let mut len = 0;
            call(&mut len, std::ptr::null_mut(), std::ptr::null_mut())?;
            let capacity = len.try_into().expect("failed to convert `N` to usize");
            let counters_buf = counters.reserve(capacity);
            len = counters_buf.len().try_into().unwrap();
            let counter_descriptions_buf = counter_descriptions.reserve(capacity);
            assert_eq!(counter_descriptions_buf.len(), counters_buf.len());
            let result = call(
                &mut len,
                counters_buf.as_mut_ptr() as *mut _,
                counter_descriptions_buf.as_mut_ptr() as *mut _,
            )?;
            counters.set_len(len.try_into().unwrap());
            counter_descriptions.set_len(len.try_into().unwrap());
            Ok(result)
        }
    }

    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR.html>
    #[inline]
    pub unsafe fn get_physical_device_queue_family_performance_query_passes(
        &self,
        physical_device: PhysicalDevice,
        performance_query_create_info: &QueryPoolPerformanceCreateInfoKHR<'_>,
    ) -> u32 {
        unsafe {
            let mut num_passes = core::mem::MaybeUninit::uninit();
            (self.get_physical_device_queue_family_performance_query_passes)(
                physical_device,
                performance_query_create_info,
                num_passes.as_mut_ptr(),
            );
            num_passes.assume_init()
        }
    }
}

pub struct DeviceFn {
    acquire_profiling_lock: PFN_vkAcquireProfilingLockKHR,
    release_profiling_lock: PFN_vkReleaseProfilingLockKHR,
}

impl LoadDeviceFn for DeviceFn {
    unsafe fn load_with(
        load: impl Fn(&CStr) -> Option<PFN_vkVoidFunction>,
    ) -> core::result::Result<Self, MissingEntryPointError> {
        unsafe {
            Ok(Self {
                acquire_profiling_lock: transmute(
                    load(c"vkAcquireProfilingLockKHR").ok_or(MissingEntryPointError)?,
                ),
                release_profiling_lock: transmute(
                    load(c"vkReleaseProfilingLockKHR").ok_or(MissingEntryPointError)?,
                ),
            })
        }
    }
}

impl DeviceFn {
    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/vkAcquireProfilingLockKHR.html>
    #[inline]
    pub unsafe fn acquire_profiling_lock(
        &self,
        device: Device,
        info: &AcquireProfilingLockInfoKHR<'_>,
    ) -> crate::Result<()> {
        unsafe {
            let result = (self.acquire_profiling_lock)(device, info);

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

    /// <https://registry.khronos.org/vulkan/specs/latest/man/html/vkReleaseProfilingLockKHR.html>
    #[inline]
    pub unsafe fn release_profiling_lock(&self, device: Device) {
        unsafe { (self.release_profiling_lock)(device) }
    }
}