Skip to content

Commit

Permalink
extensions/khr: Implement additional Swapchain functions since Vulk…
Browse files Browse the repository at this point in the history
…an 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.
  • Loading branch information
MarijnS95 committed Jun 5, 2022
1 parent 0f298ee commit 937d277
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 new functions to `VK_KHR_swapchain`, available since Vulkan 1.1 (#629)
- Added `VK_KHR_device_group_creation` instance extension (#630)

### Removed
Expand Down
64 changes: 64 additions & 0 deletions ash/src/extensions/khr/swapchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl Swapchain {
}

/// 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>
pub unsafe fn acquire_next_image(
&self,
Expand All @@ -81,6 +82,7 @@ impl Swapchain {
}

/// 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>
pub unsafe fn queue_present(
&self,
Expand All @@ -95,6 +97,68 @@ impl Swapchain {
}
}

/// Only available since Vulkan 1.1.
///
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetDeviceGroupPresentCapabilitiesKHR.html>
pub unsafe fn get_device_group_present_capabilities(
&self,
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.
///
/// <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| {
(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 {
vk::KhrSwapchainFn::name()
}
Expand Down

0 comments on commit 937d277

Please sign in to comment.