perf(agc): build compute shaders' front end when they are registered #473
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/473"
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-03T17:06:34Z.
What
The first commit is #471; this pull request is the second one.
Builds a compute shader's front end when the title registers it, on a worker thread, instead of at its first dispatch (the move discussed in #361, for compute only). With #471 the first variant compiled for a cache entry takes the program the entry was built with, so a dispatch of a prepared shader only specializes and emits.
RegisterShaderhands compute binaries (type 0) toShaderPreparation. It predicts the request a dispatch will make from the header: the code at its registered address, the user SGPR count fromCOMPUTE_PGM_RSRC2, the stage info fromCOMPUTE_NUM_THREAD_*/COMPUTE_PGM_RSRC2(DecodeComputeStageInfo, as the dispatch does), the wave size fromspecials->dispatch_modifierbit 15 (CS_W32_EN, the bit the dispatch reads from its initiator), and the current device's target.ShaderRecompiler::PrepareSource, which runsgetSource. A dispatch that arrives while the entry is being built waits on the entry's mutex, as two dispatches do today, so it never skips or duplicates work.APS5_NO_SHADER_PREPARATION=1turns it off. The worker is stopped and joined inDriver::stop, before the device is released.ShaderRecompiler::FrontEndBuilds()counts front-end runs; the test uses it.Not covered: whether
dispatch_modifieris what titles pass tosceAgcCbDispatch. I found no reference that confirms it; the name and the matching bit are the evidence. If it is not, entries are built for the wrong wave size and dispatches behave as today. Pixel and vertex shaders depend on draw state and are left for later.Tested
agc_driver_pixel_helper_lanes, which fails the same way onmainon this machine.agc_driver_shader_preparation(execution test, skips without Vulkan): registers a compute shader throughAgcDriverRegisterShader_nid_postfix, waits for exactly one front end, dispatches it through an ACB and checks the stored values and that the dispatch ran no front end; then dispatches it at the other wave size and checks it builds its own and still stores the right values. WithAPS5_NO_SHADER_PREPARATION=1it fails at the wait; with a header that predicts the wrong wave size it fails with "ran the front end again". Passes 3/3 runs, and under AddressSanitizer.FrontEndBuilds()with and withoutAPS5_NO_SHADER_PREPARATION=1over the same scene would show how many dispatches it covers.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)Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T07:10:36Z.
Thanks for this. Since my #457 landed, the build checks every driver call into the recompiler against a reviewed list, and main plus this PR now stops at the shader cache version step:
PrepareSourceonly fills the source cache for the same request a laterRecompileuses, so I think adding it toshaderCacheReviewedNamesincore/shader/recompiler/CMakeLists.txtis all it needs. Could you add it?Separately, @boykopovar, the background worker that builds compute shaders at registration is a design call for you. It reads
specials->dispatch_modifierbit 15 as wave32, which the PR says is unconfirmed; a wrong guess only costs a second build, and the test covers that case.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T07:16:57Z.
Thanks! Added
PrepareSourcetoshaderCacheReviewedNamesand rebased onto main.The rebase also showed a real break: since #316 a wave32 dispatch recompiles for
ComputeTarget(32)(32-wide subgroups), but the preparation still usedTarget(). The source key then differed in the target, so the prepared front end was never reused, andagc_driver_shader_preparationcaught it (the dispatch of a prepared shader ran the front end again). The preparation now usesComputeTarget(entry.waveSize), the same asDispatch.cpp. Release build passes, and allagc_tests pass on RADV exceptagc_driver_pixel_helper_lanes, which fails on local RADV on main too. StillDepends on #471.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T22:38:07Z.
Thanks, both fixes look right to me.
PrepareSourceis inshaderCacheReviewedNames, and the preparation now builds forComputeTarget(entry.waveSize), the same targetDispatch.cppuses, so a wave32 dispatch finds the prepared front end again. Merged with current main it builds and the full ctest passes here, includingagc_driver_shader_preparation,agc_driver_wave32_subgroupandagc_shader_disk_cache. CI is green on both jobs.The first commit is the same patch as #471, which has since merged, so that part drops out on merge. Note that #469 also edits
Driver::RegisterShaderinShaderRegistry.cpp; whichever lands second needs a small rebase there (keep theEnqueueand add the null program insert after it).From my side only the design question is left: @boykopovar, the background worker that builds compute shaders at registration (reading
specials->dispatch_modifierbit 15 as wave32) is your call.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T09:01:51Z.
Rebased on current
mainafter #610, #471 and #469:Driver::RegisterShaderinShaderRegistry.cpp: kept theEnqueueand added the null pixel program insert after it, as suggested.agc_tests pass on RADV exceptagc_driver_pixel_helper_lanes,agc_driver_pixel_ldsandagc_driver_pixel_lds_lane_slots, which fail the same on currentmainhere.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T11:03:30Z.
On standby: #639 moves the whole recompilation to
Driver::RegisterShaderand makes this one obsolete, so please don't spend review time on it. I'll close it when #639 lands.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T11:17:17Z.
Closing: #639 moves the whole shader recompilation to
Driver::RegisterShader, compute and graphics, with no per-resource variants, which replaces this front-end preparation. See the discussion there.Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-10-05T11:19:35Z.
Sorry for the delay in responding. Let's avoid making architectural changes that conflict with shader recompilation during registration. Regarding changes that don't change the architecture, please don't worry about them interfering with #639. If #639 works, I'll fix the conflicts myself.
Pull request closed