Commit Graph

10 Commits

Author SHA1 Message Date
4f958ab44b Merge origin/main into #2093 (carry prep)
tools/spirv_opt.py: both pinned_ids (main) and the SROA parameters (PR); main's id_type Result Type check kept after the PR's const_type check on null-zero loads; main's OpUndef/OpSpecConstant* const_type kept. tests/test_spirv_opt.py: both sets of new tests.

Co-authored-by: JARVIX <273200855+jarvixaiassistant-glitch@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 09:41:13 +01:00
00ed210a19 spirv_opt: scalar-replace surviving static Function arrays (SROA)
Split non-escaped, statically indexed Function-scope arrays (such as
%vgpr[256] and %sgpr[128] when no dynamic v_movrel*/s_movrel* indexing
exists) into per-slot scalar OpVariables for only the live slots
referenced after dominator-tree forwarding and DCE, eliminating the
monolithic array allocas and their static OpAccessChains.

Preserves arrays with dynamic indices, whole-array loads/stores,
escapes, decorations, non-null initializers, or negative/out-of-bounds
static indices; canonicalizes signed/unsigned constant indices with
equal value and rewrites multi-index OpAccessChains cleanly.
2026-11-28 09:12:41 +00:00
fad7435bcd spirv_opt: enforce Result Type match on int/load folding and pin OpDecorateId operands from DCE 2026-11-25 00:40:43 +01:00
85d2fb7a1a spirv_opt: --passes below 1 is a usage error, not a silent no-op
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-23 20:56:09 +01:00
32a50c949e spirv_opt: enforce strict dominance for OpPhi folding and track OpDecorateId/String/GroupDecorate (#6557)
Squash-merged after diff review of PR #6557
2026-11-23 12:45:21 -06:00
23fc0c9aa5 docs: point spirv_opt at its --help usage line (#6638)
Squash-merged after diff review of PR #6638
2026-11-23 11:09:22 -06:00
33905dc9dd Fix what the round-43 merges broke (pytest)
Merges that each passed alone but clash together:
- v_cmp_class_f64: the earlier cmp_class_f64 (685d16ed9) (operand-form checks, test_cmp_class_f64) and the later f64 branch
  in cmp_class both handled the opcode; f64 goes to cmp_class_f64 again, f16 stays in cmp_class.
- rdna2spirv CLI tests: spirv-as/spirv-val now run in the output folder with the staging file's bare name, so
  the test doubles resolve it against cwd; assemble_spirv decodes the output only when it is bytes. (The doubles
  had been writing .spirv-*.tmp files into the repository root.)
- ps_w64 fixtures (TEST-722): an 18th fixture (ps_w64_a_discard) landed; its killed lanes export nothing and
  keep the clear value.
- first_light: a run without an OBJ removes mesh.bin, and harness_env reads manifest["files"]; batch_glb's stats
  name failures and dropped textures; run_gpu_tests reports a frame never written as a missing readback
  (TEST-837).
- make_game TRANSLATION_SOURCES and runtime.yml's paths include spirv_opt.py and report_paths.py (and
  wave64_emulate_opt.py), which the translator imports.
Repo rules: stdout guard on six tools; encoding on two opens (gen_gdk_runtime_classes' helper is read_utf8);
newline on one write; anim_skeleton_match's joaat encodes like hashdict.joaat; test_feature_scan's new test is
listed with the others its globals() runner reaches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 22:07:41 -05:00
4016daf669 spirv_opt: exclude Volatile and mixed-depth Function vars from local memory opts
Addresses standalone memory-aliasing review findings on PR #2298 (@duudiis):
- Signed/unsigned integer index canonicalization (%uint 0 vs %int 0) is already handled
  by keying static OpAccessChain slots on const_int_val[i][1]; now also require every
  static slot index to be in const_int_val (treating unparsed constants as dynamic).
- Mark any Function-scope variable touched by a Volatile OpLoad or OpStore as escaped
  so volatile accesses never observe stale forwarded values or killed prior stores.
- Mark any Function-scope variable accessed at mixed aggregate/subobject slot depths
  (e.g. both whole-array and element pointers) as escaped to prevent partial-overlap
  aliasing.
- Add regression tests for all four cases in tests/test_spirv_opt.py.
2026-11-22 21:21:05 +01:00
cf9b0e5920 spirv_opt: upgrade to dominator-tree CSE, single-pred/read-only forwarding, int folding, and trivial OpPhi
Upgrades tools/spirv_opt.py from strictly intra-block peephole optimization to a
sound dominator-tree + CFG optimizer (still stdlib-only, O(N) iterative DFS with
undo-logged scoped tables):
- Dominator-tree preorder CSE for OpAccessChain, pure ALU / GLSL.std.450 ops (with
  commutative operand canonicalization), and immutable Input / PushConstant OpLoads.
- Whole-function read-only Function-scope variable propagation (e.g. %active across
  all blocks when never stored, and never-stored static slots of zero-init arrays)
  plus single-predecessor CFG slot forwarding (e.g. %entry -> %blk0 and if/else arms).
- Integer/bit constant folding (into existing module constants) and algebraic
  identities, OpCompositeExtract(OpCompositeConstruct) folding, bool-mask OpSelect
  unwrapping, double OpLogicalNot cancellation, and canonicalized integer slot keys.
- Trivial OpPhi simplification (identical or self-referential incoming values) and
  dead Function-scope OpVariable elimination.

Verification:
- tests/test_spirv_opt.py: 8/8 OK (spirv-val Vulkan 1.2 + semantic wave execution)
- 295/295 runtime/test/shaders modules (202 native + 93 --wave64-emulate) pass
  spirv-val Vulkan 1.2: -37.8% lines (454,593 -> 282,810) and -38.2% binary words
  (2,101,639 -> 1,299,235), up to -85.2% on ps_vcmpx_forms (6,138 -> 910 lines).
- Full tests/semantic/ sweep (2,567 tests) with OPT_SPIRV=True: 0 execution/value
  mismatches (only 116 raw-SPIR-V text/regex/sabotage-anchor assertions).
2026-11-22 21:21:05 +01:00
267f2e00b0 spirv_opt: sound basic-block SPIR-V peephole optimizer (#884) 2026-11-22 21:21:04 +01:00