关于 Ubuntu 中的“使用专用显卡启动”选项存在许多问题:这个,这个, 或者这个,例如。但是他们都没有问我真正想知道的问题。
我想了解此选项的作用,尤其是在我的系统环境中:主板集成了 Intel 显卡和 Nvidia 显卡。我有三个显示器连接到 Nvidia 卡上的端口,没有连接到板载显卡。
当我看到“使用专用显卡启动”时,我会想象这样的事情:桌面正在集成显卡上运行(使用其硬件并在其内存中呈现),而我刚刚使用此选项打开的这个窗口的内容正在另一张显卡上运行,并且以某种方式通过集成显卡传输输出(有点像“画中画”?)。
但鉴于我根本没有使用板载显卡,我的应用程序不是已经在专用显卡上运行了吗?
我怀疑我对此选项的理解是错误的。有人能解释一下此选项的作用吗?
答案1
我也有完全相同的问题,像__GLX_VENDOR_LIBRARY_NAME=nvidia
、__NV_PRIME_RENDER_OFFLOAD=1
、__VK_LAYER_NV_optimus=NVIDIA_only
这样的变量都没有DRI_PRIME=1
产生相同的结果。
我甚至尝试在 gnome-shell 源代码中搜索,但这些功能不在 gnome-shell repo 中。
我终于偶然发现了 switechroo-controls 包,
我尝试switcherooctl launch <command>
复制 gnome shell 的行为。然后我突然想到在 gnome-shell repo 中搜索 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);
结论
回答您的确切问题: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
使其可供子进程访问(参考)
在此之后,任何一个变量都对我有用,,,,(它们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>
答案2
我不确定它是否是唯一的效果,但从我在笔记本电脑上找到的内容来看,它为启动的进程设置了 DRI_PRIME 环境变量。
就我而言DRI_PRIME=pci-0000_01_00_0
我找不到太多关于这究竟有何影响的信息,但可以找到一些信息这里。