Skip to content

Recompiler: v_cmp_class_f32 takes abs / neg on the sign bit (#1281) - #1306

Open
tiagonogueiraa-bit wants to merge 1 commit into
xcl-dev:mainfrom
tiagonogueiraa-bit:cmp-class-f32-bits
Open

tiagonogueiraa-bit wants to merge 1 commit into
xcl-dev:mainfrom
tiagonogueiraa-bit:cmp-class-f32-bits

Conversation

@tiagonogueiraa-bit

@tiagonogueiraa-bit tiagonogueiraa-bit commented Nov 24, 2026 •

Copy link
Copy Markdown

v_cmp_class_f32 applied its VOP3 abs / neg as float operations (abs(asfloat(u)), -asfloat(u)) and passed a float to fclass. In DXIL, -x is fsub -0.0, x, which quiets an sNaN, and with D3D's fp32 denormal flush it turns a denormal into a zero. So neg on an sNaN classified it as a qNaN, and neg on a denormal as a zero. The f16 and f64 paths already work on the bits. Fixes #1281.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: in vopc, class on f32 clears or flips bit 31 of the raw bits, and fclass takes the uint, as fclass16 does.
  • crates/xcl/src/gpu/recomp/tests.rs: gpu_cmp_class_f32_modifiers_keep_the_bits checks abs / neg on a negative denormal and on an sNaN.

Tested

  • macOS, Rust stable: cargo check -p xcl --lib --tests --target x86_64-pc-windows-msvc, no errors. The C code is stubbed and nothing is linked.
  • On the CPU, not a GPU: I ran the test program's emitted HLSL from main and from this branch as C++ on one lane, with -x as fsub -0.0, x and the fp32 denormal flush on, to stand in for the GPU.
    • On main, neg(-denormal) and neg(sNaN) fail; the two abs cases pass, because fabs only touches the sign.
    • On this branch, all four pass.
  • Windows / GPU runs by others, on this head 5b4069c:
    • @IvyNotFound (RTX 5080, native Windows 11): cargo test --workspace --no-fail-fast -- --test-threads=4 752 passed, 0 failed, 41 ignored, with SKIPPED (no wave64) gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware. The new test fails with emit.rs from 930e8b4, with wave32 abs(-denormal) matches +denormal. (report)
    • @vitor127wt (RTX 5070 Ti, Wine + vkd3d-proton): the new test passes, alone and in the suite. The suite's failures under Wine are also failures on the base. (report)
    • @ySKELLETONX (AMD RX 7600 XT, RDNA3, native Windows 11): scripts/test.ps1 752 passed, 0 failed, 41 ignored, no SKIPPED. On this card the new test also passes without the change: AMD's driver keeps denormals and sNaN through fabs and fsub -0.0, x. So the test tells the two apart on NVIDIA (above) but not on AMD. (report)
    • @DavidM1911 (RTX 3060 Ti, native Windows 11), this branch merged with current main: cargo test -p xcl --lib -- --test-threads=1, all passed, 0 failed, 21 ignored. (report)

Regression run
By @IvyNotFound, scripts/smoke.ps1 -Seconds 60, XCL_PRESS_A_AT=15, RTX 5080, unedited, from the report:

main:

xcl-smoke v1
commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56
gpu: NVIDIA GeForce RTX 5080
title: game
seconds: 60
exit: 0x0
frames shown: 1273 (PresentX 1273)
presents per 2 s (last 3): 11 6 14
device removals: 0
crashes: 0
peak commit: 26663 MB

PR:

xcl-smoke v1
commit: 5b4069cdf0c1bb53886dca234ff9ef6888638fa2
gpu: NVIDIA GeForce RTX 5080
title: game
seconds: 60
exit: 0x0
frames shown: 1243 (PresentX 1244)
presents per 2 s (last 3): 2 5 9
device removals: 0
crashes: 0
peak commit: 25737 MB

Not tested

  • AMD / native wave64; the wave64 halves ran split on the NVIDIA GPUs above.
  • fclass64's double argument (point 3 of the issue). It is left for its own change.

AI use

  • Claude Code with Claude Opus 5.5. It wrote the change, the test and this description, and ran the macOS checks above.

🤖 Generated with Claude Code

…1281)

