tools/shader_meta: fold signed min/max, s_bfe_i32, s_sext_i32, s_pack_* and guard SGPR width #1865

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

@⁠kirigayakazima on GitHub · 2026-11-25 13:39 UTC · original
kirigayakazima:fix/shader-meta-scalar-folding → main · +98 −7 · 3 files · 1 commits · open

Claimed in the coordination issue as: SHADER-META-SCALAR-PACK-SEXT-SIGNED-FOLD-AND-WIDTH-GUARD (#1608)

What and why

  • Add bit-exact constant folding matching tools/rdna2spirv.py in tools/shader_meta.py for signed scalar min/max (s_min_i32, s_max_i32), signed bitfield extraction (s_bfe_i32), 16-bit half packing (s_pack_ll_b32_b16, s_pack_lh_b32_b16, s_pack_hh_b32_b16), and unary sign extension (s_sext_i32_i8, s_sext_i32_i16).
  • Guard scalar write and stride propagation branches (s_add_*, s_sub_*, s_addc_u32, s_subb_u32, and binary ALU folding) to require single-SGPR (n == 1) destination and stride-source operands so malformed multi-SGPR operands clear prior state cleanly without attaching bogus constant or stride tags.
  • Add positive and negative unit tests across tests/test_shader_meta.py and tests/test_shader_meta_operands.py.

Tested

  • Patched: python -I tests/test_shader_meta.py -v -> Ran 30 tests in 0.200s (OK); python -I tests/test_shader_meta_operands.py -v -> Ran 6 tests in 0.000s (OK).
  • Baseline check (upstream/main 5e95fa2f with updated test files copied into detached worktree): test_shader_meta.py -> Ran 30 tests in 0.267s (FAILED (failures=17)); test_shader_meta_operands.py -> Ran 6 tests in 0.001s (FAILED (failures=3)).
  • Repo gates: python -I tests/test_ci_registration.py (Ran 16 tests in 5.029s, OK), python -I tests/test_text_write_line_endings.py (Ran 3 tests in 12.679s, OK), python -I scripts/check_no_game_data.py (exit 0), python -I -m compileall -q (exit 0), git diff --check (exit 0).

GPUs tested: n/a (static shader metadata constant folding and operand width validation tests)

AI-assisted: yes

Checklist

  • Based on current main 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.
**@⁠kirigayakazima** on GitHub · 2026-11-25 13:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1865) `kirigayakazima:fix/shader-meta-scalar-folding` → `main` · +98 −7 · 3 files · 1 commits · open Claimed in the coordination issue as: SHADER-META-SCALAR-PACK-SEXT-SIGNED-FOLD-AND-WIDTH-GUARD (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why - Add bit-exact constant folding matching `tools/rdna2spirv.py` in `tools/shader_meta.py` for signed scalar min/max (`s_min_i32`, `s_max_i32`), signed bitfield extraction (`s_bfe_i32`), 16-bit half packing (`s_pack_ll_b32_b16`, `s_pack_lh_b32_b16`, `s_pack_hh_b32_b16`), and unary sign extension (`s_sext_i32_i8`, `s_sext_i32_i16`). - Guard scalar write and stride propagation branches (`s_add_*`, `s_sub_*`, `s_addc_u32`, `s_subb_u32`, and binary ALU folding) to require single-SGPR (`n == 1`) destination and stride-source operands so malformed multi-SGPR operands clear prior state cleanly without attaching bogus constant or stride tags. - Add positive and negative unit tests across `tests/test_shader_meta.py` and `tests/test_shader_meta_operands.py`. ### Tested - Patched: `python -I tests/test_shader_meta.py -v` -> `Ran 30 tests in 0.200s` (`OK`); `python -I tests/test_shader_meta_operands.py -v` -> `Ran 6 tests in 0.000s` (`OK`). - Baseline check (`upstream/main` `5e95fa2f` with updated test files copied into detached worktree): `test_shader_meta.py` -> `Ran 30 tests in 0.267s` (`FAILED (failures=17)`); `test_shader_meta_operands.py` -> `Ran 6 tests in 0.001s` (`FAILED (failures=3)`). - Repo gates: `python -I tests/test_ci_registration.py` (`Ran 16 tests in 5.029s`, `OK`), `python -I tests/test_text_write_line_endings.py` (`Ran 3 tests in 12.679s`, `OK`), `python -I scripts/check_no_game_data.py` (exit 0), `python -I -m compileall -q` (exit 0), `git diff --check` (exit 0). GPUs tested: n/a (static shader metadata constant folding and operand width validation tests) AI-assisted: yes ### Checklist - [x] Based on current `main` 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. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:09:17 +00:00
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-25 14:03 UTC · original

Tested e0a8694be on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main 71a769d7d (Python shader-metadata tool; no GPU):

  • pytest 9.2.0 on tests/test_shader_meta.py + tests/test_shader_meta_operands.py: 36 passed, 86 subtests passed at this head.
  • The same two files on main: 20 failed, 36 passed, 66 subtests — the signed min/max, s_bfe_i32, s_sext_i32, s_pack_* folds and the wide-scalar-destination width guard are new.
  • Not run: real shader metadata dumps; the tests build the instructions synthetically.

AI-assisted; synthetic fixtures only, no game data.

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 14:03 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1865#issuecomment-7164696093) Tested `e0a8694be` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `71a769d7d` (Python shader-metadata tool; no GPU): - pytest 9.2.0 on `tests/test_shader_meta.py` + `tests/test_shader_meta_operands.py`: **36 passed, 86 subtests passed** at this head. - The same two files on `main`: **20 failed**, 36 passed, 66 subtests — the signed min/max, `s_bfe_i32`, `s_sext_i32`, `s_pack_*` folds and the wide-scalar-destination width guard are new. - Not run: real shader metadata dumps; the tests build the instructions synthetically. AI-assisted; synthetic fixtures only, no game data.
Author
Owner

@⁠DeadlyChirp on GitHub · 2026-11-25 15:32 UTC · original

Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.

python -m pytest -q tests/test_shader_meta.py tests/test_shader_meta_operands.py:

  • PR: 36 passed, 86 subtests passed. main: 33 passed, 56 subtests passed. The new tests pass on Windows.

(AI-assisted test run; output checked by hand.)

**@⁠DeadlyChirp** on GitHub · 2026-11-25 15:32 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1865#issuecomment-7166994644) Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. `python -m pytest -q tests/test_shader_meta.py tests/test_shader_meta_operands.py`: - PR: 36 passed, 86 subtests passed. main: 33 passed, 56 subtests passed. The new tests pass on Windows. (AI-assisted test run; output checked by hand.)
Author
Owner

@⁠MSedgeMC on GitHub · 2026-11-25 19:28 UTC · original · approved these changes

Verified on the PR branch (clean, 1 commit ahead of main): python3 -m unittest tests.test_shader_meta -> 30 tests OK, including the new cases for signed s_min/s_max, s_bfe_i32 width clamping/sign extension, s_sext_i32_i8/i16, and s_pack_ll/lh/hh constant folding into literal samplers, plus negative cases where an unknown source must not fold. Genuine translator improvement with comprehensive 32-bit edge cases. Python-only, no game data.

**@⁠MSedgeMC** on GitHub · 2026-11-25 19:28 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1865#pullrequestreview-6063726467) · **approved these changes** Verified on the PR branch (clean, 1 commit ahead of main): python3 -m unittest tests.test_shader_meta -> 30 tests OK, including the new cases for signed s_min/s_max, s_bfe_i32 width clamping/sign extension, s_sext_i32_i8/i16, and s_pack_ll/lh/hh constant folding into literal samplers, plus negative cases where an unknown source must not fold. Genuine translator improvement with comprehensive 32-bit edge cases. Python-only, no game data.
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/1865/head:github-bot/gh-1865'
git switch 'github-bot/gh-1865'

Merge

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