From 3472daa465658d564b85001e56e4a194e712318a Mon Sep 17 00:00:00 2001 From: maratik123 Date: Wed, 13 Mar 2024 19:05:17 +0300 Subject: [PATCH] PhysicalDevice::surface_present_modes should return Vec result (#2496) * PhysicalDevice::surface_present_modes should return Vec result as any other this struct functions for consistency and to eliminate composing result back to Vec in outer usages, such as: ```rust let present_mode = physical_device .surface_present_modes(surface, SurfaceInfo::default())? .collect(); Ok(SwapChainSupportDetails { _capabilities: capabilities, formats, present_mode, }) ``` * fmt * review fix --- vulkano/src/device/physical.rs | 22 +++++++++++----------- vulkano/src/swapchain/mod.rs | 3 +-- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/vulkano/src/device/physical.rs b/vulkano/src/device/physical.rs index 5847da4e..264679fc 100644 --- a/vulkano/src/device/physical.rs +++ b/vulkano/src/device/physical.rs @@ -1981,7 +1981,7 @@ impl PhysicalDevice { } = surface_info; if let Some(present_mode) = present_mode { - let mut present_modes = unsafe { + let present_modes = unsafe { self.surface_present_modes_unchecked( surface, SurfaceInfo { @@ -1999,7 +1999,7 @@ impl PhysicalDevice { })? }; - if !present_modes.any(|mode| mode == present_mode) { + if !present_modes.into_iter().any(|mode| mode == present_mode) { return Err(Box::new(ValidationError { problem: "`surface_info.present_mode` is not supported for `surface`".into(), vuids: &["VUID-VkSurfacePresentModeEXT-presentMode-07780"], @@ -2355,7 +2355,7 @@ impl PhysicalDevice { } = surface_info; if let Some(present_mode) = present_mode { - let mut present_modes = unsafe { + let present_modes = unsafe { self.surface_present_modes_unchecked( surface, SurfaceInfo { @@ -2373,7 +2373,7 @@ impl PhysicalDevice { })? }; - if !present_modes.any(|mode| mode == present_mode) { + if !present_modes.into_iter().any(|mode| mode == present_mode) { return Err(Box::new(ValidationError { problem: "`surface_info.present_mode` is not supported for `surface`".into(), vuids: &["VUID-VkSurfacePresentModeEXT-presentMode-07780"], @@ -2601,7 +2601,7 @@ impl PhysicalDevice { &self, surface: &Surface, surface_info: SurfaceInfo, - ) -> Result, Validated> { + ) -> Result, Validated> { self.validate_surface_present_modes(surface, &surface_info)?; unsafe { Ok(self.surface_present_modes_unchecked(surface, surface_info)?) } @@ -2718,10 +2718,10 @@ impl PhysicalDevice { &self, surface: &Surface, surface_info: SurfaceInfo, - ) -> Result, VulkanError> { - surface - .surface_present_modes - .get_or_try_insert((self.handle, surface_info), |(_, surface_info)| { + ) -> Result, VulkanError> { + surface.surface_present_modes.get_or_try_insert( + (self.handle, surface_info), + |(_, surface_info)| { let &SurfaceInfo { present_mode: _, full_screen_exclusive, @@ -2837,8 +2837,8 @@ impl PhysicalDevice { .filter_map(|mode_vk| mode_vk.try_into().ok()) .collect()) } - }) - .map(IntoIterator::into_iter) + }, + ) } /// Returns whether queues of the given queue family can draw on the given surface. diff --git a/vulkano/src/swapchain/mod.rs b/vulkano/src/swapchain/mod.rs index 53a45ab1..2b2c7d0c 100644 --- a/vulkano/src/swapchain/mod.rs +++ b/vulkano/src/swapchain/mod.rs @@ -621,7 +621,7 @@ impl Swapchain { }) })? }; - let surface_present_modes: SmallVec<[_; PresentMode::COUNT]> = unsafe { + let surface_present_modes = unsafe { device .physical_device() .surface_present_modes_unchecked( @@ -644,7 +644,6 @@ impl Swapchain { ..Default::default() }) })? - .collect() }; if surface_capabilities