Skip to content

d3d12x: bound PSO bind waits, guard pending draws, and auto-init uninitialized targets - #1652

Draft
rdj415 wants to merge 8 commits into
xcl-dev:mainfrom
rdj415:pso-compile-watchdog-unblock
Draft

rdj415 wants to merge 8 commits into
xcl-dev:mainfrom
rdj415:pso-compile-watchdog-unblock

Conversation

@rdj415

@rdj415 rdj415 commented Nov 24, 2026 •

Copy link
Copy Markdown

Stacked on #1274. Prevent title watchdog freezes and DXGI_ERROR_DEVICE_HUNG (0x887A0006) during cold shader compilation by bounding PSO bind waits per frame, skipping draws/dispatches with pending or unready pipelines, auto-initializing uninitialized placed/reserved RT/DS targets before the first draw, keeping D3D12_HEAP_FLAG_CREATE_NOT_ZEROED for non-RT/DS streaming textures, and blocking Backtrace telemetry uploads.

What is in it

  • crates/xcl/src/hle/d3d12x/pso_async.rs, crates/xcl/src/gpu/recomp/dxc.rs, crates/xcl/src/hle/d3d12x/present.rs: bound runtime PSO bind waits (wait_budget: 250 ms per PSO, 2,000 ms cumulative per PresentX frame via present::frame_generation; resolve_wait_critical grace cap CRITICAL_FRAME_WAIT_CAP_MS = 2,000 ms; XCL_PSO_WAIT_MS=0 for unbounded waits), replace FIFO queues in pso_async and dxc with priority-aware scheduling so wanted/warm builds preempt unwanted cold builds, and drop expired background worker threads to BELOW_NORMAL.
  • crates/xcl/src/hle/d3d12x/bind.rs: close the resolve_wait / is_pending TOCTOU window via resolve_wait_checked, skip draws and ExecuteIndirect dispatches when a translated pipeline is still pending or failed (graphics_bound_with, note_compute_signature / is_compute_signature), and avoid passing unready stand-in PSOs to the PC driver.
  • crates/xcl/src/hle/d3d12x/list_x.rs, crates/xcl/src/hle/d3d12x/real.rs, crates/xcl/src/hle/d3d12x/device_x.rs, crates/xcl/src/hle/d3d12x/vram.rs: track placed/reserved/committed RT/DS targets and RTV/DSV handles (note_uninit_target_if_rt_ds, ensure_bound_targets_initialized, cl_discard_resource), strip D3D12_HEAP_FLAG_CREATE_NOT_ZEROED only for RT/DS targets and indirect buffers (should_strip_not_zeroed_resource) while preserving CREATE_NOT_ZEROED for ordinary textures/streaming buffers, coalesce duplicate in-flight compute PSO compiles (ComputeFlight), and persist slow (>= 250 ms) <16 KiB compute driver blobs to driver_cache.
  • crates/xcl/src/hle/netoff.rs, crates/xcl/src/host.rs: hook winhttp.dll!WinHttpConnect (install_telemetry_block) to reject *.backtrace.io uploads with ERROR_WINHTTP_NAME_NOT_RESOLVED while forwarding all other hosts untouched.

Tested

  • hardware & toolchain: NVIDIA GeForce RTX 5060 Ti (driver 616.64 / 32.0.16.1664), 12th Gen Intel(R) Core(TM) i5-12400F, rustc 1.98.0-nightly (096694416 2026-06-29), release build and debug unit tests on Windows.
  • cargo test -p xcl --lib -- --nocapture (commit fb07ff8): 747 passed, 0 failed, 21 ignored (SKIPPED GPU tests on 32-lane hardware: gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64).
  • Retail smoke comparison via scripts/smoke.ps1 -Seconds 60 on clean 9e3831e (upstream/main) and clean fb07ff8 (pso-compile-watchdog-unblock).

Regression run

main:

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: NVIDIA GeForce RTX 5060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1013 (PresentX 1014)
presents per 2 s (last 3): 20 6 0
device removals: 0
crashes: 0
peak commit: 11409 MB

PR:

xcl-smoke v1
commit: fb07ff8295fea2613a90256449b01d7718542f0b
gpu: NVIDIA GeForce RTX 5060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 888 (PresentX 889)
presents per 2 s (last 3): 22 0 0
device removals: 0
crashes: 0
peak commit: 11600 MB

Not tested

  • cargo test --workspace -- --test-threads=4, cargo test -p xcl --test gpu_compute_e2e, cargo test -p xcl --test shaders_e2e, and Python helper tests on commit fb07ff8.
  • Wave64 AMD GPUs, Linux (Wine + vkd3d-proton), and multi-title runtime runs beyond <game folder>.

AI use

  • Gemini 4 neon: assisted with implementing the bounded PSO wait/priority queues, pending-PSO draw/dispatch guards, uninitialized RT/DS target auto-init, Backtrace upload block, cherry-picking cleanly onto d3d12x-console-vtable-slots (15fab80), resolving the real.rs conflict, running cargo test -p xcl --lib, and running the scripts/smoke.ps1 verification.

…le-slots

# Conflicts:
#	crates/xcl/src/hle/d3d12x/device_x.rs
- Default bind waits (pso_async::wait_budget) to 250 ms per PSO and 2,000 ms cumulative per PresentX frame (present::frame_generation) when running a title (XCL_PSO_WAIT_MS=0 restores unbounded waits; tests without a booted title stay unbounded).
- Replace FIFO queues in pso_async::queue and dxc::pool with priority-aware queues so wanted and fresh/warm PSOs preempt late/unwanted builds without head-of-line blocking; clear wanted_flag and drop background xcl-pso-* / xcl-dxc-* worker priority to BELOW_NORMAL once a timed wait expires.
- Add per-key in-flight coalescing (ComputeFlight / coalesce_compute_build) in real::translated_compute_pso so duplicate cold keys wait for the leader driver blob while distinct keys compile in parallel, and persist slow (>= 250 ms) <16 KiB compute driver blobs to driver_cache.
- Close the resolve_wait + is_pending TOCTOU window in bind::execute_indirect via resolve_wait_checked.
- Hook winhttp.dll!WinHttpConnect via a shared OnceLock detour (netoff::install_telemetry_block, wired in host::host_main) to refuse *.backtrace.io crash uploads with ERROR_WINHTTP_NAME_NOT_RESOLVED while forwarding all other hosts untouched.
@throny

throny commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

World-loading test of fb07ff8 merged onto main c160d86, against c160d86 itself, on the retail title (counts only).

Result: in 3 of 6 runs of this PR, the process's commit climbed from about 16 GB to over 30 GB within 6 – 8 s while the title was still on its menu (22 – 44 s into the run, at about 2.5 – 3 GB/s), and our memory guard stopped the run. None of the 4 main runs did this; they stay between 15 and 17.5 GB over the same stretch. So I couldn't check whether the PR gets past the stall: main ends at the title's watchdog at 110 – 113 s in all 4 runs, and the other 3 PR runs were stopped by the guard at 85 – 92 s with about 30 GB of commit, before that point.

runs build process commit end
4 main 15.1 – 15.3 GB at 20 s, 17.1 – 17.5 GB at 44 s watchdog at 110 – 113 s
3 PR about 15.2 GB at 20 s and 17.2 GB at 44 s, then about 30 GB in world loading guard at 85 – 92 s
1 PR 15.8 GB at 20 s, 30.2 GB at 44 s guard at 45 s
1 PR 16.2 GB at 20 s, 35.0 GB at 38 s guard at 39 s
1 PR 15.2 GB at 18 s, 34.0 GB at 26 s guard at 27 s

The log shows no shader or PSO activity during the climbs, only the menu's normal presents (60 per 2 s). In the runs that reached world loading, the PR skipped 322 – 1 024 draws and 1 024 – 2 708 dispatches.

