video_core: prefer discrete gpu if available

This commit is contained in:
psucien 2024-04-29 21:36:41 +02:00
parent d496fab492
commit 1ac807dc3a
4 changed files with 33 additions and 11 deletions

View File

@ -12,7 +12,7 @@ namespace Config {
bool isNeo = false; bool isNeo = false;
u32 screenWidth = 1280; u32 screenWidth = 1280;
u32 screenHeight = 720; u32 screenHeight = 720;
u32 gpuId = 0; // Vulkan physical device no s32 gpuId = -1; // Vulkan physical device index. Set to negative for auto select
std::string logFilter; std::string logFilter;
std::string logType = "sync"; std::string logType = "sync";
bool isDebugDump = false; bool isDebugDump = false;
@ -33,7 +33,7 @@ u32 getScreenHeight() {
return screenHeight; return screenHeight;
} }
u32 getGpuId() { s32 getGpuId() {
return gpuId; return gpuId;
} }

View File

@ -16,7 +16,7 @@ std::string getLogType();
u32 getScreenWidth(); u32 getScreenWidth();
u32 getScreenHeight(); u32 getScreenHeight();
u32 getGpuId(); s32 getGpuId();
bool debugDump(); bool debugDump();
bool isLleLibc(); bool isLleLibc();

View File

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <ranges>
#include <span> #include <span>
#include <boost/container/static_vector.hpp> #include <boost/container/static_vector.hpp>
#include <fmt/format.h> #include <fmt/format.h>
@ -39,16 +40,37 @@ Instance::Instance(bool enable_validation, bool dump_command_buffers)
dump_command_buffers)}, dump_command_buffers)},
physical_devices{instance->enumeratePhysicalDevices()} {} physical_devices{instance->enumeratePhysicalDevices()} {}
Instance::Instance(Frontend::WindowSDL& window, u32 physical_device_index) Instance::Instance(Frontend::WindowSDL& window, s32 physical_device_index)
: instance{CreateInstance(dl, window.getWindowInfo().type, true, false)}, : instance{CreateInstance(dl, window.getWindowInfo().type, true, false)},
debug_callback{CreateDebugCallback(*instance)}, physical_devices{ debug_callback{CreateDebugCallback(*instance)},
instance->enumeratePhysicalDevices()} { physical_devices{instance->enumeratePhysicalDevices()} {
const std::size_t num_physical_devices = static_cast<u16>(physical_devices.size()); const std::size_t num_physical_devices = static_cast<u16>(physical_devices.size());
ASSERT_MSG(physical_device_index < num_physical_devices, ASSERT_MSG(num_physical_devices > 0, "No physical devices found");
"Invalid physical device index {} provided when only {} devices exist",
physical_device_index, num_physical_devices); if (physical_device_index < 0) {
std::vector<vk::PhysicalDeviceProperties2> properties2{};
for (auto const& physical : physical_devices) {
properties2.emplace_back(physical.getProperties2());
}
auto dev_prop2_pairs = std::views::zip(physical_devices, properties2);
std::sort(dev_prop2_pairs.begin(), dev_prop2_pairs.end(),
[](const auto& left, const auto& right) {
if (std::get<1>(left).properties.deviceType ==
std::get<1>(right).properties.deviceType) {
return true;
}
return std::get<1>(left).properties.deviceType ==
vk::PhysicalDeviceType::eDiscreteGpu;
});
physical_device = std::get<0>(dev_prop2_pairs[0]);
} else {
ASSERT_MSG(physical_device_index < num_physical_devices,
"Invalid physical device index {} provided when only {} devices exist",
physical_device_index, num_physical_devices);
physical_device = physical_devices[physical_device_index];
}
physical_device = physical_devices[physical_device_index];
available_extensions = GetSupportedExtensions(physical_device); available_extensions = GetSupportedExtensions(physical_device);
properties = physical_device.getProperties(); properties = physical_device.getProperties();
if (properties.apiVersion < TargetVulkanApiVersion) { if (properties.apiVersion < TargetVulkanApiVersion) {

View File

@ -18,7 +18,7 @@ namespace Vulkan {
class Instance { class Instance {
public: public:
explicit Instance(bool validation = false, bool dump_command_buffers = false); explicit Instance(bool validation = false, bool dump_command_buffers = false);
explicit Instance(Frontend::WindowSDL& window, u32 physical_device_index); explicit Instance(Frontend::WindowSDL& window, s32 physical_device_index);
~Instance(); ~Instance();
/// Returns a formatted string for the driver version /// Returns a formatted string for the driver version