shader_meta: handle short v_*_co_ci_u32, SMEM atomics, buffer_load lds, and VGPR swap/rel vscale (SHADER-META-OPERANDS-AND-LDS) #2018

Merged
leonida/mandy
ShotTechOp merged 1 commit from fix/shader-meta-operands-lds into main 2026-11-28 17:58:39 +00:00

Pull request successfully merged and closed

ShotTechOp commented 2026-11-25 18:14:28 +00:00

Claimed in #1608 as SHADER-META-OPERANDS-AND-LDS.

What and why

Fixes four static-analysis bugs in tools/shader_meta.py:

  1. 3-operand v_*_co_ci_u32 short forms (v_add_co_ci_u32 vD, src0, src1 and sub/subrev variants with implicit VCC): _split_operands previously treated a[1] as a written carry-out SGPR regardless of arity, dropping a user SGPR in src0 from reads and marking it written. Carry-out a[1] is now treated as a write only when len(a) >= 4.
  2. SMEM atomics (s_atomic_*, s_buffer_atomic_*): _split_operands previously placed a[0] in writes only, missing it as a read-before-write operand and falsely clobbering it when glc is absent. _step_state now also classifies a[1] as ptr64/ptr32_lo (s_atomic_*) or vsharp (s_buffer_atomic_*).
  3. LDS DMA buffer loads (buffer_load* / tbuffer_load* with lds): these omit vdata, placing srsrc (V#) at a[1] instead of a[2]. _step_state now inspects a[1] when lds is present so user-SGPR V#s are classified as vsharp.
  4. VGPR vscale tracking across v_swap_b32 and v_movreld_b32/v_movrelsd_b32/v_movrelsd_2_b32/v_swaprel_b32: v_swap_b32 now swaps vscale between both operands instead of only clearing a[0], and relative VGPR writes clear vscale entries at or above the base VGPR.

Testing

  • AI-assisted: yes.
  • Environment: Windows 11, Python 3.12 (no GPU / LLVM / SPIRV-Tools installed locally).
  • New test suite: tests/test_shader_meta_split_and_lds.py.
  • RED control on origin/main: tests/test_shader_meta_split_and_lds.py fails with FAILED (failures=9) across all 4 test methods on origin/main.
  • GREEN checks on branch:
    • python -I tests/test_shader_meta_split_and_lds.py -v (4/4 OK)
    • python -I tests/test_shader_meta.py (28/28 OK)
    • python -I tests/test_shader_meta_operands.py (5/5 OK)
    • python -I tests/test_text_write_line_endings.py (3/3 OK)
    • python -m compileall -q tools/shader_meta.py tests/test_shader_meta_split_and_lds.py
    • python -I scripts/check_no_game_data.py tools/shader_meta.py tests/test_shader_meta_split_and_lds.py
    • git diff --check
Claimed in #1608 as `SHADER-META-OPERANDS-AND-LDS`. ## What and why Fixes four static-analysis bugs in `tools/shader_meta.py`: 1. **3-operand `v_*_co_ci_u32` short forms** (`v_add_co_ci_u32 vD, src0, src1` and `sub`/`subrev` variants with implicit VCC): `_split_operands` previously treated `a[1]` as a written carry-out SGPR regardless of arity, dropping a user SGPR in `src0` from `reads` and marking it written. Carry-out `a[1]` is now treated as a write only when `len(a) >= 4`. 2. **SMEM atomics (`s_atomic_*`, `s_buffer_atomic_*`)**: `_split_operands` previously placed `a[0]` in `writes` only, missing it as a read-before-write operand and falsely clobbering it when `glc` is absent. `_step_state` now also classifies `a[1]` as `ptr64`/`ptr32_lo` (`s_atomic_*`) or `vsharp` (`s_buffer_atomic_*`). 3. **LDS DMA buffer loads (`buffer_load*` / `tbuffer_load*` with `lds`)**: these omit `vdata`, placing `srsrc` (V#) at `a[1]` instead of `a[2]`. `_step_state` now inspects `a[1]` when `lds` is present so user-SGPR V#s are classified as `vsharp`. 4. **VGPR `vscale` tracking across `v_swap_b32` and `v_movreld_b32`/`v_movrelsd_b32`/`v_movrelsd_2_b32`/`v_swaprel_b32`**: `v_swap_b32` now swaps `vscale` between both operands instead of only clearing `a[0]`, and relative VGPR writes clear `vscale` entries at or above the base VGPR. ## Testing - **AI-assisted**: yes. - **Environment**: Windows 11, Python 3.12 (no GPU / LLVM / SPIRV-Tools installed locally). - **New test suite**: `tests/test_shader_meta_split_and_lds.py`. - **RED control on `origin/main`**: `tests/test_shader_meta_split_and_lds.py` fails with `FAILED (failures=9)` across all 4 test methods on `origin/main`. - **GREEN checks on branch**: - `python -I tests/test_shader_meta_split_and_lds.py -v` (4/4 OK) - `python -I tests/test_shader_meta.py` (28/28 OK) - `python -I tests/test_shader_meta_operands.py` (5/5 OK) - `python -I tests/test_text_write_line_endings.py` (3/3 OK) - `python -m compileall -q tools/shader_meta.py tests/test_shader_meta_split_and_lds.py` - `python -I scripts/check_no_game_data.py tools/shader_meta.py tests/test_shader_meta_split_and_lds.py` - `git diff --check`
kirigayakazima commented 2026-11-28 05:35:05 +00:00

#2018 | head 92c174d7b28fa501c6cb622761dd47932301fd97 | python -I tests/test_shader_meta_split_and_lds.py | red: FAILED (failures=9, AssertionError) | green: 4/4 OK (0.001s) | full suite: 514/522 stdlib passed, 0 new failures vs main 8994000b08 | Windows 11, Python 3.14.7, no game files | AI-assisted: yes, Antigravity (Gemini)

Details:

  • Red (PR test tests/test_shader_meta_split_and_lds.py on upstream/main 8994000b08): Ran 4 tests in 0.004s — FAILED (failures=9) (9 AssertionError failures covering short v_*_co_ci_u32 operand reads, SMEM atomics, buffer/tbuffer_load_* lds V# detection, and v_swap_b32 vscale tracking).
  • Green (merged with upstream/main 8994000b08): Ran 4 tests in 0.001s — OK.
  • Repo checks: scripts/check_no_game_data.py -> 0; python -m compileall -q tools scripts tests -> 0; node --test tests/test_viewer_streaming.cjs -> 0; standalone stdlib tests/test_*.py -> 514/522 passed (33 skipped pytest/helper files; 0 new failures vs 8994000b08, same 8 pre-existing failures).
`#2018 | head 92c174d7b28fa501c6cb622761dd47932301fd97 | python -I tests/test_shader_meta_split_and_lds.py | red: FAILED (failures=9, AssertionError) | green: 4/4 OK (0.001s) | full suite: 514/522 stdlib passed, 0 new failures vs main 8994000b08 | Windows 11, Python 3.14.7, no game files | AI-assisted: yes, Antigravity (Gemini)` Details: - **Red** (PR test `tests/test_shader_meta_split_and_lds.py` on `upstream/main` `8994000b08`): `Ran 4 tests in 0.004s — FAILED (failures=9)` (9 `AssertionError` failures covering short `v_*_co_ci_u32` operand reads, SMEM atomics, `buffer/tbuffer_load_* lds` V# detection, and `v_swap_b32` `vscale` tracking). - **Green** (merged with `upstream/main` `8994000b08`): `Ran 4 tests in 0.001s — OK`. - **Repo checks**: `scripts/check_no_game_data.py` -> `0`; `python -m compileall -q tools scripts tests` -> `0`; `node --test tests/test_viewer_streaming.cjs` -> `0`; standalone stdlib `tests/test_*.py` -> `514/522 passed` (`33` skipped pytest/helper files; `0` new failures vs `8994000b08`, same 8 pre-existing failures).
zmasi commented 2026-11-28 13:01:07 +00:00

#2018 | head 92c174d7b28fa501c6cb622761dd47932301fd97 (merged cleanly onto main d48a957bb9988afce424552a3c0c8d01ef12320f) | Windows 11 (10.0.26200), CPython 3.12.10, llvm-mc (gfx1013), spirv-val (1.4.363.1), NVIDIA GeForce RTX 3090 (Vulkan 1.4.341, driver 610.88, subgroup 32..32, LEONIDA_VK_VALIDATION=1)

  • Red on main (d48a957bb9988afce424552a3c0c8d01ef12320f): tests/test_shader_meta_split_and_lds.py fails on main (FAILED (failures=9): short v_*_co_ci_u32 treats src0 user SGPR as a carry-out write, SMEM atomics without glc clobber a[0], 3-operand buffer_load* ... lds misses vsharp at a[1], and v_swap_b32 / v_movreld_b32 leave stale vscale).
  • Green on PR + main:
    • python -I tests/test_shader_meta_split_and_lds.py -v, python -I tests/test_shader_meta.py -v, and python -I tests/test_shader_meta_operands.py -v: all pass (OK).
    • Live llvm-mc + rdna2spirv.py + RTX 3090 vk_compute_test (LEONIDA_VK_VALIDATION=1, spirv-val clean) on v_swap_b32 + v_readfirstlane_b32: out[0..1] = 0x77 0x0 exact (0 Khronos validation errors).
    • scripts/check_no_game_data.py and test_text_write_line_endings.py: pass (0 CRLF).
  • Non-blocking note (cross-PR with #2168 / tools/rdna2_decode.py): srsrc_idx = 1 if (op.startswith(("buffer_load", "tbuffer_load")) and "lds" in ins.get("mods", ())) else 2 assumes the 3-operand llvm-mc spelling (vaddr, srsrc, soffset). tools/rdna2_decode.py (--backend python, supported by #2168) prints all 4 operands (vdata, vaddr, srsrc, soffset) on lds forms, where srsrc is still a[2] (len(a) == 3 disambiguates both).

AI-assisted.

#2018 | head `92c174d7b28fa501c6cb622761dd47932301fd97` (merged cleanly onto `main` `d48a957bb9988afce424552a3c0c8d01ef12320f`) | Windows 11 (`10.0.26200`), CPython `3.12.10`, `llvm-mc` (`gfx1013`), `spirv-val` (`1.4.363.1`), NVIDIA GeForce RTX 3090 (Vulkan `1.4.341`, driver `610.88`, `subgroup 32..32`, `LEONIDA_VK_VALIDATION=1`) - **Red on `main` (`d48a957bb9988afce424552a3c0c8d01ef12320f`)**: `tests/test_shader_meta_split_and_lds.py` fails on `main` (`FAILED (failures=9)`: short `v_*_co_ci_u32` treats `src0` user SGPR as a carry-out write, SMEM atomics without `glc` clobber `a[0]`, 3-operand `buffer_load* ... lds` misses `vsharp` at `a[1]`, and `v_swap_b32` / `v_movreld_b32` leave stale `vscale`). - **Green on `PR + main`**: - `python -I tests/test_shader_meta_split_and_lds.py -v`, `python -I tests/test_shader_meta.py -v`, and `python -I tests/test_shader_meta_operands.py -v`: all pass (`OK`). - Live `llvm-mc` + `rdna2spirv.py` + RTX 3090 `vk_compute_test` (`LEONIDA_VK_VALIDATION=1`, `spirv-val` clean) on `v_swap_b32` + `v_readfirstlane_b32`: `out[0..1] = 0x77 0x0` exact (`0` Khronos validation errors). - `scripts/check_no_game_data.py` and `test_text_write_line_endings.py`: pass (`0` CRLF). - **Non-blocking note (cross-PR with `#2168` / `tools/rdna2_decode.py`)**: `srsrc_idx = 1 if (op.startswith(("buffer_load", "tbuffer_load")) and "lds" in ins.get("mods", ())) else 2` assumes the 3-operand `llvm-mc` spelling `(vaddr, srsrc, soffset)`. `tools/rdna2_decode.py` (`--backend python`, supported by `#2168`) prints all 4 operands `(vdata, vaddr, srsrc, soffset)` on `lds` forms, where `srsrc` is still `a[2]` (`len(a) == 3` disambiguates both). AI-assisted.
MoonEyes commented 2026-11-28 17:58:36 +00:00

Red/green: tests/test_shader_meta_split_and_lds.py fails 9 assertions on main (short v_*_co_ci_u32 carry write, SMEM atomics without glc, buffer_load lds V# slot, v_swap/v_movrel vscale) and passes with the PR.
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main cb7a239cc in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

Red/green: tests/test_shader_meta_split_and_lds.py fails 9 assertions on main (short v_*_co_ci_u32 carry write, SMEM atomics without glc, buffer_load lds V# slot, v_swap/v_movrel vscale) and passes with the PR. Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main cb7a239cc in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No description provided.