Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- improve the queue family selection process to pick first entry in t…
…he list over later ones
  • Loading branch information
dpjudas committed Mar 24, 2019
1 parent 0be5cc7 commit 954b729
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions src/rendering/vulkan/system/vk_device.cpp
Expand Up @@ -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<std::string> requiredExtensionSearch(EnabledDeviceExtensions.begin(), EnabledDeviceExtensions.end());
Expand Down

0 comments on commit 954b729

Please sign in to comment.