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

Open
github-bot wants to merge 1 commit from github-bot/gh-2749 into main AGit
Owner

@⁠F1reworks10 on GitHub · 2026-11-25 19:34 UTC · original
F1reworks10:xtaskqueue-monitors-of-shared-ports → main · +112 −10 · 1 files · 1 commits · open

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

**@⁠F1reworks10** on GitHub · 2026-11-25 19:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2749) `F1reworks10:xtaskqueue-monitors-of-shared-ports` → `main` · +112 −10 · 1 files · 1 commits · open 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)
What was wrong: a task submitted to a port reached only the monitors of
the queue it was submitted through. A composite queue made of another
queue's ports therefore never woke that queue's monitor. The GDK
documents both halves of the common setup: a monitor that wakes a manual
queue's dispatcher (XTaskQueueRegisterMonitor's example) and a library
that shares a queue through a composite queue made of its ports
(XTaskQueueCreateComposite's example). Together, on main, the library's
callbacks wait in the port while the dispatcher sleeps. In the public
reference (libHttpClient's TaskQueue.cpp, NotifyItemQueued), every port
context attached to a port hears of each item queued to it, so each
queue using the port calls its monitors, with its own handle and the
port it uses. The reference also calls them before an immediate port
runs the item; we called them after it had run.

What changed: a port keeps the queues using it (weakly, 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 them, outside
any lock, and an immediate port runs the task after its monitors have
heard of it.

Evidence: `monitors_hear_of_tasks_submitted_through_a_composite_queue`
fails on main (the owner's monitor hears nothing) and
`monitors_hear_of_an_immediate_task_before_it_runs` fails on main (the
monitor hears of the task after it ran). `cargo test -p victory-hle`
passes; clippy (with and without --all-features) is clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:13:20 +00:00
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-25 19:54 UTC · original

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).

**@⁠cloph-dsp** on GitHub · 2026-11-25 19:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/2749#issuecomment-7172932238) 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).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 20:03 UTC · original

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.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 20:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2749#issuecomment-7173121590) 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`.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 20:07 UTC · original

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.

**@⁠kotekompotek** on GitHub · 2026-11-25 20:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/2749#issuecomment-7173225369) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:26 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 23:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2749#issuecomment-7177555335) <!-- 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)_
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 04:11 UTC · original · approved these changes

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).

**@⁠Dukestar69** on GitHub · 2026-11-26 04:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/2749#pullrequestreview-6068446573) · **approved these changes** 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).
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 13:32 UTC · original

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.
**@⁠futurepro62** on GitHub · 2026-11-26 13:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/2749#issuecomment-7193487987) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2749/head:github-bot/gh-2749'
git switch 'github-bot/gh-2749'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2749'
git switch 'github-bot/gh-2749'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2749'
git switch 'github-bot/gh-2749'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2749'
git switch 'main'
git merge --squash 'github-bot/gh-2749'
git switch 'main'
git merge --ff-only 'github-bot/gh-2749'
git switch 'main'
git merge 'github-bot/gh-2749'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2749
No description provided.