Search This Blog

Saturday, December 25, 2021

Nvidia optimus with wayland. Help needed.

I have given a try on wayland and it works in my notebook (Gigabyte p34v5) when using only the Intel gpu (/dev/dri/card0) and mesa. Now I have been trying to make it work with the Nvidia gpu (GeForce GTX 970M, /dev/dri/card1) using proprietary driver. The thing about that gpu is that is uses optimus and thus need the following command to work with X11:

# /usr/share/sddm/scripts/Xsetup file
xrandr --setprovideroutputsource modesetting NVIDIA-0

There is just a blank screen on sddm whithout that command (the Nvidia gpu is not physically connected to the display, it needs the Intel gpu to send image to any display, the command above connects the Nvidia gpu to the Intel one). Since xrandr does not work with wayland I am kind of stuck trying figure out the equivalent of that command for wayland. I have tried the following environment variable to no avail:

WLR_DRM_DEVICES=card1:card0

My current startwayland.sh script is:

# card0: intel
# card1: nvidia
export WLR_DRM_DEVICES=card1:card0
export KWIN_DRM_DEVICES=/dev/dri/card1:/dev/dri/card0
export XDG_RUNTIME_DIR=/tmp/1001
export XDG_SESSION_TYPE=wayland
export QT_QPA_PLATFORM=wayland
export GBM_BACKEND=nvidia-drm
export __EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/10_nvidia.json:/usr/share/glvnd/egl_vendor.d/50_mesa.json
export EGL_PLATFORM=wayland
export EGL_LOG_LEVEL=debug
export QT_LOGGING_RULES="kwin*=true"
export KWIN_GL_DEBUG=1
export WAYLAND_DEBUG=1
unset DISPLAY
mkdir -m 0700 -p $XDG_RUNTIME_DIR

if [ -n "$DBUS_SESSION_BUS_ADDRESS" ]; then
    export $(dbus-launch)
    sleep 1
fi


kwin_wayland --xwayland --exit-with-session=konsole 2>&1 | tee -a kwin_wayland_log.txt

I am using kwin_wayland instead of plasma-wayland so less programs are started during my tests.

EGL is correctly initialized on both gpu by what can be seen on kwin_wayland_log.txt, though nvidia-drivers uses version 1.5 and mesa uses version 1.4.

The first relevant error is "kwin_wayland_drm: swapping buffers failed on output KWin::DrmOutput(0x559b35fd8d30, name="eDP-1", geometry=QRect(0,0 1920x1080), scale=1)". eDP-1 is my laptop's LCD and W2486 is an external monitor.

There is no screen update after I launch kwin_wayland similar to what happens with X11 without the xrandr command. I need to log through ssh to 'chvt' to a different virtual terminal or kill kwin_wayland to use laptop again. I guess I just need to instruct kwin_wayland to connect the output of nvidia gpu to intel's one to make everything work. I just do not know how to do that.

My environment:

x11-drivers/nvidia-drivers-495.46-r10:0/495 to use Nvidia's new GBM support instead of EGLStream
gui-libs/egl-wayland-1.1.9:0
gui-libs/eglexternalplatform-1.1:0
media-libs/mesa-21.3.2:0
dev-qt/qtwayland-5.15.2-r16:5/5.15.2 with patch Don't block in QWaylandDisplay::flushRequests
kde-plasma/kwin-9999:5 this is a git build of commit 445946382379b65701259bc1f75c92227348db31 from Dec 15 2021 so I can use platforms/drm: use gbm with NVidia driver 495+.

Have someone successfully run plasma-wayland with nvidia's optimus and gbm instead of EGLStream?

2 comments:

Mike Lothian said...

I'm curious as to why you'd want to run your desktop from your Nvidia card. Your intel chip should be .ore than fast enough and by not using your Nvidia chip you'll save power. You can then use your Nvidia chip for games or more graphics hungry apps by starting them with DRI_PRIME=1

Lamarque said...

$ DRI_PRIME=1 glxgears
libGL error: MESA-LOADER: failed to open nouveau: /usr/lib64/dri/nouveau_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib64/dri, suffix _dri)
libGL error: failed to load driver: nouveau
X connection to :1 broken (explicit kill or server shutdown).

Is that supposed to work with proprietary drivers? The xrandr command was the first command that make X11 work on this laptop, so I kept that way. I did not know it was possible to use something like DRI_PRIME until some days ago. But I am still not sure if it is possible to use with optimus.