shader: lower v_mul_lo_u32 in pixel_aot #672
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/678"
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 Holastor on 2026-11-22T19:35:09Z.
Summary
Support 32-bit vector integer arithmetic and bitwise operations in
tools/pixel_aot.py:v_lshl_add_u32((src0 << (src1 & 31u)) + src2)v_lshl_or_b32((src0 << (src1 & 31u)) | src2)v_and_or_b32((src0 & src1) | src2)v_or3_b32(src0 | src1 | src2)v_add3_u32(src0 + src1 + src2)v_mul_lo_u32(src0 * src1)Motivation & Context
In the RDNA 2 (GFX1013) ISA, these 3-source and 2-source vector ALU operations are among the most frequently used instructions in shader resource addressing and bitfield packing:
v_lshl_add_u32ranked #11 in the missing opcode roadmap (23,000 occurrences across 4,132 shaders).v_or3_b32ranked #29 (14,308 occurrences across 2,977 shaders).v_mul_lo_u32ranked #30 (93,540 occurrences across 2,958 shaders).Adding them directly to
pixel_aot.py'sINTEGERdispatch table automatically enables lowering acrosspixel_aot.py, provides pattern coverage inscan_unsupported_shaders.py, and unlocks over 4,500 distinct shader programs.Changes
tools/pixel_aot.py:mul_lo_u32(arity 2,{0} * {1}).add3_u32(arity 3,{0} + {1} + {2}).lshl_add_u32(arity 3,({0} << ({1} & 31u)) + {2}).lshl_or_b32(arity 3,({0} << ({1} & 31u)) | {2}).and_or_b32(arity 3,({0} & {1}) | {2}).or3_b32(arity 3,{0} | {1} | {2}).tests/pixel_aot_check.py:v256).Verification
Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-22T21:03:26Z.
Thanks for the detailed review and verification on the RX 9070 XT @thepatrickworld!
Updated in e9022f26:
S0 & S1) | S2\ on row \(0x0f, 0xf0, 0xff)and \_or3_b32.Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-22T20:52:55Z.
Verification: #678
shader: lower 32-bit vector integer ALU operationsHead
c5b0a9e7, merged withmainat the time of the run. Two files:tools/pixel_aot.py(+6) andtests/pixel_aot_check.py(+23).What it changes
Six entries added to the ALU table:
mul_lo_u32{0} * {1}add3_u32{0} + {1} + {2}lshl_add_u32({0} << ({1} & 31u)) + {2}lshl_or_b32({0} << ({1} & 31u)) | {2}and_or_b32({0} & {1}) | {2}or3_b32{0} | {1} | {2}I emitted the HLSL for each and checked it against the RDNA 2 ISA description:
lshl_*shift byS1.u[4:0],and_oris(S0 & S1) | S2,add3andor3are three-operand,mul_lo_u32keeps thelow 32 bits. All six are correct, and the explicit
& 31umatches the 5-bit shift field.Precedence and casting are fine, because
int_operandonly ever produces atoms —asuint(x),asint(x),<n>u, or the bits of a float literal — so no template can be captured by a largerexpression. A register and an immediate produce the same shape:
v_lshl_add_u32 v12, s44, s45, s46and
v_lshl_add_u32 v12, s44, 2, 7differ only in the atoms.One fragility worth a pair of parentheses, not a bug today:
"{0} * {1}"is unparenthesised. It isharmless while operands are atoms, but
int16_operandalready returns composed expressions such as(asint(x) << 16) >> 16, so the day a narrowing operand reaches this table the multiplication willassociate wrongly and silently.
Environment
Windows 11 25H2 (build 26200.9711), MSVC 19.44.35230, DXC 1.9.2602.17, AMD RX 9070 XT (vendor
1002, device7550), driver 32.0.32029.2010. Python 3.15.2 in the worktree venv.Commands and output
No pre-existing suite changed behaviour.
Negative control: I replaced
mul_lo_u32with{0} + {1}in the translator and re-ran^pixel_aot_hardware$:So the added assertions do catch a wrong template.
The reserve: no draw, and no compilation either
None of the six forms is observed by a draw. There is a fixture named
check_lshl_add_u32_draw,and it is easy to count it as cover — I did at first. It does not: it runs
s_lshl1_add_u32throughs_lshl4_add_u32, which are SOP2 scalar forms taking two operands, notv_lshl_add_u32, which isVOP3 with three.
v_lshl_add_u32appears nowhere in the file outside the new block.The new block calls
translate()but nevercompile_shader(). Every assertion is a substring matchon HLSL that is never handed to DXC. A template that produces uncompilable code — a wrong type, an
unresolved operand, a mismatched arity that still formats — passes all six.
must_rejectalso catchesKeyError, not justValueError, so a negative control can succeed forthe wrong reason: a form absent from the table raises
KeyErrorand looks like a rejected arity.What I would add
A render fixture modelled on the existing one, with
integer_export=Trueso the comparison isbit-exact. Two four-channel programs cover all six forms:
The
(0x0f, 0xf0, 0xff)row is the one that kills a wrong parenthesis:(S0 & S1) | S2gives0xffwhile
S0 & (S1 | S2)gives0x0f.For the shift mask, the only case observable at runtime is an immediate above 31:
v_lshl_add_u32 v12, 1, 33, 0must yield2. Without the& 31u, DXC folds1u << 33uto zero onconstants, so a render catches it where the string comparison does not.
What this does not prove
v_lshl_or_b32with a shift of exactly 32.v_or3_b32 v256) checks a boundary, not the maximum theencoder allows.
AI-assisted; runs executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-22T22:36:41Z.
Validated on
e9022f2— the render fixture does the jobctest --preset dev --no-tests=error -R "^pixel_aot_"gives 22/22 on RDNA4 (RX 9070 XT, driver 32.0.32029.2010, MSVC 19.44.35230, DXC 1.9.2602.17).The important part is that you moved from "the translator emits something" to "the GPU returns the right bits", so I mutated every lowered operation the new fixture claims to cover:
So five of the six are load-bearing, and
(0x0f, 0xf0, 0xff)does exactly what it was for:0xffwith the right precedence,0x0fwith the wrong one.M1 is not a hole
mul_lo_u32without the parentheses survives all 22 tests, and that is correct rather than a gap: the translator always emits the expression into adst = expr;, so({0} * {1})and{0} * {1}produce the same code. The parenthesis is defensive, not observable. I am not asking for a test that cannot exist — a fixture only reaches it if the lowering is ever embedded in a larger expression, and then it will matter.Two notes, neither blocking
check_e64_render, so the total stays at 22. Nothing wrong with that, but a future reader will look forvalu_int32inctest -Nand not find it.& 31uis pinned. Mutating it fails 6 tests, so it holds — worth keeping in mind if a later refactor folds the twolshlforms together.Nothing blocking left from my side on this PR.
AI-assisted; runs executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T05:04:35Z.
#766 landed five of the forms in this branch.
v_mul_lo_u32is still separate and also appears in #532. Please coordinate with #532 so there is one implementation of the low product. Your RX 9070 XT precedence and count-masking controls are useful independent evidence for the merged forms. For the remaining multiply, keep a full-width case where nonzero high product bits must be dropped and make sure a wrong expression changes the result.Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-23T10:22:43Z.
Rebased onto main (
0306f88) following the merge of #766 and addressed review feedback:Coordination with #532:
VALU Independent Evidence Controls Preserved:
Full-width High-bit Dropping & Wrong Expression Detection:
Verification
powershell python -B tests/pixel_aot_check.py python -B tests/rdna2_tools_check.py python -B tests/docs_links_check.py python -B tests/bidi_controls_check.py python -B tests/pso_readiness_check.py python -B tests/form_coverage_check.pyAll checks passed cleanly.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T11:09:35Z.
Both Windows jobs failed on the positive wrap case. I reproduced it on WARP and corrected the three miscomputed reference words. The full-width product of
0x12345678 * 0x9abcdef0is0x0b00ea4e242d2080, so channel 0 must be0x242d2080. The replacement-of-multiply mutation still fails. The updated head93c853fpassed the integer draws on RTX 4060 Laptop and WARP, plus LLVM 15 encoding/decoding and the Python checks. Waiting for the two Windows jobs on this head.Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-23T15:34:57Z.
Post-merge check of
527a255on RDNA4, and what the new VALU fixture does and does not pin. Measurements plus arithmetic.Environment and results
check_valu_int32_drawruns throughcheck_e64_render, sopixel_aot_e64_*is where it lands, and both are green here: the nine-quadruplet programs and the mutation control fired on RDNA4, not only on WARP and the RTX.What the one line does
Before this commit
v_mul_lo_u32was not inINTEGERand fell to the genericUnsupported instruction 20: v_mul_lo_u32 …path (tools/pixel_aot.py:3518at527a255^1), so this adds support rather than correcting an expression. What it emits isasfloat((asuint(a) * asuint(b)))— uint-typed, so the wrap is defined — and an immediate stays typed (… * 3u). Operand modifiers are refused before reaching it (Unsupported 32-bit scalar operand -s44), so the row cannot be reached with a sign.The real risk on that line is its 24-bit neighbour,
mul_u32_u24(:565): copying that row would givemul24_u32(...). The fixture catches that onwrap-maxandwrap-large-nonzero-highonly.overflow-addis not discriminating:0x40000000 * 0x80000000is0x0under both*andmul24_u32, and so are the three other channels of that case. I recomputed all eight expected words mod 2^32 and they are right.Also worth knowing when reading the coverage gain: of the six opcodes the programs exercise, five (
add3_u32,or3_b32,and_or_b32,lshl_or_b32,lshl_add_u32) were already inINTEGERbefore the merge (:555-561at527a255^1). Most of the 123 added test lines cover pre-existing code.Test strength
v_mul_lo_u32→v_add3_u32(tests/pixel_aot_check.py:10083), and it lives in the draw path, so the Windows job is what exercises it. No mutation exists forlshl_add/lshl_or(& 31u), for theand_or_b32precedence, or foradd3/or3.oracle-mismatch-*cases are not mutations: they show the comparator rejects deliberately wrong words, not that a wrong lowering would be caught.cmp64_expected(:1955) orswap_ops_reference(:12221) elsewhere in the same file. A wrong convention inside the tool would pass the literals and the GPU readback alike; the readback is the only independent oracle.AI-assisted; runs executed locally. The arithmetic and the diff reading come from a separate review pass and were recomputed here at
527a255.