Skip to content

Recompiler: cube sc / tc negate by the sign bit on both backends - #2348

Open
Victorbriez wants to merge 1 commit into
xcl-dev:mainfrom
Victorbriez:recomp/cube-sign-negation
Open

Victorbriez wants to merge 1 commit into
xcl-dev:mainfrom
Victorbriez:recomp/cube-sign-negation

Conversation

@Victorbriez

@Victorbriez Victorbriez commented Nov 25, 2026 •

Copy link
Copy Markdown

Both backends negated the sources of v_cubesc_f32 / v_cubetc_f32 with fsub -0.0, x: the HLSL helpers through -x, the direct lowering through fneg. A driver may flush a denormal there: NVIDIA does on the HLSL path, so v_cubetc_f32 returned ±0 for a denormal source; RADV under vkd3d-proton does on the direct path (reported below). Both now flip the sign bit. Fixes #2347.

What is in it

  • one commit (bc43fd6): a neg_bits helper in the HLSL prelude, used by cube_sc and cube_tc (crates/xcl/src/gpu/recomp/emit.rs); an fneg_bits helper used by cube in the direct lowering (crates/xcl/src/gpu/dxil/prelude.rs); and the GPU test gpu_cube_coordinates_negate_denormals_by_sign on both backends (crates/xcl/src/gpu/recomp/tests.rs)

Tested

  • NVIDIA GeForce RTX 3070 8 GB (32-lane waves only), driver 621.24 (32.0.16.2124); AMD Ryzen 7 5800X; 16 GB RAM
  • Windows 11 Pro 10.0.26300; Rust 1.100.0 (stable-x86_64-pc-windows-msvc); debug; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0)
  • head bc43fd6 (on main 3ceb550), no uncommitted changes
  • the new test fails on main (hlsl lane 0: tc 0x80000000, want 0x80000001) and passes with the fix on both backends
  • cargo test --workspace --no-fail-fast -- --test-threads=4: main 3ceb550 1346 passed, 1 failed, 46 ignored; this PR 1347 passed, 1 failed, 46 ignored (the new test). The one failure is the same on both, a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier from Recompiler: a bridged mask write in the split form meets no barrier #2074, and is not touched here
  • SKIPPED on this adapter (28, the same on both): 22 × no wave64; 3 × wave32 per-lane form refused (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32, Recompiler: the per-lane form takes f16 converts and products from #1426 #2182); 1 × no heap windows; 1 × Developer Mode off (0x887A002D); 2 × no xgameruntime.dll
  • Tests: a cross-backend and cross-device VALU fuzzer (ignored by default) #2169's valu_fuzz_backends_agree (its file added locally, not part of this PR): main 1 instruction differs (V_CUBETC_F32, 58 of 256); this PR 0 differ, 333 of 341 compared (on eda3db7, the same change before this rebase; not rerun on bc43fd6)

Regression run

  • Not yet: I do not have a title. If someone with one can run scripts/smoke.ps1 on main and on this head, I will add both blocks here. Until then this stays a draft.

Not tested

  • any title; AMD / native wave64 on this head, and RADV under vkd3d-proton (where the direct path failed the test before this change); RDNA2 hardware, so what the console returns for a denormal source is not measured
  • release-build tests

AI use

🤖 Generated with Claude Code

@SlopTart

Copy link
Copy Markdown

Tested: current PR head merged onto current origin/main (clean, a5b31491), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).

