遊戲在wayland正常使用Nvidia Optimus但在xorg反而不能用

前幾天剛從Ubuntu轉到Debian。之前用Ubuntu沒有遇到相同的問題,在Xorg和Wayland打開Minecraft F3介面都有顯示Nividia顯卡。但是我在Debian和xorg的環境下用這個指令打開Prism Launcher(一個Minecraft的啟動器)

 __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia flatpak run org.prismlauncher.PrismLauncher

F3顯示我在用內顯(用Wayland沒有這個問題,在Ubuntu上Wayland和Xorg都沒問題)

有沒有辦法解決這個問題?

以下指令都是在Debian下執行的:

nvidia-smi
Sat Sep 16 01:54:45 2023       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.125.06   Driver Version: 525.125.06   CUDA Version: 12.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  On   | 00000000:01:00.0 Off |                  N/A |
| N/A   45C    P8    N/A /  N/A |      4MiB /  2048MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
lspci -nn | egrep -i "3d|display|vga"
00:02.0 VGA compatible controller [0300]: Intel Corporation Iris Plus Graphics G1 (Ice Lake) [8086:8a56] (rev 07)
01:00.0 3D controller [0302]: NVIDIA Corporation GP108M [GeForce MX330] [10de:1d16] (rev a1)
glxinfo | grep OpenGL
OpenGL vendor string: Intel
OpenGL renderer string: Mesa Intel(R) UHD Graphics (ICL GT1)
OpenGL core profile version string: 4.6 (Core Profile) Mesa 22.3.6
OpenGL core profile shading language version string: 4.60
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.6 (Compatibility Profile) Mesa 22.3.6
OpenGL shading language version string: 4.60
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 22.3.6
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:
__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia glxinfo | grep OpenGL
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: NVIDIA GeForce MX330/PCIe/SSE2
OpenGL core profile version string: 4.6.0 NVIDIA 525.125.06
OpenGL core profile shading language version string: 4.60 NVIDIA
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.6.0 NVIDIA 525.125.06
OpenGL shading language version string: 4.60 NVIDIA
OpenGL context flags: (none)
OpenGL profile mask: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 NVIDIA 525.125.06
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:

我注意到你在使用 flatpak 版本的 Prism Launcher,但是:

已经配置了对应的环境变量

即使我不加入環境變量,遊戲一樣會用內顯啟動,而且在wayland沒有這個問題

flatpak 调试起来有点困难,flatpak 并不依赖系统的用户空间组件,而是使用自己的 mesa

你可以尝试使用 flatpak run --command=glxinfo org.prismlauncher.PrismLauncher | grep OpenGL 检查该软件的工作状况

Mesa :frowning:

$ flatpak run --command=glxinfo org.prismlauncher.PrismLauncher | grep OpenGL
OpenGL vendor string: Intel
OpenGL renderer string: Mesa Intel(R) UHD Graphics (ICL GT1)
OpenGL core profile version string: 4.6 (Core Profile) Mesa 23.1.6 (git-0697ac0d75)
OpenGL core profile shading language version string: 4.60
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.6 (Compatibility Profile) Mesa 23.1.6 (git-0697ac0d75)
OpenGL shading language version string: 4.60
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 23.1.6 (git-0697ac0d75)
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:
__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia flatpak run --command=glxinfo org.prismlauncher.PrismLauncher | grep OpenGL
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: NVIDIA GeForce MX330/PCIe/SSE2
OpenGL core profile version string: 4.6.0 NVIDIA 525.125.06
OpenGL core profile shading language version string: 4.60 NVIDIA
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.6.0 NVIDIA 525.125.06
OpenGL shading language version string: 4.60 NVIDIA
OpenGL context flags: (none)
OpenGL profile mask: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 NVIDIA 525.125.06
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:

所以 Mesa 显然没有问题,我怀疑是 Prism Launcher 或者 flatpak 打包时有问题。

另外我注意到 Prism Launcher 的设置里有“启用独显”。这个选项有用吗?因为实际上 Prism Launcher 是否使用独显并不重要,关键是 minecraft 怎么处理。

很遗憾我没有双显卡不能进行更多的本地测试。

我有勾選啟用獨顯

你可以先启动一个 minecraft 实例,然后使用 flatpak enter org.prismlauncher.PrismLauncher bash 的方法进入 flatpak 实例内部查看,先用 ps -ef 找到 minecraft 进程的 pid,然后 cat /proc/{pid}/environ 检查环境变量或者其它问题。

1 个赞

正在研究这个程序的启动流程…


Update 1:

__GLX_VENDOR_LIBRARY_NAME=nvidia
__NV_PRIME_RENDER_OFFLOAD=1
__VK_LAYER_NV_optimus=NVIDIA_only

java 进程确实具有这些环境变量。我相信至少从这方面看不太可能是启动器的问题。

你有尝试过 Appimage 版本的 prism launcher 吗?

剛剛是這官方建議用的apt來裝
用apt裝的prism launcher有正常使用nvidia顯卡
看起來是flatpak包的問題,之前在Ubuntu用的snap包好像沒有這個問題

用這個指令解決了

sudo flatpak override --device=dri --env=__NV_PRIME_RENDER_OFFLOAD=1 --env=__VK_LAYER_NV_optimus=NVIDIA_only --env=__GLX_VENDOR_LIBRARY_NAME=nvidia org.prismlauncher.PrismLauncher

org.prismlauncher.PrismLauncher 的默认设置是 --device=all,按理说这应该包括了 dri;环境变量上启动器也都已经设置过了,真奇怪。不过既然能用就算了。

如果不想全局配置 override,可以使用


flatpak override --user --device=dri --env=__NV_PRIME_RENDER_OFFLOAD=1 --env=__VK_LAYER_NV_optimus=NVIDIA_only --env=__GLX_VENDOR_LIBRARY_NAME=nvidia org.prismlauncher.PrismLauncher

只修改当前用户的 override。

GUI 爱好者还可以使用 Flatseal 来管理 override 配置。

1 个赞