Recompiler: v_rcp_f64 and v_rsq_f64 keep NaN, infinities and denormals #530
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!530
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/530/head"
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?
@pablogonz12 on GitHub · 2026-11-24 01:26 UTC · original
pablogonz12:recomp-f64-rcp-rsq→main· +19 −4 · 2 files · 1 commits · merged 2026-11-25 01:17 UTCv_rcp_f64was translated as(1.0 / x)andv_rsq_f64as(1 / sqrt_d(x)). DXC marks a plain divide fast (no NaN, no infinities), and on RADV (through vkd3d-proton) the divide then gives 0 for 1/NaN:v_rsq_f64of every negative number and of NaN was 0 instead of NaN, which is whatgpu_f64_rootsandgpu_f64_math_randomreport onmainon this GPU. The same divide gave +0 for 1/-inf and flushed 1/DBL_MAX to 0 instead of a denormal.What is in it
crates/xcl/src/gpu/recomp/emit.rs: anrcp_dhelper next tosqrt_d. It returns NaN, ±inf for ±0 and ±0 for ±inf itself (on the bits, withisnan_d/isinf_d), and for the rest divides the mantissa (x scaled into [0.5, 1) withfrexp_exp_d/ldexp_d) as aprecisedivide and scales back withldexp_d, so a result below 2^-1022 is a denormal.v_rcp_f64isrcp_d(x),v_rsq_f64isrcp_d(sqrt_d(x)).crates/xcl/src/gpu/recomp/tests.rs:gpu_f64_rootsalso checksv_rcp_f64overF64_EDGES(1 ulp); the translation test countsrcp_d(sqrt_d(instead of(double)1 / sqrt_d(.Tested
cargo test -p xcl --lib --release --target x86_64-pc-windows-gnu(llvm-mingw), test binary run under Wine with--test-threads=4:e6d5d33): 637 passed, 3 failed, 21 ignored, noSKIPPEDlines. Failing:gpu_nonfused_mad_and_mac_prevent_fma_contraction(#472),xma2_source_voice_decodes_and_manages_lifetime,pe::tests::parses_own_test_binary_tls(#464) – all three fail onmaintoo.main(508a0c7): 632 passed, 8 failed, 21 ignored: the same three,gpu_f64_rootsandgpu_f64_math_random(fixed here), andplaced_title_textures_share_vram_and_preserve_pixels,transitions_apply_when_their_list_is_submitted,d32s8_targets_take_their_own_size_of_video_memory, which this PR does not touch and which passed in the PR's run (they look like the cross-test interference in #343).cargo test ... f64) withXCL_REQUIRE_GPU=1: 13 passed. The newgpu_f64_rootsonmain'semit.rs: FAILED –v_rcp_f64(NaN) = 0,v_rcp_f64(-inf) = 0(want -0),v_rcp_f64(DBL_MAX) = 0(want 5.56e-309),v_rsq_f64(<negative>) = 0(want NaN).Regression run
Made with
scripts/linux/smoke.shfrom #257 under Wine (notsmoke.ps1), MSVC builds (cargo xwin) of both commits, with a local copy of the script in which two lines are changed so that a run which does not reach its end still prints its block (set -euinstead ofset -euo pipefail; thedata:fallback as anif).Not tested
v_rcp_f64/v_rsq_f64on NaN or infinities; the frame counts above are not evidence either way.AI use
github-bot referenced this pull request2026-11-26 04:59:09 +00:00
@thehollowedone on GitHub · 2026-11-24 01:30 UTC · original
Tested
Native Windows D3D12 on RTX 3080 Ti (621.35), Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.99.1 MSVC, DXC 1.8.2502.11, debug. On both exact parent 508a0c7 and PR head e6d5d33, I ran
cargo test --offline --locked -p xcl --lib f64 -- --test-threads=1 --nocapturewithXCL_REQUIRE_GPU=1and separate build directories.Both revisions reported 13 passed, 0 failed, 0 ignored and no reported skips. The PR head passed the expanded root test with reciprocal edge cases. The randomized wave32 test covered 1,600 lanes on each revision. Reciprocal square root was exact on 1,584 lanes and within one ULP on the remaining 16 on both revisions.
Not tested
Full workspace, retail titles, native wave64, and identical reciprocal edge-case inputs on the old lowering. The parent ran its own unmodified tests.
AI use
Codex with GPT-6.2 Sol ran the tests and drafted this report.
@arcwiser on GitHub · 2026-11-24 01:32 UTC · original
Tested exact head
e6d5d332b9787c59951194ee1d3066cb081a9e89on native Windows / NVIDIA.XCL_REQUIRE_GPU=1,cargo test -p xcl --lib f64 -- --test-threads=4 --nocapture: 13 passed, 0 failed, 0 ignored. This includesgpu_f64_rootsandgpu_f64_math_random; the randomized test reported 0 distinct failures (rsqulps 0/1/2/>2:[1584, 16, 0, 0])..\scripts\test.ps1: workspace build passed; 680 passed, 0 failed, 41 ignored.no wave64):gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware. These skips are not counted as coverage.XCL_SAMPLE_*variables were unset, so optional game-data tests did not run. I did not run a retail-title smoke comparison.Machine: Windows 11 Home build 26200; AMD Ryzen 5 7500F; NVIDIA GeForce RTX 4070 SUPER 12 GB, driver 610.88; Rust 1.100.0 MSVC; DXC 1.9.2602.17 from Windows SDK 10.0.28000.0; debug profile.
AI use: OpenAI Codex with GPT-5 selected the verification scope, ran the commands, and drafted this report; I am posting only the measured results above.
@CryingLaughing on GitHub · 2026-11-24 01:33 UTC · original
The exact head
e6d5d332b9787c59951194ee1d3066cb081a9e89passed the Windows workspace suite on an RTX 4080. I also ran the expanded reciprocal edge-case fixture with the parent emitter restored. It passed on both, so I did not reproduce the RADV edge-case failures on this Windows driver.Tested
XCL_ADAPTER=4080,XCL_REQUIRE_GPU=1, synthetic fixtures, allXCL_SAMPLE_*variables unset. Separate Cargo target directories.cargo test -p xcl --lib --locked -j 4 gpu_f64_roots -- --show-outputpassed 1/1 at the exact head and 1/1 with onlycrates/xcl/src/gpu/recomp/emit.rsrestored from parent508a0c74d7c0625d6d2de8d24494e69dc2e1926f. The PR fixture and reciprocal inputs were identical in both runs. Neither run skipped.cargo build --workspace --locked -j 4passed.cargo test --workspace --locked -j 4 -- --test-threads=4 --show-outputreported 680 passed, 0 failed, 41 ignored, including all 13 tests withf64in the name. The pass count includes opt-in game-data tests that returned early and four explicit skips.SKIPPEDfor native wave64:gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware.SKIPPEDfor D3D12 debug-layer availability:test_title_draws_with_a_root_signature_under_the_debug_layeranduploads_start_from_each_subresources_state.Not tested
AI use
@4MDomo on GitHub · 2026-11-24 01:53 UTC · original
NVIDIA test report for
e6d5d33(this PR's head), native Windows D3D12.Tested
stable-x86_64-pc-windows-msvc; DXC 1.8.2502.11 (Windows SDK 10.0.26100.0); debug.cargo test --workspace -- --test-threads=4ate6d5d33: 680 passed, 0 failed, 41 ignored.gpu_f64_roots(with the newv_rcp_f64checks overF64_EDGES) andgpu_f64_math_randompass.main508a0c7the same machine also passesgpu_f64_rootsandgpu_f64_math_random(680 passed, 0 failed, 41 ignored), so the 1/NaN = 0 result does not show on NVIDIA's native driver. The PR keeps it passing there.gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware, as onmain.Not tested
AI use
@ghost on GitHub · 2026-11-24 02:06 UTC · original
Native Windows AMD run, since Not tested lists the native AMD driver:
e6d5d33merged ontomain9ce2070(clean merge): pass. The negative control may matter for how this is tested, though.Tested
.\scripts\test.ps1: 684 passed, 0 failed, 41 ignored; noSKIPPEDGPU tests.XCL_REQUIRE_GPU=wave64,mesh cargo test -p xcl --lib f64: 13 passed, includinggpu_f64_roots(this PR'srcp/rsqchecks) andgpu_f64_math_random.emit.rsback onmain: onlyunary_f64_math_vop1_and_vop3(the HLSL text check,rcp_d(sqrt_d(count 0 vs 2) fails. All 9gpu_f64_*tests still pass, includinggpu_f64_rootswith this PR's checks. So on the native AMD driver the old emission already gives the expected values for these inputs. The GPU test doesn't separate old from new here, and the difference you saw may be specific to RADV through vkd3d-proton. If the RADV failure has an input that isn't ingpu_f64_rootsyet, adding it would tell us whether native AMD is affected.AI use
@tugasky on GitHub · 2026-11-24 02:20 UTC · original
Your "Not tested" list names the native Windows driver, and that is what this machine is:
the same GPU as yours (RX 9070 XT, GFX1201) but Windows 11 and AMD's own driver through
Vulkan, not RADV/vkd3d-proton.
Machine: Windows 11 Pro 26300, Ryzen 7 9700X (8C/16T), Rust 1.98.0
x86_64-pc-windows-msvc, DXC 1.9.2602.17, Radeon RX 9070 XT (RDNA4, 16 GB), driver32.0.32029.2010. Release build. Head
e6d5d33already hasmain(7ebf1b8) as anancestor, so nothing had to be merged.
The f64 GPU tests pass here.
XCL_REQUIRE_GPU=1 cargo test -p xcl --lib --release -- f64 -- --test-threads=4→ 13 passed, 0 failed, including the extendedgpu_f64_roots(rcp over
F64_EDGESat 1 ulp) andgpu_f64_math_random.But the fix changes nothing on this driver, and that is the interesting part.
main'sf64 tests pass here too, which by itself means little (they do not check
v_rcp_f64), soI took only your
tests.rsontomain'semit.rs– a worktree at7ebf1b8withgit checkout e6d5d33 -- crates/xcl/src/gpu/recomp/tests.rs, nothing else, rebuilt – andran the same two tests against the old
(1.0 / x): both pass. On the native AMD Windowsdriver that divide already gives NaN for NaN, −0 for ±inf and a denormal for 1/DBL_MAX, so
the flush you measured on RADV does not exist here. That supports your diagnosis rather
than contradicting it: this is a portability fix, and my machine is the case where the old
translation happened to be right. A 1-ulp tolerance cannot be hiding your failure, which
was 0 instead of NaN, so the new test would have caught it here if it were reachable.
Does this title use the instruction at all? No. A throwaway scanner (decode the way the
recompiler does, count by opcode name) over the whole carved pack, all stages:
v_rcp_f64v_rsq_f64v_sqrt_f64v_rcp_f32(control)v_rsq_f32(control)of 26 698 programs (26 503 containers, 0 undecoded dwords; the 13 210 wave64 VS/PS from
the #517 census are inside). f64 code does exist in this pack, but only in 5 compute
programs, and only as
v_add_f64(216 uses). Sov_rcp_f64andv_rsq_f64never run forthis title on any driver – nor does
v_sqrt_f64, whichmainalready translates withsqrt_d. The PR is right for the recompiler and for the test suite, but it cannot move aframe of this title, and neither can the RADV bug it fixes.
Suite:
cargo build --workspace --release, thencargo test --workspace --release -- --test-threads=4→ 680 passed, 0 failed, 41ignored, no test skipped (701 on the #341/#517/#528 stack, which
maindoes not haveyet). Without the workspace build first, the two
e2etests fail on the missingxcl_testtitle.exe– their own guard, not your change.Not tested: the Windows smoke run (needs the retail title on this machine), NVIDIA and
Intel, and anything on RADV.
No game data in this comment – only counts printed by the tool.
AI use: written with Cline; the runs are from my machine.
mainreaches on Windows; the obstacle is replaced vtables — proposal: proxies #175@Tjabooo on GitHub · 2026-11-24 03:01 UTC · original
The setup this PR targets, RADV through vkd3d-proton, hasn't been tested yet. Here it is:
e6d5d33merged ontomaindd2ae9a(clean merge), pass: it fixes both f64 failures there.Tested
vkd3d-proton-xcl.patchand-Db_ndebug=true, Wine's own dxgi; DXC 2026_09_29 (XCL_DXC_DIR);VKD3D_CONFIG=ignore_shared_fence.x86_64-pc-windows-gnu(mingw-w64 gcc 16.2), debug; tests run under Wine viaCARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUNNER=wine.cargo test -p xcl --lib --locked --target x86_64-pc-windows-gnu -- --test-threads=4, 0 GPU tests SKIPPED:gpu_f64_rootsgpu_f64_math_randommaindd2ae9av_rsq_f64of every negative input,-infand NaN gives0e0, want NaNrsq(<negative>) = 0e0, want NaNbdab194: 644 passed, 3 failed)dd2ae9aThe one failure left with this PR,
gpu_nonfused_mad_and_mac_prevent_fma_contraction, is unrelated and fails onmaintoo:v_fma_f32 overflow control should stay fused,left: 2139095040(+inf) /right: 1946157055. RADV through dxil-spirv computes that fma unfused, so it overflows.Not tested: native Windows (others covered it above), NVIDIA under Wine, a retail title. No game files used.
AI-assisted (Claude); every number above is from a run on this machine.
@Dolaned on GitHub · 2026-11-24 05:12 UTC · original
Tested on RDNA2 as well: same fix, same result.
x86_64-pc-windows-msvcdebug (Rust 1.100, clang-cl/lld-link, xwin SDK), each lib test run on its own under Proton508a0c7e6d5d33(this PR)gpu_f64_rootsv_rsq_f64(-1.5e0) = 0e0, want NaN, ...)v_rcp_f64checksgpu_f64_math_randomunary_f64_math_vop1_and_vop3Whole lib suite on this PR: 633 passed, 2 failed, 21 ignored, 5 aborted. The failures and aborts are the ones
mainalready has on this setup and aren't touched by this change:gpu_format_stores_atomics_global_lds(wave64ds_bpermute, passes withXCL_SPLIT_WAVE64=1),xma2_source_voice_decodes_and_manages_lifetime, and five vkd3d-proton vtable asserts (heap, root signature, resource, fence x2).gpu_nonfused_mad_and_mac_prevent_fma_contractionandpe::tests::parses_own_test_binary_tlspass here.Not tested: Windows, NVIDIA, a release build, any retail title.
AI use: Claude (Claude Code) built and ran the tests on the Deck and drafted this; I checked it.
@Dolaned on GitHub · 2026-11-24 05:20 UTC · original
Also have AI pro 9700s I can test on
mainreaches on Windows; the obstacle is replaced vtables — proposal: proxies #175mainreaches on Windows; the obstacle is replaced vtables — proposal: proxies #175