perf(agc): answer a write-watch collect from a per-block observation table #17766

Merged
chitters2004 merged 4 commits from upstream-pr/17766 into main 2026-11-14 11:45:55 +00:00
chitters2004 commented 2026-11-09 15:07:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by chitters2004 on 2026-11-09T15:07:22Z.


What

One owner now answers "has this guest memory been observed since collect epoch e" for every write-watch collect. A per-64 KiB block tick table (coarse minimum per 4 MiB) records the epoch at which each block was last walked. A collect whose blocks all carry a tick at or after its epoch returns stable without an OS query, whichever thread made the earlier walk; stale blocks merge into runs, one OS call per run. Only a Complete walk publishes; refused, uncovered and failed walks publish nothing. The unwatch serial and mapping generation stay conditions of a hit. The per-thread ring, the epoch collect map and the shared ring are retired (APS5_NO_EPOCH_COLLECT_MAP, APS5_SHARED_COLLECT_MEMO removed, with the two tests that ran those modes, agc_collect_mapping_history_ring and agc_collect_mapping_history_shared). Uncached collects stay uncached and publish.

Overlaps: #9508 and #17697 touch a few lines of the same test file and docs/dev/ENVIRONMENT.md. Whichever lands second, I rebase this one.

Tested

Windows (RTX 3080, driver 621.14), head cb1632e7ff on main 6773f91a7e. agc_collect_memo_generation, agc_collect_coverage_* (#17542's tests, unchanged), agc_collect_mapping_history_*, agc_shared_write* and agc_write_tracking* pass; the new tests are red on main (two owners in one epoch cause one OS walk) and have a negative control. Seven mutants each turned the Windows test red on the earlier head (hit returns raw generation, publish on Refused, publish before stamps, ignore the unwatch serial, accept an older epoch, partial 4 MiB group answered whole, two forms); not rerun on this head, not run on Linux. Linux (WSL) tests not run on this head.
Gate on cb1632e7ff (ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, same machine and GPU), pattern covering the touched tests, agc_driver_frame_replay* and the write-tracking tests: plain main 279/279, change 277/277 (two removed variant tests); with APS5_DRAW_PIPELINE=1 APS5_PIPELINED_DRAWS=32 APS5_PIPELINE_DISPATCH=1 main 277/279, change 275/277 with the same two failures on both sides (agc_driver_draw_recapture_on_change, agc_driver_draw_unsupported_buffer_type_skip_refused). No VUID- in any ctest log or subprocess .log, no missing-layer line.
rk4 replay (7,745 draws per pass), A = replay kit (main + replay PRs), B = A plus this commit, --repeat 5 --no-pace, the three pipeline variables, passes 2-5, A B B A A B B A A B, run twice (parent head 882d1414b4, then cb1632e7ff): commit_us_per_draw 42.79 -> 41.30, delta -1.49 +/- 0.66 us, and 42.74 -> 41.29, delta -1.45 +/- 0.72 us (95% CI, 5 runs each, sd 0.2-0.7); committer CPU per draw and the timed window are within noise. Pixels identical, max channel diff 0, in all 20 runs. A profiled run per side: walking collects 39,214 -> 38,656, memo hits 260,959 -> 262,486 (cumulative over the run). Remaining repeat walks come from uncached callers, which this PR leaves alone.
Live GTA V (PPSA04263, save play1-first-autosave, 3840x2160, RTX 3080, driver 621.14, Windows 11, Ryzen 7 5800X, APS5_TRACE_SECONDS=235:30 with the three pipeline variables): main 6773f91a7e (A) against this head cb1632e7ff (B), one discarded warm-up boot per side, then pairs A B, B A, A B (fresh boot each, preflight, one timing claim; every line dirty: false; trace events dropped in every capture). Mean ms per frame A 125.63, 130.16, 129.87 (sd 2.54); B 126.86, 124.18, 130.48 (sd 3.16). Pair deltas B-A +1.23, -5.98, +0.61, mean -1.38 ms/frame (-1.1 %), inside the noise of both sides; at about 3,040 draws per frame (assumed, the summary has no draw count) that is -0.45 us per draw (-1.97 to +0.40). Driver.Draw.prepare mean delta -0.21 ms, Driver.Draw -0.19, Graphics.Draw -0.92; CopyDrawInput is not in the top-8 phases. No frame-time claim. Traces and summaries: https://github.com/chitters2004/AnyPS5/releases/tag/pr-obs-t7

Summary line, main 6773f91a7e (first timed A):

{"commit":"6773f91a7e60","dirty":false,"env":{"APS5_ADDRESS_COPY_MAX_MIB":"512","APS5_DRAW_PIPELINE":"1","APS5_DUMP_FRAMES":"80","APS5_DUMP_FRAMES_EVERY":"300","APS5_LOG_TIMESTAMPS":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_PIPELINED_DRAWS":"32","APS5_PIPELINE_DISPATCH":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"235:30","APS5_TRACE_SUMMARY_EVERY":"10","APS5_VIDEOOUT_TELEMETRY_DIR":"<path>"},"gpu":"NVIDIA GeForce RTX 3080","driver":"NVIDIA 621.14","os":"Windows 10.0.26320","cpu":"AMD Ryzen 7 5800X 8-Core Processor","cpu_threads":16,"memory_mib":32676,"title_id":"PPSA04263","title":"Grand Theft Auto V","content_version":"01.011.001","resolution":"3840x2160","window":{"spec":"seconds 235:30","first_present":4225,"ms":30025.494},"presents":239,"frame_ms":{"p50":125.132,"p90":129.212,"p99":146.037,"max":149.981},"gpu_busy_ms_per_present":33.073,"worker_busy_pct":{"queue worker 0x0":93.753},"top_phases_ms_per_frame":{"Driver.Packet":111.126,"Graphics.Draw":96.41,"Driver.Packet.draw":82.003,"Driver.Draw":81.403,"Graphics.Draw.draw_and_resource_release":75.415,"Driver.DrawFinish":73.226,"Driver.Draw.prepare":65.533,"Driver.DrawFinish.draw_enqueued":40.946},"owned_draw_counts":{"OwnedDraw.arm_attempt":717,"OwnedDraw.arm_blocks_requested":717,"OwnedDraw.arm_refused":717,"OwnedDraw.evicted_other":2139},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":5.495,"events_lost":1164358,"totals_full":false},"draw committer":{"events_full_after_s":10.575,"events_lost":480033,"totals_full":false},"draw finisher":{"events_full_after_s":15.4,"events_lost":243236,"totals_full":false}},"trace":"aps5-trace-6773f91a7e60-14924.json.gz"}

