shader: lower the SDWA forms of ten unary f32 operations in pixel_aot #750
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/756"
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 rasptum on 2026-11-23T01:02:04Z.
Change
pixel_aotlowers the SDWA forms of the exact binary32 arithmetic (add,sub,subrev,mul,mul_legacy,max,min,floor,ceil,fract,trunc) through one path,SDWA_ALU. The SDWA forms of the other unary binary32 operations it already lowers in e32 and e64 were unrecognised mnemonics.This adds those ten to the same path:
v_exp_f32_sdwa,v_log_f32_sdwa,v_rcp_f32_sdwa,v_rcp_iflag_f32_sdwa,v_rsq_f32_sdwa,v_sqrt_f32_sdwa,v_sin_f32_sdwa,v_cos_f32_sdwa,v_rndne_f32_sdwaandv_frexp_mant_f32_sdwa. The translator change is one tuple. Each operation reuses its existing entry inALUunchanged, so the whole-dword SDWA spelling and the e32 spelling produce the same shader (the controls assert this for all ten), and the result is placed with the SDWA move rules already documented.The limit recorded in
docs/experiments.mdfor SDWA float arithmetic is kept: onlysrc0_sel:DWORDis accepted, because a byte or word source would reach the arithmetic as a zero-extended, usually subnormal binary32. For each of the ten forms the controls check that these stay refused: a byte or word source (BYTE_0,BYTE_3,WORD_0,WORD_1), asrc1_sel, a second operand, an output modifier (mul:2),UNUSED_SEXTon a partial destination, andUNUSED_PRESERVEover an untracked destination.Three programs are drawn, two constant rows each. A, B, C and D are constants s44 to s47.
D3D allows
exp2,log2, a reciprocal,rsqrt,sqrt,sinandcosan error, so a raw result has no single binary32 reference. As in #729, the first two programs choose inputs whose true result is an integer, then add 0.5 and take the floor, which returns that integer for any result within 0.5 of it. This checks which operation ran and its source modifiers, not last-place accuracy.src0_sel:DWORD)v_exp_f32_sdwa v12, -s44v_log_f32_sdwa v13, |s45|v_rcp_f32_sdwa v14, s46v_rcp_iflag_f32_sdwa v15, -|s47|v_rsq_f32_sdwa v12, |s44|v_sqrt_f32_sdwa v13, s45v_sin_f32_sdwa v14, s46(revolutions)v_cos_f32_sdwa v15, -s47(revolutions)The third program is exact and is compared directly:
v_rndne_f32_sdwa v12, s44(ties 2.5 and -3.5)v_frexp_mant_f32_sdwa v13, -s45 clampv_rndne_f32_sdwa v14, s46 dst_sel:BYTE_2 dst_unused:UNUSED_PRESERVEover 1.0v_frexp_mant_f32_sdwa v15, s47 dst_sel:BYTE_3 dst_unused:UNUSED_PADNegative controls: 26 wrong references, each replacing one channel, must report
pixel_mismatch.That is 32 draws from three compiles and three renderer launches. They are registered as their own CTest entries,
pixel_aot_sdwa_unary_hardwareandpixel_aot_sdwa_unary_warp(tests/pixel_aot_check.py draw-sdwa-unary), each with its ownFORM_COVERAGE_RECORD, so nothing is added topixel_aot_hardware. The three programs are added to the LLVM 15 round trip,tests/form_coverage_check.pyasserts the ten forms, anddocs/experiments.mdhas a paragraph.tools/scan_unsupported_shaders.pygains one pattern built frompixel_aot.SDWA_ALU, with a test intests/rdna2_tools_check.py. The scanner had no pattern for SDWA float arithmetic, so this also makes it report the eleven forms accepted before this change as supported. It requires whole-dword sources, as the translator does.This advances instruction-form coverage of the pixel translator by ten forms on gfx1013 and ten on gfx1030.
Verification
Update before opening: rebased onto
mainat356a7beas c13268a. On that commit I reran the LLVM 15 round trip,tests/form_coverage_check.py, the static controls, and this PR's own draw test (draw-sdwa-unary) on WARP and on the RTX 3060: all pass. Other results below are from the commits named there.Known red check, not from this PR:
mainis currently broken by aNameErrorincheck_scalar_carry_chain_draw(since #695), which failspixel_aot_predicate_rounding_*and the combineddrawrun for every branch. #752 is the one-line fix. I will rebase this PR oncemainis green.Rebased onto
mainatcfb2600as f3dcbaf. The four commits that landed in between (#627, #740) touch no shader file. On the rebased commit I reran the two new tests on WARP and on hardware, the controls, the LLVM 15 round trip,tests/form_coverage_check.py,tests/rdna2_tools_check.pyandtests/docs_links_check.py(all pass). The fullctestrun and the coverage count below are from e47be05, the same change onmainatfd2486f.Run at e47be05, on
mainatfd2486f. Windows 10 Pro 22H2 (10.0.19045.6466), Windows SDK 10.0.26100.0 DXC, Debug build, debug layer enabled in every run.28 tests ran. 27 passed, 1 failed, 0 skipped.
WARP (Microsoft Basic Render Driver, 10.0.19041.5794):
pixel_aot_sdwa_unary_warppixel_aot_*_warptests, includingpixel_aot_warpHardware (NVIDIA GeForce RTX 3060, 10de:2503, driver 32.0.15.9636):
pixel_aot_sdwa_unary_hardwarepixel_aot_*_hardwaretestspixel_aot_blend_scalar_hardwaremainon this machine and this change does not touch it.In both new tests the six right references pass and the 26 wrong references each report
mismatch.Other checks, all passed:
python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <LLVM-C.dll>with LLVM 15.0.7. LLVM 15 assembles and prints the ten SDWA instructions as written for-mcpu=gfx1013.python -B tests/pixel_aot_check.py(controls).AGENTS.md.Evidence and follow-up
Coverage, counted with
tools/form_coverage.py's matching rule from the union of the record-writing shader tests run on WARP, once from a clean copy offd2486fand once from this commit.tools/form_coverage.pyon the JUnit file of the run above reports the same totals.mainatfd2486fThe forms added are exactly the ten SDWA forms named above, in both lists. None is removed.
docs/coverage/dashboard.svgis not regenerated here.What this does not show:
v_rcp_iflag_f32, which has no desktop equivalent (as for the e32 form).Overlap with open pull requests: the diffs of the open shader pull requests (34 read) were searched for the ten form names and for
SDWA_ALUon added lines; none adds them. #423 covers the DPP forms of some of the same operations and does not touch the SDWA path. This pull request appends one line to thecheck_binaryfixture list, as every open shader pull request does, so a textual conflict there with whichever lands first is expected and trivial.AI-assisted (Claude Code). The Windows results were measured locally.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-23T01:13:21Z.
Rebased onto
mainataeb45da(after #752 repaired theNameError) as407e355. Rerun on this commit, Windows 10 22H2, WARP 10.0.19041.5794 and RTX 3060: LLVM 15 round trip,tests/form_coverage_check.py, the fullpixel_aot_check.py drawrun on WARP, and this PR's own draw test on WARP and hardware. All pass.