Skip to content

Recompiler: lower direct DXIL float_compare to ordered/unordered fcmp - #2258

Open
ramon-victor wants to merge 1 commit into
xcl-dev:mainfrom
ramon-victor:opt/dxil-float-compare-fcmp
Open

ramon-victor wants to merge 1 commit into
xcl-dev:mainfrom
ramon-victor:opt/dxil-float-compare-fcmp

Conversation

@ramon-victor

@ramon-victor ramon-victor commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Lowers RDNA2 floating-point comparisons (Lw::float_compare, covering v_cmp*_f16, v_cmp*_f32, and v_cmp*_f64) in the direct DXIL translator directly to IEEE-754 ordered (FO*) and unordered (FU*) LLVM fcmp predicates instead of emitting explicit dx.op.isSpecialFloat(IsNaN) / splitDouble NaN checks around each compare.

Because the direct DXIL builder emits fcmp with zero fast-math flags, LLVM/DXIL olt, oeq, ole, ogt, one, oge, ord, uno, ult, ueq, ule, ugt, une, and uge already define exact NaN semantics in a single instruction (1 instruction instead of 3–8 per compare).

Part of #1269.

What is in it

  • crates/xcl/src/gpu/dxil/lower_valu.rs:
    • Replace Lw::float_compare's explicit isnan_any + or + xor + and wrapper with direct 1-to-1 Pred::FO* / Pred::FU* fcmp emission, and remove the now-unused Lw::isnan_any helper (+18/-51 production lines).
    • Add float_compare_tests::gpu_direct_float_compare_uses_fcmp_and_matches_ieee verifying DXIL validation and disassembly (every predicate emits the expected fcmp with no dx.op.isSpecialFloat or splitDouble NaN guards) and checking all 14 v_cmp_*_f32 predicates on the GPU across ±0.0, finite, ±Inf, qNaN, and sNaN pairs.

On a seeded 600-program sample (xcl shaders <archive> --direct --sample 600 --seed 3 --max-bytes 40000 --validate --threads 8, 573 programs within the cap), all 573/573 validate cleanly (0 validator failures):

  • Total emitted DXIL: 41,323,736 B -> 40,857,992 B (-465,744 B, -1.13%)

