Recompiler: invalidate block-local DXIL CSE wave/quad cache across dx.op.discard #1930

Manually merged
github merged 1 commit from gh-pr/1930/head into gh-pr/1930/base 2026-11-26 05:10:13 +00:00
Owner

@⁠AlpPesen on GitHub · 2026-11-24 23:40 UTC · original
AlpPesen:fix/dxil-cse-invalidate-across-discard → main · +66 −0 · 1 files · 1 commits · merged 2026-11-24 23:54 UTC

Fixes block-local CSE in dxil::module::opt so dx.op.wave* and dx.op.quad* intrinsics cached in the per-block local map are invalidated when visiting dx.op.discard.

In DXIL pixel shaders, dx.op.discard(cond) demotes lanes mid-block without terminating the block, changing the wave's active lane set for all subsequent wave/quad intrinsics in the same basic block. Previously local was never cleared at dx.op.discard, allowing post-discard wave/quad calls with identical operands to reuse pre-discard results.

Fixes #1891.

What is in it

  • crates/xcl/src/gpu/dxil/module/opt.rs:
    • Clear local when visiting Op::Call(f, _) where self.funcs[*f as usize].name == "dx.op.discard".
    • Add unit test block_cse_invalidates_wave_and_quad_calls_across_discard verifying that identical dx.op.waveActiveBallot and dx.op.quadReadLaneAt calls on opposite sides of dx.op.discard are preserved (2 calls remain), while identical calls without dx.op.discard in the same block still CSE to 1 call. Verified to fail on unmodified main (20cf130) before the fix (left: 1, right: 2) and pass with the fix.

Regression run

Baseline (immediate parent main 20cf130, warm shader/PSO cache):

xcl-smoke v1
commit: 20cf13022f764208384c610c2ae6a3f4eed201a2
gpu: AMD Radeon RX 6800
title: 15ace2cf
seconds: 60
exit: 0x0
frames shown: 1413 (PresentX 1413)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15260 MB

This PR (fix/dxil-cse-invalidate-across-discard, warm shader/PSO cache):

xcl-smoke v1
commit: 50228bb747077d302888cb2c5693dc798a22e154
gpu: AMD Radeon RX 6800
title: 15ace2cf
seconds: 60
exit: 0x0
frames shown: 1402 (PresentX 1402)
presents per 2 s (last 3): 2 37 60
device removals: 0
crashes: 0
peak commit: 15136 MB

Tested

Hardware: Windows 11 Pro for Workstations (Build 26300), Intel Core i9-9900K, 32 GB RAM, AMD Radeon RX 6800 (16337 MiB VRAM, Driver 32.0.21045.29003), rustc 1.100.0 (0ef1bc386 2026-11-09).

  • cargo test -p xcl --lib block_cse_invalidates_wave_and_quad_calls_across_discard: 1 passed; 0 failed; 0 ignored; 0 skipped.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 973 passed; 4 failed; 45 ignored; 8 skipped (3 pre-existing RDNA2 placed_title_textures_share_vram_and_preserve_pixels + VRAM_TEST_LOCK cascades tracked in #470, plus gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 — unrelated pre-existing fuzz failure tracked in #1905; the 8 skips are 6 per-lane f16/f32 refusals, pso_measurement_compiles_an_exact_synthetic_record needing Developer Mode, and heap_window_out_of_memory_falls_back_to_the_switch_form needing XCL_HEAP_WINDOWS=1).
  • .\scripts\smoke.ps1 on 20cf13022f764208384c610c2ae6a3f4eed201a2 and 50228bb747077d302888cb2c5693dc798a22e154 (see Regression run above).

Not tested

  • Non-AMD GPUs and Linux / Wine.

AI use

Antigravity (Gemini 4 Neon) implemented the dx.op.discard invalidation and unit test in crates/xcl/src/gpu/dxil/module/opt.rs, and ran the full test suite and paired smoke runs.

**@⁠AlpPesen** on GitHub · 2026-11-24 23:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/1930) `AlpPesen:fix/dxil-cse-invalidate-across-discard` → `main` · +66 −0 · 1 files · 1 commits · merged 2026-11-24 23:54 UTC Fixes block-local CSE in `dxil::module::opt` so `dx.op.wave*` and `dx.op.quad*` intrinsics cached in the per-block `local` map are invalidated when visiting `dx.op.discard`. In DXIL pixel shaders, `dx.op.discard(cond)` demotes lanes mid-block without terminating the block, changing the wave's active lane set for all subsequent wave/quad intrinsics in the same basic block. Previously `local` was never cleared at `dx.op.discard`, allowing post-discard wave/quad calls with identical operands to reuse pre-discard results. Fixes #1891. **What is in it** - **`crates/xcl/src/gpu/dxil/module/opt.rs`**: - Clear `local` when visiting `Op::Call(f, _)` where `self.funcs[*f as usize].name == "dx.op.discard"`. - Add unit test `block_cse_invalidates_wave_and_quad_calls_across_discard` verifying that identical `dx.op.waveActiveBallot` and `dx.op.quadReadLaneAt` calls on opposite sides of `dx.op.discard` are preserved (2 calls remain), while identical calls without `dx.op.discard` in the same block still CSE to 1 call. Verified to fail on unmodified `main` (`20cf130`) before the fix (`left: 1, right: 2`) and pass with the fix. **Regression run** Baseline (immediate parent `main` `20cf130`, warm shader/PSO cache): ``` xcl-smoke v1 commit: 20cf13022f764208384c610c2ae6a3f4eed201a2 gpu: AMD Radeon RX 6800 title: 15ace2cf seconds: 60 exit: 0x0 frames shown: 1413 (PresentX 1413) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15260 MB ``` This PR (`fix/dxil-cse-invalidate-across-discard`, warm shader/PSO cache): ``` xcl-smoke v1 commit: 50228bb747077d302888cb2c5693dc798a22e154 gpu: AMD Radeon RX 6800 title: 15ace2cf seconds: 60 exit: 0x0 frames shown: 1402 (PresentX 1402) presents per 2 s (last 3): 2 37 60 device removals: 0 crashes: 0 peak commit: 15136 MB ``` **Tested** Hardware: Windows 11 Pro for Workstations (Build 26300), Intel Core i9-9900K, 32 GB RAM, AMD Radeon RX 6800 (16337 MiB VRAM, Driver `32.0.21045.29003`), `rustc 1.100.0 (0ef1bc386 2026-11-09)`. - `cargo test -p xcl --lib block_cse_invalidates_wave_and_quad_calls_across_discard`: `1 passed; 0 failed; 0 ignored; 0 skipped`. - `cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4`: `973 passed; 4 failed; 45 ignored; 8 skipped` (3 pre-existing RDNA2 `placed_title_textures_share_vram_and_preserve_pixels` + `VRAM_TEST_LOCK` cascades tracked in #470, plus `gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1` — unrelated pre-existing fuzz failure tracked in #1905; the 8 skips are 6 per-lane f16/f32 refusals, `pso_measurement_compiles_an_exact_synthetic_record` needing Developer Mode, and `heap_window_out_of_memory_falls_back_to_the_switch_form` needing `XCL_HEAP_WINDOWS=1`). - `.\scripts\smoke.ps1` on `20cf13022f764208384c610c2ae6a3f4eed201a2` and `50228bb747077d302888cb2c5693dc798a22e154` (see **Regression run** above). **Not tested** - Non-AMD GPUs and Linux / Wine. **AI use** Antigravity (Gemini 4 Neon) implemented the `dx.op.discard` invalidation and unit test in `crates/xcl/src/gpu/dxil/module/opt.rs`, and ran the full test suite and paired smoke runs.
In dxil::module::opt, cse_kind() caches dx.op.wave* and dx.op.quad* calls in a block-local map (local). Because dx.op.discard demotes lanes to helper lanes mid-block without terminating the block, subsequent wave/quad intrinsics in the same block observe a different active lane set and must not reuse pre-discard values.

Clear local when visiting dx.op.discard and add a unit test verifying that identical dx.op.waveActiveBallot and dx.op.quadReadLaneAt calls on opposite sides of dx.op.discard are kept while non-discard calls in the same block still CSE.

Fixes #1891.

Assisted-by: Antigravity (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:10:11 +00:00
github manually merged commit 50228bb747 into gh-pr/1930/base 2026-11-26 05:10:13 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 23:43 UTC · original

NVIDIA counterpart to the RX 6800 run: RTX 3070 8 GB (32-lane waves), driver 616.56, Windows 11, debug, 50228bb merged onto main 20cf130 (clean).

  • block_cse_invalidates_wave_and_quad_calls_across_discard: passes.
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu_ --skip gpu_sparse_vram --test-threads=4: 110 passed, 0 failed, 1 ignored, the same as main on this machine. The sparse test was skipped because of #1727.

AI-assisted (Claude Code). Synthetic tests only.

**@⁠upipibi** on GitHub · 2026-11-24 23:43 UTC · [original](https://github.com/xcl-dev/xcl/pull/1930#issuecomment-7147729367) NVIDIA counterpart to the RX 6800 run: RTX 3070 8 GB (32-lane waves), driver 616.56, Windows 11, debug, `50228bb` merged onto `main` `20cf130` (clean). - `block_cse_invalidates_wave_and_quad_calls_across_discard`: passes. - `XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu_ --skip gpu_sparse_vram --test-threads=4`: 110 passed, 0 failed, 1 ignored, the same as `main` on this machine. The sparse test was skipped because of #1727. AI-assisted (Claude Code). Synthetic tests only.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 02:33 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!

**@⁠DavidM1911** on GitHub · 2026-11-25 02:33 UTC · [original](https://github.com/xcl-dev/xcl/pull/1930#issuecomment-7150885624) 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!
This discussion has been locked. Commenting is limited to contributors.
No description provided.