XGameRuntime: retain an async operation's queue after handle close #636

Open
WebIdentity1 wants to merge 1 commit from upstream-pr/641 into main
WebIdentity1 commented 2026-11-24 02:49:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by WebIdentity1 on 2026-11-24T02:49:06Z.


Closing the caller's queue handle after XAsyncBegin can make later scheduling fail or silently drop completion. XAsyncRun also loses its completion callback if its original handle closes before dispatch. Retain the queue in the operation's state and use that reference for scheduling and completion, following the existing libHttpClient contract.

Part of #576, item 2 only. Items 1, 3 and 4 remain unresolved. The cleanup-guard changes from closed #197 are not included or tested in combination. #235's fallback selection is outside this patch.

What is in it

  • State retains a queue reference captured by Begin/Run; Schedule/Complete use it. Three synthetic queue-handle regressions and README behavior note. No new dependency or copied reference code.

Tested

  • Head 8d0bbc87fb9423f1c2d49b9d43b4ab7ecba710b6, base 18c105af86929d6ae26c44096c85b66f1644e743. Native Windows 10 build 19045, Ryzen 7 7800X3D, RTX 3090 driver 591.74 plus AMD integrated driver 32.0.21030.2001, Rust 1.98.1 MSVC, SDK DXC 1.8.2502.11, Agility 1.620.2, debug.
  • cargo build --locked --workspace succeeded. cargo test --locked --workspace --no-fail-fast -- --test-threads=4 --show-output: 691 passed, 1 failed, 41 ignored. Only gpu_clamp_and_omod_per_instruction failed, previously reproduced on main. All three new regressions passed. Desktop session1, XCL_ADAPTER=3090; some upstream fixtures select AMD directly.
  • Before rebasing from 3db536e, cargo test --locked -p xcl --lib after_queue_handle_close -- --test-threads=1 --show-output: original runtime plus tests 0/3/0 (Complete/Run delivered zero callbacks; Schedule returned E_INVALIDARG), candidate 3/0/0. The original xasync.rs is identical on both base revisions. Immediate/manual ports avoid timing-dependent sleeps; the completion test also verifies the retained queue is released. cargo test --locked -p xcl --lib hle::xgameruntime:: -- --test-threads=4 --show-output: 76/0/0, no skips.
  • Four explicit full-suite skips: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no native wave64 on NVIDIA), test_title_draws_with_a_root_signature_under_the_debug_layer and uploads_start_from_each_subresources_state (debug layer unavailable). Sample variables unset; those opt-in cases return early.

Regression run
Independent contributor Anon64 supplied these exact-head/main runs, copied verbatim from that report. These are their measurements, not ours. RTX3060 12GB driver581.80, i9-14900KF, Windows11 26200.9974, Rust1.90.0, release; same title/duration, clean source, scripts/smoke.ps1. They report no test of early queue-handle closure in that title; our synthetic regressions cover that path.

xcl-smoke v1
commit: 18c105af86929d6ae26c44096c85b66f1644e743
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1648 (PresentX 1648)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14584 MB
xcl-smoke v1
commit: 8d0bbc87fb9423f1c2d49b9d43b4ab7ecba710b6
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1648 (PresentX 1648)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14586 MB

Draft retained: upstream CI run45315130577 awaits maintainer approval (action_required), and our local full suite retains the disclosed baseline CLAMP failure. No source update has invalidated these exact-head runs.

Not tested
By us: retail titles, release, Wine, installed PC XGameRuntime, or integration with #197. The independently reported startup smoke above is not gameplay or early-handle-close validation. This does not fix stale queued work or callback/wait ordering, and demonstrates no retail title gameplay progress.

AI use
Codex (GPT-6) inspected public code and overlap, implemented the queue-retention change and tests, ran native Windows validation, and prepared this description.

<!-- greyfinch-sync:ivall/xcl:issue:5465143361 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/641). Originally posted by [WebIdentity1](https://github.com/WebIdentity1) on 2026-11-24T02:49:06Z. --- Closing the caller's queue handle after `XAsyncBegin` can make later scheduling fail or silently drop completion. `XAsyncRun` also loses its completion callback if its original handle closes before dispatch. Retain the queue in the operation's state and use that reference for scheduling and completion, following the existing [libHttpClient contract](https://github.com/microsoft/libHttpClient/blob/c5007fd9cbdc785518ea6dccc5751b125d451cc1/Source/Task/AsyncLib.cpp#L431). Part of #576, **item 2 only**. Items 1, 3 and 4 remain unresolved. The cleanup-guard changes from closed #197 are not included or tested in combination. #235's fallback selection is outside this patch. **What is in it** - `State` retains a queue reference captured by Begin/Run; Schedule/Complete use it. Three synthetic queue-handle regressions and README behavior note. No new dependency or copied reference code. **Tested** - Head `8d0bbc87fb9423f1c2d49b9d43b4ab7ecba710b6`, base `18c105af86929d6ae26c44096c85b66f1644e743`. Native Windows 10 build 19045, Ryzen 7 7800X3D, RTX 3090 driver 591.74 plus AMD integrated driver 32.0.21030.2001, Rust 1.98.1 MSVC, SDK DXC 1.8.2502.11, Agility 1.620.2, debug. - `cargo build --locked --workspace` succeeded. `cargo test --locked --workspace --no-fail-fast -- --test-threads=4 --show-output`: **691 passed, 1 failed, 41 ignored**. Only `gpu_clamp_and_omod_per_instruction` failed, previously reproduced on main. All three new regressions passed. Desktop session1, `XCL_ADAPTER=3090`; some upstream fixtures select AMD directly. - Before rebasing from `3db536e`, `cargo test --locked -p xcl --lib after_queue_handle_close -- --test-threads=1 --show-output`: original runtime plus tests **0/3/0** (Complete/Run delivered zero callbacks; Schedule returned `E_INVALIDARG`), candidate **3/0/0**. The original `xasync.rs` is identical on both base revisions. Immediate/manual ports avoid timing-dependent sleeps; the completion test also verifies the retained queue is released. `cargo test --locked -p xcl --lib hle::xgameruntime:: -- --test-threads=4 --show-output`: **76/0/0**, no skips. - Four explicit full-suite skips: `gpu_geometry_wave32_prefix_count_over_a_mask` and `gpu_wave32_program_in_wave64_hardware` (no native wave64 on NVIDIA), `test_title_draws_with_a_root_signature_under_the_debug_layer` and `uploads_start_from_each_subresources_state` (debug layer unavailable). Sample variables unset; those opt-in cases return early. **Regression run** Independent contributor [Anon64 supplied these exact-head/main runs](https://github.com/ivall/xcl/pull/641#issuecomment-7125009498), copied verbatim from that report. These are their measurements, not ours. RTX3060 12GB driver581.80, i9-14900KF, Windows11 26200.9974, Rust1.90.0, release; same title/duration, clean source, `scripts/smoke.ps1`. They report no test of early queue-handle closure in that title; our synthetic regressions cover that path. ``` xcl-smoke v1 commit: 18c105af86929d6ae26c44096c85b66f1644e743 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1648 (PresentX 1648) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14584 MB ``` ``` xcl-smoke v1 commit: 8d0bbc87fb9423f1c2d49b9d43b4ab7ecba710b6 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1648 (PresentX 1648) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14586 MB ``` Draft retained: upstream CI run45315130577 awaits maintainer approval (`action_required`), and our local full suite retains the disclosed baseline CLAMP failure. No source update has invalidated these exact-head runs. **Not tested** By us: retail titles, release, Wine, installed PC XGameRuntime, or integration with #197. The independently reported startup smoke above is not gameplay or early-handle-close validation. This does not fix stale queued work or callback/wait ordering, and demonstrates no retail title gameplay progress. **AI use** Codex (GPT-6) inspected public code and overlap, implemented the queue-retention change and tests, ran native Windows validation, and prepared this description.
futurepro62 commented 2026-11-24 07:06:56 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T07:05:58Z.


Full-suite run, since this PR has no test report yet. Tested exact head 8d0bbc8 (on its base 18c105a).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 692 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: async_complete_after_queue_handle_close_delivers_callback, async_run_after_queue_handle_close_delivers_callback, async_schedule_after_queue_handle_close_uses_begins_queue.

Not tested

  • AMD, a release build, a game (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:ivall/xcl:comment:7124614013 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/641#issuecomment-7124614013). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T07:05:58Z. --- Full-suite run, since this PR has no test report yet. Tested exact head `8d0bbc8` (on its base `18c105a`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **692 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `async_complete_after_queue_handle_close_delivers_callback`, `async_run_after_queue_handle_close_delivers_callback`, `async_schedule_after_queue_handle_close_uses_begins_queue`. **Not tested** - AMD, a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Anon64 commented 2026-11-24 08:03:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Anon64 on 2026-11-24T07:27:19Z.


Regression runs for this PR's head 8d0bbc8 and for its base main 18c105a, on a retail title (same title, 60 s each), made with scripts/smoke.ps1 (release, clean tree at each commit) and pasted unedited, for Regression run.

main:

xcl-smoke v1
commit: 18c105af86929d6ae26c44096c85b66f1644e743
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1648 (PresentX 1648)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14584 MB

this PR:

xcl-smoke v1
commit: 8d0bbc87fb9423f1c2d49b9d43b4ab7ecba710b6
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1648 (PresentX 1648)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14586 MB

Tested

  • NVIDIA GeForce RTX 3060 12 GB (driver 581.80, wave32), Intel Core i9-14900KF, Windows 11 25H2 26200.9974, Rust 1.90.0

Not tested

  • the unit tests on this machine
  • whether the title closes an async queue handle early; this is a regression check only

Report written with Claude Code (Claude Opus 5.5) from runs on this machine.

<!-- greyfinch-sync:ivall/xcl:comment:7125009498 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/641#issuecomment-7125009498). Originally posted by [Anon64](https://github.com/Anon64) on 2026-11-24T07:27:19Z. --- Regression runs for this PR's head `8d0bbc8` and for its base `main` `18c105a`, on a retail title (same title, 60 s each), made with `scripts/smoke.ps1` (release, clean tree at each commit) and pasted unedited, for **Regression run**. main: ``` xcl-smoke v1 commit: 18c105af86929d6ae26c44096c85b66f1644e743 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1648 (PresentX 1648) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14584 MB ``` this PR: ``` xcl-smoke v1 commit: 8d0bbc87fb9423f1c2d49b9d43b4ab7ecba710b6 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1648 (PresentX 1648) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14586 MB ``` **Tested** - NVIDIA GeForce RTX 3060 12 GB (driver 581.80, wave32), Intel Core i9-14900KF, Windows 11 25H2 26200.9974, Rust 1.90.0 **Not tested** - the unit tests on this machine - whether the title closes an async queue handle early; this is a regression check only Report written with Claude Code (Claude Opus 5.5) from runs on this machine.
DavidM1911 commented 2026-11-25 13:05:09 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T12:31:43Z.


Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

<!-- greyfinch-sync:ivall/xcl:comment:7162496346 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/641#issuecomment-7162496346). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T12:31:43Z. --- Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
github-actions[bot] commented 2026-11-29 07:42:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T07:42:48Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7252643445 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/641#issuecomment-7252643445). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-29T07:42:48Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 03:51:34 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:51:34Z.


Triage (#1607) – head 8d0bbc8

#670 (draft, same issue #576) changes the same XAsyncComplete code for the other two parts of #576: stale work items and waits that cover the callback. It still looks the queue up from (*b).queue at completion, so it does not keep the queue alive the way this PR does. Not the same change, but the two will conflict in XAsyncComplete. Main still resolves the queue from the block's handle in XAsyncSchedule and XAsyncComplete.
Keeping the Arc<Queue> in State from XAsyncBegin / XAsyncRun is consistent: the state is registered before the provider's Begin runs, so the new lookup in XAsyncSchedule finds it. No problems found in the diff.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7300135527 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/641#issuecomment-7300135527). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T03:51:34Z. --- **Triage (#1607)** – head 8d0bbc8 #670 (draft, same issue #576) changes the same XAsyncComplete code for the other two parts of #576: stale work items and waits that cover the callback. It still looks the queue up from `(*b).queue` at completion, so it does not keep the queue alive the way this PR does. Not the same change, but the two will conflict in `XAsyncComplete`. Main still resolves the queue from the block's handle in `XAsyncSchedule` and `XAsyncComplete`. Keeping the `Arc<Queue>` in `State` from `XAsyncBegin` / `XAsyncRun` is consistent: the state is registered before the provider's Begin runs, so the new `lookup` in `XAsyncSchedule` finds it. No problems found in the diff. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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/641:upstream-pr/641'
git switch 'upstream-pr/641'

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/641'
git switch 'upstream-pr/641'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/641'
git switch 'upstream-pr/641'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/641'
git switch 'main'
git merge --squash 'upstream-pr/641'
git switch 'main'
git merge --ff-only 'upstream-pr/641'
git switch 'main'
git merge 'upstream-pr/641'
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
xcl-dev/xcl!636
No description provided.