Skip to content

D3D12.X: handle a disconnected PSO worker queue - #2826

Open
CryingLaughing wants to merge 2 commits into
xcl-dev:mainfrom
CryingLaughing:fix/pso-worker-admission
Open

CryingLaughing wants to merge 2 commits into
xcl-dev:mainfrom
CryingLaughing:fix/pso-worker-admission

Conversation

@CryingLaughing

@CryingLaughing CryingLaughing commented Nov 26, 2026 •

Copy link
Copy Markdown

Part of #2787. The admission change follows bmjask’s 0eaef7e6. The review case showed that a bounded bind could otherwise keep getting the stand-in after the regular worker queue closed.

What is in it

  • Track admission separately from pipeline completion. Set the late flag only after a successful send, and wake bounded waiters if the pool declines the job.
  • If the regular channel rejects work, try to start one replacement worker and retry the same work on its queue. Later jobs reuse that worker. Compilation stays off the bounded bind thread. If the replacement cannot start, the job remains available to an unlimited bind or an existing preload worker.
  • Subtract elapsed admission time from the remaining condition-variable wait. Thread startup and scheduling can still add latency.

Tested

  • Rebased head b610d29e92a1b65846fee5abebf6d085fce8c97b on 8b957bec6f82495aec940944c6bf47faa02db590. Windows 11 25H2 build 26200.9974, Core i5-13600K, RTX 4080 driver 621.01, Rust 1.100.0 x64 MSVC, DXC 1.8.2502.11, debug.
  • cargo test --offline --locked -p xcl --lib -j 2 a_disconnected_regular_queue_ -- --test-threads=1 --nocapture passed 2/2, with no capability skips. Injected disconnects covered retrying the first job on one replacement, later reuse, no duplicate sends, no late flag during a concurrent bounded wait while admission is pending, and a later unlimited bind after replacement fails.
  • cargo build --offline --locked -j 2 --workspace passed. cargo test --offline --locked -j 4 --workspace --no-fail-fast -- --test-threads=4 --show-output reported 1,448 passed, 0 failed, 47 ignored across 38 harnesses. The pass count includes 29 explicit capability skips and 10 separate unset optional sample messages.

Regression run

Matched retail smoke is pending for the rebased head. Anon64’s prior-head pair tested ec140e852be1ee06ac10c9f0c2930a7335ae8087 for 60 seconds and reported 99% of baseline frames, 96% of peak commit, and zero crashes or device removals.

Not tested

  • Retail behavior of the rebased head and actual OS refusal to start a worker. Recovery covers rejected sends. Work accepted before the last receiver exits is outside this change.

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

AI-assisted review (OpenAI GPT-6). I traced the disconnected-queue path in this diff; I did not run tests or the game.

if !enqueue(p) {
// Preload may still be able to build the job on its own worker.
p.want();
return built(p);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If the regular worker channel is disconnected and XCL_PSO_WAIT_MS is set, this returns the stand-in while leaving p.job untouched. Since this PR says the regular channel cannot reopen, subsequent bounded binds take the same branch, and this compute PSO can remain a no-op indefinitely unless some separate unlimited bind happens to take the job. Could this path run the retained job or hand it to a guaranteed fallback before returning the stand-in? AI-assisted review (OpenAI GPT-6); I checked the bounded and unbounded resolve paths in this diff and did not run tests or the game.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The follow-up at b610d29e92a1b65846fee5abebf6d085fce8c97b gives a rejected send one replacement worker. Bounded binds keep their time budget and leave compilation on that worker. If the OS declines to start it, the job stays pending for an unlimited bind or an existing preload worker.

An independent RX 9070/Wine check at this exact head exercised the real replacement-start function in three fresh synthetic processes. In each, one worker built the rejected first job and a later job. The simulated starter refusal preserved both jobs, which later built once each through unlimited binds. Across the admission and replacement probes the tester constructed 30 native PSOs and exported nonempty driver blobs. The focused probes had no capability skips. Independent results and limits

Track regular queue admission separately from build completion. A bounded bind can return its stand-in after a refused send, while an unlimited bind can still run the retained job. Follows the queue-admission part proposed in xcl-dev#2787 from bmjask/xcl commit 0eaef7e.
Retry rejected work on one replacement regular worker. Count admission time against the bind wait budget and record a late build only after the queue accepts it.
@Anon64

Anon64 commented Nov 26, 2026

Copy link
Copy Markdown

Regression run of ec140e8 on a newer retail title: no device removal, no crash, frames and commit within the limits.

Setup: RTX 3060 12 GB (NVIDIA 581.80), i9-14900KF, Windows 11 26200, release builds of this PR's base e120925 and of its exact head, run back to back, scripts/smoke.ps1 -Game <title> for 60 s with XCL_NETWORK=0 and A pressed every 4 s from 20 s.

base:

xcl-smoke v1
commit: e120925e3abc9956a8b9bae631969d32e8ccd43c
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1465 (PresentX 1466)
presents per 2 s (last 3): 8 0 7
device removals: 0
crashes: 0
peak commit: 24625 MB

this PR:

xcl-smoke v1
commit: ec140e852be1ee06ac10c9f0c2930a7335ae8087
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1456 (PresentX 1457)
presents per 2 s (last 3): 8 2 4
device removals: 0
crashes: 0
peak commit: 23544 MB

99 % of the base's frames, 96 % of its peak commit. One run each.

Not tested: the suite on this head; whether the title reaches the code this PR changes in its first 60 s; AMD.

AI use: Claude Code (Claude Opus 5.5) ran these runs on this machine and wrote this report.

@CryingLaughing
CryingLaughing force-pushed the fix/pso-worker-admission branch from ec140e8 to b610d29 Compare November 26, 2026 16:05
@SzczepanGrela

Copy link
Copy Markdown

Wine / RDNA4 check of the updated queue recovery, including a real replacement worker building native PSOs.

Tested

  • Current head b610d29e92a1b65846fee5abebf6d085fce8c97b against main 8b957bec6f82495aec940944c6bf47faa02db590.
  • RX 9070 16 GB (RADV GFX1201, PCI 1002:7550), Ryzen 7 7700, CachyOS kernel 7.3.0-5-cachyos, Mesa 26.3.1-arch3.5, GE-Proton11-12 Wine 11.0 Staging, vkd3d-proton 8293130ebe370b1+ (local asserts-disabled build), DXC/DXIL 1.9.2602.17, Rust 1.97.1, release x86_64-pc-windows-gnu.
  • Local cfg(test) fixtures and a typed, thread-local send-injection hook. With no injected sender, the hook delegates to each revision's regular send path. No original assertion or admission/completion condition was changed by the overlay. Removing it reconstructs the pinned source hashes.
  • Explicit RX 9070 selection, XCL_NETWORK=0, XCL_ASYNC_PSO=1, one DXC worker and private enabled caches. The native input is our own no-op HLSL shader, identical 2,044-byte DXIL in all nine native processes.

Original tests

Both updated a_disconnected_regular_queue_* tests plus five neighboring bind/wanted/budget tests, with one and four test threads:

Source Passed / failed / ignored, each run
Main 5 / 0 / 0; the two new tests are absent
Current head 7 / 0 / 0

Native admission probe

Three fresh processes per revision, with healthy admission, a final injected send refusal, and an image-only resolve called while the send callback is still in progress:

Observed flag Main Head
late after refused admission true false
late inside the in-progress send callback true false
late after the healthy queue's ordinary wait expires true true

Each case makes exactly one send attempt, performs no inline build during the bounded call, and later completes exactly one actual RX 9070 compute PSO through the admitted callback or an unlimited bind. The head probe passes 1/0/0 in each process. Main's final admission assertion fails 0/1/0 in each process, after all three native controls and object cleanup have completed.

Replacement worker, current head

A separate local test uses RegularWorkers and the unchanged start_regular_worker to recover a closed queue. Three fresh processes, 1/0/0 each:

  • Success: one real Wine thread named xcl-pso-workflow-replacement builds both the rejected first job and a later job. Both job bodies assert that thread name; neither compiles on the bounded bind thread. Exactly one replacement-start attempt and two native PSO builds.
  • Simulated starter refusal: the starter returns false. Two jobs cause only one replacement attempt for the pool, remain pending and unmarked late during bounded binds, then each builds once on its later unlimited bind.

Across the paired admission probe and replacement tests, all 30 PSOs were constructed successfully on PCI 1002:7550 and exported a nonempty 112-byte driver blob. This checks construction/export, not acceptance of a supplied cache blob. All 13 top-level summaries, queue/job counters, thread names, DXIL/blob bytes, source inventories and executable hashes were independently checked. No runtime skips or ignored tests.

Build: cargo test --offline --locked --release --target x86_64-pc-windows-gnu -p xcl --lib --no-run. Original selectors under hle::d3d12x::pso_async::used_tests::, passed together with --exact --nocapture --test-threads=1 / 4:

a_disconnected_regular_queue_reuses_one_replacement_worker
a_disconnected_regular_queue_keeps_the_job_for_an_unlimited_bind
a_bind_of_a_shared_stand_in_gets_its_driver_pipeline
a_bind_does_not_wait_for_a_pipeline_that_writes_only_images
a_bind_waits_for_a_slow_pipeline_no_longer_than_its_budget
a_waiting_bind_makes_the_builds_compiles_wanted
a_waiting_bind_makes_the_build_wanted

Local selectors under hle::d3d12x::pso_async::: workflow_queue_admission_recovers_native_pipelines and workflow_replacement_worker_builds_native_pipelines, each exact/serial under GE-Proton Wine. Inherited XCL_* flags are cleared before the explicit settings.

Not tested

Actual OS refusal to start a thread, work accepted before its receiver exits, preload/contending-waiter stress, scheduling delays under load, GPU dispatch or output, retail inputs, scripts/smoke.ps1, full suite, native Windows, other GPUs, performance or FPS. The first probe injects the final send outcome; the separate replacement test exercises the actual replacement-start function.

AI use

OpenAI Codex (GPT-6; exact serving variant not exposed) reviewed both revisions, reran after the material head update, added the local synthetic fixtures, verified the evidence and drafted this report. Publication authorized by the account owner.

@MatyEjsr

Copy link
Copy Markdown

Independent Windows/NVIDIA verification and concurrency review of PR #2826 at head b610d29e92a1b65846fee5abebf6d085fce8c97b (cleanly rebased onto origin/main 8b957bec6f82495aec940944c6bf47faa02db590, MERGEABLE, no duplicate PRs or superseding changes on main/nvidia-dev; other open PRs touching pso_async.rs (#628, #828, #889, #899, #1113) cover separate scheduling, preloading, or logging changes).

Tested

  • OS / CPU / GPU / RAM: Windows 11 Pro for Workstations Build 26200 x64, AMD Ryzen 7 7800X3D, NVIDIA GeForce RTX 3090 (24 GB, driver 32.0.16.1742), 32 GB RAM (31 GB usable), Windows Developer Mode enabled
  • Toolchain: Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17, debug (test suite) and release (xcl build)
  • cargo build --release -p xcl -j 8: passed (40.58 s)
  • cargo build --workspace -j 8: passed (7.68 s)
  • cargo test -p xcl --lib -j 8 pso_async -- --test-threads=1 --nocapture: 16 passed, 0 failed, 0 ignored (1331 filtered out, 1.19 s, 0 capability skips), including a_disconnected_regular_queue_reuses_one_replacement_worker and a_disconnected_regular_queue_keeps_the_job_for_an_unlimited_bind
  • cargo test -p xcl --lib -j 8 pso_async -- --test-threads=8: 16 passed, 0 failed, 0 ignored (1331 filtered out, 0.61 s, 0 capability skips)
  • cargo test --workspace -j 8 --no-fail-fast -- --test-threads=8 --show-output: 1448 passed, 0 failed, 47 ignored across 38 test harnesses (exit 0); the pass total includes 28 SKIPPED capability checks (21 no wave64, 3 wave32 per-lane f16/V_CVT_F16_F32 refusals, 3 missing D3D12 debug layer / d3d12SDKLayers.dll, 1 no heap windows) plus 10 unset XCL_SAMPLE_* notices, none counted as passing coverage.

Review notes (crates/xcl/src/hle/d3d12x/pso_async.rs)

  • RegularWorkers::send retries a rejected mpsc::Sender::send once on a fresh (sender, receiver) channel and reuses that replacement worker for later jobs; send_to_workers wraps the replacement receiver in a new Arc<Mutex<mpsc::Receiver<Work>>> (avoiding a poisoned original mutex) and drops rejected Work closures after releasing queue().
  • enqueue_on serializes first submission with compare_exchange(Unsent -> Sending) and publishes RegularQueue::Disconnected under p.done.lock() before p.cv.notify_all(), closing the lost-wakeup race in resolve_within.
  • resolve_within subtracts elapsed admission time from the wait budget and gates p.late on RegularQueue::Sent; resolve_spared also checks RegularQueue::Sent before marking p.late. submit_as, resolve, resolve_within, and resolve_spared route through enqueue, while build_pieces and need_by_submit route through send_to_workers so they share the single-replacement worker path.

Not tested

  • Matched retail scripts/smoke.ps1 pair (8b957bec vs b610d29e): on merge-base 8b957bec, startup shader preparation (prepare_for_launch with p.max_dxil = 0 on uncached compute pipelines) exceeded the default 180 s smoke.ps1 deadline (-Seconds 60, default -StartupTimeoutSeconds 120), so no paired retail smoke block was captured on this machine.
  • AMD / Intel GPUs and native wave64, actual OS thread-spawn failure, and worker exit after work admission.

AI use

  • Antigravity (agy) with gemini-pro-orchestrator-neon (audited by gemini-pro-orchestrator-argon) built and ran the test suite, checked PR metadata/diff, and drafted/audited this verification report.

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.

5 participants