Float compares with NaN operands, f64 math past the f32 and int64 ranges #46
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!46
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/46/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?
@grooving6 on GitHub · 2026-11-22 21:05 UTC · original
grooving6:fix/f64-math-nan-compares→main· +672 −51 · 2 files · 2 commits · merged 2026-11-23 10:13 UTCFixes float compares with NaN operands and several f64 operations in the shader translator.
!(a >= b)followed bya < bon the same operands returned true fora < bwhen an operand was NaN. The DXIL is correct, so the driver causes it. Every f32 and f64 compare now tests for NaN explicitly.floor,ceil,truncandfractwent throughint64_t, so large values, inf, NaN, signed zeros andabsandnegmodifiers came out wrong.ldexpbuilt 2^n as an f32, soldexp(1, 1023)was inf.sqrtandrsqstarted from an f32 root, sosqrt(1e300)was inf.cvt_i32_f64(NaN)gave -2^31 instead of 0.Testing
@ivall on GitHub · 2026-11-22 21:27 UTC · original
Thanks! Merged onto current
mainit builds, and all tests pass (336 lib tests, your GPU tests included, on an RX 9070, plus the test title). But it breaks a retail title, so I'm holding it for now.Unicorn Overlord: the title screen stays black. The SEGA logo and the opening text render. After them the picture stays black while the music plays.
mainshows the title screen. WithXCL_FRAME_DUMP=1, non-black samples of 518 400 (3840×2160, every 4th pixel):The black frame at 15.6 s is a normal gap between logos; it is there on
maintoo. On #46 the title screen never comes. It's the same with a warm DXIL cache: the run that was checked on screen compiled 1 new DXIL.It's the f32 compare change. Unicorn's shaders have no f64 instructions at all:
v_mul_legacy_f32v_rcp_f32v_cmp_gt_f32v_cmp_lt_f32v_log_f32v_cmp_le_f32/v_cmp_ge_f32v_sqrt_f32Their HLSL bodies never call the new f64 helpers either. For non-NaN operands the new compares give what the old ones did, so a NaN must reach one of these
v_cmp_*_f32. The old code's result (the driver's unordered one, as you describe) gave the console's picture.Since the console's compares are ordered too, I suspect the NaN itself is the real bug: something XCL computes differently from the console, so that the console never sees a NaN there.
mul_legacyalready gives 0 for 0 × ∞, so it isn't that one.rcp/logof 0 → ±∞ followed by a plain multiply or subtract would be my first guess.Options:
<data>\shaders\*_ps.*, the ones withv_rcp_f32/v_log_f32and the compares);Note that the f64 helpers sit in the shared prelude, so any change there recompiles every shader of every title after a merge. XDefiant then stays black for minutes on its first run.
Not covered yet with #46: Fortnite and XDefiant. Minecraft looked fine.
@Foniass on GitHub · 2026-11-22 22:47 UTC · original
Tested on RTX 5070 Ti only (Blackwell, driver 32.0.16.2114, D3D12 wave range 32..32). The RDNA2 iGPU on this machine is disabled, so it wasn't tested. The branch was merged onto
main521ec08. The only conflict was inrecomp/tests.rs, where both sides just add tests, and I kept both. Run withcargo test --workspace --release --no-fail-fast -- --test-threads=4, noXCL_SAMPLE_*set. Hardware details are in #42.main: 367 / 0 / 34), with no regressions.gpu_f32_compares_with_nan,gpu_f64_compares_with_nan,gpu_f64_math_random,gpu_f64_roots,gpu_f64_rounding_and_conversions,gpu_float_compares_randomandgpu_ldexp_f64all return throughgpu_ready()(no wave64). So on this card the new compares and f64 helpers are covered only by the translation tests, not by execution. If these kernels don't depend on wave width, a wave32 variant would let them run on NVIDIA too.@ivall on GitHub · 2026-11-23 10:14 UTC · original
Merged (
be1994b), thanks – and sorry for the wait.Re-tested on current
main(with #67 / #84 / #68 / #69 in) on an RX 9070: Unicorn Overlord now renders its intro and scenes with this PR (frame dumps through the whole run, warm and cold DXIL cache), so whatever produced the NaN that turned the title screen black on the 2026-11-22mainis no longer there. Workspace tests green with the retail samples (shader pack, console DLLs, texture archive), and the lib tests also withXCL_SPLIT_WAVE64=1(the 32-lane split path on RDNA).One fix on top (
6a41c55): #67 removedgpu_ready_wave32, sogpu_wavesusesgpu_readynow (a GPU with 32- or 64-lane waves plus DXC) – your tests still run as wave32 programs on NVIDIA.