XGameRuntime: dispatch serialized task queue work on the caller #2796

Closed
CryingLaughing wants to merge 1 commit from upstream-pr/2806 into main
CryingLaughing commented 2026-11-26 14:05:38 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by CryingLaughing on 2026-11-26T14:05:38Z.


A serialized thread-pool port has a ready queue. Explicit XTaskQueueDispatch can claim one ready callback and execute it on the calling thread while the automatic worker remains responsible for draining the rest. XCL returned false for this mode even when work was queued.

What is in it

  • In crates/xcl/src/hle/xgameruntime/taskqueue.rs, use the same ready-queue wake path for manual and serialized modes. The serialized worker continues to drain the queue automatically.
  • Adds an API-level regression that holds one callback on the automatic worker, dispatches exactly one queued callback on the caller, then verifies that the original worker runs the remaining callback.

Tested

  • 10dbfac3facf4a1bb93784bcb3eda6203438b134 on b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7.
  • Windows 11 25H2 build 26200.9974, Intel Core i5-13600K, RTX 4080 driver 621.01, Rust 1.100.0 x64 MSVC, DXC 1.8.2502.11. Debug build and test profiles. The focused assertion exercises CPU scheduling.
  • cargo test -p xcl --lib --locked -j 4 serialized_work_port_can_dispatch_on_the_caller -- --show-output --test-threads=1 passed 1/1. The same fixture on the parent returned dispatched=false, before_release=false, and on_caller=false and failed at the expected assertion.
  • cargo build --workspace --locked -j 4 passed. cargo test --workspace --locked -j 4 -- --test-threads=4 --show-output reported 1,436 passed, 0 failed, 47 ignored across 37 harnesses, with 29 capability skips included in the pass total.

Regression run

Independent retail smoke by Anon64 compared release builds of main and this exact head on an RTX 3060 12 GB (driver 581.80), Core i9-14900KF, and Windows 11 build 26200. The 60-second runs used the same title. The head retained 100.1% of the baseline frames and used 103.3% of its peak commit, with zero crashes or device removals. The run did not establish whether the title reached the changed code.

main:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1461 (PresentX 1462)
presents per 2 s (last 3): 10 1 1
device removals: 0
crashes: 0
peak commit: 23855 MB

PR:

xcl-smoke v1
commit: 10dbfac3facf4a1bb93784bcb3eda6203438b134
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1462 (PresentX 1462)
presents per 2 s (last 3): 7 0 4
device removals: 0
crashes: 0
peak commit: 24638 MB

Not tested

  • Other operating systems or explicit dispatch for immediate and ordinary thread-pool ports.
