@@ -706,16 +706,32 @@ 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 // Don't replace a hardware device with a software renderer (e.g. llvmpipe).
721737 // On systems without a discrete GPU the loop would otherwise overwrite an
@@ -725,8 +741,7 @@ VkPhysicalDevice Instance::SelectPhysicalDevice(uint32_t AdapterId) const noexce
725741 continue ;
726742
727743 SelectedPhysicalDevice = Device;
728- if (DeviceProps.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
729- break ;
744+ BestPriority = Priority;
730745 }
731746 }
732747 }
0 commit comments