Skip to content

Shaders: offline pipeline builds use the runtime workers' 64 MB stack - #2070

Open
thisguyStan wants to merge 1 commit into
xcl-dev:mainfrom
thisguyStan:shaders/offline-builds-runtime-stack
Open

thisguyStan wants to merge 1 commit into
xcl-dev:mainfrom
thisguyStan:shaders/offline-builds-runtime-stack

Conversation

@thisguyStan

@thisguyStan thisguyStan commented Nov 25, 2026 •

Copy link
Copy Markdown

xcl shaders --measure-pso builds its pipeline on the main thread (1 MB stack in xcl.exe's PE header), and --precompile --pipelines on scoped threads with Rust's 2 MB default. The driver compiles on the calling thread, so a measurement of what a build costs can end on a stack limit of XCL's own thread. On RADV under Wine, --measure-pso of the flat compact form of the largest compute programs ended with thread 'main' has overflowed its stack, and those runs were used to compare forms in #1269 (#2018 / #2025 threshold). This runs both offline paths on the stack of the runtime's pipeline workers (64 MB), so they build as the workers do. @ClosetPie107 found the --pipelines side in #1269 (comment, "Stack size of the offline tool"); this follows it. Part of #1269.

What is in it

  • crates/xcl/src/hle/d3d12x/pso_async.rs: the workers' stack as WORKER_STACK (same 64 MB, no change at run time).
  • crates/xcl/src/shaders.rs: one helper, worker_thread, makes a named thread with WORKER_STACK. --measure-pso runs on one (on_worker_stack, xcl-measure-pso), and so do the --precompile threads, which also make the --pipelines builds (xcl-precompile-{k}), and the threads --pipelines starts for a split program's dispatch-chain pieces (xcl-pipeline-piece-{k}, from Shaders: prebuild split compute dispatch-chain pieces under --pipelines #2338). They had no name, so an overflow printed thread '<unknown>'. Three unit tests: the thread's stack reserve is at least WORKER_STACK, a precompile thread gets the stack and its name, and a panic on the thread reaches the caller.

Not changed, and worth knowing for the RADV result
Only some runtime builds run on the 64 MB workers: pipelines an earlier run used (prebuilt at low priority), and builds after an XCL_PSO_WAIT_MS budget ran out. By default (XCL_LAZY_PSO on, no XCL_PSO_WAIT_MS) a compute pipeline is built at its first bind on the title's own thread (pso_async::resolve_wait_for), and XCL does not change the stack size of title threads. The title tested here defaults to 1 MB in its PE header, which answers the open question at the end of that comment. So the RADV overflow above may also happen in a title run under Wine, on a title thread. A bigger stack is not a cure-all either: a PSO worker overflowed its 64 MB on an unbounded recursion in dxil-spirv (comment). This PR does not change that; moving those builds off title threads is runtime work (#2001 goes in that direction).

Tested

  • NVIDIA GeForce RTX 4070 Ti (driver 32.0.16.1088, 32-lane waves), Ryzen 9 5900X, 64 GB RAM, Windows 11 Pro 10.0.26200.9974, Rust 1.100.0, debug.
  • cargo test --workspace -- --test-threads=4 on this PR's head 8cb4346 (on main 2898511): 1366 passed, 0 failed, 46 ignored. Windows Developer Mode on, so shaders::tests::pso_measurement_compiles_an_exact_synthetic_record runs and passes.
  • SKIPPED (28): 21 "no wave64", 3 per-lane form refusals (V_CVT_F16_F32, V_PK_MUL_F16, V_MUL_F16), 2 "no d3d12SDKLayers.dll", 1 "no heap windows", 1 "no D3D12 debug layer".
  • xcl shaders <pack> --precompile --only cs (XCL_NETWORK=0, an empty XCL_DXIL_CACHE), release, this change on main 3f4495a (the same change as 8cb4346 before the rebases since, without the piece threads of Shaders: prebuild split compute dispatch-chain pieces under --pipelines #2338, which was not merged yet): all 26 503 shaders, compiled 2 689 compute programs, 0 errors, exit 0, 4 455 s. An earlier pass of the same kind on an older base had stopped with exit 1 and no message at about 23 000; this one went through.
  • xcl.exe's PE header reserves 1 MB for the main thread (SizeOfStackReserve), which is where --measure-pso built before.
  • xcl shaders <pack> --measure-pso <record> --repeat 3 (one 1.1 MB HLSL-path compute program), release, main against this change on 3da2abb: identical DXIL (1 121 012 B); driver median 139.1 s against 141.1 s (ranges 138.2–141.5 s and 139.1–143.4 s), within run-to-run spread.
  • xcl shaders <pack> --precompile --only cs --pipelines --used-only (the 482 pipelines earlier title runs used here; XCL_PIPELINE_MAX_KB=512; an empty XCL_DXIL_CACHE per run), release, main 5ce558f against this change: both compiled 322, made 318 pipelines, refused 0, capped 4; 306 s against 275 s.
  • --measure-pso <record> --repeat 3 again, on the same program, on 5ce558f: identical DXIL; driver median 136.0 s (main) against 132.9 s.

Regression run

  • main 2898511:
xcl-smoke v1
commit: 2898511af1c038a2ef809719e9b6f89e5675c422
gpu: NVIDIA GeForce RTX 4070 Ti
title: 83ce7bf6
seconds: 60
exit: 0x0
frames shown: 1395 (PresentX 1396)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15116 MB
  • this PR's head 8cb4346:
xcl-smoke v1
commit: 8cb43460c48bf98beef7c1d679a6db37ef75ce39
gpu: NVIDIA GeForce RTX 4070 Ti
title: 83ce7bf6
seconds: 60
exit: 0x0
frames shown: 1440 (PresentX 1440)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15482 MB
  • 103.2 % of main's frames, 102.4 % of its peak commit, no device removal, no crash. The 60 s run does not reach xcl shaders, so it only shows the runtime is not broken by the shared constant.

Not tested

AI use

  • Claude Code (Claude Opus 5.5) wrote the change, the tests and this description, and ran the tests and smoke runs.

🤖 Generated with Claude Code

@futurepro62

futurepro62 commented Nov 25, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 0fd51f9 (on its base 5ce558f).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 1136 passed, 0 failed, 44 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: offline_builds_run_on_the_runtime_workers_stack, a_panic_on_the_worker_reaches_the_caller.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 1147 passed, 0 failed, 46 ignored. SKIPPED: 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))), 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))), 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))), 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))), 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))), 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).
  • --skip leaves out tests that fail on main cbc296a too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests const_and_null_mask_operands_agree_with_hlsl_on_the_gpu and mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@Parakeet-Wheat

Copy link
Copy Markdown

NVIDIA RTX 3070 on native Windows, head 0fd51f9 on its base 5ce558f: both new tests pass, the whole suite passes, and the smoke pair is within the limits. The new tests cannot fail on the base (the helper they call is not there), so there is no fail-before run.

Tested

  • NVIDIA GeForce RTX 3070 8 GB (driver 610.88, 32-lane waves), Ryzen 5 5600X, 32 GB, Windows 11 26300, Rust 1.95.0 stable-x86_64-pc-windows-msvc, DXC 1.8.2502.11, retail 1.0.2.1. Head 0fd51f9 (one commit on 5ce558f, 6 commits behind current main), checked out clean. Tests in the debug profile, smoke in release.
  • cargo test -p xcl --lib worker_stack_tests -- --nocapture --test-threads=1 on 0fd51f9: 2 passed, 0 failed (offline_builds_run_on_the_runtime_workers_stack, a_panic_on_the_worker_reaches_the_caller). On 5ce558f they do not compile: on_worker_stack and WORKER_STACK are new in this PR.
  • .\scripts\test.ps1 (cargo build --workspace, then cargo test --workspace -- --test-threads=4) on 0fd51f9: 1148 passed, 0 failed, 46 ignored, exit 0. SKIPPED, 25: 20 × no wave64, 3 × per-lane form refused (V_CVT_F16_F32, V_PK_MUL_F16, V_MUL_F16: "its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's"), 1 × no heap windows, 1 × cannot disable the driver cache (Windows Developer Mode required).

Regression run (scripts/smoke.ps1 -Game <folder> -Seconds 60, the same title, back to back, menus, no input; unedited). Base 5ce558f:

xcl-smoke v1
commit: 5ce558f82a48c51d527f6035234dacbd29db3f05
gpu: NVIDIA GeForce RTX 3070
title: 3d7db37d
seconds: 60
exit: 0x0
frames shown: 1471 (PresentX 1471)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16864 MB

PR head 0fd51f9:

xcl-smoke v1
commit: 0fd51f9fed6d38171cdd833690c679e7838880e9
gpu: NVIDIA GeForce RTX 3070
title: 3d7db37d
seconds: 60
exit: 0x0
frames shown: 1434 (PresentX 1435)
presents per 2 s (last 3): 60 58 12
device removals: 0
crashes: 0
peak commit: 18017 MB

That is 97 % of the base's frames and 107 % of its peak commit. One run each; the 60 58 12 tail of the PR's run (against 60 60 60) is not something I repeated.

Not tested

  • xcl shaders --measure-pso and --precompile --pipelines themselves (no offline run, so the stack-overflow case on RADV under Wine is not reproduced), AMD, native wave64 (the 20 no wave64 skips above), a world run, the tests on game data (XCL_SAMPLE_* not set).

AI use

  • Claude Code (Claude Sonnet 5.5) ran the tests and wrote this report. The account owner has not reviewed it.

@JoaoPauluu

JoaoPauluu commented Nov 25, 2026 •

Copy link
Copy Markdown

A run of the --pipelines side under Wine on Linux with vkd3d-proton as the host D3D12. Here the 64 MB stacks do not change the outcome: on both main and this PR, all four pipeline threads overflow within about two minutes and the run stalls.

Tested

  • RTX 3060 12 GB (NVIDIA 620.70.06, 32-lane waves), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from Linux: docs/linux.md, scripts/linux and Wine start-up checks for vkd3d-proton and DXVK (#154, #241) #257 (dxil-spirv), DXC 1.9.2609.5. Release, cross-built for x86_64-pc-windows-gnu. 0fd51f9 as it is (based on 5ce558f) and main cbc296a, no uncommitted changes.
  • xcl shaders <retail 1.0.2.1 shaders.rpf> --precompile --only cs --pipelines, XCL_PIPELINE_MAX_KB=0 (no cap), VKD3D_SHADER_CACHE_PATH=0 and __GL_SHADER_DISK_CACHE=0 (no driver-side caches), 2400 s cap, main first:
    • main: pipelines: 75 made, 0 refused, then four thread '<unknown>' has overflowed its stack lines. The log stopped changing about 1.5 min after start, and the cap killed the process (exit 124).
    • this PR: pipelines: 75 made, 0 refused, four has overflowed its stack lines (the first between 50 and 75 made). The log stopped changing about 1.5 min after start, and the cap killed the process (exit 124).
  • The DXIL cache (AppData\Local\xcl\dxil in the Wine prefix) was not cleared between the two runs, so the PR's run could reuse DXIL that the main run had compiled. The pipeline builds were fresh in both.
  • --measure-pso cannot run here. On both commits it stops with cannot disable the driver cache (Windows Developer Mode is required): Not implemented. (0x80004001), since vkd3d-proton does not implement the shader cache control.

XCL_DIRECT_DXIL was unset, so both runs used the HLSL → DXC path. #1805 found its overflow with direct DXIL on, in dxil-spirv's flatten_subgroup_shuffles(). These overflows are on the default path. I have not checked whether they are the same recursion, so I cannot tell from here whether XCL's 1 MB / 2 MB limits play a part.

Not tested

AI use

  • Claude Code (Claude Opus 5.5) built both commits, ran the runs and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@thisguyStan

Copy link
Copy Markdown
Author

Thank you @futurepro62, @Parakeet-Wheat, @DavidM1911 and @JoaoPauluu for testing across RTX 5070 Ti / an RDNA2 iGPU, RTX 3070, RTX 3060 Ti, and RTX 3060 under Wine with vkd3d-proton!

Rebased onto origin/main (5ce558f → 50a9fde). The one conflict was main's new worker queue in pso_async.rs (Work closures); WORKER_STACK sits above it and both worker pools still use it. Since your runs:

  • Both offline paths now make their thread with one helper, worker_thread, so the precompile threads are covered too (Parakeet-Wheat's note that the tests only reached on_worker_stack). A new test checks a precompile thread's stack and name.
  • The precompile threads are named xcl-precompile-{k}. They had no name, so an overflow like the one in JoaoPauluu's run printed thread '<unknown>', the same as a thread of the driver's.
  • JoaoPauluu's Wine run: with vkd3d-proton v3.1 the bigger stack does not help, because dxil-spirv recursed without end there. Those recursions all began in flatten_subgroup_shuffles(), which ran before the structurizer; dxil-spirv runs it after since HansKristian-Work/dxil-spirv@694cc674, and vkd3d-proton master carries that since HansKristian-Work/vkd3d-proton@89439562. Not rerun yet; it is under Not tested.
  • Re-verified on 4772a13: full workspace (1291 passed, 1 failed, 46 ignored; the failure also fails on main 50a9fde), xcl shaders --precompile --only cs (all 26 503 shaders, 2 689 compute programs compiled, 0 errors), and a paired 60 s smoke (1360 → 1457 frames, 0 device removals / crashes).

AI use: Claude Code (Claude Opus 5.5) made the changes, ran the tests and wrote this comment.

`xcl shaders --measure-pso` called CreateComputePipelineState on the
main thread, whose stack xcl.exe reserves at 1 MB, and `--precompile`
(with `--pipelines`) on scoped threads with Rust's 2 MB default. The
driver compiles on the calling thread, so a measurement of what a
build costs could end on a stack limit of XCL's own thread instead:
on RADV under Wine, `--measure-pso` of the flat compact form of the
largest compute programs ended with "thread 'main' has overflowed its
stack" (xcl-dev#1269). ClosetPie107 reported the `--pipelines` side there
first.

Name the stack of the runtime's pipeline workers
(`pso_async::WORKER_STACK`, 64 MB) and run both offline paths on a
thread with it (`worker_thread`), so they build as the workers do.
The threads `--pipelines` starts to build a split program's
dispatch-chain pieces get it too. The threads are named
(`xcl-measure-pso`, `xcl-precompile-{k}`, `xcl-pipeline-piece-{k}`):
an overflow under Wine printed `thread '<unknown>'`, which could not
be told apart from a driver's thread.

The runtime itself is unchanged. A first-time compute build at a bind
(`XCL_LAZY_PSO` on, no `XCL_PSO_WAIT_MS`) still runs on the title's
thread, with the stack the title gave it.

Part of xcl-dev#1269.

Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thisguyStan
thisguyStan force-pushed the shaders/offline-builds-runtime-stack branch from 4772a13 to 8cb4346 Compare November 25, 2026 18:56

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No concrete source defect found. Shared 64 MiB worker stack is applied consistently and result/panic propagation is sound; tests cover reserve/name/unwind. Current official Windows CI is not visible, despite strong reported suite/smoke. The RADV/Wine recursion limitation is appropriately disclosed. A bounded deep-stack/large-build integration case would strengthen tests, but I found no blocker.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

AMD RDNA3 on native Windows: full suite of 8cb4346 merged onto main 6d12f58

Test report for head 8cb43460c48bf98beef7c1d679a6db37ef75ce39, which is a rebase onto an older main than today's. I tested the PR head merged onto main 6d12f58a (a local merge commit, one auto-merged file, no conflicts; the diff against main is only this PR's two files) and compared it with main itself.

Tested

  • AMD Radeon RX 7800 XT (RDNA3, driver 32.0.31035.1003), Ryzen 7 5700X3D, Windows 11 build 26200, Rust/Cargo 1.100.0 MSVC, debug (unoptimized) profile, Windows SDK DXC.
  • cargo test --workspace --no-fail-fast -j 4 -- --test-threads=4, both trees in the same target dir, one after the other; the log shows Compiling xcl from the tested worktree.
    • main 6d12f58a: 1422 passed, 1 failed, 46 ignored.
    • PR merged onto main: 1425 passed, 1 failed, 46 ignored. The 3 extra passes are this PR's new tests.
  • The three new tests passed:
    • shaders::worker_stack_tests::offline_builds_run_on_the_runtime_workers_stack
    • shaders::worker_stack_tests::precompile_threads_are_named_and_get_the_workers_stack
    • shaders::worker_stack_tests::a_panic_on_the_worker_reaches_the_caller
  • The one failure is the same on main and on the PR: gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (seed 722). It also fails alone on main, so it is not caused by this PR.
  • SKIPPED, identical on both trees: gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu and f32_programs_on_the_gpu (f16 / f32 conversion cases refused as unsupported, 6 lines) and heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • As the earlier reports noted, the new tests call helpers that the base does not have, so there is no fail-before run.

Not tested

  • No scripts/smoke.ps1 regression run on a retail title, so there is no xcl-smoke block here.
  • No xcl shaders --pipelines / --precompile run on a large pack, so the stack-overflow case this PR is about (reported under Wine / RADV) is not exercised on this card.
  • Release profile, wave64-only GPUs, RDNA4.

AI use: this run and report were done by Claude Code (Claude Sonnet 5.5), driven by oni-swr. The commands and counts are from the run above, not edited by hand.

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.

8 participants