v_cmp_class_f32 applied its VOP3 abs / neg as float operations and passed
a float to fclass. In DXIL, -x is fsub -0.0, x, which quiets an sNaN, and
under D3D's fp32 denormal flush it turns a denormal into a zero. So neg on
an sNaN classified as a qNaN, and neg on a denormal as a zero. The f16 and
f64 paths already work on the bits.

The modifiers now clear or flip bit 31 of the raw bits, and fclass takes
the uint, as fclass16 does.

gpu_cmp_class_f32_modifiers_keep_the_bits checks abs / neg on a negative
denormal and on an sNaN.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@IvyNotFound

Copy link
Copy Markdown

GPU run of 5b4069c on Windows (NVIDIA RTX 5080, 32-lane waves), since the description's runs were on macOS without a GPU: the new test passes, and fails without the change

Tested

  • NVIDIA GeForce RTX 5080 16 GB, driver 621.24 (32.0.16.2124); Ryzen 7 7800X3D; Windows 11 25H2 (26200.9974); rustc 1.100.0 MSVC; DXC 1.9.2602.17; tests in debug, run in release. The PR head as is (base 930e8b4), clean tree.
  • cargo test -p xcl --lib gpu_cmp_class: 2 passed (gpu_cmp_class_f32_modifiers_keep_the_bits, gpu_cmp_class_f16_preserves_snan).
  • The same test with emit.rs from 930e8b4 (the test file of this PR): fails with wave32 abs(-denormal) matches +denormal, left: (0, 0), right: (4294967295, 0).
  • cargo test --workspace --no-fail-fast -- --test-threads=4 (XCL_SAMPLE_RPF, _DLLS, _TTPF, _BVH4, _BK2, _AWC set): 752 passed, 0 failed, 41 ignored; SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • Regression runs on a retail title, scripts/smoke.ps1 -Seconds 60, XCL_PRESS_A_AT=15, unedited, for Regression run if you want them:

main:

xcl-smoke v1
commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56
gpu: NVIDIA GeForce RTX 5080
title: game
seconds: 60
exit: 0x0
frames shown: 1273 (PresentX 1273)
presents per 2 s (last 3): 11 6 14
device removals: 0
crashes: 0
peak commit: 26663 MB

this PR:

xcl-smoke v1
commit: 5b4069cdf0c1bb53886dca234ff9ef6888638fa2
gpu: NVIDIA GeForce RTX 5080
title: game
seconds: 60
exit: 0x0
frames shown: 1243 (PresentX 1244)
presents per 2 s (last 3): 2 5 9
device removals: 0
crashes: 0
peak commit: 25737 MB

Not tested

  • AMD / native wave64 (the wave64 halves of the test ran split here)

AI use

  • Claude Code, Claude Opus 5.5: ran the tests and the runs and wrote this report.

@vitor127wt

Copy link
Copy Markdown

Test report on RTX 5070 Ti under Wine

Following up on #1243. I tested the exact PR head 5b4069cdf0c1bb53886dca234ff9ef6888638fa2 in a separate checkout and build directory. gpu::recomp::tests::gpu_cmp_class_f32_modifiers_keep_the_bits passed in the workspace suite and in an isolated rerun with --exact gpu::recomp::tests::gpu_cmp_class_f32_modifiers_keep_the_bits --nocapture --test-threads=1 (1 passed, 0 failed, 0 ignored, 0 skipped). The test log confirmed the RTX 5070 Ti and DXC were in use.

Tested

  • RTX 5070 Ti (16,303 MiB reported), NVIDIA Linux driver 620.73.04, Ryzen 7 9700X, 32 GB DDR5. CachyOS x86-64, kernel 7.3.5-2-cachyos, Wine 11.22, DXVK v2.7.1-498-ga6764047e587178, vkd3d-proton 3.1.0 from Proton-CachyOS (0bb64c56c8f0dcc), DXC 1.9.2609.5. Rust 1.100.0 and cargo-xwin 0.24.1, Windows MSVC debug target.
  • cargo xwin build --offline --locked --target x86_64-pc-windows-msvc --workspace succeeded. cargo xwin test --offline --locked --target x86_64-pc-windows-msvc --workspace --no-fail-fast -- --test-threads=4 ran under Wine and reported 686 passed, 66 failed, 41 ignored (exit 101). Four capability skips are included in the harness's passed count and listed below.
  • The same test command on the common base 930e8b49c1c2ec683d22c724a398b39111cd0e56 reported 683 passed, 68 failed, 41 ignored, with the same four skips. All 66 failure names from the PR also appeared on the base. The two additional base failures were gpu_nonfused_mad_and_mac_prevent_fma_contraction (device removed) and never_picks_xcl_itself (file copy error). The baseline build used an on-disk target directory after a linker error on tmpfs.
SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64
SKIPPED gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64
SKIPPED gpu::texture::tests::gpu_console_textures_upload_every_mip_and_slice: no GPU
SKIPPED gpu::texture::tests::gpu_upload_batches_reuse_the_queues_upload_buffer: no GPU

Not tested

Native Windows, AMD hardware and retail-title smoke runs. Retail sample environment variables were unset.

AI use

Codex (GPT-6, exact variant unavailable) cross-built and ran the tests, compared the failure lists and drafted this report.

@tiagonogueiraa-bit
tiagonogueiraa-bit marked this pull request as ready for review November 24, 2026 14:59
@tiagonogueiraa-bit

Copy link
Copy Markdown
Author

Thank you, @IvyNotFound and @vitor127wt! I put your runs under Tested and the two xcl-smoke blocks under Regression run exactly as posted, with credit, and marked the PR ready for review.

Written with Claude Code (Claude Opus 5.5).

@ySKELLETONX

Copy link
Copy Markdown

Test report on head 5b4069c (asked for in #1243). AI-written (Claude Code, Claude Opus 5.5) from real runs; checked by me.

Tested

  • AMD Radeon RX 7600 XT (RDNA3, driver 32.0.32015.2008), Ryzen 7 5700X3D, Windows 11 Pro 10.0.26300, rustc 1.100.0, debug build, DXC from Windows SDK 10.0.26100
  • scripts/test.ps1 (cargo test --workspace -- --test-threads=4): 752 passed, 0 failed, 41 ignored; no SKIPPED lines
  • gpu::recomp::tests::gpu_cmp_class_f32_modifiers_keep_the_bits: ok
  • With this PR's emit.rs change reverted (test kept, base 930e8b4), the test also passes on this card: AMD's driver keeps denormals / sNaN through FAbs and fsub fast -0.0, x, so on AMD it does not tell fixed from unfixed. An HLSL-level check on the f32 class path would fail on main on any GPU. Details for all four PRs on this issue: Recompiler: v_cmp_class_f32 applies abs/neg via float ops (fsrc) instead of bitwise sign-bit ops, flushing denormals and quieting sNaN #1281 (comment)

Not tested

  • NVIDIA, WARP (the GPU tests skip there: no wave64), any retail title (no smoke runs).

@tiagonogueiraa-bit

Copy link
Copy Markdown
Author

Thank you, @ySKELLETONX! That the test can't tell the two apart on AMD is a useful point, so I wrote it into Tested next to the NVIDIA run where it does fail without the change. I'm not pushing an extra HLSL-level check onto this head: that would invalidate the smoke blocks it already has. It would be an easy follow-up if a maintainer wants one.

Written with Claude Code (Claude Opus 5.5).

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
ivall#1379

Integrate 22 open upstream PRs targeting world rendering, shader correctness, DirectStorage terrain loads, and crash/memory stability:
- ivall#1321 (ivall#1307): fall back to pc blocks when structured CFG HLSL grows oversized (eliminates the 148 MB HLSL / 1 GB/s commit explosion from b8b1f49 so XCL_PSO_PRELOAD=1 stays flat at ~5.4 GiB)
- ivall#549, ivall#1312: DirectStorage late page-array queue hold (fixes 0x89240009 terrain read failures) and 0-byte memory-source requests
- ivall#1365 (ivall#1361): GFX10.30 scratch SADDR 0x7F addresses the immediate offset alone instead of adding v0
- ivall#1368: translated compute PSOs use NodeMask 0
- ivall#1371 (ivall#105): deduplicate packed ISG1 vertex input struct fields
- ivall#1375 (ivall#1360): ES s_setpc_b64 ends block before gs_start
- ivall#1350, ivall#1351, ivall#1352, ivall#1353, ivall#1349: VS layer/viewport outputs, PS sample index/fixed-point position & SV_Coverage, depth+UAV initial states, console SetPredication
- ivall#1305, ivall#1306, ivall#1314, ivall#1319, ivall#1322, ivall#1334, ivall#1339, ivall#1355, ivall#1357, ivall#1379: console_list UMA hold on Release, v_cmp_class_f32 bitwise abs/neg, late_release vram queue wait, root arg clamping, empty BVH / NaN rays, NULL IASetIndexBuffer clearing, MSAA MipLevels=1, VFS lazy-page commits, coherent VirtualFree validation, cpu_writes PAGE_GUARD & stale fence wakeups
- README.md: document the integrated PRs, XCL_PSO_PRELOAD=1, and 16 GiB cap

Verified on RX 9060 XT / GE-Proton11-14: release build clean, targeted unit tests pass (75 passed, 0 failed), and 80 s run with XCL_PSO_PRELOAD=1 and XCL_MEM_LIMIT=12G stays flat at 5340-5413 MB with 512+ pipelines preloaded (1385 frames, exit 0x0).

Assisted-by: Antigravity (Google DeepMind)
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…v#1305-xcl-dev#1379

Integrate 22 open upstream PRs targeting world rendering, shader correctness, DirectStorage terrain loads, and crash/memory stability:
- xcl-dev#1321 (xcl-dev#1307): fall back to pc blocks when structured CFG HLSL grows oversized (eliminates the 148 MB HLSL / 1 GB/s commit explosion from b8b1f49 so XCL_PSO_PRELOAD=1 stays flat at ~5.4 GiB)
- xcl-dev#549, xcl-dev#1312: DirectStorage late page-array queue hold (fixes 0x89240009 terrain read failures) and 0-byte memory-source requests
- xcl-dev#1365 (xcl-dev#1361): GFX10.30 scratch SADDR 0x7F addresses the immediate offset alone instead of adding v0
- xcl-dev#1368: translated compute PSOs use NodeMask 0
- xcl-dev#1371 (xcl-dev#105): deduplicate packed ISG1 vertex input struct fields
- xcl-dev#1375 (xcl-dev#1360): ES s_setpc_b64 ends block before gs_start
- xcl-dev#1350, xcl-dev#1351, xcl-dev#1352, xcl-dev#1353, xcl-dev#1349: VS layer/viewport outputs, PS sample index/fixed-point position & SV_Coverage, depth+UAV initial states, console SetPredication
- xcl-dev#1305, xcl-dev#1306, xcl-dev#1314, xcl-dev#1319, xcl-dev#1322, xcl-dev#1334, xcl-dev#1339, xcl-dev#1355, xcl-dev#1357, xcl-dev#1379: console_list UMA hold on Release, v_cmp_class_f32 bitwise abs/neg, late_release vram queue wait, root arg clamping, empty BVH / NaN rays, NULL IASetIndexBuffer clearing, MSAA MipLevels=1, VFS lazy-page commits, coherent VirtualFree validation, cpu_writes PAGE_GUARD & stale fence wakeups
- README.md: document the integrated PRs, XCL_PSO_PRELOAD=1, and 16 GiB cap

Verified on RX 9060 XT / GE-Proton11-14: release build clean, targeted unit tests pass (75 passed, 0 failed), and 80 s run with XCL_PSO_PRELOAD=1 and XCL_MEM_LIMIT=12G stays flat at 5340-5413 MB with 512+ pipelines preloaded (1385 frames, exit 0x0).

Assisted-by: Antigravity (Google DeepMind)
@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib -- --test-threads=1: all passed, 0 failed, 21 ignored. (Parallel runs intermittently abort with 0xc0000005 — same harness flake seen on unmodified main.)

Thanks!

@tiagonogueiraa-bit

Copy link
Copy Markdown
Author

Thank you @DavidM1911, the merged-with-main run is in Tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recompiler: v_cmp_class_f32 applies abs/neg via float ops (fsrc) instead of bitwise sign-bit ops, flushing denormals and quieting sNaN

5 participants