Skip to content

Recompiler: preserve zero sign in HLSL f16 multiplies - #2183

Open
luckyteagirl wants to merge 1 commit into
xcl-dev:mainfrom
luckyteagirl:codex/f16-mul-signed-zero
Open

luckyteagirl wants to merge 1 commit into
xcl-dev:mainfrom
luckyteagirl:codex/f16-mul-signed-zero

Conversation

@luckyteagirl

@luckyteagirl luckyteagirl commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the f16 multiplication signed-zero part of #2168 on the default HLSL backend. On the RX 6800M, DXC fast math can turn a negative-zero product into positive zero for V_MUL_F16 and V_PK_MUL_F16; direct DXIL preserves the sign. A global -Gis switch also changes FMA results on this card, so this patch repairs only the two multiply forms.

What is in it

  • Restore the zero sign from the operand half bits after HLSL f16 multiply rounding, leaving nonzero results unchanged. Scalar ABS/NEG and packed per-half NEG are accounted for; clamped multiplies retain their existing path.
  • Add a GPU regression for scalar and packed results, positive and negative zero, subnormal operands, ordinary nonzero controls, preserved destination halves, and source negation.

Tested

  • Clean rebased head abcf799a3a08766a62a645f2159a3f9e82e9459c on main 6d12f58a229bc73889878a448c64dc3af25eeba0; Windows 11 Home build 26200, Ryzen 9 5980HX, Radeon RX 6800M driver 30.0.13002.13003, Rust 1.99.0 MSVC, DXC/DXIL 1.8.2502.11.
  • cargo test --locked -p xcl --lib -j 2 gpu_f16_multiply_preserves_zero_sign -- --test-threads=1 --show-output, with XCL_ADAPTER=6800M and XCL_REQUIRE_GPU=wave64: 1 passed, 0 failed, 0 ignored, 0 SKIPPED with XCL_DIRECT_DXIL=0, and the same counts with XCL_DIRECT_DXIL=1. The two guarded runs did not trigger the memory guard.
  • An initial current-head HLSL build attempt was stopped by the 1 GiB free-commit memory guard while unrelated local jobs ran; it produced no test result. The retry above completed after memory recovered.
  • cargo build --locked --release -p xcl --bins -j 2: passed under the 1 GiB free-commit guard with no trigger on the retry. An earlier attempt was guard-stopped before completion when unrelated jobs exhausted free commit; it produced no build result. git diff --check: clean.
  • Independent RTX 3070 report on this exact clean head: .\scripts\test.ps1 completed with 1,424 passed, 0 failed, 46 ignored, and 25 explicit GPU skips (21 native-wave64, one heap-window, three refused per-lane forms). The focused f16 regression passed. A separate 60-second release title smoke showed 1,563 frames, 15,387 MB peak, and zero crashes/device removals against a same-machine main baseline of 1,605 frames and 15,009 MB. These are the independent reporter's results, not runs on our RX 6800M.
  • Historical evidence on the earlier head 46b7744: the RX 6800M fuzzer comparison found 26/256 V_MUL_F16 and 49/256 V_PK_MUL_F16 HLSL/direct differences before the emitter change, and 0/256 for each after it. Its full workspace run reported 993 passed, 162 failed, 46 ignored; 161 of the failed names matched a prior clean-main run after this old AMD driver suspended the device. These are not current-head suite results.

Regression run

The committed release binaries for the tested main base (6d12f58) and this PR ran the same locally owned title on the RX 6800M for five seconds each, with separate data and shader caches. Both exited normally with no crash, device removal, or memory-guard trigger, but neither reached a frame; these runs cover startup only. A separate seven-second main run showed six frames, while the seven-second head attempt hit the unchanged 1 GiB free-commit guard at 713 MB and produced no smoke block. The focused GPU fixture above exercises the changed f16 instructions.

Tested main base:

xcl-smoke v1
commit: 6d12f58a229bc73889878a448c64dc3af25eeba0
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 5
exit: 0x0
frames shown: 0 (PresentX 0)
presents per 2 s (last 3): 0 0
device removals: 0
crashes: 0
peak commit: 5395 MB

This PR:

xcl-smoke v1
commit: abcf799a3a08766a62a645f2159a3f9e82e9459c
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 5
exit: 0x0
frames shown: 0 (PresentX 0)
presents per 2 s (last 3): 0 0
device removals: 0
crashes: 0
peak commit: 6555 MB

On an RTX 3070, ramon-victor reported an independent 60-second retail comparison on this exact clean PR head and main 08db802. The PR showed 1,563 frames and 15,387 MB peak commit. The reported main baseline showed 1,605 frames and 15,009 MB. Both reported zero crashes or device removals. The report includes the PR's raw smoke block and summarizes the main run, so the paired raw blocks above remain the recorded comparison for the checker. The independent smoke reached rendered frames, with no verified coverage of the changed f16 instructions. Independent RTX 3070 report

Not tested

  • A completed current-head GPU workspace suite on our RX 6800M, and whether either title run executed the changed f16 opcode. The independent RTX 3070 suite skipped 25 GPU tests. No game data was uploaded.

AI use

OpenAI Codex (GPT-6; exact variant unavailable) implemented the fix and regression, rebased the commit, ran the current-head focused GPU checks and guarded release/smoke runs, reviewed logs, and drafted this description.
OpenAI Codex (GPT-6.2 Astra) verified the independent exact-head report and added its linked results to this description.
OpenAI Codex (GPT-6.2 Sol) added the attributed positive-frame comparison to the regression section and verified the PR checker without changing the code.

@luckyteagirl luckyteagirl changed the title codex/f16 mul signed zero Recompiler: preserve zero sign in HLSL f16 multiplies Nov 25, 2026
@luckyteagirl
luckyteagirl marked this pull request as ready for review November 25, 2026 08:12
@Diskuss

Diskuss commented Nov 25, 2026 •

Copy link
Copy Markdown

Tested on AMD Radeon RX 9070 XT (RDNA4) at 46b7744cc9c39eb8f8cf06ea2c95e5164abcdf9b

AMD Radeon RX 9070 XT, driver 32.0.32015.7029; Ryzen 7 5700X3D; 32 GB; Windows 11 Pro build 26300.9974; Rust 1.100.0 msvc; DXC 1.9.2602.17; debug build. The head is directly on top of main 568e7db (0 commits behind), tested as is.

Tested:

Not tested: the #2168 cross-backend fuzzer (it is not on main, so I did not check the v_sin/v_cos or ldexp cases before/after), retail title / scripts/smoke.ps1 (no game files), release build.

Update: #2169 fuzzer comparison (asked for by DarkPanda69). Base: main 568e7db plus #2169 e792e6b; head: 46b7744 plus #2169 e792e6b. Both local merges, no conflicts, not pushed. Debug build, XCL_FUZZ_OPS=V_MUL_F16,V_PK_MUL_F16,V_LDEXP_F16,V_SIN_F16,V_SIN_F32,V_COS_F32,V_FMA_F16,V_PK_FMA_F16, cargo test -p xcl --lib valu_fuzz_backends_agree -- --ignored --test-threads=1 (256 inputs per instruction, default 4 rounds):

HLSL vs direct DXIL differences (of 256) RX 9070 XT, main + #2169 RX 9070 XT, PR + #2169
V_MUL_F16 26 0
V_PK_MUL_F16 49 0
V_LDEXP_F16 19 19
V_SIN_F16 4 4
V_SIN_F32 7 7
V_COS_F32 8 8
V_FMA_F16, V_PK_FMA_F16 0 0

Instructions with differences: 6 on main, 4 with the PR. Same numbers for both multiplies as DarkPanda69's RX 9070 run. The ldexp/sin/cos differences are unchanged (out of scope for this PR).

Report written by Claude Code (Claude Sonnet 5.5) from a real run on this machine.

@DarkPanda69

DarkPanda69 commented Nov 25, 2026 •

Copy link
Copy Markdown

Update for head abcf799: rerun on main e1d84b7, with #2169 e792e6b for the fuzzer, same commands and cards. The table below holds at this head: RX 9070 XT V_MUL_F16 26 → 0 and V_PK_MUL_F16 49 → 0, the other instructions unchanged; RTX 3060 0 differences before and after. gpu_f16_multiply_preserves_zero_sign ok on both. Whole gpu:: filter with this PR: RX 9070 XT 699 passed, 2 failed (the #2115 fuzz seeds), 6 SKIPPED; RTX 3060 701 passed, 0 failed, 24 SKIPPED.

The #2169 fuzzer before and after this PR on RDNA4 and on NVIDIA ("other GPU vendors" is listed as untested, and the RDNA4 report above didn't run the fuzzer).

Head 46b7744 and #2169 e792e6b applied on main 568e7db, debug, XCL_FUZZ_OPS limited to the f16/sin/cos instructions of #2168, cargo test -p xcl --lib valu_fuzz_backends_agree -- --ignored --test-threads=1 (256 inputs per instruction):

HLSL vs direct DXIL differences RX 9070 XT, main RX 9070 XT, this PR RTX 3060, main RTX 3060, this PR
V_MUL_F16 26 0 0 0
V_PK_MUL_F16 49 0 0 0
V_LDEXP_F16, V_SIN_F16, V_SIN_F32, V_COS_F32 19, 4, 7, 8 19, 4, 7, 8 (out of scope here, as the description says) 0 0
V_FMA_F16, V_PK_FMA_F16 0 0 0 0

So the fix removes both multiply differences on RDNA4 too, and changes nothing on NVIDIA, where the HLSL path already kept the sign. gpu_f16_multiply_preserves_zero_sign passes on both cards; whole gpu:: filter with this PR: RX 9070 XT (driver 32.0.32029.2010) 585 passed, 2 failed (the #2115 fuzz seeds, same on main); RTX 3060 (32.0.16.1088) 587 passed, 0 failed.

Not tested: a title.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@luckyteagirl
luckyteagirl force-pushed the codex/f16-mul-signed-zero branch from 46b7744 to abcf799 Compare November 25, 2026 22:09
@ramon-victor

Copy link
Copy Markdown
Contributor

Independent NVIDIA (wave32) full-suite + retail smoke test report on exact PR head abcf799a3a08766a62a645f2159a3f9e82e9459c (clean detached checkout, no local changes).

Tested

  • Hardware & toolchain: NVIDIA GeForce RTX 3070 8 GiB (wave32, driver 621.24), AMD Ryzen 7 5700X, 32 GiB RAM, Windows 11 Pro (build 26300), Rust 1.99.0 (x86_64-pc-windows-msvc), DXC/DXIL 1.8.2502.11 (Windows SDK 10.0.26100.0); debug tests, release smoke.
  • Targeted PR GPU test (cargo test -p xcl --lib gpu_f16_multiply_preserves_zero_sign): 1 passed, 0 failed.
  • Full workspace (.\scripts\test.ps1): 1424 passed, 0 failed, 46 ignored (25 GPU skips expected on this wave32 adapter: 21 no wave64, 1 no heap windows, 3 wave32 per-lane refused for #1426 f16/f32 semantics).
  • Release build (cargo build --release -p xcl) and 60 s retail smoke run (XCL_NETWORK=0, compared against main @ 08db802 baseline on the same machine today: 1605 frames, 15009 MB peak commit, 0 crashes, 0 device removals):

Regression run

xcl-smoke v1
commit: abcf799a3a08766a62a645f2159a3f9e82e9459c
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1563 (PresentX 1564)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15387 MB

Not tested

  • AMD / Intel GPUs and wave64-only GPU tests (skipped on RTX 3070); XCL_SAMPLE_* tests (unset).

AI use

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

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

— Devin

@SzczepanGrela

Copy link
Copy Markdown

RX 9070 / Wine check of exact head abcf799a3a08766a62a645f2159a3f9e82e9459c, main 83b008188efbf954b846667f48d75e3fa9310a01, and an automatic conflict-free integration of this PR onto that main. All three agree with the reference in the cases below. The main control also preserves zero signs here, so this does not reproduce the Windows AMD failure on our stack.

RX 9070 16 GB (RADV GFX1201), Ryzen 7 7700, CachyOS kernel 7.3.6-1-cachyos, Mesa 26.3.1-5, GE-Proton11-12 / Wine 11.0 Staging, ntsync. Native vkd3d-proton 8293130ebe370b1+, local asserts-disabled build; DXC/DXIL 1.9.2602.17, Rust 1.97.1, Windows-GNU release. Private enabled caches per process.

Tested

  • Original gpu_f16_multiply_preserves_zero_sign, with XCL_DIRECT_DXIL=0 and 1, at both --test-threads=1 and 4, on each source: 1 passed / 0 failed / 0 ignored / 0 skipped per invocation. Copied unchanged to the main control; only added an observation before the original assertions. All 64 lanes' four output registers agree with the original expected values.
  • An appended owned RDNA2 program covers all 65,536 binary16 first-operand patterns, packed with their opposite-sign counterparts, against 12 second-operand pairs: signed zero/one, smallest/largest subnormal, smallest normal, 0x3555, 0x3c01, largest finite, infinity and quiet NaN. The upper input halves have opposite signs to the lower halves. Three scalar forms cover VOP2, ABS/NEG and VOP3 high-half sources/destination; three packed forms cover normal, per-half NEG and crossed source-half selection.
  • Both translators, native physical wave32 and wave64, default RNE, three fresh full processes per source plus one pilot each: 1 passed / 0 failed / 0 ignored / 0 skipped per invocation. Physical widths confirmed by separate GPU probes. Non-NaN results, including signed zeros and infinities, match bit-for-bit; NaNs checked by quiet class, not payload. Destination halves and every memory word outside the output region retain their guards.
  • 24 processes, 480 GPU dispatches in total. Independently checked 254,809,152 half results including repeats, 206,252,352 memory words and 1,536 width-probe outputs. The fixture uses exact integer-product/tie-even CPU arithmetic; the separate checker multiplies binary16 values exactly in binary64 and rounds once to binary16. No zero-sign or other mismatches on any source or mode; no device removal.
cargo test --offline --locked --release --target x86_64-pc-windows-gnu -p xcl --lib --no-run
wine <test-exe> gpu::recomp::tests::gpu_f16_multiply_preserves_zero_sign --exact --nocapture --test-threads=1
wine <test-exe> gpu::recomp::tests::gpu_f16_multiply_preserves_zero_sign --exact --nocapture --test-threads=4
wine <test-exe> gpu::recomp::tests::workflow_f16_multiply::workflow_all_half_multiply_patterns --exact --nocapture --test-threads=1

The last filter is a local fixture. Production functions and original assertions were not edited. The exact head's parent is 6d12f58a; the PR API reports base e1d84b7d. Integration used the actual parent and main 83b00818. During testing, main advanced to 623d02e4 via #2977; its only changed file is uma_driver.rs (grooming the coherent window). I reviewed that delta, but did not build or test the newer main snapshot.

Not tested: clamp, dynamic rounding modes, OMOD, SDWA/DPP, split wave64, other shader contexts, whole suite, title/smoke or performance. No global -Gis switch or retail data used. These are additional Wine/RADV correctness cases.

AI use: OpenAI Codex (GPT-6; exact serving variant not exposed) reviewed the public patch, prepared the source integration and local fixtures, ran and independently verified the readbacks, and drafted this report. Publication authorized by the account owner.

@Decodere

Copy link
Copy Markdown
Contributor

Independent desktop NVIDIA verification of PR #2183 at exact head abcf799a3a08766a62a645f2159a3f9e82e9459c (1 commit; exact parent & merge-base: 6d12f58a229bc73889878a448c64dc3af25eeba0 on main), plus a clean temporary local conflict-free merge onto main 623d02e465a17497a757a4ce867f482b0a6c8f3b (local merge commit 55e5afea7da3f297d4eef234680885f67f016319, discarded after testing).

Environment

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12, 32-lane waves), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6C / 12T), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200 (Developer Mode off)
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC 1.9.2609.5, --release

Targeted release tests & build (exact head abcf799a & local merge 55e5afea onto 623d02e4)

Target & Command Result
Exact head abcf799a: cargo build --release -p xcl Clean build (1m 30s, exit 0, 0 new warnings in emit.rs / tests.rs)
Exact head abcf799a: gpu_f16_multiply_preserves_zero_sign (XCL_DIRECT_DXIL=0, --test-threads=1 & --test-threads=4, 3× each) 1 passed; 0 failed; 0 ignored; 1324 filtered out × 6 (0.24–0.31s, 0 skipped)
Exact head abcf799a: gpu_f16_multiply_preserves_zero_sign (XCL_DIRECT_DXIL=1, --test-threads=1 & --test-threads=4, 3× each) 1 passed; 0 failed; 0 ignored; 1324 filtered out × 6 (0.20–0.24s, 0 skipped)
Exact head abcf799a: cargo test --release -p xcl --lib -- gpu::recomp:: --test-threads=4 --nocapture (3 consecutive runs) 393 passed; 0 failed; 19 ignored; 913 filtered out × 3 (8.15s, 7.89s, 7.81s; 23 expected runtime SKIPPED lines: 20 no wave64 + 3 wave32 per-lane refused)
Unpatched main 623d02e4 control (test-only hunk applied, emit.rs unpatched): gpu_f16_multiply_preserves_zero_sign (XCL_DIRECT_DXIL=0 & XCL_DIRECT_DXIL=1, --test-threads=1) 1 passed; 0 failed on both (0.27s / 0.24s, 0 skipped — RTX 4060 driver 621.14 + DXC 1.9.2609.5 already preserves -0 on these f16 multiplies natively)
Local temp merge 55e5afea (abcf799a onto 623d02e4, ort clean merge): cargo build --release -p xcl Clean build (1m 40s, exit 0, 0 new warnings in emit.rs / tests.rs)
Local temp merge 55e5afea: gpu_f16_multiply_preserves_zero_sign (XCL_DIRECT_DXIL=0, --test-threads=1 & --test-threads=4, 3× each) 1 passed; 0 failed; 0 ignored; 1357 filtered out × 6 (0.24–0.29s, 0 skipped)
Local temp merge 55e5afea: gpu_f16_multiply_preserves_zero_sign (XCL_DIRECT_DXIL=1, --test-threads=1 & --test-threads=4, 3× each) 1 passed; 0 failed; 0 ignored; 1357 filtered out × 6 (0.20–0.21s, 0 skipped)
Local temp merge 55e5afea: cargo test --release -p xcl --lib -- gpu::recomp:: --test-threads=4 --nocapture (3 consecutive runs) 402 passed; 0 failed; 20 ignored; 936 filtered out × 3 (7.94s, 7.98s, 7.95s; 23 expected runtime SKIPPED lines: 20 no wave64 + 3 wave32 per-lane refused)

Paired quiet 60 s retail smoke (title: 29640639, XCL_PREPARE=0 XCL_NETWORK=0)

main baseline (623d02e465a17497a757a4ce867f482b0a6c8f3b, XCL_PREPARE=0 XCL_NETWORK=0):

xcl-smoke v1
commit: 623d02e465a17497a757a4ce867f482b0a6c8f3b
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1587 (PresentX 1587)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14010 MB

Temporary local conflict-free merge of PR #2183 (abcf799a) onto 623d02e4 (55e5afea7da3f297d4eef234680885f67f016319, XCL_PREPARE=0 XCL_NETWORK=0):

xcl-smoke v1
commit: 55e5afea7da3f297d4eef234680885f67f016319
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1586 (PresentX 1586)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14043 MB

Limits of coverage

  • Verified on desktop Windows 11 + NVIDIA GeForce RTX 4060 (32-lane Wave32, driver 621.14, DXC 1.9.2609.5) across both XCL_DIRECT_DXIL=0 and XCL_DIRECT_DXIL=1 and both --test-threads=1 and --test-threads=4 (24/24 passing runs across exact head abcf799a and local merge 55e5afea), with zero parallel-scheduling flakiness observed.
  • Because unpatched main 623d02e4 already passed gpu_f16_multiply_preserves_zero_sign on this RTX 4060 + DXC 1.9.2609.5 host, this run confirms cross-vendor non-regression and parallel-test stability on NVIDIA Ada rather than reproducing the AMD RX 6800M / driver -0 erasure failure mode directly.
  • Paired 60 s retail smokes ran on the temporary local integration onto 623d02e4 (55e5afea) with XCL_PREPARE=0 (XCL_NETWORK=0), bypassing startup prepare_for_launch shader precompilation.
  • Native 64-lane AMD hardware (including AMD RX 6800M, 20 no wave64 skipped subcases), Wine hosts, and the 20 #[ignore] tests were not exercised on this machine.

AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).

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.

7 participants