shader: lower s_absdiff_i32 in the direct compute path #3055

Manually merged
github merged 1 commit from github-bot/gh-3055 into gh-pr/3055/base 2026-11-27 13:12:58 +00:00 AGit
Owner

@⁠pigalot on GitHub · 2026-11-27 12:28 UTC · original
pigalot:shader/direct-absdiff → main · +251 −1 · 4 files · 1 commits · merged 2026-11-27 13:06 UTC

Fixes #3054 (part of #2935, instruction coverage).

Change

The direct compute frontend (src/gfx1013_direct_compute.inl) used to refuse s_absdiff_i32 with direct DXIL lowering for s_absdiff_i32. It now lowers it as the RDNA 2 ISA states:

  • Result: D = S0 - S1 as a 32-bit difference that wraps, negated when negative. So a difference of 0x80000000 stays 0x80000000.
  • SCC: D != 0, written by the shared scalar tail like the other SOP2 integer operations.
  • Agreement with existing lowerings: the same rules as gfx2hlsl.py (asuint(abs(asint({0} - {1}))), SCC $ != 0), tools/pixel_aot.py and the HLSL path in src/gfx1013_compute_native.cpp.

The lowering is a sub, then a select between the difference and its negation, on a signed compare with 0.

Verification

main 232ae71e plus this change (127d40bb). The checks were run at 1ec2c938; the only commit in between (#3029) changes gfx2hlsl.py. Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 5090 (driver 32.0.16.1088), dev preset with the debug layer on.

ctest --preset dev --no-tests=error -R '^native_absdiff_' -V
Check Result
native_absdiff_controls pass: compiled; the unwrapped, unsigned, saturated, signed-difference and SCC-unchanged references each differ
native_absdiff_hardware pass: s_absdiff_i32: 1024 words of two groups and the guards matched
Lowering removed (main source) both fail: native compute +0x34: direct DXIL lowering for s_absdiff_i32
Lowering mutated: no absolute value readback fails: (10, '0xfffffffe', '0x2'), the (3, 5) case
Lowering mutated: SCC not written readback fails at the SCC words: (13, '0x0', '0x1'), (19, '0x1', '0x0'), …
ctest -R '^native_|compute_dispatch_native' -E '_hardware$' -j 8 0 of 48 failed; 4 of them are _warp tests that skipped
ctest -R '^native_.*_hardware$' -j 1 34 of 35 passed; native_cvt_pk_u8_hardware fails as reported in #3052, without this change too
tests/docs_links_check.py, tests/bidi_controls_check.py pass
  • Not run: this readback has not been run on WARP or on an AMD GPU.

Evidence

  • Fixture: tests/native_absdiff_check.py (tests/cmake/native_absdiff.cmake), with notes in docs/experiments/native-direct-absdiff.md. It is original and uses no external inputs.
    • The program is built with the encoding helpers of the other native fixtures (scalar, sop1, vop2, vmove). Every word was checked with tools/disasm_rdna2.py --hex.
    • Cases: two groups of 32 lanes. s24 = group * 0x01000193. Six register pairs are XORed with s24 at run time:
      • (5, 3) and (3, 5);
      • (0x80000000, 0) and (0x7fffffff, 0xffffffff), whose differences wrap to 0x80000000;
      • (0x80000000, 1), whose difference wraps to a positive value;
      • (7, 7), with SCC 1 before it.
    • Constant operands: two more cases take S1 as the literal 0xfffffff0 and as the inline constant -1.
    • Each case stores D and SCC (through s_cselect_b32).
    • The operands come from registers rather than constants, so a driver cannot fold the operation. #3052 shows one folding a constant differently on this GPU.
  • Local start-up capture: I ran compile_dxil --refusals (counts only) on 2,689 compute requests.
    • At 1ec2c938, 7 stop first at s_absdiff_i32 and 399 compile.
    • With this change, 400 compile.
    • The other 6 stop later: 3 at direct descriptor address outside bound table, 2 at direct image opcode or descriptor modifiers and 1 at unbound numeric SGPR sN.

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. Only the new experiment note; no README row covers this path.
  • I did not include game files, dumps, distribution links or secrets.

This change was AI-assisted.

**@⁠pigalot** on GitHub · 2026-11-27 12:28 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3055) `pigalot:shader/direct-absdiff` → `main` · +251 −1 · 4 files · 1 commits · merged 2026-11-27 13:06 UTC Fixes #3054 (part of #2935, instruction coverage). ## Change The direct compute frontend (`src/gfx1013_direct_compute.inl`) used to refuse `s_absdiff_i32` with `direct DXIL lowering for s_absdiff_i32`. It now lowers it as the RDNA 2 ISA states: - **Result:** D = S0 - S1 as a 32-bit difference that wraps, negated when negative. So a difference of 0x80000000 stays 0x80000000. - **SCC:** D != 0, written by the shared scalar tail like the other SOP2 integer operations. - **Agreement with existing lowerings:** the same rules as `gfx2hlsl.py` (`asuint(abs(asint({0} - {1})))`, SCC `$ != 0`), `tools/pixel_aot.py` and the HLSL path in `src/gfx1013_compute_native.cpp`. The lowering is a `sub`, then a select between the difference and its negation, on a signed compare with 0. ## Verification `main` `232ae71e` plus this change (`127d40bb`). The checks were run at `1ec2c938`; the only commit in between (#3029) changes `gfx2hlsl.py`. Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 5090 (driver 32.0.16.1088), dev preset with the debug layer on. ```powershell ctest --preset dev --no-tests=error -R '^native_absdiff_' -V ``` | Check | Result | |---|---| | `native_absdiff_controls` | pass: `compiled; the unwrapped, unsigned, saturated, signed-difference and SCC-unchanged references each differ` | | `native_absdiff_hardware` | pass: `s_absdiff_i32: 1024 words of two groups and the guards matched` | | Lowering removed (`main` source) | both fail: `native compute +0x34: direct DXIL lowering for s_absdiff_i32` | | Lowering mutated: no absolute value | readback fails: `(10, '0xfffffffe', '0x2')`, the (3, 5) case | | Lowering mutated: SCC not written | readback fails at the SCC words: `(13, '0x0', '0x1')`, `(19, '0x1', '0x0')`, … | | `ctest -R '^native_\|compute_dispatch_native' -E '_hardware$' -j 8` | 0 of 48 failed; 4 of them are `_warp` tests that skipped | | `ctest -R '^native_.*_hardware$' -j 1` | 34 of 35 passed; `native_cvt_pk_u8_hardware` fails as reported in #3052, without this change too | | `tests/docs_links_check.py`, `tests/bidi_controls_check.py` | pass | - **Not run:** this readback has not been run on WARP or on an AMD GPU. ## Evidence - **Fixture:** `tests/native_absdiff_check.py` (`tests/cmake/native_absdiff.cmake`), with notes in `docs/experiments/native-direct-absdiff.md`. It is original and uses no external inputs. - The program is built with the encoding helpers of the other native fixtures (`scalar`, `sop1`, `vop2`, `vmove`). Every word was checked with `tools/disasm_rdna2.py --hex`. - **Cases:** two groups of 32 lanes. `s24 = group * 0x01000193`. Six register pairs are XORed with `s24` at run time: - (5, 3) and (3, 5); - (0x80000000, 0) and (0x7fffffff, 0xffffffff), whose differences wrap to 0x80000000; - (0x80000000, 1), whose difference wraps to a positive value; - (7, 7), with SCC 1 before it. - **Constant operands:** two more cases take S1 as the literal 0xfffffff0 and as the inline constant -1. - Each case stores D and SCC (through `s_cselect_b32`). - The operands come from registers rather than constants, so a driver cannot fold the operation. #3052 shows one folding a constant differently on this GPU. - **Local start-up capture:** I ran `compile_dxil --refusals` (counts only) on 2,689 compute requests. - At `1ec2c938`, 7 stop first at `s_absdiff_i32` and 399 compile. - With this change, 400 compile. - The other 6 stop later: 3 at `direct descriptor address outside bound table`, 2 at `direct image opcode or descriptor modifiers` and 1 at `unbound numeric SGPR sN`. ## 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. Only the new experiment note; no README row covers this path. - [x] I did not include game files, dumps, distribution links or secrets. This change was AI-assisted.
The direct compute frontend refused s_absdiff_i32. It now lowers it as
the RDNA 2 ISA states and as gfx2hlsl.py, pixel_aot.py and the HLSL
native path already do: D = S0 - S1 wrapped to 32 bits, negated when
negative (so 0x80000000 stays), and SCC = D != 0 from the shared scalar
tail.

