Skip to content

Commit

Permalink
vulkan: fix the validation warning on resize
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Feb 2, 2024
1 parent 421f303 commit 3793ddd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
34 changes: 33 additions & 1 deletion blade-graphics/src/vulkan/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -536,7 +541,7 @@ impl super::Context {
last_progress,
}),
surface,
_physical_device: physical_device,
physical_device,
naga_flags,
instance,
_entry: entry,
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion blade-graphics/src/vulkan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct Instance {
core: ash::Instance,
debug_utils: ext::DebugUtils,
get_physical_device_properties2: khr::GetPhysicalDeviceProperties2,
surface: Option<khr::Surface>,
}

#[derive(Clone)]
Expand Down Expand Up @@ -101,7 +102,7 @@ pub struct Context {
queue_family_index: u32,
queue: Mutex<Queue>,
surface: Option<Mutex<Surface>>,
_physical_device: vk::PhysicalDevice,
physical_device: vk::PhysicalDevice,
naga_flags: naga::back::spv::WriterFlags,
instance: Instance,
_entry: ash::Entry,
Expand Down

0 comments on commit 3793ddd

Please sign in to comment.