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

Open
opened 2026-11-26 21:20:01 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2093
Author: @jarvixaiassistant-glitch
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: perf/spirv-opt-sroa


📝 Commits (1)

  • b782be7 spirv_opt: scalar-replace surviving static Function arrays (SROA)

📊 Changes

3 files changed (+388 additions, -11 deletions)

View changed files

📝 docs/design.md (+5 -3)
📝 tests/test_spirv_opt.py (+185 -0)
📝 tools/spirv_opt.py (+198 -8)

📄 Description

Claimed in the coordination issue as: SHADER-SPIRV-OPT-SROA (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7173149042)

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2093 **Author:** [@jarvixaiassistant-glitch](https://github.com/jarvixaiassistant-glitch) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `perf/spirv-opt-sroa` --- ### 📝 Commits (1) - [`b782be7`](https://github.com/ubiquitarianism/leonida/commit/b782be7af0c889c471fb8f7d39e32bbfe2c38430) spirv_opt: scalar-replace surviving static Function arrays (SROA) ### 📊 Changes **3 files changed** (+388 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+5 -3) 📝 `tests/test_spirv_opt.py` (+185 -0) 📝 `tools/spirv_opt.py` (+198 -8) </details> ### 📄 Description Claimed in the coordination issue as: SHADER-SPIRV-OPT-SROA (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7173149042) ### 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#2099
No description provided.