shader: lower compute v_sub_co_u32 / v_subrev_co_u32 and their carry-in forms #2126

Merged
henriazz10 merged 2 commits from upstream-pr/2134 into main 2026-11-25 01:47:57 +00:00
henriazz10 commented 2026-11-25 01:23:04 +00:00 (Migrated from github.com)

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


Change

Refs #721. Lower v_sub_co_u32, v_subrev_co_u32 (VOP3), v_sub_co_ci_u32 (_e32 and _e64), and v_subrev_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_sub_co_u32 vD, sDst, S0, S1 computes (S0 - S1) mod 2^32 into vD and tracks the per-lane borrow-out (S0 < S1 ? 1u : 0u) in sDst (vcc_lo or s0..s105); v_subrev_co_u32 swaps S0 and S1.
  • v_sub_co_ci_u32 and v_subrev_co_ci_u32 (_e32/_e64) subtract the tracked per-lane borrow-in c and write the new borrow-out ((a < b || (a - b) < c) ? 1u : 0u).
  • The borrow SGPR is tracked as a vector-like ("borrow", 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.

Verification

Commit baa0302f, on 71ae5584. The maintainer then integrated it with the merged carry-out add (#2132) in 36b814b7, which shares one VCC state between carry and borrow. The results below are for baa0302f. The draws, controls() and the LLVM 15 round trip were re-run on baa0302f. Windows 11 build 26300, DXC 10.0.26100.0, Python 3.12, debug layer enabled.

python -B tests/compute_store_check.py draw-sub-co <dxc> <offscreen_check> warp
python -B tests/compute_store_check.py draw-sub-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 (1429 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-sub-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, sub_co_controls() fails with ValueError: Unsupported compute instruction: v_sub_co_u32 v10, vcc_lo, 16, v3.

Evidence

The SUB_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_sub_co_u32 + v_sub_co_ci_u32_e32 via vcc_lo (borrowing for tid.x > 16) and v_subrev_co_u32 + v_subrev_co_ci_u32_e64 via s4/s5 (borrowing for tid.x < 32), comparing all 320 words against an independent Python model.

  • Translation controls. Verify exact HLSL output (including v_sub_co_ci_u32_e64 and v_subrev_co_ci_u32_e32), 32-thread group acceptance without wave_size=32, and refusals for >32 threads without wave_size=32, unknown/pending sources, invalid destinations, unverified borrow-in, non-_ci readers of the borrow 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_sub_co_u32.
  • Reference controls.
    • vcc borrow dropped: word 69;
    • subrev operand order swapped: word 2;
    • sgpr borrow-in ignored: word 3;
    • sentinel past group: word 256.
  • Recompiled-HLSL controls.
    • vcc borrow comparison flipped;
    • sgpr borrow-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:6594943545 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2134). Originally posted by [henriazz10](https://github.com/henriazz10) on 2026-11-25T01:23:04Z. --- ## Change Refs #721. Lower `v_sub_co_u32`, `v_subrev_co_u32` (VOP3), `v_sub_co_ci_u32` (`_e32` and `_e64`), and `v_subrev_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_sub_co_u32 vD, sDst, S0, S1` computes `(S0 - S1) mod 2^32` into `vD` and tracks the per-lane borrow-out `(S0 < S1 ? 1u : 0u)` in `sDst` (`vcc_lo` or `s0..s105`); `v_subrev_co_u32` swaps `S0` and `S1`. - `v_sub_co_ci_u32` and `v_subrev_co_ci_u32` (`_e32`/`_e64`) subtract the tracked per-lane borrow-in `c` and write the new borrow-out `((a < b || (a - b) < c) ? 1u : 0u)`. - The borrow SGPR is tracked as a vector-like `("borrow", 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`. ## Verification Commit `baa0302f`, on `71ae5584`. The maintainer then integrated it with the merged carry-out add (#2132) in `36b814b7`, which shares one VCC state between carry and borrow. The results below are for `baa0302f`. The draws, `controls()` and the LLVM 15 round trip were re-run on `baa0302f`. Windows 11 build 26300, DXC 10.0.26100.0, Python 3.12, debug layer enabled. ```powershell python -B tests/compute_store_check.py draw-sub-co <dxc> <offscreen_check> warp python -B tests/compute_store_check.py draw-sub-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` (1429 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-sub-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`, `sub_co_controls()` fails with `ValueError: Unsupported compute instruction: v_sub_co_u32 v10, vcc_lo, 16, v3`. ## Evidence The `SUB_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_sub_co_u32` + `v_sub_co_ci_u32_e32` via `vcc_lo` (borrowing for `tid.x > 16`) and `v_subrev_co_u32` + `v_subrev_co_ci_u32_e64` via `s4`/`s5` (borrowing for `tid.x < 32`), comparing all 320 words against an independent Python model. - **Translation controls.** Verify exact HLSL output (including `v_sub_co_ci_u32_e64` and `v_subrev_co_ci_u32_e32`), 32-thread group acceptance without `wave_size=32`, and refusals for >32 threads without `wave_size=32`, unknown/pending sources, invalid destinations, unverified borrow-in, non-`_ci` readers of the borrow 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_sub_co_u32`. - **Reference controls.** - `vcc borrow dropped`: word 69; - `subrev operand order swapped`: word 2; - `sgpr borrow-in ignored`: word 3; - `sentinel past group`: word 256. - **Recompiled-HLSL controls.** - `vcc borrow comparison flipped`; - `sgpr borrow-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:53 +00:00
R0Y00 commented 2026-11-25 02:02:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T01:42:13Z.


I resolved the conflict with the merged add-with-carry fixture and kept both registrations. The two paths now overwrite the same tracked VCC value. Two controls reject using a stale carry after a borrow write and a stale borrow after a carry write. Windows WARP and RTX 4060 Laptop passed both draw cases, 320 words per case with zero mismatches or debug-layer messages.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7149857506 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2134#issuecomment-7149857506). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T01:42:13Z. --- I resolved the conflict with the merged add-with-carry fixture and kept both registrations. The two paths now overwrite the same tracked VCC value. Two controls reject using a stale carry after a borrow write and a stale borrow after a carry write. Windows WARP and RTX 4060 Laptop passed both draw cases, 320 words per case with zero mismatches or debug-layer messages.
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!2126
No description provided.