From 7fac872bb08148b110016079e46c84e74d02656e Mon Sep 17 00:00:00 2001 From: Anna Sofie Nordstrand Date: Tue, 28 Dec 2021 01:18:57 -0600 Subject: [PATCH] get_surface_capabilities2: allow p_next to be set externally --- .../khr/get_surface_capabilities2.rs | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/ash/src/extensions/khr/get_surface_capabilities2.rs b/ash/src/extensions/khr/get_surface_capabilities2.rs index 7ca3d1649..8c93219cb 100644 --- a/ash/src/extensions/khr/get_surface_capabilities2.rs +++ b/ash/src/extensions/khr/get_surface_capabilities2.rs @@ -33,23 +33,48 @@ impl GetSurfaceCapabilities2 { .result_with_success(surface_capabilities) } + /// Retrieve the number of elements to pass to [`Self::get_physical_device_surface_formats2()`] + pub unsafe fn get_physical_device_surface_formats2_len( + &self, + physical_device: vk::PhysicalDevice, + surface_info: &vk::PhysicalDeviceSurfaceInfo2KHR, + ) -> VkResult { + let mut count = 0; + let err_code = self.fp.get_physical_device_surface_formats2_khr( + physical_device, + surface_info, + &mut count, + std::ptr::null_mut(), + ); + err_code.result_with_success(count as usize) + } + #[doc = "https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceSurfaceFormats2KHR.html"] + /// + /// Call [`Self::get_physical_device_surface_formats2_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. pub unsafe fn get_physical_device_surface_formats2( &self, physical_device: vk::PhysicalDevice, surface_info: &vk::PhysicalDeviceSurfaceInfo2KHR, - ) -> VkResult> { - read_into_uninitialized_vector(|count, data| { - self.fp.get_physical_device_surface_formats2_khr( - physical_device, - surface_info, - count, - data - ) - }) + out: &mut [vk::SurfaceFormat2KHR], + ) -> VkResult<()> { + let mut count = out.len() as u32; + let err_code = self.fp.get_physical_device_surface_formats2_khr( + physical_device, + surface_info, + &mut count, + out.as_mut_ptr(), + ); + assert_eq!(count, out.len() as u32); + err_code.result() } - pub fn name() -> &'static CStr { vk::KhrGetSurfaceCapabilities2Fn::name() } + pub fn name() -> &'static CStr { + vk::KhrGetSurfaceCapabilities2Fn::name() + } - pub fn fp(&self) -> &vk::KhrGetSurfaceCapabilities2Fn { &self.fp } + pub fn fp(&self) -> &vk::KhrGetSurfaceCapabilities2Fn { + &self.fp + } }