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

Merged
real-alponzo merged 1 commit from upstream-pr/1930 into main 2026-11-24 23:54:31 +00:00
real-alponzo commented 2026-11-24 23:40:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by real-alponzo on 2026-11-24T23:40:31Z.


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.

<!-- greyfinch-sync:ivall/xcl:issue:6593678743 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1930). Originally posted by [real-alponzo](https://github.com/real-alponzo) on 2026-11-24T23:40:31Z. --- 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.
upstream-sync closed this pull request 2026-11-25 00:08:27 +00:00
upipibi commented 2026-11-25 00:09:02 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-24T23:43:48Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7147729367 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1930#issuecomment-7147729367). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-24T23:43:48Z. --- 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.
DavidM1911 commented 2026-11-25 03:05:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T02:33:54Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7150885624 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1930#issuecomment-7150885624). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T02:33:54Z. --- 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!
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1920
No description provided.