shader: lower compute v_add_nc_i32 and v_sub_nc_i32 #1950

Merged
henriazz10 merged 1 commit from upstream-pr/1957 into main 2026-11-24 22:16:42 +00:00
henriazz10 commented 2026-11-24 22:07:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by henriazz10 on 2026-11-24T22:07:13Z.


Change

Refs #721. This is the v_add_nc_i32 / v_sub_nc_i32 slice claimed in https://github.com/R0Y00/Xbox2Windows/issues/721#issuecomment-7143412663. It touches only tools/compute_store_aot.py, tests/compute_store_check.py, CMakeLists.txt, and docs/experiments.md.

  • v_add_nc_i32 vD, S0, S1 and v_sub_nc_i32 vD, S0, S1 (VOP3, RDNA2 ISA D.i = S0.i + S1.i and D.i = S0.i - S1.i) lower on known words (ALU_SOURCE: VGPR, known SGPR, integer inline constant, or 32-bit literal) to ({0} + {1}) and ({0} - {1}) in uint arithmetic so 32-bit two's-complement wrap-around without carry-out is exact.
  • Refused, each with its own control:
    • unknown or pending sources (s30, v40, s12);
    • clamp on v_add_nc_i32 and v_sub_nc_i32, and omod (mul:2);
    • source modifiers (-v3, |v3|, neg(v3));
    • vD above v255 (v256);
    • other spellings (v_add_nc_i32_e32, v_add_nc_i32_e64, v_sub_nc_i32_e32, v_sub_nc_i32_e64).

Verification

Commit 4fe59c25, rebased onto 999875ad. The draws, controls() and the LLVM 15 round trip were re-run on 4fe59c25. Windows 11 build 26300, DXC 10.0.26100.0, Python 3.12.10, debug layer enabled. offscreen_check was built from an earlier main; this PR does not change it.

python -B tests/compute_store_check.py draw-vadd_nc_i32 <dxc> <offscreen_check> warp
python -B tests/compute_store_check.py draw-vadd_nc_i32 <dxc> <offscreen_check> hardware
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py
git diff --check HEAD~1
Backend Adapter / driver Result
WARP Microsoft Basic Render Driver 10.0.26100.9818 exit 0, groups=1 compared_words=320 mismatches=0, debug_errors=0 debug_warnings=0
hardware NVIDIA GeForce RTX 5080, 32.0.16.1692 exit 0, groups=1 compared_words=320 mismatches=0, debug_errors=0 debug_warnings=0
  • docs_links_check.py: exit 0 (Checked 18 Markdown files and 376 links.).
  • bidi_controls_check.py: exit 0 (Checked 1330 tracked source, script and build/CI files: no bidirectional controls.).
  • git diff --check HEAD~1: exit 0.

The LLVM 15 round trip in Docker:

docker run --rm -v "C:\Proyectos\Xbox2Windows\wt-vadd-nc-i32:/src" x2w-llvm15 bash -c 'cp -r /src /w && cd /w && python3 -B tests/compute_store_check.py binary llvm-mc-15 llvm-objcopy-15 /usr/lib/x86_64-linux-gnu/libLLVM-15.so.1; echo binary_exit=$?'

vadd_nc_i32_binary() decodes the assembled fixture back to the same v_add_nc_i32 and v_sub_nc_i32 lines and requires the same translation (binary_exit=0).

Negative control. With tools/compute_store_aot.py from origin/main, vadd_nc_i32_controls() fails with ValueError: Unsupported compute instruction: v_add_nc_i32 v4, v3, 0x7ffffff0.

Evidence

The fixture VADD_NC_I32 is source-built in LLVM 15 spelling. It runs one group of 64 threads and exercises v_add_nc_i32 and v_sub_nc_i32 across VGPR, SGPR (s4 = 0x80000005, s5 = 0x80000001), negative inline constant (-16), and 32-bit literal (0x7ffffff0), crossing 0x7fffffff <-> 0x80000000 with unique words per thread and comparing all 320 words against an independent Python reference.

  • Translation controls. vadd_nc_i32_controls() checks the exact HLSL outputData.Store expression and all rejection cases listed above.
  • Reference controls. Each must fail at its first differing word:
    • add as sub: word 0;
    • sub as add: word 0;
    • signed clamp instead of wrap: word 0;
    • sentinel past group: word 64.
  • Recompiled-HLSL controls. Each must fail on the device with Compute readback differs:
    • add replaced by sub (+ 0x7ffffff0u) -> - 0x7ffffff0u));
    • sub replaced by add (0x80000001u - tid.x -> 0x80000001u + tid.x);
    • literal off by one (0x7ffffff0u -> 0x7ffffff1u).

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed (docs/experiments.md).
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted. Gemini 4 Hydrogen (Antigravity CLI) wrote the change and ran the checks; Claude Code reviewed it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6592364925 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1957). Originally posted by [henriazz10](https://github.com/henriazz10) on 2026-11-24T22:07:13Z. --- ## Change Refs #721. This is the `v_add_nc_i32` / `v_sub_nc_i32` slice claimed in https://github.com/R0Y00/Xbox2Windows/issues/721#issuecomment-7143412663. It touches only `tools/compute_store_aot.py`, `tests/compute_store_check.py`, `CMakeLists.txt`, and `docs/experiments.md`. - `v_add_nc_i32 vD, S0, S1` and `v_sub_nc_i32 vD, S0, S1` (VOP3, RDNA2 ISA `D.i = S0.i + S1.i` and `D.i = S0.i - S1.i`) lower on known words (`ALU_SOURCE`: VGPR, known SGPR, integer inline constant, or 32-bit literal) to `({0} + {1})` and `({0} - {1})` in `uint` arithmetic so 32-bit two's-complement wrap-around without carry-out is exact. - Refused, each with its own control: - unknown or pending sources (`s30`, `v40`, `s12`); - `clamp` on `v_add_nc_i32` and `v_sub_nc_i32`, and `omod` (`mul:2`); - source modifiers (`-v3`, `|v3|`, `neg(v3)`); - `vD` above `v255` (`v256`); - other spellings (`v_add_nc_i32_e32`, `v_add_nc_i32_e64`, `v_sub_nc_i32_e32`, `v_sub_nc_i32_e64`). ## Verification Commit `4fe59c25`, rebased onto `999875ad`. The draws, `controls()` and the LLVM 15 round trip were re-run on `4fe59c25`. Windows 11 build 26300, DXC 10.0.26100.0, Python 3.12.10, debug layer enabled. `offscreen_check` was built from an earlier `main`; this PR does not change it. ```powershell python -B tests/compute_store_check.py draw-vadd_nc_i32 <dxc> <offscreen_check> warp python -B tests/compute_store_check.py draw-vadd_nc_i32 <dxc> <offscreen_check> hardware python -B tests/docs_links_check.py python -B tests/bidi_controls_check.py git diff --check HEAD~1 ``` | Backend | Adapter / driver | Result | |---|---|---| | WARP | Microsoft Basic Render Driver 10.0.26100.9818 | exit 0, `groups=1 compared_words=320 mismatches=0`, `debug_errors=0 debug_warnings=0` | | hardware | NVIDIA GeForce RTX 5080, 32.0.16.1692 | exit 0, `groups=1 compared_words=320 mismatches=0`, `debug_errors=0 debug_warnings=0` | - `docs_links_check.py`: exit 0 (`Checked 18 Markdown files and 376 links.`). - `bidi_controls_check.py`: exit 0 (`Checked 1330 tracked source, script and build/CI files: no bidirectional controls.`). - `git diff --check HEAD~1`: exit 0. The LLVM 15 round trip in Docker: ```sh docker run --rm -v "C:\Proyectos\Xbox2Windows\wt-vadd-nc-i32:/src" x2w-llvm15 bash -c 'cp -r /src /w && cd /w && python3 -B tests/compute_store_check.py binary llvm-mc-15 llvm-objcopy-15 /usr/lib/x86_64-linux-gnu/libLLVM-15.so.1; echo binary_exit=$?' ``` `vadd_nc_i32_binary()` decodes the assembled fixture back to the same `v_add_nc_i32` and `v_sub_nc_i32` lines and requires the same translation (`binary_exit=0`). **Negative control.** With `tools/compute_store_aot.py` from `origin/main`, `vadd_nc_i32_controls()` fails with `ValueError: Unsupported compute instruction: v_add_nc_i32 v4, v3, 0x7ffffff0`. ## Evidence The fixture `VADD_NC_I32` is source-built in LLVM 15 spelling. It runs one group of 64 threads and exercises `v_add_nc_i32` and `v_sub_nc_i32` across VGPR, SGPR (`s4 = 0x80000005`, `s5 = 0x80000001`), negative inline constant (`-16`), and 32-bit literal (`0x7ffffff0`), crossing `0x7fffffff <-> 0x80000000` with unique words per thread and comparing all 320 words against an independent Python reference. - **Translation controls.** `vadd_nc_i32_controls()` checks the exact HLSL `outputData.Store` expression and all rejection cases listed above. - **Reference controls.** Each must fail at its first differing word: - `add as sub`: word 0; - `sub as add`: word 0; - `signed clamp instead of wrap`: word 0; - `sentinel past group`: word 64. - **Recompiled-HLSL controls.** Each must fail on the device with `Compute readback differs`: - `add replaced by sub` (`+ 0x7ffffff0u)` -> `- 0x7ffffff0u)`); - `sub replaced by add` (`0x80000001u - tid.x` -> `0x80000001u + tid.x`); - `literal off by one` (`0x7ffffff0u` -> `0x7ffffff1u`). ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed (`docs/experiments.md`). - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted. Gemini 4 Hydrogen (Antigravity CLI) wrote the change and ran the checks; Claude Code reviewed it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 23:03:15 +00:00
tedin7 commented 2026-11-24 23:03:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T22:16:03Z.

Review: COMMENTED


Review of head 4fe59c2571

Scope: tools/compute_store_aot.py lowers v_add_nc_i32 / v_sub_nc_i32 (VOP3, known words) to ({0} + {1}) / ({0} - {1}) in uint arithmetic. clamp, omod, source modifiers, _e32/_e64 spellings and unknown sources are refused. CMakeLists.txt only registers the new compute_store_aot_vadd_nc_i32_{warp,hardware} tests. The docs match the code. No copied vendor material seen.

Commands run locally (all PASS):

  • git merge-tree --write-tree --name-only origin/main HEAD: clean, no conflicts
  • python3 -B tests/compute_store_check.py controls: controls pass (the new rejection cases and exact HLSL line)
  • python3 tests/docs_links_check.py: pass
  • python3 tests/bidi_controls_check.py: pass
  • git diff --check origin/main...HEAD: clean
  • Win2025 (win2025 1957), Debug (--preset dev) and Release /O2 (--preset release): pass, including compute_store_aot_vadd_nc_i32_warp
  • GitHub CI: Linux, Windows and gfx1013 fixtures pass

Mutations in the code under test (each killed by controls, then reverted):

  • v_add_nc_i32 lowered with - instead of +: killed (exact HLSL assert)
  • v_sub_nc_i32 lowered with + instead of -: killed (exact HLSL assert)
  • v_sub_nc_i32 dropped from the VOP3 regex: killed (lowering refused)

P1: 0. P2: 0.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6048268918 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1957#pullrequestreview-6048268918). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T22:16:03Z. **Review:** COMMENTED --- Review of head 4fe59c25713868f8566bcd1c2e15c1359707197f Scope: `tools/compute_store_aot.py` lowers `v_add_nc_i32` / `v_sub_nc_i32` (VOP3, known words) to `({0} + {1})` / `({0} - {1})` in uint arithmetic. `clamp`, `omod`, source modifiers, `_e32`/`_e64` spellings and unknown sources are refused. CMakeLists.txt only registers the new `compute_store_aot_vadd_nc_i32_{warp,hardware}` tests. The docs match the code. No copied vendor material seen. Commands run locally (all PASS): - `git merge-tree --write-tree --name-only origin/main HEAD`: clean, no conflicts - `python3 -B tests/compute_store_check.py controls`: controls pass (the new rejection cases and exact HLSL line) - `python3 tests/docs_links_check.py`: pass - `python3 tests/bidi_controls_check.py`: pass - `git diff --check origin/main...HEAD`: clean - Win2025 (`win2025 1957`), Debug (`--preset dev`) and Release /O2 (`--preset release`): pass, including `compute_store_aot_vadd_nc_i32_warp` - GitHub CI: Linux, Windows and gfx1013 fixtures pass Mutations in the code under test (each killed by `controls`, then reverted): - `v_add_nc_i32` lowered with `-` instead of `+`: killed (exact HLSL assert) - `v_sub_nc_i32` lowered with `+` instead of `-`: killed (exact HLSL assert) - `v_sub_nc_i32` dropped from the VOP3 regex: killed (lowering refused) P1: 0. P2: 0. AI-assisted; commands listed were executed locally.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
R0Y00/Xbox2Windows!1950
No description provided.