Skip to content

shader: lower v_fma_mix_f32 in gfx2hlsl - #2055

Merged
tedin7 merged 9 commits into
R0Y00:mainfrom
Not-Saii:shader/gfx2hlsl-fma-mix-f32
Nov 25, 2026
Merged

tedin7 merged 9 commits into
R0Y00:mainfrom
Not-Saii:shader/gfx2hlsl-fma-mix-f32

Conversation

@Not-Saii

@Not-Saii Not-Saii commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Scope: this adds v_fma_mix_f32 to tools/startup/gfx2hlsl.py. It also changes how v_fma_mixlo_f16 and v_fma_mixhi_f16 read their sources, because all three now share Stage.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_f32 in 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):

If the source's op_sel_hi is set, it indicates to do a conversion from fp16. If the sources's op_sel is set, it picks the high half of the source register.

AMDGPUInstPrinter::printOpSelHi prints SISrcMods::OP_SEL_1, the bit that function sets for an fp16 source. abs and then neg apply after widening. tools/ffx_dispatch_aot.py uses the same reading.

Changes in Stage.mix()

Form Before After
v_fma_mix_f32 v1, v2, v3, v4 refused v1 = U(F(v2) * F(v3) + F(v4));
… op_sel:[1,0,0] op_sel_hi:[1,0,0] (high half of src0) refused on all three forms f16tof32(v2 >> 16)
-|s5| on a binary16 source refused (-abs(f16tof32(s5 >> 16)))
-0 on any source 0.0 (binary32), accepted on binary16 (-0.0)
op_sel on a binary32 source refused refused
unknown modifier (e.g. neg_lo) ignored refused
inline float on a binary16 source, e.g. mixlo 1.0 with op_sel_hi:[0,1,0] translated as f16tof32(0x3f800000u), i.e. 0 refused
literal on a binary16 source translated from the low half refused

Test

tests/startup_gfx2hlsl_fma_mix_check.py (startup_gfx2hlsl_fma_mix) is device-free:

  • the hand encoder reproduces the two llvm-mc words already pinned in tests/rdna2_tools_check.py;
  • the decoded text and the translation of ten forms are pinned;
  • two controls check that flipping op_sel and op_sel_hi changes the output;
  • four refusals.

Negative control: on main the check fails at the first form (Unsupported: v_fma_mix_f32).

ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_' -V

Result: at the base 25317c63 plus this branch (head dc9a7f4b), all 98 startup_gfx2hlsl_* tests pass in the dev preset (Debug, MSVC 14.44, Windows 11 26300.9974). That includes startup_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.py and bidi_controls_check.py pass. This is translation and compilation only; no draw or dispatch was run.

Not changed

tools/pixel_aot.py reads the two selector fields the other way round. That is tracked separately in #2054.

🤖 Generated with Claude Code

@Not-Saii
Not-Saii force-pushed the shader/gfx2hlsl-fma-mix-f32 branch from bbdc504 to d725058 Compare November 24, 2026 23:54
@Leyukaka

Copy link
Copy Markdown
Contributor

Read the diff only (not run). The selector reading matches LLVM's SelectVOP3PMadMixModsImpl: op_sel_hi means "convert from fp16" and op_sel "high half". Refusing op_sel on a binary32 source looks right.

Two cases on the binary32 path go through Stage.f. They are not new: the existing mixlo/mixhi lowering already sends binary32 sources there. This PR adds v_fma_mix_f32 to them.

  1. --0.5 (NEG on inline -0.5). disasm_rdna2.py prints --0.5. f('--0.5') treats the first - as NEG and finds -0.5 in FLOATS, so it emits (--0.5). HLSL lexes -- as a decrement, so the shader does not compile. Example: v_fma_mix_f32 v0, --0.5, v1, v2. Emitting (-(-0.5)) or folding to 0.5 avoids it.

  2. NEG on an inline integer or a literal. f() reads any -N as an integer and drops the NEG bit.

    • For NEG on inline 1..16 the text is the same as the inline negative integer (-1 is either 193 or NEG on 129). f('-1') emits F(0xffffffffu), a NaN; NEG on inline 1 is 0x80000001.
    • NEG on 17..64 (-17..-64) is not ambiguous, but it is still read as a negative integer.
    • NEG on a literal (-0x…) is mis-read the same way.

    For v_cndmask_b32_e64, startup: lower NEG on an immediate source of v_cndmask_b32_e64 from its encoding #1932 resolved this in the decoder (check_encoding() rewrites the operand from the encoding). Here, refusing -<digits> and -0x… sources in mix is the conservative option until the decoder does the same for VOP3P.

