Skip to content

hwdec_aimagereader: release images with a fence - #18907

Open
moi15moi wants to merge 1 commit into
mpv-player:masterfrom
moi15moi:fix-aimagereader-release-fence
Open

moi15moi wants to merge 1 commit into
mpv-player:masterfrom
moi15moi:fix-aimagereader-release-fence

Conversation

@moi15moi

Copy link
Copy Markdown
Contributor

AImage_delete() returns the buffer to the decoder right away, without a release fence. Unmapping right after submitting the draws that read from the image is fine as far as GL is concerned, but the decoder can then write the next frame into the buffer while the GPU is still reading from it, which shows up as tearing (parts of two different frames in one rendered frame).

Record a fence in end_access() after each use of the image. On release, pass it to the decoder through AImage_deleteAsync() if EGL_ANDROID_native_fence_sync is available, so it waits for the GPU on its own. Otherwise, wait for the fence before calling AImage_delete(). This solves the same kind of problem as the semaphores in hwdec_vulkan.

Fix mpv-android/mpv-android#1289

Note that this PR was assisted with a LLM (Claude Opus 5.5).

AImage_delete() returns the buffer to the decoder right away, without a release fence.
Unmapping right after submitting the draws that read from the image is fine
as far as GL is concerned, but the decoder can then write the next frame
into the buffer while the GPU is still reading from it,
which shows up as tearing (parts of two different frames in one rendered frame).

Record a fence in end_access() after each use of the image.
On release, pass it to the decoder through AImage_deleteAsync() if
EGL_ANDROID_native_fence_sync is available, so it waits for the GPU on its own.
Otherwise, wait for the fence before calling AImage_delete().
This solves the same kind of problem as the semaphores in hwdec_vulkan.

Fix mpv-android/mpv-android#1289

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@moi15moi
moi15moi force-pushed the fix-aimagereader-release-fence branch from cc26704 to 984e99c Compare November 26, 2026 02:30
@moi15moi

Copy link
Copy Markdown
Contributor Author

You can ignore the force-pushed.
I just forgot to rebase my branch on master (the latest commit).

@kasper93
kasper93 requested review from sfan5 and a balanced review from Copilot and removed request for Copilot November 26, 2026 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Screen tearing

1 participant