spirv_opt: scalar-replace surviving static Function arrays (SHADER-SPIRV-OPT-SROA) #2093

Open
github-bot wants to merge 1 commit from github-bot/gh-2093 into main AGit
Owner

@⁠jarvixaiassistant-glitch on GitHub · 2026-11-25 20:02 UTC · original
jarvixaiassistant-glitch:perf/spirv-opt-sroa → main · +388 −11 · 3 files · 1 commits · open

Claimed in the coordination issue as: SHADER-SPIRV-OPT-SROA (#1608)

What and why

Adds Scalar Replacement of Aggregates (SROA) to tools/spirv_opt.py (--opt, off by default) for surviving non-escaped, statically indexed 1D Function-scope array variables (such as %vgpr[256] and %sgpr[128] when no dynamic v_movrel*/s_movrel* indexing is present):

  • Splits each qualifying Function array OpVariable into individual per-slot scalar Function OpVariables for only the live slots actually referenced after dominator-tree store-to-load forwarding and DCE, eliminating monolithic array allocas and their static OpAccessChain instructions (enabling further downstream forwarding/DSE/DCE across CFG merges and loops).
  • Soundly bails out and preserves arrays whenever any of the following apply: dynamic indices, whole-array loads/stores, non-load/store pointer escapes, decorations (OpDecorate/OpDecorateId/OpMemberDecorate), non-null initializers, or negative/out-of-bounds static indices.
  • Canonicalizes signed/unsigned constant indices with equal numeric values, rewrites multi-index OpAccessChain instructions cleanly, and generates collision-free SSA IDs across the whole module.
  • Documents the pass in docs/design.md and adds comprehensive unit + spirv-val + interpreter execution tests in tests/test_spirv_opt.py.

Tested

  • tests/test_spirv_opt.py (LEONIDA_REQUIRE_SPIRV_TOOLS=1, Khronos spirv-val): 14/14 PASS (1.013 s), including test_sroa_splits_surviving_register_arrays_across_control_flow, test_sroa_preserves_dynamic_array_and_handles_edge_cases, and test_wave64_emulated_compute_validates_and_shrinks.
  • scripts/check_no_game_data.py: PASS
  • tests/test_ci_registration.py: 16/16 PASS
  • All 13 tests/test_docs_*.py suites: 50/50 PASS

GPUs tested: n/a (pure-Python tools/spirv_opt.py + Khronos spirv-val + SPIR-V interpreter tests on Windows 11)

AI-assisted: yes (JARVIX)

Checklist

  • Based on current main (db1a22d29) and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
**@⁠jarvixaiassistant-glitch** on GitHub · 2026-11-25 20:02 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2093) `jarvixaiassistant-glitch:perf/spirv-opt-sroa` → `main` · +388 −11 · 3 files · 1 commits · open Claimed in the coordination issue as: SHADER-SPIRV-OPT-SROA (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why Adds Scalar Replacement of Aggregates (SROA) to `tools/spirv_opt.py` (`--opt`, off by default) for surviving non-escaped, statically indexed 1D `Function`-scope array variables (such as `%vgpr[256]` and `%sgpr[128]` when no dynamic `v_movrel*`/`s_movrel*` indexing is present): - Splits each qualifying `Function` array `OpVariable` into individual per-slot scalar `Function` `OpVariable`s for only the live slots actually referenced after dominator-tree store-to-load forwarding and DCE, eliminating monolithic array allocas and their static `OpAccessChain` instructions (enabling further downstream forwarding/DSE/DCE across CFG merges and loops). - Soundly bails out and preserves arrays whenever any of the following apply: dynamic indices, whole-array loads/stores, non-load/store pointer escapes, decorations (`OpDecorate`/`OpDecorateId`/`OpMemberDecorate`), non-null initializers, or negative/out-of-bounds static indices. - Canonicalizes signed/unsigned constant indices with equal numeric values, rewrites multi-index `OpAccessChain` instructions cleanly, and generates collision-free SSA IDs across the whole module. - Documents the pass in `docs/design.md` and adds comprehensive unit + `spirv-val` + interpreter execution tests in `tests/test_spirv_opt.py`. ### Tested - `tests/test_spirv_opt.py` (`LEONIDA_REQUIRE_SPIRV_TOOLS=1`, Khronos `spirv-val`): **14/14 PASS** (1.013 s), including `test_sroa_splits_surviving_register_arrays_across_control_flow`, `test_sroa_preserves_dynamic_array_and_handles_edge_cases`, and `test_wave64_emulated_compute_validates_and_shrinks`. - `scripts/check_no_game_data.py`: **PASS** - `tests/test_ci_registration.py`: **16/16 PASS** - All 13 `tests/test_docs_*.py` suites: **50/50 PASS** GPUs tested: n/a (pure-Python `tools/spirv_opt.py` + Khronos `spirv-val` + SPIR-V interpreter tests on Windows 11) AI-assisted: yes (JARVIX) ### Checklist - [x] Based on current `main` (`db1a22d29`) and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:17:32 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2093/head:github-bot/gh-2093'
git switch 'github-bot/gh-2093'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2093'
git switch 'github-bot/gh-2093'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2093'
git switch 'github-bot/gh-2093'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2093'
git switch 'main'
git merge --squash 'github-bot/gh-2093'
git switch 'main'
git merge --ff-only 'github-bot/gh-2093'
git switch 'main'
git merge 'github-bot/gh-2093'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.