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

Copy link
Copy Markdown
Contributor

Fixes the f16 multiplication signed-zero part of #2168 on the default HLSL backend. On the RX 6800M, DXC's default fast math turns a negative-zero product into positive zero for V_MUL_F16 and V_PK_MUL_F16; direct DXIL preserves the sign. Applying -Gis globally removes those differences but introduces FMA-family differences on this same GPU (measurements).

What is in it

  • After each HLSL f16 multiply is rounded, f16_mul_zero_sign restores the zero sign from the source half bits. Nonzero results are returned unchanged. The scalar path accounts for ABS/NEG; the packed path accounts for per-half NEG. Clamped multiplies stay on their existing saturation path.
  • A GPU regression checks scalar and packed products, positive and negative zero, subnormal operands, ordinary nonzero controls, preserved destination halves, and source negation.
  • This is limited to the two multiply instructions. It does not change the HLSL compiler flags, FMA lowering, or the remaining V_LDEXP_F16 / V_SIN_* / V_COS_F32 differences in Recompiler: the HLSL backend's fast-math loses -0 in f16 results and changes v_sin/v_cos on AMD #2168.

Tested

  • Windows 11 build 26200; Ryzen 9 5980HX; Radeon RX 6800M driver 30.0.13002.13003; Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5. Debug tests and release build.
  • With only the new test on clean base 568e7db, cargo test --locked -p xcl --lib -j 2 gpu_f16_multiply_preserves_zero_sign -- --test-threads=1 --show-output failed on the HLSL path at lane 0: 0xBEEF0000 vs expected 0xBEEF8000. The direct-DXIL control passed. After this fix, the expanded regression passed on both HLSL and direct DXIL with XCL_REQUIRE_GPU=wave64: 1 passed, 0 failed, 0 ignored, no skips in each run.
  • Using Tests: a cross-backend and cross-device VALU fuzzer (ignored by default) #2169's ignored fuzzer in a separate local worktree, the unmodified head had 26/256 V_MUL_F16 and 49/256 V_PK_MUL_F16 HLSL/direct differences on this GPU. With only this emitter patch applied there and default DXC flags, both instructions compared over 256 inputs each with 0 differences, 0 refusals. The fuzzer worktree was restored afterward; its code is not part of this PR.
  • cargo build --locked --workspace -j 2, cargo build --locked --workspace --release -j 2, and the e2e integration suite (3 passed, 0 failed, 0 ignored) passed.
  • Unskipped cargo test --locked --workspace --no-fail-fast -j 2 -- --test-threads=4 --show-output after the workspace build: 993 passed, 162 failed, 46 ignored across 21 test targets. Clean main on the same RX 6800M driver previously reported 993 passed, 161 failed, 46 ignored. The 161 common failure names are GPU/device-suspension failures (0x887A0005). The one additional failed name is this new GPU test: in the bulk run it too hit CreateComputePipelineState: ... device ... suspended (0x887A0005) after earlier GPU failures; it passed in isolated HLSL and direct runs. The log has nine explicit SKIPPED notices, which count as passed but do not provide coverage. A follow-up excluding the DXIL fuzz group still hit device suspension in other GPU tests.

Regression run

Paired guarded seven-second launches of the same owned 1.0.2.1 title with isolated data and shader caches. The baseline commit differs from this branch's main base only in README.md and assets/readme/status.svg, so its runtime source matches. Both runs reached one frame, with zero draws and dispatches in the observed window; they did not demonstrate execution of the changed f16 code.

xcl-smoke v1
commit: 6020a33b16ba2de25b3aef5947552f2dc1831f09
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 7
exit: 0x0
frames shown: 1 (PresentX 1)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 6884 MB
xcl-smoke v1
commit: 46b7744cc9c39eb8f8cf06ea2c95e5164abcdf9b
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 7
exit: 0x0
frames shown: 1 (PresentX 1)
presents per 2 s (last 3): 0 0 1
device removals: 0
crashes: 0
peak commit: 7040 MB

Not tested

  • A clean full RX 6800M GPU suite on this driver, other GPU vendors, or a retail shader that executes either changed instruction. The short smoke pair does not support a sustained performance conclusion.

AI use

OpenAI Codex wrote the fix and regression, ran the failed-first and direct controls, ran the AMD fuzzer comparison and Windows checks, and prepared this description. The owner requested this PR. No game files or shader packs are included.

@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

Copy link
Copy Markdown

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!

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.

4 participants