Recompiler: v_cmp_class_f32 takes abs / neg on the sign bit (#1281) #1296
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1306"
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?
Imported from ivall/xcl. Originally posted by tiagonogueiraa-bit on 2026-11-24T14:33:24Z.
v_cmp_class_f32applied its VOP3 abs / neg as float operations (abs(asfloat(u)),-asfloat(u)) and passed a float tofclass. In DXIL,-xisfsub -0.0, x, which quiets an sNaN, and with D3D's fp32 denormal flush it turns a denormal into a zero. Sonegon an sNaN classified it as a qNaN, andnegon 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: invopc,classon f32 clears or flips bit 31 of the raw bits, andfclasstakes theuint, asfclass16does.crates/xcl/src/gpu/recomp/tests.rs:gpu_cmp_class_f32_modifiers_keep_the_bitschecks abs / neg on a negative denormal and on an sNaN.Tested
cargo check -p xcl --lib --tests --target x86_64-pc-windows-msvc, no errors. The C code is stubbed and nothing is linked.mainand from this branch as C++ on one lane, with-xasfsub -0.0, xand the fp32 denormal flush on, to stand in for the GPU.main,neg(-denormal)andneg(sNaN)fail; the twoabscases pass, becausefabsonly touches the sign.5b4069c:cargo test --workspace --no-fail-fast -- --test-threads=4752 passed, 0 failed, 41 ignored, with SKIPPED (no wave64)gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware. The new test fails withemit.rsfrom930e8b4, withwave32 abs(-denormal) matches +denormal. (report)scripts/test.ps1752 passed, 0 failed, 41 ignored, noSKIPPED. On this card the new test also passes without the change: AMD's driver keeps denormals and sNaN throughfabsandfsub -0.0, x. So the test tells the two apart on NVIDIA (above) but not on AMD. (report)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:
PR:
Not tested
fclass64'sdoubleargument (point 3 of the issue). It is left for its own change.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by IvyNotFound on 2026-11-24T14:57:06Z.
GPU run of
5b4069con 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 changeTested
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).emit.rsfrom930e8b4(the test file of this PR): fails withwave32 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,_AWCset): 752 passed, 0 failed, 41 ignored;SKIPPED(no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.scripts/smoke.ps1 -Seconds 60,XCL_PRESS_A_AT=15, unedited, for Regression run if you want them:main:
this PR:
Not tested
AI use
Imported from ivall/xcl. Originally posted by vitor127wt on 2026-11-24T14:57:16Z.
Test report on RTX 5070 Ti under Wine
Following up on #1243. I tested the exact PR head
5b4069cdf0c1bb53886dca234ff9ef6888638fa2in a separate checkout and build directory.gpu::recomp::tests::gpu_cmp_class_f32_modifiers_keep_the_bitspassed 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
7.3.5-2-cachyos, Wine 11.22, DXVKv2.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 --workspacesucceeded.cargo xwin test --offline --locked --target x86_64-pc-windows-msvc --workspace --no-fail-fast -- --test-threads=4ran 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.930e8b49c1c2ec683d22c724a398b39111cd0e56reported 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 weregpu_nonfused_mad_and_mac_prevent_fma_contraction(device removed) andnever_picks_xcl_itself(file copy error). The baseline build used an on-disk target directory after a linker error on tmpfs.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.
Imported from ivall/xcl. Originally posted by tiagonogueiraa-bit on 2026-11-24T14:59:05Z.
Thank you, @IvyNotFound and @vitor127wt! I put your runs under Tested and the two
xcl-smokeblocks under Regression run exactly as posted, with credit, and marked the PR ready for review.Written with Claude Code (Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by ySKELLETONX on 2026-11-24T15:10:58Z.
Test report on head
5b4069c(asked for in #1243). AI-written (Claude Code, Claude Opus 5.5) from real runs; checked by me.Tested
scripts/test.ps1(cargo test --workspace -- --test-threads=4): 752 passed, 0 failed, 41 ignored; noSKIPPEDlinesgpu::recomp::tests::gpu_cmp_class_f32_modifiers_keep_the_bits: okemit.rschange reverted (test kept, base930e8b4), the test also passes on this card: AMD's driver keeps denormals / sNaN through FAbs andfsub 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: https://github.com/ivall/xcl/issues/1281#issuecomment-7135496005Not tested
Imported from ivall/xcl. Originally posted by tiagonogueiraa-bit on 2026-11-24T15:13:24Z.
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).
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T15:47:06Z.
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 unmodifiedmain.)Thanks!
Imported from ivall/xcl. Originally posted by tiagonogueiraa-bit on 2026-11-24T20:14:46Z.
Thank you @DavidM1911, the merged-with-
mainrun is in Tested.Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-28T07:59:58Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-30T16:24:30Z.
merge-check claim
head:
5b4069cdf0Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-30T16:37:17Z.
merge-check
base:
9dfbe3ea66head:
5b4069cdf0merge: clean (trial merge 3d56b9a59ba06639d060f6252f62b7661c496996; git diff --check clean; +44/-6 in crates/xcl/src/gpu/recomp/emit.rs and tests.rs)
build: cargo build --workspace -> ok (pre-existing warnings only, none from the PR's lines)
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2885 passed, 2 failed, 51 ignored; SKIPPED: 27 (22 "no wave64" — wave32-only GPU, 2 "no heap windows", 1 "cannot disable the driver cache (Developer Mode)", 2 "no xgameruntime.dll"); the neighboring gpu_cmp_class_f16_preserves_snan passes. Failing: (1) gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, pre-existing on this machine (identical on base
9dfbe3ea); (2) the new gpu_cmp_class_f32_modifiers_keep_the_bits, which fails on this card (RTX 4070 SUPER, Ada, driver 32.0.16.2140) WITH the fix — "wave32 abs(-denormal) matches +denormal", left (0,0) — and I reproduced the identical failure first-hand on a clean base worktree with the test file copied over, so this PR is not regressing this hardware; see review for the root cause on this card.review: read the whole diff and the surrounding code. The bug is real: the old f32 class arm went through Self::fsrc (emit.rs:3141), i.e. abs(asfloat(x)) / (-asfloat(x)) as float ops — and in DXIL -x is fsub -0.0, x, which quiets an sNaN before fclass sees it, while float abs can flush a denormal; the f16 (emit.rs:4328) and f64 (emit.rs:3738, whose comment describes exactly this) paths already applied abs/neg to the sign bit of the bit pattern, which the new "f32" if op == "class" arm now does for f32, and the fclass helper takes uint instead of float so the pattern never round-trips through a float. fclass has exactly one caller on main (the f32 class arm), so the signature change is contained. All four test expectations check out against the fclass class numbering. On this machine the new test cannot pass with or without the change: scratch probes (run and then removed) showed raw f32 sNaN / qNaN / ±denormals with no modifiers at all do not match their own class bits here, while the f16 equivalents do — f32 special values do not survive the VGPR load path on this driver, a pre-existing property outside this PR's scope. The fix is validated where it discriminates: IvyNotFound's RTX 5080 run fails without the change and passes with it; DavidM1911's RTX 3060 Ti run with the branch merged onto current main passes; ySKELLETONX's RX 7600 XT run passes with the noted caveat that AMD's driver masks the bug. No unsafe, no new dependencies, no stop-criteria files touched.
performance: none; the generated condition is a constant-size bit op where a float abs/neg used to be.
verdict: safe to merge
hardware / tool and model: RTX 4070 SUPER (driver 32.0.16.2140), Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 / OpenCode, Qwen 3.8 27B
Imported from ivall/xcl. Originally posted by lnqigr on 2026-11-30T17:08:12Z.
merge-check claim
head:
5b4069cdf0Imported from ivall/xcl. Originally posted by lnqigr on 2026-11-30T17:27:57Z.
merge-check
base:
9dfbe3ea66head:
5b4069cdf0merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> the 41 test binaries other than the xcl lib: 148 passed, 0 failed, 20 ignored; the xcl lib binary aborted with STATUS_ACCESS_VIOLATION after 86 tests (not seen again in the rerun or on the base, one run each). Rerun of the lib,
cargo test -p xcl --lib --no-fail-fast -- --test-threads=4-> 2735 passed, 4 failed, 31 ignored; SKIPPED: 24 (22 no wave64, 1 no heap windows, 1 driver cache needs Developer Mode); failing:gpu::recomp::tests::gpu_cmp_class_f32_modifiers_keep_the_bits(this PR's new test, see review),gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16(fails on the base too: base lib 2737 passed, 1 failed, 31 ignored),hle::d3d12x::uma_driver::tests::a_refused_gpu_upload_segment_becomes_customandmixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment("Map gave …, wanted …" in the parallel run; they pass on the base and 3/3 alone on the merge, and this PR does not touchuma_driver.rs)review: 1. The fix reaches only the HLSL path, and the new test fails on the default path. Direct DXIL is the default for every stage (
gpu/dxil/kernel.rsrouting, README), and the recompiler's GPU tests use it whenXCL_DIRECT_DXILis unset. Therevopc_cond(gpu/dxil/lower_valu.rs) still builds the class operand withfsrc(FAbs,fsub -0.0, x) beforefclass/fclass_const, so #1281 stays open on the default path. On this GPUgpu_cmp_class_f32_modifiers_keep_the_bitsfails withwave32 abs(-denormal) matches +denormalwhen run alone with the default setting. WithXCL_DIRECT_DXIL=0it passes, and withemit.rsfrom the base it fails with the same message, so the HLSL change itself is correct and the test catches the bug.fsrc_bitsin the same file already applies abs / neg to the bits and could serve the class branch. 2. HLSL change:fclass(uint)has one caller (the f32classarm ofvopc), abs before neg as infsrc, other f32 compares unchanged; scope fine. Duplicates: this is the suggested PR of the closed #1607 groups D1 / D2 (#1308, #1309, #1318, #1340, #1569); merged #2282 specializes the constant-mask direct-DXIL path and is a different change.performance: no cost by default: one AND / XOR in place of float ops on the HLSL fallback; it changes translator sources, so shaders are translated again once.
verdict: not yet: the PR's own test fails on the default direct-DXIL path (NVIDIA):
vopc_condingpu/dxil/lower_valu.rsneeds the same bitwise abs / neg forclasshardware / tool and model: NVIDIA GeForce RTX 4060 Laptop GPU (driver 610.88), Intel Core i9-14900HX, Windows 11 build 26300.9974, Rust 1.100.0 / Claude Code (Claude Opus 5.5)
Imported from ivall/xcl. Originally posted by Chrysana on 2026-12-01T00:13:18Z.
merge-check
base:
d0832e614fhead:
5b4069cdf0merge: clean (git diff --check clean)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2883 passed, 9 failed, 51 ignored (base: 2882 passed, 9 failed, 51 ignored); SKIPPED: 6, the same as on base (2 no heap windows, 1 cannot disable the driver cache without Developer Mode, 3 no D3D12 debug layer). This card runs wave64, so the wave64 halves of the GPU tests run here too. failing: the same 8 tests as on base, none new: fuzz_validate_and_gpu_1, fuzz_validate_and_gpu_3, gpu_smem_flat_descriptor_windows_and_limits, f32_programs_on_the_gpu, gpu_f32_compares_with_nan, gpu_float_compares_random, gpu_ps_readfirstlane_loop_on_a_primitive_edge_ends, two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (counted twice). The new gpu_cmp_class_f32_modifiers_keep_the_bits passes in wave32 and wave64 on the default path, and with XCL_DIRECT_DXIL=0.
review: I read the whole diff. The HLSL change is right: abs / neg on the sign bit before fclass, and fclass now takes the bits (its one caller is this new code). But lnqigr's finding holds, and AMD hides it rather than fixing it. The default direct-DXIL path, vopc_cond in gpu/dxil/lower_valu.rs:1391, still builds the class operand with fsrc (float fabs / fneg) instead of fsrc_bits (line 1131). The new test passes here, apparently because this AMD driver keeps the -denormal's bits through the float abs / neg. On NVIDIA it fails (lnqigr's check), so as it stands this would put a failing test into the suite on NVIDIA and leave #1281 open there.
performance: no change on the default path (direct DXIL); on the HLSL path, 1–2 integer ops per v_cmp_class_f32 with abs / neg. Not measured (Tier 1, no title run).
verdict: not yet: vopc_cond's class operand in gpu/dxil/lower_valu.rs needs the same sign-bit abs / neg (fsrc_bits); the test passes on AMD RDNA 4 only because this driver keeps denormals through fabs / fneg
hardware / tool and model: AMD Radeon RX 9070 XT 16 GB (RDNA 4, driver 32.0.32015.2008), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11 25H2 build 26200.9974, rustc 1.100.1 / Claude Code (Claude Opus 5.5)
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:23:38Z.
Triage (#1607) – head
5b4069cThe other PRs for #1281 (#1308, #1309, #1318, #1340, #1569) are closed unmerged; this is the only open one, and main still applies abs / neg as float ops before
fclassinemit.rs.The HLSL change is right:
fclassnow takes the raw bits, and the modifiers are applied as& 0x7FFFFFFF/^ 0x80000000on them. Its only caller is this one.On current main, compute goes to the direct DXIL translator by default. Its
vopc_cond(dxil/lower_valu.rs) still goes throughfsrc, sofabsandfneg(fsubfrom -0.0) run beforefclass. Once rebased, the new GPU test runs through that path (kernel_wave->direct_or) and may fail there unless the direct path gets the same fix.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.