Recompiler: keep v_fma_f64 precise so a driver cannot split it #2119
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!2119
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2119"
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?
@pablogonz12 on GitHub · 2026-11-25 05:03 UTC · original
pablogonz12:fix/v-fma-f64-precise→main· +36 −1 · 2 files · 1 commits · openThe 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; #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, #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.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)@futurepro62 on GitHub · 2026-11-25 05:19 UTC · original · edited 2026-11-25 05:23 UTC
Full-suite run, since this PR has no test report yet. Tested exact head
7b5f620(on its base6987e49).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 1143 passed, 0 failed, 44 ignored. SKIPPED (no wave64):a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu,a_per_lane_2d_or_3d_group_runs_on_the_gpu,coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu,cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu,gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware,the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.gpu_v_fma_f64_stays_fused_beside_the_same_product.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 1154 passed, 0 failed, 46 ignored. SKIPPED:f16_programs_on_the_gpu(f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))),f32_programs_on_the_gpu(f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))),f32_programs_on_the_gpu(f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).--skipleaves out tests that fail on main6020a33too, not because of this PR. On NVIDIA:heap_window_out_of_memory_falls_back_to_the_switch_form(#1651), the fourgpu::recomp::lower_dxil::tests::*_programs_on_the_gputests,const_and_null_mask_operands_agree_with_hlsl_on_the_gpuandmask_ff0_and_flbit_agree_with_hlsl_on_the_gpu(follow-up on #1651) fail becauserunner::skip_testturns their skips into failures underXCL_REQUIRE_GPU=mesh, andgpu::dxil::fuzz_testsseeds 70, 545, 1019 and 1507 failCreateComputePipelineStatewithE_OUTOFMEMORYon this card (drivers 616.64 and 621.40). On AMD:fuzz_validate_and_gpu_1fails on seed 540 (res[833]0x7 vs CPU 0x6). The AMD run does not setXCL_REQUIRE_GPU.Not tested
AI use
@DarkPanda69 on GitHub · 2026-11-25 05:23 UTC · original
Tested:
gpu_v_fma_f64_stays_fused_beside_the_same_productpasses on an AMD D3D12 driver and on an RTX 3060.gpu::filter: 585 passed, 2 failed, 22 ignored. The 2 failures are the AMD fuzz seeds 722 and 1599 tracked in #2115, which fail the same way onmain.Head
7b5f620applied onmain6020a33,cargo test -p xcl --lib -- gpu:: --test-threads=4withXCL_ADAPTERset to each card.Not tested: retail runs, and nothing beyond what the test itself asserts about the fused result.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
@JoaoPauluu on GitHub · 2026-11-25 06:12 UTC · original
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
x86_64-pc-windows-gnu.7b5f620as it is (merge base withmain6987e49), no uncommitted changes. The lib test binary runs under Wine, one test per process.gpu_v_fma_f64_stays_fused_beside_the_same_product: okNot tested
AI use
@DavidM1911 on GitHub · 2026-11-25 06:17 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. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
@jennydeth on GitHub · 2026-11-25 14:23 UTC · original
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.
@luckyteagirl on GitHub · 2026-11-26 09:06 UTC · original · reviewed
The new
gpu_v_fma_f64_stays_fused_beside_the_same_producttest on7b5f620only callsgpu_ready(), which checks adapter, wave support, and DXC but not shader FP64. It then unconditionally compiles and runs a shader withdoubleoperations. A reported XCL test adapter, Intel Arc A770, returnsDoublePrecisionFloatShaderOps=0(hardware report); on such a device the new test can fail during PSO creation before it checks fused rounding. D3D12 exposes this requirement throughD3D12_FEATURE_DATA_D3D12_OPTIONS(Microsoft reference).Could the test query that option on the adapter selected by the runner and skip the GPU execution when FP64 is unsupported? A CPU-side check of the emitted precision metadata could still exercise translation on those adapters. This is source and capability-report review only; I did not run this test on an FP64-limited GPU.
@pablogonz12 on GitHub · 2026-11-26 10:23 UTC · original
Thanks — confirmed, and it is wider than this PR's test.
Checked at head
7b5f620:gpu_v_fma_f64_stays_fused_beside_the_same_product(crates/xcl/src/gpu/recomp/tests.rs:7759) gates ongpu_ready()(tests.rs:13) only: adapter,wave64_programs_supported()anddxc::location(). No FP64 check, as you say.6987e49gate the same way:gpu_f64_class_compare,gpu_rndne_f64,gpu_frexp_f64_exp_and_mant,gpu_f64_rounding_and_conversions,gpu_f64_roots,gpu_ldexp_f64,gpu_f64_compares_with_nan,gpu_f64_math_random,gpu_f64_literal_high_word.crates/xcl/src/gpuasks forD3D12_OPTIONS.DoublePrecisionFloatShaderOps:runner::adapter()queriesD3D12_FEATURE_SHADER_MODEL,D3D12_OPTIONS1andD3D12_OPTIONS7(mesh). So on an adapter such as the A770 the nine tests that exist onmainshould fail the same way; this PR adds a tenth test of that shape, not a new hardware requirement.precise double r = fma(a, b, c);(emit.rs:6164). An assertion on the!dx.precisemetadata would still need DXC, which the DXC-gated tests here already need, but it would only cover the translation half, not the execution this PR is about.About the fix: it is not a one-line test change. It needs a capability helper in
gpu/recomp/runner.rsbesidemesh_shaders_supported(), askip_test("no fp64")in all ten f64 tests, and a mapping forXCL_REQUIRE_GPU, becauseskip_testcounts any reason other than"no mesh shaders"as a failure underXCL_REQUIRE_GPU=wave64(runner.rs:617-625) — an unmapped"no fp64"would turn a skip into a red test on that runner. If a maintainer wants that on this branch, we will push it here as one commit; otherwise a separate PR covering all ten tests is the honest scope, since it changesmain's f64 coverage too.AI use: prepared with AI assistance (DeepSeek), report only — the file and line references above were read from the source at
7b5f620.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.