shader: lower compute v_add_co_u32 and v_add_co_ci_u32 #2124

Merged
henriazz10 merged 1 commit from upstream-pr/2132 into main 2026-11-25 01:29:14 +00:00
henriazz10 commented 2026-11-25 01:17:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by henriazz10 on 2026-11-25T01:17:37Z.


Change

Refs #721. Lower v_add_co_u32 (VOP3) and v_add_co_ci_u32 (_e32 and _e64) in tools/compute_store_aot.py, touching only tools/compute_store_aot.py, tests/compute_store_check.py, CMakeLists.txt, and docs/experiments.md.

  • v_add_co_u32 vD, sDst, S0, S1 computes (S0 + S1) mod 2^32 into vD and tracks the per-lane carry-out ((S0 + S1) < S0 ? 1u : 0u) in sDst (vcc_lo or s0..s105).
  • v_add_co_ci_u32_e32 vD, vcc_lo, S0, vS1, vcc_lo and v_add_co_ci_u32_e64 vD, sDst, S0, S1, sCarryIn add the tracked per-lane carry-in and update vD and sDst.
  • The carry SGPR is tracked as a vector-like ("carry", expr) value, not a uniform scalar word. Writing vcc_lo clears any prior v_cmp guard state, and any non-_ci reader (s_* ALU, v_* ALU, v_cndmask, s_and_saveexec_b32) is refused. Groups larger than 32 threads require wave_size=32.
  • Updated the existing alu_controls() negative-opcode check from v_add_co_u32 to v_sub_co_u32.

Verification

Commit b80ffd9e, rebased onto 5581b4b0. The draws, controls() and the LLVM 15 round trip were re-run on b80ffd9e. Windows 11 build 26300, DXC 10.0.26100.0, Python 3.12, debug layer enabled.

python -B tests/compute_store_check.py draw-add-co <dxc> <offscreen_check> warp
python -B tests/compute_store_check.py draw-add-co <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, compared_words=320 mismatches=0, debug_errors=0
hardware NVIDIA GeForce RTX 5080, 32.0.16.1692 exit 0, compared_words=320 mismatches=0, debug_errors=0

docs_links_check.py (18 Markdown files, 396 links), bidi_controls_check.py (1428 files), and git diff --check HEAD~1 all exited 0.

The LLVM 15 round trip in Docker (x2w-llvm15) exited 0 (binary_exit=0):

docker run --rm -v "C:\Proyectos\Xbox2Windows\wt-add-co:/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=$?'

Negative control. With tools/compute_store_aot.py from origin/main, add_co_controls() fails with ValueError: Unsupported compute instruction: v_add_co_u32 v10, vcc_lo, -16, v3.

Evidence

The ADD_CO fixture is source-built in LLVM 15 spelling for one 64-thread group (wave_size=32, buffer_store_dwordx4, 256 output words plus 64 SENTINEL words). It exercises v_add_co_u32 + v_add_co_ci_u32_e32 via vcc_lo (crossing 2^32 for tid.x >= 16) and v_add_co_u32 + v_add_co_ci_u32_e64 via s4/s5 (crossing 2^32 for tid.x >= 32, with v13 wrapping on carry-in), comparing all 320 words against an independent Python model.

  • Translation controls. Verify exact HLSL output, 32-thread group acceptance without wave_size=32, and refusals for >32 threads without wave_size=32, unknown/pending sources, invalid destinations, unverified carry-in, non-_ci readers of the carry SGPR (s_add_u32, v_add_nc_u32_e32, v_cndmask_b32_e64, s_and_saveexec_b32), modifiers (clamp, -, |...|, mul:2), and _e64 on v_add_co_u32.
  • Reference controls.
    • vcc carry dropped: word 65;
    • vcc carry inverted: word 1;
    • sgpr carry-in ignored: word 131;
    • sentinel past group: word 256.
  • Recompiled-HLSL controls.
    • vcc carry comparison flipped;
    • sgpr carry-in zeroed.

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:6594880913 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2132). Originally posted by [henriazz10](https://github.com/henriazz10) on 2026-11-25T01:17:37Z. --- ## Change Refs #721. Lower `v_add_co_u32` (VOP3) and `v_add_co_ci_u32` (`_e32` and `_e64`) in `tools/compute_store_aot.py`, touching only `tools/compute_store_aot.py`, `tests/compute_store_check.py`, `CMakeLists.txt`, and `docs/experiments.md`. - `v_add_co_u32 vD, sDst, S0, S1` computes `(S0 + S1) mod 2^32` into `vD` and tracks the per-lane carry-out `((S0 + S1) < S0 ? 1u : 0u)` in `sDst` (`vcc_lo` or `s0..s105`). - `v_add_co_ci_u32_e32 vD, vcc_lo, S0, vS1, vcc_lo` and `v_add_co_ci_u32_e64 vD, sDst, S0, S1, sCarryIn` add the tracked per-lane carry-in and update `vD` and `sDst`. - The carry SGPR is tracked as a vector-like `("carry", expr)` value, not a uniform scalar word. Writing `vcc_lo` clears any prior `v_cmp` guard state, and any non-`_ci` reader (`s_*` ALU, `v_*` ALU, `v_cndmask`, `s_and_saveexec_b32`) is refused. Groups larger than 32 threads require `wave_size=32`. - Updated the existing `alu_controls()` negative-opcode check from `v_add_co_u32` to `v_sub_co_u32`. ## Verification Commit `b80ffd9e`, rebased onto `5581b4b0`. The draws, `controls()` and the LLVM 15 round trip were re-run on `b80ffd9e`. Windows 11 build 26300, DXC 10.0.26100.0, Python 3.12, debug layer enabled. ```powershell python -B tests/compute_store_check.py draw-add-co <dxc> <offscreen_check> warp python -B tests/compute_store_check.py draw-add-co <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, `compared_words=320 mismatches=0`, `debug_errors=0` | | hardware | NVIDIA GeForce RTX 5080, 32.0.16.1692 | exit 0, `compared_words=320 mismatches=0`, `debug_errors=0` | `docs_links_check.py` (18 Markdown files, 396 links), `bidi_controls_check.py` (1428 files), and `git diff --check HEAD~1` all exited 0. The LLVM 15 round trip in Docker (`x2w-llvm15`) exited 0 (`binary_exit=0`): ```sh docker run --rm -v "C:\Proyectos\Xbox2Windows\wt-add-co:/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=$?' ``` **Negative control.** With `tools/compute_store_aot.py` from `origin/main`, `add_co_controls()` fails with `ValueError: Unsupported compute instruction: v_add_co_u32 v10, vcc_lo, -16, v3`. ## Evidence The `ADD_CO` fixture is source-built in LLVM 15 spelling for one 64-thread group (`wave_size=32`, `buffer_store_dwordx4`, 256 output words plus 64 `SENTINEL` words). It exercises `v_add_co_u32` + `v_add_co_ci_u32_e32` via `vcc_lo` (crossing `2^32` for `tid.x >= 16`) and `v_add_co_u32` + `v_add_co_ci_u32_e64` via `s4`/`s5` (crossing `2^32` for `tid.x >= 32`, with `v13` wrapping on carry-in), comparing all 320 words against an independent Python model. - **Translation controls.** Verify exact HLSL output, 32-thread group acceptance without `wave_size=32`, and refusals for >32 threads without `wave_size=32`, unknown/pending sources, invalid destinations, unverified carry-in, non-`_ci` readers of the carry SGPR (`s_add_u32`, `v_add_nc_u32_e32`, `v_cndmask_b32_e64`, `s_and_saveexec_b32`), modifiers (`clamp`, `-`, `|...|`, `mul:2`), and `_e64` on `v_add_co_u32`. - **Reference controls.** - `vcc carry dropped`: word 65; - `vcc carry inverted`: word 1; - `sgpr carry-in ignored`: word 131; - `sentinel past group`: word 256. - **Recompiled-HLSL controls.** - `vcc carry comparison flipped`; - `sgpr carry-in zeroed`. ## 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-25 02:01:52 +00:00
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!2124
No description provided.