startup: lower v_mad_i32_i16 in gfx2hlsl #3041
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3041"
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-27T10:23:02Z.
What this changes
v_mad_i32_i16(0x375) intools/startup/gfx2hlsl.pyasasuint(asint({0} << 16) >> 16) * asuint(asint({1} << 16) >> 16) + {2}(signed 16-bit low halves multiplied and added to the 32-bit addend, mod 2^32).neg/absencoding bits onv_mad_i32_i16incheck_encoding(), allowslow16_only_von S0/S1 while keeping S2 as a full 32-bit read, and registers the opcode invalu_align4.Tests added
tests/startup_gfx2hlsl_v_mad_i32_i16_check.py: synthetic VOP3A decode viaG.decode(), 216-case evaluation against the emitted HLSL expression,EXECmasking,low16_only_vaccept (S0/S1) and refusal (S2), encoding &Stagerefusals (neg/abs/clamp/mul:2/op_sel/arity), unlowered controls, and FXCps_5_1+ DXCps_6_0offscreen readback draws with negative controls.tests/cmake/startup_gfx2hlsl_v_mad_i32_i16.cmakeandtests/checks/python-linux/startup_gfx2hlsl_v_mad_i32_i16.txt.Verification
Commit:
9c6c38a1on Windows 11 x64 (10.0.26300.9974), MSVC19.44.35230, Windows SDK10.0.26100.0, FXC + DXC1.9.2602.17, D3D12 debug layer enabled (debug_errors=0 debug_warnings=0):ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_v_mad_i32_i16|^startup_tools_lint$': 4/4 passed, 0 skippedMicrosoft Basic Render Driver,1414:008c, driver10.0.26100.9818): passNVIDIA GeForce RTX 5080,10de:2c02, driver32.0.16.2124): passctest --preset release --no-tests=error -R '^startup_gfx2hlsl_v_mad_i32_i16': 3/3 passed, 0 skippeddocs_links_check.py,bidi_controls_check.py,startup_gfx2hlsl_handler_arity_check.py,startup_gfx2hlsl_refusals_check.py,startup_gfx2hlsl_mad_check.py,git diff --check): all passed.Scope: Covers synthetic
v_mad_i32_i16fixtures in the offlinegfx2hlsltranslator and offscreen D3D12 draw harness; does not establish full-title startup or runtime execution.Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-27T10:43:05Z.
Independent check of the controls added here, head
9c6c38a1— mutation matrix, no GPUNot a code change; measurements only.
Environment
9c6c38a1f7685efdc3ff3326969a7237877e4984, base8a901eb2, tracked tree clean (git status --porcelain --untracked-files=noempty).tools/startup/gfx2hlsl.pysha2565549ae98d3a21d1c00a8fcc0544f07377c5f13c219226c65ec3ad9cf5d09a738, fixture sha25629ea6a086c6b03bbe889367699cb0d96405a28c7aad02ba2c3c24a09d84af1c1.drawentry was run. Nothing below speaks to DXC/FXC output or to adapter behaviour.What I ran
plus a mutation matrix on
tools/startup/gfx2hlsl.py: each mutant is written to a copy outside the tree, injected assys.modules['gfx2hlsl'], and the fixture and its two helpers are re-imported against it. A must-break mutant (low 16 bits read unsigned) is part of the set and is killed, so the injection is live. Baseline passes before and after; the source is restored to the sha256 above.The controls do discriminate
13 mutants applied, 9 killed, 4 survivors.
({0} & 0xffffu) * ({1} & 0xffffu)(unsigned low halves)v_mad_i32_i16 grid (216 cases)v_mad_i32_i16 grid (216 cases)<< 15) >> 15instead of<< 16) >> 16, S0v_mad_i32_i16 grid (216 cases)word0 & 0x700)encoding guard refuses abs0word1 & 0xe0000000)encoding guard refuses neg2if name == 'v_mad_i32_i16':block removed (lines 509-512)encoding guard refuses abs0low16_only=Truedropped on S0, then on S1, separatelyUnsupported, before the assertelif base == 'v_mad_u32_u16'(shared low16 path dropped)Unsupported, before the assertclamp(0x700→0x8700)op_sel(0x700→0x7f00)v_mad_i32_i16removed from thevalu_align4tuple+ {2}→+ asuint({2})u()returns a uint expression, soasuintis identity)Six kills land on a named check; three are an uncaught
Unsupportedescapingp_lo.one(...)beforecheck('low16_only_v accepted on S0 and S1', ...)is reached. A kill is a kill, but those three do not tell you which assertion would have caught them.What the table establishes: the 216-case grid is not self-referential — it evaluates the emitted expression text with its own AST evaluator against the fixture's separate
ref_mad_i32_i16, and all three expression mutants die there. And each term of the new encoding guard is pinned by its own case: dropping the ABS term and dropping the NEG term fail different checks.Three of the six source-modifier bits are not covered
ABS is
w0[10:8]and NEG isw1[31:29], one bit per source. I took the bit-to-source order fromtools/disasm_rdna2.py, not from the fixture's encoder: leaving one bit unguarded at a time and decoding prints bit 8 →|v0|, bit 9 →|v4|, bit 10 →|v8|, bit 29 →-v0, bit 30 →-v4, bit 31 →-v8. The fixture sets ABS on S0, NEG on S0 and NEG on S2, so ABS on S1 (bit 9), ABS on S2 (bit 10) and NEG on S1 (bit 30) are never produced. Narrowing the mask asks which bits those three cases can distinguish:0x100)0x300)0x500)0xa0000000)0x20000000)encoding guard refuses neg20xc0000000)encoding guard refuses neg_inline0A guard that silently stops covering those three bits still passes everything.
To be clear about what that costs today, I chased the three unguarded bits through four operand kinds each (VGPR, inline
1, inline-1, literal dword). None reached an emitted line: with the bit open the decoder prints|v4|,|v8|or-v4, and VGPR sources are then refused inu()(operand '|v4|',tools/startup/gfx2hlsl.py:2545), while an inline-integer or literal source with NEG is refused earlier by the pre-existing check at lines 549-575 (NEG on an integer or literal source 1: the printed sign would read as inline -N). So this is unmeasured guard scope, not a miscompile path — and three entries in the existing tuple would close it:abs_bits=2,abs_bits=4,neg=2.The sibling's clear-on-destination control is not ported
tests/startup_gfx2hlsl_mad_u32_u16_check.py:240-244marks its destinationlow16_only_vand asserts that a write clears the marking, that neither source ends inwhole_read_v, and that S2's source is recorded as a whole-word read. The new fixture marks only the sources ({0, 4}) and writesv12, soclear_low16(line 2807) is never reached through this op — the low16 contract is only pinned on the "accepted as source" side. One mutant (else: self.clear_low16(n)→else: pass) separates the two fixtures:..._mad_u32_u16_check.pylow16_only allowed on S0/S1 and cleared on dst..._v_mad_i32_i16_check.pyThe sibling control ports as is.
Two harness features of the sibling are absent
binary <llvm-mc>mode: the synthetic encoder is never cross-checked against an assembler. The abs/neg words are produced by the fixture's ownvop3a()and read back byG.decode, with no external oracle on the bit positions; the sibling reassembles its own sources (check_binary).refused_bytesin the sibling): theclamp,op_selandmul:2refusals here are assembly text and go throughStage.lower, so they never exercisecheck_encoding. That is why widening the encoding guard toclamporop_selchanges nothing observable — the encoding layer's scope on those fields is untested in both directions.Limits
drawwas not run, so nothing here covers the compiled HLSL or either compiler.low16_onlymutants and the shared-path one, all three of which die by exception.valu_align4entry is not covered by any control here, and the sibling fixture does not pin its own entry either.controlsreaches pull requests throughtests/checks/python-linux/*.txtand thepython-linuxjob, and_warpis outside theprpreset regex while_hardwareis excluded by-E '_hardware$'— the same shape as the rest of the family.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T11:46:47Z.
Review: APPROVED
Reviewed
9c6c38a1in integration tree49adb1b3onmain1c879506with the preceding packed-integer PRs in the tested merge order where applicable.python -B tests/startup_gfx2hlsl_v_mad_i32_i16_check.pypassed. Itsdraw <dxc> <offscreen_check> <warp|hardware> <fxc>invocation passed on WARP and RTX with both Debug and Release /O2 renderers, reusing builds of the unchanged renderer sources. Signed low halves and the full-width addend matched, including the alignment and lane-mask controls. Windows 11 26200.9974, SDK 10.0.26100, WARP 10.0.26100.9818, RTX 4060 Laptop driver 32.0.16.1656, D3D12 debug layer enabled. Hosted Windows, Linux Python and gfx1013 checks passed.