Skip to content

D3D12.X: bound driver PSO compile concurrency and surface stage progress (#156) - #214

Draft
heretic1321 wants to merge 1 commit into
ivall:mainfrom
heretic1321:fix/nvidia-pso-stall
Draft

heretic1321 wants to merge 1 commit into
ivall:mainfrom
heretic1321:fix/nvidia-pso-stall

Conversation

@heretic1321

@heretic1321 heretic1321 commented Nov 23, 2026 •

Copy link
Copy Markdown

Draft mitigation + stage instrumentation for #156, rebased cleanly onto upstream/main (4017f8f, tip 960162e; untested on Windows/GPU by me — thank you to @yous0serious and @Kalmarv for the RTX 4090 / RTX 5070 Ti runs and reviews).

Review responses (@yous0serious, @Kalmarv)

  1. Title / xcl-pso-urgent threads waiting behind background xcl-pso-N slots (both reviewers):
    • Fixed. DriverCompileGuard::enter now gates only background xcl-pso-N workers (is_background_pso_worker_name: starts_with("xcl-pso-") && != "xcl-pso-urgent") on BIG_COMPILES, wait_for_commit(), and driver_compiles(). Title threads (dev_create_*_pso, resolve_wait) and xcl-pso-urgent bypass both semaphores and wait_for_commit() completely so a blocking bind never queues behind unrelated background compiles or a 30 s commit wait, while still updating DRIVER_COMPILING and timing logs (lane=urgent vs lane=bg).
    • Added unit test urgent_and_title_threads_are_exempt_from_background_slots saturating both BIG_COMPILES and driver_compiles() and verifying both the caller thread and an xcl-pso-urgent thread enter immediately.
  2. Admission wait not timed (@Kalmarv Note #2):
    • Fixed. DriverCompileGuard now records wait_started before semaphore / commit-wait admission, logs both compile duration and admission wait ({elapsed:.2}s (wait {waited:.2}s, hr=..., concurrent=..., {lane})), and triggers the slow-compile log when either elapsed >= 2 s or waited >= 2 s (or XCL_TRACE_PSO_TIME=1).
  3. Flaky global QUEUED assertion in dormant_lazy_pipelines_are_not_counted_as_queued (@yous0serious):
    • Fixed. Factored mark_enqueued(p, queued) and finish_pending(p, real, queued) in pso_async.rs and updated the test to assert against a local AtomicUsize::new(0) instead of reading global QUEUED, eliminating parallel-test flakiness.
  4. DXC 1.7 vs 1.9 size threshold (@Kalmarv Note Implement XSystemGetDeviceType/PLS thunks and Opus audio carrier parsing #1):
    • Acknowledged: DXC 1.9 shrinks translated DXIL by 2–4× (e.g. 633 KB → 235 KB), so a fixed 256 KiB default classifies fewer DXC 1.9 shaders as "big". XCL_BIG_PSO_KB already exposes the threshold at runtime (e.g. XCL_BIG_PSO_KB=128 with DXC 1.9) without recompiling.
  5. Rebase & 3-PR split (@Kalmarv Note XAudio2: real Opus decoder via Windows MSOpusDecoder MFT #3):
    • Rebased cleanly as a single commit onto upstream/main (4017f8f) — #187 / #162 / #206 are no longer stacked here, main's retry_without_rect_gs stays inside DriverCompileGuard, standin_graphics uses main's pc_topology_type, and pso_async.rs is on main's submit_as / resolve_wait.
    • Split feasibility: Yes, this remaining diff is cheap to split cleanly into three independent PRs with zero cross-dependencies:
      1. real.rs + present.rs: background driver concurrency limits (DriverCompileGuard), 30 s wait_for_commit cap, admission + compile timing, and window-title driver progress;
      2. pso_async.rs: lock-free QUEUED accounting + isolated unit test;
      3. real.rs: fallback_stream subobjects 14/15/16 + translated_gs_pso RTV/DSV format conversion.
    • Keeping them in this single draft PR for now so we do not open extra PRs unprompted; happy to split into those three PRs as soon as maintainers confirm.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs:
    • DriverCompileGuard bounding background (xcl-pso-N) driver Create*PipelineState concurrency across all translated paths (CS, VS+PS wrapping retry_without_rect_gs, MS-mesh/MS-cs, GS-mesh/GS-cs): BIG_COMPILES (1) → wait_for_commit() (30 s cap + warning) → driver_compiles() (XCL_DRIVER_COMPILE_THREADS, default 2 on 32-lane-only / NVIDIA, 4 on 64-lane). Title and xcl-pso-urgent threads are exempt from both semaphores and wait_for_commit().
    • driver_compile_counts(), admission + compile timing (>= 2 s or XCL_TRACE_PSO_TIME=1), and unit tests (big_compile_serialization_leaves_fast_lane_for_small_compiles, urgent_and_title_threads_are_exempt_from_background_slots).
    • Console topology/RTV/DSV translation in fallback_stream (subobjects 14/15/16) and RTV/DSV format translation in translated_gs_pso.
  • crates/xcl/src/hle/d3d12x/pso_async.rs:
    • Lock-free O(1) counts() via atomic QUEUED + mark_enqueued/finish_pending/enqueue helpers excluding dormant lazy stand-ins, plus isolated unit test dormant_lazy_pipelines_are_not_counted_as_queued.
  • crates/xcl/src/hle/d3d12x/present.rs:
    • Surfaces active and completed driver PSO compiles alongside DXC and queued counts in the window title (compiling shaders: N dxc, M done, D driver (C done), Q pipelines queued).

Overlaps

Validation & what was NOT tested

  • Validated on Linux (Rust 1.95.0) at 960162e:
    • AR_x86_64_pc_windows_msvc=llvm-ar cargo check --release --workspace --target x86_64-pc-windows-msvc — exit 0 (6.31s, 0 errors, 0 warnings).
    • AR_x86_64_pc_windows_msvc=llvm-ar cargo check --tests --workspace --target x86_64-pc-windows-msvc — exit 0 (2.77s, 0 errors, 0 warnings).
  • NOT tested by me:
    • No Windows machine, no MSVC link, no cargo test execution on this revision (960162e).
    • No GPU run or retail title run on this revision.

AI use

Gemini 4 Neon (Antigravity CLI), human-reviewed. Single commit on upstream/main 4017f8f, 3 files (+360/-38 lines). Compile-checked for x86_64-pc-windows-msvc on Linux; no Windows, GPU or title run.

@yous0serious

Copy link
Copy Markdown
Contributor

Tested on Windows + NVIDIA (RTX 4090)

The PR says it was never built or run on Windows, so here is a Windows / NVIDIA run. No retail game here, so the measurement plan above (thread dumps, XCL_TRACE_PSO_TIME) is not covered – only build, test suite and the synthetic GPU experiments.

Setup: Windows 11, i7-13700KF, RTX 4090 (driver 32.0.16.2101, wave32 only), Rust 1.100 MSVC, Agility SDK 1.620.2, Windows SDK DXC 1.8.2502 (and DXC 1.9.2609 for E2).

what result
cargo build --release --workspace (MSVC link) ok, no new warnings
cargo test --workspace --release -- --test-threads=4, branch as is (bf2a27e) 592 passed, 0 failed (2 SKIPPED … no wave64)
same, branch merged into current main (af20b4b) merges without conflicts; 631 passed, 0 failed, e2e test title included
new tests pso_async::tests::dormant_lazy_pipelines_are_not_counted_as_queued, queue_tests::big_compile_serialization_leaves_fast_lane_for_small_compiles pass (3 runs)
aperture_tests GPU tests (from #187) 3 / 3 pass

E2 (e2_window_compile_time, 700 blocks, 19 601 instructions, median of 3):

form DXIL DXC 1.8.2502 DXC 1.9.2609 driver (3 runs, sorted)
1 window 190 KB 3.80 s 3.49 s 0.00, 0.00, 3.7–3.8 s
4 windows, switch 512 KB 54.2 s 44.2 s 0.00, 0.00, 7.9 s
4 windows, heap (#187) 238 KB 4.6 s 4.0 s 0.00, 0.00, 1.2–1.4 s

On this NVIDIA card the DXC step dominates, not the driver: the heap windows cut DXC ~12× and the driver's one cold compile ~6× against the switch form. Two of three driver compiles per form return in < 10 ms despite the random literal (the driver's cache, presumably) – the test prints them sorted, so only the cold one is meaningful. DXC 1.9 vs the SDK's 1.8 is only 10–18 % here (the big gap in #156 was against 1.7). E1b could not run (no debug layer through the Agility factory here, 0x887A002D).

One thing from reading the code (not measured – no game)

Title-thread compiles now wait on the background slots. Before this PR only xcl-pso-N workers took BIG_COMPILES (big compute only); a compile on the title's own thread (dev_create_*_pso → dxc::urgent(…) when there is no stand-in) or on xcl-pso-urgent (pso_async::resolve_wait, a bind waiting for its pipeline) went straight to the driver. With DriverCompileGuard::enter every translated compile takes a driver_compiles() slot (2 on NVIDIA), and a big one BIG_COMPILES (1) first. Up to cores - 1 workers wait on the same Condvar (notify_one, no order or priority), so a title thread that blocks for one pipeline can wait behind several unrelated background compiles – and behind a big one holding BIG_COMPILES through up to 30 s of wait_for_commit plus its own driver compile. Letting threads that are not xcl-pso-N workers bypass the slots (or giving them a reserved lane) would keep the bound on background work without stalling the title. wait_for_commit already exempts xcl-pso-urgent; the slots don't.

Minor: dormant_lazy_pipelines_are_not_counted_as_queued compares the global QUEUED before / after while other lib tests may queue pipelines in parallel – passed 3 / 3 here, but it could flake.

AI-assisted (GitHub Copilot); runs and numbers are from my machine.

@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested on an RTX 5070 Ti, merged onto main. The PR fixes two things that fail on main, and it no longer merges. Three notes follow.

What it fixes, shown on main:

  • The PR's dormant-count test fails on main and passes on the merge.
  • A native PSO test with stream stand-ins: main returns E_INVALIDARG for topology 19, RTV format 116, DSV format 118 and the three together. The merge creates all four. A control with PC formats succeeds on both.

Notes:

  1. The size threshold depends on the DXC version. At the default 256 KiB (real.rs:3071), all three E2 forms below take the large-pipeline slot with the SDK's DXC 1.7. With DXC 1.9 only the four-window switch form does, because 1.9's DXIL is 2–4× smaller. The same thing happened to NVIDIA (RTX 5070): graphics pipelines never finish – nvgpucomp64 stalls on large translated shaders (+ 2 fixes: chad.dll XDsp, XMemMapPhysicalPagesScatter) #156's F case, which shrank from 633 KB to 235 KB.

  2. The wait for a slot isn't timed. The compile trace starts after both semaphores are taken (real.rs:3208). With the two small slots held, an xcl-pso-urgent thread waited 251 ms to get in, and its compile timer then read 300 ns. Timing the admission wait separately would show that part of a bind stall (NVIDIA (RTX 5070): graphics pipelines never finish – nvgpucomp64 stalls on large translated shaders (+ 2 fixes: chad.dll XDsp, XMemMapPhysicalPagesScatter) #156).

  3. Rebase.

    It might go in more easily as three PRs:

    • driver limits, commit wait and timing, keeping main's rect-GS retry inside the guard;
    • the queued-count accounting and its test, on main's submit_as / resolve_wait;
    • the mesh / GS deferral and stream stand-in format conversion, with the native PSO test. Main already converts graphics stand-in topology.

E2 (from #187) at 700 blocks / 19,601 instructions. Each cell is DXIL bytes, median DXC seconds, and the range of three driver times in seconds:

E2 form SDK DXC 1.7.2308.16 DXC 1.9.2602.17
one window 695,172 / 4.43 / 0.05–6.62 190,328 / 3.97 / 0.02–2.99
four, switch 1,035,432 / 6.90 / 0.11–57.76 512,328 / 61.37 / 0.06–59.34
four, heap 807,024 / 4.85 / 0.04–6.97 237,660 / 4.84 / 0.02–3.50

Tested

  • Windows 11, RTX 5070 Ti (NVIDIA 610.74), Rust 1.99.0, release, run serially. Counts are passed / failed / ignored:
Revision SDK DXC DXC 1.9
head bf2a27e 556 / 0 / 21 556 / 0 / 21
main 60565c4 611 / 0 / 20 —
merge onto 60565c4 620 / 0 / 22 620 / 0 / 22
  • e2_window_compile_time (ignored bench) on the same merge.
  • 7a033c8: a merge check only.

Not tested

  • A retail load, peak commit, the low-commit timeout.
  • AMD.
  • Driver cache state was not controlled.

🤖 GPT-6.2 Astra, Claude Opus 5.5

heretic1321 added a commit to heretic1321/xcl that referenced this pull request Nov 23, 2026
Part of ivall#232. The null write at title+0x2215c35 is the retail game's
hang watchdog (`mov dword [0], 0`, identified in ivall#156), not a bad
pointer from the layer: it fires when one of the title's threads stays
silent for long (~30 s per ivall#214).

With lazy pipelines a graphics pipeline is sent to the workers at its
first SetPipelineState (`resolve_for_bind` -> `resolve`), and then
`bind::graphics_bound` / `execute_indirect` call `resolve_wait`: that
waits for the build without any limit, and runs it in the title's own
thread when no worker has taken it yet. An NVIDIA driver takes 10-17 s
for one big translated pixel shader (ivall#156 measurements), so a frame
that binds a few new ones holds the title's thread past its watchdog.

Now a draw sends the build to the workers and waits at most what is left
of 4 s between two presents (`XCL_PSO_WAIT_MS`, 0 = no limit as before).
Past it the draw uses the stand-in (draws nothing), logged per pipeline.
Compute pipelines are still waited for as before. Every pipeline wait
of 2 s or more is logged with the thread, so a run shows what held it.

Assisted-by: Antigravity (Claude Opus 5.5)
@heretic1321 heretic1321 changed the title D3D12.X: bound driver PSO compile concurrency and fix lazy/stand-in paths (#156) D3D12.X: bound driver PSO compile concurrency and surface stage progress (#156) Nov 23, 2026
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.

3 participants