Skip to content

XGameRuntime: XTaskQueueIsEmpty counts delayed callbacks not yet due - #1681

Merged
Prime1997 merged 1 commit into
xcl-dev:mainfrom
emirduran707:taskqueue-is-empty-delayed
Nov 30, 2026
Merged

Prime1997 merged 1 commit into
xcl-dev:mainfrom
emirduran707:taskqueue-is-empty-delayed

Conversation

@emirduran707

Copy link
Copy Markdown
Contributor

XTaskQueueIsEmpty looked only at a port's queued items and the callbacks in flight. A callback submitted with a delay (XTaskQueueSubmitDelayedCallback, or XAsyncSchedule with a delay) waits in the task queue's timer heap until it is due, so while it waited the port read as empty. libHttpClient's task queue, which XTaskQueue is, counts those entries. TaskQueuePortImpl::IsEmpty is (m_queueList->empty()) && (m_pendingList->empty()) && (m_processingCallback == 0), and a delayed entry goes to m_pendingList (TaskQueue.cpp).

A title that dispatches until the port is empty before it terminates a queue, or that uses XTaskQueueIsEmpty to tell whether its timers are done, stopped too early. The delayed callback then ran canceled at termination.

XTaskQueueIsEmpty now also looks for the queue's entries on that port in the timer heap. The locks are taken in the order submit_delayed already uses: the timer heap, then the port's items, then the queue state. No path takes the timer lock while it holds the other two.

What is in it

  • crates/xcl/src/hle/xgameruntime/taskqueue.rs: XTaskQueueIsEmpty counts delayed callbacks not yet due. Test is_empty_counts_delayed_callbacks_not_yet_due: a 60 s delayed callback keeps the work port non-empty and leaves the completion port empty, and termination cancels it.

Tested

  • AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release
  • cargo test --workspace -- --test-threads=4 on c53eed3: 859 passed, 0 failed, 42 ignored; SKIPPED: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)
  • the new test without the change in XTaskQueueIsEmpty: it fails at assert!(!XTaskQueueIsEmpty(h, PORT_WORK), "a delayed callback not yet due is still queued")

Regression run

main:

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1321 (PresentX 1323)
presents per 2 s (last 3): 44 22 24
device removals: 0
crashes: 0
peak commit: 47832 MB

this PR:

xcl-smoke v1
commit: c53eed33ef1625568c739ca854e4eb34db8d1775
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1166 (PresentX 1166)
presents per 2 s (last 3): 1 0 23
device removals: 0
crashes: 0
peak commit: 49046 MB

Not tested

AI use

  • Claude Code with Claude Opus 5.5: found the problem, wrote the change, the test and this description; I reviewed the diff and ran the tests and smoke runs above.

🤖 Generated with Claude Code

A delayed callback waits in the timer heap until it is due, and
XTaskQueueIsEmpty looked only at the port's items and the callbacks in
flight, so the port read as empty meanwhile. libHttpClient's
TaskQueuePortImpl::IsEmpty counts its pending list, where delayed
entries wait. Look in the timer heap too, taking the locks in the order
submit_delayed uses (timer, items, state).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mantavisual

Copy link
Copy Markdown

Test report for c53eed33ef16 on NVIDIA, which the PR lists as not tested.

Tested

  • RTX 4060 8 GB (driver 616.92, wave32), i5-13600K, 32 GB, Windows 11 Pro 22631, Rust 1.100.0 MSVC, DXC 1.9.2602.17 (SDK 10.0.26100), debug.
  • cargo test --workspace --locked --no-fail-fast -- --test-threads=4: 859 passed, 0 failed, 42 ignored. The new test ran.
  • Merged locally with main 4178e88: 892 passed, 0 failed, 42 ignored.
  • SKIPPED at the head: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).

Does the test notice a broken fix?

  • Fix reverted: fails. The port of a delayed callback ignored: fails.
  • Gap: with Arc::ptr_eq(&t.queue, &q) removed, so that delayed callbacks of any queue count, all 11 taskqueue tests still pass. The timer heap is shared by all queues and the test makes one. Creating a second queue while the callback is pending and asserting XTaskQueueIsEmpty(other, PORT_WORK) passes normally and fails with that break.

Not tested: AMD, retail title, concurrent use.

AI use: Claude Code (Claude Opus 5.5) ran this on my machine, wrote the report and posted it for me.

@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, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

@MiharaxD

Copy link
Copy Markdown

Test report on an NVIDIA card, head c53eed3 (on main c160d86), which covers the "NVIDIA" line.

