“使用专用显卡启动”到底是什么意思?

在Ubuntu中,关于“使用专用显卡启动”选项有一些问题:例如this onethis one或者this one。但是这些问题都没有回答我真正想知道的问题。

我想了解这个选项在我的系统中的作用,尤其是在我系统的背景下:主板上有集成的英特尔显卡和一张Nvidia显卡。我将三个显示器连接到Nvidia显卡的端口上,并没有连接任何设备到集成显卡。

当我看到“使用专用显卡启动”时,我想象的是这样的情况:桌面正在运行(使用集成显卡的硬件和内存进行渲染),而我刚刚打开的这个窗口使用另外一张显卡运行,然后输出通过集成显卡传输(有点像“画中画”?)。

但是考虑到我完全没有使用集成显卡,那么我的应用程序岂不是已经在专用显卡上运行了吗?

我怀疑我对这个选项的理解是错误的。有人能澄清一下这个选项的作用吗?

2个回答

我有完全相同的问题,像__GLX_VENDOR_LIBRARY_NAME=nvidia__NV_PRIME_RENDER_OFFLOAD=1__VK_LAYER_NV_optimus=NVIDIA_onlyDRI_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=nvidiaexport __NV_PRIME_RENDER_OFFLOAD=1export __VK_LAYER_NV_optimus=NVIDIA_onlyexport 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 - Levente
@Levente,你可以搜索并评论一下 Ubuntu 上的 switcherooctl 命令的类似功能吗? - Shriraj Hegde
在Ubuntu 20.04上,使用Intel / AMD双显卡,我已经安装了switcheroo-control软件包(我没有安装它,可能是默认安装的,或者操作系统安装程序在检测到我的硬件设置时自动引入的),但是$ switcherooctl --help \ switcherooctl: command not found,此外,对于switche子字符串的Tab键补全没有任何建议。 - Levente
我曾经能够做的唯一事情就是类似于$ DRI_PRIME=<whatev> applicationName这样的东西,基于这个arch wiki,但尽管它似乎起了作用,却没有带来任何喜悦,因为我不得不得出结论,开源的radeon驱动与我的特定显卡不兼容,所有的应用程序都会崩溃或者甚至无法启动。而且,我所读到的关于amdgpu_pro的一切都让我决定不冒险安装它。所以我只使用英特尔的显卡,不再进行切换。 - Levente
请检查最后一次编辑。 - Shriraj Hegde

我不确定这是唯一的影响,但根据我在我的笔记本电脑上找到的信息,它会为启动的进程设置DRI_PRIME环境变量。
在我的情况下,设置为DRI_PRIME=pci-0000_01_00_0
关于它具体如何产生影响,我没有找到太多信息,但可以在这里找到一些相关资料。