shader: lower the SDWA form of v_cndmask_b32 in gfx2hlsl #2391

Manually merged
github merged 3 commits from gh-pr/2391/head into gh-pr/2391/base 2026-11-27 00:47:48 +00:00
Owner

@⁠pigalot on GitHub · 2026-11-25 15:01 UTC · original
pigalot:shader/sdwa-cndmask → main · +345 −2 · 8 files · 3 commits · merged 2026-11-26 02:16 UTC

Change

tools/startup/gfx2hlsl.py refused the SDWA form of the VOP2 select with SDWA form of v_cndmask_b32. sdwa() now lowers it as a two-source integer operation: each source takes its src0_sel/src1_sel field (zero-extended, or sign-extended under sext()), the select reads VCC, its fourth operand, the same way the plain v_cndmask_b32 does, and dst_sel/dst_unused place the result by the rules the other integer SDWA forms use. clamp, float modifiers and UNUSED_SEXT stay refused. This is an independent problem, not tracked by an issue; no shared interface changes.

Verification

On 0736f67c + this commit, Windows 11 (build 26200.9974), D3D12 debug layer enabled (debug_errors=0 debug_warnings=0):

Command Result
ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_sdwa_cndmask(_warp|_hardware)?$' -V 3 passed. WARP (1414:008c, driver 10.0.26100.9818) and NVIDIA GeForce RTX 5090 (10de:2b85, driver 32.0.16.1088): 26 draws each, FXC ps_5_1 and DXC ps_6_0
python -B tests/startup_gfx2hlsl_sdwa_cndmask_check.py binary <llvm-mc> passed with LLVM 15.0.7: the fixture assembles to the same words and each select prints as written
ctest --preset dev --no-tests=error -j 8 -R 'gfx2hlsl|pixel_aot_check|rdna2_tools|compute|translator|startup_run|triage|scan_unsupported|docs|bidi|form_coverage|pso_readiness|shader_corpus' -E '_hardware$|_warp$|startup_audio_' 93 passed, 1 skipped (startup_run_sh, a shell script)
ctest --preset dev --no-tests=error -j 1 -R 'sdwa.*(_warp|_hardware)$' 16 passed
git diff --check clean

Negative control: with tools/startup/gfx2hlsl.py from main, startup_gfx2hlsl_sdwa_cndmask_check.py fails (the fixture translates, refused as SDWA form of v_cndmask_b32).

Evidence and follow-up

The fixture is a constructed gfx1013 pixel stage written for this test (MIT, no external input). VCC is bit 31 of a per-pixel product clear (set in 160 of 256 pixels). Four selects cover byte and word sources from two registers, a sign-extended BYTE_2 widened into WORD_0, and WORD_0, BYTE_1 and BYTE_2 destinations under UNUSED_PRESERVE over 1.0, which keeps every exported word a normal binary32 value (asserted, since the readback target is R32G32B32A32_FLOAT). All 1,024 exported words match a bit model. Six mutated selects (swapped operands, the mask ignored, the mask inverted, a dropped sext(), the neighbouring source byte, the wrong destination byte) each fail against the model and match their own model.

Not covered by the draw: UNUSED_PAD and DWORD destinations, whose results would be denormal or NaN words on a float target; startup_gfx2hlsl_sdwa_check.py pins their emitted text. The semantics are the integer SDWA rules already used for the other forms with the select as the operation; they are not checked against the ISA document here and not measured on a console.

Reading the mask through self.u() instead of the literal vcc keeps it the same as the plain select; I found no input where the two differ today.

Docs: docs/experiments.md (new entry after the SDWA conversions) and docs/startup-runtime.md (SDWA bullet). CI: the controls run in the Linux Python checks, and the binary mode runs with llvm-mc-15.

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.

This change was AI-assisted: written with Claude Code, and the checks above were run locally.

**@⁠pigalot** on GitHub · 2026-11-25 15:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2391) `pigalot:shader/sdwa-cndmask` → `main` · +345 −2 · 8 files · 3 commits · merged 2026-11-26 02:16 UTC ## Change `tools/startup/gfx2hlsl.py` refused the SDWA form of the VOP2 select with `SDWA form of v_cndmask_b32`. `sdwa()` now lowers it as a two-source integer operation: each source takes its `src0_sel`/`src1_sel` field (zero-extended, or sign-extended under `sext()`), the select reads VCC, its fourth operand, the same way the plain `v_cndmask_b32` does, and `dst_sel`/`dst_unused` place the result by the rules the other integer SDWA forms use. ` clamp`, float modifiers and `UNUSED_SEXT` stay refused. This is an independent problem, not tracked by an issue; no shared interface changes. ## Verification On `0736f67c` + this commit, Windows 11 (build 26200.9974), D3D12 debug layer enabled (`debug_errors=0 debug_warnings=0`): | Command | Result | |---|---| | `ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_sdwa_cndmask(_warp\|_hardware)?$' -V` | 3 passed. WARP (`1414:008c`, driver 10.0.26100.9818) and NVIDIA GeForce RTX 5090 (`10de:2b85`, driver 32.0.16.1088): 26 draws each, FXC `ps_5_1` and DXC `ps_6_0` | | `python -B tests/startup_gfx2hlsl_sdwa_cndmask_check.py binary <llvm-mc>` | passed with LLVM 15.0.7: the fixture assembles to the same words and each select prints as written | | `ctest --preset dev --no-tests=error -j 8 -R 'gfx2hlsl\|pixel_aot_check\|rdna2_tools\|compute\|translator\|startup_run\|triage\|scan_unsupported\|docs\|bidi\|form_coverage\|pso_readiness\|shader_corpus' -E '_hardware$\|_warp$\|startup_audio_'` | 93 passed, 1 skipped (`startup_run_sh`, a shell script) | | `ctest --preset dev --no-tests=error -j 1 -R 'sdwa.*(_warp\|_hardware)$'` | 16 passed | | `git diff --check` | clean | Negative control: with `tools/startup/gfx2hlsl.py` from main, `startup_gfx2hlsl_sdwa_cndmask_check.py` fails (`the fixture translates`, refused as `SDWA form of v_cndmask_b32`). ## Evidence and follow-up The fixture is a constructed gfx1013 pixel stage written for this test (MIT, no external input). VCC is bit 31 of a per-pixel product clear (set in 160 of 256 pixels). Four selects cover byte and word sources from two registers, a sign-extended `BYTE_2` widened into `WORD_0`, and `WORD_0`, `BYTE_1` and `BYTE_2` destinations under `UNUSED_PRESERVE` over 1.0, which keeps every exported word a normal binary32 value (asserted, since the readback target is `R32G32B32A32_FLOAT`). All 1,024 exported words match a bit model. Six mutated selects (swapped operands, the mask ignored, the mask inverted, a dropped `sext()`, the neighbouring source byte, the wrong destination byte) each fail against the model and match their own model. Not covered by the draw: `UNUSED_PAD` and `DWORD` destinations, whose results would be denormal or NaN words on a float target; `startup_gfx2hlsl_sdwa_check.py` pins their emitted text. The semantics are the integer SDWA rules already used for the other forms with the select as the operation; they are not checked against the ISA document here and not measured on a console. Reading the mask through `self.u()` instead of the literal `vcc` keeps it the same as the plain select; I found no input where the two differ today. Docs: `docs/experiments.md` (new entry after the SDWA conversions) and `docs/startup-runtime.md` (SDWA bullet). CI: the controls run in the Linux Python checks, and the binary mode runs with `llvm-mc-15`. ## 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. This change was AI-assisted: written with Claude Code, and the checks above were run locally.
The VOP2 select in SDWA form was refused as "SDWA form of v_cndmask_b32".
sdwa() now lowers it as a two-source integer operation: each source takes
its src0_sel/src1_sel field (sext() sign-extends), the select reads VCC,
its fourth operand, the way the plain v_cndmask_b32 does, and
dst_sel/dst_unused place the result. clamp, float modifiers and
UNUSED_SEXT stay refused.

