Integrate switcheroo-control for discrete GPU support
Signed-off-by: Jan200101 <sentrycraft123@gmail.com>
This commit is contained in:
parent
6c062c48b4
commit
514ec99a03
3 changed files with 57 additions and 6 deletions
|
@ -299,6 +299,8 @@ include(QtVersionlessBackport)
|
|||
if(Launcher_QT_VERSION_MAJOR EQUAL 5)
|
||||
set(QT_VERSION_MAJOR 5)
|
||||
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Concurrent Network Test Xml NetworkAuth)
|
||||
find_package(Qt5 COMPONENTS DBus)
|
||||
list(APPEND Launcher_QT_DBUS Qt5::DBus)
|
||||
|
||||
if(NOT Launcher_FORCE_BUNDLED_LIBS)
|
||||
find_package(QuaZip-Qt5 1.3 QUIET)
|
||||
|
@ -313,6 +315,8 @@ if(Launcher_QT_VERSION_MAJOR EQUAL 5)
|
|||
elseif(Launcher_QT_VERSION_MAJOR EQUAL 6)
|
||||
set(QT_VERSION_MAJOR 6)
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core CoreTools Widgets Concurrent Network Test Xml Core5Compat NetworkAuth)
|
||||
find_package(Qt6 COMPONENTS DBus)
|
||||
list(APPEND Launcher_QT_DBUS Qt6::DBus)
|
||||
list(APPEND Launcher_QT_LIBS Qt6::Core5Compat)
|
||||
|
||||
if(NOT Launcher_FORCE_BUNDLED_LIBS)
|
||||
|
|
|
@ -1297,6 +1297,7 @@ target_link_libraries(Launcher_logic
|
|||
Qt${QT_VERSION_MAJOR}::Gui
|
||||
Qt${QT_VERSION_MAJOR}::Widgets
|
||||
Qt${QT_VERSION_MAJOR}::NetworkAuth
|
||||
${Launcher_QT_DBUS}
|
||||
${Launcher_QT_LIBS}
|
||||
)
|
||||
target_link_libraries(Launcher_logic
|
||||
|
@ -1305,6 +1306,10 @@ target_link_libraries(Launcher_logic
|
|||
LocalPeer
|
||||
Launcher_rainbow
|
||||
)
|
||||
if (TARGET ${Launcher_QT_DBUS})
|
||||
add_compile_definitions(WITH_QTDBUS)
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
set(CMAKE_MACOSX_RPATH 1)
|
||||
set(CMAKE_INSTALL_RPATH "@loader_path/../Frameworks/")
|
||||
|
|
|
@ -99,8 +99,48 @@
|
|||
#include "MangoHud.h"
|
||||
#endif
|
||||
|
||||
#ifdef WITH_QTDBUS
|
||||
#include <QtDBus/QtDBus>
|
||||
#endif
|
||||
|
||||
#define IBUS "@im=ibus"
|
||||
|
||||
static bool switcherooSetupGPU(QProcessEnvironment& env)
|
||||
{
|
||||
#ifdef WITH_QTDBUS
|
||||
if (!QDBusConnection::systemBus().isConnected())
|
||||
return false;
|
||||
|
||||
QDBusInterface switcheroo("net.hadess.SwitcherooControl", "/net/hadess/SwitcherooControl", "org.freedesktop.DBus.Properties",
|
||||
QDBusConnection::systemBus());
|
||||
|
||||
if (!switcheroo.isValid())
|
||||
return false;
|
||||
|
||||
QDBusReply<QDBusVariant> reply =
|
||||
switcheroo.call(QStringLiteral("Get"), QStringLiteral("net.hadess.SwitcherooControl"), QStringLiteral("GPUs"));
|
||||
if (!reply.isValid())
|
||||
return false;
|
||||
|
||||
QDBusArgument arg = qvariant_cast<QDBusArgument>(reply.value().variant());
|
||||
QList<QVariantMap> gpus;
|
||||
arg >> gpus;
|
||||
|
||||
for (const auto& gpu : gpus) {
|
||||
QString name = qvariant_cast<QString>(gpu[QStringLiteral("Name")]);
|
||||
bool defaultGpu = qvariant_cast<bool>(gpu[QStringLiteral("Default")]);
|
||||
if (!defaultGpu) {
|
||||
QStringList envList = qvariant_cast<QStringList>(gpu[QStringLiteral("Environment")]);
|
||||
for (int i = 0; i + 1 < envList.size(); i += 2) {
|
||||
env.insert(envList[i], envList[i + 1]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
// all of this because keeping things compatible with deprecated old settings
|
||||
// if either of the settings {a, b} is true, this also resolves to true
|
||||
class OrSetting : public Setting {
|
||||
|
@ -617,12 +657,14 @@ QProcessEnvironment MinecraftInstance::createLaunchEnvironment()
|
|||
}
|
||||
|
||||
if (settings()->get("UseDiscreteGpu").toBool()) {
|
||||
// Open Source Drivers
|
||||
env.insert("DRI_PRIME", "1");
|
||||
// Proprietary Nvidia Drivers
|
||||
env.insert("__NV_PRIME_RENDER_OFFLOAD", "1");
|
||||
env.insert("__VK_LAYER_NV_optimus", "NVIDIA_only");
|
||||
env.insert("__GLX_VENDOR_LIBRARY_NAME", "nvidia");
|
||||
if (!switcherooSetupGPU(env)) {
|
||||
// Open Source Drivers
|
||||
env.insert("DRI_PRIME", "1");
|
||||
// Proprietary Nvidia Drivers
|
||||
env.insert("__NV_PRIME_RENDER_OFFLOAD", "1");
|
||||
env.insert("__VK_LAYER_NV_optimus", "NVIDIA_only");
|
||||
env.insert("__GLX_VENDOR_LIBRARY_NAME", "nvidia");
|
||||
}
|
||||
}
|
||||
|
||||
if (settings()->get("UseZink").toBool()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue