Direct DXIL: compute_deps() poisons memo tables on cyclic phis/loops and omits store pointer/control dependencies in dx.viewIdState / PSV0 #1892

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

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

Static audit on main @ 689f2db found two soundness bugs in compute_deps() (crates/xcl/src/gpu/dxil/graphics.rs:755-861), which computes the input-to-output dependency tables written into DXIL dx.viewIdState metadata and the PSV0 container part. (Note: open PR #1770 preserves the exact same traversal and memoization algorithm, so these bugs apply there too.)

Where

  • crates/xcl/src/gpu/dxil/graphics.rs:755-861 (compute_deps, block_deps, value_deps)

Root causes

  1. Memo poisoning on cyclic PHIs and loops (graphics.rs:786-808, 859)
    To break recursion cycles, value_deps inserts an empty BTreeSet::new() into memo before recursing (graphics.rs:808), and block_deps does the same for ctrl_memo (graphics.rs:790):

    • Suppose a loop has PHI A (depending on loadInput(in0) on the preheader edge and B on the back-edge) and PHI/value B (depending on A).
    • If value_deps(A) starts first, memo[A] is seeded with {}. When value_deps(A) recurses into B, B reads memo[A] (getting {}), computes B's dependencies without in0, and permanently caches that incomplete set in memo[B].
    • Any output derived from B then omits in0 from dx.viewIdState / PSV0, which causes DXIL validation failures or broken shader-stage linkage / interpolation optimization on drivers.
    • The same happens in block_deps for mutually control-dependent blocks inside loops.
  2. Incomplete memory / control dependencies for Store and Alloca/TGSM loads (graphics.rs:758-771, 843-858)

    • root_stores (graphics.rs:760-762) only records the stored value v — it omits the store's pointer operand p (so an input-dependent array index used to select which slot is written is lost on subsequent loads) AND omits the store's enclosing block control dependency block_deps(store_block) (so a conditional store gated by an input-dependent branch is lost on subsequent loads).
    • block_of is built across all instructions (graphics.rs:755-759) and then explicitly ignored at graphics.rs:858 (let _ = cx.block_of;).

Fix direction

  • Replace the single-pass recursive memoization with a monotone worklist / fixed-point propagation over (value_deps, block_deps) (or Tarjan SCC condensation) so cyclic PHIs and loops converge to the exact union of dependencies without memo poisoning.
  • Include p and block_deps(store_block) in root_stores entries (and for atomics in graphics.rs:763-770) so loads from alloca / TGSM capture pointer-index and control-flow dependencies.

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/1892) Static audit on `main @ 689f2db` found two soundness bugs in `compute_deps()` (`crates/xcl/src/gpu/dxil/graphics.rs:755-861`), which computes the input-to-output dependency tables written into DXIL `dx.viewIdState` metadata and the `PSV0` container part. *(Note: open PR `#1770` preserves the exact same traversal and memoization algorithm, so these bugs apply there too.)* ### Where - `crates/xcl/src/gpu/dxil/graphics.rs:755-861` (`compute_deps`, `block_deps`, `value_deps`) ### Root causes 1. **Memo poisoning on cyclic PHIs and loops (`graphics.rs:786-808, 859`)** To break recursion cycles, `value_deps` inserts an empty `BTreeSet::new()` into `memo` before recursing (`graphics.rs:808`), and `block_deps` does the same for `ctrl_memo` (`graphics.rs:790`): - Suppose a loop has PHI `A` (depending on `loadInput(in0)` on the preheader edge and `B` on the back-edge) and PHI/value `B` (depending on `A`). - If `value_deps(A)` starts first, `memo[A]` is seeded with `{}`. When `value_deps(A)` recurses into `B`, `B` reads `memo[A]` (getting `{}`), computes `B`'s dependencies **without `in0`**, and permanently caches that incomplete set in `memo[B]`. - Any output derived from `B` then omits `in0` from `dx.viewIdState` / `PSV0`, which causes DXIL validation failures or broken shader-stage linkage / interpolation optimization on drivers. - The same happens in `block_deps` for mutually control-dependent blocks inside loops. 2. **Incomplete memory / control dependencies for `Store` and `Alloca`/TGSM loads (`graphics.rs:758-771, 843-858`)** - `root_stores` (`graphics.rs:760-762`) only records the stored value `v` — it omits the store's pointer operand `p` (so an input-dependent array index used to select which slot is written is lost on subsequent loads) AND omits the store's enclosing block control dependency `block_deps(store_block)` (so a conditional store gated by an input-dependent branch is lost on subsequent loads). - `block_of` is built across all instructions (`graphics.rs:755-759`) and then explicitly ignored at `graphics.rs:858` (`let _ = cx.block_of;`). ### Fix direction - Replace the single-pass recursive memoization with a monotone worklist / fixed-point propagation over `(value_deps, block_deps)` (or Tarjan SCC condensation) so cyclic PHIs and loops converge to the exact union of dependencies without memo poisoning. - Include `p` and `block_deps(store_block)` in `root_stores` entries (and for atomics in `graphics.rs:763-770`) so loads from `alloca` / TGSM capture pointer-index and control-flow dependencies. ### 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

@⁠Decodere on GitHub · 2026-11-24 23:55 UTC · original · edited 2026-11-25 00:03 UTC

Stepping back from #1892 in favor of #1966 (just opened) to avoid duplicate/overlapping edits in graphics.rs.

**@⁠Decodere** on GitHub · 2026-11-24 23:55 UTC · [original](https://github.com/xcl-dev/xcl/issues/1892#issuecomment-7147942841) · edited 2026-11-25 00:03 UTC Stepping back from `#1892` in favor of `#1966` (just opened) to avoid duplicate/overlapping edits in `graphics.rs`.
Author
Owner

@⁠JJAutoCompare on GitHub · 2026-11-25 00:51 UTC · original · edited 2026-11-25 01:05 UTC

Standalone CPU regression check for #1892

I reran a local Rust harness using the DXIL graphics code from 6567c5ffa38fbc7039b2d6bf520154689cc1f482 and PR #1966 head 25298fb70155f9b7c724560b7af4455bc9a4a450. Windows 11 build 26200.9974, Ryzen 7 3800X, Rust 1.100.0 MSVC. The two harnesses used the same fixture and matching auxiliary source modules.

  • harness.exe loop ran the PR regression. Main failed with “output B depends on input X through the loop; its inputs: {}” (exit 101). The PR head passed (exit 0).
  • harness.exe memory <out-dir> tests/data/dxil/dxc_vs_control.dxil completed on both heads (exit 0). The existing VS control case produced the same PSV0 bytes as its DXC reference. For a load influenced by an input-dependent write index and for a load influenced by a conditional write, both heads emitted the dependency mask 0b10 in dx.viewIdState and PSV0. These cases expect 0b11 because both outputs depend on the input. The harness printed these masks and did not assert their expected value, hence the successful process exits.

These are harness checks. No Cargo suite, GPU execution, or DXIL validation was run. Test and report prepared with Codex in T3 Code (gpt-6.2-sol).

Cargo and DXC follow-up on #1966

Base 25298fb70155f9b7c724560b7af4455bc9a4a450. The base run added only the two regression tests. The patched runs used the local, uncommitted diff on that same base. SHA-256 of git diff --full-index --binary for the tested patch is f1be92ad2039df7c881954b06e10e02bced44bc7652e648cdd62da7b099d7ce6.

Windows 11 build 26200.9974, Ryzen 7 3800X, Rust 1.100.0 MSVC debug, DXC and DXIL 1.9.2609.5. The isolated checkout, Cargo target and temporary directory were under L:/XclTooling/1892-store-deps with CARGO_BUILD_JOBS=2 and CARGO_INCREMENTAL=0. The draw run used Intel Arc A770 driver 32.0.101.9175 with XCL_ADAPTER=A770.

  • Base plus tests, cargo test -p xcl --lib vs_load_depends_on_store_ -- --nocapture --test-threads=1. 0 passed, 2 failed as expected, 0 ignored, 0 skipped, 967 filtered, exit 101. The input-dependent write index and conditional write each emitted 0b10 in both dx.viewIdState and PSV0.
  • Patched CPU and DXC, cargo test -p xcl --lib gpu::dxil::graphics::tests:: -- --nocapture --test-threads=1 --skip emitted_. 23 passed, 0 failed, 0 ignored, 0 skipped, 946 filtered, exit 0. Both new fixtures asserted 0b11 in both encodings and passed DXC validation. The existing loop and DXC PSV0 comparison regressions passed.
  • Patched Arc draws, & 'L:/XclTooling/Invoke-ArcTest.ps1' -Test { cargo test -p xcl --lib gpu::dxil::graphics::tests::emitted_ -- --nocapture --test-threads=1 }. 4 passed, 0 failed, 0 ignored, 0 skipped, 965 filtered, exit 0. The wrapper acquired and released the Arc lock. It ran with a process-scoped PowerShell execution policy override.

Not tested
GPU execution of the two new fixtures, other adapters, retail shaders, title smoke, and the full workspace suite.

AI use
Codex in T3 Code (gpt-6.2-sol) wrote the local patch and tests, ran them, and prepared this report.

**@⁠JJAutoCompare** on GitHub · 2026-11-25 00:51 UTC · [original](https://github.com/xcl-dev/xcl/issues/1892#issuecomment-7148952256) · edited 2026-11-25 01:05 UTC **Standalone CPU regression check for #1892** I reran a local Rust harness using the DXIL graphics code from `6567c5ffa38fbc7039b2d6bf520154689cc1f482` and PR #1966 head `25298fb70155f9b7c724560b7af4455bc9a4a450`. Windows 11 build `26200.9974`, Ryzen 7 3800X, Rust `1.100.0` MSVC. The two harnesses used the same fixture and matching auxiliary source modules. - `harness.exe loop` ran the PR regression. Main failed with “output B depends on input X through the loop; its inputs: {}” (exit 101). The PR head passed (exit 0). - `harness.exe memory <out-dir> tests/data/dxil/dxc_vs_control.dxil` completed on both heads (exit 0). The existing VS control case produced the same PSV0 bytes as its DXC reference. For a load influenced by an input-dependent write index and for a load influenced by a conditional write, both heads emitted the dependency mask `0b10` in `dx.viewIdState` and PSV0. These cases expect `0b11` because both outputs depend on the input. The harness printed these masks and did not assert their expected value, hence the successful process exits. These are harness checks. No Cargo suite, GPU execution, or DXIL validation was run. Test and report prepared with Codex in T3 Code (`gpt-6.2-sol`). **Cargo and DXC follow-up on #1966** Base `25298fb70155f9b7c724560b7af4455bc9a4a450`. The base run added only the two regression tests. The patched runs used the local, uncommitted diff on that same base. SHA-256 of `git diff --full-index --binary` for the tested patch is `f1be92ad2039df7c881954b06e10e02bced44bc7652e648cdd62da7b099d7ce6`. Windows 11 build `26200.9974`, Ryzen 7 3800X, Rust `1.100.0` MSVC debug, DXC and DXIL `1.9.2609.5`. The isolated checkout, Cargo target and temporary directory were under `L:/XclTooling/1892-store-deps` with `CARGO_BUILD_JOBS=2` and `CARGO_INCREMENTAL=0`. The draw run used Intel Arc A770 driver `32.0.101.9175` with `XCL_ADAPTER=A770`. - Base plus tests, `cargo test -p xcl --lib vs_load_depends_on_store_ -- --nocapture --test-threads=1`. 0 passed, 2 failed as expected, 0 ignored, 0 skipped, 967 filtered, exit 101. The input-dependent write index and conditional write each emitted `0b10` in both `dx.viewIdState` and `PSV0`. - Patched CPU and DXC, `cargo test -p xcl --lib gpu::dxil::graphics::tests:: -- --nocapture --test-threads=1 --skip emitted_`. 23 passed, 0 failed, 0 ignored, 0 skipped, 946 filtered, exit 0. Both new fixtures asserted `0b11` in both encodings and passed DXC validation. The existing loop and DXC PSV0 comparison regressions passed. - Patched Arc draws, `& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test { cargo test -p xcl --lib gpu::dxil::graphics::tests::emitted_ -- --nocapture --test-threads=1 }`. 4 passed, 0 failed, 0 ignored, 0 skipped, 965 filtered, exit 0. The wrapper acquired and released the Arc lock. It ran with a process-scoped PowerShell execution policy override. **Not tested** GPU execution of the two new fixtures, other adapters, retail shaders, title smoke, and the full workspace suite. **AI use** Codex in T3 Code (`gpt-6.2-sol`) wrote the local patch and tests, ran them, and prepared this report.
This discussion has been locked. Commenting is limited to contributors.
No description provided.