Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 936310 - media-libs/mesa-24.1.4: broken VAAPI AV1 decoding on AMD due to media-video/ffmpeg bug
Summary: media-libs/mesa-24.1.4: broken VAAPI AV1 decoding on AMD due to media-video/f...
Status: IN_PROGRESS
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Gentoo Media-video project
URL:
Whiteboard:
Keywords: PATCH
Depends on: 936326 936327
Blocks:
  Show dependency tree
 
Reported: 2024-07-19 14:44 UTC by Johannes Penßel
Modified: 2024-07-29 14:37 UTC (History)
9 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
ff-esr-ffmpeg-av1.patch (ff-esr-ffmpeg-av1.patch,6.15 KB, text/plain)
2024-07-22 15:56 UTC, Alexander Tsoy
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Johannes Penßel 2024-07-19 14:44:13 UTC
media-libs/mesa-24.1.4 dropped a workaround for ffmpeg incorrectly decoding AV1 via VAAPI. This effectively breaks VAAPI AV1 hardware decoding on AMD. 
TL;DR: Fixing this either involves patching ffmpeg, firefox and anything else that uses an internal copy of the former, or reverting a commit in mesa.

Upstream bug:
https://gitlab.freedesktop.org/mesa/mesa/-/issues/11533

Commit in question:
https://gitlab.freedesktop.org/mesa/mesa/-/commit/b0d6e58d88f28dd10599c4b967f9ff99f4406829

Upstream suggests that distros should backport the necessary fixes to ffmpeg rather than reapplying the workaround in mesa. These are:

lavc/vaapi_decode: Make it possible to send multiple slice params buffers
https://github.com/FFmpeg/FFmpeg/commit/fe9d889dcd79ea18d4dfaa39df4ddbd4c8c3b15c

lavc/vaapi_av1: Avoid sending the same slice buffer multiple times
https://github.com/FFmpeg/FFmpeg/commit/d2d911eb9a2fc6eb8d86b3ae025a56c1a2692fba

Both patches apply cleanly on top of media-libs/ffmpeg-6.1.1-r7.

This leaves Firefox out of the equation, which needs a patch for its internal copy of ffmpeg. However, this is currently targeted at Milestone 130:
https://phabricator.services.mozilla.com/D216919

This patch applies to firefox-128 as well.
Comment 1 Matt Turner gentoo-dev 2024-07-19 16:59:53 UTC
Looks like the change in Mesa is being reverted on the stable branch (https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30255)

But we should definitely go ahead and backport the ffmpeg patches. Mesa-24.2 isn't far away.
Comment 2 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-07-19 21:32:44 UTC
> Upstream suggests that distros should backport the necessary fixes to ffmpeg rather than reapplying the workaround in mesa

A good thing to write to the distros ML about ;)
Comment 3 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-07-20 03:28:28 UTC
(In reply to Sam James from comment #2)
> > Upstream suggests that distros should backport the necessary fixes to ffmpeg rather than reapplying the workaround in mesa
> 
> A good thing to write to the distros ML about ;)

Done at https://lore.kernel.org/distributions/87bk2syc9r.fsf@gentoo.org/T/#u.
Comment 4 Larry the Git Cow gentoo-dev 2024-07-20 04:09:02 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=00fd18da17d96ebc907f61f5481d406b7c834cef

commit 00fd18da17d96ebc907f61f5481d406b7c834cef
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2024-07-20 04:06:35 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2024-07-20 04:06:35 +0000

    media-video/ffmpeg: fix AMD AV1 vaapi regression w/ newer mesa for 6.1.x
    
    Bug: https://bugs.gentoo.org/936310
    Signed-off-by: Sam James <sam@gentoo.org>

 media-video/ffmpeg/ffmpeg-6.1.1-r8.ebuild          | 623 +++++++++++++++++++++
 .../ffmpeg/files/ffmpeg-6.1.1-amd-av1-vaapi.patch  | 254 +++++++++
 2 files changed, 877 insertions(+)

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=50569482e7b98f08980f26be076b72b9ce5b2469

