Skip to content

Recompiler: direct DXIL folds all-ones EXEC and skips dead VGPR reads - #1801

Open
xADEL wants to merge 1 commit into
xcl-dev:mainfrom
xADEL:dxil/fold-all-ones-exec
Open

xADEL wants to merge 1 commit into
xcl-dev:mainfrom
xADEL:dxil/fold-all-ones-exec

Conversation

@xADEL

@xADEL xADEL commented Nov 24, 2026 •

Copy link
Copy Markdown

Direct DXIL entry_exec already initializes EXEC to all ones on full-wave compute and mesh shaders, and Lw::guarded already skips branches when its condition is constant 1, but lanebit / lanebit_at emitted (w >> lane31) & 1 != 0 without folding w == u32::MAX to true, so full-wave lane guards and dead old/cur VGPR reads were still emitted. Part of #1269.

What is in it

  • crates/xcl/src/gpu/dxil/lanes.rs: fold constant 0 and u32::MAX masks in lanebit and lanebit_at, and skip the upper-half compare in lanebit_at when hi == lo.
  • crates/xcl/src/gpu/dxil/lower.rs: fold Or(x, mask) => mask and same-operand integer identities in Lw::bin (so s_or_saveexec -1 restores constant all-ones EXEC), and add Lw::wr_if to skip dead old VGPR reads when cond is constant.
  • crates/xcl/src/gpu/dxil/lower_valu.rs, lower_wide.rs, lower_gfx.rs, lower_image.rs: route guarded writes through wr_if and read cur lazily only in RMW instructions (including valu_f32_rm added by Direct DXIL: geometry mode, MSAA loads and directed f32 rounding #1679).
  • crates/xcl/src/gpu/dxil/kernel.rs: bump TRANSLATOR_VERSION from 7 to 8.
  • crates/xcl/src/gpu/dxil/core_tests.rs: disassembly/validation and GPU tests (full_wave_exec_folds_away_lane_guards_and_dead_vgpr_reads, exec_folding_and_rmw_match_expected_on_gpu).

Tested

  • Hardware: NVIDIA GeForce RTX 3050 6GB Laptop GPU (32.0.16.2124), Intel Core i5-12450HX, 24 GB RAM, Windows 11 Pro (10.0.26300), rustc 1.100.0, Windows SDK 10.0.26100.0 (dxcompiler.dll / dxil.dll 1.9.2602.17), debug tests + release sweep/smoke.
  • XCL_ADAPTER="rtx 3050" cargo test --workspace -- --test-threads=4 (rebased head e00963f on main 8e87fc7): 992 passed, 0 failed, 45 ignored (both new EXEC-folding tests and all upstream core_tests / round_tests / msaa_tests / geometry_tests passed).
  • SKIPPED GPU tests on this adapter (24): 19 no wave64 (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, lower::tests::*, lower_dxil::tests::* wave64 arms), 3 per-lane wave32 unsupported f16/cvt arms (f16_programs_on_the_gpu, f32_programs_on_the_gpu), 1 no heap windows (heap_window_out_of_memory_falls_back_to_the_switch_form), 1 0x887A002D Developer Mode required (pso_measurement_compiles_an_exact_synthetic_record).
  • Retail shaders.rpf sweep (xcl shaders <pack> --direct --validate --sample 500 --seed 1, release): 408/408 translated (100.0%: 33 CS, 11 GS, 155 MS, 164 PS, 45 VS), 0 validator errors, 0 panics (2.1 s).

Regression run

xcl-smoke v1
commit: 8e87fc7b62a87ea589ccb9ea6182f514016cf7db
gpu: NVIDIA GeForce RTX 3050 6GB Laptop GPU
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1514 (PresentX 1514)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14719 MB
xcl-smoke v1
commit: e00963fafdae4420f88333e7b2eb75d1ab9a994a
gpu: NVIDIA GeForce RTX 3050 6GB Laptop GPU
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1554 (PresentX 1554)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14711 MB

(Note: smoke.ps1 runs without XCL_DIRECT_DXIL=1, so this regression check verifies no runtime regression on the default path and is not a gameplay FPS claim for the direct-DXIL optimization.)

Not tested

  • Native wave64 GPUs (AMD RDNA2/3/4), Intel GPUs, XCL_HEAP_WINDOWS=1 runtime runs, XCL_DIRECT_DXIL=1 full title runs, and XCL_SAMPLE_* tests.

AI use

  • Antigravity (Gemini 4 Neon) investigated the gap, wrote the patch and tests, rebased onto 8e87fc7 (extending lazy cur to valu_f32_rm and bumping TRANSLATOR_VERSION to 8), ran the workspace suite, --direct --validate sweep, and smoke.ps1 runs on this machine, and drafted this description.

@ivall ivall added the goal:world-load Bears on the retail title getting past world loading label Nov 24, 2026

@lewisnic94-max lewisnic94-max left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review of 5623328.

All 128 GPU lane results matched the CPU reference across four execution masks on an RTX 3080.

No actionable defects identified within the reviewed scope. AMD and Intel hardware were not tested.

AI-assisted review and validation by Codex.

@futurepro62

futurepro62 commented Nov 24, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 271b0da (on its base 20cf130).

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::dxil::fuzz_tests: 968 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: full_wave_exec_folds_away_lane_guards_and_dead_vgpr_reads, exec_folding_and_rmw_match_expected_on_gpu.
  • 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: 977 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 62265d3 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) and the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests (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.

entry_exec already initializes EXEC to all ones on full-wave compute and mesh shaders, and Lw::guarded already skips branches when its condition is constant 1, but lanebit/lanebit_at emitted (w >> lane31) & 1 != 0 without folding w == u32::MAX to true.

- Fold constant 0 and u32::MAX masks in lanebit and lanebit_at (skipping the upper-half compare when hi == lo).
- Fold Or(x, all_ones) => all_ones and same-operand integer identities in Lw::bin so s_or_saveexec -1 restores constant all-ones EXEC.
- Add Lw::wr_if and lazy cur reads in VALU lowering so unconditional writes do not read dead old VGPR values.
- Bump TRANSLATOR_VERSION from 7 to 8.

Part of xcl-dev#1269.

@lewisnic94-max lewisnic94-max left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revalidated the EXEC-mask and accumulator changes at e00963fafdae4420f88333e7b2eb75d1ab9a994a against merge base 8e87fc7b62a87ea589ccb9ea6182f514016cf7db. The original four-mask wave32 test passed all 128 lane checks.

With runtime rounding toward +infinity, −infinity and zero, I compared 1,152 lane results for V_FMAC_F32, V_FMAC_LEGACY_F32 and V_MAC_F32. Every result matched the merge base bit for bit. Thirty active legacy FMAC results differed from the arithmetic reference on both builds. With input denormals preserved, the smallest positive subnormal times +infinity plus 1 returned 1.0. The reference expected +infinity. Native RDNA2 confirmation of that legacy case is still pending.

Head totals were 9 passed, 1 failed, 0 ignored and 0 skip notices. The merge base had 7 passed, 1 failed, 0 ignored and 0 skip notices. The failure was the same new legacy assertion. The five stock gpu::dxil::round_tests passed on both builds. Windows 11 build 26200.9974, Ryzen 7 5800X, RTX 3080 driver 616.92, Rust 1.100.0 MSVC, DXC 1.9.2602.17. The other head filters were batch002_dynamic_exec, full_wave_exec_folds, exec_folding_and_rmw, followup_directed_accumulator and followup_accumulator_readback_matrix. Coverage was limited to synthetic inputs on this adapter.

Codex (GPT-6) assisted with the test fixtures, GPU readbacks and comparison.

@JJAutoCompare

Copy link
Copy Markdown

Focused Intel Arc regression run for exact head e00963fafdae4420f88333e7b2eb75d1ab9a994a. The checkout was clean before and after testing, and the live PR head matched after the run.

Tested

  • Intel Arc A770, driver 32.0.101.9175, Ryzen 7 3800X, Windows 11 Enterprise Evaluation build 26200.9974, Rust/Cargo 1.100.0 (stable-x86_64-pc-windows-msvc), debug profile. The test binary logged dxcompiler.dll and dxil.dll version 1.9.2609.5 from %LOCALAPPDATA%/XclTooling/dxc-1.9.2609/bin/x64 via XCL_DXC_DIR. Used an isolated target and TEMP/TMP on L:, two build jobs, and CARGO_INCREMENTAL=0.
  • Built with cargo +stable-x86_64-pc-windows-msvc test -j 2 -p xcl --lib --no-run. Both tests used XCL_REQUIRE_GPU=wave64,mesh. The dispatch test used XCL_ADAPTER=A770 and ran inside & 'L:/XclTooling/Invoke-ArcTest.ps1' -Test { ... }. The build and disassembly test ran outside the lock.
cargo +stable-x86_64-pc-windows-msvc test -j 2 -p xcl --lib gpu::dxil::core_tests::full_wave_exec_folds_away_lane_guards_and_dead_vgpr_reads -- --exact --nocapture
cargo +stable-x86_64-pc-windows-msvc test -j 2 -p xcl --lib gpu::dxil::core_tests::exec_folding_and_rmw_match_expected_on_gpu -- --exact --nocapture

Each command reported 1 passed, 0 failed, 0 ignored, 0 skip notices. The disassembly assertions checked full-wave guard folding and the retained accumulator load. The GPU test executed direct-translated DXIL and checked lane and memory readbacks for zero, half-active, restored and dynamically narrowed EXEC masks. D3D12 reported a wave lane range of 8–32 on this adapter, so the dispatch test exercised split wave64 and native wave32.

Not tested

  • Native wave64 dispatch, a full workspace run on Arc, a release build, retail titles, and the separate directed-rounding cases discussed above.

AI use

  • Codex (gpt-6.2-sol) ran the tests and wrote this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants