Recompiler: keep memory unchanged on NaN operands in atomic fmin/fmax #1271

Open
github-bot wants to merge 1 commit from github-bot/gh-1271 into main AGit
Owner

@⁠b3IKK on GitHub · 2026-11-24 14:03 UTC · original
b3IKK:recomp/atomic-fmin-fmax-ignore-nan → main · +59 −7 · 2 files · 1 commits · open

float_minmax_mem routed NaN operands (> +inf) into the unsigned branch (InterlockedMax / InterlockedMin), so a NaN operand such as +qNaN (0x7FC00000) overwrote a finite value in memory (e.g. +1.0f) under *_atomic_fmin instead of leaving memory unchanged per IEEE minNum / maxNum.

This guards NaN operands before the signed/unsigned integer-atomic branches so they only load the existing value (for GLC) without modifying memory, preserving the loop-free native integer-atomic lowering for f32 and f64 (no CAS loops added; memory cells already holding NaN remain a known non-CAS limitation).

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: guard NaN operands ((v & ~sign_bit) > +inf) in float_minmax_mem for both f32 and f64 (_x2), loading {old} without writing memory.
  • crates/xcl/src/gpu/recomp/tests.rs: add GPU test gpu_atomic_fmin_fmax_nan_operand_leaves_memory covering +qNaN / -qNaN for GLOBAL_ATOMIC_FMIN, GLOBAL_ATOMIC_FMAX, GLOBAL_ATOMIC_FMIN_X2, and GLOBAL_ATOMIC_FMAX_X2 with GLC = 1 (verified failing before the fix).

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 752 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 no wave64 — gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)
  • cargo test -p xcl --lib gpu_atomic_fmin_fmax_nan_operand_leaves_memory and atomic_fmin_fmax_x2_are_native_64_bit_atomics: both pass (first failed on the GPU before the fix, overwriting +1.0f with +qNaN)

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1226 (PresentX 1226)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15341 MB

PR:

xcl-smoke v1
commit: e3b0d0293a97c637612402ada8312df940809ed7
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1642 (PresentX 1642)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14609 MB