commit 50569482e7b98f08980f26be076b72b9ce5b2469
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2024-07-20 03:56:09 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2024-07-20 03:56:57 +0000

    media-video/ffmpeg: fix AMD AV1 vaapi regression w/ newer mesa for 4.4.x
    
    For 4.4.x, use rebased versions from Solus.
    
    Bug: https://bugs.gentoo.org/936310
    Signed-off-by: Sam James <sam@gentoo.org>

 media-video/ffmpeg/ffmpeg-4.4.4-r10.ebuild         | 622 +++++++++++++++++++++
 .../ffmpeg/files/ffmpeg-4.4.4-amd-av1-vaapi.patch  | 257 +++++++++
 2 files changed, 879 insertions(+)
Comment 5 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-07-20 04:09:10 UTC
Leonardo, I've not touched 7.0.1 as I wasn't 100% sure if it was needed there (it applied with fuzz) and I already spent too much time on yak shaving so far today.
Comment 6 Larry the Git Cow gentoo-dev 2024-07-20 06:49:21 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e5ab16d8c800ada9960d78e57eaa7df8fcef179f

commit e5ab16d8c800ada9960d78e57eaa7df8fcef179f
Author:     Joonas Niilola <juippis@gentoo.org>
AuthorDate: 2024-07-20 06:48:33 +0000
Commit:     Joonas Niilola <juippis@gentoo.org>
CommitDate: 2024-07-20 06:48:38 +0000

    www-client/firefox: add upstream patch to 128.0 about mesa/vaapi issue
    
    Bug: https://bugs.gentoo.org/936310
    Signed-off-by: Joonas Niilola <juippis@gentoo.org>

 www-client/firefox/Manifest             | 2 +-
 www-client/firefox/firefox-128.0.ebuild | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Comment 7 Alexander Tsoy 2024-07-21 10:24:53 UTC
(In reply to Larry the Git Cow from comment #6)
I successfully backported this patch to 115 ESR and it works flawlessly so far. Are there any plans to do this in gentoo or we have to rely on reverted commit in the mesa stable branch for now? It looks like 128 ESR and mesa 24.2 without revert will reach the tree at about the same time.
Comment 8 tt_1 2024-07-21 15:08:10 UTC
the easiest fix for esr will be if someone with higher mozilla bugzilla rights could ask to officially backport the fix to 129, 128 and 115 branch.
Comment 9 Joonas Niilola gentoo-dev 2024-07-22 14:13:14 UTC
(In reply to Alexander Tsoy from comment #7)
> (In reply to Larry the Git Cow from comment #6)
> I successfully backported this patch to 115 ESR and it works flawlessly so
> far. Are there any plans to do this in gentoo or we have to rely on reverted
> commit in the mesa stable branch for now? It looks like 128 ESR and mesa
> 24.2 without revert will reach the tree at about the same time.

Can you post the patch here? I tried https://hg.mozilla.org/mozilla-central/rev/a782319319be on esr but it wouldn't apply. 

128.1.0esr is out in a couple of weeks which holds the fix, but if there's a patch that works with 115esr it can be added for sure.
Comment 10 Alexander Tsoy 2024-07-22 15:56:22 UTC
Created attachment 898118 [details]
ff-esr-ffmpeg-av1.patch
Comment 11 Joonas Niilola gentoo-dev 2024-07-23 05:49:29 UTC
(In reply to Alexander Tsoy from comment #10)
> Created attachment 898118 [details]
> ff-esr-ffmpeg-av1.patch

Awesome, it worked, thanks!
Comment 12 Larry the Git Cow gentoo-dev 2024-07-23 05:51:09 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c92ca5c45cd2e7998027f697995eab5c04e2f435

commit c92ca5c45cd2e7998027f697995eab5c04e2f435
Author:     Joonas Niilola <juippis@gentoo.org>
AuthorDate: 2024-07-23 05:50:04 +0000
Commit:     Joonas Niilola <juippis@gentoo.org>
CommitDate: 2024-07-23 05:51:05 +0000

    www-client/firefox: add ffmpeg-vaapi patch fix to 115esr
    
    Bug: https://bugs.gentoo.org/936310
    Signed-off-by: Joonas Niilola <juippis@gentoo.org>

 www-client/firefox/Manifest                | 2 +-
 www-client/firefox/firefox-115.13.0.ebuild | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)