From d10212ac3bf492eae34ee79861c02eb9996f15d2 Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Sat, 24 May 2025 16:44:51 +0200 Subject: [PATCH] engine_vulkan: Fixes of queue allocation - Avoid to allocate dedicated queue for presentation and use graphics queue for it - Use queueCount of Queue Family Properties for queue support checking --- crates/engine_vulkan/src/queues.rs | 31 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/crates/engine_vulkan/src/queues.rs b/crates/engine_vulkan/src/queues.rs index fc49dcc..6b94f76 100644 --- a/crates/engine_vulkan/src/queues.rs +++ b/crates/engine_vulkan/src/queues.rs @@ -45,7 +45,6 @@ impl From> for VulkanQueueFamilyStatus { #[derive(Debug)] pub struct VulkanQueueFamilyIndices { - pub present_queue_family_index: VulkanQueueFamilyStatus, pub graphics_queue_family_index: VulkanQueueFamilyStatus, pub compute_queue_family_index: VulkanQueueFamilyStatus, pub transfer_queue_family_index: VulkanQueueFamilyStatus, @@ -54,7 +53,6 @@ pub struct VulkanQueueFamilyIndices { impl From for Vec { fn from(indices: VulkanQueueFamilyIndices) -> Self { vec![ - indices.present_queue_family_index, indices.graphics_queue_family_index, indices.compute_queue_family_index, indices.transfer_queue_family_index, @@ -93,7 +91,6 @@ impl From for Vec { impl<'a> From<&'a VulkanQueuesQuery<'a>> for VulkanQueueFamilyIndices { fn from(query: &'a VulkanQueuesQuery<'a>) -> Self { VulkanQueueFamilyIndices { - present_queue_family_index: query.with_surface.into(), graphics_queue_family_index: query.with_graphics_queue.into(), compute_queue_family_index: query.with_compute_queue.into(), transfer_queue_family_index: query.with_transfer_queue.into(), @@ -116,36 +113,40 @@ pub fn find_queues_family_indices( for (i, queue_family_properties) in physical_device.queue_family_properties().iter().enumerate() { - if indices.present_queue_family_index.can_be_set() - && check_presentation_support( - physical_device, - i as u32, - &query.with_surface.as_ref().unwrap(), - ) - { - indices.present_queue_family_index = VulkanQueueFamilyStatus::Supported(i as u32); - } + let mut available_queue_count = queue_family_properties.queue_count; if indices.graphics_queue_family_index.can_be_set() && check_queue_support(queue_family_properties, QueueFlags::GRAPHICS) + && available_queue_count > 0 { - indices.graphics_queue_family_index = VulkanQueueFamilyStatus::Supported(i as u32); + if query.with_surface.is_none() + || check_presentation_support( + physical_device, + i as u32, + &query.with_surface.as_ref().unwrap(), + ) + { + indices.graphics_queue_family_index = VulkanQueueFamilyStatus::Supported(i as u32); + available_queue_count -= 1; + } } if indices.compute_queue_family_index.can_be_set() && check_queue_support(queue_family_properties, QueueFlags::COMPUTE) + && available_queue_count > 0 { indices.compute_queue_family_index = VulkanQueueFamilyStatus::Supported(i as u32); + available_queue_count -= 1; } if indices.transfer_queue_family_index.can_be_set() && check_queue_support(queue_family_properties, QueueFlags::TRANSFER) + && available_queue_count > 0 { indices.transfer_queue_family_index = VulkanQueueFamilyStatus::Supported(i as u32); } - if !indices.present_queue_family_index.can_be_set() - && !indices.graphics_queue_family_index.can_be_set() + if !indices.graphics_queue_family_index.can_be_set() && !indices.compute_queue_family_index.can_be_set() && !indices.transfer_queue_family_index.can_be_set() {