Repository navigation
perf(shader): look up opcode access traits in a table built at compile time - #12002
Conversation
|
This pull request is labeled |
|
Title captures for this change, the same setup as the captures on #12039 and #11967: Super Meat Boy 3D (PPSA31162 02.000.001), release libs, 100 s at a 12 GB cap with the same input script, recompiler cache off (
No run reached the later scene that skewed some other PRs' captures (483 to 507 worker artifacts in all ten). Over each run's first 400 worker and first 350 title-thread artifacts, the same boot work (total ms):
The title captures show no gain from this change. Over the same work the workers are 1.6 % higher (lower in 3 of 5 rounds) and the title thread 14.6 % higher (lower in 1 of 5). The median worker slice is also higher on this side in all 5 rounds (by 0 to 29 %), and round 4's PR run was slow throughout (worker median 12.3 ms against 8.1 to 9.9 ms in the other nine runs). This change only replaces four switches with a table built at compile time, and I have no explanation for a cost of this size. I don't read it as a measured regression, but there is no improvement here either. The replay task-clock measurement in the description already called it noise on So I'm marking this PR as a draft. Once those three are in The summary lines of round 2: All ten traces, summary lines and AI-assisted: yes (Claude Code) |
|
Hi @milescoviello, thanks for marking this ready again. Reviewed at f0595a7. #11798, #11820 and #11967 are all in |
|
Re-measured on current Setup. Base SPIR-V still byte-identical on current Task-clock over all 457 requests:
The table is faster on this side in 10 of 10 rounds (mean -2.03 %, median 16.98 s vs 16.63 s). So with the three prerequisites in AI-assisted: yes (Claude Code) |
|
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.
|
Reviewed opcode access-trait table (IrOpcode.cpp) — no blocking findingsThe five trait lookups return exactly what the old What I readHead reviewed: No build or test was run here; this review is from reading the code only. The test results and timings in the description and comments are the author's. Results
FindingsBlockingNone. Non-blocking
Not verified
To get this to a good stateNothing is required. Optionally add the table-equivalence test from non-blocking item 1. AI-assisted: yes (code read with Claude Code; no build or test run). |
|
Thanks for reading it closely. You're right that the table is the old AI-assisted: yes (Claude Code) |
…e time Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Added in AI-assisted: yes (Claude Code) |
f0595a7 to
4b8f060
Compare
Add ir_opcode_traits: asserts BufferAccessOf / SharedAccessOf / AddressOpcodeInfoOf / ImageOpcodeInfoOf / IrOpcodeHasSideEffects return the expected trait for a spread of opcodes, so a later change to a compute*() function the TraitTable is built from is caught even though the table equals the functions by construction (requested by Jirka135). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
4b8f060 to
2a3231d
Compare
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