perf(agc): publish storage-image results into resident heap mirrors #17796

Merged
ashwin280802 merged 6 commits from upstream-pr/17796 into main 2026-11-19 09:11:18 +00:00
ashwin280802 commented 2026-11-09 16:31:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ashwin280802 on 2026-11-09T16:31:28Z.


What

When an address-based build refreshes a resident heap mirror, pending storage images inside it are no longer stored back to guest memory first. Their pending units are retiled on the GPU into the mirror, so the build reads the results without a CPU round trip. The images stay pending: a hooked CPU read, a label or an idle store writes guest memory as before. Blocks the CPU or another store wrote since a unit's generation are left out, as in the write-back. DCC keys that do not read uncompressed, partly drawn rectangles, read traps, unwatched memory, copied heap mirrors and ranges the build itself writes fall back to the old store. APS5_NO_MIRROR_PUBLISH=1 restores the old path; the debt entry lists what stays unproven.

Overlap: 79 open PRs could not be checked automatically. By title none implements this; #13251 (storage image units on the device) is closest, and #15296 touches the same mirror code.

Tested

Windows 11 10.0.26300, MinGW UCRT64 GCC, NVIDIA GeForce RTX 5070 (driver 617.42), commit faf7f5a2650481abb11e5392d7267cb9d76b7739.

ctest --test-dir build-full -R "^agc_driver_(resident_heap_mirror|address_draw_space_reuse)" --output-on-failure

2/7 Test #1740: agc_driver_resident_heap_mirror ...................   Passed    0.69 sec
7/7 Test #2463: agc_driver_resident_heap_mirror_no_publish ........   Passed    0.58 sec
100% tests passed out of 7

The tests check that a published image leaves guest memory untouched yet reads back through the hook, that unchanged rebuilds skip the publish, that CPU writes win, that DCC images with uncompressed keys publish and that writable and copied mirrors fall back; _no_publish is the negative control.

With ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, the same tests on main (9d2e737432, built here) and the change; the new negative control has no main counterpart and ran on the change alone:

RESULT: PASS
layer: loaded
diagnostics: change 0, baseline 0, new 0

The full Windows suite passed except tests that also fail on main here (vulkan_validation_gate_commands; guest_timed_join_import_libkernel_web, fixed on main by 07572f5d1c). Linux (llvmpipe, 0 failures) and ASan ran on the revision before the last two fixes, not on this commit. I changed 20 conditions one at a time: 10 failed the tests, 1 did not build; of the other 9, five are equivalent, diagnostic or lifetime guards and four are the untested paths below.

Speed, Jusant (PPSA10264). It needs #8089 to run, so both sides are one build of this patch on top of #8089 with publishing on and off (APS5_NO_MIRROR_PUBLISH=1 stores as main does). Measured on the revision before the last fix, which only changes what happens when a mirror is evicted during the build.

Guest flips per 10 s, ABBA:

Run Mode Last 6 Windows (Flips / 10 s) Mean Presents Equal Flips
01-change Change 32, 31, 31, 32, 31, 31 31.3 True
02-off Publishing off 14, 14, 14, 14, 14, 14 14.0 True
03-off Publishing off 14, 14, 14, 14, 14, 15 14.2 True
04-change Change 29, 28, 28, 28, 28, 28 28.2 True

APS5_TRACE_SECONDS=200:20 captures, warm caches, no other trace or profile switch (tools/trace_digest.py):

Mode Present Window Presents (20 s) Frame p50 Frame p90 Frame p99 Max GPU Busy (ms/present)
Change seconds 200:20 from present 348 57 351.9 ms 374.2 ms 545.9 ms 545.9 ms 147.6 ms
Publishing off seconds 200:20 from present 153 30 672.7 ms 692.6 ms 729.9 ms 729.9 ms 151.6 ms

Phase breakdown (draw committer thread):

Mode Phase Duration (% Frame) Self (%) Slices Wait Sub-phases
Change draw committer 176.0 ms (49 %) 35.9 ms (10 %) 143.9 1.7 Graphics.Draw 101.4, Recorder.Sync 81.0
Publishing off draw committer 422.6 ms (63 %) 111.9 ms (17 %) 137.5 2.3 Graphics.Draw 368.9, Recorder.Sync 133.4

Change first, publishing off second. GPU time is unchanged; the gain is the CPU store-backs the build no longer waits for. Traces: change aps5-trace-475c6eb5d3ff-25588.json.gz, publishing off aps5-trace-475c6eb5d3ff-43440.json.gz.

Summary lines (aps5-summary.jsonl, one per capture, in the order above):

{"commit":"475c6eb5d3ff","dirty":false,"env":{"APS5_PLAYGO_UNLISTED_CHUNKS":"absent","APS5_TRACE_SECONDS":"200:20"},"gpu":"NVIDIA GeForce RTX 5070","driver":"NVIDIA 617.42","os":"Windows 10.0.26300","cpu":"Intel(R) Core(TM) i5-14600K","cpu_threads":20,"memory_mib":16147,"title_id":"PPSA10264","title":"Jusant","content_version":"02.000.000","resolution":"3840x2160","window":{"spec":"seconds 200:20","first_present":348,"ms":20280.093},"presents":57,"frame_ms":{"p50":351.917,"p90":374.204,"p99":545.87,"max":545.87},"gpu_busy_ms_per_present":147.635,"worker_busy_pct":{"queue worker 0x0":98.335,"queue worker 0x20":75.629},"top_phases_ms_per_frame":{"Driver.Packet":613.356,"Driver.Packet.dispatch":293.082,"Driver.Dispatch":185.387,"Recorder.Sync":137.559,"Graphics.Draw":111.687,"Graphics.Draw.draw_and_resource_release":104.057,"Resources.Complete":88.254,"Driver.Packet.prepare_memory":85.999},"trace_dropped":false,"trace":"aps5-trace-475c6eb5d3ff-25588.json.gz"}
{"commit":"9d2e737432d","dirty":false,"env":{"APS5_PLAYGO_UNLISTED_CHUNKS":"absent","APS5_TRACE_SECONDS":"200:20"},"gpu":"NVIDIA GeForce RTX 5070","driver":"NVIDIA 617.42","os":"Windows 10.0.26300","cpu":"Intel(R) Core(TM) i5-14600K","cpu_threads":20,"memory_mib":16147,"title_id":"PPSA10264","title":"Jusant","content_version":"02.000.000","resolution":"3840x2160","window":{"spec":"seconds 200:20","first_present":153,"ms":20161.35},"presents":30,"frame_ms":{"p50":672.733,"p90":692.634,"p99":729.904,"max":729.904},"gpu_busy_ms_per_present":151.647,"worker_busy_pct":{"queue worker 0x0":97.477,"queue worker 0x20":66.991},"top_phases_ms_per_frame":{"Driver.Packet":1099.931,"Driver.Packet.dispatch":461.8,"Graphics.Draw":379.564,"Graphics.Draw.draw_and_resource_release":372.194,"Driver.Dispatch":272.052,"Driver.Packet.pipeline_drain":184.101,"Driver.Packet.prepare_memory":181.467,"Recorder.Sync":176.318},"trace_dropped":false,"trace":"aps5-trace-475c6eb5d3ff-43440.json.gz"}

Not verified: on a console; on GPUs other than this one; Jusant on plain main (it does not run without #8089).
Not covered by a test: the publish drain of a reused address-based build (GuestBufferMemory::RecordStagingCopies); a heap mirror evicted by the same build after an image was deferred into it (the publish then finds the mirror gone by base and serial and stores the image instead); images outside the write watch, array layers, multiple mips, edge blocks and memo eviction. Devices without sparse residency never publish; there the negative control skips.

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, driver 617.42, Windows 11 10.0.26300
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5227345311 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17796). Originally posted by [ashwin280802](https://github.com/ashwin280802) on 2026-11-09T16:31:28Z. --- ### What When an address-based build refreshes a resident heap mirror, pending storage images inside it are no longer stored back to guest memory first. Their pending units are retiled on the GPU into the mirror, so the build reads the results without a CPU round trip. The images stay pending: a hooked CPU read, a label or an idle store writes guest memory as before. Blocks the CPU or another store wrote since a unit's generation are left out, as in the write-back. DCC keys that do not read uncompressed, partly drawn rectangles, read traps, unwatched memory, copied heap mirrors and ranges the build itself writes fall back to the old store. `APS5_NO_MIRROR_PUBLISH=1` restores the old path; the debt entry lists what stays unproven. Overlap: 79 open PRs could not be checked automatically. By title none implements this; #13251 (storage image units on the device) is closest, and #15296 touches the same mirror code. ### Tested Windows 11 10.0.26300, MinGW UCRT64 GCC, NVIDIA GeForce RTX 5070 (driver 617.42), commit faf7f5a2650481abb11e5392d7267cb9d76b7739. `ctest --test-dir build-full -R "^agc_driver_(resident_heap_mirror|address_draw_space_reuse)" --output-on-failure` ``` 2/7 Test #1740: agc_driver_resident_heap_mirror ................... Passed 0.69 sec 7/7 Test #2463: agc_driver_resident_heap_mirror_no_publish ........ Passed 0.58 sec 100% tests passed out of 7 ``` The tests check that a published image leaves guest memory untouched yet reads back through the hook, that unchanged rebuilds skip the publish, that CPU writes win, that DCC images with uncompressed keys publish and that writable and copied mirrors fall back; `_no_publish` is the negative control. With `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, the same tests on main (9d2e737432d, built here) and the change; the new negative control has no main counterpart and ran on the change alone: ``` RESULT: PASS layer: loaded diagnostics: change 0, baseline 0, new 0 ``` The full Windows suite passed except tests that also fail on main here (`vulkan_validation_gate_commands`; `guest_timed_join_import_libkernel_web`, fixed on main by 07572f5d1c6). Linux (llvmpipe, 0 failures) and ASan ran on the revision before the last two fixes, not on this commit. I changed 20 conditions one at a time: 10 failed the tests, 1 did not build; of the other 9, five are equivalent, diagnostic or lifetime guards and four are the untested paths below. Speed, [Jusant (PPSA10264)](https://github.com/boykopovar/AnyPS5/discussions/12317). It needs #8089 to run, so both sides are one build of this patch on top of #8089 with publishing on and off (`APS5_NO_MIRROR_PUBLISH=1` stores as main does). Measured on the revision before the last fix, which only changes what happens when a mirror is evicted during the build. Guest flips per 10 s, ABBA: | Run | Mode | Last 6 Windows (Flips / 10 s) | Mean | Presents Equal Flips | | :--- | :--- | :--- | :--- | :--- | | `01-change` | Change | 32, 31, 31, 32, 31, 31 | 31.3 | True | | `02-off` | Publishing off | 14, 14, 14, 14, 14, 14 | 14.0 | True | | `03-off` | Publishing off | 14, 14, 14, 14, 14, 15 | 14.2 | True | | `04-change` | Change | 29, 28, 28, 28, 28, 28 | 28.2 | True | `APS5_TRACE_SECONDS=200:20` captures, warm caches, no other trace or profile switch (`tools/trace_digest.py`): | Mode | Present Window | Presents (20 s) | Frame p50 | Frame p90 | Frame p99 | Max | GPU Busy (ms/present) | | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | | **Change** | seconds 200:20 from present 348 | 57 | 351.9 ms | 374.2 ms | 545.9 ms | 545.9 ms | 147.6 ms | | **Publishing off** | seconds 200:20 from present 153 | 30 | 672.7 ms | 692.6 ms | 729.9 ms | 729.9 ms | 151.6 ms | Phase breakdown (`draw committer` thread): | Mode | Phase | Duration (% Frame) | Self (%) | Slices | Wait | Sub-phases | | :--- | :--- | :--- | :--- | :--- | :--- | :--- | | **Change** | draw committer | 176.0 ms (49 %) | 35.9 ms (10 %) | 143.9 | 1.7 | Graphics.Draw 101.4, Recorder.Sync 81.0 | | **Publishing off** | draw committer | 422.6 ms (63 %) | 111.9 ms (17 %) | 137.5 | 2.3 | Graphics.Draw 368.9, Recorder.Sync 133.4 | Change first, publishing off second. GPU time is unchanged; the gain is the CPU store-backs the build no longer waits for. Traces: change [aps5-trace-475c6eb5d3ff-25588.json.gz](https://github.com/ashwin280802/AnyPS5/releases/download/pr-mirror-publish-traces/aps5-trace-475c6eb5d3ff-25588.json.gz), publishing off [aps5-trace-475c6eb5d3ff-43440.json.gz](https://github.com/ashwin280802/AnyPS5/releases/download/pr-mirror-publish-traces/aps5-trace-475c6eb5d3ff-43440.json.gz). Summary lines (`aps5-summary.jsonl`, one per capture, in the order above): ```json {"commit":"475c6eb5d3ff","dirty":false,"env":{"APS5_PLAYGO_UNLISTED_CHUNKS":"absent","APS5_TRACE_SECONDS":"200:20"},"gpu":"NVIDIA GeForce RTX 5070","driver":"NVIDIA 617.42","os":"Windows 10.0.26300","cpu":"Intel(R) Core(TM) i5-14600K","cpu_threads":20,"memory_mib":16147,"title_id":"PPSA10264","title":"Jusant","content_version":"02.000.000","resolution":"3840x2160","window":{"spec":"seconds 200:20","first_present":348,"ms":20280.093},"presents":57,"frame_ms":{"p50":351.917,"p90":374.204,"p99":545.87,"max":545.87},"gpu_busy_ms_per_present":147.635,"worker_busy_pct":{"queue worker 0x0":98.335,"queue worker 0x20":75.629},"top_phases_ms_per_frame":{"Driver.Packet":613.356,"Driver.Packet.dispatch":293.082,"Driver.Dispatch":185.387,"Recorder.Sync":137.559,"Graphics.Draw":111.687,"Graphics.Draw.draw_and_resource_release":104.057,"Resources.Complete":88.254,"Driver.Packet.prepare_memory":85.999},"trace_dropped":false,"trace":"aps5-trace-475c6eb5d3ff-25588.json.gz"} {"commit":"9d2e737432d","dirty":false,"env":{"APS5_PLAYGO_UNLISTED_CHUNKS":"absent","APS5_TRACE_SECONDS":"200:20"},"gpu":"NVIDIA GeForce RTX 5070","driver":"NVIDIA 617.42","os":"Windows 10.0.26300","cpu":"Intel(R) Core(TM) i5-14600K","cpu_threads":20,"memory_mib":16147,"title_id":"PPSA10264","title":"Jusant","content_version":"02.000.000","resolution":"3840x2160","window":{"spec":"seconds 200:20","first_present":153,"ms":20161.35},"presents":30,"frame_ms":{"p50":672.733,"p90":692.634,"p99":729.904,"max":729.904},"gpu_busy_ms_per_present":151.647,"worker_busy_pct":{"queue worker 0x0":97.477,"queue worker 0x20":66.991},"top_phases_ms_per_frame":{"Driver.Packet":1099.931,"Driver.Packet.dispatch":461.8,"Graphics.Draw":379.564,"Graphics.Draw.draw_and_resource_release":372.194,"Driver.Dispatch":272.052,"Driver.Packet.pipeline_drain":184.101,"Driver.Packet.prepare_memory":181.467,"Recorder.Sync":176.318},"trace_dropped":false,"trace":"aps5-trace-475c6eb5d3ff-43440.json.gz"} ``` Not verified: on a console; on GPUs other than this one; Jusant on plain main (it does not run without #8089). Not covered by a test: the publish drain of a reused address-based build (`GuestBufferMemory::RecordStagingCopies`); a heap mirror evicted by the same build after an image was deferred into it (the publish then finds the mirror gone by base and serial and stores the image instead); images outside the write watch, array layers, multiple mips, edge blocks and memo eviction. Devices without sparse residency never publish; there the negative control skips. ### 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, driver 617.42, Windows 11 10.0.26300 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-16 18:40:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T18:40:20Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this change; the inspected code supports the described resident mirror publication flow, with some edge cases explicitly left unverified.

What I ran

Reviewed head 38ecc79651f123a77d602bce24c2d53f2b803570 using the prepared diff and repo_read.py. No tests or builds were run; the test results in the PR description are author reported.

Results

Check Result Note
Patch and targeted source review passed Main defer and publish paths inspected
Tests and build not run Author reports test runs
Console and other GPUs not run Not verified by this review

Findings

Blocking

None.

Non-blocking

  • The PR description identifies untested paths for reused-build publish drains and mirror eviction during the same build, plus array layers, multiple mips, edge blocks, and memo eviction. Add targeted coverage for these cases as the implementation is extended.

Sources

Reviewed GuestBufferMemory.cpp, Texture.cpp, ResidentMirror.cpp, Recorder.cpp, and ResidentHeapMirror.cpp at the pinned head, alongside the prepared diff. The diff adds fallback checks for read traps, DCC state, drawn rectangles, write-watch coverage, pending generations, and writable mirror writes; it also guards publication with mirror serials and refreshes guest changes before recording GPU copies.

Not verified

No build or tests were run. The PR description’s reported test and performance results were not independently verified. Console behavior, other GPU vendors, and the listed untested edge cases were not verified. Full source text for GuestBufferMemory.cpp and Texture.cpp was excluded from the review bundle; targeted ranges were read through repo_read.py. All changed files listed in the manifest were identified, but not every changed file was read in full. Other changed files not listed above were not reviewed in detail.

To get this to a good state

Nothing is required. Optional: add coverage for the untested paths listed in the PR description.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5925426676 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17796#pullrequestreview-5925426676). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-16T18:40:20Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this change; the inspected code supports the described resident mirror publication flow, with some edge cases explicitly left unverified. ## What I ran Reviewed head `38ecc79651f123a77d602bce24c2d53f2b803570` using the prepared diff and `repo_read.py`. No tests or builds were run; the test results in the PR description are author reported. ## Results | Check | Result | Note | |---|---|---| | Patch and targeted source review | passed | Main defer and publish paths inspected | | Tests and build | not run | Author reports test runs | | Console and other GPUs | not run | Not verified by this review | ## Findings ### Blocking None. ### Non-blocking - The PR description identifies untested paths for reused-build publish drains and mirror eviction during the same build, plus array layers, multiple mips, edge blocks, and memo eviction. Add targeted coverage for these cases as the implementation is extended. ## Sources Reviewed `GuestBufferMemory.cpp`, `Texture.cpp`, `ResidentMirror.cpp`, `Recorder.cpp`, and `ResidentHeapMirror.cpp` at the pinned head, alongside the prepared diff. The diff adds fallback checks for read traps, DCC state, drawn rectangles, write-watch coverage, pending generations, and writable mirror writes; it also guards publication with mirror serials and refreshes guest changes before recording GPU copies. ## Not verified No build or tests were run. The PR description’s reported test and performance results were not independently verified. Console behavior, other GPU vendors, and the listed untested edge cases were not verified. Full source text for `GuestBufferMemory.cpp` and `Texture.cpp` was excluded from the review bundle; targeted ranges were read through `repo_read.py`. All changed files listed in the manifest were identified, but not every changed file was read in full. Other changed files not listed above were not reviewed in detail. ## To get this to a good state Nothing is required. Optional: add coverage for the untested paths listed in the PR description.
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!17796
No description provided.