Skip to content

GameInput: touch device, readings and host bridge (RT-167) - #2939

Open
Vyral1978 wants to merge 4 commits into
ItsNotRexed:mainfrom
Vyral1978:rt-167-gameinput-touch
Open

Vyral1978 wants to merge 4 commits into
ItsNotRexed:mainfrom
Vyral1978:rt-167-gameinput-touch

Conversation

@Vyral1978

@Vyral1978 Vyral1978 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-167 (#2516 (comment))

Depends on: #2413 (reuses its non-pad device list and kind-filtered reading path). Because #2413 conflicts with main since #3172 (RT-175, raw HID) and #2751 landed, this branch carries #2413's two commits replayed onto main 3faac557 (as b7314cb4 and d711b962), followed by the two RT-167 commits. When #2413 is rebased or merged, this PR is restacked on it.

What and why

IGameInputReading::GetTouchCount and GetTouchState returned 0, so a title that queries touch input through GameInput on touchscreen PCs and handhelds received nothing. As noted in #2300 / #2516, SDL3's touch subsystem is initialized inside SDL_INIT_VIDEO (which must run on the main thread with an SDL-managed window and is built with SDL_VIDEO=OFF here).

This adds the GameInput touch device, its readings, and a thread-safe host-window bridge behind LEONIDA_TOUCH (off by default, like LEONIDA_KEYBOARD_PAD and LEONIDA_KEYBOARD_MOUSE):

  • ABI (runtime/shims/gameinput_abi.h): GameInputTouchState (48 bytes), GameInputTouchSensorInfo (64 bytes), and GameInputTouchShape / GameInputLabel / GameInputLocation, checked side by side against the v0 header of Microsoft.GameInput 0.2303.22621.3038 and pinned with static_asserts.
  • Device (runtime/shims/gameinput.cpp): Touch (Leonida) behind LEONIDA_TOUCH=1|focus|always|off, with supportedInput = GameInputKindTouch, touchPointCount = 10, touchSensorCount = 1 and touchSensorInfo, kept out of the gamepad list (connected_count() is unchanged). Enumeration, GetCurrentReading / GetNextReading / GetPreviousReading, CreateAggregateDevice(GameInputKindTouch, ...), FindDeviceFromId and reading callbacks cover it.
  • Readings: carry GameInputKindTouch only (GetTouchCount / GetTouchState in ascending touchId order, up to 10 contacts); pad, keyboard and mouse getters return nothing on a touch reading, and gamepad queries never return touch readings.
  • Host bridge & test seam (runtime/shims/gameinput.h): rt::gameinput::touch_contact(id, x, y, pressure, down) (and clear_touch_contacts()) can be called from any thread (e.g. a host window's WndProc on WM_POINTER*), clamping coordinates and pressure to 0..1, plus rt::gameinput::set_touch_source for synthetic tests, under the keyboard pad's focus rule.
  • Docs (docs/gameinput.md): adds the "Touch device" section, the LEONIDA_TOUCH row in the environment table, and updates the IGameInputReading API table.

Tested

AI-assisted (Claude Code). Re-run after rebasing on #2413's current head.

Windows 11 (26300), MSVC 19.51, SDL3 3.4.20 (-DLEONIDA_SDL3_FETCH=ON), Ninja RelWithDebInfo, NVIDIA GeForce RTX 3070:

  • ABI offset check: compiled side by side against Microsoft.GameInput 0.2303.22621.3038 GameInput.h with cl /std:c++20 to verify sizeof and every member's offsetof for GameInputTouchState and GameInputTouchSensorInfo.
  • gameinput_test: 262 checks, 0 failures (26 new touch checks covering: off by default, LEONIDA_TOUCH=1 focused mode, device info and touchSensorInfo, FindDeviceFromId, initial zero-contact reading, pad/keyboard/mouse isolation, multi-contact ordering by ascending touchId, coordinate/pressure clamping to 0..1, GetTouchState capacity and null output, contact movement and removal, GetPreviousReading history walk, 10-contact maxTouchPoints cap, focus loss vs LEONIDA_TOUCH=always, set_touch_source seam, CreateAggregateDevice(GameInputKindTouch, ...), non-finite coordinates and pressure, and disconnecting on LEONIDA_TOUCH=off).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (N/A: runtime only.)

🤖 Generated with Claude Code

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested f959626 merged onto main 1628210 on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:

  • Full ctest: 130/130.
  • gameinput: passes 20 of 20 runs, and passes under LEONIDA_VK_VALIDATION=1 with 0 validation messages.
  • Warnings: none new in the files this PR changes.

AI-assisted (Claude Code).

@steamaze0

Copy link
Copy Markdown

Tested f959626 on NVIDIA RTX 5060 Ti (Blackwell), NVIDIA 621.01 (Vulkan 1.4.357), Windows 11 (26300), VS Build Tools 2022 (MSVC) + Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, SDL3 (-DLEONIDA_SDL3_FETCH=ON): pass.

  • gameinput: PASS (it was disabled without SDL3). The new touch subtests pass: off-by-default / no touch reading, LEONIDA_TOUCH=1 focused mode, not counted as a gamepad, zero-contact initial reading, no pad/keyboard/mouse state on a touch reading, device info (10 touch points / 1 sensor), display name, FindDeviceFromId, two contacts held, ascending touchId order, clamped pressure and contact rect. Touch (Leonida) connects/disconnects cleanly.
  • ctest --output-on-failure -j4: 122 passed, 0 failed (game-data/optional skipped) — gameinput now runs.

AI-assisted (Qoder): I built the full runtime with MSVC + SDL3 and ran ctest.

@Vyral1978
Vyral1978 force-pushed the rt-167-gameinput-touch branch from f959626 to 9084a0e Compare November 22, 2026 20:38
@Vyral1978

Copy link
Copy Markdown
Contributor Author

Rebased onto #2413's current head 09e77438, which is on main 16282101. The PR is still the same two RT-167 commits, now 67f06cb3 and 9084a0e8.

Conflicts with what landed since (RT-160 haptics, RT-176 dispatcher quota):

  • gameinput.cpp: kept RT-160's set_haptic_source next to the touch functions.
  • docs/gameinput.md: the IGameInputReading row gets touch, and the IGameInputDevice row is RT-160's (force feedback and haptics).
  • gameinput_abi.h merged without a textual conflict, but GameInputLocation ended up defined twice: RT-160 added the full enum, and this PR had a subset with the same values. I removed this PR's copy, so the touch code uses RT-160's.

Tested on Windows 11, RTX 3070 (NVIDIA 32.0.16.1088), MSVC (VS 18), SDL3 3.4.20 (LEONIDA_SDL3_FETCH from a local copy):

  • gameinput: 10/10 in a row.
  • Full ctest: 133/133.

The earlier GPU reports (@JRamos1993, @steamaze0) were on f9596268, before this rebase.

AI-assisted (Claude Code).

@mesterember104-cpu

Copy link
Copy Markdown

Tested f959626 on Tiger Lake (Xe-LP) iGPU 0x9a78, driver 32.0.101.7088, Windows 11, MSVC 14.44: pass

Built with -DLEONIDA_SDL3_FETCH=ON (the author's config), full ctest -C RelWithDebInfo: 111/113 pass, 5 skips (shader_library_corpus, vk_sync_validation, d3d12_queue_wait, d3d12_rgb9e5_rtv, d3d12_first_light). The 2 failures are the known Intel-main pair (d3d12_buffer_tiles, d3d12_descriptor) — they fail the same way on main, untouched by this PR.

gameinput_test run separately with LEONIDA_TOUCH=1: 262 checks, 0 failures — matches the author's count, including the 26 new touch checks (device enumeration behind LEONIDA_TOUCH, ascending touchId ordering, coordinate/pressure clamping, non-finite handling: NaN positions dropped, NaN pressure read as 0, set_touch_source seam, CreateAggregateDevice(GameInputKindTouch)).

First-time game-gated data on this machine (package DLLs, no game data quoted): bink_decode PASS (512x512, 90 frames decoded via the package Bink2Scarlett.dll), bink_audio PASS, pe_loader PASS, pe_loader_bounds PASS.

AI-assisted (GLM, operated by the account owner).

@kotorvr

kotorvr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 9084a0e, the rebased head (the earlier checks here are of f959626), on Windows 11 Home 26200, MSVC 19.44 (VS 2022), Ninja, RelWithDebInfo, SDL 3.4.20 through main's own -DLEONIDA_SDL3_FETCH=ON (the PR does not touch the fetch or any CMake file); the machine has an RTX 4090 on 621.14, which this test does not use: pass.

The branch as it is now: #2413's two keyboard/mouse commits plus the two RT-167 commits, on main f847748.

main f847748 9084a0e
gameinput_test.exe 276 checks, 0 failures 327 checks, 0 failures
ctest -R "^gameinput$" --repeat until-fail:20 passed (5 runs) 20/20
ctest -R "gameinput|xgameruntime|loader|unimplemented_policy|run_" 18 of 19: loader_tls failed once

The loader_tls failure is not this PR: it passed 60 of 60 when I repeated it in this tree, and on plain main f847748 the same test fails the same way about once in 100 runs while other suites run on the machine ("gta6rt_tls_host.dll is missing or has no module TLS index"). I posted it as a finding in the coordination issue. This PR changes only the GameInput shim, its test and the doc.

No compiler warnings from the gameinput files. Not run: a real touch screen or LEONIDA_TOUCH on real hardware (the test's own subtests cover the modes). No game files. AI-assisted check (Claude Code).

@Rossrocha

Copy link
Copy Markdown

Tested on AMD Radeon RX 6600 (RDNA2, gfx1032), Windows 11, Adrenalin 26.11.2 (Vulkan driver 32.0.21045.29003).

PR head 9084a0e8 merged onto main f847748c, fresh MSVC build:

  • ctest: 140/140 passed, and 140/140 with LEONIDA_VK_VALIDATION=1
  • run_gpu_tests.py: 184/199 passed, 15 skipped (expected), native and with LEONIDA_W64_EMULATE=1

No regressions on this hardware. (The PR now conflicts with main, so this is the pre-conflict state.)

TheHoracio and others added 4 commits November 23, 2026 09:14
IGameInputReading returned nothing for keyboard and mouse, so a title that
reads them through GameInput got no input on PC. With
LEONIDA_KEYBOARD_MOUSE=1|always the shim connects a keyboard device and a
mouse device next to the pads. Their readings carry GameInputKindKeyboard or
GameInputKindMouse only: GetKeyCount/GetKeyState list the held keys (virtual
key, scan code, character, dead-key flag; up to 16), GetMouseState the
buttons and the cursor's movement summed into relative positions. Keys and
buttons come from GetAsyncKeyState with the keyboard pad's focus rule.

They stay out of the pad list (no SDL, rumble, battery or player slot), and
every reading search, enumeration, aggregate and FindDeviceFromId covers
them; a search with no device now filters by kind, so a gamepad query never
answers with a keyboard reading. The v0 structs are declared in
gameinput_abi.h with static_asserts on their layout.

gameinput_test: 21 checks with fake keys, focus and cursor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, non-null nativeLanguage, full key compare

From Kam471's review of ItsNotRexed#2413 and @justr4mzi's ItsNotRexed#2426:
- keyboardInfo.layout is the active KLID (GetKeyboardLayoutNameW), keyCount the reportable virtual keys with a
  scan code, functionKeyCount GetKeyboardType(2) (12 if Windows doesn't say).
- keyboardInfo.nativeLanguage points at an empty GameInputString instead of null, so a title reading it does not
  dereference null.
- mouseInfo.sampleRate is 500: one sample per 2 ms poll_thread() pass.
- A held key whose scan code, character or dead-key flag changes (a layout switch) is a new reading: same_keys
  compares every field, not only virtualKey.

gameinput_test: 226 checks, 0 failures (4 new).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GetTouchCount and GetTouchState returned 0. SDL3's touch subsystem lives
inside SDL_INIT_VIDEO (off in this build, and tied to the main thread and
an SDL window), so with LEONIDA_TOUCH=1|always the shim connects a
"Touch (Leonida)" device fed by rt::gameinput::touch_contact(), a
thread-safe bridge a host window's WndProc can call on WM_POINTER*, or by
set_touch_source() in tests.

Its readings carry GameInputKindTouch only: up to 10 contacts in ascending
touchId order, coordinates and pressure clamped to 0..1. It follows the
keyboard pad's focus rule, stays out of the pad list and is covered by
enumeration, reading searches, CreateAggregateDevice, FindDeviceFromId and
reading callbacks. GameInputTouchState and GameInputTouchSensorInfo are
declared in gameinput_abi.h with static_asserts on their v0 layout.

gameinput_test: 24 touch checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
std::clamp passes NaN through, so a host bridge that sent a NaN coordinate
or pressure would have handed it to the title. touch_contact() now leaves
the contact table unchanged for a non-finite position and reads a
non-finite pressure as 0.

gameinput_test: 2 more checks, 262 in all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Vyral1978
Vyral1978 force-pushed the rt-167-gameinput-touch branch from 9084a0e to 5bcb104 Compare November 23, 2026 08:23
@Vyral1978

Copy link
Copy Markdown
Contributor Author

Restacked on main 3faac557. #2413 conflicts with main since #3172 (RT-175, raw HID) and #2751 landed, so this branch now carries #2413's two commits replayed onto main (b7314cb4, d711b962), then the two RT-167 commits (a893fba2, 5bcb1042).

@TheHoracio, I had to resolve the RT-159 commit against RT-175 here. Feel free to reuse the resolution when you rebase #2413, or tell me if you'd do it differently. Once #2413 is rebased or merged, I'll restack this PR on it.

The RT-159 conflicts were all cumulative (both sides add something):

  • kSupportedKinds keeps RT-175's GameInputKindRawDeviceReport. kReadableKinds adds keyboard and mouse to it, and touch in the RT-167 commit.
  • Reading::GetInputKind returns the keyboard/mouse kind first, then the pad's kinds as RT-175 computes them (motion and raw report only when present).
  • GetRawReport is RT-175's out-of-line version. A keyboard or mouse reading has has_raw == false, so it returns false as before. GetControllerAxisCount stays 0 for keyboard and mouse.
  • gameinput.h: RT-175's HID declarations and RT-167's touch functions, side by side.
  • docs/gameinput.md: RT-175's IGameInputReading row gets keys/mouse and touch. The older duplicate rows already on main are left as they are.

Tested on Windows 11, RTX 3070 (NVIDIA 32.0.16.1088), MSVC (VS 18) + Ninja, SDL3 3.4.20:

  • gameinput: 10/10 in a row.
  • Full ctest: 170/170.

AI-assisted (Claude Code).

@milas6669

Copy link
Copy Markdown

Tested 5bcb1042 (the 08:23 restack on main 3faac557) on Windows 11, MSVC 19.44 + Ninja, RelWithDebInfo, NVIDIA GeForce RTX 3070 present but not used (these are CPU tests), Python 3.14: pass. Every earlier check on this PR is on the previous head 9084a0e8, so this is the first on the restacked branch.

Not run: a negative control (the production change is +458 lines in gameinput.cpp, so I did not revert it), the rest of CTest, a real touch device or controller, and Linux/Wine. I did not read the PR's design choices; this is a build-and-run check.

AI-assisted. Synthetic virtual devices only; no game data.

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.

8 participants