Recompiler: round direct-DXIL f16 converts and products to nearest-even #1742
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!1742
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1742/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@oni-swr on GitHub · 2026-11-24 20:07 UTC · original
oni-swr:dxil/f16-default-rne→main· +107 −11 · 4 files · 1 commits · merged 2026-11-25 02:00 UTCIn the direct DXIL backend (#1426),
v_cvt_f16_f32,v_mul_f16andv_pk_mul_f16went throughLw::to_f16, which without a program-setMODE[3:2]emitsdx.op.legacyF32ToF16and 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 gives3075.0 -> 0x6A01(want0x6A02),-3075.0 -> 0xEA01,65520.0 -> 0x7BFF(want+inf), and the smallest denormal is lost. This addsLw::to_f16_rounded, the counterpart ofto_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, theV_CVT_F16_F32/V_MUL_F16/V_PK_MUL_F16entries onDIFFERS_ON_1426in gefydev'sdirect-on-1426branch can be dropped.What is in it
crates/xcl/src/gpu/dxil/prelude.rs:Lw::to_f16_rounded(RNE, orVAR_FP16_RMwhen 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_f16andv_pk_mul_f16use it.v_mad_f16's product already rounded this way inline and now calls it (no output change). Other f16 ops keepto_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 nolegacyF32ToF16is emitted and runs the three instructions on the GPU in wave32, split wave64 and native wave64 (midpoints, sign, overflow to inf, denormals).Tested
85e3826with only the test added: 0 passed / 1 failed (legacyF32ToF16in 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].18423c3, debug.cargo build --workspacesucceeded on base and head.cargo test -p xcl --lib f16_conversions_and_products_default_to_round_to_nearest_even -- --nocapturepassed on the GPU (1 passed, 0 failed, 0 ignored, 0 skipped).cargo test --workspace --no-fail-fast -- --test-threads=4 --nocaptureon 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.gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, also fails on base3da2abbwithcargo test -p xcl --lib gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 -- --exact --nocapture(0 passed, 1 failed). Both report seed 722, GPU0x1against CPU0x7fffffff.cargo clippy --workspace --all-targetsfails on three existingapprox_constantdiagnostics for TAU literals in DXIL and recompiler lowering. All three literals are present on the base.Regression run
Not tested
XCL_DIRECT_DXIL=1), so the title runs do not reach the changed lowering. They are a regression check only.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
@FIJI1299 on GitHub · 2026-11-24 21:03 UTC · original
Test report on NVIDIA GeForce RTX 5070 (12 GB)
35355a2)621.35), 32 GB DDR5 6000MT/s26300),rustc 1.100.0 (0ef1bc386 2026-11-09), Windows SDK10.0.26100.0(debug build).\scripts\test.ps1(cargo test --workspace -- --test-threads=4)xcl --lib:827 passed; 0 failed; 22 ignored(15.12s)8 passed; 0 failed; 12 ignored(1 + 1 + 6)835 passed; 0 failed; 34 ignored2 (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))smoke.ps1), native wave64 / AMD GPUs, release build.@DavidM1911 on GitHub · 2026-11-24 22:43 UTC · original
Verification on RTX 3060 Ti (Windows 11): merge conflict with current
main— needs a rebase before it can be tested.@oni-swr on GitHub · 2026-11-24 23:08 UTC · original
Rebased onto
main689f2dbas13d1944, for @DavidM1911's test run.kernel.rs: upstream had already raisedTRANSLATOR_VERSIONto 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.cargo test --workspace --locked(XCL_ADAPTER=warp): 908 passed, 1 failed, 26 ignored. The failure istest_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 unmodified689f2db.AI use: Claude Code (Claude Opus 5.5) did the rebase, ran the tests and wrote this comment.
@JJAutoCompare on GitHub · 2026-11-25 01:35 UTC · original
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.The prebuild ran outside the Arc lock with two Cargo jobs,
CARGO_INCREMENTAL=0,CARGO_PROFILE_DEV_DEBUG=0, andCARGO_PROFILE_TEST_DEBUG=0. The lock wrapper ran with process-scoped PowerShell execution policyBypassafter the default policy blocked the initial invocation before any tests ran.SKIPPEDline.0x7c00), and the conversion at half the smallest denormal rounded to zero while the next input rounded to0x0001. 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.@fromthemoonx on GitHub · 2026-11-24 20:39 UTC · original · edited 2026-11-25 01:47 UTC
Rerun on the new head
18423c3(on main3da2abb): still passes on NVIDIA (RTX 3060). But the rebase dropped theTRANSLATOR_VERSIONbump.kernel.rs:41is still8, the same as onmain. This PR changes the containers that version 8 emits, so caches built by currentmainunderXCL_DIRECT_DXILwould keep the old toward-zero f16 converts. It needs9; #1973's new headaaf2c78also takes9, so whichever merges second needs10.cargo build --workspace+cargo test --workspace --no-fail-fast -- --test-threads=4at18423c3, which is already on currentmain: 1112 passed, 0 failed, 46 ignored (24 SKIPPED: no wave64, the per-lane refusals, no heap windows; the same as onmain).f16_conversions_and_products_default_to_round_to_nearest_even: 10 of 10 passed.13d1944.Rerun on the rebased head
13d1944: still passes on NVIDIA (RTX 3060), also merged onto currentmain.13d194404283a87324748fc8d3a0a34385de556f(base689f2db):cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4: 976 passed, 0 failed, 45 ignoredmain20cf130(no conflict): 977 passed, 0 failed, 45 ignoredf16_conversions_and_products_default_to_round_to_nearest_even: runs on the GPU here, 10 of 10 passedXCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- --test-threads=1 gpu::dxil(merged tree): 102 passed, 0 failed, 3 ignoredno wave64/ per-lane refusals ingpu::recomp, andheap_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
stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug35355a282bf85511a4279d515584cb8ffabb04ad(base85e3826):cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4: 876 passed, 0 failed, 42 ignoredmainb9b6ea6(no conflict): 890 passed, 0 failed, 42 ignoredf16_conversions_and_products_default_to_round_to_nearest_evenruns on the GPU here (no skip). 10 runs: 10 of 10 passed.kernel.rs,lower_valu.rs,lower_wide.rsandprelude.rsas on85e3826, and only the disassembly assert taken out of the new test, the wave32 run givesv_cvt_f16_f32 [6a01, 6a01, 6a01, 6a04, ea01, 7bff, 0000, 0000]instead of[6a01, 6a02, 6a02, 6a04, ea02, 7c00, 0000, 0001]. So NVIDIA'slegacyF32ToF16truncates the midpoint, clamps 65520 to7bffinstead 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 ignoredNot tested
XCL_DIRECT_DXIL=1.AI use
@raylitebull on GitHub · 2026-11-25 01:59 UTC · original
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.@DavidM1911 on GitHub · 2026-11-26 00:29 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