jay_ash/extensions/khr/device_group.rs
1//! <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_device_group.html>
2
3#[cfg(doc)]
4use crate::khr;
5use crate::prelude::*;
6use crate::vk;
7use alloc::vec::Vec;
8use core::mem;
9
10impl crate::khr::device_group::Device {
11 /// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetDeviceGroupPeerMemoryFeaturesKHR.html>
12 #[inline]
13 pub unsafe fn get_device_group_peer_memory_features(
14 &self,
15 heap_index: u32,
16 local_device_index: u32,
17 remote_device_index: u32,
18 ) -> vk::PeerMemoryFeatureFlags {
19 unsafe {
20 let mut peer_memory_features = mem::MaybeUninit::uninit();
21 (self.fp.get_device_group_peer_memory_features_khr)(
22 self.handle,
23 heap_index,
24 local_device_index,
25 remote_device_index,
26 peer_memory_features.as_mut_ptr(),
27 );
28 peer_memory_features.assume_init()
29 }
30 }
31
32 /// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdSetDeviceMaskKHR.html>
33 #[inline]
34 pub unsafe fn cmd_set_device_mask(&self, command_buffer: vk::CommandBuffer, device_mask: u32) {
35 unsafe { (self.fp.cmd_set_device_mask_khr)(command_buffer, device_mask) }
36 }
37
38 /// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdDispatchBaseKHR.html>
39 #[inline]
40 pub unsafe fn cmd_dispatch_base(
41 &self,
42 command_buffer: vk::CommandBuffer,
43 base_group: (u32, u32, u32),
44 group_count: (u32, u32, u32),
45 ) {
46 unsafe {
47 (self.fp.cmd_dispatch_base_khr)(
48 command_buffer,
49 base_group.0,
50 base_group.1,
51 base_group.2,
52 group_count.0,
53 group_count.1,
54 group_count.2,
55 )
56 }
57 }
58
59 /// Requires [`VK_KHR_surface`] to be enabled.
60 ///
61 /// Also available as [`khr::swapchain::Device::get_device_group_present_capabilities()`] since [Vulkan 1.1].
62 ///
63 /// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetDeviceGroupPresentCapabilitiesKHR.html>
64 ///
65 /// [Vulkan 1.1]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_VERSION_1_1.html
66 /// [`VK_KHR_surface`]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_surface.html
67 #[inline]
68 pub unsafe fn get_device_group_present_capabilities(
69 &self,
70 device_group_present_capabilities: &mut vk::DeviceGroupPresentCapabilitiesKHR<'_>,
71 ) -> VkResult<()> {
72 unsafe {
73 (self.fp.get_device_group_present_capabilities_khr)(
74 self.handle,
75 device_group_present_capabilities,
76 )
77 .result()
78 }
79 }
80
81 /// Requires [`VK_KHR_surface`] to be enabled.
82 ///
83 /// Also available as [`khr::swapchain::Device::get_device_group_surface_present_modes()`] since [Vulkan 1.1].
84 ///
85 /// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetDeviceGroupSurfacePresentModesKHR.html>
86 ///
87 /// [Vulkan 1.1]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_VERSION_1_1.html
88 /// [`VK_KHR_surface`]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_surface.html
89 #[inline]
90 pub unsafe fn get_device_group_surface_present_modes(
91 &self,
92 surface: vk::SurfaceKHR,
93 ) -> VkResult<vk::DeviceGroupPresentModeFlagsKHR> {
94 unsafe {
95 let mut modes = mem::MaybeUninit::uninit();
96 (self.fp.get_device_group_surface_present_modes_khr)(
97 self.handle,
98 surface,
99 modes.as_mut_ptr(),
100 )
101 .assume_init_on_success(modes)
102 }
103 }
104
105 /// On success, returns the next image's index and whether the swapchain is suboptimal for the surface.
106 ///
107 /// Requires [`VK_KHR_swapchain`] to be enabled.
108 ///
109 /// Also available as [`khr::swapchain::Device::acquire_next_image2()`] since [Vulkan 1.1].
110 ///
111 /// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkAcquireNextImage2KHR.html>
112 ///
113 /// [Vulkan 1.1]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_VERSION_1_1.html
114 /// [`VK_KHR_swapchain`]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_swapchain.html
115 #[inline]
116 pub unsafe fn acquire_next_image2(
117 &self,
118 acquire_info: &vk::AcquireNextImageInfoKHR<'_>,
119 ) -> VkResult<(u32, bool)> {
120 unsafe {
121 let mut index = mem::MaybeUninit::uninit();
122 let err_code =
123 (self.fp.acquire_next_image2_khr)(self.handle, acquire_info, index.as_mut_ptr());
124 match err_code {
125 vk::Result::SUCCESS => Ok((index.assume_init(), false)),
126 vk::Result::SUBOPTIMAL_KHR => Ok((index.assume_init(), true)),
127 _ => Err(err_code),
128 }
129 }
130 }
131}
132
133impl crate::khr::device_group::Instance {
134 /// Requires [`VK_KHR_surface`] to be enabled.
135 ///
136 /// Also available as [`khr::swapchain::Instance::get_physical_device_present_rectangles()`] since [Vulkan 1.1].
137 ///
138 /// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDevicePresentRectanglesKHR.html>
139 ///
140 /// [Vulkan 1.1]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_VERSION_1_1.html
141 /// [`VK_KHR_surface`]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_surface.html
142 #[inline]
143 pub unsafe fn get_physical_device_present_rectangles(
144 &self,
145 physical_device: vk::PhysicalDevice,
146 surface: vk::SurfaceKHR,
147 ) -> VkResult<Vec<vk::Rect2D>> {
148 unsafe {
149 read_into_uninitialized_vector(|count, data| {
150 (self.fp.get_physical_device_present_rectangles_khr)(
151 physical_device,
152 surface,
153 count,
154 data,
155 )
156 })
157 }
158 }
159}