Skip to main content

jay_ash/extensions/khr/
surface.rs

1//! <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_surface.html>
2
3use crate::RawPtr;
4use crate::prelude::*;
5use crate::vk;
6use alloc::vec::Vec;
7use core::mem;
8
9impl crate::khr::surface::Instance {
10    /// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceSurfaceSupportKHR.html>
11    #[inline]
12    pub unsafe fn get_physical_device_surface_support(
13        &self,
14        physical_device: vk::PhysicalDevice,
15        queue_family_index: u32,
16        surface: vk::SurfaceKHR,
17    ) -> VkResult<bool> {
18        unsafe {
19            let mut b = mem::MaybeUninit::uninit();
20            (self.fp.get_physical_device_surface_support_khr)(
21                physical_device,
22                queue_family_index,
23                surface,
24                b.as_mut_ptr(),
25            )
26            .result()?;
27            Ok(b.assume_init() > 0)
28        }
29    }
30
31    /// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceSurfacePresentModesKHR.html>
32    #[inline]
33    pub unsafe fn get_physical_device_surface_present_modes(
34        &self,
35        physical_device: vk::PhysicalDevice,
36        surface: vk::SurfaceKHR,
37    ) -> VkResult<Vec<vk::PresentModeKHR>> {
38        unsafe {
39            read_into_uninitialized_vector(|count, data| {
40                (self.fp.get_physical_device_surface_present_modes_khr)(
41                    physical_device,
42                    surface,
43                    count,
44                    data,
45                )
46            })
47        }
48    }
49
50    /// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceSurfaceCapabilitiesKHR.html>
51    #[inline]
52    pub unsafe fn get_physical_device_surface_capabilities(
53        &self,
54        physical_device: vk::PhysicalDevice,
55        surface: vk::SurfaceKHR,
56    ) -> VkResult<vk::SurfaceCapabilitiesKHR> {
57        unsafe {
58            let mut surface_capabilities = mem::MaybeUninit::uninit();
59            (self.fp.get_physical_device_surface_capabilities_khr)(
60                physical_device,
61                surface,
62                surface_capabilities.as_mut_ptr(),
63            )
64            .assume_init_on_success(surface_capabilities)
65        }
66    }
67
68    /// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceSurfaceFormatsKHR.html>
69    #[inline]
70    pub unsafe fn get_physical_device_surface_formats(
71        &self,
72        physical_device: vk::PhysicalDevice,
73        surface: vk::SurfaceKHR,
74    ) -> VkResult<Vec<vk::SurfaceFormatKHR>> {
75        unsafe {
76            read_into_uninitialized_vector(|count, data| {
77                (self.fp.get_physical_device_surface_formats_khr)(
78                    physical_device,
79                    surface,
80                    count,
81                    data,
82                )
83            })
84        }
85    }
86
87    /// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkDestroySurfaceKHR.html>
88    #[inline]
89    pub unsafe fn destroy_surface(
90        &self,
91        surface: vk::SurfaceKHR,
92        allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
93    ) {
94        unsafe {
95            (self.fp.destroy_surface_khr)(self.handle, surface, allocation_callbacks.as_raw_ptr());
96        }
97    }
98}