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

Merged
legacy-code-archaeologist merged 1 commit from upstream-pr/2990 into cpp-migration 2026-11-27 03:47:12 +00:00
legacy-code-archaeologist commented 2026-11-27 03:29:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T03:29:07Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5520672119 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2990). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-27T03:29:07Z. --- ## 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)
MasterDomino commented 2026-11-27 03:47:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-27T03:47:09Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6083199700 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2990#pullrequestreview-6083199700). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-27T03:47:09Z. **Review:** APPROVED --- 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.
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!2990
No description provided.