AvPlayer: threaded video decode, fix flickering video #2259
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!2259
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2259"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@jgoyvaerts on GitHub · 2026-11-13 19:10 UTC · original
jgoyvaerts:port/avplayer→main· +161 −2 · 6 files · 2 commits · openAvPlayer, fixes the flickering Astro Bot intro video:
a6f4e8e7), that copy got a later frame. GuestGpu now numbers its submissions and tracks those not yet completed.Tested:
avplayer_file_tests(a new case with a fake GPU fails without the fix). The same change in a Jetsku-based build fixed the intro: a hash of the copied textures matches the frame the game was given.AI use: the code, tests and this description were written with an LLM (Claude). The tests listed ran on a Linux x86-64 build.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-11-13 19:16 UTC · original
Walkthrough
Guest GPU submissions now receive sequence markers, and callers can wait for work through a marker with cancellation support. The graphics API exposes marker retrieval and waiting. The video player records GPU work associated with returned buffers and waits for completion before reusing them. Video decoder setup now enables automatic frame and slice threading. A test covers holding a video buffer while GPU work remains pending and reusing it after completion.
Suggested reviewers:
nmzikChange: Bug fix
Merge Risk:
Moderate · up to
44380The change fixes video buffer reuse, but waiting on a global GPU marker can stall video delivery behind unrelated compute work. A stop or seek during a pending wait can also free texture memory the GPU may still be reading. Both should be resolved or explicitly accepted before merge.
Pre-merge checks:
4
Full details: Title check
Explanation
The title names the two main changes: threaded video decoding in AvPlayer and a fix for flickering video. The changeset matches both. Frame and slice threading is set in OpenCodec, and GPU-aware buffer reuse addresses the flicker. The title is short and specific, though it bundles two changes.
Full details: Description check
Explanation
The description states the purpose (fixing the flickering Astro Bot intro video). It explains the two changes: per-CPU video decoding threads and delaying buffer reuse until submitted GPU work completes. It also names the tests run and the AI-use disclosure. This matches the changeset files, including GuestGpu submission tracking, agc.cpp/agc.h wait APIs, avPlayer.cpp buffer handling, and the new test in AvPlayerFileTests.cpp.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
@ -981,0 +986,4 @@// The guest's GPU work may still read the frame it gives back (Astro Bot copies each one// with a DMA the command processor runs up to two frames later): the decoder writes the// buffer again only once all work submitted until now has completed.current_video->buffer->gpu_work = Graphics::SubmittedGpuWork();@coderabbitai[bot] on GitHub · 2026-11-13 19:16 UTC · original · edited 2026-11-13 19:28 UTC
Buffer reuse waits for unrelated compute submissions.
SubmittedGpuWork()records the last submission sequence on every queue, including compute.WaitForGpuWorkinReceiveFramesthen waits for all of them before the buffer can be reused. Video delivery stalls until every earlier compute submission completes.If a compute submission waits on a guest signal that is issued only after more video frames are delivered, the stall does not end. The decoder waits on that compute submission, no new frame reaches
Video(), and the guest does not issue the signal. Delivery resumes only after stop or seek. Even without a circular wait, a long-running compute submission delays video delivery for its full duration.Track the readers of each buffer and wait only for submissions that can read it. Do not use a global queue-wide marker for buffer reuse.
@ -1407,1 +1427,4 @@}if ((*buffer)->gpu_work != 0) {if (!Graphics::WaitForGpuWork((*buffer)->gpu_work, worker_stop)) {buffers.Push(std::move(*buffer));@coderabbitai[bot] on GitHub · 2026-11-13 19:16 UTC · original · edited 2026-11-13 19:29 UTC
Do not destroy video buffers that still have pending GPU work.
The GPU wait at line 1429 can be cancelled by
worker_stop. The buffer then returns tovideo_bufferswithgpu_workstill set.ResetNoLock()clears that pool at line 1065. TheWorkQueue::Clear()call destroys eachunique_ptr<GuestBuffer>.GuestBuffer::Reset()then callsdeallocate_textureon the buffer, even though the buffer's own comment says the GPU may still read it.This can release texture memory while a submitted GPU operation still reads it. The repository does not show that the guest-supplied deallocator defers physical reuse. A safe fix needs a retirement path. Buffers with nonzero
gpu_workshould move to a separate list, and their deallocation should wait until that work completes. A localized diff is not established by the inspected code.@coderabbitai[bot] on GitHub · 2026-11-13 19:16 UTC · original · reviewed
Actionable comments posted: 2
2ab80a75-ab22-4512-8db7-a6c23f8000ffReviewing files that changed from the base of the PR and between
58ca8d1d7fand443804ca9f.src/graphics/guest_gpu/graphicsRun.cppsrc/graphics/guest_gpu/graphicsRun.hsrc/libs/agc.cppsrc/libs/agc.hsrc/libs/avPlayer.cpptests/AvPlayerFileTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@ -981,0 +986,4 @@// The guest's GPU work may still read the frame it gives back (Astro Bot copies each one// with a DMA the command processor runs up to two frames later): the decoder writes the// buffer again only once all work submitted until now has completed.current_video->buffer->gpu_work = Graphics::SubmittedGpuWork();@jgoyvaerts on GitHub · 2026-11-13 19:28 UTC · original
The wait is deliberately conservative, since the buffer's readers aren't known (here it is a CP DMA on the graphics queue, but a game could sample the frame from compute). It covers only work admitted before the buffer was given back, and the decoder blocks only when every other buffer is in use. Stalling for good would need a submission admitted before the release to block until the game has received more frames than are decoded ahead. Video delivery never blocks the guest, and we haven't seen that pattern. Tracking actual readers would need the buffer cache to record reads of AvPlayer ranges. That's possible as a follow-up if you prefer it.
@ -1407,1 +1427,4 @@}if ((*buffer)->gpu_work != 0) {if (!Graphics::WaitForGpuWork((*buffer)->gpu_work, worker_stop)) {buffers.Push(std::move(*buffer));@jgoyvaerts on GitHub · 2026-11-13 19:28 UTC · original
This is pre-existing. Before this PR, buffers returned by
Video()sat in the same pool andResetNoLock()freed them the same way, while GPU work could still read them. This PR doesn't change when buffers are freed. A buffer whose wait was cancelled goes back to the pool exactly as before. Deferring those frees until the work completes would need a blocking or deferred free on the guest thread (Stop/Close). I'd keep that as a separate change.@ -981,0 +986,4 @@// The guest's GPU work may still read the frame it gives back (Astro Bot copies each one// with a DMA the command processor runs up to two frames later): the decoder writes the// buffer again only once all work submitted until now has completed.current_video->buffer->gpu_work = Graphics::SubmittedGpuWork();@coderabbitai[bot] on GitHub · 2026-11-13 19:29 UTC · original
@jgoyvaerts Thanks for the explanation. The conservative wait makes sense while buffer readers are unknown, including possible compute readers.
My comment overstated the effect: the decoder waits on the selected buffer, but
Video()can still deliver frames that are ready. A long-running earlier submission can delay future output, and a circular wait remains possible, but I have not established an affected game.I agree that reader tracking can be a follow-up rather than a requirement for this PR. I’m not marking the concern as addressed because the conservative wait remains.
You are interacting with an AI system.
@ -1407,1 +1427,4 @@}if ((*buffer)->gpu_work != 0) {if (!Graphics::WaitForGpuWork((*buffer)->gpu_work, worker_stop)) {buffers.Push(std::move(*buffer));@coderabbitai[bot] on GitHub · 2026-11-13 19:29 UTC · original
Analysis chain
Script executed:
Length of output: 9366
@jgoyvaertsYou’re right. The base already returned video buffers to the pool and cleared that pool without a GPU completion wait. I withdraw this as a regression finding.The potential teardown risk remains, but it can be addressed separately.
Review thread resolved.
You are interacting with an AI system.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.