perf(agc): audit a cached template only after the host import set changed #9012
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9012"
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 SP4C3B4R-8 on 2026-10-21T09:43:45Z.
What
#8047 (@fisherjoey) made a cached
ShaderResourcestake the full walk instead of the fast proof once its last full walk is older thanAPS5_TEMPLATE_AUDIT_MS(1000 ms). The case it names is a sampled lookup whose answer changes without any lookup running: a snapshot whose surface became host-imported is viewed through its storage image from then on. That answer depends onHostImportCovers, so it can only change when the set of host imports changes.On a committer-bound scene the audit is a steady cost. Astro Bot (PPSA21564), Crash Site hub, has ~1,600 cached templates, so it runs ~7,700 full walks per 10 s, about 44 µs each. In these runs no audit failed a template (
failed 0).This PR keeps the interval and adds one condition: the audit runs only when a host import was added or retired since the template's last full walk.
GuestBufferMemory.cppkeeps a process-wideimportSetGeneration, read byHostImportSetGeneration().bumpEpoch(state)replaces every++state.epoch(retireImport, the device change inrefreshImports,ClearHostImports) and bumps the generation too;importSetChanged()follows the import insert inimportRunAt.ShaderResourcesrecords the generation when it is built and at the start of each full walk (walkImportGeneration). The audit condition becomesTemplateAuditDue(lastFullWalk) && (AuditEveryInterval() || walkImportGeneration != HostImportSetGeneration()).APS5_TEMPLATE_AUDIT_BUDGET(default 8,0= no limit) start per 4 ms across all templates. A template over the budget keeps the fast proof and audits at a later use.ProofReport::auditedsays whether the proof took the full walk because of the audit.APS5_TEMPLATE_AUDIT_ALWAYS=1restores the audit at every interval, without the budget.APS5_TEMPLATE_AUDIT_MS=0still turns it off.The released-texture check from #8047 is unchanged.
Tested
Windows 11, RTX 5070 Ti (NVIDIA 617.42), Ryzen 7 7800X3D, MinGW GCC 15.2, Release. First measured on
main27c88a8d7(table below). Rebased onmaind6eafa54don 10-22, measured again and retested (see the review reply for the captures).APS5_PROFILE_DRAW=1, same session:mainmain+APS5_TEMPLATE_AUDIT_MS=0(two runs)mainagain (two runs)Frame dumps of the hub with this PR look the same as
main.19191f4ea, same session: 10.10 fps with this PR vs 9.89 withAPS5_TEMPLATE_AUDIT_ALWAYS=1. Audits per 10 s with this PR: 1, 15, 78, 157, 14 through the menu and the load, then 0 in the level. Committer busy per frame (tools/trace_digest.py): 46.5 vs 49.4 ms.SampledCacheBudgetresource-lookup-changed: past the interval with no import change, and after a write to an unrelated surface, the proof stays fast and is not audited. After a host import of an unrelated surface the next proof past the interval is audited and keeps the bound texture. After the import of the bound surface the proof fails and the rebuilt template binds the storage view. Mutation: without the insert bump the test fails at the audit step.agc_driver_graphics_testsand 124 ctests (*draw*,*stencil*,*indirect*,*multisample*,*msaa*,*target*,*pass*,*sampled_cache*,*resource_cache*,*host_import*): all pass apart from the relinker testunused_filter_indirect, which does not touch this code.python tools/check_conventions.py --base origin/main: all checks passed.Performance report
Capture on
mainand with this change, same title, scene and machine, by @panicDa3m0n (full table, profiled pair and all twelve summary lines in his comment and the comment after it). Astro Bot Crash Site, 3840x2160, RTX 4070 Ti SUPER (NVIDIA 616.64), i7-11700K, Windows 10.0.26200, MinGW GCC 15.2 Release,maind6eafa54d(this head's parent) against19191f4ea,APS5_TRACE_SECONDS=150:5, six alternated rounds.Graphics.Drawon the committer is lower in all six rounds, with either build first: −8.5, −5.7, −5.6, −5.8, −4.9, −5.5 ms per frame.main, none with this PR; revalidate 1,734.7 against 1,606.2 ms per 10 s; 35.6 against 33.1 µs per pipelined commit; no failed proof.VUID.Round 1 summary lines (
main, then this PR):tools/trace_digest.py, first line of each:Traces: round 1, 2, 3, 4, 5, 6.
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 github-actions[bot] on 2026-10-21T09:44:00Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-21T10:42:12Z.
Thanks for measuring this. The 44 µs per walk on Astro Bot is a real cost, and gating the audit on import changes makes sense if that is the only thing it has to catch.
One data point from Demon's Souls before this goes in. The audit in #8047 is what fixed the DS level crawl (#8040). The released-texture check alone was not enough: with only that check, 2 of 2 runs still crawled (indexed-indirect draw ratio 439 and 436, normal is 200 to 225). With the timed audit added, 3 of 3 were normal on the old base and 3 of 3 on main
676269473.What I don't know yet is which change the audit catches on DS. If it is always a host import being added or retired, this PR keeps the fix. If something else changes a lookup's answer there, gating on
importSetGenerationwould bring the crawl back.I'm running DS with this PR on top of our stack tonight and will post the crawl ratios and the audit failure counts here when they're in.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-21T13:40:30Z.
Follow-up with the Demon's Souls numbers. This PR doesn't bring the crawl back on DS, and the audits it skips are not ones that fail there.
Setup: our DS stack (main
676269473plus #8047 and a few of our open fixes) with this PR cherry-picked, plus a local counter for audits that the import gate skips, audits that fail, and failures with no import change since the template's last full walk. Three 900 s runs from boot into the first level, judged by the indexed-indirect draw ratio from #8040 (normal 200 to 225, crawl 410 to 475) and a screenshot at t+400 s. Counts are totals over the whole run.APS5_TEMPLATE_AUDIT_ALWAYS=1With the audit forced at every interval (run 2), 39 audits failed, and every one of them came after a host import was added or retired. None failed without an import change, so on DS the gate keeps exactly the case the audit exists for. All the failures fall in the title, menu and level-load stretch, where the import set churns. In the level itself no audit failed in any run.
No crashes, and the screenshots are clean. Steady presents were 9.79 per 10 s with this PR and 9.57 with the audit forced, about 2% better (run 1 overlapped a build on the same machine, so I left its fps out).
Caveats: one title and three runs. A lookup change that doesn't go through the host import set would get past the gate, and DS showed none.
(Edited: the first version of this comment quoted counts from the last 10 s report only, which showed 0 failures. These are whole-run totals.)
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-21T17:53:53Z.
Review: COMMENTED
The cost is measured on a scene where it matters (Astro Bot Crash Site: ~7,700 audit walks at about 44 us per 10 s; revalidate 1,542 ms to 1,162 ms per 10 s;
APS5_TEMPLATE_AUDIT_MS=0gives the same 1,180 ms, so the PR reaches the "audit off" cost) and the reasoning for the condition is sound: the answer the audit guards depends onHostImportCovers, which can only change when the import set does.walkImportGeneration != HostImportSetGeneration()true for every cached template at its next use past the interval. With ~1,600 templates at ~44 us that is about 70 ms of audit walks landing in the frames right after one import, on the committer, which is the bound thread in this scene. In a scene that imports regularly (streaming, #8926's rewatch, windows retiring and being replaced) the saving shrinks and the cost arrives as hitches. Please post the audits per 10 s and the worst frame time on a scene that streams imports, or stagger it: audit at most N templates per frame after a change, oldestlastFullWalkfirst.Other), so the audit is not what catches it there". So no test shows the audit catching a stale answer after an import change, which is the only case it still exists for, and the only case this PR can break. Add one where the fast proof would pass and only the audit catches it, with an import added (the audit runs) and with an unrelated change (it doesn't).HostImportSetGenerationis bumped "wherever the registry'sepochis bumped" and where an import is inserted. List the sites in the description and add a test that fails if a new bump site forgets it, since a missing bump silently disables the audit.Imported from boykopovar/AnyPS5. Originally posted by SP4C3B4R-8 on 2026-10-22T08:41:38Z.
@CnRJay thanks, all three points are addressed in the new push (rebased on
maind6eafa54d, it was conflicting). @fisherjoey thanks for the Demon's Souls runs: 39 audit failures with the audit forced, all after an import change, is the case the gate keeps.1. Audits after one import change are now spread out.
ImportAuditAdmitted()lets at mostAPS5_TEMPLATE_AUDIT_BUDGETaudits start per 4 ms (default 8,0= no limit). The audits that an import change starts are counted across all templates. A template that is over the budget keeps the fast proof and audits at a later use. With ~1,600 templates, the walks after one import take about 0.8 s at most 88 µs per 4 ms, instead of ~70 ms in one go. That is still ~2,000 audits/s, above the old steady rate (~800/s here), so no template waits long.APS5_TEMPLATE_AUDIT_ALWAYS=1is not limited and keeps the old behaviour.Audits per 10 s on Astro Bot (PPSA21564) with this PR, from boot through the menu, the hub load and the Crash Site hub (
APS5_PROFILE_DRAW=1): 1, 15, 78, 157, 14, then 0 for every report in the level. WithAPS5_TEMPLATE_AUDIT_ALWAYS=1: ~400 per 10 s in the menu, 7,200-8,200 in the level. The import churn is in the load stretch, and the worst 10 s there is 157 walks (~7 ms).2. A test where only the audit runs after an import, and one where it doesn't.
ProofReportnow hasaudited(the proof took the full walk because of the audit).resource-lookup-changednow checks, in order:Mutation: with the bump after the import insert removed (and the generation
Requiretaken out), the test fails at "a proof past the audit interval after a host import was added did not audit the template".About the last step: in this fixture the import of the bound surface fails the fast proof itself. The import re-arms write tracking of the range, so the fast proof fails on
Collectbefore the audit is reached. I found no host-only way to changeHostImportCoversfor a bound surface without touching its tracking, so the test checks the gate on the unrelated import instead. The DS counts above show the real case where the fast proof passes and only the audit catches the change.3. Bump sites. There are no separate bumps any more.
bumpEpoch(state)replaces every++state.epoch(3 sites on currentmain:retireImport, the device change inrefreshImports,ClearHostImports), andimportSetChanged()follows the onestate.imports.emplaceinimportRunAt. A new retire path that moves the epoch gets the generation with it. The test above fails if the insert bump is missing. They are listed in the description.Performance capture (same build,
19191f4ea, Crash Site hub, warm caches,APS5_TRACE_SECONDS=140:10; "main" =APS5_TEMPLATE_AUDIT_ALWAYS=1, which ismain's audit):tools/trace_digest.py: draw committer busy 49.4 ms per frame with the audit forced, 46.5 ms with this PR (-6 %). Queue 0's worker bounds this scene on currentmain: it is busy ~80 of ~96 ms per frame, 33 ms of that inDriver.Draw.shader_compile_and_link. So the committer saving shows up only partly in FPS. Untraced runs, same session: 10.10 fps with this PR, 9.89 with the audit forced. The full summary lines and both traces are available if you want them attached.Tests on the rebase:
agc_driver_graphics_testsand 124 ctests (*draw*,*stencil*,*indirect*,*multisample*,*msaa*,*target*,*pass*,*sampled_cache*,*resource_cache*,*host_import*) pass, exceptunused_filter_indirect, a relinker test that does not touch this code. Conventions pass.AI-assisted: yes (Claude Code)
Pull request closed