Skip to content

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

Open
hajduzsolt wants to merge 1 commit into
xcl-dev:mainfrom
hajduzsolt:fix/xuser-device-association-safety
Open

hajduzsolt wants to merge 1 commit into
xcl-dev:mainfrom
hajduzsolt:fix/xuser-device-association-safety

Conversation

@hajduzsolt

@hajduzsolt hajduzsolt commented Nov 24, 2026 •

Copy link
Copy Markdown

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.

@Anon64

Anon64 commented Nov 24, 2026

Copy link
Copy Markdown

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.

@futurepro62

futurepro62 commented Nov 24, 2026 •

Copy link
Copy Markdown

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.

@hajduzsolt
hajduzsolt marked this pull request as draft November 24, 2026 16:12
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…README

Integrates 12 additional open upstream PRs on top of upstream/main
(b7aa9f3):
- xcl-dev#1432: GFX10 to DXGI format mappings, depth SRVs, and byte sizing
- xcl-dev#1447: Arena::take overflow/alignment and Uma::free pool validation
- xcl-dev#1441: drop SC_KEYMENU so the window is never frozen in menu mode
- xcl-dev#1431, xcl-dev#1436: TLS directory sizing/alignment and RegisterClassExA checks
- xcl-dev#1430, xcl-dev#1446: XGameSave quota/URL and XAudio2 XMA channel validation
- xcl-dev#1415, xcl-dev#1433: VFS merged-directory sync and CreateFile2 checks
- xcl-dev#1418: XGameRuntime device association synchronization
- xcl-dev#1410, xcl-dev#1413: wave64 form logging and XCL_SAFE_BARRIER cache bypass

Also removes duplicate a_huge_constant_count_has_no_layout test left
from pre-applying xcl-dev#1290 before upstream merged it, and updates README.md.

Verified under GE-Proton11-14 (RX 9060 XT / RADV):
- Release build (x86_64-pc-windows-msvc): ok (22.05s)
- Proton unit test sweep across all merged/touched modules: 209 passed,
  2 failed (known Wine/vkd3d-proton diffs: xma2_source_voice current_buffer_context
  before Start, and vkd3d-proton accepting UNORDERED_ACCESS without UAV flag),
  1 ignored, 0 skipped.
@DavidM1911

Copy link
Copy Markdown
Contributor

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!

@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

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.

@CalvyPZ CalvyPZ added the duplicate This issue or pull request already exists label Nov 25, 2026
@CalvyPZ CalvyPZ closed this Nov 25, 2026
@CalvyPZ CalvyPZ reopened this Nov 25, 2026
@CalvyPZ CalvyPZ removed the duplicate This issue or pull request already exists label Nov 25, 2026
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…cl-dev#1753, Windows verbatim + Linux twin)

Windows hle/xgameruntime/mod.rs is the upstream hunk verbatim
(reference-only on Linux): AssociationCall gains token + Queued/
Running/Done state + condvar, ASSOCIATION_CALLS liveset tracks
in-flight callbacks; association_call skips canceled/non-queued
records, unregister marks queued ones Done and with wait=true joins
running ones. Upstream test ported verbatim.

Linux twin hle/xuser_linux.rs mirrors the same state machine on
xtaskqueue_linux (win64 ABI, submit_now bool path) with a
Linux-shaped twin test (manual queue + dispatch + token+1 pin).

Triage per keeper (land ONE, xcl-dev#1753 preferred): xcl-dev#1583 closes with
citation (its +2 is a comment on its own competing stopped/in_flight
registry, which stays out); xcl-dev#1418 stays out (Entry/manager +
running_threads + unknown-token-false + re-entrant self-skip is the
competing design; xcl-dev#1753 keeps the existing always-true unregister).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants