gameinput: queue only events a callback wants, so a later pad's connect is not stuck behind a backlog (RT-GAMEINPUT-LATE-PAD) #1559

Merged
kawaii-shakal merged 3 commits from upstream-pr/1559 into main 2026-11-28 17:58:20 +00:00
kawaii-shakal commented 2026-11-25 04:35:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kawaii-shakal on 2026-11-25T04:35:37Z.


Item: RT-GAMEINPUT-LATE-PAD (claimed in #2570).

What and why

On the retail boot (RTX 5070 Ti, DualSense), a pad connected after the title started was seen by the shim (connected DualSense Wireless Controller (..., player 2, ...), then 47 press lines), but the title did not react. A pad present at start worked, and so did one that dropped out and came back as the same device.

A pad present at start reaches the title through blocking enumeration, which runs synchronously inside RegisterDeviceCallback. A pad that connects later reaches it only through the connect event that open_pad queues for IGameInputDispatcher::Dispatch. queue_event queued every event, whether or not any callback wanted it, including the reading events the poll loop makes for a moving stick and a DualSense's 125 Hz sensor stream. A title that holds a dispatcher and runs one item a frame (Dispatch(0), as Microsoft's guidance suggests) falls further behind every frame, and the late pad's connect event never comes out.

  • runtime/shims/gameinput.cpp: queue_event drops an event that no registered callback matches. GameInput has no callback to run for it, so nothing should be queued.
  • Logging, to confirm the path on the next retail boot: the first 8 RegisterDeviceCallback calls (device or all, kind, status filter, enumeration mode), and the first CreateDispatcher and Dispatch calls (with the quota).
  • docs/gameinput.md: both, in "How it runs".

Not yet confirmed on the retail title. I have not booted this branch with a pad plugged in late. If that boot logs no CreateDispatcher, this backlog is not what kept the pad from the title, and the new RegisterDeviceCallback lines are where to look next. I checked the other candidates in the code and none of them explains it. Null-device reads aggregate over all pads. Status and kind filters treat a live connect the same as an enumeration event. The player slot only drives the LEDs. Offline, every device belongs to the one user.

Test

test_late_pad_behind_dispatcher in runtime/test/gameinput_test.cpp:

  • With no pad present, the "title" holds a dispatcher and registers a device callback with blocking enumeration.
  • One virtual pad moves its stick on every poll, with no reading callback registered.
  • After 50 frames of 4 polls and one Dispatch(0), a DualSense-like pad with sensors is attached.
  • Its connect must reach the callback within 10 frames, and its A press must read through the device that callback handed over.

Results:

  • Without the shim change: 371 checks, 2 fail (the late pad's connect and its A press).
  • With it: 371 checks, 0 fail.
  • ctest -C RelWithDebInfo -R gameinput: gameinput, gameinput_host and gameinput_script pass (Windows 11 Pro 26300, MSVC 19.50, SDL3 3.4.20). gta6rt builds.

#1528 (keyboard pad on by default) and #1510 touch the same files; either may need a trivial rebase after the other.

AI-assisted: yes (Claude Code, Claude Opus 5.5).

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5485246998 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1559). Originally posted by [kawaii-shakal](https://github.com/kawaii-shakal) on 2026-11-25T04:35:37Z. --- Item: RT-GAMEINPUT-LATE-PAD (claimed in #2570). ### What and why On the retail boot (RTX 5070 Ti, DualSense), a pad connected **after** the title started was seen by the shim (`connected DualSense Wireless Controller (..., player 2, ...)`, then 47 `press` lines), but the title did not react. A pad present at start worked, and so did one that dropped out and came back as the same device. A pad present at start reaches the title through blocking enumeration, which runs synchronously inside `RegisterDeviceCallback`. A pad that connects later reaches it only through the connect event that `open_pad` queues for `IGameInputDispatcher::Dispatch`. `queue_event` queued **every** event, whether or not any callback wanted it, including the reading events the poll loop makes for a moving stick and a DualSense's 125 Hz sensor stream. A title that holds a dispatcher and runs one item a frame (`Dispatch(0)`, as Microsoft's guidance suggests) falls further behind every frame, and the late pad's connect event never comes out. - `runtime/shims/gameinput.cpp`: `queue_event` drops an event that no registered callback matches. GameInput has no callback to run for it, so nothing should be queued. - Logging, to confirm the path on the next retail boot: the first 8 `RegisterDeviceCallback` calls (device or all, kind, status filter, enumeration mode), and the first `CreateDispatcher` and `Dispatch` calls (with the quota). - `docs/gameinput.md`: both, in "How it runs". **Not yet confirmed on the retail title.** I have not booted this branch with a pad plugged in late. If that boot logs no `CreateDispatcher`, this backlog is not what kept the pad from the title, and the new `RegisterDeviceCallback` lines are where to look next. I checked the other candidates in the code and none of them explains it. Null-device reads aggregate over all pads. Status and kind filters treat a live connect the same as an enumeration event. The player slot only drives the LEDs. Offline, every device belongs to the one user. ### Test `test_late_pad_behind_dispatcher` in `runtime/test/gameinput_test.cpp`: - With no pad present, the "title" holds a dispatcher and registers a device callback with blocking enumeration. - One virtual pad moves its stick on every poll, with no reading callback registered. - After 50 frames of 4 polls and one `Dispatch(0)`, a DualSense-like pad with sensors is attached. - Its connect must reach the callback within 10 frames, and its A press must read through the device that callback handed over. Results: - Without the shim change: 371 checks, 2 fail (the late pad's connect and its A press). - With it: 371 checks, 0 fail. - `ctest -C RelWithDebInfo -R gameinput`: `gameinput`, `gameinput_host` and `gameinput_script` pass (Windows 11 Pro 26300, MSVC 19.50, SDL3 3.4.20). `gta6rt` builds. #1528 (keyboard pad on by default) and #1510 touch the same files; either may need a trivial rebase after the other. AI-assisted: yes (Claude Code, Claude Opus 5.5). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
PierreEbele commented 2026-11-25 15:39:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T15:39:32Z.


Reviewed a05f1f3: read the shim and test on both trees; gameinput_test needs Windows+SDL+MSVC, so it was not run here. A model of matches()/queue_event/deliver_within(0) replaying test_late_pad_behind_dispatcher matches the commit message: on main the late pad's connect sits behind 150+ readings no callback asked for and its 2 checks fail; with the fix it reaches the callback in the first frame after attach and nothing stale is dispatched. All five queue_event call sites run under the state lock, dropped events keep the refcount balanced (push_reading lends its pointer), and the async- and blocking-enumeration paths are unaffected. Note the (documented) behaviour change: an event that arrives with no matching callback is dropped rather than replayed to a later-registered callback, which matches real GameInput, where registration's enumeration is what reports current state.

AI-assisted review.

Recommendation: Merge

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7167182006 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1559#issuecomment-7167182006). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T15:39:32Z. --- Reviewed a05f1f3: read the shim and test on both trees; gameinput_test needs Windows+SDL+MSVC, so it was not run here. A model of matches()/queue_event/deliver_within(0) replaying test_late_pad_behind_dispatcher matches the commit message: on main the late pad's connect sits behind 150+ readings no callback asked for and its 2 checks fail; with the fix it reaches the callback in the first frame after attach and nothing stale is dispatched. All five queue_event call sites run under the state lock, dropped events keep the refcount balanced (push_reading lends its pointer), and the async- and blocking-enumeration paths are unaffected. Note the (documented) behaviour change: an event that arrives with no matching callback is dropped rather than replayed to a later-registered callback, which matches real GameInput, where registration's enumeration is what reports current state. AI-assisted review. **Recommendation:** Merge
MoonEyes commented 2026-11-28 03:01:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T03:01:43Z.


Hi @kawaii-shakal, thanks for this pull request.

CONTRIBUTING.md asks contributors to claim their work in the coordination issue ("Coordinating who works on what", currently #1608) before opening a pull request: post claiming: <ID> there, or a one-line description if the item is not listed yet, and put the ID in the pull request. I could not find a claim from you for this one (the ID RT-GAMEINPUT-LATE-PAD appears in the pull request, but there is no claiming: line for it).

The claim matters because "it is claimed in the coordination issue by the pull request's author" is the first item on the maintainers' checklist for a mergeable pull request, and because it lets others see that the work is taken before they write it a second time.

Could you post the claim in #1608 and add the ID to the pull request description? If you already claimed it in another form, a link to your comment is enough.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7232746562 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1559#issuecomment-7232746562). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T03:01:43Z. --- Hi @kawaii-shakal, thanks for this pull request. CONTRIBUTING.md asks contributors to claim their work in the coordination issue ("Coordinating who works on what", currently #1608) before opening a pull request: post `claiming: <ID>` there, or a one-line description if the item is not listed yet, and put the ID in the pull request. I could not find a claim from you for this one (the ID `RT-GAMEINPUT-LATE-PAD` appears in the pull request, but there is no `claiming:` line for it). The claim matters because "it is claimed in the coordination issue by the pull request's author" is the first item on the maintainers' checklist for a mergeable pull request, and because it lets others see that the work is taken before they write it a second time. Could you post the claim in #1608 and add the ID to the pull request description? If you already claimed it in another form, a link to your comment is enough. AI-assisted (Claude Code, Claude Opus 5.5).
kawaii-shakal commented 2026-11-28 11:22:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kawaii-shakal on 2026-11-28T11:22:58Z.


Thanks, claimed now: https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7238480832 (the coordination thread moved on from #1608 to #2570 today). The ID is in the title and the first line of the description. The branch still merges cleanly into main 4a54aedc.


Generated by Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238513779 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1559#issuecomment-7238513779). Originally posted by [kawaii-shakal](https://github.com/kawaii-shakal) on 2026-11-28T11:22:58Z. --- Thanks, claimed now: https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7238480832 (the coordination thread moved on from #1608 to #2570 today). The ID is in the title and the first line of the description. The branch still merges cleanly into main 4a54aedc. --- _Generated by [Claude Code](https://claude.ai/code)_
MoonEyes commented 2026-11-28 17:58:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T17:58:17Z.


Red/green: On main gameinput_test fails 2 checks (a pad connected later is never seen by the callback and its A press is not read), and with the PR ctest -R "^gameinput(_script)?$" passes.
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7243428270 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1559#issuecomment-7243428270). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T17:58:17Z. --- Red/green: On main gameinput_test fails 2 checks (a pad connected later is never seen by the callback and its A press is not read), and with the PR ctest -R "^gameinput(_script)?$" passes. Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.
OreoFR commented 2026-11-28 21:52:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:52:25Z.


Verified by OreoFR

Run 1 (nat04)

  • Base: main c1ecf04ed + PR head 5fbcc642a
  • Test: ctest -R "^gameinput(_script)?$"
  • Red on main: gameinput fails (2 FAIL: a pad plugged in later is never seen by the callback, its A press not read)
  • Green with the PR: OK
  • Verdict: READY (shares files with #1831; merged during the test, at the tested head)

Run 2 (combo #1559 + #1095)

  • Base: main 3408969a7 + #1559 5fbcc642a + #1095 a3158989c (merged in that order, no conflict)
  • Test: ctest -R "^gameinput(_script)?$"
  • Red on main: n/a (compatibility check of the two PRs together)
  • Green with the PR: gameinput and gameinput_script OK; 381 checks, 0 failures, including #1559's late-pad checks and #1095's 7 current-token checks
  • Verdict: COMPATIBLE (both merged since, at the tested heads)

All runs

  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246335194 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1559#issuecomment-7246335194). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T21:52:25Z. --- **Verified by OreoFR** **Run 1 (nat04)** - Base: main `c1ecf04ed` + PR head `5fbcc642a` - Test: `ctest -R "^gameinput(_script)?$"` - Red on main: gameinput fails (2 FAIL: a pad plugged in later is never seen by the callback, its A press not read) - Green with the PR: OK - Verdict: READY (shares files with #1831; merged during the test, at the tested head) **Run 2 (combo #1559 + #1095)** - Base: main `3408969a7` + #1559 `5fbcc642a` + #1095 `a3158989c` (merged in that order, no conflict) - Test: `ctest -R "^gameinput(_script)?$"` - Red on main: n/a (compatibility check of the two PRs together) - Green with the PR: gameinput and gameinput_script OK; 381 checks, 0 failures, including #1559's late-pad checks and #1095's 7 current-token checks - Verdict: COMPATIBLE (both merged since, at the tested heads) **All runs** - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!1559
No description provided.