extensions/khr: Implement additional Swapchain functions since Vulkan 1.1 (#629)

* extensions/khr: Reorder `Swapchain` functions to match `KhrSwapchainFn`

* extensions/khr: Implement additional `Swapchain` functions since Vulkan 1.1

These are also made available by `VK_KHR_device_group` when
`VK_KHR_swapchain` (and for certain functions only the underlying
`VK_KHR_surface` extension) is enabled.
This commit is contained in:
Marijn Suijten 2022-06-05 21:47:29 +02:00 committed by GitHub
parent a950e14f89
commit 1459da47bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 86 additions and 21 deletions

View file

@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `VK_EXT_sample_locations` device extension (#616) - Added `VK_EXT_sample_locations` device extension (#616)
- Update Vulkan-Headers to 1.3.211 (#605, #608) - Update Vulkan-Headers to 1.3.211 (#605, #608)
- Added `VK_EXT_image_drm_format_modifier` device extension (#603) - Added `VK_EXT_image_drm_format_modifier` device extension (#603)
- Added new functions to `VK_KHR_swapchain`, available since Vulkan 1.1 (#629)
- Added `VK_KHR_device_group_creation` instance extension (#630) - Added `VK_KHR_device_group_creation` instance extension (#630)
### Removed ### Removed

View file

@ -20,6 +20,22 @@ impl Swapchain {
Self { handle, fp } Self { handle, fp }
} }
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCreateSwapchainKHR.html>
pub unsafe fn create_swapchain(
&self,
create_info: &vk::SwapchainCreateInfoKHR,
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::SwapchainKHR> {
let mut swapchain = mem::zeroed();
(self.fp.create_swapchain_khr)(
self.handle,
create_info,
allocation_callbacks.as_raw_ptr(),
&mut swapchain,
)
.result_with_success(swapchain)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDestroySwapchainKHR.html> /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDestroySwapchainKHR.html>
pub unsafe fn destroy_swapchain( pub unsafe fn destroy_swapchain(
&self, &self,
@ -29,7 +45,18 @@ impl Swapchain {
(self.fp.destroy_swapchain_khr)(self.handle, swapchain, allocation_callbacks.as_raw_ptr()); (self.fp.destroy_swapchain_khr)(self.handle, swapchain, allocation_callbacks.as_raw_ptr());
} }
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetSwapchainImagesKHR.html>
pub unsafe fn get_swapchain_images(
&self,
swapchain: vk::SwapchainKHR,
) -> VkResult<Vec<vk::Image>> {
read_into_uninitialized_vector(|count, data| {
(self.fp.get_swapchain_images_khr)(self.handle, swapchain, count, data)
})
}
/// On success, returns the next image's index and whether the swapchain is suboptimal for the surface. /// On success, returns the next image's index and whether the swapchain is suboptimal for the surface.
///
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkAcquireNextImageKHR.html> /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkAcquireNextImageKHR.html>
pub unsafe fn acquire_next_image( pub unsafe fn acquire_next_image(
&self, &self,
@ -54,23 +81,8 @@ impl Swapchain {
} }
} }
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCreateSwapchainKHR.html>
pub unsafe fn create_swapchain(
&self,
create_info: &vk::SwapchainCreateInfoKHR,
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::SwapchainKHR> {
let mut swapchain = mem::zeroed();
(self.fp.create_swapchain_khr)(
self.handle,
create_info,
allocation_callbacks.as_raw_ptr(),
&mut swapchain,
)
.result_with_success(swapchain)
}
/// On success, returns whether the swapchain is suboptimal for the surface. /// On success, returns whether the swapchain is suboptimal for the surface.
///
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkQueuePresentKHR.html> /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkQueuePresentKHR.html>
pub unsafe fn queue_present( pub unsafe fn queue_present(
&self, &self,
@ -85,16 +97,68 @@ impl Swapchain {
} }
} }
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetSwapchainImagesKHR.html> /// Only available since Vulkan 1.1.
pub unsafe fn get_swapchain_images( ///
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetDeviceGroupPresentCapabilitiesKHR.html>
pub unsafe fn get_device_group_present_capabilities(
&self, &self,
swapchain: vk::SwapchainKHR, device_group_present_capabilities: &mut vk::DeviceGroupPresentCapabilitiesKHR,
) -> VkResult<Vec<vk::Image>> { ) -> VkResult<()> {
(self.fp.get_device_group_present_capabilities_khr)(
self.handle,
device_group_present_capabilities,
)
.result()
}
/// Only available since Vulkan 1.1.
///
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetDeviceGroupSurfacePresentModesKHR.html>
pub unsafe fn get_device_group_surface_present_modes(
&self,
surface: vk::SurfaceKHR,
) -> VkResult<vk::DeviceGroupPresentModeFlagsKHR> {
let mut modes = mem::zeroed();
(self.fp.get_device_group_surface_present_modes_khr)(self.handle, surface, &mut modes)
.result_with_success(modes)
}
/// Only available since Vulkan 1.1.
///
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDevicePresentRectanglesKHR.html>
pub unsafe fn get_physical_device_present_rectangles(
&self,
physical_device: vk::PhysicalDevice,
surface: vk::SurfaceKHR,
) -> VkResult<Vec<vk::Rect2D>> {
read_into_uninitialized_vector(|count, data| { read_into_uninitialized_vector(|count, data| {
(self.fp.get_swapchain_images_khr)(self.handle, swapchain, count, data) (self.fp.get_physical_device_present_rectangles_khr)(
physical_device,
surface,
count,
data,
)
}) })
} }
/// On success, returns the next image's index and whether the swapchain is suboptimal for the surface.
///
/// Only available since Vulkan 1.1.
///
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkAcquireNextImage2KHR.html>
pub unsafe fn acquire_next_image2(
&self,
acquire_info: &vk::AcquireNextImageInfoKHR,
) -> VkResult<(u32, bool)> {
let mut index = 0;
let err_code = (self.fp.acquire_next_image2_khr)(self.handle, acquire_info, &mut index);
match err_code {
vk::Result::SUCCESS => Ok((index, false)),
vk::Result::SUBOPTIMAL_KHR => Ok((index, true)),
_ => Err(err_code),
}
}
pub const fn name() -> &'static CStr { pub const fn name() -> &'static CStr {
vk::KhrSwapchainFn::name() vk::KhrSwapchainFn::name()
} }