Shaders: XCL_DIRECT_DXIL=all ignores split_wave64 / upper_lanes for wave64 VS/PS (poisoning split=1 cache), and XCL_DXIL_NO_OPT bypasses cache_allowed() #1895

Open
opened 2026-11-26 05:08:37 +00:00 by github-bot · 3 comments
Owner

@⁠microwave805 on GitHub · 2026-11-24 22:37 UTC · original

Static audit on main @ 689f2db found two shader-routing / cache-correctness bugs in crates/xcl/src/gpu/recomp/pso.rs and crates/xcl/src/gpu/dxil/coverage.rs:

1. XCL_DIRECT_DXIL=all ignores split_wave64 / upper_lanes for wave64 VS/PS and caches broken DXIL under the split=1 cache key

  • Where:
    • crates/xcl/src/gpu/recomp/pso.rs:365-373 (compile_console_shader does not pass split_wave64 to direct_graphics)
    • crates/xcl/src/gpu/recomp/pso.rs:651-666 (direct_graphics hardcodes split: false)
    • crates/xcl/src/gpu/recomp/pso.rs:258-263, 324-331 (disk cache stores the result under {hash}_{stage}_{sampler_base}_{windows}_{split as u8}.bin)
    • crates/xcl/src/gpu/dxil/kernel.rs:390 (let split = split && !gfx;)
    • crates/xcl/src/gpu/dxil/coverage.rs:254-255 (translate_mode also forces split: false for VS/PS)
  • Root cause: Unlike the HLSL path (recomp/emit.rs:4267) and the per-lane path (recomp/lower.rs:1100), Direct DXIL (gpu/dxil) has no upper_lanes handling for wave64 vertex/pixel shaders running on 32-lane hardware (NVIDIA, or AMD in wave32 graphics mode). When XCL_DIRECT_DXIL=all is set on a wave32 GPU (split_wave64 == true):
    1. direct_graphics() silently translates wave64 VS/PS with split: false even when upper_lanes::analyze(&insts) finds cross-lane reads of lanes 32..63 (which WaveReadLaneAt / WaveActiveBallot cannot provide in a 32-lane graphics wave), instead of falling back to the HLSL upper_lanes path.
    2. The resulting wave64-only DXIL is persisted into the translated disk cache under the split=1 filename (..._1.bin), poisoning the cache for wave32 GPUs.
  • Fix direction: Pass split_wave64 into direct_graphics() (and translate_mode()), and when wave64 && split_wave64 check upper_lanes::analyze and return Err(...) to fall back to the HLSL upper_lanes path whenever any read is non-Native (matching recomp/lower.rs:1100).

2. XCL_DXIL_NO_OPT is omitted from cache_allowed(), poisoning the translated disk cache

  • Where:
    • crates/xcl/src/gpu/recomp/pso.rs:560-573 (cache_allowed)
    • crates/xcl/src/gpu/dxil/module/opt.rs:352 (std::env::var("XCL_DXIL_NO_OPT"))
  • Root cause: Module::optimize() reads XCL_DXIL_NO_OPT (phi, cse, dce, or all) to skip optimization passes for bisecting, but cache_allowed() does not check XCL_DXIL_NO_OPT (and identity() does not include it). Running once with XCL_DXIL_NO_OPT=all writes unoptimized DXIL into the persistent disk cache under the normal identity, silently serving unoptimized shaders on all subsequent normal runs. (Same class of bug as #1409 for XCL_SAFE_BARRIER=0.)
  • Fix direction: Add "XCL_DXIL_NO_OPT" to the list of env vars in cache_allowed() (pso.rs:561), and add a unit test in pso.rs verifying cache_allowed returns false when XCL_DXIL_NO_OPT is set.

AI use

  • Antigravity (Gemini 4 Neon): static code audit on main @ 689f2db and issue drafting.
**@⁠microwave805** on GitHub · 2026-11-24 22:37 UTC · [original](https://github.com/xcl-dev/xcl/issues/1895) Static audit on `main @ 689f2db` found two shader-routing / cache-correctness bugs in `crates/xcl/src/gpu/recomp/pso.rs` and `crates/xcl/src/gpu/dxil/coverage.rs`: ### 1. `XCL_DIRECT_DXIL=all` ignores `split_wave64` / `upper_lanes` for wave64 VS/PS and caches broken DXIL under the `split=1` cache key - **Where:** - `crates/xcl/src/gpu/recomp/pso.rs:365-373` (`compile_console_shader` does not pass `split_wave64` to `direct_graphics`) - `crates/xcl/src/gpu/recomp/pso.rs:651-666` (`direct_graphics` hardcodes `split: false`) - `crates/xcl/src/gpu/recomp/pso.rs:258-263, 324-331` (disk cache stores the result under `{hash}_{stage}_{sampler_base}_{windows}_{split as u8}.bin`) - `crates/xcl/src/gpu/dxil/kernel.rs:390` (`let split = split && !gfx;`) - `crates/xcl/src/gpu/dxil/coverage.rs:254-255` (`translate_mode` also forces `split: false` for VS/PS) - **Root cause:** Unlike the HLSL path (`recomp/emit.rs:4267`) and the per-lane path (`recomp/lower.rs:1100`), Direct DXIL (`gpu/dxil`) has no `upper_lanes` handling for wave64 vertex/pixel shaders running on 32-lane hardware (NVIDIA, or AMD in wave32 graphics mode). When `XCL_DIRECT_DXIL=all` is set on a wave32 GPU (`split_wave64 == true`): 1. `direct_graphics()` silently translates wave64 VS/PS with `split: false` even when `upper_lanes::analyze(&insts)` finds cross-lane reads of lanes 32..63 (which `WaveReadLaneAt` / `WaveActiveBallot` cannot provide in a 32-lane graphics wave), instead of falling back to the HLSL `upper_lanes` path. 2. The resulting wave64-only DXIL is persisted into the translated disk cache under the `split=1` filename (`..._1.bin`), poisoning the cache for wave32 GPUs. - **Fix direction:** Pass `split_wave64` into `direct_graphics()` (and `translate_mode()`), and when `wave64 && split_wave64` check `upper_lanes::analyze` and return `Err(...)` to fall back to the HLSL `upper_lanes` path whenever any read is non-`Native` (matching `recomp/lower.rs:1100`). ### 2. `XCL_DXIL_NO_OPT` is omitted from `cache_allowed()`, poisoning the translated disk cache - **Where:** - `crates/xcl/src/gpu/recomp/pso.rs:560-573` (`cache_allowed`) - `crates/xcl/src/gpu/dxil/module/opt.rs:352` (`std::env::var("XCL_DXIL_NO_OPT")`) - **Root cause:** `Module::optimize()` reads `XCL_DXIL_NO_OPT` (`phi`, `cse`, `dce`, or `all`) to skip optimization passes for bisecting, but `cache_allowed()` does not check `XCL_DXIL_NO_OPT` (and `identity()` does not include it). Running once with `XCL_DXIL_NO_OPT=all` writes unoptimized DXIL into the persistent disk cache under the normal identity, silently serving unoptimized shaders on all subsequent normal runs. *(Same class of bug as `#1409` for `XCL_SAFE_BARRIER=0`.)* - **Fix direction:** Add `"XCL_DXIL_NO_OPT"` to the list of env vars in `cache_allowed()` (`pso.rs:561`), and add a unit test in `pso.rs` verifying `cache_allowed` returns `false` when `XCL_DXIL_NO_OPT` is set. ### AI use - Antigravity (Gemini 4 Neon): static code audit on `main @ 689f2db` and issue drafting.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:08:37 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 11:15 UTC · original

Taking #1895: respect split_wave64 / upper_lanes under XCL_DIRECT_DXIL=all for wave64 VS/PS and enforce cache_allowed() when XCL_DXIL_NO_OPT is set, with cache/translator regression tests.

**@⁠oni-swr** on GitHub · 2026-11-25 11:15 UTC · [original](https://github.com/xcl-dev/xcl/issues/1895#issuecomment-7160808041) Taking #1895: respect split_wave64 / upper_lanes under XCL_DIRECT_DXIL=all for wave64 VS/PS and enforce cache_allowed() when XCL_DXIL_NO_OPT is set, with cache/translator regression tests.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 12:02 UTC · original

Releasing our claim on #1895: PR #1913 / #2252 and merged PR #2013 already cover both items.

**@⁠oni-swr** on GitHub · 2026-11-25 12:02 UTC · [original](https://github.com/xcl-dev/xcl/issues/1895#issuecomment-7161836864) Releasing our claim on #1895: PR #1913 / #2252 and merged PR #2013 already cover both items.
Author
Owner

@⁠YaBulochka on GitHub · 2026-11-25 12:29 UTC · original

Status check on current main (568e7db), in case it saves someone a re-audit:

  • crates/xcl/src/gpu/recomp/pso.rs:760 fn direct_graphics(blob, stage, sampler_base, windows) still takes no split_wave64, and line 767 still builds KernelOptions { wave64: ..., split: false, ... }.
  • the cache key does carry split, so the "poisoning" half is unchanged until that is passed through.

So as of 568e7db the split half of #1895 is still present in the tree; #1913/#2252 are the fix and are still open. The cache half is covered by #2013, as @⁠oni-swr said.

No action wanted from this comment - just recording the exact line and the state, so the next person reading the issue does not have to grep it again. I will re-check after #2252 lands.

**@⁠YaBulochka** on GitHub · 2026-11-25 12:29 UTC · [original](https://github.com/xcl-dev/xcl/issues/1895#issuecomment-7162449902) Status check on current `main` (`568e7db`), in case it saves someone a re-audit: - `crates/xcl/src/gpu/recomp/pso.rs:760` `fn direct_graphics(blob, stage, sampler_base, windows)` still takes **no `split_wave64`**, and line 767 still builds `KernelOptions { wave64: ..., split: false, ... }`. - the cache key does carry `split`, so the "poisoning" half is unchanged until that is passed through. So as of `568e7db` the split half of #1895 is still present in the tree; #1913/#2252 are the fix and are still open. The cache half is covered by #2013, as @⁠oni-swr said. No action wanted from this comment - just recording the exact line and the state, so the next person reading the issue does not have to grep it again. I will re-check after #2252 lands.
This discussion has been locked. Commenting is limited to contributors.
No description provided.