From 85fa5425d91733201ca6f9a73cbf6e748976d309 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Sun, 5 Jun 2022 12:32:26 +0200 Subject: [PATCH] extensions/khr: Add VK_KHR_device_group_creation (#630) --- Changelog.md | 1 + .../extensions/khr/device_group_creation.rs | 62 +++++++++++++++++++ ash/src/extensions/khr/mod.rs | 2 + 3 files changed, 65 insertions(+) create mode 100644 ash/src/extensions/khr/device_group_creation.rs diff --git a/Changelog.md b/Changelog.md index 355131a..af9b41f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added `VK_EXT_sample_locations` device extension (#616) - Update Vulkan-Headers to 1.3.211 (#605, #608) - Added `VK_EXT_image_drm_format_modifier` device extension (#603) +- Added `VK_KHR_device_group_creation` instance extension (#630) ### Removed diff --git a/ash/src/extensions/khr/device_group_creation.rs b/ash/src/extensions/khr/device_group_creation.rs new file mode 100644 index 0000000..f6c72b4 --- /dev/null +++ b/ash/src/extensions/khr/device_group_creation.rs @@ -0,0 +1,62 @@ +use crate::prelude::*; +use crate::vk; +use crate::{Entry, Instance}; +use std::ffi::CStr; +use std::mem; +use std::ptr; + +#[derive(Clone)] +pub struct DeviceGroupCreation { + handle: vk::Instance, + fp: vk::KhrDeviceGroupCreationFn, +} + +impl DeviceGroupCreation { + pub fn new(entry: Entry, instance: &Instance) -> Self { + let handle = instance.handle(); + let fp = vk::KhrDeviceGroupCreationFn::load(|name| unsafe { + mem::transmute(entry.get_instance_proc_addr(handle, name.as_ptr())) + }); + Self { handle, fp } + } + + /// Retrieve the number of elements to pass to [`enumerate_physical_device_groups()`][Self::enumerate_physical_device_groups()] + #[inline] + pub unsafe fn enumerate_physical_device_groups_len(&self) -> VkResult { + let mut group_count = 0; + (self.fp.enumerate_physical_device_groups_khr)( + self.handle, + &mut group_count, + ptr::null_mut(), + ) + .result_with_success(group_count as usize) + } + + /// + /// + /// Call [`enumerate_physical_device_groups_len()`][Self::enumerate_physical_device_groups_len()] to query the number of elements to pass to `out`. + /// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer. + #[inline] + pub unsafe fn enumerate_physical_device_groups( + &self, + out: &mut [vk::PhysicalDeviceGroupProperties], + ) -> VkResult<()> { + let mut count = out.len() as u32; + (self.fp.enumerate_physical_device_groups_khr)(self.handle, &mut count, out.as_mut_ptr()) + .result()?; + assert_eq!(count as usize, out.len()); + Ok(()) + } + + pub const fn name() -> &'static CStr { + vk::KhrDeviceGroupCreationFn::name() + } + + pub fn fp(&self) -> &vk::KhrDeviceGroupCreationFn { + &self.fp + } + + pub fn device(&self) -> vk::Instance { + self.handle + } +} diff --git a/ash/src/extensions/khr/mod.rs b/ash/src/extensions/khr/mod.rs index 55f6e8e..fe1c5cf 100644 --- a/ash/src/extensions/khr/mod.rs +++ b/ash/src/extensions/khr/mod.rs @@ -4,6 +4,7 @@ pub use self::buffer_device_address::BufferDeviceAddress; pub use self::copy_commands2::CopyCommands2; pub use self::create_render_pass2::CreateRenderPass2; pub use self::deferred_host_operations::DeferredHostOperations; +pub use self::device_group_creation::DeviceGroupCreation; pub use self::display::Display; pub use self::display_swapchain::DisplaySwapchain; pub use self::draw_indirect_count::DrawIndirectCount; @@ -39,6 +40,7 @@ mod buffer_device_address; mod copy_commands2; mod create_render_pass2; mod deferred_host_operations; +mod device_group_creation; mod display; mod display_swapchain; mod draw_indirect_count;