perf(agc): audit a cached template only after the host import set changed #9012

Closed
SP4C3B4R-8 wants to merge 1 commit from upstream-pr/9012 into main
SP4C3B4R-8 commented 2026-10-21 09:43:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SP4C3B4R-8 on 2026-10-21T09:43:45Z.


What

#8047 (@fisherjoey) made a cached ShaderResources take the full walk instead of the fast proof once its last full walk is older than APS5_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 on HostImportCovers, 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.cpp keeps a process-wide importSetGeneration, read by HostImportSetGeneration(). bumpEpoch(state) replaces every ++state.epoch (retireImport, the device change in refreshImports, ClearHostImports) and bumps the generation too; importSetChanged() follows the import insert in importRunAt.
  • ShaderResources records the generation when it is built and at the start of each full walk (walkImportGeneration). The audit condition becomes TemplateAuditDue(lastFullWalk) && (AuditEveryInterval() || walkImportGeneration != HostImportSetGeneration()).
  • The audits that an import change starts are spread out: at most 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::audited says whether the proof took the full walk because of the audit.
  • APS5_TEMPLATE_AUDIT_ALWAYS=1 restores the audit at every interval, without the budget. APS5_TEMPLATE_AUDIT_MS=0 still 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 main 27c88a8d7 (table below). Rebased on main d6eafa54d on 10-22, measured again and retested (see the review reply for the captures).

  • Astro Bot Crash Site, warm caches, APS5_PROFILE_DRAW=1, same session:
fps revalidate per 10 s full walks per 10 s (audit)
main 9.86 1542 ms 10,534 (7,982)
this PR 10.37 1162 ms 2,367 (0)
main + APS5_TEMPLATE_AUDIT_MS=0 (two runs) 10.45 / 10.45 1180 ms 2,423
main again (two runs) 9.89 / 9.78 1530 ms 10,358

Frame dumps of the hub with this PR look the same as main.

  • 10-22, rebased build 19191f4ea, same session: 10.10 fps with this PR vs 9.89 with APS5_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.
  • SampledCacheBudget resource-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_tests and 124 ctests (*draw*, *stencil*, *indirect*, *multisample*, *msaa*, *target*, *pass*, *sampled_cache*, *resource_cache*, *host_import*): all pass apart from the relinker test unused_filter_indirect, which does not touch this code.
  • python tools/check_conventions.py --base origin/main: all checks passed.

Performance report

Capture on main and 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, main d6eafa54d (this head's parent) against 19191f4ea, APS5_TRACE_SECONDS=150:5, six alternated rounds.

  • Graphics.Draw on 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.
  • Profiled pair: audit walks about 6,300 per 10 s on 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.
  • Frame time is level on that machine: it is bound by the GPU (about 150 ms per present) and by the queue 0 worker (98.7-98.9% busy), so the committer saving does not reach the frame there. On comparable windows the medians differ by about 1 ms of GPU busy and 1.5 ms of frame p50, inside the run-to-run spread.
  • Linux/RADV, Sky Garden, RX 9070 XT (@EdouardSence, comment): level and clean, no device loss or VUID.

Round 1 summary lines (main, then this PR):

{"commit":"d6eafa54d046","dirty":false,"env":{"APS5_HOST_IMPORT_MIB":"13312","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"150:5"},"gpu":"NVIDIA GeForce RTX 4070 Ti SUPER","driver":"NVIDIA 616.64","os":"Windows 10.0.26200","cpu":"11th Gen Intel(R) Core(TM) i7-11700K @ 3.60GHz","cpu_threads":16,"memory_mib":32599,"title_id":"PPSA21567","title":"ASTRO BOT","content_version":"01.019.000","resolution":"3840x2160","window":{"spec":"seconds 150:5","first_present":4972,"ms":5147.612},"presents":31,"frame_ms":{"p50":167.36,"p90":175.426,"p99":177.992,"max":177.992},"gpu_busy_ms_per_present":139.637,"worker_busy_pct":{"queue worker 0x0":98.759,"queue worker 0x40":97.698,"queue worker 0x48":88.554,"queue worker 0x46":4.664},"top_phases_ms_per_frame":{"Driver.Packet":480.607,"Driver.Packet.memory_wait":274.15,"Driver.Packet.draw":97.616,"Driver.Draw":96.491,"Graphics.Draw":85.504,"Graphics.Draw.draw_and_resource_release":68.385,"Driver.Draw.shader_compile_and_link":54.439,"Driver.Packet.prepare_memory":45.847},"trace_dropped":false,"trace":"aps5-trace-d6eafa54d046-8152.json.gz"}
{"commit":"19191f4ea263","dirty":false,"env":{"APS5_HOST_IMPORT_MIB":"13312","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"150:5"},"gpu":"NVIDIA GeForce RTX 4070 Ti SUPER","driver":"NVIDIA 616.64","os":"Windows 10.0.26200","cpu":"11th Gen Intel(R) Core(TM) i7-11700K @ 3.60GHz","cpu_threads":16,"memory_mib":32599,"title_id":"PPSA21567","title":"ASTRO BOT","content_version":"01.019.000","resolution":"3840x2160","window":{"spec":"seconds 150:5","first_present":2672,"ms":5036.035},"presents":29,"frame_ms":{"p50":175.86,"p90":181.506,"p99":184.268,"max":184.268},"gpu_busy_ms_per_present":157.641,"worker_busy_pct":{"queue worker 0x0":98.774,"queue worker 0x40":97.846,"queue worker 0x48":94.081,"queue worker 0x46":9.056},"top_phases_ms_per_frame":{"Driver.Packet":520.138,"Driver.Packet.memory_wait":295.873,"Driver.Packet.draw":88.37,"Driver.Draw":87.244,"Graphics.Draw":77.007,"Driver.Packet.prepare_memory":61.107,"Graphics.Draw.draw_and_resource_release":59.743,"Driver.Packet.dispatch":53.233},"trace_dropped":false,"trace":"aps5-trace-19191f4ea263-22164.json.gz"}

tools/trace_digest.py, first line of each:

aps5-trace-d6eafa54d046-8152.json.gz: **seconds 150:5** from present 4972: 31 presents, frame p50 167.4 / p90 175.4 / p99 178.0 / max 178.0 ms, GPU busy 139.6 ms per present
aps5-trace-19191f4ea263-22164.json.gz: **seconds 150:5** from present 2672: 29 presents, frame p50 175.9 / p90 181.5 / p99 184.3 / max 184.3 ms, GPU busy 157.6 ms per present

Traces: round 1, 2, 3, 4, 5, 6.

Checklist

  • Based on current main; no other open PR implements the same functions
  • 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 under Silent stubs in their library's technical debt file
  • 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
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 5070 Ti, driver 617.42, Windows 11
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4949571315 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9012). Originally posted by [SP4C3B4R-8](https://github.com/SP4C3B4R-8) on 2026-10-21T09:43:45Z. --- ### What #8047 (@fisherjoey) made a cached `ShaderResources` take the full walk instead of the fast proof once its last full walk is older than `APS5_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 on `HostImportCovers`, 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.cpp` keeps a process-wide `importSetGeneration`, read by `HostImportSetGeneration()`. `bumpEpoch(state)` replaces every `++state.epoch` (`retireImport`, the device change in `refreshImports`, `ClearHostImports`) and bumps the generation too; `importSetChanged()` follows the import insert in `importRunAt`. - `ShaderResources` records the generation when it is built and at the start of each full walk (`walkImportGeneration`). The audit condition becomes `TemplateAuditDue(lastFullWalk) && (AuditEveryInterval() || walkImportGeneration != HostImportSetGeneration())`. - The audits that an import change starts are spread out: at most `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::audited` says whether the proof took the full walk because of the audit. - `APS5_TEMPLATE_AUDIT_ALWAYS=1` restores the audit at every interval, without the budget. `APS5_TEMPLATE_AUDIT_MS=0` still 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 `main` 27c88a8d7 (table below). Rebased on `main` d6eafa54d on 10-22, measured again and retested (see the review reply for the captures). - Astro Bot Crash Site, warm caches, `APS5_PROFILE_DRAW=1`, same session: | | fps | revalidate per 10 s | full walks per 10 s (audit) | |---|---|---|---| | `main` | 9.86 | 1542 ms | 10,534 (7,982) | | this PR | 10.37 | 1162 ms | 2,367 (0) | | `main` + `APS5_TEMPLATE_AUDIT_MS=0` (two runs) | 10.45 / 10.45 | 1180 ms | 2,423 | | `main` again (two runs) | 9.89 / 9.78 | 1530 ms | 10,358 | Frame dumps of the hub with this PR look the same as `main`. - 10-22, rebased build 19191f4ea, same session: 10.10 fps with this PR vs 9.89 with `APS5_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. - `SampledCacheBudget` `resource-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_tests` and 124 ctests (`*draw*`, `*stencil*`, `*indirect*`, `*multisample*`, `*msaa*`, `*target*`, `*pass*`, `*sampled_cache*`, `*resource_cache*`, `*host_import*`): all pass apart from the relinker test `unused_filter_indirect`, which does not touch this code. - `python tools/check_conventions.py --base origin/main`: all checks passed. ### Performance report Capture on `main` and with this change, same title, scene and machine, by @panicDa3m0n (full table, profiled pair and all twelve summary lines in [his comment](https://github.com/boykopovar/AnyPS5/pull/9012#issuecomment-6361833585) 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, `main` d6eafa54d (this head's parent) against 19191f4ea, `APS5_TRACE_SECONDS=150:5`, six alternated rounds. - `Graphics.Draw` on 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. - Profiled pair: audit walks about 6,300 per 10 s on `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. - Frame time is level on that machine: it is bound by the GPU (about 150 ms per present) and by the queue 0 worker (98.7-98.9% busy), so the committer saving does not reach the frame there. On comparable windows the medians differ by about 1 ms of GPU busy and 1.5 ms of frame p50, inside the run-to-run spread. - Linux/RADV, Sky Garden, RX 9070 XT (@EdouardSence, [comment](https://github.com/boykopovar/AnyPS5/pull/9012#issuecomment-6363581990)): level and clean, no device loss or `VUID`. Round 1 summary lines (`main`, then this PR): ```json {"commit":"d6eafa54d046","dirty":false,"env":{"APS5_HOST_IMPORT_MIB":"13312","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"150:5"},"gpu":"NVIDIA GeForce RTX 4070 Ti SUPER","driver":"NVIDIA 616.64","os":"Windows 10.0.26200","cpu":"11th Gen Intel(R) Core(TM) i7-11700K @ 3.60GHz","cpu_threads":16,"memory_mib":32599,"title_id":"PPSA21567","title":"ASTRO BOT","content_version":"01.019.000","resolution":"3840x2160","window":{"spec":"seconds 150:5","first_present":4972,"ms":5147.612},"presents":31,"frame_ms":{"p50":167.36,"p90":175.426,"p99":177.992,"max":177.992},"gpu_busy_ms_per_present":139.637,"worker_busy_pct":{"queue worker 0x0":98.759,"queue worker 0x40":97.698,"queue worker 0x48":88.554,"queue worker 0x46":4.664},"top_phases_ms_per_frame":{"Driver.Packet":480.607,"Driver.Packet.memory_wait":274.15,"Driver.Packet.draw":97.616,"Driver.Draw":96.491,"Graphics.Draw":85.504,"Graphics.Draw.draw_and_resource_release":68.385,"Driver.Draw.shader_compile_and_link":54.439,"Driver.Packet.prepare_memory":45.847},"trace_dropped":false,"trace":"aps5-trace-d6eafa54d046-8152.json.gz"} {"commit":"19191f4ea263","dirty":false,"env":{"APS5_HOST_IMPORT_MIB":"13312","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"150:5"},"gpu":"NVIDIA GeForce RTX 4070 Ti SUPER","driver":"NVIDIA 616.64","os":"Windows 10.0.26200","cpu":"11th Gen Intel(R) Core(TM) i7-11700K @ 3.60GHz","cpu_threads":16,"memory_mib":32599,"title_id":"PPSA21567","title":"ASTRO BOT","content_version":"01.019.000","resolution":"3840x2160","window":{"spec":"seconds 150:5","first_present":2672,"ms":5036.035},"presents":29,"frame_ms":{"p50":175.86,"p90":181.506,"p99":184.268,"max":184.268},"gpu_busy_ms_per_present":157.641,"worker_busy_pct":{"queue worker 0x0":98.774,"queue worker 0x40":97.846,"queue worker 0x48":94.081,"queue worker 0x46":9.056},"top_phases_ms_per_frame":{"Driver.Packet":520.138,"Driver.Packet.memory_wait":295.873,"Driver.Packet.draw":88.37,"Driver.Draw":87.244,"Graphics.Draw":77.007,"Driver.Packet.prepare_memory":61.107,"Graphics.Draw.draw_and_resource_release":59.743,"Driver.Packet.dispatch":53.233},"trace_dropped":false,"trace":"aps5-trace-19191f4ea263-22164.json.gz"} ``` `tools/trace_digest.py`, first line of each: ``` aps5-trace-d6eafa54d046-8152.json.gz: **seconds 150:5** from present 4972: 31 presents, frame p50 167.4 / p90 175.4 / p99 178.0 / max 178.0 ms, GPU busy 139.6 ms per present aps5-trace-19191f4ea263-22164.json.gz: **seconds 150:5** from present 2672: 29 presents, frame p50 175.9 / p90 181.5 / p99 184.3 / max 184.3 ms, GPU busy 157.6 ms per present ``` Traces: [round 1](https://github.com/user-attachments/files/33864932/pr9012-ab-round1.zip), [2](https://github.com/user-attachments/files/33864946/pr9012-ab-round2.zip), [3](https://github.com/user-attachments/files/33864960/pr9012-ab-round3.zip), [4](https://github.com/user-attachments/files/33864977/pr9012-ab-round4.zip), [5](https://github.com/user-attachments/files/33864991/pr9012-ab-round5.zip), [6](https://github.com/user-attachments/files/33865001/pr9012-ab-round6.zip). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 5070 Ti, driver 617.42, Windows 11 - [x] AI-assisted: yes (Claude Code)
github-actions[bot] commented 2026-10-21 09:44:00 +00:00 (Migrated from github.com)

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 on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6312937931 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9012#issuecomment-6312937931). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T09:44:00Z. --- <!-- pr-labels-perf --> This pull request is labeled `perf`, so it needs the summary line of a capture on `main` and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both `aps5-summary.jsonl` lines, attach the two traces and add the output of `tools/trace_digest.py`.
fisherjoey commented 2026-10-21 10:42:12 +00:00 (Migrated from github.com)

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 importSetGeneration would 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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6313996974 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9012#issuecomment-6313996974). Originally posted by [fisherjoey](https://github.com/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 `importSetGeneration` would 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
fisherjoey commented 2026-10-21 13:40:30 +00:00 (Migrated from github.com)

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 676269473 plus #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.

run audit mode crawl? ratio, last half median audit walks audits skipped by the gate audits failed failed with no import change
1 this PR no 216 9,536 4,140,321 40 0
2 APS5_TEMPLATE_AUDIT_ALWAYS=1 no 214 390,832 0 39 0
3 this PR no 214 9,642 5,054,035 40 0

With 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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6317534792 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9012#issuecomment-6317534792). Originally posted by [fisherjoey](https://github.com/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 676269473 plus #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. | run | audit mode | crawl? | ratio, last half median | audit walks | audits skipped by the gate | audits failed | failed with no import change | |---|---|---|---|---|---|---|---| | 1 | this PR | no | 216 | 9,536 | 4,140,321 | 40 | 0 | | 2 | `APS5_TEMPLATE_AUDIT_ALWAYS=1` | no | 214 | 390,832 | 0 | 39 | 0 | | 3 | this PR | no | 214 | 9,642 | 5,054,035 | 40 | 0 | With 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
CnRJay commented 2026-10-21 17:53:53 +00:00 (Migrated from github.com)

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=0 gives 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 on HostImportCovers, which can only change when the import set does.

  • The generation is process-wide. Any import added or retired anywhere makes 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, oldest lastFullWalk first.
  • The test says the import "also fails the fast proof by itself (full path, failure 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).
  • HostImportSetGeneration is bumped "wherever the registry's epoch is 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.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5603954328 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9012#pullrequestreview-5603954328). Originally posted by [CnRJay](https://github.com/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=0` gives 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 on `HostImportCovers`, which can only change when the import set does. - The generation is process-wide. Any import added or retired anywhere makes `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, oldest `lastFullWalk` first. - The test says the import "also fails the fast proof by itself (full path, failure `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). - `HostImportSetGeneration` is bumped "wherever the registry's `epoch` is 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.
SP4C3B4R-8 commented 2026-10-22 08:41:38 +00:00 (Migrated from github.com)

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 main d6eafa54d, 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 most APS5_TEMPLATE_AUDIT_BUDGET audits 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=1 is 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. With APS5_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. ProofReport now has audited (the proof took the full walk because of the audit). resource-lookup-changed now checks, in order:

  • past the interval with no import change: fast proof, not audited;
  • a guest write to an unrelated, non-imported surface, past the interval: fast proof, not audited;
  • a host import of an unrelated surface (separated from the bound one by a reserved gap, so the import does not cover it): the generation moves, and the next proof past the interval is audited, takes the full walk and keeps the bound texture; the proof after that is fast again;
  • then the import of the bound surface: the proof fails and the rebuilt template binds the storage view, as before.

Mutation: with the bump after the import insert removed (and the generation Require taken 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 Collect before the audit is reached. I found no host-only way to change HostImportCovers for 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 current main: retireImport, the device change in refreshImports, ClearHostImports), and importSetChanged() follows the one state.imports.emplace in importRunAt. 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 is main's audit):

{"commit":"19191f4ea263","env":{"APS5_TEMPLATE_AUDIT_ALWAYS":"1","APS5_TRACE_SECONDS":"140:10",...},"presents":104,"frame_ms":{"p50":96.4,"p90":105.0,"p99":108.5,"max":110.2},"gpu_busy_ms_per_present":62.3}
{"commit":"19191f4ea263","env":{"APS5_TRACE_SECONDS":"140:10",...},"presents":105,"frame_ms":{"p50":95.8,"p90":103.3,"p99":108.4,"max":108.5},"gpu_busy_ms_per_present":64.6}

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 current main: it is busy ~80 of ~96 ms per frame, 33 ms of that in Driver.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_tests and 124 ctests (*draw*, *stencil*, *indirect*, *multisample*, *msaa*, *target*, *pass*, *sampled_cache*, *resource_cache*, *host_import*) pass, except unused_filter_indirect, a relinker test that does not touch this code. Conventions pass.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6336558490 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9012#issuecomment-6336558490). Originally posted by [SP4C3B4R-8](https://github.com/SP4C3B4R-8) on 2026-10-22T08:41:38Z. --- @CnRJay thanks, all three points are addressed in the new push (rebased on `main` d6eafa54d, 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 most `APS5_TEMPLATE_AUDIT_BUDGET` audits 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=1` is 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. With `APS5_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.** `ProofReport` now has `audited` (the proof took the full walk because of the audit). `resource-lookup-changed` now checks, in order: - past the interval with no import change: fast proof, not audited; - a guest write to an unrelated, non-imported surface, past the interval: fast proof, not audited; - a host import of an unrelated surface (separated from the bound one by a reserved gap, so the import does not cover it): the generation moves, and the next proof past the interval is audited, takes the full walk and keeps the bound texture; the proof after that is fast again; - then the import of the bound surface: the proof fails and the rebuilt template binds the storage view, as before. Mutation: with the bump after the import insert removed (and the generation `Require` taken 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 `Collect` before the audit is reached. I found no host-only way to change `HostImportCovers` for 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 current `main`: `retireImport`, the device change in `refreshImports`, `ClearHostImports`), and `importSetChanged()` follows the one `state.imports.emplace` in `importRunAt`. 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 is `main`'s audit): ``` {"commit":"19191f4ea263","env":{"APS5_TEMPLATE_AUDIT_ALWAYS":"1","APS5_TRACE_SECONDS":"140:10",...},"presents":104,"frame_ms":{"p50":96.4,"p90":105.0,"p99":108.5,"max":110.2},"gpu_busy_ms_per_present":62.3} {"commit":"19191f4ea263","env":{"APS5_TRACE_SECONDS":"140:10",...},"presents":105,"frame_ms":{"p50":95.8,"p90":103.3,"p99":108.4,"max":108.5},"gpu_busy_ms_per_present":64.6} ``` `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 current `main`: it is busy ~80 of ~96 ms per frame, 33 ms of that in `Driver.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_tests` and 124 ctests (`*draw*`, `*stencil*`, `*indirect*`, `*multisample*`, `*msaa*`, `*target*`, `*pass*`, `*sampled_cache*`, `*resource_cache*`, `*host_import*`) pass, except `unused_filter_indirect`, a relinker test that does not touch this code. Conventions pass. AI-assisted: yes (Claude Code)

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9012
No description provided.