Compiling Mesa 22.2 with codec support (the easy way)

EDIT: Looks like the Arch maintainers have included the necessary build flags so this wont be necessary, but this is still useful as a basic guide to easily building mesa with additional flags

This year Mesa made some changes to 22.2 that effectively removes hardware encode/decode support from AMD and Intel GPUs/ Mesa in the default configuration.

This means there is a high chance that unless Arch devs decide to not care and add the flags for the codecs back or you decide to use AMDGPU-Pro going forward you may not have support for H264/H265(HEVC)/VC1 hardware encoding/decoding on a GPU using Mesa/VAAPI.

The problem with this comes down to apparently nobody knowing who tf is supposed to pay the license fee/ if its paid for most GPUs in regards to Mesa. In theory your AMD/Intel/Nvidia GPU should already be paid for license wise but this may not trickle down to the OSS drivers and overall its just a fat mess of stupid thanks to MPEG-LA being giant pieces of shit.

So, what to do then? how can you actually use all your GPU and its features? Well since licenses dont apply to the code itself they can have support in the code and you compile it yourself.


Currently the Arch Repo isnt on 22.2 so this isnt needed yet, if you folow these directions as of 08/18/2022 you will not get mesa 22.2

  1. First, you need to get the package build from Arch repos here https://github.com/archlinux/svntogit-packages/tree/packages/mesa you can click Code and download zip OR using git clone in a directory you made for building it. I believe EOS includes git on default so you should be able to just run this

builddir is just a generic name for what ever you name the directory youll be building in, i wouldnt call it builddir personally but you do you.

I.E

mkdir builddir
cd builddir
git clone --single-branch --branch packages/mesa https://github.com/archlinux/svntogit-packages.git

  1. Now you need to navigate to the pkgbuild for this, we will use terminal but you can use your file manager of choice and open a terminal there. assuming you followed the initial steps you should already be in your builddir

cd svntogit-packages/trunk

  1. Now you need to edit the pkgbuild, Ill be using nano in this example but use w/e editor youre comfortable with and know how to use. This wont include how to use nano though

nano PKGBUILD

navigate to the section of the pkgbuild just above

 # Print config
  meson configure build

youll see build flags like -D valgrind=enabled

add this just after valgrind
-D video-codecs=h264dec,h264enc,h265dec,h265enc,vc1dec

it should now look like

    -D shared-glapi=enabled \
    -D microsoft-clc=disabled \
    -D valgrind=enabled \
    -D video-codecs=h264dec,h264enc,h265dec,h265enc,vc1dec
  1. after editing the pkgbuild you may now run

makepkg -si

from inside the same directory as the pkgbuild, this will pull in needed depends and build/install the package.


This all may not even end up being needed based on how things go, but luckily Arch PKGBUILDs make fixing the issue incredibly easy. If not being needed, great! otherwise its going to require you as the user to do the work yourself. Since this will likely also propagate to Flatpaks also I look into how best handle that situation and add a guide here for that also.

6 Likes

added a note that as of this day (08/18/2022) this doesnt build Mesa 22.2

This will change when arch repo moves to 22.2 and this guide is for when that happens/if this is an issue.

I am quite sure Arch maintainers will include support for whatever necessary and take care of us, just like how they did with glibc 2.36 EAC conflict and Linux 5.18 & Nvidia driver conflict.

glibc didnt come with the risk on the MPEG-LA going after them legally, afaik Debian doesnt give af and includes the codec flags for mesa but i cant say for 100% sure Arch will do the same as there is an open bugreport on it currently and i dont know the discussion being had about it.

Best case is Mesa disappears from Repos in regions the patent is valid and they do it anyway hosting in other countries for that package, worst we build it ourselves. They may also not care all together and just continue as usual adding the flags in, idk.

Well, VLC, ffmpeg etc. are in official repos and Debian which is more strict has included the flags, so why wouldn’t Arch?

this is just an in case, i dont have the answer and i honeslty cant answer this question. Id prefer to keep that discussion elsewhere though so as to keep the guide thread clean for support requests if needed.

VLC, ffmpeg, and others i know have been hosted outside the patent regions to get around the issue, but i cant 100% say what will happening going forward. Flatpak will likely not include them and neither will several other distros so when i do the flatpak part this will still be useful.

  • Support for building Mesa with select video codecs disabled out of software patent concerns.

Do I understand correctly, that it’s not possible to build Mesa with codecs at all from now on?

I suppose we will need to follow the tutorial in the 1st post here, to include the codecs…

No, OP is instructions on how to do it. Its still there just not on by default

1 Like

Speaking of that, you included h264, h265, vc1, and not vp9 or av1?

Av1 AFAIK has no issues and neither should vp9. They aren’t held back by patents so are enabled by default

2 Likes

@I0F @anon49550872

keep in mind that the Arch maintainers may handle this for you. This thread will be updated based on how its handled by the maintainers and if it is needed or not.

3 Likes

@I0F @anon49550872 @mrvictory

Checking the testing mesa release it looks like thing will be good to go for codecs in 22.2

5 Likes

Thanks for keeping us up to date on this.

the package itself has some major issues though

The first time since 2016 (my switch to free drivers) that I had to revert a mesa update xD

Fedora disabled it as is expected

The people in the comments seem to think flatpak will be fine but flatpak folks seem likely to follow a similar path to Fedora looking at their mesa-git and related issues.

If Flatpak drops it I’ll figure a way for building mesa Flatpak on Arch in an easy way

4 Likes

AUR mesa-git is compiling with all the codecs automatically.
I suppose that this could also be an option ?

$ mpv The\ Simpsons\ Movie\ -\ Trailer.mp4 
 (+) Video --vid=1 (*) (h264 1280x544 23.976fps)
 (+) Audio --aid=1 (*) (aac 2ch 48000Hz)
[vo/gpu/wayland] GNOME's wayland compositor lacks support for the idle inhibit protocol. This means the screen can blank during playback.
Cannot load libcuda.so.1
Using hardware decoding (vaapi).
AO: [pulse] 48000Hz stereo 2ch float
VO: [gpu] 1280x544 vaapi[nv12]
AV: 00:00:03 / 00:02:17 (3%) A-V: -0.017 DS: 6.314/23

Im avoiding AUR simply to allow for a better level of trust in the package build. If it comes directly from the Arch maintainers/repo or another trusted sourceyou can be confident its what you would get from a normal install and then providing instructions to make the needed changes.

1 Like

Arch includes the codecs, so why use the AUR?

@Echoa is talking about Fedora, and the AUR is not available there.