Skip to content

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

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

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 (eda3db7): 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 eda3db7 (on main 50a9fde), 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 50a9fde 1288 passed, 1 failed, 46 ignored; this PR 1289 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 (27, the same on both): 21 × 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); 1 × 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)

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.

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 a5b3149 to eda3db7 Compare November 25, 2026 17:10
@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.

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

2 participants