Skip to main content

bedrock/
base.rs

1//! Vulkan Base Objects(Instance/PhysicalDevice)
2
3use crate::error::translate_vk_result;
4use crate::ffi_helper::{CStrFFIRef, slice_as_ptr_empty_null};
5use crate::*;
6use bedrock_vk::{self as brvk, TypedVulkanStructure};
7use core::ffi::CStr;
8use derives::implements;
9
10#[cfg(feature = "Multithreaded")]
11struct LazyCellReadRef<'d, T>(::std::sync::RwLockReadGuard<'d, Option<T>>);
12#[cfg(feature = "Multithreaded")]
13impl<'d, T> ::std::ops::Deref for LazyCellReadRef<'d, T> {
14    type Target = T;
15    fn deref(&self) -> &T {
16        self.0.as_ref().unwrap()
17    }
18}
19
20/// A Value Object represents the Vulkan version number
21// Note: (MSB) major | minor | patch (LSB) の順でビットが割り当てられているので合成した状態の比較で正しい順序になる
22#[repr(transparent)]
23#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
24pub struct Version(u32);
25impl Version {
26    /// Version 1.0.0
27    pub const V1: Self = Self::new(1, 0, 0);
28
29    /// Construct an object from discrete values
30    #[inline(always)]
31    pub const fn new(major: u16, minor: u16, patch: u16) -> Self {
32        Self::with_variant(0, major, minor, patch)
33    }
34
35    /// Construct an object from discrete values
36    pub const fn with_variant(variant: u8, major: u16, minor: u16, patch: u16) -> Self {
37        Self(brvk::VK_MAKE_VERSION(variant, major, minor, patch))
38    }
39
40    /// Construct an object from a raw value
41    pub const fn from_raw(v: u32) -> Self {
42        Self(v)
43    }
44
45    /// Gets a raw value from this object
46    pub const fn raw(&self) -> u32 {
47        self.0
48    }
49
50    /// Version variant number
51    pub const fn variant(&self) -> u8 {
52        brvk::VK_VARIANT_VERSION(self.0)
53    }
54
55    /// Major version number
56    pub const fn major(&self) -> u16 {
57        brvk::VK_MAJOR_VERSION(self.0)
58    }
59
60    /// Minor version number
61    pub const fn minor(&self) -> u16 {
62        brvk::VK_MINOR_VERSION(self.0)
63    }
64
65    /// Patch version number
66    pub const fn patch(&self) -> u16 {
67        brvk::VK_PATCH_VERSION(self.0)
68    }
69}
70impl core::fmt::Display for Version {
71    #[inline]
72    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
73        // TODO: Variantを含めたバージョン表示
74        write!(f, "{}.{}.{}", self.major(), self.minor(), self.patch())
75    }
76}
77
78/// Query instance-level version before instance creation
79/// # Failures
80/// On failure, this command returns
81///
82/// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
83#[inline]
84#[implements]
85pub fn instance_version() -> crate::Result<Version> {
86    #[cfg(feature = "Allow1_1APIs")]
87    unsafe {
88        use crate::error::translate_vk_result;
89
90        let mut sink = 0;
91        translate_vk_result(brvk::fns::enumerate_instance_version(&mut sink))?;
92        Ok(Version(sink))
93    }
94    #[cfg(not(feature = "Allow1_1APIs"))]
95    {
96        // fixed to v1.0.0
97        Ok(Version::V1)
98    }
99}
100
101/// Returns up to all of global layer properties
102/// # Failures
103/// On failure, this command returns
104///
105/// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
106/// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
107#[implements("alloc")]
108pub fn instance_layer_properties_alloc() -> crate::Result<Vec<brvk::VkLayerProperties>> {
109    let n = crate::vkfn_wrapper::instance_layer_property_count()?;
110    if n == 0 {
111        // no items
112        return Ok(crate::alloc::empty_sink_buffer());
113    }
114
115    let mut xs = crate::alloc::reserve(n as _);
116    let r = crate::vkfn_wrapper::instance_layer_properties(xs.spare_capacity_mut())?.assert_complete();
117    unsafe {
118        xs.set_len(r as _);
119    }
120
121    Ok(xs)
122}
123
124/// Returns up to all of global extension properties
125/// # Failures
126/// On failure, this command returns
127///
128/// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
129/// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
130/// * `brvk::VK_ERROR_LAYER_NOT_PRESENT`
131#[implements("alloc")]
132pub fn instance_extension_properties_alloc(
133    layer_name: Option<&CStr>,
134) -> crate::Result<Vec<brvk::VkExtensionProperties>> {
135    let n = crate::vkfn_wrapper::instance_extension_property_count(layer_name)? as usize;
136    if n == 0 {
137        // no items
138        return Ok(crate::alloc::empty_sink_buffer());
139    }
140
141    let mut xs = crate::alloc::reserve(n);
142    let r = crate::vkfn_wrapper::instance_extension_properties(layer_name, xs.spare_capacity_mut())?.assert_complete();
143    unsafe {
144        xs.set_len(r as _);
145    }
146
147    Ok(xs)
148}
149
150/// Returns up to all of global extension properties
151/// # Failures
152/// On failure, this command returns
153///
154/// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
155/// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
156/// * `brvk::VK_ERROR_LAYER_NOT_PRESENT`
157#[implements("alloc")]
158pub fn instance_extension_properties_str_alloc(
159    layer_name: Option<&str>,
160) -> crate::Result<Vec<brvk::VkExtensionProperties>> {
161    instance_extension_properties_alloc(layer_name.map(|s| crate::alloc::str_to_cstr(s).unwrap()).as_deref())
162}
163
164#[implements]
165type InstanceResolvedFn<F> = brvk::ResolvedFnCell<F, InstanceResolverImpl>;
166#[implements]
167#[repr(transparent)]
168pub struct InstanceResolverImpl(pub brvk::VkInstance);
169#[implements]
170impl brvk::ResolverInterface for InstanceResolverImpl {
171    #[tracing::instrument(
172        name = "<brvk::VkInstance as ResolverInterface>::load_symbol_unconstrainted",
173        skip(self)
174    )]
175    unsafe fn load_symbol_unconstrainted(&self, name: &core::ffi::CStr) -> core::ptr::NonNull<core::ffi::c_void> {
176        match unsafe { brvk::fns::get_instance_proc_addr(self.0, name.as_ptr().cast()) } {
177            Some(x) => unsafe { core::ptr::NonNull::new_unchecked(x as _) },
178            None => {
179                tracing::error!("instance function not found, bedrock could not continue");
180                std::process::abort();
181            }
182        }
183    }
184
185    #[tracing::instrument(
186        name = "<brvk::VkInstance as ResolverInterface>::load_function_unconstrainted",
187        skip(self)
188    )]
189    unsafe fn load_function_unconstrainted(&self, name: &core::ffi::CStr) -> brvk::PFN_vkVoidFunction {
190        match unsafe { brvk::fns::get_instance_proc_addr(self.0, name.as_ptr().cast()) } {
191            Some(x) => x,
192            None => {
193                tracing::error!("instance function not found, bedrock could not continue");
194                std::process::abort();
195            }
196        }
197    }
198}
199
200#[repr(transparent)]
201pub struct ApplicationInfo<'d>(brvk::VkApplicationInfo, core::marker::PhantomData<&'d CStr>);
202impl<'d> ApplicationInfo<'d> {
203    #[inline(always)]
204    pub const fn new(app_name: &'d CStr, app_version: Version, engine_name: &'d CStr, engine_version: Version) -> Self {
205        Self(
206            brvk::VkApplicationInfo {
207                sType: brvk::VkApplicationInfo::TYPE,
208                pNext: core::ptr::null(),
209                apiVersion: brvk::VK_API_VERSION_1_0,
210                pApplicationName: app_name.as_ptr(),
211                applicationVersion: app_version.0,
212                pEngineName: engine_name.as_ptr(),
213                engineVersion: engine_version.0,
214            },
215            core::marker::PhantomData,
216        )
217    }
218
219    #[inline(always)]
220    pub const fn api_version(mut self, version: Version) -> Self {
221        self.0.apiVersion = version.0;
222        self
223    }
224}
225
226#[derive(Debug, Clone, Copy, PartialEq, Eq)]
227#[bitflags_newtype]
228pub struct InstanceCreateFlags(brvk::VkInstanceCreateFlags);
229impl InstanceCreateFlags {
230    /// Empty bits.
231    pub const EMPTY: Self = Self(0);
232
233    #[cfg(feature = "VK_KHR_portability_enumeration")]
234    /// The instance will enumerate available Vulkan Portability-compliant physical devices and groups
235    /// in addition to the Vulkan physical devices and groups that are enumerated by default.
236    pub const ENUMERATE_PORTABILITY: Self = Self(brvk::VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR);
237}
238
239#[repr(transparent)]
240#[derive(Clone)]
241pub struct InstanceCreateInfo<'d>(
242    brvk::VkInstanceCreateInfo,
243    core::marker::PhantomData<(
244        Option<&'d dyn brvk::VulkanStructure>,
245        &'d ApplicationInfo<'d>,
246        &'d [CStrFFIRef<'d>],
247    )>,
248);
249impl<'d> InstanceCreateInfo<'d> {
250    pub const fn new(
251        application_info: &'d ApplicationInfo<'d>,
252        layers: &'d [CStrFFIRef<'d>],
253        extensions: &'d [CStrFFIRef<'d>],
254    ) -> Self {
255        Self(
256            brvk::VkInstanceCreateInfo {
257                sType: brvk::VkInstanceCreateInfo::TYPE,
258                pNext: core::ptr::null(),
259                flags: 0,
260                pApplicationInfo: core::ptr::from_ref(application_info).cast(),
261                enabledLayerCount: layers.len() as _,
262                ppEnabledLayerNames: slice_as_ptr_empty_null(layers) as _,
263                enabledExtensionCount: extensions.len() as _,
264                ppEnabledExtensionNames: slice_as_ptr_empty_null(extensions) as _,
265            },
266            core::marker::PhantomData,
267        )
268    }
269
270    /// # Safety
271    ///
272    /// raw must be a valid brvk::VkInstanceCreateInfo struct.
273    pub const unsafe fn from_raw(raw: brvk::VkInstanceCreateInfo) -> Self {
274        Self(raw, core::marker::PhantomData)
275    }
276
277    pub const fn into_raw(self) -> brvk::VkInstanceCreateInfo {
278        self.0
279    }
280
281    #[inline(always)]
282    pub fn with_next(mut self, next: &'d (impl brvk::VulkanStructure + ?Sized)) -> Self {
283        self.0.pNext = next.as_generic() as *const _ as _;
284        self
285    }
286
287    pub const fn flags(mut self, flags: InstanceCreateFlags) -> Self {
288        self.0.flags = flags.bits();
289        self
290    }
291}
292
293/// Opaque handle to a instance object
294#[derive(VkHandle, VkObject)]
295#[VkObject(type = brvk::VK_OBJECT_TYPE_INSTANCE)]
296pub struct InstanceObject {
297    #[handle]
298    handle: brvk::VkInstance,
299    #[cfg(feature = "Implements")]
300    ext: InstanceExtFunctions,
301}
302unsafe impl Sync for InstanceObject {}
303unsafe impl Send for InstanceObject {}
304#[implements]
305impl Drop for InstanceObject {
306    #[inline(always)]
307    fn drop(&mut self) {
308        crate::vkfn_wrapper::destroy_instance(self.as_transparent_ref_mut(), None);
309    }
310}
311impl Instance for InstanceObject {}
312impl InstanceObject {
313    /// Create a new Vulkan instance
314    /// # Failures
315    /// On failure, this command returns
316    ///
317    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
318    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
319    /// * `brvk::VK_ERROR_INITIALIZATION_FAILED`
320    /// * `brvk::VK_ERROR_LAYER_NOT_PRESENT`
321    /// * `brvk::VK_ERROR_EXTENSION_NOT_PRESENT`
322    /// * `brvk::VK_ERROR_INCOMPATIBLE_DRIVER`
323    #[implements]
324    #[inline]
325    pub fn new(info: &InstanceCreateInfo) -> crate::Result<Self> {
326        Ok(unsafe { Self::manage(crate::vkfn_wrapper::create_instance(info, None)?) })
327    }
328
329    /// Constructs from raw handle
330    /// # Safety
331    /// the handle must be valid and not freed
332    pub const unsafe fn manage(handle: brvk::VkInstance) -> Self {
333        Self {
334            handle,
335            #[cfg(feature = "Implements")]
336            ext: InstanceExtFunctions::new(handle),
337        }
338    }
339
340    /// Purges internal values (Drop will not be called for this resource)
341    pub const fn unmanage(self) -> brvk::VkInstance {
342        let v = self.handle;
343        core::mem::forget(self);
344
345        v
346    }
347}
348
349/// A Vulkan Instance interface
350pub trait Instance: VkHandle<Handle = brvk::VkInstance> {
351    /// Return a function pointer for a command
352    #[deprecated = "do not use this directly(this does not provide caching!)"]
353    #[implements]
354    #[inline]
355    fn extra_procedure(&self, name: &CStr) -> Option<brvk::PFN_vkVoidFunction> {
356        unsafe { brvk::fns::get_instance_proc_addr(self.native_ptr(), name.as_ptr()) }
357    }
358
359    /// Counts the physical devices accessible to a Vulkan instance
360    /// # Failures
361    /// On failure, this command returns
362    ///
363    /// * [`brvk::VK_ERROR_OUT_OF_HOST_MEMORY`]
364    /// * [`brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`]
365    /// * [`brvk::VK_ERROR_INITIALIZATION_FAILED`]
366    #[implements]
367    #[inline(always)]
368    fn physical_device_count(&self) -> crate::Result<u32> {
369        crate::vkfn_wrapper::physical_device_count(self.as_transparent_ref())
370    }
371
372    /// Enumerates the physical devices accessible to a Vulkan instance
373    /// # Failures
374    /// On failure, this command returns
375    ///
376    /// * [`brvk::VK_ERROR_OUT_OF_HOST_MEMORY`]
377    /// * [`brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`]
378    /// * [`brvk::VK_ERROR_INITIALIZATION_FAILED`]
379    #[implements]
380    #[inline(always)]
381    fn enumerate_physical_devices(
382        &self,
383        sink: &mut [core::mem::MaybeUninit<brvk::VkPhysicalDevice>],
384    ) -> crate::Result<ArrayQueryResult<u32>> {
385        crate::vkfn_wrapper::enumerate_physical_devices(self.as_transparent_ref(), sink)
386    }
387
388    /// Lazyly enumerates the physical devices accessible to a Vulkan instance
389    ///
390    /// # Failures
391    ///
392    /// On failure, this command returns
393    ///
394    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
395    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
396    /// * `brvk::VK_ERROR_INITIALIZATION_FAILED`
397    #[implements("alloc")]
398    fn iter_physical_devices<'a>(&'a self) -> crate::Result<IterPhysicalDevices<'a, Self>> {
399        let n = self.physical_device_count()? as usize;
400        if n == 0 {
401            // no items
402            return Ok(IterPhysicalDevices(crate::alloc::empty_sink_buffer(), 0, self));
403        }
404
405        let mut xs = Vec::with_capacity(n);
406        let r = self
407            .enumerate_physical_devices(xs.spare_capacity_mut())?
408            .assert_complete();
409        unsafe {
410            xs.set_len(r as _);
411        }
412
413        Ok(IterPhysicalDevices(xs, 0, self))
414    }
415
416    /// Enumerates the physical devices accessible to a Vulkan instance
417    /// # Failures
418    /// On failure, this command returns
419    ///
420    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
421    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
422    /// * `brvk::VK_ERROR_INITIALIZATION_FAILED`
423    #[implements("alloc")]
424    fn enumerate_physical_devices_alloc(&self) -> crate::Result<Vec<PhysicalDeviceObject<&Self>>> {
425        self.iter_physical_devices().map(crate::alloc::collect_vec)
426    }
427}
428DerefContainerWithGuardsBracketImpl!(for Instance {});
429
430/// Extension function caches
431#[implements]
432struct InstanceExtFunctions {
433    #[cfg(feature = "VK_KHR_get_physical_device_properties2")]
434    get_physical_device_properties2_khr: InstanceResolvedFn<brvk::PFN_vkGetPhysicalDeviceProperties2KHR>,
435    #[cfg(feature = "VK_KHR_get_physical_device_properties2")]
436    get_physical_device_features2_khr: InstanceResolvedFn<brvk::PFN_vkGetPhysicalDeviceFeatures2KHR>,
437    #[cfg(feature = "VK_KHR_get_physical_device_properties2")]
438    get_physical_device_format_properties2_khr: InstanceResolvedFn<brvk::PFN_vkGetPhysicalDeviceFormatProperties2KHR>,
439    #[cfg(feature = "VK_EXT_debug_report")]
440    create_debug_report_callback_ext: InstanceResolvedFn<brvk::PFN_vkCreateDebugReportCallbackEXT>,
441    #[cfg(feature = "VK_EXT_debug_report")]
442    destroy_debug_report_callback_ext: InstanceResolvedFn<brvk::PFN_vkDestroyDebugReportCallbackEXT>,
443    #[cfg(feature = "VK_EXT_debug_report")]
444    debug_report_message_ext: InstanceResolvedFn<brvk::PFN_vkDebugReportMessageEXT>,
445    #[cfg(feature = "VK_EXT_debug_utils")]
446    create_debug_utils_messenger_ext: InstanceResolvedFn<brvk::PFN_vkCreateDebugUtilsMessengerEXT>,
447    #[cfg(feature = "VK_EXT_debug_utils")]
448    destroy_debug_utils_messenger_ext: InstanceResolvedFn<brvk::PFN_vkDestroyDebugUtilsMessengerEXT>,
449    #[cfg(feature = "VK_EXT_debug_utils")]
450    set_debug_utils_object_name_ext: InstanceResolvedFn<brvk::PFN_vkSetDebugUtilsObjectNameEXT>,
451    #[cfg(feature = "VK_KHR_external_fence_capabilities")]
452    get_physical_device_external_fence_properties_khr:
453        InstanceResolvedFn<brvk::PFN_vkGetPhysicalDeviceExternalFencePropertiesKHR>,
454    #[cfg(feature = "VK_EXT_acquire_xlib_display")]
455    get_randr_output_display_ext: InstanceResolvedFn<brvk::PFN_vkGetRandROutputDisplayEXT>,
456    #[cfg(feature = "VK_EXT_acquire_xlib_display")]
457    acquire_xlib_display_ext: InstanceResolvedFn<brvk::PFN_vkAcquireXlibDisplayEXT>,
458    #[cfg(feature = "VK_EXT_full_screen_exclusive")]
459    get_physical_device_surface_present_modes_2_ext:
460        InstanceResolvedFn<brvk::PFN_vkGetPhysicalDeviceSurfacePresentModes2EXT>,
461    #[cfg(feature = "VK_KHR_get_surface_capabilities2")]
462    get_physical_device_surface_capabilities_2_khr:
463        InstanceResolvedFn<brvk::PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR>,
464    #[cfg(feature = "VK_EXT_direct_mode_display")]
465    release_display_ext: InstanceResolvedFn<brvk::PFN_vkReleaseDisplayEXT>,
466    #[cfg(feature = "VK_EXT_sample_locations")]
467    get_physical_device_multisample_properties_ext:
468        InstanceResolvedFn<brvk::PFN_vkGetPhysicalDeviceMultisamplePropertiesEXT>,
469}
470#[implements]
471impl InstanceExtFunctions {
472    const fn new(r: brvk::VkInstance) -> Self {
473        Self {
474            #[cfg(feature = "VK_KHR_get_physical_device_properties2")]
475            get_physical_device_properties2_khr: InstanceResolvedFn::new(InstanceResolverImpl(r)),
476            #[cfg(feature = "VK_KHR_get_physical_device_properties2")]
477            get_physical_device_features2_khr: InstanceResolvedFn::new(InstanceResolverImpl(r)),
478            #[cfg(feature = "VK_KHR_get_physical_device_properties2")]
479            get_physical_device_format_properties2_khr: InstanceResolvedFn::new(InstanceResolverImpl(r)),
480            #[cfg(feature = "VK_EXT_debug_report")]
481            create_debug_report_callback_ext: InstanceResolvedFn::new(InstanceResolverImpl(r)),
482            #[cfg(feature = "VK_EXT_debug_report")]
483            destroy_debug_report_callback_ext: InstanceResolvedFn::new(InstanceResolverImpl(r)),
484            #[cfg(feature = "VK_EXT_debug_report")]
485            debug_report_message_ext: InstanceResolvedFn::new(InstanceResolverImpl(r)),
486            #[cfg(feature = "VK_EXT_debug_utils")]
487            create_debug_utils_messenger_ext: InstanceResolvedFn::new(InstanceResolverImpl(r)),
488            #[cfg(feature = "VK_EXT_debug_utils")]
489            destroy_debug_utils_messenger_ext: InstanceResolvedFn::new(InstanceResolverImpl(r)),
490            #[cfg(feature = "VK_EXT_debug_utils")]
491            set_debug_utils_object_name_ext: InstanceResolvedFn::new(InstanceResolverImpl(r)),
492            #[cfg(feature = "VK_KHR_external_fence_capabilities")]
493            get_physical_device_external_fence_properties_khr: InstanceResolvedFn::new(InstanceResolverImpl(r)),
494            #[cfg(feature = "VK_EXT_acquire_xlib_display")]
495            get_randr_output_display_ext: InstanceResolvedFn::new(InstanceResolverImpl(r)),
496            #[cfg(feature = "VK_EXT_acquire_xlib_display")]
497            acquire_xlib_display_ext: InstanceResolvedFn::new(InstanceResolverImpl(r)),
498            #[cfg(feature = "VK_EXT_full_screen_exclusive")]
499            get_physical_device_surface_present_modes_2_ext: InstanceResolvedFn::new(InstanceResolverImpl(r)),
500            #[cfg(feature = "VK_KHR_get_surface_capabilities2")]
501            get_physical_device_surface_capabilities_2_khr: InstanceResolvedFn::new(InstanceResolverImpl(r)),
502            #[cfg(feature = "VK_EXT_direct_mode_display")]
503            release_display_ext: InstanceResolvedFn::new(InstanceResolverImpl(r)),
504            #[cfg(feature = "VK_EXT_sample_locations")]
505            get_physical_device_multisample_properties_ext: InstanceResolvedFn::new(InstanceResolverImpl(r)),
506        }
507    }
508}
509
510#[cfg(feature = "VK_KHR_get_physical_device_properties2")]
511pub trait InstanceGetPhysicalDeviceProperties2Extension: Instance {
512    #[implements]
513    fn get_physical_device_properties2_khr_fn(&self) -> brvk::PFN_vkGetPhysicalDeviceProperties2KHR;
514    #[implements]
515    fn get_physical_device_features2_khr_fn(&self) -> brvk::PFN_vkGetPhysicalDeviceFeatures2KHR;
516    #[implements]
517    fn get_physical_device_format_properties2_khr_fn(&self) -> brvk::PFN_vkGetPhysicalDeviceFormatProperties2KHR;
518}
519#[cfg(feature = "VK_KHR_get_physical_device_properties2")]
520DerefContainerWithGuardsBracketImpl!(for InstanceGetPhysicalDeviceProperties2Extension {
521    #[implements]
522    ForwardFnPtr!(deref get_physical_device_properties2_khr_fn -> brvk::PFN_vkGetPhysicalDeviceProperties2KHR);
523    #[implements]
524    ForwardFnPtr!(deref get_physical_device_features2_khr_fn -> brvk::PFN_vkGetPhysicalDeviceFeatures2KHR);
525    #[implements]
526    ForwardFnPtr!(deref get_physical_device_format_properties2_khr_fn -> brvk::PFN_vkGetPhysicalDeviceFormatProperties2KHR);
527});
528#[cfg(feature = "VK_KHR_get_physical_device_properties2")]
529impl InstanceGetPhysicalDeviceProperties2Extension for InstanceObject {
530    #[implements]
531    #[inline(always)]
532    fn get_physical_device_properties2_khr_fn(&self) -> brvk::PFN_vkGetPhysicalDeviceProperties2KHR {
533        *self.ext.get_physical_device_properties2_khr.resolve()
534    }
535    #[implements]
536    #[inline(always)]
537    fn get_physical_device_features2_khr_fn(&self) -> brvk::PFN_vkGetPhysicalDeviceFeatures2KHR {
538        *self.ext.get_physical_device_features2_khr.resolve()
539    }
540    #[implements]
541    #[inline(always)]
542    fn get_physical_device_format_properties2_khr_fn(&self) -> brvk::PFN_vkGetPhysicalDeviceFormatProperties2KHR {
543        *self.ext.get_physical_device_format_properties2_khr.resolve()
544    }
545}
546
547#[cfg(feature = "VK_EXT_debug_report")]
548pub trait InstanceDebugReportExtension: Instance {
549    #[implements]
550    fn create_debug_report_callback_ext_fn(&self) -> brvk::PFN_vkCreateDebugReportCallbackEXT;
551    #[implements]
552    fn destroy_debug_report_callback_ext_fn(&self) -> brvk::PFN_vkDestroyDebugReportCallbackEXT;
553    #[implements]
554    fn debug_report_message_ext_fn(&self) -> brvk::PFN_vkDebugReportMessageEXT;
555
556    /// Register a debug report callback
557    /// # Failures
558    /// On failure, this command returns
559    ///
560    /// * [`brvk::VK_ERROR_OUT_OF_HOST_MEMORY`]
561    ///
562    /// # Safety
563    /// must not execute in parallel with any Vulkan commands
564    #[implements]
565    #[inline]
566    unsafe fn new_debug_report_callback_raw(
567        &self,
568        info: &crate::DebugReportCallbackCreateInfo,
569        allocation_callbacks: Option<&brvk::VkAllocationCallbacks>,
570    ) -> crate::Result<brvk::VkDebugReportCallbackEXT> {
571        let mut h = core::mem::MaybeUninit::uninit();
572        translate_vk_result(unsafe {
573            self.create_debug_report_callback_ext_fn().0(
574                self.native_ptr(),
575                info.as_raw_ref(),
576                crate::ffi_helper::opt_pointer(allocation_callbacks),
577                h.as_mut_ptr(),
578            )
579        })?;
580
581        Ok(unsafe { h.assume_init() })
582    }
583
584    /// Inject its own messages into the debug stream
585    #[implements]
586    #[inline]
587    #[allow(clippy::too_many_arguments)]
588    fn debug_message(
589        &self,
590        flags: brvk::VkDebugReportFlagsEXT,
591        object_type: crate::DebugReportObjectType,
592        object: u64,
593        location: usize,
594        message_count: i32,
595        layer_prefix: &core::ffi::CStr,
596        message: &core::ffi::CStr,
597    ) {
598        unsafe {
599            self.debug_report_message_ext_fn().0(
600                self.native_ptr(),
601                flags,
602                object_type as _,
603                object,
604                location,
605                message_count,
606                layer_prefix.as_ptr(),
607                message.as_ptr(),
608            );
609        }
610    }
611
612    /// Destroy a debug report callback object
613    /// # Safety
614    /// * must be created from this Instance object
615    /// * must not execute in parallel with any Vulkan commands
616    #[implements]
617    #[inline]
618    unsafe fn destroy_debug_report_callback_raw(
619        &self,
620        obj: brvk::VkDebugReportCallbackEXT,
621        allocation_callbacks: Option<&brvk::VkAllocationCallbacks>,
622    ) {
623        unsafe {
624            self.destroy_debug_report_callback_ext_fn().0(
625                self.native_ptr(),
626                obj,
627                crate::ffi_helper::opt_pointer(allocation_callbacks),
628            );
629        }
630    }
631}
632#[cfg(feature = "VK_EXT_debug_report")]
633DerefContainerWithGuardsBracketImpl!(for InstanceDebugReportExtension {
634    #[implements]
635    ForwardFnPtr!(deref create_debug_report_callback_ext_fn -> brvk::PFN_vkCreateDebugReportCallbackEXT);
636    #[implements]
637    ForwardFnPtr!(deref destroy_debug_report_callback_ext_fn -> brvk::PFN_vkDestroyDebugReportCallbackEXT);
638    #[implements]
639    ForwardFnPtr!(deref debug_report_message_ext_fn -> brvk::PFN_vkDebugReportMessageEXT);
640});
641#[cfg(feature = "VK_EXT_debug_report")]
642impl InstanceDebugReportExtension for InstanceObject {
643    #[implements]
644    #[inline(always)]
645    fn create_debug_report_callback_ext_fn(&self) -> brvk::PFN_vkCreateDebugReportCallbackEXT {
646        *self.ext.create_debug_report_callback_ext.resolve()
647    }
648    #[implements]
649    #[inline(always)]
650    fn destroy_debug_report_callback_ext_fn(&self) -> brvk::PFN_vkDestroyDebugReportCallbackEXT {
651        *self.ext.destroy_debug_report_callback_ext.resolve()
652    }
653    #[implements]
654    #[inline(always)]
655    fn debug_report_message_ext_fn(&self) -> brvk::PFN_vkDebugReportMessageEXT {
656        *self.ext.debug_report_message_ext.resolve()
657    }
658}
659
660#[cfg(feature = "VK_EXT_debug_utils")]
661pub trait InstanceDebugUtilsExtension: Instance {
662    #[implements]
663    fn create_debug_utils_messenger_ext_fn(&self) -> brvk::PFN_vkCreateDebugUtilsMessengerEXT;
664    #[implements]
665    fn destroy_debug_utils_messenger_ext_fn(&self) -> brvk::PFN_vkDestroyDebugUtilsMessengerEXT;
666    #[implements]
667    fn set_debug_utils_object_name_ext_fn(&self) -> brvk::PFN_vkSetDebugUtilsObjectNameEXT;
668
669    /// Create a debug messenger object
670    /// # Failures
671    /// On failure, this command returns
672    ///
673    /// * [`brvk::VK_ERROR_OUT_OF_HOST_MEMORY`]
674    ///
675    /// # Safety
676    /// must not be executed in parallel with any Vulkan commands
677    #[implements]
678    #[inline]
679    unsafe fn new_debug_utils_messenger_raw(
680        &self,
681        info: &crate::DebugUtilsMessengerCreateInfo,
682        allocation_callbacks: Option<&brvk::VkAllocationCallbacks>,
683    ) -> crate::Result<brvk::VkDebugUtilsMessengerEXT> {
684        let mut h = core::mem::MaybeUninit::uninit();
685        crate::error::translate_vk_result(unsafe {
686            self.create_debug_utils_messenger_ext_fn().0(
687                self.native_ptr(),
688                core::ptr::from_ref(info).cast(),
689                crate::ffi_helper::opt_pointer(allocation_callbacks),
690                h.as_mut_ptr(),
691            )
692        })?;
693
694        Ok(unsafe { h.assume_init() })
695    }
696
697    /// Destroy a debug messenger object
698    /// # Safety
699    /// * must be created from this Instance object
700    /// * must not execute in parallel with any Vulkan commands
701    #[implements]
702    #[inline]
703    unsafe fn destroy_debug_utils_messenger_raw(
704        &self,
705        obj: brvk::VkDebugUtilsMessengerEXT,
706        allocation_callbacks: Option<&brvk::VkAllocationCallbacks>,
707    ) {
708        unsafe {
709            self.destroy_debug_utils_messenger_ext_fn().0(
710                self.native_ptr(),
711                obj,
712                crate::ffi_helper::opt_pointer(allocation_callbacks),
713            );
714        }
715    }
716
717    /// Give an application-defined name to an object
718    ///
719    /// # Failure
720    ///
721    /// On failure, this command returns
722    ///
723    /// * [`brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`]
724    /// * [`brvk::VK_ERROR_OUT_OF_HOST_MEMORY`]
725    /// * [`brvk::VK_ERROR_UNKNOWN`]
726    /// * [`brvk::VK_ERROR_VALIDATION_FAILED`]
727    ///
728    /// # Safety
729    ///
730    /// * `objectHandle` in `info` must be associated with the `device`
731    /// * `objectHandle` in `info` must be externally synchronizewd
732    #[implements]
733    #[inline]
734    unsafe fn set_debug_utils_object_name_ext(
735        &self,
736        device: VkHandleRef<brvk::VkDevice>,
737        info: &DebugUtilsObjectNameInfo,
738    ) -> crate::Result<()> {
739        crate::error::translate_vk_result(unsafe { self.set_debug_utils_object_name_ext_fn().0(device.0, &info.0) })?;
740
741        Ok(())
742    }
743}
744#[cfg(feature = "VK_EXT_debug_utils")]
745DerefContainerWithGuardsBracketImpl!(for InstanceDebugUtilsExtension {
746    #[implements]
747    ForwardFnPtr!(deref create_debug_utils_messenger_ext_fn -> brvk::PFN_vkCreateDebugUtilsMessengerEXT);
748    #[implements]
749    ForwardFnPtr!(deref destroy_debug_utils_messenger_ext_fn -> brvk::PFN_vkDestroyDebugUtilsMessengerEXT);
750    #[implements]
751    ForwardFnPtr!(deref set_debug_utils_object_name_ext_fn -> brvk::PFN_vkSetDebugUtilsObjectNameEXT);
752});
753#[cfg(feature = "VK_EXT_debug_utils")]
754impl InstanceDebugUtilsExtension for InstanceObject {
755    #[implements]
756    #[inline(always)]
757    fn create_debug_utils_messenger_ext_fn(&self) -> brvk::PFN_vkCreateDebugUtilsMessengerEXT {
758        *self.ext.create_debug_utils_messenger_ext.resolve()
759    }
760    #[implements]
761    #[inline(always)]
762    fn destroy_debug_utils_messenger_ext_fn(&self) -> brvk::PFN_vkDestroyDebugUtilsMessengerEXT {
763        *self.ext.destroy_debug_utils_messenger_ext.resolve()
764    }
765    #[implements]
766    #[inline(always)]
767    fn set_debug_utils_object_name_ext_fn(&self) -> brvk::PFN_vkSetDebugUtilsObjectNameEXT {
768        *self.ext.set_debug_utils_object_name_ext.resolve()
769    }
770}
771
772#[cfg(feature = "VK_KHR_external_fence_capabilities")]
773pub trait InstanceExternalFenceCapabilitiesExtension: Instance {
774    #[implements]
775    fn get_physical_device_external_fence_properties_khr_fn(
776        &self,
777    ) -> brvk::PFN_vkGetPhysicalDeviceExternalFencePropertiesKHR;
778}
779#[cfg(feature = "VK_KHR_external_fence_capabilities")]
780DerefContainerWithGuardsBracketImpl!(for InstanceExternalFenceCapabilitiesExtension {
781    #[implements]
782    ForwardFnPtr!(deref get_physical_device_external_fence_properties_khr_fn -> brvk::PFN_vkGetPhysicalDeviceExternalFencePropertiesKHR);
783});
784#[cfg(feature = "VK_KHR_external_fence_capabilities")]
785impl InstanceExternalFenceCapabilitiesExtension for InstanceObject {
786    #[implements]
787    #[inline(always)]
788    fn get_physical_device_external_fence_properties_khr_fn(
789        &self,
790    ) -> brvk::PFN_vkGetPhysicalDeviceExternalFencePropertiesKHR {
791        *self.ext.get_physical_device_external_fence_properties_khr.resolve()
792    }
793}
794
795#[cfg(feature = "VK_EXT_acquire_xlib_display")]
796pub trait InstanceAcquireXlibDisplayExtension: Instance {
797    #[implements]
798    fn get_randr_output_display_ext_fn(&self) -> brvk::PFN_vkGetRandROutputDisplayEXT;
799    #[implements]
800    fn acquire_xlib_display_ext_fn(&self) -> brvk::PFN_vkAcquireXlibDisplayEXT;
801}
802#[cfg(feature = "VK_EXT_acquire_xlib_display")]
803DerefContainerWithGuardsBracketImpl!(for InstanceAcquireXlibDisplayExtension {
804    #[implements]
805    ForwardFnPtr!(deref get_randr_output_display_ext_fn -> brvk::PFN_vkGetRandROutputDisplayEXT);
806    #[implements]
807    ForwardFnPtr!(deref acquire_xlib_display_ext_fn -> brvk::PFN_vkAcquireXlibDisplayEXT);
808});
809#[cfg(feature = "VK_EXT_acquire_xlib_display")]
810impl InstanceAcquireXlibDisplayExtension for InstanceObject {
811    #[implements]
812    #[inline(always)]
813    fn get_randr_output_display_ext_fn(&self) -> brvk::PFN_vkGetRandROutputDisplayEXT {
814        *self.ext.get_randr_output_display_ext.resolve()
815    }
816    #[implements]
817    #[inline(always)]
818    fn acquire_xlib_display_ext_fn(&self) -> brvk::PFN_vkAcquireXlibDisplayEXT {
819        *self.ext.acquire_xlib_display_ext.resolve()
820    }
821}
822
823#[cfg(feature = "VK_EXT_full_screen_exclusive")]
824pub trait InstanceFullScreenExclusiveExtension: Instance {
825    #[implements]
826    fn get_physical_device_surface_present_modes_2_ext_fn(
827        &self,
828    ) -> brvk::PFN_vkGetPhysicalDeviceSurfacePresentModes2EXT;
829
830    /// # Safety
831    ///
832    /// surface in `surface_info` and `physical_device` must be created from the same instance.
833    #[implements]
834    #[inline]
835    unsafe fn get_physical_device_surface_present_mode2_count(
836        &self,
837        physical_device: VkHandleRef<brvk::VkPhysicalDevice>,
838        surface_info: &brvk::VkPhysicalDeviceSurfaceInfo2KHR,
839    ) -> crate::Result<u32> {
840        let mut n = 0;
841        translate_vk_result(unsafe {
842            self.get_physical_device_surface_present_modes_2_ext_fn().0(
843                physical_device.0,
844                surface_info,
845                &mut n,
846                core::ptr::null_mut(),
847            )
848        })?;
849
850        Ok(n)
851    }
852
853    /// # Safety
854    ///
855    /// surface in `surface_info` and `physical_device` must be created from the same instance.
856    #[implements]
857    #[inline]
858    unsafe fn get_physical_device_surface_present_modes2(
859        &self,
860        physical_device: VkHandleRef<brvk::VkPhysicalDevice>,
861        surface_info: &brvk::VkPhysicalDeviceSurfaceInfo2KHR,
862        sink: &mut [core::mem::MaybeUninit<brvk::VkPresentModeKHR>],
863    ) -> crate::Result<ArrayQueryResult<u32>> {
864        let mut n = sink.len() as _;
865        let r = ArrayQueryResult::from_vk_result(unsafe {
866            self.get_physical_device_surface_present_modes_2_ext_fn().0(
867                physical_device.0,
868                surface_info,
869                &mut n,
870                sink.as_mut_ptr().cast(),
871            )
872        })?;
873
874        Ok(r.with_result(n))
875    }
876}
877#[cfg(feature = "VK_EXT_full_screen_exclusive")]
878DerefContainerWithGuardsBracketImpl!(for InstanceFullScreenExclusiveExtension {
879    #[implements]
880    ForwardFnPtr!(deref get_physical_device_surface_present_modes_2_ext_fn -> brvk::PFN_vkGetPhysicalDeviceSurfacePresentModes2EXT);
881});
882#[cfg(feature = "VK_EXT_full_screen_exclusive")]
883impl InstanceFullScreenExclusiveExtension for InstanceObject {
884    #[implements]
885    #[inline(always)]
886    fn get_physical_device_surface_present_modes_2_ext_fn(
887        &self,
888    ) -> brvk::PFN_vkGetPhysicalDeviceSurfacePresentModes2EXT {
889        *self.ext.get_physical_device_surface_present_modes_2_ext.resolve()
890    }
891}
892
893#[cfg(feature = "VK_KHR_get_surface_capabilities2")]
894pub trait InstanceGetSurfaceCapabilities2Extension: Instance {
895    #[implements]
896    fn get_physical_device_surface_capabilities_2_khr_fn(&self)
897    -> brvk::PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR;
898
899    /// # Safety
900    ///
901    /// surface in `surface_info` and `physical_device` must be created from the same instance.
902    #[implements]
903    #[inline(always)]
904    unsafe fn get_physical_device_surface_capabilities2(
905        &self,
906        physical_device: VkHandleRef<brvk::VkPhysicalDevice>,
907        surface_info: &brvk::VkPhysicalDeviceSurfaceInfo2KHR,
908        sink: &mut core::mem::MaybeUninit<brvk::VkSurfaceCapabilities2KHR>,
909    ) -> crate::Result<()> {
910        translate_vk_result(unsafe {
911            self.get_physical_device_surface_capabilities_2_khr_fn().0(
912                physical_device.0,
913                surface_info,
914                sink.as_mut_ptr(),
915            )
916        })?;
917
918        Ok(())
919    }
920}
921#[cfg(feature = "VK_KHR_get_surface_capabilities2")]
922DerefContainerWithGuardsBracketImpl!(for InstanceGetSurfaceCapabilities2Extension {
923    #[implements]
924    ForwardFnPtr!(deref get_physical_device_surface_capabilities_2_khr_fn -> brvk::PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR);
925});
926#[cfg(feature = "VK_KHR_get_surface_capabilities2")]
927impl InstanceGetSurfaceCapabilities2Extension for InstanceObject {
928    #[implements]
929    #[inline(always)]
930    fn get_physical_device_surface_capabilities_2_khr_fn(
931        &self,
932    ) -> brvk::PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR {
933        *self.ext.get_physical_device_surface_capabilities_2_khr.resolve()
934    }
935}
936
937#[cfg(feature = "VK_EXT_direct_mode_display")]
938pub trait InstanceDirectModeDisplayExtension: Instance {
939    #[implements]
940    fn release_display_ext_fn(&self) -> brvk::PFN_vkReleaseDisplayEXT;
941}
942#[cfg(feature = "VK_EXT_direct_mode_display")]
943DerefContainerWithGuardsBracketImpl!(for InstanceDirectModeDisplayExtension {
944    #[implements]
945    ForwardFnPtr!(deref release_display_ext_fn -> brvk::PFN_vkReleaseDisplayEXT);
946});
947#[cfg(feature = "VK_EXT_direct_mode_display")]
948impl InstanceDirectModeDisplayExtension for InstanceObject {
949    #[implements]
950    #[inline(always)]
951    fn release_display_ext_fn(&self) -> brvk::PFN_vkReleaseDisplayEXT {
952        *self.ext.release_display_ext.resolve()
953    }
954}
955
956#[cfg(feature = "VK_EXT_sample_locations")]
957pub trait InstanceSampleLocationsExtension: Instance {
958    #[implements]
959    fn get_physical_device_multisample_properties_ext_fn(
960        &self,
961    ) -> brvk::PFN_vkGetPhysicalDeviceMultisamplePropertiesEXT;
962}
963#[cfg(feature = "VK_EXT_sample_locations")]
964DerefContainerWithGuardsBracketImpl!(for InstanceSampleLocationsExtension {
965    #[implements]
966    ForwardFnPtr!(deref get_physical_device_multisample_properties_ext_fn -> brvk::PFN_vkGetPhysicalDeviceMultisamplePropertiesEXT);
967});
968#[cfg(feature = "VK_EXT_sample_locations")]
969impl InstanceSampleLocationsExtension for InstanceObject {
970    #[implements]
971    #[inline(always)]
972    fn get_physical_device_multisample_properties_ext_fn(
973        &self,
974    ) -> brvk::PFN_vkGetPhysicalDeviceMultisamplePropertiesEXT {
975        *self.ext.get_physical_device_multisample_properties_ext.resolve()
976    }
977}
978
979/// Opaque handle to a physical device object
980///
981/// ## Platform Dependent Methods: Presentation Support checking functions
982///
983/// * `xlib_presentation_support(&self, queue_family: u32, display: *mut x11::xlib::Display, visual: x11::xlib::VisualID) -> bool`: brvk::VK_KHR_xlib_surface
984/// * `xcb_presentation_support(&self, queue_family: u32, connection: *mut xcb::ffi::xcb_connection_t, visual: xcb::ffi::xcb_visualid_t) -> bool`: brvk::VK_KHR_xcb_surface
985/// * `wayland_presentation_support(&self, queue_family: u32, display: *mut wayland_client::sys::wl_display) -> bool`: brvk::VK_KHR_wayland_surface
986/// * `win32_presentation_support(&self, queue_family: u32) -> bool`: brvk::VK_KHR_win32_surface
987/// * Methods for Android and Mir surfaces are not implemented
988#[derive(VkHandle, VkObject, crate::InstanceChild, crate::InstanceChildTransferrable, Clone)]
989#[VkObject(type = brvk::VK_OBJECT_TYPE_PHYSICAL_DEVICE)]
990pub struct PhysicalDeviceObject<Owner: Instance>(brvk::VkPhysicalDevice, #[parent] Owner);
991unsafe impl<Owner: Instance + Sync> Sync for PhysicalDeviceObject<Owner> {}
992unsafe impl<Owner: Instance + Send> Send for PhysicalDeviceObject<Owner> {}
993impl<Owner: Instance> PhysicalDevice for PhysicalDeviceObject<Owner> {}
994impl<Owner: Instance> PhysicalDeviceObject<Owner> {
995    /// # Safety
996    ///
997    /// passed handles must be valid, and owned by the same instance as `owner`.
998    pub const unsafe fn manage(handle: brvk::VkPhysicalDevice, owner: Owner) -> Self {
999        Self(handle, owner)
1000    }
1001
1002    pub const fn unmanage(self) -> (brvk::VkPhysicalDevice, Owner) {
1003        let handle = self.0;
1004        let owner = unsafe { core::ptr::read(&self.1) };
1005        core::mem::forget(self);
1006
1007        (handle, owner)
1008    }
1009}
1010impl<Owner: Instance + Clone> PhysicalDeviceObject<&'_ Owner> {
1011    /// Split the lifetime from owner by cloning it.
1012    #[inline(always)]
1013    pub fn clone_parent(&self) -> PhysicalDeviceObject<Owner> {
1014        PhysicalDeviceObject(self.0, self.1.clone())
1015    }
1016}
1017
1018pub struct IterPhysicalDevices<'i, Source: Instance + 'i + ?Sized>(Vec<brvk::VkPhysicalDevice>, usize, &'i Source);
1019impl<'i, Source: Instance + 'i + ?Sized> Iterator for IterPhysicalDevices<'i, Source> {
1020    type Item = PhysicalDeviceObject<&'i Source>;
1021
1022    #[inline(always)]
1023    fn next(&mut self) -> Option<PhysicalDeviceObject<&'i Source>> {
1024        if self.0.len() <= self.1 {
1025            None
1026        } else {
1027            self.1 += 1;
1028            Some(PhysicalDeviceObject(self.0[self.1 - 1], self.2))
1029        }
1030    }
1031    #[inline(always)]
1032    fn size_hint(&self) -> (usize, Option<usize>) {
1033        (self.0.len(), Some(self.0.len()))
1034    }
1035}
1036impl<'i, Source: Instance + 'i + ?Sized> ExactSizeIterator for IterPhysicalDevices<'i, Source> {
1037    #[inline(always)]
1038    fn len(&self) -> usize {
1039        self.0.len()
1040    }
1041}
1042impl<'i, Source: Instance + 'i + ?Sized> DoubleEndedIterator for IterPhysicalDevices<'i, Source> {
1043    #[inline(always)]
1044    fn next_back(&mut self) -> Option<PhysicalDeviceObject<&'i Source>> {
1045        if self.0.len() <= self.1 {
1046            None
1047        } else {
1048            self.0.pop().map(|p| PhysicalDeviceObject(p, self.2))
1049        }
1050    }
1051}
1052
1053/// A PhysicalDevice interface
1054pub trait PhysicalDevice: VkHandle<Handle = brvk::VkPhysicalDevice> + InstanceChild {
1055    /// Returns a count of properties of available physical device layers
1056    /// # Failures
1057    /// On failure, this command returns
1058    ///
1059    /// * [`brvk::VK_ERROR_OUT_OF_HOST_MEMORY`]
1060    /// * [`brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`]
1061    #[implements]
1062    #[inline(always)]
1063    fn layer_property_count(&self) -> crate::Result<u32> {
1064        crate::vkfn_wrapper::device_layer_property_count(self.as_transparent_ref())
1065    }
1066
1067    /// Returns properties of available physical device layers
1068    /// # Failures
1069    /// On failure, this command returns
1070    ///
1071    /// * [`brvk::VK_ERROR_OUT_OF_HOST_MEMORY`]
1072    /// * [`brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`]
1073    #[implements]
1074    #[inline(always)]
1075    fn enumerate_layer_properties(
1076        &self,
1077        sink: &mut [core::mem::MaybeUninit<brvk::VkLayerProperties>],
1078    ) -> crate::Result<ArrayQueryResult<u32>> {
1079        crate::vkfn_wrapper::enumerate_device_layer_properties(self.as_transparent_ref(), sink)
1080    }
1081
1082    /// Returns properties of available physical device layers
1083    /// # Failures
1084    /// On failure, this command returns
1085    ///
1086    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1087    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1088    #[implements("alloc")]
1089    fn enumerate_layer_properties_alloc(&self) -> crate::Result<Vec<brvk::VkLayerProperties>> {
1090        let count = self.layer_property_count()? as usize;
1091        if count == 0 {
1092            // no items
1093            return Ok(crate::alloc::empty_sink_buffer());
1094        }
1095
1096        let mut xs = crate::alloc::reserve(count);
1097        let r = self
1098            .enumerate_layer_properties(xs.spare_capacity_mut())?
1099            .assert_complete();
1100        unsafe {
1101            xs.set_len(r as _);
1102        }
1103
1104        Ok(xs)
1105    }
1106
1107    /// Returns a count of properties of available physical device extensions
1108    /// # Failures
1109    /// On failure, this command returns
1110    ///
1111    /// * [`brvk::VK_ERROR_OUT_OF_HOST_MEMORY`]
1112    /// * [`brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`]
1113    /// * [`brvk::VK_ERROR_LAYER_NOT_PRESENT`]
1114    #[implements]
1115    #[inline(always)]
1116    fn extension_property_count(&self, layer_name: Option<&CStr>) -> crate::Result<u32> {
1117        crate::vkfn_wrapper::device_extension_property_count(self.as_transparent_ref(), layer_name)
1118    }
1119
1120    /// Returns properties of available physical device extensions
1121    /// # Failures
1122    /// On failure, this command returns
1123    ///
1124    /// * [`brvk::VK_ERROR_OUT_OF_HOST_MEMORY`]
1125    /// * [`brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`]
1126    /// * [`brvk::VK_ERROR_LAYER_NOT_PRESENT`]
1127    #[implements]
1128    #[inline(always)]
1129    fn enumerate_extension_properties(
1130        &self,
1131        layer_name: Option<&CStr>,
1132        sink: &mut [core::mem::MaybeUninit<brvk::VkExtensionProperties>],
1133    ) -> crate::Result<ArrayQueryResult<u32>> {
1134        crate::vkfn_wrapper::enumerate_device_extension_properties(self.as_transparent_ref(), layer_name, sink)
1135    }
1136
1137    /// Returns properties of available physical device extensions
1138    /// # Failures
1139    /// On failure, this command returns
1140    ///
1141    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1142    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1143    /// * `brvk::VK_ERROR_LAYER_NOT_PRESENT`
1144    #[implements("alloc")]
1145    fn enumerate_extension_properties_alloc(
1146        &self,
1147        layer_name: Option<&CStr>,
1148    ) -> crate::Result<Vec<brvk::VkExtensionProperties>> {
1149        let n = self.extension_property_count(layer_name)? as usize;
1150        if n == 0 {
1151            // no items
1152            return Ok(crate::alloc::empty_sink_buffer());
1153        }
1154
1155        let mut xs = crate::alloc::reserve(n);
1156        let r = self
1157            .enumerate_extension_properties(layer_name, xs.spare_capacity_mut())?
1158            .assert_complete();
1159        unsafe {
1160            xs.set_len(r as _);
1161        }
1162
1163        Ok(xs)
1164    }
1165
1166    /// Returns properties of available physical device extensions
1167    /// # Failures
1168    /// On failure, this command returns
1169    ///
1170    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1171    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1172    /// * `brvk::VK_ERROR_LAYER_NOT_PRESENT`
1173    #[implements("alloc")]
1174    #[inline]
1175    fn enumerate_extension_properties_str_alloc(
1176        &self,
1177        layer_name: Option<&str>,
1178    ) -> crate::Result<Vec<brvk::VkExtensionProperties>> {
1179        self.enumerate_extension_properties_alloc(layer_name.map(|s| crate::alloc::str_to_cstr(s).unwrap()).as_deref())
1180    }
1181
1182    /// Reports capabilities of a physical device.
1183    #[implements]
1184    #[inline]
1185    fn features(&self) -> brvk::VkPhysicalDeviceFeatures {
1186        let mut p = std::mem::MaybeUninit::uninit();
1187        crate::vkfn_wrapper::get_physical_device_features(self.as_transparent_ref(), &mut p);
1188
1189        unsafe { p.assume_init() }
1190    }
1191
1192    /// Reports capabilities of a physical device
1193    #[implements("Allow1_1APIs")]
1194    #[inline(always)]
1195    fn features2(&self, sink: &mut core::mem::MaybeUninit<PhysicalDeviceFeatures2>) {
1196        crate::vkfn_wrapper::get_physical_device_features2(self.as_transparent_ref(), sink)
1197    }
1198
1199    /// Reports capabilities of a physical device
1200    #[implements("VK_KHR_get_physical_device_properties2")]
1201    #[inline]
1202    fn features2_khr(&self, sink: &mut core::mem::MaybeUninit<PhysicalDeviceFeatures2>)
1203    where
1204        Self::ConcreteInstance: InstanceGetPhysicalDeviceProperties2Extension,
1205    {
1206        unsafe {
1207            self.instance().get_physical_device_features2_khr_fn().0(self.native_ptr(), sink.as_mut_ptr().cast());
1208        }
1209    }
1210
1211    /// Returns properties of a physical device
1212    #[implements]
1213    #[inline]
1214    fn properties(&self) -> brvk::VkPhysicalDeviceProperties {
1215        let mut p = std::mem::MaybeUninit::uninit();
1216        crate::vkfn_wrapper::get_physical_device_properties(self.as_transparent_ref(), &mut p);
1217
1218        unsafe { p.assume_init() }
1219    }
1220
1221    /// Returns properties of a physical device
1222    #[implements("Allow1_1APIs")]
1223    #[inline(always)]
1224    fn properties2(&self, sink: &mut core::mem::MaybeUninit<brvk::VkPhysicalDeviceProperties2KHR>) {
1225        crate::vkfn_wrapper::get_physical_device_properties2(self.as_transparent_ref(), sink)
1226    }
1227
1228    /// Returns properties of a physical device
1229    #[implements("VK_KHR_get_physical_device_properties2")]
1230    #[inline]
1231    fn properties2_khr(&self, sink: &mut core::mem::MaybeUninit<brvk::VkPhysicalDeviceProperties2KHR>)
1232    where
1233        Self::ConcreteInstance: InstanceGetPhysicalDeviceProperties2Extension,
1234    {
1235        unsafe {
1236            self.instance().get_physical_device_properties2_khr_fn().0(self.native_ptr(), sink.as_mut_ptr());
1237        }
1238    }
1239
1240    /// Lists physical device's format capabilities
1241    #[implements]
1242    #[inline]
1243    fn format_properties(&self, format: brvk::VkFormat) -> brvk::VkFormatProperties {
1244        let mut p = std::mem::MaybeUninit::uninit();
1245        crate::vkfn_wrapper::get_physical_device_format_properties(self.as_transparent_ref(), format, &mut p);
1246
1247        unsafe { p.assume_init() }
1248    }
1249
1250    /// Lists physical device's format capabilities
1251    #[implements("Allow1_1APIs")]
1252    #[inline(always)]
1253    fn format_properties2(
1254        &self,
1255        format: brvk::VkFormat,
1256        out: &mut core::mem::MaybeUninit<brvk::VkFormatProperties2KHR>,
1257    ) {
1258        crate::vkfn_wrapper::get_physical_device_format_properties2(self.as_transparent_ref(), format, out)
1259    }
1260
1261    /// Lists physical device's format capabilities
1262    #[implements("VK_KHR_get_physical_device_properties2")]
1263    #[inline]
1264    fn format_properties2_khr(
1265        &self,
1266        format: brvk::VkFormat,
1267        out: &mut core::mem::MaybeUninit<brvk::VkFormatProperties2KHR>,
1268    ) where
1269        Self::ConcreteInstance: InstanceGetPhysicalDeviceProperties2Extension,
1270    {
1271        unsafe {
1272            self.instance().get_physical_device_format_properties2_khr_fn().0(
1273                self.native_ptr(),
1274                format,
1275                out.as_mut_ptr(),
1276            );
1277        }
1278    }
1279
1280    /// Lists physical device's image format capabilities
1281    /// # Failures
1282    /// On failure, this command returns
1283    ///
1284    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1285    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1286    /// * `brvk::VK_ERROR_FORMAT_NOT_SUPPORTED`
1287    #[implements]
1288    #[inline]
1289    fn image_format_properties(
1290        &self,
1291        format: brvk::VkFormat,
1292        itype: brvk::VkImageType,
1293        tiling: brvk::VkImageTiling,
1294        usage: ImageUsageFlags,
1295        flags: ImageFlags,
1296    ) -> crate::Result<brvk::VkImageFormatProperties> {
1297        let mut p = std::mem::MaybeUninit::uninit();
1298        crate::vkfn_wrapper::get_physical_device_image_format_properties(
1299            self.as_transparent_ref(),
1300            format,
1301            itype,
1302            tiling,
1303            usage,
1304            flags,
1305            &mut p,
1306        )?;
1307
1308        Ok(unsafe { p.assume_init() })
1309    }
1310
1311    /// Reports a count of properties of the queues of the specified physical device
1312    #[implements]
1313    #[inline(always)]
1314    fn queue_family_property_count(&self) -> u32 {
1315        crate::vkfn_wrapper::get_physical_device_queue_family_property_count(self.as_transparent_ref())
1316    }
1317
1318    /// Reports properties of the queues of the specified physical device
1319    #[implements]
1320    #[inline(always)]
1321    fn queue_family_properties(&self, sink: &mut [core::mem::MaybeUninit<QueueFamilyProperties>]) -> u32 {
1322        crate::vkfn_wrapper::get_physical_device_queue_family_properties(self.as_transparent_ref(), sink)
1323    }
1324
1325    /// Reports properties of the queues of the specified physical device
1326    #[implements("alloc")]
1327    fn queue_family_properties_alloc(&self) -> QueueFamilies {
1328        let n = self.queue_family_property_count() as usize;
1329        if n == 0 {
1330            // no items
1331            return QueueFamilies(crate::alloc::empty_sink_buffer());
1332        }
1333
1334        let mut xs = crate::alloc::reserve(n);
1335        let filled = self.queue_family_properties(xs.spare_capacity_mut());
1336        unsafe {
1337            xs.set_len(filled as _);
1338        }
1339
1340        QueueFamilies(xs)
1341    }
1342
1343    /// Reports memory information for the specified physical device
1344    #[implements]
1345    #[inline]
1346    fn memory_properties(&self) -> MemoryProperties {
1347        let mut p = core::mem::MaybeUninit::uninit();
1348        crate::vkfn_wrapper::get_physical_device_memory_properties(self.as_transparent_ref(), &mut p);
1349
1350        unsafe { MemoryProperties(p.assume_init()) }
1351    }
1352
1353    /// Retrieve a count of properties of an image format spplied to sparse images
1354    #[implements]
1355    #[inline(always)]
1356    fn sparse_image_format_property_count(
1357        &self,
1358        format: brvk::VkFormat,
1359        image_type: brvk::VkImageType,
1360        samples: brvk::VkSampleCountFlags,
1361        usage: ImageUsageFlags,
1362        tiling: brvk::VkImageTiling,
1363    ) -> u32 {
1364        crate::vkfn_wrapper::get_physical_device_sparse_image_format_property_count(
1365            self.as_transparent_ref(),
1366            format,
1367            image_type,
1368            samples,
1369            usage,
1370            tiling,
1371        )
1372    }
1373
1374    /// Retrieve properties of an image format applied to sparse images
1375    #[implements]
1376    #[inline(always)]
1377    fn sparse_image_format_properties(
1378        &self,
1379        format: brvk::VkFormat,
1380        image_type: brvk::VkImageType,
1381        samples: brvk::VkSampleCountFlags,
1382        usage: ImageUsageFlags,
1383        tiling: brvk::VkImageTiling,
1384        sink: &mut [core::mem::MaybeUninit<brvk::VkSparseImageFormatProperties>],
1385    ) -> u32 {
1386        crate::vkfn_wrapper::get_physical_device_sparse_image_format_properties(
1387            self.as_transparent_ref(),
1388            format,
1389            image_type,
1390            samples,
1391            usage,
1392            tiling,
1393            sink,
1394        )
1395    }
1396
1397    /// Retrieve properties of an image format applied to sparse images
1398    #[implements]
1399    #[cfg(feature = "alloc")]
1400    fn sparse_image_format_properties_alloc(
1401        &self,
1402        format: brvk::VkFormat,
1403        itype: brvk::VkImageType,
1404        samples: brvk::VkSampleCountFlags,
1405        usage: ImageUsageFlags,
1406        tiling: brvk::VkImageTiling,
1407    ) -> Vec<brvk::VkSparseImageFormatProperties> {
1408        let n = self.sparse_image_format_property_count(format, itype, samples, usage, tiling);
1409        if n == 0 {
1410            // no items
1411            return crate::alloc::empty_sink_buffer();
1412        }
1413
1414        let mut xs = crate::alloc::reserve(n as _);
1415        let filled =
1416            self.sparse_image_format_properties(format, itype, samples, usage, tiling, xs.spare_capacity_mut());
1417        unsafe {
1418            xs.set_len(filled as _);
1419        }
1420
1421        xs
1422    }
1423
1424    /// # Safety
1425    /// Caller must guarantee that all write operations to `sink` and its `pNext` fields are safe
1426    #[implements("VK_EXT_sample_locations")]
1427    unsafe fn multisample_properties(
1428        &self,
1429        samples: brvk::VkSampleCountFlags,
1430        sink: &mut core::mem::MaybeUninit<brvk::VkMultisamplePropertiesEXT>,
1431    ) where
1432        Self::ConcreteInstance: InstanceSampleLocationsExtension,
1433    {
1434        self.instance().get_physical_device_multisample_properties_ext_fn().0(
1435            self.native_ptr(),
1436            samples,
1437            sink.as_mut_ptr(),
1438        );
1439    }
1440
1441    /// Function for querying external fence handle capabilities
1442    /// # Safety
1443    /// Caller must guarantee that all write operations to `sink` and its `pNext` fields are safe
1444    #[implements("VK_KHR_external_fence_capabilities")]
1445    #[inline(always)]
1446    unsafe fn external_fence_properties(
1447        &self,
1448        info: &brvk::VkPhysicalDeviceExternalFenceInfoKHR,
1449        sink: &mut core::mem::MaybeUninit<brvk::VkExternalFencePropertiesKHR>,
1450    ) where
1451        Self::ConcreteInstance: InstanceExternalFenceCapabilitiesExtension,
1452    {
1453        unsafe {
1454            self.instance().get_physical_device_external_fence_properties_khr_fn().0(
1455                self.native_ptr(),
1456                info,
1457                sink.as_mut_ptr(),
1458            );
1459        }
1460    }
1461
1462    /// Query if presentation is supported
1463    /// # Failures
1464    /// On failure, this command returns
1465    ///
1466    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1467    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1468    /// * `brvk::VK_ERROR_SURFACE_LOST_KHR`
1469    #[implements("VK_KHR_surface")]
1470    #[inline(always)]
1471    fn surface_support(&self, queue_family: u32, surface: &(impl Surface + ?Sized)) -> crate::Result<bool> {
1472        unsafe {
1473            crate::vkfn_wrapper::get_physical_device_surface_support(
1474                self.as_transparent_ref(),
1475                queue_family,
1476                surface.as_transparent_ref(),
1477            )
1478        }
1479    }
1480
1481    /// Query surface capabilities
1482    /// # Failures
1483    /// On failure, this command returns
1484    ///
1485    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1486    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1487    /// * `brvk::VK_ERROR_SURFACE_LOST_KHR`
1488    #[implements("VK_KHR_surface")]
1489    #[inline]
1490    fn surface_capabilities(&self, surface: &(impl Surface + ?Sized)) -> crate::Result<SurfaceCapabilities> {
1491        let mut s = std::mem::MaybeUninit::uninit();
1492        unsafe {
1493            crate::vkfn_wrapper::get_physical_device_surface_capabilities(
1494                self.as_transparent_ref(),
1495                surface.as_transparent_ref(),
1496                &mut s,
1497            )?;
1498        }
1499
1500        Ok(unsafe { s.assume_init() })
1501    }
1502
1503    /// Reports capabilities of a surface on a physical device
1504    ///
1505    /// # Failures
1506    ///
1507    /// On failure, this command returns
1508    /// * [`brvk::VK_ERROR_OUT_OF_HOST_MEMORY`]
1509    /// * [`brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`]
1510    /// * [`brvk::VK_ERROR_SURFACE_LOST_KHR`]
1511    ///
1512    /// # Safety
1513    /// Caller must guarantee that all write operations to `sink` and its `pNext` fields are safe
1514    #[implements("VK_KHR_get_surface_capabilities2")]
1515    #[inline(always)]
1516    unsafe fn surface_capabilities2(
1517        &self,
1518        surface_info: &brvk::VkPhysicalDeviceSurfaceInfo2KHR,
1519        sink: &mut core::mem::MaybeUninit<brvk::VkSurfaceCapabilities2KHR>,
1520    ) -> crate::Result<()>
1521    where
1522        Self::ConcreteInstance: InstanceGetSurfaceCapabilities2Extension,
1523    {
1524        unsafe {
1525            self.instance()
1526                .get_physical_device_surface_capabilities2(self.as_transparent_ref(), surface_info, sink)
1527        }
1528    }
1529
1530    /// Query a count of color formats supported by surface
1531    /// # Failures
1532    /// On failure, this command returns
1533    ///
1534    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1535    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1536    /// * `brvk::VK_ERROR_SURFACE_LOST_KHR`
1537    #[implements("VK_KHR_surface")]
1538    #[inline(always)]
1539    fn surface_format_count(
1540        &self,
1541        surface: &(impl VkHandle<Handle = brvk::VkSurfaceKHR> + ?Sized),
1542    ) -> crate::Result<u32> {
1543        unsafe {
1544            crate::vkfn_wrapper::get_physical_device_surface_format_count(
1545                self.as_transparent_ref(),
1546                surface.as_transparent_ref(),
1547            )
1548        }
1549    }
1550
1551    /// Query a count of color formats supported by surface
1552    /// # Failures
1553    /// On failure, this command returns
1554    ///
1555    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1556    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1557    /// * `brvk::VK_ERROR_SURFACE_LOST_KHR`
1558    #[implements("VK_KHR_surface")]
1559    #[inline(always)]
1560    fn surface_formats(
1561        &self,
1562        surface: &(impl VkHandle<Handle = brvk::VkSurfaceKHR> + ?Sized),
1563        sink: &mut [core::mem::MaybeUninit<brvk::VkSurfaceFormatKHR>],
1564    ) -> crate::Result<ArrayQueryResult<u32>> {
1565        unsafe {
1566            crate::vkfn_wrapper::get_physical_device_surface_formats(
1567                self.as_transparent_ref(),
1568                surface.as_transparent_ref(),
1569                sink,
1570            )
1571        }
1572    }
1573
1574    /// Query color formats supported by surface
1575    /// # Failures
1576    /// On failure, this command returns
1577    ///
1578    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1579    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1580    /// * `brvk::VK_ERROR_SURFACE_LOST_KHR`
1581    #[implements("VK_KHR_surface", "alloc")]
1582    fn surface_formats_alloc(&self, surface: &(impl Surface + ?Sized)) -> crate::Result<Vec<brvk::VkSurfaceFormatKHR>> {
1583        let n = self.surface_format_count(surface)?;
1584        if n == 0 {
1585            // no items
1586            return Ok(crate::alloc::empty_sink_buffer());
1587        }
1588
1589        let mut xs = crate::alloc::reserve(n as _);
1590        let filled = self
1591            .surface_formats(surface, xs.spare_capacity_mut())?
1592            .assert_complete();
1593        unsafe {
1594            xs.set_len(filled as _);
1595        }
1596
1597        Ok(xs)
1598    }
1599
1600    /// Query a count of supported presentation modes
1601    /// # Failures
1602    /// On failure, this command returns
1603    ///
1604    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1605    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1606    /// * `brvk::VK_ERROR_SURFACE_LOST_KHR`
1607    #[implements("VK_KHR_surface")]
1608    #[inline(always)]
1609    fn surface_present_mode_count(
1610        &self,
1611        surface: &(impl VkHandle<Handle = brvk::VkSurfaceKHR> + ?Sized),
1612    ) -> crate::Result<u32> {
1613        unsafe {
1614            crate::vkfn_wrapper::get_physical_device_surface_present_mode_count(
1615                self.as_transparent_ref(),
1616                surface.as_transparent_ref(),
1617            )
1618        }
1619    }
1620
1621    /// Query supported presentation modes
1622    /// # Failures
1623    /// On failure, this command returns
1624    ///
1625    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1626    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1627    /// * `brvk::VK_ERROR_SURFACE_LOST_KHR`
1628    #[implements("VK_KHR_surface")]
1629    #[inline(always)]
1630    fn surface_present_modes(
1631        &self,
1632        surface: &(impl VkHandle<Handle = brvk::VkSurfaceKHR> + ?Sized),
1633        sink: &mut [core::mem::MaybeUninit<PresentMode>],
1634    ) -> crate::Result<ArrayQueryResult<u32>> {
1635        unsafe {
1636            crate::vkfn_wrapper::get_physical_device_surface_present_modes(
1637                self.as_transparent_ref(),
1638                surface.as_transparent_ref(),
1639                sink,
1640            )
1641        }
1642    }
1643
1644    /// Query supported presentation modes
1645    /// # Failures
1646    /// On failure, this command returns
1647    ///
1648    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1649    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1650    /// * `brvk::VK_ERROR_SURFACE_LOST_KHR`
1651    #[implements("VK_KHR_surface", "alloc")]
1652    fn surface_present_modes_alloc(&self, surface: &(impl Surface + ?Sized)) -> crate::Result<Vec<PresentMode>> {
1653        let n = self.surface_present_mode_count(surface)?;
1654        if n == 0 {
1655            // no items
1656            return Ok(crate::alloc::empty_sink_buffer());
1657        }
1658
1659        let mut xs = crate::alloc::reserve(n as _);
1660        let filled = self
1661            .surface_present_modes(surface, xs.spare_capacity_mut())?
1662            .assert_complete();
1663        unsafe {
1664            xs.set_len(filled as _);
1665        }
1666
1667        Ok(xs)
1668    }
1669
1670    /// Query physical device for presentation to X11 server using Xlib
1671    ///
1672    /// # Safety
1673    ///
1674    /// Provided `display` must be a valid reference
1675    #[implements("VK_KHR_xlib_surface")]
1676    #[inline(always)]
1677    unsafe fn xlib_presentation_support(
1678        &self,
1679        queue_family: u32,
1680        display: *mut x11::xlib::Display,
1681        visual: x11::xlib::VisualID,
1682    ) -> bool {
1683        unsafe {
1684            crate::vkfn_wrapper::get_physical_device_xlib_presentation_support(
1685                self.as_transparent_ref(),
1686                queue_family,
1687                display,
1688                visual,
1689            )
1690        }
1691    }
1692
1693    /// Query physical device for presentation to X11 server using XCB
1694    ///
1695    /// # Safety
1696    ///
1697    /// Provided `connection` must be a valid reference
1698    #[implements("VK_KHR_xcb_surface")]
1699    #[inline(always)]
1700    unsafe fn xcb_presentation_support(
1701        &self,
1702        queue_family: u32,
1703        connection: *mut xcb::ffi::xcb_connection_t,
1704        visual: xcb::x::Visualid,
1705    ) -> bool {
1706        unsafe {
1707            crate::vkfn_wrapper::get_physical_device_xcb_presentation_support(
1708                self.as_transparent_ref(),
1709                queue_family,
1710                connection,
1711                visual,
1712            )
1713        }
1714    }
1715
1716    /// Query physical device for presentation to Wayland
1717    ///
1718    /// # Safety
1719    ///
1720    /// Provided `display` must be a valid reference
1721    #[implements("VK_KHR_wayland_surface")]
1722    #[inline(always)]
1723    unsafe fn wayland_presentation_support(&self, queue_family: u32, display: *mut core::ffi::c_void) -> bool {
1724        unsafe {
1725            crate::vkfn_wrapper::get_physical_device_wayland_presentation_support(
1726                self.as_transparent_ref(),
1727                queue_family,
1728                display,
1729            )
1730        }
1731    }
1732
1733    /// Query queue family support for presentation on a Win32 display
1734    #[implements("VK_KHR_win32_surface")]
1735    #[inline(always)]
1736    fn win32_presentation_support(&self, queue_family: u32) -> bool {
1737        crate::vkfn_wrapper::get_physical_device_win32_presentation_support(self.as_transparent_ref(), queue_family)
1738    }
1739
1740    /// Query a count of the set of mode properties supported by the display
1741    /// # Failures
1742    /// On failure, this command returns
1743    ///
1744    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1745    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1746    #[implements("VK_KHR_display")]
1747    #[inline(always)]
1748    fn display_mode_property_count(&self, display: VkHandleRef<brvk::VkDisplayKHR>) -> crate::Result<u32> {
1749        unsafe { crate::vkfn_wrapper::get_display_mode_property_count(self.as_transparent_ref(), display) }
1750    }
1751
1752    /// Query the set of mode properties supported by the display
1753    /// # Failures
1754    /// On failure, this command returns
1755    ///
1756    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1757    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1758    #[implements("VK_KHR_display")]
1759    #[inline(always)]
1760    fn display_mode_properties(
1761        &self,
1762        display: VkHandleRef<brvk::VkDisplayKHR>,
1763        sink: &mut [core::mem::MaybeUninit<DisplayModeProperties>],
1764    ) -> crate::Result<ArrayQueryResult<u32>> {
1765        unsafe { crate::vkfn_wrapper::get_display_mode_properties(self.as_transparent_ref(), display, sink) }
1766    }
1767
1768    /// Query the set of mode properties supported by the display
1769    /// # Failures
1770    /// On failure, this command returns
1771    ///
1772    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1773    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1774    #[implements("VK_KHR_display", "alloc")]
1775    fn display_mode_properties_alloc(
1776        &self,
1777        display: VkHandleRef<brvk::VkDisplayKHR>,
1778    ) -> crate::Result<Vec<DisplayModeProperties>> {
1779        let n = self.display_mode_property_count(display)?;
1780        if n == 0 {
1781            // no items
1782            return Ok(crate::alloc::empty_sink_buffer());
1783        }
1784
1785        let mut xs = crate::alloc::reserve(n as _);
1786        let res = self
1787            .display_mode_properties(display, xs.spare_capacity_mut())?
1788            .assert_complete();
1789        unsafe {
1790            xs.set_len(res as _);
1791        }
1792
1793        Ok(xs)
1794    }
1795
1796    /// Create a display mode
1797    /// # Failures
1798    /// On failure, this command returns
1799    ///
1800    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1801    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1802    /// * `brvk::VK_ERROR_INITIALIZATION_FAILED`
1803    ///
1804    /// # Safety
1805    /// no guarantee will be provided (simply calls under api)
1806    #[implements("VK_KHR_display")]
1807    #[inline]
1808    unsafe fn new_display_mode_raw(
1809        &self,
1810        display: brvk::VkDisplayKHR,
1811        info: &brvk::VkDisplayModeCreateInfoKHR,
1812        allocation_callbacks: Option<&brvk::VkAllocationCallbacks>,
1813    ) -> crate::Result<brvk::VkDisplayModeKHR> {
1814        let mut h = core::mem::MaybeUninit::uninit();
1815
1816        translate_vk_result(unsafe {
1817            brvk::fns::create_display_mode_khr(
1818                self.native_ptr(),
1819                display,
1820                info,
1821                crate::ffi_helper::opt_pointer(allocation_callbacks),
1822                h.as_mut_ptr(),
1823            )
1824        })?;
1825
1826        Ok(unsafe { h.assume_init() })
1827    }
1828
1829    /// Query capabilities of a mode and plane combination
1830    /// # Failures
1831    /// On failure, this command returns
1832    ///
1833    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1834    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1835    #[implements("VK_KHR_display")]
1836    #[inline]
1837    fn display_plane_capabilities(
1838        &self,
1839        mode: VkHandleRefMut<brvk::VkDisplayModeKHR>,
1840        plane_index: u32,
1841    ) -> crate::Result<brvk::VkDisplayPlaneCapabilitiesKHR> {
1842        let mut s = core::mem::MaybeUninit::uninit();
1843        unsafe {
1844            crate::vkfn_wrapper::get_display_plane_capabilities(self.as_transparent_ref(), mode, plane_index, &mut s)?;
1845        }
1846
1847        Ok(unsafe { s.assume_init() })
1848    }
1849
1850    /// Query a count of information about the available displays
1851    /// # Failures
1852    /// On failure, this command returns
1853    ///
1854    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1855    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1856    #[implements("VK_KHR_display")]
1857    #[inline(always)]
1858    fn display_property_count(&self) -> crate::Result<u32> {
1859        crate::vkfn_wrapper::get_physical_device_display_property_count(self.as_transparent_ref())
1860    }
1861
1862    /// Query information about the available displays
1863    /// # Failures
1864    /// On failure, this command returns
1865    ///
1866    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1867    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1868    #[implements("VK_KHR_display")]
1869    #[inline(always)]
1870    fn display_properties(
1871        &self,
1872        sink: &mut [core::mem::MaybeUninit<DisplayProperties>],
1873    ) -> crate::Result<ArrayQueryResult<u32>> {
1874        crate::vkfn_wrapper::get_physical_device_display_properties(self.as_transparent_ref(), sink)
1875    }
1876
1877    /// Query information about the available displays.
1878    /// # Failures
1879    /// On failure, this command returns
1880    ///
1881    /// * brvk::VK_ERROR_OUT_OF_HOST_MEMORY
1882    /// * brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY
1883    #[implements("VK_KHR_display", "alloc")]
1884    fn display_properties_alloc(&self) -> crate::Result<Vec<DisplayPropertiesWithPhysicalDeviceRef<&Self>>> {
1885        let n = self.display_property_count()?;
1886        if n == 0 {
1887            // no items
1888            return Ok(crate::alloc::empty_sink_buffer());
1889        }
1890
1891        let mut xs = crate::alloc::reserve(n as _);
1892        let r = self.display_properties(xs.spare_capacity_mut())?.assert_complete();
1893        unsafe {
1894            xs.set_len(r as _);
1895        }
1896
1897        Ok(crate::alloc::collect_vec(
1898            xs.into_iter()
1899                .map(move |x| DisplayPropertiesWithPhysicalDeviceRef(x, self)),
1900        ))
1901    }
1902
1903    /// Query a count of the plane properties
1904    /// # Failures
1905    /// On failure, this command returns
1906    ///
1907    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1908    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1909    #[implements("VK_KHR_display")]
1910    #[inline(always)]
1911    fn display_plane_property_count(&self) -> crate::Result<u32> {
1912        crate::vkfn_wrapper::get_physical_device_display_plane_property_count(self.as_transparent_ref())
1913    }
1914
1915    /// Query the plane properties
1916    /// # Failures
1917    /// On failure, this command returns
1918    ///
1919    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1920    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1921    #[implements("VK_KHR_display")]
1922    #[inline(always)]
1923    fn display_plane_properties(
1924        &self,
1925        sink: &mut [core::mem::MaybeUninit<brvk::VkDisplayPlanePropertiesKHR>],
1926    ) -> crate::Result<ArrayQueryResult<u32>> {
1927        crate::vkfn_wrapper::get_physical_device_display_plane_properties(self.as_transparent_ref(), sink)
1928    }
1929
1930    /// Query the plane properties.
1931    /// # Failures
1932    /// On failure, this command returns
1933    ///
1934    /// * brvk::VK_ERROR_OUT_OF_HOST_MEMORY
1935    /// * brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY
1936    #[implements("VK_KHR_display", "alloc")]
1937    fn display_plane_properties_alloc(&self) -> crate::Result<Vec<DisplayPlanePropertiesWithPhysicalDeviceRef<&Self>>> {
1938        let n = self.display_plane_property_count()?;
1939        if n == 0 {
1940            // no items
1941            return Ok(crate::alloc::empty_sink_buffer());
1942        }
1943
1944        let mut xs = crate::alloc::reserve(n as _);
1945        let r = self
1946            .display_plane_properties(xs.spare_capacity_mut())?
1947            .assert_complete();
1948        unsafe {
1949            xs.set_len(r as _);
1950        }
1951
1952        Ok(crate::alloc::collect_vec(
1953            xs.into_iter()
1954                .map(move |x| DisplayPlanePropertiesWithPhysicalDeviceRef(x, self)),
1955        ))
1956    }
1957
1958    /// Query a count of the list of displays a plane supports
1959    /// # Failures
1960    /// On failure, this command returns
1961    ///
1962    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1963    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1964    #[implements("VK_KHR_display")]
1965    #[inline(always)]
1966    fn display_plane_supported_display_count(&self, plane_index: u32) -> crate::Result<u32> {
1967        crate::vkfn_wrapper::get_display_plane_supported_display_count(self.as_transparent_ref(), plane_index)
1968    }
1969
1970    /// Query the list of displays a plane supports
1971    /// # Failures
1972    /// On failure, this command returns
1973    ///
1974    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
1975    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
1976    #[implements("VK_KHR_display")]
1977    #[inline(always)]
1978    fn display_plane_supported_displays(
1979        &self,
1980        plane_index: u32,
1981        sink: &mut [core::mem::MaybeUninit<brvk::VkDisplayKHR>],
1982    ) -> crate::Result<ArrayQueryResult<u32>> {
1983        crate::vkfn_wrapper::get_display_plane_supported_displays(self.as_transparent_ref(), plane_index, sink)
1984    }
1985
1986    /// Query the list of displays a plane supports.
1987    /// # Failures
1988    /// On failure, this command returns
1989    ///
1990    /// * brvk::VK_ERROR_OUT_OF_HOST_MEMORY
1991    /// * brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY
1992    #[implements("VK_KHR_display", "alloc")]
1993    fn display_plane_supported_displays_alloc(&self, plane_index: u32) -> crate::Result<Vec<Display<&Self>>> {
1994        let n = self.display_plane_supported_display_count(plane_index)?;
1995        if n == 0 {
1996            // no items
1997            return Ok(crate::alloc::empty_sink_buffer());
1998        }
1999
2000        let mut xs = crate::alloc::reserve(n as _);
2001        let r = self
2002            .display_plane_supported_displays(plane_index, xs.spare_capacity_mut())?
2003            .assert_complete();
2004        unsafe {
2005            xs.set_len(r as _);
2006        }
2007
2008        Ok(crate::alloc::collect_vec(xs.into_iter().map(move |x| Display(x, self))))
2009    }
2010
2011    /// Create a `Surface` object representing a display plane and mode
2012    /// # Failures
2013    /// On failure, this command returns
2014    ///
2015    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
2016    /// * `brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`
2017    ///
2018    /// # Safety
2019    /// no guarantee will be provided (simply calls under api)
2020    #[implements("VK_KHR_display", "VK_KHR_surface")]
2021    #[inline]
2022    unsafe fn new_surface_for_display_plane_raw(
2023        &self,
2024        info: &brvk::VkDisplaySurfaceCreateInfoKHR,
2025        allocation_callbacks: Option<&brvk::VkAllocationCallbacks>,
2026    ) -> crate::Result<brvk::VkSurfaceKHR> {
2027        let mut h = core::mem::MaybeUninit::uninit();
2028        translate_vk_result(unsafe {
2029            brvk::fns::create_display_plane_surface_khr(
2030                self.instance().native_ptr(),
2031                info,
2032                crate::ffi_helper::opt_pointer(allocation_callbacks),
2033                h.as_mut_ptr(),
2034            )
2035        })?;
2036
2037        Ok(unsafe { h.assume_init() })
2038    }
2039
2040    /// Query the brvk::VkDisplayKHR corresponding to an X11 RandR Output
2041    /// # Failures
2042    /// On failure, this command returns
2043    /// * `brvk::VK_ERROR_OUT_OF_HOST_MEMORY`
2044    ///
2045    /// # Safety
2046    /// Provided `dpy` must be a valid reference
2047    #[implements("VK_EXT_acquire_xlib_display")]
2048    #[inline]
2049    unsafe fn get_randr_output_display(
2050        self,
2051        dpy: *mut x11::xlib::Display,
2052        rr_output: x11::xrandr::RROutput,
2053    ) -> crate::Result<Display<Self>>
2054    where
2055        Self: Sized,
2056        Self::ConcreteInstance: InstanceAcquireXlibDisplayExtension,
2057    {
2058        let mut d = core::mem::MaybeUninit::uninit();
2059
2060        crate::error::translate_vk_result(unsafe {
2061            self.instance().get_randr_output_display_ext_fn().0(self.native_ptr(), dpy, rr_output, d.as_mut_ptr())
2062        })?;
2063
2064        Ok(Display(unsafe { d.assume_init() }, self))
2065    }
2066
2067    /// Query a count of supported presentation modes
2068    /// # Failures
2069    /// On failure, this command returns
2070    ///
2071    /// * [`brvk::VK_ERROR_OUT_OF_HOST_MEMORY`]
2072    /// * [`brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`]
2073    /// * [`brvk::VK_ERROR_SURFACE_LOST_KHR`]
2074    #[implements("VK_EXT_full_screen_exclusive")]
2075    #[inline(always)]
2076    fn surface_present_mode2_count(&self, surface_info: &brvk::VkPhysicalDeviceSurfaceInfo2KHR) -> crate::Result<u32>
2077    where
2078        Self::ConcreteInstance: InstanceFullScreenExclusiveExtension,
2079    {
2080        unsafe {
2081            self.instance()
2082                .get_physical_device_surface_present_mode2_count(self.as_transparent_ref(), surface_info)
2083        }
2084    }
2085
2086    /// Query supported presentation modes
2087    /// # Failures
2088    /// On failure, this command returns
2089    ///
2090    /// * [`brvk::VK_ERROR_OUT_OF_HOST_MEMORY`]
2091    /// * [`brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`]
2092    /// * [`brvk::VK_ERROR_SURFACE_LOST_KHR`]
2093    #[implements("VK_EXT_full_screen_exclusive")]
2094    #[inline(always)]
2095    fn surface_present_modes2(
2096        &self,
2097        surface_info: &brvk::VkPhysicalDeviceSurfaceInfo2KHR,
2098        sink: &mut [core::mem::MaybeUninit<brvk::VkPresentModeKHR>],
2099    ) -> crate::Result<ArrayQueryResult<u32>>
2100    where
2101        Self::ConcreteInstance: InstanceFullScreenExclusiveExtension,
2102    {
2103        unsafe {
2104            self.instance()
2105                .get_physical_device_surface_present_modes2(self.as_transparent_ref(), surface_info, sink)
2106        }
2107    }
2108
2109    /// Query supported presentation modes.
2110    ///
2111    /// # Failures
2112    ///
2113    /// On failure, this command returns
2114    /// * [`brvk::VK_ERROR_OUT_OF_HOST_MEMORY`]
2115    /// * [`brvk::VK_ERROR_OUT_OF_DEVICE_MEMORY`]
2116    /// * [`brvk::VK_ERROR_SURFACE_LOST_KHR`]
2117    #[implements("VK_EXT_full_screen_exclusive", "alloc")]
2118    fn surface_present_modes2_alloc(
2119        &self,
2120        surface_info: &brvk::VkPhysicalDeviceSurfaceInfo2KHR,
2121    ) -> crate::Result<Vec<brvk::VkPresentModeKHR>>
2122    where
2123        Self::ConcreteInstance: InstanceFullScreenExclusiveExtension,
2124    {
2125        let n = self.surface_present_mode2_count(surface_info)?;
2126        if n == 0 {
2127            // no items
2128            return Ok(crate::alloc::empty_sink_buffer());
2129        }
2130
2131        let mut xs = crate::alloc::reserve(n as _);
2132        let r = self.surface_present_modes2(surface_info, xs.spare_capacity_mut())?;
2133        assert!(!r.is_incomplete);
2134        unsafe {
2135            xs.set_len(r.result as _);
2136        }
2137
2138        Ok(xs)
2139    }
2140}
2141DerefContainerWithGuardsBracketImpl!(for PhysicalDevice {});
2142
2143pub trait InstanceChild {
2144    type ConcreteInstance: Instance;
2145
2146    fn instance(&self) -> &Self::ConcreteInstance;
2147}
2148DerefContainerBracketImpl!(for InstanceChild {
2149    type ConcreteInstance = T::ConcreteInstance;
2150
2151    #[inline(always)]
2152    fn instance(&self) -> &Self::ConcreteInstance { T::instance(self) }
2153});
2154GuardsImpl!(for InstanceChild {
2155    type ConcreteInstance = T::ConcreteInstance;
2156
2157    #[inline(always)]
2158    fn instance(&self) -> &Self::ConcreteInstance { T::instance(self) }
2159});
2160
2161pub trait InstanceChildTransferrable: InstanceChild {
2162    fn transfer_instance(self) -> Self::ConcreteInstance;
2163}
2164impl<T> InstanceChildTransferrable for &'_ T
2165where
2166    T: InstanceChild,
2167    T::ConcreteInstance: Clone,
2168{
2169    #[inline(always)]
2170    fn transfer_instance(self) -> Self::ConcreteInstance {
2171        self.instance().clone()
2172    }
2173}
2174
2175pub type PhysicalDeviceFeatures = brvk::VkPhysicalDeviceFeatures;
2176#[cfg(feature = "Allow1_2APIs")]
2177pub type PhysicalDeviceVulkan11Features = brvk::VkPhysicalDeviceVulkan11Features;
2178
2179pub type PhysicalDeviceProperties = brvk::VkPhysicalDeviceProperties;
2180#[cfg(feature = "Allow1_2APIs")]
2181pub type PhysicalDeviceVulkan11Properties = brvk::VkPhysicalDeviceVulkan11Properties;
2182
2183#[repr(transparent)]
2184pub struct PhysicalDeviceMemoryProperties(brvk::VkPhysicalDeviceMemoryProperties);
2185impl PhysicalDeviceMemoryProperties {
2186    #[inline(always)]
2187    pub fn types(&self) -> &[MemoryType] {
2188        unsafe { core::mem::transmute::<&[_], &[_]>(&self.0.memoryTypes[..self.0.memoryTypeCount as _]) }
2189    }
2190
2191    #[inline(always)]
2192    pub fn heaps(&self) -> &[MemoryHeap] {
2193        unsafe { core::mem::transmute::<&[_], &[_]>(&self.0.memoryHeaps[..self.0.memoryHeapCount as _]) }
2194    }
2195}
2196
2197#[repr(transparent)]
2198#[derive(Debug, Clone)]
2199pub struct MemoryType(brvk::VkMemoryType);
2200impl MemoryType {
2201    pub const fn property_flags(&self) -> MemoryPropertyFlags {
2202        MemoryPropertyFlags(self.0.propertyFlags)
2203    }
2204
2205    pub const fn heap_index(&self) -> u32 {
2206        self.0.heapIndex
2207    }
2208}
2209
2210#[repr(transparent)]
2211#[derive(Debug, Clone)]
2212pub struct MemoryHeap(brvk::VkMemoryHeap);
2213impl MemoryHeap {
2214    pub const fn flags(&self) -> MemoryHeapFlags {
2215        MemoryHeapFlags(self.0.flags)
2216    }
2217
2218    pub const fn size(&self) -> brvk::VkDeviceSize {
2219        self.0.size
2220    }
2221}
2222
2223/// Device memory properties
2224#[repr(transparent)]
2225pub struct MemoryProperties(PhysicalDeviceMemoryProperties);
2226impl MemoryProperties {
2227    #[inline(always)]
2228    pub fn types(&self) -> &[MemoryType] {
2229        self.0.types()
2230    }
2231    #[inline(always)]
2232    pub fn heaps(&self) -> &[MemoryHeap] {
2233        self.0.heaps()
2234    }
2235
2236    #[inline]
2237    pub fn find_type_index(
2238        &self,
2239        mask: MemoryPropertyFlags,
2240        exclude: MemoryPropertyFlags,
2241        index_mask: u32,
2242    ) -> Option<u32> {
2243        self.types().iter().enumerate().find_map(|(i, mt)| {
2244            (index_mask & (1u32 << i) != 0
2245                && mt.property_flags().has_all(mask)
2246                && !mt.property_flags().has_any(exclude))
2247            .then_some(i as _)
2248        })
2249    }
2250
2251    pub fn find_device_local_index(&self, index_mask: u32) -> Option<u32> {
2252        self.find_type_index(
2253            MemoryPropertyFlags::DEVICE_LOCAL,
2254            MemoryPropertyFlags::LAZILY_ALLOCATED,
2255            index_mask,
2256        )
2257    }
2258    pub fn find_lazily_allocated_device_local_index(&self, index_mask: u32) -> Option<u32> {
2259        self.find_type_index(
2260            MemoryPropertyFlags::DEVICE_LOCAL | MemoryPropertyFlags::LAZILY_ALLOCATED,
2261            MemoryPropertyFlags::EMPTY,
2262            index_mask,
2263        )
2264    }
2265    pub fn find_host_visible_index(&self, index_mask: u32) -> Option<u32> {
2266        self.find_type_index(
2267            MemoryPropertyFlags::HOST_VISIBLE,
2268            MemoryPropertyFlags::EMPTY,
2269            index_mask,
2270        )
2271    }
2272
2273    pub fn is_coherent(&self, index: u32) -> bool {
2274        self.0.types()[index as usize]
2275            .property_flags()
2276            .has_any(MemoryPropertyFlags::HOST_COHERENT)
2277    }
2278    pub fn is_cached(&self, index: u32) -> bool {
2279        self.0.types()[index as usize]
2280            .property_flags()
2281            .has_any(MemoryPropertyFlags::HOST_CACHED)
2282    }
2283}
2284
2285/// Bitmask specifying properties for a memory type
2286#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2287#[bitflags_newtype]
2288pub struct MemoryPropertyFlags(brvk::VkMemoryPropertyFlags);
2289impl MemoryPropertyFlags {
2290    /// Empty set
2291    pub const EMPTY: Self = MemoryPropertyFlags(0);
2292
2293    /// Memory allocated with this type is the most efficient for device access
2294    pub const DEVICE_LOCAL: Self = MemoryPropertyFlags(brvk::VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
2295    /// Memory allocated with this type can be mapped for host access using `vkMapMemory`
2296    pub const HOST_VISIBLE: Self = MemoryPropertyFlags(brvk::VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
2297    /// The host cache management commands `vkFlushMappedMemoryRanges` and `vkInvalidateMappedMemoryRanges`
2298    /// are not needed to flush host writes to the device or make device writes visible to the host, respectively.
2299    pub const HOST_COHERENT: Self = MemoryPropertyFlags(brvk::VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
2300    /// Memory allocated with this type is cached on the host.
2301    /// Host memory accesses to uncached memory are slower than to cached memory, however uncached memory is always host coherent
2302    pub const HOST_CACHED: Self = MemoryPropertyFlags(brvk::VK_MEMORY_PROPERTY_HOST_CACHED_BIT);
2303    /// The memory type only allows device access to the memory.
2304    pub const LAZILY_ALLOCATED: Self = MemoryPropertyFlags(brvk::VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT);
2305
2306    #[cfg(feature = "Allow1_1APIs")]
2307    /// The memory type only allows device access to the memory, and allows protected queue operations to access the memory.
2308    pub const PROTECTED: Self = Self(brvk::VK_MEMORY_PROPERTY_PROTECTED_BIT);
2309}
2310
2311/// Bitmask specifying attribute flags for a heap
2312#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2313#[bitflags_newtype]
2314pub struct MemoryHeapFlags(brvk::VkMemoryHeapFlags);
2315impl MemoryHeapFlags {
2316    /// Empty set
2317    pub const EMPTY: Self = Self(0);
2318
2319    /// The heap corresponds to device-local memory.
2320    /// Device-local memory may have different performance characteristics than host-local memory,
2321    /// and may support different memory property flags.
2322    pub const DEVICE_LOCAL: Self = Self(brvk::VK_MEMORY_HEAP_DEVICE_LOCAL_BIT);
2323
2324    #[cfg(feature = "Allow1_1APIs")]
2325    /// In a logical device representing more than one physical device,
2326    /// there is a per-physical device instance of the heap memory.
2327    /// By default, an allocation from such a heap will be replicated to each physical device's instance of the heap.
2328    pub const MULTI_INSTANCE: Self = Self(brvk::VK_MEMORY_HEAP_MULTI_INSTANCE_BIT);
2329}
2330
2331/// List of queue families
2332pub struct QueueFamilies(pub Vec<QueueFamilyProperties>);
2333impl QueueFamilies {
2334    /// Find a queue family index containing specified bitflags
2335    pub fn find_matching_index(&self, flags: QueueFlags) -> Option<u32> {
2336        self.0
2337            .iter()
2338            .position(|q| q.queue_flags().has_all(flags))
2339            .map(|x| x as _)
2340    }
2341
2342    /// Find a queue family index containing specified bitflags
2343    pub fn find_another_matching_index(&self, flags: QueueFlags, exclude: u32) -> Option<u32> {
2344        self.0
2345            .iter()
2346            .enumerate()
2347            .find_map(|(n, p)| (p.queue_flags().has_all(flags) && exclude != n as u32).then_some(n as _))
2348    }
2349
2350    /// Number of queue families
2351    pub fn count(&self) -> u32 {
2352        self.0.len() as _
2353    }
2354
2355    #[inline(always)]
2356    pub fn iter(&self) -> impl Iterator<Item = &QueueFamilyProperties> {
2357        self.0.iter()
2358    }
2359
2360    /// Number of queues in selected queue family
2361    pub fn queue_count(&self, family_index: u32) -> u32 {
2362        self.0[family_index as usize].queue_count()
2363    }
2364
2365    /// Unsigned integer count of meaningful bits in the timestamps written via `vkCmdWriteTimestamp`
2366    pub fn timestamp_valid_bits(&self, family_index: u32) -> u32 {
2367        self.0[family_index as usize].timestamp_valid_bits()
2368    }
2369
2370    /// Minimum granularity supported for image transfer operations on the queues in selected queue family
2371    pub fn minimum_image_transfer_granularity(&self, family_index: u32) -> &brvk::VkExtent3D {
2372        self.0[family_index as usize].min_image_transfer_granularity()
2373    }
2374}
2375
2376#[repr(transparent)]
2377pub struct QueueFamilyProperties(brvk::VkQueueFamilyProperties);
2378impl QueueFamilyProperties {
2379    pub const fn queue_flags(&self) -> QueueFlags {
2380        QueueFlags(self.0.queueFlags)
2381    }
2382
2383    pub const fn queue_count(&self) -> u32 {
2384        self.0.queueCount
2385    }
2386
2387    pub const fn timestamp_valid_bits(&self) -> u32 {
2388        self.0.timestampValidBits
2389    }
2390
2391    pub const fn min_image_transfer_granularity(&self) -> &brvk::VkExtent3D {
2392        &self.0.minImageTransferGranularity
2393    }
2394}
2395
2396/// Set of bit of queue flags
2397#[derive(Debug, Clone, PartialEq, Eq, Copy)]
2398#[bitflags_newtype]
2399pub struct QueueFlags(brvk::VkQueueFlags);
2400impl QueueFlags {
2401    /// Empty bits
2402    pub const EMPTY: Self = QueueFlags(0);
2403    /// Supports only graphics operations
2404    pub const GRAPHICS: Self = QueueFlags(brvk::VK_QUEUE_GRAPHICS_BIT);
2405    /// Supports only compute operations
2406    pub const COMPUTE: Self = QueueFlags(brvk::VK_QUEUE_COMPUTE_BIT);
2407    /// Supports only transfer operations
2408    pub const TRANSFER: Self = QueueFlags(brvk::VK_QUEUE_TRANSFER_BIT);
2409    /// Supports only sparse memory management operations
2410    pub const SPARSE_BINDING: Self = QueueFlags(brvk::VK_QUEUE_SPARSE_BINDING_BIT);
2411}
2412
2413#[cfg(feature = "VK_KHR_display")]
2414mod display;
2415#[cfg(feature = "VK_KHR_display")]
2416pub use self::display::*;