Skip to content

Shaders: resolve deep DXIL SSA joins without recursion - #1844

Open
gloger2003 wants to merge 1 commit into
xcl-dev:mainfrom
gloger2003:fix/dxil-iterative-ssa-joins
Open

gloger2003 wants to merge 1 commit into
xcl-dev:mainfrom
gloger2003:fix/dxil-iterative-ssa-joins

Conversation

@gloger2003

@gloger2003 gloger2003 commented Nov 24, 2026 •

Copy link
Copy Markdown

Part of #1805. The direct DXIL SSA reader could exhaust a worker stack when resolving a definition across many sealed control-flow joins. A synthetic chain of 8,192 joins reproduces the overflow on a 256 KiB stack.

What is in it

  • Walk pending joins on an explicit stack. Keep predecessor order, cached reads and lazy phi creation on loop backedges.
  • Add a regression test for the deep chain with identical incoming values.

Tested

  • Windows x64, Ryzen 7 5700X, Radeon RX 7800 XT.

  • cargo build --offline --locked --release -p xcl on the baseline and this head.

  • cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --show-output. 958 reported passed, 0 failed, 42 ignored. Runtime GPU skips: 7 (gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's)), gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's)), gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's)), gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's)), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's)), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's)), heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows).

  • gpu_scalar_loop_and_scc with XCL_DIRECT_DXIL=1 and XCL_REQUIRE_GPU=wave64. One passed.

  • The new test overflowed before the patch and passed with it.

  • Supplemental integration on main 689f2db plus this patch (cc07eac), RX 7800 XT. DXIL suite: 100 passed, one failed, three ignored. The new deep-join test passed. The failure was seed 722 in fuzz_validate_and_gpu_1. A targeted run on clean 689f2db reproduced the same mismatch at output 30. The GPU scalar-loop and divergent-execution tests both passed with XCL_DIRECT_DXIL=1 and XCL_REQUIRE_GPU=wave64.

Regression run

Minecraft Preview, 30 seconds per build with matching settings and the default shader path.

xcl-smoke v1
commit: 177cd407e0114bd087622ae0c358fb3ba7e97484
gpu: AMD Radeon RX 7800 XT
title: c22a3829
seconds: 30
exit: 0x0
frames shown: 1588 (PresentX 1588)
presents per 2 s (last 3): 120 120 120
device removals: 0
crashes: 0
peak commit: 3380 MB
xcl-smoke v1
commit: 71f2ceb5a05951f8d3d1f6aebe92c13eec240317
gpu: AMD Radeon RX 7800 XT
title: c22a3829
seconds: 30
exit: 0x0
frames shown: 1640 (PresentX 1640)
presents per 2 s (last 3): 120 120 120
device removals: 0
crashes: 0
peak commit: 3359 MB

Not tested

The title and Wine setup reported in #1805.

AI use

OpenAI Codex (GPT-6.2 Sol, high reasoning effort, Fast mode) wrote the code and regression test, ran the checks and drafted this description.

Walk pending joins on a heap-backed stack while preserving lazy phi creation and predecessor order. A synthetic test covers 8192 joins on a 256 KiB thread stack.

Assisted-by: OpenAI Codex (GPT-6.2 Sol, high reasoning effort, Fast mode)
@frenziedcoder

Copy link
Copy Markdown

NVIDIA test report for 71f2ceb: full suite green, its own test deep_joins_read_on_a_small_stack passes, and a clean smoke pair on the retail title (1654 vs 1655 frames).

Tested

  • NVIDIA GeForce RTX 5080 16 GB (driver 617.14, 32-lane waves), AMD Ryzen 7 9800X3D, 64 GB, Windows 11 Pro 25H2 (26200.9974), rustc 1.100.0 stable-x86_64-pc-windows-msvc, DXC 1.8.2502.11 (SDK 10.0.26100.0). Exact head 71f2ceb5a05951f8d3d1f6aebe92c13eec240317, no local changes.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 (debug): 958 passed, 0 failed, 42 ignored; the PR's own test deep_joins_read_on_a_small_stack passes. SKIPPED: gpu::recomp::lower::tests::a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu (no wave64), gpu::recomp::lower::tests::coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu (no wave64), gpu::recomp::lower::tests::cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu (no wave64), gpu::recomp::lower::tests::the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu (no wave64), gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu (no wave64), gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu (f16 arithmetic, wave64: no wave64), gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu (f16 packed, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 arithmetic, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 compares, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 conversions, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 rounding, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 three-source, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 transcendentals, wave64: no wave64), gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu (f64, wave64: no wave64), gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu (integer arithmetic, wave64: no wave64), gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu (integer carries, wave64: no wave64), gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • test_title_draws_with_a_root_signature_under_the_debug_layer reports ok, but this machine has no D3D12 debug layer (debug layer requested but unavailable … (0x887A002D)), so it ran without the layer and is no evidence either way.

Regression run (scripts/smoke.ps1 -Seconds 60, release, the retail title of #505 at its start screen; XCL_PSO_PRELOAD=0 for both builds, because this machine's preload list holds the program of #1307)

base (177cd40, this PR's merge base with main):

xcl-smoke v1
commit: 177cd407e0114bd087622ae0c358fb3ba7e97484
gpu: NVIDIA GeForce RTX 5080
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 1655 (PresentX 1655)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14599 MB

this PR:

xcl-smoke v1
commit: 71f2ceb5a05951f8d3d1f6aebe92c13eec240317
gpu: NVIDIA GeForce RTX 5080
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 1654 (PresentX 1654)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14595 MB

Not tested: this code in the title: it is on the opt-in direct-DXIL path (XCL_DIRECT_DXIL), which the smoke runs leave unset (default HLSL backend), so they show only that nothing else regressed; the world load (the smoke runs stop at the start screen, so code that only runs later is not exercised there); AMD.

AI use: Claude Code (Claude Opus 5.5) built and ran the tests and smoke runs on my machine and wrote this report; I checked it.

@YaBulochka

Copy link
Copy Markdown

AMD/RADV check, and it does not reproduce as a speed-up here: on this machine the per-shader numbers improve but the wall time doubles.

GPU RX 7600 XT (RDNA3), radv as recorded by the title runs on this box
OS Linux, Wine 11.22, x86_64-pc-windows-gnu, release
Mode xcl shaders <retail shaders.rpf> --compile 500 --json, XCL_DIRECT_DXIL=1, XCL_DXIL_CACHE=0 XCL_PSO_DISK_CACHE=0, no title run

Five runs in total; the last pair was taken with the same environment and no XCL_DXC_THREADS set:

base c160d86 this PR
wall 78.7 / 84.4 / 98.5 s 187.1 / 188.5 / 190.5 s
median 0.47 / 0.47 / 0.48 s 0.40 / 0.44 / 0.46 s
p90 2.50 / 3.01 / 3.94 s 3.03 / 3.15 / 3.63 s
max 6.5 / 9.7 / 17.6 s 8.6 / 13.3 / 13.7 s
sum (CPU) 494 / 558 / 722 s 532 / 554 / 555 s

Reading: the CPU sum is the same (555 vs 558 on the clean pair), the medians favour the PR, but the wall is 2.2x worse and remarkably stable at ~188 s while the base swings 79-98 s. The same shape appears with XCL_DXC_THREADS=8 fixed, so it does not look like a thread-count artefact on my side.

My guess, offered as a guess: the explicit-stack walk shares state that serialises the workers, so the work is the same but less of it runs concurrently. If you have a way to log how many DXC compiles are in flight at once, that would confirm or kill it in one run.

No crash or stack overflow at 500 shaders on this box, so the overflow this PR targets did not show up in this mode.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
@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.

@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that #1852 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.

@JJAutoCompare

Copy link
Copy Markdown

Exact-head CPU validation with DXC 1.9.2609.5

On clean 71f2ceb5a05951f8d3d1f6aebe92c13eec240317, both focused tests ran and passed: gpu::dxil::ssa::tests::deep_joins_read_on_a_small_stack and gpu::dxil::core_tests::long_pixel_shader_translates_fast (2 passed, 0 failed, 0 ignored, 0 skipped). I used cargo test --locked -p xcl --lib <exact-name> -- --exact --nocapture --test-threads=1 separately for each. The long-shader case used DXC/DXIL 1.9.2609.5 for CPU validation.

Host: Ryzen 7 3800X, Windows 11 25H2 build 26200.9974, Rust 1.100.0 MSVC debug, Windows SDK 10.0.26100.0, Intel Arc A770 (driver 32.0.101.9175). This adds a newer DXC version to the existing exact-head report.

Not tested: GPU execution, full workspace suite, retail smoke, or the pre-fix baseline. Codex in T3 Code (gpt-6.2-sol) ran the checks and prepared the test evidence.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@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.

Reviewed commit 71f2ceb5a05951f8d3d1f6aebe92c13eec240317.

Both 8,192-level diamond and region shapes completed seven times each on a 256 KiB thread stack. The same probes overflowed the stack on the merge base 177cd40. A 4,000-deep shader join also translated on a 2 MiB stack. All 24 seeded draws on the head returned the expected 64 RGBA pixels, and all 24 DXIL blobs matched the corresponding base draw byte-for-byte.

The graphics dependency benchmark distinguishes this PR from #1852. At 1,024 steps the median additional peak process commit inside the walker was 0.832 MiB here, versus 16.531 MiB on #1852 at c2b1029 (seven release processes each). Median phase times were 43.09 and 50.78 ms respectively. Both produced the same DXIL SHA-256. This PR changes SSA join resolution. The other PR also changes graphics dependency traversal. Their SSA edits overlap, so applying both as-is produces a conflict in ssa.rs.

Windows 11 x64, Ryzen 7 5800X, GeForce RTX 3080 (616.92), Rust 1.100.0 MSVC and DXC 1.9.2602.17. No skips in those draw or head stack probes. Timing is specific to this synthetic shader and machine. No retail shader or native RDNA2 run. No additional actionable defect identified in this scope.

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

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@raylitebull

Copy link
Copy Markdown
Member

Diff review on 71f2ceb confirms Ssa::read in crates/xcl/src/gpu/dxil/ssa.rs uses purely per-call local vectors (chain and joins: Vec<ReadJoin>) with no shared or global synchronization state, and @lewisnic94-max + @frenziedcoder + RX 7800 XT runs are strong.

Before merge, it would be helpful to briefly close out @YaBulochka's Wine --compile 500 wall-time anomaly report (78-98s vs 187-190s) with a confirmation/note so there are no open timing questions on the thread.

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.

10 participants