Skip to content

dinput8 proxy: answer wheel polls from a cached state (#121) - #157

Draft
mescon wants to merge 1 commit into
masterfrom
fix/dinput-state-cache
Draft

mescon wants to merge 1 commit into
masterfrom
fix/dinput-state-cache

Conversation

@mescon

@mescon mescon commented Nov 30, 2026

Copy link
Copy Markdown
Owner

Refs #121.

Wine's input thread keeps the DirectInput device lock for as long as reports are queued for the device (hid_joystick_read loops on ReadFile inside the lock). Poll and GetDeviceState take the same lock, so a game that polls the wheel from its physics thread stalls behind it. The reporter's capture shows Assetto Corsa EVO's physics thread waiting there in 13 of 40 samples.

The escape proxy now refreshes the state on its own thread once a millisecond and answers the game's Poll and GetDeviceState from the last successful copy.

  • Failures are never served from the copy.
  • Acquire, Unacquire, SetDataFormat, SetProperty and SetCooperativeLevel drop the copy, so the next read goes to the real device.
  • Logitech game controllers only.
  • LOGI_POLL_CACHE=0 switches it off.

Tested

Bench only (virtual wheel at 1 kHz with a 4 s flood of 64 kHz, a program polling 1000 times a second, Proton Experimental):

longest poll
cache off 5.9 s
cache on 0.13 ms

check-committed-dlls.sh --verify-bytes passes for the rebuilt DLL.

Not tested

Draft until it has run in Assetto Corsa EVO on a real wheel. Known limit: the first read after a format change or an acquire still goes to Wine.

Wine's input thread takes the DirectInput device lock and keeps it for
as long as reports are queued for the device: hid_joystick_read loops on
ReadFile inside the lock. Poll and GetDeviceState take the same lock, so
a game that polls the wheel from its physics thread stalls behind it. A
capture from the reporter of #121 shows Assetto Corsa EVO's physics
thread waiting there in 13 of 40 samples while the input thread sat in
ReadFile in 29.

The proxy now refreshes the state on a thread of its own, once a
millisecond, and answers the game's Poll and GetDeviceState from the
last successful copy. Failures and everything that changes what the
state means (Acquire, Unacquire, SetDataFormat, SetProperty,
SetCooperativeLevel) still go to the real device. Logitech game
controllers only. LOGI_POLL_CACHE=0 switches it off.

Bench, a virtual wheel at 1 kHz with a 4 s flood of 64 kHz and a
program polling 1000 times a second: the longest poll was 5.9 s without
the cache and 0.13 ms with it. Not yet tried in a game.
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant