perf(agc): store a resident heap mirror's write-back from its readback buffer #12827
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12827"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-29T11:42:52Z.
Status (2026-12-01): head
ce2550a3f277is @oneandonlydean's merge ofmain, which re-applies this change on the piece-wise write-back path that #12840 introduced: a piece covered by a heap readback is now stored straight from the readback span instead of being copied into a temporary vector first. Linux at this head (Arch Linux, RX 6650 XT, Mesa RADV, Release, Vulkan validation layer active):ctest -R 'agc_driver_resident_heap_mirror|heap_mirror|resident'29/29 passed, 0 VUID, 0 SYNC-HAZARD. His same-scene pair on PPSA21564 (base, head, head, base) is neutral: +0.44 ms frame p50 against a 1.0 ms noise floor. This PR therefore claims only the per-write-back copy it removes, not a scene speedup.Current Linux qualification and scope (2026-11-19): commands, source pins, validation, readback attribution and attached evidence. This report addresses the review's alternative of retaining per-write-back attribution without claiming a scene-matched title speedup. The topic remains
c12a20f45da5; no implementation change is implied by this description update.The report applies the existing patch privately on main
50f2772c6b10, with the same diagnostic instrumentation and copied-writer fixture held constant in both arms. Full SDK builds pass. The same eight focused checks pass on each arm on Linux / AMD Radeon RX 6650 XT / RADV Mesa 26.2.7 / Khronos validation 1.4.363: no skips or VUIDs, seven layer insertions per arm, including actual sparse resident mirror execution.Two separately queued cold-opening Mortal Shell II (PPSA34008) runs completed normally with fresh saves and identical cache conditions. The recorded
UploadFinish.cpu_writersspans total 46,042 ms versus 14,906 ms over 10–120 s. These private-instrumentation observations are attribution only: at 135 s the baseline is black while the change shows a character/cutscene, and the sampled fault recordings lose data. They establish no FPS ratio, matched-scene gain or title unblock. The implementation removes the temporary readback copy; a merge decision need not rely on any numerical title speed claim from this new report.Older contributor measurements and historical integrations below retain their own source/configuration pins and limitations; they are not new plain-main or current-main performance validation. The requested scene-matched performance rerun remains unproven by this latest local experiment.
Additional title measurements supplied by @mrfelek, 2026-11-04: full route, source pins, summaries and trace digests. On PPSA22408 (Hot Wheels Infinite Rush), RTX3080Ti/NVIDIA615.71.09, Ryzen5950X/Linux7.3, 3840×2160, warm shader caches and identical import/staging/shadow settings, their alternating A/B/A/B route compares plain main
b11c7bf84fwith that main plus this PR'sc12a20f45dtopic (5fcf8be8a4). The post-load flyover improves from 0.30/0.30 to 0.62/0.63 presents/s, with median frame p50 moving from3.94/4.10s to1.82/1.86s. This remains very slow gameplay.The race-load window has no established improvement; the attached 330:10s trace windows land in loading and do not measure that post-load gain. The comment separately provides the post-load summary records. Later magenta/green artifacts also occur on their longer main control, and no exceptions occurred. These are the contributor's measurements, not locally reproduced title results. Their PPSA28416 multi-PR-tree switch pairs are attribution-only, not plain-main performance evidence. All measurements retain these historical source/configuration pins and do not qualify later heads.
Previous implementation report and contribution template:
What
GuestBufferMemory::WriteBackstores a resident heap mirror's write-back from its recorded readback buffer. It used to copy the readback into a newstd::vector<std::byte>of the written range and store from that copy.ResidentBuffer::StoreandstoreChanged/storeSparsetake astd::span<const std::byte>, and the readback buffer stays alive inheapReadbacksfor the whole write-back, so the copy is dropped. A write-back without a recorded readback (ResidentBuffer::ReadDevice) still reads into a vector, as before. The bytes stored in the resident shadow and in guest memory are the same.Why
In Echoes of the End (PPSA25636), a compute dispatch with atomic writes into a resident sparse heap mirror completes about once per second. Each completion writes back the dispatch's whole written range, about 540 MiB. A later build that reads the same heap waits for that write-back in
CompletePendingCpuWrites(UploadFinish). Allocating, zeroing and filling the 540 MiB vector took most of each write-back.The attribution below comes from a private integration tree (older
mainplus open PRs) with private counters (APS5_PROFILE_DRAWplus diagnostics). It is attribution, not a speed claim: 4 interleaved 900 s runs of the same build, with a private switch restoring the copy.ResidentBuffer::StorestoreChanged)CompletePendingCpuWritessync per copied-writer overlapResidentBuffer::Storereads the host-visible readback mapping directly now, so it got slower. The total per write-back still falls from about 419 ms to about 115 ms.Tested
Arch Linux 7.2.9-arch1-1, AMD Radeon RX 6650 XT, RADV Mesa 26.2.4, Ryzen 9 7950X.
Focused tests on
mainand on the change (ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -V -j1 -R 'agc_driver_resident_heap_mirror|heap_mirror'; 9 tests):main4c7d275bef: 9/9 passed, 0VUID-.4c7d275bef): 9/9 passed, 0VUID-.was not found but was requested by env var VK_INSTANCE_LAYERS.agc_driver_resident_heap_mirrorran its resident tests on this device (the device has sparse residency; the log printsresident heap mirror tests passed, not the skip message). They dispatch stores into a resident heap mirror and check guest memory after the write-back.Echoes of the End: same-scene
main/change pairs on one machine (also posted with screenshots in https://github.com/boykopovar/AnyPS5/pull/12827#issuecomment-6505299937). Echoes does not boot onmainalone:-1000072003) and it segfaults at 32 s.ShaderRecompiler::Recompile: value IR instruction definition does not dominate its use(#8050).Both sides therefore use the same private base:
main899ae3d1ad+ #4449 + #8089 + #11873 + #6867, commit 27db71c581b. The change side is that base + this PR's commit, 3e83ee94776; itsgit patch-idequalsc12a20f45da's. These runs therefore compare this PR on that private stack, not on baremain.Runs:
6a3bbca6eb39b28b),APS5_TRACE_SECONDS=1500:240, no otherAPS5_TRACE_*/APS5_PROFILE_*switch set.Pair 1: in-game "Loading..." screen (cathedral with the blue crystal) in both windows. Base, then change:
Resources.Completeon queue worker 0x20 (the copied-writer write-back) took 7.4 s on base and 3.5 s on the change.Recorder.Syncon that worker took 1.6 s and 0.8 s.Pair 2: in-world scene (two characters at a ruined archway) in both windows. Base, then change:
Caveats:
trace_dropped: true; the digests list the times). The frame times come from presents and are complete; only the per-phase totals are partial.An earlier pair in this description (900 s runs,
APS5_TRACE_SECONDS=600:240) landed on different scenes, so it is removed and is not evidence.tools/trace_digest.pyoutput for the four traces:Pair 1 base (27db71c581b4)
seconds 1500:240 from present 803: 125 presents, frame p50 1621.1 / p90 2233.2 / p99 8046.2 / max 8428.7 ms, GPU busy 816.4 ms per present
AMD Radeon RX 6650 XT (RADV NAVI23), radv Mesa 26.2.4-arch1.1, Linux 7.2.9-arch1-1, 3840x2160, commit 27db71c581b4, dropped: yes
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 2191.6, Driver.Packet.dispatch 1045.8, Driver.Packet.memory_wait 991.9, Driver.Dispatch 930.1, batch 817.7, Resources.Complete 639.5, Vulkan.Dispatch 621.0, Vulkan.Dispatch.shader_resources 552.2, Graphics.Draw 269.5, Graphics.Draw.draw_and_resource_release 259.3
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Pair 1 change (3e83ee94776d)
seconds 1500:240 from present 1452: 341 presents, frame p50 704.9 / p90 877.5 / p99 1018.8 / max 1114.2 ms, GPU busy 335.1 ms per present
AMD Radeon RX 6650 XT (RADV NAVI23), radv Mesa 26.2.4-arch1.1, Linux 7.2.9-arch1-1, 3840x2160, commit 3e83ee94776d, dropped: yes
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 342.5, batch 335.0, Driver.Packet.memory_wait 168.9, Driver.Packet.dispatch 142.4, Driver.Dispatch 130.2, Graphics.Draw 119.0, Graphics.Draw.draw_and_resource_release 114.0, Recorder.Submit 88.1, Resources.Complete 70.1, Vulkan.Dispatch 61.7
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Pair 2 base (27db71c581b4)
seconds 1500:240 from present 1054: 220 presents, frame p50 1084.5 / p90 1276.9 / p99 1413.1 / max 1538.9 ms, GPU busy 563.6 ms per present
AMD Radeon RX 6650 XT (RADV NAVI23), radv Mesa 26.2.4-arch1.1, Linux 7.2.9-arch1-1, 3840x2160, commit 27db71c581b4, dropped: yes
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 733.8, batch 563.6, Driver.Packet.memory_wait 392.9, Driver.Packet.dispatch 287.7, Driver.Dispatch 253.6, Resources.Complete 152.3, Graphics.Draw 139.3, Graphics.Draw.draw_and_resource_release 132.6, Vulkan.Dispatch 130.4, Vulkan.Dispatch.shader_resources 127.2
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Pair 2 change (3e83ee94776d)
seconds 1500:240 from present 1305: 239 presents, frame p50 1018.3 / p90 1212.9 / p99 1379.8 / max 1666.4 ms, GPU busy 515.5 ms per present
AMD Radeon RX 6650 XT (RADV NAVI23), radv Mesa 26.2.4-arch1.1, Linux 7.2.9-arch1-1, 3840x2160, commit 3e83ee94776d, dropped: yes
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 668.7, batch 514.3, Driver.Packet.memory_wait 361.7, Driver.Packet.dispatch 261.5, Driver.Dispatch 238.7, Resources.Complete 150.2, Graphics.Draw 133.5, Graphics.Draw.draw_and_resource_release 127.1, Vulkan.Dispatch 127.1, Vulkan.Dispatch.shader_resources 124.1
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Attached in the release https://github.com/JJenkx/AnyPS5/releases/tag/heap-writeback-readback-samescene-20261029: the four traces, the four summary lines, their digests, the 1440 s and 1795 s screenshots and the seed manifest. The earlier release https://github.com/JJenkx/AnyPS5/releases/tag/heap-writeback-readback-evidence holds the focused-test VVL logs.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T11:48:43Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The code change is correct, merges cleanly, builds, and the focused resident heap mirror tests pass with validation on. The block is on evidence only: this is a
perfPR, and its description does not yet carry the same-scenemain/change summary lines that CONTRIBUTING.md requires.What I ran
c12a20f45da55cd45da092e937ee196416cc2f72main:ba5b5330b37724bca4b99f30faab504653635a04(the head's parent, so the PR is on currentmain)BUILD_TESTING=ON, in a clean worktree withmainmerged with the PR head (--no-ff).Results
maingit diff --checkcheck_conventions.pyAll conventions checks passed.main)VUID-linesmainVUID-linesInserted device layer "VK_LAYER_KHRONOS_validation"in 6 Vulkan tests in each log; nowas not found but was requested by env var VK_INSTANCE_LAYERSagc_driver_resident_heap_mirror_testsrecords 16 readbacks (RecordCopyBacks) and callsResidentBuffer::Store8 times fromGuestBufferMemory::WriteBack;ReadDeviceis never calledtools/pr_labels.pyhas_numberson the descriptionFalsectest, merged tree
gdb call counts, agc_driver_resident_heap_mirror_tests (merged tree)
Negative control
None. The PR adds or changes no tests, and the change is meant to store the same bytes as before, so no existing test should fail when it is reverted. The gdb run above shows that the existing
agc_driver_resident_heap_mirrortest does reach the changed recorded-readback branch and checks guest memory after it.Findings
Blocking
The
perfevidence required by CONTRIBUTING.md is not in the description. CONTRIBUTING.md:71 requires aperf(...)PR to show the summary lines ofmainand of the change, from the same machine and scene. It keepsperf numbers missingon the PR until the description holds two valid summary lines with different commits. Two things are missing:..., so they are not JSON.tools/pr_labels.pyhas_numbersreturnsFalseon the current description, which is why the label is still set. The full lines are only in the external release.Using
main+ #4449/#8089/#11873/#6867 as the base, because the title does not boot onmainalone, is well explained. Whether that is an acceptable stand-in formainis for the maintainers to decide.Non-blocking
None about the code. What I checked:
currentnow points into the readbackBuffermapping. That buffer is owned byheapReadbacks(and byrecorder.Keep) from GuestBufferMemory.cpp:5876-5877 untilheapReadbacks.clear()after the loop. Nothing inResidentBuffer::Store,storeSparseorstoreChangedmodifiesheapReadbacks, so the span stays valid across GuestBufferMemory.cpp:6291-6303.memcpyread the same mapping at the same point.ResidentBuffer::Store'sGuestBytesZerocheck scans host pointers, so passing the mapping instead of a vector does not change its meaning.Bufferuses the defaultHOST_VISIBLE | HOST_COHERENTflags, andContext::BufferMemoryTypeprefers aHOST_CACHEDtype for those flags. So the extra reads of the mapping (byStore, then bystoreChanged/storeSparse) are cached reads wherever the driver exposes such a type. The description'sResidentBuffer::Store42 → 78 ms is consistent with that.Not verified
ReadDevicefallback branch (no recorded readback). No focused test reaches it. Its behaviour is unchanged apart from moving the vector intoread.To get this to a good state
aps5-summary.jsonllines (one base, one change) into the description, so that theperf numbers missinggate can parse them.tools/trace_digest.pyoutput for that pair as before.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-29T15:49:02Z.
Review: CHANGES_REQUESTED
The code change itself checks out: the readback span in
GuestBufferMemory.cpp:6295stays alive inheapReadbacksuntil it is cleared after the write-back loop,Store/storeSparse/storeChangedonly read it, and the size is checked against the write-back length. The NVIDIA CI run is clean (0 new failures, 0 new validation IDs).What blocks it is evidence, as the
perflabel bot and @XairRrR's review say:aps5-summary.jsonlline ofmainand of the change from the same title, scene and machine, plus thetools/trace_digest.pyoutput. The pair in the description lands on different scenes (the description says so itself), so it does not qualify.Happy to merge once the report is in and the review request is cleared.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T20:27:26Z.
Review: APPROVED
Re-checked — approved
The code is the same commit (
c12a20f). The description now holds the fullaps5-summary.jsonllines of two same-scene base/change pairs, with trace digests, so the one blocking finding of my last review is resolved.What changed since my last review
c12a20f45d = c12a20f45d.1500:240) were added, with scene screenshots at 1440 s and 1795 s;tools/trace_digest.pyoutput for all four traces is now in the description.What I ran
Head
c12a20f45da55cd45da092e937ee196416cc2f72,main096c45570f516de76a43bbe1b97781381c84f55f, merged treedeea710d7d1c33842a4cb6ce865061c3f49a9daa. Debian 13 VM (Xeon Gold 6136), GCC 14.2.0, lavapipe (Mesa 26.1.6). Release, Ninja,BUILD_TESTING=ON.The script also built the merged tree and ran the selected tests and the validation comparison against
main.maingit diff --checkcheck_conventions.pyAll conventions checks passed.libsmain.main(757 tests)VUID-heap_mirror|residenttests (16), with validationVUID-lines; nowas not foundline; the layer was inserted in 6 tests;resident heap mirror tests passedprinted, longest test 2.08 spr_labels.has_numberson the pair-1 linesTruePrevious findings
perfevidence required by CONTRIBUTING.md:73 was missing. Resolved.27db71c581b4) and change (3e83ee94776d) lines,has_numbersreturnsTrue, so theperf numbers missinggate is satisfied.trace_dropped).main+ #4449/#8089/#11873/#6867 on both sides. As I said before, the maintainers decide whether that stands in formain. The description is clear that this is not a bare-mainresult.New findings
Blocking
None.
Non-blocking
None. I re-checked the span lifetime on the merged tree:
heapReadbacksis filled inRecordCopyBacks.releaseHeapReferences(GuestBufferMemory.cpp:6652-6656). That function is called fromtakeHeapReferencesbefore the build and at the end ofWriteBack(GuestBufferMemory.cpp:6781), after the loop.GuestBufferMemory.cpp:6720stays valid throughStore/storeSparse/storeChanged(GuestBufferMemory.cpp:6726-6728).This agrees with adriadam10's review.
Not verified
ReadDevicefallback branch (no recorded readback). No focused test reaches it; it only moved into thereadvector.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T06:15:56Z.
Review: COMMENTED
Reviewed — no blocking findings
The change uses the recorded readback buffer directly for resident heap write-back; I found no defect in the code inspected, but tests were not run here, so a formal approval is not justified.
What I ran
Reviewed head
c12a20f45da55cd45da092e937ee196416cc2f72usingrepo_read.pysearches and targeted reads. No tests or builds were run.Results
Negative control
Not run; no test execution was available to change code under test and confirm a failure.
Findings
Blocking
None.
Non-blocking
None.
Sources
The reviewed write-back change is pinned to GuestBufferMemory.cpp at this head.
Not verified
Tests and build were not run. Read:
description.mdlines 1–200,commits.md,manifest.json,diff.patch, and targeted ranges inGuestBufferMemory.cppandResidentMirror.cpp. The changed file was included in the prepared files; no changed files were excluded by the manifest.To get this to a good state
Nothing is required. The focused tests described in the PR remain to be independently run on this head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T02:46:27Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the implementation uses the recorded readback span for resident write-back and keeps the existing device-read fallback.
What I ran
Reviewed head
ce2550a3f2775ccc20f49fb47ccbf6e36968ec1dusingrepo_read.pyto inspect the prepared diff and targeted source ranges. No build or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full changed source file was excluded as too large; the changed hunk and targeted surrounding ranges were read through the pinned reader. The full build and focused tests described in the PR description were author-reported and not run in this review. Hardware behavior and performance were not independently verified.
ResidentBufferreadback buffer host visibility/coherency implementation was not inspected.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:54:39Z.
Review: COMMENTED
The trial merge with
mainis clean. The selected heap readback still owns the bytes whileexactconsumes the bounded span, and the direct device read retains its own vector. Please include a resident-mirror control with a nonzero offset and multiple declared pieces in the same readback, alongside the direct-read control. This catches using the span base or its full length when storing a clipped piece. I have no paired Vulkan result for this head yet.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T02:28:25Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
79c65447269ee77f1902c2c0eb9df2ff6db30cce. I inspected the prepared diff and changed code withrepo_read.py; I did not run tests or compile anything.Results
Negative control
Not run; the regression tests cover separate readbacks, one shared readback, and direct reads.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
GuestBufferMemory.cppwas not included in the review folder; its changed function context was read withrepo_read.py.GuestBufferMemory.hpp,GuestBufferMemory.cpp, andResidentHeapMirror.cpp.files.jsonlists no excluded files.To get this to a good state
Nothing required.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.