startup: draw the gfx2hlsl binary32 arithmetic operations #1705
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1712"
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 Asimmimx on 2026-11-24T17:37:12Z.
Refs #1149.
Change
No check ran these thirteen binary32 operations of the
VEC_Ftable intools/startup/gfx2hlsl.py:v_add_f32,v_sub_f32,v_subrev_f32,v_mul_f32,v_mul_legacy_f32,v_min_f32,v_max_f32,v_fma_f32,v_mad_f32,v_mad_legacy_f32,v_med3_f32,v_min3_f32andv_max3_f32.This PR adds a check only. The translator does not change.
tests/startup_gfx2hlsl_float_alu_check.pydraws them with the per-lane runnertests/startup_gfx2hlsl_lane_alu.py. The runner is byte-identical to the copies in #1703, #1706 and #1708. In each draw:_e32and_e64for the VOP2 forms;binarymode;neg_loandneg_hi.References (AMD RDNA 2 ISA reference):
v_subrevis S1 - S0.0 * inf,inf * 0,0 * NaNandNaN * 0.v_med3_f32is the middle of three values.Every input set has an exact result: dyadic values whose sums and products fit in 24 bits. The check therefore does not depend on rounding or on whether a compiler fuses a multiply and an add.
Mutations, one per operation. The first draw with the mutated lowering must read the mutation's own reference words:
a * b - cfor the multiply-adds;max3formed3.Results
Commit
0389c74aonorigin/main. Windows 11 26300.9974, DXC 1.8.2502.11, FXC 10.0.26100, debug layer on.There were no skips.
binarywith llvm-mc 19.1.1 givesfixture words match llvm-mc.Observation:
v_fma_f32andv_mad_f32on an inexact product. The translation writes both asa * b + c.v_fma_f32rounds once.v_mad_f32rounds the product and then the sum.I drew them with
a = b = 1 + 2^-12andc = -(1 + 2^-11). A single rounding gives 2^-24 (0x33800000), and two roundings give 0.v_fma_f32, FXC and DXC0000000033800000v_mad_f32, FXC and DXC0000000033800000So the same translated text rounds twice on WARP and is fused on the RX 6600.
v_fma_f32differs from the ISA on WARP, andv_mad_f32differs on the RX 6600. As far as I know, binary32 HLSL has no form that guarantees either behaviour, which is also whycompute_store_aotrefuses fused multiply-add. I recorded this under "Not covered" indocs/experiments.mdand did not change the lowering.Also found.
v_add_f32 v1, v2(one source short) raisesIndexErrorinStage.oneinstead ofUnsupported. A VEC_F form with an extra source, such asv_med3_f32 v1, v2, v3, v4, v5, translates with the extra source silently dropped. The VEC_U table already checks the operand count. I'll send that fix as a separate PR.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:46:21Z.
Review: COMMENTED
Peer review at
head_sha:0389c74aa5df30e68390b29a96cdef1de97bb3d5Verdict: 0 P1, 0 P2. The translator is not changed; this PR only adds checks.
Scope (full diff read)
tests/startup_gfx2hlsl_float_alu_check.pyand the shared runnertests/startup_gfx2hlsl_lane_alu.py. Changed:CMakeLists.txt(a controls test pluswarp/hardwaredraw tests withSKIP_RETURN_CODE 77),docs/experiments.md, and.github/workflows/windows.yml(two lines: thebinarycheck withllvm-mc-15in the Python check list, and the file in the Linux check list). Nothing undersrc/ortools/.d8801e44cfe611cdfor all four heads), so the add/add on that path merges cleanly whichever lands first.git merge-treeagainst currentmain(eaa2024b): no conflicts; it also merges cleanly with #1716, and with both applied the controls,binarymode and my evaluation below still pass.Semantics against the ISA
v_subrev_f32= S1 - S0;v_mul_legacy_f32andv_mad_legacy_f32use a multiply that reads 0 when either factor is 0, even against an infinity or NaN (the fixture sets include0 * inf,inf * 0,0 * NaN,NaN * 0);med3is the middle value;min3/max3are the nested min/max. These match theVEC_Fentries and themul_legacy/med3helpers ((a == 0.0 || b == 0.0) ? 0.0 : a * bandmax(min(a, b), min(max(a, b), c))).v_fma_f32andv_mad_f32are both lowered asa * b + c, which gives adapter-dependent results on an inexact product), NaN and signed-zero ordering in min/max/med3, and denormals.Independent check on Linux
The draw is Windows-only, so I evaluated the translated text myself: for each of the 13 operations I translated the fixture, evaluated the four per-lane expressions in Python (binary32 conversion for
F/U, the two helpers as defined above), and compared with the reference words. I used the PR's draw sets plus 4,000 random exact sets per operation (multiples of 1/8, all with exact results), and did the same for each mutated lowering against its mutated reference: 11,026 four-lane chunks, 0 differences.llvm-mc-19 -mcpu=gfx1013words for all 13 bodies match the recorded words (binarymode).Findings
startup_gfx2hlsl_float_alu_warp/_hardware) to prove the semantics. The Linux-run controls only check shape (four lanes translated, mutation pattern matches four times, mutation changes set 0). For example, flippingv_subrev_f32toa - bin the translator still passes the Linux controls andbinarymode (see below). That is by design, and the PR says the evaluator-style results come from the draw, but it means the numbers in the docs (52 draws on WARP and on an RX 6600, 26 mutated draws) are not something I could reproduce here.Verified
Limits: Linux x86-64 only. No D3D12, no DXC/FXC, so
draw(and the WARP and RX 6600 results in the docs) was not run.llvm-mc-15, which CI uses, is not installed here; I usedllvm-mc-19.python3 -B tests/startup_gfx2hlsl_float_alu_check.py-> exit 0 (41 checks ok).... binary /usr/bin/llvm-mc-19-> "fixture words match llvm-mc", exit 0.python3 -B tests/docs_links_check.py-> OK.v_subrev_f32{1} - {0}->{0} - {1}: Linux controls exit 0 andbinaryexits 0 (escape; only the draw, or my evaluator, sees it:0xbf400000vs0x3f400000).v_mad_legacy_f32mul_legacy({0}, {1}) + {2}->{0} * {1} + {2}: Linux controls exit 1 (AssertionError: ('v_mad_legacy_f32', 0), the mutation pattern no longer matches).v_min3_f32reshaped tomin(min({0}, {1}), {2}): Linux controls exit 1 (same pattern assertion).v_med3_f32body word changed:binaryexits 1 (assembled ..., recorded ...).git checkout -- .;git status --shortclean.Also found (not for this PR)
v_fma_f32is lowered toa * b + c, which is not a single-rounding fused operation on every adapter (the docs show0x33800000on RX 6600 and0on WARP). That is a translator question for a later change, not a defect of this check.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-24T20:23:53Z.
Green on its base, red on main
I merged this branch into
mainatdf40e4bcon a physical RX 9070 XT (RDNA 4, driver 32.0.32029.2010) to run the draw mode. All three registered tests fail before any draw executes. Three runs, identical:That is one local merge on my machine, not a CI run.
df40e4bcwas the head ofmainwhen I merged; the only conflict wasdocs/experiments.md, resolved by keeping both experiment sections; the tree committed clean andgit diff --checkpasses.The mutation for
v_mad_f32finds nothing left to replace, becausemainchanged the lowering under you.df40e4bccontainsf7b7297d("shader: preserve non-fused gfx1013 multiply-add rounding"). Excerpt of its hunk ontools/startup/gfx2hlsl.py:v_fma_f32is the same string on both sides of the hunk;v_mad_f32andv_mad_legacy_f32are not.VEC_Fis a single table with nogfx1013or per-adapter branch, and translating the PR'sv_mad_f32body againstdf40e4bcprintsv12 = U(mad32(F(v0), F(v4), F(v8), false));— which is the output the mutation is looking at.I checked the other side on the same code, at the base this PR was written against (
bfe9158d, beforef7b7297d), wheregit show bfe9158d:tools/startup/gfx2hlsl.py | grep -c 'mad32('returns 0. There, both opcodes emitted the same text:For the
v_mad_f32mutation on this one shader, that pattern matches 4 times atbfe9158dand 0 times atdf40e4bc, per run. So the sentence in the PR body — that the translator writes both of them asa * b + c— is accurate at its base and stale at today'smain. That is one stale claim in the last paragraph, not a defect in the test: the test is doing its job by catching the table change.Why the checks were green
The PR's merge ref is
16979ce0, "Merge0389c74aintobfe9158d" — a base that predatesf7b7297d, so the tree built there contains nomad32(. The green checks are attached to the head commit0389c74a; no check run is attached to the merge ref. Whatever the green run built, it was not the tree that merging this into today'smaincreates — I recreated that tree twice, and both times the same assertion fired.What I would change
main, so the tests see the current table.VEC_F, or a check that a draw reads the words the operation's semantics call for. Those are different tests, and the second is the one I would write: it should catch a table change likef7b7297don purpose instead of by accident.mad32(..., false)andmad32(..., true)in place, fused versus twice-rounded is now a per-operation question the draw can be asked, instead of a shareda * b + cthat could not distinguish them.I have made no hardware claim here: the fixture never reached a draw, so this says nothing about RDNA 4 arithmetic. Once the controls pass I can run the 52 draws and the 26 mutants on the same machine that produced this report.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-24T22:28:05Z.
Hardware run of head
0389c74a. Windows 11 Pro 26100.9168, DXC/FXC from Windows SDK 10.0.26100,devpreset, debug layer unavailable here. Adapter selected withXBOX2WINDOWS_ADAPTER: WARP 10.0.26100.8972, NVIDIA Quadro M1000M (Maxwell, 10de:13b1) 32.0.15.7371, Intel HD Graphics 530 (Gen9, 8086:191b) 31.0.101.2111.startup_gfx2hlsl_float_alu_controlsstartup_gfx2hlsl_float_alu_warpstartup_gfx2hlsl_float_alu_hardwareon the Quadro M1000Mstartup_gfx2hlsl_float_alu_hardwareon the HD 530No changes made.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:53:28Z.
@Asimmimx could you rebase this branch onto current
mainand force-push?GitHub reports head
0389c74aas conflicting withmain, so it cannot be merged as is.Files that conflict with current
main(cf97bee1):CMakeLists.txtdocs/experiments.mdtests/startup_gfx2hlsl_lane_alu.pyCommands run locally:
Once it is rebased and CI is green it will be re-checked right away.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:29:05Z.
Pushed two commits on top of the branch (no force, no rebase): a merge of current
main, and a small test follow-up that the merge made necessary.Merge (
1ac9d3161): GitHub reported conflicts in three files.CMakeLists.txtanddocs/experiments.md: append-style conflicts with new tests and sections frommain; kept both sides (the branch's float ALU test block and doc section, thenmain's).tests/startup_gfx2hlsl_lane_alu.py(add/add): keptmain's copy. It differs from the branch's copy only by thepipeline:docstring line and the**family.get('pipeline', {})keyword arguments.Follow-up: after the merge,
tests/startup_gfx2hlsl_float_alu_check.pyfailed on Linux atv_mad_f32 (0 matches), becausemainnow lowers these operations differently from the text the mutations search for. Three mutation patterns were updated, nothing else in the check changed (the references and recorded words are untouched):v_mad_f32:mad32(a, b, c, false)-> mutated tomad32(a, b, -c, false)(stilla * b - c)v_mad_legacy_f32:mad32(a, b, c, true)-> mutated tomad32(2.0 * a, b, c, true)(still twice the legacy product)v_med3_f32: the search pattern is nowmed3_32(...)Commands executed:
git merge origin/main, conflicts resolved as abovepython3 tests/startup_gfx2hlsl_float_alu_check.py(Linux, before the follow-up: AssertionError('v_mad_f32', 0); after: all ok, including "mutation changes draw set 0" for every operation)0389c74aplus the mergedtools/startup/gfx2hlsl.py,tools/disasm_rdna2.pyand the two test files:ctest -R startup_gfx2hlsl_float_alu-> 3/3 passed ondevand 3/3 passed onrelease(controls, warp, hardware-adapter entry)AI-assisted; commands listed were executed locally.