Skip to content

XGameRuntime: wake XAsyncGetStatus waiters before immediate completion callback - #1176

Open
b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:xgameruntime/xasync-notify-before-immediate-cb
Open

b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:xgameruntime/xasync-notify-before-immediate-cb

Conversation

@b3IKK

@b3IKK b3IKK commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

XAsyncComplete called s.cv.notify_all() after taskqueue::submit_now(). When the completion port uses MODE_IMMEDIATE, submit_now() runs the completion callback synchronously on the completing thread, so any callback that synchronises with a thread blocked in XAsyncGetStatus(b, true) deadlocked deterministically because waiters were never woken.

This moves s.cv.notify_all() directly after publishing completion and before submitting the completion callback.

What is in it

  • crates/xcl/src/hle/xgameruntime/xasync.rs: call s.cv.notify_all() before taskqueue::submit_now() in XAsyncComplete; add regression test complete_wakes_waiters_before_immediate_completion_callback (verified timing out before the fix and passing in ~20 ms after).

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 complete_wakes_waiters_before_immediate_completion_callback: 1 passed, 0 failed (timed out before the fix)

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: 978a5dedf432ecdf57d00497e884044a9c3f7dd2
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1638 (PresentX 1639)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14582 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 xasync.rs, wrote the fix and regression test, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.

…n callback

XAsyncComplete called s.cv.notify_all() after taskqueue::submit_now().
When the completion port uses MODE_IMMEDIATE, submit_now() runs the
completion callback synchronously on the completing thread, so any
callback that synchronises with a thread blocked in
XAsyncGetStatus(b, true) deadlocked deterministically because waiters
were never woken.

Notify the condvar as soon as completion is published and before
submitting the completion callback.

Assisted-by: OpenCode (Gemini 4 Neon)
@DavidM1911

Copy link
Copy Markdown
Contributor

Independent verification on current main 384f7f7 (branch already contains it — clean).

Machine: Windows 11, Ryzen 9 7900X; Rust stable MSVC, debug.

  • cargo test -p xcl --lib xasync: 16 passed, 0 failed — the waiter-wake ordering change keeps the XAsync suite green.

AI use: test runs by Devin (Cognition, SWE-2); no code changes.

@PedroNunes11

Copy link
Copy Markdown

Independent GTA VI long-run regression on the PR head. The XAsync regression test passes, but this change does not resolve the later world-loading stop tracked in #232 on this machine.

Build

Machine

  • NVIDIA RTX 4070 Ti SUPER 16 GB, driver 32.0.16.2124
  • Ryzen 7 9800X3D, 32 GB RAM
  • Windows 11 build 26200

Checks

  • cargo test -p xcl --lib complete_wakes_waiters_before_immediate_completion_callback -- --test-threads=1: 1 passed
  • 300 s GTA VI run, warm shader/pipeline cache, XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_UMA_MB=4095 XCL_COHERENT_MB=4095; XCL_PSO_WAIT_MS unset

Result

  • no skipped draws or dispatches before the stop
  • DirectStorage failures: 0; bcpack_refused: empty
  • presents dropped to 0 at 72 s, immediately after the dispatch count crossed 8,192
  • at 98.420 s: 0xc0000005 null write in game_scarlett_master.exe+0x23cf683, with the same title stack through +0x4e4ba89, +0x2215c35, +0x71b9a20, +0x2215eca
  • no device removal; peak commit 33,002 MB

So the waiter-wake ordering fix behaves correctly in its focused test, but the later GTA VI stop remains independently reproducible. This is intended as scope information, not evidence against the XAsync fix.

AI use: Codex applied the PR in an isolated worktree, ran the tests, extracted the counters from XCL's log/report, and drafted this comment; I observed the game run.

IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…ream xcl-dev#1201 + xcl-dev#1205 + xcl-dev#1188 + xcl-dev#1176, verbatim Windows + Linux twin)

Windows hle/xgameruntime/xasync.rs hunks are verbatim (reference-only,
cfg(windows)-only, 0 tests run on Linux): cherry-pick -n of the four
heads conflicted (1201/1205 append tests at the same site), so the four
hunks were applied by hand and every non-test hunk verified present.

Linux live path hle/xuser_linux.rs (win64 ABI, xtaskqueue_linux queues)
gets the twin port, no pc() legs exist there:
- xcl-dev#1201: XAsyncGetResultSize writes *size = 0 while pending and
  unconditionally on Finished (was: only when status >= 0).
- xcl-dev#1205: XAsyncGetResult writes *used = 0 on Invalid, pending-active,
  and failed-active arms before every early return.
- xcl-dev#1188: GetResult preserves non-zero success HRESULTs (zero-payload
  arms return h.status, payload arm returns status unless the provider
  failed).
- xcl-dev#1176: XAsyncComplete wakes GetStatus waiters (notify_all) before
  submitting the completion callback, so a MODE_IMMEDIATE callback that
  syncs with a waiter no longer deadlocks.

Failing-first: all four new twin tests FAILED pre-fix (sentinel
unchanged / S_OK instead of S_FALSE / 1 s waiter timeout), green post.
Twin tests drop ASYNC_TEST_LOCK (no such lock on the Linux twin) and
use a local begins_without_work helper, xtaskqueue_linux queue calls.
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.

3 participants