XGameRuntime: a task queue's termination callback runs on its completion port #1154
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!1154
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@emirduran707 on GitHub · 2026-11-24 12:35 UTC · original
emirduran707:taskqueue-terminate-port→main· +114 −10 · 1 files · 1 commits · openXTaskQueueTerminatewithwait = 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
@thehollowedone on GitHub · 2026-11-24 12:48 UTC · original
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.
@DavidM1911 on GitHub · 2026-11-24 12:48 UTC · original
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.
@kacper-serewis on GitHub · 2026-11-24 20:20 UTC · original
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.
@emirduran707 on GitHub · 2026-11-24 21:21 UTC · original
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.
@DavidM1911 on GitHub · 2026-11-26 03:52 UTC · original
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
@fromthemoonx on GitHub · 2026-11-24 12:59 UTC · original · edited 2026-11-26 04:07 UTC
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
github-bot referenced this pull request2026-11-26 06:18:31 +00:00
@futurepro62 on GitHub · 2026-11-26 08:54 UTC · original
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
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.