Skip to content

gameinput: raw HID reports and raw device I/O through SDL's hidapi (RT-175) - #3172

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
boraswim:rt-175-raw-hid
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
boraswim:rt-175-raw-hid

Conversation

@boraswim

@boraswim boraswim commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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

Depends on: #2939, #2751 (conflicts only). Both edit runtime/shims/gameinput.cpp and/or docs/gameinput.md near the same places. Whichever merges second needs a small merge.

What and why

GameInput's raw HID calls returned nothing or E_NOTIMPL, so a title that talks to a pad through raw reports got nothing. This PR backs them with SDL3's hidapi (SDL_hid_*).

  • Opening the device.
    • Each pad's HID device is opened by the device path SDL reports for it. When that path isn't a HID path, the shim falls back to the pad's vendor and product id, but only when exactly one game-pad collection (usage page 1, usage 5) has them, so twins never mix.
    • The shim reads the report descriptor. A small parser, rt::gameinput::parse_report_descriptor, gives every input, output and feature report's id and payload size. It handles Report ID/Size/Count, Push/Pop and long items, and refuses malformed descriptors.
  • A pad opened this way:
    • reports GameInputKindRawDeviceReport in supportedInput and GameInputDeviceRawIoEnabled in its status;
    • fills inputReportInfo, outputReportInfo and featureReportInfo with their counts, with itemCount 0 (items are not decoded).
  • Readings carry the newest raw input report. Each poll drains what arrived, and a changed report makes a reading of its own. IGameInputReading::GetRawReport returns it as an IGameInputRawDeviceReport.
  • Device calls:
    • CreateRawDeviceReport, GetRawDeviceFeature, SetRawDeviceFeature and SendRawDeviceOutput work through the backend, with the id byte in front as hidapi expects.
    • An undeclared id or kind is E_INVALIDARG, and a failed transfer is E_FAIL.
    • A pad without a HID device keeps the old answers: E_NOTIMPL, and no raw kind.
  • Not done (documented): the per-item calls (Get/Set/ResetItemValue, ResetAllItems answer false), SendRawDeviceOutputWithResponse, ExecuteRawDeviceIoControl and exclusive access.
  • ABI (gameinput_abi.h, Leonida's own declarations): IGameInputRawDeviceReport (IID 61F08CF1-…), GameInputRawDeviceReportKind, GameInputRawDeviceReportInfo, GameInputRawDeviceReportItemInfo and GameInputRawDeviceItemCollectionInfo, with static_asserts. Following docs/gameinput.md's ABI section, they were compiled next to Microsoft's public v0 header (NuGet Microsoft.GameInput 0.2303.22621.3038, not added to the repository). The check compares offsetof for all 38 fields, sizes and enum values, calls all 12 vtable slots through Microsoft's interface, and checks the IID. Everything matches.
  • Xbox pads on Windows are read by SDL through XInput (path XInput#n). SDL's hidapi skips their XInput HID interface (&IG_; SDL's comment says those carry no full HID reports), so they get no raw I/O. The log now says why.
  • Seam: rt::gameinput::set_hid_backend, for tests.

Tested

  • Windows 11, MSVC 2022, SDK 10.0.26100, scripts/build_runtime.ps1 -FetchSdl3 (SDL 3.4.20). ctest -R gameinput passes: gameinput_test runs 300 checks with 0 failures, 24 of them new. After merging main with RT-160's force feedback and haptics, both test sets run (the raw HID fakes are renamed so they don't clash).
    • Descriptor parser: report ids, none, Push/Pop with a long item, and the refused forms.
    • A fake HID backend behind a virtual pad (pid.codes test ids). It checks the report tables, the kind and status bits, raw reports in readings (an undeclared id is ignored), creating, sending and reading back output and feature reports with their id byte, SetRawData's exact size, the item calls, E_INVALIDARG, E_FAIL and E_NOTIMPL, and the device closing on unplug.
  • Live, Xbox Series X controller over Bluetooth: it connects and plays as before, with no raw I/O, logged as "an XInput pad". I don't have a DualSense, DualShock 4 or Switch Pro, so the working raw path has only run against the fake backend. A check from someone with one of those would help: run gameinput_probe --seconds 15 and press buttons. It should print the descriptor's reports and changing raw bytes.
  • Full Python suite, as CI runs it: 227 stdlib files pass except tests/test_report_paths.py, which fails the same way on main on Windows (unrelated). The pytest files: 1,463 passed, 15 skipped.

AI-assisted.

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. (Not applicable: no translator change.)

…T-175)

The shim opens each pad's HID device with SDL_hid_* (by SDL's device path, else the one game-pad collection with the
pad's vendor and product id) and reads its report descriptor for every input, output and feature report's id and
size. Such a pad reports GameInputKindRawDeviceReport and GameInputDeviceRawIoEnabled and fills inputReportInfo,
outputReportInfo and featureReportInfo (no item tables). Readings carry the newest raw input report, and
IGameInputReading::GetRawReport returns it as an IGameInputRawDeviceReport. CreateRawDeviceReport,
GetRawDeviceFeature, SetRawDeviceFeature and SendRawDeviceOutput work through the backend; an undeclared id or kind
is E_INVALIDARG, a failed transfer E_FAIL, and a pad without a HID device keeps E_NOTIMPL.

gameinput_abi.h declares IGameInputRawDeviceReport, GameInputRawDeviceReportKind and the three raw report info
structs, checked against Microsoft's v0 header (offsetof for every field, the 12 vtable slots, the IID). Xbox pads on
Windows go through XInput, whose HID interface SDL's hidapi skips, so they have no raw I/O; the log says so.

gameinput_test covers the descriptor parser and the whole path with a fake HID backend (24 checks);
gameinput_probe prints each pad's report tables and newest raw input report. docs/gameinput.md: "Raw HID".
Keep RT-160's force-feedback interface and tests next to the raw HID ones.
The raw HID test fakes are renamed (FakeRawHid, raw_*) so they no longer clash
with the haptic fakes. The API table gets one IGameInputDevice row with both
feature sets; the stale duplicate IGameInputDevice and IGameInputDispatcher
rows are dropped.
@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 364fdcb 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).

@kotorvr

kotorvr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 76d1add (the head after the merge of main) 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.

main f847748 76d1add
gameinput_test.exe 276 checks, 0 failures 300 checks, 0 failures
ctest -R "^gameinput$" --repeat until-fail:20 passed (5 runs) 20/20
ctest -R "gameinput|xgameruntime|loader|unimplemented_policy|run_" 19/19

No compiler warnings from the gameinput files. The raw-HID checks run against the test's fake backend, so nothing was sent to a real device, and I did not run gameinput_probe (no controller attached). No game files. AI-assisted check (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit c77e940 into ItsNotRexed:main Nov 22, 2026
2 of 4 checks passed
dev-ewann pushed a commit to dev-ewann/Leonida that referenced this pull request Nov 22, 2026
- shader_disasm: prune stale listings against every input, not the --skip-existing remainder (a resumed run
  deleted every listing it had just reused).
- progress_dashboard: a drive-letter path is never inside the repository off Windows (it printed user names);
  its own read_text helper is read_utf8, so the encoding check does not take it for pathlib's.
- Translator tests follow this round's rules: desc_lookup's BroadcastFirst in the typed-load condition walker;
  resinfo sizes are 0 past the last level and a 2D depth word is 0 (SHADER-388); SHADER-315 constant folding in
  the perm and i16 tests; ItsNotRexed#2089's structured wave64 emulation.
- test_semantic_translator_use: 57 oracle-only files merged before it are DEBT; test_spirv_tools_required is
  allowed (CI meta-test).
- Test fixes: image_fuzz fake writes the programs, preflight follows c506d00's loader hint rule, feature_scan
  reads the first line of a pytest-decorated message, w64_graphics wording.
- docs: rows merged again in design.md, README.md, d3d12_vulkan.md; GameInput table rebuilt from ItsNotRexed#3172's rows;
  orphan rows in models.md and embedded_shaders.md; repeated bullets; anchors; a flag not on main.
- Repo rules: stdout guard on 14 programs; LF writes; csv lineterminator in bink_play.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@boraswim
boraswim deleted the rt-175-raw-hid branch November 22, 2026 21:58
@mesterember104-cpu

Copy link
Copy Markdown

Tested 76d1add on Intel Tiger Lake Xe-LP (0x9a78, iGPU, subgroup 8..32, no mesh), driver 32.0.101.7088, Windows 11, MSVC 14.44: pass

Built with -DLEONIDA_SDL3_FETCH=ON so the GameInput SDL3 shim (and its raw-HID path) actually runs: gameinput passed (1.94 s) on real Windows with SDL3's hidapi backing the raw report calls — likely the only Windows+iGPU data point for that path so far. Full runtime ctest: 116/124 passed, 5 skipped (shader work folder / driver-feature skips), 3 failed, none touching this PR's code: d3d12_buffer_tiles and d3d12_descriptor reproduce on main 16282101 on this machine (Intel-side; descriptor is the known D3D-219), and winhttp_offline comes from the newer main merged into this branch (9f41bf65 "gta6rt: WinHTTP offline for mapped images", a test that does not exist at 16282101) — 3 of its 40 HANDLE_CLOSING checks fail deterministically here; this PR's files (gameinput shim/tests/docs) do not touch WinHTTP.

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

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.

5 participants