perf(agc): bind a sparse descriptor heap's committed run in place from its import #5249
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5249"
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 SleglJan on 2026-10-13T15:34:50Z.
What
A descriptor heap that a shader binds whole while only the pieces from its base are mapped (a sparse heap) is copied on the CPU for every build that binds it, unless a mirror serves it. The sparse heap mirror (#3167) takes a heap whose needed extent lies in one releasable registered range. A heap the title maps piece by piece, each mapping its own allocation and the pieces back to back from the heap's base, is several registered ranges, so every build copied its mapped run again.
Such a region is now bound in place from an import of that run: an import that already covers it, the run's own import, or one joined over exactly the run (#4517).
APS5_NO_LEASE_MIRRORorAPS5_NO_SPARSE_HEAP_MIRROR.mainsince #4517. Joins stop after 64 per joined run base, with one message; from then on the heap is bound in place only while an existing import covers its run, and copied otherwise. The records go when their range does. The host-imports debt entry says so.Descriptor, as onmain.A set over such a region stays reusable in the resource cache:
DirectRegionsandInPlaceReadsname the region up to its import's end, so the import's serial proves it. Without that, a set over a region bound in place would stay unreusable, as one over a copied region is onmain, because no import covers the whole region.CutRegions). That check runs whenever the imports or the registry changed, which every mapping does, so a mapping past the cut makes the set miss instead of reading zeros through it.DirectRegionsrefuses a set any of whose regions bound in place no longer holds the import found at its base (a later join in the same build retired it). This applies to every region bound in place.There is no switch: the fallback is the existing copy path for every case it does not take.
Tested
Linux (CachyOS, kernel 7.2.9), GCC 16.2.1, Release. Windows was not built or run.
New test
sparseRunImportTestsin the recorder tests, asagc_sparse_run_importandagc_sparse_run_import_copied. Three 64 KiB allocations mapped back to back at the start of a 512 KiB range whose tail is unmapped:DirectRegions,InPlaceReadsandCutRegionsnaming the cut, and a GPU copy through the view returning the guest bytes;agc_sparse_run_import_copied: once the run has been seen, a bind with a view past the run is copied, nothing is read in place, and a GPU copy through the view returns the guest's mapped bytes.Red/green on lavapipe (Mesa llvmpipe): the in-place test fails on this branch with the binding removed ("a sparse run heap is not bound in place from its run's import"), with the cut reverted (
Descriptorrefuses the view), withDirectRegions/InPlaceReadsnaming the whole region ("… is not named up to its import's end for reuse"), without the reuse check of the mapped extent ("a set over a sparse run heap mapped past its cut was reused") and without the wait for an unchanged run ("a sparse run heap was joined the first time its run was seen"). It passes with the change. On a4d8c2931, with the last view ignored (neededEndset to the committed end), both tests fail ("a sparse run heap with a view past its run is bound in place", "… past its stable run is bound in place"); the five earlier reds were run on the in-place test before the switch was dropped.Suite on lavapipe,
ctest -j 8 --timeout 300, on an earlier base,main0f2683cb7: 1035 of 1046 pass with the change and 1032 of 1044 without. The same 11 fail on both in that container (hardware_oracle,guest_syslog,agc_driver_depth_compare_copy,autorun_exit_status,guest_none_relocations,guest_module_argsand fivelinux_*executable tests);guest_audio_in_captureaborted once onmainunder the parallel run and passes alone on both. Onmaind1b3aa137, which has #4517 and #290, the two new tests and 494 of 496agc_tests pass on 9c8fd7687, and 492 of 494 onmainalone; the same two fail on both in that container:agc_driver_depth_compare_copyandagc_driver_bc_block_copy(the guest block is not write-watched there). a4d8c2931 (onmaina5f493f90, the switch dropped) gives the same: both new tests pass and 494 of 496agc_with the same two failing.tools/check_conventions.py --base upstream/mainandtools/check_test_registration.pypass.Title: 007 First Light (PPSA11386), NVIDIA GeForce RTX 3080 (615.71.09). The title does not reach the scene on
mainalone, so the numbers come from one build of our 007 integration stack (upstream/main3e0e01f35of 2026-10-12 plus 164 commits of our 007 integration work, including cross-tests of #757, #758, #1201, #4515, #4517, #4554, #4724 and #4841 (#4515, #4517 and #4554 have merged since and #4724 was closed)), whose version of this change has this PR's behaviour behind the stack's own opt-in switchAPS5_SPARSE_RUN_IMPORTand prints counters of what it did. In the run with the change on, binds waited for an unchanged run in 10 of the 142 ten-second reports (1 to 5 binds each: four before the cinematic, five in its first 35 frames and one later), and no heap reached the join limit. With that switch off and on, from the same save, warm caches, 1500 s each; neither run crashed:The copied regions are the title's two descriptor heaps, each a 512 MiB view over 6–42 MiB of mapped pieces: about 30 GiB copied per 10 s without the change.
In each run's 60 s trace window (900–960 s: frames 248–263 of the cinematic with the change, 126–139 without), a resource build (
Resources.Complete, all threads) took 1.8 ms on average with the change against 4.9 ms without; builds per frame were about equal (619 against 570). The trace with the change dropped events: queue worker 0x0 reached its event limit at 50.9 s, so its window ends at the last present before that. The windows are at different frames, so the runs' summary lines are not a before/after pair (p50 frame time 4,598 ms with the change, 4,199 ms without).Later stretches of the cinematic vary a lot between runs; on earlier builds of our integration line without this change, the first 150 frames sat at 0.20–0.24.
Capture: 3840x2160. Both runs set further
APS5_TRACE_*switches,APS5_PROFILE_VRAM=1andAPS5_DUMP_SHADERS=1, and redirected the log, unlike the Performance report form; their environments differ only in the integration stack's switch for this change.The integration stack also carries a local change that keeps draws over copied read-only buffers reusable (sparse heaps included), so the column without this change is better than
main's copy path for these heaps.Summary lines, with
envreduced to the integration stack's switch for this change (the traces are attached asaps5-trace-on.json.gzandaps5-trace-off.json.gz):With the change:
Without the change:
InPlaceReadssits next to #4978'sSplitInPlaceReads. At #4978's current head a6970f1af the two conflict only on theif(WIN32)PATH list line inlibSceAgcDriver/CMakeLists.txt, where #4978 addsagc_recorder_read_listand this PR its two tests.SplitInPlaceReadsnames its own regions up toregion.end; whichever merges second should end them atinPlaceEnd(region), asInPlaceReadsdoes here.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)agc_, ond34564be4(its rebase ontomain3e577edac; only theif(WIN32)test list merged) both new tests; NVIDIA GeForce RTX 3080, driver 615.71.09, Linux (CachyOS, kernel 7.2.9): at 510f926b5, before the rebase onto #290 and the switch removal, both new tests passed and noagc_test failed (487 run,agc_driver_stencil_ref_exportskipped itself), and the title runs on our integration stack with this change behind that stack's opt-in switch🤖 Generated with Claude Code
https://claude.ai/code/session_01Fnrk5Dazjb2tLooVSpdRQq
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-13T15:36:32Z.
aps5-trace-off.json.gz
aps5-trace-on.json.gz
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-13T16:41:28Z.
@MichonGoddijn231849 The overlap check lists #290. Every line except
GuestBufferMemory.cppL3015-3017 is #4515's and #4517's, which this PR carries. This PR's own change adds one condition to the import lookup inUploadFinishthere, which #290 makes windowed. Neither needs the other. This PR merges after #4517 either way; the order of #290 and #4515/#4517 is for you and @AlxcBTW. If #290 lands first, I rebase onto it and add it toDepends on. After that rebase, a joined run import that #290's budget evicts is joined again at the next bind and counts toward this PR's limit of 64 joins per base; I'll check that case then.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-13T19:05:20Z.
Windows cross-test of the sparse-run change: author-preserved integration281506e81 plus older-layout CTest correction693182a5b65dde056084f6e6dad0b5199903ad96, https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-sparse-run-import . Reviewed rebased headc75fac9a: sparse-run production differs fromc6e only by whitespace. Our stack already carries4515/4517 plus window-budget integrationc990fc176; it preserves non-sparse importAccess and the separate copied-read reuse checks.
RTX5070Ti /Windows /GCC15.2 /Vulkan required: final8/8 controls PASS7.76s, including imported and opt-out copied sparse runs, mapped-run growth/reusable cut, import unmap/retirement, alias handovers, graphics/BDA. Targeted production-negative disables sparseRunImportsEnabled with fixtures unchanged: imported test FAILS (not bound in place), copied test PASSES. Restored/touched/rebuilt positives pass. Initial two CTest registrations failed DLL lookup in this older Windows layout, corrected before these results. No skips at the CTest level; this is not full CI or a fresh-current-main build.
Our bounded title diagnostic matches the scope:12of16 sampled descriptors512MiB over10MiB covered by2 imported ranges. First title attempt on this port was guard-ended during startup with current host RAM pressure, before the scene or sparse-run samples, so no FPS/copy reduction claim yet. Guard/settings retained; investigating memory headroom before retry. Native evidence is independent of that incomplete title run. AI-assisted: yes (Codex); no title data attached.
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-13T19:09:09Z.
Rebase handoff — rebased onto current
main(staleness only, applied cleanly), authorship unchanged.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesmainregression (agc_driver_tessellationsegfault, #4727) — not caused by this PRTo pick it up:
Head is
49d2a5cf7.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T23:03:59Z.
On Windows the two new tests
agc_sparse_run_importandagc_sparse_run_import_copiedexit with0xc0000135(DLL not found) and never start. They are not in theif(WIN32)set_tests_properties(... ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")list that the otheragc_driver_recorder_testsentries are in. With that directory prepended toPATHby hand, both pass in 3 of 3 runs; without it, both fail in 3 of 3 runs.Built on
main18c438b10with this PR's commit. Windows 10 (19045), MinGW-w64 GCC 15.2, Release, NVIDIA GeForce RTX 4080 SUPER (driver 610.74). Not tested: Linux, AMD.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-13T23:10:18Z.
@Scramblrrrr @xXPBSXx Thanks for the Windows runs. This was a gap in the PR, not in the older layout: both new tests were missing the
if(WIN32)PATH entry that every otheragc_driver_recorder_teststest has. 510f926b5 addsagc_sparse_run_importandagc_sparse_run_import_copiedto the list withagc_host_import_retirement, which prepends the libc directory toPATHas xXPBSXx did by hand; it is the same one-line change as Scramblrrrr's 693182a5b. Not run on Windows here.@blawesom Thanks for the RADV run. I'm keeping the branch on #4517's head f6c289ea4, so the #4517 commit here stays identical to AlxcBTW's. Your 49d2a5cf7 matches c75fac9a1 patch for patch; 510f926b5 merges with current
main(30f961266) without conflicts.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:48:50Z.
#290 is in now. It changed the import lookup in
GuestBufferMemory.cpp(windowed imports throughimportAccess, with eviction under the budget), so this conflicts there, intests/BdaResources.cppand in the debt file. Can you rebase it? The evicted joined-run case you mentioned is the one to check after.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T03:06:07Z.
One more for the rebase: please drop
APS5_NO_SPARSE_RUN_IMPORT; new paths don't get env switches.Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-14T03:25:14Z.
@oneandonlydean Rebased onto
maina5f493f90(with #4517 and #290) and dropped the switch; this PR is now the one commit a4d8c2931.UploadFinish. A region that isn't a sparse run takes #290'simportAccess; a sparse run takes the path this PR adds, unchanged. The debt file conflicted only on the two entries above this PR's line.tests/BdaResources.cppno longer conflicts, since the #4517 commit this PR carried is gone.main,importRunAtskips the held check for a join.agc_sparse_run_importchecks the join over all four pieces after the growth.APS5_NO_SPARSE_RUN_IMPORTis gone.agc_sparse_run_import_copiednow reaches the copy through a view past the run and checks the copied bytes with a GPU copy through the view.agc_, the same as 9c8fd7687 onmaind1b3aa137, wheremainalone passes 492 of 494; the same two fail throughout (agc_driver_depth_compare_copy, andagc_driver_bc_block_copy: "the guest block is not write-watched" in that container). With the last view ignored, both new tests fail.Evicted joined runs, from the code (no test evicts a joined import yet):
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-14T10:48:19Z.
@adriadam10 Thanks. The list of failing lines came through empty in your comment (the same empty list went to six other PRs between 10:32 and 10:37 UTC). The description passes
tools/check_conventions.py --title … --body …from currentmain(3e577edac), and the conventions check is green on the new head. I've cutDepends onto the template'snone(#4517 and #290 are merged). The branch did conflict withmainsince #4935, on theif(WIN32)test PATH list inlibSceAgcDriver/CMakeLists.txt; it's rebased onto3e577edacwith both lists kept, headd34564be4. If something still fails on your side, which lines are they?AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T10:50:29Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libSceAgcDriver.mdL84Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:01:11Z.
Checked the head merged onto current
main: scoped build and test run of libSceAgcDriver, both new tests pass; the only failures areagc_driver_tessellation(#4727) andagc_recorder_kept_bytes, which fails the same with this PR's changes reverted. The new tests useCutRegions, so they do not build without the change. Windows PATH entry, dropped env switch and debt entry are in place; merging once the Windows Build is green.