perf(shader): index specialization tables by SPIR-V id #4772
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4772"
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 TideOPL on 2026-10-12T21:26:31Z.
What
SpecializeSpirvruns whenever a prepared shader is materialized with a new set of specialization constants, on the queue worker that draws or dispatches. It kept all of its per-id data instd::mapandstd::set: folded values, result types, scalar types, vector types, removed ids, and per pass the blocks, edges, loop headers, live sets, extracts, copies and definitions.Runrepeats fold, prune and copy propagation over the whole module until nothing changes, so a large module paid several full passes of tree lookups.SPIR-V ids are dense below the header's bound. These tables become
IdTable<T>(a value vector with a presence flag) andIdSet(a flag vector), indexed by id:propagateCopieserases, the pending list inremoveDeadComputations,evaluate's operand lookups) stay bounds-checked and read as absent past the bound.IdTableiterates in ascending id order, as the maps did. The loops overblocks,edgesanddefinitionsare unchanged, and the output is byte-identical.The passes themselves are unchanged.
Tested
System: Windows 11 (26200), Ryzen 7 7800X3D, WinLibs GCC, Release, rebased on
mainc2565f014(which includes #4600).Real modules: I dumped 60
SpecializeSpirvinputs from Minecraft Dungeons II (PPSA16064) materializations: 2.35M words, the largest about 220k words. A throwaway benchmark (not part of this PR) runsSpecializeSpirvon each, best of 3:main2913d850cbdad15d2913d850cbdad15dThe outputs are identical for every module. Measured again after the rebase onto #4600.
In the title (perf branch, not a clean-
mainA/B): MCD2 spent about 8.3 s inSpecializeSpirvduring the first 40 s of a cold run, across 506 module builds. A single build took up to about 150 ms on a queue worker, which shows as a hitch when new effects appear. Steady-state frame times at the title were unchanged in a same-window A/B, as expected: the change only shortens first-use builds.New check in
agc_spirv_module: a module whose ids reach the header's bound is rejected. It fails onmain, where the maps accept any id, and passes with this change.Suites:
ctest -R "^agc", 460 tests: 457 pass,agc_driver_stencil_ref_exportis skipped as onmain, andagc_driver_bda_span_readsandagc_driver_pixel_interlockfail withvkDeviceWaitIdle-4 (device lost). Those two fail the same way onmainc2565f014on this machine.tools/check_conventions.pypasses.Not run: Linux, AMD.
Rebased onto
mainafter #4600 merged:loopHeadersis an id set next to #4600'scontinueHeadersmap, which stays astd::map.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)Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T03:27:15Z.
Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on current main
0c3dc9ca2together with eight other open GPU PRs (their own commits cherry-picked, no merge commits), so only the tests that belong to this PR say something about it:tests/SpirvModule.cpp(agc_spirv_module): 3 of 3 runs passed.Not tested: no game run. The batch was built once, not per PR; it had no failures, so no bisect was needed.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T15:27:20Z.
Checked the id-indexed tables against the diff: no pass allocates ids beyond the header bound, literal lookups stay bounds-checked, iteration stays in ascending id order. Built and ran the AGC/AgcDriver tests on the PR merged onto main (only the
agc_driver_tessellationsegfault that already fails on main);agc_spirv_modulepasses and its new bound check fails without the change. Merging once the Windows build is green.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-13T18:48:15Z.
Rebase handoff — rebased onto current
main(staleness only, applied cleanly), authorship unchanged.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesmainregression (agc_driver_tessellationsegfault, #4727)To pick it up:
Head is
5b3dc805d.