ash/extensions/ext/
full_screen_exclusive.rs

1use crate::prelude::*;
2use crate::vk;
3use crate::{Device, Entry, Instance};
4use std::ffi::CStr;
5use std::mem;
6
7/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_EXT_full_screen_exclusive.html>
8#[derive(Clone)]
9pub struct FullScreenExclusive {
10    handle: vk::Device,
11    fp: vk::ExtFullScreenExclusiveFn,
12}
13
14impl FullScreenExclusive {
15    /// # Warning
16    /// [`Instance`] functions cannot be loaded from a [`Device`] and will always panic when called:
17    /// - [`Self::get_physical_device_surface_present_modes2()`]
18    ///
19    /// Load this struct using an [`Instance`] instead via [`Self::new_from_instance()`] if the
20    /// above [`Instance`] function is called. This will be solved in the next breaking `ash`
21    /// release: <https://github.com/ash-rs/ash/issues/727>.
22    pub fn new(instance: &Instance, device: &Device) -> Self {
23        let handle = device.handle();
24        let fp = vk::ExtFullScreenExclusiveFn::load(|name| unsafe {
25            mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr()))
26        });
27        Self { handle, fp }
28    }
29
30    /// Loads all functions on the [`Instance`] instead of [`Device`]. This incurs an extra
31    /// dispatch table for [`Device`] functions but also allows the [`Instance`] function to be
32    /// loaded instead of always panicking. See also [`Self::new()`] for more details.
33    ///
34    /// It is okay to pass [`vk::Device::null()`] when this struct is only used to call the
35    /// [`Instance`] function.
36    pub fn new_from_instance(entry: &Entry, instance: &Instance, device: vk::Device) -> Self {
37        let fp = vk::ExtFullScreenExclusiveFn::load(|name| unsafe {
38            mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
39        });
40        Self { handle: device, fp }
41    }
42
43    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkAcquireFullScreenExclusiveModeEXT.html>
44    #[inline]
45    pub unsafe fn acquire_full_screen_exclusive_mode(
46        &self,
47        swapchain: vk::SwapchainKHR,
48    ) -> VkResult<()> {
49        (self.fp.acquire_full_screen_exclusive_mode_ext)(self.handle, swapchain).result()
50    }
51
52    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceSurfacePresentModes2EXT.html>
53    ///
54    /// # Warning
55    ///
56    /// Function will always panic unless this struct is loaded via [`Self::new_from_instance()`].
57    #[inline]
58    pub unsafe fn get_physical_device_surface_present_modes2(
59        &self,
60        physical_device: vk::PhysicalDevice,
61        surface_info: &vk::PhysicalDeviceSurfaceInfo2KHR,
62    ) -> VkResult<Vec<vk::PresentModeKHR>> {
63        read_into_uninitialized_vector(|count, data| {
64            (self.fp.get_physical_device_surface_present_modes2_ext)(
65                physical_device,
66                surface_info,
67                count,
68                data,
69            )
70        })
71    }
72
73    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkReleaseFullScreenExclusiveModeEXT.html>
74    #[inline]
75    pub unsafe fn release_full_screen_exclusive_mode(
76        &self,
77        swapchain: vk::SwapchainKHR,
78    ) -> VkResult<()> {
79        (self.fp.release_full_screen_exclusive_mode_ext)(self.handle, swapchain).result()
80    }
81
82    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetDeviceGroupSurfacePresentModes2EXT.html>
83    #[inline]
84    pub unsafe fn get_device_group_surface_present_modes2(
85        &self,
86        surface_info: &vk::PhysicalDeviceSurfaceInfo2KHR,
87    ) -> VkResult<vk::DeviceGroupPresentModeFlagsKHR> {
88        let mut present_modes = mem::zeroed();
89        (self.fp.get_device_group_surface_present_modes2_ext)(
90            self.handle,
91            surface_info,
92            &mut present_modes,
93        )
94        .result_with_success(present_modes)
95    }
96
97    #[inline]
98    pub const fn name() -> &'static CStr {
99        vk::ExtFullScreenExclusiveFn::name()
100    }
101
102    #[inline]
103    pub fn fp(&self) -> &vk::ExtFullScreenExclusiveFn {
104        &self.fp
105    }
106
107    #[inline]
108    pub fn device(&self) -> vk::Device {
109        self.handle
110    }
111}