startup: accept v_fma_mix reading the low half of a plain v_interp_p2_f16 result #2781

Closed
tedin7 wants to merge 4 commits from upstream-pr/2789 into main
tedin7 commented 2026-11-26 09:20:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T09:20:26Z.


Part of #1723

What this unblocks: pixel programs that feed a plain v_interp_p2_f16 result to v_fma_mix_f32 as a binary16 low half no longer stop at "reads the upper 16 bits".

Source: AMD RDNA2 ISA guide, VOP3P v_fma_mix_f32 / v_fma_mixlo_f16 / v_fma_mixhi_f16: op_sel_hi[i] set means source i is binary16, and op_sel[i] picks its upper half (clear = low half). v_interp_p2_f16 without op_sel 0x8 writes only the low 16 bits of its destination. Stage.mix already lowers this exactly, including op_sel on binary32 sources refused.

What changed

  • interp_f16_scan refused every reader of a plain p2 result except v_cvt_f32_f16. A v_fma_mix* whose every source naming that register has op_sel_hi set and op_sel clear reads only defined bits, so it is accepted.
  • A v_fma_mix_f32 rewrites the whole 32-bit destination, so no half of the old value survives: the register leaves the undefined-half state.

Also fixed in the same scan: exp mrt0 v4, ... parses with the export target glued to the first channel, so the scan never saw the first exported register; a plain p2 result exported as channel x went unchecked (found by mutation: dropping the "mix rewrites the destination" step survived). The first channel is read now.

What stays refused: an op_sel pick of the upper half, a binary32 source (no op_sel_hi), and every other reader of an undefined upper half.

Tests: startup_gfx2hlsl_interp_f16_check.py gains four llvm-mc-verified variants (plus a draw readback, below) (low half accepted and evaluated against the binary32 product, upper-half pick refused, binary32 source refused, plain p2 result exported as the first channel refused). The accepted case is refused on main with the old message.

Verification:

  • python3 -B tests/startup_gfx2hlsl_interp_f16_check.py -> controls ok; on origin/main the same file fails with "v_fma_mix_f32 reads the upper 16 bits of the v_interp_p2_f16 result v4: not modelled".
  • python3 -B tests/startup_gfx2hlsl_interp_f16_check.py binary llvm-mc-19 -> fixture words match llvm-mc.
  • startup_gfx2hlsl_interp_p2_hi_check.py, startup_gfx2hlsl_fma_mix_check.py -> pass.
  • remote_pycheck.sh <worktree> --compare origin/main -> 0 scripts differ from main.
  • draw mode: the translated fma_mix low half pixel stage is drawn and read back against the ISA arithmetic (binary16 low half squared in binary32), with two wrong-reference controls that must mismatch (plain pair vs mix reference, mix program vs plain reference).
  • tested on RTX 3090 through vkd3d-proton (Linux): startup_gfx2hlsl_interp_f16_{controls,warp,hardware} 3/3 passed at head 959b38b64.
  • Mutation: replacing the "mix rewrites the destination" step with pass now fails the check.
  • Win2025 WARP dev+release: pending Stage-2.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6623458310 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2789). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T09:20:26Z. --- Part of #1723 What this unblocks: pixel programs that feed a plain `v_interp_p2_f16` result to `v_fma_mix_f32` as a binary16 low half no longer stop at "reads the upper 16 bits". Source: AMD RDNA2 ISA guide, VOP3P `v_fma_mix_f32` / `v_fma_mixlo_f16` / `v_fma_mixhi_f16`: `op_sel_hi[i]` set means source i is binary16, and `op_sel[i]` picks its upper half (clear = low half). `v_interp_p2_f16` without op_sel 0x8 writes only the low 16 bits of its destination. `Stage.mix` already lowers this exactly, including `op_sel` on binary32 sources refused. What changed - `interp_f16_scan` refused every reader of a plain p2 result except `v_cvt_f32_f16`. A `v_fma_mix*` whose every source naming that register has `op_sel_hi` set and `op_sel` clear reads only defined bits, so it is accepted. - A `v_fma_mix_f32` rewrites the whole 32-bit destination, so no half of the old value survives: the register leaves the undefined-half state. Also fixed in the same scan: `exp mrt0 v4, ...` parses with the export target glued to the first channel, so the scan never saw the first exported register; a plain p2 result exported as channel x went unchecked (found by mutation: dropping the "mix rewrites the destination" step survived). The first channel is read now. What stays refused: an `op_sel` pick of the upper half, a binary32 source (no `op_sel_hi`), and every other reader of an undefined upper half. Tests: `startup_gfx2hlsl_interp_f16_check.py` gains four llvm-mc-verified variants (plus a `draw` readback, below) (low half accepted and evaluated against the binary32 product, upper-half pick refused, binary32 source refused, plain p2 result exported as the first channel refused). The accepted case is refused on main with the old message. Verification: - `python3 -B tests/startup_gfx2hlsl_interp_f16_check.py` -> controls ok; on origin/main the same file fails with "v_fma_mix_f32 reads the upper 16 bits of the v_interp_p2_f16 result v4: not modelled". - `python3 -B tests/startup_gfx2hlsl_interp_f16_check.py binary llvm-mc-19` -> fixture words match llvm-mc. - `startup_gfx2hlsl_interp_p2_hi_check.py`, `startup_gfx2hlsl_fma_mix_check.py` -> pass. - `remote_pycheck.sh <worktree> --compare origin/main` -> 0 scripts differ from main. - `draw` mode: the translated `fma_mix low half` pixel stage is drawn and read back against the ISA arithmetic (binary16 low half squared in binary32), with two wrong-reference controls that must mismatch (plain pair vs mix reference, mix program vs plain reference). - tested on RTX 3090 through vkd3d-proton (Linux): `startup_gfx2hlsl_interp_f16_{controls,warp,hardware}` 3/3 passed at head 959b38b64. - Mutation: replacing the "mix rewrites the destination" step with `pass` now fails the check. - Win2025 WARP dev+release: pending Stage-2. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-26 10:04:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T09:55:58Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 959b38b648

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6071940042 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2789#pullrequestreview-6071940042). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T09:55:58Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `959b38b648` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
tedin7 commented 2026-11-26 10:04:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T09:49:31Z.


