Skip to content

Commit ab90b00

Browse files
authored
Vulkan: do not replace hardware GPU with software renderer (#781)
1 parent 5a36dbe commit ab90b00

File tree

1 file changed

+20
-5
lines changed
  • Graphics/GraphicsEngineVulkan/src/VulkanUtilities

1 file changed

+20
-5
lines changed

Graphics/GraphicsEngineVulkan/src/VulkanUtilities/Instance.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,20 +706,35 @@ VkPhysicalDevice Instance::SelectPhysicalDevice(uint32_t AdapterId) const noexce
706706
SelectedPhysicalDevice = m_PhysicalDevices[AdapterId];
707707
}
708708

709-
// Select a device that exposes a queue family that supports both compute and graphics operations.
710-
// Prefer discrete GPU.
709+
// Select a device that exposes a queue family that supports both compute and graphics operations
710+
// DISCRETE > INTEGRATED > everything else.
711711
if (SelectedPhysicalDevice == VK_NULL_HANDLE)
712712
{
713+
// Returns a priority value for the device type (higher is better).
714+
const auto GetDeviceTypePriority = [](VkPhysicalDeviceType Type) -> int {
715+
switch (Type)
716+
{
717+
case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: return 3;
718+
case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: return 2;
719+
case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU: return 1;
720+
default: return 0;
721+
}
722+
};
723+
724+
int BestPriority = -1;
713725
for (VkPhysicalDevice Device : m_PhysicalDevices)
714726
{
727+
if (!IsGraphicsAndComputeQueueSupported(Device))
728+
continue;
729+
715730
VkPhysicalDeviceProperties DeviceProps;
716731
vkGetPhysicalDeviceProperties(Device, &DeviceProps);
717732

718-
if (IsGraphicsAndComputeQueueSupported(Device))
733+
const int Priority = GetDeviceTypePriority(DeviceProps.deviceType);
734+
if (Priority > BestPriority)
719735
{
720736
SelectedPhysicalDevice = Device;
721-
if (DeviceProps.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
722-
break;
737+
BestPriority = Priority;
723738
}
724739
}
725740
}

0 commit comments

Comments
 (0)