perf(shader): look up opcode access traits in a table built at compile time #12002
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12002"
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 milescoviello on 2026-10-27T16:29:03Z.
What
Performance evidence: this is a CPU-only change to shader compilation, and the SPIR-V is byte-identical. oneandonlydean accepted paired replay timings for this class of change instead of title captures (#9132, #9198, #11719); the timings are below.
BufferAccessOf,SharedAccessOf,AddressOpcodeInfoOf,ImageOpcodeInfoOfandIrOpcodeHasSideEffectseach run aswitchover the opcode.IrOpcodeHasSideEffectsruns four of them before its own. Passes call them per instruction and per use, at 61 call sites in 17 files: dead code elimination'sMayHaveSideEffects,ValidateProgram, the memory and resource passes. In a replay profile with #11798, #11820 and #11967 applied,AddressOpcodeInfoOfalone is 2.7 % of samples.This turns the five
switches intoconstexprfunctions and fills a table with all five traits for everyIrOpcodeat compile time. The five public functions become one indexed load. An opcode outside the enum gets the same defaults theswitches'default:cases return:Noneaccesses, value-initialized info structs, no side effects.Measured with the shader replay over the 152 Crimson Desert (PPSA25286) pipeline requests in
--preparemode,perf stat -e task-clock, release builds,ANYPS5_NO_SHADER_CACHE=1:maineece5da035aloneOn
maineece5da035alone the gain was inside the run-to-run noise: one 17.63 s round sets the mean. The three allocation PRs have since merged (#11798, #11820, #11967), so the gain now shows onmainitself.Current
main(11-09):main52c33518f8against this PR merged onto it (354249cff1), release builds with SPIRV-Tools off,ANYPS5_NO_SHADER_CACHE=1,--spvover the 152 Crimson Desert and 305 MXGP 26 requests (457),perf stat -e task-clock, 10 interleaved rounds:main52c33518f8The SPIR-V is byte-identical there too: 0 of the 65 Crimson Desert modules and 0 of the 304 MXGP modules differ. The SPIR-V is byte-identical: all 65 modules from the Crimson Desert requests and all 302 from MXGP 26's (PPSA30839) dump, both on
mainand on the stack.How
IrOpcode.cpponly:computeBufferAccess,computeSharedAccess,computeAddressOpcodeInfo,computeImageOpcodeInfoandcomputeHasSideEffectsare the former bodies, nowstatic constexpr.TraitTableis aconstexpr std::array<OpcodeTraits, IrOpcode::Count>built from them.traitsOfreturns a defaultedOpcodeTraitsfor an index past the table, matching theswitches'default:cases.Tested
Linux (Ubuntu 26.04, GCC 15.2):
ctest3 runs: all 75 entries pass in every run at this head (f0595a79ba).agc_ir_reclaim,agc_shader_memoryandagc_validate_program, 3 runs: all pass, with no AddressSanitizer or LeakSanitizer report.mainand on this head: 26 of 26 pass in all 3 runs on both sides.tools/pr_overlap.py: #7410 (wachi35676) editsIrOpcode.cppbut already conflicts withmain. It adds an opcode to theOpcodeMetatable around line 323, away from these hunks. A new opcode gets its traits from the sameconstexprfunctions, so the table needs no separate update.Timing method: 10 rounds per comparison in alternating or rotating order, nothing else running.
Title captures: Super Meat Boy 3D,
main9af563f33d+ #11580 (608dd76843) against the same + this PR (a1a31f6512), 5 interleaved rounds, recompiler cache off: no gain. Over each run's first 400 worker artifacts the worker time is 8,855 ms → 8,997 ms (+1.6 %, lower in 3 of 5) and over the first 350 title-thread artifacts 5,579 ms → 6,396 ms (+14.6 %, lower in 1 of 5); this PR is a draft until #11798, #11820 and #11967 land and it is measured again on them (table and traces). Round 2's summary lines: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