Independent Stage-2 review of head 959b38b6: PASS (round 2; round 1 failed on a missing GPU readback and a surviving mutant, both fixed in 663c84f1).

  • Round 1 findings, now closed: the accepted v_fma_mix_f32 low-half case is drawn and read back (startup_gfx2hlsl_interp_f16_{warp,hardware}, with two wrong-reference controls that must mismatch), and the "mix rewrites the destination" step is now covered (mutation caught).
  • Mutations tried on the head, each against startup_gfx2hlsl_interp_f16_check.py: op_sel ignored (upper half accepted): caught; binary32 source accepted: caught; destination state kept after a v_fma_mix_f32: caught; first exported channel not read: caught. One survivor is equivalent (the instruction-name guard in mix_low_only is redundant, since non-mix rows carry no op_sel_hi modifier).
  • 173 translation shapes unchanged against origin/main; remote_pycheck.sh --compare origin/main: 0 scripts differ; startup_gfx2hlsl_interp_f16_check.py, its binary llvm-mc-19 mode, interp_p2_hi, fma_mix pass.
  • Hygiene: Part of #1723, What this unblocks:, Source: (AMD RDNA 2 ISA guide, VOP3P v_fma_mix_f32 and VINTRP v_interp_p2_f16), Verification: and the signature line are present.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 959b38b64871c58172eeb2b15fbc5ec846ec0508:

  • Debug (--preset dev): cmake --build --preset dev --target offscreen_check -- -j 2 then ctest --preset dev -R '^startup_gfx2hlsl_(interp_f16|interp_p2_hi|fma_mix)' --no-tests=error --output-on-failure: 8/8 passed (startup_gfx2hlsl_interp_f16_controls, _warp, _hardware, startup_gfx2hlsl_interp_p2_hi_controls, startup_gfx2hlsl_fma_mix, _fxc, _dispatch_warp, _dispatch_hardware).
  • Release /O2 (--preset release): the same build and ctest command with --preset release: 8/8 passed, same eight tests.
  • tested on RTX 3090 through vkd3d-proton (Linux): the same 8 tests, 8/8 passed (bash runpod_test.sh 2789).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7188524770 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2789#issuecomment-7188524770). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T09:49:31Z. --- Independent Stage-2 review of head 959b38b6: PASS (round 2; round 1 failed on a missing GPU readback and a surviving mutant, both fixed in 663c84f1). - Round 1 findings, now closed: the accepted `v_fma_mix_f32` low-half case is drawn and read back (`startup_gfx2hlsl_interp_f16_{warp,hardware}`, with two wrong-reference controls that must mismatch), and the "mix rewrites the destination" step is now covered (mutation caught). - Mutations tried on the head, each against `startup_gfx2hlsl_interp_f16_check.py`: `op_sel` ignored (upper half accepted): caught; binary32 source accepted: caught; destination state kept after a `v_fma_mix_f32`: caught; first exported channel not read: caught. One survivor is equivalent (the instruction-name guard in `mix_low_only` is redundant, since non-mix rows carry no `op_sel_hi` modifier). - 173 translation shapes unchanged against `origin/main`; `remote_pycheck.sh --compare origin/main`: 0 scripts differ; `startup_gfx2hlsl_interp_f16_check.py`, its `binary llvm-mc-19` mode, `interp_p2_hi`, `fma_mix` pass. - Hygiene: `Part of #1723`, `What this unblocks:`, `Source:` (AMD RDNA 2 ISA guide, VOP3P `v_fma_mix_f32` and VINTRP `v_interp_p2_f16`), `Verification:` and the signature line are present. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `959b38b64871c58172eeb2b15fbc5ec846ec0508`: - Debug (`--preset dev`): `cmake --build --preset dev --target offscreen_check -- -j 2` then `ctest --preset dev -R '^startup_gfx2hlsl_(interp_f16|interp_p2_hi|fma_mix)' --no-tests=error --output-on-failure`: 8/8 passed (`startup_gfx2hlsl_interp_f16_controls`, `_warp`, `_hardware`, `startup_gfx2hlsl_interp_p2_hi_controls`, `startup_gfx2hlsl_fma_mix`, `_fxc`, `_dispatch_warp`, `_dispatch_hardware`). - Release `/O2` (`--preset release`): the same build and ctest command with `--preset release`: 8/8 passed, same eight tests. - tested on RTX 3090 through vkd3d-proton (Linux): the same 8 tests, 8/8 passed (`bash runpod_test.sh 2789`). AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-26 10:04:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T09:49:41Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T09:56:01.073630Z 959b38b Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7188528499 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2789#issuecomment-7188528499). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T09:49:41Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"959b38b64871c58172eeb2b15fbc5ec846ec0508","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-26T09:56:01.073630Z">2026-11-26T09:56:01.073630Z</relative-time> | `959b38b` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
chatgpt-codex-connector[bot commented 2026-11-26 10:04:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T09:55:59Z.

Code review location: tools/startup/gfx2hlsl.py; line 8427

@@ -8403,7 +8424,7 @@ def regs(tok):
                 if r in stale:
                     raise Unsupported('v%d is the v_interp_p1ll_f16 result, which emits nothing: %s reads it after '
                                       'a v_interp_p2_f16 that wrote another register' % (r, n))
-                if r in high_undefined and not (low_reader and r == int(ops[1][1:])):
+                if r in high_undefined and not (low_reader and r == int(ops[1][1:])) and not mix_low_only(n, ops, mods, r):

P1 Badge Validate decorated registers before allowing low-half mix reads

With plain v_interp_p2_f16 results in v4 and v5, v_fma_mix_f32 v4, v4, |v5|, 0 op_sel:[0,1,0] op_sel_hi:[1,1,0] is now accepted despite reading the unmodelled upper half of v5. The scan builds read using regs(o), which does not recognize |v5| or -v5, so the new mix_low_only exception validates only v4. Mutating the added low-half fixture this way succeeds, whereas the parent refuses it, and emits f16tof32(v5 >> 16), allowing unmodelled bits to affect the exported result. Normalize negation/absolute-value modifiers when collecting source registers, and add a refusal control using distinct interpolation-result registers.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4706573372 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2789#discussion_r4706573372). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T09:55:59Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 8427 ~~~~diff @@ -8403,7 +8424,7 @@ def regs(tok): if r in stale: raise Unsupported('v%d is the v_interp_p1ll_f16 result, which emits nothing: %s reads it after ' 'a v_interp_p2_f16 that wrote another register' % (r, n)) - if r in high_undefined and not (low_reader and r == int(ops[1][1:])): + if r in high_undefined and not (low_reader and r == int(ops[1][1:])) and not mix_low_only(n, ops, mods, r): ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Validate decorated registers before allowing low-half mix reads** With plain `v_interp_p2_f16` results in `v4` and `v5`, `v_fma_mix_f32 v4, v4, |v5|, 0 op_sel:[0,1,0] op_sel_hi:[1,1,0]` is now accepted despite reading the unmodelled upper half of `v5`. The scan builds `read` using `regs(o)`, which does not recognize `|v5|` or `-v5`, so the new `mix_low_only` exception validates only `v4`. Mutating the added low-half fixture this way succeeds, whereas the parent refuses it, and emits `f16tof32(v5 >> 16)`, allowing unmodelled bits to affect the exported result. Normalize negation/absolute-value modifiers when collecting source registers, and add a refusal control using distinct interpolation-result registers. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
upstream-sync closed this pull request 2026-11-26 11:02:49 +00:00
tedin7 commented 2026-11-26 11:02:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T10:12:53Z.


Withdrawn: shader translation is moving to the native C++ frontend (see #870), so we are not continuing this change to the Python translator. The branch stays available if any part is useful later. Thank you to everyone who reviewed and tested it.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7189061840 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2789#issuecomment-7189061840). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T10:12:53Z. --- Withdrawn: shader translation is moving to the native C++ frontend (see #870), so we are not continuing this change to the Python translator. The branch stays available if any part is useful later. Thank you to everyone who reviewed and tested it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2781
No description provided.