perf(agc-driver): join the imports of adjacent ranges of any size that a buffer is bound exactly over #4517
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4517"
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 AlxcBTW on 2026-10-12T14:09:38Z.
Sword of the Sea (PPSA25344) loading: 16 MiB and 4 MiB buffers bound over several small adjacent registered ranges are imported once instead of copied on every use. CPU copies outside imports drop from 256-348 GB per loading run to 2.3 GB.
What
The join from #4515 imports adjacent registered ranges as one when a buffer is bound across them, but only when every range is larger than the 8 MiB window. The title's loading screen binds fixed 16 MiB and 4 MiB buffers whose backing is registered in two to six adjacent pieces with the same access, and some pieces are smaller than the window. A diagnostic build listed the first nine such regions of a loading run. Each one starts exactly at a range's start and ends exactly at a later range's end, for example:
0x32609f0000+0x1000000over0xc60000 + 0x3a0000;0x304df90000+0x1000000over0x810000 + 0x70000 + 0x780000;0x32c7810000+0x400000over0x210000 + 0xd0000 + 0x20000 + 0x100000.No import covers such a buffer, so every use copied it on the CPU.
Now
joinedRunalso joins a run of any range sizes when the bound region covers it exactly, from the first range's start to the last range's end:joinedCovers. It is used when a joined import retires (its shadowed units go back to the ranges still registered) and now accepts any adjacent run, so a unit inside a joined run of small ranges still counts as registered.The TechnicalDebt entry for host imports names the new case.
Tested
Windows 11, WinLibs GCC 15.2.0 r7, Release, on top of #4515.
importJoinTests(inagc_driver_graphics, RTX 5070 Laptop): a new check binds a buffer exactly over two 64 KiB pieces of a partly filled window and requires one import of both. The existing check (a binding across them that starts inside the first piece stays apart) still holds. Passes; with thejoinedRunchange reverted, it fails witha buffer bound exactly over two pieces no larger than the import window was not imported as one.Non-GPU suite (
ctest -E "^agc_driver|^video_out|^guest_video"): 600 of 601 pass;log_macrosfails as onmainon that machine.Sword of the Sea, New Game into the first scene (our lab branch:
mainplus local patches for this title, upstream default env, join on):With the change, 83 imports log
joined at bind, and the scene's picture shows from t420. Without it, the 1800 s run first showed it between its t300 and t600 captures. No GPU event or device loss occurred.Conventions:
tools/check_conventions.pypasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T14:53:42Z.
Pre-review found a deterministic test failure on Linux/RADV — flagging early since full CI doesn't run automatically on PRs.
Independent pre-review (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV GFX1201):tools/check_conventions.pypasses.agc_host_import_retirefails 3/3 runs (deterministic):vkCmdCopyBufferis core Vulkan 1.0 and present on this device, so the failure is in how the new code resolves it: the retire path callscontext.Resolved(&DeviceFunctions::cmdCopyBuffer, ...)on a route where the test's context has nocmdCopyBuffertable entry and nodeviceProcfallback —Context.hpp'sFunction()then throws. Worth checking whether the test context needs the table entry, or whether the call belongs on a layer that always has the resolver.Everything else passes (949/950 — only this test).
Also worth noting: this PR contains all of #4515's commits (the "adjacent large ranges" version) plus its generalization — listing #4515 in Depends on (or closing it as superseded) would make the relationship explicit for reviewers.
Reproduce:
ctest -R agc_host_import_retire --output-on-failureImported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T15:05:46Z.
Preparing a Windows 007 cross-test of your #4515 + #4517 heads7a99692b/da93351f. Our diagnostic run on0e981f4e (all public Sleg hull-v1 commits plus #4017/#1359/#3471) reaches rendered menu ~1.4FPS under APS5_PROFILE_DRAW=1, then black frames after Resume. Completed CPU-copy reads grow from340459MiB at menu to1281216MiB after ~5minutes loading; all counted outside imports. Sparse trimming/mirroring is already enabled. This is cumulative traffic, not resident RAM.
Source-only port https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-joined-import-cross-test head481d840452a34814d909f56099f15bfedfe2a4a6 is building now. Includes Angel21PC Windows non-contiguous alias87af6e09; our integration already has map-node retirement/KeepThroughHold/holder parking. Resolved conflicts preserving our end-aware single-range window imports, adaptive import budget/eviction, per-build pointer protection and #4017 unlocked-refusal handling. Author fixtures retained alongside our whole-range and relief fixtures. No new upstream PR, no claimed 007 benefit yet. I will report native checks and whether actual joined-at-bind imports reduce those copies. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T15:12:43Z.
Native checks completed on final adaptation c990fc176a714ead3241d93645826488651cad64: nine targeted tests pass (graphics author join fixtures plus existing whole-range/relief cases; guest_memory Windows alias; copied/direct ordering; retirement/at-map; storage snapshots/upload; mid-hold import lifetime). Native lifetime fixture is mocked, not a GPU race reproduction. Exact-small-span negative control retaining all fixtures but refusing joinedRun's exact-span case fails specifically 'a buffer bound exactly over two pieces no larger than the import window was not imported as one'; restored9/9 pass, conventions clean.
Two adapter issues caught and fixed by retained fixtures: fresh end=0 lookup must not mark a shorter window as used before replacement; join boundary probes must not count as uses. Ordinary replacement/eviction retains per-build pointer protection; pre-confirmation joins use the existing extracted-node/KeepThroughHold lifetime and epoch invalidation, as in your branch. Runtime now staging graphics and the required Windows-alias libc only; originals backed up. Same warm cache and PROFILE_DRAW settings as preceding 007 diagnostic. No benefit claim yet. Final branch https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-joined-import-cross-test . AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T15:18:47Z.
First 007 runtime signal on c990fc176 (still running, not gameplay): same PROFILE_DRAW config/warm cache as0e981f4e. At exactly34,000 resource builds, guest-memory upload drops29710→4890ms and image preparation39556→21716ms; bindings767→761ms/precollect2643→2561ms. Startup/autosave and health screens render
2.05–2.10FPS versus preceding autosave1.62FPS. Last copy counter7,000operations/46,307MiB, and the old prominent0x3f10000000 copy bucket is absent so far. Cumulative traffic, not RAM; startup screen advancement/control timing differ, so not a whole-run copy ratio or playable-FPS claim. New private~16.4GB. No native builds during this run. Continuing to menu/Resume; I will report the result. Host-import trace was not enabled in this run, so no joined-at-bind diagnostic line yet. AI-assisted: Codex.Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T15:25:08Z.
007 runtime ended unexpectedly15:23:32 UTC on c990fc176, exit0xc0000005 (access violation), below memory guard limit. Last UI sampled15:23:06 was black frame1862~6.53FPS (~80s after Resume15:21:44); no visible level. Last private24.116GB/free5.943GB. Crash reported on guest RenderThread, read of0x40 with RSI=0; reported instruction location game-dump-modules.exe+0x17bd927 (not a native libSceAgcDriver frame). This identifies the detection site only; not attributing the invalid guest state to this PR. Local dump retained privately, no game instructions/data uploaded. Earlier unsupported image-table writeback pcs0x224/0xa4 still occurred. No debugger attached.
Performance lead remains: matched34k resource checkpoint upload29.710→4.890s, images39.556→21.716s; title/menu
1.8–1.9FPS under profiling vs preceding1.4; load advanced quickly before the crash. Last CPU-copy counter20k/209740MiB, no0x3f10000000 bucket yet. Needs repeat/control to separate newly reached guest failure from integration regression. Will inspect locally and cross-test. AI-assisted: Codex.Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T15:35:53Z.
Alias-dependency control: old graphics0e981f4e with the same new libc5A176460..., same cache/PROFILE_DRAW settings. Matched34,000-build upload30391ms/images39932ms versus joined graphics c990 upload4890ms/images21716ms. Original old-graphics/old-libc run was29710ms/39556ms. Thus the required alias library alone does not explain the measured preparation gain. Large0x3f10000000 outside-import CPU-copy bucket returns (29,431MiB already during startup); title frame959~1.16FPS/private19.91GB. One run each, FPS not fixed-frame matched. Control is still running toward Resume, to compare the guest null-pointer crash. No native builds during measurements. A new synthetic GPU writer/copy check across two registered ranges is prepared but unbuilt/unpublished so far. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T15:47:44Z.
@blawesom fixed in #4385's
63ddeb09f(the Linux write-protection probe hit the test's mock device, not the retire path); details on #4515. Merged into this branch as 2a479b422.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T15:55:30Z.
Windows follow-up: alias-only control (graphics0e981f4e, same new multi-section libc5A176460) ended deliberately15:46:59 UTC at black frame2015~0.07FPS, private28.16GB/free3.09GB. Same unsupported image-table operations reached, no logged access violation before shutdown. Completed CPU copies101k/1439788MiB cumulative. Matched34k resource builds: upload30391ms/images39932ms, close to original29710/39556; joined c990 was4890/21716. One run each; late progress differs, so absence of crash is not regression proof.
Added actual Windows Vulkan crossing-writer/copy test on fork head0d8bbef5712c3ed67dfc81a2ddbb47657a8a99c4: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-joined-import-cross-test . Dispatch stores across two adjacent registered ranges, requires one import covering output, then copies and checks bytes/boundary guards. Disabled large-range joining with fixture retained: FAIL at covering-import assertion0.39s; restored final2/2PASS0.65s, no skips. This tests that path, not the game's terrain readback race. Production remains c990; newest commit tests only.
@SleglJan Thanks for the crash breakdown. I will repeat quiet at6GiB first, with host-import diagnostics, then compare a larger budget if it recurs. Same signature suggests newly reached readback failure, but I will not attribute it without the comparison. All title data/dumps retained locally only. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T16:58:10Z.
@Scramblrrrr thanks a lot for the 007 cross-test, that's exactly the independent evidence these two need. At the matched 34k-build checkpoint the joined head goes from 29.7 s to 4.9 s upload and from 39.6 s to 21.7 s image preparation, and the alias-only control stays at 30.4 s / 39.9 s. So the join, not the alias library, removes the outside-import copies (including the 0x3f10000000 bucket).
On the RenderThread crash (read of 0x40 with RSI=0 in guest code, not a driver frame): one candidate worth ruling out is #361. On Sword of the Sea, parl0v just proved that Windows writes the exception frame below
rspwhen a guest store faults on a shared view (WindowsMappings::HandleWrite), which zeroes red-zone locals of leaf functions; the crashing leaf then reads a pointer back as 0. Faster loading means more first-touch faults on freshly mapped ranges, so a run that gets further can hit it more often. A ring of resumed faults in the vectored handler (thread, rsp, rip) shows it directly: a shared-view write fault on the crashing thread at the crash rsp, 0 ms before.Your crossing-writer Vulkan test (dispatch storing across two adjacent registered ranges, one covering import, byte and boundary checks) would be a good addition to #4517. If you're fine with it, I'll cherry-pick it with your authorship.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-13T10:14:53Z.
Tested on Minecraft Dungeons II (PPSA16064): Windows 11, RTX 5070, WinLibs GCC, Release, gameplay at the Squid Coast spawn, trace window 25-40 s after the HUD appears (#4526 trace,
APS5_TRACE_SECONDS=25:15).In gameplay, Unreal binds buffers exactly over 2 to 5 adjacent registered pieces of the one direct-memory allocation (for example
0x306a280000+0xa00000over0x810000 + 0x1f0000, or0x322b8b0000+0x200000over five pieces). Without this change none of them could be imported (the 8 MiB window), so they were copied on the CPU, which also made those builds non-reusable. That was about 300 full resource builds per frame on queue 0, and the frame time depended on where the heap placed them: p50 118 ms in one run, 158-229 ms in others.With #4515 + #4517 (and #4367) on
mainplus the patches MCD2 needs to reach gameplay: p50 131 ms, p99 139-155 ms, steady across 5 runs. Queue-0 resource builds drop to about 50 per frame. (An older build without the join ran about 4.8 FPS at the same spot, on a different base.)Not run: Linux, AMD, the PR's own tests.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T10:32:06Z.
Same as #4515: rebase onto main without the merge commits (six here), keeping only #4515's commit and this one.
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T11:46:36Z.
Rebased onto current main on top of the rebased #4515, so the branch holds only #4515's commit and this PR's commit, without merge commits. The debt entry is merged the same way as in #4515. Checked with check_conventions and a full Linux and Windows run on a fork branch before the push (the Windows job hit a one-off agc_driver_wait_shutdown timeout once and passed on re-run).
Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-13T17:37:38Z.
Palworld (PPSA23126, UE5) data point, Windows 11, RTX 3080 (driver 610.74), 32 GB, WinLibs GCC 15.2.0 r7, Release.
Palworld's character creation binds buffers across adjacent registered ranges of its direct memory. With
APS5_PROFILE_DRAW=1on my test branch, where these joins did not happen (see the caveat below),[buffers]reported 16,000-44,000 CPU copies outside imports per run (290-820 GB in total), almost all in 0x3130000000-0x31a0000000, and drawresourcestook 6-7.6 s of every 10 s (uploadalmost all of it). A local trace of the first regions of 1 MiB or more showed three shapes, each starting at a range's start:0x3125480000+0x800000over0x780000 + 0x80000;0x3137de0000+0x18f0000over0x1010000 + 0xfd0000;0x3139de0000+0xa80000over0x810000 + 0x60000 + 0x790000.On
mainffa2a6ecd+ #5003 + this PR (a7851d475, with #4515 in it), the same scene logs 9 copies outside imports (under 1 MiB in total),uploadfalls to 9 ms per 10 s, and the menu ran at 20-22 FPS against 15-17 on the branch that still copied. Character creation is then bound by pipeline compiles on a cold cache and by per-draw cost (about 20,000 draws per 10 s) once warm, at about 1.2 FPS, so the copies were the first wall, not the last.One caveat: when I merged this PR by hand together with #290 (host import windows), the joins did not happen and the copies stayed. I did not find why, so it may be my merge; mentioning it in case the two meet.
AI-assisted (Claude Code); I ran the above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T17:38:57Z.
Thank you @ps54all, that's a strong independent data point. On Palworld, 290–820 GB of outside-import copies drop to under 1 MiB, and the menu goes from 15–17 to 20–22 FPS.
On your caveat with #290, it's not your merge. We hit the same thing on Sword of the Sea: #290's replace loop refuses a join whose new import would replace imports that are still held. With both PRs in, the join is never made and the buffer keeps copying. In our main-based lab build it was 639 GB of copies with both in, and back to the joined behaviour after a small fix that lets a join replace held imports. I'll offer that fix on #290, since it belongs where the two meet.
This PR needs a rebase now that #4515 is merged; that's next on my list.
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T18:24:32Z.
Rebased onto current main now that #4515 is merged. Git dropped the #4515 commit as already applied, so this branch is now only the exact-cover join commit. The fork CI is green on Windows and Linux.
Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-13T18:29:09Z.
Thanks for this. It's in our Minecraft Dungeons II (PPSA16064) test build, and we hit a case it still leaves on the CPU path. I've opened #5372 on top of this PR (it includes your commit) instead of changing the behaviour here, so you can choose what to take.
0x305fca0000+0x160000over0x110000 + 0x30000 + part of 0x50000. When the first bind comes before the 8 MiB window is full,importRunimports the first piece alone andjoinedRunrefuses the partial cover. The buffer is then copied on every draw: about 40k copies in 25 s, and about 280 resource builds per frame. About half the runs land there: p50 113–131 ms against 92–97 ms.importAllocationhands that region the joined import found at its start, andDescriptorfails withrounded up to its view range exceeds its GPU owner. The growth check in #5372'simportJoinTestsreproduces it.#5372's joins would hit the same #290 refusal, so your fix there covers both.
Numbers and test details are in #5372. Happy to fold it into this PR instead if you prefer.
Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-13T18:35:35Z.
@AlxcBTW Above
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T18:38:04Z.
@TideOPL thanks, that's a real gap. The first piece gets imported alone before the window fills, and then the partial cover is refused. I'd keep this PR as it is: it's rebased and green, and it has two independent measurements (Palworld, SotS). #5372 can follow it as the general join, since it changes #4515's "two pieces no larger than the window" expectation and is better reviewed on its own. I'll run #5372 on Sword of the Sea in our next main-based row (current main + the join stack) and post the outside-import copy counts there, so it gets a second title next to Minecraft Dungeons II.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T19:35:19Z.
#4515 is merged now. Please rebase this onto main so it carries only its own commit; the copy of #4515 in this branch (
3fbd63fb0) now conflicts with the merged one.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T22:38:01Z.
TideOPL's note above says this PR alone can reach a throw: after an exact-cover join, once the window around it fills, a bind across the join's end gets the joined import from
importAllocationandDescriptorfails withrounded up to its view range exceeds its GPU owner. Does the growth check in #5372'simportJoinTestsfail on this head? If it does, the fix belongs in this PR, since it turns a copied buffer into a stop.My rebase note was out of date; the branch is fine as it is.
Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-13T22:45:21Z.
@oneandonlydean Yes. On this head (
f6c289ea4) I added only the growth step toimportJoinTests: after the exact two-piece join, register a third 64 KiB piece and bind 32 bytes across the join's end, with no expectations. It fails withAGC graphics: guest buffer view …+0x20 rounded up to its view range exceeds its GPU owner …. Withmain'sGuestBufferMemory.cppthe same bind passes; it's copied. So I agree it belongs here.@AlxcBTW The fix in #5372 is two lines in
UploadFinish, after theimportAllocationcall for a region a window run covers:On this PR,
importJoinedrefuses the partial cover, so the region falls back to a copy, as onmain. Feel free to take it with the growth step; I'll drop it from #5372 once it's in here.Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T23:13:39Z.
@TideOPL thanks. Your two lines are in
ea2ea5518(with you as co-author), andimportJoinTestsnow does your growth step: after the exact two-piece join it registers a third 64 KiB piece and binds 32 bytes across the join's end. Fork CI for the head: run 38482881106, running. You can drop it from #5372 once that's green. @oneandonlydeanImported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T23:36:43Z.
Fork CI for
ea2ea5518is green on Linux and Windows (run 38482881106), the growth step inimportJoinTestsincluded.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T00:46:21Z.
Rebased onto main to resolve the conflict in
docs/dev/debt/libSceAgcDriver.mdafter #4603 (kept both entries); no other change.