shader: lower plain e32 binary16 v_fmac_f16 and v_ldexp_f16 in pixel_aot #1120

Merged
tedin7 merged 1 commit from upstream-pr/1127 into main 2026-11-24 02:05:09 +00:00
tedin7 commented 2026-11-24 01:31:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T01:31:56Z.


Change

Lowers the plain e32 binary16 v_fmac_f16 and v_ldexp_f16 in tools/pixel_aot.py (Refs #839, already claimed there). This is separate code from the 16-bit integer conversions in #1077 (now merged): it adds its own helper and its own branch, and does not touch those.

  • v_fmac_f16: fused S0 * S1 + D, rounded once to nearest even with the existing fma16_rne. The destination is the accumulator, so it must already hold a statically proven finite half. src1 must be a VGPR (e32).
  • v_ldexp_f16: S0 * 2^S1 with S1 the signed low 16 bits of a VGPR (high half never read). The exponent must be statically known and within -64..64, so the binary32 product is exact and narrow16 rounds once.
  • Both results are computed exactly at translation time (f16_pk_fmac_lane_result, new f16_ldexp_result), so overflow is refused and chains stay proven. Source proof, entry profile, result tag and readers are those of the binary16 VOP2 arithmetic.
  • The scanner (tools/scan_unsupported_shaders.py) counts the two e32 forms. _e64, DPP, SDWA, clamp, omod and modifiers stay refused.
  • docs/experiments.md has a new paragraph; the new draw has a CTest entry per adapter.

AI-assisted: the code, tests and this description were written with an AI assistant and checked by running the commands below.

Verification

Host: Linux, LLVM 19 locally (CI uses LLVM 15), no DXC and no GPU, so the new draw was not run here.

  • python3 -B tests/pixel_aot_check.py : exit 0 (includes the new check_f16_fmac_ldexp_controls).
  • ./out/pe-env/bin/python -B tests/form_coverage_check.py : form coverage checks passed (new check_f16_fmac_ldexp_forms).
  • python3 -B tests/rdna2_tools_check.py : OK (skipped=10) (scanner rows added to test_low16_binary16_e32_scanner_support).
  • The new check_f16_fmac_ldexp_binary (llvm-mc-19 encodings, disassembly, e64 refusals) and the round trip of all 14 draw programs through llvm-mc and the disassembler were run with LLVM 19 and pass. The whole pixel_aot_check.py binary command stops earlier on an unrelated existing row (check_f16_cvt_int16_binary, a 0xfff0 literal that LLVM 19 prints differently from LLVM 15); CI runs it with LLVM 15.
  • Independent check of the lowering: a line-by-line Python transliteration of fma16_rne, widen16, narrow16 and the scaling product agrees with the reference on 200000 random fused triples and on every finite half times 14 exponents, and on all 24 baked fused rows.
  • Reference: the test's reference finds the nearest binary16 value on the sorted grid of exact values (no formula shared with the translator) and agrees with the translator's own functions on 4000 random triples and scalings.

Negative control (new test fails on origin/main, passes with the change):

  • origin/main tools/pixel_aot.py: every one of the 14 new fixtures is refused with Unsupported instruction 24: v_fmac_f16_e32 v24, v18, v28 (and the ldexp equivalent).
  • This branch: all 14 translate; the controls pass.
  • Draw deviations (run by the CTest draw, 7 batches, each must report pixel_mismatch on its first detecting program): product rounded before the sum, accumulator ignored, multiplicand/accumulator swapped, a source read from bits 31:16 (fused and scaling), exponent negated, subnormal results flushed to signed zero. A Python pre-check in the same test requires each to change at least one expected word and leaves unrelated rows alone.

Evidence and follow-up

  • Fixtures are synthetic: every operand is baked into a program from an inline constant, a 16-bit literal, an SGPR or a VGPR copy of a literal, with junk in bits 31:16 of every source word and in the high half of the exponent words. No game data.
  • Assumptions: the formulas come from the AMD RDNA 2 ISA reference and LLVM 15 VOP2Instructions.td (VOP_F16_F16_I16); not measured on the console. Not covered: NaN and infinity operands, runtime operands and exponents, exponents beyond 64 in magnitude, the destination's high half, the console denormal state.
  • Follow-up for another contributor: the _e64 forms, DPP and SDWA spellings, and a runtime exponent with a range proof.
  • The draw (draw-f16-fmac-ldexp, tests pixel_aot_f16_fmac_ldexp_hardware and _warp) needs a Windows adapter and DXC; please run it in CI or on a Windows host.
  • Reproduce: python3 -B tests/pixel_aot_check.py draw-f16-fmac-ldexp <dxc> <offscreen_check> <adapter>.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6572556569 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1127). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T01:31:56Z. --- ## Change Lowers the plain e32 binary16 `v_fmac_f16` and `v_ldexp_f16` in `tools/pixel_aot.py` (Refs #839, already claimed there). This is separate code from the 16-bit integer conversions in #1077 (now merged): it adds its own helper and its own branch, and does not touch those. - `v_fmac_f16`: fused `S0 * S1 + D`, rounded once to nearest even with the existing `fma16_rne`. The destination is the accumulator, so it must already hold a statically proven finite half. src1 must be a VGPR (e32). - `v_ldexp_f16`: `S0 * 2^S1` with `S1` the signed low 16 bits of a VGPR (high half never read). The exponent must be statically known and within -64..64, so the binary32 product is exact and `narrow16` rounds once. - Both results are computed exactly at translation time (`f16_pk_fmac_lane_result`, new `f16_ldexp_result`), so overflow is refused and chains stay proven. Source proof, entry profile, result tag and readers are those of the binary16 `VOP2` arithmetic. - The scanner (`tools/scan_unsupported_shaders.py`) counts the two e32 forms. `_e64`, DPP, SDWA, `clamp`, omod and modifiers stay refused. - `docs/experiments.md` has a new paragraph; the new draw has a CTest entry per adapter. AI-assisted: the code, tests and this description were written with an AI assistant and checked by running the commands below. ## Verification Host: Linux, LLVM 19 locally (CI uses LLVM 15), no DXC and no GPU, so the new draw was not run here. - `python3 -B tests/pixel_aot_check.py` : exit 0 (includes the new `check_f16_fmac_ldexp_controls`). - `./out/pe-env/bin/python -B tests/form_coverage_check.py` : `form coverage checks passed` (new `check_f16_fmac_ldexp_forms`). - `python3 -B tests/rdna2_tools_check.py` : `OK (skipped=10)` (scanner rows added to `test_low16_binary16_e32_scanner_support`). - The new `check_f16_fmac_ldexp_binary` (llvm-mc-19 encodings, disassembly, e64 refusals) and the round trip of all 14 draw programs through llvm-mc and the disassembler were run with LLVM 19 and pass. The whole `pixel_aot_check.py binary` command stops earlier on an unrelated existing row (`check_f16_cvt_int16_binary`, a `0xfff0` literal that LLVM 19 prints differently from LLVM 15); CI runs it with LLVM 15. - Independent check of the lowering: a line-by-line Python transliteration of `fma16_rne`, `widen16`, `narrow16` and the scaling product agrees with the reference on 200000 random fused triples and on every finite half times 14 exponents, and on all 24 baked fused rows. - Reference: the test's reference finds the nearest binary16 value on the sorted grid of exact values (no formula shared with the translator) and agrees with the translator's own functions on 4000 random triples and scalings. Negative control (new test fails on `origin/main`, passes with the change): - `origin/main` `tools/pixel_aot.py`: every one of the 14 new fixtures is refused with `Unsupported instruction 24: v_fmac_f16_e32 v24, v18, v28` (and the ldexp equivalent). - This branch: all 14 translate; the controls pass. - Draw deviations (run by the CTest draw, 7 batches, each must report `pixel_mismatch` on its first detecting program): product rounded before the sum, accumulator ignored, multiplicand/accumulator swapped, a source read from bits 31:16 (fused and scaling), exponent negated, subnormal results flushed to signed zero. A Python pre-check in the same test requires each to change at least one expected word and leaves unrelated rows alone. ## Evidence and follow-up - Fixtures are synthetic: every operand is baked into a program from an inline constant, a 16-bit literal, an SGPR or a VGPR copy of a literal, with junk in bits 31:16 of every source word and in the high half of the exponent words. No game data. - Assumptions: the formulas come from the AMD RDNA 2 ISA reference and LLVM 15 `VOP2Instructions.td` (`VOP_F16_F16_I16`); not measured on the console. Not covered: NaN and infinity operands, runtime operands and exponents, exponents beyond 64 in magnitude, the destination's high half, the console denormal state. - Follow-up for another contributor: the `_e64` forms, DPP and SDWA spellings, and a runtime exponent with a range proof. - The draw (`draw-f16-fmac-ldexp`, tests `pixel_aot_f16_fmac_ldexp_hardware` and `_warp`) needs a Windows adapter and DXC; please run it in CI or on a Windows host. - Reproduce: `python3 -B tests/pixel_aot_check.py draw-f16-fmac-ldexp <dxc> <offscreen_check> <adapter>`. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets.
