Nvidia GPU video acceleration with Firefox

So Firefox 102 just landed in nixpkgs, which contains the fix for VA-API with the RDD sandbox, and there is support for VA-API using the nvidia drivers by default with NixOS now - I’d really like to start rendering videos with my GPU, so I figured I’d give it a try.

From previous experimentation, I know about Firefox does not take advantage of hardware acceleration even when aviable · Issue #157061 · NixOS/nixpkgs · GitHub (which AIUI is fixed, and only basic config should be necessary at this point), I’ve set media.ffmpeg.vaapi.enabled in my Firefox settings, and I’ve set LIBVA_DRIVER_NAME=nvidia. I even have modesetting enabled:

tlater ~ $ lsmod | grep modeset
nvidia_modeset       1146880  7 nvidia_drm
nvidia              40828928  368 nvidia_uvm,nvidia_modeset
backlight              24576  2 drm,nvidia_modeset

vainfo seems to confirm my configuration is correct:

tlater ~ $ NVD_LOG=1 nix shell nixpkgs#libva-utils -c vainfo
libva info: VA-API version 1.14.0
libva info: User environment variable requested driver 'nvidia'
libva info: Trying to open /run/opengl-driver/lib/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_0
[12633-12633] ../src/vabackend.c:1634       __vaDriverInit_1_0 Initialising NVIDIA VA-API Driver: 0x1a5a400
[12633-12633] ../src/export-buf.c: 171          findCudaDisplay Found 3 EGL devices
[12633-12633] ../src/export-buf.c: 175          findCudaDisplay Got EGL_CUDA_DEVICE_NV value '0' from device 0
[12633-12633] ../src/export-buf.c: 135    checkModesetParameter Checking device file: /dev/dri/renderD128
[12633-12633] ../src/export-buf.c: 210             initExporter Got EGLDisplay from CUDA device
[12633-12633] ../src/export-buf.c: 240             initExporter Driver doesn't support 16-bit surfaces
[12633-12633] ../src/export-buf.c:  95                reconnect Reconnecting to stream
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.14 (libva 2.14.0)
vainfo: Driver version: VA-API NVDEC driver
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      <unknown profile>               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileHEVCMain               : VAEntrypointVLD
      VAProfileVP8Version0_3          : VAEntrypointVLD
      VAProfileVP9Profile0            : VAEntrypointVLD
[12633-12633] ../src/vabackend.c:1618              nvTerminate Terminating 0x1a5a400
[12633-12633] ../src/export-buf.c:  57          releaseExporter Releasing exporter, 0 outstanding frames
[12633-12633] ../src/export-buf.c:  74          releaseExporter Done releasing frames

Firefox also seems to confirm it’s working:

tlater ~ $ firefox
libva info: VA-API version 1.14.0
libva info: User environment variable requested driver 'nvidia'
libva info: Trying to open /run/opengl-driver/lib/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_0
libva info: va_openDriver() returns 0

However, when I try a video I get spammed with errors:

libva info: VA-API version 1.14.0
libva info: User environment variable requested driver 'nvidia'
libva info: Trying to open /run/opengl-driver/lib/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_0
libva error: /run/opengl-driver/lib/dri/nvidia_drv_video.so init failed
libva info: va_openDriver() returns 1
libva info: VA-API version 1.14.0
libva info: User environment variable requested driver 'nvidia'
libva info: Trying to open /run/opengl-driver/lib/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_0
libva error: /run/opengl-driver/lib/dri/nvidia_drv_video.so init failed
libva info: va_openDriver() returns 1
libva info: VA-API version 1.14.0
libva info: User environment variable requested driver 'nvidia'
libva info: Trying to open /run/opengl-driver/lib/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_0
libva error: /run/opengl-driver/lib/dri/nvidia_drv_video.so init failed
libva info: va_openDriver() returns 1
libva info: VA-API version 1.14.0
libva info: User environment variable requested driver 'nvidia'
libva info: Trying to open /run/opengl-driver/lib/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_0
libva error: /run/opengl-driver/lib/dri/nvidia_drv_video.so init failed
libva info: va_openDriver() returns 1
libva info: VA-API version 1.14.0
libva info: User environment variable requested driver 'nvidia'
libva info: Trying to open /run/opengl-driver/lib/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_0
libva error: /run/opengl-driver/lib/dri/nvidia_drv_video.so init failed
libva info: va_openDriver() returns 1
libva info: VA-API version 1.14.0
libva info: User environment variable requested driver 'nvidia'
libva info: Trying to open /run/opengl-driver/lib/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_0
libva error: /run/opengl-driver/lib/dri/nvidia_drv_video.so init failed
libva info: va_openDriver() returns 1
libva info: VA-API version 1.14.0
libva info: User environment variable requested driver 'nvidia'
libva info: Trying to open /run/opengl-driver/lib/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_0
libva error: /run/opengl-driver/lib/dri/nvidia_drv_video.so init failed
libva info: va_openDriver() returns 1

