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

Open
github-bot wants to merge 1 commit from github-bot/gh-2348 into main AGit
Owner

@⁠Victorbriez on GitHub · 2026-11-25 16:13 UTC · original
Victorbriez:recomp/cube-sign-negation → main · +59 −6 · 3 files · 1 commits · open

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 #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, #2182); 1 × no heap windows; 1 × Developer Mode off (0x887A002D); 2 × no xgameruntime.dll
  • #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

  • Claude Code (Claude Opus 5.5) found the difference with #2169's fuzzer, wrote the fix, the test and this description, and ran the tests on my machine. I have read the diff.

🤖 Generated with Claude Code

**@⁠Victorbriez** on GitHub · 2026-11-25 16:13 UTC · [original](https://github.com/xcl-dev/xcl/pull/2348) `Victorbriez:recomp/cube-sign-negation` → `main` · +59 −6 · 3 files · 1 commits · open 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 #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`, #2182); 1 × no heap windows; 1 × Developer Mode off (0x887A002D); 2 × no xgameruntime.dll - #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** - Claude Code (Claude Opus 5.5) found the difference with #2169's fuzzer, wrote the fix, the test and this description, and ran the tests on my machine. I have read the diff. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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 #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 #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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:28:31 +00:00
Author
Owner

@⁠SlopTart on GitHub · 2026-11-25 16:41 UTC · original

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 #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.

**@⁠SlopTart** on GitHub · 2026-11-25 16:41 UTC · [original](https://github.com/xcl-dev/xcl/pull/2348#issuecomment-7168381269) **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 #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.
Author
Owner

@⁠Victorbriez on GitHub · 2026-11-25 17:10 UTC · original

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.

**@⁠Victorbriez** on GitHub · 2026-11-25 17:10 UTC · [original](https://github.com/xcl-dev/xcl/pull/2348#issuecomment-7169121795) 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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 18:27 UTC · original

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

  • cargo test -p xcl --lib: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 18:27 UTC · [original](https://github.com/xcl-dev/xcl/pull/2348#issuecomment-7170925924) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun. Thanks!
Author
Owner

@⁠emirduran707 on GitHub · 2026-11-25 19:54 UTC · original

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.
    • The PR's GPU test passed (no skips): gpu::recomp::tests::gpu_cube_coordinates_negate_denormals_by_sign.
    • The 3 failures are pre-existing on the PR's base main: gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (seed 722) and fuzz_validate_and_gpu_3 (seed 1599) on this GPU, plus gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier (from 50a9fde / #2074, fixed later on main in #2420).

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.
**@⁠emirduran707** on GitHub · 2026-11-25 19:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/2348#issuecomment-7172932722) 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. - The PR's GPU test passed (no skips): `gpu::recomp::tests::gpu_cube_coordinates_negate_denormals_by_sign`. - The 3 failures are pre-existing on the PR's base `main`: `gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1` (seed 722) and `fuzz_validate_and_gpu_3` (seed 1599) on this GPU, plus `gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier` (from `50a9fde` / #2074, fixed later on `main` in #2420). **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.
Author
Owner

@⁠Victorbriez on GitHub · 2026-11-25 20:17 UTC · original

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.

**@⁠Victorbriez** on GitHub · 2026-11-25 20:17 UTC · [original](https://github.com/xcl-dev/xcl/pull/2348#issuecomment-7173457430) 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.
Author
Owner

@⁠bmjask on GitHub · 2026-11-25 20:26 UTC · original · reviewed

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.

**@⁠bmjask** on GitHub · 2026-11-25 20:26 UTC · [original](https://github.com/xcl-dev/xcl/pull/2348#pullrequestreview-6064470626) · **reviewed** 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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 08:15 UTC · original

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

**@⁠DavidM1911** on GitHub · 2026-11-26 08:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/2348#issuecomment-7186375274) 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
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2348/head:github-bot/gh-2348'
git switch 'github-bot/gh-2348'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2348'
git switch 'github-bot/gh-2348'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2348'
git switch 'github-bot/gh-2348'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2348'
git switch 'main'
git merge --squash 'github-bot/gh-2348'
git switch 'main'
git merge --ff-only 'github-bot/gh-2348'
git switch 'main'
git merge 'github-bot/gh-2348'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.