Skip to content

GPU: pipeline workers get a 64 MB stack for the driver's compiler - #2588

Open
MoonEyes wants to merge 5 commits into
ProjectLeonida:mainfrom
MoonEyes:port-br-pipeline-worker-stack
Open

MoonEyes wants to merge 5 commits into
ProjectLeonida:mainfrom
MoonEyes:port-br-pipeline-worker-stack

Conversation

@MoonEyes

@MoonEyes MoonEyes commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Item: PORT-BR-PIPELINE-WORKER-STACK
Claim: #2570 (comment)
Source: edsuuu/VI-BR-PORT d09c31b4 by Peppacodes and 72903b29 by edsuuu (GPL-3.0); both credited with Co-authored-by and in the d3d12/README.md credit table.

The NVIDIA driver compiles pipelines on our pipeline worker threads, and on a large world compute shader its compiler overflowed the default 2 MB thread stack (seen upstream on an RTX 5080): the pipeline was refused and its dispatches lost. Pipeline workers are now spawned through worker_builder(i) with a 64 MB stack (PIPELINE_STACK). On Windows this is reserved address space, committed as the stack grows (about 1.1 GB of addresses at most with the default worker count). Under Wine/Proton a thread's whole stack is committed, so workers there keep the default stack: the NVIDIA overflow is therefore not handled under Wine, and this version was not measured there.

Only the stack half of the upstream item is taken; the 8 ms wait and creation-time compute launches are left out.

Tests (no game files): wine_workers_keep_the_default_stack checks the choice for both systems; pipeline_workers_reserve_a_64_mb_stack reads a real worker's stack size; it fails with 2,097,152 bytes without the change and passes with it. Passes on this branch merged with main 5cb4592; check_no_game_data.py is clean.

Not tested in the title: whether the driver now accepts that shader on an 8 GB RTX 4060 is not checked here, only the stack size.

AI-assisted (Claude Code, Claude Opus 5.5); reviewed by a separate agent before opening.

🤖 Generated with Claude Code

MoonEyes and others added 2 commits November 28, 2026 20:38
Item: PORT-BR-PIPELINE-WORKER-STACK (first half of
PORT-BR-PIPELINE-WORKER-STACK-AND-WAIT).

The host driver compiles pipelines on our worker threads. On an RTX 5080
NVIDIA's compiler (nvgpucomp64.dll) recursed past the default 2 MB stack
while creating a world compute pipeline: the thread overflowed its stack
(0xc00000fd), then the pipeline was refused with E_OUTOFMEMORY and its
dispatches dropped. A 64 MB stack is reserved address space, committed
only as the compiler uses it.

Ported from edsuuu/VI-BR-PORT d09c31b4 (Peppacodes, the original) and
72903b29 (edsuuu, "Port of d09c31b4"), GPL-3.0. Not a cherry-pick: the
file is d3d12/crates/leonida-gpu/src/pipeline/make.rs here and the worker
spawn is shared through worker_builder() so a test can check it.

Test pipeline_workers_reserve_a_64_mb_stack reads the worker thread's stack
limits (GetCurrentThreadStackLimits): 2097152 bytes without stack_size
(fails), at least 64 MB with it (passes). No game file needed.

Co-authored-by: Peppacodes <360593343+Peppacodes@users.noreply.github.com>
Co-authored-by: edsuuu <111332935+edsuuu@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@MoonEyes

Copy link
Copy Markdown
Collaborator Author

@DadaCap could you review this one when you have a moment? It merges cleanly with main. The red checks are the three tests that fail on main 5cb4592 too, already claimed: test_valu_cvt_f16_int16_mods (translator f16), test_the_loader_gets_the_stack_reserve_cmake_gives_it (loader stack) and test_resolve_pools_deduplicates_macos_case_and_accents_and_keeps_case_sensitive (path dedup). None of them touches this diff. The ERROR: lines in those logs come from tests that pass.

AI-assisted (Claude Code, Claude Opus 5.5), posted for MoonEyes.

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

Reviewed 53323d3f2 (d3d12/crates/leonida-gpu/src/pipeline/make.rs).

Extracting worker_builder with .stack_size(PIPELINE_STACK) (64 MiB) is minimal and self-contained, and the unit test directly verifies the reserved stack span via GetCurrentThreadStackLimits.

Local verification:

  • cargo test --manifest-path d3d12/Cargo.toml -p leonida-gpu --lib stack: 1/1 passed (pipeline::make::tests::pipeline_workers_reserve_a_64_mb_stack).
  • python -I scripts/check_no_game_data.py: passed.

AI-assisted (Antigravity, Gemini).

@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Physical Hardware Verification — Windows 11 + NVIDIA GeForce RTX 3090 (610.88)

Verified head commit 53323d3f21d5c2600e7cdf6f88365c61dcfaa1b5 cleanly merged (no-commit) onto origin/main (1bc055e6c2dedaa0de23ec79d8c4007c1dff1fb3; git merge-tree --write-tree rc=0).

  • Cross-PR merge note: #2588 merges cleanly with #2589, and has a trivial 1-line adjacent table-row conflict at the end of the settings table in d3d12/README.md with #2587 (git merge-tree rc=1 on d3d12/README.md only).

Red -> Green Verification

  • Red (origin/main 1bc055e6c2):
    • Compiling #2588's pipeline_workers_reserve_a_64_mb_stack test on origin/main fails (E0425: PIPELINE_STACK and worker_builder missing).
    • Running a runtime probe spawning origin/main's std::thread::Builder::new().name("leonida-pipelines-0".into()) and querying GetCurrentThreadStackLimits on Windows 11 fails the >= 64 MiB assertion (default stack was only 2097152 bytes = 2 MiB).
  • Green (origin/main + 53323d3f21):
    • cargo test --locked -p leonida-gpu --lib pipeline::make::tests:: -- --test-threads=4: 8/8 passed (including pipeline::make::tests::pipeline_workers_reserve_a_64_mb_stack, confirming GetCurrentThreadStackLimits reserves >= 67,108,864 bytes on Windows 11).
    • cargo test --locked -p leonida-gpu --lib pipeline::host::tests:: -- --test-threads=4: 9/9 passed on NVIDIA GeForce RTX 3090.
    • python -I tests/test_docs_encoding.py (1/1), python -I tests/test_docs_links.py (17/17), python -I tests/test_docs_env_vars.py (5/5), and python -I scripts/check_no_game_data.py d3d12/README.md d3d12/crates/leonida-gpu/src/pipeline/make.rs (0 issues) all pass.

Code Review Notes

  • PIPELINE_STACK (64 << 20) reserves virtual address space per worker thread on Windows (MEM_RESERVE) while physical pages remain committed on demand, cleanly preventing nvgpucomp64.dll stack overflow (0xc00000fd) without upfront physical memory cost. No blockers found.

AI-assisted.

@TheGeogeo

TheGeogeo commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Re-checked on main c8bf0e7b6 (head 53323d3f2 unchanged): Windows 11 10.0.26300, Rust 1.98.1, host-side unit test (no GPU needed).

  • Green: cargo test -p leonida-gpu --lib --locked --offline: 526 passed, 0 failed, 46 ignored (plain main: 525 passed, 0 failed, 46 ignored). pipeline_workers_reserve_a_64_mb_stack passes. The leonida-gpu test build gives 10 warnings, the same as on main.
  • Red: with .stack_size(PIPELINE_STACK) removed from worker_builder, the test fails with stack of 2097152 bytes.
  • One of 4 full runs on the merge failed watch::tests::writes_in_partly_committed_view_blocks_are_reported (watch.rs, not touched here). It passed in the 3 other full runs and in 5 runs on its own, and in 4 full runs and 5 runs on its own on main. That looks like an existing flaky test, unrelated to this PR.
  • check_no_game_data.py is clean on the 2 files.

No blocker from my side. AI-assisted (Claude Code).


Tested 53323d3f2 merged (no commit) with main aa918e5d9, Windows 11 10.0.26300, Rust 1.98.1 (NVIDIA GeForce RTX 3080, driver 621.40 in the machine; host-side unit test).

  • Green: cargo test -p leonida-gpu --lib --locked: 516 passed, 0 failed, 46 ignored (plain main: 515 passed, 0 failed, 46 ignored). pipeline_workers_reserve_a_64_mb_stack passes. The leonida-gpu test build gives 10 warnings, the same as on main.
  • Red: with .stack_size(PIPELINE_STACK) removed from worker_builder, the test fails with stack of 2097152 bytes.
  • check_no_game_data.py is clean on the 2 files.
  • Not checked: whether the driver now accepts the large compute shader (no game run).

No blocker from my side. AI-assisted (Claude Code).

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

Static audit of 53323d3f2 against 48bae6cad. Rust requests a 64 MiB stack reservation on Windows. The Wine and Proton implementations I checked map the full request as committed writable memory. With 18 workers that can account for roughly 1.125 GiB of Linux commit when the pool starts. Please bound the pool stack budget on Wine/Proton and document its allocation behavior.

The Windows stack-span test can pass with either allocation behavior. A host-only check of pool creation and commit usage under Wine/Proton would cover the difference. Pipeline creation on the affected NVIDIA driver remains unverified in this audit.

AI-assisted.

@merzleckeier

Copy link
Copy Markdown
Contributor

Measured the Wine stack-budget concern at 53323d3f2 merged onto c22a0a732. I ran the actual idle workers() pool, with the same test-only measurement hook on both trees, using System Wine 11.22 and cachyos-11.0-20261015-slr on CachyOS (Linux 7.3.6).

Pool main, either runner PR, System Wine PR, CachyOS-Proton
Default on this host (8 + 2 screen workers) 20 MiB 640 MiB 640 MiB
LEONIDA_PIPELINE_WORKERS=16 (16 + 2) 36 MiB 1,152 MiB 1,151.992 MiB

The table sums only worker stack bytes marked VmFlags: ac in Linux smaps. The probe walks each worker's bounds with VirtualQuery, requires the Linux process to map the actual test PE, and checks residency page by page through pagemap. The matched stacks had 0.6–5.0 MiB resident in total across all 16 idle starts (two repetitions per case). The included 64 MiB stack-span test passed on both runners. That span check alone cannot distinguish address space from Linux commit accounting.

The 64 MiB stacks therefore add 620–1,116 MiB of idle Linux commit on these runners. The committed only as used source comment should be scoped to Windows. Any Wine stack budget needs to include the two screen workers. I measured startup only, with no GPU compilation or game files. AI-assisted with OpenAI Codex (GPT-6).

@enlight3d

Copy link
Copy Markdown
Contributor

RUN (independent run, #2588 head 53323d3 on main 878b024; merged locally with git merge --no-ff, no conflicts; also no conflict with #2566 head 7b5cb29 per git merge-tree --write-tree).

Commands, in d3d12/, target x86_64-pc-windows-msvc, toolchain 1.98.1:

  • cargo check --tests -p leonida-gpu: OK on the merged tree.
  • cargo test -p leonida-gpu: green, 545 passed / 0 failed / 47 ignored, including pipeline_workers_reserve_a_64_mb_stack.
  • Red, behavioural: with the .stack_size(PIPELINE_STACK) call removed (the old behaviour), cargo test -p leonida-gpu --lib pipeline_workers_reserve fails: "stack of 2097152 bytes" (the 2 MB default) against the 64 MB asserted.
  • Red, build: with the PR's non-test changes reverted and the test kept, it does not compile (E0425, PIPELINE_STACK and worker_builder not found).
  • Not covered: that 64 MB is enough for the driver's compiler (needs the real driver and a world program); the test only shows the reservation is made.

No runtime/ C++ or Python in this PR, so no link or import check applies.
Machine: Windows 11 Pro 26300, i9-13900K, 64 GB, RTX 3090 24 GB, NVIDIA 621.40.

# Conflicts:
#	d3d12/README.md
@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 29, 2026
@OreoFR

OreoFR commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

Verified by OreoFR

PR head 9dec31305 (a merge of main on top of the tested 53323d3f2; the PR's own change is the same) merged with git merge --no-ff onto main 060c47160, no conflict. Windows 11 Pro 10.0.26300, RTX 4070 Laptop 8 GB, NVIDIA 621.40, Rust 1.98.1 (host-side unit test, no GPU used). New here: a red at this head.

  • Crate: cargo test -p leonida-gpu --locked in d3d12/, own target dir.
  • Green: 550 passed / 0 failed / 47 ignored (main 549/0/47); pipeline_workers_reserve_a_64_mb_stack passes.
  • Red: the test calls worker_builder, which the PR adds, so restoring make.rs to main does not compile. I kept the PR and removed only .stack_size(PIPELINE_STACK): the test fails with stack of 2097152 bytes (Rust's 2 MB default).
  • Clippy (--all-targets, leonida-gpu): no new lint in pipeline/make.rs.
  • [integration] PageMirror, GPU detile, async queue & RDNA2->SPIR-V performance stack (INTEGRATION-PERF-CPU-GPU-R6) #2566 (eade9562c) rebase needed after this: no (git merge-tree is clean).
  • Still open: merzleckeier measured that Wine/Proton commit the whole 64 MiB per worker (about 0.6 to 1.1 GiB idle), so the comment saying the stack is committed only as it is used holds on Windows only. Not measured here: no Wine on this machine.

Verdict: READY (green, red seen). Ready to merge per the maintainers' plan.

This verification was AI-assisted (Claude Code, oreofr-agent).

…er-stack

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KelboLive

Copy link
Copy Markdown

Independent check on Windows (not the author), at 7355da91a.

  • cargo test --locked -p leonida-gpu --lib (shared warm target): 564 passed, 0 failed, 52 ignored in 13.4 s.

The 64 MB worker stack itself is not covered by unit tests; this confirms the pipeline make path still compiles and the crate stays green. The driver-compiler crash scenario needs a game/pipeline run.

Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, NVIDIA RTX 4070 Ti SUPER (driver 621.01), Rust 1.98.1 pinned.

AI-assisted: yes (opencode).

@enlight3d

Copy link
Copy Markdown
Contributor

RUN (independent run on Windows, #2588 head 7355da9, tested as it is: it already has main d367675 merged in. The PR's own changes are line for line the same as on its earlier heads 9dec313 and 53323d3; only main's commits came in. The head still merges cleanly into main 8f41d7d. CI on 7355da9: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass.) This replaces my earlier RUN on 53323d3.

Commands, in d3d12/, target x86_64-pc-windows-msvc, toolchain 1.98.1, all with --locked, at low priority:

  • cargo test -p leonida-gpu --no-fail-fast: green, 564 passed / 0 failed / 52 ignored. Main d367675 gives 563 / 0 / 52, so pipeline_workers_reserve_a_64_mb_stack is the one new test, and it passes.
  • cargo clippy -p leonida-gpu --all-targets (without -D warnings, which already fails on main in leonida-shader and leonida-lua), on main and on the head: no warning in pipeline/make.rs on either.
  • Red, behavioural: with the .stack_size(PIPELINE_STACK) call removed (the old behaviour) and the test kept, cargo test -p leonida-gpu --lib pipeline_workers_reserve fails with "stack of 2097152 bytes", the 2 MB default, against the 64 MB asserted.
  • Not covered: that 64 MB is enough for the driver's compiler. That needs the real driver and a world program. The test only shows that the reservation is made.

No runtime/ C++ or Python in this PR, so no link or import check applies.
Machine: Windows 11 Pro 26300, i9-13900K, 64 GB, RTX 3090 24 GB, NVIDIA 621.40.

@enlight3d

Copy link
Copy Markdown
Contributor

IN-GAME RUN (gate, independent): #2588 head 7355da9, RTX 3090 24 GB, NVIDIA 621.40, Windows 11.

Setup: d3d12/scripts/build-nvidia.ps1 (diag profile, no DLSS files), scripts/play-d3d12.ps1 -SeriesS -NoDlss -NoFrameGen -Log, the same save restored before the run, standing still once in the world. A shader translation ran on the PC at the same time, so the frame rates are not comparable with other runs.

Gate: no device loss in the 300 s warm-up (world at 97 s) or in the 420 s run (world at 78 s, so 342 s in the world; ended at the time limit). Median 7.0 fps (p5 1.4).

The late memory build-up that main shows on this card in most runs (list scratch kept in card memory while the release thread's queue grows) is present here too, at the same scale as on main (queue about 196,000, mapped scratch 6.9 GB at the end, VRAM peak 18.3 GB). It is not caused by this PR.

With the cargo RUN posted earlier on this head, this completes my verification of #2588. Not checked: Series X, walking, picture.

…s the whole of it

Found by timbot103 and measured by merzleckeier on ProjectLeonida#2588.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MoonEyes

MoonEyes commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

@timbot103 @merzleckeier thanks, the point is right: the stack was only "committed as used" on Windows. Fixed on head 6b4a44e18:

  • Wine/Proton: a pipeline worker keeps the default stack (pipeline_stack(wine), detected as leonida-hle does, from ntdll's wine_get_version). On Windows nothing changes: 64 MiB reserved.
  • The comments and the README line say so, with merzleckeier's numbers (0.6 to 1.1 GiB of Linux commit for the idle pool with 64 MB stacks).
  • Tests: wine_workers_keep_the_default_stack (the choice), and pipeline_workers_reserve_a_64_mb_stack, which under Wine now asks for a stack below 64 MiB instead of at least 64 MiB.

MEASURED, Windows 11, RTX 4060, Rust 1.98.1: cargo test -p leonida-gpu --lib --locked 565 passed, 0 failed, 52 ignored; the two stack tests again after a last edit of them. By mutation: ignoring Wine fails the first test, dropping .stack_size fails the second.

Not measured: anything under Wine or Proton (no Linux here). So the overflow in NVIDIA's compiler is not handled there, and the commit at pool creation with this head is untested. @merzleckeier, if you can run your pool measurement again on this head, that would settle it. The earlier verdicts and the in-game run were on 7355da91a. On Windows the stack asked for is the same; the new code only adds the Wine check.

Posted by an AI agent (Claude Code) for MoonEyes.

@merzleckeier

Copy link
Copy Markdown
Contributor

Idle worker stack accounting on the Wine-aware head 6b4a44e18, merged into 66c79286f. I repeated the earlier pool measurement on system Wine 11.22 and on the Wine 11.0 runtime bundled with CachyOS Proton. There were two fresh starts per runtime, tree and pool size, 16 starts total.

Idle pool Current main Current #2588 Earlier 64 MiB #2588 head
Automatic (8 regular + 2 screen workers) 20 MiB 20 MiB 640 MiB
Forced 16 regular + 2 screen workers 36 MiB 36 MiB ~1,152 MiB

The table is the exact overlap of each actual worker’s VirtualQuery stack range with Linux smaps mappings marked VmFlags: ac. Every worker on both current trees mapped and accounted for 2 MiB on both runtimes. The PR’s stock Wine stack test also passed in all eight PR starts. The queue was empty, so this covers idle stack accounting. Compiler stability and native Windows memory accounting were outside the run. Earlier measurement.

MEASURED with OpenAI Codex and a separate read-only review.

@xVegetax

xVegetax commented Dec 1, 2026

Copy link
Copy Markdown

Dropping the pipeline worker stack change from #2929 to avoid duplication — supporting this PR instead.

@fiestorra

Copy link
Copy Markdown
Contributor

Independent verification on Windows 11, Ryzen 7 7800X3D, RTX 4090 - by the AGENTS.md method.

Applied on main 913b88b90:

git merge-tree --write-tree origin/main refs/remotes/pr/2588     no conflicts
git merge --squash refs/remotes/pr/2588                          clean, 2 files, +70/-2

What it does here:

cargo test -p leonida-gpu --lib -- --test-threads=1 pipeline::make
    14 passed; 0 failed
cargo test -p leonida-gpu --lib -- --test-threads=1
    645 passed; 1 failed; 59 ignored
    the failure is descriptor::host::tests::views_are_made_beside_the_heap_and_copied_in,
    which is not yours: it is the byte-comparison test that fails on this machine's
    integrated Radeon, because every device test still makes its device with
    D3D12CreateDevice(None, ..) (#2995 puts them on the card, and it passes there)
cargo clippy -p leonida-gpu --all-targets
    1 warning, host.rs:7680, on main already (#2877 carries it)

pipeline_workers_reserve_a_64_mb_stack is the right test for this: it spawns a worker and reads GetCurrentThreadStackLimits from inside it, so it checks the reservation the driver's compiler actually gets, not the constant. And the Wine branch is the kind of thing that would have bitten later: 64 MB × 10-18 idle workers as committed Linux memory is 0.6 to 1.1 GiB, and your pipeline_stack(wine) returning None there is the right call.

What I cannot test, and did not: whether the driver's compiler stops overflowing on an 8 GB card (nvgpucomp64.dll, ~7 min in). No 8 GiB card here, and no game run.

AI-assisted: yes - DeepSeek v4.1 (flash).

Written with an AI assistant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.