AI-assisted.

Not-Saii added a commit to Not-Saii/Xbox2Windows that referenced this pull request Nov 25, 2026
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>
@Not-Saii

Copy link
Copy Markdown
Contributor Author

Thanks. Both findings are addressed in 63bafe58, scoped to mix(). I didn't change Stage.f, because other handlers call it:

  1. --0.5: neg on a negative inline float now emits (-(-0.5)). FXC 10.0.26100 compiles it. The decoded text v_fma_mix_f32 v1, --0.5, v3, v4 is pinned in the check.
  2. Negated integer or literal: a binary32 source matching -<digits> or -0x… is now refused, as you suggested, until the decoder resolves VOP3P operands from the encoding the way startup: lower NEG on an immediate source of v_cndmask_b32_e64 from its encoding #1932 does for v_cndmask_b32_e64. The check adds refusals for neg on inline 1, inline -1 (the same text), neg on inline 17 and neg on a literal. A control checks that an unnegated literal still translates.

Without the fix, exactly these five new cases fail. With it, all 45 startup_gfx2hlsl_* tests pass locally (ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_').

AI-assisted (Claude Code).

@Not-Saii
Not-Saii force-pushed the shader/gfx2hlsl-fma-mix-f32 branch from 63bafe5 to fd4c334 Compare November 25, 2026 01:02
Not-Saii added a commit to Not-Saii/Xbox2Windows that referenced this pull request Nov 25, 2026
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 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 >> 16 high-half shift in Stage.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 -0 and (-(…)) for --0.5 avoid the HLSL decrement trap.
  • The change in tools/startup/gfx2hlsl.py is 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.

@R0Y00

R0Y00 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

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, python -B tests/startup_gfx2hlsl_fma_mix_check.py passed on the follow-up commit. This is available to cherry-pick onto this PR: 54b947b1.

@Not-Saii
Not-Saii force-pushed the shader/gfx2hlsl-fma-mix-f32 branch from fd4c334 to dc9a7f4 Compare November 25, 2026 10:27
Not-Saii added a commit to Not-Saii/Xbox2Windows that referenced this pull request Nov 25, 2026
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 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (with STARTUP_FXC) only compile it for ps_5_1. Neither runs the shader, so the fma_mix numeric result (>> 16 half select, abs/neg order, clamp, -0 product) 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.py mix: a * b + c in HLSL may not be fused. For f32-sourced operands this can differ by 1 ulp from a true fma. Worth a comment, or use mad/fma if 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.0 becomes 0.0: 2 checks failed.
    • drop abs(): 1 check failed.

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.

@Not-Saii

Copy link
Copy Markdown
Contributor Author

@R0Y00 thanks. 54b947b is now on the PR as 2afae54d, with you as author. Two conflicts with the rebased head, both resolved:

  • gfx2hlsl.py: the register path keeps self.u(tok, low16_only=not is_hi), the D16 low16_only tracking from main. Your literal and inline-0.5 branches come before it unchanged. I dropped the stale "literals stay refused" comment.
  • The check: your cases run before the FXC block, so startup_gfx2hlsl_fma_mix_fxc compiles them too. It now compiles all 17 translated lines for ps_5_1.

741ff02c updates docs/experiments.md for literal half selection and inline 0.5, along with the counts.

On Windows 11 26300.9974 with MSVC 14.44 in the dev preset, all 98 startup_gfx2hlsl_* tests pass (ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_'). The handler-arity, pso_readiness, rdna2_tools, startup_translator, docs-link and bidi checks also pass.

@tedin7, re your P2: this push does not add a WARP readback against a CPU reference yet.

AI-assisted (Claude Code).

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 >> 16 literal half pick (0x40003c00 -> 1.0 / 2.0), inline 0.5 as binary16, abs/neg order, clamp, -0 product. 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 0x40003c00 selects f16tof32(0x3c00u) for the low half and 0x4000 for the high half. Inline 0.5 on the low half is 0.5. Inline 0.5 on 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 + c may 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.5 allowed on the high half: test failed.
    • literal half word flipped (word ^ 1): test failed.

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.

Not-Saii added a commit to Not-Saii/Xbox2Windows that referenced this pull request Nov 25, 2026
…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>
@Not-Saii

Copy link
Copy Markdown
Contributor Author

@tedin7, for your P2: de42d59b adds a dispatch mode to tests/startup_gfx2hlsl_fma_mix_check.py, registered as startup_gfx2hlsl_fma_mix_dispatch_warp and _hardware.

  • What runs: all 17 translated lines run in one DXC cs_6_0 thread through offscreen_check --raw-uav-dump. Each case loads its register words XOR the raw UAV fill pattern, so DXC can't fold them, runs the line and stores the destination.
  • Reference: a CPU reference that decodes the VOP3P word itself, without disasm_rdna2.py or gfx2hlsl, and applies the LLVM 15 reading: op_sel_hi = binary16, op_sel = high half, abs then neg, clamp. It covers the >> 16 selection, abs/neg order, clamp, the -0 product, mixlo/mixhi half preservation and literal halves.
  • Control: it drops the >> 16 from the emitted lines. Its readback must then follow a reference with op_sel cleared in all 4 high-half cases, and differ from the correct result in at least one. It differs in 3; the -0 case has a zero product, so the half doesn't show.
  • Fused vs unfused: the inputs have short mantissas, so fused and unfused give the same word. This check doesn't settle your FMA nit, and I left a * b + c as is.

Results at 741ff02c plus this commit, dev preset, Windows 11 26300.9974:

Adapter Readback vs reference Control
WARP (Microsoft Basic Render Driver, 1414:008c) 17/17 follows the low-half reference 4/4, differs 3/4
NVIDIA GeForce RTX 4090 (10de:2684, driver 32.0.16.1088) 17/17 follows the low-half reference 4/4, differs 3/4

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))?$' -V

All 100 startup_gfx2hlsl_* tests pass when run serially. The pr CTest preset doesn't include startup_gfx2hlsl_*_warp tests, the mad dispatch tests included, so PR CI won't run this one. The full non-hardware suite on main or a manual run will.

AI-assisted (Claude Code).

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 >> 16 from the emitted lines. The readback must then match a reference with op_sel cleared and differ from the correct result somewhere. Good: this proves the readback is sensitive to the half select. The -0 case is correctly excluded from "differs" (zero product).
  • Fine: exit 77 maps to CTest SKIP, -j1 in 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.py mix: a * b + c may 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 for clamp in mix: the text check fails (reverted with git 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_warp 0.50s, _dispatch_hardware 0.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.

Not-Saii added a commit to Not-Saii/Xbox2Windows that referenced this pull request Nov 25, 2026
Review nit on R0Y00#2055.

Refs R0Y00#1723

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Not-Saii and others added 8 commits November 25, 2026 16:32
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>
@Makto94

Makto94 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Hardware run and Windows 11 MSVC build at head 9d64a6b5.

Environment: Windows 11 Pro build 26300.9974, Debug (dev preset), MSVC 19.44.35230.0 (cl 14.44.35207), driver 32.0.16.2101. The hardware test prints adapter=NVIDIA GeForce RTX 3070 Ti vendor=10de device=2482 and backend=hardware debug_layer=enabled, with debug_errors=0 debug_warnings=0. The runs were serial (-j1); the hardware run was on an idle machine.

Build: cmake --build --preset dev exited 0. This PR changes no C++ source.

Tests:

  • ctest --preset dev --no-tests=error -j1 -R 'startup_gfx2hlsl_fma_mix' -E 'hardware' -V: 3/3 passed (startup_gfx2hlsl_fma_mix, _fxc, _dispatch_warp).
  • ctest --preset dev --no-tests=error -j1 -R 'startup_gfx2hlsl_fma_mix_dispatch_hardware' -V: 1/1 passed. 0 capability skips (77).

The hardware test runs the translated shader on the GPU and prints hardware: ... readback: ok for all 17 dispatch cases. The control without the high-half shift reads the low half in all 4 high-half cases and changes 3 of 4 high-half results, so the check can fail. The final line is all fma_mix checks passed.

Not covered by this run: AMD hardware, and any draw (pixel shader) path; only the compute dispatch was run.

legacy-code-archaeologist added a commit to legacy-code-archaeologist/Xbox2Windows that referenced this pull request Nov 25, 2026
# Conflicts:
#	CMakeLists.txt
legacy-code-archaeologist added a commit to legacy-code-archaeologist/Xbox2Windows that referenced this pull request Nov 25, 2026
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 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head 48c38d2 (after updating with main). Code and fixture review only; no executable results claimed.

What I checked:

  • Stage.mix() in tools/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_aot handling 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 -> pass
  • git diff --check origin/main...HEAD -> clean
  • Mutation 1: drop the >> 16 high-half shift -> 6 checks fail as intended
  • Mutation 2: change inline-0 text from 0.0 to 1.0 -> test fails

No blocking findings. Windows WARP run follows separately.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

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 48c38d2d9bcd742f3d677d93c63bbb3c7df72a16:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target offscreen_check -- -j 2): 0.93s (configure 2.16s)
    • Test (ctest --preset dev -R 'startup_gfx2hlsl_fma_mix($|_dispatch_warp|_fxc)' --parallel 2 --no-tests=error --output-on-failure): 3/3 passed (0.58s: startup_gfx2hlsl_fma_mix 0.11s, startup_gfx2hlsl_fma_mix_fxc 0.13s, startup_gfx2hlsl_fma_mix_dispatch_warp 0.34s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target offscreen_check -- -j 2): 1.15s (configure 2.19s)
    • Test (ctest --preset release -R 'startup_gfx2hlsl_fma_mix($|_dispatch_warp|_fxc)' --parallel 2 --no-tests=error --output-on-failure): 3/3 passed (0.52s: startup_gfx2hlsl_fma_mix 0.10s, startup_gfx2hlsl_fma_mix_fxc 0.12s, startup_gfx2hlsl_fma_mix_dispatch_warp 0.29s)
  • Windows Python checks: tests/mesh_heap_sampler_check.py ok (0.7s), tests/startup_buffer_address_check.py ok (0.5s), tests/startup_buffer_format_word3_table_check.py ok (0.1s), tests/startup_compute_request_offline_check.py ok (0.5s), tests/startup_compute_translate_check.py ok (0.3s), tests/startup_flat_param_check.py ok (0.1s), tests/startup_gfx2hlsl_add_sub_co_check.py ok (0.1s), tests/startup_gfx2hlsl_add_sub_co_ci_check.py ok (0.1s), tests/startup_gfx2hlsl_bit_alu_check.py ok (0.7s), tests/startup_gfx2hlsl_capture_check.py ok (1.1s), tests/startup_gfx2hlsl_cmp16_check.py ok (0.2s), tests/startup_gfx2hlsl_compare_dst_check.py ok (0.1s), tests/startup_gfx2hlsl_compute_check.py ok (0.4s), tests/startup_gfx2hlsl_cselect_mask_check.py ok (0.1s), tests/startup_gfx2hlsl_cvt_alu_check.py ok (0.1s), tests/startup_gfx2hlsl_cvt_off_f32_i4_check.py ok (0.2s), tests/startup_gfx2hlsl_f32_lg_check.py ok (1.3s), tests/startup_gfx2hlsl_f32_nan_check.py ok (7.5s), tests/startup_gfx2hlsl_fma_mix_check.py ok (1.5s), tests/startup_gfx2hlsl_getpc_refusal_check.py ok (0.2s), tests/startup_gfx2hlsl_handler_arity_check.py ok (0.2s), tests/startup_gfx2hlsl_image_arity_check.py ok (0.5s), tests/startup_gfx2hlsl_image_get_lod_check.py ok (0.3s), tests/startup_gfx2hlsl_int_med3_check.py ok (0.2s), tests/startup_gfx2hlsl_join_symbols_check.py ok (0.5s), tests/startup_gfx2hlsl_loop_constants_check.py ok (0.5s), tests/startup_gfx2hlsl_mask_overwrite_check.py ok (0.2s), tests/startup_gfx2hlsl_operand_count_check.py ok (0.8s), tests/startup_gfx2hlsl_pack_absdiff_check.py ok (3.4s), tests/startup_gfx2hlsl_readfirstlane_recompute_check.py ok (0.1s), tests/startup_gfx2hlsl_readfirstlane_uniform_check.py ok (0.1s), tests/startup_gfx2hlsl_refusals_check.py ok (0.6s), tests/startup_gfx2hlsl_root_check.py ok (0.9s), tests/startup_gfx2hlsl_sad_check.py ok (0.4s), tests/startup_gfx2hlsl_saveexec_same_reg_check.py ok (0.1s), tests/startup_gfx2hlsl_scalar_arity_check.py ok (0.2s), tests/startup_gfx2hlsl_scalar_brev_fold_check.py ok (0.1s), tests/startup_gfx2hlsl_scalar_m0_check.py ok (0.2s), tests/startup_gfx2hlsl_scalar_table_arity_check.py ok (0.3s), tests/startup_gfx2hlsl_sdwa_cvt_check.py ok (0.3s), tests/startup_gfx2hlsl_sgpr_spill_check.py ok (0.1s), tests/startup_gfx2hlsl_shift64_check.py ok (0.1s), tests/startup_gfx2hlsl_sload_const_offset_check.py ok (0.1s), tests/startup_gfx2hlsl_smem_offset_check.py ok (0.1s), tests/startup_gfx2hlsl_sop2_complement_check.py ok (5.6s), tests/startup_gfx2hlsl_sopk_accum_check.py ok (0.8s), tests/startup_gfx2hlsl_sopk_signext_check.py ok (0.1s), tests/startup_gfx2hlsl_swap_check.py ok (0.3s), tests/startup_gfx2hlsl_vopc_sdwa_check.py ok (4.1s), tests/startup_gfx2hlsl_waitcnt_depctr_check.py ok (0.1s), tests/startup_gfx2hlsl_watch_check.py ok (2.3s), tests/startup_image_2d_array_check.py ok (0.2s), tests/startup_image_3d_check.py ok (0.1s), tests/startup_image_gather_lz_check.py ok (0.5s), tests/startup_image_load_d16_check.py ok (0.9s), tests/startup_image_sample_a16_check.py ok (0.1s), tests/startup_image_sample_b_check.py ok (0.1s), tests/startup_image_sample_c_check.py ok (0.2s), tests/startup_image_sample_l_check.py ok (0.2s), tests/startup_image_sample_lod_check.py ok (0.6s), tests/startup_inline_sampler_check.py ok (0.1s), tests/startup_mesh57_skeleton_check.py ok (0.2s), tests/startup_run_ps1_check.py ok (9.2s), tests/startup_run_sh_check.py skipped (0.1s), tests/startup_sampler_heap_check.py ok (0.1s), tests/startup_shader_cache_rekey_check.py ok (1.9s), tests/startup_smem_address_check.py ok (0.1s), tests/startup_stream_fetch_check.py ok (0.2s), tests/startup_stream_interface_check.py ok (0.2s), tests/startup_translator_check.py ok (0.4s)
  • sccache: -384/-270 hits; wall 69.2s

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 merged commit 6dc9520 into R0Y00:main Nov 25, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants