perf(agc): baseline shader recompilation on registration #639
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/639"
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 boykopovar on 2026-10-05T10:34:06Z.
What
All game shaders pass through
Driver::RegisterShaderduring game initialization. Recompiling them at this stage would allow draw/dispatch to use precompiled SPIR-V without compiling shaders during gameplay.The current recompiler embeds resource parameters into shader code, so resource changes require recompilation. Even without resource changes, the initial compilation still occurs just before rendering during gameplay. Original shaders read these parameters at runtime. Recompiled shaders must do the same: fixed code, with resources supplied separately.
Compiled artifacts are separated from invocation data, and RDNA-to-SPIR-V compilation runs during shader registration and static ABI preparation. Draw/dispatch require prepared artifacts and fail if missing. Pipeline specialization and direct access for CPU-resolvable buffers are partially implemented; specialization validation and serialization have been added. Vertex fetch restoration and image/sampler optimization remain incomplete.
If successful, this will eliminate the last fundamental source of performance overhead compared to a real PS5.
Tested
There's no noticeable performance improvement on Dreaming Sarah. This may be because shader recompilation has never been a significant feature in this game.
Checklist
NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T11:03:32Z.
Is there anything I can do to help with this without getting in your way? One idea: before you remove the image/sampler specialization, a test-only PR on
mainwith execution tests that pin results across T#/S# variations (formats,dst_sel, mip/array ranges, clamp/border modes, filters), so you can check the runtime-descriptor version against them. If you would rather have something else, or a separate piece of the remaining work, tell me which and I'll stay off the rest. #473 is on standby until this lands.Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-10-05T11:08:23Z.
Don't worry about changes to the main branch interfering with my progress. Keep up the good work. If my idea works, I'll resolve the conflicts myself and adapt everything.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T11:11:35Z.
Thanks! Then I'll leave this area to you: no new PRs from me on moving shader compilation to registration or on resource specialization, since your approach replaces it. I'll keep working on the rest as before.
Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-10-05T11:15:00Z.
Regarding #473, it's still not worth making any architecture changes that don't align with shader recompilation at the registration stage.
Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-06T10:58:54Z.
Testing notes from PPSA26344 (Ghost of Yōtei v1.008) on the runtime buffer path, in case they help.
The pattern. Six compute shaders stop on
mainatGetBufferResource dword 0 is not a valid runtime value: 0x8000289300, 0x800022d100, 0x800028d800, 0x8000284e00, 0x80002a9600 and 0x80002a1f00.[SRT+0x1b8]+0x20, then use the V#s stored in each record (+0x00, +0x10, +0xa0, +0xb0).s48 * 0xc0) or taken from a tile-list entry.buffer_load_ushort/ubyte/dword/dwordx4(idxen),buffer_load_format_x,buffer_load_format_d16_xyzw(about 128 per shader),s_buffer_load, andbuffer_store_byte/_d16_hi(glc).main,TakeGpuDescriptorroutes a runtime V# to BDA only for 32-bit raw accesses, so the ushort load at pc 0x78c reachesGetHandleand throws.Replay through this branch. I replayed the six captured requests through this branch's
agc_shader_replay(531e76d7), with the SRT and record memory reconstructed from values captured live. The replay needed a local test-only patch: req version 8 and memory injection.ResourceTrackeraccepts five of the six. The sixth (0x800022d100) stops earlier, at a VOP2 SDWA destination selector that #751 fixed onmain, so a rebase covers it.Two things showed up.
word3is not an immediate, soformattedDispatchinlines all 77 formats at every formatted access.OpSwitches of 77 cases and 1.36M blocks. The title's other shaders are 17k-273k words.RuntimeImageMode(ResourceMaterializer.cpp:552) throws "image descriptor is incompatible with the static runtime image interface" for the placeholder T#s the title binds atP+0x84..0xe4.image_sample_lz dim:3D.Not verified. The byte stores through these runtime V#s need write access in the BDA table. As far as I can see,
AddressRanges(GuestBufferMemory.cpp:2306) grants it only to imported writable allocations or to ranges inwrites, and the driver never sees a runtime V#'s range.Context. At this point in the title the record table is empty (
num_records0, count 0), so the loop runs zero times on hardware. When the six dispatches are skipped, the title goes on to present frames. Happy to re-run these shaders with the title after a rebase.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-06T17:49:55Z.
Two things from Ghost of Yōtei (PPSA26344) for this branch: a registration check at cf2bf8e27, and the sub-dword buffer stores behind most of its 1.3 fps.
I ran
PrepareShaderthe wayRegisterShadercalls it (zero user data, code and header only) over the 126 compute programs the title dispatched in a run today: 103 prepare, 23 throw. OnlyProcessShutdownis caught on the way out ofsceAgcCreateShader, so I'd expect the 23 to stop the title at registration, though I haven't run it on this branch. 16 of them dispatch fine on our integration build.mainalready has: the SDWA selectors from #509 (not #751, as I wrote last time), the vcc global base from #750 and the DPP16 row_share controls from #660.On
main, the light-culling shader (0x800036e100) takes about 589 ms of GPU time per dispatch, nearly all in compare-exchange loops for its 8- and 16-bit format stores, each an atomic over PCIe on host-imported memory. Plain 8/16-bit stores through aliased views take 28 ms, and the boot logos go from 1.3 to 5.6 fps with identical frames. Here runtime V#s store single bytes, but this shader's V#s take the direct path, wherewriteBufferstill merges sub-dword fields withAtomicUpdate. I have a small PR formainready (buffers_u8/buffers_u16views; odd addresses and devices without 16-bit storage keep the loop). Should I open it to land first, for you to keep or port, or hold it for you to fold in?Two smaller questions. 0x80001e5f00 stores to tables it reads: is the bindless storage table refusal meant to stay? And 0x80002c4500's S# is unnormalized with wrap, which #799 still refuses (2391 skipped dispatches), but all 26 dispatches I dumped sample inside its 1408x1408 T#, so a clamp-to-edge sampler with a deferred fault outside it would be exact. On #822 that flag would be a
ResourceSpecializationbit, which goes away here. Would aPipelineSpecializationentry suit you, and whichFaultReasonvalue? #757 addsImageTable = 8, this branchInvalidDescriptor = 8.Details
global_load_dwordwith vcc base, pc 0x4a9c), 0x80003b1700, 0x80003c5900, 0x80003dc800 (DPP).OpAtomicCompareExchange.00008000 00fff000 05000000 00000000; u 0.5-719.5, v 96.5-1055.5.Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-10-07T12:01:15Z.
@Celegans12 I'll finish this branch myself for now. All that's left is to rebase again. And test it on different games.
Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-07T12:05:06Z.
Sounds good. Once the rebase is up, I'll run Ghost of Yōtei on it (Windows, RTX 3080) and post how far it gets, including the 23 compute programs that failed
PrepareShaderlast time. Until #639 lands I'll keep the sub-dword store change local, and I can redo it on top afterwards if you still want it.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T13:55:59Z.
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)sceAgcCreatePrimStatesceAgcLinkShadersImported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-10-07T15:59:06Z.
Test Changes
index < records && offset < stride; main’s previous direct path bypassed it. Computational expectations remain unchanged.GuestSystemFont: unrelated to the branch architecture; changed the fixture directory to avoid deleting an open file on Windows.
Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-10-08T15:39:00Z.
In main, baseline recompilation depends on the resource configuration and runs on the first use of each corresponding variant.
This branch prepares IR, the static interface, baseline SPIR-V, and available ABI variants during shader registration. The compiled artifact is separate from per-draw and per-dispatch data.
Before the first execution with a new resource configuration, the runtime reads descriptors, validates compatibility, prepares the binding plan, specializes existing SPIR-V by substituting constants and removing unused branches and computations, materializes invocation data, and creates the Vulkan pipeline. These results are cached.
Variants that depend on linked graphics stages are prepared when the corresponding ABI is resolved. Unregistered compute shaders undergo baseline preparation on their first dispatch, emit an error log, and cache the result.
Subsequent executions reuse prepared artifacts, specializations, and pipelines while updating invocation data and resources as needed.
Imported from boykopovar/AnyPS5. Originally posted by gjonn on 2026-10-08T16:23:22Z.
Since baseline compilation now runs at shader registration, a large title spends a long time before its first frame with nothing on screen. On one title I tested, the first launch compiled about 1,400 shaders over roughly 100 s before anything appeared; later launches are faster once the disk cache is warm. Could the preparation path report progress? For example, a line like
Compiling shaders: N compiled, M failed, updated every ~250 ms, in the console window title and on the console. I tried this locally from thePrepareShaderpath withSetConsoleTitleAplus aCONOUT$write, and it made the wait much easier to tell apart from a hang.Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-10-08T16:30:09Z.
We'll definitely show the recompilation progress. I think it can be done right where the FPS counter is displayed. What game did you test it on, and how was the performance after that long loading time?
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T16:37:29Z.
this loading progress should be in this or another pr?
Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-10-08T16:39:23Z.
@adriadam10 I'm so tired of this PR that I don't want to add this new functionality to it. Better in the next one. Otherwise, it might break something.
Imported from boykopovar/AnyPS5. Originally posted by gjonn on 2026-10-08T16:40:12Z.
Gran Turismo 7 - performance is still bad. Working on some other issues that this PR doesn't address.
Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-10-08T16:41:39Z.
Is the performance worse after long loading times on this game compared to main?
Imported from boykopovar/AnyPS5. Originally posted by gjonn on 2026-10-08T16:45:43Z.
It's worse but it's missing some of the optimizations I had already applied in my other branch. I'm in the process of adding them into this branch now to compare the two.
Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-10-08T17:43:09Z.
Finally
Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-08T20:52:54Z.
Ghost of Yōtei (PPSA26344 v1.008) now stops at start-up on
main, about 7-8 s in, before the swapchain is created. The registration-time preparation throws for a program the game hasn't executed yet, nothing catches it, and the process terminates:main6b56175a(this merge, before #1217):unsupported SOP1 opcode 33main55e8959b(with #1217):computed/data-dependent s_swappc_b64 call target at program counter 0x00000074 is not statically resolvableNeither error showed up in our hour-long runs on the tree before this PR, so as far as I can tell these programs either never run in that part of the game or aren't reached for a long time. With preparation at registration, one unsupported instruction in any registered program now ends the whole title. That's probably the start-up regression you were worried about, just in a harder form than a slow first launch.
Would it work to record a preparation failure per shader and raise it at that shader's first draw or dispatch instead? That keeps exact-or-throw for every program that actually runs, without stopping a title over ones that don't. I'm happy to test a change on Yōtei.
Details
Windows 11, RTX 3080 Laptop, a save past the first-boot screens, cold shader cache (
format 19).The abort comes right after
Vulkan device ready, on the first device. On4b005b22(before this PR), the same save gets past the swapchain and stops later at a descriptor read that #759 fixes.