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

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: --measure-pso runs on a WORKER_STACK thread (on_worker_stack), and the --precompile threads, which also make the --pipelines builds, are spawned with it. Two unit tests: the thread's stack reserve is at least WORKER_STACK, and a panic on it 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 main 5ce558f + this change: 1148 passed, 0 failed, 46 ignored. Windows Developer Mode on, so shaders::tests::pso_measurement_compiles_an_exact_synthetic_record runs and passes.
  • SKIPPED: 20 "no wave64", 3 per-lane form f16 refusals, 1 "no heap windows".
  • 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 ef008c0f04b6261a --repeat 3 (a 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 ef008c0f04b6261a --repeat 3 again on 5ce558f: identical DXIL; driver median 136.0 s (main) against 132.9 s.

Regression run

  • main 5ce558f:
xcl-smoke v1
commit: 5ce558f82a48c51d527f6035234dacbd29db3f05
gpu: NVIDIA GeForce RTX 4070 Ti
title: 83ce7bf6
seconds: 60
exit: 0x0
frames shown: 1462 (PresentX 1462)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15299 MB
  • this PR's head 0fd51f9:
xcl-smoke v1
commit: 0fd51f9fed6d38171cdd833690c679e7838880e9
gpu: NVIDIA GeForce RTX 4070 Ti
title: 83ce7bf6
seconds: 60
exit: 0x0
frames shown: 1432 (PresentX 1432)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17245 MB
  • 97.9 % of main's frames, 112.7 % 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

  • The RADV / Wine overflow itself (no AMD card or Linux here); whether the flat compact form then builds there, or still fails for another reason.
  • Whether title-thread builds overflow on RADV in a title run.
  • AMD Windows, wave64 hardware.

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

`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, so they build as the workers do.

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

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.

6 participants