perf(agc): fast revalidation over untracked memory proves a surface by its stamp until the next ordering point #6192
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6192"
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 TheAggie on 2026-10-15T01:35:19Z.
What
Stacked on #6187; only the last two commits are this PR.
A cached resource template is reused only after
ShaderResources::Revalidateproves its textures and storage images current. The fast proof (fastRevalidate) answers from write stamps; a surface in memory the write watch does not cover (on Windows, every host-pointer import of the guest mapping, #1441) has none, soCollectWritesreturns 0, the fast proof fails withcollect, and the full walk repeats every texture lookup.In RetroArch's Flycast core (PPSA99169) on Windows: 2.06 million of 2.2 million revalidations per 10 s took the full walk for that reason, and revalidation took 15.2 s of thread time per 10 s in all.
captureValidation), each surface over untracked memory also records a stamp: the collect epoch,NewestStamp(driver stores into the range),ForgetStamp(#6187) and the recorder's newest pending write note over the range. Storage images get the same, instorageUntracked.fastRevalidateaccepts such a surface while its stamp is unchanged, instead of failing withcollect, and leaves it out of theUnchangedSinceAllquery. Everything else in the fast proof is as before: the keys, the pending-image scan and the cache checks still run.compareUntrackedalready uses for untracked memory: a CPU store there is seen at the next ordering point (docs/dev/ARCHITECTURE.md, "Untracked storage image comparisons"). A collect epoch of 0 or a forget in progress gives no stamp, so the full walk runs.APS5_VERIFY_UNTRACKED_PROOFS=1runs the full walk beside every fast proof that involved an untracked surface and reports how often it disagreed.Tested
Windows 11, NVIDIA GeForce RTX 5070 Ti, MinGW-w64 GCC 15.2.0, on main
8cd937e29with #6187; rebased onto main92e50418f(only a CMake test list conflicted), where the full suite passes 1277 of 1296, 14 skipped, failing only the known tests below.ctest: 1229 of 1249 pass, 14 skipped.guest_call_trace_abortandwindows_backtrace_reportfail, and fail the same way on plain main here.agc_driver_prepared_graphics_prebuild_0/_1andundeliverable_host_exceptionfail under my test runner because it skips their environment changes and pass pattern; run with those, they pass.agc_driver_multisample_fill_host_onlyfailed once in the parallel run and passed three times out of three run alone.agc_untracked_revalidate(agc_driver_recorder_tests --untracked-revalidate-only): a sampled template over an untracked allocation proves on the fast path twice in one collect epoch; after a CPU store and a new epoch it takes the full walk. Without this change the test fails with "a sampled template over untracked memory took the full walk in the same collect epoch".APS5_VERIFY_UNTRACKED_PROOFS=1: 1,600,000 fast proofs over untracked memory checked by the full walk, 0 disagreed.ANYPS5_PRESENT_MODE=immediate, unprofiled, on the local stack described in #6187 with #6187 included: two runs each, audio produced at 63.1% and 62.6% of real time without this change against 65.3% and 66.9% with it. Fast proofs per 10 s went from 0.13 million of 2.2 million revalidations to 1.96 million of 2.48 million; the committer's lookup phase went from 9.75 to 5.75 µs per draw. I have no measurement ofmainalone.Related: #6060 keeps Windows imports of private write-watched memory on
GetWriteWatchwhen a start-up probe allows it; memory it keeps watched never reaches this path, so this PR matters for what stays untracked (imports through views, devices whose probe fails). I have not measured how much of the Flycast workload #6060 would cover.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
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-15T05:08:33Z.
@TheAggie I had a variant of this running locally when #6192 went up, and measured it at Astro Bot's title (PPSA21567, the
collectcase from #357). The design difference and the numbers are below; the numbers say thecollectfailures are not where Astro Bot's revalidation time goes.Design difference. Instead of a stamp taken in
captureValidation, the fast proof reuses the keys the lookups already decide with:cachedTextureputs itsuntrackedKeyinto the lookup record. That key is the write-watch hint,NewestStamp,ForgetSerialand the newest write note, taken before the bytes are read or compared. The proof accepts the surface while the key is unchanged and!SnapshotWriteOverlaps, which is thekept()rule.comparedGuestBytesequals the stampcompareUntrackedwould take now. It also requires that the saved bytes hold, that no save is in flight, that no unit kept at an unwatch holds, and that no recorded write is pending over the surface (Refreshwould flush that write first).On a microbenchmark (16 untracked sampled surfaces) this took
Revalidatefrom 86–93 µs to 37–41 µs at one proof per collect epoch, and from 52–56 µs to 10–13 µs at eight per epoch.At the title it saved nothing. Setup:
maine858dbd78plus the change,APS5_PROFILE_DRAW=1.APS5_NO_UNTRACKED_PROOF=1.lookup/record/readTargetmscollect/untracked memo/pending image[textures]untracked snapshots kept by hint / compared[guestmem]compareThe one window of the title intro before the press agrees:
So the proof does what the counters promise:
collectfailures go from 5330 to 0 per 10 s;But a revalidation costs the same either way. Solving the two rows, a full walk costs only about 7 µs more than a fast proof here, and the other ~580 µs of each
Revalidateis spent outside the image lookups. My guess is the epoch gate's registry scan and flush for imported regions (0 registry scans skippedin every window) orCompletePendingCpuWrites, but I have not split it. Most of the ~5900 revalidations per 10 s come from dispatches, not the ~1530 draws.On safety, both runs show the same three
guest memory changed while GPU results were pendingwarnings and nothing else.APS5_VERIFY_PROOFSwas not set in the title runs. With it, the 565agc_ctests pass and 4,000 benchmark proofs were each checked against the full walk without an abort.I'm not opening this as a competing PR: at this title it doesn't buy anything over #6192, and #6192 has measured gains on Flycast. If you do want the stamp to outlive the epoch for hinted ranges, the test I used (
agc_untracked_hint_revalidate) checks a view, a snapshot and a storage image across 20 epochs without stores. It also checks that the proof does not hold after a changed CPU store, a store of the same bytes, a driver store, or over a pending recorded write. I can push it if that's useful.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-15T16:10:07Z.
@fdfawef324 thanks for measuring this at Astro Bot's title, and for the detailed write-up.
Your table matches what #6192 claims and no more. It removes the
collectfast-fails. On the Flycast demo those fails were where the revalidation time went. At Astro Bot's title the ~580 µs of eachRevalidatespent outside the image lookups dominates, so the proof can't show there. I haven't split that part either. If it is the epoch gate's registry scan orCompletePendingCpuWrites, that is a separate change, and a better target for that title than this PR.On letting the proof outlive the epoch for hinted ranges: I'd keep #6192's stamp with the epoch in it, because of the race you describe (a store between the lookup's read and the capture whose mark another hint walk consumed).
Your
agc_untracked_hint_revalidatetest would still be useful. Its negative cases (a changed CPU store, a store of the same bytes, a driver store, a pending recorded write) could be run against #6192's rule too. If you push it, as its own PR or as a branch I can pull from, I'll run it against this branch and report back.I've rebased #6187 and #6192 onto current
mainlocally and will push them after the tests rerun.AI-assisted (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-17T11:12:46Z.
@TheAggie MGS4 (PPSA18194) data on Windows, plus a small extension that may belong in this PR.
What we saw. With #6192 (and #6187) on our test stack, MGS4 gameplay still takes the full walk for about 25.8k of 140k revalidations per 10 s, all
collectfast-fails. A diagnostic on that path shows every failure differs from the recorded stamp only in the collect epoch: the surfaces (about 360, 0.2-1.4 MiB each, in the arena at 0x2d...-0x2e...) are Windows host-pointer imports, and the queue worker bumps the epoch about 160 times per 10 s. So each template over them takes one full walk per epoch.Extension. On Windows, #4878 already keeps write-watch marks of unwatched blocks as a hint, and
compareUntrackedputsUntrackedHintinto its memo key in place of the epoch. The same rule works for the fast proof's stamp:A CPU store is still seen at the next ordering point:
UntrackedHintwalks the range's marks once per collect epoch and thread, so a marked page gives a newer hint and the stamp fails as before. Ranges without a hint (Linux, tracked blocks) keep the epoch. The top bit only keeps a hint from ever equalling an epoch value.Measured (Windows 11, RTX 3080, NVIDIA 610.74, i9-10850K; our integ stack with #6192/#6187; one build, the change switched off by an env var for the control; 540 s each, the same save, medians of the last 18 windows of 10 s in gameplay):
collectfast-failslookupphaseFrame rate does not move here: MGS4's draw thread is bound by other phases.
APS5_VERIFY_UNTRACKED_PROOFS=1with the change (420 s run): 2,000,000 fast proofs over untracked memory checked by the full walk, 0 disagreed. HUD and text match the control in screenshots. One pair of runs only; no new test yet (the obvious one: a template over a hinted import stays on the fast proof across epochs without a store and takes the full walk after a CPU store).Feel free to fold it in if it fits your PR; if you would rather keep #6192 as is, I can open it separately once this one merges.
AI-assisted (Claude Code); the runs and numbers above are ours.
Imported from boykopovar/AnyPS5. Originally posted by CPritch on 2026-10-18T20:41:17Z.
GTA V (PPSA04263, 01.010.002) on Linux, Performance mode, prologue bank, measured on this head (
2d030407e). #7515 is merged in both builds of each pair for its counters; the desktop pair also has #7646, since mainc4c2b3aa7does not start without it (#7636). Merging onto main hits one hunk infastRevalidate's storage-image loop: main's depth-surface guard and this PR's stamp check. I kept the guard, followed by this PR's lines.c4c2b3aa7505767380Two runs per build, alternating, 120 s windows after the load. GPU time per present is unchanged on both machines, so the gain is on the CPU side. On the desktop the draw committer is the bottleneck, and
ShaderResources::Revalidate's memcmp was about 21 % of it before this change.APS5_VERIFY_UNTRACKED_PROOFS=1on the laptop: 0 disagreements in 700,000 checks over 3 runs, one of them 900 s long. The verifier prints its totals every 100,000 checks, so the checks after the last print of each run are not counted. On this title most stamped surfaces are textures in partially committed memory:CollectWritesreturns 0 because the write watch does not cover the whole range, not because the memory is untracked. The PR's argument is written for untracked memory; the verifier agrees in these cases too, but the counters cannot split textures from storage images, so that part is from reading the code. Rendering looked the same in the frames we compared.Not tested: Windows, AMD GPUs, Fidelity mode.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-21T17:53:59Z.
Review: COMMENTED
The cost is shown on the right workload (Flycast core, 2.06 of 2.2 million revalidations per 10 s on the full walk, 15.2 s of thread time per 10 s), the gain is measured (fast proofs 0.13 to 1.96 million of 2.48, lookup phase 9.75 to 5.75 us per draw, audio 62.6-63.1% to 65.3-66.9% of real time), and
APS5_VERIFY_UNTRACKED_PROOFS=1with 1.6 million proofs and 0 disagreements is a good check. The design decision it makes should be explicit, because it changes what a title sees.mainalone": the baseline is the stack with #6187, notmain. Post the pair onmainwith the stack's other PRs listed, so the gain can be tied to this PR.main, and stacked on #6187. The sibling #6209 (DCC key proofs over untracked memory) uses the same stamp rule and reports a gain of about 1 to 3 points of audio on top of this one; they should be reviewed as one decision about the ordering-point contract.Imported from boykopovar/AnyPS5. Originally posted by johandavidcm on 2026-10-22T06:34:53Z.
Windows data point from Yakuza 0 Director's Cut (PPSA31327), gameplay in Kamurocho with the character standing still, 1920x1080, warm caches. Windows 11 Pro 26200, RTX 4070 (617.42), Ryzen 7 7800X3D, WinLibs GCC 15.2.0, Release.
main80565c594+ #8098 (the title's audio) + #8117. Change: this PR (2d030407e) merged onto that base.fastRevalidate's storage-image loop (main's depth-surface guard kept, then this PR's lines) and the Windows test list inCMakeLists.txt(union).--untracked-forget-onlyand--untracked-revalidate-onlypass 3 of 3 on the merged build ("host imports are compared").APS5_PAD_INPUT_FILE,APS5_NO_PAD_INPUT=1, no manual input) through the load and the first dialogue.APS5_TRACE_SECONDS=170:60records only gameplay. Builds were interleaved over three batches.Graphics.Drawgoes from 290 to 251 ms per frame.Mechanism (
APS5_PROFILE_DRAW, median of 14 gameplay intervals of 10 s):collectfast-failsRevalidateReplicated on current
main0c6a5bd59(+ #8098 + #8117), same scene, window140:60, 2 runs each:0c6a5bd59this PR conflicts in three files.CMakeLists.txt: the Windows test list, as before.fastRevalidate:mainnow passesGenerationFor(address, bytes)and keeps its depth guard. I resolved it asif (!untracked) queries.push_back({address, bytes, source->GenerationFor(address, bytes)})(the same forimage), with the guard followed by your stamp check.StorageTexture::compareUntracked:mainnow memoizes several compared ranges (comparedRanges) instead of the whole image. I keptmain's range list and put yourForgetStamp(address, bytes)in the stamp, with the forget-in-progress check (ForgetSerial() & 1) as a separatecacheablecondition.main's array-layer target tests (with and without host imports) pass.Verifier:
APS5_VERIFY_UNTRACKED_PROOFS=1with this PR, one 300 s run from boot to gameplay: 1,100,000 fast proofs checked, 0 disagreed.@ps54all, your hint stamp on top of this PR, from your comment above:
collectfast-fails drop further, to 8,202, andRevalidateto 1,279 ms per 10 s.Summary lines (one run of each build)
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:57:50Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the reviewed code and supplied validation evidence support merging.
What I ran
Reviewed head
2d030407eb8f3ac7fb8078e1fd0d48d95acf450fusing the prepared diff andrepo_read.pyat the pinned head. No tests or build commands were run in this review; the Windows test and performance results below are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The changed lines in
core/libs/prx/libSceAgcDriver/tests/Recorder.cppwere not read; the file was excluded from the review folder as too large. Its diff was reviewed. The supplied Windows suite, targeted test, and Flycast measurements were not independently run. Linux behavior was not tested.To get this to a good state
Nothing is required.
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.