From 3793ddd0bf04f9dcdf9141662ee7254a90270dc4 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Thu, 1 Feb 2024 21:21:33 -0800 Subject: [PATCH] vulkan: fix the validation warning on resize --- blade-graphics/src/vulkan/init.rs | 34 ++++++++++++++++++++++++++++++- blade-graphics/src/vulkan/mod.rs | 3 ++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/blade-graphics/src/vulkan/init.rs b/blade-graphics/src/vulkan/init.rs index 7ef78687..c90541a2 100644 --- a/blade-graphics/src/vulkan/init.rs +++ b/blade-graphics/src/vulkan/init.rs @@ -287,6 +287,11 @@ impl super::Context { &entry, &core_instance, ), + surface: if surface_handles.is_some() { + Some(khr::Surface::new(&entry, &core_instance)) + } else { + None + }, core: core_instance, }; @@ -536,7 +541,7 @@ impl super::Context { last_progress, }), surface, - _physical_device: physical_device, + physical_device, naga_flags, instance, _entry: entry, @@ -587,7 +592,34 @@ impl super::Context { impl super::Context { pub fn resize(&self, config: crate::SurfaceConfig) -> crate::TextureFormat { + let surface_khr = self.instance.surface.as_ref().unwrap(); let mut surface = self.surface.as_ref().unwrap().lock().unwrap(); + + let capabilities = unsafe { + surface_khr + .get_physical_device_surface_capabilities(self.physical_device, surface.raw) + .unwrap() + }; + if config.size.width < capabilities.min_image_extent.width + || config.size.width > capabilities.max_image_extent.width + || config.size.height < capabilities.min_image_extent.height + || config.size.height > capabilities.max_image_extent.height + { + log::warn!( + "Requested size {}x{} is outside of surface capabilities", + config.size.width, + config.size.height + ); + } + if config.frame_count < capabilities.min_image_count + || config.frame_count > capabilities.max_image_count + { + log::warn!( + "Requested frame count {} is outside of surface capabilities", + config.frame_count + ); + } + let queue_families = [self.queue_family_index]; let format = crate::TextureFormat::Bgra8UnormSrgb; let vk_format = super::map_texture_format(format); diff --git a/blade-graphics/src/vulkan/mod.rs b/blade-graphics/src/vulkan/mod.rs index 0772970c..ae3bc92a 100644 --- a/blade-graphics/src/vulkan/mod.rs +++ b/blade-graphics/src/vulkan/mod.rs @@ -13,6 +13,7 @@ struct Instance { core: ash::Instance, debug_utils: ext::DebugUtils, get_physical_device_properties2: khr::GetPhysicalDeviceProperties2, + surface: Option, } #[derive(Clone)] @@ -101,7 +102,7 @@ pub struct Context { queue_family_index: u32, queue: Mutex, surface: Option>, - _physical_device: vk::PhysicalDevice, + physical_device: vk::PhysicalDevice, naga_flags: naga::back::spv::WriterFlags, instance: Instance, _entry: ash::Entry,