Not tested

  • AMD GPUs and native wave64 hardware
  • memory cells already holding NaN when a finite operand arrives (stays non-CAS by design)
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Gemini 4 Neon: audited emit.rs, wrote the fix and GPU test, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.
**@⁠b3IKK** on GitHub · 2026-11-24 14:03 UTC · [original](https://github.com/xcl-dev/xcl/pull/1271) `b3IKK:recomp/atomic-fmin-fmax-ignore-nan` → `main` · +59 −7 · 2 files · 1 commits · open `float_minmax_mem` routed NaN operands (`> +inf`) into the unsigned branch (`InterlockedMax` / `InterlockedMin`), so a NaN operand such as `+qNaN` (`0x7FC00000`) overwrote a finite value in memory (e.g. `+1.0f`) under `*_atomic_fmin` instead of leaving memory unchanged per IEEE `minNum` / `maxNum`. This guards NaN operands before the signed/unsigned integer-atomic branches so they only load the existing value (for `GLC`) without modifying memory, preserving the loop-free native integer-atomic lowering for f32 and f64 (no CAS loops added; memory cells already holding NaN remain a known non-CAS limitation). **What is in it** - `crates/xcl/src/gpu/recomp/emit.rs`: guard NaN operands (`(v & ~sign_bit) > +inf`) in `float_minmax_mem` for both f32 and f64 (`_x2`), loading `{old}` without writing memory. - `crates/xcl/src/gpu/recomp/tests.rs`: add GPU test `gpu_atomic_fmin_fmax_nan_operand_leaves_memory` covering `+qNaN` / `-qNaN` for `GLOBAL_ATOMIC_FMIN`, `GLOBAL_ATOMIC_FMAX`, `GLOBAL_ATOMIC_FMIN_X2`, and `GLOBAL_ATOMIC_FMAX_X2` with `GLC = 1` (verified failing before the fix). **Tested** - hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`), DXC 1.9.2609.5, debug (`scripts/test.ps1`) and release (`scripts/smoke.ps1`) - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): 752 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 `no wave64` — `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware`) - `cargo test -p xcl --lib gpu_atomic_fmin_fmax_nan_operand_leaves_memory` and `atomic_fmin_fmax_x2_are_native_64_bit_atomics`: both pass (first failed on the GPU before the fix, overwriting `+1.0f` with `+qNaN`) **Regression run** main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1226 (PresentX 1226) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15341 MB ``` PR: ``` xcl-smoke v1 commit: e3b0d0293a97c637612402ada8312df940809ed7 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1642 (PresentX 1642) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14609 MB ``` **Not tested** - AMD GPUs and native wave64 hardware - memory cells already holding `NaN` when a finite operand arrives (stays non-CAS by design) - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Gemini 4 Neon: audited `emit.rs`, wrote the fix and GPU test, ran the test suite and `scripts/smoke.ps1` regression runs, and drafted this PR description.
float_minmax_mem routed NaN operands (> +inf) into the unsigned branch
(InterlockedMax / InterlockedMin), so a NaN operand such as +qNaN
(0x7FC00000) overwrote a finite value in memory (e.g. +1.0f) under
*_atomic_fmin instead of leaving memory unchanged per IEEE minNum/maxNum.

Guard NaN operands before the signed/unsigned integer-atomic branches
so they only load the existing value (for GLC) without modifying memory,
preserving the loop-free native integer-atomic lowering for f32 and f64.

Assisted-by: OpenCode (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:49:03 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 14:07 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • lib recomp: 190 passed, 18 ignored, 0 failed.

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 14:07 UTC · [original](https://github.com/xcl-dev/xcl/pull/1271#issuecomment-7133881858) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - lib recomp: 190 passed, 18 ignored, 0 failed. Thanks!
Author
Owner

@⁠DarkPanda69 on GitHub · 2026-11-25 13:57 UTC · original

AMD run with native wave64 (listed as untested), plus an RTX 3060: the new test passes on both, so a NaN operand leaves memory unchanged on the AMD driver too.

Head e3b0d02 applied on main 06c9f55, debug, Windows 11 Pro 26200, cargo test -p xcl --lib -- gpu:: --test-threads=4:

  • RX 9070 XT (RDNA4, driver 32.0.32029.2010, waves 32..64): gpu_atomic_fmin_fmax_nan_operand_leaves_memory ok. 639 passed, 2 failed, 22 ignored, 6 SKIPPED; the 2 failures are the AMD fuzz seeds tracked in #2115, the same on main.
  • RTX 3060 (driver 32.0.16.1088): the new test ok; 641 passed, 0 failed, 22 ignored.

Not tested: a memory cell already holding NaN, a title, Linux / Wine.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

**@⁠DarkPanda69** on GitHub · 2026-11-25 13:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/1271#issuecomment-7164547137) AMD run with native wave64 (listed as untested), plus an RTX 3060: the new test passes on both, so a NaN operand leaves memory unchanged on the AMD driver too. Head `e3b0d02` applied on `main` `06c9f55`, debug, Windows 11 Pro 26200, `cargo test -p xcl --lib -- gpu:: --test-threads=4`: - **RX 9070 XT** (RDNA4, driver 32.0.32029.2010, waves 32..64): `gpu_atomic_fmin_fmax_nan_operand_leaves_memory` ok. 639 passed, 2 failed, 22 ignored, 6 SKIPPED; the 2 failures are the AMD fuzz seeds tracked in #2115, the same on `main`. - **RTX 3060** (driver 32.0.16.1088): the new test ok; 641 passed, 0 failed, 22 ignored. Not tested: a memory cell already holding NaN, a title, Linux / Wine. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Author
Owner

@⁠S1m0ne1997 on GitHub · 2026-11-25 14:44 UTC · original

Test report for e3b0d0293a97c637612402ada8312df940809ed7 (this PR's head), for #1607.

Tested

  • NVIDIA GeForce RTX 4090 24 GB (driver 621.40), AMD Ryzen 9 9950X3D, 47 GB RAM, Windows 11 Home 10.0.26300, rustc 1.100.0 (0ef1bc386 2026-11-09) x86_64-pc-windows-msvc, debug.
  • cargo build --workspace, then cargo test --workspace -- --test-threads=4 at the head: 752 passed, 0 failed, 41 ignored.
  • SKIPPED (2): gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64).

Regression run (retail title, scripts/smoke.ps1 -Seconds 60, release; main built from the commit in its block, this PR from its head with no changes to crates/, both run with the scripts/smoke.ps1 of main, which hashes the name of the game folder)

main:

xcl-smoke v1
commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324
gpu: NVIDIA GeForce RTX 4090
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1599 (PresentX 1599)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16384 MB

this PR:

xcl-smoke v1
commit: e3b0d0293a97c637612402ada8312df940809ed7
gpu: NVIDIA GeForce RTX 4090
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1660 (PresentX 1660)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16407 MB

Not tested

  • AMD, other NVIDIA cards and drivers, Linux. I did not review the diff; this report is the build, the suite and the regression run only.

AI use: Claude Code with Claude Opus 5.5 ran the build, the suite and the regression run and wrote this report at my request.

**@⁠S1m0ne1997** on GitHub · 2026-11-25 14:44 UTC · [original](https://github.com/xcl-dev/xcl/pull/1271#issuecomment-7165730807) Test report for `e3b0d0293a97c637612402ada8312df940809ed7` (this PR's head), for #1607. **Tested** - NVIDIA GeForce RTX 4090 24 GB (driver 621.40), AMD Ryzen 9 9950X3D, 47 GB RAM, Windows 11 Home 10.0.26300, `rustc 1.100.0 (0ef1bc386 2026-11-09)` `x86_64-pc-windows-msvc`, debug. - `cargo build --workspace`, then `cargo test --workspace -- --test-threads=4` at the head: **752 passed, 0 failed, 41 ignored**. - SKIPPED (2): `gpu_geometry_wave32_prefix_count_over_a_mask` (no wave64), `gpu_wave32_program_in_wave64_hardware` (no wave64). **Regression run** (retail title, `scripts/smoke.ps1 -Seconds 60`, release; `main` built from the commit in its block, this PR from its head with no changes to `crates/`, both run with the `scripts/smoke.ps1` of `main`, which hashes the name of the game folder) main: ``` xcl-smoke v1 commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324 gpu: NVIDIA GeForce RTX 4090 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1599 (PresentX 1599) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16384 MB ``` this PR: ``` xcl-smoke v1 commit: e3b0d0293a97c637612402ada8312df940809ed7 gpu: NVIDIA GeForce RTX 4090 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1660 (PresentX 1660) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16407 MB ``` **Not tested** - AMD, other NVIDIA cards and drivers, Linux. I did not review the diff; this report is the build, the suite and the regression run only. *AI use: Claude Code with Claude Opus 5.5 ran the build, the suite and the regression run and wrote this report at my request.*
Author
Owner

@⁠Lum7nt on GitHub · 2026-11-25 14:54 UTC · original

Tested on \e3b0d0293a\ (\e3b0d02, clean PR head):

  • Hardware / OS / Toolchain: NVIDIA GeForce RTX 3060 12 GB (driver \32.0.15.8142\ / 581.42, wave32), Intel Core i5-10400, Windows 11 (NT \10.0.22631.0),
    ustc 1.100.0\ (\x86_64-pc-windows-msvc), DXC \1.8.2502.11\ (Windows SDK \10.0.26100.0), debug profile, \XCL_ADAPTER=nvidia.
  • Focused GPU run (\cargo test -p xcl --lib atomic_fmin -- --nocapture): 4 passed, 0 failed, 0 ignored (\725 filtered out), including \gpu::recomp::tests::gpu_atomic_fmin_fmax_nan_operand_leaves_memory, \gpu_atomic_fmin_fmax_negative_zero, \gpu_atomic_fmin_fmax_x2, and \tomic_fmin_fmax_x2_are_native_64_bit_atomics.
  • Workspace suite (\cargo test --workspace --no-fail-fast -- --test-threads=4): 751 passed, 1 failed, 41 ignored (708 lib + 43 integration).
    • The 1 failure is \gpu_compute_e2e::offline_compute_pipeline_is_reused_by_a_second_process\ (\driver_file.metadata()\ \ERROR_PATH_NOT_FOUND), which also fails identically on \origin/main\ \
**@⁠Lum7nt** on GitHub · 2026-11-25 14:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/1271#issuecomment-7166003753) **Tested** on \e3b0d0293a97c637612402ada8312df940809ed7\ (\e3b0d02\, clean PR head): - **Hardware / OS / Toolchain:** NVIDIA GeForce RTX 3060 12 GB (driver \32.0.15.8142\ / 581.42, wave32), Intel Core i5-10400, Windows 11 (NT \10.0.22631.0\), \ ustc 1.100.0\ (\x86_64-pc-windows-msvc\), DXC \1.8.2502.11\ (Windows SDK \10.0.26100.0\), debug profile, \XCL_ADAPTER=nvidia\. - **Focused GPU run (\cargo test -p xcl --lib atomic_fmin -- --nocapture\):** **4 passed, 0 failed, 0 ignored** (\725 filtered out\), including \gpu::recomp::tests::gpu_atomic_fmin_fmax_nan_operand_leaves_memory\, \gpu_atomic_fmin_fmax_negative_zero\, \gpu_atomic_fmin_fmax_x2\, and \tomic_fmin_fmax_x2_are_native_64_bit_atomics\. - **Workspace suite (\cargo test --workspace --no-fail-fast -- --test-threads=4\):** **751 passed, 1 failed, 41 ignored** (708 lib + 43 integration). - The 1 failure is \gpu_compute_e2e::offline_compute_pipeline_is_reused_by_a_second_process\ (\driver_file.metadata()\ \ERROR_PATH_NOT_FOUND\), which also fails identically on \origin/main\ \
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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