ublue-os / bluefin

The next generation Linux workstation, designed for reliability, performance, and sustainability.
https://projectbluefin.io
Apache License 2.0
1.26k stars 162 forks source link

Hardware video decoding is broken in flatpak Firefox (Intel GPU) #1409

Open tamasd opened 5 months ago

tamasd commented 5 months ago

I installed Bluefin on my laptop and noticed that YouTube videos make my laptop quite warm. I started to look into it, and I saw that Firefox can't use hardware acceleration for video decoding.

First I checked the output of vainfo:

$ vainfo
Trying display: wayland
libva info: VA-API version 1.21.0
libva info: Trying to open /usr/lib64/dri-nonfree/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_21
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.21 (libva 2.21.0)
vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 24.1.5 ()
vainfo: Supported profile and entrypoints
      VAProfileNone                   : VAEntrypointVideoProc
      VAProfileNone                   : VAEntrypointStats
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Simple            : VAEntrypointEncSlice
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointFEI
      VAProfileH264Main               : VAEntrypointEncSliceLP
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSlice
      VAProfileH264High               : VAEntrypointFEI
      VAProfileH264High               : VAEntrypointEncSliceLP
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileJPEGBaseline           : VAEntrypointVLD
      VAProfileJPEGBaseline           : VAEntrypointEncPicture
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline: VAEntrypointFEI
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSliceLP
      VAProfileVP8Version0_3          : VAEntrypointVLD
      VAProfileVP8Version0_3          : VAEntrypointEncSlice
      VAProfileHEVCMain               : VAEntrypointVLD
      VAProfileHEVCMain               : VAEntrypointEncSlice
      VAProfileHEVCMain               : VAEntrypointFEI
      VAProfileHEVCMain10             : VAEntrypointVLD
      VAProfileHEVCMain10             : VAEntrypointEncSlice
      VAProfileVP9Profile0            : VAEntrypointVLD
      VAProfileVP9Profile2            : VAEntrypointVLD

The about:support page says that HARDWARE_VIDEO_DECODING runtime is unavailable because it got force disabled by glxInfo with the failure code FEATURE_FAILURE_VIDEO_DECODING_TEST_FAILED.

After reading forum posts and tutorials, I set environment variables in Flatseal:

I enabled GPU acceleration in the Devices section.

I also set a dozen configurations in about:config in various combinations but nothing worked.

So I looked into what Firefox is actually doing when checking the hardware support. Turns out there is a small program called vaapitest. Running this inside the flatpak container revealed the actual problem:

[📦 org.mozilla.firefox ~]$ MOZ_GFX_DEBUG=1 /app/lib/firefox/vaapitest -d /dev/dri/renderD128
vaapitest start, device /dev/dri/renderD128
libva error: dlopen of /run/host/usr/lib64/dri/iHD_drv_video.so failed: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `CXXABI_1.3.15' not found (required by /run/host/usr/lib64/dri/iHD_drv_video.so)
vaInitialize failed -1

Running it outside of the flatpak works:

$ MOZ_GFX_DEBUG=1 /var/lib/flatpak/app/org.mozilla.firefox/current/active/files/lib/firefox/vaapitest -d /dev/dri/renderD128
vaapitest start, device /dev/dri/renderD128
libva info: VA-API version 1.21.0
libva info: Trying to open /usr/lib64/dri-nonfree/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_21
libva info: va_openDriver() returns 0
vaInitialize finished
Profile: H264Main
Profile: H264High
Profile: H264ConstrainedBaseline
Profile: VP8Version0_3
Profile: VP9Profile0
Profile: VP9Profile2
vaapitest finished
VAAPI_SUPPORTED
TRUE
VAAPI_HWCODECS
112
VAAPI_SUPPORTED
TRUE
VAAPI_HWCODECS
112

I checked the libstdc++.so.6 file for the CXXABI support and it has it:

$  strings /usr/lib64/libstdc++.so.6 | grep CXXABI
CXXABI_1.3
CXXABI_1.3.1
CXXABI_1.3.2
CXXABI_1.3.3
CXXABI_1.3.4
CXXABI_1.3.5
CXXABI_1.3.6
CXXABI_1.3.7
CXXABI_1.3.8
CXXABI_1.3.9
CXXABI_1.3.10
CXXABI_1.3.11
CXXABI_1.3.12
CXXABI_1.3.13
CXXABI_1.3.14
CXXABI_1.3.15
CXXABI_TM_1
CXXABI_FLOAT128

The one in the flatpak (coming from org.freedesktop.Platform) does not:

$ strings /var/lib/flatpak/runtime/org.freedesktop.Platform/x86_64/23.08/active/files/lib/x86_64-linux-gnu/libstdc++.so.6 | grep CXXABI
CXXABI_1.3
CXXABI_1.3.1
CXXABI_1.3.2
CXXABI_1.3.3
CXXABI_1.3.4
CXXABI_1.3.5
CXXABI_1.3.6
CXXABI_1.3.7
CXXABI_1.3.8
CXXABI_1.3.9
CXXABI_1.3.10
CXXABI_1.3.11
CXXABI_1.3.12
CXXABI_1.3.13
CXXABI_1.3.14
CXXABI_TM_1
CXXABI_FLOAT128

I think the problem is that the intel-media-driver package from RPMFusion is compiled against a newer libstdc++ while the flatpak platform ships an older one.

$ rpm-ostree status
State: idle
AutomaticUpdates: stage; rpm-ostreed-automatic.timer: last run 13h ago
Deployments:
● ostree-image-signed:docker://ghcr.io/ublue-os/bluefin-dx:latest
                   Digest: sha256:45125c748d736eae5c56cded559ae011669c100695a21d7fcc876a73e9fe1e96
                  Version: 40.20240618.0 (2024-06-18T22:58:32Z)
      RemovedBasePackages: opensc 0.25.0-1.fc40
          LayeredPackages: alacritty
profetik-777 commented 5 months ago

Are you using fedora's FF Flatpak or the one from mozilla?

gnome-software1-1024x697

https://src.fedoraproject.org/flatpaks/firefox

Here is the FF from Mozilla. https://flathub.org/apps/org.mozilla.firefox

I wonder if you might get better luck w/ the Mozilla one?

tamasd commented 5 months ago

I switched from the Flathub version to the Fedora one. Making my host libraries available in the flatpak and playing around a bit with LD_LIBRARY_PATH, so the Intel driver could find libigdgmm.so.12, I was able to make vaapitest run. However, hardware decoding was still unavailable, the about:support page had the same error message.

The Fedora version is worse than the Flathub one, because the software decoder can only play YouTube videos at ~1fps. So I switched back to the Flathub version (that I had originally), this way the software decoding works.

castrojo commented 5 months ago

Yeah this issue has nothing to do with the Fedora flatpak, is that screenshot from a ublue system?

I haven't been able to reproduce on my intel systems, the hwaccel is working on all of them ootb, so maybe it's something else.

spacimek commented 5 months ago

@tamasd I suggest to update your Firefox, this seemed to be broader issue that was fixed in version 127.0.2. I have this version from Flatpak, don't see any issues.

tamasd commented 5 months ago

I checked with 127.0.2, unfortunately I have the same error :(

I think this will be resolved temporarly when the new freedesktop flatpak platform will be released (in a month or so) and a new firefox version will be released using that. However, it might come back when a new Fedora will be released, because the rpm fusion intel driver package is built against Fedora's libraries and not the standard platform.

profetik-777 commented 3 months ago

Should we give this a tag "unable to confirm*" and close? What do we need to confirm root cause?

tamasd commented 3 months ago

I have Firefox 128.0.3 now, the situation is not changed.

Can I get a confirmation from someone who has Intel iGPU and the Flatpak Firefox that on the about:support page HARDWARE_VIDEO_DECODING is enabled? If not, open the Firefox flatpak shell with flatpak run --command=sh org.mozilla.firefox and type MOZ_GFX_DEBUG=1 /app/lib/firefox/vaapitest -d /dev/dri/renderD128 or MOZ_GFX_DEBUG=1 /app/lib/firefox/vaapitest -d /dev/dri/renderD129 in the shell. Is there an error in the output?

castrojo commented 3 months ago

Reopening since this is still affecting people.

Novantric commented 1 month ago

Sorry if this is off topic but been googling this for ages now and it's infuriating, especially as people are gonna be moving to Firefox from chrome after the manifest v2 deprecation. Proper GPU decoding support really does matter, especially whilst multitasking. (Nvidia GPU btw)

bsherman commented 3 weeks ago

@tamasd First, thank you for your issue and for the detailed troubleshooting, that's very helpful!

TL;DR - I believe things should be working well now, at least on intel.

Here's what I'm seeing on a recent bluefin image ( ghcr.io/ublue-os/bluefin-dx-nvidia:stable Version: 40.20241101.0 )... So Fedora 40 on a hybrid intel+nvidia laptop running flatpak mozilla firefox version 132.

Image

I have all default settings for Firefox in Flatseal, nothing custom. I tried to set old "forced" config options to defaults in about:config to see where we are today, including resetting media.ffmpeg.vaapi.enable to default.

Image

Image

Within a flatpak run --command=sh org.mozilla.firefox shell:

$ MOZ_GFX_DEBUG=1 /app/lib/firefox/vaapitest -d /dev/dri/renderD128
vaapitest start, device /dev/dri/renderD128
libva info: VA-API version 1.19.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/intel-vaapi-driver/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_19
libva info: va_openDriver() returns 0
vaInitialize finished
Profile: H264Main
Profile: H264High
Profile: H264ConstrainedBaseline
Profile: VP8Version0_3
Profile: VP9Profile0
Profile: VP9Profile2
Profile: AV1Profile0
vaapitest finished
VAAPI_SUPPORTED
TRUE
VAAPI_HWCODECS
240
VAAPI_SUPPORTED
TRUE
VAAPI_HWCODECS
240

$ MOZ_GFX_DEBUG=1 /app/lib/firefox/vaapitest -d /dev/dri/renderD129
vaapitest start, device /dev/dri/renderD129
libva info: VA-API version 1.19.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/nvidia_drv_video.so
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/intel-vaapi-driver/nvidia_drv_video.so
libva info: Trying to open /usr/lib/x86_64-linux-gnu/GL/lib/dri/nvidia_drv_video.so
libva info: va_openDriver() returns -1
vaInitialize failed -1

On host using flatpak binary:

$ MOZ_GFX_DEBUG=1 /var/lib/flatpak/app/org.mozilla.firefox/current/active/files/lib/firefox/vaapitest -d /dev/dri/renderD128
vaapitest start, device /dev/dri/renderD128
libva info: VA-API version 1.22.0
libva info: Trying to open /usr/lib64/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_22
libva info: va_openDriver() returns 0
vaInitialize finished
Profile: H264Main
Profile: H264High
Profile: H264ConstrainedBaseline
Profile: VP8Version0_3
Profile: VP9Profile0
Profile: VP9Profile2
Profile: AV1Profile0
vaapitest finished
VAAPI_SUPPORTED
TRUE
VAAPI_HWCODECS
240
VAAPI_SUPPORTED
TRUE
VAAPI_HWCODECS
240

$ MOZ_GFX_DEBUG=1 /var/lib/flatpak/app/org.mozilla.firefox/current/active/files/lib/firefox/vaapitest -d /dev/dri/renderD129
vaapitest start, device /dev/dri/renderD129
libva info: VA-API version 1.22.0
libva info: Trying to open /usr/lib64/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_0
libva info: va_openDriver() returns 0
vaInitialize finished
Profile: H264Main
Profile: H264High
Profile: H264ConstrainedBaseline
Profile: VP8Version0_3
Profile: VP9Profile0
Profile: AV1Profile0
Profile: VP9Profile2
vaapitest finished
VAAPI_SUPPORTED
TRUE
VAAPI_HWCODECS
240
VAAPI_SUPPORTED
TRUE
VAAPI_HWCODECS
240

Nvidia vaapi does fail, but I haven't dug in to that as I don't want to use it and it does show as supported in host.

tamasd commented 3 weeks ago

I have Firefox 132.0 and the system is on the sha256:27d65e684ef5e4159e480ec4c531b137579d31707773cba9d13bf75dbbf47495 revision, tracking the latest branch. The issue still exists.

@bsherman what are your flatpak info and overrides? Mine are:

$ flatpak info org.mozilla.firefox

Firefox - Fast, Private & Safe Web Browser

          ID: org.mozilla.firefox
         Ref: app/org.mozilla.firefox/x86_64/stable
        Arch: x86_64
      Branch: stable
     Version: 132.0
     License: MPL-2.0
      Origin: flathub
  Collection: org.flathub.Stable
Installation: system
   Installed: 267,6 MB
     Runtime: org.freedesktop.Platform/x86_64/23.08
         Sdk: org.freedesktop.Sdk/x86_64/23.08

      Commit: eddd807e2511ac9589811461dca1a8e9e119958730fafc21425dae23cac1b5e8
      Parent: 4fea3214184b32a765c4bb2d764b9b2700251f5e9b7863d666b67000829235c3
     Subject: Export org.mozilla.firefox
        Date: 2024-10-29 12:47:03 +0000
$ flatpak override --show org.mozilla.firefox
[Context]
filesystems=xdg-run/app/org.keepassxc.KeePassXC/org.keepassxc.KeePassXC.BrowserServer;
$ flatpak override --show --user org.mozilla.firefox
[Context]
sockets=!fallback-x11;!x11
devices=dri
filesystems=host-os

[Environment]
LIBVA_DRIVER_NAME=iHD
LIBVA_DRIVERS_PATH=/run/host/usr/lib64/dri
LIBVA_MESSAGING_LEVEL=1
MOZ_ENABLE_WAYLAND=1
MOZ_DISABLE_RDD_SANDBOX=1
NVD_BACKEND=direct
bsherman commented 2 weeks ago

@tamasd

$ flatpak info org.mozilla.firefox

Firefox - Fast, Private & Safe Web Browser

          ID: org.mozilla.firefox
         Ref: app/org.mozilla.firefox/x86_64/stable
        Arch: x86_64
      Branch: stable
     Version: 132.0.1
     License: MPL-2.0
      Origin: flathub
  Collection: org.flathub.Stable
Installation: system
   Installed: 267.5 MB
     Runtime: org.freedesktop.Platform/x86_64/23.08
         Sdk: org.freedesktop.Sdk/x86_64/23.08

      Commit: 0e0e422a8c3302703c13198b964ac50dc14ad64cdf756e63ad8d726c31c1df84
      Parent: eddd807e2511ac9589811461dca1a8e9e119958730fafc21425dae23cac1b5e8
     Subject: Export org.mozilla.firefox
        Date: 2024-11-04 19:36:26 +0000

In this possibly related ticket, the solution was to modify the intel driver GUC parameter.

I wonder if that may help for you, depending on your specific hardware.

bsherman commented 2 weeks ago

Also, this PR just merged, https://github.com/ublue-os/bluefin/pull/1876

It will set media.ffmpeg.vaapi.enabled to true in Firefox's about:config (assuming it's not already forced to false).

I have found this is needed on AMD, I don't think it will help on Intel, especially if the problem is GUC related, but it's worth mentioning.

Tomorrow's Bluefin builds will have this.