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.
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.