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

Merged
pigalot merged 3 commits from upstream-pr/2391 into main 2026-11-26 02:16:46 +00:00
pigalot commented 2026-11-25 15:01:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-25T15:01:19Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6607424308 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2391). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-25T15:01:19Z. --- ## 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.
RavenCurseBurg commented 2026-11-25 16:05:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T15:07:39Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7166345169 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2391#issuecomment-7166345169). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T15:07:39Z. --- 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)`.
pigalot commented 2026-11-25 16:05:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-25T15:19:46Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7166670090 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2391#issuecomment-7166670090). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-25T15:19:46Z. --- 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.
upstream-sync closed this pull request 2026-11-26 03:02:52 +00:00
tedin7 commented 2026-11-26 03:03:21 +00:00 (Migrated from github.com)

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


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7180597768 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2391#issuecomment-7180597768). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:14:16Z. --- 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.
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!2383
No description provided.