[HOLD] perf(agc): pre-warm deferred shaders on SET_SH_REG packet execution #5115
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5115"
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 Kikoarl on 2026-10-13T12:09:44Z.
Summary
When games register compute or graphics shaders whose program addresses were not yet present in the shader registers at registration time,
libSceAgcDriverdefers preparation until the shader is used. When the subsequent draw or dispatch packet executes, the shader must either be compiled synchronously on the queue worker thread or block until asynchronous preparation finishes, introducing visible compile hitches during gameplay.This change triggers background preparation of deferred shaders immediately when PM4 opcode
0x76(SET_SH_REG) or opcode0x63(SET_SH_REG_INDIRECT) writes the stage's program registers and stage prerequisites (resource count and workgroup/thread configuration). This allows compilation inRegistrationPreparePoolto overlap with earlier command processing instead of stalling at the moment of draw/dispatch.Differential Unit Test
DeferredShaderPrewarmedOnSetShRegtotests/execution/PreparedShaders.cpp.prepared->entrieswithout blocking subsequent packet handling.Standard #218 Multi-Sample Telemetry (Astro Bot -
PPSA21567)Tested on native Linux x86_64 with NVIDIA GeForce RTX 5060 Ti across 3 alternating runs on
origin/main(commit14036cb0e) vsmain + PR:origin/mainmain + PRorigin/mainmain + PRorigin/mainmain + PRUnit Cost Breakdown:
preparing it at use: 0).Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T00:51:34Z.
Review: COMMENTED
I don't think this does what it intends, and it adds work to a very hot packet.
1. The state is planned before it is final.
CanPlanDeferredShaderonly checks that registers are present (contains).QueueStatekeeps every register from earlier packets and submissions, so they are almost always present. They just hold the previous draw's values. The context registers it reads (0x1b3,0x1b4,0x1b6,0x2d5) are usually written bySET_CONTEXT_REGafter theSET_SH_REGthat sets the program address and before the draw. The plan is then keyed on stale state. The draw doesn't match it and prepares again at use, so the shader is compiled twice and the stall this PR targets remains.2. The overlap is very small.
SET_SH_REGfor a stage's program is normally a few packets before the draw or dispatch that uses it, in the same command buffer and on the same thread.PlanRegistered(decode plus request build) now runs synchronously on the queue worker. The background job then starts microseconds before the draw blocks onpending. The gap between the two packets is all that can be hidden. Hiding a 35–110 ms compile needs it to start much earlier, for example from the resolve-ahead pass, or atsceAgcDriverResolve*Abitime asmainalready does when the state is known.3. Every
SET_SH_REGpays for it. Titles write the program registers on nearly every draw. Each such packet now does a registry lookup (RegisteredProgram) and takes the snapshot's mutex, even when nothing is deferred, and does it for up to five stages per packet.4. Errors are swallowed.
catch (...) { return false; }aroundRegisteredProgramandPlanRegisteredhides real failures. The draw would throw them later anyway, but the repository's rule is exact or throw. If a prewarm must be best-effort, it should at least not catchstd::bad_allocor the "front entry matching both type 2 and type 4" ambiguity, whichmaintreats as an error.5. Duplicated ABI knowledge. The program and resource register numbers per stage type are hard-coded twice (in
checkDeferredShadersOnShRegWriteand inCanPlanDeferredShader), separately from the code that already resolves them in the registry.6. The measurement. The table shows the deferred count at registration changing between runs of the same branch (127/124/98), and no frame times. CONTRIBUTING asks a
perf(PR for theaps5-summary.jsonllines and traces ofmainand of the change. A trace would also show whether the draw still waits onpending(point 2) or prepares again (point 1).Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-14T11:58:55Z.
putting this pr on hold while i re-evaluate telemetry and profiling on full in-engine scenes.
Pull request closed