HLE: serialize device callbacks across delivery threads #613
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!613
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/613/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Quat3rnion on GitHub · 2026-11-24 05:36 UTC · original
Quat3rnion:victory-input-serialization→main· +270 −45 · 1 files · 2 commits · closed without mergingWhat
The registration thread and the poll thread both called
deliverdirectly,so an initial enumeration callback and a hotplug notification could run at
the same time. GameInput guarantees callbacks arrive one at a time in order,
and titles rely on that when maintaining a device list. Events now go through
one queue in the hub's state with a single delivery loop; a callback that
enqueues more events joins the same loop instead of nesting. The existing
running-callback tracking still lets
UnregisterCallbackwait for a callbackthat is in flight.
An AI tool wrote part of this change.
Tested
cargo test --workspace: 165 passed, 0 failed, 3 ignored. A regression holds a blocking enumeration callback open on one thread while another thread connects a fake pad and polls, then checks peak simultaneous callbacks is one and that all notifications were delivered.cargo check --target x86_64-pc-windows-gnu --workspace --testspasses. No Windows host here.cargo xtask policypasses (150 files ok). No game files or data from them were added.Checklist
cargo xtask policypasses. No game files or data from them were added.@dpalacios69 on GitHub · 2026-11-24 10:46 UTC · original
Nice cleanup on serializing
Hub::deliver! One edge case to double-check forGameInputBlockingEnumeration:In
register_device_callback(gameinput.rs:781),hub.deliver(found)is called right before returningS_OK. With the new early return whenstate.deliveringis alreadytrue(gameinput.rs:416–445), if the poll thread (or another thread) is currently inside a callback,RegisterDeviceCallback(..., BlockingEnumeration, ...)appendsfoundtostate.queueand returnsS_OKbefore the initial enumeration callbacks have actually run.Per the public GameInput API contract,
GameInputBlockingEnumerationguarantees initial callbacks complete synchronously beforeRegisterDeviceCallbackreturns. (Waiting onself.returnedfrom a different thread would address that, though it would need care if an in-flight callback can ever synchronize with the registering thread to avoid a deadlock — and same-thread re-entrant registration must still return immediately.)Worth considering whether
BlockingEnumerationshould wait for its queued batch to drain (with a regression test coveringpoll()active during registration), or documenting the behavior if titles don't depend on it here.Static code review only; AI-assisted.
@geiyiliyabumo on GitHub · 2026-11-24 10:55 UTC · original
Independent verification & code review on Windows 11 Pro (build 26100, Rust
1.98.1), cleanly merged ontomain(ffe310e):cargo xtask policy: PASS (154 files ok)cargo clippy -p victory-hle --all-targets --locked -- -D warnings: PASScargo clippy -p victory-hle --all-targets --features diagnostics --locked -- -D warnings: PASScargo test -p victory-hle --locked: 95 passed + 1 integration test (no_dll_planting), 0 failed (including newcallbacks_from_registration_and_poll_are_serialized)Diff review notes (
crates/victory-hle/src/modules/gameinput.rs)BlockingEnumerationcontract race (register_device->deliver): Whenregister_deviceis called withBlockingEnumeration(2) from thread B while thread A (e.g.poll) is currently inside a callback (state.delivering == true),deliver(found)appendsfoundtostate.queueand returns immediately — soRegisterDeviceCallbackreturnsS_OKbefore its initial enumeration callbacks have actually run. Trackingdelivering: Option<ThreadId>(instead ofbool) would let a blocking registration from another thread wait onself.returneduntil its queued events drain, while still returning without deadlocking if called re-entrantly from the delivering thread.deliverlines 435–452): Poppingstate.queue.pop_front(), checkingstate.callbacks, and pushing(r.token, me)tostate.runningcan happen under a singleself.state()lock acquisition instead of unlocking and immediately relocking. (Alsoforgetcould optionally prunestate.queuealongsidestate.pending, thoughdeliveralready skips unregistered tokens safely.)AI-assisted; synthetic tests only, no game files.
@MichaelSmithAI on GitHub · 2026-11-24 11:10 UTC · original
We ran a focused test for the blocking-enumeration question above on exact head
2750ab1with Win64 under Wine. One thread held an existing callback open. A second thread calledRegisterDeviceCallbackthrough the GameInput vtable withGameInputBlockingEnumeration. It returnedS_OKwith zero initial callbacks completed. After the first callback was released, the initial callback ran once.This gives a regression assertion for the queue change: on the registering thread, read the completed-callback count immediately after the API returns and expect one. The existing serialization test checks the complementary requirement that callbacks do not overlap. GameInput registration contract
@Quat3rnion on GitHub · 2026-11-24 14:13 UTC · original
@mercuryVM Blocking enumeration now finishes on the registering thread before returning, even when a poll callback is active. Hotplug events for that registration wait until enumeration finishes. Both cases have regression tests, and
cargo test -p victory-hle --no-fail-fastpassed all 54 tests on Linux at7da55bef. Could you re-check?@ThomasHFWright on GitHub · 2026-11-24 15:08 UTC · original
Re-tested the revised callback implementation at
7da55befe68142103d81110c5eaab47a8f4d6b43under Wine, with this PR's complete diff applied to currentmainffe310eb2098e52169f4c44db5ffdabf43a72622in an isolated checkout.All 9 GameInput fake-host tests pass, including:
callbacks_from_registration_and_poll_are_serializedblocking_enumeration_finishes_on_registering_thread_while_poll_deliversblocking_enumeration_reports_devices_connected_during_its_callbackThis exercises the revised completion/thread and hotplug-ordering assertions, rather than the older revision discussed in the earlier Wine report.
Full workspace unit/integration comparison:
ffe310eAll 14 Windows test executables were built with
cargo test --workspace --all-features --locked --offline --target x86_64-pc-windows-msvc --no-runand run under Wine with--nocapture --test-threads=1. The HLE crate changes from 93 passed / 1 failed to 96 passed / 1 failed. No new failures appeared.The five shared failures are the existing Wine missing-Winsock-export test (
only_loopback_is_reachable), nested Cargo fixture build (loads_binds_and_calls_probe), empty pipeline library (a_rejected_blob_gives_an_empty_library, addressed separately by #347), shader-checksum rejection expectation (stub_pipeline_is_created), and Windows xtask's inability to run host Git (repository_passes_policy). Native Linuxcargo test -p xtaskseparately passes all four tests, asset policy passes, and Windows-target HLE Clippy with all targets/features and-D warningspasses.Environment: Rust 1.98.1, Wine 11.22, Linux, RTX 5090 / NVIDIA 620.73.04, vkd3d-proton
30b0eb9bc12dc9fwith app-local DXVK and natived3dcompiler_47for the GPU fixtures. Both full-suite configurations use the same runtime and compiler DLLs. Tests ran offline under Xvfb; the GameInput tests use fake devices.Limits: no physical-controller or gameplay test, native Windows/WARP run, or Wine doctests. Some existing tests return early when optional console compilers or the DXIL validator are absent; the aggregate does not establish coverage of those paths. No game files or generated game data were used or attached.
AI-assisted testing with Codex.
@Marvisak on GitHub · 2026-11-25 01:28 UTC · original
Automated triage for the maintainers.
Merge candidate.
Hub::deliver(crates/victory-hle/src/modules/gameinput.rs) is replaced by a queue inStatethat one thread drains (claim_delivery,drain,invoke). Callbacks frompolland from registration therefore no longer overlap.invokechecks the registration and marks it running under the same lock, soUnregisterCallbackstill waits for a callback that is running.The blocking-enumeration issue raised in review is fixed in
7da55bef. If another thread is already delivering,register_deviceruns that registration's initial callbacks on the calling thread, which avoids a deadlock. It holds back that registration's hotplug events inState::enumeratinguntil enumeration ends, soRegisterDeviceCallbackreturns only after its initial callbacks have run. The three new tests cover serialization, completion on the registering thread, and a hotplug during enumeration.Known trade-off: in that one inline case, the registering thread's enumeration callbacks can run at the same time as another registration's callback on the poll thread. Contention is the price of not blocking there.
Optional cleanup:
forgetcould also prunestate.queue. It isn't needed for correctness, becauseinvokeskips unregistered tokens.CI: passing.
Generated by Claude Code
@Marvisak on GitHub · 2026-11-25 21:59 UTC · original
Automated triage for the maintainers, second look (a review against current
main, with builds and tests where they could change the verdict).Closing because what the title needs from device callbacks is already in
main, and this adds risk on a path every boot runs. The title's two registrations are blocking, and the keyboard one is made under a lock that its own callback takes again, so the enumeration has to run on the registering thread, whichmaindoes. The races closed here need a pad to connect or disconnect in the microseconds between a registration's snapshot and its enumeration. Against that, the new delivery state still runs callbacks on two threads at once in the inline case, and the registering thread can end up draining other registrations' callbacks while it holds that lock. The publicRegisterDeviceCallbackpage does not promise one callback at a time across registrations either.If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.
Pull request closed