Tested

  • RTX 4080 (32-lane waves), i9-12900K, 64 GB (commit limit 68 GB; the guard stops a run below 6 GB of free system commit, so a process gets about 30 – 35 GB), Windows 11 26300, release builds.
  • Runs in a row on one shader cache, no input. main: 2 runs with the default DXC threads, 2 with XCL_DXC_THREADS=4. PR: 2 with the default, 4 with XCL_DXC_THREADS=4 (all three jumps were in those).

Not tested: the suite on this head, AMD, a machine with more free commit (whether the PR gets to the end of the stall), and what allocates during the climbs.

This PR is about 2 800 added lines and bundles several changes (PSO wait budget, DXC queue scheduling, skipped draws, target initialisation, NOT_ZEROED handling, driver-blob persistence, a telemetry block). Split into separate PRs, a memory jump like this one could be traced to one of them.

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

@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored.

Thanks!

@milesah3ad

Copy link
Copy Markdown

@rdj415 a question before I write anything, so we don't end up with two PRs for the same thing again. Would you split the per-frame cap on bind waits out of this PR into a small one of its own? That's wait_budget against a cumulative limit per PresentX frame (present::frame_generation), with binds past it going on with the stand-in. If you'd rather not, I'm happy to write it as a standalone PR that credits this one.

Why that piece on its own:

AI use: Claude Code (Claude Opus 5.5) drafted this.

RVZO6 added a commit to RVZO6/xcl that referenced this pull request Nov 25, 2026
…late PSOs

Add pso_async::resolve_wait_checked returning ResolveOutcome (Untracked,
Ready, Pending, Failed) under a single p.done lock, and short-circuit
already-late pipelines under a wait budget without constructing Held::new()
so skipped draws do not freeze kernelx::Sleep via title_held().

Use resolve_wait_checked in bind::execute_indirect to close the TOCTOU
window between resolve_wait and is_pending and stop failed translated
graphics stand-ins from reaching the PC command list. Factor
bind_abi_resolved so dispatch and execute_indirect skip a second PENDING
lookup.

Stacked on d3d12x/pso-async-lane-isolation. Part of xcl-dev#1452, xcl-dev#505, xcl-dev#1652.

Assisted-by: T3 Code (Antigravity, gemini-4-neon)
@rdj415

rdj415 commented Nov 25, 2026

Copy link
Copy Markdown
Author

@throny @milesah3ad Thanks for testing and the clear breakdown!

I split out just the per-frame PSO bind wait cap (present::frame_generation + FrameBudget / XCL_PSO_FRAME_WAIT_MS, with deterministic unit tests and a paired 60 s smoke run on current main) into #2114 so it can be reviewed and tested independently from the commit-growth regression and the rest of the changes here.

For the open question on #1452: on a longer Windows RTX 5060 Ti run of #2114 alone (8044bed), the per-frame cap kicked in during world load (at 694.8 s) and kept the title past its watchdog with 0 device removals, reaching the opening cutscene dialogue (72,927 Opus packets decoded, 0 errors) and opening credits. Wait64BitValueX did time out 40 times at 2,000 ms while cold compute pipelines were still compiling (46,227 dispatches skipped), without triggering a device removal.

Converting this PR to draft while breaking out the remaining pieces cleanly.

@rdj415
rdj415 marked this pull request as draft November 25, 2026 05:06
@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
RVZO6 added a commit to RVZO6/xcl that referenced this pull request Nov 25, 2026
…late PSOs

Add pso_async::resolve_wait_checked returning ResolveOutcome (Untracked,
Ready, Pending, Failed) under a single p.done lock, and short-circuit
already-late pipelines under a wait budget without constructing Held::new()
so skipped draws do not freeze kernelx::Sleep via title_held().

Use resolve_wait_checked in bind::execute_indirect to close the TOCTOU
window between resolve_wait and is_pending and stop failed translated
graphics stand-ins from reaching the PC command list. Factor
bind_abi_resolved so dispatch and execute_indirect skip a second PENDING
lookup.

Stacked on d3d12x/pso-async-lane-isolation. Part of xcl-dev#1452, xcl-dev#505, xcl-dev#1652.

Assisted-by: T3 Code (Antigravity, gemini-4-neon)
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.

4 participants