shader: lower v_ldexp_f16 in the direct compute path #3123
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3123"
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-27T16:11:32Z.
Fixes #3122. Refs #2935.
What this changes
v_ldexp_f16(VOP20x3b/ VOP3A0x13b) insrc/gfx1013_direct_compute.inlusing exact 32-bit integer IEEE-754 binary16 scaling while preservingD[31:16].S1[15:0]and clamps the exponent delta to[-64, 64], normalizes denormal inputs without flushing, rounds subnormal underflows to nearest-even, preserves±0.0h,±Inf, andNaN, supports VOP3Aabs/negonsrc0andclamp, and refuses unsupported modifiers (omod,neg/absonsrc1,op_sel, unusedsrc2).Tests & docs added
tests/native_ldexp_f16_check.py&tests/cmake/native_ldexp_f16.cmake:native_ldexp_f16_controls: validates emitted integer DXIL (shl i32/lshr i32), refuses invalid modifiers, and verifies that theflush_denormals,truncate_subnormal,no_clamp, andzero_highnegative controls each differ.native_ldexp_f16_hardware: dispatches 8 binary16 scaling cases (normals, negativei16exponent, denormal promotion, subnormal round-up and even/odd ties, overflow to+Inf/clamp) across VOP2 and VOP3A with pre-seededD[31:16], matching 2048 result words and 16 sentinel guards.docs/experiments/native-ldexp-f16.md: experiment note and reproduction commands.Verification
520ac7d110.0.26300.9974), MSVC19.44.35230, Windows SDK / DXC10.0.26100.0, NVIDIA GeForce RTX 5080 (10de:2c02, driver32.0.16.2124).ctest --preset dev --no-tests=error -R '^native_ldexp_' -V: 4/4 passed (0 skipped).ctest --preset release --no-tests=error -R '^native_ldexp_': 4/4 passed (0 skipped).tests/docs_links_check.py&tests/bidi_controls_check.py: passed.Scope: covers synthetic direct-DXIL compute fixtures for
v_ldexp_f16only; does not establish full-game execution.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T18:09:18Z.
Review: COMMENTED
Review of
0594e4332c(the change from520ac7d1, updated with main). Comment only.The scaling, the denormal normalization, the round-to-nearest-even subnormal path and the overflow to Inf read correctly to me, and the CPU reference is independent of the lowering.
One thing should change before merge: inline float constants.
operand32(i, i.src[0])returns the f32 bit pattern for sources 240-248, and the lowering then keeps only the low 16 bits. For 0.5, 1.0, 2.0, 4.0 and their negatives the low half of the f32 pattern is 0, sov_ldexp_f16 v4, 1.0, v3scales +0 instead of 1.0h; 1/(2*pi) gives an unrelated value. Thev_add_f16block in the same file maps these sources throughhalves[](binary16 roundings). Could you do the same here, or refuse 240-248, and add one inline-constant source to the fixture? The same pattern was raised on #3135, and #3120 (already merged) has it too, so one follow-up could cover all of them.Windows Server 2025 (Build 26100, MSVC 14.44.35207, D3D12 WARP) at
0594e433, for information:ctest --preset dev -R <native sweep>after buildingcompile_dxil native_store_replay: 100% tests passed out of 134--preset release: 100% tests passed out of 134<native sweep>is everynative_*test exceptnative_startup_request_cache_hardware(fails on WARP-only hosts with or without this PR). The_hardwarelegs skip on WARP.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T18:51:00Z.
Review: APPROVED
Correct lowering of
v_ldexp_f16using exact integer-based IEEE-754 binary16 scaling. The denormal normalization, exponent clamping to [-64, 64], round-to-nearest-even subnormal underflow, and overflow handling are all precise. VOP3A abs/neg/clamp support is correct and unsupported modifiers (omod, neg/abs on src1, op_sel) are properly refused. Test suite covers denormal promotion, negative exponents, tie cases, and negative controls. Approved.Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-28T00:03:14Z.
This PR shares the same inline float constant bug that tedin7 already flagged on this PR:
operand32(i, i.src[0])returns f32 bit patterns for src 240-248 (e.g.,0x3f800000for 1.0), then the lowering keeps only the low 16 bits (& 65535). For 0.5, 1.0, 2.0, 4.0 and their negatives that low half is0, sov_ldexp_f16 v4, 1.0, v3scales +0 instead of 1.0h. The fix: map sources 240-248 through ahalves[]array like thev_add_f16block does (line ~1207-1212), or refuse them. Please add an inline-constant case to the fixture.Missing graphics guard. The v_add_f16 block has
if (graphics_input) return false;. Your new block lacks this, so direct compute lowering now applies to vertex/fragment shaders too. Add the same guard unless that's intentional.CMake guard. Same issue as #3125/#3135: uses
X2W_HAVE_DXCAPI AND EXISTS INTAKE_PYTHONinstead ofTARGET compile_dxil AND TARGET native_store_replay AND EXISTS .... Please match the pattern used by other native fragments.NaN/Inf test coverage. The reference correctly handles NaN and Inf (
exp == 0x1F or (bits & 0x7FFF) == 0). But no source inCASEShas exponent=0x1F with zero mantissa (+Inf/-Inf), which should pass through unchanged. Please add ±Inf to the fixture.VOP2 abs/neg not tested. The lowering supports
i.abs & 1andi.neg & 1, but the test program only runs VOP3A forms (with neg/abs on src0). Either test VOP2 with abs/neg or narrow the description.Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-28T07:01:20Z.
Thanks for the ldexp lowering. I reviewed
0594e433, the current head, and the earlier review points aren't on the branch yet. One thing needs fixing before this can merge, and three more changes would make the tests pin what the description claims:operand32(i, i.src[0]) & 65535, but for sources 240-248constant32returns the f32 pattern (inline_float_words,0x3f800000for 1.0). Sov_ldexp_f16 v4, 1.0, v3scales +0h, and 1/(2π) scales0xf983. Main'sv_fma_f16block maps these throughhalves[](0x3800, 0xb800, 0x3c00, ...). Either that or refusing 240-248 works, plus one inline-constant source (every src0 is nowv2, set byv_mov_lit).!half_mode_known || ((mode_bits ^ 0xf0u) & 0x8000ccu)(7 sites). ldexp rounds subnormal results to nearest-even and keeps denormals, so a program that sets f16 round-toward-zero or denormal flush would silently get different results. The same refusal, plus adding the op to thehalf_binaryscan, would close this.CASEShas no ±0, ±Inf or NaN source, and the largest |delta| is 10. Droppingresult = select(keep, bits, result);would turn a NaN input into ±Inf or a finite value, and every case would still pass, the hardware leg included. Adding ±0, ±Inf, a qNaN and deltas such as ±100 and0x8000would pin what the description says the lowering preserves.controlsdoesn't check results. It asserts only that'shl i32 'and'lshr i32 'appear in the dump, and thereference() != reference(...)lines test only the Python model. Values are checked only by thehardwareleg, which skips on WARP and isn't in CI'sprpreset (69 tests, none of themnative_ldexp).Minor, and consistent with some existing blocks: there's no
graphics_inputguard, and the CMake guard doesn't testTARGET compile_dxil. The VOP2 abs/neg request doesn't apply, since VOP2 has no abs/neg fields and DPP and SDWA are refused.On the conflict:
git merge-treeagainst mainbbf4687breports one file and one hunk. Main replaced theif (n == "v_add_f16" || ...)line that follows your block withif (binary16_alu(n) || binary16_unary(n)) {. Your block still goes in unchanged right before it, giving +46/−0 against main (and +75/−0 together with #3125's block), so the rebase should be mechanical.This was a static review: code reading plus
git merge-tree. I didn't build or run anything.This comment was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-11-28T09:17:27Z.
Merged current
main(3f780716) and addressed all review points:240..248forsrc0throughpacked_f16_inline_constant(halves[]) instead of taking the low 16 bits of the f32 word, and added a VOP2 inline1.0(src0=242) test case.if (graphics_input) return false;, the FP16 MODE guard (!half_mode_known || ((mode_bits ^ 0xf0u) & 0x8000ccu)),v_ldexp_f16in thehalf_binaryscan, and as_round_moderefusal test.±0.0h,±Inf,qNaN,±100, andINT16_MIN(0x8000) deltas, plusdrop_keepandinline_as_zeronegative controls.TARGET compile_dxil AND TARGET native_store_replay AND EXISTS ${INTAKE_PYTHON}.Verified on NVIDIA GeForce RTX 5080 (
10de:2c02, driver32.0.16.2140), Windows 11 (10.0.26300.9974), MSVC19.44.35230, SDK DXC10.0.26100.0:ctest --preset dev --no-tests=error -R '^native_ldexp_|^native_f16_alu': 6/6 passed (0 skipped).ctest --preset release --no-tests=error -R '^native_ldexp_|^native_f16_alu': 6/6 passed (0 skipped).Ready for re-review!
Commit:
7a971b36Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T09:50:29Z.
Review: APPROVED
Retested
7a971b36integrated overmain32dc3d7c(tree7b0ce75a). The merge is clean andgit diff --checkis clean.Earlier points. tedin7's inline-constant finding is addressed: src0 240..248 now goes through
packed_f16_inline_constant, and batch 1 covers it. Thegraphics_inputguard, the MODE gate, thehalf_binaryscan entry and the CMake guard are in. The delta cases cover ±0, ±Inf, qNaN, ±100 andINT16_MIN.What I traced. I read the new
v_ldexp_f16block against the RDNA ISA description:e > 30overflows to Inf;The wide form refuses
op_sel, src1/src2 modifiers and src2, and the block refuses subword, DPP, permuted and scaled forms.What I ran. I built in
devandreleasewith the pinned SPIR-V tools set, then ran:The
_hardwarerun went through the GPU lock. Results in Debug and Release/O2, with no skips:native_ldexp_f16_hardwareprintsbatch=0/1: 2048 result words (high halves kept) and 16 guards matched.Control and mutants. Each mutant changes
src/gfx1013_direct_compute.inl, then runsnative_ldexp_f16_controlsandnative_ldexp_f16_hardware:main(control)beef0000vsbeef5000Restored afterwards; the worktree matches the trial merge.
Non-blocking.
bad_moderefusal (s_round_mode 0xC) in the controls test still passes, so something earlier refuses that program first. I didn't trace which. Either the in-block gate is redundant, or the control needs a case that only that gate catches._irmode. The value semantics are pinned only by the hardware test, so they run only on wave32 GPUs. CI's controls test checks the DXIL forshl,lshrand15360only.tests/native_ldexp_f16_check.pycompare the Python reference with itself. They don't exercise the lowering.Verdict: approve on
7a971b36.Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; SDK 10.0.28000.0 DXC; wave32; Python 3.12.10.
CI:
Build and test on Windowspasses on7a971b36.This reply was AI-assisted.