Skip to content

Recompiler: honor FP32 denormal mode in FREXP exponent - #1994

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
pane33:fix/gpu-frexp-exp-f32-mode
Nov 25, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
pane33:fix/gpu-frexp-exp-f32-mode

Conversation

@pane33

@pane33 pane33 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Honor explicitly written guest FP32 input-denormal mode when translating V_FREXP_EXP_I32_F32. Derive the exponent from the input bits after a write to MODE[4] and preserve the legacy result before that write.

Previously, the exponent calculation could return zero for a preserved FP32 subnormal. For example, the smallest positive subnormal (0x00000001) should produce -148 when input denormals are preserved.

What is in it

  • Track explicit MODE[4] writes in the HLSL and Direct DXIL recompiler paths. Direct DXIL reuses its existing MODE state and bumps the translation-cache version from 7 to 8.
  • Add GPU coverage for denormal modes, partial register writes, control flow, initial MODE, directed rounding, and the per-lane path.

Tested

  • Candidate 7a1f5a2 and upstream baseline 8e87fc7. Windows x64 build 26300.9974, AMD Ryzen 5 7600X, NVIDIA GeForce RTX 4060 (621.24), Rust 1.100.0, DXC 1.9.2602.17.
  • cargo test -p xcl --lib gpu_frexp_exp_f32_denorm -- --nocapture. The FREXP filter passed six tests in each configuration: four backend-selectable tests and two explicit Direct DXIL tests covering directed rounding and per-lane lowering. Zero skips. Loop/SSA and upstream regression filters passed in both configurations. A standalone GPU probe verified the legacy result at loop entry and exponent -148 after the MODE write crossed the back-edge, in all 32 lanes in each backend.
  • cargo build --workspace and cargo test --workspace --no-fail-fast -- --test-threads=4: HLSL (Direct DXIL unset) 996 passed, 0 failed, 45 ignored. With XCL_DIRECT_DXIL=all: 995 passed, 1 failed, 45 ignored. Each suite logged 24 skip events across 14 tests, including partial skips: 19 wave64 cases, 3 unsupported per-lane cases, 1 driver-cache control case, and 1 heap-window case.
  • offline_compute_pipeline_is_reused_by_a_second_process also fails on the clean upstream baseline with Direct DXIL and passes there with HLSL. Both Direct DXIL failures occur while looking up a top-level .dxil cache file.
  • cargo build --release -p xcl succeeded on both commits.
  • Ran scripts/smoke.ps1 for 60 seconds per run on a newer retail game. Both candidate runs were repeated after the push. HLSL: frames 1,069 to 1,128 (+5.52%), peak committed memory 15,336 to 15,327 (-0.06%) MB. Direct DXIL: frames 1,149 to 1,154 (+0.44%), peak committed memory 15,329 to 15,323 (-0.04%) MB. All four comparison runs exited with 0x0, zero crashes and zero device removals. The deltas are single-run observations.
  • Direct DXIL recorded CS 1, PS 5, VS 5 translations on each commit, with zero failures or HLSL fallbacks.
  • Warning messages and counts matched within each backend after normalizing addresses and call-site references. The logs contained no errors.

Regression run

Each run used a clean profile, an isolated XCL cache, no input and the RTX 4060. Direct DXIL runs used XCL_DIRECT_DXIL=all and XCL_DIRECT_DXIL_STATS=1. Per-lane lowering and the PSO disk cache were disabled.

Baseline HLSL

xcl-smoke v1
commit: 8e87fc7b62a87ea589ccb9ea6182f514016cf7db
gpu: NVIDIA GeForce RTX 4060
title: 4949b6b3
seconds: 60
exit: 0x0
frames shown: 1069 (PresentX 1069)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15336 MB

Baseline Direct DXIL

xcl-smoke v1
commit: 8e87fc7b62a87ea589ccb9ea6182f514016cf7db
gpu: NVIDIA GeForce RTX 4060
title: 4949b6b3
seconds: 60
exit: 0x0
frames shown: 1149 (PresentX 1149)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15329 MB

Candidate Direct DXIL

xcl-smoke v1
commit: 7a1f5a2e6541c9fa0ef921e319fa81a2fdc2e42f
gpu: NVIDIA GeForce RTX 4060
title: 4949b6b3
seconds: 60
exit: 0x0
frames shown: 1154 (PresentX 1154)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15323 MB

Candidate HLSL

xcl-smoke v1
commit: 7a1f5a2e6541c9fa0ef921e319fa81a2fdc2e42f
gpu: NVIDIA GeForce RTX 4060
title: 4949b6b3
seconds: 60
exit: 0x0
frames shown: 1128 (PresentX 1128)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15327 MB

Not tested

  • Native wave64, AMD hardware, and optional XCL_SAMPLE_* datasets. Retail coverage of the specific FREXP opcode remains unverified.

AI use

  • The original commit records Assisted-by: Codex (GPT-6.2-Sol) for the implementation and tests. Codex (GPT-6 family, exact variant unavailable in the current session) reviewed upstream changes, resolved the test-placement conflict, ran and summarized synthetic and retail validation, and prepared this draft.
  • ChatGPT (GPT-6.2) assisted with technical planning, implementation supervision, independent diff review, validation strategy, and PR description review.

Derive the exponent from the input bits after an explicit MODE[4]
write. Preserve the legacy result before that write and reuse the
Direct DXIL MODE state.

Assisted-by: Codex (GPT-6.2-Sol)
@pane33
pane33 marked this pull request as ready for review November 25, 2026 00:32
@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

An independent hardware reference for the rule: boykopovar/AnyPS5's debt notes (docs/dev/debt/shader.md, f32 denormals entry) record, from their hardware oracle on RDNA2 gfx1035 at IEEE=0 and 1, that v_frexp_exp_i32_f32 flushes its f32 input when the f32 denormal field flushes. So a denormal gives exponent 0 under the usual 0xc0 mode, and with denormals kept the input's own exponent is used (−148 for 0x00000001). That matches what this PR does once MODE[4] is written.

Also passes here: RTX 3070 (Ampere, driver 616.56, Windows 11, debug) at 7a1f5a2, with the gpu_ tests under XCL_DIRECT_DXIL=0 and 1 giving 117 passed each, and the dxil:: units passing.

One merge-order note: this is the fourth open PR moving TRANSLATOR_VERSION from 7 to 8 (with #1946, #1950 and #1952). #1947 would make those bumps unnecessary.

AI-assisted (Claude Code). Synthetic tests only.

@DarkPanda69

Copy link
Copy Markdown

AMD run with native 64-lane waves, which this PR lists as not tested.

Tested: pass, head 7a1f5a2 applied on its base main 6567c5f, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17.
cargo test -p xcl --lib -- gpu:: --test-threads=4:

  • AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010, waves 32..64: 470 passed, 2 failed, 21 ignored. All six gpu_frexp_exp_f32_denorm_* tests ok. The 2 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 and _3, which fail the same way on main 6567c5f without this PR on this card.
  • NVIDIA RTX 3060, driver 32.0.16.1088: 472 passed, 0 failed, 21 ignored. All six new tests ok.

Not tested: XCL_SAMPLE_* data; the whole workspace suite; a title.

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

@raylitebull

Copy link
Copy Markdown
Member

Both AMD and NVIDIA passes look clean on 7a1f5a2.

Remaining before merge: please rebase onto main — #1950 already took TRANSLATOR_VERSION = 8 and #1947 now auto-hashes gpu/dxil sources (XCL_DIRECT_DXIL_SOURCE_ID), so the manual kernel.rs version bump can be dropped — then let Build and test (Windows, no GPU) complete cleanly.

@zhouzhidong3-hash

Copy link
Copy Markdown

Independent RTX 5070 focused verification of #1994

Commit 7a1f5a2. No tracked source differences after execution.

Windows x64, NVIDIA GeForce RTX 5070 driver 591.86, Rust 1.100.0 MSVC debug test build, DXC/DXIL 1.8.2502.11, local D3D12 Agility SDK. XCL_ADAPTER=5070 was explicitly set.

Command in each configuration

cargo test --locked -p xcl --lib gpu_frexp_exp_f32_denorm -- --test-threads=1 --nocapture

  • XCL_DIRECT_DXIL=0, 6 passed, 0 failed, 0 ignored, 966 filtered out, 12.29 seconds.
  • XCL_DIRECT_DXIL=all, 6 passed, 0 failed, 0 ignored, 966 filtered out, 0.34 seconds.
  • No SKIPPED or skipping messages in either final log. Two tests explicitly exercise Direct DXIL regardless of the outer backend setting. Four tests are backend-selectable.
  • Covered denormal modes, setreg writes, control flow, initial mode, explicit Direct DXIL directed rounding and per-lane lowering.

Logs are gpu-0.log and gpu-all.log in this directory. Earlier retry logs with six skips are environment failures and provide zero GPU coverage. Initial build attempts exited 101 due to transient executable-launch denial, subsequently resolved without security-setting changes. Its cause remains unknown.

Not tested in this run: baseline control, full workspace suite, Release build, native RDNA2, wave64, retail game behavior, or runtime fallback instrumentation. These results establish focused synthetic assertion coverage on this adapter.

AI assistance: OpenAI Codex prepared the environment, ran the unchanged upstream tests, inspected logs and drafted this report.

@JJAutoCompare

Copy link
Copy Markdown

Independent Intel Arc A770 verification of 7a1f5a2e6541c9fa0ef921e319fa81a2fdc2e42f. The checkout was clean before and after testing and still matched the open PR head before posting.

Tested

  • Intel Arc A770, driver 32.0.101.9175, Windows 11 Enterprise Evaluation x64 build 26200.9974, AMD Ryzen 7 3800X (6 cores / 12 threads exposed), Rust/Cargo 1.100.0 (x86_64-pc-windows-msvc), debug, DXC and DXIL validator 1.9.2609.5.
  • Prebuilt with cargo test -p xcl --lib --no-run outside the shared Arc lock. Ran the command below once with XCL_DIRECT_DXIL=0 and once with XCL_DIRECT_DXIL=1 inside the lock, both with XCL_ADAPTER=A770. TEMP, TMP and the Cargo target were isolated on L:, with CARGO_BUILD_JOBS=2 and CARGO_INCREMENTAL=0.
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test {
    cargo test -p xcl --lib gpu_frexp_exp_f32_denorm -- --nocapture --test-threads=1
}
Backend setting Passed Failed Ignored GPU skips Filtered out
XCL_DIRECT_DXIL=0 5 1 0 0 966
XCL_DIRECT_DXIL=1 5 1 0 0 966

The four backend-selectable cases (denormal modes, partial register writes, control flow, initial mode) passed through HLSL and Direct DXIL. The explicit Direct DXIL per-lane case passed in both runs. The explicit Direct DXIL test gpu::dxil::round_tests::gpu_frexp_exp_f32_denorm_with_directed_rounding failed in both runs after validation, at PSO creation, before its GPU output assertions.

GPU run: "CreateComputePipelineState: The parameter is incorrect. (0x80070057)"

Not tested

Baseline, cause of the PSO failure, native wave64, other hardware or driver versions, full workspace suite, retail-title smoke, and optional sample data.

AI use

Codex (gpt-6.2-sol) ran the existing tests, checked the logs and wrote this report.

@raylitebull
raylitebull merged commit edf8c16 into xcl-dev:main Nov 25, 2026
3 checks passed
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.

6 participants