shader: lower the SAD operations in the direct C++ compute path #2990

Manually merged
github merged 1 commit from github-bot/gh-2990 into gh-pr/2990/base 2026-11-27 03:51:23 +00:00 AGit
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-27 03:29 UTC · original
legacy-code-archaeologist:shader/direct-sad → cpp-migration · +216 −0 · 4 files · 1 commits · merged 2026-11-27 03:47 UTC

Change

The direct compute frontend now lowers v_sad_u8, v_sad_hi_u8, v_sad_u16, v_sad_u32 and v_msad_u8. Before, it refused them with direct DXIL lowering for <name>. Refs #2987, part of the integer-ALU coverage in #2935, from the same VOP3 probe as #2985.

The results are those of gfx2hlsl.py's sad_u8, sad4_u8, sad_u16 and sad_u32 helpers and of tools/pixel_aot.py. Each adds S2 and wraps modulo 2^32:

Instruction Sum of unsigned absolute differences
v_sad_u8 the four bytes
v_sad_hi_u8 the four bytes, shifted left by 16
v_sad_u16 the two halfwords
v_sad_u32 the dwords
v_msad_u8 the four bytes, skipping each byte whose S1 byte is zero

Source abs/neg, clamp and output modifiers stay refused with direct ALU operand modifiers, as for the other integer VOP3 forms.

Verification

Commit 750739d2 on cpp-migration 4ff5e36d, Windows 10.0.26100.9711, dev preset. NVIDIA Quadro M1000M, driver 32.0.15.7371, debug layer unavailable.

  • ctest --preset dev --no-tests=error -R '^native_sad_|^native_direct_container$': 2 passed, 1 skipped.
    • native_sad_controls passed. It compiles the program, refuses the clamp form of v_sad_u8, and checks that four mutated references each differ from the expected words: signed differences, msad unmasked, sad_hi unshifted, and S2 dropped.
    • native_sad_hardware skipped (77). It needs shader model 6.6 with wave32. The readback is not measured here. A run on a wave32 SM 6.6 adapter would be welcome.
  • The fixture's CPU reference agrees for all 64 lanes with the existing references in tests/startup_gfx2hlsl_sad_check.py (ref_sad_u8, ref_sad_u16, ref_sad_u32) and tests/startup_gfx2hlsl_sad_hi_msad_check.py (sad4_u8). I checked this once while writing the fixture; the fixture does not import them.
  • python -B tests/docs_links_check.py: ok.

Evidence and follow-up

The words were assembled with LLVM 15.0.7 (clang -cc1as -triple amdgcn -target-cpu gfx1013 -filetype asm -show-encoding). The dispatch has two groups of 32 lanes. With n = lane + 32 * group:

  • S0 = mul_u32_u24(n, 0x050311) ^ 0x80f00a33;
  • S1 = mul_u32_u24(n, 0x010203) & 0xffff00ff, so byte 1 is always zero and byte 0 is zero for n = 0;
  • S2 = mul_u32_u24(n, 0x1001).

S0 bytes both above and below the S1 bytes occur. The 320 results and the guard words are compared with the reference. The note is docs/experiments/native-direct-sad.md.

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.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

🤖 Generated with Claude Code

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-27 03:29 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2990) `legacy-code-archaeologist:shader/direct-sad` → `cpp-migration` · +216 −0 · 4 files · 1 commits · merged 2026-11-27 03:47 UTC ## Change The direct compute frontend now lowers `v_sad_u8`, `v_sad_hi_u8`, `v_sad_u16`, `v_sad_u32` and `v_msad_u8`. Before, it refused them with `direct DXIL lowering for <name>`. Refs #2987, part of the integer-ALU coverage in #2935, from the same VOP3 probe as #2985. The results are those of `gfx2hlsl.py`'s `sad_u8`, `sad4_u8`, `sad_u16` and `sad_u32` helpers and of `tools/pixel_aot.py`. Each adds S2 and wraps modulo 2^32: | Instruction | Sum of unsigned absolute differences | |---|---| | `v_sad_u8` | the four bytes | | `v_sad_hi_u8` | the four bytes, shifted left by 16 | | `v_sad_u16` | the two halfwords | | `v_sad_u32` | the dwords | | `v_msad_u8` | the four bytes, skipping each byte whose S1 byte is zero | Source abs/neg, clamp and output modifiers stay refused with `direct ALU operand modifiers`, as for the other integer VOP3 forms. ## Verification Commit `750739d2` on `cpp-migration` `4ff5e36d`, Windows 10.0.26100.9711, `dev` preset. NVIDIA Quadro M1000M, driver 32.0.15.7371, debug layer unavailable. - `ctest --preset dev --no-tests=error -R '^native_sad_|^native_direct_container$'`: 2 passed, 1 skipped. - `native_sad_controls` passed. It compiles the program, refuses the clamp form of `v_sad_u8`, and checks that four mutated references each differ from the expected words: signed differences, msad unmasked, sad_hi unshifted, and S2 dropped. - **`native_sad_hardware` skipped (77).** It needs shader model 6.6 with wave32. **The readback is not measured here.** A run on a wave32 SM 6.6 adapter would be welcome. - The fixture's CPU reference agrees for all 64 lanes with the existing references in `tests/startup_gfx2hlsl_sad_check.py` (`ref_sad_u8`, `ref_sad_u16`, `ref_sad_u32`) and `tests/startup_gfx2hlsl_sad_hi_msad_check.py` (`sad4_u8`). I checked this once while writing the fixture; the fixture does not import them. - `python -B tests/docs_links_check.py`: ok. ## Evidence and follow-up The words were assembled with LLVM 15.0.7 (`clang -cc1as -triple amdgcn -target-cpu gfx1013 -filetype asm -show-encoding`). The dispatch has two groups of 32 lanes. With n = lane + 32 * group: - S0 = mul_u32_u24(n, 0x050311) ^ 0x80f00a33; - S1 = mul_u32_u24(n, 0x010203) & 0xffff00ff, so byte 1 is always zero and byte 0 is zero for n = 0; - S2 = mul_u32_u24(n, 0x1001). S0 bytes both above and below the S1 bytes occur. The 320 results and the guard words are compared with the reference. The note is `docs/experiments/native-direct-sad.md`. ## 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. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The direct compute frontend refused v_sad_u8, v_sad_hi_u8, v_sad_u16,
v_sad_u32 and v_msad_u8. They now sum unsigned absolute differences of
four bytes, two halfwords or one dword, add S2 and wrap modulo 2^32, as
gfx2hlsl.py's SAD helpers and tools/pixel_aot.py do. v_msad_u8 skips a
byte whose S1 byte is zero; v_sad_hi_u8 shifts the byte sum left by 16.
Source and output modifiers stay refused like the other integer VOP3
forms.

