Recompiler: keep memory unchanged on NaN operands in atomic fmin/fmax #1261
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1271"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T14:03:48Z.
float_minmax_memrouted 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_fmininstead of leaving memory unchanged per IEEEminNum/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) infloat_minmax_memfor both f32 and f64 (_x2), loading{old}without writing memory.crates/xcl/src/gpu/recomp/tests.rs: add GPU testgpu_atomic_fmin_fmax_nan_operand_leaves_memorycovering+qNaN/-qNaNforGLOBAL_ATOMIC_FMIN,GLOBAL_ATOMIC_FMAX,GLOBAL_ATOMIC_FMIN_X2, andGLOBAL_ATOMIC_FMAX_X2withGLC = 1(verified failing before the fix).Tested
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: 2no 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_memoryandatomic_fmin_fmax_x2_are_native_64_bit_atomics: both pass (first failed on the GPU before the fix, overwriting+1.0fwith+qNaN)Regression run
main:
PR:
Not tested
NaNwhen a finite operand arrives (stays non-CAS by design)AI use
emit.rs, wrote the fix and GPU test, ran the test suite andscripts/smoke.ps1regression runs, and drafted this PR description.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T14:07:39Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:Thanks!
Imported from ivall/xcl. Originally posted by DarkPanda69 on 2026-11-25T13:57:51Z.
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
e3b0d02applied onmain06c9f55, debug, Windows 11 Pro 26200,cargo test -p xcl --lib -- gpu:: --test-threads=4:gpu_atomic_fmin_fmax_nan_operand_leaves_memoryok. 639 passed, 2 failed, 22 ignored, 6 SKIPPED; the 2 failures are the AMD fuzz seeds tracked in #2115, the same onmain.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.
Imported from ivall/xcl. Originally posted by S1m0ne1997 on 2026-11-25T14:44:03Z.
Test report for
e3b0d0293a97c637612402ada8312df940809ed7(this PR's head), for #1607.Tested
rustc 1.100.0 (0ef1bc386 2026-11-09)x86_64-pc-windows-msvc, debug.cargo build --workspace, thencargo test --workspace -- --test-threads=4at the head: 752 passed, 0 failed, 41 ignored.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;mainbuilt from the commit in its block, this PR from its head with no changes tocrates/, both run with thescripts/smoke.ps1ofmain, which hashes the name of the game folder)main:
this PR:
Not tested
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.
Imported from ivall/xcl. Originally posted by Lum7nt on 2026-11-25T14:54:33Z.
Tested on \
e3b0d0293a\ (\e3b0d02, clean PR head):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.
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T20:42:23Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by brainhay5 on 2026-11-30T05:57:15Z.
merge-check claim
head:
e3b0d0293aImported from ivall/xcl. Originally posted by brainhay5 on 2026-11-30T06:03:19Z.
merge-check
base:
d52ff48caahead:
e3b0d0293amerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2875 passed, 3 failed, 51 ignored; 29 SKIPPED lines
failing: gpu::recomp::tests::gpu_atomic_fmin_fmax_nan_operand_leaves_memory
failing: test_title_runs_and_game_folder_is_untouched
review: automated overnight check — diff inspected for safety only (no build/CI/toolchain/script changes, no process/network/runtime-loading code); no duplicate search performed; no line-by-line code review.
performance: not assessed beyond the suite.
verdict: not yet: adds failing test(s): gpu::recomp::tests::gpu_atomic_fmin_fmax_nan_operand_leaves_memory
hardware / tool and model: RTX 5070 Ti 16 GB, driver 610.88 (32.0.16.1088); Ryzen 7 5800X3D, 64 GB; Windows 11 22631; OpenCode agent, DeepSeek V4.1 Flash 1017
correction: this check first reported the PR as "not yet" because of a test failure that is not the PR's. The base-comparison step failed to run (test names contain a double colon, not a legal Windows filename), so an empty read was mistaken for "passes on base".
gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16fails on based52ff48cby itself (verified separately with the same command: "assertion failed: 2D D16 resinfo clobbered v2/v3"). Verdict corrected. Apologies for the noise.Imported from ivall/xcl. Originally posted by Elytes on 2026-11-30T09:30:49Z.
merge-check
base:
f95f5f66e2head:
e3b0d0293amerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2883 passed, 2 failed, 51 ignored; SKIPPED: 28 (22 no wave64, 2 no heap windows, 3 no D3D12 debug layer, 1 driver cache needs Developer Mode); failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16 (also fails on main
d52ff48c, measured earlier today) and this PR's gpu::recomp::tests::gpu_atomic_fmin_fmax_nan_operand_leaves_memory (fmin(+qNaN) overwrites +1.0f).review: the fix is right for the HLSL path, but that is no longer the default: with XCL_DIRECT_DXIL unset, the runner and titles go through the direct DXIL translator, whose float_minmax_mem and 64-bit fmin/fmax in dxil/lower_mem.rs have the same missing NaN guard. Measured: with XCL_DIRECT_DXIL=0 the new test passes with the fix and fails without it; by default it fails. #3283 (Kalmarv) ports the guard to lower_mem.rs, with no file overlap, but conflicts with main today. Two ways forward: land #3283 first (then this test passes by default), or make this test run the HLSL path explicitly.
performance: one extra compare per float min/max atomic on the HLSL path only; nothing on the default path (reasoned).
verdict: not yet: the PR's own test fails on main's default (direct DXIL) path; needs #3283 first, or the test pinned to the HLSL path
hardware / tool and model: NVIDIA GeForce RTX 5090 (driver 32.0.16.1742, wave32), Intel Core i9-14900KS, 192 GB, Windows 11 build 26300.10075, rustc 1.100.1, debug / Claude Code (Claude Opus 5.5) ran the merge, build, suite and the HLSL-path runs with and without the fix, searched for the direct DXIL counterpart and reviewed the diff and comments.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:17:48Z.
Triage (#1607) – head
e3b0d02#3283 fixes the same NaN-operand case for the Direct DXIL path (gpu/dxil/lower_mem.rs); this PR fixes the HLSL path (gpu/recomp/emit.rs float_minmax_mem). They complement each other, not duplicates.
The fix is right as far as I can see: on main a +qNaN operand to fmin takes the unsigned InterlockedMax path and overwrites memory with the NaN. The test covers f32 and f64 with GLC.
The branch conflicts with main (emit.rs has moved); it needs a rebase.
Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.