The new test goes red on this lane, but only on the direct_dxil backend.

  • gpu_ suite (--release --locked, --test-threads=2): 145 passed / 4 failed / 1 ignored vs baseline 144 / 3. The three baseline failures are this rig's known set (fuzz seed 1003 of DXIL fuzz tests: fuzz_validate_and_gpu_1 fails on AMD (seed 722 and others, RDNA2-4), so the default suite is red there #2115, gpu_nonfused_mad_and_mac_prevent_fma_contraction, gpu_depth_buffer_created_for_unordered_access_is_placed); the 4th is the new gpu_cube_coordinates_negate_denormals_by_sign.
  • It fails deterministically: 3/3 solo reruns with --test-threads=1, always the first assert of the second backend loop:
    direct_dxil lane 0: (sc, tc) of [0000ffff, 00000001, bf800000] -> left: [2147483648, 2147483648] right: [2147549183, 2147483649] (tests.rs:9690).
  • Reading the bits: expected 0x8000FFFF / 0x80000001 (denormals negated by sign bit), got 0x80000000 twice, i.e. the GPU returned -0.0 for both: the denormals were flushed to zero. The hlsl backend loop passes on this lane (the PR's fix holds there); it is the direct_dxil backend's emitted code that still loses denormals on RADV, exactly the fsub -0.0, x class the test doc-comment warns about.
  • So on Linux/RADV the sign-bit negate needs to reach the direct DXIL emitter too, not just the HLSL path; otherwise this PR's own test stays red here. vkd3d-proton 3.1 (XCL patch) + Mesa 26.2.5 both in the chain, so I cannot fully separate emitter vs dxil-spirv/Mesa policy from outside, but the fix direction the PR already took applies.

Not tested: retail titles (no title data on this lane, counts only).

AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.

@Victorbriez
Victorbriez force-pushed the recomp/cube-sign-negation branch from a5b3149 to eda3db7 Compare November 25, 2026 17:10
Victorbriez added a commit to Victorbriez/xcl that referenced this pull request Nov 25, 2026
Both backends negated with `fsub -0.0, x`: the HLSL helpers through `-x`, the direct lowering through `fneg`. With no denormal option a driver may flush a denormal there. NVIDIA does on the HLSL path (v_cubetc_f32 returned ±0 for a denormal source on an RTX 3070), and RADV under vkd3d-proton does on the direct path (reported on xcl-dev#2348). Both now flip the sign bit, as the direct backend's directed-rounding path already does for source modifiers (`fsrc_bits`). The VALU fuzzer of xcl-dev#2169 found 58 of 256 cases differing between the backends on NVIDIA; with this change it finds none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Victorbriez Victorbriez changed the title Recompiler: cube sc / tc negate by the sign bit on the HLSL backend Recompiler: cube sc / tc negate by the sign bit on both backends Nov 25, 2026
@Victorbriez

Copy link
Copy Markdown
Author

Thanks, you are right, and the description was wrong about the direct backend: its fneg (crates/xcl/src/gpu/dxil/lower.rs) is fsub -0.0, x too, not a sign-bit flip. NVIDIA keeps the denormal there, RADV under vkd3d-proton does not.

eda3db7 (on main 50a9fde) flips the sign bit in the direct cube as well (fneg_bits in crates/xcl/src/gpu/dxil/prelude.rs, an integer xor). On the RTX 3070 the test still passes on both backends and #2169's fuzzer finds no difference; the description has the new counts. Could you rerun gpu_cube_coordinates_negate_denormals_by_sign on your RADV lane with this head?

AI use: Claude Code (Claude Opus 5.5) checked the report against the code, wrote the change and this reply; I checked it before posting.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

Both backends negated with `fsub -0.0, x`: the HLSL helpers through `-x`, the direct lowering through `fneg`. With no denormal option a driver may flush a denormal there. NVIDIA does on the HLSL path (v_cubetc_f32 returned ±0 for a denormal source on an RTX 3070), and RADV under vkd3d-proton does on the direct path (reported on xcl-dev#2348). Both now flip the sign bit, as the direct backend's directed-rounding path already does for source modifiers (`fsrc_bits`). The VALU fuzzer of xcl-dev#2169 found 58 of 256 cases differing between the backends on NVIDIA; with this change it finds none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Victorbriez
Victorbriez force-pushed the recomp/cube-sign-negation branch from eda3db7 to bc43fd6 Compare November 25, 2026 19:04
@Victorbriez
Victorbriez marked this pull request as ready for review November 25, 2026 19:09
@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) test report on exact head bc43fd6dc4035f3687fe2667024b65e9742442f6 (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1345 passed, 3 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record). All native wave64 GPU tests ran and passed.

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release)

xcl-smoke v1
commit: bc43fd6dc4035f3687fe2667024b65e9742442f6
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1559 (PresentX 1559)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14025 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • D3D12 debug layer; Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.

@Victorbriez

Copy link
Copy Markdown
Author

Thanks a lot, this is the AMD / native wave64 run and the regression run this PR was missing.

PR checks needs both xcl-smoke blocks pasted under Regression run, and the main one has to be the block itself, not a summary. Could you paste the full xcl-smoke v1 block of your main 68a284a run (the 1573 frames / 14420 MB one)? I will then put both blocks in the description, credited to you, with your hardware and the counts.

AI use: Claude Code (Claude Opus 5.5) read the report and drafted this reply; I checked it before posting.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No source-level defect found. The sign-bit XOR is consistent across HLSL and Direct-DXIL, preserves bit patterns, and the new GPU test covers both backends with denormals; the submitted RDNA4 report and head smoke are encouraging. Merge readiness is administrative: all current PR-description checks fail because the required full main baseline smoke block is missing (a summary is not enough). Please add the complete main block and rerun the description check.

@DavidM1911

Copy link
Copy Markdown
Contributor

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

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: on NVIDIA the HLSL backend's v_cubetc_f32 flushes a denormal result to ±0; the direct backend keeps it

5 participants