Skip to content

D3D12.X: log PresentX waits that time out; XCL_PRESENT_WAIT_MS - #3637

Open
vasanex wants to merge 1 commit into
xcl-dev:mainfrom
vasanex:present-wait-log
Open

vasanex wants to merge 1 commit into
xcl-dev:mainfrom
vasanex:present-wait-log

Conversation

@vasanex

@vasanex vasanex commented Dec 2, 2026 •

Copy link
Copy Markdown

PresentX waits up to 2000 ms for the copy of frame N-2. When that wait times out it returns without a log line, while present_x still reports the flip: a title that stops showing frames this way leaves nothing in xcl.log. Each time-out is now logged with a count, and XCL_PRESENT_WAIT_MS sets the limit (default 2000, as before).

What is in it

  • present.rs: the warning with a counter (the first eight, then at each doubling, so a title that times out on every frame does not fill the log); XCL_PRESENT_WAIT_MS (a whole number of ms above 0, anything else the default; at most 60000, since the wait holds the presenter's lock that a queue's release needs too), a log line with the wait in effect when it is set, and its unit test
  • README.md: one entry. It says the setting changes only the PresentX wait: the waits before a swap chain resize (2000 ms), for a frame dump (2000 ms), at a queue switch and at shutdown (1000 ms each) keep their limits (review of 52bbcc3)

Tested

  • NVIDIA GeForce RTX 3080 10 GB (driver 621.40), AMD Ryzen 9 7950X, Windows 11 Pro 26200, rustc 1.100.0
  • cargo build --workspace: ok; cargo test --workspace --no-fail-fast -- --test-threads=4 (debug) on this head (a4893cc): 3005 passed, 0 failed, 52 ignored (main 817eb1f: 3004 passed)
  • SKIPPED on this adapter: 25 (22 no wave64, 2 no heap windows, 1 cannot disable the driver cache), the same tests as on main
  • 60 s of a retail title, release, default settings plus XCL_NETWORK=0 on both sides: see below

Regression run
main:

xcl-smoke v1
commit: 817eb1fc9fb0763008ae5d8de1f7f586f442b51d
gpu: NVIDIA GeForce RTX 3080
title: aaa95fa3
seconds: 60
exit: 0x0
frames shown: 1697 (PresentX 1697)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17887 MB

this PR's head:

xcl-smoke v1
commit: a4893ccc9fcb96148c6dd2311f6461811254cfec
gpu: NVIDIA GeForce RTX 3080
title: aaa95fa3
seconds: 60
exit: 0x0
frames shown: 1691 (PresentX 1691)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18051 MB

Not tested

  • A run in which the wait times out on this head, and a run with the variable set (the cap and the log line are covered by the unit test and by reading only).
  • A title whose GPU frames take longer than those other waits: raising XCL_PRESENT_WAIT_MS does not get it past a swap chain resize.
  • AMD, Intel.

AI use

  • Claude Code with Claude Fable 5.2 (parts written earlier with Claude Opus 5.5): wrote the code, the tests and this description, and ran the tests.

🤖 Generated with Claude Code

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Review (head c6ca119, diff read, not a merge-check; draft, checks red):

No problems found in the diff. Checked that the default stays 2000 ms (present_wait_ms_from rejects empty, zero, negative, non-numeric and u32::MAX values, each covered by the unit test), that a PresentX copy timeout was silent before (present_now ~1500 skipped FenceError::Timeout), that the warning fires only when is_frame is true so the window-thread fallback present (100 ms) still logs nothing, and that the timeout path keeps the ring state as before; the README entry matches. Still owed: suite counts and the xcl-smoke blocks (the reason PR description is red). #3571 inserts a test at the same spot in present.rs's test module, so whichever lands second has a trivial conflict.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@vasanex
vasanex marked this pull request as ready for review December 2, 2026 03:07
@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 2, 2026

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

Review of c6ca1196: 1 finding(s) (1 medium), most severe first.

  1. Medium crates/xcl/src/hle/d3d12x/present.rs:1013: XCL_PRESENT_WAIT_MS has no upper bound: only 0 and u32::MAX are rejected, so values close to u32::MAX are accepted and give an effectively unbounded wait while the PRESENTER mutex is held. (inline)

These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

Comment thread crates/xcl/src/hle/d3d12x/present.rs Resolved
@bmjask

bmjask commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

@vasanex

vasanex commented Dec 2, 2026

Copy link
Copy Markdown
Author

