feat(agc): count why a template's collect was refused #11550

Merged
johandavidcm merged 1 commit from upstream-pr/11550 into main 2026-10-30 00:04:12 +00:00
johandavidcm commented 2026-10-26 18:24:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by johandavidcm on 2026-10-26T18:24:34Z.


What

A template's fast proof (ShaderResources::fastRevalidate) leaves the object to the full walk when GuestMemory::CollectWrites returns 0 for one of its surfaces, which the [rescache] line counts as the fast-fail reason collect. In Yakuza 0 Director's Cut (PPSA31327) that reason sends 23,700 of 31,400 full walks per 10 s, and the revalidation total is 1,700 ms per 10 s of the draw committer, but the line says nothing about why the collect was refused, how many surfaces are behind it, or what the full walks that follow cost. CollectWrites returns 0 only when the page walk fails: the range has pages that are not committed, or pages the arena compares instead of watching.

With APS5_PROFILE_DRAW=1, no behaviour change:

  • Each collect refusal is counted by element kind (a sampled surface, a storage image) and by cause: the range has uncommitted pages (GuestMemory::Accessible is false), it is outside the write tracker (GuestMemory::Watched is false), or neither (other); the distinct surfaces refused in the report window and their bytes are counted too (at most 65,536 distinct addresses are kept per window).
  • The full walks are timed by the fast-fail reason that sent them there.
  • The [rescache] revalidate line gains full walk ms by reason: ... and collect refusals: sampled N, storage M (uncommitted pages U, unwatched W, other O) over S surfaces, X MiB. Tests read the same counters through ShaderResources::CollectRefusalCounts() and ShaderResources::FullWalkNanoseconds().

Tested

Windows 11 Pro 26200, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, head 49eecbcc8 on main f1efa4ddc.

New test agc_driver_resource_cache_collect_refusals (tests/execution/SampledCacheBudget.cpp, mode collect-refusals): a sampled template and a storage-image template over a surface whose last page is reserved but not committed take the full walk; the counters must show two sampled refusals and one storage refusal, all three as uncommitted pages, one surface of the surface's bytes, and a non-zero full-walk time under collect; a sampled template over a surface the test allocated outside the guest arena (VirtualAlloc) must count one more sampled refusal as unwatched and a second surface; once the page is committed the proofs count no refusal.

  • Without the change it fails with two collect refusals of a sampled surface were not counted.
  • With the change it passes, also with --repeat until-fail:20.

Pass with the change (and on main): agc_driver_resource_cache_storage_admission, agc_driver_resource_cache_oversized_storage_admission, agc_driver_resource_cache_storage_clear, agc_driver_resource_cache_replaced_texture, agc_driver_resource_cache_lookup_changed, agc_driver_resource_cache_growth, agc_driver_sampled_cache_budget, agc_driver_sampled_cache_budget_memory, agc_driver_sampled_cache_budget_without_storage_image_multisample, agc_driver_lookup_log_fits_build, agc_driver_partially_resident_snapshot, agc_driver_partially_resident_pending_stores, agc_driver_draw_cache_reuse and its _draw_pipeline, _entry_verify, _inline, _off and _verify variants, agc_driver_graphics.

With ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (VK_LOADER_DEBUG=layer showing the layer inserted), ctest -R <those tests> -V passes on main f1efa4ddc (19 of 19) and on this head (20 of 20, with the new test); both logs show the layer inserted, neither contains was not found but was requested by env var VK_INSTANCE_LAYERS, and neither contains a VUID- line (0 on main, 0 on the head).

PPSA31327 01.015.000, gameplay in Kamurocho, scripted boot through the first dialogue, 1920x1080, APS5_DRAW_PIPELINE=1 APS5_DRAW_INPUTS_IN_PLACE=1 APS5_PROFILE_DRAW=1, one run of 270 s on main f616a1397 + #8098 (the title's audio fix) with this PR's driver (a reading of the counters, not a timing claim); means of the last 15 [rescache] windows (steady gameplay, 49 presents and 403,000 draws per 10 s):

per 10 s value
Revalidate calls, time 63,600, 1,709 ms
fast proofs / full walks 31,300 / 32,300
fast-fail by reason collect 24,900, memory changed 95
full walk time by the reason that sent it there collect 627 ms, audit 100 ms, memory changed 6 ms
collect refusals sampled 24,900, storage 0
by cause uncommitted pages 0, unwatched 24,900, other 0
distinct surfaces, bytes 123, 13.0 MiB

So every refused collect in this title is a sampled surface that lies outside the write tracker: on Windows the tracker covers the whole arena span, so unwatched means the surface overlaps a host region, memory the title obtained outside the guest arena. About 500 draws per frame sample one of some 123 such surfaces, the fast proof cannot stamp them, and each of those draws repeats the lookups: 627 ms per 10 s, 6 % of the draw committer's time, with the sampled cache itself already keeping these snapshots by the write-watch hint ([textures]: 294,000 untracked snapshots kept by the hint, 100 compared, over the run). A follow-up can give the fast proof the same hint for untracked surfaces; this PR only makes the numbers visible.

One steady window as printed
[rescache] revalidate (10 s): 63690 calls 1711.4 ms: fast 31307, full 32383, failed 0; fast-fail by reason: collect 24983 memory changed 94; full walks: T1 refreshed 0 (0 storage images, 0 view sources, 0 views served by their own pending source, 0 overlaps left by the refresh accepted), full by reason: collect 24983 memory changed 94 audit 7306, T1 fallback by reason:, proofs verified 0; fast-fail pending image: own 0 (the query excepts the own object), foreign 0, snapshot 0, T1 eligible 0; keys proven: 78718 sampled, 0 storage; epoch gate: 1223 registry scans skipped, 63648 import loops skipped; lookup log: 0 builds and full walks kept their records past the bound; full walk ms by reason: collect 636.6 memory changed 5.6 audit 98.8; collect refusals: sampled 24983, storage 0 (uncommitted pages 0, unwatched 24983, other 0) over 124 surfaces, 13.2 MiB

