startup: draw the gfx2hlsl binary32 rounding operations #1734
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1741"
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-24T18:01:16Z.
Refs #1149.
Change
No check ran the rounding operations of the
VEC_Ftable intools/startup/gfx2hlsl.py:v_floor_f32,v_ceil_f32,v_trunc_f32,v_fract_f32andv_rndne_f32. They lower to HLSLfloor,ceil,trunc,fracandround.This PR adds a check only. The translator does not change.
tests/startup_gfx2hlsl_float_round_check.pydraws them with the per-lane runnertests/startup_gfx2hlsl_lane_alu.py. The runner is byte-identical to the copies in #1703, #1706, #1708 and #1712. In each draw:_e32and_e64;binarymode.The references follow the AMD RDNA 2 ISA reference:
ceil(-0.75),trunc(-0.75)andrndne(-2^-30)give -0 (0x80000000).v_rndne_f32rounds halves to even. 2.5 → 2, 3.5 → 4, -2.5 → -2, 1000000.5 → 1000000, 8388607.5 → 8388608.v_fract_f32isx - floor(x), capped at the largest binary32 below 1.0. For -2^-30 the exact difference rounds to 1.0, and the instruction gives0x3f7fffff. The compute translator lowers fract with an explicit cap because HLSLfraccan return 1.0 there on some adapters; see thev_fract_f32note indocs/experiments.md.The inputs also include the binary32 just below 0.5 (
0x3effffff).Each operation has one mutated lowering, and the first draw with it must read the mutation's own reference words:
x - trunc(x)for frac;Results
Commit
8ff3dddfonorigin/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.frac(-2^-30). On both adapters, through both compilers, the plain HLSLfracread0x3f7fffff. The gfx2hlsl lowering, which has no explicit cap, therefore matches the ISA on these two adapters. An adapter whosefracreturns 1.0 there would fail this draw. That is intended: the check would then show that gfx2hlsl needs the same cap ascompute_store_aot.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T18:08:33Z.
Review: COMMENTED
Review of head
8ff3dddf38854a2b59e036c89274442f38c7925f. Tests, CMake, CI list and docs only;tools/startup/gfx2hlsl.pyis unchanged. Verdict: 0 P1, 1 P2 (design note, not blocking), plus coverage nits.Linux limits. Linux x86_64,
llvm-mc-19(the new CI entry pinsllvm-mc-15), Python 3.14. No Windows, no DXC/FXC, no WARP or GPU: I could NOT run thedrawmode, so the WARP/RX 6600 results in the docs (20 draws, 10 mutated draws,frac(-2^-30)=0x3f7fffff) are not verified by me. Nothing was run through HLSL; the lowerings are only read as text.What I ran (worktree at that head)
python3 -B tests/startup_gfx2hlsl_float_round_check.py(controls): passes.... binary llvm-mc-19:fixture words match llvm-mc.git diff --check origin/main...HEAD,docs_links_check.py,bidi_controls_check.py: clean. The diff has one non-ASCII line (the->arrows in the docs).ceil(-0.75),trunc(-0.75),rndne(-2^-30)give -0),v_rndne_f32is half-to-even (Pythonroundon the double is also half-to-even; 2.5 -> 2, 3.5 -> 4, -2.5 -> -2, 1000000.5 -> 1000000),v_fract_f32is x - floor(x) capped at0x3f7fffff.0xb0800000is -2^-30 and0x3effffffis the binary32 below 0.5. TheVEC_Ftext is plainfloor/ceil/trunc/frac/round.git checkout -- .):v_fract_f32frac->trunc: controls FAILED (AssertionError: ('v_fract_f32', 0)); this happens because the control's mutation regex no longer matches the changed text.v_ceil_f32opcode 0x45 -> 0x44: FAILED inbinary(assembled words differ).floor({0})->floor({0} + 0.0000001): controls andbinaryPASSED, not caught on Linux.round({0})->round(-{0}): controls andbinaryPASSED, not caught on Linux.v_rndne_f32changed to ties-up: controls andbinaryPASSED (only the draw reads it).So a wrong value that keeps the shape of the text is caught only by the draws on a Windows adapter; please make sure they ran for this head.
P2 (design note). The cap of
v_fract_f32at0x3f7fffffis part of the reference, but the translator emits a barefrac(x); the docs say both adapters returned0x3f7fffff"without an explicit comparison". For -2^-30 the exact difference rounds to 1.0, so on an adapter or compiler path that computesfracas x - floor(x) in binary32 the result would be0x3f800000. The new test will then fail on that adapter rather than the lowering being fixed; amin(..., 0x3f7fffff)in the lowering, or a note that the cap is adapter-dependent, would settle it.Coverage nits
floor(NaN),rndne(-0.0),ceil(-0.0),trunc(+/-inf)are unchecked, although the task of the check is the sign-of-zero rule.binary32values at and above 2^23 (no fractional bits) appear only as 8388607.5 and 1000000.5.Not approving (comment only).
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by KainanP on 2026-11-24T18:18:53Z.
A heads-up for
v_rndne_f32 -> round({0}), since the draws ran on WARP and an RX 6600 only.In LooperSalty/AnyXboxX#160, HLSL
round()(DXILdx.op.unary26,Round_ne) returned round-half-away-from-zero on an RTX 5070 (Blackwell), driver 32.0.16.2140. It did so only when the driver could propagate a constant into it. The repro kept a 256-entry register array, stored 2.5 into one entry under an EXEC test, then calledround(asfloat(v[15])). That gave 0.5 → 1.0, 1.5 → 2.0, 2.5 → 3.0, -0.5 → -1.0, -2.5 → -3.0, where WARP gives 0.0, 2.0, 2.0, -0.0, -2.0. The DXIL from dxc was correct. When the value came from memory,roundwas correct on the same card, andfloor/ceil/trunc/fracwere unaffected: https://github.com/LooperSalty/AnyXboxX/pull/160It did not reproduce on an RTX 4060 Laptop (Ada), driver 32.0.16.1047: https://github.com/LooperSalty/AnyXboxX/pull/160#issuecomment-7140062578. So it is either Blackwell-specific or new in recent drivers.
What this means here:
v_rndne_f32source turns into a constant after inlining, for example a literal or ans_movthat reaches it.v_rndne_f32withoutround():floor, then a tie-to-even correction on an exact.5fraction, the value passed through unchanged from 2^23 up, and the sign kept for a zero result.ps_5_1.AI-assisted (Claude Code). The measurements are from the linked AnyXboxX threads, not from runs of this PR.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-24T18:59:53Z.
Draw mode on Windows, and one thing to fix in the CMake block
tedin7's review says it could not run the draw mode, so the independent confirmation was missing. It is here now — with one caveat about the test registration, below.
2026-11-24, head
8ff3dddf, merged onto main330df7f0(my mergeadfee36b, tree90a3df7f, 1117 tests). The merge conflicts only indocs/experiments.md: main added the#1728non-fused multiply-add section at the same place as your rounding section, so I kept both and committed that.Result, with the FXC path passed explicitly:
Same counts as the table in the PR body, on a different architecture:
AMD Radeon RX 9070 XT1002:7550driver32.0.32029.2010(RDNA 4,gfx1201) rather than the RX 6600, with DXC1.9.2602.17rather than1.8.2502.11and FXC10.0.26100.frac(-2^-30). On this adapter, through both compilers, it reads0x3f7fffff, the capped value — the same word your two adapters give. So the failure mode you documented does not appear here, and the lowering keeps the cap without an explicit comparison on a third adapter. That is a result for this adapter and driver, not a reason to drop the cap: an adapter whosefracreturns1.0there would still fail the draw, which is what you intended. The draw prints it directly for the eighth input set:v_rndne_f32against KainanP's heads-upThe comment above reports
round()returning round-half-away-from-zero on an RTX 5070 when the driver propagated a constant, which is exactly whatv_rndne_f32 -> round({0})lowers to. On this adapter, through both compilers, the draw reads half-to-even:So the away-from-zero result does not reproduce here, on AMD hardware or on WARP, with FXC or DXC. That says nothing about the RTX 5070 case — I have no NVIDIA hardware — but it does mean the lowering is not wrong per se, and that a driver can differ on it.
The registration drops the FXC argument
Running the test through
ctestgives 10 draws and 5 mutated draws, not 20 and 10 — one compiler instead of two:The fifth argument is empty, so
check_drawreceives nofxcand buildscompilerswith DXC only. Passing the path by hand gives the 20/10 counts above, on the same build and the same tree.Cause:
${STARTUP_FXC}is expanded at configure time, andfind_program(STARTUP_FXC fxc HINTS "${DXC_BIN_DIR}")sits at line 1665, after theadd_testblock at lines 1648–1653 in the same function scope. The variable is therefore empty when thoseadd_testcalls run, while the cache still ends up withSTARTUP_FXC:FILEPATH=.../10.0.26100.0/x64/fxc.exe. Re-runningcmake --preset devdoes not help — I checked, the command still carries"", because the ordering is the same on every configure.Consequence: on a fresh build, every reader of this test gets the DXC half only, and the test still passes, so nothing signals the gap. Moving the
find_programabove the new block restores the 20/10 counts underctestwithout touching the fixture — the sampler-heap section further down already does it that way, with itsfind_programabove its own tests.Environment: Windows 11 25H2
26200.9974, DXC1.9.2602.17, FXC10.0.26100,devpreset,debug_layer=unavailable.Limits: one adapter, one driver, no debug layer. The inputs are exact, so this checks which function and which base each operation lowers to, not any adapter's approximation error.
AI-assisted; runs executed on the machine above.
Imported from R0Y00/Xbox2Windows. Originally posted by Makto94 on 2026-11-24T20:47:06Z.
Independent run of
8ff3dddfon an NVIDIA GeForce RTX 3070 Ti (desktop), Debug build.startup_gfx2hlsl_float_round_hardwarefails on this adapter;_controlsand_warppass.Environment: driver 32.0.16.2101 (621.01); Windows 11 Pro 10.0.26300.9974; DXC 1.9.2602.17;
debug_layer=enabled,debug_errors=0 debug_warnings=0.Hardware, second
v_fract_f32draw, third lane (inputb0800000, -2^-30). The test alone fails the same way:WARP, same draw, same build:
tools/startup/gfx2hlsl.py:1057(not changed by this PR) emitsfrac({0}); the reference intests/startup_gfx2hlsl_float_round_check.py:41-43caps the result at0x3f7fffff.0x3f800000is the value tedin7's review note gives for -2^-30.The test stops at that draw. A local wrapper that records a failed draw and continues (not the PR command) shows the other 9 unmutated hardware draws matching and the 5 mutated draws reading their mutated words, including:
Not covered by this run: the FXC path (the registered command passes
""for it), constant inputs, a Blackwell adapter, and the inputs 0.5, 1.5 and -0.5.Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-24T22:28:06Z.
Hardware run of head
8ff3dddf. 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_round_controlsstartup_gfx2hlsl_float_round_warpstartup_gfx2hlsl_float_round_hardwareon the HD 530startup_gfx2hlsl_float_round_hardwareon the Quadro M1000Mv_fract_f32(FXC)The floor, ceil and trunc rows pass on the Quadro too. The failing draw:
Lane 2 is
0xb0800000, a tiny negative value.0x3f7fffff, the largest value below 1.0.0x3f800000, which is 1.0.This looks like a real difference in the lowering, not in the fixture.
v_fract_f32isfrac({0})ingfx2hlsl, and D3D'sfrachas no clamp below 1.0.pixel_aotdocuments exactly this ("D3D frac has no clamp and differs between adapters") and lowers it throughfract32, which clamps to0x3f7fffff. WARP and the HD 530 happen to return the clamped value; Maxwell does not. I have not tested a fix.No changes made.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-24T23:01:45Z.
@Asimmimx the two NVIDIA results in this thread come from the lowering, not from your draw:
gfx2hlslemits a barefrac({0})forv_fract_f32, whiletools/pixel_aot.pyhas always capped the same instruction at0x3f7fffffthroughfract32, with the comment that D3Dfrachas no clamp and differs between adapters. On0xb0800000the uncapped form rounds up to 1.0 on Maxwell and Turing.I have opened #2010, which puts that capped helper in the gfx2hlsl preamble, points the table entry at it, and adds a check that pins the emitted text. It targets
main, so your branch does not have to carry it.Two things worth knowing. There is no NVIDIA adapter on my machine — RX 9070 XT and WARP only — so I cannot confirm that the Maxwell and Turing rows turn green; the reasoning above comes from your two reports and from the rule this repository had already written, not from a measurement. And your branch does not carry the
ftz32/mad32helpers thatmainhas today, so rebasing it conflicts in that same preamble; thev_fract_f32row should have nothing left to disagree about once both land.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-25T00:56:25Z.
@Asimmimx one change your branch will need when it lands, so that it does not break quietly.
tests/startup_gfx2hlsl_float_round_check.pypins thev_fract_f32lowering by mutating the emitted text, and the pattern it matches isU(frac(. The lowering is nowfract32({0})(#2010), so that pattern will no longer match: the mutation will leave the shader untouched and the control will pass without testing anything. Both Makto94 and legacy-code-archaeologist ran into this and changed the pattern toU(fract32(locally. It is worth making the control assert that the mutation actually changed the text, so the next lowering change cannot silence it the same way.The rest is good news for your draw. The form that survives FXC is to compare the encoding rather than
frac(value) >= 1.0f, which FXC folds to false and compiles to a barefrc; #2010 now carriesasuint(f) == 0x3f800000u ? asfloat(0x3f7fffffu) : f. On that head the same four inputs read3f000000,3effffff,3f7fffff,3f000000on WARP, on the Quadro M1000M that was failing and on an Intel HD 530, under fxc and dxc — so the row your draw is missing should go green once the two are combined.Your branch also predates #1728, so a rebase conflicts in the preamble where
ftz32andmad32live. Keep both sides there; nothing in your change depends on them.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:53:26Z.
@Asimmimx could you rebase this branch onto current
mainand force-push?GitHub reports head
8ff3dddfas 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:17:39Z.
Pushed
2f12d1e4a: merged currentmaininto this branch (no rebase, no force) so it no longer conflicts, plus one fix the merge needed.tests/startup_gfx2hlsl_lane_alu.py(added on both sides): took main's version, a superset of this branch's file.CMakeLists.txt,docs/experiments.md,.github/workflows/windows.yml: kept both sides.v_fract_f32through thefract32helper, so the fract mutation intests/startup_gfx2hlsl_float_round_check.pyno longer matched (frac(...)found 0 times). The pattern now matchesU(fract32(F(vN)))and still replaces it with the wrongx - trunc(x)lowering, which the draw must reject.Verification:
python3 tests/startup_gfx2hlsl_float_round_check.py,... binary llvm-mc-19, and the other lane_alu users (cvt_pk_u8,pack_b32_f16,cvt_alu): pass.x2w_pipe.py win2025 1741 --patch <merge diff> --regex 'startup_gfx2hlsl_(float_round|cvt_pk_u8|pack_b32_f16|cvt_alu|fract)': 16/16 passed.AI-assisted; commands listed were executed locally.