Skip to content

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

Draft
henriazz10 wants to merge 3 commits into
xcl-dev:mainfrom
henriazz10:recompiler/fma-legacy-zero-product
Draft

henriazz10 wants to merge 3 commits into
xcl-dev:mainfrom
henriazz10:recompiler/fma-legacy-zero-product

Conversation

@henriazz10

@henriazz10 henriazz10 commented Nov 24, 2026 •

Copy link
Copy Markdown

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).

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

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 and others added 3 commits November 24, 2026 00:10
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 <noreply@anthropic.com>
… callback

Part of xcl-dev#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 <noreply@anthropic.com>
@henriazz10 henriazz10 changed the title Recompiler: a zero product in v_fma_legacy_f32 still adds c Recompiler: legacy FMA zero product adds c; XAsync waits cover the callback Nov 24, 2026
@dadnotdaddy

Copy link
Copy Markdown

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).

@ryosen0

ryosen0 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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.

@joeypercia

Copy link
Copy Markdown
Contributor

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).

@Toons29

Toons29 commented Nov 24, 2026

Copy link
Copy Markdown

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.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown

Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

@github-actions github-actions Bot added the stale No activity for 3 days; closed 4 days later unless something happens label Nov 29, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Triage (#1607) – head 47b4989

Overlap: the XAsyncGetResultSize hunk in xasync.rs (write 0 while pending, and on the Finished path whatever the status) is the same change as #1201, which makes only that change and is mergeable. The rest of this PR (work and completion items carry the call's Arc<State>, waits cover the completion callback, the fma_legacy zero-product fix in emit.rs, the cube / legacy GPU tests) is not on main and no other open PR does it. #641 also touches xasync.rs but keeps the queue alive after the handle closes (#576 point 2), which is a different problem.
No problems found in the diff. The PR combines a recompiler fix and an XAsync fix that are unrelated. Splitting them, and leaving the GetResultSize part to #1201, would make each easier to review.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale No activity for 3 days; closed 4 days later unless something happens

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants