perf(recompiler): keep the vector window's unindexed slots out of the array #5757
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5757"
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 hypermoist on 2026-10-14T09:36:46Z.
What
A program with any
v_movreld/v_movrelsd/v_swaprelkeeps its whole relative-addressing window in one Function-storage array (#3856), and with indexed writes every direct access to a window register goes through that array too. Drivers put an indexable array in local memory, so every register of the window stays in memory even when the relative accesses only reach a few of them. In a PPSA08427 (Killing Floor 3) compute program with 20v_movrels/v_movreld, the window spans 167 registers while every relative index isv_bfe_u32 ..., 10, 2(0 to 3); the SPIR-V had ~22kOpAccessChaininto the array.IndexedWindowSlotsestimates the slots the relative accesses reach: it bounds each run-time index through the IR (bit-field extracts, masks, shifts, adds, selects, phis,ReadFirstLane, and the stores to a window slot that reach a load of it, walking the CFG back from the load).OpSwitchover the slot variables loads or stores the right one. The estimate only affects speed, not results.APS5_NO_WINDOW_NARROWING=1turns it off (a recompiler switch, so it is part of the shader cache key).On the PPSA08427 program above the array shrinks from 167 slots to 4 with 163 separate variables per lane half, and the module from 517983 to 484107 SPIR-V words (replayed from a dumped request on the PPSA08427 bring-up branch, whose request format
maincan't read).Tested
CachyOS Linux (kernel 7.2.9), NVIDIA GeForce RTX 3060, driver 615.78.08, GCC 16.2.1, Release, this branch merged with
main8cd937e29.New execution test
agc_driver_vector_window_narrowing: a 32-register window whose one bounded index (s8 & 3) keeps the array to 4 slots, and whose data index (s9) reads and writes either the array or the separate variables at run time (data index 20, 2 and 31), wave32 and wave64. It also checks the window was split; withAPS5_NO_WINDOW_NARROWING=1that check fails.Pass:
agc_vector_window,agc_driver_vector_window_direct_access,agc_driver_relative_indexing,agc_driver_scalar_relative_indexing,agc_driver_dpp16_operands,agc_driver_pixel_wave_reduction,agc_driver_scalar_sop1,agc_shader_memory, and the new test.spirv-val --target-env vulkan1.3accepts the PPSA08427 program's module.Speed,
main8cd937e29vs this PR (andAPS5_NO_WINDOW_NARROWING=1, which emits the same module asmain): a compute micro-benchmark with a 167-register window, an ALU loop over every window register (256 iterations) and relative accesses withm0 = s8 & 3, 2048 groups of 64 threads, median of 15 dispatches after a warm-up, two process runs each:mainThe output buffer is identical in every mode. The benchmark is in the review reply; it is not part of this PR.
PPSA08427 hub (bring-up branch, which carries this change behind the same switch), three on and three off runs of 80 s: 19 presents per 10 s either way, and the GPU time of the eight most expensive programs within run-to-run noise. The game is bound by the CPU there, so the earlier 17-18 to 29 figure, which mixed this change with another, is withdrawn.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
https://claude.ai/code/session_01Uzy15wqYTt6iWyxYXEzUWo
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T13:32:53Z.
Review: CHANGES_REQUESTED
Checked on the PR merged onto current
main: build + the Agc/AgcDriver ctest scope with SPIR-V tools ON, and the newagc_driver_vector_window_narrowingpasses and fails without the change. The only red test,agc_driver_tessellation, also segfaults onmain. The design is sound: the bound estimate only chooses what goes in the array, and every access stays correct (constant index, in-array,OpSwitchover the slot variables, 0 / dropped write past the window).APS5_NO_WINDOW_NARROWINGis in the shader cache key.Two things before this can merge:
main-vs-PR capture, and the 17-18 → 29 presents figure mixes this with a relaxed-f16 change. Please post a paired measurement of this change alone (same scene or the same shader,mainvs PR, several runs, driver named), or a micro-benchmark of the PPSA08427 program on your RTX 3060. The SPIR-V size drop is not a speed claim: whether the driver keeps the 163 separate variables in registers is exactly what the technical debt line says is not measured.docs/dev/debt/shader.md:119("Relative vector addressing") still says every register from the lowest base up lives in one function-scope array. Update it for the narrowed array, the per-slot variables, theOpSwitchfallback and the switch, and say what you measured.Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-15T03:03:06Z.
Thanks for the review. Both points are addressed in
a4639ad2f(merged with currentmain, conflict-free):Measured gain. The PR description now has a
mainvs PR micro-benchmark on the RTX 3060 (driver 615.78.08, CachyOS Linux). A compute program with a 167-register window whose ALU loop touches every window register:main8cd937e29APS5_NO_WINDOW_NARROWING=1m0 = s8 & 3m0 = s8 & 3m0 = s11(50 / 166, past the array)The numbers are the median of 15 dispatches of 2048 groups after a warm-up, with two process runs per cell. The output is identical across modes.
mainand the switched-off PR give the same module (9321 / 17003 SPIR-V words) and the same times. The unbounded-index row covers theOpSwitchfallback: it still runs about 19x faster thanmain. On this driver, a whole-windowFunctionarray costs far more than the per-slot variables plus the switch.I also ran the PPSA08427 hub paired with the switch (three runs on, three off, 80 s each). Presents per 10 s are 19 either way, and the GPU time of the eight most expensive programs stays within run-to-run noise. The title is bound by the CPU there, so I withdrew the 17-18 → 29 figure, which mixed in another change.
Technical debt. I rewrote
docs/dev/debt/shader.md"Relative vector addressing" to describe the bounded array, the per-slot variables, theOpSwitchfallback andAPS5_NO_WINDOW_NARROWING, and added the measurement. Whether the driver keeps the variables in registers is still listed as not measured; the benchmark only shows the time difference.The PR's tests pass on the merged tree:
agc_vector_window,agc_driver_vector_window_direct_access,agc_driver_relative_indexing,agc_driver_scalar_relative_indexingandagc_driver_vector_window_narrowing. The new test still fails with the switch set.Benchmark (not part of the PR): drop into
core/libs/prx/libSceAgcDriver/tests/execution/VectorWindowBenchmark.cpp, runagc_driver_vector_window_benchmark_tests <wave> 256 [m0 for the unbounded variant]bench.s(bench2.s addss_mov_b32 m0, s11,v_movrels_b32 v5, v10,v_add_nc_u32 v4, v4, v5,v_movreld_b32 v10, v4after the firstv_movreld_b32):🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:09:14Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvModuleSetup.cppcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppdocs/dev/debt/shader.mdcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppdocs/dev/debt/shader.mdImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T12:36:47Z.
Review: APPROVED
Re-checked on the PR merged onto current
main: build + Agc/AgcDriver ctest,agc_driver_vector_window_narrowingpasses; the only red test,agc_driver_tessellation, also segfaults onmain. Both earlier points are addressed: the pairedmain/ narrowing-off / PR measurement is in the description (and the withdrawn presents figure), and the technical debt line for relative vector addressing now describes the narrowed array, the slot variables, theOpSwitchfallback, the switch and the numbers. Merging once the full Build is green.