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

Merged
SimSalabimse merged 5 commits from upstream-pr/2640 into main 2026-11-26 00:25:43 +00:00
SimSalabimse commented 2026-11-26 00:07:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-26T00:07:18Z.



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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6616399527 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2640). Originally posted by [SimSalabimse](https://github.com/SimSalabimse) on 2026-11-26T00:07:18Z. --- --- ## Change Part of [#1723](https://github.com/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://github.com/R0Y00/Xbox2Windows/issues/1723#issuecomment-7178303087) 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.
upstream-sync closed this pull request 2026-11-26 01:02:00 +00:00
tedin7 commented 2026-11-26 01:02:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T00:11:30Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6066790142 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2640#pullrequestreview-6066790142). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T00:11:30Z. **Review:** COMMENTED --- 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.
SimSalabimse commented 2026-11-26 01:02:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-26T00:21:51Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7178676661 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2640#issuecomment-7178676661). Originally posted by [SimSalabimse](https://github.com/SimSalabimse) on 2026-11-26T00:21:51Z. --- Addressing [review](https://github.com/R0Y00/Xbox2Windows/pull/2640#pullrequestreview-6066790142) @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://github.com/R0Y00/Xbox2Windows/pull/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.
SimSalabimse commented 2026-11-26 01:02:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-26T00:47:43Z.


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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7179120439 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2640#issuecomment-7179120439). Originally posted by [SimSalabimse](https://github.com/SimSalabimse) on 2026-11-26T00:47:43Z. --- 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).
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!2632
No description provided.