shader: lower s_abs_i32 in gfx2hlsl (Part of #1723) #2640

Manually merged
github merged 5 commits from gh-pr/2640/head into gh-pr/2640/base 2026-11-27 01:10:15 +00:00
Owner

@⁠SimSalabimse on GitHub · 2026-11-26 00:07 UTC · original
SimSalabimse:cursor/gfx2hlsl-s-abs-i32-5a9e → main · +313 −0 · 6 files · 5 commits · merged 2026-11-26 00:25 UTC


Change

Part of #1723: port s_abs_i32 from pixel_aot into tools/startup/gfx2hlsl.py.

  • D = asint(S0) < 0 ? (0u - S0) : S0 (INT_MIN stays)
  • SCC = (D != 0)
  • Lane masks and descriptor-bearing SGPRs refused
  • Known constant sources fold

Claim before coding. Base is main.

AI-assisted.

Verification

Commit under test: this PR head (includes sopk_accum mutant-needle pin so the plain-scalar allow-list line is not required to be unique).

python3 -B tests/startup_gfx2hlsl_s_abs_check.py
# all ok

python3 -B tests/startup_gfx2hlsl_handler_arity_check.py
python3 -B tests/docs_links_check.py

All passed on Linux (CPU evaluation of the translated text). Windows WARP/hardware draws were not run here; the fixture is device-free.

Windows verification:

ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_abs$' -V

Evidence and follow-up

  • Hand-assembled SOP1 encodings via disasm_rdna2 / gfx2hlsl.decode; no retail bytes.
  • Negative control: mutating the emitted expression to drop the abs diverges from the ISA reference on a negative word.

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.
**@⁠SimSalabimse** on GitHub · 2026-11-26 00:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2640) `SimSalabimse:cursor/gfx2hlsl-s-abs-i32-5a9e` → `main` · +313 −0 · 6 files · 5 commits · merged 2026-11-26 00:25 UTC --- ## Change Part of [#1723](https://git.gtahub.st/github/R0Y00--Xbox2Windows/issues/1723): port `s_abs_i32` from `pixel_aot` into `tools/startup/gfx2hlsl.py`. - `D = asint(S0) < 0 ? (0u - S0) : S0` (INT_MIN stays) - `SCC = (D != 0)` - Lane masks and descriptor-bearing SGPRs refused - Known constant sources fold [Claim](https://git.gtahub.st/github/R0Y00--Xbox2Windows/issues/1723) before coding. Base is `main`. AI-assisted. ## Verification Commit under test: this PR head (includes `sopk_accum` mutant-needle pin so the plain-scalar allow-list line is not required to be unique). ```bash python3 -B tests/startup_gfx2hlsl_s_abs_check.py # all ok python3 -B tests/startup_gfx2hlsl_handler_arity_check.py python3 -B tests/docs_links_check.py ``` All passed on Linux (CPU evaluation of the translated text). Windows WARP/hardware draws were not run here; the fixture is device-free. Windows verification: ```powershell ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_abs$' -V ``` ## Evidence and follow-up - Hand-assembled SOP1 encodings via `disasm_rdna2` / `gfx2hlsl.decode`; no retail bytes. - Negative control: mutating the emitted expression to drop the abs diverges from the ISA reference on a negative word. ## 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.
Port the pixel_aot signed absolute SOP1 so ordinary pipelines that only need
|S0| stop refusing. SCC is the nonzero test of the result; INT_MIN stays.
Lane masks and descriptor words are refused. CPU fixture with a negative control.

Co-authored-by: SimSalabimse <[email protected]>
s_bitset0/1_b32 reused the plain-scalar sym allow-list line, so the
sopk_accum mutant needle was no longer unique. Match the sopk raise that
formats with `base` instead.

Co-authored-by: SimSalabimse <[email protected]>
Mirror the #2639 / pack_absdiff UAV dump pattern. Cover INT_MIN, -1, 0,
a positive word, SCC, and an SCC-dependent branch on the adapter.