Right, there was no upper bound. 11d7ddd caps XCL_PRESENT_WAIT_MS at 60000 ms (a larger value is taken as 60000) and logs the wait in effect once when the variable is set; the unit test covers 60000, 60001 and 4294967294. Rebased onto main 817eb1f; suite 3005 passed, 0 failed, 52 ignored, smoke pair in the description.

A value above the 2 s / 5 s watchdogs can still trip them; that is what the switch is for (to see whether a longer wait gets the frame), so I left it. Not done: a run with the variable set.

Claude Code with Claude Fable 5.2 checked the point and wrote the change and this reply.

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

Review of 11d7ddd0: 2 finding(s) (2 medium), most severe first.

  1. Medium crates/xcl/src/hle/d3d12x/present.rs:1515: The new timeout warning has no rate limit, and log::write flushes the file for Warn, so on default settings every timed-out frame does a synchronous file write and flush on the title's present thread while holding PRESENTER. (inline)
  2. Medium crates/xcl/src/hle/d3d12x/present.rs:1042: Allowing up to 60000 ms lets the N-2 wait hold PRESENTER (and PRESENTX_LOCK) up to 30x longer than before, so quiesce_queue (line 584, PRESENTER.lock()) can be blocked for a minute or starved indefinitely. (inline)

These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

Comment thread crates/xcl/src/hle/d3d12x/present.rs Resolved
}
if wait_val > 0 {
let timeout_ms = if is_present_x { 2000 } else { 100 };
let timeout_ms = if is_present_x { present_wait_ms() } else { 100 };

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.

Medium: Allowing up to 60000 ms lets the N-2 wait hold PRESENTER (and PRESENTX_LOCK) up to 30x longer than before, so quiesce_queue (line 584, PRESENTER.lock()) can be blocked for a minute or starved indefinitely. With XCL_PRESENT_WAIT_MS=60000 and a stalled GPU, each PresentX holds PRESENTER for 60 s, drops it, and the title's next PresentX takes it straight back (std Mutex isn't fair). A queue retirement in invalidate_queue_caches -> quiesce_queue then waits a minute or more, so the queue is never released and the retirement worker hangs. Waiting on the fence without holding PRESENTER, or capping the wait well below the retirement timeout, would avoid it.

@github-actions github-actions Bot added the needs-1st-check Passes gates; needs first independent merge-check (#3041) label Dec 2, 2026
@vasanex

vasanex commented Dec 2, 2026

Copy link
Copy Markdown
Author
  1. The timeout warning: at the default wait it is at most one line per 2 s, but with a small XCL_PRESENT_WAIT_MS it could be one per frame. 52bbcc3 logs the first eight and then at each doubling (the count is in the line), as alloc_pool.rs and dstorage.rs do.
  2. The 60 s cap and PRESENTER: XCL_PRESENT_WAIT_MS is a deliberate debug setting that the user sets; the default stays 2000 ms, so nothing changes unless it is set. A longer wait then holds PRESENTER for that long by design: the switch exists to see whether a longer wait gets the frame, and a queue release waits up to the chosen time. The README names the cap. Waiting on the fence without PRESENTER would be a change to PresentX's locking, which this PR does not make. That said, 60 s is a judgment call, and I am open to other suggestions for the cap if you or a maintainer prefer a different value.

Suite on the new head: 3005 passed, 0 failed, 52 ignored; smoke pair in the description.

Claude Code with Claude Fable 5.2 checked the points and wrote the change.

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

Review of 52bbcc38: 1 finding(s) (1 medium), most severe first.

Re-review at 52bbcc38. The timeout warning now has a counter and wasn't flagged again, so the per-frame flush looks addressed. The 60 s cap holding PRESENTER (and blocking quiesce_queue) from the 11d7ddd0 review is still open. One new item below.

  1. Medium crates/xcl/src/hle/d3d12x/present.rs:1042: XCL_PRESENT_WAIT_MS changes only the frame N-2 wait. (inline)

These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

}
if wait_val > 0 {
let timeout_ms = if is_present_x { 2000 } else { 100 };
let timeout_ms = if is_present_x { present_wait_ms() } else { 100 };

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.

Medium: XCL_PRESENT_WAIT_MS changes only the frame N-2 wait. The other fence waits on the same present path keep their hardcoded limits: the drain before ResizeBuffers (line 1384, 2000 ms), the frame-dump copy wait (line 1704, 2000 ms), the queue-switch wait (line 1480, 1000 ms) and Presenter::drop (1000 ms). For a title whose GPU frame takes ~5 s, run with XCL_PRESENT_WAIT_MS=10000, the PresentX wait now succeeds, but the first swap-chain resize still times out at 2000 ms: ensure_swapchain logs 'drain before resize: GPU fence still pending after 2000 ms' and returns false, so no frame is shown even though the user raised the wait. Frame dumps under XCL_FRAME_DUMP are skipped the same way. Using the setting for every present-path wait, or at least the resize drain, would make it do what the README says.

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.

Right: the setting changes only the PresentX wait for the copy of frame N-2. The drain before a resize (2000 ms), the frame-dump wait (2000 ms), the queue-switch wait and Presenter::drop (1000 ms each) keep their limits, so a title with ~5 s GPU frames still fails at the first resize.

I kept this PR to what its title says and made the README say so (a4893ccc): only that wait is set. Giving the other four waits the setting changes behaviour on the resize and shutdown paths and wants its own PR with a run that reaches them; the description lists the gap under Not tested.

On the 60 s cap holding PRESENTER: unchanged, it is a debug setting with a default that is as before. If you have a concrete case where the cap should be lower, or the wait should let the lock go, I am open to it.

Written with Claude Code (Claude Fable 5.2).

@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review of 52bbcc38, since c6ca1196 (code reading only, not a merge-check) · no new findings

In short: The PR logs PresentX waits for the copy of frame N-2 that time out, and adds XCL_PRESENT_WAIT_MS. This push caps the wait at 60,000 ms, because the wait holds PRESENTER, which a queue's release needs too. It also logs only the first eight timeouts and then each doubling, and logs the value once when the variable is set. The README says the same. Nothing blocks it.

Checked and fine
  • The earlier review found no problems. The default is still 2,000 ms, and empty, zero, negative, non-numeric and u32::MAX values still give it.
  • present_wait_ms_from now caps a valid value with min(PRESENT_WAIT_MAX_MS). The test covers 60000, 60001 and 4294967294.
  • n <= 8 || n.is_power_of_two() keeps the count in each line, so the total stays readable from the last one.
  • The info line is written only when the variable is set, once (OnceLock).
  • D3D12.X: XCL_DUMP_WAIT_MS sets how long a dumped frame's present waits for the dump's copies #3571 adds a test at the same place in present.rs's test module; whichever lands second has a trivial conflict.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

PresentX waits up to 2000 ms for the copy of frame N-2. When that times
out it returned without a log line, and present_x still reports the flip.
Each time-out is now logged with a counter, and XCL_PRESENT_WAIT_MS sets
the limit (default 2000, as before).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review of a4893ccc, since 52bbcc38 (code reading only, not a merge-check) · no new findings

In short: This push only adds a sentence to the README: XCL_PRESENT_WAIT_MS sets only PresentX's wait for the copy of frame N-2, and the waits before a swap chain resize, for a frame dump, at a queue switch and at shutdown keep their own 1-2 s limits. The code is unchanged, and nothing blocks it.

Checked and fine
  • No code change since 52bbcc38 (git range-diff); the earlier review found no problems.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

@fromthemoonx

fromthemoonx commented Dec 3, 2026 •

Copy link
Copy Markdown

merge-check
base: 395405e
head: a4893cc
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3013 passed, 0 failed, 56 ignored (base: 3012 passed, 0 failed, 56 ignored); SKIPPED: 25, the same as base (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps); failing: none
review: read the whole diff (2 files, +48 -2). No finding. I ran the two cases listed under Not tested, with XCL's own test title (xcl run … -- --hello). Two scratch changes were needed: the title presents 41 frames instead of 1 (with 1 it never waits for frame N-2), and the first waits can be made to wait for a fence value that never comes.

XCL_PRESENT_WAIT_MS waits made to time out what happened
unset 0 limit 2000 ms, no new log line
20000 0 limit 20000 ms, logged once
90000 0 limit 60000 ms, logged once
unset 2 each gave up after 2000 ms, 2 warnings
2 s (not a number) 1 gave up after 2000 ms, 1 warning
3000 1 gave up after 3000 ms, 1 warning
50 20 20 time-outs, 9 warnings: #1 to #8 and #16
  1. After the time-outs every later wait succeeded, and the title exited with 0 in all of these runs.
  2. The line with the wait in effect is written at the first wait, so a title that shows fewer than 3 frames does not log it. That is fine for this switch.
  3. The README's limits for the other waits match the code (resize and frame dump 2000 ms, queue switch and shutdown 1000 ms).
  4. Not tested: a GPU that really is that slow, a retail title (none on this machine), AMD.
    performance: none by default: the limit is read once, and the rest runs only after a time-out. Reasoned, not measured.
    verdict: safe to merge
    hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:title-run Runtime change: needs a merge-check with a real title run into the world (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:title-run Runtime change: needs a merge-check with a real title run into the world (#3041) needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants