Repository navigation
perf(agc-driver): import adjacent registered ranges as one host-import span - #3158
Conversation
…t span A host import covered exactly one registered range, so a buffer crossing two ranges had no import and was copied on the CPU at every use, under the GPU mutex. Titles that map a GPU heap piece by piece (Uncharted maps 1 MiB direct-memory pieces) hit this for every buffer larger than a piece. An import now covers the run of address-adjacent registered ranges that are readable with the same write and GPU access. Runs never overlap, so imports do not either; an import is retired when any range of its run changes, and a refused run is remembered by its base. Callers already address imports relative to their base.
Dextroid17
left a comment
There was a problem hiding this comment.
Two performance changes that share a cause — work serialised behind a lock — though they arrive at it differently: #3159 moves a compile out of the critical section, while #3158 widens a host import so that a buffer crossing two registered ranges stops taking the copied path under the GPU mutex at all. Both descriptions carry the measurement that turns the claim into a fact.
#3158, one import per run of ranges. The pathology is stated in a form that would survive any review: a host import covered exactly one registered range, PPSA05684 maps its heap in 1 MiB pieces, so every buffer larger than a piece had no import and every use was copied on the CPU under the GPU mutex — about 1,000 copies of 9 to 15 MiB per 10 s, roughly 15 GiB per 10 s of guest reads, with the [buffers] ... outside imports line to look for. Covering a run of address-adjacent ranges readable with the same access is the right generalisation, and the four properties you state — disjoint runs, retirement when any range of a run changes, a refused run remembered by its base, and the full-registry path producing the same import — are exactly the ones a reader would ask about. Stating them is what makes the widening reviewable rather than a leap.
#3159, preparing before the lock. This one is sharper still, because the cost is attached to something a player feels: the preparation transaction took the global writers lock when constructed and held it through a compile, so sceAgcCreateInterpolantMapping and sceAgcLinkShaders serialised every thread on one variant build — and the frames over 150 ms spent about 515 ms in Shader.Register against 9 ms in the others. Taking the lock on first use and preparing the variants before reading prepared state is the standard shape, and the samples are what rule out the simpler explanation that the lock was merely contended.
What both get right is the part usually left out: a before figure, an after figure, the log or sample that produced them, and the properties the new code has to hold for the widening to be safe. That is what makes a performance change reviewable instead of hopeful.
Written with AI assistance.
|
Windows run, since the PR was tested on Linux: Windows 11, WinLibs GCC 15.2.0 r7, Release, head
That's Everything else in a full AI-assisted (Claude Code); I ran all of this on my machine. |
|
On Linux (RTX 4090,
So a merged span can be larger than the driver will import in one piece. It needs to stay within what a single import can hold, and an import that fails has to be handled exactly rather than lose the device. ctest passes, so a test that covers a span past that size would help. |
|
Tried this with Ratchet & Clank: Rift Apart (PPSA01474) on Linux with an RTX 4090. It helps with one problem but runs into another. Short version:
So for this title the span probably needs a size cap, or fixed-size aligned chunks (e.g. 64 MiB), so that adding a page never re-imports what's already there. Happy to test a revised version against it. Details and logsSetup:
None of those changes touch Mapping pattern: Without the PR ( Kernel memory charged to the process's cgroup goes ~0.7 → 15–18 GiB → back, with VRAM at 2–7 GiB of 24. With the PR: Kernel memory stays at ~0.2–0.3 GiB. After the refusals the process sits at ~330% CPU in the copy path. Not reproduced: one earlier run with the PR segfaulted ~50 s in inside glibc Tested and written by Claude (AI assistant) on a contributor's machine. |
|
Checked on Linux: PR merged onto current main, libSceAgcDriver build and ctest 349/349; the new |
…ts alias #3158 imports a run of address-adjacent registered ranges as one span. On Windows a shared mapping in the span needs a read-write alias, and MapAlias refuses one unless the range is a single contiguous run of views of one section. Ranges that are adjacent in guest address can be separate views, so the refusal escaped from importAllocation and agc_driver_dcc_keys_first_write failed on main with "read-write alias of shared guest memory ...: the range is not one contiguous run of views of a section". A span whose alias is refused is now remembered, and its ranges are imported one at a time as before spans; a single range that is refused still throws. Claude-Session: https://claude.ai/code/session_012SLQbhAiexxW6TtjYToW8a
|
Follow-up to my comment above, now that this is merged: #3335 bounds spans to aligned windows (8 MiB by default). It joins ranges only when a chain fills a whole window, so heap growth no longer re-imports the chain. With Ratchet over a 4-minute run: 11.0 GB imported in total for 9.4 GB live, no refused imports. It was closed by the intake bot, so it can be reopened or carried, and it composes with #3324's alias fallback. Tested and written by Claude (AI assistant) on a contributor's machine. |
What
A host import covered exactly one registered range. A buffer crossing two ranges had no import, so every use copied it on the CPU under the GPU mutex.
PPSA05684 maps its GPU heap as 1 MiB direct-memory pieces. Every buffer larger than a piece took this path in its first level: about 1,000 copies of 9 to 15 MiB per 10 s (
[buffers] ... outside imports), about 15 GiB per 10 s of guest reads.An import now covers the run of address-adjacent registered ranges that are readable with the same write and GPU access:
ImportMappedRangesimports with the full registry, so it creates the same span.In the first level, CPU copies drop from 15.9 GiB to 316 MiB per run and the frame rate goes from 1.34 fps to 2.76 fps.
Two 12-minute runs reaching the first level (
world-boat-intro); frame rate and median over the last 60 s, copies over the whole run (frame-timing.log):[guestmem] write-changed)Tests in
tests/BdaResources.cpp:importCrossingTestsnow expects the two ranges as one span.importSpanTestscovers: a writable range stays out of a read-only span, a view crossing ranges of different access gets no import, and removing a range retires the span.Tested
BUILD_TESTING=ON.agc_driver_dcc_keys_first_write, fails the same way on plain main 91b1341. Conventions check passed.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)