Skip to content

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

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
AlpPesen:fix/dxil-cse-invalidate-across-discard
Nov 24, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
AlpPesen:fix/dxil-cse-invalidate-across-discard

Conversation

@AlpPesen

Copy link
Copy Markdown
Contributor

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 D3D12.X: map a one-slice title texture's packed mips where D3D12 addresses them #470, plus gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 — unrelated pre-existing fuzz failure tracked in DXIL GPU fuzz tests reproducibly fail with E_OUTOFMEMORY on RTX 5060 #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.

….op.discard

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 xcl-dev#1891.

Assisted-by: Antigravity (Gemini 4 Neon)
@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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).

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

@raylitebull
raylitebull merged commit 36ac23d into xcl-dev:main Nov 24, 2026
2 checks passed
anoyarou added a commit to anoyarou/xcl that referenced this pull request Nov 25, 2026
, xcl-dev#1869, xcl-dev#1898)

Brings main to full parity with upstream/main (8e87fc7):
- xcl-dev#1930: invalidate block-local DXIL CSE wave/quad cache across dx.op.discard (fixes xcl-dev#1891)
- xcl-dev#1864: allow inline-constant and NULL mask operands in the per-lane form
- xcl-dev#1869: avoid 2 - off underflow in s_setreg_b32 targeting HW_REG_MODE bit 3
- xcl-dev#1898: truncate s instead of returning native on special values in round_exact

Conflict in crates/xcl/src/gpu/dxil/core_tests.rs resolved by keeping both tests
(opt_folds_i64_bitcast_selects_and_commutative_cse and s_setreg_b32_mode_bit3_does_not_underflow).

Assisted-by: Antigravity (Gemini 4)
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
Pulls in xcl-dev#1836 (graphics and two-pass PSO disk cache + lazy MS/GS + shader build coalescing), xcl-dev#1930 (DXIL CSE across discard), xcl-dev#1900, xcl-dev#1005, xcl-dev#1053, xcl-dev#1864, xcl-dev#1866, xcl-dev#1869, xcl-dev#1876, and xcl-dev#1898 while keeping our RDNA4 MSAA clamp (xcl-dev#1908), wave64 graphics Direct DXIL guard (xcl-dev#1913), atomic writable-range tracking, static-sampler cache keys, and 4M-group indirect dispatch clamp.
@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

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.

Direct DXIL: block-local CSE in Module::optimize does not invalidate wave/quad intrinsics across dx.op.discard

4 participants