shader: lower RDNA2 s_absdiff_i32 in pixel_aot #618
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/624"
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 stan495 on 2026-11-22T16:19:39Z.
Translate RDNA2 32-bit signed scalar absolute difference instruction
s_absdiff_i32intools/pixel_aot.pyasasuint(abs(asint({0}) - asint({1})))with scalar condition codeNONZERO(dest != 0u).Update opcode definitions in
tools/disasm_rdna2.py(0x2c), scanner recognition intools/scan_unsupported_shaders.py, and synthetic opcode decoding tests intests/rdna2_tools_check.py. Add static checks, rejection controls, form coverage assertions intests/form_coverage_check.py, and RGBA32_UINT integer readback draw checks verifying signed absolute differences and SCC nonzero conditions across positive difference, negative difference, zero difference (clearing SCC), double-negative inputs, mixed-sign inputs, andINT_MINboundaries intests/pixel_aot_check.py.Change
Translates the scalar 32-bit signed absolute difference instruction
s_absdiff_i32(SOP2 opcode0x2c) in pixel shaders to desktop HLSL, and advances scalar ALU coverage inpixel_aot.0x2cass_absdiff_i32intools/disasm_rdna2.py.s_absdiff_i32intools/scan_unsupported_shaders.py.s_absdiff_i32intools/pixel_aot.pyasasuint(abs(asint({0}) - asint({1})))and updatesSCC = (dest != 0u).tests/rdna2_tools_check.pywith synthetic disassembly tests for0x2c.s_absdiff_i32from themust_rejectlist intests/pixel_aot_check.py, adding static translation assertions, rejection controls for invalid types/arities/vector operands, and integer render target draw tests (check_absdiff_i32_draw).("SOP2", "s_absdiff_i32")coverage intests/form_coverage_check.pyand records rejection controls for unsupporteds_absdiff_i64ands_absdiff_u32.docs/experiments.md.Verification
Commit under test:
79a3529ctest --preset dev --no-tests=error -R 'pixel_aot_e64_warp' -V:Passed (3.90s, Microsoft Basic Render Driver vendor 1414 device 008c, driver 10.0.26100.9711, debug layer enabled).
python -B tests/rdna2_tools_check.py: Passed (51 tests).python -B tests/form_coverage_check.py: Passed.python -B tests/pixel_aot_check.py: Passed.python -B tests/docs_links_check.py: Passed (122 links).python -B tests/bidi_controls_check.py: Passed (557 files checked).Evidence and follow-up
All fixtures are synthetic source-built programs following the project guidelines.
Negative controls verify that:
oracle-mismatchreports a pixel mismatch when the expected readback or SCC does not match.s_absdiff_i64), types (s_absdiff_u32), operand counts (1 or 3 operands), and invalid vector source/destination operands (v12,v13) fail translation.Checklist
AI-assisted: yes
Imported from R0Y00/Xbox2Windows. Originally posted by MarlomMedeiros on 2026-11-22T18:02:43Z.
Review: COMMENTED
Community review + independent run on a second adapter, since the PR reports WARP only.
Environment
79a3529on base7b55abcctest --preset dev --no-tests=error -R '^pixel_aot_(e64|u32_from_f32)_(warp|hardware)$' -V: 4/4 passeddebug_errors=0 debug_warnings=0,pixels=4096 max_absolute_error=0tests/pixel_aot_check.pycontrols,tests/form_coverage_check.py,tests/rdna2_tools_check.py(51 tests, 1 skipped) and the LLVM 15.0.7 binary round-trip all passReview notes
asuint(abs(asint({0}) - asint({1})))matches the ISA even at the overflow boundary: LLVM's ownmoveToVALUexpansion ofS_ABSDIFF_I32(llvm/llvm-project#167691) emitsv_sub_u32+v_max_i32(v, -v), which is exactly wrap-then-abs.INT_MAX - INT_MINtherefore yields 1 on real hardware, identical to this emission.abs(INT_MIN)returning INT_MIN bits in HLSL agrees with the hardware's 0x80000000 result, and theint-min-zerodraw case pins it.scc=0path (throughs_cselect), sign-mixed inputs and an oracle mismatch, on the lossless integer readback. Reject controls cover the i64/u32 spellings, operand counts and vector registers.NONZEROSCC is the right predicate:s_absdiffsets SCC iff the result is nonzero, matching the neighbouringabs_i32entry.7b55abcsits ~10 commits behind currentmain(8f57366); a rebase may be asked for, but the single-table-entry change should merge trivially.No blockers found.
AI-assisted: yes. All reported checks ran locally on the adapter and driver listed.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-22T18:00:37Z.
@stan495 Independent AMD (RDNA4) result on
79a3529, plus one coverage observation. Measurements only, no code change.Environment
debug_layer=unavailable(Tools.Graphics.DirectXisNotPresenthere)79a3529.Commands
Observed
23 tests, 23 passed, 0 failed, 0 skipped (111.87 s):
rdna2_tools_check, the eleven_hardwaresuites and their eleven_warpcounterparts.pixel_aot_hardwarealone: 47 draws, 46 atpixels=4096and one atpixels=64, every onemax_absolute_error=0; same split on WARP.The six draw cases the fixture registers are
positive-diff(10, 4) → 6,negative-diff(4, 10) → 6,zero-diff(7, 7) → 0 with SCC clear,both-negative(-10, -4) → 6,mixed-signs(-5, 8) → 13 andint-min-zero(0x80000000, 0) →0x80000000. All six drew with zero absolute error on both backends.One coverage gap in the
INT_MIN boundariescaseThis is about what the fixture proves, not about the lowering being wrong.
The lowering is
asuint(abs(asint(a) - asint(b)))withNONZERO=r != 0u. Both the subtraction andabswrap in 32 bits, which matches the documented pseudo-codeD = abs(S0 - S1). There are, however, two possible readings of that pseudo-code once the difference exceeds2^31:0x7fffffff,0x800000000x000000010xffffffff0x80000000,0x000000010x7fffffff0x80000001Every case in this PR has
|a-b| ≤ 2^31.int-min-zerois exactly on the boundary, where both readings agree — so it provesabs(INT_MIN)survives, which is useful, but it cannot distinguish the two semantics above. Nothing here is wrong; the fixture simply does not yet have a case in the(2^31, 2^32)window.Two additions would make the claim discriminating:
(0x7fffffff, 0x80000000)and(0x80000000, 0x00000001). Expected values are known for each reading, so a single draw decides it. Which one RDNA2 actually implements is not measurable on this machine — that needs Scarlett hardware, so the fixture would be recording an assumption rather than a measurement either way.SCC does not diverge:
|a-b|maxes at0xffffffff, never 0, soNONZEROis identical under both readings.Minor, unverified:
abs()on a signed int is the only place in this table that uses the HLSLabsrather than an explicit(asint({0}) < 0 ? (0u - {0}) : {0})ternary. If DXC emitsllvm.abswithis_int_min_poison, theint-min-zerocase would rest on optimiser behaviour rather than on the lowering. Worth checking in the generated DXIL if that case is meant to be a guarantee.Also: this PR is currently in conflict
GitHub reports
mergeable: false,mergeable_state: dirtyagainstmain, so this run measured a head that cannot merge as-is. The conflict is mechanical (nothing in the draw results suggests a semantic clash) but a rebase will be needed, and the test numbers above should be re-read against the rebased head.AI-assisted; runs executed locally. The coverage observation was produced by a separate code review and re-verified by independent computation before posting.
Imported from R0Y00/Xbox2Windows. Originally posted by stan495 on 2026-11-23T01:07:36Z.
Thanks @thepatrickworld and @MarlomMedeiros for the detailed reviews and independent hardware runs on RX 9070 XT and RTX 5070!
I have rebased the PR onto current
main(67edabe) to resolve the merge conflict, and addressed the suggestions:Overflow-wrap boundary tests:
Added the two discriminating cases in the
(2^31, 2^32)difference window tocheck_absdiff_i32_drawintests/pixel_aot_check.py, and updateddocs/experiments.md:("overflow-wrap-max-min", (0x7fffffff, 0x80000000), (1, 1, 0, 0), "pass")(diff yields1,SCC = 1)("overflow-wrap-min-pos", (0x80000000, 1), (0x7fffffff, 1, 0, 0), "pass")(diff yields0x7fffffff,SCC = 1)HLSL
abs()in DXIL:Inspected the disassembly from DXC (
1.9.2602.17): DXC emits an explicit negation and signed maximum (sub i32 0, %difffollowed by@dx.op.binary.i32(37, %diff, %neg)/IMax), matching LLVM'smoveToVALUlowering (v_sub_u32+v_max_i32(v, -v)). It does not emit poison onINT_MIN, guaranteeing0x80000000preservation across two's-complement negation.Verification on rebased head (
4525ac7)ctest --preset dev --no-tests=error -R "^pixel_aot_e64_|^rdna2_tools": 7/7 passed (22.90s, including WARP and hardware draws withmax_absolute_error=0)python -B tests/rdna2_tools_check.py: Passed (50 tests, 1 skipped)python -B tests/form_coverage_check.py: Passedpython -B tests/pixel_aot_check.py: Passedpython -B tests/docs_links_check.py: Passed (122 links)python -B tests/bidi_controls_check.py: Passed (568 files)Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-23T14:19:49Z.
Merged as
3cd9df3, and the merged tree runs green on RDNA4 (native wave64). Measurements only.Environment
debug_layer=unavailable(Tools.Graphics.DirectXisNotPresenthere)The merge changed nothing
Comparing the lines
3cd9df3^1..3cd9df3adds or removes withaeb45daf..9577694gives the same 93 lines, character for character. The merge applied the reviewed head unchanged, so the earlier verification applies to the merged tree as-is.Commands and results
check_absdiff_i32_drawis reached throughcheck_e64_render(tests/pixel_aot_check.py:8812, modedraw-e64at:8862), so thepixel_aot_e64_*entries are the ones that exercise it, notpixel_aot_hardware. Both are green here: the nine quadruplets — includingint-min-zero,overflow-wrap-max-minandoverflow-wrap-min-pos— compare bitwise equal on this adapter throughR32G32B32A32_UINT.What a green run does not settle
check_absdiff_i32_drawcarries no mutation control. The only negative case isoracle-mismatch, a deliberately wrong expected word, which exercises the comparison path but says nothing about whether a different lowering would be caught; the rest of the file recompiles a knowingly wrong variant and demands a mismatch, and this test does not.The lowering also emits
abs(asint(x)), whereabs_i32elsewhere avoidsabs()and writes0u - xprecisely becauseabs(INT_MIN)is the one input for which DXC may assume poison.int-min-zerocompares equal on driver 32.0.32029.2010 — one compiler, one adapter.CI on
3cd9df3is 5/5, including both Windows jobs that were red on4525ac7before the rebase ontoaeb45daf, which contains632e60f(theNameError: name 'draw'fix). That matches the earlier finding that the failure belonged tomainand not to this change.AI-assisted; runs executed locally.