tests/native_sad_check.py dispatches per-lane operands with zero S1
bytes and S0 bytes on both sides against a CPU reference, refuses the
clamp form, and checks that signed, unmasked, unshifted and S2-dropped
references differ.

Refs #2987. AI-assisted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 03:34:03 +00:00
github-bot changed target branch from cpp-migration to gh-pr/2990/base 2026-11-27 03:51:22 +00:00
github manually merged commit 750739d238 into gh-pr/2990/base 2026-11-27 03:51:23 +00:00
Author
Owner

@⁠MasterDomino on GitHub · 2026-11-27 03:47 UTC · original · approved these changes

Review of head 750739d2. CI on the head is green. This is the wave32 SM 6.6 readback you asked for. Approving and merging.

Code read: the five forms lower as unsigned ABSDIFF over byte, halfword or dword lanes plus S2, modulo 2^32. v_sad_hi_u8 shifts the byte sum by 16, and v_msad_u8 drops each byte whose S1 byte is zero. This matches the RDNA 2 ISA definitions recorded for the pixel path in docs/experiments.md, including both halfword lanes for v_sad_u16 and the mask taken from the S1 reference. Modifiers stay refused by the shared integer VOP3 check.

Run on AMD: Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010), plus WARP, release. This was tested together with #2989, #2992 and #2994 merged onto cpp-migration 4ff5e36d; all four merge cleanly with each other. ctest --preset release --no-tests=error -R '^(native_.*|startup_compute_dispatch(_.*)?_(warp|hardware)|startup_slot67_indirect_dispatch_warp|startup_compute_translate_e2e_warp|startup_stream_draw.*|startup_native_graphics.*)$' gives 88 tests, 84 passed and 4 skipped (77: native_comparison_pso_warp, native_heap_handle_probe_warp, native_global_srv_heap_replay_warp and startup_compute_dispatch_native_warp, because WARP has no 32-lane waves).

  • native_sad_hardware passed: "five SAD operations: 320 words of two groups and the guards matched".
  • native_sad_controls passed.

Mutation here: taking the v_msad_u8 mask from S0 instead of S1 fails native_sad_hardware, for example (12, '0x1ad', '0x0'). With it restored, it passes.

As with the other ALU readbacks, this shows that the DXIL computes the documented operation on a desktop GPU, not what the console does. I will close #2987 by hand.

AI-assisted; the commands above were run locally.

**@⁠MasterDomino** on GitHub · 2026-11-27 03:47 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2990#pullrequestreview-6083199700) · **approved these changes** Review of head `750739d2`. CI on the head is green. **This is the wave32 SM 6.6 readback you asked for.** Approving and merging. **Code read:** the five forms lower as unsigned `ABSDIFF` over byte, halfword or dword lanes plus S2, modulo 2^32. `v_sad_hi_u8` shifts the byte sum by 16, and `v_msad_u8` drops each byte whose S1 byte is zero. This matches the RDNA 2 ISA definitions recorded for the pixel path in `docs/experiments.md`, including both halfword lanes for `v_sad_u16` and the mask taken from the S1 reference. Modifiers stay refused by the shared integer VOP3 check. **Run on AMD:** Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010), plus WARP, release. This was tested together with #2989, #2992 and #2994 merged onto `cpp-migration` `4ff5e36d`; all four merge cleanly with each other. `ctest --preset release --no-tests=error -R '^(native_.*|startup_compute_dispatch(_.*)?_(warp|hardware)|startup_slot67_indirect_dispatch_warp|startup_compute_translate_e2e_warp|startup_stream_draw.*|startup_native_graphics.*)$'` gives 88 tests, 84 passed and 4 skipped (77: `native_comparison_pso_warp`, `native_heap_handle_probe_warp`, `native_global_srv_heap_replay_warp` and `startup_compute_dispatch_native_warp`, because WARP has no 32-lane waves). - `native_sad_hardware` **passed**: "five SAD operations: 320 words of two groups and the guards matched". - `native_sad_controls` passed. **Mutation here:** taking the `v_msad_u8` mask from S0 instead of S1 fails `native_sad_hardware`, for example `(12, '0x1ad', '0x0')`. With it restored, it passes. As with the other ALU readbacks, this shows that the DXIL computes the documented operation on a desktop GPU, not what the console does. I will close #2987 by hand. AI-assisted; the commands above were run locally.
This discussion has been locked. Commenting is limited to contributors.
No description provided.