Repository navigation
Recompiler: keep v_fma_f64 precise so a driver cannot split it - #2119
pablogonz12 wants to merge 1 commit into
Conversation
The HLSL path emitted v_fma_f64 as a plain fma(), so DXC left the Fma
call without !dx.precise and vkd3d-proton gave the driver an Fma without
NoContraction. With the same a * b already computed in the shader, RADV
split the fma and merged the two products: v_fma_f64(x, x, -(x * x))
returned 0 instead of the rounding error of the product.
Emit it through fma_d(), whose result is precise. vkd3d-proton passes
that on for Fma from dxil-spirv fd92a550 ("Handle precise for full FMA
opcode").
Assisted-by: Claude Code (Claude Sonnet 5.5)
|
Full-suite run, since this PR has no test report yet. Tested exact head Tested
Not tested
AI use
|
|
Tested:
Head |
|
A run with vkd3d-proton as the host D3D12. The DXIL goes through dxil-spirv and then the NVIDIA Vulkan driver, not the native-Windows path: this PR's new test passes, none skipped. Tested
Not tested
AI use
|
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
|
Native Windows run on an NVIDIA D3D12 driver (listed under Not tested). Setup: RTX 3060 12 GB (32-lane waves, driver 32.0.16.2101), Ryzen 5 5600X, 32 GB RAM, Windows 11 build 26300, Rust 1.100.0, DXC 1.9.2609.5, debug build. Head 7b5f620. Result: cargo test --workspace -- --test-threads=4: 1155 passed, 0 failed, 46 ignored. SKIPPED: 18 GPU tests for no wave64 (expected on this card); the per-lane refused cases; heap windows; driver cache. Not tested: AMD; a title run. AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report. |
The HLSL path emitted
v_fma_f64as a plainfma(). DXC then left thedx.op.tertiaryFma call without!dx.precise, vkd3d-proton gave RADV anOpExtInst FmawithoutNoContraction, and RADV split that fma when the shader already computed the samea * b: it merged the two products and rounded twice.v_fma_f64(x, x, -(x * x))returned0instead of the rounding error of the product (2^-56 + 2^-104,0x3C70000000200000), so any f64 fma whose product is also written elsewhere in the shader loses its fused result on RADV.v_fma_f64now goes throughfma_d(), whose result isprecise. Related: #472 is the f32 form of an unfused fma (mad()on RDNA1); this is the f64 form, which needs only that the host passespreciseon.What is in it
crates/xcl/src/gpu/recomp/emit.rs:v_fma_f64emitsfma_d(...);fma_dis defined in the prelude besidemad_nfand computes the fma in aprecisedouble.crates/xcl/src/gpu/recomp/tests.rs:gpu_v_fma_f64_stays_fused_beside_the_same_productcompiles with the runtime's own DXC arguments (no-Gis), runsp = x * xandfma(x, x, -p)on the GPU and checkspand the exact residual.Evidence
7b5f620(disassembled withdxil::validate::disassemble, there is nodxc.exeon this machine):call double @dx.op.tertiary.f64(i32 47, …), !dx.precise !12 ; Fma(a,b,c).VKD3D_SHADER_DUMP_PATHon the same commit:%81 = OpFMul %doubledecoratedNoContraction, theFmadecoratedNoContractionas well. Before the change theFmahad no decoration.d3d12core.dllour test prefix has (dxil-spirv7c048638is in the tree, but that DLL was built beforefd92a550"Handle precise for full FMA opcode") and passes with vkd3d-proton master30b0eb9(dxil-spirv34f0ff8) and with our patched v3.1 rebuilt today (10c5f7c4). The fix therefore takes effect with any vkd3d-proton whose dxil-spirv containsfd92a550; on an older one the host dropspreciseforFmaand nothing in XCL can keep the fma fused on that path.Tested
cargo xwinx86_64-pc-windows-msvc,-C target-feature=+crt-static, release.xcllib suite,--test-threads=4, skippinginteger_ops_match_cpu,uaddc_and_usubb_match_cpu,jumps_to_outer_loop_heads_are_structured(they kill the lib test binary on RADV; main tip: jumps_to_outer_loop_heads_are_structured kills the whole lib test binary on Wine + RDNA3 (exit status 5), bisected to b8b1f49 #1246, separate):6987e491085 passed, 10 failed, 26 ignored; this head7b5f6201088 passed, 8 failed, 26 ignored (head's extra failure is the new test, which stays red on that stale DLL; the 3 title-textures / d32s8 failures of main's run passed on head)10c5f7c4): main6987e491088 passed, 7 failed, 26 ignored; this head7b5f6201089 passed, 7 failed, 26 ignored — the same 7 on both (fuzz_validate_and_gpu_2,directed_reference_basics,lower_dxilf64 and f32,gpu_nonfused_mad_and_mac_prevent_fma_contraction, depth-UAV placement,xma2_source_voice), and the new test passes.e2e,pls_quota,predication_e2eand the other 14 test binaries), one thread: the same 3 failures on main and on head (e2econsole-screen cloak,pls_quotaWineERROR_FILE_NOT_FOUND,predication_e2ecopies not predicated by vkd3d-proton).SKIPPEDon this adapter: the four f16 / f32-conversion programs oflower_dxil(unsupportedV_MUL_F16semantics, gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426), unchanged by this PR.Regression run
Both blocks are the output of each commit's own unmodified
scripts/smoke.ps1, written to a file by PowerShell and pasted as is. It ran in Windows PowerShell 7.7.0 (pwsh.exe) under Wine (GE-Proton11-14, Linux), not on native Windows, with MinGit 2.56.1 forgit;xcl.exeis an MSVC release build (cargo xwin, static CRT), passed with-Xcl. Host workarounds outside the script: a pseudo-terminal,DOTNET_SYSTEM_GLOBALIZATION_USENLS=1, and importing PowerShell's Utility and Management modules before calling it.mainis this PR's base commit. These replace the earlier blocks from a bash port. Frame counts at this speed are small; I read them only as no crash or device removal. Each commit was run once. Note that this title can end in a device removal on this host even onmain(seen in repeat runs of another base commit, see #464).main:This PR's head:
Not tested
NoContractionon theFma, so the fma should stay fused, but I did not measure it.v_fma_f64with the same product written elsewhere; no title was checked for a change in output.XCL_DIRECT_DXIL: itsFmastill carries nodx.preciseand itsf64_programs_on_the_gpufails the same way; that is a separate change ingpu/dxil.AI use
fma_dand the test, dumped the DXIL and SPIR-V, ran the suite, the integration tests and the two smoke runs, and wrote this description. I checked every line of the diff and every number above.