1 use crate::prelude::*; 2 use crate::vk; 3 use crate::{Entry, Instance}; 4 use std::ffi::CStr; 5 use std::mem; 6 use 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)] 10 pub struct DeviceGroupCreation { 11 handle: vk::Instance, 12 fp: vk::KhrDeviceGroupCreationFn, 13 } 14 15 impl DeviceGroupCreation { new(entry: Entry, instance: &Instance) -> Self16 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] enumerate_physical_device_groups_len(&self) -> VkResult<usize>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] enumerate_physical_device_groups( &self, out: &mut [vk::PhysicalDeviceGroupProperties], ) -> VkResult<()>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] name() -> &'static CStr53 pub const fn name() -> &'static CStr { 54 vk::KhrDeviceGroupCreationFn::name() 55 } 56 57 #[inline] fp(&self) -> &vk::KhrDeviceGroupCreationFn58 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] device(&self) -> vk::Instance64 pub fn device(&self) -> vk::Instance { 65 self.handle 66 } 67 68 #[inline] instance(&self) -> vk::Instance69 pub fn instance(&self) -> vk::Instance { 70 self.handle 71 } 72 } 73