Fix/agc hold flip behind worker #1745
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1745"
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 AymanFE on 2026-10-08T18:20:58Z.
<html>
What
A title that paces itself on pending flips can get further ahead of the queue 0 worker than its per-frame memory allows, and the worker then records a frame from memory the title has already rewritten.
Astro Bot (PPSA21564) keeps per-frame data in a ring of three slots, polls
sceVideoOutIsFlipPending, and submits the next flip as soon as fewer than three are pending. On hardware a pending flip is a frame whose commands have been read. Here submissions waited 98 to 110 ms in queue 0, so the worker was still recording frame N while the title wrote frame N+3 into the same slot. A block of per-frame constants that holds the title's frame counter read0x17ein the frame right after one that read0x17a: the worker recorded frame0x17bfrom the slot of frame0x17e. When the slot was half rewritten the draw bound the wrong block, and the frame came out black, without the movie quad, or with the quad at half size: 8 to 16 of 48 window captures in each of five runs.APS5_FLIP_READ_CHECK=1counted 141,478 of 158,640 in-place reads as overwritten before execution. The same overrun producedguest snapshot differs from registered memoryin compute shader0x5005e7b00.A submission on queue 0 that carries a flip now waits until the worker has reached the flip of every earlier one. The wait ends early when queue 0 is blocked on memory that no running, held or pending work writes, the criterion
orderReleaseduses, since only the title can end that wait. The presenter stays asynchronous: the title still has three flips pending when the display is the limit.APS5_NO_FLIP_HOLD=1submits as before.tests/Flip.cppgains a case: a flip behind a closed rendering wait holds the next flip submission until the wait opens, and a flip behind aWAIT_REG_MEMon a label only the test stores does not hold it.Not established: what the console returns from
sceVideoOutIsFlipPendingwhile its GPU is behind. The change does not depend on it.Tested
b3fcd6d6(an oldermain) with this change. 45 s runs through the intro, 48 window captures each in bursts 70 ms apart:With the change the snapshot check passes through the whole intro without
APS5_NO_SNAPSHOT_CHECK. The title still needs a local workaround for an unrelated failure in the same shader at the first frame (guest memory is not readable at 0x30) andAPS5_HOST_IMPORT_MIB=16384.4ddbf049(this branch's base):agc_driver_flip,agc_driver_pm4andagc_driver_pm4_failurepass;agc_driveris skipped there because the machine has no Vulkan device. The new case fails withAPS5_NO_FLIP_HOLD=1and passes without it.tools/check_conventions.py --base origin/mainpasses. The rest of the test suite was not built or run.4ddbf049itself (the Windows runs used the older base; rebasing needed two textual conflict resolutions next to the new timing fields), any title on Linux, any title other than Astro Bot.Checklist
- Based on current
- One topic per PR; follow-ups go in a new PR
- No comments in code except technical debt
- Unimplemented paths throw (
- No notes, investigation
- New third-party code is a submodule built from source (none added)
- Generic behaviour, not specific to one title
- Depends on: none
- AI-assisted: yes. The investigation, the change, the test and this description were written with Claude; the Windows runs were made on my PC with my own copy of the game.
</html>Whatmain; no other open PR implements the same functions (unmerged pull requests from #1380 to #1744 were checked through their refs; older ones were not)NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)A title that paces itself on pending flips can get further ahead of the queue 0 worker than its per-frame memory allows, and the worker then records a frame from memory the title has already rewritten.
Astro Bot (PPSA21564) keeps per-frame data in a ring of three slots, polls sceVideoOutIsFlipPending, and submits the next flip as soon as fewer than three are pending. On hardware a pending flip is a frame whose commands have been read. Here submissions waited 98 to 110 ms in queue 0, so the worker was still recording frame N while the title wrote frame N+3 into the same slot. A block of per-frame constants that holds the title's frame counter read 0x17e in the frame right after one that read 0x17a: the worker recorded frame 0x17b from the slot of frame 0x17e. When the slot was half rewritten the draw bound the wrong block, and the frame came out black, without the movie quad, or with the quad at half size: 8 to 16 of 48 window captures in each of five runs. APS5_FLIP_READ_CHECK=1 counted 141,478 of 158,640 in-place reads as overwritten before execution. The same overrun produced guest snapshot differs from registered memory in compute shader 0x5005e7b00.
A submission on queue 0 that carries a flip now waits until the worker has reached the flip of every earlier one. The wait ends early when queue 0 is blocked on memory that no running, held or pending work writes, the criterion orderReleased uses, since only the title can end that wait. The presenter stays asynchronous: the title still has three flips pending when the display is the limit. APS5_NO_FLIP_HOLD=1 submits as before.
tests/Flip.cpp gains a case: a flip behind a closed rendering wait holds the next flip submission until the wait opens, and a flip behind a WAIT_REG_MEM on a label only the test stores does not hold it.
Not established: what the console returns from sceVideoOutIsFlipPending while its GPU is behind. The change does not depend on it.
Tested
Windows 11, RTX 5070 Ti, Astro Bot (PPSA21564, 01.007.000), built from
b3fcd6d6(an older main) with this change. 45 s runs through the intro, 48 window captures each in bursts 70 ms apart:Build Odd captures Frames presented
Without the change (five runs) 8 to 16 730 to 795
With the change (two runs) 0 868, 999
With the change and APS5_NO_FLIP_HOLD=1 12 795
With the change the snapshot check passes through the whole intro without APS5_NO_SNAPSHOT_CHECK. The title still needs a local workaround for an unrelated failure in the same shader at the first frame (guest memory is not readable at 0x30) and APS5_HOST_IMPORT_MIB=16384.
Linux, on
4ddbf049(this branch's base): agc_driver_flip, agc_driver_pm4 and agc_driver_pm4_failure pass; agc_driver is skipped there because the machine has no Vulkan device. The new case fails with APS5_NO_FLIP_HOLD=1 and passes without it. tools/check_conventions.py --base origin/main passes. The rest of the test suite was not built or run.Not tested: the title on
4ddbf049itself (the Windows runs used the older base; rebasing needed two textual conflict resolutions next to the new timing fields), any title on Linux, any title other than Astro Bot.Checklist
Based on current main; no other open PR implements the same functions (unmerged pull requests from #1380 to #1744 were checked through their refs; older ones were not)
One topic per PR; follow-ups go in a new PR
No comments in code except technical debt
Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
No notes, investigation .md files or images added to the repository (attach them to this PR)
New third-party code is a submodule built from source (none added)
Generic behaviour, not specific to one title
Depends on: none
AI-assisted: yes. The investigation, the change, the test and this description were written with Claude; the Windows runs were made on my PC with my own copy of the game.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T20:44:35Z.
I checked the failed conventions run (37825811506). It reports that
What,Tested, andChecklistare missing, plus a non-Conventional Commit title. The submitted body starts with a pasted HTML document and then repeats the same content as plain text, so the checker is not recognizing the sections. Please replace it with the repository template in plain Markdown (one copy), use a title such asfix(agc): hold flips behind the worker, then rerun conventions. The Linux build is still running; the latest Windows build passed. CONTRIBUTING also asks for a branch based on currentmain, so please refresh the branch before treating the reported older-base results as final.Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-09T04:52:35Z.
Linux results, since this was tested on Windows only. Everything passes here.
Nobara 44 (Linux 7.2), GCC 16.2.1, Release,
BUILD_TESTING=ON. This PR merged ontomainf1451396cleanly.mainf1451396main+ this PRctest -R agc_driver -j1-E agc_driver)The CPU failure is
guest_dynamic_loader, which fails the same way onmain.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:35:10Z.
Three things before this can go in:
APS5_NO_FLIP_HOLD(Submission.cpp:141). Env switches that turn a fix off aren't wanted here; the hold should just be right.Submission.cpp:148waits in 1 mswait_forsteps untilflipHoldOver()is true. NotifychangedwhereverrunningWorkers,orderHoldersand the pending completions drop, and wait on the predicate. Polling costs a wake-up every millisecond while held and can release up to 1 ms late.submission.queue != 0returns early (Submission.cpp:142), so a title that writes the next frame's data through a compute or second graphics queue still races the worker. The flip being held is on queue 0, but the overwrite can come from any queue.Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:22:51Z.
Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head
878d7ca1, merged ontomaind70b8998in one build with 33 other AGC/shader PRs that had no Windows run.agc_driver_flip,agc_driver_flip_compute. None of them reported skipping a case.PATHsetup.No title was run.
🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T05:57:44Z.
Review: DISMISSED
Thanks for the investigation and the measurements. Still open before this can go in:
APS5_NO_FLIP_HOLD(Submission.cpp:141), wake the hold by notifyingchangedwhererunningWorkers,orderHoldersand the pending completions drop instead of the 1 mswait_forpoll (Submission.cpp:148), and hold writers coming from queues other than 0 (Submission.cpp:142).conventionsis red: the PR body is a pasted HTML document followed by a plain-text copy, so theWhat/Tested/Checklistsections are not recognized. Please replace it with one plain-Markdown copy of the template, and retitle asfix(agc): hold flips behind the worker(Conventional Commits).Flip.cppshould also cover the notify path (hold released by worker progress with no extra submission) once the polling is gone.Rebase on current
mainwhen you push; the Linux (fisherjoey) and Windows (popcoder565) runs on this head were clean.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T10:07:04Z.
I rebased this on current
mainand added one commit on top for the review points (5d888abd75):APS5_NO_FLIP_HOLDis gone.changedwith no timeout. Two things wake it: the worker that reaches a flip, and the queue 0 worker once its memory or rewind wait can only be ended by a store from the title. That second check is the same oneflipHoldOvermade, now done by the worker in its wait loop.agc_driver_flip_tests: a flip held behind a rendering wait is released when the worker moves on to a label wait that only the title can satisfy, without another submission. Without the wake it fails.I left the other-queue point out. The hold blocks the title's thread at its flip submission, so that thread's later submissions on any queue come after the held one anyway.
Tested: Linux, RTX 4090, Release, full
ctest. Everything passes exceptagc_driver_dcc_keys_first_write, which fails onmaintoo.agc_driver_flippasses 20 of 20 runs.