fix(input): XInput is read on a thread of its own, so players with no controller no longer hitch every second #2124
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2124
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Longshot:fix/xinput-off-game-thread"
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?
Summary
Players report a better frame rate with a controller connected. On Windows, with no controller SDL reads, the game's
input read (
pads_readinhost/nn_hid.c) asked XInput for its pads itself, on the game's thread. Each second itasked all four empty slots again, all in the same read.
XInputGetStateon an empty slot is slow (it looks for thedevice again: a millisecond or more, longer with Bluetooth or a virtual pad's driver installed). Players on a keyboard
and mouse got a hitch every second. Plugging in a controller SDL reads turns the XInput path off, so the hitch went
away.
XInput is now read on a thread of its own (
xinput_main): every 2 ms while an XInput pad is there, every 100 ms whilenone is, nothing while SDL has the pads.
pads_readonly takes its last reading. The reading itself(
xinput_poll) is the old loop, moved unchanged. Linux is unaffected in practice: itsXInputGetStateis a stub.On
main: Windows, no controller plugged in, keyboard and mouse. The frame-time graph (or a Tracy capture) should showa spike on the game's thread once a second, in
pads_read. Plug in a pad and it goes.Read first:
xinput_poll,xinput_mainandxinput_readinhost/nn_hid.c, and the call inpads_read.Testing
Tested: not run in the game: the person I work for asked to open it with
--forceand leave the in-game testingto the Test Farm. This PC is Linux, where the bug does not happen. No checks were run on this PC either (left to CI).
Still to test:
record frame times on
mainand on this PR. Expecting the once-a-second spike onmainto be gone here(@Beanstalk windows)
HOS_NO_SDL=1): buttons, both sticks and the dead zone work, and the padis found when plugged in mid-game. Expecting the same as
main(@Beanstalk windows, or by hand)main(@Beanstalk linux)tests/test_xinput_thread.pyfails onmain(the game's thread asks XInput) and passes here, and the changedtest_pads_after_menu.pyandtest_stick_dead_zone.pystill passMeasurements
Verdict: not measured yet. The numbers need a Windows PC with no controller (Test Farm, above).
Setup: Windows, keyboard and mouse only; frame times over 60 s standing still,
mainagainst this PR.b62932a96a34b94a2Risks
HOS_XINPUT=1) is now up to 2 ms older than before: thethread's reading, then
pads_read's own 2 ms cache. That's the same as SDL's pads, which have their own thread too.Checklist
Ready for review
main; the title is a Conventional Commit.opened with
--forceon request; the Test Farm runs it)mise run testpasses (any failure that also fails onmainis named). (not run on this PC; waiting on CI)main, or Measurements says why there is nothing to measure. (needs Windows: Test Farm)third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here. (written as its own first commit; not run eitherway yet, CI will)
tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
@Beanstalk windows: with no controller plugged in (keyboard and mouse only), stand still in Kokiri Forest for 60 s and record frame times on main and on this PR. On main I expect a frame-time spike once a second; here it should be gone. Then, if the PC has an Xbox pad, set HOS_NO_SDL=1, plug the pad in mid-game, and check its buttons and both sticks work as they do on main.
Beanstalk test farm · ⛔ can't be tested as asked
Commit
a34b94a· approved by HumanBean (untrusted) · dashboardNot run: the farm can't test this as asked, so nothing is built or run:
⚠️ Note: The frame-time probe reports summary metrics, not the once-per-second spike pattern, so it cannot establish that the periodic hitch is gone.
What it could test instead: The alternative plan measures 60 seconds of stationary frame times in Kokiri Forest on Windows, comparing three starts each of main and the PR. It fails on a crash or a 15% regression in 99th-percentile frame time. The unattended farm cannot ensure that controllers are disconnected or perform the requested Xbox pad hot-plug test.
A member of
BigBeanscan comment@Beanstalk <new words>to ask for something else, or@Beanstalk test it anywayto run the plan regardless.WIP: fix(input): XInput is read on a thread of its own, so players with no controller no longer hitch every secondto fix(input): XInput is read on a thread of its own, so players with no controller no longer hitch every second