Skip to content

D3D12.X: bound wait_for_commit so big background compiles cannot deadlock - #567

Closed
gridoe wants to merge 1 commit into
xcl-dev:mainfrom
gridoe:wait-for-commit-bound
Closed

gridoe wants to merge 1 commit into
xcl-dev:mainfrom
gridoe:wait-for-commit-bound

Conversation

@gridoe

@gridoe gridoe commented Nov 24, 2026 •

Copy link
Copy Markdown

Bound wait_for_commit in d3d12x/real.rs with a 5 s grace timeout so big background compute PSO compiles cannot permanently deadlock BIG_COMPILES.

Previously, wait_for_commit polled GlobalMemoryStatusEx in an unbounded loop until ullAvailPageFile >= 3 GiB while holding the single BIG_COMPILES (most: 1) slot. On a 32 GB Windows system with a system-managed dynamic pagefile (~47 GB initial commit limit), once a retail title commits ~41–42 GB, Windows does not expand pagefile.sys while threads only poll GlobalMemoryStatusEx. The worker then slept indefinitely holding BIG_COMPILES, starving every subsequent queued compute PSO behind it.

Keeping BIG_COMPILES serialized to 1 and the 3 GiB target unchanged, wait_for_commit now waits up to 5 s (BIG_COMMIT_GRACE) before proceeding one compile at a time and logging once if the grace window expires.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs: extract avail_pagefile_bytes and wait_for_commit_with with a 5 s BIG_COMMIT_GRACE cap, log once when proceeding below the 3 GiB target, and add unit tests wait_for_commit_returns_when_headroom_appears and wait_for_commit_does_not_hang_forever_below_reserve.

Tested

  • Hardware / OS / toolchain: NVIDIA GeForce RTX 3080 (10053 MiB VRAM, driver 617.42, wave32), AMD Ryzen 7 5700X3D (16 logical CPUs), Windows 10 IoT Enterprise LTSC 2024 26H2 (Build 26300.9974), DXC 1.9.2602.17, rustc 1.99.1 (58cf8f9c3 2026-10-13) (stable-x86_64-pc-windows-msvc), debug (tests) and release (smoke).
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 682 passed, 0 failed, 41 ignored.
  • SKIPPED GPU tests on this adapter: 2 (no wave64 — gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware).
  • New tests wait_for_commit_returns_when_headroom_appears and wait_for_commit_does_not_hang_forever_below_reserve pass.

Regression run

xcl-smoke v1
commit: 508a0c74d7c0625d6d2de8d24494e69dc2e1926f
gpu: NVIDIA GeForce RTX 3080
title: d2d324b7
seconds: 60
exit: 0x0
frames shown: 1443 (PresentX 1443)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14466 MB
xcl-smoke v1
commit: 7a63914dcaf56cd930a91b3874ffcca88e80ad3c
gpu: NVIDIA GeForce RTX 3080
title: d2d324b7
seconds: 60
exit: 0x0
frames shown: 1433 (PresentX 1434)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14441 MB

Not tested

  • AMD / Intel GPUs and wave64-native adapters.
  • 16 GB or fixed-pagefile Windows machines where pagefile.sys cannot grow past the initial commit limit.
  • Other retail titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and sample-data tests requiring XCL_SAMPLE_* env vars.
  • Note: the 60 s smoke run stays on the menu/intro and does not reach the ~41 GB world-loading commit threshold where wait_for_commit previously wedged; that path is exercised by the new unit tests.

AI use

  • Antigravity with Gemini: diagnosed the dynamic-pagefile deadlock from local logs, wrote wait_for_commit_with, unit tests, and the PR description; all builds, tests, and smoke runs were executed locally on the hardware listed above.

…lock

wait_for_commit previously polled GlobalMemoryStatusEx in an unbounded loop until 3 GB of pagefile commit were free, while holding BIG_COMPILES (most: 1).

On Windows with a system-managed dynamic pagefile (e.g. 32 GB RAM + 15 GB initial pagefile = ~47 GB commit limit), once a retail title commits ~41-42 GB, ullAvailPageFile remains below 3 GB because Windows only grows pagefile.sys on an actual allocation rather than while threads poll GlobalMemoryStatusEx. The background worker then slept indefinitely holding BIG_COMPILES, starving every queued compute PSO behind it.

Add a 5 s grace timeout (wait_for_commit_with) while keeping BIG_COMPILES serialized to 1 and the 3 GB target unchanged, log once if the grace window expires, and add unit tests covering both headroom recovery and bounded return.

Assisted-by: Antigravity (Gemini)
@chadatouille

Copy link
Copy Markdown

A before/after on the case listed here under Not tested (a fixed page file), on an NVIDIA machine whose 32 GB run stopped in the same place. This is data on the mechanism; #567 itself was not built or run.

Setup

system-managed page file fixed 80 000 MB page file (after a reboot)
commit free while the world loads not sampled in this run; 0.8–1.0 GiB in the run before it 50–59 GiB
xcl-dxc threads in wait_for_memory 5 0
xcl-pso thread in wait_for_commit 1 0
xcl-pso threads probably queued on BIG_COMPILES 4 1
title threads in resolve_wait 5 4
Wait64BitValueX timed out lines 9 0
compute PSO with the translated console CS lines 71 209
process commit, peak 40.2 GB 40.7 GB
stop (+0x23cf683) 263.2 s 243.2 s

What it shows

  • With the commit limit at 109.9 GiB nothing waited for commit at the stop, and about three times as many compute pipelines were built. That fits wait_for_commit holding the one BIG_COMPILES slot.
  • It did not get past the title's watchdog. The stop came 20 s earlier, with 4 title threads still in resolve_wait. So on this machine commit is one cause of the stall, not the only one.
  • One difference from the description: here the system-managed page file did grow while the title ran (commit limit 64.8 → 65.8 → 66.8 GiB), but about 1 GiB at a time, so free commit stayed at 0.8–1.0 GiB, under the 3 GiB target, in every sample taken while it loaded (run before the first column).

Limits

  • The release binary had no symbols. The function names come from matching its code bytes against a second build of the same tree with line tables (86–94 of 94 bytes compared on the frames that matched; wait_for_commit 92/94, real.rs:3373). The BIG_COMPILES frames did not match directly, hence "probably".
  • The two runs also differ by the reboot and by caches the first run filled.

Not tested: #567 on any build, plain main, AMD, other titles.

AI use: Claude Code (Claude Opus 5.5) read the logs, matched the stack frames, built the binary and wrote this comment, and posted it at the account owner's request. The owner did the runs. Counts and offsets only; no game data.

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 7a63914dcaf56cd930a91b3874ffcca88e80ad3c on AMD RDNA4; the PR was tested on NVIDIA only. I merged it onto current main 3db536e locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 688 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 648 passed, 0 failed, 21 ignored
  • 0 SKIPPED; wait_for_commit_returns_when_headroom_appears and wait_for_commit_does_not_hang_forever_below_reserve pass.

Review: wait_for_commit_with returns at once when GlobalMemoryStatusEx fails (as before) or when the reserve is met, and gives up after BIG_COMMIT_GRACE; the compile then goes ahead, still one at a time under BIG_COMPILES. That is a trade-off rather than a bug: past the 5 s, a big compile can start with less than 3 GB of free commit, which the old loop never allowed, so the title's own commits next to it have less room. The warning is logged once per process (Once), so later fallbacks are silent; a counter in report.json would show how often it happens. I found nothing to change in the code itself.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@mastrr9

mastrr9 commented Nov 24, 2026

Copy link
Copy Markdown

Code audit + NVIDIA RTX 5080 test run on 7a63914dcaf56cd930a91b3874ffcca88e80ad3c:

Review

Looks clean and ready to merge — bounding wait_for_commit to BIG_COMMIT_GRACE = 5 s breaks the Windows dynamic pagefile deadlock while keeping big compiles serialized one at a time under BIG_COMPILES. Both unit tests cleanly exercise the headroom-appears and timeout paths.

Tested

  • Hardware / OS / toolchain: NVIDIA GeForce RTX 5080 (driver 617.42), AMD Ryzen 7 9800X3D, Windows 11 25H2 (build 26200.9711), rustc 1.100.0 (MSVC), debug build.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4: 682 passed, 0 failed, 41 ignored.
  • New tests wait_for_commit_returns_when_headroom_appears and wait_for_commit_does_not_hang_forever_below_reserve: both passed.
  • SKIPPED GPU/D3D12 tests: gpu_geometry_wave32_prefix_count_over_a_mask / gpu_wave32_program_in_wave64_hardware (no wave64), plus 2 D3D12 debug-layer tests (no d3d12SDKLayers.dll).

Not tested

  • Retail title / scripts/smoke.ps1 run (test suite only).
  • AMD / Intel GPUs.

AI use: code review and test run orchestrated with Antigravity (Gemini 4 Neon) on the hardware listed above.

@brainhay5

Copy link
Copy Markdown

Tested merged onto main 47efa2e (clean merge), RTX 5070 Ti, driver 32.0.16.1088, Windows 11 22631, XCL_NETWORK=0, XCL_PRESS_A_AT every 5 s, full launch.

It does not change the stall here. XCL's own overlay at 95 s:

0.0 FPS | compiling shaders: 0 running, 0 done, 57510 pipelines queued

On plain 47efa2e the same capture reads 0 running, 3 done, 57516 queued. Both are a black screen at 0 fps with the queue full.

The thread dump at the end shows xcl-pso-5 … xcl-pso-14 all in ntdll.dll+0xa49f4 (a wait) and none in DXC, so the workers are blocked with ~57k pipelines queued, not busy. If that is the deadlock this PR is meant to bound, it does not show up as drained work on this title.

Not tested: AMD, other titles, longer runs.

AI use: OpenCode, DeepSeek V4.1 Flash 1017.

@gridoe

gridoe commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

Closing as superseded by ivall's commits 25c6f7e ("D3D12.X: a big pipeline build the title waits for does not wait for its turn") and 9a272d4 on main, which replace wait_for_commit() with a wanted() bypass that solves the deadlock cleanly without dropping the 3 GB commit reserve for un-waited speculative builds.

Thanks to @chadatouille, @MesshM, @mastrr9, and @brainhay5 for testing and feedback!

AI use

  • Antigravity with Gemini 4 Neon: checked 25c6f7e / 9a272d4 against this PR and drafted this closing note.

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