Skip to content

[upstream #1154] XGameRuntime: a task queue's termination callback runs on its completion port - #8

Closed
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1154
Closed

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1154

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

XTaskQueueTerminate with wait = false ran the title's termination callback on XCL's own worker thread, as soon as the queue's work had finished. Microsoft's documentation of XTaskQueueTerminate says the callback is invoked from the completion thread at the end of termination. Its example for a manual completion port relies on that: the callback is queued to the completion port, so it already runs on the title's UI thread. A title that dispatches its completion port by hand could get the callback on a thread it does not expect, while that thread may still be touching the queue.

Now, with wait = false, the callback is submitted to the queue's completion port once the pending work and completions are done. The port's monitors are notified, so on a manual port the callback runs from the title's own XTaskQueueDispatch. With wait = true the callback still runs on the calling thread before Terminate returns: queuing it there could hang a caller whose manual port nobody dispatches while it waits.

What is in it

  • crates/xcl/src/hle/xgameruntime/taskqueue.rs:
    • submit_now goes through a private submit that can let the termination entry past the terminated check.
    • run_terminated runs the queued callback.
    • Test termination_callback_runs_from_a_manual_completion_port_dispatch.

Tested

  • AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release
  • cargo test --workspace -- --test-threads=4 on ea68eaa: 742 passed, 0 failed, 41 ignored; no SKIPPED GPU tests
  • the new test without the change in XTaskQueueTerminate fails ("the termination callback ran before the completion port was dispatched"); with it it passes; cargo test -p xcl --lib xgameruntime 3 times: 74 passed, 0 failed each

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1541 (PresentX 1541)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19650 MB

this PR:

xcl-smoke v1
commit: ea68eaab214f941b0f12b4274b156b165c588cfa
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1566 (PresentX 1566)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 19745 MB

Not tested

  • A title that terminates a queue with a manual completion port and wait = false (the smoke title's run is a regression check only).
  • If the title never dispatches that manual port again, the small record holding the callback is not freed.
  • NVIDIA and Intel GPUs.

AI use

  • Claude Code with Claude Opus 5.5: found the problem, wrote the change, the test and this description; I reviewed the diff and ran the tests and smoke runs above.

🤖 Generated with Claude Code


Mirror of xcl-dev#1154 (auto-synced, do not edit).

…ion port

XTaskQueueTerminate(wait = false) had a worker of the shared pool call the
title's termination callback directly. The GDK docs say the callback "will be
invoked from the completion thread at the end of termination", and their
example terminates a queue with a manual completion port from WM_CLOSE and
calls DestroyWindow in the callback, relying on it running from the UI
thread's own XTaskQueueDispatch. libHttpClient likewise queues a termination
entry on the completion port and notifies the queue's monitors.

Once in-flight work and completions have drained, the callback is now
submitted to the completion port through the same path as other completion
callbacks (which notifies monitors), allowed past the terminated check. On a
manual port it runs from the title's XTaskQueueDispatch, on a thread-pool
port on the pool. With wait = true the callback still runs on the calling
thread before Terminate returns: on a manual port nobody may dispatch while
the caller waits, which the docs warn may deadlock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#1154 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/1154 branch November 25, 2026 00:15
ufoptg pushed a commit that referenced this pull request Nov 27, 2026
Part of xcl-dev#480.

Add integration tests comparing D3D12.X runtime wrappers against host
ID3D12Device objects and console ABI contracts across:
- ID3D12Resource Map, Unmap, GetGPUVirtualAddress (including lazy
  TITLE_ADDRESS texture fallback and UMA buffer placement), and
  WriteToSubresource
- ID3D12DescriptorHeap console slot #9/#10 start handles and
  console_heap::start lifecycle on host and console #14 heaps
- ID3D12CommandQueue GetDesc, GetTimestampFrequency,
  GetClockCalibration (host parity and pre/post-QUEUE_OLDER console
  calls), ExecuteCommandLists, Wait, Signal, and SignalX (#23)
- ID3D12Fence slot #12 64-byte-aligned completed-value cell and CPU
  Signal updates, plus ID3D12CommandAllocator::Reset (#8)

Verified on AMD Radeon RX 9070 XT (debug, release, XCL_D3D12_DEBUG=1),
AMD Radeon(TM) Graphics, and WARP.
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.

2 participants