summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_vulkan
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2020-04-25 09:27:40 +0200
committerGitHub <noreply@github.com>2020-04-25 09:27:40 +0200
commitc5bf6938827a5fbdbd633a9dec62a695c27186d9 (patch)
treedcb8a253cc497122a1f2094a780641b76f655300 /src/video_core/renderer_vulkan
parentMerge pull request #3734 from ReinUsesLisp/half-float-mods (diff)
parentvulkan/wrapper: Sort physical devices (diff)
downloadyuzu-c5bf6938827a5fbdbd633a9dec62a695c27186d9.tar
yuzu-c5bf6938827a5fbdbd633a9dec62a695c27186d9.tar.gz
yuzu-c5bf6938827a5fbdbd633a9dec62a695c27186d9.tar.bz2
yuzu-c5bf6938827a5fbdbd633a9dec62a695c27186d9.tar.lz
yuzu-c5bf6938827a5fbdbd633a9dec62a695c27186d9.tar.xz
yuzu-c5bf6938827a5fbdbd633a9dec62a695c27186d9.tar.zst
yuzu-c5bf6938827a5fbdbd633a9dec62a695c27186d9.zip
Diffstat (limited to 'src/video_core/renderer_vulkan')
-rw-r--r--src/video_core/renderer_vulkan/wrapper.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/video_core/renderer_vulkan/wrapper.cpp b/src/video_core/renderer_vulkan/wrapper.cpp
index 539f3c974..7f5bc1404 100644
--- a/src/video_core/renderer_vulkan/wrapper.cpp
+++ b/src/video_core/renderer_vulkan/wrapper.cpp
@@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
+#include <algorithm>
#include <exception>
#include <memory>
#include <optional>
@@ -16,6 +17,23 @@ namespace Vulkan::vk {
namespace {
+void SortPhysicalDevices(std::vector<VkPhysicalDevice>& devices, const InstanceDispatch& dld) {
+ std::stable_sort(devices.begin(), devices.end(), [&](auto lhs, auto rhs) {
+ // This will call Vulkan more than needed, but these calls are cheap.
+ const auto lhs_properties = vk::PhysicalDevice(lhs, dld).GetProperties();
+ const auto rhs_properties = vk::PhysicalDevice(rhs, dld).GetProperties();
+
+ // Prefer discrete GPUs, Nvidia over AMD, AMD over Intel, Intel over the rest.
+ const bool preferred =
+ (lhs_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU &&
+ rhs_properties.deviceType != VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) ||
+ (lhs_properties.vendorID == 0x10DE && rhs_properties.vendorID != 0x10DE) ||
+ (lhs_properties.vendorID == 0x1002 && rhs_properties.vendorID != 0x1002) ||
+ (lhs_properties.vendorID == 0x8086 && rhs_properties.vendorID != 0x8086);
+ return !preferred;
+ });
+}
+
template <typename T>
bool Proc(T& result, const InstanceDispatch& dld, const char* proc_name,
VkInstance instance = nullptr) noexcept {
@@ -389,7 +407,8 @@ std::optional<std::vector<VkPhysicalDevice>> Instance::EnumeratePhysicalDevices(
if (dld->vkEnumeratePhysicalDevices(handle, &num, physical_devices.data()) != VK_SUCCESS) {
return std::nullopt;
}
- return physical_devices;
+ SortPhysicalDevices(physical_devices, *dld);
+ return std::make_optional(std::move(physical_devices));
}
DebugCallback Instance::TryCreateDebugCallback(