Is there anything I’m doing wrong? Is this working for anyone else?

Get more info with MOZ_LOG="PlatformDecoderModule:5" and/or MOZ_SANDBOX_LOGGING=1.

Does it work in other applications like mpv?

Increasing the log verbosity for the decoder is very verbose, but ultimately doesn’t give much information. This is the section where it tries to initialize va-api:

<snip>
[Child 5673: MediaPDecoder #1]: D/PlatformDecoderModule Sandbox RDD decoder supports requested type
[Child 5673: MediaPDecoder #1]: D/PlatformDecoderModule Sandbox RDD decoder supports requested type
[RDD 5723: MediaSupervisor #1]: D/PlatformDecoderModule FFmpeg decoder supports requested type 'video/vp9'
[RDD 5723: MediaSupervisor #1]: D/PlatformDecoderModule FFmpeg decoder supports requested type 'video/vp9'
[RDD 5723: MediaSupervisor #1]: D/PlatformDecoderModule FFVPX: FFmpegVideoDecoder::FFmpegVideoDecoder MIME video/vp9 Codec ID 167
[RDD 5723: MediaPDecoder #1]: D/PlatformDecoderModule FFVPX: Initialising VA-API FFmpeg decoder
[RDD 5723: MediaPDecoder #1]: D/PlatformDecoderModule FFVPX:   codec vp9 : Google VP9
libva info: VA-API version 1.14.0
libva info: User environment variable requested driver 'nvidia'
libva info: Trying to open /run/opengl-driver/lib/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_0
libva error: /run/opengl-driver/lib/dri/nvidia_drv_video.so init failed
libva info: va_openDriver() returns 1
[RDD 5723: MediaPDecoder #1]: D/PlatformDecoderModule FFVPX:   vaInitialize failed.
[RDD 5723: MediaPDecoder #1]: D/PlatformDecoderModule FFVPX:   Failed to create VA-API device context
[RDD 5723: MediaPDecoder #1]: D/PlatformDecoderModule FFVPX: Initialising FFmpeg decoder
[RDD 5723: MediaPDecoder #1]: D/PlatformDecoderModule FFVPX:   codec vp9 : Google VP9
<snip>

The rest is just the ffmpeg decoder writing some logs.

The sandbox log gives me:

<snip lots of unrelated file accesses>
Sandbox: Failed errno -2 op open flags 00 path /nix/store/pd14x38108qqasl0n62v1jn5mqwwhhki-libva-2
.14.0/etc/libva.conf
Sandbox: Failed errno -2 op open flags 00 path /nix/store/pd14x38108qqasl0n62v1jn5mqwwhhki-libva-2
.14.0/etc/libva.conf
Sandbox: Failed errno -2 op open flags 00 path /nix/store/pd14x38108qqasl0n62v1jn5mqwwhhki-libva-2
.14.0/etc/libva.conf
Sandbox: Failed errno -2 op open flags 00 path /nix/store/pd14x38108qqasl0n62v1jn5mqwwhhki-libva-2
.14.0/etc/libva.conf
Sandbox: Failed errno -2 op open flags 00 path /nix/store/pd14x38108qqasl0n62v1jn5mqwwhhki-libva-2
.14.0/etc/libva.conf
Sandbox: Failed errno -2 op open flags 00 path /nix/store/pd14x38108qqasl0n62v1jn5mqwwhhki-libva-2
.14.0/etc/libva.conf
Sandbox: Failed errno -2 op open flags 00 path /nix/store/pd14x38108qqasl0n62v1jn5mqwwhhki-libva-2
.14.0/etc/libva.conf
Sandbox: Failed errno -2 op open flags 00 path /nix/store/pd14x38108qqasl0n62v1jn5mqwwhhki-libva-2
.14.0/etc/libva.conf
libva info: VA-API version 1.14.0
libva info: User environment variable requested driver 'nvidia'
libva info: Trying to open /run/opengl-driver/lib/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_0
libva error: /run/opengl-driver/lib/dri/nvidia_drv_video.so init failed
libva info: va_openDriver() returns 1
<snip many repetitions of this and other sandbox stuff>

mpv seems to be attempting to use va-api as well, but it’s not rendering anything. Unsure whether that’s an issue with the video or the rendering, just used freetube to download the video I used for testing Firefox…

<snip GPU details, other startup info>
[vd] Trying hardware decoding via h264-vaapi.
[vd] Selected codec: h264 (H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)
[vf] User filter list:
[vf]   (empty)
[ad] Codec list:
[ad]     aac - AAC (Advanced Audio Coding)
[ad]     aac_fixed (aac) - AAC (Advanced Audio Coding)
[ad] Opening decoder aac
[ad] Requesting 1 threads for decoding.
[ad] Selected codec: aac (AAC (Advanced Audio Coding))
[af] User filter list:
[af]   (empty)
[cplayer] Starting playback...
[af] [in] 44100Hz stereo 2ch floatp
[af] [userspeed] 44100Hz stereo 2ch floatp
[af] [userspeed] (disabled)
[af] [convert] 44100Hz stereo 2ch floatp
[vd] Pixel formats supported by decoder: vdpau cuda vaapi_vld yuv420p
[vd] Codec profile: Main (0x4d)
[vd] Requesting pixfmt 'vaapi_vld' from decoder.
[vd] Using hardware decoding (vaapi).
[vd] Decoder format: 1280x720 vaapi[nv12] bt.709/bt.709/bt.1886/limited/auto CL=mpeg2/4/h264
[vf] [in] 1280x720 vaapi[nv12] bt.709/bt.709/bt.1886/limited/display SP=1.000000 CL=mpeg2/4/h264
[vf] [userdeint] 1280x720 vaapi[nv12] bt.709/bt.709/bt.1886/limited/display SP=1.000000 CL=mpeg2/4/h264
[vf] [userdeint] (disabled)
[vf] [autorotate] 1280x720 vaapi[nv12] bt.709/bt.709/bt.1886/limited/display SP=1.000000 CL=mpeg2/4/h264
[vf] [autorotate] (disabled)
[vf] [convert] 1280x720 vaapi[nv12] bt.709/bt.709/bt.1886/limited/display SP=1.000000 CL=mpeg2/4/h264
[vf] [convert] (disabled)
[vf] [out] 1280x720 vaapi[nv12] bt.709/bt.709/bt.1886/limited/display SP=1.000000 CL=mpeg2/4/h264
[ao] Trying audio driver 'pulse'
[ao/pulse] requested format: 44100 Hz, stereo channels, floatp
[ao/pulse] Library version: 15.0.0
[ao/pulse] Proto: 35
[ao/pulse] Server proto: 4294967295
[ao/pulse] Channel layouts:
[ao/pulse]  - #fl
[ao/pulse]  - #fr
[ao/pulse]  - #fc
[ao/pulse]  - #lfe
[ao/pulse]  - #bl
[ao/pulse]  - #br
[ao/pulse]  - #flc
[ao/pulse]  - #frc
[ao/pulse]  - #bc
[ao/pulse]  - #sl
[ao/pulse]  - #sr
[ao/pulse]  - #tc
[ao/pulse]  - #tfl
[ao/pulse]  - #tfc
[ao/pulse]  - #tfr
[ao/pulse]  - #tbl
[ao/pulse]  - #tbc
[ao/pulse]  - #tbr
[ao/pulse] result: stereo
[ao/pulse] device buffer: 4410 samples.
[ao/pulse] using soft-buffer of 8820 samples.
[cplayer] AO: [pulse] 44100Hz stereo 2ch float
[cplayer] AO: Description: PulseAudio audio output
[autoconvert] inserting resampler
[swresample] format change, reinitializing resampler
[swresample] 44100Hz stereo floatp -> 44100Hz stereo float
[af] [out] 44100Hz stereo 2ch float
[cplayer] VO: [gpu] 1280x720 vaapi[nv12]
[cplayer] VO: Description: Shader-based GPU Renderer
[vo/gpu] reconfig to 1280x720 vaapi[nv12] bt.709/bt.709/bt.1886/limited/display SP=1.000000 CL=mpeg2/4/h264
[vo/gpu] Resize: 890x539
[vo/gpu] Window size: 890x539 (Borders: l=0 t=0 r=0 b=0)
[vo/gpu] Video source: 1280x720 (1:1)
[vo/gpu] Video display: (0, 0) 1280x720 -> (0, 19) 890x500
[vo/gpu] Video scale: 0.695312/0.694444
[vo/gpu] OSD borders: l=0 t=19 r=0 b=20
[vo/gpu] Video borders: l=0 t=19 r=0 b=20
[vo/gpu] Reported display depth: 8
[vo/gpu/opengl] before video texture creation: OpenGL error INVALID_OPERATION.
[vo/gpu] Testing FBO format rgba16f
[vo/gpu] Using FBO format rgba16f.
[vo/gpu] No advanced processing required. Enabling dumb mode.
[vo/gpu/opengl] after rendering: OpenGL error INVALID_OPERATION.
[cplayer] first video frame after restart shown
[cplayer] audio ready
[cplayer] starting audio playback
[cplayer] playback restart complete @ 0.000000, audio=playing, video=playing
[ao/pulse] starting AO
[cplayer] Set property: shared-script-properties -> 1
[cplayer] Set property: shared-script-properties -> 1
[vo/gpu/x11] Disabling screensaver.
[vo/gpu/opengl] after rendering: OpenGL error INVALID_OPERATION.
[vo/gpu/opengl] after rendering: OpenGL error INVALID_OPERATION.
[vo/gpu/opengl] after rendering: OpenGL error INVALID_OPERATION.
[vo/gpu/opengl] after rendering: OpenGL error INVALID_OPERATION.
<snip>

The final few lines seem suspicious.

Any ideas? Looks to me like the whole va-api driver thing is just nonfunctional, which is weird - I’ve had it working before, but wanted to wait until Firefox 102 to actually use it. Also sadly none of these logs help figuring out what to do about it.

Is this a case of “see if upstream knows more”? :slight_smile:

Yeah definitely. Nobody wants to support Nvidia officially because they A. don’t provide VA-API themselves (it’s a third party who tries to make VA-API work on top of Nvidia’s stuff) and B. wouldn’t know how to debug them properly because they’d be closed source.

Such is the life on an Nvidia user on Linux. Proprietary software will always be a second class citizen.

2 Likes

Yep, well aware, sadly, and yet I keep making this mistake. Hopefully the other vendors make GPUs that fit into a reasonably sized box by the next time I buy one, though the way that trend is going I’ll need a whole house with an integrated nuclear power plant regardless of which vendor I buy from.

Thanks for the sanity check, either way. Let’s see if upstream can help debug, they seem fairly responsive.

1 Like

FYI, this is “fixed” as of nvidia 545.29.02: Nvidia GPU Firefox Wayland [GFX1-]: No GPUs detected via PCI [GFX1-]: glxtest: process failed (received signal 11) · Issue #202454 · NixOS/nixpkgs · GitHub

It came down to a bug in a library vendored with their driver (which we package downstream but don’t substitute by default).

Sadly that driver broke the rest of my wayland env, but if you’re on sway (not any other wlroots compositor), gnome or kde it probably works now, provided you’ve configured all the other things correctly.

Thanks for the update!

Could you please share what the “other things” entails?

You need at least modesetting and a bunch of these variables: https://github.com/TLATER/dotfiles/blob/e633196dca42d96f42f9aa9016fa8d307959232f/nixos-config/yui/nvidia.nix#L33

In addition to some firefox settings: https://github.com/TLATER/dotfiles/blob/e633196dca42d96f42f9aa9016fa8d307959232f/home-config/config/graphical-applications/firefox.nix#L68

It changes all the time, too, best to look upstream, but note that some details have historically not made it into the readme, so you’ll need to dig through the issues (sometimes including closed ones): GitHub - elFarto/nvidia-vaapi-driver: A VA-API implemention using NVIDIA's NVDEC

The real fix remains to join team red.

1 Like