XGameRuntime: synchronize device association registration and unregister (#1389) #1418

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

@⁠hajduzsolt on GitHub · 2026-11-24 15:46 UTC · original
hajduzsolt:fix/xuser-device-association-safety → main · +245 −29 · 1 files · 1 commits · open

What is in it

  • crates/xcl/src/hle/xgameruntime/mod.rs:
  • Defined AssociationEntry and AssociationState tracking stopped, in_flight, and active thread IDs with a Condvar (matching gameinput.rs pattern).
  • association_call: drops Box without calling cb when canceled is true or st.stopped is true; uses AssociationInFlightGuard to safely track in-flight execution and signal done upon completion.
  • XUserRegisterForDeviceAssociationChanged and user_signed_in: protected by ASSOCIATION_MGR mutex so registration and signed_in state transitions cannot race to queue duplicate association callbacks.
  • XUserUnregisterForDeviceAssociationChanged: atomically removes the entry, marks stopped = true, and if wait = true, waits until all in-flight invocations on other threads have finished (re-entrant calls on the callback's own thread return immediately without deadlocking).
  • Unit tests:
  • association_unregister_stops_pending_callback: verifies unregistering stops queued items from executing on manual queue dispatch.
  • association_call_drops_on_canceled_queue: verifies queue termination (canceled = true) drops callbacks safely.
  • association_unregister_waits_for_in_flight_callback: verifies wait = true blocks until in-flight execution finishes.
  • association_unregister_reentrant_and_unknown_token: verifies re-entrant unregister succeeds without deadlock, and invalid/already-removed tokens return false.

Tested

  • Hardware: AMD Radeon RX 9070 XT 16GB, AMD Ryzen 7 9800X3D, Windows 11 x64, rustc 1.98.1 (48a229cea 2026-09-01), debug
  • cargo test --workspace -- --test-threads=4: 752 passed, 0 failed, 37 ignored (SKIPPED GPU tests: none)
  • cargo test -p xcl --lib hle::xgameruntime: 77 passed, 0 failed

Regression run

main:

xcl-smoke v1
commit: b7aa9f3bd212088e0d927439284dc5ed325ce3c7
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1675 (PresentX 1675)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14837 MB

PR:

xcl-smoke v1
commit: 2fc1b5c8a671b49b0b398948b8e3966d3d0caf04
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1682 (PresentX 1682)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14834 MB

Not tested

  • Physical multi-gamepad hardware hotplugging under Windows Gaming Services (verified via virtual gamepad device association and synthetic taskqueue tests).

AI use

  • Antigravity (Gemini) wrote the code and unit tests, and drafted this description.
**@⁠hajduzsolt** on GitHub · 2026-11-24 15:46 UTC · [original](https://github.com/xcl-dev/xcl/pull/1418) `hajduzsolt:fix/xuser-device-association-safety` → `main` · +245 −29 · 1 files · 1 commits · open **What is in it** - crates/xcl/src/hle/xgameruntime/mod.rs: - Defined AssociationEntry and AssociationState tracking stopped, in_flight, and active thread IDs with a Condvar (matching gameinput.rs pattern). - association_call: drops Box<AssociationCall> without calling cb when canceled is true or st.stopped is true; uses AssociationInFlightGuard to safely track in-flight execution and signal done upon completion. - XUserRegisterForDeviceAssociationChanged and user_signed_in: protected by ASSOCIATION_MGR mutex so registration and signed_in state transitions cannot race to queue duplicate association callbacks. - XUserUnregisterForDeviceAssociationChanged: atomically removes the entry, marks stopped = true, and if wait = true, waits until all in-flight invocations on other threads have finished (re-entrant calls on the callback's own thread return immediately without deadlocking). - Unit tests: - association_unregister_stops_pending_callback: verifies unregistering stops queued items from executing on manual queue dispatch. - association_call_drops_on_canceled_queue: verifies queue termination (canceled = true) drops callbacks safely. - association_unregister_waits_for_in_flight_callback: verifies wait = true blocks until in-flight execution finishes. - association_unregister_reentrant_and_unknown_token: verifies re-entrant unregister succeeds without deadlock, and invalid/already-removed tokens return false. **Tested** - Hardware: AMD Radeon RX 9070 XT 16GB, AMD Ryzen 7 9800X3D, Windows 11 x64, rustc 1.98.1 (48a229cea 2026-09-01), debug - `cargo test --workspace -- --test-threads=4`: 752 passed, 0 failed, 37 ignored (SKIPPED GPU tests: none) - `cargo test -p xcl --lib hle::xgameruntime`: 77 passed, 0 failed **Regression run** main: ``` xcl-smoke v1 commit: b7aa9f3bd212088e0d927439284dc5ed325ce3c7 gpu: AMD Radeon RX 9070 XT title: A newer retail game seconds: 60 exit: 0x0 frames shown: 1675 (PresentX 1675) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14837 MB ``` PR: ``` xcl-smoke v1 commit: 2fc1b5c8a671b49b0b398948b8e3966d3d0caf04 gpu: AMD Radeon RX 9070 XT title: A newer retail game seconds: 60 exit: 0x0 frames shown: 1682 (PresentX 1682) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14834 MB ``` **Not tested** - Physical multi-gamepad hardware hotplugging under Windows Gaming Services (verified via virtual gamepad device association and synthetic taskqueue tests). **AI use** - Antigravity (Gemini) wrote the code and unit tests, and drafted this description.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:53:16 +00:00
Author
Owner

@⁠Anon64 on GitHub · 2026-11-24 15:54 UTC · original

Regression run for this PR: head 2fc1b5c, based on main 930e8b4. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, XCL_NETWORK=0, A pressed every 4 s from 20 s, scripts/smoke.ps1 on a retail title for 60 s.

main 930e8b4:

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

this PR:

xcl-smoke v1
commit: 2fc1b5c8a671b49b0b398948b8e3966d3d0caf04
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1594 (PresentX 1594)
presents per 2 s (last 3): 57 34 49
device removals: 0
crashes: 0
peak commit: 91885 MB

No device removals or crashes; 104 % of main's frames, 100 % of its peak commit.

Both runs' peak commit is high because of this machine's pipeline preload list at the time (the same on main), not this PR.

Not tested: the whole suite; whether the title reaches the changed code in these 60 s.

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

**@⁠Anon64** on GitHub · 2026-11-24 15:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/1418#issuecomment-7136817736) Regression run for this PR: head `2fc1b5c`, based on `main` `930e8b4`. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, `XCL_NETWORK=0`, A pressed every 4 s from 20 s, `scripts/smoke.ps1` on a retail title for 60 s. main `930e8b4`: ``` xcl-smoke v1 commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1537 (PresentX 1537) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 92236 MB ``` this PR: ``` xcl-smoke v1 commit: 2fc1b5c8a671b49b0b398948b8e3966d3d0caf04 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1594 (PresentX 1594) presents per 2 s (last 3): 57 34 49 device removals: 0 crashes: 0 peak commit: 91885 MB ``` No device removals or crashes; 104 % of main's frames, 100 % of its peak commit. Both runs' peak commit is high because of this machine's pipeline preload list at the time (the same on `main`), not this PR. **Not tested:** the whole suite; whether the title reaches the changed code in these 60 s. Written with Claude Code (Claude Opus 5.5) from runs on this machine.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 15:57 UTC · original · edited 2026-11-24 16:05 UTC

Full-suite run, since this PR has no test report yet. Tested exact head 2fc1b5c (on its base 930e8b4).

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: 755 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: association_unregister_stops_pending_callback, association_call_drops_on_canceled_queue, association_unregister_waits_for_in_flight_callback, association_unregister_reentrant_and_unknown_token.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 755 passed, 0 failed, 41 ignored, no skips.

Not tested

  • 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.
**@⁠futurepro62** on GitHub · 2026-11-24 15:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/1418#issuecomment-7136888214) · edited 2026-11-24 16:05 UTC Full-suite run, since this PR has no test report yet. Tested exact head `2fc1b5c` (on its base `930e8b4`). **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`: **755 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: `association_unregister_stops_pending_callback`, `association_call_drops_on_canceled_queue`, `association_unregister_waits_for_in_flight_callback`, `association_unregister_reentrant_and_unknown_token`. - Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **755 passed, 0 failed, 41 ignored**, no skips. **Not tested** - 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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 17:13 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (One parallel run showed a single flaky failure; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 17:13 UTC · [original](https://github.com/xcl-dev/xcl/pull/1418#issuecomment-7138865354) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. (One parallel run showed a single flaky failure; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
Author
Owner

@⁠throny on GitHub · 2026-11-25 00:27 UTC · original

Two contributors checked independently and found that #1583 #1753 solves the same problem (for #1389) in a different way: #1607, group D58. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

**@⁠throny** on GitHub · 2026-11-25 00:27 UTC · [original](https://github.com/xcl-dev/xcl/pull/1418#issuecomment-7148522386) <!-- xcl-1607-hint:D58 --> Two contributors checked independently and found that #1583 #1753 solves the same problem (for #1389) in a different way: #1607, group D58. You may want to compare them with the other author and agree on one, or say in the PR why both are needed. This is a hint from the community triage in #1607, not a maintainer decision. AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
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/1418/head:github-bot/gh-1418'
git switch 'github-bot/gh-1418'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1418'
git switch 'github-bot/gh-1418'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1418'
git switch 'github-bot/gh-1418'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1418'
git switch 'main'
git merge --squash 'github-bot/gh-1418'
git switch 'main'
git merge --ff-only 'github-bot/gh-1418'
git switch 'main'
git merge 'github-bot/gh-1418'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.