Friday, June 10, 2022

Stadia Hardware VP9 under Fedora Linux

RIP Stadia. I'll miss you.

After long nights of beating my head against a wall I finally figured out the special recipie for hardware decoding the VP9 codec in Google Stadia. Contrary to what I've read in a whole slew of forum posts from the past 2 years, hardware decoding is possible in Linux with the standard Google Chrome browser. I didn't need to use any special builds of Chromium or Microsoft's Edge browser. I am using the very same RPM you can download off Google's website.

Goggle Stadia

I am running Fedora 36 Workstation Linux. I'm not sure how much of this article will apply to other distributions but at least the general idea should hold up. I'm running with an AMD 6900XT RDNA2 card in my system, I've not installed any extra driver or libva packages beyond what's installed during the OS install. So everything should be pretty standard for other AMD or Intel cards. nVidia cards will need their proprietary drivers installed. Normally I use the nVidia packages from RPM Fusion but you can install them however you please. I also run a X.ORG session as I couldn't get hardware decoding to work in Wayland.

First off you'll want to make sure your card supports libva decoding. I'd think pretty much any modern video card will, but to check use the terminal command vainfo. Below is the output for my system.

[jeremy@fedora ~]$ vainfo
libva info: VA-API version 1.14.0
libva info: Trying to open /usr/lib64/dri/
libva info: Found init function __vaDriverInit_1_14
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.14 (libva 2.14.0)
vainfo: Driver version: Mesa Gallium driver 22.0.3 for AMD Radeon RX 6900 XT (sienna_cichlid, LLVM 14.0.0, DRM 3.44, 5.17.12-300.fc36.x86_64)
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

It looks like my card is supported so I'm gonna move on to convinecing Chrome to use this hardware decode acceleration. Several forum posts from the past couple of years claim I need to set flags under chrome://flags to enable hardware VP9 decoding but this is untrue. I've done everything via the command line. I didn't want to make anything set in stone so the command line is fine with me. 

Here is the terminal command I used to start Chrome with.

google-chrome --ignore-gpu-blocklist --enable-gpu-rasterization --enable-zero-copy --enable-features=VaapiVideoDecoder --disable-features=UseChromeOSDirectVideoDecoder --use-gl=egl

After starting Chrome with the above options you can navigate to chrome://gpu and check out what your card is capable of. Mine looks like the below.

The biggie here is Video Decode: Hardware accelerated. If you see it's enable then Stadia should be good to go.

Before you run off to I recommend installing one google extension to help enable the VP9 codec and set your monitor's resolution. I'm talking about Stadia Enhanced. You can find it by clicking here or searching for it on the Chrome Web Store. Once you have it added to Chrome we can go to

If you're familiar with the Stadia website you'll notice a couple of changes caused by Stadia Enhanced. Namely the cheeseburger menu button next to the search box. We'll be using this menu to set up the few changes we need to make to Stadia. Just follow along and you'll be set in no time.

See the cheeseburger menu button? It's right by the search box. Click it!

After you click the cheeseburger a memu will drop down. You'll want to click on the Stream tab to the side. Here you will set the Codec to VP9, set the resolution to whatever your monitor will do (keep in mind anything over 1080p requires Stadia Pro) and enable the Stream Monitor for now to verify Chrome is decoding in hardware.

Normally after setting option in Stadia I refresh the page to make sure they took properly. After Stadia refreshes pick a game and start it. If everything goes as it should you will have confirmation in the Stream Monitor nestled in the upper left hand corner. It should look something like this.

Now you have verified everything is working. You can back out of your game and disable the Stream Monitor if you like. From here you can make a desktop item for stadia with the needed options or you can start it from a terminal each time. The choice is yours about how to use this newly learned information.