Direct DXIL: make Ssa::read iterative to avoid stack overflow (#1805) #1852
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!1852
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1852"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@fixgep on GitHub · 2026-11-24 21:54 UTC · original
fixgep:fix/dxil-ssa-iterative-read→main· +560 −127 · 5 files · 2 commits · openConvert
Ssa::readand sibling CFG/dependency walkers incrates/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 todxil-spirvin #1860, so this PR does not claim to fix #1805).What is in it
crates/xcl/src/gpu/dxil/ssa.rs: convertSsa::readfrom call-stack recursion to an explicit heap-allocated frame stack (Vec), preserving single-predecessor chain caching, loop-phivisitingmarkers, 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 recursiveblock_deps/value_depsincompute_depsto an explicit heap-allocated stack (eval_dep) preservingSets-based loop fixpoint iteration, borrow shared store lists and call arguments via ausizeslice cursor (DepChildren::Values) instead of copying store lists into every liveDepFrame, 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 inis_const_global_ptrwith a loop.Tested
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 inreal.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;SKIPPEDwave64 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:
PR:
Not tested
no wave64on RTX 3060).heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).cargo test --workspaceand non-dxil--libunit tests were not rerun after rebasing ontob49be183(rancargo build --workspace,cargo test -p xcl --lib dxil -- --test-threads=4,cargo test -p xcl --lib gpu::dxil -- --test-threads=4, andcargo test -p xcl --test '*' -- --test-threads=4).AI use
Ssa::read,compute_deps, andis_const_global_ptrto iterative implementations, refactoredcompute_depsload/call traversal to borrow slices with ausizecursor, added the bounded-stack and shared-root load/store regression tests, rebased ontoupstream/main(b49be183) resolving conflicts ingraphics.rsandkernel.rs, ran the tests and smoke checks, and updated this PR description.@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
1d027e5c76c9a86a7ee2ca1cc677edf0be95d331with only their test functions added to the tree, and then on clean PR headc2b1029c224fa279aa83323bf5b42a3684ba5c04.deep_join_chain_does_not_overflow_stackdeep_branch_chain_compiles_on_bounded_stackdeep_region_join_and_loop_phi_preserve_semanticsdeep_phi_deps_do_not_overflow_stackBoth base runs logged
virtual_setup_exception stack overflowand 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
7.3.5-2-cachyos, Proton Experimental 11.0 (experimental-11.0-20261112-x86_64), vkd3d-protonec207194with the #257 patch and dxil-spirv7c048638. Rust 1.100.0, LLVM-MinGW 20261117 (x86_64-pc-windows-gnullvm), DXC 1.9.2609.5.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.
@itsd-effex on GitHub · 2026-11-24 22:47 UTC · original
A note from #1805's reporter: the
Ssa::readsuspicion 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: withssa.rsunchanged 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
@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.
@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-26 00:34 UTC · original
Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current
mainon the new head — needs another rebase before it can be tested.83af903e3bto2a6feac292@fixgep on GitHub · 2026-11-26 04:37 UTC · original
@DavidM1911 Rebased onto
main(b49be183, new HEAD2a6feac2) and resolved the conflicts ingraphics.rsandkernel.rs@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_depsfrom 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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.