ash/extensions/khr/
device_group_creation.rs

1use crate::prelude::*;
2use crate::vk;
3use crate::{Entry, Instance};
4use std::ffi::CStr;
5use std::mem;
6use std::ptr;
7
8/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_KHR_device_group_creation.html>
9#[derive(Clone)]
10pub struct DeviceGroupCreation {
11    handle: vk::Instance,
12    fp: vk::KhrDeviceGroupCreationFn,
13}
14
15impl DeviceGroupCreation {
16    pub fn new(entry: Entry, instance: &Instance) -> Self {
17        let handle = instance.handle();
18        let fp = vk::KhrDeviceGroupCreationFn::load(|name| unsafe {
19            mem::transmute(entry.get_instance_proc_addr(handle, name.as_ptr()))
20        });
21        Self { handle, fp }
22    }
23
24    /// Retrieve the number of elements to pass to [`enumerate_physical_device_groups()`][Self::enumerate_physical_device_groups()]
25    #[inline]
26    pub unsafe fn enumerate_physical_device_groups_len(&self) -> VkResult<usize> {
27        let mut group_count = 0;
28        (self.fp.enumerate_physical_device_groups_khr)(
29            self.handle,
30            &mut group_count,
31            ptr::null_mut(),
32        )
33        .result_with_success(group_count as usize)
34    }
35
36    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkEnumeratePhysicalDeviceGroupsKHR.html>
37    ///
38    /// Call [`enumerate_physical_device_groups_len()`][Self::enumerate_physical_device_groups_len()] to query the number of elements to pass to `out`.
39    /// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer.
40    #[inline]
41    pub unsafe fn enumerate_physical_device_groups(
42        &self,
43        out: &mut [vk::PhysicalDeviceGroupProperties],
44    ) -> VkResult<()> {
45        let mut count = out.len() as u32;
46        (self.fp.enumerate_physical_device_groups_khr)(self.handle, &mut count, out.as_mut_ptr())
47            .result()?;
48        assert_eq!(count as usize, out.len());
49        Ok(())
50    }
51
52    #[inline]
53    pub const fn name() -> &'static CStr {
54        vk::KhrDeviceGroupCreationFn::name()
55    }
56
57    #[inline]
58    pub fn fp(&self) -> &vk::KhrDeviceGroupCreationFn {
59        &self.fp
60    }
61
62    #[deprecated = "typo: this function is called `device()`, but returns an `Instance`."]
63    #[inline]
64    pub fn device(&self) -> vk::Instance {
65        self.handle
66    }
67
68    #[inline]
69    pub fn instance(&self) -> vk::Instance {
70        self.handle
71    }
72}