#![allow(unused_imports)]
use crate::{vk::Result as VkResult, vk::*, *};
use core::ffi::{CStr, c_char, c_int, c_void};
use core::mem::transmute;
use core::ptr;
pub const EXTENSION_NAME: &CStr = c"VK_KHR_device_group";
pub(super) mod defs {
#![allow(non_camel_case_types, unused_imports)]
use crate::{vk::*, *};
use core::ffi::{CStr, c_char, c_int, c_void};
use core::fmt;
use core::marker::PhantomData;
use core::ptr;
pub type MemoryAllocateFlagsInfoKHR<'a> = MemoryAllocateFlagsInfo<'a>;
pub type BindBufferMemoryDeviceGroupInfoKHR<'a> = BindBufferMemoryDeviceGroupInfo<'a>;
pub type BindImageMemoryDeviceGroupInfoKHR<'a> = BindImageMemoryDeviceGroupInfo<'a>;
pub type DeviceGroupRenderPassBeginInfoKHR<'a> = DeviceGroupRenderPassBeginInfo<'a>;
pub type DeviceGroupCommandBufferBeginInfoKHR<'a> = DeviceGroupCommandBufferBeginInfo<'a>;
pub type DeviceGroupSubmitInfoKHR<'a> = DeviceGroupSubmitInfo<'a>;
pub type DeviceGroupBindSparseInfoKHR<'a> = DeviceGroupBindSparseInfo<'a>;
pub type PeerMemoryFeatureFlagsKHR = PeerMemoryFeatureFlags;
pub type MemoryAllocateFlagsKHR = MemoryAllocateFlags;
pub type PFN_vkGetDeviceGroupPeerMemoryFeaturesKHR = PFN_vkGetDeviceGroupPeerMemoryFeatures;
pub type PFN_vkCmdSetDeviceMaskKHR = PFN_vkCmdSetDeviceMask;
pub type PFN_vkCmdDispatchBaseKHR = PFN_vkCmdDispatchBase;
}
#[cfg(feature = "ffi")]
pub(super) mod ffi {
#![allow(non_camel_case_types)]
use super::defs::*;
pub type VkMemoryAllocateFlagsInfoKHR = MemoryAllocateFlagsInfoKHR<'static>;
pub type VkBindBufferMemoryDeviceGroupInfoKHR = BindBufferMemoryDeviceGroupInfoKHR<'static>;
pub type VkBindImageMemoryDeviceGroupInfoKHR = BindImageMemoryDeviceGroupInfoKHR<'static>;
pub type VkDeviceGroupRenderPassBeginInfoKHR = DeviceGroupRenderPassBeginInfoKHR<'static>;
pub type VkDeviceGroupCommandBufferBeginInfoKHR = DeviceGroupCommandBufferBeginInfoKHR<'static>;
pub type VkDeviceGroupSubmitInfoKHR = DeviceGroupSubmitInfoKHR<'static>;
pub type VkDeviceGroupBindSparseInfoKHR = DeviceGroupBindSparseInfoKHR<'static>;
pub type VkPeerMemoryFeatureFlagsKHR = PeerMemoryFeatureFlagsKHR;
pub type VkMemoryAllocateFlagsKHR = MemoryAllocateFlagsKHR;
}
pub struct InstanceFn {
get_physical_device_present_rectangles: Option<PFN_vkGetPhysicalDevicePresentRectanglesKHR>,
}
impl LoadInstanceFn for InstanceFn {
unsafe fn load_with(
load: impl Fn(&CStr) -> Option<PFN_vkVoidFunction>,
) -> core::result::Result<Self, MissingEntryPointError> {
unsafe {
Ok(Self {
get_physical_device_present_rectangles: transmute(load(
c"vkGetPhysicalDevicePresentRectanglesKHR",
)),
})
}
}
}
impl InstanceFn {
#[inline]
pub unsafe fn get_physical_device_present_rectangles(
&self,
physical_device: PhysicalDevice,
surface: SurfaceKHR,
mut rects: impl EnumerateInto<Rect2D>,
) -> crate::Result<()> {
unsafe {
let call = |rect_count, rects| {
let result = (self.get_physical_device_present_rectangles.unwrap())(
physical_device,
surface,
rect_count,
rects as _,
);
match result {
VkResult::SUCCESS => Ok(()),
VkResult::INCOMPLETE => Ok(()),
err => Err(err),
}
};
let mut len = 0;
call(&mut len, std::ptr::null_mut())?;
let capacity = len.try_into().expect("failed to convert `N` to usize");
let rects_buf = rects.reserve(capacity);
len = rects_buf.len().try_into().unwrap();
let result = call(&mut len, rects_buf.as_mut_ptr() as *mut _)?;
rects.set_len(len.try_into().unwrap());
Ok(result)
}
}
}
pub struct DeviceFn {
get_device_group_peer_memory_features: PFN_vkGetDeviceGroupPeerMemoryFeatures,
cmd_set_device_mask: PFN_vkCmdSetDeviceMask,
cmd_dispatch_base: PFN_vkCmdDispatchBase,
get_device_group_present_capabilities: Option<PFN_vkGetDeviceGroupPresentCapabilitiesKHR>,
get_device_group_surface_present_modes: Option<PFN_vkGetDeviceGroupSurfacePresentModesKHR>,
acquire_next_image2: Option<PFN_vkAcquireNextImage2KHR>,
}
impl LoadDeviceFn for DeviceFn {
unsafe fn load_with(
load: impl Fn(&CStr) -> Option<PFN_vkVoidFunction>,
) -> core::result::Result<Self, MissingEntryPointError> {
unsafe {
Ok(Self {
get_device_group_peer_memory_features: transmute(
load(c"vkGetDeviceGroupPeerMemoryFeaturesKHR").ok_or(MissingEntryPointError)?,
),
cmd_set_device_mask: transmute(
load(c"vkCmdSetDeviceMaskKHR").ok_or(MissingEntryPointError)?,
),
cmd_dispatch_base: transmute(
load(c"vkCmdDispatchBaseKHR").ok_or(MissingEntryPointError)?,
),
get_device_group_present_capabilities: transmute(load(
c"vkGetDeviceGroupPresentCapabilitiesKHR",
)),
get_device_group_surface_present_modes: transmute(load(
c"vkGetDeviceGroupSurfacePresentModesKHR",
)),
acquire_next_image2: transmute(load(c"vkAcquireNextImage2KHR")),
})
}
}
}
impl DeviceFn {
#[inline]
pub unsafe fn get_device_group_peer_memory_features(
&self,
device: Device,
heap_index: u32,
local_device_index: u32,
remote_device_index: u32,
) -> PeerMemoryFeatureFlags {
unsafe {
let mut peer_memory_features = core::mem::MaybeUninit::uninit();
(self.get_device_group_peer_memory_features)(
device,
heap_index,
local_device_index,
remote_device_index,
peer_memory_features.as_mut_ptr(),
);
peer_memory_features.assume_init()
}
}
#[inline]
pub unsafe fn cmd_set_device_mask(&self, command_buffer: CommandBuffer, device_mask: u32) {
unsafe { (self.cmd_set_device_mask)(command_buffer, device_mask) }
}
#[inline]
pub unsafe fn cmd_dispatch_base(
&self,
command_buffer: CommandBuffer,
base_group_x: u32,
base_group_y: u32,
base_group_z: u32,
group_count_x: u32,
group_count_y: u32,
group_count_z: u32,
) {
unsafe {
(self.cmd_dispatch_base)(
command_buffer,
base_group_x,
base_group_y,
base_group_z,
group_count_x,
group_count_y,
group_count_z,
)
}
}
#[inline]
pub unsafe fn get_device_group_present_capabilities(
&self,
device: Device,
device_group_present_capabilities: &mut DeviceGroupPresentCapabilitiesKHR<'_>,
) -> crate::Result<()> {
unsafe {
let result = (self.get_device_group_present_capabilities.unwrap())(
device,
device_group_present_capabilities,
);
match result {
VkResult::SUCCESS => Ok(()),
err => Err(err),
}
}
}
#[inline]
pub unsafe fn get_device_group_surface_present_modes(
&self,
device: Device,
surface: SurfaceKHR,
) -> crate::Result<DeviceGroupPresentModeFlagsKHR> {
unsafe {
let mut modes = core::mem::MaybeUninit::uninit();
let result = (self.get_device_group_surface_present_modes.unwrap())(
device,
surface,
modes.as_mut_ptr(),
);
match result {
VkResult::SUCCESS => Ok(modes.assume_init()),
err => Err(err),
}
}
}
#[inline]
pub unsafe fn acquire_next_image2(
&self,
device: Device,
acquire_info: &AcquireNextImageInfoKHR<'_>,
) -> crate::Result<(u32, bool)> {
unsafe {
let mut image_index = core::mem::MaybeUninit::uninit();
let result =
(self.acquire_next_image2.unwrap())(device, acquire_info, image_index.as_mut_ptr());
match result {
VkResult::SUCCESS => Ok((image_index.assume_init(), false)),
VkResult::SUBOPTIMAL_KHR => Ok((image_index.assume_init(), true)),
err => Err(err),
}
}
}
}