Repository navigation
Conversation
… byte-identical output process_block now skips instructions no rule can touch (_BLOCK_OPS, _SIMPLIFY_OPS, _FOLD_OPS), _fold_int_op rejects a 3-operand op with no constant and no repeated operand up front, the escape / discover / DCE / dead-store scans walk only the opcodes they act on (list comprehensions and a C-level set intersection), the CFG reads its terminators once, alias resolution is skipped for instructions that name no alias, id_type no longer copies const_type per pass, and the module scan no longer parses every body line a second time to find OpFunctionEnd. Output is byte-identical on 221 translated shaders (max_passes 1, 2, 4, 8), and tracemalloc peak is unchanged. tests/test_spirv_opt_hotpath.py pins each opcode set to the rules it gates and pins a hand-written module's output. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Tested b4b411d merged with main 8575d36 on Linux/Python 3.12.16: pass Commands run (merged worktree,
Diff read: the optimizer's passes are gated by per-pass opcode sets, loops over all instructions are replaced by filtered iterations, the use-count and alias checks are shortened, and |
|
Tested b4b411d merged onto
AI-assisted (Claude Code). |
|
Tested b4b411d on Windows 11, Python 3.15.2, NVIDIA RTX 4060 Ti (driver 621.24; CPU-only checks, no game files, no GPU/llvm-mc/MSVC used): pass. Ran the test files this PR adds or changes, from a clean checkout of the PR head: AI-assisted (Claude Code). |
AI-assisted (Claude Code). Claims the item in #6910 ("claiming: new BUILD item —
tools/spirv_opt.pyhot path").#4760 turns
--opton for all 26,503 shaders, sotools/spirv_opt.pyis on the whole shader build's critical path. This makesoptimize()about 28% cheaper in CPU time with byte-identical output and no peak-memory change. It adds no cache, so nothing needs bounding.What changed (all in
tools/spirv_opt.py)process_blockreturns early for opcodes no rule can touch (_BLOCK_OPS), runs the copy/select/logical rules only for_SIMPLIFY_OPS, and asks_fold_int_oponly for_FOLD_OPS. It computesres not in decorated_idsonce per instruction._fold_int_oprejects a 3-operand op with no constant operand and no repeated operand first. Every rule it has needs one of the two.use_countis aCounterover the flattened operands. Dead instructions are dropped withitertools.compressinstead ofenumerateplus a set lookup._build_cfg_and_domreads the terminators while it splits blocks, and alias resolution is skipped for instructions that name no alias.optimize()no longer parses every function-body line a second time just to findOpFunctionEnd._parse_line, the OpPhi rule, the CLI and the decoration handling. They are what SHADER-885: preserve instructions with quoted SPIR-V comments #5064, spirv_opt: enforce strict dominance for OpPhi folding and track OpDec… #6557, BUILD-1578: Preserve vector shape and signedness in SPIR-V folds #5150, spirv_opt: a missing input or unwritable -o is one error line and exit 2 #4806 and spirv_opt: an unreadable src and an unwritable --out are one ERROR line and exit 2 #6022 touch.git merge-treeof this branch with each of those PR heads is clean, and with BUILD-1578: Preserve vector shape and signedness in SPIR-V folds #5150 and spirv_opt: enforce strict dominance for OpPhi folding and track OpDec… #6557 merged in the new tests still pass.id_typestays a full dict that includesconst_type, since BUILD-1578: Preserve vector shape and signedness in SPIR-V folds #5150 reads constant types from it.Measurements
Corpus: the 221 synthetic shaders of the GPU audit set (
gpu-current-shader-audit/disasm), translated withrdna2spirv.py --assembler python(all 221 translate;spirv-as/spirv-valaren't installed on this Windows machine, so assembly and validation were stubbed out of the harness). That is 15 MB of.spvasm, 311,534 lines before and 222,329 after. Python 3.12.10, Windows 11,time.process_time(),optimize()over all 221 modules, base and new alternated in one process:1cc6e3c12)The machine is noisy (the base alone varied 2.73-3.30 s between runs), so the table gives the ranges seen. The worst single round of the cleanest run was a 22.7% speedup; a few noisier rounds fell lower. The
cProfileview agrees:_optimize_functionplusprocess_blockself time drops from 6.6 s to 2.2 s under the profiler.Byte-identical output
main, at the defaultmax_passes=4.max_passes1, 2 and 8, and when the optimizer is applied a second time to its own output.tests/test_spirv_opt_hotpath.py.Tests
tests/test_spirv_opt_hotpath.py(11 tests, hand-written module, no game data). It checks that every opcode quoted inprocess_block, the simplify block,_fold_int_opand the DCE candidate test is in the set that gates it, so a new rule (for example the vector folds in BUILD-1578: Preserve vector shape and signedness in SPIR-V folds #5150) that forgets the gate fails the test and doesn't silently stop firing. It also probes_fold_int_opfor any opcode outside_FOLD_OPSthat folds, covers the fast-reject edge cases, and pins the optimized text of a module with store forwarding across a block edge, an escaped variable, folding, CSE, copy removal and DCE.python -m compileall -q tools/spirv_opt.py tests: clean.python -I tests/test_spirv_opt.py(9 tests) andpython -I tests/test_spirv_opt_hotpath.py(11 tests): OK.tests/semantic(as asked), and anything needingspirv-as/spirv-valor a GPU. No GPU involved.🤖 Generated with Claude Code