From 807f421752a63756cb1eda734cd588c0e8d6811e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mat=C3=ADas=20Locatti?= <matias.locatti@gmail.com>
Date: Wed, 24 Jan 2024 23:32:20 -0300
Subject: [PATCH] Demote Mesa dozen to the bottom of the device list

---
 src/video_core/vulkan_common/vulkan_wrapper.cpp | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/video_core/vulkan_common/vulkan_wrapper.cpp b/src/video_core/vulkan_common/vulkan_wrapper.cpp
index 074aed9645..3966bd61ee 100644
--- a/src/video_core/vulkan_common/vulkan_wrapper.cpp
+++ b/src/video_core/vulkan_common/vulkan_wrapper.cpp
@@ -39,6 +39,10 @@ void SortPhysicalDevicesPerVendor(std::vector<VkPhysicalDevice>& devices,
     }
 }
 
+bool IsMicrosoftDozen(const char* device_name) {
+    return std::strstr(device_name, "Microsoft") != nullptr;
+}
+
 void SortPhysicalDevices(std::vector<VkPhysicalDevice>& devices, const InstanceDispatch& dld) {
     // Sort by name, this will set a base and make GPUs with higher numbers appear first
     // (e.g. GTX 1650 will intentionally be listed before a GTX 1080).
@@ -52,6 +56,12 @@ void SortPhysicalDevices(std::vector<VkPhysicalDevice>& devices, const InstanceD
     });
     // Prefer Nvidia over AMD, AMD over Intel, Intel over the rest.
     SortPhysicalDevicesPerVendor(devices, dld, {0x10DE, 0x1002, 0x8086});
+    // Demote Microsoft's Dozen devices to the bottom.
+    SortPhysicalDevices(
+        devices, dld,
+        [](const VkPhysicalDeviceProperties& lhs, const VkPhysicalDeviceProperties& rhs) {
+            return IsMicrosoftDozen(rhs.deviceName) && !IsMicrosoftDozen(lhs.deviceName);
+        });
 }
 
 template <typename T>