perf(agc): build shader pipeline libraries when shaders are registered #4152
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4152"
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 adriadam10 on 2026-10-12T00:05:38Z.
What
Phase B of #2242: on devices with graphics pipeline libraries (GPL), vertex and pixel shaders get their pipeline libraries built when they are registered, not at their first draw. A draw whose shaders were prebuilt only links (about 0.01 ms). Devices without GPL keep today's path unchanged; every test passes in both modes.
What each commit does:
ResourceMetadata, so direct images read mode, swizzle and mip range at run time the way indirect ones already did.VUID-vkCmdDispatch-None-08611).INDEPENDENT_SETS, so each stage's library depends only on its own set layout. The layout no longer enters the vertex library's key, which should also remove the repeated vertex-library compile Raghav measured when only the pipeline layout changed (not measured on NVIDIA).DescribeSetLayoutsbuilds the set layouts from the compiled shaders alone, which registration needs.APS5_VERIFY_SET_LAYOUTS=1compares them with the draw's layouts on every pipeline build; the whole suite passes with it.ResolveGraphicsStagesAbi(vertex stages) and the registered or static-ABI preparation of pixel shaders hand a registration result toPrebuildStageLibrary, which builds that stage's library with a stub partner and a fixed default state.VkShaderModuleuntil the device is torn down. A module can be destroyed once the pipeline is built (vkDestroyShaderModule), and the optimized link does not need it. This also changesmain's draw path. Its cost shows with large modules: about 1.1 MB per library on RADV with Astro's Playroom shaders (3.17 GB → 1.98 GB peak for 1200 headers).registrationWordLimit(200000 SPIR-V words) is re-emitted specialized and compiles at its draw as today.CompiledShaderArtifact::registrationModulerecords the form and is stored in the disk cache. Prebuilds run on their own one-thread pool (APS5_PREBUILD_THREADS), separate from the registration pool, as Raghav suggested.main. In registration form, theagc_driver_dword_pattern_fillcompute shader hung CI's lavapipe in the build withANYPS5_ENABLE_SPIRV_TOOLS=ON(not RADV, not without SPIRV-Tools). I didn't find the cause, so compute stays out until someone does (TechnicalDebt has the reproduction).agc_driver_wait_shutdownandagc_driver_flip_computeon Windows CI, where no prebuild ever runs.buffer_*_format). As a runtime value, every such access compiled the decoder of every format:agc_driver_vertex_fetchwent from 0.59 s to 9.96 s on CI's lavapipe with a cold driver cache (2 cores, SPIRV-Tools on, 88 % of the time in LLVM), past the 5 s fence on CI. With the word specialized it takes 1.05 s. This was most likely also behind the compute "hang" in item 11, which looked like a very long JIT rather than a loop. Shaders that still specialize something (these buffers, or texel-offset folding) get no prebuild, since their prebuilt module would never match a real draw.DontInlinethe driver couldn't fold the format switch anymore. That grew a compute shader in PPSA36082's loading frame from 51k to 236k words (22 → 794 ms) and kept that boot crashing (@Raghav314, #2242).FormattedBufferOncepins it: one formatted load gives 26.5k words (117.5k before;main26.5k), and the vertex registration form stays under 1.5× its specialized form.agc_driver_pixel_lds's pixel shader, which hung an RTX 4090 for Raghav (Xid 109) 3 times in 4 whilemainpasses. Both forms of that shader now have no loops or atomics, andFormattedBufferOncechecks that registration form has no more compare-exchanges than the specialized form. Not yet confirmed on the 4090.Why the word limit
Astro's Playroom registers 907 pixel shaders of 200k to 900k SPIR-V words (ubershaders). With runtime selectors the driver can no longer prune them: the largest one compiles as a fragment library in 7.1 s and 366 MB instead of 0.9 s and 132 MB, and prebuilding all of them took the process past 10 GB.
A paired sample of 60 pixel shaders (same shaders,
mainvs this branch, RADV Radeon 660M, Mesa 26.2.4, cache off) gave two clear groups:No shader falls between 141k and 280k, so the limit sits in that gap. Re-measured after items 14-15: below the limit ×1.84 (<100k) and ×2.24 (100-200k) compile with modules only ×1.10-1.14 the words; above it, in registration form with the limit off, 20 shaders still compiled ×5.9 (p10 ×5.2, p90 ×7.4) slower and ×20 on the optimized link, so the limit stays. The cost is the runtime values the driver can't fold, not module size. Below it, the extra compile time is paid once, on the background thread, and taken off the draw.
Tested
Linux (CachyOS), RADV Radeon 660M (Mesa 26.2.4), GCC 16, Release, rebased on
main8c4a295ff(headb1ee794a6):^agc_|^shader, GPL on (withAPS5_VERIFY_SET_LAYOUTS=1)APS5_NO_GPL=1^agc_underVK_LAYER_KHRONOS_validation, GPL on and off^agc_on CI's lavapipe (Mesa 25.2.8)/dev/udmabuf,--timeout 120 --parallel 4, clean build)New or extended tests:
BufferDescriptorRuntime: every V# case gives byte-identical SPIR-V and the same pipeline variant in registration form.TypedHeaps: present and null images give the same module.ZeroStrideVertexFetch: two swizzled cases (W Z 1 0), in and out of range, checked by value; all 7 cases give identical SPIR-V in registration form.VertexFetch: a mixed pipeline (vertex in registration form, pixel forced specialized withregistrationWordLimit = 1).PreparedGraphics: the vertex stage alone and the pixel stage alone each build exactly their library without linking, the pair then finds both, and a second preparation of the same stages finds them again.ShaderMemory: serializer v17 round trip and cache key.The new assertions were checked to fail when their expected value is mutated.
Astro's Playroom, every
Shaderheader registered and resolved through the realAgcDriverRegisterShader/Resolve*Abipath (offline harness, not committed):mainNot measured here: the effect on a real boot. I can't run titles on this machine. @Raghav314, a PPSA36082 cold start on this branch would be the deciding number. Your phase B simulation in #2242 suggested this boot survives once libraries are built at registration. Please don't merge before that run.
Checklist
main; no other open PR implements the same functions (shares files with #3763, #3988, #3717, #3846, #3946, #3738, #3656; none implements these functions)NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-12T00:56:13Z.
I tested this on PPSA36082 cold starts on my machine (RTX 4090, Linux) and posted the details in the discussion: https://github.com/boykopovar/AnyPS5/discussions/2242#discussioncomment-18871532
In short:
DontInline, a compute shader in that frame goes from 51,382 to 236,457 SPIR-V words, and its pipeline create from 22 to 757 ms. The loading frame ends up slower than on main and the boot still crashes.agc_driver_pixel_ldshung the GPU on this PR's head (Xid 109, device lost) on a freshly booted GPU, with and without that change. Main passed it there. Small numbers, details in the discussion.LLM assistance used.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T02:24:54Z.
Changes since opening, after the first two CI rounds (the body is updated):
agc_driver_wait_shutdownandagc_driver_flip_computehung at exit, because closing the prebuild pool at shutdown created it, and with no Vulkan device on Windows CI it never existed before. The pool is now closed only if it exists.agc_driver_dword_pattern_filland thenagc_driver_vertex_fetchhit the 5 s fence. Cause: in registration form the buffer V# format word was read at run time, so everybuffer_*_formataccess compiled every format's decoder. On CI's lavapipe with a cold driver cache that's 9.96 s instead of 0.59 s forvertex_fetch(2 cores, SPIRV-Tools on, 88 % in LLVM). The format word now stays specialized for those buffers (1.05 s), and shaders that still specialize something get no prebuild. Compute shaders stay specialized as onmain, since only vertex and pixel shaders are prebuilt.spirv-val.Third round: full build green on Linux (926/926) and Windows, plus all PR checks. Astro's Playroom coverage: 1937 libraries prebuilt, 5.41 GB peak against 5.07 GB with prebuild off.
Still waiting on a PPSA36082 cold start before merging.
AI-assisted: yes (Claude).
Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-12T02:30:40Z.
Reran PPSA36082 cold starts on 14b52c1ac on my machine (RTX 4090, Linux), details in the discussion: https://github.com/boykopovar/AnyPS5/discussions/2242#discussioncomment-18872521
Short version: the formatted buffer helper still makes the loading frame's compute shader 236,457 words with a 794 ms pipeline create, and the stock boot still crashes loading
GUI.pkg(3/3). With the helper change from my earlier comment on top, it boots 3/3 with frame 1 at about 790 ms, and the Linux test job passes 921/923 (same two failures as main).agc_driver_pixel_ldshung the GPU again on 14b52c1ac as pushed (Xid 109); main passes it here.LLM assistance used.
Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-12T03:37:31Z.
Same formatted buffer helper, registration form this time. On Demon's Souls (PPSA01341), dumped on my machine and compiled offline, the helper still switches over every format when the format is specialized at the call site, because it takes word 3 as a parameter. That makes the vertex shaders' registration form 3.3x their specialized form, with 39 of the 58 largest over
registrationWordLimit. Reading word 3 as the specialization constant inside the helper in that case brings it to 1.1x and none over the limit. Details and the diff in the discussion: https://github.com/boykopovar/AnyPS5/discussions/2242#discussioncomment-18873211LLM assistance used.
Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-12T07:28:16Z.
Independent Windows / RTX 5080 validation of exact 14b52c1ac
I built the exact PR head
14b52c1ac38d2f9c254299189e0bccba26bed752and its actual merge-basebca7a29d259299aaa8972c94d12694232bb3bb08separately. No additional failing test was observed on the PR in this configuration. This is matching-base validation, not a test merged into today's main.Windows 11 Enterprise 26200, Ryzen 9950X3D, RTX 5080 / NVIDIA 610.62 (
32.0.16.1062), WinLibs GCC 15.2 r7, Release, testing ON, bundled dependencies, SPIRV-Tools OFF. Full builds and system-library targets pass; source checkouts remain clean. Vulkan required,ANYPS5_GPU="RTX 5080",ANYPS5_NO_SHADER_CACHE=1; the PR additionally usesAPS5_VERIFY_SET_LAYOUTS=1.Serial
ctest -R "^(agc_|shader)" --parallel 1 --timeout 30:bca7a29d2bca7a29d2APS5_NO_GPL=1)The same two failures on both revisions, in both modes:
agc_write_tracking:an unwatched range reads as not stored over.agc_driver_prepared_shaders_registered_workgroup_sync:expected preparation failure(also noted in the PR's matching-base results).Each failure reproduces 5/5 isolated attempts on each revision. The eight GPL-off skips are the
pipeline_optimized_readbackD32/D16/color32/color64 cases and their fast variants; the same skips occur on the base. The earlier selection of 16 relevant graphics/registration/cache groups passes five repeats each on both revisions. Maximum passed-test duration across the full runs is 10.674 s on this machine, not a lavapipe/CI timing guarantee.For the NVIDIA LDS concern in #2242:
agc_driver_pixel_ldspasses five isolated repeats on each revision, as well as both full-suite modes on each. No timeout orVK_ERROR_DEVICE_LOSTwas logged. These are Windows / RTX5080 measurements on an already running GPU, not fresh-boot/Linux RTX4090 controls; they do not disprove the reported Xid109 problem there.Limits: NVIDIA driver disk-cache coldness is not established. This is behavior validation, not a registration/first-draw speedup measurement. No PR-head title cold boot, PPSA36082/Hades II, PPSA01341, or Astro shader replay was performed; PPSA99902 needs additional startup/graphics prerequisites on this base. No game binaries/shaders/images were uploaded. AI-assisted independent build/test/report: Codex.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T07:55:30Z.
@Amoenus thanks, that's a useful control, especially
agc_driver_pixel_ldson another NVIDIA generation.Since 14b52c1ac, three changes are coming in the next push (rebased onto current
main; it goes up once the local suites, validation layer and CI-like run pass on the rebased tree):FormattedBufferOncenow pins both: one formatted load gives 26.5k words, same asmain, against 117.5k before.pixel_lds's pixel shader that removes the 6 unaligned compare-exchange loops that registration form had and the specialized form doesn't (0 loops, 0 atomics in both forms now). It's the only structural difference I found in that shader, so it's my best guess for Raghav's Xid 109, but I can't confirm that without his 4090.AI-assisted: yes (Claude).
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T08:35:19Z.
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/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppL1342-1343, L1421-1423, L1435-1437, L3463-3466, L3468-3469, L3474-3485core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppL586-587core/shader/recompiler/Optimization/include/Optimization/DescriptorBindingBuilder.hppL16core/shader/recompiler/Optimization/src/BindingAllocator.cppL105core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppL296-297, L330-342, L407-418, L429core/shader/recompiler/ShaderDiskCache.cppL67-70core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cppL49-58, L60-62, L1656, L1679-1693core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvDescriptors.cppL57-82core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppL1342-1343, L1421-1423, L1435-1437, L3463-3466, L3468-3469, L3474-3485core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppL586-587core/shader/recompiler/Optimization/include/Optimization/DescriptorBindingBuilder.hppL16core/shader/recompiler/Optimization/src/BindingAllocator.cppL105core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppL296-297, L330-342, L407-418, L429core/shader/recompiler/ShaderDiskCache.cppL67-70core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cppL49-58, L60-62, L1656, L1679-1693core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvDescriptors.cppL57-82core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppL430-434core/libs/prx/libSceAgcDriver/tests/FormattedBufferOnce.cppL101-102core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppL2939core/shader/recompiler/CacheKey.hppL243core/shader/recompiler/Recompiler.cppL420core/shader/recompiler/Recompiler.hppL232core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitter.hppL23core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppL93core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppL252core/shader/recompiler/Recompiler.cppL420-421, L425core/libs/prx/libSceAgcDriver/Graphics/src/PipelineLibrary.cppL138-139