Skip to content

DXIL: set DisableMathRefactoring when lowering unfused mad without FMad - #1973

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
raylitebull:feat/dxil-disable-math-refactoring
Nov 25, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
raylitebull:feat/dxil-disable-math-refactoring

Conversation

@raylitebull

@raylitebull raylitebull commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Sets the DXIL entry-point DisableMathRefactoring flag (bit 1, SFI0 = 0) when the direct DXIL translator lowers unfused mad_nf (V_MAD_F32 / V_MAC_F32), unless the optimized module still emits live dx.op.tertiary.* FMad (opcode 46) calls (which DXIL validation forbids combining with DisableMathRefactoring).

Part of #1269.

What is in it

  • crates/xcl/src/gpu/dxil/kernel.rs: bump TRANSLATOR_VERSION (8 -> 9; merges cleanly with main, where XCL_DIRECT_DXIL_SOURCE_ID from Recompiler: direct DXIL cache entries change when its sources do #1947 now automatically invalidates direct-DXIL disk caches on gpu/dxil source changes).
  • crates/xcl/src/gpu/dxil/shader.rs: add Feature::DisableMathRefactoring (metadata_bit = 1, container_bit = 0) and Shader::feature_flags() + Shader::uses_fmad() so DisableMathRefactoring is omitted whenever post-optimize() IR still contains dx.op.tertiary.* opcode 46 (FMad).
  • crates/xcl/src/gpu/dxil/graphics.rs: route entry-point shader flag computation through self.feature_flags().
  • crates/xcl/src/gpu/dxil/prelude.rs: require Feature::DisableMathRefactoring in Lw::mad_nf, and add disable_math_refactoring_tests (5 tests covering compute/pixel unfused mad, live FMad suppression, plain v_add_f32, and post-DCE dead FMad).

Tested

  • Toolchain: Windows 11 x64, rustc 1.99.1 (58cf8f9c3 2026-10-13), DXC dxcompiler 1.8.2502.11 / dxil 1.8.2502.11, rebased cleanly onto 656c0e8 (aaf2c78).
  • cargo check --workspace --tests: passed.
  • cargo test -p xcl --lib disable_math_refactoring_tests: 5 passed, 0 failed (dxil 1.8.2502.11 validated).
  • Community verification on exact head aaf2c78:
    • @fromthemoonx (NVIDIA RTX 3060): 1067 passed, 0 failed, 45 ignored, disable_math_refactoring_tests 10/10.
    • @DavidM1911 (NVIDIA RTX 3060 Ti): cargo test -p xcl --lib passed, 0 failed.
    • @pablogonz12 (AMD RX 9070 XT, Linux/Wine/RADV): +5/5 disable_math_refactoring_tests, 0 regressions vs base.
    • @JJAutoCompare: disable_math_refactoring_tests 5/5 passed with dxil 1.9.2609.5.
    • @Toons29 (AMD Radeon RX 9070): 60 s scripts/smoke.ps1 pair passed (1634 vs 1566 frames, 0 device removals, 0 crashes).

Regression run
60 s scripts/smoke.ps1 pair on exact head aaf2c788 vs main 568e7db7 (AMD Radeon RX 9070, driver 32.0.32029.2010, Windows 11 26300, release, XCL_NETWORK=0 on a retail title), contributed by @Toons29:

main:

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1566 (PresentX 1566)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14592 MB

this PR:

xcl-smoke v1
commit: aaf2c788f5f6262a6e20b2e2a6de63e4b5dfa81c
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1634 (PresentX 1634)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14683 MB

Not tested

  • A GPU program whose output numerically diverges on Windows with FMA contraction enabled; Intel Arc execution.

AI use

  • Antigravity assisted with implementation and DXIL validation tests; the author reviewed the diff and test output.

@futurepro62

futurepro62 commented Nov 25, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head cda8355 (on its base 80f4819).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_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::dxil::fuzz_tests: 987 passed, 0 failed, 43 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.
  • The new tests ran and passed: compute_unfused_mad_sets_disable_math_refactoring, pixel_unfused_mad_sets_disable_math_refactoring, fmad_suppresses_disable_math_refactoring_in_compute_and_pixel, plain_float_add_does_not_set_disable_math_refactoring, dead_fmad_eliminated_by_dce_still_allows_disable_math_refactoring.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 997 passed, 0 failed, 45 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #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 gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #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 gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #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 gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #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 gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 80f4819 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests and const_and_null_mask_operands_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@fromthemoonx

fromthemoonx commented Nov 25, 2026 •

Copy link
Copy Markdown

Update: TRANSLATOR_VERSION needs 10 now. #1992 merged with 9 (daf52ab, "translator version 9 (main took 8)"), and #1742 followed. This PR also sets 9, so it still merges cleanly into main 025c786 (both sides write the same line), and git will not flag it. But caches built by current main under XCL_DIRECT_DXIL would then be reused without DisableMathRefactoring.


Rerun on the new head aaf2c78 (rebased, TRANSLATOR_VERSION 9): still passes on the RTX 3060, and the cache point below is resolved. cargo test --workspace --no-fail-fast -- --test-threads=4: 1067 passed, 0 failed, 45 ignored. disable_math_refactoring_tests: 10 of 10. #1742 also changes direct-DXIL output without a bump yet, so whichever of the two merges second needs 10. The report below is for cda8355.


Passes on an RTX 3060 (Ampere). The new tests fail without the fix. One gap: TRANSLATOR_VERSION is not bumped, so cached direct-DXIL translations keep the old flags.

The cache. This PR changes the emitted containers (entry flags bit 1) for every program with an unfused v_mad_f32 / v_mac_f32. The direct translator's disk-cache identity is TRANSLATOR_VERSION (gpu/dxil/kernel.rs:40). Its comment says to bump it on any change that alters the emitted containers, because build.rs's TRANSLATOR_SOURCES hashes only gpu/recomp, not gpu/dxil. Without a bump, a title run with XCL_DIRECT_DXIL and an existing cache keeps loading the translations without DisableMathRefactoring. #1966 bumps the same line 7 → 8, so whichever PR merges second needs the next number. #1947 would make this automatic, but it is still open.

What this run adds to the RTX 5070 Ti report above:

  • Exact head cda8355 (already on main 80f4819, so this is also the merged tree). cargo build --workspace + cargo test --workspace --no-fail-fast -- --test-threads=4 with no --skip and no XCL_REQUIRE_GPU: 998 passed, 0 failed, 45 ignored. 23 SKIPPED: 19 for no wave64 (wave32 card), 3 per-lane lower_dxil refusals (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32; main skips the same way) and heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • The 5 new disable_math_refactoring_tests pass 10/10 runs.
  • Mutation check: with only the self.s.require(Feature::DisableMathRefactoring) line in Lw::mad_nf removed, 3 of the 5 fail (compute_unfused_mad_…, pixel_unfused_mad_…, dead_fmad_eliminated_by_dce_…). The other 2 still pass, as expected, because they assert that the flag is absent.
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu:: -- --test-threads=1 --skip gpu_sparse_vram: PR 468 passed / 0 failed / 21 ignored; main 80f4819 463 / 0 / 21 (the difference is the 5 new tests). gpu_nonfused_mad_and_mac_prevent_fma_contraction passes on both, so this driver did not contract that program on main either: on this card the flag changes no result the suite can see.
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --test e2e: 3 passed.

Hardware: RTX 3060 12 GB, driver 610.88, Windows 11 Pro 26300, Rust 1.100.0 MSVC, DXC / dxil 1.9.2602.17, debug.

Not tested: AMD, a release build, scripts/smoke.ps1 (no title on this machine), a program whose result changes with FMA contraction on NVIDIA.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

@raylitebull
raylitebull force-pushed the feat/dxil-disable-math-refactoring branch from cda8355 to 7dfa64c Compare November 25, 2026 00:39
@raylitebull

Copy link
Copy Markdown
Member Author

Thanks for catching that, @fromthemoonx!

Updated #1973 cleanly on top of 6567c5f in commit 7dfa64c to bump TRANSLATOR_VERSION from 7 to 8 in crates/xcl/src/gpu/dxil/kernel.rs so existing XCL_DIRECT_DXIL disk caches invalidate and regenerate containers with DisableMathRefactoring.

Verified with cargo check --workspace --tests and cargo test -p xcl --lib disable_math_refactoring_tests (5 passed, 0 failed, dxil 1.8.2502.11).

anoyarou pushed a commit to anoyarou/xcl that referenced this pull request Nov 25, 2026
@raylitebull
raylitebull force-pushed the feat/dxil-disable-math-refactoring branch from 7dfa64c to aaf2c78 Compare November 25, 2026 01:14
@raylitebull

Copy link
Copy Markdown
Member Author

Rebased #1973 cleanly onto 656c0e8 in commit aaf2c78 with TRANSLATOR_VERSION bumped from 8 to 9 in crates/xcl/src/gpu/dxil/kernel.rs (after #1950 bumped 7 -> 8), ensuring existing XCL_DIRECT_DXIL disk caches regenerate with DisableMathRefactoring — thanks again, @fromthemoonx!

Verified with cargo check --workspace --tests and cargo test -p xcl --lib disable_math_refactoring_tests (5 passed, 0 failed, dxil 1.8.2502.11 validated).

@pablogonz12

Copy link
Copy Markdown
Contributor

Test report for head aaf2c78 (base 656c0e8), on the platform the description lists as not tested: Linux / Wine / RADV. It passes here with no regression; the one red assertion the description's test has on this GPU is pre-existing and unchanged.

Tested

  • AMD Radeon RX 9070 XT (RDNA4, gfx1201, 32-lane waves), Ryzen 9 9900X, CachyOS (Linux 7.3.6), Mesa 26.3.1 (RADV), Wine GE-Proton11-14, vkd3d-proton v3.1.1-235-gf90f1bf180f4135 (the GE-Proton build), DXC 1.9.2609.5 (dxcompiler + dxil 01b62ad4), rustc 1.100.0, release, static CRT (RUSTFLAGS=-C target-feature=+crt-static), x86_64-pc-windows-msvc built with cargo xwin, run under Wine.
  • Whole xcl lib suite, --test-threads=4, same command on both commits:
    • 656c0e8 (base): 1001 passed, 9 failed, 25 ignored
    • aaf2c78 (this head): 1006 passed, 9 failed, 25 ignored — the +5 are disable_math_refactoring_tests; the nine red are the same nine.
  • The nine that fail on both: gpu_f64_roots, gpu_f64_math_random, gpu_nonfused_mad_and_mac_prevent_fma_contraction, gpu_depth_buffer_created_for_unordered_access_is_placed (Tests: assert the refused depth-buffer UAV state on Windows only #1475 fixes it, not merged), xma2_source_voice_decodes_and_manages_lifetime (Wine FAudio, XAudio2: GetState names the oldest queued buffer when the host gives none #890/Tests: the XMA2 voice test accepts no context before Start under Wine #1557), lower_dxil::tests::{f32,f64}_programs_on_the_gpu and dxil::round_tests::directed_reference_basics (the host fmaf under Wine), dxil::fuzz_tests::fuzz_validate_and_gpu_2.
  • Three tests were filtered out: integer_ops_match_cpu, uaddc_and_usubb_match_cpu, jumps_to_outer_loop_heads_are_structured. That is a RADV access violation inside libvulkan_radeon.so during vkCreateComputePipelines (exit 3), present on unmodified main for days and unrelated to this PR.
  • disable_math_refactoring_tests: 5 passed, 0 failed on this head, both with and without XCL_DIRECT_DXIL=1.
  • gpu_nonfused_mad_and_mac_prevent_fma_contraction, single test, --test-threads=1, base and head, XCL_DIRECT_DXIL unset and =1 (4 runs): every run stops at the same place, v_fma_f32 overflow control should stay fused, left 2139095040 (0x7F800000), right 1946157055 (0x73FFFFFF). The v_mac_f32/v_mad_f32/v_madak_f32 vectors above that assertion pass on both commits, with and without the flag, so on gfx12 the unfused lowering was already un-contracted here and DisableMathRefactoring changes nothing measurable for this test. The red is the lone v_fma_f32 control, which RADV on gfx12 rounds twice — the same failure as in Tests: run the v_fma_f32 control of the no-contraction test on its own #676; NVIDIA and RDNA2 do not see it (RDNA2 report in Tests: run the v_fma_f32 control of the no-contraction test on its own #676).

Not tested

  • The scripts/smoke.ps1 pair for this runtime change, and the retail title.
  • Windows, and NVIDIA.
  • Wave64 hardware; other Wine/vkd3d-proton versions.

AI use

  • This report was written by DeepSeek V4.1 Flash (opencode agent) from the runs above on the machine listed; no XCL code was written by it.

@JJAutoCompare

Copy link
Copy Markdown

Tested

Clean head aaf2c788f5f6262a6e20b2e2a6de63e4b5dfa81c. The remote PR ref and open GitHub PR page showed this SHA before and after the run. PR #1973

  • Native Windows 11 Enterprise Evaluation 26200.9974, AMD Ryzen 7 3800X, rustc and Cargo 1.100.0 (stable-x86_64-pc-windows-msvc), unoptimized test profile.
  • The test process logged loading dxcompiler.dll 1.9.2609.5 (01b62ad4) and dxil.dll 1.9.2609.5 from XCL_DXC_DIR.
$env:CARGO_TARGET_DIR = 'L:/XclTooling/pr1512-tiling-edges-fddfa267/target'
$env:CARGO_INCREMENTAL = '0'
$env:CARGO_PROFILE_DEV_DEBUG = '0'
$env:CARGO_PROFILE_TEST_DEBUG = '0'
$env:TEMP = 'L:/XclTooling/pr1973/run-aaf2c78-20261125T031023096Z/temp'
$env:TMP = $env:TEMP
$env:XCL_DXC_DIR = 'C:/Users/ljensen/AppData/Local/XclTooling/dxc-1.9.2609/bin/x64'
& 'C:/Users/ljensen/.cargo/bin/cargo.exe' +stable-x86_64-pc-windows-msvc test --locked -p xcl --lib -j 2 gpu::dxil::prelude::disable_math_refactoring_tests:: -- --nocapture --test-threads=1

Result — 5 passed, 0 failed, 0 ignored, 0 skipped, 1,038 filtered out. Cargo exited 0. The five tests reached seven explicit DXIL validator calls and seven matching disassemblies, with zero validator skips.

  • Compute V_MAD_F32 and V_MAC_F32 each set entry-point DisableMathRefactoring (bit 1).
  • Pixel V_MAD_F32 with an exported result emitted live fmul float and fadd float and set bit 1.
  • Mixed V_MAD_F32 and V_FMA_F32 retained DXIL FMad (opcode 46) and left bit 1 clear in compute and pixel.
  • Plain compute V_ADD_F32 left bit 1 clear.
  • Pixel dead-code elimination removed the unused FMad and the entry-point flags retained bit 1.

Not tested

GPU execution, driver-level contraction or numerical parity, disk-cache behavior, malformed inputs, the full suite, release builds, and retail-title smoke runs.

AI use

T3 Code / Codex (gpt-6.2-sol) ran the checked-in tests, verified the output, and wrote this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of aaf2c788 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 568e7db7, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1566 (PresentX 1566)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14592 MB
xcl-smoke v1
commit: aaf2c788f5f6262a6e20b2e2a6de63e4b5dfa81c
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1634 (PresentX 1634)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14683 MB

Against the limits in CONTRIBUTING.md: 104 % of main's frames, 101 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; a script posted this right after the run, with both blocks exactly as printed.

@raylitebull

Copy link
Copy Markdown
Member Author

Thanks @Toons29 for the exact-head RX 9070 60 s scripts/smoke.ps1 pair on aaf2c78 (0 device removals, 0 crashes) — added to the PR description! Thanks also to @pablogonz12 (RX 9070 XT Wine/RADV), @fromthemoonx (RTX 3060), @DavidM1911 (RTX 3060 Ti), and @JJAutoCompare for verifying aaf2c78.

Re #1947 / TRANSLATOR_VERSION: now that #1947 (XCL_DIRECT_DXIL_SOURCE_ID in crates/xcl/src/gpu/dxil/kernel.rs) has landed on main, direct-DXIL disk caches automatically invalidate on any gpu/dxil/* source edit without needing a TRANSLATOR_VERSION = 10 bump (and TRANSLATOR_VERSION = 9 merges cleanly with main).

@raylitebull
raylitebull merged commit 13c2a40 into xcl-dev:main Nov 25, 2026
2 of 4 checks passed
anoyarou added a commit to anoyarou/xcl that referenced this pull request Nov 25, 2026
Brings main to full parity with upstream/main (cdb0891), including:
- World rendering & gameplay: xcl-dev#1991, xcl-dev#1988, xcl-dev#1984, xcl-dev#2028, xcl-dev#2078
- Memory / VRAM / PSO: xcl-dev#1985, xcl-dev#2157, xcl-dev#2178, xcl-dev#2195, xcl-dev#2176, xcl-dev#1996, xcl-dev#1914
- Direct DXIL & shaders: xcl-dev#2120, xcl-dev#2174, xcl-dev#2194, xcl-dev#2207, xcl-dev#1951, xcl-dev#1973, xcl-dev#2156, xcl-dev#2064
- Preserves local Linux/Wine customizations: docs/linux.md, scripts/linux/*,
  in-process Wine XAsync (xgameruntime/api.rs), loader watchdog bypass, and
  Wine MEM_WRITE_WATCH bypass on coherent UMA windows (gpu/uma.rs).

Assisted-by: Antigravity (Gemini 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants