fix(agc): defer shaders that cannot be prepared at registration to their first use #1836
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1836"
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 EdouardSence on 2026-10-08T21:08:47Z.
What
Since #639,
RegisterShaderprepares every registered shader up front, and the first one that can't be prepared ends the run. Before that, such a shader only failed when it was dispatched, so titles that never dispatch it, or dispatch it late, kept running.Several titles now stop at registration on compute shaders that call a user-data function pointer with
s_swappc_b64, which is not implemented (#1817): Astro Bot, Ghost of Yōtei, Rise of the Ronin, Epic Mickey: Rebrushed, Stray and GTA V. Silksong and Ratchet & Clank: Rift Apart also register headers without their program address registers.This change marks those shaders
deferredinstead of preparing them, and prepares them when they are first used. The deferral is decided before any preparation starts, and only in two cases:s_swappc_b64whose target the call analysis can't resolve.ShaderRecompiler::UnresolvableSwappcTargetis the condition thatGraphBuilder::Buildthrows on today. It is shared with the analysis through a newisFetchCallhelper, so fetch-shader calls are still accepted.Every other error, including any
GraphBuilder,StructurizerorPrepareShaderfailure, still throws at registration. There is no retry after an error.SourceHandleForandInvocationForprepare a deferred shader at dispatch, the path unregistered compute shaders already take. So the original error is raised there if the shader is really used.Tested
Linux (CachyOS, GCC), RX 9070 XT, Mesa 26.2.4 RADV. Head
52b77c20onmain43972e69.agc_driver_prepared_shaders_deferredregisters a compute shader made ofs_swappc_b64 s[4:5], s[4:5].its s_swappc_b64 at program counter 0x0 calls a computed target.not statically resolvable.agc_driver(tests/Submit.cpp,testHeaderWithoutProgramAddress, contributed by @lubaxe) registers a type 4 header withoutSPI_SHADER_PGM_LO/HI. Onmainit fails withmissing static shader ABI register 201.ctest: 512/513. The failing test isimport_audit, which can't read the commit hash in my worktree and is unrelated.tools/check_conventions.pypasses.UnresolvableSwappcTargetis added toshaderCacheReviewedNames: it only decides whether to prepare at registration and doesn't change what a recompile produces.computed/data-dependent s_swappc_b64 call target at program counter 0x00000074.s_swappc_b64and 1 for missing program registers.rectangle ABI refers to a replaced shader header, which #1837 fixes. No frame is presented yet.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
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T22:32:42Z.
Tested on a third title: Stray (PPSA02100 v1.05, Unreal Engine 4) stops at the same point on
main, and this PR gets it past it.Setup: Linux (Nobara 44, kernel 7.2), RTX 5070 Ti, NVIDIA 595.91.07. Base is
main1be6f9f1+ #861 (Linux needs it to boot titles).Without this PR, Stray exits about 10 s after launch, before any window, on its first
sceAgcCreateShader:Stack from the core:
sceAgcCreateShader->Driver::RegisterShader->PrepareRegistered->GraphBuilder::Build->analyzeSwappcCalls.With this PR, registration gets through 111 deferred shaders:
s_swappc_b64user-data calls, at 27 different program counters (0x3c to 0xfc4).shader sampler pairs exceed runtime heap capacity(#1789).The run then stops on a different error that is not related to this PR:
AGC driver: unsupported registered shader type, which I'm looking into separately.One note: the PR no longer merges cleanly onto current
main. #1851 addedRegisteredFloatMode(snapshot)to theRecompileRequestinPrepareRegistered. I kept your try/catch and added that argument inside it.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T23:45:15Z.
Title evidence — the deferral is what unblocks a real title.
PPSA26344 (Ghost of Yōtei 01.008): decrypted
eboot.binrelinked, staged runtime layout, RTX 3080 Ti on Linux. Stack measured:main+ #757 (image/sampler tables at runtime offsets) + this PR.mainGetImageResource dword 0 is not a valid runtime valuemain+ #757computed/data-dependent s_swappc_b64 call target at program counter 0x74 is not statically resolvablemain+ #757 + this PRWith this PR the run does not terminate: the shaders it cannot prepare are deferred and the title continues.
Measured ~2 minutes in: the process is alive with 29 threads at ~100% CPU, the GPU is active, the shader disk cache is past 68 writes, and the frame path prints no error (the earlier run's
[videoout] presentation failedis gone). I cannot yet say a frame is on screen — this is a Wayland session with no window-listing tooling here — so the claim is "the title keeps running instead of aborting", not "the title renders".Note #757 is a prerequisite for reaching this point: on
mainalone the title dies at the earlier image-descriptor wall, so a rebase/test loop needs both.Merge note: one conflict,
Execution/src/Driver/Shaders/ShaderRegistry.cpp— kept this PR'stry/deferstructure with main's newerRecompileRequest(it gainedRegisteredFloatMode(snapshot)since this PR's base). Worth checking that when you rebase.Raw log kept. Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by lubaxe on 2026-10-09T03:26:17Z.
PPSA12544 (Hollow Knight: Silksong) on Windows (RTX 5090) hits the "program address registers are missing from the header" case of this PR during startup. It registers a type 4 shader whose header has only these registers:
mainstops withAGC driver: missing static shader ABI register 201(0xc9,SPI_SHADER_PGM_HIof the vertex/mesh front). I worked around it locally by returning no prepared entries at registration whenprogramRegisterorprogramRegister + 1is missing. That is the first case your PR covers. With it, the title reaches gameplay (tut_01).If it helps, this is the regression I used, for
tests/Submit.cpp(agc_driver_tests). It fails onmainwith exactly that error:I haven't tested this PR's branch itself yet, since it currently conflicts with
main.(Written with AI assistance: Claude Code.)
Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-09T07:36:58Z.
Rebased onto
maina8b032b2as 177c4b2b. It merges cleanly again. The conflict was the one @fisherjoey and @Dextroid17 described: thetryblock now builds theRecompileRequestwithRegisteredFloatMode(snapshot).@lubaxe thanks for the Silksong header and the regression test. I added it to
tests/Submit.cppastestHeaderWithoutProgramAddress. Onmainit fails withAGC driver: missing static shader ABI register 201. On this branch it passes, so it covers the second deferral path (missing program address registers). The first path, an unresolvables_swappc_b64, is covered by thedeferredprepared-shader test.ctest -j8: 495 of 496 pass. The one failure isimport_audit, which can't read the commit hash in my worktree and is unrelated.As @Dextroid17 says, this PR only moves the failure from registration to first use. Inlining user-data
s_swappc_b64targets is still #1817.Thanks to all three of you for testing it on Stray, Ghost of Yōtei and Silksong.
AI-assisted: the rebase, the added test and this reply were done by Claude (Claude Code) on my machine.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T07:38:37Z.
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/Execution/src/Driver/Shaders/ShaderRegistry.cppL178-180, L219-221core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cppL13, L178-180, L219-221core/libs/prx/libSceAgcDriver/tests/execution/PreparedShaders.cppL263core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cppL178-181, L219-222Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:22:37Z.
The
try/catchinPrepareRegistered(ShaderRegistry.cpp) turns any preparation error at registration into a second attempt at first use, which is a retry after an error and isn't allowed here; it would also hide real translation bugs until the shader runs. Please decide the deferral before preparing: the missing program-address registers check you already have, plus a user-datas_swappc_b64found by the analysis, and let every other error throw at registration as before.The new
agc_driver_prepared_shaders_deferredalso fails on the Windows runner (vkCreateInstance: Vulkan result -9); it needs to skip without a device like the other AGC device tests.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:35:29Z.
@boykopovar this one needs your call, since it touches when shaders compile.
Since #639, several titles stop at registration (testers here name PPSA21567, PPSA26344, PPSA02100 and PPSA12544), and in testing I see the same two stops:
s_swappc_b64 s[14:15], mid-program, several times per shader): the target is only known at dispatch, so the shader can't be prepared at registration;missing static shader ABI register 201).I don't see another way for these to boot than preparing those shaders at first use, the way #639 already does for draw-state-dependent stages; the alternative is translating the data-dependent calls, which isn't written yet. If deferral is acceptable, I'd ask for it to be decided up front (detect the call / missing register before preparing) rather than catching any registration error, as noted above. If you'd rather keep everything at registration, these titles stay stopped until the calls are translated.
Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-09T10:37:54Z.
Two more titles hit both deferral paths, on Linux with an RX 9070 XT, on
main43972e69.Rise of the Ronin (PPSA04540):
computed/data-dependent s_swappc_b64 call target at program counter 0x00000074 is not statically resolvable.Ratchet & Clank: Rift Apart (PPSA01474):
Tested and written by Claude (AI assistant) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-09T11:18:30Z.
Three titles' worth of evidence now, and both deferral paths hit in the wild rather than in a fixture — that is what this needed, and the program-counter ranges for Rise of the Ronin are the part that makes it checkable.
One limitation on my side, so you know what I can and cannot add: I can only run the GPU tests on lavapipe here, because the NVIDIA driver path does not work on Linux yet. So I cannot give you a second AMD data point. What I can do is run the agc suite on lavapipe at your head — the CI device is where a green run counts — and report it here if that would be useful.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-09T12:26:54Z.
@oneandonlydean thanks. Both points are addressed in
52b77c20.No catch-all any more.
PrepareRegistereddecides the deferral before preparing anything, in two cases only:ShaderRecompiler::UnresolvableSwappcTargetfinds ans_swappc_b64whose target the call analysis can't resolve. That is the same conditionanalyzeSwappcCallsthrows on, and the two share the fetch-call check through a newisFetchCallhelper.Every other error, including
GraphBuilder,StructurizerandPrepareShaderfailures, throws at registration as before.The
--deferredtest now returnsVulkanTestSkippedwhenOpenVulkanTestDevice()fails. Its CMake entry already setsSKIP_RETURN_CODE 77.Rebased onto
main43972e69. Fullctestpasses except the unrelatedimport_audit. On Astro Bot the run defers 96 shaders through the swappc check and 1 for missing registers, then reaches the stop #1837 fixes. The description is updated.AI-assisted: the change and this reply were written by Claude (Claude Code) on my machine.
Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-09T12:36:37Z.
Also unblocks Hollow Knight: Silksong (PPSA12544) on Linux. On current
main(d70b89989) it stops while registering shaders:With this branch merged onto the same
main, that shader is deferred instead:and the title gets past that point. It now loads its Unity modules and stops later at
sceKernelRaiseException not implemented, which is the Linux signal delivery in #1431, not this change.Imported from boykopovar/AnyPS5. Originally posted by orbz22 on 2026-10-09T12:44:43Z.
Astro's Playroom (PPSA01325) stops here too, on Windows with NVIDIA.
main943bd526(with an unrelated DMA_DATA change on top), it stops at registration, before the first frame:AGC driver: missing static shader ABI register 201.main745b775e:could not be prepared at registration (its program address is not in the shader registers); preparing it when it is used(0x500001700, 0x50000d900, 0x500019b00, ...);rectangle ABI refers to a replaced shader header.Setup: Windows 11, RTX 3060 Laptop (NVIDIA 616.92), WinLibs GCC 15.2.
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-09T13:25:41Z.
This builds on the deferral path introduced here, so it is stacked on this PR (declared as a dependency in #2257).
Context: a decode failure was still fatal because the decode sat outside the
trythis PR adds. #2257 moves it in, but only for the failure class that is a capability gap (a known family, an opcode we do not implement), so the contract that corrupt code fails loudly is untouched —PreparedShaders.cpp:239still passes.