Skip to content

Recompiler: drop redundant IsNaN checks in direct DXIL cvt_u32 and f16_rtz - #2289

Open
ramon-victor wants to merge 1 commit into
xcl-dev:mainfrom
ramon-victor:opt/dxil-drop-redundant-isnan-cvt
Open

ramon-victor wants to merge 1 commit into
xcl-dev:mainfrom
ramon-victor:opt/dxil-drop-redundant-isnan-cvt

Conversation

@ramon-victor

Copy link
Copy Markdown
Contributor

Removes redundant explicit dx.op.isSpecialFloat(IsNaN) guards in two hot direct DXIL float-conversion helpers (Lw::cvt_u32 and Lw::f16_rtz):

  • Lw::cvt_u32 (v_cvt_u32_f32): replaces isnan(f) || (f <=o 0.0) (3 ops) with a single unordered fcmp ule float %f, 0.0 (Pred::FULe, 1 op), which already evaluates to true for both NaN and f <= 0.0.
  • Lw::f16_rtz (v_cvt_pkrtz_f16_f32): drops !isnan(f) from (!isnan(f)) && nz && (abs(back) >o abs(f)) (3 ops removed per half, 6 per v_cvt_pkrtz_f16_f32), because ordered fcmp ogt (Pred::FOGt) already evaluates to false when f (and therefore abs(f)) is NaN.

Part of #1269.

What is in it

  • crates/xcl/src/gpu/dxil/prelude.rs:
    • Simplify Lw::cvt_u32 to Pred::FULe and Lw::f16_rtz to self.land(nz, gt) (+5/-8 lines in production code).
    • Add cvt_isnan_tests::gpu_direct_cvt_u32_and_pkrtz_drop_isnan_and_match_isa verifying DXIL validation, disassembly (zero dx.op.isSpecialFloat calls, fcmp ule float emitted), and GPU execution across ±0.0, negative values, rounding boundaries, >= 2^32, ±Inf, qNaN, and sNaN.

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 -> 41,224,580 B (-99,156 B, -0.24%)
  • Translation time p95: 263.12 ms -> 255.59 ms (-2.9%)

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::prelude::cvt_isnan_tests (debug): 1 passed; 0 failed (DXIL validation, disassembly check, and RTX 3070 GPU verification).
  • .\scripts\test.ps1 (debug, full workspace): 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: eaa509ddbcb77ef688895a73873bc446e3afb7fa
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1616 (PresentX 1616)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14419 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): simplified Lw::cvt_u32 and Lw::f16_rtz in prelude.rs, added DXIL disassembly and GPU execution tests, and ran the workspace test suite, 573-shader validation benchmark, and 60 s smoke regression run.

@DarkPanda69

Copy link
Copy Markdown

The AMD native wave64 run listed as untested, plus an RTX 3060: passes on both. I checked this one closely on AMD because #2258 (removing NaN guards from float compares) fails there; here, with the NaN checks dropped from cvt_u32 and f16_rtz, the NaN cases still come out right on the RX 9070 XT.

Head eaa509d applied on main 1a0bbe3, debug, Windows 11 Pro 26200:

Not tested: a title with XCL_DIRECT_DXIL=1.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@raylitebull

Copy link
Copy Markdown
Member

Diff review, CI, and both AMD and NVIDIA checks passed on eaa509d, but recent origin/main merges turned this branch CONFLICTING/DIRTY. Please rebase onto origin/main so it becomes mergeable again.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head eaa509d

No open or merged PR makes the same change. Main's cvt_u32 and f16_rtz in gpu/dxil/prelude.rs still call isnan. fcmp ule f, 0.0 is true for NaN and for f <= 0, and the ordered ogt in f16_rtz is already false for NaN, so the results stay the same. Unordered predicates are already used elsewhere in direct DXIL (v_cmp_n*). The PR conflicts with main.
Recommendation: keep open.

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