Skip to content

D3D12.X: run whole split-PSO builds on one late worker without pc_call - #2921

Open
saintwolf wants to merge 1 commit into
xcl-dev:nvidia-devfrom
saintwolf:fix/pso-whole-worker-queue
Open

saintwolf wants to merge 1 commit into
xcl-dev:nvidia-devfrom
saintwolf:fix/pso-whole-worker-queue

Conversation

@saintwolf

Copy link
Copy Markdown

Fixes three issues introduced when #2893 moved split compute PSO whole-form compilation off the title thread:

  1. Unbounded 64 MiB-stack OS threads: dispatch_chain::whole_ready() spawned a fresh xcl-pso-whole thread (stack_size(64 << 20)) for every distinct split compute PSO hitting an indirect dispatch when XCL_CS_PSO_WAIT_MS was set. On a retail title run, 100+ xcl-pso-whole threads piled up simultaneously behind real::huge_compile_turn (6+ GiB of reserved stack VA, ~2,000 condvar wakeups/s polling GlobalMemoryStatusEx, and slots.urgent > 100).
  2. Missed D3D12.X: a build the title already draws without waits for half the commit headroom #2894 half-headroom rule: standalone xcl-pso-whole threads had pso_async::BUILDING == None, so pso_async::build_is_late() always returned false. Every whole-form compile waited for the full 3 GiB+ commit headroom even while indirect dispatches were actively skipped waiting for it.
  3. False pc_call() registration: Chain::whole() still called pso_async::pc_call() on background xcl-pso-whole threads, registering parked background workers in PC_CALLS as if a title thread were stalled in a long PC call.

What is in it

  • crates/xcl/src/hle/d3d12x/pso_async.rs: adds a thread-local JOB_LATE override and RAII-guarded with_late_build() helper checked by build_is_late().
  • crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs:
    • replaces per-PSO std::thread::Builder::spawn in whole_ready() with a single persistent xcl-pso-whole worker thread (64 MiB stack) fed by an mpsc channel, running each job under pso_async::with_late_build().
    • passes on_title_thread: bool to Chain::whole() so pso_async::pc_call() is only taken when building synchronously on a title thread.
    • adds unit tests whole_worker_runs_all_jobs_on_one_late_thread and with_late_build_resets_after_return_and_panic.

Tested

  • Windows 11 (build 26300), NVIDIA GeForce RTX 4070 SUPER (12 GiB, driver 32.0.16.2140), AMD Ryzen 7 7800X3D, rustc 1.100.0, debug test build + release smoke build.
  • cargo test -p xcl --lib hle::d3d12x::real::dispatch_chain::tests -- --test-threads=1: 4 passed, 0 failed, 0 ignored, 0 skipped (including both new tests).
  • cargo test --workspace -- --test-threads=4 (with XCL_DXIL_CACHE set): 1,697 passed, 3 failed, 28 ignored (all 3 failures are pre-existing on nvidia-dev: gpu_compute_thread_limits_leave_the_lanes_past_them_out and two texture_upload overflow tests; wave64 GPU tests printed SKIPPED ...: no wave64 on NVIDIA).

Regression run
main:

xcl-smoke v1
commit: e120925e3abc9956a8b9bae631969d32e8ccd43c
gpu: NVIDIA GeForce RTX 4070 SUPER
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1045 (PresentX 1045)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14930 MB

PR head (XCL_DIRECT_DXIL=1, XCL_PREPARE_GRAPHICS=0):

xcl-smoke v1
commit: 8b57c36e7971d8d16e6ee48dc526e157ca43c400
gpu: NVIDIA GeForce RTX 4070 SUPER
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1611 (PresentX 1611)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17609 MB

Not tested

  • AMD RDNA / Intel GPUs and Linux / Wine / vkd3d-proton (tested on Windows 11 + NVIDIA RTX 4070 SUPER only).

AI use

  • Antigravity (exact model name not provided to the agent): investigated the thread dump, implemented the fix and unit tests, ran the test suite and smoke check, and drafted this description (reviewed before opening).

Fixes three issues introduced when xcl-dev#2893 moved split compute PSO whole-form compilation off the title thread:

1. Unbounded 64 MiB-stack OS threads: whole_ready() spawned a fresh thread per distinct split PSO, piling up 100+ live xcl-pso-whole threads behind real::huge_compile_turn (6+ GiB stack VA reserved, ~2000 wakeups/s polling GlobalMemoryStatusEx). Replaced with a single persistent xcl-pso-whole worker thread fed by an mpsc channel.
2. Missed xcl-dev#2894 half-headroom rule: standalone xcl-pso-whole threads had pso_async::BUILDING == None, so build_is_late() returned false and every whole-form compile waited for the full 3 GiB+ commit headroom even while indirect dispatches were actively skipped. Added pso_async::with_late_build() (RAII thread-local override) around the worker's jobs.
3. False pc_call() registration: Chain::whole() still called pso_async::pc_call() on background threads, marking parked background workers in PC_CALLS as if a title thread were stalled. Now pc_call() is only taken when building synchronously on a title thread.

Assisted-by: Antigravity
@JJAutoCompare

Copy link
Copy Markdown

Tested: Clean 8b57c36e7971d8d16e6ee48dc526e157ca43c400, Windows 11 build 26200, Ryzen 7 3800X, Rust 1.100.0 MSVC, debug. CPU only. Built with cargo test --locked -j 2 -p xcl --lib --no-run, then ran cargo test --locked -j 2 -p xcl --lib -- --test-threads=1 --nocapture with filters for dispatch_chain::tests, big_compile_tests, pso_async::used_tests, execute_indirect_with_a_pipeline_still_building_is_skipped, async_compute_pso_success_and_failure_in_dispatch_and_execute_indirect, and execute_indirect_skips_failed_shared_console_compute_standin: 61 passed, 0 failed, 0 ignored, 0 skips. A separate rustc --edition=2021 --test harness using the head worker and gate code passed 1 test with zero skips. With 128 jobs queued under simulated low commit, the waiter used zero compile slots. At 2 GiB simulated free commit, one worker drained all 128 jobs in FIFO order.

Not tested: Live split-compute ExecuteIndirect submission, driver compilation and PC_CALLS, GPU readback, full workspace suite and retail smoke.

AI use: T3 Code / Codex (gpt-6.2-sol) ran and independently reran the checks and drafted this report.

@3L1A5-1

3L1A5-1 commented Nov 27, 2026 •

Copy link
Copy Markdown

In-game observation on 8 GB NVIDIA / 16 GB RAM: with 8b57c36e the thread count stays flat through the world burst. Without it, nvidia-dev doubles its threads there. One run per arm. The second arm also carries other local changes (listed below), so this shows the thread behaviour, not a clean A/B of everything else.

Tested

Results

A: eff3bcab B: eff3bcab + 8b57c36e (+ local changes)
Threads before the world burst 131–138 132–137
Threads during the burst 267 (doubled within 30 s of its start) 132–137 (flat)
Process private bytes during the burst +4.5 GB in ~50 s +3.5 GB (22 → 25.5 GB)
Whole-form skips (ExecuteIndirect skipped) 15 512
  • Arm A's doubling and memory jump come right at the start of the burst. That matches the PR's description of one 64 MiB-stack xcl-pso-whole thread per split program. I counted threads per process, not by name, so attributing them to xcl-pso-whole is an inference.
  • Arm B did not survive. The device was removed (0x887a0006, hung) at title 198 s, while arm A ran its 300 s. I'm isolating whether one of our local changes causes that. Counted shader code in B reached 754 MB, far above the ~448 MB NVIDIA code-heap class (NVIDIA: the device is removed when the pipelines in use need more than 512 MB of shader code (0x887a0005) #2403). The skips show that many more whole forms were waiting at once, which fits the burst no longer being throttled by threads. I can't attribute the removal from these runs.

Not tested: this PR alone on eff3bcab (arm B has other changes too), repeats, AMD.

AI use: runs and analysis by Claude Code agents (Claude Sonnet 5.5), report written and checked against the run logs by Claude Code (Claude Opus 5.5).

Update: a second baseline run on eff3bcab (same recipe, 450 s limit) shows the same jump: 131–137 → 302 threads and +4 GB private bytes at the start of the world burst. So the doubling reproduces in 2 of 2 baseline runs. That run ended in a device removal (0x887a0005) at title 272.5 s, with local video memory 4.5 GB over budget, so the 8 GB removal also happens without our local changes.

Update 2 (clean arm): eff3bcab + this PR + #2630 only, with none of our local changes (#2630 creates no threads), same recipe, 450 s limit: threads stayed at 121–136 through the world burst, against 267 and 302 in the two eff3bcab runs. Commit peak 29.7 GB. That run had no device removal (the title stopped presenting at title 241 s; the base alone also ended three different ways in three runs on this PC, so I'm not attributing that). So the thread bound holds without our changes.

@ettehn

ettehn commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Native Windows GPU check for 8b57c36e (RTX 5070 Ti Laptop, driver 621.24, Windows 11 26200.9974, Rust 1.97.1 MSVC, DXC/DXIL 1.8.2502.11, debug).

  • Clean PR head: cargo test --offline --locked -p xcl -j 4 --lib dispatch_chain::tests -- --test-threads=1 --nocapture passed 4/4. The worker test ran 16 jobs on the same late worker.
  • I added a local test-only fixture to exercise whole_ready with an actual NVIDIA PSO. With XCL_CS_PSO_WAIT_MS=1, a synthetic wave32 compute shader split at 12 instructions and one shader memory window, I held the worker behind a channel barrier. Two calls returned Late while the worker was held. After releasing it, the calls returned Ready twice with the same PSO, and D3D12 returned a 1,978-byte driver blob. This verifies creation and reuse through the worker path.
  • The clean gpu_compute_e2e harness reported 5 passed / 2 failed / 0 ignored, with no skips, on both eff3bcab (exact parent) and 8b57c36e (exact head). The failures matched: async_compute_pso_registers_real_pso_and_not_standin at the TRANSLATED_COMPUTE cleanup assertion, and split_compute_prefers_the_offline_whole_pipeline at compiled.dispatch_chain.is_some().

Coverage is synthetic. The local fixture did not execute the resulting whole PSO or run a retail title, so it does not resolve the reported device removal. OpenAI Codex (6.2sol) assisted with verification.

@Decodere

Copy link
Copy Markdown
Contributor

Independent desktop NVIDIA (natural 8 GB VRAM) verification of PR #2921 at head 8b57c36e7971d8d16e6ee48dc526e157ca43c400 (1 commit; exact parent & merge-base: eff3bcabf1b6f99223796ece166948003a53e0bc on nvidia-dev, MERGEABLE against live nvidia-dev ecc0bb57).

Environment

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6C / 12T), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200 (Developer Mode off)
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC 1.9.2609.5, --release

Targeted release tests & build (8b57c36e)

Command Result
cargo test --release -p xcl --lib whole_worker_runs_all_jobs_on_one_late_thread -- --nocapture (3 consecutive runs) 1 passed; 0 failed; 0 ignored; 1727 filtered out × 3 (0.00s × 3, 0 skipped)
cargo test --release -p xcl --lib with_late_build_resets_after_return_and_panic -- --nocapture (3 consecutive runs) 1 passed; 0 failed; 0 ignored; 1727 filtered out × 3 (0.00s × 3, 0 skipped)
cargo test --release -p xcl --lib hle::d3d12x::pso_async:: -- --test-threads=1 (3 consecutive runs) 39 passed; 0 failed; 0 ignored; 1689 filtered out × 3 (3.88s, 3.87s, 3.86s, 0 skipped)
cargo test --release -p xcl --lib hle::d3d12x::real::dispatch_chain:: -- --test-threads=1 (3 consecutive runs) 4 passed; 0 failed; 0 ignored; 1724 filtered out × 3 (0.17s × 3, 0 skipped)
cargo build --release -p xcl Clean build (1m 25s, exit 0, 0 new warnings vs. parent eff3bcab)

Paired quiet 60 s retail smoke (title: 29640639)

Exact parent & merge-base (eff3bcabf1b6f99223796ece166948003a53e0bc, fresh back-to-back baseline on the same machine):

xcl-smoke v1
commit: eff3bcabf1b6f99223796ece166948003a53e0bc
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1579 (PresentX 1579)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14695 MB

PR #2921 (8b57c36e7971d8d16e6ee48dc526e157ca43c400):

xcl-smoke v1
commit: 8b57c36e7971d8d16e6ee48dc526e157ca43c400
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1637 (PresentX 1637)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14743 MB

Runtime log observations (xcl.log)

  • 9430 log lines, 0 [ERROR] / device-removal / panic lines.
  • Final draw/memory telemetry in log: 19357 draws with translated pipelines (0 skipped, 0 with PC pipelines), 1024 dispatches (0 skipped); last memory sample 14743 MB committed by the process; video memory 6118 MB local, 4812 MB non-local.
  • 0 background xcl-pso-whole whole-form split PSO spawns triggered during the warm-cache 60 s smoke on title: 29640639.

Limits of coverage

  • Serialized single-worker late whole-PSO execution and with_late_build panic/return guard reset were verified via both new unit tests (3/3 each), hle::d3d12x::pso_async:: (39/39 × 3), and hle::d3d12x::real::dispatch_chain:: (4/4 × 3).
  • The paired 60 s retail smoke ran with warm shader/driver caches on title: 29640639 (0 cold split whole-form PSO builds triggered), so it confirms zero runtime regression on nvidia-dev rather than reproducing a cold split-program whole-PSO compilation burst (frame-count and peak-commit deltas vs. back-to-back parent reflect single-run startup variance, not this PR).

AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).

@LocranKing

Copy link
Copy Markdown

Independent 180 s paired check on NVIDIA GeForce RTX 3060 Ti (8 GB) (8b57c36e merged with nvidia-dev ecc0bb57, Series S / lockhart profile, identical warm cache snapshot).

Setup

  • Machine: Windows 11 Home build 26300, AMD Ryzen 5 5500 (6C/12T), 31.8 GB RAM, RTX 3060 Ti (8 GB, driver 621.40, nvprofile shader heap 2048 MB), DXC 1.9.2602.17.
  • Env: XCL_DEVICE_TYPE=lockhart XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_TEXTURE_LEVEL_PAGES=1 XCL_PSO_WAIT_MS=50 XCL_GFX_PSO_WAIT_MS=200 XCL_CS_PSO_WAIT_MS=50 XCL_PREPARE_GRAPHICS=0 XCL_DRED=1 + XCL_PRESS_AT (18:A..74:A).

Results (180 s paired runs)

tree frames (PresentX) peak commit local / non-local VRAM peak first two-pass mesh
nvidia-dev (ecc0bb57) 1,825 27,125 MB 9,773 / 4,914 MB 112.9 s
PR #2921 (8b57c36e + ecc0bb57) 1,862 (+2.0 %) 26,012 MB (-1,113 MB) 9,518 / 4,698 MB 111.8 s

Both runs entered the 3D world and exited 0x0 with 0 device removals and 0 crashes (put-off dispatches: 287 put off, 48 recorded, 239 skipped on #2921 vs 390 put off, 76 recorded, 314 skipped on ecc0bb57).

xcl-smoke v1
commit: ecc0bb57976b1bc94854199ddf4f915fd00e0a59
gpu: NVIDIA GeForce RTX 3060 Ti
title: 9cc6a39e
seconds: 180
exit: 0x0
frames shown: 1825 (PresentX 1825)
presents per 2 s (last 3): 1 1 1
device removals: 0
crashes: 0
peak commit: 27125 MB
xcl-smoke v1
commit: 8b57c36e7971d8d16e6ee48dc526e157ca43c400
gpu: NVIDIA GeForce RTX 3060 Ti
title: 9cc6a39e
seconds: 180
exit: 0x0
frames shown: 1862 (PresentX 1862)
presents per 2 s (last 3): 0 2 0
device removals: 0
crashes: 0
peak commit: 26012 MB

Not tested: cold world entry without cached driver blobs, Series X (anaconda) profile.

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

A panic on the shared whole-PSO worker can leave unrelated pipelines permanently pending. The worker exits and drops jobs already accepted by its channel. Each affected chain has already set whole_sent=true, so later calls return Late without retrying even though its job is gone. The synchronous fallback only covers a send that fails immediately. I verified the channel behavior with the exact worker code on Windows: a gated first job panicked after the worker accepted a second job, the second job was discarded, and the stored sender refused new work. Could worker failure explicitly resolve the accepted jobs or clear their pending state so they can recover? A two-job fault-injection fixture would cover this path. Worker loop · Pending flag and fallback

AI use: OpenAI Codex (GPT-6.2 Sol) reviewed the source, ran the isolated CPU-only harness, and drafted this comment. The harness injects a panic in a synthetic job and does not call the driver or run a title.

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.

7 participants