tests/native_absdiff_check.py compiles and reads back eight cases over
two groups: register pairs set at run time, including both wrap results
and an equal pair with SCC 1 beforehand, plus a literal and an inline
-1 operand. Its controls reject unwrapped, unsigned, saturated,
signed-difference and SCC-unchanged references.

Fixes #3054. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 12:30:48 +00:00
github-bot changed target branch from main to gh-pr/3055/base 2026-11-27 13:12:56 +00:00
github manually merged commit 127d40bb0a into gh-pr/3055/base 2026-11-27 13:12:58 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-27 13:06 UTC · original

Independent review of 127d40bb0a4753437705aec1b6559b6d96bc6593 integrated with main fca7c35b (tree 5d44259c96bcf314822e4d1fcb6ed0249785e798). The signed comparison follows the wrapped i32 subtraction, and the shared SOP2 tail still writes SCC from the nonzero result. The fixture reads SCC as well as the result and includes equal inputs after a prior SCC of 1, edge wrapping, inline and literal forms.

Built compile_dxil native_store_replay and ran ctest --test-dir <build> --no-tests=error -V -R '^native_(absdiff|perm_lerp|align_bfm)_'. Debug and Release /O2 each passed 6/6 with zero skips. The new RTX replay matched all 1,024 output words and guards; the mutant references differed as intended. Windows 11 26200.9974, RTX 4060 Laptop driver 32.0.16.1656, SDK DXC 10.0.26100; replay debug layer off. No WARP test is registered for this wave32 fixture. Hosted Windows Debug and both Linux jobs passed, and the pull-request workflow skips its hosted /O2 job.

**@⁠R0Y00** on GitHub · 2026-11-27 13:06 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3055#issuecomment-7219068279) Independent review of `127d40bb0a4753437705aec1b6559b6d96bc6593` integrated with `main` `fca7c35b` (tree `5d44259c96bcf314822e4d1fcb6ed0249785e798`). The signed comparison follows the wrapped i32 subtraction, and the shared SOP2 tail still writes SCC from the nonzero result. The fixture reads SCC as well as the result and includes equal inputs after a prior SCC of 1, edge wrapping, inline and literal forms. Built `compile_dxil native_store_replay` and ran `ctest --test-dir <build> --no-tests=error -V -R '^native_(absdiff|perm_lerp|align_bfm)_'`. Debug and Release `/O2` each passed 6/6 with zero skips. The new RTX replay matched all 1,024 output words and guards; the mutant references differed as intended. Windows 11 26200.9974, RTX 4060 Laptop driver 32.0.16.1656, SDK DXC 10.0.26100; replay debug layer off. No WARP test is registered for this wave32 fixture. Hosted Windows Debug and both Linux jobs passed, and the pull-request workflow skips its hosted `/O2` job.
This discussion has been locked. Commenting is limited to contributors.
No description provided.