Test: startup_gfx2hlsl_sdwa_check.py pins the emitted text.
startup_gfx2hlsl_sdwa_cndmask_check.py draws a constructed gfx1013 pixel
stage with four selects over 16 x 16 pixels on WARP and hardware (FXC
ps_5_1 and DXC ps_6_0): all 1,024 words match a bit model, and six
mutated selects fail against it and match their own. Its binary mode
requires LLVM 15 to assemble the fixture to the same words. With the
previous translator the fixture is refused.
Review follow-up. run_pixel_words exited 77 on a renderer skip even after
an earlier check had failed, so ctest reported a skip instead of the
failure. It now exits 1 when a check has failed, as #2380 did for the
sibling draw fixtures.

Test: with a check failed and the renderer returning 77, the old code
exits 77 and the new code exits 1; without a failure both exit 77.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:47:46 +00:00
github manually merged commit 91a1d93f21 into gh-pr/2391/base 2026-11-27 00:47:48 +00:00
Author
Owner

@⁠RavenCurseBurg on GitHub · 2026-11-25 15:07 UTC · original

I tested the two destination cases called out in the description using the existing float renderer. The synthetic gfx1013 pixel shader splits each 32-bit select result into two 16-bit halves and exports each half in the mantissa of 1.0. This preserves every result bit while keeping the four output channels finite. The two selects exercise BYTE_1 with UNUSED_PAD over deadbeef, and a full DWORD destination with both VCC outcomes.

At b99d95f1, FXC and DXC each matched all 1,024 expected words on WARP, Intel UHD 770 and RTX 4060. Two separately assembled controls also matched their own references: changing PAD to PRESERVE changed 512 exported words, and changing DWORD to WORD_0 changed 254. Both failed against the original reference on all six compiler/adapter pairs. The programs were assembled by LLVM 15.0.7; the local D3D12 debug layer was unavailable. Reproducible source and readback script.

I’ll carry the destination-mode coverage as a follow-up once the lowering lands. One small change applies directly to this PR: run_pixel_words still exits 77 after a prior failed comparison. Calling check(..., False) and then injecting a renderer return of 77 reproduces it. #2380 just fixed the sibling fixtures with sys.exit(1 if failures else 77).

**@⁠RavenCurseBurg** on GitHub · 2026-11-25 15:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2391#issuecomment-7166345169) I tested the two destination cases called out in the description using the existing float renderer. The synthetic gfx1013 pixel shader splits each 32-bit select result into two 16-bit halves and exports each half in the mantissa of 1.0. This preserves every result bit while keeping the four output channels finite. The two selects exercise BYTE_1 with UNUSED_PAD over `deadbeef`, and a full DWORD destination with both VCC outcomes. At `b99d95f1`, FXC and DXC each matched all 1,024 expected words on WARP, Intel UHD 770 and RTX 4060. Two separately assembled controls also matched their own references: changing PAD to PRESERVE changed 512 exported words, and changing DWORD to WORD_0 changed 254. Both failed against the original reference on all six compiler/adapter pairs. The programs were assembled by LLVM 15.0.7; the local D3D12 debug layer was unavailable. [Reproducible source and readback script](https://github.com/RavenCurseBurg/Xbox2Windows/blob/b6d0bd19ebc2db451cd8735245e0d1e33c96a806/tests/measure_cndmask_dest.py). I’ll carry the destination-mode coverage as a follow-up once the lowering lands. One small change applies directly to this PR: `run_pixel_words` still exits 77 after a prior failed comparison. Calling `check(..., False)` and then injecting a renderer return of 77 reproduces it. #2380 just fixed the sibling fixtures with `sys.exit(1 if failures else 77)`.
Author
Owner

@⁠pigalot on GitHub · 2026-11-25 15:19 UTC · original

