shader: lower the SDWA form of v_cndmask_b32 in gfx2hlsl #2383
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2391"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-25T15:01:19Z.
Change
tools/startup/gfx2hlsl.pyrefused the SDWA form of the VOP2 select withSDWA form of v_cndmask_b32.sdwa()now lowers it as a two-source integer operation: each source takes itssrc0_sel/src1_selfield (zero-extended, or sign-extended undersext()), the select reads VCC, its fourth operand, the same way the plainv_cndmask_b32does, anddst_sel/dst_unusedplace the result by the rules the other integer SDWA forms use.clamp, float modifiers andUNUSED_SEXTstay 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):ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_sdwa_cndmask(_warp|_hardware)?$' -V1414:008c, driver 10.0.26100.9818) and NVIDIA GeForce RTX 5090 (10de:2b85, driver 32.0.16.1088): 26 draws each, FXCps_5_1and DXCps_6_0python -B tests/startup_gfx2hlsl_sdwa_cndmask_check.py binary <llvm-mc>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_'startup_run_sh, a shell script)ctest --preset dev --no-tests=error -j 1 -R 'sdwa.*(_warp|_hardware)$'git diff --checkNegative control: with
tools/startup/gfx2hlsl.pyfrom main,startup_gfx2hlsl_sdwa_cndmask_check.pyfails (the fixture translates, refused asSDWA 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_2widened intoWORD_0, andWORD_0,BYTE_1andBYTE_2destinations underUNUSED_PRESERVEover 1.0, which keeps every exported word a normal binary32 value (asserted, since the readback target isR32G32B32A32_FLOAT). All 1,024 exported words match a bit model. Six mutated selects (swapped operands, the mask ignored, the mask inverted, a droppedsext(), the neighbouring source byte, the wrong destination byte) each fail against the model and match their own model.Not covered by the draw:
UNUSED_PADandDWORDdestinations, whose results would be denormal or NaN words on a float target;startup_gfx2hlsl_sdwa_check.pypins 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 literalvcckeeps 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) anddocs/startup-runtime.md(SDWA bullet). CI: the controls run in the Linux Python checks, and the binary mode runs withllvm-mc-15.Checklist
This change was AI-assisted: written with Claude Code, and the checks above were run locally.
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_wordsstill exits 77 after a prior failed comparison. Callingcheck(..., False)and then injecting a renderer return of 77 reproduces it. #2380 just fixed the sibling fixtures withsys.exit(1 if failures else 77).Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-25T15:19:46Z.
Thanks, @RavenCurseBurg. Pushed
81d0e386.run_pixel_wordsnow exits1 if failures else 77, as #2380 did for the sibling fixtures. Checked by injecting a renderer return of 77: after a failedcheck(...), 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).UNUSED_PADand the whole-DWORDdestination 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.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:14:16Z.
Merged
origin/maininto this branch (91a1d93f2, fast-forward from81d0e386f) 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 newstartup_gfx2hlsl_sdwa_cndmask_check.pyentry 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.pyandtests/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, includingstartup_gfx2hlsl_sdwa_cndmask_warpand_hardware.AI-assisted; commands listed were executed locally.