Tested

  • RTX 3070 Ti 8 GB (driver 621.01), Intel i5-14400F, 32 GB RAM, Windows 11 Pro 10.0.26300, Rust 1.100.0, DXC 1.9.2602.17.
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4 (debug) on c53eed3: 859 passed, 0 failed, 42 ignored (lib tests 810 / 0 / 22).
  • SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64).
  • is_empty_counts_delayed_callbacks_not_yet_due passes.

Regression run
scripts/smoke.ps1 -Game <game folder> -Seconds 60 (release builds, start screen, no input). main is c160d86:

main:

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: NVIDIA GeForce RTX 3070 Ti
title: game
seconds: 60
exit: 0x0
frames shown: 1586 (PresentX 1586)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15055 MB

this PR's head:

xcl-smoke v1
commit: c53eed33ef1625568c739ca854e4eb34db8d1775
gpu: NVIDIA GeForce RTX 3070 Ti
title: game
seconds: 60
exit: 0x0
frames shown: 1607 (PresentX 1607)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15583 MB

Not tested

  • A title that waits on XTaskQueueIsEmpty with delayed callbacks pending: the smoke run is a regression check only.
  • AMD / Intel, gameplay past the start screen.

AI use: Claude Code (Claude Opus 5.5) built the PR, ran the tests and both smoke runs, read the logs and wrote this report; I checked it before posting.

@JJAutoCompare

Copy link
Copy Markdown

XCL PR #1681 compatibility verification

Commit c53eed33ef1625568c739ca854e4eb34db8d1775 on STOR-WINLAB. Windows 11 Enterprise Evaluation build 26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 16 GiB with driver 32.0.101.9175. The adapter reports DoublePrecisionFloatShaderOps=0 and a wave range of 8–32. d3d12SDKLayers.dll is absent. DXC/DXIL 1.9.2609.5 and rustc 1.100.0 (0ef1bc386 2026-11-09), unoptimized builds with debug info disabled.

Tested

  • cargo build --workspace and cargo test --workspace --no-run succeeded. Both emitted two deprecation warnings for Atomic::fetch_update (duplicated in the test build).
  • cargo test -p xcl xgameruntime -- --nocapture under the Arc lock reported 75 passed, 0 failed, 0 ignored, 0 SKIPPED lines. All 74 unit tests ran. The libHttpClient integration test returned early because XCL_SAMPLE_DLLS was unset. The new regression passed here and in the workspace run. In a manual queue it verified that a not-yet-due callback makes the work port nonempty, leaves the completion port empty, and clears on termination.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 ran once under the Arc lock and exited 101. Across 20 harness summaries, pr1681-suite.log recorded 841 passed, 18 failed, 42 ignored and 3 SKIPPED lines. The harness totals include early returns. Two explicit skips cited no wave64 and one cited no heap windows. These skips provide no test coverage.

Of the 18 failures, 13 GPU tests reported CreateComputePipelineState returning 0x80070057. Four other GPU tests reported mismatches in fused multiply-add, implicit texture LOD, f16 lane preservation, and wave64 pixel reduction. The test-title e2e failed the D3D12.X dynamic depth-bias check (RSSetDepthBiasX), which produced a blue pixel where green was expected.

Not tested

Main-branch baseline, retail-title smoke runs, optional XCL_SAMPLE_* fixtures, and other GPU adapters.

AI use

T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1681-suite.log and published.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…#1681 + xcl-dev#1276)

Windows hle/xgameruntime/taskqueue.rs hunks verbatim (cfg(windows)-only,
0 tests run on Linux): xcl-dev#1681 timer-heap leg in XTaskQueueIsEmpty (lock
order timer -> items -> state) + test; xcl-dev#1276 inflight reserve under the
timer lock + dispatch_due_timed with canceled-execute fallback + test.
Fidelity: diff vs pr1681head/pr1276head shows only the other PR's hunks.

Linux live twin hle/xtaskqueue_linux.rs gets both semantics (win64 ABI)
+ 2 Linux-shaped tests. Failing-first shown in an isolated pre-fix
worktree (since removed): IsEmpty test FAILED at runtime, due-delayed
test failed to compile on missing dispatch_due_timed; both green post.

Gates: both cargo checks 0 errors; lib 650/0/1 t=4 (+2); diff --check
clean; title fresh-root FAIL set byte-identical pre/post (13: 12
D3D12.X GPU-only + files:delete os-error-2, the latter also failing on
pristine HEAD - pre-existing drift, no regress); retail fresh-root
SIGSEGV +0x2237320 fault 0x0 exit 139 stubs 20 xgr 3 apis - HOLDS.
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
, verbatim Windows + Linux twin)

