Skip to content

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

Open
fixgep wants to merge 2 commits into
xcl-dev:mainfrom
fixgep:fix/dxil-ssa-iterative-read
Open

fixgep wants to merge 2 commits into
xcl-dev:mainfrom
fixgep:fix/dxil-ssa-iterative-read

Conversation

@fixgep

@fixgep fixgep commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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), 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 (driver 32.0.15.9144), AMD Ryzen 5 7500F 6-Core Processor, Windows 10.0.26200.0, rustc 1.100.0 (0ef1bc386 2026-11-09), debug (cargo test) & release (cargo build --release -p xcl).
  • cargo test -p xcl --lib gpu::dxil -- --test-threads=4: 89 passed, 0 failed, 1 ignored (dump_dxc_lowering).
  • cargo test -p xcl --test '*' -- --test-threads=4: 49 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: 1d027e5c76c9a86a7ee2ca1cc677edf0be95d331
gpu: NVIDIA GeForce RTX 3060
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1097 (PresentX 1097)
presents per 2 s (last 3): 60 60 59
device removals: 0
crashes: 0
peak commit: 15401 MB

PR:

xcl-smoke v1
commit: 83af903e3b9324b764eb37cfb443d352c4c913fc
gpu: NVIDIA GeForce RTX 3060
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1141 (PresentX 1141)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 15337 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-gpu::dxil --lib unit tests were not rerun after 83af903 (ran 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, ran the test suites and smoke check, and drafted this PR description.

@vitor127wt

Copy link
Copy Markdown

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 Linux: docs/linux.md, scripts/linux and Wine start-up checks for vkd3d-proton and DXVK (#154, #241) #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.

mastrr9 added a commit to mastrr9/xcl that referenced this pull request Nov 24, 2026
…to ethans-superbuild

dxil/kernel.rs: its test module follows geom_init.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@itsd-effex

Copy link
Copy Markdown

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.

@lewisnic94-max lewisnic94-max left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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 71f2ceb. 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.

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)
@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

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.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
# Conflicts:
#	crates/xcl/src/gpu/dxil/graphics.rs
#	crates/xcl/src/gpu/dxil/kernel.rs
IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
…compact argument

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@CalvyPZ CalvyPZ added the duplicate This issue or pull request already exists label Nov 25, 2026
@CalvyPZ CalvyPZ closed this Nov 25, 2026
@CalvyPZ CalvyPZ removed the duplicate This issue or pull request already exists label Nov 25, 2026
@CalvyPZ CalvyPZ reopened this Nov 25, 2026
@DavidM1911

Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Direct DXIL: xcl pipelines workers overflow their 512 MB stack on big compute programs under Wine

7 participants