Co-authored-by: SimSalabimse <[email protected]>
Wire startup_gfx2hlsl_s_abs_dispatch_{warp,hardware} to the new
UAV-readback mode so Windows CI and Sander can run the fixture.

Co-authored-by: SimSalabimse <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:10:14 +00:00
github manually merged commit a0b791b2f6 into gh-pr/2640/base 2026-11-27 01:10:15 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 00:11 UTC · original · reviewed

Review of head 48236d4d against current main (comment only).

Checked:

  • op_s_abs_i32 (tools/startup/gfx2hlsl.py:5507): D = asint(S0) < 0 ? 0u - S0 : S0, SCC = D != 0, INT_MIN stays, constant folding wraps to 32 bits, lane masks and descriptor-bearing SGPRs refused. The semantics match the RDNA 2 SOP1 definition and the existing pixel_aot lowering. I found no logic bug.
  • No other open PR covers this slice. Earlier merged work lowered s_abs_i32 in other paths (#574 pixel_aot, #1956 compute); this one adds the gfx2hlsl path. The sibling s_absdiff_i32 table entry is untouched and is a different opcode.
  • Wiring is complete: CMake test entry, windows.yml Python check list, AGENTS.md, docs/experiments.md, and the sopk_accum needle pin.

Commands run (Linux, clean worktree on the head):

  • python3 -B tests/startup_gfx2hlsl_s_abs_check.py -> all ok
  • python3 -B tests/startup_gfx2hlsl_sopk_accum_check.py -> PASS
  • python3 tests/docs_links_check.py -> 19 files, 507 links ok
  • python3 tests/bidi_controls_check.py -> no bidirectional controls
  • git diff --check origin/main...HEAD -> clean
  • Mutation: replaced the abs expression with a plain pass-through -> the new test fails ("mutation that drops abs diverges" / SGPR source case). Reverted.

What is missing before this can merge:

  1. The new test only evaluates the translated HLSL text on the CPU. For shader/math lowerings we need a real D3D12 WARP GPU-readback vs CPU-reference test (at least INT_MIN, -1, 0, a positive value, and an SCC-dependent branch), extending the existing WARP test suite next to the other scalar lowerings. A text-only check cannot show that asint/0u - x compile and behave on the device.
  2. No Windows result on this head (win2025=None); the PR body says WARP was not run. A Windows dev + release run is needed once item 1 exists.

I am not merging this. Once the WARP readback test is added and Windows passes, it looks ready.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-26 00:11 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2640#pullrequestreview-6066790142) · **reviewed** Review of head 48236d4d against current main (comment only). Checked: - `op_s_abs_i32` (tools/startup/gfx2hlsl.py:5507): `D = asint(S0) < 0 ? 0u - S0 : S0`, `SCC = D != 0`, INT_MIN stays, constant folding wraps to 32 bits, lane masks and descriptor-bearing SGPRs refused. The semantics match the RDNA 2 SOP1 definition and the existing pixel_aot lowering. I found no logic bug. - No other open PR covers this slice. Earlier merged work lowered `s_abs_i32` in other paths (#574 pixel_aot, #1956 compute); this one adds the gfx2hlsl path. The sibling `s_absdiff_i32` table entry is untouched and is a different opcode. - Wiring is complete: CMake test entry, `windows.yml` Python check list, AGENTS.md, docs/experiments.md, and the `sopk_accum` needle pin. Commands run (Linux, clean worktree on the head): - `python3 -B tests/startup_gfx2hlsl_s_abs_check.py` -> all ok - `python3 -B tests/startup_gfx2hlsl_sopk_accum_check.py` -> PASS - `python3 tests/docs_links_check.py` -> 19 files, 507 links ok - `python3 tests/bidi_controls_check.py` -> no bidirectional controls - `git diff --check origin/main...HEAD` -> clean - Mutation: replaced the abs expression with a plain pass-through -> the new test fails ("mutation that drops abs diverges" / SGPR source case). Reverted. What is missing before this can merge: 1. The new test only evaluates the translated HLSL text on the CPU. For shader/math lowerings we need a real D3D12 WARP GPU-readback vs CPU-reference test (at least INT_MIN, -1, 0, a positive value, and an SCC-dependent branch), extending the existing WARP test suite next to the other scalar lowerings. A text-only check cannot show that `asint`/`0u - x` compile and behave on the device. 2. No Windows result on this head (`win2025=None`); the PR body says WARP was not run. A Windows dev + release run is needed once item 1 exists. I am not merging this. Once the WARP readback test is added and Windows passes, it looks ready. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠SimSalabimse on GitHub · 2026-11-26 00:21 UTC · original · edited 2026-11-26 01:33 UTC

Addressing review @⁠tedin7 — added the D3D12 WARP GPU readback.

What landed (6afdbd92 + CMake follow-up on cursor/gfx2hlsl-s-abs-i32-5a9e)

  • tests/startup_gfx2hlsl_s_abs_check.py now has a dispatch mode mirroring #2639 / pack_absdiff (offscreen_check --raw-uav-dump).
  • Cases: INT_MIN (0x80000000), -1, 0, positive 0x12345678.
  • Each case stores D, SCC as uint, and an SCC-dependent if (scc) branch token so the nonzero test is exercised on the device, not only as a stored bool.
  • CMake: startup_gfx2hlsl_s_abs_dispatch_{warp,hardware}.

Linux CPU path re-run green. WARP dispatch was not run here.

Windows verification:

ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_abs$' -V
ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_abs_dispatch_warp$' -V

AI-assisted.

**@⁠SimSalabimse** on GitHub · 2026-11-26 00:21 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2640#issuecomment-7178676661) · edited 2026-11-26 01:33 UTC Addressing [review](https://git.gtahub.st/github/R0Y00--Xbox2Windows/pulls/2640) @⁠tedin7 — added the D3D12 WARP GPU readback. **What landed** (`6afdbd92` + CMake follow-up on `cursor/gfx2hlsl-s-abs-i32-5a9e`) - `tests/startup_gfx2hlsl_s_abs_check.py` now has a `dispatch` mode mirroring [#2639](https://git.gtahub.st/github/R0Y00--Xbox2Windows/pulls/2639) / `pack_absdiff` (`offscreen_check --raw-uav-dump`). - Cases: **INT_MIN** (`0x80000000`), **-1**, **0**, positive `0x12345678`. - Each case stores `D`, `SCC` as `uint`, and an **SCC-dependent `if (scc)` branch token** so the nonzero test is exercised on the device, not only as a stored bool. - CMake: `startup_gfx2hlsl_s_abs_dispatch_{warp,hardware}`. Linux CPU path re-run green. WARP dispatch was not run here. Windows verification: ```powershell ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_abs$' -V ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_abs_dispatch_warp$' -V ``` AI-assisted.
Author
Owner

@⁠SimSalabimse on GitHub · 2026-11-26 00:47 UTC · original

Host Windows retest on this PR head:

ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_abs' -V

Passed: startup_gfx2hlsl_s_abs, startup_gfx2hlsl_s_abs_dispatch_warp, startup_gfx2hlsl_s_abs_dispatch_hardware (3/3).

**@⁠SimSalabimse** on GitHub · 2026-11-26 00:47 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2640#issuecomment-7179120439) Host Windows retest on this PR head: ``` ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_abs' -V ``` Passed: `startup_gfx2hlsl_s_abs`, `startup_gfx2hlsl_s_abs_dispatch_warp`, `startup_gfx2hlsl_s_abs_dispatch_hardware` (3/3).
This discussion has been locked. Commenting is limited to contributors.
No description provided.