<!-- greyfinch-sync:ivall/xcl:issue:5511473825 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2806). Originally posted by [CryingLaughing](https://github.com/CryingLaughing) on 2026-11-26T14:05:38Z. --- A serialized thread-pool port has a ready queue. Explicit `XTaskQueueDispatch` can claim one ready callback and execute it on the calling thread while the automatic worker remains responsible for draining the rest. XCL returned false for this mode even when work was queued. **What is in it** - In `crates/xcl/src/hle/xgameruntime/taskqueue.rs`, use the same ready-queue wake path for manual and serialized modes. The serialized worker continues to drain the queue automatically. - Adds an API-level regression that holds one callback on the automatic worker, dispatches exactly one queued callback on the caller, then verifies that the original worker runs the remaining callback. **Tested** - `10dbfac3facf4a1bb93784bcb3eda6203438b134` on `b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7`. - Windows 11 25H2 build 26200.9974, Intel Core i5-13600K, RTX 4080 driver 621.01, Rust 1.100.0 x64 MSVC, DXC 1.8.2502.11. Debug build and test profiles. The focused assertion exercises CPU scheduling. - `cargo test -p xcl --lib --locked -j 4 serialized_work_port_can_dispatch_on_the_caller -- --show-output --test-threads=1` passed 1/1. The same fixture on the parent returned `dispatched=false`, `before_release=false`, and `on_caller=false` and failed at the expected assertion. - `cargo build --workspace --locked -j 4` passed. `cargo test --workspace --locked -j 4 -- --test-threads=4 --show-output` reported 1,436 passed, 0 failed, 47 ignored across 37 harnesses, with 29 capability skips included in the pass total. **Regression run** [Independent retail smoke by Anon64](https://github.com/xcl-dev/xcl/pull/2806#issuecomment-7195246957) compared release builds of main and this exact head on an RTX 3060 12 GB (driver 581.80), Core i9-14900KF, and Windows 11 build 26200. The 60-second runs used the same title. The head retained 100.1% of the baseline frames and used 103.3% of its peak commit, with zero crashes or device removals. The run did not establish whether the title reached the changed code. main: ``` xcl-smoke v1 commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 gpu: NVIDIA GeForce RTX 3060 title: 21222967 seconds: 60 exit: 0x0 frames shown: 1461 (PresentX 1462) presents per 2 s (last 3): 10 1 1 device removals: 0 crashes: 0 peak commit: 23855 MB ``` PR: ``` xcl-smoke v1 commit: 10dbfac3facf4a1bb93784bcb3eda6203438b134 gpu: NVIDIA GeForce RTX 3060 title: 21222967 seconds: 60 exit: 0x0 frames shown: 1462 (PresentX 1462) presents per 2 s (last 3): 7 0 4 device removals: 0 crashes: 0 peak commit: 24638 MB ``` **Not tested** - Other operating systems or explicit dispatch for immediate and ordinary thread-pool ports.
Anon64 commented 2026-11-26 15:03:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Anon64 on 2026-11-26T14:44:09Z.


Regression run of 10dbfac on a newer retail title: no device removal, no crash, frames and commit within the limits.

Setup: RTX 3060 12 GB (NVIDIA 581.80), i9-14900KF, Windows 11 26200, release builds of main b49be18 (this PR's base) and of this PR's exact head, scripts/smoke.ps1 -Game <title> for 60 s with XCL_NETWORK=0 and A pressed every 4 s from 20 s. Main ran before and after a batch of 11 PRs and peaked at 23,855 and 23,844 MB, so the baseline held steady over the batch.

main:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1461 (PresentX 1462)
presents per 2 s (last 3): 10 1 1
device removals: 0
crashes: 0
peak commit: 23855 MB

this PR:

xcl-smoke v1
commit: 10dbfac3facf4a1bb93784bcb3eda6203438b134
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1462 (PresentX 1462)
presents per 2 s (last 3): 7 0 4
device removals: 0
crashes: 0
peak commit: 24638 MB

100 % of main's frames, 103 % of its peak commit. One run each.

Not tested: the suite on this head; whether the title reaches the code this PR changes in its first 60 s; AMD.

AI use: Claude Code (Claude Opus 5.5) ran these runs on this machine and wrote this report.

<!-- greyfinch-sync:ivall/xcl:comment:7195246957 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2806#issuecomment-7195246957). Originally posted by [Anon64](https://github.com/Anon64) on 2026-11-26T14:44:09Z. --- **Regression run of `10dbfac` on a newer retail title: no device removal, no crash, frames and commit within the limits.** **Setup:** RTX 3060 12 GB (NVIDIA 581.80), i9-14900KF, Windows 11 26200, release builds of main `b49be18` (this PR's base) and of this PR's exact head, `scripts/smoke.ps1 -Game <title>` for 60 s with `XCL_NETWORK=0` and A pressed every 4 s from 20 s. Main ran before and after a batch of 11 PRs and peaked at 23,855 and 23,844 MB, so the baseline held steady over the batch. main: ``` xcl-smoke v1 commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 gpu: NVIDIA GeForce RTX 3060 title: 21222967 seconds: 60 exit: 0x0 frames shown: 1461 (PresentX 1462) presents per 2 s (last 3): 10 1 1 device removals: 0 crashes: 0 peak commit: 23855 MB ``` this PR: ``` xcl-smoke v1 commit: 10dbfac3facf4a1bb93784bcb3eda6203438b134 gpu: NVIDIA GeForce RTX 3060 title: 21222967 seconds: 60 exit: 0x0 frames shown: 1462 (PresentX 1462) presents per 2 s (last 3): 7 0 4 device removals: 0 crashes: 0 peak commit: 24638 MB ``` 100 % of main's frames, 103 % of its peak commit. One run each. **Not tested:** the suite on this head; whether the title reaches the code this PR changes in its first 60 s; AMD. AI use: Claude Code (Claude Opus 5.5) ran these runs on this machine and wrote this report.
gut0to commented 2026-11-26 15:23:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-11-26T15:23:44Z.

Review: COMMENTED


AI-assisted review: I checked the dispatch path against the GDK contract.

<!-- greyfinch-sync:ivall/xcl:review:6076698179 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2806#pullrequestreview-6076698179). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-26T15:23:44Z. **Review:** COMMENTED --- AI-assisted review: I checked the dispatch path against the GDK contract.
CryingLaughing commented 2026-11-26 16:06:02 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by CryingLaughing on 2026-11-26T15:37:55Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:ivall/xcl:review:6076886004 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2806#pullrequestreview-6076886004). Originally posted by [CryingLaughing](https://github.com/CryingLaughing) on 2026-11-26T15:37:55Z. **Review:** COMMENTED --- _No description provided._
Gevroska commented 2026-11-26 16:06:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Gevroska on 2026-11-26T15:41:52Z.


I tested a case complementary to the existing zero-timeout test with work already queued. I held the automatic worker inside a callback, left the ready queue empty, and started an explicit dispatch with a 4,000 ms timeout. The fixture schedules a callback with a 50 ms delay only after the explicit caller enters the empty-queue wait.

On parent b49be183, explicit dispatch returned immediately without entering the wait, so the fixture never scheduled the delayed callback. On head 10dbfac3, the caller entered the wait and executed the delayed callback on its own thread after 60 ms. The automatic worker was still held at that point. Once released, it executed a separate queued callback on its own thread.

An independent repeat on the head observed 55 ms. Both the new delayed-work case and the existing ready-work case passed with zero skips. This verifies that the explicit caller can wait for and execute newly ready work while preserving subsequent automatic dispatch. The stock failure occurs at admission, before the wakeup path can be tested.

I used Codex GPT-6.2 Sol for the fixture and Windows tests, and a separate GPT-6.2 Sol agent for independent verification. Codex GPT-6.2 Astra wrote this comment.

I reviewed and approved this comment before posting.

<!-- greyfinch-sync:ivall/xcl:comment:7196626564 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2806#issuecomment-7196626564). Originally posted by [Gevroska](https://github.com/Gevroska) on 2026-11-26T15:41:52Z. --- I tested a case complementary to the existing zero-timeout test with work already queued. I held the automatic worker inside a callback, left the ready queue empty, and started an explicit dispatch with a 4,000 ms timeout. The fixture schedules a callback with a 50 ms delay only after the explicit caller enters the empty-queue wait. On parent `b49be183`, explicit dispatch returned immediately without entering the wait, so the fixture never scheduled the delayed callback. On head `10dbfac3`, the caller entered the wait and executed the delayed callback on its own thread after 60 ms. The automatic worker was still held at that point. Once released, it executed a separate queued callback on its own thread. An independent repeat on the head observed 55 ms. Both the new delayed-work case and the existing ready-work case passed with zero skips. This verifies that the explicit caller can wait for and execute newly ready work while preserving subsequent automatic dispatch. The stock failure occurs at admission, before the wakeup path can be tested. I used Codex GPT-6.2 Sol for the fixture and Windows tests, and a separate GPT-6.2 Sol agent for independent verification. Codex GPT-6.2 Astra wrote this comment. I reviewed and approved this comment before posting.
gut0to commented 2026-11-26 16:06:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-11-26T15:23:44Z.

Code review location: crates/xcl/src/hle/xgameruntime/taskqueue.rs; line 345

@@ -355,10 +341,11 @@ pub fn submit_delayed(q: &Arc<Queue>, port: u32, delay_ms: u32, item: Item) -> b
     true
 }
 
-/// Dispatch one item from a Manual port. Returns true when something ran.
+/// Dispatch one queued item on the caller's thread. Returns true when something ran.
 pub fn dispatch(q: &Arc<Queue>, port: u32, timeout_ms: u32) -> bool {

Could this preserve the serialized guarantee when XTaskQueueDispatch is called on an automatic port? The new test holds one callback on the worker and then runs a second on the caller, so two callbacks are active simultaneously. GDK defines SerializedThreadPool as allowing only one active callback at a time, while XTaskQueueDispatch runs on its calling thread. Please synchronize explicit dispatch with the worker (or otherwise serialize both paths). AI-assisted review; I checked the implementation against the dispatch-mode and dispatch contracts.

<!-- greyfinch-sync:ivall/xcl:review-comment:4710393667 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2806#discussion_r4710393667). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-26T15:23:44Z. **Code review location:** `crates/xcl/src/hle/xgameruntime/taskqueue.rs`; line 345 ~~~~diff @@ -355,10 +341,11 @@ pub fn submit_delayed(q: &Arc<Queue>, port: u32, delay_ms: u32, item: Item) -> b true } -/// Dispatch one item from a Manual port. Returns true when something ran. +/// Dispatch one queued item on the caller's thread. Returns true when something ran. pub fn dispatch(q: &Arc<Queue>, port: u32, timeout_ms: u32) -> bool { ~~~~ --- Could this preserve the serialized guarantee when XTaskQueueDispatch is called on an automatic port? The new test holds one callback on the worker and then runs a second on the caller, so two callbacks are active simultaneously. GDK defines SerializedThreadPool as allowing only one active callback at a time, while XTaskQueueDispatch runs on its calling thread. Please synchronize explicit dispatch with the worker (or otherwise serialize both paths). AI-assisted review; I checked the implementation against the [dispatch-mode](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xtaskqueue/enums/xtaskqueuedispatchmode?view=gdk-2604) and [dispatch](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xtaskqueue/functions/xtaskqueuedispatch?view=gdk-2604) contracts.
CryingLaughing commented 2026-11-26 16:06:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by CryingLaughing on 2026-11-26T15:37:55Z.

Code review location: crates/xcl/src/hle/xgameruntime/taskqueue.rs; line 345

@@ -355,10 +341,11 @@ pub fn submit_delayed(q: &Arc<Queue>, port: u32, delay_ms: u32, item: Item) -> b
     true
 }
 
-/// Dispatch one item from a Manual port. Returns true when something ran.
+/// Dispatch one queued item on the caller's thread. Returns true when something ran.
 pub fn dispatch(q: &Arc<Queue>, port: u32, timeout_ms: u32) -> bool {

I checked this against the installed Windows runtime on Windows 11 build 26200.9974 (xgameruntime.dll 10.0.26100.9656). With SerializedThreadPool automatic dispatch alone, three synthetic callbacks ran in order on one worker with no overlap. In a separate queue, while the first worker callback was held, XTaskQueueDispatch(queue, Work, 0) returned true and ran the second callback on the calling thread. The third stayed queued until the first worker callback was released. All queues terminated and the probe exited 0.

That matches the two paths in this test at 10dbfac3facf4a1bb93784bcb3eda6203438b134. The dispatch mode contract describes serial execution on the thread pool. The reference explicit dispatch path drains one item directly, and the automatic worker path owns the serialization check. This covers the Windows runtime version above.

<!-- greyfinch-sync:ivall/xcl:review-comment:4710550753 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2806#discussion_r4710550753). Originally posted by [CryingLaughing](https://github.com/CryingLaughing) on 2026-11-26T15:37:55Z. **Code review location:** `crates/xcl/src/hle/xgameruntime/taskqueue.rs`; line 345 ~~~~diff @@ -355,10 +341,11 @@ pub fn submit_delayed(q: &Arc<Queue>, port: u32, delay_ms: u32, item: Item) -> b true } -/// Dispatch one item from a Manual port. Returns true when something ran. +/// Dispatch one queued item on the caller's thread. Returns true when something ran. pub fn dispatch(q: &Arc<Queue>, port: u32, timeout_ms: u32) -> bool { ~~~~ --- I checked this against the installed Windows runtime on Windows 11 build `26200.9974` (`xgameruntime.dll` `10.0.26100.9656`). With `SerializedThreadPool` automatic dispatch alone, three synthetic callbacks ran in order on one worker with no overlap. In a separate queue, while the first worker callback was held, `XTaskQueueDispatch(queue, Work, 0)` returned `true` and ran the second callback on the calling thread. The third stayed queued until the first worker callback was released. All queues terminated and the probe exited 0. That matches the two paths in this test at `10dbfac3facf4a1bb93784bcb3eda6203438b134`. The [dispatch mode contract](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xtaskqueue/enums/xtaskqueuedispatchmode?view=gdk-2604) describes serial execution on the thread pool. The [reference explicit dispatch path](https://github.com/microsoft/libHttpClient/blob/c5007fd9cbdc785518ea6dccc5751b125d451cc1/Source/Task/TaskQueue.cpp#L745-L799) drains one item directly, and the [automatic worker path](https://github.com/microsoft/libHttpClient/blob/c5007fd9cbdc785518ea6dccc5751b125d451cc1/Source/Task/TaskQueue.cpp#L1736-L1755) owns the serialization check. This covers the Windows runtime version above.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!2796
No description provided.