Tested

  • Hardware and toolchain: NVIDIA GeForce RTX 3070 (8 GiB, driver 621.24, wave32), AMD Ryzen 7 5700X, Windows 11 Pro 26300, rustc 1.99.0 (x86_64-pc-windows-msvc), DXC/DXIL 1.8.2502.11 (Windows SDK 10.0.26100.0).
  • cargo test -p xcl --lib gpu::dxil::lower_valu::float_compare_tests (debug): 1 passed; 0 failed.
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu_f32_compares (debug): 1 passed; 0 failed (gpu_f32_compares_with_nan on RTX 3070).
  • .\scripts\test.ps1 (debug, full workspace on head c204653): 1251 passed; 0 failed; 46 ignored (25 GPU sub-checks skipped on this wave32 adapter: 21 no wave64, 1 no heap windows, 3 per-lane #1426 refusals).
  • cargo build --release -p xcl + direct DXIL validation sweep on 573 sampled retail shader programs: 573/573 translated and dxil.dll-validated (0 failures).

Regression run

xcl-smoke v1
commit: f087b998d0d51a9f11bbfa0761967a63e778edd9
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14467 MB
xcl-smoke v1
commit: c2046530321844e65a64df2ef2ff78e15ac095ea
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14470 MB

Not tested

  • Native wave64 GPU hardware (AMD/Intel): RTX 3070 only supports wave32, so native wave64 tests skip on this adapter.
  • Sample-gated tests (XCL_SAMPLE_* env vars unset).

AI use

  • Antigravity (Gemini 4 Neon): analyzed float_compare in lower_valu.rs, simplified it to direct LLVM fcmp predicates, wrote unit and GPU tests, rebased onto origin/main (1a0bbe3), and ran XCL_DIRECT_DXIL=1 compare tests, the full workspace test suite, the 573-shader validation benchmark, and the 60 s smoke regression run.

@ramon-victor
ramon-victor force-pushed the opt/dxil-float-compare-fcmp branch from c7940b3 to c204653 Compare November 25, 2026 12:33
@DarkPanda69

Copy link
Copy Markdown

Fails on AMD (native wave64), passes on NVIDIA. On an RX 9070 XT, the ordered not-equal compare returns true for a NaN input, in the new test and in the existing f32_programs_on_the_gpu, which passes on main.

Tested at head c204653 (as is, on main 1a0bbe3), debug, Windows 11 Pro 26200, DXC 1.9.2602.17, cargo test -p xcl --lib -- gpu_direct_float_compare_uses_fcmp_and_matches_ieee f32_programs_on_the_gpu --test-threads=1:

  • RX 9070 XT (RDNA4, driver 32.0.32029.2010, waves 32..64): 2 failed, 3 of 3 runs (also on the earlier head c7940b3):
    • gpu_direct_float_compare_uses_fcmp_and_matches_ieee: V_CMP_LG_F32 lane 8 (NaN, 0.0): got true, want false (core_tests.rs:673).
    • f32_programs_on_the_gpu: f32 compares, wave32: s10, left: 4294967291, right: 4008636138 (lower_dxil.rs:738).
  • RX 9070 XT on main 1a0bbe3: f32_programs_on_the_gpu passes, so this PR introduces the second failure.
  • RTX 3060 (driver 32.0.16.1088): both pass, at this head and on main.

So on this AMD driver the fcmp one (ordered not-equal) that V_CMP_LG_F32 now lowers to does not come out false for a NaN operand, where the removed explicit isnan guard did. Whole gpu:: filter at c7940b3: RX 9070 XT 625 passed, 5 failed (these 2, plus the #2115 fuzz seeds and gpu_image_get_resinfo_past_last_level that its old base still had); RTX 3060 630 passed, 0 failed.

Not tested: the other 13 predicates past the first failing assertion on AMD, RDNA2/RDNA3.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent RDNA2 confirmation of the AMD NaN regression reported above, at exact PR head c2046530321844e65a64df2ef2ff78e15ac095ea versus main 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6.

Environment: Windows 11 build 26200; Ryzen 9 5980HX; Radeon RX 6800M driver 30.0.13002.13003 (native wave64); Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5. Isolated worktrees and Cargo targets. Debug tests use XCL_ADAPTER=6800M, XCL_REQUIRE_GPU=wave64, -j 2, --test-threads=1, --show-output.

Results

  • On this PR, cargo test --locked -p xcl --lib gpu_direct_float_compare_uses_fcmp_and_matches_ieee with XCL_DIRECT_DXIL=1: 0 passed, 1 failed, 0 ignored, no skip. The assertion is exactly V_CMP_LG_F32 lane 8 (NaN, 0.0): got true, want false at lower_valu.rs:1420. This is a value mismatch after GPU execution, not a PSO/device-removal failure.
  • Existing f32_programs_on_the_gpu: main 1/0/0, PR 0/1/0 with XCL_DIRECT_DXIL=1. The PR fails f32 compares, wave32: s10 (left: 4294967291, right: 4008636138) at lower_dxil.rs:738.
  • The same existing-test control with XCL_DIRECT_DXIL=0 also passes on main 1/0/0 and fails on this PR 0/1/0 with the same s10 values. That test exercises its own DXIL path, so changing the environment flag does not remove the regression.

This extends the reported failure from RX 9070 XT/RDNA4 to RX 6800M/RDNA2. It is a reproducible PR-head regression against this main revision. I ran focused synthetic tests only; no full workspace suite or retail-title smoke on this head. No game data was used.

AI use: OpenAI Codex (GPT-6; exact variant not exposed in this session) ran the native Windows GPU tests and main/PR controls, checked the exact assertions, and drafted this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head c204653

lower_valu.rs::float_compare replaces the explicit NaN tests with single ordered/unordered fcmps, for f64 as well as f32. Main already has that f32 form, from a899ec9 (#3269). It breaks gpu_f32_compares_with_nan, gpu_float_compares_random and f32_programs_on_the_gpu on AMD: the driver treats fcmp one as une and merges ordered/unordered pairs of the same operands (#46, #3539). The comments here report the same failures for this head on an RX 9070 XT and an RX 6800M. Extending the form to f64 would bring the bug back for f64 compares.
Recommendation: close (bad: drops the NaN tests needed for the AMD driver bug, fails on AMD).

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

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants