Repository navigation
Recompiler: guard and scale direct DXIL v_rcp_f64 and v_rsq_f64 - #2063
Conversation
Direct DXIL lowering of v_rcp_f64 and v_rsq_f64 emitted raw unguarded double division (1.0 / a and 1.0 / sqrt_d(a)), unlike the HLSL path's rcp_d helper (xcl-dev#530). Drivers may return 0 for 1/NaN (e.g. v_rsq_f64 of negative numbers) or flush subnormal reciprocals such as 1/DBL_MAX to 0. Add Lw::rcp_d in crates/xcl/src/gpu/dxil/lower_wide.rs handling NaN (preserving payload), ±0 -> ±inf, and ±inf -> ±0 explicitly, substituting 1.0 into the eager divide path for special inputs, and scaling finite operands into [0.5, 1) via frexp_exp_d and ldexp_d around ddiv(1.0, scaled) before rescaling back with ldexp_d. Wire both v_rcp_f64 and v_rsq_f64 through Lw::rcp_d and add DXIL validation/disassembly and wave32 GPU edge regression tests. Part of xcl-dev#1269 Assisted-by: Google Antigravity (Gemini 4 Neon)
PR #2063 CPU/DXC verificationTestedPR #2063 was open at Windows 11 Enterprise Evaluation 26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175, rustc and Cargo 1.100.0 (x86_64-pc-windows-msvc), unoptimized test profile with debug info disabled. The test logged dxcompiler 1.9.2609.5 (01b62ad4) and dxil 1.9.2609.5 loaded from the explicit DXC directory. $env:TEMP = 'L:/XclTooling/pr2063'
$env:TMP = 'L:/XclTooling/pr2063'
$env:CARGO_TARGET_DIR = 'L:/XclTooling/pr1947-1831ec4-t3-97236edf/target'
$env:CARGO_BUILD_JOBS = '2'
$env:CARGO_INCREMENTAL = '0'
$env:CARGO_PROFILE_DEV_DEBUG = '0'
$env:CARGO_PROFILE_TEST_DEBUG = '0'
$env:XCL_ADAPTER = 'A770'
$env:XCL_DXC_DIR = Join-Path $env:LOCALAPPDATA 'XclTooling/dxc-1.9.2609/bin/x64'
$env:PATH = (Join-Path $env:USERPROFILE '.cargo/bin') + ';' + $env:PATH
cargo test -p xcl --lib --jobs 2 gpu::dxil::lower_wide::rcp_d_tests::v_rcp_f64_and_v_rsq_f64_use_guarded_scaled_rcp_d -- --exact --nocaptureResult: 1 passed, 0 failed, 0 ignored, 0 skipped, 0 measured, 1,125 filtered out. Exit code 0. Cargo reported 1m 00s to finish the build and the harness reported 0.03s for the test. Wall time including build and test was 64.691s. The fixture assembled separate
Not testedGPU dispatch, shader FP64 execution, numerical accuracy, and per-input behavior including signed zero, infinities, NaNs, and subnormals. This Arc has no shader FP64 support. The checked test covers DXIL structure and DXC acceptance. The separate GPU edge-case test, HLSL backend, workspace suite, and title smoke tests were outside this run. AI useT3 Code / Codex (gpt-6.2-sol) verified the PR head, ran the checked-in test, and recorded the result. |
|
A run with vkd3d-proton as the host D3D12. The DXIL goes through dxil-spirv and then the NVIDIA Vulkan driver, a different compiler from a native-Windows run: this PR's 2 new tests pass. Tested
Not tested
AI use
|
|
Native-wave64 AMD run on Windows, which this PR lists as not tested (#530's Tested: pass, head
Not tested: RDNA2/3, RADV. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report. |
|
NVIDIA RTX 3070 on native Windows, head Tested
Regression run ( PR head That is 100 % of Not tested
AI use
|
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
|
Linux/RADV run, the configuration this PR's tester list is missing. Tested (RX 7900 XT, RDNA3, RADV NAVI31, Mesa 26.2.5, Proton Experimental wine-11.0, DXC 1.9.2609.5, release build, tests under wine,
The before/after on this stack is direct. On Not tested: split-wave64 mode, other Mesa versions, native Linux (non-wine) runs. Counts only, no game data. AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting. |
What is in it
Bring Direct DXIL
v_rcp_f64andv_rsq_f64into parity with the HLSL path'srcp_dhelper (merged in #530).Part of #1269
crates/xcl/src/gpu/dxil/lower_wide.rs, Direct DXIL lowering ofv_rcp_f64andv_rsq_f64still emitted raw unguardedddiv(1.0, a)/ddiv(1.0, sqrt_d(a)). As documented in Recompiler: v_rcp_f64 and v_rsq_f64 keep NaN, infinities and denormals #530, drivers can return0for1/NaN(for examplev_rsq_f64on negative inputs) or flush subnormal reciprocals such as1/f64::MAXto0.Lw::rcp_dincrates/xcl/src/gpu/dxil/lower_wide.rsand wire bothv_rcp_f64(self.rcp_d(a)) andv_rsq_f64(self.rcp_d(self.sqrt_d(a))) through it:NaN(preserving the input bits),±0.0 -> ±inf, and±inf -> ±0.0explicitly usingisnan_d,isinf_d,fcmp(Pred::FOEq, x, 0.0), andmkdwith the input sign bit.1.0into the eager division path (safe_x = sel(special, 1.0, x)) so special operands never reachddiv.[0.5, 1)viae = frexp_exp_d(safe_x)andscaled = ldexp_d(safe_x, -e), computer = ddiv(1.0, scaled), and rescale back withldexp_d(r, -e)so subnormal reciprocals are preserved.rcp_d_testsat the end ofcrates/xcl/src/gpu/dxil/lower_wide.rs:v_rcp_f64_and_v_rsq_f64_use_guarded_scaled_rcp_d: validates bothv_rcp_f64andv_rsq_f64(wave32 and wave64) withdxil.dlland checks the DXIL disassembly for the zero guard,frexp_exp_dscaling, and post-divisionldexp_d/ select guards.gpu_direct_rcp_f64_and_rsq_f64_edges: unconditional wave32 Direct DXIL GPU test across 32 edge inputs (±0.0,±inf,±qNaNwith payload, negative values,±f64::MAX,±f64::MIN_POSITIVE, smallest/largest±denormals, and normal floats), verifying exact±inf/±0signs, NaN payload preservation forv_rcp_f64,NaNforv_rsq_f64(-x),<= 1 ULPforv_rcp_f64, and<= 2 ULPforv_rsq_f64.Tested
621.14, wave32), Intel Core i5-11400F, 32 GB RAM, Windows 11 Home build 26200, Rust1.100.0(stable-x86_64-pc-windows-msvc), DXC1.9.2609.5(01b62ad4).origin/main5ce558fwith new test added, debug):cargo test -p xcl --lib gpu::dxil::lower_wide::rcp_d_tests::v_rcp_f64_and_v_rsq_f64_use_guarded_scaled_rcp_d -- --nocapture->0 passed; 1 failed(panicked:v_rcp_f64 must guard ±0 before dividingbecause unfixed Direct DXIL emitted barefdiv double 1.000000e+00, ...with nofcmp oeq doubleor scaling).4510bf84):cargo test --release -p xcl --lib gpu::dxil::lower_wide -- --nocapture->4 passed; 0 failed; 0 ignored(including bothv_rcp_f64_and_v_rsq_f64_use_guarded_scaled_rcp_dandgpu_direct_rcp_f64_and_rsq_f64_edgeson RTX 4060).XCL_DIRECT_DXIL=1 cargo test --release -p xcl --lib gpu_f64_roots -- --nocapture->1 passed; 0 failed; 0 ignored.cargo test --release -p xcl --lib f64_programs_on_the_gpu -- --nocapture->1 passed; 0 failed; 0 ignored(wave32 HLSL vs Direct DXIL bit-for-bit match; wave64 skippedno wave64).4510bf84):cargo build --release --workspace+cargo test --release --workspace -- --test-threads=4 --nocapture->1156 passed, 0 failed, 46 ignoredacross 21 test binaries.SKIPPEDlines (27 total, all pre-existing on this wave32 Windows host without Graphics Tools / Developer Mode / heap windows):no wave64skips (4ingpu::recomp::lower::tests,14ingpu::recomp::lower_dxil::tests,2ingpu::recomp::tests).per-lane form: refusedskips ingpu::recomp::lower_dxil::tests(f16 arithmetic,f16 packed,f32 conversions).test_title_draws_with_a_root_signature_under_the_debug_layer: nod3d12SDKLayers.dll;uploads_start_from_each_subresources_state:0x887A002D).shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable driver cache without Windows Developer Mode.heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows.Regression run
Paired 60 s retail title runs with
scripts/smoke.ps1(release build, same title, clean working tree) onorigin/main(cbc296ab) and this PR (4510bf84):main:this PR:
Not tested
1/NaNreturning0and1/DBL_MAXdenormal flushing were originally observed in Recompiler: v_rcp_f64 and v_rsq_f64 keep NaN, infinities and denormals #530), wave64 hardware, adapters without double-precision support, D3D12 debug layer, heap windows, and Linux/Wine.v_rcp_f64orv_rsq_f64under Direct DXIL; the paired smoke run is a regression check only.AI use
Google Antigravity (Gemini 4 Neon) wrote the fix, tests, and this PR description; all builds, tests, and paired retail smoke runs were executed locally on the hardware listed above.