Summary line, cb1632e7ff (first timed B):

{"commit":"cb1632e7ff79","dirty":false,"env":{"APS5_ADDRESS_COPY_MAX_MIB":"512","APS5_DRAW_PIPELINE":"1","APS5_DUMP_FRAMES":"80","APS5_DUMP_FRAMES_EVERY":"300","APS5_LOG_TIMESTAMPS":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_PIPELINED_DRAWS":"32","APS5_PIPELINE_DISPATCH":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"235:30","APS5_TRACE_SUMMARY_EVERY":"10","APS5_VIDEOOUT_TELEMETRY_DIR":"<path>"},"gpu":"NVIDIA GeForce RTX 3080","driver":"NVIDIA 621.14","os":"Windows 10.0.26320","cpu":"AMD Ryzen 7 5800X 8-Core Processor","cpu_threads":16,"memory_mib":32676,"title_id":"PPSA04263","title":"Grand Theft Auto V","content_version":"01.011.001","resolution":"3840x2160","window":{"spec":"seconds 235:30","first_present":4214,"ms":30066.564},"presents":237,"frame_ms":{"p50":125.59,"p90":130.811,"p99":171.329,"max":238.496},"gpu_busy_ms_per_present":33.31,"worker_busy_pct":{"queue worker 0x0":95.011},"top_phases_ms_per_frame":{"Driver.Packet":114.307,"Graphics.Draw":97.635,"Driver.Packet.draw":84.164,"Driver.Draw":83.542,"Graphics.Draw.draw_and_resource_release":77.212,"Driver.DrawFinish":73.969,"Driver.Draw.prepare":67.409,"Driver.DrawFinish.draw_enqueued":40.684},"owned_draw_counts":{"OwnedDraw.arm_attempt":711,"OwnedDraw.arm_blocks_requested":711,"OwnedDraw.arm_refused":711,"OwnedDraw.evicted_other":2455},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":5.434,"events_lost":1179664,"totals_full":false},"draw committer":{"events_full_after_s":10.379,"events_lost":490498,"totals_full":false},"draw finisher":{"events_full_after_s":15.254,"events_lost":251270,"totals_full":false}},"trace":"aps5-trace-cb1632e7ff79-28820.json.gz"}

Sub-block collects that cannot widen are kept exactly in a 16-entry ring under the tracker lock, so they walk once per epoch as under #17542's interval map. agc_collect_memo_generation has a case for it (fake write watch that refuses ranges above 16 KiB: red on the parent head, "a sub-block collect that could not widen reached the write watch again in one epoch"; Linux only, the Windows case needs an uncommitted neighbour page). Fork CI (Linux, run 42628752351): the collect, shared-write and write-tracking tests pass, no new VUID, and four mutants of the new lines (no record, ignore tick, accept a partial overlap, ignore the floor) are killed. The Windows gate below was rerun on cb1632e7ff.

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: AGC gate on NVIDIA GeForce RTX 3080, driver 621.14, Windows 11
  • AI-assisted: yes

Known gap (not fixed here): a depth retirement can see a cached hit where an uncached observation is needed (DepthSurface.cpp WrittenUnits before retireStoringStale). It exists on main for one thread and is fixed at the caller by #16368; this PR does not change the caller.

Overlaps in GuestMemory.cpp: #12745, #16897, #16368 (caller-side depth retirement).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5226085149 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17766). Originally posted by [chitters2004](https://github.com/chitters2004) on 2026-11-09T15:07:22Z. --- ### What One owner now answers "has this guest memory been observed since collect epoch e" for every write-watch collect. A per-64 KiB block tick table (coarse minimum per 4 MiB) records the epoch at which each block was last walked. A collect whose blocks all carry a tick at or after its epoch returns `stable` without an OS query, whichever thread made the earlier walk; stale blocks merge into runs, one OS call per run. Only a Complete walk publishes; refused, uncovered and failed walks publish nothing. The unwatch serial and mapping generation stay conditions of a hit. The per-thread ring, the epoch collect map and the shared ring are retired (`APS5_NO_EPOCH_COLLECT_MAP`, `APS5_SHARED_COLLECT_MEMO` removed, with the two tests that ran those modes, `agc_collect_mapping_history_ring` and `agc_collect_mapping_history_shared`). Uncached collects stay uncached and publish. Overlaps: #9508 and #17697 touch a few lines of the same test file and `docs/dev/ENVIRONMENT.md`. Whichever lands second, I rebase this one. ### Tested Windows (RTX 3080, driver 621.14), head cb1632e7ff on main 6773f91a7e. `agc_collect_memo_generation`, `agc_collect_coverage_*` (#17542's tests, unchanged), `agc_collect_mapping_history_*`, `agc_shared_write*` and `agc_write_tracking*` pass; the new tests are red on main (two owners in one epoch cause one OS walk) and have a negative control. Seven mutants each turned the Windows test red on the earlier head (hit returns raw generation, publish on Refused, publish before stamps, ignore the unwatch serial, accept an older epoch, partial 4 MiB group answered whole, two forms); not rerun on this head, not run on Linux. Linux (WSL) tests not run on this head. Gate on cb1632e7ff (`ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, same machine and GPU), pattern covering the touched tests, `agc_driver_frame_replay*` and the write-tracking tests: plain main 279/279, change 277/277 (two removed variant tests); with `APS5_DRAW_PIPELINE=1 APS5_PIPELINED_DRAWS=32 APS5_PIPELINE_DISPATCH=1` main 277/279, change 275/277 with the same two failures on both sides (`agc_driver_draw_recapture_on_change`, `agc_driver_draw_unsupported_buffer_type_skip_refused`). No `VUID-` in any ctest log or subprocess `.log`, no missing-layer line. rk4 replay (7,745 draws per pass), A = replay kit (main + replay PRs), B = A plus this commit, `--repeat 5 --no-pace`, the three pipeline variables, passes 2-5, A B B A A B B A A B, run twice (parent head 882d1414b4, then cb1632e7ff): `commit_us_per_draw` 42.79 -> 41.30, delta -1.49 +/- 0.66 us, and 42.74 -> 41.29, delta -1.45 +/- 0.72 us (95% CI, 5 runs each, sd 0.2-0.7); committer CPU per draw and the timed window are within noise. Pixels identical, max channel diff 0, in all 20 runs. A profiled run per side: walking collects 39,214 -> 38,656, memo hits 260,959 -> 262,486 (cumulative over the run). Remaining repeat walks come from uncached callers, which this PR leaves alone. Live GTA V (PPSA04263, save `play1-first-autosave`, 3840x2160, RTX 3080, driver 621.14, Windows 11, Ryzen 7 5800X, `APS5_TRACE_SECONDS=235:30` with the three pipeline variables): main `6773f91a7e` (A) against this head `cb1632e7ff` (B), one discarded warm-up boot per side, then pairs A B, B A, A B (fresh boot each, preflight, one timing claim; every line `dirty: false`; trace events dropped in every capture). Mean ms per frame A 125.63, 130.16, 129.87 (sd 2.54); B 126.86, 124.18, 130.48 (sd 3.16). Pair deltas B-A +1.23, -5.98, +0.61, mean -1.38 ms/frame (-1.1 %), inside the noise of both sides; at about 3,040 draws per frame (assumed, the summary has no draw count) that is -0.45 us per draw (-1.97 to +0.40). `Driver.Draw.prepare` mean delta -0.21 ms, `Driver.Draw` -0.19, `Graphics.Draw` -0.92; `CopyDrawInput` is not in the top-8 phases. No frame-time claim. Traces and summaries: https://github.com/chitters2004/AnyPS5/releases/tag/pr-obs-t7 Summary line, main 6773f91a7e (first timed A): ```json {"commit":"6773f91a7e60","dirty":false,"env":{"APS5_ADDRESS_COPY_MAX_MIB":"512","APS5_DRAW_PIPELINE":"1","APS5_DUMP_FRAMES":"80","APS5_DUMP_FRAMES_EVERY":"300","APS5_LOG_TIMESTAMPS":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_PIPELINED_DRAWS":"32","APS5_PIPELINE_DISPATCH":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"235:30","APS5_TRACE_SUMMARY_EVERY":"10","APS5_VIDEOOUT_TELEMETRY_DIR":"<path>"},"gpu":"NVIDIA GeForce RTX 3080","driver":"NVIDIA 621.14","os":"Windows 10.0.26320","cpu":"AMD Ryzen 7 5800X 8-Core Processor","cpu_threads":16,"memory_mib":32676,"title_id":"PPSA04263","title":"Grand Theft Auto V","content_version":"01.011.001","resolution":"3840x2160","window":{"spec":"seconds 235:30","first_present":4225,"ms":30025.494},"presents":239,"frame_ms":{"p50":125.132,"p90":129.212,"p99":146.037,"max":149.981},"gpu_busy_ms_per_present":33.073,"worker_busy_pct":{"queue worker 0x0":93.753},"top_phases_ms_per_frame":{"Driver.Packet":111.126,"Graphics.Draw":96.41,"Driver.Packet.draw":82.003,"Driver.Draw":81.403,"Graphics.Draw.draw_and_resource_release":75.415,"Driver.DrawFinish":73.226,"Driver.Draw.prepare":65.533,"Driver.DrawFinish.draw_enqueued":40.946},"owned_draw_counts":{"OwnedDraw.arm_attempt":717,"OwnedDraw.arm_blocks_requested":717,"OwnedDraw.arm_refused":717,"OwnedDraw.evicted_other":2139},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":5.495,"events_lost":1164358,"totals_full":false},"draw committer":{"events_full_after_s":10.575,"events_lost":480033,"totals_full":false},"draw finisher":{"events_full_after_s":15.4,"events_lost":243236,"totals_full":false}},"trace":"aps5-trace-6773f91a7e60-14924.json.gz"} ``` Summary line, cb1632e7ff (first timed B): ```json {"commit":"cb1632e7ff79","dirty":false,"env":{"APS5_ADDRESS_COPY_MAX_MIB":"512","APS5_DRAW_PIPELINE":"1","APS5_DUMP_FRAMES":"80","APS5_DUMP_FRAMES_EVERY":"300","APS5_LOG_TIMESTAMPS":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_PIPELINED_DRAWS":"32","APS5_PIPELINE_DISPATCH":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"235:30","APS5_TRACE_SUMMARY_EVERY":"10","APS5_VIDEOOUT_TELEMETRY_DIR":"<path>"},"gpu":"NVIDIA GeForce RTX 3080","driver":"NVIDIA 621.14","os":"Windows 10.0.26320","cpu":"AMD Ryzen 7 5800X 8-Core Processor","cpu_threads":16,"memory_mib":32676,"title_id":"PPSA04263","title":"Grand Theft Auto V","content_version":"01.011.001","resolution":"3840x2160","window":{"spec":"seconds 235:30","first_present":4214,"ms":30066.564},"presents":237,"frame_ms":{"p50":125.59,"p90":130.811,"p99":171.329,"max":238.496},"gpu_busy_ms_per_present":33.31,"worker_busy_pct":{"queue worker 0x0":95.011},"top_phases_ms_per_frame":{"Driver.Packet":114.307,"Graphics.Draw":97.635,"Driver.Packet.draw":84.164,"Driver.Draw":83.542,"Graphics.Draw.draw_and_resource_release":77.212,"Driver.DrawFinish":73.969,"Driver.Draw.prepare":67.409,"Driver.DrawFinish.draw_enqueued":40.684},"owned_draw_counts":{"OwnedDraw.arm_attempt":711,"OwnedDraw.arm_blocks_requested":711,"OwnedDraw.arm_refused":711,"OwnedDraw.evicted_other":2455},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":5.434,"events_lost":1179664,"totals_full":false},"draw committer":{"events_full_after_s":10.379,"events_lost":490498,"totals_full":false},"draw finisher":{"events_full_after_s":15.254,"events_lost":251270,"totals_full":false}},"trace":"aps5-trace-cb1632e7ff79-28820.json.gz"} ``` Sub-block collects that cannot widen are kept exactly in a 16-entry ring under the tracker lock, so they walk once per epoch as under #17542's interval map. `agc_collect_memo_generation` has a case for it (fake write watch that refuses ranges above 16 KiB: red on the parent head, "a sub-block collect that could not widen reached the write watch again in one epoch"; Linux only, the Windows case needs an uncommitted neighbour page). Fork CI (Linux, run 42628752351): the collect, shared-write and write-tracking tests pass, no new VUID, and four mutants of the new lines (no record, ignore tick, accept a partial overlap, ignore the floor) are killed. The Windows gate below was rerun on cb1632e7ff. ### Checklist - [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: AGC gate on NVIDIA GeForce RTX 3080, driver 621.14, Windows 11 - [x] AI-assisted: yes Known gap (not fixed here): a depth retirement can see a cached hit where an uncached observation is needed (`DepthSurface.cpp` `WrittenUnits` before `retireStoringStale`). It exists on main for one thread and is fixed at the caller by #16368; this PR does not change the caller. Overlaps in `GuestMemory.cpp`: #12745, #16897, #16368 (caller-side depth retirement). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!17766
No description provided.