Repository navigation
shader: lower v_fma_mix_f32 in gfx2hlsl - #2055
Conversation
bbdc504 to
d725058
Compare
|
Read the diff only (not run). The selector reading matches LLVM's Two cases on the binary32 path go through
AI-assisted. |
Emit neg on a negative inline float (`--0.5`) as `(-(-0.5))` instead of an HLSL decrement, and refuse binary32 sources printed as a negative integer or literal, where the decoder text loses the sign-bit flip (review on R0Y00#2055). Refs R0Y00#1723 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks. Both findings are addressed in
Without the fix, exactly these five new cases fail. With it, all 45 AI-assisted (Claude Code). |
63bafe5 to
fd4c334
Compare
Emit neg on a negative inline float (`--0.5`) as `(-(-0.5))` instead of an HLSL decrement, and refuse binary32 sources printed as a negative integer or literal, where the decoder text loses the sign-bit flip (review on R0Y00#2055). Refs R0Y00#1723 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tedin7
left a comment
There was a problem hiding this comment.
Review of head fd4c3341a00f033fe16c8cbc41dbfed4309adf26.
Result: no P1, no P2.
CI: gfx1013 fixtures, Windows build/test and Linux Python checks all pass at this head.
Commands run locally in a worktree at this head:
git diff --stat origin/main...HEAD: 6 files, +290/-15.python3 tests/startup_gfx2hlsl_fma_mix_check.py:all fma_mix checks passed.python3 tests/docs_links_check.py: self-test passed, 18 files, 396 links.python3 tests/bidi_controls_check.py: 1430 files, no bidirectional controls.git diff --check origin/main...HEAD: clean.
Mutation checks (reverted with git checkout -- .):
- Dropped the
>> 16high-half shift inStage.mix(): the check fails on 5 cases (high half of src0, op_sel control, abs+neg high half, -0 addend, mixhi). - Dropped the
abs()wrap on binary16 sources: the check fails on the abs/neg high-half case. - Both mutations were killed.
Review notes:
- Source selection (op_sel_hi = binary16, op_sel = high half, abs then neg after widening) matches the cited LLVM 15 reading.
- Refusing unknown modifiers instead of ignoring them is the right call. It does tighten mixlo/mixhi, and the PR body says so.
(-0.0)for-0and(-(…))for--0.5avoid the HLSL decrement trap.- The change in
tools/startup/gfx2hlsl.pyis a lowering, and the PR adds a CPU-side check. I did not run a Windows WARP readback for this review. Windows CI is green, but I did not inspect whether it covers a GPU readback of the new opcode.
nit: mergeable showed UNKNOWN when I checked, so a rebase may be needed before it is made Ready.
AI-assisted; commands listed were executed locally.
|
I tested a follow-up on fd4c334 for half-precision sources. The current candidate refuses a packed 32-bit literal used for its low or high half, and refuses inline 0.5 on the low-half path. The latter caused three regressions in a matched private corpus comparison. The follow-up implements literal half selection and retains the low-half inline 0.5 case. Source-built controls cover 1.0 and 2.0 packed in the same literal, swapping the selector, and rejecting the unverified high half of an inline constant. The previous signed-literal rejection remains covered. On Windows, |
fd4c334 to
dc9a7f4
Compare
Emit neg on a negative inline float (`--0.5`) as `(-(-0.5))` instead of an HLSL decrement, and refuse binary32 sources printed as a negative integer or literal, where the decoder text loses the sign-bit flip (review on R0Y00#2055). Refs R0Y00#1723 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tedin7
left a comment
There was a problem hiding this comment.
Re-review of head dc9a7f4bd3e2c2c2e9983b2fa1336ceb2a8e8167 (new since fd4c334: refused negated integer/literal sources, -0 handling, fxc compile test, CMake/docs tidy).
Verdict: no P1. One P2, one nit.
Checked against LLVM 15 mad-mix semantics: op_sel_hi picks binary16, op_sel picks the high half, abs applies before neg, clamp is saturate, and op_sel on a binary32 source is refused. All of this matches the new Stage.mix in tools/startup/gfx2hlsl.py.
- P2
tests/startup_gfx2hlsl_fma_mix_check.py(whole file): the checks compare translated text and (withSTARTUP_FXC) only compile it for ps_5_1. Neither runs the shader, so the fma_mix numeric result (>> 16half select, abs/neg order, clamp,-0product) is never compared with a CPU reference. A D3D12 WARP GPU-readback vs CPU-reference case is still missing. It needs Windows CI/WARP before Ready. - nit
tools/startup/gfx2hlsl.pymix:a * b + cin HLSL may not be fused. For f32-sourced operands this can differ by 1 ulp from a true fma. Worth a comment, or usemad/fmaif the target allows it.
Commands executed locally (Linux):
git diff --stat origin/main...HEAD: 6 files, +351/-15.python3 tests/startup_gfx2hlsl_fma_mix_check.py: "all fma_mix checks passed".python3 tests/docs_links_check.py: pass (436 links).python3 tests/bidi_controls_check.py: pass.git diff --check origin/main...HEAD: clean.- Mutations (each reverted with
git checkout -- .), all killed by the test:- drop
>> 16: 5 checks failed. - drop the neg wrap: 1 check failed.
-0.0becomes0.0: 2 checks failed.- drop
abs(): 1 check failed.
- drop
CI at review time: Linux Python checks pass. Windows jobs and fixture assembly were still pending. I did not run the Win2025 queue, so the WARP result is unverified.
Mergeable, title neutral, no clean-room concerns seen.
AI-assisted; commands listed were executed locally.
|
@R0Y00 thanks. 54b947b is now on the PR as
On Windows 11 26300.9974 with MSVC 14.44 in the @tedin7, re your P2: this push does not add a WARP readback against a CPU reference yet. AI-assisted (Claude Code). |
tedin7
left a comment
There was a problem hiding this comment.
Re-review of head 741ff02cc8c3ab2dcf49dab51eee71357822ce82 (new since dc9a7f4: literal half selection for binary16 literal sources, inline 0.5 on the low half, docs).
Verdict: no P1. The previous P2 is NOT resolved.
- P2 (still open)
tests/startup_gfx2hlsl_fma_mix_check.py: the checks still compare translated text (plus an optional fxc compile). No D3D12 WARP GPU-readback vs CPU-reference case exists (rg -in "warp|readback|d3d12"on the test and the new CMake lines finds nothing for fma_mix). The new logic adds more cases that only a numeric run proves: the>> 16literal half pick (0x40003c00-> 1.0 / 2.0), inline0.5as binary16, abs/neg order, clamp,-0product. The Windows CI jobs pass, but they do not exercise this lowering numerically. Needs a WARP readback case (or a Win2025 WARP pass cited in the body) before Ready. - Checked and fine: literal
0x40003c00selectsf16tof32(0x3c00u)for the low half and0x4000for the high half. Inline0.5on the low half is0.5. Inline0.5on the high half is still refused. This matches the binary16 encoding of the literal and the 0.5 inline constant. - nit
tools/startup/gfx2hlsl.py(mix):a * b + cmay not be fused in HLSL, so f32-sourced operands can differ by 1 ulp from a true fma. Still worth a comment (carried over).
Commands executed locally (Linux):
git diff --stat origin/main...HEAD: 6 files, +373/-15.python3 tests/startup_gfx2hlsl_fma_mix_check.py: "all fma_mix checks passed".python3 tests/docs_links_check.py: pass (436 links).python3 tests/bidi_controls_check.py: pass.git diff --check origin/main...HEAD: clean.- Mutations on the new logic (each reverted with
git checkout -- .), all killed by the test:- literal shift
>> (16 if is_hi else 0)changed to>> 0: test failed. - inline
0.5allowed on the high half: test failed. - literal half word flipped (
word ^ 1): test failed.
- literal shift
CI at review time: Linux Python checks, Windows build/test and gfx1013 fixture assembly pass; the /O2 job was skipped. I did not run the Win2025 queue, so the WARP result is unverified.
Mergeable, title neutral, no clean-room concerns seen.
AI-assisted; commands listed were executed locally.
…ence Add a dispatch mode to startup_gfx2hlsl_fma_mix_check.py. Every translated line runs in a DXC cs_6_0 thread on WARP or a hardware adapter, and each result word is compared with a CPU reference that decodes the VOP3P word itself (LLVM 15 reading). A control drops the high-half shift and must then follow a reference with op_sel cleared. Registered as startup_gfx2hlsl_fma_mix_dispatch_warp and _hardware (review on R0Y00#2055). Refs R0Y00#1723 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@tedin7, for your P2:
Results at
Neither run reported a capability skip. The fixture doesn't report D3D12 debug-layer status. ctest --preset dev --no-tests=error -j1 -R '^startup_gfx2hlsl_fma_mix(_fxc|_dispatch_(warp|hardware))?$' -VAll 100 AI-assisted (Claude Code). |
tedin7
left a comment
There was a problem hiding this comment.
Re-review of head de42d59bb5fe4b72eabdb6700a89ad265c58e02b (new since 741ff02: dispatch mode in tests/startup_gfx2hlsl_fma_mix_check.py, CMake startup_gfx2hlsl_fma_mix_dispatch_{warp,hardware}, docs).
Verdict: no P1, no P2. The previous P2 (no WARP GPU-readback vs CPU-reference case) is resolved.
- The dispatch mode compiles all 17 translated lines into one DXC cs_6_0 thread, loads inputs through the raw UAV fill (not foldable), stores the destination, and compares each word with
reference(). The reference decodes the VOP3P word itself (op_sel_hi = binary16, op_sel = high half, abs then neg, clamp), independent of the decoder and the translator. - A control drops the
>> 16from the emitted lines. The readback must then match a reference withop_selcleared and differ from the correct result somewhere. Good: this proves the readback is sensitive to the half select. The-0case is correctly excluded from "differs" (zero product). - Fine: exit 77 maps to CTest SKIP,
-j1in the doc command avoids sharing the adapter, inputs have short mantissas so fused vs unfused gives the same word (the doc says this openly). - nit (carried over)
tools/startup/gfx2hlsl.pymix:a * b + cmay not be fused in HLSL, so f32 operands with long mantissas can differ by 1 ulp from a true fma. The new test does not separate the two, by design. A one-line comment at the expression would help.
Commands executed locally:
git diff --check origin/main...HEAD: clean.python3 tests/startup_gfx2hlsl_fma_mix_check.py: "all fma_mix checks passed".python3 tests/docs_links_check.py: pass (436 links).python3 tests/bidi_controls_check.py: pass.- Mutation: removing the
saturate(...)wrap forclampinmix: the text check fails (reverted withgit checkout -- .). - Win2025 (dev, WARP, default slot pool):
ctest --preset dev -R '^startup_gfx2hlsl_fma_mix' --no-tests=error: 4/4 passed (startup_gfx2hlsl_fma_mix,_fxc,_dispatch_warp0.50s,_dispatch_hardware0.48s). Release was not run.
CI at review time: Linux Python checks, Windows build/test and gfx1013 fixture assembly pass; the /O2 job was skipped. Mergeable, title neutral, no clean-room concerns seen.
AI-assisted; commands listed were executed locally.
Review nit on R0Y00#2055. Refs R0Y00#1723 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tedin7
left a comment
There was a problem hiding this comment.
Re-review of head 7d28557f5f5aa9bf9352aba279e0bed23669cbc1 (previous review head: de42d59b).
What changed since the last review: one commit, 7d28557f. It adds a 2-line comment in tools/startup/gfx2hlsl.py (fma_mix lowering) noting that HLSL may round a * b before the add, so binary32 sources with long mantissas can differ from hardware by 1 ULP, as in v_fma_f32. There is no logic change.
Commands run locally on this head:
git diff de42d59b 7d28557f: comment-only, no behavior change.python3 tests/startup_gfx2hlsl_fma_mix_check.py:all fma_mix checks passed.python3 tests/docs_links_check.py: 18 files, 436 links OK.python3 tests/bidi_controls_check.py: 1580 files, no bidi controls.git diff --check origin/main...HEAD: clean.- Mutation: replaced
saturate(%s)with(%s)in the lowering. The check failed (abs then neg after widening a high half, scalar source, clamp), so the tests catch it. Reverted afterwards. - CI: Linux Python checks, gfx1013 fixtures and Windows build/test are all green. The PR is mergeable and the title is neutral.
Findings: P1=0, P2=0.
- nit: the new comment is accurate. No other change is needed.
- The Windows (Win2025) WARP run was not repeated. The delta is comment-only, so earlier results for the logic still apply.
AI-assisted; commands listed were executed locally.
v_fma_mix_f32 was refused by the startup translator (58 code pairs in the R0Y00#1723 refusal snapshot). It now shares Stage.mix() with the two binary16-destination forms and writes the binary32 result to the whole VGPR. Source selection follows LLVM 15 SelectVOP3PMadMixModsImpl: op_sel_hi marks a binary16 source and op_sel picks its high half; abs then neg apply after widening. The shared handler now reads high halves, accepts neg/abs on binary16 registers, and refuses op_sel on a binary32 source, unknown modifiers, and inline floats or literals on binary16 sources (mixlo/mixhi used to read the binary32 bits of 1.0 as 0). Refs R0Y00#1723 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Restore the negated inline zero on binary16 sources, read it as -0.0 on every source, and check the test encoder against two llvm-mc words. Refs R0Y00#1723 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Emit neg on a negative inline float (`--0.5`) as `(-(-0.5))` instead of an HLSL decrement, and refuse binary32 sources printed as a negative integer or literal, where the decoder text loses the sign-bit flip (review on R0Y00#2055). Refs R0Y00#1723 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Check op_sel on a binary32 source before the -0 shortcut, drop a stray tool marker from a comment, and fix the docs wording about earlier op_sel handling. Add a check mode that compiles every translated line with FXC for ps_5_1 (startup_gfx2hlsl_fma_mix_fxc when FXC is found), and cases for a register with undefined upper bits after an odd-dmask D16 image_load: a low-half read is accepted, high-half and binary32 reads are refused. Refs R0Y00#1723 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs R0Y00#1723 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ence Add a dispatch mode to startup_gfx2hlsl_fma_mix_check.py. Every translated line runs in a DXC cs_6_0 thread on WARP or a hardware adapter, and each result word is compared with a CPU reference that decodes the VOP3P word itself (LLVM 15 reading). A control drops the high-half shift and must then follow a reference with op_sel cleared. Registered as startup_gfx2hlsl_fma_mix_dispatch_warp and _hardware (review on R0Y00#2055). Refs R0Y00#1723 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review nit on R0Y00#2055. Refs R0Y00#1723 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7d28557 to
9d64a6b
Compare
|
Hardware run and Windows 11 MSVC build at head Environment: Windows 11 Pro build 26300.9974, Debug ( Build: Tests:
The hardware test runs the translated shader on the GPU and prints Not covered by this run: AMD hardware, and any draw (pixel shader) path; only the compute dispatch was run. |
# Conflicts: # CMakeLists.txt
The union resolver truncated the R0Y00#2404 lds_b128 control block (missing PASS_REGULAR_EXPRESSION and endforeach) and registered fma_mix, fract and fract_draw twice after the updated R0Y00#2055/R0Y00#2010 heads. Configure succeeds again; every add_test of the merged PR heads is present once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tedin7
left a comment
There was a problem hiding this comment.
Review of head 48c38d2 (after updating with main). Code and fixture review only; no executable results claimed.
What I checked:
Stage.mix()intools/startup/gfx2hlsl.py: op_sel_hi = binary16 flag, op_sel = high half, abs then neg after widening, clamp, refusal of op_sel on binary32 sources and of unknown modifiers. This matches the LLVM 15 reading quoted in the description.- Sibling callsites: mixlo/mixhi share the same path; the CMake entries (CPU, fxc, warp/hardware dispatch), the Windows CI list and AGENTS.md all list the new test.
pixel_aothandling is a separate slice (#2103), no overlap in files. - The new test has a real D3D12 dispatch (warp/hardware) against a CPU reference that decodes the VOP3P word itself.
Commands run locally on the head:
python3 -B tests/startup_gfx2hlsl_fma_mix_check.py-> all checks passed- all
tests/startup_gfx2hlsl_*_check.py-> no failures python3 tests/docs_links_check.py,python3 tests/bidi_controls_check.py-> passgit diff --check origin/main...HEAD-> clean- Mutation 1: drop the
>> 16high-half shift -> 6 checks fail as intended - Mutation 2: change inline-0 text from
0.0to1.0-> test fails
No blocking findings. Windows WARP run follows separately.
AI-assisted; commands listed were executed locally.
|
Win2025 WARP receipt for head 48c38d2 after updating with main. Focused run: startup_gfx2hlsl_fma_mix, _fxc and _dispatch_warp all passed (3/3, dev and release). Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
AI-assisted; commands listed were executed locally. |
Scope: this adds
v_fma_mix_f32totools/startup/gfx2hlsl.py. It also changes howv_fma_mixlo_f16andv_fma_mixhi_f16read their sources, because all three now shareStage.mix(). Some mixlo/mixhi forms that used to translate (incorrectly) are now refused; see below.Refs #1723. The 2026-11-24 refusal snapshot there lists
v_fma_mix_f32in 58 code pairs. I did not re-run the census, because I have no recorded cache, so I make no claim about how many of those pairs now translate.Semantics
Source selection follows LLVM 15 (
AMDGPUDAGToDAGISel::SelectVOP3PMadMixModsImpl, llvmorg-15.0.7):AMDGPUInstPrinter::printOpSelHiprintsSISrcMods::OP_SEL_1, the bit that function sets for an fp16 source. abs and then neg apply after widening.tools/ffx_dispatch_aot.pyuses the same reading.Changes in
Stage.mix()v_fma_mix_f32 v1, v2, v3, v4v1 = U(F(v2) * F(v3) + F(v4));… op_sel:[1,0,0] op_sel_hi:[1,0,0](high half of src0)f16tof32(v2 >> 16)-|s5|on a binary16 source(-abs(f16tof32(s5 >> 16)))-0on any source0.0(binary32), accepted on binary16(-0.0)op_selon a binary32 sourceneg_lo)1.0withop_sel_hi:[0,1,0]f16tof32(0x3f800000u), i.e. 0Test
tests/startup_gfx2hlsl_fma_mix_check.py(startup_gfx2hlsl_fma_mix) is device-free:llvm-mcwords already pinned intests/rdna2_tools_check.py;op_selandop_sel_hichanges the output;Negative control: on
mainthe check fails at the first form (Unsupported: v_fma_mix_f32).Result: at the base
25317c63plus this branch (headdc9a7f4b), all 98startup_gfx2hlsl_*tests pass in thedevpreset (Debug, MSVC 14.44, Windows 11 26300.9974). That includesstartup_gfx2hlsl_fma_mix_fxc, which compiles all 13 translated lines with FXC 10.0.26100 for ps_5_1.pso_readiness_check.py,rdna2_tools_check.py,startup_translator_check.py,startup_gfx2hlsl_handler_arity_check.py,docs_links_check.pyandbidi_controls_check.pypass. This is translation and compilation only; no draw or dispatch was run.Not changed
tools/pixel_aot.pyreads the two selector fields the other way round. That is tracked separately in #2054.🤖 Generated with Claude Code