From 954b72915c5d2cf7b0c2435e0e30c3433ceb3d71 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 24 Mar 2019 18:33:59 +0100 Subject: [PATCH] - improve the queue family selection process to pick first entry in the list over later ones --- src/rendering/vulkan/system/vk_device.cpp | 40 ++++++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/rendering/vulkan/system/vk_device.cpp b/src/rendering/vulkan/system/vk_device.cpp index cd47292cf..86fbe5645 100644 --- a/src/rendering/vulkan/system/vk_device.cpp +++ b/src/rendering/vulkan/system/vk_device.cpp @@ -120,23 +120,45 @@ void VulkanDevice::SelectPhysicalDevice() VulkanCompatibleDevice dev; dev.device = &AvailableDevices[idx]; - int i = 0; - for (const auto& queueFamily : info.QueueFamilies) + // Figure out what can present + for (int i = 0; i < (int)info.QueueFamilies.size(); i++) { - // Only accept a decent GPU for now.. + VkBool32 presentSupport = false; + VkResult result = vkGetPhysicalDeviceSurfaceSupportKHR(info.Device, i, surface, &presentSupport); + if (result == VK_SUCCESS && info.QueueFamilies[i].queueCount > 0 && presentSupport) + { + dev.presentFamily = i; + break; + } + } + + // Look for family that can do both graphics and transfer + for (int i = 0; i < (int)info.QueueFamilies.size(); i++) + { + const auto &queueFamily = info.QueueFamilies[i]; VkQueueFlags gpuFlags = (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_TRANSFER_BIT); if (queueFamily.queueCount > 0 && (queueFamily.queueFlags & gpuFlags) == gpuFlags) { dev.graphicsFamily = i; dev.transferFamily = i; + break; } + } - VkBool32 presentSupport = false; - VkResult result = vkGetPhysicalDeviceSurfaceSupportKHR(info.Device, i, surface, &presentSupport); - if (result == VK_SUCCESS && queueFamily.queueCount > 0 && presentSupport) - dev.presentFamily = i; - - i++; + // OK we didn't find any. Look for any match now. + if (dev.graphicsFamily == -1) + { + for (int i = 0; i < (int)info.QueueFamilies.size(); i++) + { + const auto &queueFamily = info.QueueFamilies[i]; + if (queueFamily.queueCount > 0) + { + if (dev.graphicsFamily == -1 && (queueFamily.queueFlags & VK_QUEUE_GRAPHICS_BIT)) + dev.graphicsFamily = i; + if (dev.transferFamily == -1 && (queueFamily.queueFlags & VK_QUEUE_TRANSFER_BIT)) + dev.transferFamily = i; + } + } } std::set requiredExtensionSearch(EnabledDeviceExtensions.begin(), EnabledDeviceExtensions.end());