Thanks, @⁠RavenCurseBurg. Pushed 81d0e386.

  • Skip after a failure: fixed. run_pixel_words now exits 1 if failures else 77, as #2380 did for the sibling fixtures. Checked by injecting a renderer return of 77: after a failed check(...), the previous code exits 77 and the new code exits 1; with no failure, both exit 77. ctest --preset dev --no-tests=error -j 1 -R '^startup_gfx2hlsl_sdwa_cndmask(_warp|_hardware)?$': 3 passed (WARP and RTX 5090).
  • Destination modes: thanks for measuring UNUSED_PAD and the whole-DWORD destination on WARP, UHD 770 and RTX 4060, and for the PAD-to-PRESERVE and DWORD-to-WORD_0 controls. Splitting the result across two mantissas of 1.0 is a neater way round the float target than the one I took. Glad for you to carry that coverage as the follow-up once this lands.

Still open: nothing for this PR.

AI-assisted: written with Claude Code; the commands above were run locally.

**@⁠pigalot** on GitHub · 2026-11-25 15:19 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2391#issuecomment-7166670090) Thanks, @⁠RavenCurseBurg. Pushed 81d0e386. - **Skip after a failure:** fixed. `run_pixel_words` now exits `1 if failures else 77`, as #2380 did for the sibling fixtures. Checked by injecting a renderer return of 77: after a failed `check(...)`, the previous code exits 77 and the new code exits 1; with no failure, both exit 77. `ctest --preset dev --no-tests=error -j 1 -R '^startup_gfx2hlsl_sdwa_cndmask(_warp|_hardware)?$'`: 3 passed (WARP and RTX 5090). - **Destination modes:** thanks for measuring `UNUSED_PAD` and the whole-`DWORD` destination on WARP, UHD 770 and RTX 4060, and for the PAD-to-PRESERVE and DWORD-to-WORD_0 controls. Splitting the result across two mantissas of 1.0 is a neater way round the float target than the one I took. Glad for you to carry that coverage as the follow-up once this lands. Still open: nothing for this PR. AI-assisted: written with Claude Code; the commands above were run locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 02:14 UTC · original

Merged origin/main into this branch (91a1d93f2, fast-forward from 81d0e386f) so the PR no longer conflicts. No author code was changed.

Conflict: only .github/workflows/windows.yml (the Linux check list). Kept both sides: the new startup_gfx2hlsl_sdwa_cndmask_check.py entry plus the three entries that landed on main.

Verification (Win2025, merge diff applied on the PR head):

  • python3 -B tests/startup_gfx2hlsl_sdwa_cndmask_check.py and tests/startup_gfx2hlsl_sdwa_check.py: PASS (Linux)
  • x2w_pipe.py win2025 2391 --patch <merge diff> --targets offscreen_check --regex startup_gfx2hlsl_sdwa: dev 7/7 and release 7/7 passed, including startup_gfx2hlsl_sdwa_cndmask_warp and _hardware.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-26 02:14 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2391#issuecomment-7180597768) Merged `origin/main` into this branch (`91a1d93f2`, fast-forward from `81d0e386f`) so the PR no longer conflicts. No author code was changed. Conflict: only `.github/workflows/windows.yml` (the Linux check list). Kept both sides: the new `startup_gfx2hlsl_sdwa_cndmask_check.py` entry plus the three entries that landed on main. Verification (Win2025, merge diff applied on the PR head): - `python3 -B tests/startup_gfx2hlsl_sdwa_cndmask_check.py` and `tests/startup_gfx2hlsl_sdwa_check.py`: PASS (Linux) - `x2w_pipe.py win2025 2391 --patch <merge diff> --targets offscreen_check --regex startup_gfx2hlsl_sdwa`: dev 7/7 and release 7/7 passed, including `startup_gfx2hlsl_sdwa_cndmask_warp` and `_hardware`. AI-assisted; commands listed were executed locally.
This discussion has been locked. Commenting is limited to contributors.
No description provided.