Recompiler: legacy FMA zero product adds c; XAsync waits cover the callback #670

Open
github-bot wants to merge 3 commits from github-bot/gh-670 into main AGit
Owner

@⁠henriazz10 on GitHub · 2026-11-24 03:11 UTC · original
henriazz10:recompiler/fma-legacy-zero-product → main · +459 −20 · 3 files · 3 commits · draft

Two fixes and a set of GPU tests, kept as separate commits so each can be reviewed or dropped on its own. Part of #576 (points 1, 3 and 4).

  • Recompiler: with a zero multiplicand, v_fma_legacy_f32 / v_fmac_legacy_f32 still add c to a +0.0 product, so c = -0.0 gives +0.0 (LLVM folds fma_legacy(±0.0, x, y) to fadd y, 0.0). The recompiler's fma_legacy helper returned c unchanged and gave -0.0.
  • XAsync (#576): a stale DoWork item could run a later call on a reused XAsyncBlock; XAsyncGetStatus(wait = true) could return before the completion callback ran; XAsyncGetResultSize did not always write the size.

What is in it

  • Tests: GPU tests for V_CUBE*_F32 and the legacy mul / fma / fmac: gpu_cube_face_sc_tc_ma_and_ties and gpu_legacy_zero_wins_mul_fma_fmac in gpu/recomp/tests.rs (test only).
  • Recompiler: a zero product in v_fma_legacy_f32 still adds c: the zero-product branch of fma_legacy in gpu/recomp/emit.rs returns precise c + 0.0f; new test gpu_fma_legacy_zero_product_adds_c (fails without the change: 0x80000000 where 0x00000000 is expected).
  • XGameRuntime: XAsync work items carry their call, and waits cover the callback, in hle/xgameruntime/xasync.rs: each queued item carries its call's state (an Arc as the queue context); a wait returns only after the completion callback has returned, also when it starts after completion (a call without a payload stays registered until its callback returns), and a wait from inside the callback does not deadlock; XAsyncGetResultSize always writes the size. Four new tests, each failing without its part of the change.

Tested

  • NVIDIA GeForce RTX 5080, driver 616.92, wave32; Windows 11 Pro 26300; Rust 1.100, MSVC 14.29 (VS 2019); debug.
  • cargo test --workspace -- --test-threads=4 on this branch (47b4989): 697 passed, 0 failed, 41 ignored.
  • SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.

Regression run

  • None: I have no title for scripts/smoke.ps1. The second and third commits change the runtime (emit.rs, xasync.rs), so this PR needs someone with a title to add the two xcl-smoke blocks. It stays a draft until then.

Not tested

  • AMD GPUs, wave64.
  • Console hardware: the legacy FMA +0.0 result follows LLVM's folding of the instruction; it was not measured on a console. sNaN in c with a zero product is not covered.
  • XAsync with a retail title; #576 point 2 (a closed queue handle) is not part of this PR.

AI use

  • Claude Code (Claude Opus 5.5): wrote the fma_legacy fix, the XAsync change and their tests, the commits and this description; ran the tests.
  • Gemini CLI (model not recorded): wrote the cube and legacy GPU tests in the first commit, first noted the fma_legacy behaviour, and reviewed the XAsync change (found the late-wait case fixed here).

🤖 Generated with Claude Code

**@⁠henriazz10** on GitHub · 2026-11-24 03:11 UTC · [original](https://github.com/xcl-dev/xcl/pull/670) `henriazz10:recompiler/fma-legacy-zero-product` → `main` · +459 −20 · 3 files · 3 commits · draft Two fixes and a set of GPU tests, kept as separate commits so each can be reviewed or dropped on its own. Part of #576 (points 1, 3 and 4). - **Recompiler:** with a zero multiplicand, `v_fma_legacy_f32` / `v_fmac_legacy_f32` still add `c` to a +0.0 product, so `c = -0.0` gives +0.0 (LLVM folds `fma_legacy(±0.0, x, y)` to `fadd y, 0.0`). The recompiler's `fma_legacy` helper returned `c` unchanged and gave -0.0. - **XAsync (#576):** a stale DoWork item could run a later call on a reused `XAsyncBlock`; `XAsyncGetStatus(wait = true)` could return before the completion callback ran; `XAsyncGetResultSize` did not always write the size. **What is in it** - `Tests: GPU tests for V_CUBE*_F32 and the legacy mul / fma / fmac`: `gpu_cube_face_sc_tc_ma_and_ties` and `gpu_legacy_zero_wins_mul_fma_fmac` in `gpu/recomp/tests.rs` (test only). - `Recompiler: a zero product in v_fma_legacy_f32 still adds c`: the zero-product branch of `fma_legacy` in `gpu/recomp/emit.rs` returns `precise c + 0.0f`; new test `gpu_fma_legacy_zero_product_adds_c` (fails without the change: `0x80000000` where `0x00000000` is expected). - `XGameRuntime: XAsync work items carry their call, and waits cover the callback`, in `hle/xgameruntime/xasync.rs`: each queued item carries its call's state (an `Arc` as the queue context); a wait returns only after the completion callback has returned, also when it starts after completion (a call without a payload stays registered until its callback returns), and a wait from inside the callback does not deadlock; `XAsyncGetResultSize` always writes the size. Four new tests, each failing without its part of the change. **Tested** - NVIDIA GeForce RTX 5080, driver 616.92, wave32; Windows 11 Pro 26300; Rust 1.100, MSVC 14.29 (VS 2019); debug. - `cargo test --workspace -- --test-threads=4` on this branch (`47b4989`): 697 passed, 0 failed, 41 ignored. - SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. **Regression run** - None: I have no title for `scripts/smoke.ps1`. The second and third commits change the runtime (`emit.rs`, `xasync.rs`), so this PR needs someone with a title to add the two `xcl-smoke` blocks. It stays a draft until then. **Not tested** - AMD GPUs, wave64. - Console hardware: the legacy FMA +0.0 result follows LLVM's folding of the instruction; it was not measured on a console. sNaN in `c` with a zero product is not covered. - XAsync with a retail title; #576 point 2 (a closed queue handle) is not part of this PR. **AI use** - Claude Code (Claude Opus 5.5): wrote the `fma_legacy` fix, the XAsync change and their tests, the commits and this description; ran the tests. - Gemini CLI (model not recorded): wrote the cube and legacy GPU tests in the first commit, first noted the `fma_legacy` behaviour, and reviewed the XAsync change (found the late-wait case fixed here). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
gpu_cube_face_sc_tc_ma_and_ties checks V_CUBEID / SC / TC / MA_F32 on every
major axis, including ties between components. gpu_legacy_zero_wins_mul_fma_fmac
checks that a zero multiplicand wins over inf and NaN in V_MUL / FMA /
FMAC_LEGACY_F32, with neg, abs and clamp modifiers, and a fused rounding witness.

Assisted-by: Gemini CLI (model not recorded)
With a zero multiplicand the legacy FMA's product is +0.0 and c is still
added to it, so c = -0.0 gives +0.0 (LLVM folds fma_legacy(+/-0.0, x, y)
to fadd y, 0.0). The fma_legacy helper returned c unchanged, so
v_fma_legacy_f32 and v_fmac_legacy_f32 gave -0.0. The add is marked
precise so that DXC keeps it.

New test gpu_fma_legacy_zero_product_adds_c fails without the change
(0x80000000 where +0.0 is expected) on an RTX 5080.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Part of #576 (points 1, 3 and 4).

- A queued DoWork item now carries the state of the call that queued it
  (an Arc passed as the queue context), so a stale item left from an
  earlier call on a reused XAsyncBlock no longer runs the later call.
- XAsyncGetStatus(wait = true) returns only after the completion callback
  has returned, also when the wait starts after the call completed: a call
  without a payload stays registered until its callback returns. A wait
  from inside the callback itself does not deadlock.
- XAsyncGetResultSize always writes the size (0 while pending or when
  there is no payload).

Four new tests in xasync.rs, each failing without its part of the change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:28:57 +00:00
Author
Owner

@⁠dadnotdaddy on GitHub · 2026-11-24 04:11 UTC · original

For the #679 part: the issue's bit-based form, asfloat(select(c == 0.0f, 0u, asuint(c))), leaves DXC nothing to fold and doesn't depend on precise holding across drivers. Tested with a GPU test in #720 (VOP3 and VOP2, c = -0 with 05, -05, 5*-0, 0inf, -0NaN): fails on main, passes with it on an RTX 2070 SUPER. Feel free to take it into this PR; I'll close #720 so there's one fix to review. AI-assisted (Claude Code).

**@⁠dadnotdaddy** on GitHub · 2026-11-24 04:11 UTC · [original](https://github.com/xcl-dev/xcl/pull/670#issuecomment-7121797809) For the #679 part: the issue's bit-based form, `asfloat(select(c == 0.0f, 0u, asuint(c)))`, leaves DXC nothing to fold and doesn't depend on `precise` holding across drivers. Tested with a GPU test in #720 (VOP3 and VOP2, c = -0 with 0*5, -0*5, 5*-0, 0*inf, -0*NaN): fails on main, passes with it on an RTX 2070 SUPER. Feel free to take it into this PR; I'll close #720 so there's one fix to review. AI-assisted (Claude Code).
Author
Owner

@⁠ryosen0 on GitHub · 2026-11-24 04:14 UTC · original

Smoke blocks for this head, from a machine with the title — you asked for someone to run them.

Setup: RTX 3060 Ti 8 GB (wave32), Ryzen 7 9800X3D, 32 GB RAM, driver 32.0.16.1742, Windows 11, release builds, retail title 1.0.2.1, scripts/smoke.ps1 -Seconds 90 (it sets XCL_NETWORK=0 XCL_ACTIVITY=1 itself).

Tests on 47b4989: cargo test --workspace --no-fail-fast -- --test-threads=1: 697 passed, 0 failed, 41 ignored; SKIPPED: the two wave64 GPU tests (no wave64 here). Matches your count on the RTX 5080.

Regression run
Main dd2ae9a (this branch's merge-base):

xcl-smoke v1
commit: dd2ae9a70af5eb5aad60f02d86e386b72abe1e95
gpu: NVIDIA GeForce RTX 3060 Ti
title: ScarlettGame
seconds: 90
exit: 0x0
frames shown: 2402 (PresentX 2402)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14610 MB

Head 47b4989:

xcl-smoke v1
commit: 47b4989511827c6b4e2310223da39b802fc2d781
gpu: NVIDIA GeForce RTX 3060 Ti
title: ScarlettGame
seconds: 90
exit: 0x0
frames shown: 2391 (PresentX 2393)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14489 MB

Both reach the menus at a steady 60 presents / 2 s; the frame-count difference is within run-to-run variance we see between identical builds.

Not tested: the XAsync change against a retail title doing real async work beyond the 90 s menu window (the smoke runs stay in the menus); wave64 hardware; the legacy-FMA result on console hardware (as your description notes).

AI use: GPT-6.2 Astra (API model selector) in DSH built both revisions, ran the suite and the two smoke runs, and wrote this report; the human contributor reviewed the numbers before posting.

**@⁠ryosen0** on GitHub · 2026-11-24 04:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/670#issuecomment-7121833502) Smoke blocks for this head, from a machine with the title — you asked for someone to run them. **Setup:** RTX 3060 Ti 8 GB (wave32), Ryzen 7 9800X3D, 32 GB RAM, driver 32.0.16.1742, Windows 11, release builds, retail title 1.0.2.1, `scripts/smoke.ps1 -Seconds 90` (it sets `XCL_NETWORK=0 XCL_ACTIVITY=1` itself). **Tests** on `47b4989`: `cargo test --workspace --no-fail-fast -- --test-threads=1`: **697 passed, 0 failed, 41 ignored**; SKIPPED: the two wave64 GPU tests (no wave64 here). Matches your count on the RTX 5080. **Regression run** Main `dd2ae9a` (this branch's merge-base): ``` xcl-smoke v1 commit: dd2ae9a70af5eb5aad60f02d86e386b72abe1e95 gpu: NVIDIA GeForce RTX 3060 Ti title: ScarlettGame seconds: 90 exit: 0x0 frames shown: 2402 (PresentX 2402) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14610 MB ``` Head `47b4989`: ``` xcl-smoke v1 commit: 47b4989511827c6b4e2310223da39b802fc2d781 gpu: NVIDIA GeForce RTX 3060 Ti title: ScarlettGame seconds: 90 exit: 0x0 frames shown: 2391 (PresentX 2393) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14489 MB ``` Both reach the menus at a steady 60 presents / 2 s; the frame-count difference is within run-to-run variance we see between identical builds. **Not tested:** the XAsync change against a retail title doing real async work beyond the 90 s menu window (the smoke runs stay in the menus); wave64 hardware; the legacy-FMA result on console hardware (as your description notes). **AI use:** GPT-6.2 Astra (API model selector) in DSH built both revisions, ran the suite and the two smoke runs, and wrote this report; the human contributor reviewed the numbers before posting.
Author
Owner

@⁠joeypercia on GitHub · 2026-11-24 04:14 UTC · original

Data for the precise vs bits question on the fma_legacy part: the precise form doesn't hold on AMD's driver.

I put this PR's helper (precise float z = c + 0.0f; … ? z : …) into main 91f9a5e and ran the zero-product test from #679 (VOP3 v_fma_legacy_f32 and VOP2 v_fmac_legacy_f32; c = -0 with 0 · inf, -0 · 5, 0 · NaN):

precise c + 0.0f (this PR) bits: asfloat(select(c == 0.0f, 0u, asuint(c)))
AMD RDNA2 iGPU (7800X3D), 26.11.2, native wave64 fails: 6 of 6 c = -0 cases give -0 (0x80000000), same as main passes
RTX 4070 Ti, 616.56, wave32 passes passes

Windows 11 Pro 26200, DXC 1.8.2502.11, Rust 1.100.0 MSVC, debug. So the add survives DXC here but AMD's compiler still drops it; on the bits there is nothing for either compiler to fold, which is what @⁠dadnotdaddy suggested.

Also, this PR predates #679 (my search missed drafts, sorry for the duplicate issue). If you take the bit form, a Fixes #679 would close that one too.

Run and report by Claude Code (Claude Opus 5.5).

**@⁠joeypercia** on GitHub · 2026-11-24 04:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/670#issuecomment-7121833531) Data for the `precise` vs bits question on the `fma_legacy` part: **the `precise` form doesn't hold on AMD's driver.** I put this PR's helper (`precise float z = c + 0.0f; … ? z : …`) into `main` `91f9a5e` and ran the zero-product test from #679 (VOP3 `v_fma_legacy_f32` and VOP2 `v_fmac_legacy_f32`; `c = -0` with `0 · inf`, `-0 · 5`, `0 · NaN`): | | `precise c + 0.0f` (this PR) | bits: `asfloat(select(c == 0.0f, 0u, asuint(c)))` | |---|---|---| | AMD RDNA2 iGPU (7800X3D), 26.11.2, native wave64 | **fails: 6 of 6 `c = -0` cases give `-0`** (`0x80000000`), same as `main` | passes | | RTX 4070 Ti, 616.56, wave32 | passes | passes | Windows 11 Pro 26200, DXC 1.8.2502.11, Rust 1.100.0 MSVC, debug. So the add survives DXC here but AMD's compiler still drops it; on the bits there is nothing for either compiler to fold, which is what @⁠dadnotdaddy suggested. Also, this PR predates #679 (my search missed drafts, sorry for the duplicate issue). If you take the bit form, a `Fixes #679` would close that one too. Run and report by Claude Code (Claude Opus 5.5).
Author
Owner

@⁠Toons29 on GitHub · 2026-11-24 13:40 UTC · original

RDNA4 data for the precise vs bits question above: on an RX 9070 this PR's own new test fails the same way as on the RDNA2 iGPU.

Tested

  • 47b4989 merged into main 1ec4c98 (clean merge), debug
  • AMD Radeon RX 9070 (RDNA4, native wave64, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0 (stable MSVC)
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 718 passed, 4 failed, 41 ignored, 0 GPU tests SKIPPED
test result
gpu_fma_legacy_zero_product_adds_c failed: in the whole suite, and 8 of 8 alone (--exact)
the other 6 new tests (gpu_cube_face_sc_tc_ma_and_ties, gpu_legacy_zero_wins_mul_fma_fmac, the 4 XAsync tests) passed 5 of 5 alone each
assertion `left == right` failed: wave64 lane 0 v_fma_legacy_f32(0x00000000, 0x40400000, 0x80000000)
  left: 2147483648
 right: 0

So the precise c + 0.0f add is dropped here too (0x80000000 instead of +0).

With only that helper line changed locally to the bit form suggested above, return (a == 0.0f || b == 0.0f) ? asfloat(select(c == 0.0f, 0u, asuint(c))) : mad(a, b, c); (this PR merged into main 077ce40, everything else as in the PR):

precise c + 0.0f (this PR) bit form
gpu_fma_legacy_zero_product_adds_c, alone fails 3 of 3 passes 3 of 3
gpu_legacy_zero_wins_mul_fma_fmac, alone passes 3 of 3 passes 3 of 3

So the bit form holds on RDNA4 as well as on the RDNA2 iGPU.

The other 3 failures in the suite run are the title-texture trio from #718 (placed_title_textures_share_vram_and_preserve_pixels and the two PoisonError tests). They fail the same way on main 1ec4c98 without this PR and pass alone on both, so they are not from this PR.

Not tested

  • No regression run (scripts/smoke.ps1): I have no retail title.
  • NVIDIA / wave32-only GPUs.

AI use

  • Claude Code (Claude Opus 5.5) ran the builds and tests and drafted this report on the machine above; I checked each point against the logs before posting.
**@⁠Toons29** on GitHub · 2026-11-24 13:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/670#issuecomment-7133172501) RDNA4 data for the `precise` vs bits question above: on an RX 9070 this PR's own new test fails the same way as on the RDNA2 iGPU. **Tested** - `47b4989` merged into `main` `1ec4c98` (clean merge), debug - AMD Radeon RX 9070 (RDNA4, native wave64, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0 (stable MSVC) - `cargo test --workspace --no-fail-fast -- --test-threads=4`: 718 passed, 4 failed, 41 ignored, 0 GPU tests SKIPPED | test | result | |---|---| | `gpu_fma_legacy_zero_product_adds_c` | **failed**: in the whole suite, and 8 of 8 alone (`--exact`) | | the other 6 new tests (`gpu_cube_face_sc_tc_ma_and_ties`, `gpu_legacy_zero_wins_mul_fma_fmac`, the 4 XAsync tests) | passed 5 of 5 alone each | ``` assertion `left == right` failed: wave64 lane 0 v_fma_legacy_f32(0x00000000, 0x40400000, 0x80000000) left: 2147483648 right: 0 ``` So the `precise c + 0.0f` add is dropped here too (`0x80000000` instead of `+0`). With only that helper line changed locally to the bit form suggested above, `return (a == 0.0f || b == 0.0f) ? asfloat(select(c == 0.0f, 0u, asuint(c))) : mad(a, b, c);` (this PR merged into `main` `077ce40`, everything else as in the PR): | | `precise c + 0.0f` (this PR) | bit form | |---|---|---| | `gpu_fma_legacy_zero_product_adds_c`, alone | fails 3 of 3 | **passes 3 of 3** | | `gpu_legacy_zero_wins_mul_fma_fmac`, alone | passes 3 of 3 | passes 3 of 3 | So the bit form holds on RDNA4 as well as on the RDNA2 iGPU. The other 3 failures in the suite run are the title-texture trio from #718 (`placed_title_textures_share_vram_and_preserve_pixels` and the two `PoisonError` tests). They fail the same way on `main` `1ec4c98` without this PR and pass alone on both, so they are not from this PR. **Not tested** - No regression run (`scripts/smoke.ps1`): I have no retail title. - NVIDIA / wave32-only GPUs. **AI use** - Claude Code (Claude Opus 5.5) ran the builds and tests and drafted this report on the machine above; I checked each point against the logs before posting.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 12:21 UTC · original

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

**@⁠DavidM1911** on GitHub · 2026-11-25 12:21 UTC · [original](https://github.com/xcl-dev/xcl/pull/670#issuecomment-7162257174) Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
This pull request has changes conflicting with the target branch.
  • crates/xcl/src/gpu/recomp/tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/670/head:github-bot/gh-670'
git switch 'github-bot/gh-670'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-670'
git switch 'github-bot/gh-670'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-670'
git switch 'github-bot/gh-670'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-670'
git switch 'main'
git merge --squash 'github-bot/gh-670'
git switch 'main'
git merge --ff-only 'github-bot/gh-670'
git switch 'main'
git merge 'github-bot/gh-670'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.