shader: lower compute v_med3_u32 and v_med3_i32 #1570
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1577"
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-24T14:32:40Z.
Change
Refs #1546. This lowers
v_med3_u32andv_med3_i32in the compute translator (tools/compute_store_aot.py). Each returns the median of src0, src1 and src2, compared unsigned or as two's complement.v_med3_u32max(min(a, b), min(max(a, b), c))v_med3_i32asint(...)of each source, wrapped inasuint(...)This is the pattern LLVM 15 selects these instructions for (
IntMed3PatinSIInstructions.td, llvmorg-15.0.7), with smin/smax and umin/umax. The change adds twoALUentries and appends both opcodes to the three-source matcher group,(v_mad_u32_u24|v_med3_u32|v_med3_i32).The fixture and controls are in a new
tests/compute_alu_med3_check.py. It imports the helpers oftests/compute_store_check.pyand does not change that file.Fixture
READ_MED3. It is a variant ofREAD_COMPUTE. With w = the lane's source word, a = w << 9 and cap =params[0].y=0x3a5c0f1d, it runs:0x80000000is the largest value when compared unsigned and the smallest when compared signed, so the two medians differ in every lane. The controls also assert thata,capand0x80000000each win as the median in some lane.The expected words come from a Python reference that sorts the three words; it does not use the lowering. Lane 0 is worked by hand:
0xc359730e.Checks that must fail:
_u32compared signed;_i32compared unsigned;_i32lowered unsigned,_u32lowered signed, minimum for every median, and_u32asmax(a, b).Controls refused with the existing messages:
clamp,op_sel,-v2and|v2|;v[2:3]range;v_med3_u16,v_med3_i16andv_med3_f32;v256destination;The new CTest is
compute_store_aot_alu_med3_${adapter}, aftercompute_store_aot_mubuf_vector. A "Three-source median" subsection is added todocs/experiments.md.Verification
Commit
6c0e5380(main) plus this change,devpreset, Windows 11 Pro build 26300.9974, DXC 1.8.2502.11.1002:73ff), driver 32.0.21045.29003, debug layer enabledThese also pass with the change:
compute_store_checktranslator controls;draw-guard-readon WARP (32 dispatches, mismatches 0);draw-f32on WARP;tests/docs_links_check.py,tests/bidi_controls_check.pyandgit diff --check.I did not run the LLVM 15
binarymode, because it needs LLVM 15 and libLLVM.Notes
Unsupported compute instruction: …rather thanUnverified ALU operand, the same as forv_mad_u32_u24. I left the matcher unchanged.ALU_EXPRESSION_LIMITquickly. The fixture's stored word is 928 characters.Checklist
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T15:39:35Z.
Review: COMMENTED
Peer review at
9cea0b18(shader: lower compute v_med3_u32 and v_med3_i32): looks good, no blocking issues found.Code & Semantics Review
tools/compute_store_aot.py:v_med3_u32andv_med3_i32lower tomax(min({0}, {1}), min(max({0}, {1}), {2}))(unsigned) andasuint(max(min(asint({0}), asint({1})), min(max(asint({0}), asint({1})), asint({2}))))(signed), matching the 3-sourceALU_SOURCEguard alongsidev_mad_u32_u24withdst <= 255, data-only usage, andALU_EXPRESSION_LIMIT.tests/compute_alu_med3_check.py: exercises VGPR, SGPR, inline constant (-1), and0x80000000literal operands, equal-operand tie cases, hand-worked lane 0 (0xc359730e), modifier/16-bit/f32/unverified-operand rejections, plus 5 wrong references and 4 DXC-compiled HLSL mutations indraw.CMakeLists.txt&docs/experiments.md: registerscompute_store_aot_alu_med3_${adapter}and documents the lowering and controls.Local Verification
python3 tests/compute_alu_med3_check.py controls— passedllvm-mc-19 -arch=amdgcn -mcpu=gfx1013 -show-encoding&-mcpu=gfx1030onv_med3_u32/v_med3_i32forms — passedpython3 tests/docs_links_check.py(16 Markdown files, 344 links) — passedpython3 tests/bidi_controls_check.py(1253 tracked files) — passed--preset devDebug &--preset release/O2):ctest --preset dev -R '^compute_store_aot_alu_med3_warp$'(within 41/41 compute-store suite) — 41/41 passed (compute_store_aot_alu_med3_warp3.73s)ctest --preset release -R '^compute_store_aot_alu_med3_warp$'(within 41/41 compute-store suite) — 41/41 passed (compute_store_aot_alu_med3_warp3.85s)AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T16:09:26Z.
Resolved the main conflict in
20d2ef06by retaining both opcode sets in the three-source matcher and both documentation sections. Windows Release passed 6/6 across MED3, MIN3/MAX3 and XOR3 on RTX and WARP, with no skips.