Hardware Acceleration on Linux Mint, Cinnamon, and Firefox
15/Dec 2023Background
I can’t believe how much time I spent on debugging this. This story begins with a new AMD graphics card. After installing the AMD RX6000 series graphics card and the amdgpu driver, and setting all the required Firefox configs, I open a youtube video at 4k 60fps on Firefox and expect to enjoy av1 hardware accelerated decoding. Disappointingly, all I see is dropped frames.
To understand what’s wrong, I head over to about:support and observe some FEATURE_FAILURE_SOFTWARE_GL and FEATURE_FAILURE_VIDEO_DECODING_TEST_FAILED. It is all “Unsupported” under Media > Codec Support Information > Hardware Decoding.
Debugging
Firefox
FEATURE_FAILURE_SOFTWARE_GL doesn’t return many hits on Google. The most useful one is a link to Firefox source code GfxInfo.cpp. The comment says:
// All Mesa software drivers, they should get Software WebRender instead.
Well, somehow Firefox thinks Mesa is running in software rendering mode.
vainfo
vainfo looks perfectly normal though:
$ vainfo
libva info: VA-API version 1.16.0
libva info: Trying to open /opt/amdgpu/lib/x86_64-linux-gnu/dri/radeonsi_drv_video.so
libva info: Found init function __vaDriverInit_1_16
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.16 (libva 2.12.0)
vainfo: Driver version: Mesa Gallium driver 23.2.0-devel for AMD Radeon RX 6750 GRE 12GB (navi22, LLVM 16.0.6, DRM 3.54, 6.5.0-14-generic)
vainfo: Supported profile and entrypoints
VAProfileMPEG2Simple : VAEntrypointVLD
VAProfileMPEG2Main : VAEntrypointVLD
VAProfileVC1Simple : VAEntrypointVLD
VAProfileVC1Main : VAEntrypointVLD
VAProfileVC1Advanced : VAEntrypointVLD
VAProfileH264ConstrainedBaseline: VAEntrypointVLD
VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
VAProfileH264Main : VAEntrypointVLD
VAProfileH264Main : VAEntrypointEncSlice
VAProfileH264High : VAEntrypointVLD
VAProfileH264High : VAEntrypointEncSlice
VAProfileHEVCMain : VAEntrypointVLD
VAProfileHEVCMain : VAEntrypointEncSlice
VAProfileHEVCMain10 : VAEntrypointVLD
VAProfileHEVCMain10 : VAEntrypointEncSlice
VAProfileJPEGBaseline : VAEntrypointVLD
VAProfileVP9Profile0 : VAEntrypointVLD
VAProfileVP9Profile2 : VAEntrypointVLD
VAProfileAV1Profile0 : VAEntrypointVLD
VAProfileNone : VAEntrypointVideoProc
Environment
In terminal:
$ inxi -Gx
Graphics:
Device-1: AMD Navi 22 [Radeon RX 6700/6700 XT / 6800M] vendor: Tul
driver: amdgpu v: kernel bus-ID: 08:00.0
Display: x11 server: X.Org v: 1.21.1.4 driver: X: loaded: amdgpu
unloaded: fbdev,modesetting,vesa gpu: amdgpu resolution: 2560x1440~144Hz
OpenGL: renderer: llvmpipe (LLVM 16.0.6 256 bits)
v: 4.5 Mesa 23.2.0-devel direct render: Yes
OpenGL: renderer: llvmpipe does confirm that the terminal is not using amdgpu. A quick search returns this thread on Linux Mint forum with no answers. I wonder if this is what’s happening to me as well, given the similar setup.
So I open an another tab in terminal:
$ inxi -Gx
Graphics:
Device-1: AMD Navi 22 [Radeon RX 6700/6700 XT / 6800M] vendor: Tul
driver: amdgpu v: kernel bus-ID: 08:00.0
Display: x11 server: X.Org v: 1.21.1.4 driver: X: loaded: amdgpu
unloaded: fbdev,modesetting,vesa gpu: amdgpu resolution: 2560x1440~144Hz
OpenGL: renderer: AMD Radeon RX 6750 GRE 12GB (navi22 LLVM 16.0.6 DRM
3.54 6.5.0-14-generic)
v: 4.6 Mesa 23.2.0-devel direct render: Yes
Wow. This is not expected. Why is OpenGL renderer different in another terminal? Let’s check what’s different in the environment.
Back to the 1st terminal:
$ env > term0.envIn 2nd tab:
$ env > term1.env
$ diff --color -u term0.env term1.env Here’s the diff:
--- term0.env 2023-12-15 10:33:05.280564866 +0000
+++ term1.env 2023-12-15 10:33:11.256683682 +0000
@@ -9,17 +9,15 @@
LANGUAGE=en_HK:en
MANDATORY_PATH=/usr/share/gconf/cinnamon2d.mandatory.path
SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
-CINNAMON_VERSION=5.8.4
XMODIFIERS=@im=fcitx
DESKTOP_SESSION=cinnamon2d
-CINNAMON_SLOWDOWN_FACTOR=0.0001
GTK_MODULES=gail:atk-bridge
-XDG_SEAT=seat0
PWD=/home/carson
LOGNAME=carson
XDG_SESSION_DESKTOP=cinnamon2d
XDG_SESSION_TYPE=x11
GPG_AGENT_INFO=/run/user/1000/gnupg/S.gpg-agent:0:1
+SYSTEMD_EXEC_PID=2071
XAUTHORITY=/home/carson/.Xauthority
XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/carson
GDM_LANG=en_US
@@ -29,9 +27,8 @@
XDG_CURRENT_DESKTOP=X-Cinnamon
VTE_VERSION=6800
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
-GNOME_TERMINAL_SCREEN=/org/gnome/Terminal/screen/a3b05e4f_66fc_43a4_87bb_d14237b3bda7
+GNOME_TERMINAL_SCREEN=/org/gnome/Terminal/screen/3346a129_0c6f_4a36_800e_b2e353af8108
MOZ_DISABLE_RDD_SANDBOX=1
-CLUTTER_DEFAULT_FPS=15
NVM_DIR=/home/carson/.nvm
LESSCLOSE=/usr/bin/lesspipe %s %s
XDG_SESSION_CLASS=user
@@ -44,17 +41,11 @@
SHLVL=1
NVM_CD_FLAGS=
QT_IM_MODULE=fcitx
-XDG_VTNR=7
-CLUTTER_PAINT=disable-culling
-LIBGL_ALWAYS_SOFTWARE=1
-XDG_SESSION_ID=c2
XDG_RUNTIME_DIR=/run/user/1000
GTK3_MODULES=xapp-gtk3-module
XDG_DATA_DIRS=/home/carson/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share/:/usr/share/cinnamon2d:/usr/share/gnome:/home/carson/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop
PATH=/home/carson/.nvm/versions/node/v16.15.1/bin:/home/carson/.poetry/bin:/home/carson/bin:/home/carson/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
-CINNAMON_2D=1
GDMSESSION=cinnamon2d
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
NVM_BIN=/home/carson/.nvm/versions/node/v16.15.1/bin
-MUFFIN_NO_SHADOWS=1
_=/usr/bin/env
Obviously, the culprit is LIBGL_ALWAYS_SOFTWARE=1. Firefox will not use hardware acceleration with LIBGL_ALWAYS_SOFTWARE=1. To confirm that, I start firefox in the 2nd tab, and yes, hardware accelerated video decoding works there.
But who sets that LIBGL_ALWAYS_SOFTWARE=1? And what’s CINNAMON_2D=1?
Session
A quick search on cinnamon LIBGL_ALWAYS_SOFTWARE returns a line in cinnamon repo. Basically cinnamon2d sets all these environment variables. I don’t know why I’m in a cinnamon 2D session as opposed to a normal one, but this is the root cause of all hardware acceleration issues.
Resolution
Log out. In the cinnamon login page, next to your username, select Cinnamon (Default), instead of Cinnamon (Software Rendering). This choice will be memorized. Log in.
There you go. Everything now works as expected.
And why that happened in the first place? My best guess is that either I had been running 2D Cinnamon forever, or it was selected automatically when I was messing with the drivers.