fix(agc): store small pending storage results at each flip #4841
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4841"
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 gjonn on 2026-10-12T23:27:41Z.
What
A storage image result stays on the GPU until something stores it to guest memory: a driver-observed use of its range (
FlushPendingthrough the flush hook, a packet that reads the range), the queue-idle store (#3777), orAPS5_STORE_AT_FLIP=1atPresentDisplayBuffer. A guest CPU that reads the result with plain loads gets none of the first, the second only runs when queue 0 drains, and the third is off by default. While a title keeps queue 0 busy, such a result never reaches guest memory.PPSA01317 needs a guarantee here. Its CPU auto-exposure reads 16x16 R32F and RGBA16F images that the GPU writes in host-imported memory, a frame or more after they are written. On an older local tree without #3777, those images were marked written 50 to 80 times and stored 0 times, and a guard-page probe on them caught guest CPU loads. The exposure multiplier computed from them collapsed to 2^-32 and the garage car view went black within seconds of each camera cut.
On current
main, #3777 covers this whenever queue 0 drains between frames. This change makes the store not depend on the queue going idle. That matters if the idle store is delayed, as #4410 proposes (50 ms): this title's gap between a flip and its next submit is about 5 to 13 ms. I have not run the title on currentmain; the test below shows the failure onmainwhen the queue stays busy.Change: when queue 0 reaches a flip packet, before the flip's batch is submitted,
StorageTexture::StoreSmallPendingstores every pending image of at mostSmallStoreBytes(64 KiB) whose memory is host-imported. The stores are recorded on the GPU behind the frame's work and submitted in the flip's batch, so neither the queue worker nor the title waits for the GPU. A flip ends the title's frame, so a result it reads a frame later has been stored by then.The bounds:
APS5_STORE_AT_FLIP=1does, and its cost is why that switch is off by default (#1995).APS5_STORE_AT_FLIP=1is unchanged.Related: #4794 (open) stores every image result at draw time instead; this PR stores only small imported results, once per frame.
Tested
mainat90c683946.agc_driver_flip_stores_small_results: on queue 0, a dispatch writes a 16x16 R32 storage image in imported guest memory, then a flip, then aWAIT_REG_MEMon a dword only the test writes, which keeps queue 0 busy so the queue-idle store cannot run. The test polls the image with plain CPU loads for 2 s. Without the change it fails ("a small image written before a flip did not reach guest memory while the queue kept working"); with it, it passes.ctest -R agc_driver: 347 tests, all passed (1 skipped as onmain:agc_driver_stencil_ref_export).python tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-13T04:07:34Z.
An Intel run, and the full suite.
Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, CI configure flags, an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. The head fb388af3f merged into
main495bf91a0, which passes 1023 of 1023 on both GPUs.agc_driver_flip_stores_small_resultspasses on both GPUs with--repeat until-fail:3, and it ran on both without returning 77.ctest --timeout 120 --parallel 4): 1024 of 1024 on both GPUs.No negative control here: with the production files as on
mainthe test doesn't build, becauseStorageTexture::SmallStoreBytesis new.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T04:39:02Z.
Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on current main
3779597together with four other open GPU PRs (their own commits cherry-picked, no merge commits), so only the tests that belong to this PR say something about it:tests/execution/FlipStoresSmallResults.cpp(agc_driver_flip_stores_small_results): 3 of 3 runs passed.Not tested: no game run. The batch was built once, not per PR; nothing failed, so no bisect was needed.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by gjonn on 2026-10-14T13:14:11Z.
Rebased onto
main63fb0cd92(force-push, one commit,0b5a4aae3). The only conflict was inTexture.hpp, wheremainaddedSaveBeforeUnwatchnext toSmallStoreBytesandStoreSmallPending; both are kept.agc_driver_flip_stores_small_resultspasses on Windows (MinGW GCC, Release, RTX 5090 Laptop), andtools/check_conventions.pypasses.Thanks @kr4y4 and @xXPBSXx for the runs.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-14T14:02:05Z.
A game run: Kena: Bridge of Spirits (PPSA01802) shows this on its title screen, and this PR fixes it.
Setup: Linux (Arch, kernel 7.2.9), GCC, Release, RX 9070 XT (RADV, Mesa 26.2.4). Kena does not reach its title on plain
main(it stops atbuffer descriptor uses an unsupported type, which #5049 covers), so the runs are on a local stack:mainf74ec639c+ #5049 + #5156 + #4722 + #1201 (withAPS5_PIPELINED_DRAWS=1) + local stand-ins,APS5_SYNC_FLIP=1. This PR's commit0b5a4aae3was cherry-picked on top. Each run starts from the same save and sits on the title; every presented frame from the same point on was dumped (APS5_DUMP_FRAMES) and its mean brightness measured.[storage]write-backs by reason:memory access 284, no flip stores.[storage]write-backs:flip 560/30.0 MiBover the run. No GPU reset.agc_driver_flip_stores_small_resultspasses here (Linux, RADV).The 3-frame cycle and the fix fit the exposure readback described above (small GPU-written results read by the CPU a frame later, here apparently rotating through three images). With queue 0 kept busy by the pipelined committer, the queue-idle store does not cover it.
Before finding this PR I had a narrower local version (images of at most 4x4 texels, stored through
FlushPendingat the flip); I am dropping it in favour of this one.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T17:17:56Z.
Checked on Linux (merged onto current
main):agc_driver_flip_stores_small_resultspasses, and it fails with the flip hook inPacketMemory.cppremoved. The rest of the agc scope is green exceptagc_driver_tessellation, which segfaults here with and without this change. Also confirmed by @kr4y4 (Windows, RTX 4070 + Intel iGPU), @xXPBSXx (Windows, RTX 4080 SUPER) and @alfalfa-star (Linux RADV, Kena title screen flicker gone). Merging once the full Build is green.