fix(avplayer): keep handed-out video frames until later frames are handed out #1601
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1601"
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?
Imported from boykopovar/AnyPS5. Originally posted by awake-devel on 2026-10-08T14:06:59Z.
What
A title that asks AvPlayer for 2 output video framebuffers (
num_output_video_framebuffers = 2) got no protection for the frame it was shown last. InSource.cpp,presentkeepsvideoBuffers - 3earlier handed-out frames, which is 0 for 2 or 3 buffers, so the previous frame's buffer goes back to the free list as soon as the next frame is handed out.acquireBufferthen takes the newest free buffer first, so the decoder writes the next decoded picture into exactly that buffer right away. AnyPS5's GPU work runs behind the game thread, and can still be reading that buffer for the frame the game already submitted.In Hollow Knight: Silksong (PPSA12544) this shows in the intro cinematic: whole frames briefly jump back about 0.3 s (sometimes forward), and one frame was torn. Discussion: https://github.com/boykopovar/AnyPS5/discussions/1519
The change:
The unknown console rule is recorded in
docs/dev/TechnicalDebt.md.Open question
The fix keeps a fixed number of frames; it does not know when the GPU has actually read a frame. AvPlayer has no link to the AGC driver today. A rule tied to GPU completion (for example waiting until the GPU work submitted before the next
GetVideoDatahas finished before reusing a buffer) would be exact, but it needs a hook between the two libraries, and how the console itself handles this (how long a frame fromsceAvPlayerGetVideoDatastays valid) is not documented. Reviewers who know the console behaviour, or prefer the GPU-completion approach, are welcome to say so.Tested
Arch Linux, GCC, Release,
-DBUILD_TESTING=ON; Intel i7-8750H, GTX 1050 Ti Max-Q with NVIDIA 580.178.04. Rebased ontomain406b5e1c; the results below are on406b5e1cunless marked as from the earlier basecba8d86d.guest_avplayer: new cases check that with 2 output buffers the 5 newest handed-out frames are not overwritten (and with 6 buffers), and that the 4 extra framebuffers are requested only when the texture memory allows. Passes; with only theSource.cppchange reverted it fails (checked oncba8d86d).ctest -j4: 482/482 passed, 0 skipped, 0 failed, the same set asmain406b5e1c.VK_LAYER_KHRONOS_validation(oncba8d86d): 452/452 passed, 0 skipped; the sameValidation ErrorVUIDs and counts asmain.tools/check_conventions.py --base 406b5e1candtools/check_test_registration.py build: pass.mainbehaviour): 63 such events in about 130 s of cinematic (50 plain jumps, the rest around the cinematic's own flashes);Not changed by this PR: in the same cinematic the sound plays well ahead of the picture (the user estimates up to about a minute by the end). It was already there before this change, and the picture does not look slowed down, more like a growing or fixed offset. It is being investigated separately.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
https://claude.ai/code/session_01HeC9bA3n74TzJRYv9AgBE8
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-11T08:55:28Z.
Hi! This PR currently conflicts with
main, so I rebased it onto the latestmain(d3e84f85, includes #3296). The mechanical conflict incore/libs/tests/GuestAvPlayer.cpp(main addedTestPs5ExtendedInitLayout/TestAutoStartKeepsStartedPlayback/TestUnsyncedVideoKeepsUpWithAudioat the same spot as this PR'sTestHandedOutFramesStayIntact) resolved cleanly by keeping both sides.However, there is now a semantic conflict that needs a decision: main's newer
TestPs5ExtendedInitLayoutwaits forTextureCount() == Buffers + DecodeAheadBuffers(3 + 4 = 7), but with this change's 4 additional held framebuffers the count settles at 11, so that check never passes (the PR's ownTestHandedOutFramesStayIntactstill passes). Either the new test needs updating to expectBuffers + DecodeAheadBuffers + 4held buffers, or the held-buffer approach needs adjusting.The rebased branch is available for reference (it builds; the failure above is the only failing check):
Feel free to ignore this if you'd rather rebase yourself.
Imported from boykopovar/AnyPS5. Originally posted by awake-devel on 2026-10-11T10:47:54Z.
Working on this rn dw
If you can open an issue about the semantic conflict so the maintainer can take a decision about this
Imported from boykopovar/AnyPS5. Originally posted by awake-devel on 2026-10-11T14:10:27Z.
Thanks @blawesom for the rebase and for spotting this. Since no issue exists yet, here is the decision a maintainer needs to make.
The conflict. #1601 keeps the last handed-out video frames intact. Without that, a title that asks for 2 output framebuffers gets the frame it is drawing overwritten by the decoder (Hollow Knight: Silksong, PPSA12544, intro cinematic: frames jump back about 0.3 s, one torn frame).
TestPs5ExtendedInitLayoutfrom #2159 waits forTextureCount() == Buffers + DecodeAheadBuffers(3 + 4 = 7), but #1601 allocates 4 more framebuffers, so the count becomes 11.Where the 7 comes from. 3 is the count the test writes at 0x228. 4 is AnyPS5's own decode-ahead pool from #591, which TechnicalDebt already lists as an assumption ("the console's internal buffering behaviour is unknown"). As far as we can tell, no console documentation sets the total number of textures AvPlayer allocates; the point of the #2159 check is that the field at 0x228 is read.
Two ways to resolve it:
TestPs5ExtendedInitLayoutexpectsBuffers + DecodeAheadBuffers + 4textures.Neither ties a frame's lifetime to the GPU having read it. That would be exact, but it needs a link from AvPlayer to the AGC driver, and how long a frame from
sceAvPlayerGetVideoDatastays valid on the console is unknown.Which one would you prefer? I'll update the PR to match and mark it ready.
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-16T17:08:30Z.
Opened the semantic-conflict issue as requested: #6898 — it lays out both designs (hold within the existing 7-buffer pool vs. the +4 allocation with the
TestPs5ExtendedInitLayoutupdate) for a maintainer decision.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T11:09:31Z.
Review: APPROVED
Reviewed — looks good
Nothing in the reviewed changes shows a blocking defect; the lifetime policy is documented as an approximation and the added tests cover the 2- and 6-buffer cases.
What I ran
Inspected head
91f77a4555c2816218b08fb6f1b622d0d1daa0ccusingrepo_read.py's review bundle and targeted file reads. No commands or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Did not independently run tests or verify the author's hardware, game, or performance observations. Read all changed files listed in the manifest:
core/libs/prx/libSceAvPlayer/src/Source.cpp,core/libs/tests/GuestAvPlayer.cpp, anddocs/dev/TechnicalDebt.md. No changed files were excluded by the manifest.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T17:15:31Z.
Review: COMMENTED
The current lifetime guarantee depends on whether the host allocator can supply both optional video buffer batches. For a title requesting two buffers,
addOptionalVideoBuffersretains four previous frames only when all eight optional allocations succeed. The same guest configuration can therefore get different reuse behavior under memory pressure, and the proposed lifetime comes from a single title experiment. Can the PR pin down the console lifetime rule and add a fixture that checks it with and without optional decode-ahead capacity? That would let the extra buffers remain an allocator choice while the guest-visible lifetime follows the same rule.This finding is from source inspection.
AI-assisted: yes.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.