shader: lower v_fma_f16, v_fmac_f16, v_fmamk_f16 and v_fmaak_f16 in the direct C++ path #3187
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3187"
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 legacy-code-archaeologist on 2026-11-27T20:48:54Z.
Lowers scalar binary16 FMA instructions (
v_fma_f16,v_fmac_f16,v_fmamk_f16,v_fmaak_f16) in the direct C++ compute path (DirectCompute::float_alu()insrc/gfx1013_direct_compute.inl).Summary of changes
fused_half_rne()): Reuses the shared 32-bit integerfused_half_rne(a, b, c)helper introduced in#3151(25a4fb23) rather than adding a duplicate FMA helper, preservingD[31:16].v_fma_f16(VOP3),v_fmac_f16(VOP2/VOP3A),v_fmamk_f16(VOP2),v_fmaak_f16(VOP2), including SGPR/literal/inline-float/inline-int sources anddst = src0overlap.abs,neg, andclamp([0.0, 1.0]saturation).half_binaryinDirectCompute::lower().omod, high-halfop_sel, and third-source modifiers/src2onv_fmac_f16_e64.tests/cmake/native_fma_f16.cmake,tests/native_fma_f16_check.py(41 cases incl. all 4#2073tie witnesses,diff_e >= 30sticky-bit midpoint128.0625 + 2^-24->0x5801, underflow/overflow/cancellation/Inf/NaN + 12 refusals), anddocs/experiments/native-direct-fma-f16.md.tests/native_f16_alu_check.pyfromv_fmac_f16tov_pk_fmac_f16, and added@dx.op.unaryBits.i32(i32 33, ...)evaluation to its IR interpreter sonative_fma_f16_irevaluatesfused_half_rne()directly.Fixes #3186
Refs #2935
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T21:16:18Z.
The title says "lower v_fma_f16...", but this PR removes the implementation (
fma_half_rne,float_alucases) and tests for these instructions from the direct compute path.Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T21:22:49Z.
@KelboLive You may have caught GitHub's diff view right during the force-push/rebase onto
3d7b3a26(#3159+#3126). On the current head6d5f8ee2(#3187), all implementation and tests are added (+531/-2across 5 files):src/gfx1013_direct_compute.inl:+175/-1(fma_half_rne(),float_alu()cases forv_fma_f16/v_fmac_f16/v_fmamk_f16/v_fmaak_f16, andhalf_binary)tests/cmake/native_fma_f16.cmake:+19tests/native_fma_f16_check.py:+298tests/native_f16_alu_check.py:+1/-1(v_fmac_f16->v_pk_fmac_f16)docs/experiments/native-direct-fma-f16.md:+38AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T21:50:35Z.
Review: CHANGES_REQUESTED
I tried to review
6d5f8ee2over currentmain8a8da963. The trial merge (git merge --no-ff --no-commit) conflicts insrc/gfx1013_direct_compute.inl, in two places:25a4fb23, merged today) addedpacked_f16_arithmeticandfused_half_rne, where this PR addsfma_half_rne.half_binarymode scan: #3144 (e219d724) reformatted that condition and addedv_pk_min_f16/v_pk_max_f16, where this PR adds the four FMA names.The PR's merge base is
3d7b3a26, so both landed after it.Not just a textual conflict.
mainnow hasfused_half_rne(a, b, c), which #3151 uses forv_pk_fma_f16. Its contract is the same as this PR'sfma_half_rne: three binary16 encodings in the low 16 bits, one exact single-rounded RNE result, and0x7e00for every NaN. Keeping both would put two independent 120-line implementations of the same arithmetic in one file, and they could disagree on edge cases without any test noticing.Suggested direction (unconfirmed): rebase onto current
main, and have the scalarv_fma_f16/v_fmac_f16/v_fmamk_f16/v_fmaak_f16path callfused_half_rneon the decoded and modified halves (including abs and neg) instead of addingfma_half_rne. Yournative_fma_f16_ir/_controls/_hardwarecases, the four #2073 tie witnesses and the subnormal, overflow and cancellation edges, would then also pin the shared helper. Iffused_half_rnegets one of those cases wrong, that is worth a finding of its own, so please report it on the PR if it does.I stopped at the conflict, so I have not built or run this head. I'll retest once it merges cleanly.
Environment: Windows 11 25H2 build 26200.9974; Git trial merge only.
CI:
Build and test on Windowspasses on6d5f8ee2against its own base.This reply was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T21:59:41Z.
@pigalot Thank you for the review! Rebased onto
c45bf9ab(#3151+#3144), droppedfma_half_rne(), and wired scalarv_fma_f16,v_fmac_f16,v_fmamk_f16, andv_fmaak_f16toupstream/main's sharedfused_half_rne(a, b, c)helper.Also added
@dx.op.unaryBits.i32(i32 33, ...)(FirstbitHi) evaluation totests/native_f16_alu_check.py's IR interpreter sonative_fma_f16_irevaluatesfused_half_rne()directly.Result on
fused_half_rne(): All 41 single-rounded cases (including the four#2073tie witnesses, subnormals, exact cancellation, underflow ties, overflow,Inf/NaN, and thediff_e >= 30sticky-bit midpoint128.0625 + 2^-24->0x5801) matched thefractions.Fractionreference with zero discrepancies.Local verification (
c45bf9ab+ rebasedshader/direct-fma-f16, Windows 10.0.26100,devpreset):cmake --build --preset dev --target compile_dxil native_compute_ir_dump native_store_replay: passedctest --preset dev --no-tests=error -R '^(native_fma_f16_|native_packed_f16_|native_cvt_f16_i16_|native_f16_alu_)' -V: 8 passed (native_f16_alu_ir,native_fma_f16_ir,native_fma_f16_controls,native_cvt_f16_i16_ir,native_cvt_f16_i16_controls,native_packed_f16_controls,native_packed_f16_pixel_warp,native_packed_f16_pixel_hardware), 4 skipped (77,*_hardwarecompute tests onIntel(R) HD Graphics 53031.0.101.2111: requires SM 6.6 with wave32)ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure: 57/57 passedzero_high_half,drop_sticky,swap_fmamk_fmaak,drop_clamp,drop_inf_cancel_nan): all exited1onnative_fma_f16_ir;native_fma_f16_irpassed again after restoringsrc/gfx1013_direct_compute.inlpython -B tests/docs_links_check.py: passed (108Markdown files,600links)AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T22:18:12Z.
Review: COMMENTED
I independently applied exact head
eb3524f6overmaine582a9a4, including #3188's DPP16 support (clean trial treedd9b7dc2). The scalar forms now use #3151's sharedfused_half_rne; the packed path remains and the resolved change retains #3188's handling. I builtcompile_dxil native_store_replay native_compute_ir_dumpand ranctest --test-dir <build> --no-tests=error -j1 -V -R '^(native_fma_f16_.*|native_f16_alu_(ir|hardware)|native_packed_f16_controls)$'. Debug and Release /O2 each passed 6/6, with no skips. The IR and RTX 4060 Laptop readback matched all 41 scalar witnesses and the controls matched 12 named refusals. Windows 11 26200.9974, driver 32.0.16.1656, debug layer off for the standalone replay. Required hosted Windows passed. @pigalot, the two conflicts from the previous head no longer reproduce; could you update your review on this head?Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T22:27:24Z.
Review: APPROVED
Retested
eb3524f6merged over currentmainf6206217, which includes #3188's DPP16 change. The merge is clean (tree6d04976f) andgit diff --cached --checkis clean.Earlier finding: addressed.
fma_half_rneis gone. The scalarv_fma_f16,v_fmac_f16,v_fmamk_f16andv_fmaak_f16forms call #3151'sfused_half_rneon the decoded halves, after abs and neg are applied. The IR interpreter intests/native_f16_alu_check.pynow evaluates FirstbitHi (op 33), which the shared helper uses. This supersedes my changes-requested review on6d5f8ee2.What I traced.
fmamktakes the literal asb, andfmaaktakes it asc.fmacreads its addend from the low half ofD, and the e64 form refuses asrc2field or a third-source modifier.0x3c00.D[31:16]is kept.op_seland non-default MODE are refused. The scan entry makes MODE known for these ops.binary16_alu. Their DPP forms are still refused, as before.What I ran.
devandrelease/O2: builtcompile_dxil,native_store_replay,native_compute_ir_dumpandoffscreen_check, then ran10/10 pass in each preset, with no skips.
Fuzz: a local fuzz compares the dumped IR, run through the test's interpreter, against an exact
FractionFMA reference rounded once to binary16. It uses random and near-cancellationv_fma_f16VOP3 cases. 250,000 cases over five seeds give 0 mismatches. The last 50,000 ran on this merge, and the rest ran on the earlier886a5a28merge.Mutants, each rebuilt in
dev(on the886a5a28merge, where the new block is byte-identical) and run againstnative_fma_f16_ir,_controlsand_hardware. The unmutated baseline passes first.fmamk/fmaakliteral positions swappedfmacaddend fromsrc2instead ofDD[31:16]zeroedop_selrefusal droppedfmacthird-source modifier refusal droppedTwo mutants of the shared helper, sticky bit dropped and round-to-odd dropped, both fail
native_fma_f16_ir. Your tie witnesses catch the round-to-odd one, which my random fuzz misses. Restored and rebuilt afterwards;git diff --quietis clean.Non-blocking.
s_round_modebefore av_fma_f16would pin it.Verdict: approve on
eb3524f6.Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10; wave32; debug layer off.
CI:
Build and test on Windows,Assemble and translate gfx1013 fixturesandRun platform-independent Python checks on Linuxpass oneb3524f6.This reply was AI-assisted.