我有完全相同的问题,像
__GLX_VENDOR_LIBRARY_NAME=nvidia
、
__NV_PRIME_RENDER_OFFLOAD=1
、
__VK_LAYER_NV_optimus=NVIDIA_only
、
DRI_PRIME=1
这些变量都没有产生相同的结果。
我甚至尝试在gnome-shell源代码中搜索,但这些函数并不在gnome-shell仓库中。
最后,我偶然发现了switechroo-controls软件包,
我尝试了
switcherooctl launch <command>
,它复制了gnome shell的行为。
然后我突然想到在gnome-shell仓库中搜索switcheroo。
❯ grep -ri 'switcheroo'
Binary file .git/index matches
data/dbus-interfaces/net.hadess.SwitcherooControl.xml: net.hadess.SwitcherooControl:
data/dbus-interfaces/net.hadess.SwitcherooControl.xml: check the value of net.hadess.SwitcherooControl.HasDualGpu to see
data/dbus-interfaces/net.hadess.SwitcherooControl.xml: The object path will be "/net/hadess/SwitcherooControl".
data/dbus-interfaces/net.hadess.SwitcherooControl.xml: <interface name="net.hadess.SwitcherooControl">
js/ui/appDisplay.js: this._switcherooNotifyId = global.connect('notify::switcheroo-control',
js/ui/appDisplay.js: this._switcherooProxy = global.get_switcheroo_control();
js/ui/appDisplay.js: if (this._switcherooProxy) {
js/ui/appDisplay.js: let prop = this._switcherooProxy.get_cached_property('HasDualGpu');
src/meson.build:dbus_generated += gnome.gdbus_codegen('switcheroo-control',
src/meson.build: '../data/dbus-interfaces/net.hadess.SwitcherooControl.xml',
src/shell-app.c:#include "switcheroo-control.h"
src/shell-app.c: proxy = shell_global_get_switcheroo_control (global);
src/shell-app.c: g_warning ("Could not apply discrete GPU environment, switcheroo-control not available");
src/shell-app.c: variant = shell_net_hadess_switcheroo_control_get_gpus (SHELL_NET_HADESS_SWITCHEROO_CONTROL (proxy));
src/shell-app.c: g_debug ("Could not find discrete GPU in switcheroo-control, not applying environment");
src/shell-global.c:#include "switcheroo-control.h"
src/shell-global.c: GDBusProxy *switcheroo_control;
src/shell-global.c: GCancellable *switcheroo_cancellable;
src/shell-global.c: PROP_SWITCHEROO_CONTROL,
src/shell-global.c:got_switcheroo_control_gpus_property_cb (GObject *source_object,
src/shell-global.c: g_debug ("Could not get GPUs property from switcheroo-control: %s", error->message);
src/shell-global.c: g_dbus_proxy_set_cached_property (global->switcheroo_control, "GPUs", gpus);
src/shell-global.c: g_object_notify (G_OBJECT (global), "switcheroo-control");
src/shell-global.c:switcheroo_control_ready_cb (GObject *source_object,
src/shell-global.c: ShellNetHadessSwitcherooControl *control;
src/shell-global.c: control = shell_net_hadess_switcheroo_control_proxy_new_for_bus_finish (res, &error);
src/shell-global.c: g_debug ("Could not get switcheroo-control GDBusProxy: %s", error->message);
src/shell-global.c: global->switcheroo_control = G_DBUS_PROXY (control);
src/shell-global.c: g_debug ("Got switcheroo-control proxy successfully");
src/shell-global.c: cached_props = g_dbus_proxy_get_cached_property_names (global->switcheroo_control);
src/shell-global.c: g_object_notify (G_OBJECT (global), "switcheroo-control");
src/shell-global.c: g_dbus_connection_call (g_dbus_proxy_get_connection (global->switcheroo_control),
src/shell-global.c: g_dbus_proxy_get_name (global->switcheroo_control),
src/shell-global.c: g_dbus_proxy_get_object_path (global->switcheroo_control),
src/shell-global.c: g_dbus_proxy_get_interface_name (global->switcheroo_control),
src/shell-global.c: global->switcheroo_cancellable,
src/shell-global.c: got_switcheroo_control_gpus_property_cb,
src/shell-global.c: case PROP_SWITCHEROO_CONTROL:
src/shell-global.c: g_value_set_object (value, global->switcheroo_control);
src/shell-global.c:switcheroo_appeared_cb (GDBusConnection *connection,
src/shell-global.c: g_debug ("switcheroo-control appeared");
src/shell-global.c: shell_net_hadess_switcheroo_control_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
src/shell-global.c: "net.hadess.SwitcherooControl",
src/shell-global.c: "/net/hadess/SwitcherooControl",
src/shell-global.c: global->switcheroo_cancellable,
src/shell-global.c: switcheroo_control_ready_cb,
src/shell-global.c:switcheroo_vanished_cb (GDBusConnection *connection,
src/shell-global.c: g_debug ("switcheroo-control vanished");
src/shell-global.c: g_clear_object (&global->switcheroo_control);
src/shell-global.c: g_object_notify (G_OBJECT (global), "switcheroo-control");
src/shell-global.c: global->switcheroo_cancellable = g_cancellable_new ();
src/shell-global.c: "net.hadess.SwitcherooControl",
src/shell-global.c: switcheroo_appeared_cb,
src/shell-global.c: switcheroo_vanished_cb,
src/shell-global.c: g_cancellable_cancel (global->switcheroo_cancellable);
src/shell-global.c: g_clear_object (&global->switcheroo_cancellable);
src/shell-global.c: PROP_SWITCHEROO_CONTROL,
src/shell-global.c: g_param_spec_object ("switcheroo-control",
src/shell-global.c: "switcheroo-control",
src/shell-global.c: "D-Bus Proxy for switcheroo-control daemon",
src/shell-global.c: * shell_global_get_switcheroo_control:
src/shell-global.c: * Get the global #GDBusProxy instance for the switcheroo-control
src/shell-global.c:shell_global_get_switcheroo_control (ShellGlobal *global)
src/shell-global.c: return global->switcheroo_control;
src/shell-global.h: shell_global_get_switcheroo_control (ShellGlobal *global);
这证实了一件事,更直观的证据(我是一个 Fedora 用户):
简而言之
回答你的问题:Gnome使用一个名为switcheroo-control
的库来实现。
实际操作:你可以使用switcherooctl launch <command>
来做同样的事情。
编辑:我不确定这个命令在Ubuntu上是否有效,但是Debian和Ubuntu的软件库中有一个名为
switcheroo-control
的软件包。
这是提取出来的
switcheroo-control
软件包(deb)的树形结构。
.
├── etc
│ └── dbus-1
│ └── system.d
│ └── net.hadess.SwitcherooControl.conf
├── lib
│ ├── systemd
│ │ └── system
│ │ └── switcheroo-control.service
│ └── udev
│ └── hwdb.d
│ └── 30-pci-intel-gpu.hwdb
└── usr
├── libexec
│ └── switcheroo-control
└── share
└── doc
└── switcheroo-control
├── changelog.Debian.gz
├── copyright
├── NEWS.gz
└── README.md
编辑:好的,我找到了问题所在。当设置变量时,如果像这样设置
VAR=value
,那么这是一个普通变量,而
export VAR=value
则使其可供子进程访问
(REF)。
在此之后,任何一个变量都对我有效,例如:
export __GLX_VENDOR_LIBRARY_NAME=nvidia
、
export __NV_PRIME_RENDER_OFFLOAD=1
、
export __VK_LAYER_NV_optimus=NVIDIA_only
、
export DRI_PRIME=1
(它们各自有不同的功能)。
因此,使用
switchrootctl launch <command>
或者导出上述变量并启动进程。你甚至可以创建一个别名。
例如:
alias dgpu="export __GLX_VENDOR_LIBRARY_NAME=nvidia && export __NV_PRIME_RENDER_OFFLOAD=1 &&"
然后使用
dgpu <command>
。
这是由switchroot-control设置的环境变量(在我的情况下)。
vga_switcheroo
的信息:https://help.ubuntu.com/community/HybridGraphics - Leventeswitcherooctl
命令的类似功能吗? - Shriraj Hegdeswitcheroo-control
软件包(我没有安装它,可能是默认安装的,或者操作系统安装程序在检测到我的硬件设置时自动引入的),但是$ switcherooctl --help \ switcherooctl: command not found
,此外,对于switche
子字符串的Tab键补全没有任何建议。 - Levente$ DRI_PRIME=<whatev> applicationName
这样的东西,基于这个arch wiki,但尽管它似乎起了作用,却没有带来任何喜悦,因为我不得不得出结论,开源的radeon驱动与我的特定显卡不兼容,所有的应用程序都会崩溃或者甚至无法启动。而且,我所读到的关于amdgpu_pro
的一切都让我决定不冒险安装它。所以我只使用英特尔的显卡,不再进行切换。 - Levente