startup: lower v_dot4_i32_i8 and v_dot4_u32_u8 in gfx2hlsl #3031
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3031"
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:00:22Z.
What this changes
Adds lowering for the VOP3P 4-byte integer dot-product instructions
v_dot4_i32_i8(0x16) andv_dot4_u32_u8(0x17) intools/startup/gfx2hlsl.py(already decoded bytools/disasm_rdna2.pyand handled intools/pixel_aot.py).int8) or unsigned (uint8) byte products plusS2in 32-bit integer arithmetic. Whenclampis set, saturates to[INT32_MIN, INT32_MAX](signed) orUINT32_MAX(unsigned).dot4_i32_i8/dot4_u32_u8incommon()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_dot4_check.py: VOP3P binary decode viaG.decode(), 672 cases per instruction covering wrapping andclampsaturation, 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_dot4.cmakeandtests/checks/python-linux/startup_gfx2hlsl_v_dot4.txt.Verification
1f6cceb1(onupstream/main3b6c38a8)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_dot4'-> 3/3 passed, 0 skipped (debug_errors=0 debug_warnings=0on all draws;startup_tools_lintalso passed)ctest --preset release --no-tests=error -R '^startup_gfx2hlsl_v_dot4'-> 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 pigalot on 2026-11-27T20:10:31Z.
Review: CHANGES_REQUESTED
I reviewed
58d69281. It now conflicts withmain3c30dc74: #3030 addeduses_bitreplicateat the same threePipeline/ComputePipelinesites and the same helper block incommon(). Keeping both sides resolves all four hunks. I tested on that local resolution (tree290a7056).What I traced.
r < cis exactly uint32 overflow.c == 0can't overflow.set_v, so EXEC masking is kept. 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_dot4'3/3 passed in each preset, with no skips, on WARP and an RTX 5090.
Gap: the signed clamp's sign guards are untested.
The controls check
eval_dot4_i32_i8_hlsl, a Python copy of the helper. So the emitted HLSL is checked only by the draws.The signed
clamp=1draw lanes never have a positive accumulator with a negative sum, or the reverse.So each of these HLSL-only mutants passes all 3 tests:
asint(c) > 0 && s > 0 && asint(r) < 0changed toasint(c) > 0 && asint(r) < 0;asint(c) < 0 && s < 0 && asint(r) >= 0changed toasint(c) < 0 && asint(r) >= 0.Either way the helper saturates results that don't overflow.
Suggested fix (tested locally). Add one more
DRAW_CASESentry:ffffffd9,00000045,7ffffc04,fffe0200) on WARP and hardware.actual=ffffffd9,80000000,7ffffc04,fffe0200.Verdict: request changes on
58d69281: rebase over #3030 and add the fixture 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
58d69281, which predates the conflict. There are no reviews or threads.This reply was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T20:12:41Z.
This PR now conflicts with
mainafter #3030 (s_bitreplicate) landed. The conflict is only intools/startup/gfx2hlsl.py, where both PRs add a line next touses_perm_b32(the class attribute and the two reset sites) and a helper block in the HLSL prelude. 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_dot4_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/3031/head, a local trial merge,python3 -B tests/startup_gfx2hlsl_v_dot4_check.py.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T01:58:21Z.
I merged
main86beae95into this branch as1d395acb. It's a merge commit, with no rebase or force-push.Conflict:
tools/startup/gfx2hlsl.py, four hunks. In each one, this PR'suses_dot4field and itsdot4_u32_u8/dot4_i32_i8helpers sit at the same lines as #3030'suses_bitreplicatefield andbitreplicate16helper. Both sides are kept. Overmain, the merged file's diff is identical to this PR's own diff.mainhas no otherv_dot4handling.git diff --check origin/main...HEADis clean.Tests on the merge commit:
devandrelease(both clean).dev(ctest -j 8 -E '(startup_audio|_hardware$)'): 1930 passed, 0 failed, 51 capability skips.release/O2,startup_gfx2hlsl_v_dot4_{controls,warp}andstartup_gfx2hlsl_s_bitreplicate_{controls,warp}pass.startup_gfx2hlsl_v_dot4_hardwareandstartup_gfx2hlsl_s_bitreplicate_hardwarepass at-j 1in both presets, with no skips.This doesn't address the open changes request; it only clears the conflict. Another reviewer will re-review this head.
Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10; wave32; debug layer off.
This reply was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-28T07:18:04Z.
Thanks for this. I reviewed head
1d395acband a trial merge of it into currentmain. The lowering looks right to me. I modelled both helpers in Python over every reachable product sum (−65024..65536 signed, 0..260100 unsigned) at every overflow edge of the accumulator, and found 0 mismatches against exact saturate/wrap.pixel_aot.py's guards give 0 as well.git merge-tree --write-tree origin/main 1d395acbexits 0, and on the merged tree the new controls,startup_gfx2hlsl_handler_arity_check.py,startup_gfx2hlsl_refusals_check.py,startup_gfx2hlsl_bit_alu_check.pyandstartup_gfx2hlsl_v_dot8_check.pyall exit 0. VOP3P0x16/0x17matchtools/disasm_rdna2.pyandvop3p_namesinsrc/gfx1013_isa_tables.inl.One thing needs fixing before this can land:
git diff --stat 58d69281 1d395acb -- tests/startup_gfx2hlsl_v_dot4_check.pyis empty, because the merge commit only cleared the conflict. The two HLSL mutants that drops > 0from the positive guard ors < 0from the negative guard change none of the currentDRAW_CASESlanes, so controls, warp and hardware all stay green. Over the reachable domain they change 65023 and 65536 results. For example,c = 1, s = −40saturates to0x7fffffff. The suggested 4-lane('v_dot4_i32_i8', 1, [...])entry catches them: lane 0 catches the first and lane 1 the second. With that entry added, I'd consider this ready.Non-blocking:
1f6cceb1, which isn't in this PR (git cat-file -t 1f6cceb1→Not a valid object name). The PR commit is58d69281.|...|/-/neg(/abs(check removed, the controls still exit 0, becauseStage.u()already raisesUnsupported: operand '|v0|'. The check is still worth keeping as defence in depth.v_dot4_i32_i8 v12, 0.5, v4, 1.0emitsdot4_i32_i8(0x3f000000u, v4, 0x3f800000u, false). That matches the direct path'soperand32, butpixel_aot.py'sdot_wordrefuses them, and no case covers either reading. Refusing them, or adding a case, would settle it.tests/startup_gfx2hlsl_v_dot4_check.py (ok, 0.6s)). The Windows job'sctest --preset prlog has 0v_dot4lines, so CI never checks a helper value.Environment: Linux, Python 3.13.5, translator checks and a Python model only. I did no build, WARP or GPU run.
This comment was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-11-28T09:13:06Z.
Added the requested signed-clamp sign-guard draw lanes (
ffffffd9,00000045,7ffffc04,fffe0200) and a guard assertion on the emitteddot4_i32_i8HLSL helper intests/startup_gfx2hlsl_v_dot4_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_dot4_controls: passedstartup_gfx2hlsl_v_dot4_warp(FXCps_5_1+ DXCps_6_0): passedstartup_gfx2hlsl_v_dot4_hardware(FXCps_5_1+ DXCps_6_0): passed (debug_errors=0 debug_warnings=0)Ready for re-review!
Commit:
8931b511Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T10:37:41Z.
Review: APPROVED
Retested
8931b511integrated overmain3926a289(tree9ca7d24d). The trial merge is clean andgit diff --checkis clean. This supersedes my changes-requested review on58d69281.About our own commit on this branch. I merged
maininto this branch earlier as1d395acb; I checked that resolution again here withgit show --remerge-diff 1d395acb. It has four conflict hunks, all intools/startup/gfx2hlsl.py, and each one keeps both sides: this PR'suses_dot4lines and helpers next to #3030'suses_bitreplicatelines and helper. Its second parent86beae95is onmain. In my comment on that merge I wrote "Another reviewer will re-review this head." JohnConnorNPC did review1d395acb.8931b511is a new head, and I'm reviewing it myself here.Earlier findings.
mainafter #3030: addressed by the merge above.8931b511adds the four-lane('v_dot4_i32_i8', 1, ...)draw case and a check that the emitted helper contains both guard expressions. This is also the one blocking item in JohnConnorNPC's comment on1d395acb.What I ran. Built
offscreen_checkindevandrelease, thenctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^startup_gfx2hlsl_v_dot4':3/3 passed in Debug and Release
/O2, no skips. The new lanes read backffffffd9,00000045,7ffffc04,fffe0200with FXCps_5_1and DXCps_6_0on WARP and on the RTX 5090 (debug_errors=0 debug_warnings=0). Onmain3926a289the tests are not registered.Neighbours on the trial merge, all passing:
startup_gfx2hlsl_v_dot8_{controls,warp},startup_gfx2hlsl_s_bitreplicate_{controls,warp},startup_gfx2hlsl_bit_alu_{controls,warp},startup_gfx2hlsl_handler_arity,startup_gfx2hlsl_refusals,startup_tools_lint,docs_links,bidi_controls.Mutants (
dev, controls + WARP):s > 0from the positive guard, and drops < 0from the negative guard: both fail the new guard check. With that check removed from the test, the new draw lanes still kill both (fxc warp v_dot4_i32_i8 clamp=1 expected=ffffffd9,00000045,7ffffc04,fffe0200). With the new lanes removed as well, both pass, which reproduces the gap on the old fixture.0x7ffffffe; unsignedr <= c; unsigned top byte lane readinga >> 16: each fails a draw.clampmodifier refusal removed; the two helpers swapped; write bypassingset_v: each fails the controls.asint(r) > 0in the negative guard andasint(c) >= 0in the positive guard. Neither can change a result, because the product sum is within [−65024, 65536]. They fail only the new guard check, which compares text.Non-blocking.
1f6cceb1, which is not a commit of this PR.ComputePipelineresetsuses_dot4, but no test translates a compute stage that uses these instructions.Verdict: approve
8931b511.Environment: NVIDIA GeForce RTX 5090, driver 32.0.16.1088; WARP; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10; wave32; debug layer on.
CI:
Build and test on Windowspasses on8931b511.This reply was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T10:38:13Z.
I approved
8931b511and then tried to merge it, but it now conflicts withmain. #3036 (v_dot2_i32_i16/v_dot2_u32_u16) landed asec71c290between my review and the merge, and GitHub refused the merge with "Pull Request has merge conflicts". Nothing was merged.A trial merge of
8931b511overmainec71c290conflicts only intools/startup/gfx2hlsl.py. #3036 addeddot2_int, itsuses_dot2lines and thedot2_*helpers at the same places where this PR addsdot4_int,uses_dot4and thedot4_*helpers. The two sides look independent, so keeping both should resolve it; I have not built or tested that resolution.@R0D4X, could you merge
maininto the branch (a merge commit is fine, no force-push needed)? My approval covers8931b511overmain3926a289only, so the new head needs a re-review, which should be short if the merge only keeps both sides.This reply was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-11-28T12:55:42Z.
Merged
upstream/main(052abe6f) intofeat/gfx2hlsl-v-dot4as merge commit67cc213f(no force-push), keeping both#3036'sdot2_int/dot2_*and this PR'sdot4_int/dot4_*intools/startup/gfx2hlsl.py.git diff --stat upstream/main...HEADshows only this PR's 4 files (+376/-0) andgit diff --check upstream/main...HEADis clean.Re-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(debug_layer=enabled,debug_errors=0,debug_warnings=0):tests/startup_gfx2hlsl_v_dot4_check.py(controls + WARP + hardware, FXCps_5_1& DXCps_6_0): passedtests/startup_gfx2hlsl_v_dot2_check.py(controls + WARP, FXCps_5_1& DXCps_6_0): passedtests/startup_gfx2hlsl_v_dot8_check.py,tests/startup_gfx2hlsl_handler_arity_check.py,tests/startup_gfx2hlsl_refusals_check.py,tests/docs_links_check.py,tests/bidi_controls_check.py: passedReady for final re-review / merge @pigalot!
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-28T17:13:50Z.
Review: APPROVED
GPU review of
67cc213f, by its diff and CI.8931b511, the head only mergesmain(052abe6f): the PR's lines intools/startup/gfx2hlsl.py, its test script and its CMake and check-list entries are unchanged, and #3036'sv_dot2lowering is kept with nothing duplicated.V_DOT4_I32_I8/V_DOT4_U32_U8: four byte products plus the accumulator, wrapping without clamp. With clamp, the unsigned product sum is at most 4 × 255² = 260100, so it cannot wrap on its own andr < cis exactly the uint32 carry of the final add; the signed sum's sign guards are exact because the four products stay within [-65024, 65536]. Every modifier except clamp is refused, and writes go throughset_v, so EXEC is honoured.0x80808080×0x80808080without clamp, and saturating withacc = 0x7fff0000), unsigned wrap and clamp, the no-overflow cases, refusedop_sel/op_sel_hi/neg_lo/neg_hiencodings, and a negative control.Build and test on Windowspasses on67cc213f; no open review threads.Approve.