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

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1865
Author: @kirigayakazima
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/shader-meta-scalar-folding


📝 Commits (1)

  • e0a8694 Fold s_min/max_i32, s_bfe_i32, s_sext_i32, and s_pack_* in shader_meta and guard SGPR width

📊 Changes

3 files changed (+98 additions, -7 deletions)

View changed files

📝 tests/test_shader_meta.py (+39 -0)
📝 tests/test_shader_meta_operands.py (+21 -0)
📝 tools/shader_meta.py (+38 -7)

📄 Description

Claimed in the coordination issue as: SHADER-META-SCALAR-PACK-SEXT-SIGNED-FOLD-AND-WIDTH-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164029615)

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.

🔄 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/1865 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/shader-meta-scalar-folding` --- ### 📝 Commits (1) - [`e0a8694`](https://github.com/ubiquitarianism/leonida/commit/e0a8694befcf39bafe1b0ddd4519af31dc274832) Fold s_min/max_i32, s_bfe_i32, s_sext_i32, and s_pack_* in shader_meta and guard SGPR width ### 📊 Changes **3 files changed** (+98 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_shader_meta.py` (+39 -0) 📝 `tests/test_shader_meta_operands.py` (+21 -0) 📝 `tools/shader_meta.py` (+38 -7) </details> ### 📄 Description Claimed in the coordination issue as: SHADER-META-SCALAR-PACK-SEXT-SIGNED-FOLD-AND-WIDTH-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164029615) ### 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. --- <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#1877
No description provided.