Skip to content

Recompiler: round direct-DXIL f16 converts and products to nearest-even - #1742

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
oni-swr:dxil/f16-default-rne
Nov 25, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
oni-swr:dxil/f16-default-rne

Conversation

@oni-swr

@oni-swr oni-swr commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

In the direct DXIL backend (#1426), v_cvt_f16_f32, v_mul_f16 and v_pk_mul_f16 went through Lw::to_f16, which without a program-set MODE[3:2] emits dx.op.legacyF32ToF16 and rounds toward zero. RDNA2 and the HLSL backend (to_f16_rounded_expr, #166) round these to nearest-even by default. On main the RX 7800 XT gives 3075.0 -> 0x6A01 (want 0x6A02), -3075.0 -> 0xEA01, 65520.0 -> 0x7BFF (want +inf), and the smallest denormal is lost. This adds Lw::to_f16_rounded, the counterpart of to_f16_rounded_expr, and uses it for those three instructions. Part of #1269.

This is @itsSio's released patch (7452171, posted on #1269 at 18:37 UTC, "If someone picks it up, we will not submit a competing PR"), rebased onto current main, with the test widened to split wave64 and an extra denormal product lane. itsSio is credited as co-author. With this in, the V_CVT_F16_F32 / V_MUL_F16 / V_PK_MUL_F16 entries on DIFFERS_ON_1426 in gefydev's direct-on-1426 branch can be dropped.

What is in it

  • crates/xcl/src/gpu/dxil/prelude.rs: Lw::to_f16_rounded (RNE, or VAR_FP16_RM when the program sets a mode); to_f16's dynamic-mode branch calls it.
  • crates/xcl/src/gpu/dxil/lower_valu.rs, lower_wide.rs: v_cvt_f16_f32, v_mul_f16 and v_pk_mul_f16 use it. v_mad_f16's product already rounded this way inline and now calls it (no output change). Other f16 ops keep to_f16, as in the HLSL backend.
  • crates/xcl/src/gpu/dxil/core_tests.rs: f16_conversions_and_products_default_to_round_to_nearest_even. It checks that no legacyF32ToF16 is emitted and runs the three instructions on the GPU in wave32, split wave64 and native wave64 (midpoints, sign, overflow to inf, denormals).

Tested

  • AMD Radeon RX 7800 XT, driver 32.0.31035.1003 (wave32 and native wave64); Ryzen 7 5700X3D; Windows 11 Pro build 26200; Rust 1.100.0 MSVC; debug.
  • New test on main 85e3826 with only the test added: 0 passed / 1 failed (legacyF32ToF16 in the disassembly). With that check taken out, the GPU result also fails: wave32 base 0: v_cvt_f16_f32 [6a01, 6a01, 6a01, 6a04, ea01, 7bff, 0000, 0000] != [6a01, 6a02, 6a02, 6a04, ea02, 7c00, 0000, 0001].
  • Rebased head 18423c3, debug. cargo build --workspace succeeded on base and head. cargo test -p xcl --lib f16_conversions_and_products_default_to_round_to_nearest_even -- --nocapture passed on the GPU (1 passed, 0 failed, 0 ignored, 0 skipped).
  • cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture on head: 1111 passed, 1 failed, 46 ignored. Seven reported skips within passing tests: six refused per-lane f16 multiply, packed multiply and f32 conversion cases across wave32/64, and one unavailable heap-window case. Sample variables were unset.
  • The sole failure, gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, also fails on base 3da2abb with cargo test -p xcl --lib gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 -- --exact --nocapture (0 passed, 1 failed). Both report seed 722, GPU 0x1 against CPU 0x7fffffff.
  • cargo clippy --workspace --all-targets fails on three existing approx_constant diagnostics for TAU literals in DXIL and recompiler lowering. All three literals are present on the base.

Regression run

xcl-smoke v1
commit: 3da2abb81606df622610e009f0430de99aa9881c
gpu: AMD Radeon RX 7800 XT
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 739 (PresentX 739)
presents per 2 s (last 3): 36 2 19
device removals: 0
crashes: 0
peak commit: 15676 MB
xcl-smoke v1
commit: 18423c3ca988bdd0e546130f5010df3428a5e890
gpu: AMD Radeon RX 7800 XT
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 834 (PresentX 834)
presents per 2 s (last 3): 2 29 60
device removals: 0
crashes: 0
peak commit: 15543 MB

Not tested

  • The smoke runs use the default runtime path. The direct DXIL backend is opt-in (XCL_DIRECT_DXIL=1), so the title runs do not reach the changed lowering. They are a regression check only.
  • NVIDIA, Intel, RDNA4, release builds, programs that set MODE[3:2] through the direct backend (that path is unchanged).

AI use

  • T3 Code through Antigravity, Gemini 4 Neon: rebased itsSio's patch, extended the GPU test, ran the first builds.

  • Claude Code, Claude Opus 5.5: rebased onto current main, checked the test fails on main, ran the full suite and the smoke pair, and wrote the commit message and this description.

  • T3 Code through Codex, gpt-6.2-astra: rebased onto 3da2abb, retained both GPU tests at the conflict, verified the builds, GPU suite and smoke pair, and updated this report. Current main hashes the DXIL source for cache invalidation.

🤖 Generated with Claude Code

@fromthemoonx

fromthemoonx commented Nov 24, 2026 •

Copy link
Copy Markdown

Rerun on the new head 18423c3 (on main 3da2abb): still passes on NVIDIA (RTX 3060). But the rebase dropped the TRANSLATOR_VERSION bump. kernel.rs:41 is still 8, the same as on main. This PR changes the containers that version 8 emits, so caches built by current main under XCL_DIRECT_DXIL would keep the old toward-zero f16 converts. It needs 9; #1973's new head aaf2c78 also takes 9, so whichever merges second needs 10.

  • cargo build --workspace + cargo test --workspace --no-fail-fast -- --test-threads=4 at 18423c3, which is already on current main: 1112 passed, 0 failed, 46 ignored (24 SKIPPED: no wave64, the per-lane refusals, no heap windows; the same as on main).
  • f16_conversions_and_products_default_to_round_to_nearest_even: 10 of 10 passed.
  • The same RTX 3060 (driver 610.88), DXC 1.9.2602.17, debug. The report below is for 13d1944.

Rerun on the rebased head 13d1944: still passes on NVIDIA (RTX 3060), also merged onto current main.

  • Exact head 13d194404283a87324748fc8d3a0a34385de556f (base 689f2db): cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: 976 passed, 0 failed, 45 ignored
  • Merged onto current main 20cf130 (no conflict): 977 passed, 0 failed, 45 ignored
  • f16_conversions_and_products_default_to_round_to_nearest_even: runs on the GPU here, 10 of 10 passed
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- --test-threads=1 gpu::dxil (merged tree): 102 passed, 0 failed, 3 ignored
  • SKIPPED in both full runs: 21 no wave64 / per-lane refusals in gpu::recomp, and heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows. Same machine and toolchain as below. The old-lowering check was not repeated.

Passes on NVIDIA, and on this card the old lowering rounds toward zero just as you describe.

Tested

  • NVIDIA GeForce RTX 3060 12 GB (32-lane waves only: the test's wave32 and split-wave64 runs, no native wave64), driver 32.0.16.1088; AMD Ryzen 7 5700X; native Windows 11 Pro 26H2 (build 26300.9974); rustc 1.100.0 stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug
  • Exact head 35355a282bf85511a4279d515584cb8ffabb04ad (base 85e3826): cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: 876 passed, 0 failed, 42 ignored
  • Merged onto current main b9b6ea6 (no conflict): 890 passed, 0 failed, 42 ignored
  • f16_conversions_and_products_default_to_round_to_nearest_even runs on the GPU here (no skip). 10 runs: 10 of 10 passed.
  • Old lowering, GPU results only: with kernel.rs, lower_valu.rs, lower_wide.rs and prelude.rs as on 85e3826, and only the disassembly assert taken out of the new test, the wave32 run gives v_cvt_f16_f32 [6a01, 6a01, 6a01, 6a04, ea01, 7bff, 0000, 0000] instead of [6a01, 6a02, 6a02, 6a04, ea02, 7c00, 0000, 0001]. So NVIDIA's legacyF32ToF16 truncates the midpoint, clamps 65520 to 7bff instead of +inf, and flushes the smallest denormal, the same as on your AMD card.
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- --test-threads=1 gpu::dxil: 81 passed, 0 failed, 1 ignored

Not tested

  • Native wave64 (none here); release build; a title with XCL_DIRECT_DXIL=1.

AI use

  • Claude Code (Claude Opus 5.5) ran the builds and tests on the machine above, including the old-lowering check, and wrote this report from the output.

@alexmircea1299

Copy link
Copy Markdown

Test report on NVIDIA GeForce RTX 5070 (12 GB)

  • PR / Commit: Recompiler: round direct-DXIL f16 converts and products to nearest-even #1742 (35355a2)
  • Hardware: AMD Ryzen 5 9600X, NVIDIA GeForce RTX 5070 (12 GB VRAM, driver 621.35), 32 GB DDR5 6000MT/s
  • Environment: Windows 11 (build 26300), rustc 1.100.0 (0ef1bc386 2026-11-09), Windows SDK 10.0.26100.0 (debug build)
  • Command: .\scripts\test.ps1 (cargo test --workspace -- --test-threads=4)
  • Results:
    • xcl --lib: 827 passed; 0 failed; 22 ignored (15.12s)
    • Integration tests: 8 passed; 0 failed; 12 ignored (1 + 1 + 6)
    • Total workspace: 835 passed; 0 failed; 34 ignored
  • GPU tests skipped on this adapter:
    • 2 (no wave64)
    • 1 (no heap windows)
    • 1 (cannot disable the driver cache (Windows Developer Mode is required): The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D))
  • Not tested: Retail title (smoke.ps1), native wave64 / AMD GPUs, release build.
  • AI use: Google Gemini assisted with running the commands and drafting this report from my real local test run.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

@oni-swr
oni-swr force-pushed the dxil/f16-default-rne branch from 35355a2 to 13d1944 Compare November 24, 2026 22:56
@oni-swr

oni-swr commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main 689f2db as 13d1944, for @DavidM1911's test run.

  • Conflicts: kernel.rs: upstream had already raised TRANSLATOR_VERSION to 7, so this PR now raises it to 8. core_tests.rs: upstream added two tests where this PR's test was; I kept both, with the PR's test after them, unchanged. The other three files merged cleanly. Diff: 5 files, +108 / −12.
  • Regression test: fails without the fix ("default RNE f16 ops should not emit legacyF32ToF16") and passes with it, on WARP (disassembly check; the wave32/wave64 GPU lanes skip on WARP).
  • cargo test --workspace --locked (XCL_ADAPTER=warp): 908 passed, 1 failed, 26 ignored. The failure is test_title_draws_with_a_root_signature_under_the_debug_layer: XCL refuses the test title on WARP ("waves of 4–4 lanes"), and it fails the same way on unmodified 689f2db.

AI use: Claude Code (Claude Opus 5.5) did the rebase, ran the tests and wrote this comment.

@JJAutoCompare

Copy link
Copy Markdown

Tested

Intel Arc A770 passed the checked-in direct-DXIL FP16 nearest-even test on clean PR head 6d2b3a7588de12153406c7408f00a70e88c10d5d. Hardware and tools were Arc A770 driver 32.0.101.9175, Ryzen 7 3800X, Windows 11 Enterprise Evaluation build 26200.9974, Rust 1.100.0 x86_64-pc-windows-msvc, and the unoptimized test profile with debug info disabled. The test process logged dxcompiler and dxil 1.9.2609.5.

cargo test -p xcl --lib --locked --no-run
$env:XCL_ADAPTER = 'A770'
$env:XCL_DXC_DIR = "$env:LOCALAPPDATA\XclTooling\dxc-1.9.2609\bin\x64"
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test {
    & 'L:/XclTooling/CapabilityProbe/capabilities.exe'
    & 'L:\XclTooling\pr1512-tiling-edges-fddfa267\target\debug\build\xcl\97fdf2b9ff8e1482\out\xcl-97fdf2b9ff8e1482.exe' 'gpu::dxil::core_tests::f16_conversions_and_products_default_to_round_to_nearest_even' --exact --nocapture --test-threads=1
}

The prebuild ran outside the Arc lock with two Cargo jobs, CARGO_INCREMENTAL=0, CARGO_PROFILE_DEV_DEBUG=0, and CARGO_PROFILE_TEST_DEBUG=0. The lock wrapper ran with process-scoped PowerShell execution policy Bypass after the default policy blocked the initial invocation before any tests ran.

  • 1 passed, 0 failed, 0 ignored, 0 explicit skips, 1063 filtered out. Test exit 0.
  • D3D12 reported a wave-lane range of 8–32 on the Arc A770. The test executed wave32 and split-wave64, asserting lanes 0–7 and 32–39 in the two split-wave64 halves. The native-wave64 branch was gated out without a SKIPPED line.
  • In both executed modes, all conversion, scalar multiply, and packed multiply assertions matched. Midpoint and adjacent conversions rounded as expected, the negative midpoint preserved sign, 65520 converted to positive infinity (0x7c00), and the conversion at half the smallest denormal rounded to zero while the next input rounded to 0x0001. Packed products matched the positive and negative midpoint and smallest-denormal encodings.

Not tested

Native wave64, the HLSL backend, old lowering on Arc, other GPUs, the full workspace suite, and retail-title smoke runs.

AI use

Codex in T3 Code (gpt-6.2-sol) ran the test, verified the checkout and output, and wrote the report.

The HLSL backend rounds v_cvt_f16_f32, v_mul_f16 and v_pk_mul_f16 with
to_f16_rounded_expr: round-to-nearest-even in the default mode, the
program's MODE[3:2] when it sets one (xcl-dev#166). The direct DXIL backend
used to_f16 for them, which without a dynamic mode is
dx.op.legacyF32ToF16, rounding toward zero: 3075.0 became 0x6A01
instead of 0x6A02, 65520.0 stayed finite and products just above half
the smallest denormal flushed to 0.

Add Lw::to_f16_rounded (the counterpart of to_f16_rounded_expr) and
use it for the three instructions; v_mad_f16's product, which already
rounded this way inline, calls it too. The GPU test runs
the three instructions in wave32, split wave64 and native wave64.

Based on itsSio's released patch (7452171, on xcl-dev#1269).

Co-authored-by: itsSio <31954644+itsSio@users.noreply.github.com>
Assisted-by: T3 Code through Antigravity (Gemini 4 Neon)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@raylitebull

Copy link
Copy Markdown
Member

Verified on current \18423c3: both \PR description\ and \Build and test (Windows, no GPU)\ are green, and the head has dual-vendor coverage across AMD RX 7800 XT (RDNA3, native wave64 + paired smoke) and NVIDIA RTX 3060 (1112/0/46, 10/10 on \ 16_conversions_and_products_default_to_round_to_nearest_even), plus Intel Arc A770 on the pre-rebase commit.\n\nRe: the \TRANSLATOR_VERSION\ note above — #1947\ is merged on \main\ (\�uild.rs\ computes \XCL_DIRECT_DXIL_SOURCE_ID\ over all \gpu/dxil\ sources into \pso::direct_version, documented in \kernel.rs:39), so edits to \gpu/dxil/*\ no longer need a manual bump.

@raylitebull
raylitebull merged commit c2dcef3 into xcl-dev:main Nov 25, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants