Direct DXIL: make Ssa::read iterative to avoid stack overflow (#1805) #1852

Open
github-bot wants to merge 2 commits from github-bot/gh-1852 into main AGit
Owner

@⁠fixgep on GitHub · 2026-11-24 21:54 UTC · original
fixgep:fix/dxil-ssa-iterative-read → main · +560 −127 · 5 files · 2 commits · open

Convert Ssa::read and sibling CFG/dependency walkers in crates/xcl/src/gpu/dxil/ from call-stack recursion to explicit heap-allocated worklists/loops so large shaders with long chains of join blocks or memory dependencies do not overflow bounded thread stacks. This is bounded-stack hardening motivated by #1805 (the retail crash reported in #1805 was separately traced to dxil-spirv in #1860, so this PR does not claim to fix #1805).

What is in it

  • crates/xcl/src/gpu/dxil/ssa.rs: convert Ssa::read from call-stack recursion to an explicit heap-allocated frame stack (Vec), preserving single-predecessor chain caching, loop-phi visiting markers, operand ordering, and trivial-phi elimination; add bounded-stack (2 MiB) synthetic tests for 4,000 sequential if/else diamonds and 3,000 region joins with a loop phi.
  • crates/xcl/src/gpu/dxil/kernel.rs: add a bounded-stack (2 MiB) full direct-DXIL compile test (deep_branch_chain_compiles_on_bounded_stack) with 4,000 sequential conditional branches.
  • crates/xcl/src/gpu/dxil/graphics.rs, crates/xcl/src/gpu/dxil/graphics_tests.rs: convert mutually recursive block_deps / value_deps in compute_deps to an explicit heap-allocated stack (eval_dep) preserving Sets-based loop fixpoint iteration, borrow shared store lists and call arguments via a usize slice cursor (DepChildren::Values) instead of copying store lists into every live DepFrame, and add bounded-stack (2 MiB) synthetic tests for a 4,000-phi dependency chain and a 1,024-step shared-root load/store chain asserting linear live child storage (peak_live_children).
  • crates/xcl/src/gpu/dxil/module/opt.rs: replace tail recursion in is_const_global_ptr with a loop.

Tested

  • Hardware & toolchain: NVIDIA GeForce RTX 3060, rustc 1.100.0 (0ef1bc386 2026-11-09), Windows, debug (cargo test) & release (cargo build --release -p xcl).
  • cargo build --workspace: built cleanly with 0 new warnings (3 pre-existing warnings in real.rs, xgameruntime/mod.rs, vram.rs).
  • cargo test -p xcl --lib dxil -- --test-threads=4: 224 passed, 0 failed, 3 ignored (dump_dxc_lowering, amd_reduced_seeds, debug_seed; SKIPPED wave64 and unsupported-f16 GPU sub-cases on RTX 3060).
  • cargo test -p xcl --lib gpu::dxil -- --test-threads=4: 189 passed, 0 failed, 3 ignored (dump_dxc_lowering, amd_reduced_seeds, debug_seed; SKIPPED dispatch_chain_native_wave64_builds_whole: no wave64).
  • cargo test -p xcl --test '*' -- --test-threads=4: 126 passed, 0 failed, 20 ignored (SKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows).
  • cargo build --release -p xcl: built cleanly with 0 new warnings.

Regression run

main:


xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 3060
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1470 (PresentX 1470)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13928 MB

PR:


xcl-smoke v1
commit: 2a6feac29252a49af8553ed459f71b00883cde6d
gpu: NVIDIA GeForce RTX 3060
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1439 (PresentX 1439)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14324 MB

Not tested

  • AMD GPUs and native wave64 hardware (no wave64 on RTX 3060).
  • heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • Full cargo test --workspace and non-dxil --lib unit tests were not rerun after rebasing onto b49be183 (ran cargo build --workspace, cargo test -p xcl --lib dxil -- --test-threads=4, cargo test -p xcl --lib gpu::dxil -- --test-threads=4, and cargo test -p xcl --test '*' -- --test-threads=4).

AI use

  • Antigravity (Gemini 4 Hydrogen): converted Ssa::read, compute_deps, and is_const_global_ptr to iterative implementations, refactored compute_deps load/call traversal to borrow slices with a usize cursor, added the bounded-stack and shared-root load/store regression tests, rebased onto upstream/main (b49be183) resolving conflicts in graphics.rs and kernel.rs, ran the tests and smoke checks, and updated this PR description.
**@⁠fixgep** on GitHub · 2026-11-24 21:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/1852) `fixgep:fix/dxil-ssa-iterative-read` → `main` · +560 −127 · 5 files · 2 commits · open Convert `Ssa::read` and sibling CFG/dependency walkers in `crates/xcl/src/gpu/dxil/` from call-stack recursion to explicit heap-allocated worklists/loops so large shaders with long chains of join blocks or memory dependencies do not overflow bounded thread stacks. This is bounded-stack hardening motivated by #1805 (the retail crash reported in #1805 was separately traced to `dxil-spirv` in #1860, so this PR does not claim to fix #1805). **What is in it** - `crates/xcl/src/gpu/dxil/ssa.rs`: convert `Ssa::read` from call-stack recursion to an explicit heap-allocated frame stack (`Vec`), preserving single-predecessor chain caching, loop-phi `visiting` markers, operand ordering, and trivial-phi elimination; add bounded-stack (2 MiB) synthetic tests for 4,000 sequential if/else diamonds and 3,000 region joins with a loop phi. - `crates/xcl/src/gpu/dxil/kernel.rs`: add a bounded-stack (2 MiB) full direct-DXIL compile test (`deep_branch_chain_compiles_on_bounded_stack`) with 4,000 sequential conditional branches. - `crates/xcl/src/gpu/dxil/graphics.rs`, `crates/xcl/src/gpu/dxil/graphics_tests.rs`: convert mutually recursive `block_deps` / `value_deps` in `compute_deps` to an explicit heap-allocated stack (`eval_dep`) preserving `Sets`-based loop fixpoint iteration, borrow shared store lists and call arguments via a `usize` slice cursor (`DepChildren::Values`) instead of copying store lists into every live `DepFrame`, and add bounded-stack (2 MiB) synthetic tests for a 4,000-phi dependency chain and a 1,024-step shared-root load/store chain asserting linear live child storage (`peak_live_children`). - `crates/xcl/src/gpu/dxil/module/opt.rs`: replace tail recursion in `is_const_global_ptr` with a loop. **Tested** - Hardware & toolchain: NVIDIA GeForce RTX 3060, `rustc 1.100.0 (0ef1bc386 2026-11-09)`, Windows, debug (`cargo test`) & release (`cargo build --release -p xcl`). - `cargo build --workspace`: built cleanly with 0 new warnings (3 pre-existing warnings in `real.rs`, `xgameruntime/mod.rs`, `vram.rs`). - `cargo test -p xcl --lib dxil -- --test-threads=4`: 224 passed, 0 failed, 3 ignored (`dump_dxc_lowering`, `amd_reduced_seeds`, `debug_seed`; `SKIPPED` wave64 and unsupported-f16 GPU sub-cases on RTX 3060). - `cargo test -p xcl --lib gpu::dxil -- --test-threads=4`: 189 passed, 0 failed, 3 ignored (`dump_dxc_lowering`, `amd_reduced_seeds`, `debug_seed`; `SKIPPED dispatch_chain_native_wave64_builds_whole: no wave64`). - `cargo test -p xcl --test '*' -- --test-threads=4`: 126 passed, 0 failed, 20 ignored (`SKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows`). - `cargo build --release -p xcl`: built cleanly with 0 new warnings. **Regression run** main: ``` xcl-smoke v1 commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 gpu: NVIDIA GeForce RTX 3060 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1470 (PresentX 1470) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 13928 MB ``` PR: ``` xcl-smoke v1 commit: 2a6feac29252a49af8553ed459f71b00883cde6d gpu: NVIDIA GeForce RTX 3060 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1439 (PresentX 1439) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14324 MB ``` **Not tested** - AMD GPUs and native wave64 hardware (`no wave64` on RTX 3060). - `heap_window_out_of_memory_falls_back_to_the_switch_form` (`no heap windows`). - Full `cargo test --workspace` and non-`dxil` `--lib` unit tests were not rerun after rebasing onto `b49be183` (ran `cargo build --workspace`, `cargo test -p xcl --lib dxil -- --test-threads=4`, `cargo test -p xcl --lib gpu::dxil -- --test-threads=4`, and `cargo test -p xcl --test '*' -- --test-threads=4`). **AI use** - Antigravity (Gemini 4 Hydrogen): converted `Ssa::read`, `compute_deps`, and `is_const_global_ptr` to iterative implementations, refactored `compute_deps` load/call traversal to borrow slices with a `usize` cursor, added the bounded-stack and shared-root load/store regression tests, rebased onto `upstream/main` (`b49be183`) resolving conflicts in `graphics.rs` and `kernel.rs`, ran the tests and smoke checks, and updated this PR description.
Part of #1805.

Assisted-by: Antigravity (Gemini 4 Hydrogen)
Avoid cloning the per-root store list into every live DepFrame in eval_dep by borrowing the shared slice with a usize cursor, preventing quadratic child storage on deep load/store chains.

Assisted-by: Antigravity (Gemini 4 Hydrogen)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:07:16 +00:00
Author
Owner

@⁠vitor127wt on GitHub · 2026-11-24 22:25 UTC · original

Independent bounded-stack tests on Proton / Wine

I ran the two published 2 MiB stack cases individually on base 1d027e5c76c9a86a7ee2ca1cc677edf0be95d331 with only their test functions added to the tree, and then on clean PR head c2b1029c224fa279aa83323bf5b42a3684ba5c04.

Test Base with test only PR
deep_join_chain_does_not_overflow_stack Wine stack overflow, test failed Passed
deep_branch_chain_compiles_on_bounded_stack Wine stack overflow, test failed Passed
deep_region_join_and_loop_phi_preserve_semantics — Passed
deep_phi_deps_do_not_overflow_stack — Passed

Both base runs logged virtual_setup_exception stack overflow and returned test-harness status 101. Totals across separate processes were 0 passed / 2 failed on the base and 4 passed / 0 failed on the PR, with zero ignored or skipped in these filtered runs.

Tested

  • RTX 5070 Ti 16 GB, NVIDIA 620.73.04, Ryzen 7 9700X, 32 GB DDR5, CachyOS 7.3.5-2-cachyos, Proton Experimental 11.0 (experimental-11.0-20261112-x86_64), vkd3d-proton ec207194 with the #257 patch and dxil-spirv 7c048638. Rust 1.100.0, LLVM-MinGW 20261117 (x86_64-pc-windows-gnullvm), DXC 1.9.2609.5.
  • Debug library test binaries from cargo test --locked --target x86_64-pc-windows-gnullvm -p xcl --lib --no-run. Ran each filter under Wine with --exact --test-threads=1 --nocapture.

These results cover the synthetic compiler tests on this PR. The retail replay was made with #759 to reproduce the worker loss separately. Retail reproduction on #1805

AI use — OpenAI Codex (GPT-6, exact variant unavailable) ran the tests, checked the logs, and drafted this report.

**@⁠vitor127wt** on GitHub · 2026-11-24 22:25 UTC · [original](https://github.com/xcl-dev/xcl/pull/1852#issuecomment-7146205501) **Independent bounded-stack tests on Proton / Wine** I ran the two published 2 MiB stack cases individually on base `1d027e5c76c9a86a7ee2ca1cc677edf0be95d331` with only their test functions added to the tree, and then on clean PR head `c2b1029c224fa279aa83323bf5b42a3684ba5c04`. | Test | Base with test only | PR | | --- | --- | --- | | `deep_join_chain_does_not_overflow_stack` | Wine stack overflow, test failed | Passed | | `deep_branch_chain_compiles_on_bounded_stack` | Wine stack overflow, test failed | Passed | | `deep_region_join_and_loop_phi_preserve_semantics` | — | Passed | | `deep_phi_deps_do_not_overflow_stack` | — | Passed | Both base runs logged `virtual_setup_exception stack overflow` and returned test-harness status 101. Totals across separate processes were **0 passed / 2 failed** on the base and **4 passed / 0 failed** on the PR, with zero ignored or skipped in these filtered runs. **Tested** - RTX 5070 Ti 16 GB, NVIDIA 620.73.04, Ryzen 7 9700X, 32 GB DDR5, CachyOS `7.3.5-2-cachyos`, Proton Experimental 11.0 (`experimental-11.0-20261112-x86_64`), vkd3d-proton `ec207194` with the #257 patch and dxil-spirv `7c048638`. Rust 1.100.0, LLVM-MinGW 20261117 (`x86_64-pc-windows-gnullvm`), DXC 1.9.2609.5. - Debug library test binaries from `cargo test --locked --target x86_64-pc-windows-gnullvm -p xcl --lib --no-run`. Ran each filter under Wine with `--exact --test-threads=1 --nocapture`. These results cover the synthetic compiler tests on this PR. The retail replay was made with #759 to reproduce the worker loss separately. [Retail reproduction on #1805](https://git.gtahub.st/github/xcl-dev--xcl/issues/1805) **AI use** — OpenAI Codex (GPT-6, exact variant unavailable) ran the tests, checked the logs, and drafted this report.
Author
Owner

@⁠itsd-effex on GitHub · 2026-11-24 22:47 UTC · original

A note from #1805's reporter: the Ssa::read suspicion in #1805's description was mine and is withdrawn. The retail crash there is in dxil-spirv (Royalflamejlh's analysis on #1805), and #1860 alone fixes it: with ssa.rs unchanged and dxil-spirv unpatched, the 21 retail pipelines that killed workers all build (test), against 0 of 21 without it. So this PR doesn't fix #1805's crash as far as I can tell. The deep-join recursion it removes is real on small stacks (vitor127wt's 2 MiB runs), so it may still be worth having as hardening. I haven't tested this PR against those 21. Sorry for the misdirection.

AI use

  • Claude Code (Claude Opus 5.5) wrote this comment.
**@⁠itsd-effex** on GitHub · 2026-11-24 22:47 UTC · [original](https://github.com/xcl-dev/xcl/pull/1852#issuecomment-7146639628) A note from #1805's reporter: the `Ssa::read` suspicion in #1805's description was mine and is withdrawn. The retail crash there is in dxil-spirv (Royalflamejlh's analysis on #1805), and #1860 alone fixes it: with `ssa.rs` unchanged and dxil-spirv unpatched, the 21 retail pipelines that killed workers all build ([test](https://git.gtahub.st/github/xcl-dev--xcl/pulls/1860)), against 0 of 21 without it. So this PR doesn't fix #1805's crash as far as I can tell. The deep-join recursion it removes is real on small stacks (vitor127wt's 2 MiB runs), so it may still be worth having as hardening. I haven't tested this PR against those 21. Sorry for the misdirection. **AI use** - Claude Code (Claude Opus 5.5) wrote this comment.
Author
Owner

@⁠throny on GitHub · 2026-11-25 01:02 UTC · original

Two contributors checked independently and found that #1844 solves the same problem (for #1805) in a different way: #1607, group D70. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

**@⁠throny** on GitHub · 2026-11-25 01:02 UTC · [original](https://github.com/xcl-dev/xcl/pull/1852#issuecomment-7149136606) <!-- xcl-1607-hint:D70 --> Two contributors checked independently and found that #1844 solves the same problem (for #1805) in a different way: #1607, group D70. You may want to compare them with the other author and agree on one, or say in the PR why both are needed. This is a hint from the community triage in #1607, not a maintainer decision. AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 01:28 UTC · original

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

**@⁠DavidM1911** on GitHub · 2026-11-25 01:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/1852#issuecomment-7149591542) Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 00:34 UTC · original

Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current main on the new head — needs another rebase before it can be tested.

**@⁠DavidM1911** on GitHub · 2026-11-26 00:34 UTC · [original](https://github.com/xcl-dev/xcl/pull/1852#issuecomment-7178905370) Re-verification on RTX 3060 Ti (Windows 11): still a **merge conflict with current `main`** on the new head — needs another rebase before it can be tested.
github-bot force-pushed github-bot/gh-1852 from 83af903e3b to 2a6feac292 2026-11-26 06:16:14 +00:00 Compare
Author
Owner

@⁠fixgep on GitHub · 2026-11-26 04:37 UTC · original

@⁠DavidM1911 Rebased onto main (b49be183, new HEAD 2a6feac2) and resolved the conflicts in graphics.rs and kernel.rs

**@⁠fixgep** on GitHub · 2026-11-26 04:37 UTC · [original](https://github.com/xcl-dev/xcl/pull/1852#issuecomment-7182762602) @⁠DavidM1911 Rebased onto `main` (`b49be183`, new HEAD `2a6feac2`) and resolved the conflicts in `graphics.rs` and `kernel.rs`
Author
Owner

@⁠lewisnic94-max on GitHub · 2026-11-24 22:50 UTC · original · reviewed

[P2] Excessive dependency walker memory allocation

At line 868, each pending load copies the full store list for its pointer root. A 1,024-step pixel shader retained 1,050,625 copied entries.

Borrowing the list preserved traversal depth and byte-identical DXIL while reducing median additional peak commit inside compute_deps from 16.621 to 0.727 MiB across seven release runs.

Please keep a cursor into the shared list and add a regression test for live child storage.

AI-assisted validation by Codex (GPT-6).

Independent follow-up

Reviewed commit c2b1029c224fa279aa83323bf5b42a3684ba5c04.

On a 1,024-step synthetic pixel shader, seven paired release runs measured median additional peak process commit inside compute_deps of 16.691 MiB with the copying walk (16.617–16.703 MiB) and 0.723 MiB with a borrowed list (0.715–0.789 MiB). Frame-array capacity stayed at 393,216 bytes. Live child-vector capacity fell from 16,891,936 to 131,136 bytes, with 1,050,625 store entries copied versus zero. All 14 translations had the same DXIL SHA-256, abd199f5003ece1b194be93660c8a0b84a63981e55a9c42e9ad9392fb1903fc9. The readout brackets the dependency pass and excludes subsequent DXC work.

The normal review build gave 16.531 MiB median against 0.832 MiB for #1844 at 71f2ceb5a0. Both heads passed the 4,000-join shader on a 2 MiB stack and all 24 seeded GPU draws per head. The stack improvement and child-storage regression can be addressed independently. In crates/xcl/src/gpu/dxil/graphics.rs:868, keep a cursor over the shared store list and add a test that bounds live child storage while preserving the DXIL.

Windows 11 x64, Ryzen 7 5800X, GeForce RTX 3080 (616.92), Rust 1.100.0 MSVC and DXC 1.9.2602.17. No runtime skips in those draw trials. Measurements are process commit deltas and instrumented capacities on a synthetic workload. Retail performance was not measured.

AI assistance: OpenAI Codex (GPT-6) inspected the implementation, analyzed the synthetic test evidence and drafted this review.

**@⁠lewisnic94-max** on GitHub · 2026-11-24 22:50 UTC · [original](https://github.com/xcl-dev/xcl/pull/1852#pullrequestreview-6048634203) · **reviewed** **[P2] Excessive dependency walker memory allocation** At line 868, each pending load copies the full store list for its pointer root. A 1,024-step pixel shader retained 1,050,625 copied entries. Borrowing the list preserved traversal depth and byte-identical DXIL while reducing median additional peak commit inside `compute_deps` from 16.621 to 0.727 MiB across seven release runs. Please keep a cursor into the shared list and add a regression test for live child storage. AI-assisted validation by Codex (GPT-6). **Independent follow-up** Reviewed commit `c2b1029c224fa279aa83323bf5b42a3684ba5c04`. On a 1,024-step synthetic pixel shader, seven paired release runs measured median additional peak process commit inside compute_deps of 16.691 MiB with the copying walk (16.617–16.703 MiB) and 0.723 MiB with a borrowed list (0.715–0.789 MiB). Frame-array capacity stayed at 393,216 bytes. Live child-vector capacity fell from 16,891,936 to 131,136 bytes, with 1,050,625 store entries copied versus zero. All 14 translations had the same DXIL SHA-256, abd199f5003ece1b194be93660c8a0b84a63981e55a9c42e9ad9392fb1903fc9. The readout brackets the dependency pass and excludes subsequent DXC work. The normal review build gave 16.531 MiB median against 0.832 MiB for #1844 at 71f2ceb5a05951f8d3d1f6aebe92c13eec240317. Both heads passed the 4,000-join shader on a 2 MiB stack and all 24 seeded GPU draws per head. The stack improvement and child-storage regression can be addressed independently. In crates/xcl/src/gpu/dxil/graphics.rs:868, keep a cursor over the shared store list and add a test that bounds live child storage while preserving the DXIL. Windows 11 x64, Ryzen 7 5800X, GeForce RTX 3080 (616.92), Rust 1.100.0 MSVC and DXC 1.9.2602.17. No runtime skips in those draw trials. Measurements are process commit deltas and instrumented capacities on a synthetic workload. Retail performance was not measured. AI assistance: OpenAI Codex (GPT-6) inspected the implementation, analyzed the synthetic test evidence and drafted this review.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1852/head:github-bot/gh-1852'
git switch 'github-bot/gh-1852'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1852'
git switch 'github-bot/gh-1852'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1852'
git switch 'github-bot/gh-1852'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1852'
git switch 'main'
git merge --squash 'github-bot/gh-1852'
git switch 'main'
git merge --ff-only 'github-bot/gh-1852'
git switch 'main'
git merge 'github-bot/gh-1852'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.