tools/check_conventions.py --base origin/main passes.

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 (PPSA31327 #6722 is the title the numbers come from)
  • GPUs tested: NVIDIA GeForce RTX 4070, driver 621.01, Windows 11 Pro 26200
  • AI-assisted: yes.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5022576106 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11550). Originally posted by [johandavidcm](https://github.com/johandavidcm) on 2026-10-26T18:24:34Z. --- ### What A template's fast proof (`ShaderResources::fastRevalidate`) leaves the object to the full walk when `GuestMemory::CollectWrites` returns 0 for one of its surfaces, which the `[rescache]` line counts as the fast-fail reason `collect`. In Yakuza 0 Director's Cut (PPSA31327) that reason sends 23,700 of 31,400 full walks per 10 s, and the revalidation total is 1,700 ms per 10 s of the draw committer, but the line says nothing about why the collect was refused, how many surfaces are behind it, or what the full walks that follow cost. `CollectWrites` returns 0 only when the page walk fails: the range has pages that are not committed, or pages the arena compares instead of watching. With `APS5_PROFILE_DRAW=1`, no behaviour change: - Each collect refusal is counted by element kind (a sampled surface, a storage image) and by cause: the range has uncommitted pages (`GuestMemory::Accessible` is false), it is outside the write tracker (`GuestMemory::Watched` is false), or neither (`other`); the distinct surfaces refused in the report window and their bytes are counted too (at most 65,536 distinct addresses are kept per window). - The full walks are timed by the fast-fail reason that sent them there. - The `[rescache] revalidate` line gains `full walk ms by reason: ...` and `collect refusals: sampled N, storage M (uncommitted pages U, unwatched W, other O) over S surfaces, X MiB`. Tests read the same counters through `ShaderResources::CollectRefusalCounts()` and `ShaderResources::FullWalkNanoseconds()`. ### Tested Windows 11 Pro 26200, WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`, head 49eecbcc8 on `main` f1efa4ddc. **New test `agc_driver_resource_cache_collect_refusals`** (`tests/execution/SampledCacheBudget.cpp`, mode `collect-refusals`): a sampled template and a storage-image template over a surface whose last page is reserved but not committed take the full walk; the counters must show two sampled refusals and one storage refusal, all three as `uncommitted pages`, one surface of the surface's bytes, and a non-zero full-walk time under `collect`; a sampled template over a surface the test allocated outside the guest arena (`VirtualAlloc`) must count one more sampled refusal as `unwatched` and a second surface; once the page is committed the proofs count no refusal. - Without the change it fails with `two collect refusals of a sampled surface were not counted`. - With the change it passes, also with `--repeat until-fail:20`. **Pass with the change** (and on `main`): `agc_driver_resource_cache_storage_admission`, `agc_driver_resource_cache_oversized_storage_admission`, `agc_driver_resource_cache_storage_clear`, `agc_driver_resource_cache_replaced_texture`, `agc_driver_resource_cache_lookup_changed`, `agc_driver_resource_cache_growth`, `agc_driver_sampled_cache_budget`, `agc_driver_sampled_cache_budget_memory`, `agc_driver_sampled_cache_budget_without_storage_image_multisample`, `agc_driver_lookup_log_fits_build`, `agc_driver_partially_resident_snapshot`, `agc_driver_partially_resident_pending_stores`, `agc_driver_draw_cache_reuse` and its `_draw_pipeline`, `_entry_verify`, `_inline`, `_off` and `_verify` variants, `agc_driver_graphics`. With `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (`VK_LOADER_DEBUG=layer` showing the layer inserted), `ctest -R <those tests> -V` passes on `main` f1efa4ddc (19 of 19) and on this head (20 of 20, with the new test); both logs show the layer inserted, neither contains `was not found but was requested by env var VK_INSTANCE_LAYERS`, and neither contains a `VUID-` line (0 on `main`, 0 on the head). **PPSA31327 01.015.000**, gameplay in Kamurocho, scripted boot through the first dialogue, 1920x1080, `APS5_DRAW_PIPELINE=1 APS5_DRAW_INPUTS_IN_PLACE=1 APS5_PROFILE_DRAW=1`, one run of 270 s on `main` f616a1397 + #8098 (the title's audio fix) with this PR's driver (a reading of the counters, not a timing claim); means of the last 15 `[rescache]` windows (steady gameplay, 49 presents and 403,000 draws per 10 s): | per 10 s | value | |---|---| | Revalidate calls, time | 63,600, 1,709 ms | | fast proofs / full walks | 31,300 / 32,300 | | fast-fail by reason | collect 24,900, memory changed 95 | | full walk time by the reason that sent it there | collect 627 ms, audit 100 ms, memory changed 6 ms | | collect refusals | sampled 24,900, storage 0 | | by cause | uncommitted pages 0, unwatched 24,900, other 0 | | distinct surfaces, bytes | 123, 13.0 MiB | So every refused collect in this title is a sampled surface that lies outside the write tracker: on Windows the tracker covers the whole arena span, so `unwatched` means the surface overlaps a host region, memory the title obtained outside the guest arena. About 500 draws per frame sample one of some 123 such surfaces, the fast proof cannot stamp them, and each of those draws repeats the lookups: 627 ms per 10 s, 6 % of the draw committer's time, with the sampled cache itself already keeping these snapshots by the write-watch hint (`[textures]`: 294,000 untracked snapshots kept by the hint, 100 compared, over the run). A follow-up can give the fast proof the same hint for untracked surfaces; this PR only makes the numbers visible. <details><summary>One steady window as printed</summary> ``` [rescache] revalidate (10 s): 63690 calls 1711.4 ms: fast 31307, full 32383, failed 0; fast-fail by reason: collect 24983 memory changed 94; full walks: T1 refreshed 0 (0 storage images, 0 view sources, 0 views served by their own pending source, 0 overlaps left by the refresh accepted), full by reason: collect 24983 memory changed 94 audit 7306, T1 fallback by reason:, proofs verified 0; fast-fail pending image: own 0 (the query excepts the own object), foreign 0, snapshot 0, T1 eligible 0; keys proven: 78718 sampled, 0 storage; epoch gate: 1223 registry scans skipped, 63648 import loops skipped; lookup log: 0 builds and full walks kept their records past the bound; full walk ms by reason: collect 636.6 memory changed 5.6 audit 98.8; collect refusals: sampled 24983, storage 0 (uncommitted pages 0, unwatched 24983, other 0) over 124 surfaces, 13.2 MiB ``` </details> `tools/check_conventions.py --base origin/main` passes. ### 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 (PPSA31327 #6722 is the title the numbers come from) - [x] GPUs tested: NVIDIA GeForce RTX 4070, driver 621.01, Windows 11 Pro 26200 - [x] AI-assisted: yes.
MarcZX10 commented 2026-10-26 18:49:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T18:49:28Z.

Review: APPROVED


Reviewed the profiling-only counters and the new focused test. Refusal classification follows Accessible then Watched, sampled/storage paths are counted separately, full-walk timing is indexed by the triggering fast-fail reason, and the distinct-address table is mutex-protected and explicitly capped as described. The regression test checks uncommitted, unwatched, same-surface aggregation, elapsed full-walk time, and recovery after committing the missing page. I did not rerun the Windows/Vulkan tests locally; the author reports the focused test passes 20 repeats and 20 other focused tests pass with validation on both main and this head, with no VUIDs. Current required eligibility, conventions, labels, and report checks pass. Intake returned HTTP 502 from GitHub Search, not a limit decision; I independently checked the current author queue (4 open, 4 merged), within the repository’s 20-open allowance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5657329400 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11550#pullrequestreview-5657329400). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T18:49:28Z. **Review:** APPROVED --- Reviewed the profiling-only counters and the new focused test. Refusal classification follows `Accessible` then `Watched`, sampled/storage paths are counted separately, full-walk timing is indexed by the triggering fast-fail reason, and the distinct-address table is mutex-protected and explicitly capped as described. The regression test checks uncommitted, unwatched, same-surface aggregation, elapsed full-walk time, and recovery after committing the missing page. I did not rerun the Windows/Vulkan tests locally; the author reports the focused test passes 20 repeats and 20 other focused tests pass with validation on both main and this head, with no VUIDs. Current required eligibility, conventions, labels, and report checks pass. Intake returned HTTP 502 from GitHub Search, not a limit decision; I independently checked the current author queue (4 open, 4 merged), within the repository’s 20-open allowance.
MarcZX10 commented 2026-10-26 18:51:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T18:51:56Z.

Review: CHANGES_REQUESTED


A new overlap report identifies two still-open PRs touching lines changed here: #9884 overlaps the sampled-cache test insertion, and #10894 overlaps ShaderResources.hpp/ShaderResources.cpp. Both still declare Depends on: none. CONTRIBUTING.md requires the authors to agree on merge order for reported overlaps and record the dependency where one PR must land first. Please coordinate with those authors and update the order/dependency before this is merge-ready. The functional review above remains positive; my earlier approval is superseded until this repository requirement is resolved.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5657364343 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11550#pullrequestreview-5657364343). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T18:51:56Z. **Review:** CHANGES_REQUESTED --- A new overlap report identifies two still-open PRs touching lines changed here: #9884 overlaps the sampled-cache test insertion, and #10894 overlaps `ShaderResources.hpp`/`ShaderResources.cpp`. Both still declare `Depends on: none`. `CONTRIBUTING.md` requires the authors to agree on merge order for reported overlaps and record the dependency where one PR must land first. Please coordinate with those authors and update the order/dependency before this is merge-ready. The functional review above remains positive; my earlier approval is superseded until this repository requirement is resolved.
adriadam10 commented 2026-10-28 08:41:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-28T08:41:58Z.

Review: CHANGES_REQUESTED


Read the diff: the counters are profile-only (APS5_PROFILE_DRAW), the refused-surface table is bounded and locked, the full-walk time is indexed by the triggering fast-fail reason, and agc_driver_resource_cache_collect_refusals is registered and reads counters that only exist with this change. No code changes needed from our side.

  • The only open point is @MarcZX10's CHANGES_REQUESTED on this head about the overlap with #9884 and #10894 (both still open). Your proposed order (this lands after both, you rebase) answers it; it needs that reviewer to lift the request, or those two to merge first, before this can be merged.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5679896468 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11550#pullrequestreview-5679896468). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-28T08:41:58Z. **Review:** CHANGES_REQUESTED --- Read the diff: the counters are profile-only (`APS5_PROFILE_DRAW`), the refused-surface table is bounded and locked, the full-walk time is indexed by the triggering fast-fail reason, and `agc_driver_resource_cache_collect_refusals` is registered and reads counters that only exist with this change. No code changes needed from our side. - The only open point is @MarcZX10's CHANGES_REQUESTED on this head about the overlap with #9884 and #10894 (both still open). Your proposed order (this lands after both, you rebase) answers it; it needs that reviewer to lift the request, or those two to merge first, before this can be merged.
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!11550
No description provided.