perf(agc): leave a lazily registered shader's resolved ABI to its first use #7644
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7644"
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 EagleBearerYS on 2026-10-18T19:20:36Z.
What
Under
APS5_LAZY_SHADER_PREPARE=1, registration prepares nothing. ButResolveShaderAbistill planned and prepared every compute or pixel stage whose ABI the title resolved. A title that resolves every shader's ABI therefore prepared them all at boot, whether they ever drew.Resident Evil Village (PPSA01556) is such a title. Its prepared shaders take a large part of its private memory at the menu: this PR saves ~3 to 4.5 GB there (see Tested), more than the ~2–3 GB we had estimated from per-program holders of ~0.5 MiB across ~6,000 programs.
With lazy preparation,
ResolveShaderAbinow:Then the shader's first draw or dispatch plans and prepares the queued ABIs with that state, before it looks for its artifact.
Concurrent first uses. The first use of a shader with deferred ABIs marks the shader while it prepares them, then publishes all their entries together under the shader's lock. A use from another queue that arrives meanwhile waits on the shader's existing condition until they're published, then matches the published entry, so each ABI is prepared once. If no entry matches (its preparation failed, or the use's state differs), each use prepares its own entry, as without deferral. After the first use, the lookup reads one more flag under the lock it already holds.
Which workloads it helps. The saving is the memory of entries prepared for resolved ABIs that a title never draws or dispatches with.
mainat 600 s.APS5_LAZY_SHADER_PREPARE=1.Cost at first use. The preparation moves from resolution to a shader's first draw or dispatch, on the queue worker. The Village pairs below are at the static menu, so they can't show it. A Resident Evil Village pair across the transition from the menu into first gameplay, on a warm shader cache, with and without this PR (comment, and Tested): 24:11 from Yes to the first lit gameplay frame with it, against 24:00 without, and the worst frames within the same range (85.5 s against 133.0 s at the top). On that memory-bound machine, a first-use cost smaller than its paging stalls wouldn't show.
The commits:
Driver::PreparedEntriescounts a registered shader's prepared entries, for the test.The change.
test(agc): the lazy resolved ABI test's eager reference runs without the switch.test(agc): a lazily resolved ABI's entries, libraries and cache files are compared with eager preparation's.test(agc): stale-state cases of a deferred ABI are compared with eager preparation.test(agc): a deferred compute ABI is checked under lazy preparation.Commits 3 to 6 came from an adversarial review. They're described under Tested.
A counter for whether a deferred ABI's first use finds its artifact among the queued entries. It tells whether the queued preparation is the use's own work or extra, through
Driver::DeferredAbiUsesand a[shaders] deferred ABIs: ...line.fix(agc): a deferred ABI is prepared once when queues make its first use at once (above).fix(agc): the[shaders] deferred ABIsline prints only underAPS5_PROFILE_DRAW, through the profile output the[rescache]lines use.Where the end state can differ from eager preparation, with no wrong state:
Tested
agc_driver_lazy_resolved_abiruns one scenario with eager and with lazy preparation, and compares the lazy run's end state with the eager run's.agc_driver_lazy_resolved_abi_switch_setruns it withAPS5_LAZY_SHADER_PREPARE=1exported.agc_driver_prepared_shaders_abi_deferred_compute_lazyresolves a compute ABI under the switch. Neither resolution builds a front end, and the first dispatch links both callees and writes the expected value in every lane.agc_driver_prepared_shaders_abi_deferred_concurrent_lazy(commit 8):ShaderRegistry.hppandShaderRegistry.cppas before commit 8, in 20 of 20 runs: "four queues making the first use of one deferred ABI at once did not prepare it once (2 front-end builds, 2 prepared entries, 1 first uses, 0 found, 0 own, 0 entries used)". Green in 20 of 20.The profile line (commit 9): without
APS5_PROFILE_DRAW, no[shaders] deferred ABIsline. With it:[shaders] deferred ABIs: 1 prepared at first use, 1 found their artifact there, 0 prepared their own; 1 of the 2 entries prepared from them never matched a use.Linux, CI's configuration (a cloud worker), at the head:
agc_driver_lazy_resolved_abi,agc_driver_lazy_resolved_abi_switch_set,agc_driver_prepared_shaders,agc_driver_prepared_shaders_abi_deferred_compute_lazyandagc_driver_prepared_shaders_abi_deferred_concurrent_lazypass 20 runs in a row.^agcpasses 795 of 797 (57 skipped). The two failures also fail onmain:agc_driver_sgpr_pattern_fill_keysfails under the sweep's parallel load, andagc_driver_storage_read_during_idle_storefails in about 1% of runs on that machine (alone: 4 of 360 runs at the head, 3 of 360 at the base).Resident Evil Village (PPSA01556), Windows 11, NVIDIA GeForce RTX 3070 Laptop GPU, one run each. Both runs use our test tree (
mainwith #6366 and other open PRs of ours) plus #6178, withAPS5_LAZY_SHADER_PREPARE=1, heap counters on (APS5_PROFILE_HEAP=1) and GPL on. Private memory at the menu:APS5_RELEASE_SPIRV=1) was at 21,485 MB at menu + 1.Resident Evil Village (PPSA01556), a second pair with traces, on the same two trees: without the change (964a4ea473) and with it (174358bd0d). Windows 11, NVIDIA GeForce RTX 3070 Laptop GPU (driver 617.42),
APS5_LAZY_SHADER_PREPARE=1, GPL on, no heap counters, a warm shader cache in both (an untraced boot filled it first), one run each, menu only. The GPU was at P0 for 100% of the samples in both runs (mean 1,293 and 1,294 MHz); clocks weren't locked.Private memory at the menu: 25,629 / 26,236 MB without the change and 21,510 / 22,072 MB with it at + 1 / + 10 min, −4,119 / −4,164 MB. That's the same saving as the first pair.
Frame times at the static menu, minutes 5 to 15: 13 presents in 530 s without the change (0.0245 fps, median frame 38.9 s) and 12 in 531 s with it (0.0226 fps, 42.6 s). One frame either way at ~40 s a frame, so this pair can't resolve a frame-time difference; the change is to memory.
The summary line from the middle of each arm's menu window, without and then with the change:
tools/trace_digest.pyon those two lines:2 intervals, 1958.0 to 2012.0 s, 2 presents
NVIDIA GeForce RTX 3070 Laptop GPU, NVIDIA 617.42, Windows 10.0.26300, 3840x2160, commit 964a4ea47335
commit, environment, GPU, driver or OS changed at interval 2
The two traces are on this fork release. Their 60 s windows (
APS5_TRACE_SECONDS=900:60) fell in the intro, about 6 to 7 minutes before the main menu, since these trees take ~23 minutes to reach it.Resident Evil Village (PPSA01556), a third pair on this head (
1ba22061e3), menu only, one run each. Windows 11, NVIDIA GeForce RTX 3070 Laptop GPU; clocks weren't held, and no GPU timing is claimed.main1ff5c8ac5cwith #8926's fix (63d5414338), which Resident Evil Village needs on thatmainto get through its intro. One has this PR on top, and one doesn't.APS5_LAZY_SHADER_PREPARE=1, GPL on,APS5_HOST_IMPORT_MIB=6400, a warm shader cache, no profiling, no input.Resident Evil Village (PPSA01556), the menu → first gameplay transition on this head (
1ba22061e3), one matched pair (comment, with the summary lines and digests). Windows 11, NVIDIA GeForce RTX 3070 Laptop GPU; clocks weren't held (P0 at 1,290 MHz in the slow intervals).main1ff5c8ac5cwith #8926's fix (63d5414338), with and without this PR.APS5_LAZY_SHADER_PREPARE=1,APS5_NO_GPL=1(with GPL on, this PC doesn't load past the menu),APS5_HOST_IMPORT_MIB=6400andAPS5_TRACE_SUMMARY_EVERY=1. Warm shader cache, the same route and the same host-import mode.A harness on a cloud worker (Linux, lavapipe):
The adversarial review (a cloud worker). Its question: can a deferred preparation run with different state from what eager resolution would have used? The answer is no.
agc_driver_lazy_resolved_abi_switch_set).GitHub's runners at
1ba22061e3(run): the five tests above pass 5 runs in a row on Linux. On Windows they need Vulkan and skip. The libc and libkernel suites pass on both.Checklist
mainf47c856634, rebased, and it merges cleanly with currentmain; 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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T19:20:52Z.
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 fma-rc on 2026-10-19T14:51:24Z.
@EagleBearerYS here's Astro's Playroom (PPSA01325) with
APS5_LAZY_SHADER_PREPARE=1on this head (40e0d968c3) and on themaincommit it merges (324e0e48e0). Linux, RTX 5080, one run each, 600 s with Cross pressed every 4 s. Private memory isPrivate_Clean + Private_Dirtyfromsmaps_rollup:mainPlayroom shows no saving here. I don't have Resident Evil Village, so this doesn't test the ~4.5 GB in the description.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-19T17:51:02Z.
Review: COMMENTED
The memory result is clear and repeats (menu private memory down 4,489 and 4,119 MB across two pairs, 21.4-21.9 GB against 25.6-26.5 GB), the cold-cache control shows it isn't the shader cache, and the test compares the lazy end state with eager preparation entry by entry.
What the PR does not show is the price. The preparation does not go away; it moves from boot to a shader's first draw or dispatch, on the queue worker.
[shaders] deferred ABIscounter is diagnostics that prints to stderr every minute for everyone. Put it behind a profile switch, or keep it out of the PR.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T11:46:49Z.
Review: CHANGES_REQUESTED
Thanks, the lazy-vs-eager end-state test is a good check. Before this can merge:
main, and the history. #6366 is merged, so please rebase ontomainso only this PR's commits remain (no merge commits, per CONTRIBUTING).[shaders] deferred ABIs: ...line goes to stderr every minute for every user (ShaderRegistry.cpp, the newfprintf(stderr, ...)). Put it behind a profile switch or drop it from this PR.Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-21T05:58:15Z.
@adriadam10 @CnRJay, thanks for the reviews.
1ba22061e3is a rebase ontomainwith two new fixes. Point by point:History. The branch is rebased onto
mainf47c856634, and it merges cleanly with currentmain.main.Once per ABI (
4eeeeb6438).agc_driver_prepared_shaders_abi_deferred_concurrent_lazysubmits the first dispatch of one deferred ABI from four queues at once, and requires one preparation that all four use. It failed in 20 of 20 runs before the fix ("2 front-end builds, 2 prepared entries, 1 first uses, 0 found, 0 own, 0 entries used"), and passes in 20 of 20 with it. On GitHub's runners (run) it and the four other lazy and prepared-shader tests pass 5 runs in a row on Linux; on Windows they need Vulkan and skip.The counter line (
1ba22061e3) prints only underAPS5_PROFILE_DRAW, through the profile output the[rescache]lines use. The counters still count, for the tests.Which workloads. The saving is the memory of entries prepared for resolved ABIs that a title never draws or dispatches with. Resident Evil Village (PPSA01556) resolves every shader's ABI at boot, and saves ~4.1 to 4.6 GB at the menu. @fma-rc's Astro's Playroom (PPSA01325) run shows no saving. Without
APS5_LAZY_SHADER_PREPARE=1nothing changes. The description now says this.The cost at first use. A Resident Evil Village pair across the transition from the menu into first gameplay is queued, on a warm shader cache, with and without this head, both under
APS5_LAZY_SHADER_PREPARE=1. It will give the worst frame times, the time from starting the game at the menu to the first stable gameplay frame, both summary lines and the digest. I'll post it when it's in.Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T02:15:49Z.
@adriadam10 @CnRJay, here's the Resident Evil Village (PPSA01556) transition pair from the menu into first gameplay, as promised: one matched pair, without and with this PR.
Setup
main1ff5c8ac5cwith #8926 (63d5414338), and the same with this PR's head1ba22061e3(074e31acbe).APS5_LAZY_SHADER_PREPARE=1,APS5_NO_GPL=1,APS5_HOST_IMPORT_MIB=6400, andAPS5_TRACE_SUMMARY_EVERY=1(summary lines only, no trace window).nvidia-smishowed P0 at 1,290 MHz in the slow intervals.APS5_NO_GPL=1, and its memory compares only within the pair. In this pair, private memory at the menu is 415 MB higher with the change; it doesn't show whether the description's GPL-on saving carries over toAPS5_NO_GPL=1.Results
Per frame over the frames above 2 s, counted where a phase is among the frame's eight largest:
Driver.Packet.memory_waitDriver.Packet.dispatchResources.CompleteGraphics.Draw.draw_and_resource_releaseShader.DrawStageShader.ResolveGraphicsStagesAbi"First lit gameplay frame" is the end of the opening scene's fade-in. Gameplay then runs at about 0.1 fps on this machine, so there's no stable frame rate to time.
Reading: there's no measurable difference in the time into gameplay or in the worst frames. With the change, the shader disk cache was asked for half as many entries, which fits the entries it leaves unprepared. But both runs are memory-bound: page-ins run at about 5,000 to 45,000 a second, and
Driver.Packet.memory_waitis the largest phase of the slow frames. So a first-use cost smaller than the paging stalls wouldn't show here. The first minute of gameplay is slower with the change (10.5-11.7 s against 7.6-9.5 s per frame), while the run without it has a 22.9 s frame with 8.7 s inShader.DrawStageand 8.6 s inDriver.Draw.shader_compile_and_link. One pair on this machine can't separate those from paging. I can run a second pair if you'd like one.An earlier warm-up run with the change used the other host-import mode, which turns up on any tree, so it isn't compared here.
The first gameplay summary line of each run, and the digest of the first minute
Without (
trace_digest.py):With this PR:
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T05:07:41Z.
Overlap note from PR #9626: I added a process-private-memory admission check to the non-lazy registration path, so it touches the RegisterShader branch changed here. To avoid conflicting sequencing, I marked #9626 as depending on #7644 and will adapt the guard after this PR’s disposition. If you prefer a different order or think these changes should be integrated together, please let me know. I have not changed your branch.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T05:11:30Z.
Update on my earlier overlap note: I moved the memory admission check into
PlanRegistered, outside theRegisterShaderhunk changed here. The current overlap check no longer reports a direct conflict with #7644, so #9626 no longer depends on it. Please disregard the previous sequencing note; I have not changed your branch.