File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed
Graphics/GraphicsEngineVulkan/src/VulkanUtilities Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments