perf(recompiler): read the buffer stride and presence at run time in compute modules #5353
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5353"
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 Pipodi on 2026-10-13T17:44:39Z.
What
A specialized compute module bakes four words of each buffer V#: the stride (
dwords[1] & 0xffff0000), the format word (dwords[3]), whether the buffer is present, and the base misalignment. When a program is dispatched with a different stride, or once with an absent buffer and later with a real one, the module differs only in those constants. The driver still compiles each one as a new pipeline, from scratch.With this change compute modules read the stride and the presence from the V# at run time, the way registration-form modules (#4152) already do:
descriptor()takesword1andpresentfrom the V# operands for compute stages. The record count was already a run-time value there.DescriptorBindingBuilder::Prepareno longer adds those two constants for compute stages, so modules that differ only in them get the same specialization and the same pipeline.What stays baked: the format word, because a run-time format makes the driver compile every format decoder (#4152 item 13), and the misalignment, because the unaligned store loops it would otherwise keep caused hangs (#4152 item 15). Graphics stages are unchanged.
Why
Ghost of Yōtei (PPSA26344) dispatches its largest compute programs (1.1–1.5M SPIR-V words) first with one buffer absent and later with it present. The two modules are structurally identical: diffing them shows only 44–132 constants changed. These are the absent buffer's stride, its presence flag, and the folded results (
8 → 192,false → true). A cold boot builds both.Measured offline:
agc_compute_pipeline_replay, RTX 4090, driver 617.42, fresh driver cache per run, idle machine. Modules from captured pipelines; for the run-time form, the constants that differ between a pair are replaced with push-constant loads.0x800022d100present, specialized0x800022d100present, stride and presence at run time0x8000261500present, specialized0x8000261500present, stride and presence at run timeReading the two values at run time does not slow the driver's compile down, unlike the run-time format and component selectors measured in #4152. A cold boot of this title then compiles 13 fewer giant pipelines, about 103 s on this machine. That's 18% of those programs' compile time.
Tested
Windows 11 Pro 26200, RTX 4090, driver 617.42.
agc_driver_buffer_descriptor_runtime: newstride 16case. In specialized form thealigned,records 37,stride 16andabsentcases must give byte-identical SPIR-V and the same pipeline variant, and every case still checks the values it reads. Onmainthe new check fails ("the stride, record count or presence of the V# changed the compute module").ctest -j 16): 1096/1097.agc_driver_pixel_ldsfailed once under the parallel run; on its own it passes 4 times in 4. It's a pixel-shader test this change doesn't touch, and #4152 reports the same test as unstable on an RTX 4090.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (none).mdfiles or images added to the repository🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T00:53:38Z.
Review: COMMENTED
Well-documented change, and the compile-time measurement is careful. One side of the trade-off is missing, though: what the run-time form costs when the pipeline executes.
Specialization constants are there so the driver compiler can fold the stride into every address computation and drop the code of an absent buffer entirely. Reading them from the V# turns that into per-access ALU work, an extra predicate per load/store, and, for 1.1–1.5M-word programs, possibly higher register pressure. If occupancy drops, every dispatch of these programs gets slower for the rest of the session. The replay table shows the compile doesn't get slower, but not whether the dispatch does.
The two costs are also paid at different times:
Before this goes in for all compute stages, I'd like to see GPU time for these dispatches in both forms: the trace's GPU ranges for the Yōtei programs, or
agc_compute_pipeline_replaytiming a dispatch rather than the compile. If one form costs measurably more on large programs, a narrower option is to read stride and presence at run time only where a variant with a different stride or presence was actually seen for the program. That covers the absent-then-present pattern here without changing every compute module.The code changes look consistent with the registration-form path (
descriptor()reuses its run-time presence expression,Preparedrops exactly the two constants), and the newsameModulechecks are a good guard.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T05:10:49Z.
CnRJay's question is the one that decides this: compute modules now read the stride and presence at run time, which may cost GPU time on every dispatch, and the 103 s saved is a cold-cache cost only.
Please add the summary lines of main and of this change from the same machine and scene in PPSA26344 after a warm-up (warm driver cache), so the in-game cost shows, per the performance template.
Imported from boykopovar/AnyPS5. Originally posted by Pipodi on 2026-10-14T12:24:07Z.
I measured on PPSA26344 what @CnRJay and @oneandonlydean asked for: the GPU time per dispatch, and the template's summary lines after a warm-up. In short, I found no measurable GPU cost. The run-time form does add a cold-boot cost that the PR description doesn't mention.
Builds. Both builds are this PR's base
18c438b10plus the same additions.git diff A Bis identical to this PR's diff. The additions are what the title needs to boot and reach the scene:18c438b10; without it both builds abort on format 169);e5449936fthrows. It never fired on this base.None of these change how buffer accesses are emitted. Machine: RTX 4090, NVIDIA 617.42, Windows 10.0.26200, 3840x2160. Both builds ran with the same env:
APS5_HOST_IMPORT_MIB=16384 APS5_STAGING_POOL_MIB=2048 APS5_PREPARED_SPIRV_MIB=6144 APS5_NO_SNAPSHOT_CHECK=1.Scene. The loading phase, presents 700 to 760 (
APS5_TRACE_FRAMES=700:60), where the large compute programs are dispatched. A later scene was out of reach: about 10 minutes after the loading spinner, the title takes commit headroom to 0 on this 32 GB machine.Runs. For each build, I ran warm-up boots until the shader disk cache was complete. Then I restarted it with only the trace switch set. Every capture had 0 disk cache misses. I captured A twice, before and after B, to see how much boots differ.
Summary lines (presents 700 to 760):
The two A captures differ by 6.4% in GPU busy time, and B is 3.6% below their mean, inside that spread. Frame times in this window are set by CPU shader preparation (8 prepare threads about 90% busy,
Shader.PrepareArtifactthe top phase), not by the GPU. So I don't read anything into the frame time differences either.Full summary lines
GPU time per dispatch (
APS5_PROFILE_GPU=1, warm, presents 100 to 500; no pipeline was built in this range in either run):0x800036e1000x80003cb2000x80002531000x80003a1d000x80003c81000x80003cee00The programs that take the most GPU time are within 5% either way. Programs under 1 ms vary by up to 20% in both directions. In presents 700 to 760,
0x80001e5f00(1.8M words) took 10.65 ms per dispatch in A and 10.17 ms in B. B's run built a pipeline inside that range, so I'd only take the direction from it. These numbers come from[gputime], which lists the 12 hottest programs per 10 s.Cold boot, not in the description. With empty caches, B shows its first frame at about 462 s, against 141 s for A. The absent-buffer variants were cheap to build: A builds
0x8000289300's first variant in 10.7 s. In B that program always has its full code, so its first build takes 86.5 s, about what A pays later for the present variant (85 s). Builds hold the GPU mutex on main, so this cost lands before the first frame. The giants also still build a second full variant in B (0x800022d100: 50.5 s, then 58.0 s), because only the stride and presence split goes away. I couldn't measure end-to-end cold time to the same present: the cold A run aborted (before #4487 was added) and the cold B run ran out of disk space. Once warm, B shows its first frame at 40 s.So: in this title I found no GPU cost per dispatch or per present. The trade is a cold-only one: fewer variants in total, at the price of a longer wait before the first frame. Celegans12 reported on #675 that specializing buffer slots that are null when first bound took these programs from 37 variants to 6. That keeps the cheap builds, so it may be worth comparing with this PR or with the narrower option.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:07:35Z.
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)core/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppL63Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppcore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppcore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppcore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppcore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppImported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-16T21:54:23Z.
Review: COMMENTED
Thanks @Pipodi, this answers the question I asked: no GPU cost per dispatch or per present, with the top programs within 5% in both directions and the A/A spread (6.4%) larger than the A/B difference.
That leaves the cold boot as the real price of this change: first frame at about 462 s against 141 s, because the stride and presence split no longer lets the large programs build a cheap variant first. That is a regression for every first launch with an empty cache, and the description should state it. The shipped trade is "fewer variants in total, 3x longer wait before the first frame", and a user who has never run the title sees only the second part.
Two things to settle before this goes further:
0x8000289300should not run under that lock.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-16T23:29:25Z.
Agreed with @CnRJay's review. The cold-boot cost (first frame at about 462 s against 141 s with empty caches) should be in the description, since it's what every first launch pays. Before this goes further I'd also like the comparison with the narrower option from #675 (specializing slots that are null when first bound), and, if the run-time form stays, the 86.5 s build of
0x8000289300moved out from under the GPU mutex.Imported from boykopovar/AnyPS5. Originally posted by Pipodi on 2026-10-17T10:41:09Z.
@CnRJay @oneandonlydean I measured all three on current
main, and the result goes against this PR: on today'smain, reading presence at run time costs the cold boot 120 s and saves nothing in total.Setup. PPSA26344, RTX 4090, NVIDIA 617.42, Windows 11 Pro 26200. Three builds on
main6e7ba928aplus what the title needs to boot (startup dialogs and entitlements, #6867, #6537, #6958, a blend skip for 10_11_11 targets, two log lines), differing only inlibSceAgcDriver.prx:mainmain+ this PR (34372f735)main+ the narrow option: stride at run time, presence still specialized, so a buffer absent at first bind keeps the cheap buildEach arm ran one cold boot for 1200 s, in the order P, Q, R, with default settings. Each started with an empty shader cache, pipeline cache and NVIDIA driver cache. The NVIDIA cache was moved aside before each run; our earlier cold runs had silently hit it. Each run was checked to be cold: 1.08M words of
0x800022d100take 11.9 s in P.main)Builds of the ≥ 1M-word programs, per arm
0x80001965000x80001abb000x80001c0d000x80001d57000x80001e5f000x800022d1000x8000261500What this shows, with one run per arm:
0x80001d5700,0x800022d100,0x8000261500) as intended. The programs that still build several variants (0x8000196500,0x80001abb00) build about 10–25% slower, though, so the total goes up by about 90 s and the first frame comes 120 s later. A single run can't separate that slowdown from run-to-run noise (R is also 3–7% slower than P per build). Either way, the 103 s saved offline doesn't show up here.main: the same 62 builds and the same first frame. In this window no program was dispatched with only a different stride, so reading the stride at run time saves nothing either.0x8000196500(4 builds) and0x80001abb00(2), in all three arms. Their variants differ in something other than buffer stride and presence, so neither form addresses it.So this PR shouldn't merge, and the narrow option isn't worth a PR on this evidence. I'm closing it. Thanks both for pushing for the cold measurement.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T10:45:03Z.
Thanks for measuring all three arms with cold caches. A 120 s cold-boot cost with no saving in total on current main is a clear answer, and closing makes sense.
Pull request closed