perf(agc): mirror a sparse heap whose committed span crosses adjacent ranges #9551
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9551"
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-22T02:01:33Z.
What
A sparse heap mirror needs one leased range that covers the heap's committed span:
bindSparseMirrorcallscontainingRange(lease, begin, neededEnd). When the guest grows a sparse heap by mapping a second range directly after the first, two adjacent leased ranges cover the span instead of one. The bind is then refused, and every use of the heap falls back tocopyRegion, which copies every committed piece on the CPU and diffs it at write-back.Echoes of the End (PPSA25636) does this with its PRT heap:
0x8fc0000000+0x21000000, then0x8fe1000000+0x1000000. Its committed span ends at0x8fe2000000. The first 8 binds succeed while one range covers the span. After that, each use copies about 550 MiB.With this change,
bindSparseMirrorfalls back to a joined range when no single range covers the span. The joined range covers the run of continuing ranges (crossedRun, the same rule the import path uses).joinedHeapRangekeeps it for as long as the run's member ranges are the same objects, so the mirror's identity check (sameRange) holds across builds. When a member changes, the joined range is replaced: the old mirror's weakrangeexpires and the sweep drops it, as it does for a single range that goes away.sweepMirrorsfirst releases the joined ranges whose members have expired, and forces a full sweep when it releases one, so a mirror over ranges the guest released is freed even if no bind follows.Main now imports a fitting prefix and mirrors only each registered heap's unimported tail (merged
5785179785). This refresh preserves that selected-range allocation and the(begin, end)import intervals. Only a mirror synthesized across adjacent registrations receives the partial-import retention guard. Imported intervals are merged as coverage; the joined mirror is retained while coverage is incomplete and released when their union covers its reserved span. Ordinary tail mirrors retain main's overlap-based release behavior.Tested
Current head
a99150abfcaaa9ef7fa26f314826c9cb680a6a30is four linear topic commits on mainc8d34aa8f4d8058d57169cc1e423ba6db00faaf0, with no merge commits.libs,relinker, graphics mock tests, BDA device tests, host-import sparse tests, and both physical execution targets pass on main and this head.agc_sparse_run_import, its copied variant,agc_driver_resident_heap_mirror,agc_driver_sparse_dma_buf_import) inserted validation three times each, with zero VUIDs. No CTest skips. The two existing guest-arena/write-watch unavailable messages inagc_driver_graphicsremain untested branches on both Linux arms; they are not claimed as coverage.AcquireRegistered, and checks buffer identity, refresh after address-build stores, and release after two separate imported intervals cover the entire joined mirror. The former fixture let both ranges import completely and incorrectly expected retention.an address build that imported one range of a joined heap mirror released the mirror. Restore exact production source and rebuild: the complete paired gate above passes.git diff --checkpasses. Conventions against fresh main: all checks pass; against localorigin/main: zero errors, six unrelated existing debt-length warnings.Build logs, 30 focused logs/JUnit, negative control, reviewed receipts, patch and overlap evidence (87,602 bytes; SHA-256
5d711379665d4dfb12afa0fe17d0a054afb98eed71a195429f66efee0ddfcff4). No game files or binaries included.Historical title/performance evidence
The following captures predate this head and the current-main semantic adaptation. No new title run or current-main performance comparison was made for this refresh. Their limits remain: median frame time 3.3% worse, mean frame time 3.0% lower, dropped events in both traces, and no established repeatable FPS gain.
APS5_PROFILE_DRAW=1 APS5_TRACE_BIGBUF=1, 420 s each). Before:APS5_TRACE_SECONDS=290:120(420 s per arm):Driver.Presenttimestamps), with this change: present 560 at 290.7 s (330.8 s without), 600 at 317.1 s (355.4), 640 at 343.5 s (379.7), 660 at 364.1 s (403.4). That is 36-40 s earlier, the same title state about 10 % sooner.seconds 290:120 from present 516: 149 presents, frame p50 644.0 / p90 1389.8 / p99 2297.5 / max 2380.6 ms, GPU busy 386.7 ms per present; withseconds 290:120 from present 559: 114 presents, frame p50 672.1 / p90 1541.4 / p99 7793.8 / max 7978.6 ms, GPU busy 386.8 ms per present. The slowest frames with the change (presents 668-672) come after the last present the other arm reached.APS5_PROFILE_DRAW=1 APS5_TRACE_BIGBUF=1, 420 s per arm, 0 amdgpu kernel events in either:External Windows cross-test
Scramblrrrr reports testing this head
c83c5ea1c9in integration152c7a80ac70, based on163fd9b52c, on Windows 11 / RTX 5070 Ti 617.42 / Ryzen 7800X3D / 32 GiB / WinLibs GCC 15.2r7 Release, with SPIRV Tools off. The fetched integration commit has exactly those base/topic parents and contains this topic head.The external report records 85 focused passes and one expected Linux-only skip, with Khronos 1.4.363 loaded for native Vulkan cases. Two
02275errors insampled_storage_base_level_usagealso occurred on that tester's baseline; no new validation errors were reported. The graphics regression uses a mock device. Reverting onlyGuestBufferMemory.cppto that integration's baseline made it fail at the adjacent-range sparse-heap assertion; restoring the candidate passed with the fixture executable unchanged. The restored focused import/mirror controls passed 16 cases with one expected skip and zero validation errors.This is external correctness evidence, not the required controlled performance comparison or a native Vulkan claim for the mock graphics case. The tester reached a moving offline menu, not gameplay, and explicitly did not establish an FPS improvement or regression. The requested controlled same-scene performance comparison remains open. A later focused Linux gate receipt records main
4777caca34and candidate98de5968c0passing 15/15 on the same machine, with required Vulkan, shader cache disabled, four actual validation-layer instance insertions and zero VUIDs per arm. The test-only and release-fix-reverted controls each fail the intended assertion (14/15). Two existing Windows guest-arena cases are skipped on Linux in every arm; neither new joined-range case is skipped. These are results on the pinned base above, not a claim of testing every subsequent main revision. The receipt also corrects the oldervvl9551e-ctest-change.logprovenance: it is from318ad5365b;vvl9551f-ctest-change.logcovers98de5968c0.Summary lines
Measured at head
98de5968c0(the same joined-range and partial-import logic, before the #7647 port and the #7292 piece-import fix; not re-measured ona5331de72d), present-matched warm pair:APS5_TRACE_FRAMES=450:100, 540 s per arm, same seed. Both arms are the integration tree; the baseline has this PR's code reverted. Files: https://github.com/JJenkx/AnyPS5/releases/tag/pr9551-evidence (thecurrent-*assets).Baseline (without this PR):
With this PR:
tools/performance_compare.py: mean frame -3.0 %, p50 +3.3 %, p90 -4.8 %, p99 -16.7 %, GPU busy -4.1 %. 0 amdgpu kernel events in either.c83c5ea1c9measured mean -15.1 %; its files are the non-currentassets of the same release.Direct links to the existing capture evidence
These are the already-published integration captures summarized above, not a new title run or a plain-main benchmark. Their digest output has been regenerated from the linked traces and matching summary files with
tools/trace_digest.pyatdb6af9e0fd; both outputs match the existing release digests byte for byte.Baseline integration without this PR: summary line, trace, trace_digest output.
Integration with this PR: summary line, trace, trace_digest output.
Both traces dropped events. The existing limits still apply: median frame time is 3.3% worse, mean frame time is 3.0% lower, and a repeatable FPS gain is not established. This evidence-link update does not change the implementation or claim new GPU or title validation.
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 (no unimplemented path added).mdfiles or images added to the repository (attach them to this PR)sweepMirrors: preserve bothreleaseExpiredJoinedHeaps()andReferenceStorage::Shared().ReleaseIdle()when the second branch is merged. Their combination has not been tested.Original work assisted by Claude Code; this current-main adaptation and validation assisted by Codex.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-22T02:01:47Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T02:03:00Z.
Review: CHANGES_REQUESTED
The new synthetic test and the hosted eligibility, conventions, intake, labels, and report checks are useful. I cannot approve this performance PR yet because the repository performance-report rule is not met: the matched-seed
APS5_TRACE_SECONDS=290:120summaries compare different scene stretches (the PR notes presents 516–664 versus 559–672), and the report lacks the required attached base/change traces plustools/trace_digest.pyoutput. The profile runs withAPS5_PROFILE_DRAW/APS5_TRACE_BIGBUFare diagnostic runs, not compliant performance captures under the report form. Please provide a warm-cache capture pair on the same title state/settings/machine with the required summary lines, traces and digests, or remove the speed claim/perf title and retain the measured observations as non-comparative diagnostics. Separately, AGC changes require the same focused Vulkan tests on main and this commit withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1, and the Khronos validation layer, confirming no new VUIDs and that the requested layer was found; this report does not include that comparison. Hosted GPU jobs were skipped, so I have not treated them as run. I did not run local tests.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T02:03:02Z.
The AGC rules require the same focused Vulkan test on
mainand the change on the same machine/GPU withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1, andVK_LAYER_KHRONOS_validation; compare VUIDs and confirm the layer was found. Also, because this is labeledperf, the PR needs two valid warm-cache summary lines, attached traces, andtools/trace_digest.pyoutput from the same title scene/settings/machine. The current 290–410 s windows cover different present ranges, as the report itself notes; the diagnostic profile traces do not substitute for the report form capture. Please add compliant comparisons or remove the speed claim and perf labeling. The hosted Linux/Windows and relinker test jobs are skipped for this file set; I did not run these tests locally.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T02:06:31Z.
@MarcZX10 thanks, both points are right. Coming next:
ctest -Vrun onmainand on this branch, on the same RX 6650 XT / RADV machine, withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1. I'll include the layer-load lines and the VUID comparison.APS5_TRACE_FRAMES=<start>:<count>instead of a seconds window. Bothaps5-summary.jsonllines, the traces and thetools/trace_digest.pyoutput will be attached.One thing a reviewer should know: Echoes does not reach this scene on plain
main. It needs #8089, #4449, #8091 and #8908. So the perf baseline will be that integration tree without this change, notmainitself.If that is not acceptable for the
perflabel, I'll drop the speed claim and keep the change as a fix for the CPU copies, which the counters show directly.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T03:45:05Z.
Present-matched capture, as asked.
Setup
APS5_TRACE_FRAMES=560:100, so both arms record the same 100 presents (560-659), 480 s runs, no other overrides.20f928c642. Candidate: the same tree with it,0560946d6d. The two differ only inGuestBufferMemory.cpp.Summary lines (
tools/trace_digest.py)frames 560:100 from present 560: 100 presents, frame p50 748.4 / p90 1091.6 / p99 6985.3 / max 6985.3 ms, GPU busy 412.5 ms per presentframes 560:100 from present 560: 100 presents, frame p50 630.0 / p90 1299.8 / p99 2373.5 / max 2373.5 ms, GPU busy 400.7 ms per presenttools/performance_compare.py, candidate minus baselineDriver.DispatchResources.CompleteThe gain is on the CPU side, as expected from removing the per-use copies of the heap. One pair, so p90 and the tails are within run-to-run variance.
Files (both
aps5-summary.jsonllines, both traces, both full digests and the comparison) are on the branch https://github.com/JJenkx/AnyPS5/tree/evidence/pr9551.The focused
ctest -Vcomparison under the validation layer passed on bothmain(a6dcea9279) and this branch, 2/2 each, with no VUIDs. I'm rerunning it withVK_LOADER_DEBUG=layerto show the layer was loaded, and will post that with the logs.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:15:50Z.
Thanks for adding the present-matched capture details. Two required pieces are still outstanding in the PR itself: (1) the
evidence/pr9551fork branch is not an attachment to this pull request, so please attach the summary lines, traces, digests, and comparison here; (2) the Vulkan comparison currently citesmaina6dcea9279, not current upstream maindce41a89478876a8e3ea9c346b1dac00bb31c8cd, and the requested layer-load confirmation is still pending. Please update the comparison to current main (or document why the current main build cannot reach this scene, then keep the performance claim limited to the explicitly identified integration baseline) and include logs proving the layer loaded and no new VUIDs. The 560:100 integration-tree pair is useful same-scene performance evidence, but its p90 regression and single pair should remain disclosed as you have done.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T04:53:09Z.
Focused tests under the validation layer, on
mainand on this branch.Setup
mainis this PR's base,a6dcea9279; the change isc83c5ea1c9.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer.ctest -V -R '^(agc_driver_graphics|agc_sparse_.*|agc_heap_mirror_.*|agc_host_import_sparse)$'. That is 12 tests, covering the sparse heap mirror, heap mirror, sparse run import and sparse host import paths, and including the newsparseJoinedHeapMirrorTestscase.Result
[Vulkan Loader] WARNING | LAYER: env var 'VK_INSTANCE_LAYERS' defined and adding layers "VK_LAYER_KHRONOS_validation"and the inserts, for the tests that create a real instance (agc_sparse_run_import,agc_sparse_run_import_copied).agc_driver_graphicsand the mirror cases run on the mock device, so the layer has nothing to validate there.VUID-vkCmdCopyBuffer-srcBuffer-00118inagc_sparse_run_import_copied. It is present onmaintoo, so this change neither adds nor removes it.Logs (paths redacted): https://github.com/JJenkx/AnyPS5/tree/evidence/pr9551/vvl
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T06:16:06Z.
The
aps5-summary.jsonllines of the present-matched pair (APS5_TRACE_FRAMES=560:100). The traces and thetools/trace_digest.pyoutput are on https://github.com/JJenkx/AnyPS5/tree/evidence/pr9551.Baseline (without this change):
With this change:
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T06:45:15Z.
@MarcZX10 your review's points are all addressed now. Please take another look when you have time.
APS5_TRACE_FRAMES=560:100instead of the seconds window. Both arms record presents 560-659 from one seed of shader caches and save state, with no diagnostic overrides. The results are in the comment above and in the description's "Summary lines" section.aps5-summary.jsonllines are in the description. The two traces, bothtools/trace_digest.pyoutputs and thetools/performance_compare.pytable are at https://github.com/JJenkx/AnyPS5/tree/evidence/pr9551.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. All pass on both. The loader shows the layer added for the tests that create a real instance, and the VUIDs are identical on both (one pre-existingvkCmdCopyBuffer-srcBuffer-00118, present onmain). The logs are invvl/on the same branch.APS5_PROFILE_DRAW/APS5_TRACE_BIGBUFruns remain in the description as observations (CPU copy counts) and are not presented as the performance capture.Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-22T10:50:54Z.
Windows cross-test completed for c83c5ea1c9 on integration 152c7a80ac70 (base 163fd9b52c):
https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-oct22-sparse-heap-runs
Windows 11 / RTX 5070 Ti 617.42 / Ryzen 7800X3D / 32 GiB, WinLibs 15.2r7 Release, SPIRV Tools OFF. 85 focused cases passed, one expected Linux-only skip (36.81 s), with the actual Khronos 1.4.363 layer loaded for native Vulkan cases. Two existing 02275 validation errors in sampled_storage_base_level_usage match the baseline; no new validation errors. The graphics regression itself uses the mock device, so its passing result is not a native Vulkan validation claim.
Production-only negative: restoring baseline 163 GuestBufferMemory.cpp while retaining the new fixture makes graphics fail with “a sparse heap whose committed span crosses an adjacent range was not mirrored.” Restoring the exact candidate passes; fixture executable hashes were unchanged. Restored focused import/mirror controls: 16 pass, one expected skip, 8.78 s, zero validation errors.
007 observation, not a controlled performance claim: six contained summary intervals in the observed warm moving offline menu gave 78 presents / 63.204949 s = 1.2341 FPS, GPU busy 191.76 ms/present. Previous 163 menu observation was 1.2788 FPS. This does not establish an improvement or regression; the diagnostic startup settings and scene timing are not a strict performance pair. Large CPU buffer copies persist, so I have not established that the dominant title copies are this adjacent-range sparse case. No gameplay was reached in this run; it ended at the bounded 30-minute deadline. #9652 remains excluded pending isolation of a separate startup failure.
Original author commits retained, no duplicate implementation. Raw title code/requests/captures remain local. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T11:03:20Z.
Added
c65f593739: keep a heap mirror that an import covers only in part.While profiling the joined mirror's rebuilds, I found an interaction with the existing release rule:
AcquireRegistered) releases the heap mirror at the base of each range it imports.The fix releases a heap mirror only when the imported range covers its reserved span. For a single-range mirror these are the same range, so its behaviour does not change.
Echoes (PPSA25636), one 480 s run each, same settings (
APS5_PROFILE_DRAW=1 APS5_TRACE_BIGBUF=1), integration tree:The mock-device tests cannot exercise this path, because host imports fail there and nothing is released. The focused validation-layer tests on this new head are queued, and I will post them.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T11:27:14Z.
I reviewed the new c65f593739 change as well. The
reserved > bytesguard is aimed at the partial-import release case, butsparseJoinedHeapMirrorTestscurrently binds twice and then removes the registrations; it does not pass through a host import that covers only the first member range. Please add a focused regression asserting that this partial import keeps the joined heap mirror and does not force a rebuild. I also found the open #7647 sparse-heap mirror PR editsGuestBufferMemory.cppandBdaResources.cpp; a three-way merge of both heads is text-clean, but these are closely related mirror paths. Please coordinate with its author on merge order/composition and record the decision in the checklist, adding Depends on if sequencing is required. Current main is4777caca34; this PR is 3 ahead/119 behind (merge basea6dcea927). Diff-check, conventions and merge-tree against main pass. The focused Vulkan report in the PR/comments is on earlier head c83c5ea1c9 and old basea6dcea927; the author says the c65 validation rerun is queued. Since this changes AGC, please complete the prescribed same-machine/GPU main and current-head run with required Vulkan, no shader cache and validation settings, layer-load confirmation and VUID comparison. The performance summaries/traces also need to match the current head and be attached per the report form; the existing pair is from the earlier head and the trace artifacts are linked from a fork. I did not run GPU tests locally.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T11:27:16Z.
Review: DISMISSED
The added partial-import guard addresses a real lifecycle issue, but its new behavior lacks a targeted test: the sparse joined heap case never imports only one member range after creating the mirror. Please add that regression. Also coordinate with open #7647, which edits the same mirror implementation and tests, and record whether either depends on the other. This head is 3 ahead/119 behind current upstream/main
4777caca34(merge basea6dcea927). Diff-check, conventions and merge-tree against main pass, but the GPU evidence and performance pair in the PR cover earlier head c83c5ea1c9 on older basea6dcea927. The required AGC validation comparison and report artifacts must be refreshed on current main and this head, with the layer confirmed loaded and VUIDs compared. I did not run GPU tests locally.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T11:27:42Z.
Focused validation-layer tests on the new head
c65f593739, as promised in my last comment.Setup:
a6dcea9279againstc65f593739.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest -V -R '^(agc_driver_graphics|agc_sparse_.*|agc_heap_mirror_.*|agc_host_import.*)$'(15 tests).Result:
VK_LAYER_KHRONOS_validationadded in both (8 lines each).VUID-vkCmdCopyBuffer-srcBuffer-00118inagc_sparse_run_import_copied, the same pre-existing message as before. It is reported on this older base; currentmainno longer reports it.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T13:29:02Z.
@MarcZX10 this covers your latest review, on head
98de5968c0(rebased ontomain4777caca34):joinedHeapMirrorPartialImportTests, commit98de5968c0. A heap bound across two committed ranges is mirrored over both, and an address build on an importing context imports the first range. The mirror must stay: same buffer, no rebuild. With only the release fix (318ad5365b) reverted, it fails with "an address build that imported one range of a joined heap mirror released the mirror". With it, 15/15 focused tests pass, the layer is added, and there are no VUIDs.git merge-treeshows two mechanical conflicts inGuestBufferMemory.cpp, and the resolution is described there. The description'sDepends online says so.main4777caca34: 15/15 pass.mainplus the test commit only fails the new case as intended. The change passes 15/15. The loader adds the layer in every arm, and no arm reports a VUID.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T01:12:25Z.
Review: CHANGES_REQUESTED
Checked the joined-range lifetime, the partial-import guard, the piece-import byte sum and the two new
bda_resourcescases on the current head, merged onto11d6efa06; the code compiles against the moved main (no staleimportedcall sites). Requesting changes on the process side, not the code:aps5-summary.jsonllines, both traces, and thetools/trace_digest.pyoutput formainand for the change, from the same title, scene and machine. The fork branchevidence/pr9551is not an attachment, and the description's summary hasperformance_compareoutput but notrace_digestoutput. (AGENTS.md: a speed claim showstrace_digestsummaries of both arms.)