Repository navigation
perf(agc-driver): join the imports of adjacent ranges of any size that a buffer is bound exactly over - #4517
Conversation
|
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,
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: |
|
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. |
|
Native checks completed on final adaptation c990fc1: 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. |
|
First 007 runtime signal on c990fc1 (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 |
|
007 runtime ended unexpectedly15:23:32 UTC on c990fc1, 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 |
|
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. |
|
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. |
|
@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 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) |
|
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.
#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. |
|
@AlxcBTW Above |
|
@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. |
…m its import 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 takes a heap whose needed extent lies in one releasable registered range. A heap mapped 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 already covering it, the run's own import, or one joined over exactly the run (boykopovar#4517). This applies to any sparse heap no mirror took, including under APS5_NO_LEASE_MIRROR or APS5_NO_SPARSE_HEAP_MIRROR. A join is made only for a region that starts at a registered range, once the previous bind of that address saw the same last mapped byte: a heap that grows between every two of its binds keeps the copy, and one bound more often than it grows is joined again after each growth. Joins stop after 64 per joined run base, with a message: the heap is then bound in place while an existing import covers its run and copied otherwise. The records go with their range. The region's descriptor and BDA ranges end at the import's end, which covers the mapped run and the last view, as the copy does. A region whose mapped part does not start at its base, with a view past the run, written by its shader, or whose run is not imported is copied as before. APS5_NO_SPARSE_RUN_IMPORT=1 keeps the copy. A direct region whose import ends before it outside this path still fails in Descriptor, as before. A set over such a region stays reusable: DirectRegions and InPlaceReads name the region up to its import's end, so the import's serial proves it, and a reuse also requires the heap to be mapped exactly up to that end (CutRegions), checked whenever the imports or the registry changed, so a mapping past the cut makes the set miss. DirectRegions also refuses 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, also under the opt-out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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 My rebase note was out of date; the branch is fine as it is. |
|
@oneandonlydean Yes. On this head ( @AlxcBTW The fix in #5372 is two lines in if (entry != nullptr && region.end > entry->base + entry->bytes) entry = importJoined(context, state, region.begin, region.end, importRanges());
if (entry != nullptr && (region.begin < entry->base || region.end > entry->base + entry->bytes)) entry = nullptr;On this PR, |
…m its import 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 takes a heap whose needed extent lies in one releasable registered range. A heap mapped 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 already covering it, the run's own import, or one joined over exactly the run (boykopovar#4517). This applies to any sparse heap no mirror took, including under APS5_NO_LEASE_MIRROR or APS5_NO_SPARSE_HEAP_MIRROR. A join is made only for a region that starts at a registered range, once the previous bind of that address saw the same last mapped byte: a heap that grows between every two of its binds keeps the copy, and one bound more often than it grows is joined again after each growth. Joins stop after 64 per joined run base, with a message: the heap is then bound in place while an existing import covers its run and copied otherwise. The records go with their range. The region's descriptor and BDA ranges end at the import's end, which covers the mapped run and the last view, as the copy does. A region whose mapped part does not start at its base, with a view past the run, written by its shader, or whose run is not imported is copied as before. APS5_NO_SPARSE_RUN_IMPORT=1 keeps the copy. A direct region whose import ends before it outside this path still fails in Descriptor, as before. A set over such a region stays reusable: DirectRegions and InPlaceReads name the region up to its import's end, so the import's serial proves it, and a reuse also requires the heap to be mapped exactly up to that end (CutRegions), checked whenever the imports or the registry changed, so a mapping past the cut makes the set miss. DirectRegions also refuses 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, also under the opt-out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@TideOPL thanks. Your two lines are in |
|
Fork CI for |
…t a buffer is bound exactly over A bound buffer is joined across adjacent registered ranges only when every one of them is larger than the 8 MiB window. PPSA25344's loading binds 16 MiB and 4 MiB buffers whose backing was registered in two to six adjacent pieces with the same access, some of them smaller than the window, so each use of such a buffer was copied on the CPU: up to 348 GB in the first 300 s of loading. A bound buffer that starts at the first crossed range's start and ends at the last one's end now joins those ranges whatever their size. A heap grown in pieces matches that only for a binding over exactly its current pieces, so growth beside a joined import does not re-import it. joinedCovers, used when a joined import retires, accepts any adjacent run of ranges. importJoinTests binds exactly over two 64 KiB pieces of a partly filled window and requires one import of both; a binding across them that starts inside the first piece stays apart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…part After an exact two-piece join, a bind across the join's end got the joined import from importAllocation and the view failed as "rounded up to its view range exceeds its GPU owner". UploadFinish now asks importJoined for a region past the import's end and drops an import that still does not cover the region, so the region is copied, as on main. The join test binds across the end of an exact join after a third piece is registered. Co-authored-by: TideOPL <57710757+TideOPL@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ea2ea55 to
d275a58
Compare
|
Rebased onto main to resolve the conflict in |
…m its import 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 takes a heap whose needed extent lies in one releasable registered range. A heap mapped 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 already covering it, the run's own import, or one joined over exactly the run (boykopovar#4517). This applies to any sparse heap no mirror took, including under APS5_NO_LEASE_MIRROR or APS5_NO_SPARSE_HEAP_MIRROR. A join is made only for a region that starts at a registered range, once the previous bind of that address saw the same last mapped byte: a heap that grows between every two of its binds keeps the copy, and one bound more often than it grows is joined again after each growth. Joins stop after 64 per joined run base, with a message: the heap is then bound in place while an existing import covers its run and copied otherwise. The records go with their range. The region's descriptor and BDA ranges end at the import's end, which covers the mapped run and the last view, as the copy does. A region whose mapped part does not start at its base, with a view past the run, written by its shader, or whose run is not imported is copied as before. APS5_NO_SPARSE_RUN_IMPORT=1 keeps the copy. A direct region whose import ends before it outside this path still fails in Descriptor, as before. A set over such a region stays reusable: DirectRegions and InPlaceReads name the region up to its import's end, so the import's serial proves it, and a reuse also requires the heap to be mapped exactly up to that end (CutRegions), checked whenever the imports or the registry changed, so a mapping past the cut makes the set miss. DirectRegions also refuses 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, also under the opt-out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…m its import 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 takes a heap whose needed extent lies in one releasable registered range. A heap mapped 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 already covering it, the run's own import, or one joined over exactly the run (boykopovar#4517). This applies to any sparse heap no mirror took, including under APS5_NO_LEASE_MIRROR or APS5_NO_SPARSE_HEAP_MIRROR. A join is made only for a region that starts at a registered range, once the previous bind of that address saw the same last mapped byte: a heap that grows between every two of its binds keeps the copy, and one bound more often than it grows is joined again after each growth. Joins stop after 64 per joined run base, with a message: the heap is then bound in place while an existing import covers its run and copied otherwise. The records go with their range. The region's descriptor and BDA ranges end at the import's end, which covers the mapped run and the last view, as the copy does. A region whose mapped part does not start at its base, with a view past the run, written by its shader, or whose run is not imported is copied as before. A direct region whose import ends before it outside this path still fails in Descriptor, as before. A set over such a region stays reusable: DirectRegions and InPlaceReads name the region up to its import's end, so the import's serial proves it, and a reuse also requires the heap to be mapped exactly up to that end (CutRegions), checked whenever the imports or the registry changed, so a mapping past the cut makes the set miss. DirectRegions also refuses 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. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…m its import 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 takes a heap whose needed extent lies in one releasable registered range. A heap mapped 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 already covering it, the run's own import, or one joined over exactly the run (boykopovar#4517). This applies to any sparse heap no mirror took, including under APS5_NO_LEASE_MIRROR or APS5_NO_SPARSE_HEAP_MIRROR. A join is made only for a region that starts at a registered range, once the previous bind of that address saw the same last mapped byte: a heap that grows between every two of its binds keeps the copy, and one bound more often than it grows is joined again after each growth. Joins stop after 64 per joined run base, with a message: the heap is then bound in place while an existing import covers its run and copied otherwise. The records go with their range. The region's descriptor and BDA ranges end at the import's end, which covers the mapped run and the last view, as the copy does. A region whose mapped part does not start at its base, with a view past the run, written by its shader, or whose run is not imported is copied as before. A direct region whose import ends before it outside this path still fails in Descriptor, as before. A set over such a region stays reusable: DirectRegions and InPlaceReads name the region up to its import's end, so the import's serial proves it, and a reuse also requires the heap to be mapped exactly up to that end (CutRegions), checked whenever the imports or the registry changed, so a mapping past the cut makes the set miss. DirectRegions also refuses 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. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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