Live pr805head=e88ee4d1 still OPEN (merge-base false); Windows
hle/xgameruntime/taskqueue.rs hunks hand-applied byte-identical
(cherry-pick -n conflicted at the shared test-site tail: steps-49/50
tests moved the append anchor; production + test hunks verified
identical to the head by direct diff, only line numbers drift).
Fidelity: git diff pr805head shows only steps-49/50 drift
(xcl-dev#1276/xcl-dev#1681 timer, xcl-dev#1154 terminate); pool block + mpsc test import +
new test byte-identical.

Production: fixed clamp(2,8) mpsc pool -> Pool{Mutex<PoolState>,Condvar,
base} + MAX_WORKERS=256 + IDLE_EXIT 30s + worker loop + spawn
wake-idle-else-grow with rollback + notify on spawn failure.
Linux live twin hle/xtaskqueue_linux.rs mirrors the production hunks
(ABI-neutral pool; win64 ABI untouched) + 1 Linux-shaped twin test
(16 blockers + releaser through wait=true Terminate, extern win64).

Failing-first: twin test FAILED pre-fix (7 vs 16, releaser starved on
the fixed 8-worker pool), green post-fix. Gates: both cargo checks 0
errors; lib 652/0/1 t=4 (+1); diff --check clean; lock audit clean
(named g/ng guards, explicit drop before job). Title fresh-root 12
unique FAILs all D3D12.X GPU-only 0 non-GPU (harness FAILs by design,
M2 baseline). Retail fresh-root SIGSEGV game_scarlett_master.exe
+0x2237320 fault 0x0 unmapped exit 139 stubs 20 xgr exactly
XAsync/XNetworking/XUser unimplemented [] - HOLDS, M1-RE TERMINAL.
@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: c53eed3

@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: e429936
head: c53eed3
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2127 passed, 9 failed, 48 ignored (26 SKIPPED lines). The 9 failures are main's own at e429936 on this GPU (reported with a bisect on #3041: they arrive with the merge of #2959); the set is identical with and without this PR. Base alone: 2126 passed, 9 failed, 48 ignored.
review: no blocking finding. Lock order is timer, then items, then state, and no path on main takes them the other way round. Minor: the timer thread drops the heap lock between popping an entry and submitting it, so IsEmpty can briefly say true in that gap (still better than main). Test gap from the thread: removing the queue-identity comparison still passes all tests.
performance: XTaskQueueIsEmpty now takes the process-wide timer lock and scans the delayed heap; small unless a title polls it hard with many timers (not measured).
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

@fromthemoonx

fromthemoonx commented Nov 30, 2026 •

Copy link
Copy Markdown

merge-check
base: 53e85fb
head: c53eed3
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2793 passed, 1 failed, 49 ignored; SKIPPED: 29 (mostly "no wave64"); failing: hle::d3d12x::standin::tests::concurrent_shell_miss_reuses_winner_and_releases_loser_pipeline, which fails on the base 53e85fb alone too (#2369's test against main's late_release, see #2369), not this PR
review: none blocking, after reading the whole diff (xgameruntime/taskqueue.rs). Lock order: XTaskQueueIsEmpty now takes timer, then items, then state. The other timer-lock sites fit that order: submit_delayed takes timer then state (is_terminated), the timer thread drops the heap lock before submit_now, and XTaskQueueTerminate releases the timer lock before taking state. No path takes timer while holding items or state. is_empty_counts_delayed_callbacks_not_yet_due passes 30/30 alone and hle::xgameruntime::taskqueue:: (11 tests) 30/30 at --test-threads=8. With the new delayed condition disabled (scratch), the test fails ("a delayed callback not yet due is still queued").
performance: one more mutex (the shared timer heap) and a scan of the pending delayed callbacks per XTaskQueueIsEmpty; nothing per frame unless a title polls it. Reasoned, not measured.
verdict: safe to merge
hardware / tool and model: RTX 3060 12 GB (driver 610.88), Ryzen 7 5700X, Windows 11 Pro 26300, Rust 1.100.0 MSVC, debug / Claude Code (Claude Opus 5.5)

@github-actions github-actions Bot added area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) labels Nov 30, 2026
@Prime1997
Prime1997 merged commit 75093ad into xcl-dev:main Nov 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH ready-to-merge Has 2 independent safe merge-checks on current head (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants