shader: lower gfx1013 integer multiplies in pixel_aot #532
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!532
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-532"
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?
@Vonsek on GitHub · 2026-11-22 09:58 UTC · original
Vonsek:pixel-aot-int-multiply→main· +293 −3 · 6 files · 1 commits · draftChange
tools/pixel_aot.pynow lowers the gfx1013 integer multiply family. Each form becomes one HLSLuintexpression in the existingINTEGERtable (added through a separateINT_MULTIPLYtable):v_mul_lo_u32v_mul_hi_u32v_mul_hi_i32v_mul_u32_u24v_mul_i32_i24v_mul_hi_u32_u24v_mul_hi_i32_i24v_mad_u32_u24v_mad_i32_i24v_mad_u32_u16v_mad_i32_i16uint, which gives the same low word and avoids signed overflow in the shader.mul_hi_u32, which builds bits [63:32] from 16-bit limbs, so the shader does not need the optional 64-bit integer feature.mul_hi_i32is the unsigned high word minus each operand that the other's sign bit weights by 2^32. The helpers are emitted once, and only when a high-word form is used.int_operandpath, so float source modifiers,clamp,op_sel, a wrong operand count, a 33-bit immediate, unwritten registers, reads of outstanding samples or scalar loads and the whole-quad mask are rejected.v_mul_lo_u16,v_mul_lo_i32,v_mad_u64_u32,v_mad_i64_i32and the SDWA and DPP forms stay rejected. LLVM 18 assemblesv_mul_lo_i32for gfx1013, but the RDNA 2 reference and LLVM 15's gfx1013 form list do not include it.tools/scan_unsupported_shaders.pyderives its supported list frompixel_aot.INTEGER, so it recognises the new forms without a separate list (tests/pso_readiness_check.pyasserts this for two forms and two rejected neighbours).Tests:
tests/pixel_aot_check.pyaddsintmul_program(k). It computes all 15 forms from SGPR, VGPR, inline (-7) and VOP3 SGPR-source operands, then exports the four bytes of resultkthroughv_cvt_f32_ubyte0-3, so each channel is an exact integer 0..255.intmul_referenceis an independent Python model of the ISA definitions. Set 1 multiplies a negativeaby a positiveb; set 2 a positiveaby a negativeb. Each has bit 23 set in a negative 24-bit operand and bits above 23 that the 24-bit forms must drop, and bit 15 ofbdiffers between the sets.draw-intmul, registered aspixel_aot_intmul_hardwareandpixel_aot_intmul_warp(60 s timeout,SKIP_RETURN_CODE 77on hardware,FORM_COVERAGE_RECORDset). It runs 15 compiles × 2 input sets, then nine mutations on set 1 that must reportpixel_mismatch:v_mul_lo_u32↔v_mul_hi_u32both ways,v_mul_hi_i32→v_mul_hi_u32,v_mul_i32_i24→v_mul_u32_u24,v_mul_hi_i32_i24→v_mul_hi_u32_u24,v_mad_i32_i24→v_mad_u32_u24,v_mad_i32_i16→v_mad_u32_u16, and two that drop the 24-bit truncation:v_mul_u32_u24→v_mul_lo_u32andv_mul_hi_u32_u24→v_mul_hi_u32.pixel_aot_predicate_rounding_*is unchanged.mul_hi_u32alone for the unsigned 24-bit high word, both for signed); the rejections listed above; and a Python check that each mutation changes the set 1 word.tests/pixel_aot_check.py binaryround-trips the fixture for results 0 and 14 throughllvm-mcand the disassembler.tests/form_coverage_check.pyasserts the 15 forms (4 VOP2 and 11 VOP3) are counted in bothgfx1013.tsvandrdna2.tsv(exactly 15 more covered forms), and that the rejected neighbours stay out.docs/experiments.md#offline-pixel-shader-recompilationdescribes the forms, the fixture, the exceptions to normal patterns and the new tests.Verification
tests/pixel_aot_check.py(controls) andtests/pixel_aot_check.py binary llvm-mc llvm-objcopy libLLVM.so.1pass;form_coverage_check,pso_readiness_check,rdna2_tools_check,shader_probe_check,ffx_dispatch_aot_check,docs_links_checkandbidi_controls_checkpass;git diff --checkis clean.tools/pixel_aot.pyfrommain,tests/pixel_aot_check.py,tests/form_coverage_check.pyanddraw-intmulfail withValueError: Unsupported instruction 22: v_mul_lo_u32 v20, s44, v18, and the scanner reportsv_mul_lo_u32andv_mad_u32_u16as unsupported.uintsemantics (clang 18), matchintmul_referencefor all 15 results on both input sets and on 900 further cases with random and edge words (0, 1, 0x7fffffff, 0x80000000, 0xffffffff, 0x00800000, 0x00ffffff, 0xff800000, 0x7fff, 0x8000, 0xffff), including subnormal and NaN patterns. Thedraw-intmulmode ran end to end with a pass-through compiler and a renderer stand-in that evaluates the HLSL the same way: 30 draws matched and all nine mutations reportedpixel_mismatch.intmul_referenceon an NVIDIA GeForce RTX 5080 (driver 32.0.16.1692) and on WARP, including results 7 to 10, whose words are subnormal patterns on set 1 and NaN patterns on set 2: neither adapter flushed or changed them betweenasfloatandasuint. All nine mutations reportpixel_mismatchon both adapters.ctest --preset dev --no-tests=error -R '^pixel_aot_(intmul_(hardware|warp)|hardware|warp)$' -Vat7327767on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100: 4/4 passed.pixel_aot_intmul_hardwaretook 11.8-12.8 s andpixel_aot_intmul_warp2.9 s, well under the 60 s timeout;pixel_aot_hardwareandpixel_aot_warpstill pass. The D3D12 debug layer was not available. The fullctest --preset dev --no-tests=errorpassed 245/245, withbvh_wave64_hardware,bvh_wave64_warpandwave_shuffle_warpskipped.Evidence and follow-up
floatbetweenasfloatandasuint. DXC should fold that pair of bitcasts. If an adapter flushes or changes them, the draw for results 7 to 10 will report a mismatch and identify the problem; the other 11 results are normal patterns.INTEGERtable and listsv_mad_u32_u24,v_mad_u32_u16andv_mul_lo_u32as rejected neighbours in its controls and inform_coverage_check.py. This PR adds its forms through a separateINT_MULTIPLYtable so the table edits do not overlap. Whichever lands second must drop those three names from the other's rejection lists.v_mad_u64_u32/v_mad_i64_i32(64-bit result with a carry-out mask),v_mul_lo_u16, the SDWA 24-bit multiplies, andop_selonv_mad_u32_u16/v_mad_i32_i16.@R0Y00 on GitHub · 2026-11-23 04:51 UTC · original
Current main already includes the four plain 24-bit multiply forms. The full-width
v_mul_lo_u32,v_mul_hi_u32andv_mul_hi_i32are still candidates. Please update the PR to focus on those three, retain the distinguishing signed/unsigned and wraparound readbacks, and coordinate the overlapping low product with #678.@JB2WIN on GitHub · 2026-11-24 06:03 UTC · original
@Vonsek, I'd like to take
v_mad_u64_u32andv_mad_i64_i32, which your PR lists as still uncovered. I'll open a separate PR with its own table and mode, so neither theINTEGERnor theINT_MULTIPLYtable changes. The PR will cover the 64-bit result in a register pair and the carry-out lane mask. If you'd rather keep these in #532, tell me and I'll drop them.AI-assisted (Claude Code).
@tedin7 on GitHub · 2026-11-27 09:37 UTC · original
This PR now conflicts with
main. Conflicting files:CMakeLists.txttests/form_coverage_check.pytests/pixel_aot_check.pytools/pixel_aot.pyCould you merge
maininto your branch (a merge commit, no force push needed) and resolve these? Thank you.AI-assisted; commands listed were executed locally. (
git merge-tree origin/main <head>)@Leyukaka on GitHub · 2026-11-29 10:10 UTC · original
@Vonsek status of the table against main
c3259f27(tools/pixel_aot.py):Already on main:
v_mul_lo_u32:INTEGERtable, line 873 (f7d0e897, merged with #678 as527a2557).v_mul_u32_u24,v_mul_i32_i24,v_mul_hi_u32_u24,v_mul_hi_i32_i24: lines 869-872 (#542,bbebcad0).mul_hi_u32/mul_hi_i32HLSL helpers:SALU_HELPERS["scalar_mul_hi"], lines 936-947 (#604,7cfe3b03), used fors_mul_hi_u32/i32(SCALARtable, lines 1753-1754) and byv_mad_u64_u32/v_mad_i64_i32(#1278,c919ad07). This branch'sINTEGER_HELPERSdefines functions with the same two names, so the branch could reuse that helper.Not on main:
v_mul_hi_u32,v_mul_hi_i32(vector).v_mad_u32_u24,v_mad_i32_i24,v_mad_u32_u16,v_mad_i32_i16.tests/pixel_aot_check.py:7631currently expectsv_mad_u32_u16andv_mad_i32_i16to be refused.Of the three forms named in the 2026-11-23 comment here, only
v_mul_hi_u32andv_mul_hi_i32are left. Could you narrow the branch to what is still missing and merge main? It conflicts inCMakeLists.txt,tests/form_coverage_check.py,tests/pixel_aot_check.pyandtools/pixel_aot.py.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.