Recompiler: fold finite constant legacyF16ToF32 conversions in direct DXIL #2552
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!2552
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2552"
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?
@ramon-victor on GitHub · 2026-11-25 22:43 UTC · original
ramon-victor:opt/dxil-const-f16-to-f32→main· +163 −1 · 2 files · 1 commits · openPart of #1269.
Problem
RDNA2 mixed-precision and half-conversion instructions (
v_fma_mix_f32,v_fma_mixlo_f16,v_fma_mixhi_f16,v_cvt_f32_f16, packed f16 helpers) frequently convert inline or constant-folded 16-bit half operands tof32viaShader::f16_to_f32(dx.op.legacyF16ToF32). Even afteropt.rsfolds the precedingand 0xFFFF/lshr 16extraction to a constant integer,dx.op.legacyF16ToF32was left as an intrinsic call and was also absent fromopt::removable, preventing constant folding and dead-code elimination.Fix
f16_bits_to_f32_bits(h: u16) -> Option<u32>incrates/xcl/src/gpu/dxil/ops.rs, performing exact IEEE-754 binary16 → binary32 conversion for all finite values (±0.0, all subnormals, all normals) while returningNonefor±InfandNaNso DXIL never materializes non-finite float constants.Shader::f16_to_f32(ops.rs) and post-SSA/constant-propagationdx.op.legacyF16ToF32calls inModule::simplify_op(module/opt.rs).dx.op.legacyF16ToF32calls inModule::removable(module/opt.rs);legacyF16ToF32isReadNone, uses no 64-bit types, and sets no DXIL shader feature flags.ops::f16_fold_testscovering all 65,536 half bit patterns, finite direct & shift/mask-folded constants (verifying zero remaininglegacyF16ToF32), non-finite preservation, and bit-exact RTX 3070 GPU parity with hardwaredx.op.legacyF16ToF32.Measured impact
573-program retail direct-DXIL validation sweep (
dxil.dll1.8.2502.11):6d12f58):573/573validated (val_fail=0),51,117,488total DXIL bytes (p50=22,865 us,p95=408,132 us).84f6bdc):573/573validated (val_fail=0),51,074,004total DXIL bytes (-43,484 B/-0.085%;p50=19,788 us,p95=389,471 us).Tested
cargo test --lib -p xcl f16_fold): 2 passed, 0 failed (f16_bits_to_f32_bits_exhaustive,f16_to_f32_constant_folding_validates_and_matches_gpu)..\scripts\test.ps1, NVIDIA GeForce RTX 3070, Windows 11):1425 passed, 0 failed, 46 ignored.dxil.dllvalidation sweep:573/573passed,0failures.cargo build --release -p xcl) and 60 s retail smoke run (see below).Not tested
Regression run
Main (
f087b99):This PR (
84f6bdc):AI use
@DavidM1911 on GitHub · 2026-11-25 23:06 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 26 ignored.Thanks!
— Devin
@DarkPanda69 on GitHub · 2026-11-25 23:11 UTC · original
Wave64 run (listed as untested; the wave64 GPU tests skipped on the RTX 3070) on an AMD RX 9070 XT, plus an RTX 3060: both new tests pass, and nothing else changes in the direct-DXIL GPU suite.
Head
84f6bdcapplied onmaine1d84b7, debug, Windows 11 Pro 26200,XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4onmainand with the PR, card chosen withXCL_ADAPTER:mainOn both cards, the only result changes against
mainare the newf16_bits_to_f32_bits_exhaustiveandf16_to_f32_constant_folding_validates_and_matches_gpu, both ok, with no new skips. So the wave64 tests that skip on a 32-lane GPU ran over the new folding here and still pass. The 2 RX 9070 XT failures are the AMD fuzz seeds tracked in #2115, the same onmain.Not tested: Intel, a title.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
@emirduran707 on GitHub · 2026-11-25 23:17 UTC · original
Independent AMD RDNA4 (native wave64) verification of exact PR head
84f6bdc97a46acac6b875e4419facfcd23e650ddon Windows 11 Pro 26300 (AMD Radeon RX 9060 XT 16 GB, driver32.0.31044.16, Ryzen 5 5600, Rust 1.100.0 MSVC, DXC1.9.2602.17).Tested
cargo build --workspace(debug): passed (0errors).cargo test --workspace --no-fail-fast -- --test-threads=4:1423 passed, 2 failed, 46 ignored(8 SKIPPED: 6 per-lane DXIL forms refused by host adapter/driver, 1heap_window_out_of_memory_falls_back_to_the_switch_formno heap windows, 1pso_measurement_compiles_an_exact_synthetic_recordWindows Developer Mode off).gpu::dxil::ops::f16_fold_tests::f16_bits_to_f32_bits_exhaustivegpu::dxil::ops::f16_fold_tests::f16_to_f32_constant_folding_validates_and_matches_gpugpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1andfuzz_validate_and_gpu_3) are pre-existing on unmodifiedmainon this RX 9060 XT / driver32.0.31044.16.cargo build --release -p xcl+ 60 s retail-title smoke test (scripts/smoke.ps1, offline):(Compare against
main68a284aon this machine:1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)Not tested
AI use
@SlopTart on GitHub · 2026-11-25 23:41 UTC · original
Tested: current PR head merged onto current
origin/main(clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo targetx86_64-pc-windows-gnurun under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).gpu_suite (cold cache): 165 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR. This PR does not change the mad/mac red on RADV.Targeted run of
f16_bits_to_f32_bits_exhaustive(all 65536 f16 patterns) andf16_to_f32_constant_folding_validates_and_matches_gpu: 2 passed; the..._matches_gpuname sits outside thegpu_filter, so it ran targeted.Not tested: retail titles (no title data on this lane, counts only).
AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.
@Decodere on GitHub · 2026-11-27 01:58 UTC · original
Independent desktop NVIDIA (Wave32-only Ada) verification of PR #2552 at head
84f6bdc97a46acac6b875e4419facfcd23e650dd(1commit; exact parent & merge-base:e1d84b7d9153f86a97d2ec5d209d196046fc0bea, pre-#2555ancestor ofmain).Environment
7956 MiBreported by D3D12, Wave32-only Ada), driver32.0.16.2114(NVIDIA621.14, WDDM 3.2)31.9 GiBusable), Windows 11 Home26200(Developer Mode off)rustc 1.100.0 (0ef1bc386 2026-11-09)MSVC, DXC1.9.2609.5,--releaseTargeted release tests & build (
84f6bdc9)cargo test --release -p xcl --lib f16_bits_to_f32_bits_exhaustive -- --nocapture(3 consecutive runs)1 passed; 0 failed; 0 ignored; 1325 filtered out× 3 (0.00s× 3,0skipped)cargo test --release -p xcl --lib f16_to_f32_constant_folding_validates_and_matches_gpu -- --nocapture(3 consecutive runs)1 passed; 0 failed; 0 ignored; 1325 filtered out× 3 (0.22s,0.18s,0.20s,0skipped — live Wave32 GPU parity on RTX 4060)cargo test --release -p xcl --lib gpu::dxil:: -- --test-threads=4(3 consecutive runs)185 passed; 0 failed; 3 ignored; 1138 filtered out× 3 (3.95s,3.63s,3.61s;184executed +1expected Wave32-only skipdispatch_chain_native_wave64_builds_whole: no wave64)cargo build --release -p xcl1m 12s, exit0,0new warnings)Paired quiet 60 s retail smoke (
title: 29640639)Exact parent & merge-base (
e1d84b7d9153f86a97d2ec5d209d196046fc0bea, cached baseline on the same machine):PR #2552 (
84f6bdc97a46acac6b875e4419facfcd23e650dd):Runtime log observations (
xcl.log)9222log lines,0[ERROR]/ device-removal / panic lines.19531 draws with translated pipelines (0 skipped, 0 with PC pipelines), 1024 dispatches (0 skipped); last memory sample14013 MB committed by the process; video memory 6114 MB local, 4682 MB non-local.Limits of coverage
f16_bits_to_f32_bits_exhaustive) and direct-DXILlegacyF16ToF32constant folding were verified end-to-end on desktop Wave32-only NVIDIA RTX 4060 (f16_to_f32_constant_folding_validates_and_matches_gpu× 3,0skipped, plusgpu::dxil::184executed +1expectedno wave64skip × 3).title: 29640639confirms zero runtime regression rather than re-compiling a coldXCL_DIRECT_DXIL=1shader set (frame-count and commit deltas vs. cached parent reflect single-run startup variance, not this PR).AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
@SzczepanGrela on GitHub · 2026-11-27 04:23 UTC · original
RX 9070 / RADV / Wine verification of exact head
84f6bdc97a46acac6b875e4419facfcd23e650dd, current main8b957bec6f82495aec940944c6bf47faa02db590and the PR applied to that main. This adds direct native-wave64 coverage of finite constant folding and exhaustive dynamic half conversion on this lane.Tested
26.3.1-arch3.5, Ryzen 7 7700, CachyOS7.3.0-5-cachyos. Windows GNU release executables, Rust1.97.1, GE-Proton11-12 / Wine 11.0 Staging, native DXGI/D3D12 through vkd3d-proton8293130ebe370b1+(local asserts-disabled build), DXC/DXIL1.9.2602.17.cfg(test)solely to compile the identical upstream CPU oracle/tests; its production Shader and Module logic remain unchanged.cargo test --offline --locked --release --target x86_64-pc-windows-gnu -p xcl --lib --no-run --message-format=json-render-diagnostics.<unit.exe> f16_fold_tests --nocapture --test-threads=1, then--test-threads=4.Main fails the finite-constant IR assertion before that original test dispatches. Head/integration remove the finite calls and preserve all four dynamic/non-finite calls in the second original shader. Full captured readbacks, including unmodified slots and all active lanes, were independently checked. The helper's original exhaustive CPU test covers all 65,536 half bit patterns.
Additional owned filter
<unit.exe> workflow_half_conversion_matrix --nocapture --test-threads=1, three fresh processes per source: 1 passed, 0 failed in all nine runs. Each process has 64 dispatches, half native wave32 and half native wave64:Across both groups: 584 captured GPU dispatches, including 288 native wave64, and 2,934,784 output/guard words. Python's independent IEEE-half decoder verifies finite/infinite outputs bit-for-bit and NaNs by class; untouched slots, guards and physical widths also match. Matrix payloads repeat byte-for-byte within each source and across source arms, including NaN payloads. Exact head and integration captures match. 0 ignored, 0 skipped.
Inherited
XCL_*cleared;XCL_NETWORK=0, RX 9070 selected,XCL_REQUIRE_GPU=wave64,XCL_DXC_THREADS=1; private enabled caches per process.Not tested
Full suite, HLSL backend, whole RDNA2 mixed/packed-f16 instructions, guest Compute ABI integration, native Windows, other GPUs, retail workload,
scripts/smoke.ps1, timing or FPS. The additional shaders exercise the direct DXIL builder and optimizer.AI use
OpenAI Codex (GPT-6; exact serving variant not exposed) reviewed the diff, wrote the owned test-only matrix and captures, ran comparisons, independently verified IEEE conversion results, NaN classes, guards, wave widths and source/executable provenance, and drafted this report. Publication authorized by the account owner.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.