Repository navigation
HLE: serialize device callbacks across delivery threads - #613
Quat3rnion wants to merge 2 commits into
Conversation
LAKSHYA-cmd-tech
left a comment
There was a problem hiding this comment.
Tested on native Windows 11 with Rust 1.98.1 (x86_64-pc-windows-msvc).
- cargo test -p victory-hle: all 82 tests in �ictory_hle and
o_dll_planting passed cleanly. - callbacks_from_registration_and_poll_are_serialized successfully verified that concurrent enumeration and poll threads serialize device callback delivery with a peak of 1.
- cargo xtask policy: 150 files ok.
b275dfa to
2750ab1
Compare
|
Nice cleanup on serializing In Per the public GameInput API contract, Worth considering whether Static code review only; AI-assisted. |
|
Independent verification & code review on Windows 11 Pro (build 26100, Rust
Diff review notes (
|
|
We ran a focused test for the blocking-enumeration question above on exact head 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 |
mercuryVM
left a comment
There was a problem hiding this comment.
Tested 2750ab1 on Windows 11, RTX 5070, MSVC: cargo test -p victory-hle 88 passed, including callbacks_from_registration_and_poll_are_serialized.
The single queue does serialize callbacks, but it breaks blocking enumeration in the other ordering:
gameinput.rs(register_device, thenHub::deliver): when a blocking-enumerationRegisterDeviceCallbackarrives while the poll thread is already insidedeliver(delivering == true), the registration'sfoundevents are appended toqueueanddeliverreturns at once.register_devicethen returnsS_OKbefore any of its enumeration callbacks have run, and they run later on the poll thread. The doc comment aboveregister_devicepromises they run "blocking on the caller's thread before we return". GameInput's blocking enumeration means the title's device list is complete when the call returns, and the title holds the lock its callback needs, so it can't observe the late callbacks until it releases that lock. The new test only covers registration-first-then-poll, not poll-first-then-register.- Possible fix: don't make the registration visible to the poll thread until its own enumeration is done. Deliver
foundsynchronously on the caller's thread, then push the registration intostate.callbacksand queue any hotplug events that arrived meanwhile. That keeps one-at-a-time delivery per callback and keeps the blocking guarantee. Waiting on a condvar for the queue to drain would deadlock in exactly the lock-holding case the comment describes.
AI-assisted (Claude Code).
Registration and poll threads both called deliver directly, so an initial enumeration callback and a hotplug could run at the same time; GameInput guarantees one callback at a time in order. Events now go through one queue in Hub state, with a single thread draining it; callbacks that enqueue more events join the same loop instead of nesting. Add a regression that holds a registration callback open while another thread polls and checks peak concurrency is one.
Run blocking enumeration on the caller when another delivery is active. Hold hotplug events for that registration until enumeration ends, and track inline callbacks for unregistration.
2750ab1 to
7da55be
Compare
|
@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 |
mercuryVM
left a comment
There was a problem hiding this comment.
Re-tested 7da55be on Windows 11, RTX 5070, MSVC: cargo test -p victory-hle 98 passed, including the new regression, where a blocking enumeration callback is held open on one thread while another connects a fake pad and polls. cargo clippy -p victory-hle --all-targets is clean.
This addresses my earlier review:
- When a blocking registration arrives while another thread is delivering, its own enumeration events run inline on the caller's thread, and the registration sits in
enumerating, invisible to the poll thread, until they're done. SoRegisterDeviceCallbackreturns only after its enumeration ran. - Hotplug events that arrive in the meantime are held in the
Enumeration'shotpluglist and queued afterwards, keeping order per callback. - When no one is delivering, the caller claims delivery and drains synchronously, which also satisfies the blocking contract.
AI-assisted (Claude Code).
…s delivery threads Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Re-tested the revised callback implementation at All 9 GameInput fake-host tests pass, including:
This 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:
All 14 Windows test executables were built with The five shared failures are the existing Wine missing-Winsock-export test ( Environment: Rust 1.98.1, Wine 11.22, Linux, RTX 5090 / NVIDIA 620.73.04, vkd3d-proton 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. |
|
Automated triage for the maintainers. Merge candidate.
The blocking-enumeration issue raised in review is fixed in 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: CI: passing. Generated by Claude Code |
Upstream: Marvisak#613 by @Quat3rnion (cherry picked from commit 35ecf4d)
|
Automated triage for the maintainers, second look (a review against current Closing because what the title needs from device callbacks is already in If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution. |
What
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.