Direct DXIL: make compute_deps and is_const_global_ptr iterative (#1805) #1842
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from ivall/xcl. Originally posted by fixgep on 2026-11-24T21:54:11Z.
Make DXIL graphics dependency analysis (
compute_deps) and constant-global-pointer checks (is_const_global_ptr) iterative so deep shader CFGs and load/store chains do not overflow the thread stack.Rebased onto
upstream/main: the redundant productionSsa::readrewrite incrates/xcl/src/gpu/dxil/ssa.rswas dropped in favor of#1844, while keeping the bounded-stack tests and updatingkernel.rsfor3cde0cc.Part of #1805.
What is in it
crates/xcl/src/gpu/dxil/graphics.rs: replace recursivevalue_deps/block_depsincompute_depswith an explicit frame stack (eval_depandDepChildren), borrowingroot_storesslices via aDepChildren::Writescursor instead of cloning store lists per live frame, and preservingSetsopen/close fixpoint iteration.crates/xcl/src/gpu/dxil/module/opt.rs: convertis_const_global_ptrfrom recursion to an iterative loop.crates/xcl/src/gpu/dxil/ssa.rs: keepupstream/main's#1844Ssa::readimplementation; adddeep_join_chain_does_not_overflow_stackanddeep_region_join_and_loop_phi_preserve_semantics.crates/xcl/src/gpu/dxil/graphics_tests.rs: adddeep_phi_deps_do_not_overflow_stackanddeep_shared_root_loads_borrow_store_list_without_quadratic_children.crates/xcl/src/gpu/dxil/kernel.rs: adddeep_branch_chain_compiles_on_bounded_stack(usingVec::new()and0fortranslate_on_this_thread).Tested
XCL_ADAPTER=warp, Windows 11 x64 (stable-x86_64-pc-windows-msvc).cargo build -j 4 --workspace,cargo test -j 4 --workspace --no-run,cargo build -j 4 --release -p xcl: exited 0, 0 new warnings.--test-threads=1):cargo test -j 4 -p xcl --lib gpu::dxil::ssa -- --test-threads=1: 3 passed, 0 failed, 0 ignored (0 skipped)cargo test -j 4 -p xcl --lib gpu::dxil::graphics -- --test-threads=1: 34 passed, 0 failed, 0 ignored (0 skipped)cargo test -j 4 -p xcl --lib gpu::dxil::kernel -- --test-threads=1: 8 passed, 0 failed, 0 ignored (1 skipped:dispatch_chain_native_wave64_builds_whole: no wave64)cargo test -j 4 -p xcl --lib gpu::dxil::module::opt -- --test-threads=1: 24 passed, 0 failed, 0 ignored (0 skipped)XCL_ADAPTER=warp(--test-threads=1):cargo test -j 4 -p xcl --lib gpu::dxil::ssa -- --test-threads=1: 3 passed, 0 failed, 0 ignored (0 skipped)cargo test -j 4 -p xcl --lib gpu::dxil::graphics -- --test-threads=1: 34 passed, 0 failed, 0 ignored (2 skipped:no wave64)cargo test -j 4 -p xcl --lib gpu::dxil::kernel -- --test-threads=1: 8 passed, 0 failed, 0 ignored (3 skipped:no wave32 GPU/no wave64/no wave32)cargo test -j 4 -p xcl --lib gpu::dxil::module::opt -- --test-threads=1: 24 passed, 0 failed, 0 ignored (1 skipped:no wave32)Regression run
Not tested
cargo test --workspace) and native wave64 GPU execution (no wave64 hardware on this machine).AI use
upstream/main, dropped redundantssa.rsSsa::readrewrite in favor of#1844, adaptedDepChildren::Writesforroot_stores(Vec<Value>, usize)entries andkernel.rstest arguments, ran builds, targeted tests, and smoke runs.Imported from ivall/xcl. Originally posted by lewisnic94-max on 2026-11-24T22:50:28Z.
Review: COMMENTED
[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.
Imported from ivall/xcl. Originally posted by vitor127wt on 2026-11-24T22:25:10Z.
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.
Imported from ivall/xcl. Originally posted by itsd-effex on 2026-11-24T22:47:02Z.
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
Imported from ivall/xcl. Originally posted by throny on 2026-11-25T01:02:00Z.
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.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T01:28:44Z.
Verification on RTX 3060 Ti (Windows 11): merge conflict with current
main— needs a rebase before it can be tested.Imported from ivall/xcl. Originally posted by CalvyPZ on 2026-11-25T22:43:15Z.
This PR has been marked as a duplicate and closed after multiple agreeing checks in #1607. If you believe this is incorrect please re-open with why.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T00:34:57Z.
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.Imported from ivall/xcl. Originally posted by fixgep on 2026-11-26T04:37:54Z.
@DavidM1911 Rebased onto
main(b49be183, new HEAD2a6feac2) and resolved the conflicts ingraphics.rsandkernel.rsImported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T00:55:26Z.
merge-check
base:
fa204595a4head:
2a6feac292merge: clean as text (trial merge fa9e8773a02e15d0d153a5ebd8f0139903c8bcb8, local, not pushed;
git diff --checkclean), but it does not build as a test on current main (see tests)build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 (XCL_DXC_DIR = DXC 1.9.2609) on the merge as it is -> lib test target fails to compile:
error[E0425]: cannot find value TABLE_WORDS_WAVE32 in module crate::gpu::dxil::compactatkernel.rs:1436. The newdeep_branch_chain_compiles_on_bounded_stackpassescompact::TABLE_WORDS_WAVE32as the last argument oftranslate_on_this_thread; main3cde0cc3("Recompiler: use larger compact tables on every GPU") removed that constant and the parameter is nowrodata: Vec<(u32, Vec<u32>)>. With that one argument changed toVec::new()locally (6294eda7, not pushed) -> 2613 passed, 0 failed, 49 ignored; SKIPPED: 26 (21 no wave64 on this 32-lane GPU, 3 per-lane f16/f32 forms refused (#1426 semantics), 2 no heap windows); failing: none. All five new tests ran and passed:ssa::tests::deep_join_chain_does_not_overflow_stack,ssa::tests::deep_region_join_and_loop_phi_preserve_semantics,graphics::tests::deep_phi_deps_do_not_overflow_stack,graphics::tests::deep_shared_root_loads_borrow_store_list_without_quadratic_children,kernel::tests::deep_branch_chain_compiles_on_bounded_stack. I did not check that they overflow without the change.review: whole diff read (ssa.rs, graphics.rs, graphics_tests.rs, kernel.rs, module/opt.rs). Only blocker: the stale test call above.
Ssa::readas an explicit frame stack matches main's recursion: same cache lookups, predecessor order, visiting marker, and trivial-phi removal.eval_depincompute_depsmatches the oldblock_deps/value_depspair: children are visited in the same order (block: each ctrl edge's cond, then the edge block if it is not itself; loadInput: the row value only when the row is not constant, after the row components; other calls: args; phi: value, incoming block, its cond; load: pointer, then the root's stores; other: operands).Sets::known/open/closehappen at the same points, and a non-instruction value still returns an empty set without touchingSets. Calls and loads borrow their argument / store slices instead of copying them, so live child storage stays linear (the new peak-children test checks this).is_const_global_ptras a loop is equivalent. Context: #1607 group D70 lists #1844 (same goal, a different approach) as a duplicate, and #1805's crash was traced to dxil-spirv (#1860), so this PR alone may not close #1805.performance: no default cost expected: the same work in the same order, with heap frames instead of stack frames. Not measured. No title run, because the merge does not build its tests on main; the head will change.
verdict: not yet: the new kernel test does not compile on current main (TABLE_WORDS_WAVE32 was removed by
3cde0cc3); rebase and passVec::new()(rodata) instead. With that change the suite passes here and I found no other issue.hardware / tool and model: NVIDIA GeForce RTX 5070 Ti 16 GB (driver 610.74, wave32 only), AMD Ryzen 9 9950X, Windows 11 build 26200; rustc 1.99.0, debug test profile, DXC 1.9.2609 via XCL_DXC_DIR. Claude Code, Claude Opus 5.5: merge, build, suite and full-diff review; this report.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:59:36Z.
Triage (#1607) – head
1fbdea9After the rebase (
1fbdea91) thessa.rspart only adds a deep-join test;Ssa::readitself is main's (#1844). The commit is still titled "make Ssa::read iterative", which no longer matches what it changes. The rest is not on main:compute_depsingraphics.rs(block_deps/value_depsare still recursive there), the loop inmodule/opt.rsis_const_global_ptr, and the bounded-stack tests. The explicit-stackeval_depkeeps the old child order and theSetsopen/close fixpoint. #1860 takes a different approach (one back edge per loop head for dxil-spirv) and is not a duplicate. The branch now merges cleanly into main.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by fixgep on 2026-12-01T16:46:10Z.
Thanks
@Foniassand@Kalmarv! Rebased ontoupstream/main(6bfb5c51):Ssa::readrewrite incrates/xcl/src/gpu/dxil/ssa.rsin favor of#1844, while keeping the two bounded-stack tests (deep_join_chain_does_not_overflow_stackanddeep_region_join_and_loop_phi_preserve_semantics).eval_depingraphics.rsforupstream/main's(Vec<Value>, usize)root_storesentries (borrowing viaDepChildren::Writesand handlingInstInfo::Atomic).deep_branch_chain_compiles_on_bounded_stackinkernel.rsfrom the removedcompact::TABLE_WORDS_WAVE32toVec::new()(and0forps_rt32_mask).smoke.ps1runs.Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-01T16:59:32Z.
merge-check
base:
6bfb5c5153head:
1fbdea91a5merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2909 passed, 0 failed, 51 ignored (base: 2904); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as base; failing: none from this PR. The counts are the lib binary's clean run (2761 passed, 0 failed, 31 ignored) plus the other binaries (148 passed, 0 failed, 20 ignored). How the runs went:
eh::tests::thread_dumps_while_threads_run_and_exit(after 7 and 5 of its 40 dumps). That is #3586: it is on main too, and this PR does not toucheh.rs.title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels("superseded unaligned extra_pages must be reclaimed immediately", a device-wide page count), plus 3 tests of that module poisoned by the sharedTEST_LOCK.review: read the whole diff (5 files, +463 -74). No correctness problem found.
compute_deps: the explicit frame stack visits children in the same order as the oldblock_deps/value_depsrecursion:It calls
Sets::known/open/closeat the same points, so cuts and fixpoint passes are unchanged.Writesborrows the store lists instead of copying them.is_const_global_ptr: the loop returns the same answers as the recursion.graphics.rsandopt.rswith the PR's tests (plus a shim forcompute_deps_with_peak).gpu::dxil::graphics::tests::deep_phi_deps_do_not_overflow_stackanddeep_shared_root_loads_borrow_store_list_without_quadratic_childreneach abort with "has overflowed its stack" on their 2 MiB thread. Good.ssa::tests::deep_join_chain_does_not_overflow_stack,ssa::tests::deep_region_join_and_loop_phi_preserve_semanticsandkernel::tests::deep_branch_chain_compiles_on_bounded_stack. They guard #1844's iterativeSsa::read, already on main, not this PR's code. No test reaches a deep GEP chain inis_const_global_ptr.Ssa::read; it changescompute_deps.performance: not measured. The same work per node, with frames on the heap instead of the stack.
peak_childrenis counted on every call, including in production, which is a few additions.verdict: safe to merge
hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)
Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T08:07:09Z.
merge-check
base:
1c8b551475head:
1fbdea91a5merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2913 passed, 1 failed, 51 ignored; SKIPPED: 28 (22 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 2 no heap windows, 1 cannot disable the driver cache / Windows Developer Mode required); failing: tests/gpu_two_pass_cache_e2e.rs :: two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (pre-existing on clean base
1c8b5514: 2908 passed, 1 failed, 51 ignored, identical 28 SKIPPED). All 5 new bounded-stack tests pass (+5 vs base).review: Full merged diff read (5 files, +463/-74). No blocking findings. eval_dep in graphics.rs preserves the exact visit order and Sets::{known, open, close} fixpoint semantics of recursive block_deps/value_deps with zero-copy DepChildren::{Values, Writes} cursors so shared-root load/store graphs avoid quadratic child storage, and is_const_global_ptr in module/opt.rs is an exact iterative equivalent. Minor non-blocking notes: commit 1's subject still mentions Ssa::read although ssa.rs only adds tests here (iterative Ssa::read is already on main), and open PR #3646 also rewrites graphics.rs::compute_deps. Untested: AMD/native wave64 GPUs, D3D12 debug layer, and retail smoke (Tier 1 compiler pass, not required by TESTING.md).
performance: Negligible on normal shaders; replaces call-stack recursion with a heap Vec frame stack and zero-copy borrowed slices for Call/Load children, preventing stack overflow on deep CFGs without quadratic child copies (reasoned; linear peak_live_children verified by unit test).
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 4060 8 GB (driver 621.40), Intel Core i5-11400F, 32 GB RAM, Windows 11 Build 26200, Rust 1.100.1 MSVC, DXC 1.9.2602.17 / Antigravity (Gemini 4 Neon)
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.