XGameRuntime: a task queue's termination callback runs on its completion port #1145
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1154"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-24T12:35:33Z.
XTaskQueueTerminatewithwait = falseran the title's termination callback on XCL's own worker thread, as soon as the queue's work had finished. Microsoft's documentation ofXTaskQueueTerminatesays 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 ownXTaskQueueDispatch. While an async termination callback is still pending submission, a completion-portXTaskQueueDispatchwith a timeout (includingINFINITE) waits for it instead of returningfalseearly. Withwait = truethe callback still runs on the calling thread beforeTerminatereturns: 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_nowgoes through a privatesubmitthat can let the termination entry past the terminated check.QueueState::termination_cb_pendingkeeps a manual completion-portdispatchwaiting until the async termination entry has been queued.run_terminatedruns the queued callback.termination_callback_runs_from_a_manual_completion_port_dispatchandinfinite_completion_pump_receives_termination_callback.Tested
cargo test --workspace -- --test-threads=4oncc8fbcd: 743 passed, 0 failed, 41 ignored; no SKIPPED GPU testscargo test -p xcl --lib taskqueue -- --test-threads=4: 12 passed, 0 failedinfinite_completion_pump_receives_termination_callbackfailed before the pending-termination wait (pump exited before termination callback in 49 of 50 runs); passes 50/50 afterRegression run
main:
this PR:
Not tested
wait = false(the smoke title's run is a regression check only).AI use
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-24T12:48:24Z.
Independent Windows 11 build 26300 check, Ryzen 7 9800X3D, Rust 1.99.1 MSVC, debug. I queued a completion on a parent, then terminated a child asynchronously while both shared that manual completion port.
47efa2e, the child’s termination callback ran before any dispatch. Dispatching the parent then ran only its own completion.ea68eaa, neither callback ran before dispatch. The parent handle dispatched its own uncanceled completion first, then the child’s termination callback. Both ran on the dispatching thread. This passed in the 12-testtaskqueue::testsrun and in three separate runs ofscratch_child_termination_obeys_shared_manual_port_order.Both revisions used
cargo test --offline --locked -p xcl --lib <filter> -- --nocapture --test-threads=1. Synthetic queue callbacks only.AI-assisted. Codex (GPT-6, exact variant unavailable) wrote and ran the scratch fixture and drafted this report.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T12:48:46Z.
Independent verification on current
main384f7f7(branch already contains it — clean).Machine: Windows 11, Ryzen 9 7900X; Rust stable MSVC, debug.
cargo test -p xcl --lib taskqueue: 11 passed, 0 failed — includes the newtermination_callback_runs_from_a_manual_completion_port_dispatch.AI use: test runs by Devin (Cognition, SWE-2); no code changes.
Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-11-24T12:59:51Z.
Rerun on the new head
cc8fbcd(theINFINITEcompletion-pump fix): still passes on the RTX 3060, and the new pump test catches the case it was added for.cargo test --workspace --no-fail-fast -- --test-threads=4,cc8fbcdmerged ontomainb49be18(clean)SKIPPEDlinestermination_callback_runs_from_a_manual_completion_port_dispatch,infinite_completion_pump_receives_termination_callback,composite_queue_termination_preserves_shared_parent_port_work, alone, 40 runs eachhle::xgameruntime::taskqueue::(12 tests),--test-threads=8, 30 runs|| (port == PORT_COMPLETION && state.termination_cb_pending > 0)infinite_completion_pump_receives_termination_callbackfails attaskqueue.rs:951; the other 11 passSame machine, debug. The report below is for
ea68eaa.NVIDIA run with the whole suite, since Not tested lists NVIDIA.
Tested
stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17; debugea68eaab214f941b0f12b4274b156b165c588cfa, which is on currentmain47efa2e(so also the merged result):cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4: 742 passed, 0 failed, 41 ignored. The newtaskqueue::tests::termination_callback_runs_from_a_manual_completion_port_dispatchpassed.taskqueue.rsas onmainplus only the new test, it fails withthe termination callback ran before the completion port was dispatched,left: Some(ThreadId(4)), right: None.hle::xgameruntime::taskqueuetests, 10 runs: 10 of 10 passed (11 each)e2e, 3 runs: 3 of 3 passed. The test title uses XGameRuntime task queues through the GDK thunks.gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardwareNot tested
AI use
Imported from ivall/xcl. Originally posted by kacper-serewis on 2026-11-24T20:20:04Z.
On
ea68eaa, a title that pumps its manual completion port withXTaskQueueDispatch(h, Completion, INFINITE)in a loop does not get the termination callback.Tested: Windows 11, debug, CPU only. Idle queue (ThreadPool / Manual), a pump thread blocked in dispatch, then
XTaskQueueTerminate(wait = false). The pump is joined, then 50 ms pass:47efa2eea68eaaFrom the code: Terminate wakes the dispatcher, which returns false because the queue is terminated and empty, so the pump ends before the callback is queued. The PR's test waits for the entry and then dispatches once with a zero timeout. Suggested (not tested): an infinite dispatch must not return false on a terminated queue until its termination entry has run.
Test (append to taskqueue.rs)
AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this comment. I checked the points before posting.
Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-24T21:21:20Z.
Fixed in
cc8fbcd(squashed and force-pushed).QueueStatenow tracks pending async termination callbacks (termination_cb_pending): set inXTaskQueueTerminatewhen!wait && cb != 0, and decremented inside thep.items+q.statelocks insubmitas the termination entry is pushed ontoPORT_COMPLETION(waking waiting dispatchers withnotify_all).dispatchkeeps waiting onPORT_COMPLETIONwhiletermination_cb_pending > 0, and returnsfalseonce the queue is empty and terminated with no pending termination entry.Reproduced the failure with
infinite_completion_pump_receives_termination_callback(missed 49 of 50 runs onea68eaa); oncc8fbcdit passes 50/50,cargo test -p xcl --lib taskqueuepasses 12/12, and the full workspace suite passes (743 passed, 0 failed, 41 ignored).AI use: Antigravity with Gemini 4 Neon wrote the fix, test, and this reply.
upstream-sync referenced this pull request2026-11-24 23:06:49 +00:00
upstream-sync referenced this pull request2026-11-25 06:04:27 +00:00
upstream-sync referenced this pull request2026-11-25 11:07:09 +00:00
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T03:52:36Z.
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-26T08:54:31Z.
NVIDIA and AMD full-suite run, to go with the reports above by fromthemoonx, since none of them covers AMD. Tested exact head
cc8fbcd6(on its base47efa2e).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 743 passed, 0 failed, 41 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.termination_callback_runs_from_a_manual_completion_port_dispatch,infinite_completion_pump_receives_termination_callback.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 743 passed, 0 failed, 41 ignored, no skips.--skipleaves out tests that fail on mainb49be183too, not because of this PR. On NVIDIA:heap_window_out_of_memory_falls_back_to_the_switch_form(#1651), the fourgpu::recomp::lower_dxil::tests::*_programs_on_the_gputests,const_and_null_mask_operands_agree_with_hlsl_on_the_gpuandmask_ff0_and_flbit_agree_with_hlsl_on_the_gpu(follow-up on #1651) fail becauserunner::skip_testturns their skips into failures underXCL_REQUIRE_GPU=mesh, andgpu::dxil::fuzz_testsseeds 70, 545, 1019 and 1507 failCreateComputePipelineStatewithE_OUTOFMEMORYon this card (drivers 616.64 and 621.40). On AMD:fuzz_validate_and_gpu_1fails on seed 540 (res[833]0x7 vs CPU 0x6). The AMD run does not setXCL_REQUIRE_GPU.Not tested
AI use
Imported from ivall/xcl. Originally posted by throny on 2026-11-28T07:07:24Z.
merge-check claim
head:
cc8fbcd64dImported from ivall/xcl. Originally posted by throny on 2026-11-28T07:18:17Z.
merge-check
base:
e429936chead:
cc8fbcd64dmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2128 passed, 9 failed, 48 ignored (26 SKIPPED lines). The 9 failures are main's own at
e429936con this GPU (reported on #3041: they arrive with the merge of #2959); base alone: 2126 passed, 9 failed, 48 ignored.review: no blocking finding. Lock order is consistent (items, then state; Terminate takes state alone; nothing takes the timer lock while holding either), the pending-callback counter stays balanced, and the private state struct's two constructors are updated. Behaviour to know: with wait=false on a manually pumped completion port the callback now runs only if the title keeps dispatching through a live handle (said to match the reference implementation; not verified here). It applies together with #1681 in either order.
performance: none; not on the frame path.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Imported from ivall/xcl. Originally posted by jsalzy on 2026-11-30T01:15:06Z.
merge-check claim
head:
cc8fbcd64dImported from ivall/xcl. Originally posted by jsalzy on 2026-11-30T01:34:31Z.
merge-check
base:
53e85fb124head:
cc8fbcd64dmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2794 passed, 1 failed, 49 ignored; SKIPPED: 28 (22 no wave64 on this GPU; 3 per-lane form refused: V_CVT_F16_F32, V_MUL_F16, V_PK_MUL_F16 (#1426 semantics); 2 no heap windows (opt-in XCL_HEAP_WINDOWS=1); 1 driver cache cannot be disabled without Windows Developer Mode); failing: hle::d3d12x::standin::tests::concurrent_shell_miss_reuses_winner_and_releases_loser_pipeline (standin.rs:459, left (0, 1, 1), right (0, 0, 1)), fails on base too: main alone at
53e85fbgives 2792 passed, 1 failed (same test, same assertion), 49 ignored. The PR's two new tests (termination_callback_runs_from_a_manual_completion_port_dispatch, infinite_completion_pump_receives_termination_callback) pass.review: no blocking finding; whole diff read (one file). With wait = false the termination callback is now queued to the queue's completion port once its work and completions have drained, instead of running on XCL's worker thread; with wait = true it still runs inline, so a manual port cannot deadlock there. Lock order stays items -> state (dispatch's new wait condition takes the state lock under the port's items lock, as submit does). termination_cb_pending goes up once per async callback in XTaskQueueTerminate and down once when the entry is pushed, and all four port modes take the new path; on immediate and thread-pool completion ports the callback still runs on an XCL thread, as before. Behaviour to know: on a manual completion port the callback now runs only if the title dispatches that port again; if it stops dispatching (or closes its last handle) first, the callback never runs, as with any completion left on an undispatched manual port. The new tests cover only the manual completion port; wait = false on immediate and thread-pool completion ports has no test. Duplicates: none among the open and merged task-queue PRs.
performance: none measurable: one counter under the existing state lock; dispatch takes the state lock once per wake-up while it waits on an empty port.
verdict: safe to merge
hardware / tool and model: RTX 4070 SUPER 12 GB (621.24 / 32.0.16.2124), Ryzen 7 7800X3D, 32 GB, Windows 11 Pro 25H2 26200.9974, Rust 1.100.0, debug / Claude app (Claude Opus 5.5): merge, build and suite run on this PC with git and cargo only; diff review by Claude Opus 5.5.