XGameRuntime: skip canceled device association callbacks and serialize sign-in check #1231

Closed
github-bot wants to merge 1 commit from gh-pr/1231/head into gh-pr/1231/base
Owner

@⁠b3IKK on GitHub · 2026-11-24 13:26 UTC · original
b3IKK:xgameruntime/xuser-association-canceled → main · +38 −9 · 1 files · 1 commits · closed without merging

association_call ignored the task queue's canceled parameter, so terminating the queue before dispatching still invoked the guest's XUserDeviceAssociationChangedCallback on a terminated queue instead of only dropping Box<AssociationCall>.

In addition, XUserRegisterForDeviceAssociationChanged pushed to ASSOCIATION_CALLBACKS and checked USER_SIGNED_IN outside the lock while user_signed_in() swapped USER_SIGNED_IN before locking, allowing a concurrent sign-in and registration to deliver the same callback twice.

This skips invoking the guest callback when canceled is true and reads/sets USER_SIGNED_IN while holding ASSOCIATION_CALLBACKS.

What is in it

  • crates/xcl/src/hle/xgameruntime/mod.rs: return without invoking the guest callback in association_call when canceled is true; check/set USER_SIGNED_IN under ASSOCIATION_CALLBACKS.lock(); add unit test device_association_callback_not_invoked_when_queue_terminated (verified failing before the fix).

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 742 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 no wave64 — gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)
  • cargo test -p xcl --lib device_association_callback_not_invoked_when_queue_terminated: 1 passed, 0 failed (failed before the fix with callback invoked once on queue termination)

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1226 (PresentX 1226)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15341 MB

PR:

xcl-smoke v1
commit: 8947c81d6f61904dc3da59acb4968ac9e76ef0f6
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
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: 14598 MB

Not tested

  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Gemini 4 Neon: audited xgameruntime/mod.rs, wrote the fix and regression test, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.
**@⁠b3IKK** on GitHub · 2026-11-24 13:26 UTC · [original](https://github.com/xcl-dev/xcl/pull/1231) `b3IKK:xgameruntime/xuser-association-canceled` → `main` · +38 −9 · 1 files · 1 commits · closed without merging `association_call` ignored the task queue's `canceled` parameter, so terminating the queue before dispatching still invoked the guest's `XUserDeviceAssociationChangedCallback` on a terminated queue instead of only dropping `Box<AssociationCall>`. In addition, `XUserRegisterForDeviceAssociationChanged` pushed to `ASSOCIATION_CALLBACKS` and checked `USER_SIGNED_IN` outside the lock while `user_signed_in()` swapped `USER_SIGNED_IN` before locking, allowing a concurrent sign-in and registration to deliver the same callback twice. This skips invoking the guest callback when `canceled` is true and reads/sets `USER_SIGNED_IN` while holding `ASSOCIATION_CALLBACKS`. **What is in it** - `crates/xcl/src/hle/xgameruntime/mod.rs`: return without invoking the guest callback in `association_call` when `canceled` is true; check/set `USER_SIGNED_IN` under `ASSOCIATION_CALLBACKS.lock()`; add unit test `device_association_callback_not_invoked_when_queue_terminated` (verified failing before the fix). **Tested** - hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`), DXC 1.9.2609.5, debug (`scripts/test.ps1`) and release (`scripts/smoke.ps1`) - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): 742 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 `no wave64` — `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware`) - `cargo test -p xcl --lib device_association_callback_not_invoked_when_queue_terminated`: 1 passed, 0 failed (failed before the fix with callback invoked once on queue termination) **Regression run** main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1226 (PresentX 1226) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15341 MB ``` PR: ``` xcl-smoke v1 commit: 8947c81d6f61904dc3da59acb4968ac9e76ef0f6 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e 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: 14598 MB ``` **Not tested** - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Gemini 4 Neon: audited `xgameruntime/mod.rs`, wrote the fix and regression test, ran the test suite and `scripts/smoke.ps1` regression runs, and drafted this PR description.
association_call ignored the task queue's `canceled` parameter, so
terminating the queue before dispatching still invoked the guest's
XUserDeviceAssociationChangedCallback on a terminated queue instead of
only dropping the AssociationCall allocation.

In addition, XUserRegisterForDeviceAssociationChanged pushed to
ASSOCIATION_CALLBACKS and read USER_SIGNED_IN outside the lock while
user_signed_in swapped USER_SIGNED_IN before locking, allowing a
concurrent sign-in and registration to deliver the same callback twice.

Skip invoking the guest callback when `canceled` is true, and read/set
USER_SIGNED_IN while holding ASSOCIATION_CALLBACKS so each registration
is notified once.

Assisted-by: OpenCode (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:47:53 +00:00
github-bot closed this pull request 2026-11-26 04:47:53 +00:00
Author
Owner

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

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

  • cargo test -p xcl --lib xgameruntime: 74 passed, 0 failed.

Note: the full d3d12x lib filter currently aborts with 0xc0000005 on unmodified main too (pre-existing, unrelated to this PR); the PR's own tests were run by name and pass.

**@⁠DavidM1911** on GitHub · 2026-11-24 13:47 UTC · [original](https://github.com/xcl-dev/xcl/pull/1231#issuecomment-7133339997) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - cargo test -p xcl --lib xgameruntime: 74 passed, 0 failed. Note: the full `d3d12x` lib filter currently aborts with 0xc0000005 on unmodified `main` too (pre-existing, unrelated to this PR); the PR's own tests were run by name and pass.
Author
Owner

@⁠b3IKK on GitHub · 2026-11-25 00:04 UTC · original

Closing in favour of #1753, this account's later PR on the same callbacks (#1607, group D58). #1753's association_call already skips a call the queue canceled, which is the first half of this PR, and also cancels queued calls on unregister. The second half here (reading the sign-in flag under the callbacks lock) is what #1418 and #1583 do more completely. AI use: OpenCode, Claude Fable 5.2.

**@⁠b3IKK** on GitHub · 2026-11-25 00:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/1231#issuecomment-7148118466) Closing in favour of #1753, this account's later PR on the same callbacks (#1607, group D58). #1753's `association_call` already skips a call the queue canceled, which is the first half of this PR, and also cancels queued calls on unregister. The second half here (reading the sign-in flag under the callbacks lock) is what #1418 and #1583 do more completely. AI use: OpenCode, Claude Fable 5.2.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 04:17 UTC · original

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 04:17 UTC · [original](https://github.com/xcl-dev/xcl/pull/1231#issuecomment-7182462759) Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.