Jan 17 '22

Starting KDE plasma wayland with Fedora 35 and nvidia drivers

A quick bit of background: X11 is a compositor and Wayland is a protocol for a compositor. Compositors typically take all the windows, the cursor and window decorations (borders, shadow etc.) and combine them into one big image that gets sent to your monitor.

There’s a few things I’m getting tired of with X11…

  • No easy per-monitor high DPI support
  • Screen tearing - e.g. from youtube videos and basically any animation
  • Dirty regions not updating - e.g. when you drag a window over another it leaves a trail of itself smeard across whatever’s behind it
  • Low framerate - I could swear I’m not getting 60fps
  • Occasional system hangs while the compositor crashes. This is likely plasma/kwin’s fault for all I know.

Incidentally, workarounds include disabling HW composition or just restarting things. For me with KDE plasma, that’s kwin --replace and maybe killall plasmashell ; kstart plasmashell.

I’ve never looked at the code and this is entirely hearsay. I think with X11 apps actually share access to a framebuffer. There is just one framebuffer for all monitors. The framebuffer is front-buffered, i.e. no swapchain or flipping on vsync, which is why tearing is inevitable. However, there appears to be double buffering and multiple framebuffer extensions, so this could all be wrong or they’re just not used.

In contrast, some cleaner limitataions of the wayland protocol and a from-scratch modern compositor implementation might avoid some of the above issues.

akmod-nvidia conflict

After upgrading from Fedora 32 to 35 (via 34) I hit the following conflict when installing the nvidia driver.

sudo dnf install akmod-nvidia
Last metadata expiration check: 0:05:06 ago on Mon 17 Jan 2022 13:16:57 PST.
 Problem: conflicting requests
  - package akmod-nvidia-3:470.74-1.fc35.x86_64 requires nvidia-kmod-common >= 3:470.74, but none of the providers can be installed
  - package akmod-nvidia-3:495.46-1.fc35.x86_64 requires nvidia-kmod-common >= 3:495.46, but none of the providers can be installed
  - package xorg-x11-drv-nvidia-3:470.74-1.fc35.x86_64 is filtered out by modular filtering
  - package xorg-x11-drv-nvidia-3:495.46-1.fc35.x86_64 is filtered out by modular filtering
(try to add '--skip-broken' to skip uninstallable packages)

This was caused by the nvidia cuda-fedora repository. I had just upgraded from fedora 32 and still had the old one installed at /etc/yum.repos.d/cuda-fedora32.repo. Adding the new repo allowed me to install akmod-nvidia, but caused problems for DRM/wayland:

sudo dnf config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/fedora35/x86_64/cuda-fedora35.repo
sudo dnf config-manager --set-disabled cuda-fedora32-x86_64

The cuda-fedora repository included a newer nvidia driver but I think it did not include the new nvidia_drm kernel module. When I tried to load it with modeset=1 I was getting an error from sudo modprobe nvidia_drm modeset=1 about a version mismatch. My solution was to remove the repo entirely and reinstall the nvidia driver from the regular fedora repos, which ultimately allowed me to run plasma wayland.

To uninstall the cuda-fedora repo and reinstall the nvidia driver from rpmfusion-nonfree-updates:

sudo dnf repository-packages cuda-fedora35-x86_64 remove
sudo dnf config-manager --set-disabled cuda-fedora35-x86_64

# Again I hit the above conflict issue from dnf. The following fixed it but I don't understand why at all.
sudo dnf module disable nvidia-driver
# This command looks like it should list the above to check if it's already disabled, but doesn't print anything for me
sudo dnf module list --disabled

# Reinstall the nvidia driver, that the above uninstalled
sudo dnf install akmod-nvidia

Enabling Nvidia DRM modeset

In order to use the plasma wayland compositor, nvidia’s DRM backend is needed. This has to be enabled explicitly with a flag to the kernel module. Once enabled it’s possible X11 breaks so remember how to undo it. Add the following to to /etc/default/grub:


Re-generate the grub config (if you’re using grub2, otherwise drop the 2s):

sudo grub2-mkconfig -o /boot/grub2/grub.cfg
# Reboot

Hopefully that just works. If it doesn’t, doing it manually can print some useful error messages:

# Stop the greeter, e.g. one of: kdm, sddm, gdm, lightdm
# In a virtual terminal (ctrl-alt-f2 for example)
sudo service kdm stop

# Remove and reinstall the kernel module with the modeset flag
sudo modprobe -r nvidia_drm
sudo modprobe nvidia_drm modeset=1

sudo service kdm start

Finally in plasma wayland

It seems that most greeters automatically filter out wayland backends if they don’t see the nvidia DRM module loaded. Typically there will be a “Plasma (Wayland)” option to pick on the login screen. If not it’s likely the nvidia kernel module is missing modeset=1 (see above).

Once getting past the above, the “Plasma (Wayland)” option appeared and I could log in.

  • ps -e | grep X gives Xwayland and no Xorg :D
  • My multi-monitor setup with 4k + 1080p JUST WORKS! Font scaling in apps such as google-chrome is a problem, but the desktop looks nice and crisp.
  • No weird graphics glitches yet that I’ve noticed.
  • Performance isn’t great. There’s a long delay when clicking the launcher button. kwin_wayland is chewing up CPU in top, especaially when anything is animating, which makes me think there is now HW compositing.

Given the performance issues I might head back to X11 for a bit, but still this is really promising.

Per-monitor high DPI with X11

I have a 4k monitor and a little 1080p monitor. I’d recommend to everyone: just buy a monitor that’s the same :)

X11 has no support for per-monitor high DPI, so a workaround is to make a framebuffer (the composited result) for two 4k monitors and then have it scale the output for the 1080p monitor.

# Show the current monitors

# Set up 2x 4k outputs and scale down for the 1080p monitor
xrandr \
        --fb 7680x2160 \
        --output DP-2   --auto --panning 3840x2160+0+0 --scale 1x1 --primary \
        --output DP-1   --auto --panning 3840x2160+3840+0 --scale 2x2 --right-of DP-2
There are no comments yet.