shader: lower s_ff0_i32_b32 in gfx2hlsl (#1723) #2666

Merged
SimSalabimse merged 4 commits from upstream-pr/2674 into main 2026-11-26 03:08:17 +00:00
SimSalabimse commented 2026-11-26 01:44:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-26T01:44:16Z.


Change

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

  • D = firstbitlow(~S0) (0xffffffff when every bit of S0 is set)
  • SCC unchanged
  • 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.

python3 -B tests/startup_gfx2hlsl_s_ff0_check.py
# all ok

python3 -B tests/startup_gfx2hlsl_handler_arity_check.py
python3 -B tests/docs_links_check.py
python3 -B tests/bidi_controls_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 (when available):

ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_ff0$' -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 ~ complement diverges from the ISA reference.

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:6617614166 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2674). Originally posted by [SimSalabimse](https://github.com/SimSalabimse) on 2026-11-26T01:44:16Z. --- ## Change Part of [#1723](https://github.com/R0Y00/Xbox2Windows/issues/1723): port `s_ff0_i32_b32` from `pixel_aot` into `tools/startup/gfx2hlsl.py`. - `D = firstbitlow(~S0)` (0xffffffff when every bit of S0 is set) - SCC unchanged - Lane masks and descriptor-bearing SGPRs refused - Known constant sources fold [Claim](https://github.com/R0Y00/Xbox2Windows/issues/1723#issuecomment-7179943649) before coding. Base is `main`. AI-assisted. ## Verification Commit under test: this PR head. ```bash python3 -B tests/startup_gfx2hlsl_s_ff0_check.py # all ok python3 -B tests/startup_gfx2hlsl_handler_arity_check.py python3 -B tests/docs_links_check.py python3 -B tests/bidi_controls_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 (when available): ```powershell ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_ff0$' -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 `~` complement diverges from the ISA reference. ## 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.
tedin7 commented 2026-11-26 03:03:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:56:37Z.

Review: COMMENTED


Review of head 5595ec77 (s_ff0_i32_b32 in gfx2hlsl, Part of #1723).

Result: no blocking findings.

What I checked

  • Semantics: D = firstbitlow(~S0), 0xffffffff when every bit is set, SCC untouched. Same shape as the merged s_ff1_i32_b32 handler (lane masks refused, constants folded, descriptor-bearing SGPRs refused). Inline float constants fall through to the register check and are refused.
  • Sibling forms: s_ff0_i32_b64 / s_ff1_i32_b64 are not lowered on main either, so nothing is left inconsistent. No other open or merged PR lowers s_ff0 (searched s_ff0; #2072 covers other 64-bit scan ops).
  • Tests/registration: new check is in CMakeLists.txt, windows.yml and AGENTS.md; the scalar-table arity check was adjusted for the new own-arity template.
  • Mutation controls (applied, then reverted): dropping the ~ makes the new check fail; removing the - 1 in the constant fold makes it fail.
  • Device readback: a one-instruction pixel program (s_ff0_i32_b32 s10, s9, converted to float and exported) built with this PR's translator, drawn on D3D12 WARP for the inputs 0xffffffff, 0xfffffffe, 0, 0x80000000, 0x7fffffff, 0x55555555, 0x12345678, 1: all 8 read back equal to the CPU reference, and a reference with one wrong word fails each time. The PR's own fixture is device-free, so this is extra evidence (the PR body says Windows draws were not run).

Commands run (Linux, worktree at the PR head)

  • python3 -B tests/startup_gfx2hlsl_s_ff0_check.py, ..._handler_arity_check.py, ..._scalar_table_arity_check.py, tests/docs_links_check.py, tests/bidi_controls_check.py: all pass
  • git diff --check origin/main...HEAD: clean

Win2025 (Build 26100, MSVC 14.44, D3D12 WARP) at 5595ec77: x2w_pipe.py win2025 2674 --wait 7200 --keep-release: PASS (debug and release builds and the Windows Python checks of the pipeline's default set). The new startup_gfx2hlsl_s_ff0 CTest itself is a Python check registered in CMake; it passes on Linux as above.

Note: the PR is 23 commits behind main and touches .github/workflows/windows.yml (one list entry); its own CI run exercises that line. I did not update the branch. Merge left to the maintainers.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6067940814 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2674#pullrequestreview-6067940814). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:56:37Z. **Review:** COMMENTED --- Review of head 5595ec77 (`s_ff0_i32_b32` in gfx2hlsl, Part of #1723). **Result: no blocking findings.** What I checked - Semantics: `D = firstbitlow(~S0)`, `0xffffffff` when every bit is set, SCC untouched. Same shape as the merged `s_ff1_i32_b32` handler (lane masks refused, constants folded, descriptor-bearing SGPRs refused). Inline float constants fall through to the register check and are refused. - Sibling forms: `s_ff0_i32_b64` / `s_ff1_i32_b64` are not lowered on main either, so nothing is left inconsistent. No other open or merged PR lowers `s_ff0` (searched `s_ff0`; #2072 covers other 64-bit scan ops). - Tests/registration: new check is in `CMakeLists.txt`, `windows.yml` and `AGENTS.md`; the scalar-table arity check was adjusted for the new own-arity template. - Mutation controls (applied, then reverted): dropping the `~` makes the new check fail; removing the `- 1` in the constant fold makes it fail. - Device readback: a one-instruction pixel program (`s_ff0_i32_b32 s10, s9`, converted to float and exported) built with this PR's translator, drawn on D3D12 WARP for the inputs `0xffffffff, 0xfffffffe, 0, 0x80000000, 0x7fffffff, 0x55555555, 0x12345678, 1`: all 8 read back equal to the CPU reference, and a reference with one wrong word fails each time. The PR's own fixture is device-free, so this is extra evidence (the PR body says Windows draws were not run). Commands run (Linux, worktree at the PR head) - `python3 -B tests/startup_gfx2hlsl_s_ff0_check.py`, `..._handler_arity_check.py`, `..._scalar_table_arity_check.py`, `tests/docs_links_check.py`, `tests/bidi_controls_check.py`: all pass - `git diff --check origin/main...HEAD`: clean Win2025 (Build 26100, MSVC 14.44, D3D12 WARP) at 5595ec77: `x2w_pipe.py win2025 2674 --wait 7200 --keep-release`: PASS (debug and release builds and the Windows Python checks of the pipeline's default set). The new `startup_gfx2hlsl_s_ff0` CTest itself is a Python check registered in CMake; it passes on Linux as above. Note: the PR is 23 commits behind main and touches `.github/workflows/windows.yml` (one list entry); its own CI run exercises that line. I did not update the branch. Merge left to the maintainers. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-26 04:04:15 +00:00
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!2666
No description provided.