startup: lower v_dot2_i32_i16 and v_dot2_u32_u16 in gfx2hlsl #3036
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3036"
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 R0D4X on 2026-11-27T09:28:15Z.
What this changes
Adds lowering for the VOP3P 2-halfword integer dot-product instructions
v_dot2_i32_i16(0x14) andv_dot2_u32_u16(0x15) intools/startup/gfx2hlsl.py(already decoded bytools/disasm_rdna2.pyand handled intools/pixel_aot.py).S0.lo * S1.lo + S0.hi * S1.hi + S2in signed (int16->int32) or unsigned (uint16->uint32) arithmetic. Because two 16x16 products plusS2can overflow 32 bits twice (e.g.,(-32768)^2 + (-32768)^2 = +2^31or2 * 65535^2), both helpers use exact multi-step / 64-bit carry tracking soclampsaturates accurately (and exact cancellations like2^31 + (-2^31) = 0do not falsely saturate).dot2_i32_i16/dot2_u32_u16incommon()only when the corresponding instruction is used; routes assignments throughStage.set_vsoEXECmasking is preserved.clampVOP3P modifiers (op_sel,op_sel_hi,neg_lo,neg_hi), source modifiers (|...|,-...,neg(...),abs(...)), non-VGPR destinations, and out-of-range or pair register operands.Tests added
tests/startup_gfx2hlsl_v_dot2_check.py: VOP3P binary decode viaG.decode(), 588 cases per instruction covering wrapping andclampsaturation (including double-overflow and exact cancellation), on-demand helper emission/omission,EXECmasking, refusal cases, unlowered control, and FXCps_5_1+ DXCps_6_0GPU readback draws (including a negative-control draw).tests/cmake/startup_gfx2hlsl_v_dot2.cmakeandtests/checks/python-linux/startup_gfx2hlsl_v_dot2.txt.Verification
3cb04f53(onupstream/maine446b072)10.0.26300.9974), MSVC19.44.35230, Windows SDK10.0.26100.0, FXC + DXC1.9.2602.17, D3D12 debug layer enabled1414:008c, driver10.0.26100.9818) and NVIDIA GeForce RTX 5080 (10de:2c02, driver32.0.16.2124)Results:
ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_v_dot2|^startup_tools_lint$' -V-> 4/4 passed, 0 skipped (debug_errors=0 debug_warnings=0on all draws)ctest --preset release --no-tests=error -R '^startup_gfx2hlsl_v_dot2'-> 3/3 passed, 0 skippeddocs_links_check.py,bidi_controls_check.py,startup_gfx2hlsl_handler_arity_check.py,startup_gfx2hlsl_refusals_check.py,git diff --check) -> all passedgfx2hlsl.py(droppingclamp, dropping non-clampmodifier refusal, dropping helper gates, dropping source-modifier refusal) -> 5/5 caught (rc=1)Scope: Covers synthetic gfx1013 VOP3P fixtures translated by
gfx2hlsl.pyand run on WARP and RTX 5080; does not establish full-title startup or frame rate.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T20:12:42Z.
This PR now conflicts with
mainafter #3030 (s_bitreplicate) landed. The conflict is one block intools/startup/gfx2hlsl.pywhere both PRs add lines at the same spot. Keeping both sides resolves it; I checked locally that the union gives exactly main plus this PR's own lines and thattests/startup_gfx2hlsl_v_dot2_check.py(controls) still passes.Could you merge
maininto your branch (a merge commit is fine, no force push needed)? I will rerun the Windows tests on the new head and review it then.Commands:
git merge-tree --write-tree origin/main pull/3036/head, a local trial merge,python3 -B tests/startup_gfx2hlsl_v_dot2_check.py.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T20:14:04Z.
Review: CHANGES_REQUESTED
I reviewed
a416bed4. Like #3031, it now conflicts withmain3c30dc74at oneuses_bitreplicate/uses_dot2site added by #3030. Keeping both sides resolves it. I tested on that local resolution (tree001670be).What I traced.
carry != 0is exactly "the sum exceedsUINT32_MAX".(hi, lo)pair is a correct 64-bit two's-complement accumulate. Each product is sign-extended intohi, andt < lois the carry out oflo. The two clamp tests are the exact int32 bounds.|c + p0 + p1|stays below 2^32, sohiis always 0 or −1. That makeshi > 0andhi < -1unreachable. They're harmless.set_v. Every modifier exceptclampis refused.What I ran. I built
offscreen_checkindevandrelease, then ran:ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^startup_gfx2hlsl_v_dot2'3/3 passed in each preset, with no skips, on WARP and an RTX 5090.
Gap: the carry compare in the signed helper is untested.
clamp=1signed lane has two non-zero products.((t0 < lo) ? 1 : 0)/((t1 < lo) ? 1 : 0)changed to<=. It adds a false carry whenever a product is 0, sodot2(0x00000003, 0x00010005, 0x3f800000) clampwould return0x7fffffff.Suggested fix (tested locally). Add a lane set with zero products:
expected=3f80000f,0000000e,7fffffff,80000000 actual=7fffffff,7fffffff,7fffffff,7fffffff.Verdict: request changes on
a416bed4: rebase over #3030 and add the zero-product lanes. The lowering itself looks right to me.Environment: NVIDIA GeForce RTX 5090, driver 32.0.16.1088; WARP 10.0.26100.9818; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10; debug layer on.
CI: passes on
a416bed4, which predates the conflict. There are no reviews or threads.This reply was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T03:03:11Z.
Merged
mainfdb6faaainto this branch asb87eef1d. The push fast-forwards froma416bed4; there was no rebase and no force-push.Conflict and how I resolved it.
tools/startup/gfx2hlsl.py, helper emission. This branch emits thedot2_u32_u16anddot2_i32_i16helpers.main(#3030) emitsbitreplicate16at the same place. The helpers are independent, so I kept both: thedot2helpers first, thenbitreplicate16.mainhas nov_dot2lowering of its own.uses_dot2anduses_bitreplicateare both still initialised in the stage state.git diff --check origin/main...HEADis clean.What I ran. I built everything in
devand inrelease(/O2), then ran_hardwarepass._hardwarepass.The runs include this branch's
startup_gfx2hlsl_v_dot2_{controls,warp,hardware}andmain'sstartup_gfx2hlsl_s_bitreplicate_{controls,warp,hardware}.This needs a re-review by someone else; I won't review or merge it myself.
Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; SDK 10.0.28000.0 DXC (the one CTest picked up); Python 3.12.10.
This reply was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-28T07:18:20Z.
Thanks for this. The lowering looks right to me, but one change from pigalot's review is still missing on
b87eef1d. Could you add it?Addressed: the merge of
mainafter #3030 is done (b87eef1d). A trial merge into currentmain(c3204a9c) is clean:git merge-tree --write-treereturns rc=0, and the merged tree adds exactly this PR's 368 lines.Still needed: the zero-product lanes.
tests/startup_gfx2hlsl_v_dot2_check.pyis byte-identical to thea416bed4version:git rev-parse a416bed4:tests/startup_gfx2hlsl_v_dot2_check.py b87eef1d:tests/startup_gfx2hlsl_v_dot2_check.pygives2a97924bfor both. If the signed carry compares((t0 < lo) ? 1 : 0)and((t1 < lo) ? 1 : 0)are changed to<=, the controls still pass (rc=0). The draws miss it too: under the test's own model, the mutant changes 0/4 of the signedclamp=0lanes and 0/4 of theclamp=1lanes. pigalot's suggested lane set catches it: expected3f80000f,0000000e,7fffffff,80000000, mutant7fffffff×4. Adding that('v_dot2_i32_i16', 1, [...])entry toDRAW_CASESwould close this.Smaller, optional: CI doesn't see the emitted HLSL. Windows ran
ctest --preset pr(70 tests, nonev_dot2), and Linux ran only the controls. The controls checkeval_dot2_*_hlsl, which is a Python copy of the helpers, not the helper text thattranslate()emits. So three mutants of the helper body pass the controls: the carry compare above, a wrong u32 saturate value, and dropping thep0sign-extend. Evaluating the emitted helper, or asserting that it matches the copy, would let Linux CI catch them.What I checked:
llvm-mc-19 -mcpu=gfx1030 -show-encodinggives opcodes0x14and0x15with the same defaultop_sel_hias your encoder. The translator lowers those bytes, andop_sel_hi:[0,1,1]is refused.pixel_aot.py: exact 64-bit accumulate, then saturate.Not run here: the draws (this machine has no WARP or GPU).
This comment was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-11-28T09:11:52Z.
Added the requested zero-product signed-clamp draw lanes (
3f80000f,0000000e,7fffffff,80000000) and a strict unsigned carry-compare assertion on the emitteddot2_i32_i16HLSL helper intests/startup_gfx2hlsl_v_dot2_check.py.Verified on NVIDIA GeForce RTX 5080 (
10de:2c02, driver32.0.16.2140), WARP (10.0.26100.9818), Windows 11 (10.0.26300.9974), SDK DXC/FXC10.0.26100.0:startup_gfx2hlsl_v_dot2_controls: passedstartup_gfx2hlsl_v_dot2_warp(FXCps_5_1+ DXCps_6_0): passedstartup_gfx2hlsl_v_dot2_hardware(FXCps_5_1+ DXCps_6_0): passed (debug_errors=0 debug_warnings=0)Ready for re-review!
Commit:
8c05ff2eImported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T10:36:26Z.
Review: APPROVED
Earlier I wrote here that this "needs a re-review by someone else; I won't review or merge it myself". That was wrong: our account's only commit on this branch is the merge of
main(b87eef1d), and I'm reviewing it myself now. I will merge it once the merge gates pass.Retested
8c05ff2eintegrated overmain3926a289(treedfba0d32). The trial merge is clean andgit diff --checkis clean. This supersedes my changes-requested review ona416bed4.Earlier findings.
maininto this branch earlier asb87eef1d; I checked that resolution again here.git show --remerge-diff b87eef1dshows one conflict intools/startup/gfx2hlsl.py, resolved by keeping both sides: the twodot2helpers, thenbitreplicate16. Nothing else differs from an automatic merge.8c05ff2echanges only the test file (+8 lines). It adds the zero-productclamp=1lane set and a check that the emitted helper contains both strict compares.<=in either compare now fails the controls, so Linux CI sees it.t0 == lo. The controls pass, and the draw fails in the new lane set:expected=3f80000f,0000000e,7fffffff,80000000 actual=3f80000f,7fffffff,7fffffff,7fffffff.What I ran. I built
offscreen_checkindevandrelease(/O2), then ranctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^startup_gfx2hlsl_v_dot2_(controls|warp)$'and the_hardwaretest on its own:3/3 passed in each preset, with no skips, FXC
ps_5_1and DXCps_6_0,debug_errors=0 debug_warnings=0. The tests are not registered onmain.Mutants (18, each against the controls and the WARP draws in
dev).<=att0, and att1(controls);t0, and att1(draws only);0xffffffffusaturate value;p0sign-extend dropped, and thep1one;clampflag never passed;<=;hinot initialised from the sign ofc;set_v;p0term dropped from the signed sum.hi > 0 ||and droppinghi < -1 ||.hiis always 0 or -1, as noted in my first review.source modifierrefusal.|v0|,-v0andneg(1)are still refused later, by the operand parser, and the test doesn't pin which message it gets. Not blocking: the behaviour is the same either way.Other reviewers. JohnConnorNPC's comment on
b87eef1dasked for the same zero-product lanes, which are now in. Their optional point (Linux CI not seeing the emitted helper) is partly covered by the new string check: of their three mutants, the carry compare now fails the controls, while the saturate value and thep0sign-extend are still caught only by the draws. That's fine for this PR.Verdict: approve
8c05ff2e.Environment: NVIDIA GeForce RTX 5090, driver 32.0.16.1088; WARP 10.0.26100.9818; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; debug layer on.
CI:
Build and test on Windowspasses on8c05ff2e.This reply was AI-assisted.