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

Open
github-bot wants to merge 2 commits from github-bot/gh-1559 into main AGit
Owner

@⁠kawaii-shakal on GitHub · 2026-11-25 04:35 UTC · original
kawaii-shakal:gameinput-hotplug → main · +94 −3 · 3 files · 2 commits · open

Claim: RT-GAMEINPUT-LATE-PAD. The coordination issue #14 no longer takes comments (over 2,500), so the claim is this PR itself.

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

**@⁠kawaii-shakal** on GitHub · 2026-11-25 04:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1559) `kawaii-shakal:gameinput-hotplug` → `main` · +94 −3 · 3 files · 2 commits · open Claim: RT-GAMEINPUT-LATE-PAD. The coordination issue #14 no longer takes comments (over 2,500), so the claim is this PR itself. ### 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)
A pad connected after the title started was seen by the shim but not by the
title, while pads present at start worked. Pads present at start reach a title
through blocking enumeration, which runs synchronously in RegisterDeviceCallback.
A later pad reaches it only through a queued connect event. queue_event queued
every reading and guide change whether or not any callback listened. With a
dispatcher held, a title that runs one item a frame (Dispatch(0), the pattern
Microsoft's Dispatch page suggests) falls further behind every frame, because a
moving stick or a sensor pad's 125 Hz stream queues items faster. The later
pad's connect event then never comes out of the queue.

queue_event now drops an event no registered callback matches, as GameInput has
no work to dispatch then. The first few RegisterDeviceCallback calls and the
first CreateDispatcher and Dispatch calls are logged, so a retail run shows
whether the title holds a dispatcher (not yet confirmed for the retail title).

Test: test_late_pad_behind_dispatcher. A title with a dispatcher registers its
device callback with no pad, a first pad moves on every poll, and a pad attached
later must reach the callback within ten frames of Dispatch(0). Without the fix
it fails (2 of 371 checks); with it, 371 checks pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:56:36 +00:00
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 15:39 UTC · original

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

**@⁠PierreEbele** on GitHub · 2026-11-25 15:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1559#issuecomment-7167182006) 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
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1559/head:github-bot/gh-1559'
git switch 'github-bot/gh-1559'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1559'
git switch 'github-bot/gh-1559'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1559'
git switch 'github-bot/gh-1559'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1559'
git switch 'main'
git merge --squash 'github-bot/gh-1559'
git switch 'main'
git merge --ff-only 'github-bot/gh-1559'
git switch 'main'
git merge 'github-bot/gh-1559'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.