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() #1885

Open
opened 2026-11-24 22:37:56 +00:00 by microwave805 · 3 comments
microwave805 commented 2026-11-24 22:37:56 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by microwave805 on 2026-11-24T22:37:56Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:6592814346 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/1895). Originally posted by [microwave805](https://github.com/microwave805) on 2026-11-24T22:37:56Z. --- 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.
oni-swr commented 2026-11-25 12:06:15 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by oni-swr on 2026-11-25T11:15:35Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7160808041 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/1895#issuecomment-7160808041). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T11:15:35Z. --- 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 commented 2026-11-25 12:06:33 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by oni-swr on 2026-11-25T12:02:22Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7161836864 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/1895#issuecomment-7161836864). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T12:02:22Z. --- Releasing our claim on #1895: PR #1913 / #2252 and merged PR #2013 already cover both items.
YaBulochka commented 2026-11-25 13:05:07 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by YaBulochka on 2026-11-25T12:29:44Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7162449902 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/1895#issuecomment-7162449902). Originally posted by [YaBulochka](https://github.com/YaBulochka) on 2026-11-25T12:29:44Z. --- 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.
Sign in to join this conversation.
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#1885
No description provided.