shader: lower compute v_dot2_u32_u16 and v_dot4_u32_u8 #2138

Merged
henriazz10 merged 2 commits from upstream-pr/2146 into main 2026-11-25 01:58:18 +00:00
henriazz10 commented 2026-11-25 01:39:39 +00:00 (Migrated from github.com)

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


Change

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

  • v_dot2_u32_u16 (VOP3P 0x15) and v_dot4_u32_u8 (VOP3P 0x17) compute unsigned packed 16-bit (2-element) and 8-bit (4-element) dot products accumulated into a 32-bit unsigned integer, wrapping modulo 2^32.
    • They lower to dot2_u32_u16 and dot4_u32_u8 in HLSL uint arithmetic without 64-bit emulation.
  • Refused, each with its own control:
    • clamp (v_dot2_u32_u16 ... clamp, v_dot4_u32_u8 ... clamp);
    • op_sel / op_sel_hi and neg_lo / neg_hi;
    • source modifiers (-v4, |v4|), omod (mul:2), and other spellings (v_dot2_i32_i16);
    • unknown or pending sources (v40, s12) and vD above v255 (v256).

Verification

Commit 6f784a50, rebased onto 8e8b0621. The draws, controls() and the LLVM 15 round trip were re-run on 6f784a50. Windows 11 build 26300, VS 2019 Build Tools 16.11 (MSVC 14.29), DXC 1.8.2502.11, Python 3.12, 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-dot-u <dxc> <offscreen_check> warp
python -B tests/compute_store_check.py draw-dot-u <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 (18 Markdown files, 398 links), bidi_controls_check.py (1437 tracked 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-dot-u:/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=$?'

dot_u_binary() assembles DOT_U on gfx1030 (since LLVM's gfx1013 subtarget omits v_dot4_u32_u8), decodes it back to the same v_dot* lines, and requires the same translation.

Negative control. With tools/compute_store_aot.py from origin/main, dot_u_controls() fails with ValueError: Unsupported compute instruction: v_dot2_u32_u16 v10, 0xffff0002, 0xffff0003, v4.

Evidence

The DOT_U fixture is source-built in LLVM 15 spelling (gfx1030). It runs one group of 64 threads (buffer_store_dwordx4, 256 output words plus 64 SENTINEL words), covering MSB=1 unsigned lanes (0xffff, 0x8001, 0xff, 0x80, 0xfe), SGPR and inline/literal operands, and 32-bit wrap-around on tid.x >= 25, comparing all 320 words against an independent Python model.

  • Translation controls. Verify the exact outputData.Store4(...) line, per-helper emission, unknown/pending sources, v256, clamp, op_sel, neg_lo, source modifiers, omod, and v_dot2_i32_i16.
  • Reference controls. Each fails at its first differing word:
    • dot2 treated as signed i16: word 0;
    • dot4 treated as signed i8: word 2;
    • dot2 saturated instead of wrapped: word 100;
    • sentinel past group: word 256.
  • Recompiled-HLSL controls. Each fails on the device with Compute readback differs:
    • dot2_u32_u16 drops + (a >> 16) * (b >> 16);
    • dot4_u32_u8 drops + (a >> 24) * (b >> 24).

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:6595152615 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2146). Originally posted by [henriazz10](https://github.com/henriazz10) on 2026-11-25T01:39:39Z. --- ## Change Refs #721. This is the `v_dot2_u32_u16` and `v_dot4_u32_u8` slice claimed in https://github.com/R0Y00/Xbox2Windows/issues/721#issuecomment-7144791814. It touches only `tools/compute_store_aot.py`, `tests/compute_store_check.py`, `CMakeLists.txt` and `docs/experiments.md`. - `v_dot2_u32_u16` (`VOP3P 0x15`) and `v_dot4_u32_u8` (`VOP3P 0x17`) compute unsigned packed 16-bit (2-element) and 8-bit (4-element) dot products accumulated into a 32-bit unsigned integer, wrapping modulo `2^32`. - They lower to `dot2_u32_u16` and `dot4_u32_u8` in HLSL `uint` arithmetic without 64-bit emulation. - Refused, each with its own control: - `clamp` (`v_dot2_u32_u16 ... clamp`, `v_dot4_u32_u8 ... clamp`); - `op_sel` / `op_sel_hi` and `neg_lo` / `neg_hi`; - source modifiers (`-v4`, `|v4|`), `omod` (`mul:2`), and other spellings (`v_dot2_i32_i16`); - unknown or pending sources (`v40`, `s12`) and `vD` above `v255` (`v256`). ## Verification Commit `6f784a50`, rebased onto `8e8b0621`. The draws, `controls()` and the LLVM 15 round trip were re-run on `6f784a50`. Windows 11 build 26300, VS 2019 Build Tools 16.11 (MSVC 14.29), DXC 1.8.2502.11, Python 3.12, 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-dot-u <dxc> <offscreen_check> warp python -B tests/compute_store_check.py draw-dot-u <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` (18 Markdown files, 398 links), `bidi_controls_check.py` (1437 tracked 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-dot-u:/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=$?' ``` `dot_u_binary()` assembles `DOT_U` on `gfx1030` (since LLVM's `gfx1013` subtarget omits `v_dot4_u32_u8`), decodes it back to the same `v_dot*` lines, and requires the same translation. **Negative control.** With `tools/compute_store_aot.py` from `origin/main`, `dot_u_controls()` fails with `ValueError: Unsupported compute instruction: v_dot2_u32_u16 v10, 0xffff0002, 0xffff0003, v4`. ## Evidence The `DOT_U` fixture is source-built in LLVM 15 spelling (`gfx1030`). It runs one group of 64 threads (`buffer_store_dwordx4`, 256 output words plus 64 `SENTINEL` words), covering MSB=1 unsigned lanes (`0xffff`, `0x8001`, `0xff`, `0x80`, `0xfe`), SGPR and inline/literal operands, and 32-bit wrap-around on `tid.x >= 25`, comparing all 320 words against an independent Python model. - **Translation controls.** Verify the exact `outputData.Store4(...)` line, per-helper emission, unknown/pending sources, `v256`, `clamp`, `op_sel`, `neg_lo`, source modifiers, `omod`, and `v_dot2_i32_i16`. - **Reference controls.** Each fails at its first differing word: - `dot2` treated as signed `i16`: word 0; - `dot4` treated as signed `i8`: word 2; - `dot2` saturated instead of wrapped: word 100; - sentinel past group: word 256. - **Recompiled-HLSL controls.** Each fails on the device with `Compute readback differs`: - `dot2_u32_u16` drops `+ (a >> 16) * (b >> 16)`; - `dot4_u32_u8` drops `+ (a >> 24) * (b >> 24)`. ## 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:57 +00:00
tedin7 commented 2026-11-25 02:01:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:50:51Z.

Review: COMMENTED


Review of head 6f784a50b4 (comment only).

Result: not mergeable as is. The PR is CONFLICTING with main (CMakeLists.txt and tests/compute_store_check.py). Please rebase, then re-run the checks below.

Logic (read-only review):

  • v_dot2_u32_u16 and v_dot4_u32_u8 lower to uint HLSL helpers. The non-clamp forms wrap mod 2^32, so 32-bit uint arithmetic is exact. The >> 16 and >> 24 terms need no mask on uint.
  • The regex has one capture group per ALU_SOURCE, so m.groups()[2:] is exactly the three sources.
  • Refusals (clamp, op_sel, neg, omod, vD > 255, unverified sources) fall through to the existing rejection path.
  • Helpers are emitted only when used, next to the existing F32/CVT helpers.
  • No P1 or P2 found in the logic.

Commands executed locally in a review worktree:

  • python3 tests/docs_links_check.py : PASS (18 files, 398 links)
  • python3 tests/bidi_controls_check.py : PASS
  • git diff --check origin/main...HEAD : clean
  • git merge-tree HEAD origin/main : conflicts in CMakeLists.txt and tests/compute_store_check.py

Not run: the new compute_store test (needs dxc and the D3D12 WARP runner, so Windows only) and the logic mutation check. They are deferred until the rebase.

GitHub: Build and test on Windows = pass; Python checks on Linux = pass; fixtures = pass.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050401527 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2146#pullrequestreview-6050401527). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:50:51Z. **Review:** COMMENTED --- Review of head 6f784a50b4d00318fa9b1511fe08c17283b1f21d (comment only). Result: not mergeable as is. The PR is CONFLICTING with main (CMakeLists.txt and tests/compute_store_check.py). Please rebase, then re-run the checks below. Logic (read-only review): - v_dot2_u32_u16 and v_dot4_u32_u8 lower to uint HLSL helpers. The non-clamp forms wrap mod 2^32, so 32-bit uint arithmetic is exact. The `>> 16` and `>> 24` terms need no mask on uint. - The regex has one capture group per ALU_SOURCE, so `m.groups()[2:]` is exactly the three sources. - Refusals (clamp, op_sel, neg, omod, vD > 255, unverified sources) fall through to the existing rejection path. - Helpers are emitted only when used, next to the existing F32/CVT helpers. - No P1 or P2 found in the logic. Commands executed locally in a review worktree: - python3 tests/docs_links_check.py : PASS (18 files, 398 links) - python3 tests/bidi_controls_check.py : PASS - git diff --check origin/main...HEAD : clean - git merge-tree HEAD origin/main : conflicts in CMakeLists.txt and tests/compute_store_check.py Not run: the new compute_store test (needs dxc and the D3D12 WARP runner, so Windows only) and the logic mutation check. They are deferred until the rebase. GitHub: Build and test on Windows = pass; Python checks on Linux = pass; fixtures = pass. AI-assisted; commands listed were executed locally.
R0Y00 commented 2026-11-25 02:02:09 +00:00 (Migrated from github.com)

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


I resolved the test overlap with the merged add and subtract slices. On Windows WARP and RTX 4060 Laptop, all three compute cases independently compared 320 words with zero mismatches and zero debug messages. Their negative controls and the documentation link check also passed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7150110788 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2146#issuecomment-7150110788). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T01:55:08Z. --- I resolved the test overlap with the merged add and subtract slices. On Windows WARP and RTX 4060 Laptop, all three compute cases independently compared 320 words with zero mismatches and zero debug messages. Their negative controls and the documentation link check also passed.
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!2138
No description provided.