diff --git a/Changelog.md b/Changelog.md index 1336816..d60b59f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -17,6 +17,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 new functions to `VK_KHR_swapchain`, available since Vulkan 1.1 (#629) - Added `VK_KHR_device_group_creation` instance extension (#630) ## [0.37.0] - 2022-03-23 diff --git a/ash/src/extensions/khr/swapchain.rs b/ash/src/extensions/khr/swapchain.rs index 407433b..d375538 100755 --- a/ash/src/extensions/khr/swapchain.rs +++ b/ash/src/extensions/khr/swapchain.rs @@ -20,6 +20,22 @@ impl Swapchain { Self { handle, fp } } + /// + pub unsafe fn create_swapchain( + &self, + create_info: &vk::SwapchainCreateInfoKHR, + allocation_callbacks: Option<&vk::AllocationCallbacks>, + ) -> VkResult { + 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) + } + /// pub unsafe fn destroy_swapchain( &self, @@ -29,7 +45,18 @@ impl Swapchain { (self.fp.destroy_swapchain_khr)(self.handle, swapchain, allocation_callbacks.as_raw_ptr()); } + /// + pub unsafe fn get_swapchain_images( + &self, + swapchain: vk::SwapchainKHR, + ) -> VkResult> { + 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. + /// /// pub unsafe fn acquire_next_image( &self, @@ -54,23 +81,8 @@ impl Swapchain { } } - /// - pub unsafe fn create_swapchain( - &self, - create_info: &vk::SwapchainCreateInfoKHR, - allocation_callbacks: Option<&vk::AllocationCallbacks>, - ) -> VkResult { - 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. + /// /// pub unsafe fn queue_present( &self, @@ -85,16 +97,68 @@ impl Swapchain { } } - /// - pub unsafe fn get_swapchain_images( + /// Only available since Vulkan 1.1. + /// + /// + pub unsafe fn get_device_group_present_capabilities( &self, - swapchain: vk::SwapchainKHR, - ) -> VkResult> { + device_group_present_capabilities: &mut vk::DeviceGroupPresentCapabilitiesKHR, + ) -> VkResult<()> { + (self.fp.get_device_group_present_capabilities_khr)( + self.handle, + device_group_present_capabilities, + ) + .result() + } + + /// Only available since Vulkan 1.1. + /// + /// + pub unsafe fn get_device_group_surface_present_modes( + &self, + surface: vk::SurfaceKHR, + ) -> VkResult { + 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. + /// + /// + pub unsafe fn get_physical_device_present_rectangles( + &self, + physical_device: vk::PhysicalDevice, + surface: vk::SurfaceKHR, + ) -> VkResult> { 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. + /// + /// + 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 { vk::KhrSwapchainFn::name() }