GBM_BACKEND=nvidia-drm on wayland with discrete GPU on laptop failure

Hello all!

I would like to start KDE Plasma on a laptop using the discrete NVIDIA GPU as primary graphic processor, so I follow this guide:

https://community.kde.org/Plasma/Wayland/Nvidia

But kde control center show Intel as the graphics processor and reported also by the nvidia-smi command.

Screenshot_20230822_132620

So after googling I found the necessary to set
GBM_BACKEND=nvidia-drm

But I got this kind of errors when try to launch plasma on wayland from a VT:

#> export GBM_BACKEND=nvidia-drm
#> dbus-run-session startplasma-wayland

dbus-daemon[1071302]: [session uid=1000 pid=1071302] Activating service name='org.freedesktop.systemd1' requested by ':1.0' (uid=1000 pid=1071303 comm="startplasma-wayland ")
dbus-daemon[1071302]: [session uid=1000 pid=1071302] Activated service 'org.freedesktop.systemd1' failed: Process org.freedesktop.systemd1 exited with status 1
dbus-daemon[1071302]: [session uid=1000 pid=1071302] Activating service name='org.freedesktop.systemd1' requested by ':1.0' (uid=1000 pid=1071303 comm="startplasma-wayland ")
dbus-daemon[1071302]: [session uid=1000 pid=1071302] Activated service 'org.freedesktop.systemd1' failed: Process org.freedesktop.systemd1 exited with status 1
dbus-daemon[1071302]: [session uid=1000 pid=1071302] Activating service name='org.freedesktop.systemd1' requested by ':1.0' (uid=1000 pid=1071303 comm="startplasma-wayland ")
dbus-daemon[1071302]: [session uid=1000 pid=1071302] Activated service 'org.freedesktop.systemd1' failed: Process org.freedesktop.systemd1 exited with status 1
dbus-daemon[1071302]: [session uid=1000 pid=1071302] Activating service name='org.kde.KSplash' requested by ':1.0' (uid=1000 pid=1071303 comm="startplasma-wayland ")
dbus-daemon[1071302]: [session uid=1000 pid=1071302] Activating service name='org.freedesktop.systemd1' requested by ':1.0' (uid=1000 pid=1071303 comm="startplasma-wayland ")
dbus-daemon[1071302]: [session uid=1000 pid=1071302] Activated service 'org.freedesktop.systemd1' failed: Process org.freedesktop.systemd1 exited with status 1
dbus-daemon[1071302]: [session uid=1000 pid=1071302] Activating service name='org.freedesktop.systemd1' requested by ':1.3' (uid=1000 pid=1071329 comm="/usr/bin/kwin_wayland_wrapper --xwayland ")
dbus-daemon[1071302]: [session uid=1000 pid=1071302] Activated service 'org.freedesktop.systemd1' failed: Process org.freedesktop.systemd1 exited with status 1
kdeinit5: preparing to launch '/usr/lib/x86_64-linux-gnu/libexec/kf5/klauncher'
kdeinit5: Launched KLauncher, pid = 1071340, result = 0
No backend specified, automatically choosing drm
No backend specified, automatically choosing drm
No backend specified, automatically choosing drm
No backend specified, automatically choosing drm
No backend specified, automatically choosing drm
qt.qpa.wayland: Creating a fake screen in order for Qt not to crash
Error: could not determine $DISPLAY.
Error: Can not contact kdeinit5!
org.kde.startup: "kdeinit5_shutdown" () exited with code 255
startplasma-wayland: Shutting down...
startplasmacompositor: Shutting down...
startplasmacompositor: Done.
qt.qpa.wayland: Creating a fake screen in order for Qt not to crash
qt.qpa.wayland: Failed to initialize EGL display 3001
Warning: fallback to QtQuick software backend.
qt.qpa.wayland: Failed to initialize EGL display 3001
Warning: fallback to QtQuick software backend.
kdeinit5: Communication error with launcher. Exiting!
org.kde.knotifications: WaitForName: Service was not registered within timeout

The unique way to obtain nvidia primary gpu on wayland is to launch startplasma-wayland with prime offload:

#> export __NV_PRIME_RENDER_OFFLOAD=1
#>  export __GLX_VENDOR_LIBRARY_NAME=nvidia
 #> dbus-run-session startplasma-wayland

But the desktop is very un-responsible even if kde control center show nvidia card as graphic processor, probably due to using nvidia and not nvidia-drm driver.

So, there are some limitations on using nvidia gpu on plasma wayland for nvidia prime laptops?

Thanks a lot to everyone!

NVIDIA Driver Version: 535.98
KDE Plasma version: 5.27.7
NVIDIA RTX A2000 8GB Laptop GPU
Intel® Core™ i7-12800H

Neither of these are a correct or sane way to make KWin choose a GPU. You need to put KWIN_DRM_DEVICES="/dev/dri/card1:/dev/dri/card0" into /etc/environment and reboot

Thank you very much @Zamundaaa !!!
It works!

Anyway I observed a high cpu usage taken by kwin_wayland process, around 10-20 %.
Is it expected?

It’s not entirely unexpected; due to some unfortunate shortcomings of OpenGL on NVidia, copying the screen content from the NVidia to the Intel GPU is quite inefficient. It will be fixed with the Vulkan renderer for KWin, but that will still take some time to be ready for prime time