XTaskQueue: every queue using a port hears of a task submitted to it #2747

Open
F1reworks10 wants to merge 1 commit from upstream-pr/2749 into main
F1reworks10 commented 2026-11-25 19:34:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by F1reworks10 on 2026-11-25T19:34:40Z.


A task submitted to a port only reached the monitors of the queue it was submitted through. So a composite queue built from another queue's ports never woke that queue's monitor.

The GDK documents both halves of a common setup:

Put together on main, callbacks submitted through the composite queue sit in the port while the dispatcher sleeps.

In the public reference implementation (libHttpClient's TaskQueue.cpp, TaskQueuePortImpl::NotifyItemQueued), every port context attached to a port hears of each item queued to it. Each queue that uses the port therefore calls its monitors, with its own handle and the port it uses.

The reference also calls the monitors before an immediate port runs the item. On main they were called after it had already run.

Change (crates/victory-hle/src/modules/xasync.rs)

  • A port keeps a weak list of the queues using it, each with the port it is to that queue. A composite queue may use one port as both of its ports.
  • Delivering a task calls the monitors of each of those queues, outside any lock.
  • An immediate port runs the task after its monitors have heard of it.

Tests

  • monitors_hear_of_tasks_submitted_through_a_composite_queue: fails on main, because the owner's monitor hears nothing.
  • monitors_hear_of_an_immediate_task_before_it_runs: fails on main, because the monitor hears of the task after it ran.

cargo test -p victory-hle passes. Clippy is clean with and without --all-features. This PR merges cleanly together with #2616 and #2618, and all 18 xasync tests pass on the combination.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:5497858576 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2749). Originally posted by [F1reworks10](https://github.com/F1reworks10) on 2026-11-25T19:34:40Z. --- A task submitted to a port only reached the monitors of the queue it was submitted through. So a composite queue built from another queue's ports never woke that queue's monitor. The GDK documents both halves of a common setup: - [XTaskQueueRegisterMonitor](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xtaskqueue/functions/xtaskqueueregistermonitor): its example drives a manual queue by having a monitor wake the dispatcher thread. - [XTaskQueueCreateComposite](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xtaskqueue/functions/xtaskqueuecreatecomposite): its example lets another API share a queue through a composite queue made of that queue's ports. Put together on main, callbacks submitted through the composite queue sit in the port while the dispatcher sleeps. In the public reference implementation ([libHttpClient's `TaskQueue.cpp`](https://github.com/microsoft/libHttpClient/blob/main/Source/Task/TaskQueue.cpp), `TaskQueuePortImpl::NotifyItemQueued`), every port context attached to a port hears of each item queued to it. Each queue that uses the port therefore calls its monitors, with its own handle and the port it uses. The reference also calls the monitors *before* an immediate port runs the item. On main they were called after it had already run. ### Change (`crates/victory-hle/src/modules/xasync.rs`) - A port keeps a weak list of the queues using it, each with the port it is to that queue. A composite queue may use one port as both of its ports. - Delivering a task calls the monitors of each of those queues, outside any lock. - An immediate port runs the task after its monitors have heard of it. ### Tests - `monitors_hear_of_tasks_submitted_through_a_composite_queue`: fails on main, because the owner's monitor hears nothing. - `monitors_hear_of_an_immediate_task_before_it_runs`: fails on main, because the monitor hears of the task after it ran. `cargo test -p victory-hle` passes. Clippy is clean with and without `--all-features`. This PR merges cleanly together with #2616 and #2618, and all 18 `xasync` tests pass on the combination. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
cloph-dsp commented 2026-11-25 20:06:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T19:54:43Z.


Independent local verification of this PR (claim VERIFY-2749-XTASKQUEUE-PORT-NOTIFICATIONS on #1633).

  • Windows, Rust 1.100.0/MSVC, cargo --locked, CARGO_BUILD_JOBS=2. No GPU, no game data, no clippy/rustup.
  • Diff: 1 file, +112/-10 in crates/victory-hle/src/modules/xasync.rs (tell_monitors plus two synthetic tests).
  • git diff --check origin/main..HEAD clean; origin/main is an ancestor of the PR head.
  • cargo test --locked -p victory-hle --lib monitors_hear_of --quiet → 2 passed, 0 failed.
  • cargo test --locked -p victory-hle --lib --quiet → 148 passed, 0 failed (plus 1 doctest passed).
  • Negative control: both new test names are absent from origin/main in xasync.rs.
  • Only pre-existing deprecation warnings in victory-gpu/src/object.rs and victory-hle/src/modules/xmem.rs; non-blocking.

No blocking findings. AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7172932238 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2749#issuecomment-7172932238). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-25T19:54:43Z. --- Independent local verification of this PR (claim `VERIFY-2749-XTASKQUEUE-PORT-NOTIFICATIONS` on #1633). - Windows, Rust 1.100.0/MSVC, `cargo --locked`, `CARGO_BUILD_JOBS=2`. No GPU, no game data, no clippy/rustup. - Diff: 1 file, +112/-10 in `crates/victory-hle/src/modules/xasync.rs` (`tell_monitors` plus two synthetic tests). - `git diff --check origin/main..HEAD` clean; `origin/main` is an ancestor of the PR head. - `cargo test --locked -p victory-hle --lib monitors_hear_of --quiet` → 2 passed, 0 failed. - `cargo test --locked -p victory-hle --lib --quiet` → 148 passed, 0 failed (plus 1 doctest passed). - Negative control: both new test names are absent from `origin/main` in `xasync.rs`. - Only pre-existing deprecation warnings in `victory-gpu/src/object.rs` and `victory-hle/src/modules/xmem.rs`; non-blocking. No blocking findings. AI-assisted (Hy4 flash).
fuzeofficlal commented 2026-11-25 20:06:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T20:03:12Z.


Reviewed and verified 63c930da on Windows 11 against main (13f91ca).

Code review

  • Locking and re-entrancy look clean: Queue::new prunes dead Weak<Queue> entries under port.attached and records (Arc::downgrade(&queue), kind). Queue::tell_monitors upgrades live Weak references under port.attached, drops that lock, clones each queue's monitor callbacks under queue.monitors, drops that lock, and invokes all callbacks outside every lock—so callbacks re-entering register_monitor/unregister_monitor/XTaskQueueCloseHandle/XTaskQueueTerminate/Submit/Dispatch cannot deadlock.
  • Notification ordering: deliver enqueues onto target.submit(task) (waking ready) before tell_monitors for Manual/Serialized ports, avoiding lost wakeups for a Dispatch triggered by the monitor; for Immediate, monitors run before task.run(false).
  • Composite queues: binding the same Port as both WORK and COMPLETION records both (derived, WORK) and (derived, COMPLETION), notifying each attached queue with its own handle and port kind. (Minor non-blocking note: dead Weaks in attached are pruned on the next Queue::new rather than inside tell_monitors, which is fine unless a single long-lived port churns many short-lived composite queues.)

Verification (Windows 11, rustc 1.98.1 MSVC)

  • cargo test -p victory-hle --lib --locked (3 consecutive full parallel runs): 3/3 passed (148 passed, 0 failed + crash_child 1 passed, 0 failed each run, including both new composite/immediate monitor tests).
  • cargo clippy -p victory-hle --all-targets --locked (default and --all-features): 0 warnings; cargo xtask policy: 184 files ok.
  • Clean git merge-tree against 13f91ca, #2616, and #2618.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7173121590 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2749#issuecomment-7173121590). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T20:03:12Z. --- Reviewed and verified `63c930da` on Windows 11 against `main` (`13f91ca`). ### Code review - **Locking and re-entrancy look clean**: `Queue::new` prunes dead `Weak<Queue>` entries under `port.attached` and records `(Arc::downgrade(&queue), kind)`. `Queue::tell_monitors` upgrades live `Weak` references under `port.attached`, drops that lock, clones each queue's monitor callbacks under `queue.monitors`, drops that lock, and invokes all callbacks outside every lock—so callbacks re-entering `register_monitor`/`unregister_monitor`/`XTaskQueueCloseHandle`/`XTaskQueueTerminate`/`Submit`/`Dispatch` cannot deadlock. - **Notification ordering**: `deliver` enqueues onto `target.submit(task)` (waking `ready`) before `tell_monitors` for `Manual`/`Serialized` ports, avoiding lost wakeups for a `Dispatch` triggered by the monitor; for `Immediate`, monitors run before `task.run(false)`. - **Composite queues**: binding the same `Port` as both `WORK` and `COMPLETION` records both `(derived, WORK)` and `(derived, COMPLETION)`, notifying each attached queue with its own handle and port kind. (Minor non-blocking note: dead `Weak`s in `attached` are pruned on the next `Queue::new` rather than inside `tell_monitors`, which is fine unless a single long-lived port churns many short-lived composite queues.) ### Verification (Windows 11, `rustc 1.98.1` MSVC) - `cargo test -p victory-hle --lib --locked` (3 consecutive full parallel runs): **3/3 passed** (`148 passed, 0 failed` + `crash_child` `1 passed, 0 failed` each run, including both new composite/immediate monitor tests). - `cargo clippy -p victory-hle --all-targets --locked` (default and `--all-features`): **0 warnings**; `cargo xtask policy`: **184 files ok**. - Clean `git merge-tree` against `13f91ca`, `#2616`, and `#2618`.
kotekompotek commented 2026-11-25 21:03:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T20:07:35Z.


Matches the reference behavior: every queue sharing a port hears of items queued to it, so a composite queue's submits wake the owner's monitor and its dispatcher no longer sleeps through library work. Weak refs on the attached list can't resurrect dead queues, and the retain on attach prunes closed ones. Ordering is right too - immediate ports run the task after monitors are told.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7173225369 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2749#issuecomment-7173225369). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T20:07:35Z. --- Matches the reference behavior: every queue sharing a port hears of items queued to it, so a composite queue's submits wake the owner's monitor and its dispatcher no longer sleeps through library work. Weak refs on the attached list can't resurrect dead queues, and the retain on attach prunes closed ones. Ordering is right too - immediate ports run the task after monitors are told.
Marvisak commented 2026-11-26 00:03:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:26:08Z.


Automated triage for the maintainers. In crates/victory-hle/src/modules/xasync.rs, each Port now keeps a weak list of the queues that use it. Queue::deliver/tell_monitors call the monitors of every such queue, outside the locks, so a task submitted through a composite queue wakes the owning queue's monitor. An immediate port now notifies before it runs the task. Both behaviours follow the cited public reference (libHttpClient TaskQueue.cpp). I checked that the weak references create no cycle, that dead entries are pruned in Queue::new, and that callbacks run with no lock held. One minor point: a composite queue that uses the same port twice hears of a task once per use. CI: check passing. This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177555335 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2749#issuecomment-7177555335). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T23:26:08Z. --- <!-- victory-triage v1 head=63c930da533abff4aa0ac4b096afea6bfd738ca7 verdict=merge-candidate at=2026-11-25T23:26:01Z --> Automated triage for the maintainers. In `crates/victory-hle/src/modules/xasync.rs`, each `Port` now keeps a weak list of the queues that use it. `Queue::deliver`/`tell_monitors` call the monitors of every such queue, outside the locks, so a task submitted through a composite queue wakes the owning queue's monitor. An immediate port now notifies before it runs the task. Both behaviours follow the cited public reference (libHttpClient `TaskQueue.cpp`). I checked that the weak references create no cycle, that dead entries are pruned in `Queue::new`, and that callbacks run with no lock held. One minor point: a composite queue that uses the same port twice hears of a task once per use. CI: `check` passing. This is a recommendation for a maintainer to look, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
Dukestar69 commented 2026-11-26 04:11:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T04:11:57Z.

Review: APPROVED


Tested merged onto origin/main (63bcca4) on Windows 11 x64:

  • cargo test -p victory-hle --lib modules::xasync::: 15 passed, 0 failed (including new monitors_hear_of_tasks_submitted_through_a_composite_queue and monitors_hear_of_an_immediate_task_before_it_runs).
  • cargo clippy -p victory-hle --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6068446573 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2749#pullrequestreview-6068446573). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T04:11:57Z. **Review:** APPROVED --- Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64: - `cargo test -p victory-hle --lib modules::xasync::`: **15 passed, 0 failed** (including new `monitors_hear_of_tasks_submitted_through_a_composite_queue` and `monitors_hear_of_an_immediate_task_before_it_runs`). - `cargo clippy -p victory-hle --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
futurepro62 commented 2026-11-26 14:01:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T13:32:16Z.


NVIDIA full-suite run, to go with the reports above by Dukestar69, cloph-dsp, fuzeofficlal, since none of them names a GPU run. Tested exact head 63c930d (on its base 13f91ca).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 775 passed, 0 failed, 9 ignored.
  • The new tests ran and passed: monitors_hear_of_tasks_submitted_through_a_composite_queue, monitors_hear_of_an_immediate_task_before_it_runs.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7193487987 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2749#issuecomment-7193487987). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T13:32:16Z. --- NVIDIA full-suite run, to go with the reports above by Dukestar69, cloph-dsp, fuzeofficlal, since none of them names a GPU run. Tested exact head `63c930d` (on its base `13f91ca`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **775 passed, 0 failed, 9 ignored**. - The new tests ran and passed: `monitors_hear_of_tasks_submitted_through_a_composite_queue`, `monitors_hear_of_an_immediate_task_before_it_runs`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
fuzeofficlal commented 2026-11-27 01:11:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T01:11:05Z.

Review: CHANGES_REQUESTED


The Port::attached Weak<Queue> fan-out avoids lock-ordering cycles (all mutexes are released before invoking callbacks), modules::xasync:: tests pass (15/15), and rustfmt (on changed lines), clippy, and xtask policy are clean.

Two behavioral issues in the new deliver / tell_monitors flow should be fixed before merge:

  1. Immediate tasks still run uncanceled if a monitor terminates the queue (xasync.rs:265-270)

    • Because tell_monitors(target) now runs before task.run(false) on Mode::Immediate, a monitor callback that calls XTaskQueueTerminate(queue, ...) observes termination and returns, yet deliver still invokes task.run(false) on the stack-held task (since it was never in port.tasks or queue.delayed). Checking self.terminated.load(Ordering::Acquire) after tell_monitors (passing it to task.run(...)) avoids running uncanceled work post-termination.
  2. Composite queues sharing one Port for WORK and COMPLETION receive two monitor calls per task (xasync.rs:217-222, :278-292)

    • Queue::new pushes both (queue, WORK) and (queue, COMPLETION) into the same port.attached, so a single submission fires any monitor registered on that composite queue twice. If the monitor synchronously dispatches (XTaskQueueDispatch(..., INFINITE)), the first invocation drains the single task and the second invocation stalls submission waiting on an empty queue.
<!-- greyfinch-sync:Marvisak/VIctory:review:6082188268 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2749#pullrequestreview-6082188268). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T01:11:05Z. **Review:** CHANGES_REQUESTED --- The `Port::attached` `Weak<Queue>` fan-out avoids lock-ordering cycles (all mutexes are released before invoking callbacks), `modules::xasync::` tests pass (15/15), and `rustfmt` (on changed lines), `clippy`, and `xtask policy` are clean. Two behavioral issues in the new `deliver` / `tell_monitors` flow should be fixed before merge: 1. **Immediate tasks still run uncanceled if a monitor terminates the queue (`xasync.rs:265-270`)** - Because `tell_monitors(target)` now runs before `task.run(false)` on `Mode::Immediate`, a monitor callback that calls `XTaskQueueTerminate(queue, ...)` observes termination and returns, yet `deliver` still invokes `task.run(false)` on the stack-held `task` (since it was never in `port.tasks` or `queue.delayed`). Checking `self.terminated.load(Ordering::Acquire)` after `tell_monitors` (passing it to `task.run(...)`) avoids running uncanceled work post-termination. 2. **Composite queues sharing one `Port` for `WORK` and `COMPLETION` receive two monitor calls per task (`xasync.rs:217-222`, `:278-292`)** - `Queue::new` pushes both `(queue, WORK)` and `(queue, COMPLETION)` into the same `port.attached`, so a single submission fires any monitor registered on that composite queue twice. If the monitor synchronously dispatches (`XTaskQueueDispatch(..., INFINITE)`), the first invocation drains the single task and the second invocation stalls submission waiting on an empty queue.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2749:upstream-pr/2749'
git switch 'upstream-pr/2749'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2749'
git switch 'upstream-pr/2749'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2749'
git switch 'upstream-pr/2749'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2749'
git switch 'main'
git merge --squash 'upstream-pr/2749'
git switch 'main'
git merge --ff-only 'upstream-pr/2749'
git switch 'main'
git merge 'upstream-pr/2749'
git push origin 'main'
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
Marvisak/VIctory!2747
No description provided.