upstream-sync closed this pull request 2026-11-24 06:46:28 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:50:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T01:32:05Z.


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-24T01:37:46.032265Z a02c48b PR opened
ℹ️ 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:7119194701 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1127#issuecomment-7119194701). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T01:32:05Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"a02c48bbcc9b26b9b154708b264445e2fd59a677","has_any_findings":false,"has_unresolved_findings":false,"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-24T01:37:46.032265Z">2026-11-24T01:37:46.032265Z</relative-time> | `a02c48b` | PR opened | <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>
thepatrickworld commented 2026-11-24 06:50:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-24T01:53:44Z.


Hardware side of the new entry: CI excludes _hardware$ (-E '_hardware$' in windows.yml), so it is never exercised there. Head a02c48bb merged onto a7710b73 → 3df1ca6e, tree 6b4de6ba, clean tree, dev preset, DXC 1.9.2602.17, RX 9070 XT (vendor 1002, device 7550), driver 32.0.32029.2010, Windows 26200.9711, debug_layer=unavailable.

pixel_aot_f16_fmac_ldexp_hardware passed in 5.81 s, three consecutive runs, with the neighbouring entries green in the same selection (pixel_aot_f16_arith_hardware 10.82 s, pixel_aot_f16_round_hardware 7.16 s) plus three _warp entries. The log carries the mutation sweep on the card — f16_fmac_ldexp mutation unfused: program ('fmac', 0) statuses ['mismatch']. That sweep calls run_pixel_batch_statuses(renderer, ...) and raises when no mismatch appears, so the fmac unfused mutant is detected on the hardware renderer, not only on WARP.

Limits: one GPU, one driver.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7119556316 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1127#issuecomment-7119556316). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-24T01:53:44Z. --- Hardware side of the new entry: CI excludes `_hardware$` (`-E '_hardware$'` in `windows.yml`), so it is never exercised there. Head `a02c48bb` merged onto `a7710b73` → `3df1ca6e`, tree `6b4de6ba`, clean tree, `dev` preset, DXC `1.9.2602.17`, RX 9070 XT (vendor 1002, device 7550), driver `32.0.32029.2010`, Windows `26200.9711`, `debug_layer=unavailable`. `pixel_aot_f16_fmac_ldexp_hardware` passed in 5.81 s, three consecutive runs, with the neighbouring entries green in the same selection (`pixel_aot_f16_arith_hardware` 10.82 s, `pixel_aot_f16_round_hardware` 7.16 s) plus three `_warp` entries. The log carries the mutation sweep on the card — `f16_fmac_ldexp mutation unfused: program ('fmac', 0) statuses ['mismatch']`. That sweep calls `run_pixel_batch_statuses(renderer, ...)` and raises when no mismatch appears, so the fmac unfused mutant is detected on the hardware renderer, not only on WARP. Limits: one GPU, one driver. _AI-assisted._
Toons29 commented 2026-11-24 06:50:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Toons29 on 2026-11-24T02:02:47Z.


Tested a02c48bb on an AMD Radeon RX 9070 (RDNA 4, 1002:7550), driver 32.0.32029.2010, Windows 11 build 26300, dev preset, debug layer unavailable: pass

The description asked for a Windows run of the draw, so here it is:

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

Both pixel_aot_f16_fmac_ldexp_hardware and pixel_aot_f16_fmac_ldexp_warp (in-box WARP 10.0.26100.9818) pass, with no skips. On each adapter all seven mutations come back as mismatch: unfused, no_acc, role_swap and src_high on ('fmac', 0), and exp_negated and flush_out on ('ldexp', 0), plus src_high on ('ldexp', 1). DXC is the Windows SDK copy, 1.9.2602.17.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7119700911 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1127#issuecomment-7119700911). Originally posted by [Toons29](https://github.com/Toons29) on 2026-11-24T02:02:47Z. --- Tested a02c48bb on an AMD Radeon RX 9070 (RDNA 4, `1002:7550`), driver `32.0.32029.2010`, Windows 11 build 26300, `dev` preset, debug layer unavailable: pass The description asked for a Windows run of the draw, so here it is: ```powershell ctest --preset dev --no-tests=error -R '^pixel_aot_f16_fmac_ldexp_' -V ``` Both `pixel_aot_f16_fmac_ldexp_hardware` and `pixel_aot_f16_fmac_ldexp_warp` (in-box WARP `10.0.26100.9818`) pass, with no skips. On each adapter all seven mutations come back as `mismatch`: `unfused`, `no_acc`, `role_swap` and `src_high` on `('fmac', 0)`, and `exp_negated` and `flush_out` on `('ldexp', 0)`, plus `src_high` on `('ldexp', 1)`. DXC is the Windows SDK copy, `1.9.2602.17`.
thepatrickworld commented 2026-11-24 06:50:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-24T02:12:25Z.


Confirmed on the merge commit, since the run above was on a merge I built myself (tree 6b4de6ba) rather than on the tree that shipped: 416084579160b96565ae95be1b55dcf0666584e3, tree b5a0f4f1c955375773dfb6b490a7bd8877c7acfc, clean tree. The same six entries pass, twice — pixel_aot_f16_fmac_ldexp_hardware 5.57 s, pixel_aot_f16_arith_hardware 9.99 s, pixel_aot_f16_round_hardware 6.92 s and the three _warp ones.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7119864658 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1127#issuecomment-7119864658). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-24T02:12:25Z. --- Confirmed on the merge commit, since the run above was on a merge I built myself (tree `6b4de6ba`) rather than on the tree that shipped: `416084579160b96565ae95be1b55dcf0666584e3`, tree `b5a0f4f1c955375773dfb6b490a7bd8877c7acfc`, clean tree. The same six entries pass, twice — `pixel_aot_f16_fmac_ldexp_hardware` 5.57 s, `pixel_aot_f16_arith_hardware` 9.99 s, `pixel_aot_f16_round_hardware` 6.92 s and the three `_warp` ones. _AI-assisted._
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!1120
No description provided.