Input: QueryInterface, a dispatcher, device methods, trigger rumble #1958

Open
github-bot wants to merge 4 commits from github-bot/gh-1958 into main AGit
Owner

@⁠RaghavVijayanand on GitHub · 2026-11-25 01:45 UTC · original
RaghavVijayanand:hle/input-gaps → main · +902 −77 · 3 files · 4 commits · open

GameInput gaps and trigger rumble (README: "Input … Needs: Trigger rumble"). Four commits, each building and passing tests.

  • QueryInterface by interface id. The input object, devices and readings answer IUnknown and their own interface (with AddRef) and refuse everything else with E_NOINTERFACE and a cleared out pointer. A null out pointer gets E_POINTER, and a null id E_INVALIDARG. The interface ids are from the GDK's v0 GameInput.h.
  • A dispatcher for manual dispatch. This follows the GDK docs.
    • Holding a dispatcher switches to manual dispatch, and releasing the last reference switches back.
    • In manual mode the poll thread stops polling, and Dispatch polls on the title's thread.
    • OpenWaitHandle hands out an auto-reset event that the poll thread signals while dispatch is manual.
  • Device methods answer as devices without those features. The device table now uses the v0 signatures and gains its missing 22nd slot.
    • The old shared stub returned E_NOTIMPL. To the methods that return a bool, that read as true, so "is the force-feedback motor on?" and "can I get exclusive raw access?" both answered yes. It also left the battery struct and out pointers unwritten.
  • Trigger rumble through Windows.Gaming.Input. Levels are clamped to 0-1 (NaN becomes 0).
    • The big motors still go through XInput. Trigger levels also go to the matching Windows.Gaming.Input pad, with one more state sent to stop them.
    • Without a matching pad, only the motors run.
    • Pads now report all four motors.

Not done, on purpose: CreateAggregateDevice stays E_NOTIMPL. The GDK documents it as "introduced but unimplemented" in v0, the API version implemented here.

Shortcuts, documented in the code:

  • XInput slots are matched to Windows.Gaming.Input pads by order, which is right with one pad.
  • Battery status is "unknown".
  • Reading callbacks still never run, as before.

Tests: 8 new tests plus one extended, using a fake host backend for the rumble mapping and one call into the real Windows.Gaming.Input.

  • A mutation script broke each behavior one at a time (id check, AddRef, dispatch mode switching, wait-handle signalling, bool answers, battery struct, clamping, pad index, motor routing, the motor count), and every mutation made a test fail.
  • Trigger rumble has not been tried on a physical pad.
  • Cargo.lock is unchanged: upstream had already made windows non-optional, so the rebase only adds Gaming_Input to its features. Upstream's device walking and VICTORY_KEYS merge are kept, and manual Dispatch uses upstream's poll.

Rebased onto current main (940d32f). On this machine, 5 tests fail on main itself, with or without this change: descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views, the two stride_tests::a_heap_buffer_read_* tests, and synthetic_tests::gathers_at_a_level_match_the_hardware. Everything else passes, and clippy passes with -D warnings, with and without --all-features.

**@⁠RaghavVijayanand** on GitHub · 2026-11-25 01:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/1958) `RaghavVijayanand:hle/input-gaps` → `main` · +902 −77 · 3 files · 4 commits · open GameInput gaps and trigger rumble (README: "Input … Needs: Trigger rumble"). Four commits, each building and passing tests. - **QueryInterface by interface id.** The input object, devices and readings answer IUnknown and their own interface (with AddRef) and refuse everything else with E_NOINTERFACE and a cleared out pointer. A null out pointer gets E_POINTER, and a null id E_INVALIDARG. The interface ids are from the GDK's v0 `GameInput.h`. - **A dispatcher for manual dispatch.** This follows the GDK docs. - Holding a dispatcher switches to manual dispatch, and releasing the last reference switches back. - In manual mode the poll thread stops polling, and `Dispatch` polls on the title's thread. - `OpenWaitHandle` hands out an auto-reset event that the poll thread signals while dispatch is manual. - **Device methods answer as devices without those features.** The device table now uses the v0 signatures and gains its missing 22nd slot. - The old shared stub returned E_NOTIMPL. To the methods that return a bool, that read as **true**, so "is the force-feedback motor on?" and "can I get exclusive raw access?" both answered yes. It also left the battery struct and out pointers unwritten. - **Trigger rumble through Windows.Gaming.Input.** Levels are clamped to 0-1 (NaN becomes 0). - The big motors still go through XInput. Trigger levels also go to the matching Windows.Gaming.Input pad, with one more state sent to stop them. - Without a matching pad, only the motors run. - Pads now report all four motors. Not done, on purpose: `CreateAggregateDevice` stays E_NOTIMPL. The GDK documents it as "introduced but unimplemented" in v0, the API version implemented here. Shortcuts, documented in the code: - XInput slots are matched to Windows.Gaming.Input pads by order, which is right with one pad. - Battery status is "unknown". - Reading callbacks still never run, as before. **Tests:** 8 new tests plus one extended, using a fake host backend for the rumble mapping and one call into the real Windows.Gaming.Input. - A mutation script broke each behavior one at a time (id check, AddRef, dispatch mode switching, wait-handle signalling, bool answers, battery struct, clamping, pad index, motor routing, the motor count), and every mutation made a test fail. - Trigger rumble has not been tried on a physical pad. - `Cargo.lock` is unchanged: upstream had already made `windows` non-optional, so the rebase only adds `Gaming_Input` to its features. Upstream's device walking and `VICTORY_KEYS` merge are kept, and manual `Dispatch` uses upstream's poll. **Rebased onto current main (940d32f).** On this machine, 5 tests fail on main itself, with or without this change: `descriptor::host::tests::dynamic_slots_are_held_until_released`, `memory::tests::lists_share_a_table_and_copies_keep_their_views`, the two `stride_tests::a_heap_buffer_read_*` tests, and `synthetic_tests::gathers_at_a_level_match_the_hardware`. Everything else passes, and clippy passes with `-D warnings`, with and without `--all-features`.
The input object, its devices and its readings answered every
QueryInterface with E_NOINTERFACE and a warning that it was not
implemented. Each now answers IUnknown and its own interface
(IGameInput, IGameInputDevice, IGameInputReading; ids from the GDK's
GameInput.h, API v0) with itself and a new reference, as COM does;
other ids get null and E_NOINTERFACE, a null out pointer E_POINTER and
a null id E_INVALIDARG. Readings are counted, so a query's reference is
the title's to release; the input object and devices live as long as
the process and their counts stay nominal.

A test queries each object for each interface id and a foreign one,
checks the pointers handed back, that failures clear the out pointer,
and that a reading's count grows by one per answer and not on a
refusal. It fails when the id check is skipped or the reference is not
taken.
CreateDispatcher failed with E_NOTIMPL. It now hands out a counted
IGameInputDispatcher. As documented, holding one switches GameInput to
manual dispatch and releasing the last switches back: while one lives,
our poll thread stops polling the host, and Dispatch polls it on the
title's thread, running the device callbacks that brings there. One
poll is all the work there is, so Dispatch returns false (none left).

OpenWaitHandle returns a new handle (a duplicate, which the title
closes) to an auto-reset event of ours that the poll thread sets each
period while dispatch is manual. Shortcut: every period counts as work,
since telling whether the host changed would take the poll Dispatch is
for.

Tests drive the dispatcher through its table: QueryInterface for its
own id and IUnknown (and refusal of the others) with the count checked;
a pad connected under manual dispatch is not seen until Dispatch, whose
callbacks run on the calling thread; releasing the last reference
returns to automatic polling; wait handles are distinct, signalled by
the period only in manual mode, auto-reset, and survive the title
closing one. Each fails when the mode switch, the poll in Dispatch, the
release bookkeeping, the signal or the interface id is broken.
Every IGameInputDevice method after GetDeviceStatus but SetRumbleState
returned E_NOTIMPL from one stub, whatever its signature. For the methods that
return bool that read as true (E_NOTIMPL's low byte is 1): a title
asking whether a force feedback motor is on, or for exclusive raw
access, was told yes. GetBatteryState left the title's struct
unwritten, and the methods with an out pointer left it as it was. The
table was also one slot short: API v0 ends with
ReleaseExclusiveRawDeviceAccess at 0xa8.

Each slot now has its v0 signature (GameInput.h of the GDK) and answers
as a device with no battery report, no force feedback or haptic motors
(as its info says), no input synchronization and no raw reports:
battery status unknown with zero rates (shortcut: XInput's coarse
levels give no capacities; v0 documents battery state as
unimplemented), force feedback effects and haptic states
E_INVALIDARG for a motor it does not have, false for the booleans,
E_NOTIMPL with cleared out pointers (and zero bytes written) for raw
reports and I/O controls, and no effect for gain, synchronization,
PowerOff and releasing access (shortcut: PowerOff leaves the host pad
on).

CreateAggregateDevice keeps E_NOTIMPL, now as the documented answer
rather than a gap: the GDK lists it as introduced but unimplemented in
v0, removed in v1 and implemented with another signature only from v3.

A test calls every device slot on a pad and on the keyboard with
poisoned outputs and checks each answer, and the aggregate refusal. It
fails when the feature read is given the create signature, a boolean
answers true, the battery is left unwritten or its status is wrong, or
the I/O control's byte count is not cleared.
SetRumbleState took the low and high frequency motors to XInput and
dropped the trigger levels: XInput has no trigger motors. Grand Theft
Auto VI sends trigger levels too. Our pads also told the title they had
only the two big motors; they now report all four, as a console pad.

The title's four levels are clamped to 0..1 (NaN is 0) and handed to a
router over two host backends. The big motors still go to XInput as
before. When a trigger level is set, Windows.Gaming.Input
(Gamepad.Vibration) also gets all four levels, with the motors at the
same values, so XInput's state is not undone. Once triggers have been
set, the next state goes there too so they stop. A state with no trigger
levels leaves that API alone. Without WinRT (the factory fails) the API
is marked unavailable once and the motors work as before. An empty slot
or a pad the API lacks gets the motors only.

Shortcut: XInput slots and Windows.Gaming.Input pads are matched by
order (the nth connected slot is that API's nth pad), since neither
says which of the other's pads is which. That is right with one pad;
with several, another pad's triggers may answer. Not tried on a
physical pad: none is attached here.

The `windows` dependency (no longer optional) also enables Gaming_Input.
Cargo.lock is unchanged because the crate was already locked.

Tests check through a fake host: levels clamped and scaled (0.5 to
32767, out of range and NaN), motors to XInput only, triggers to the
trigger API at the pad's rank with all four levels, one stop and then
silence, a missing trigger pad and an empty slot still driving the
motors, the reported motors, and SetRumbleState through the device
table reaching the host. A further test calls the real trigger API for
a pad it lacks. Each test fails when the clamp, the rank, the stop
bookkeeping, the empty-slot check, the motor call, the reported motors
or the host call is broken.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:50:03 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 02:19 UTC · original · edited 2026-11-25 03:21 UTC

Automated triage for the maintainers.

Needs work: needs the maintainer's decision. The behaviour looks reasonable:

  • QueryInterface by id;
  • a dispatcher for manual dispatch;
  • device methods that answer "no" instead of an E_NOTIMPL that reads as true;
  • trigger rumble through Windows.Gaming.Input. The only Cargo change is the Gaming_Input feature of the existing windows crate.

CI passes. It breaks repo rule 2, though. The comments in gameinput.rs name the console SDK and its header ("from the GDK's GameInput.h", "the GDK documents CreateAggregateDevice"). They also use the header's identifiers, such as GameInputBatteryState and method names like IsForceFeedbackMotorPoweredOn in the DEVICE table. main uses only slot offsets and our own descriptions. Please reword those comments. Whether the interface ids copied from that header are acceptable under docs/asset-policy.md is for the maintainer to decide.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 02:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/1958#issuecomment-7150579206) · edited 2026-11-25 03:21 UTC <!-- victory-triage v1 head=e104ae71d8e3005b1f1dfe33be4d5d7c23cce8da verdict=needs-work at=2026-11-25T03:21:00Z --> Automated triage for the maintainers. **Needs work: needs the maintainer's decision.** The behaviour looks reasonable: - QueryInterface by id; - a dispatcher for manual dispatch; - device methods that answer "no" instead of an `E_NOTIMPL` that reads as `true`; - trigger rumble through Windows.Gaming.Input. The only Cargo change is the `Gaming_Input` feature of the existing `windows` crate. CI passes. It breaks repo rule 2, though. The comments in `gameinput.rs` name the console SDK and its header ("from the GDK's `GameInput.h`", "the GDK documents CreateAggregateDevice"). They also use the header's identifiers, such as `GameInputBatteryState` and method names like `IsForceFeedbackMotorPoweredOn` in the `DEVICE` table. `main` uses only slot offsets and our own descriptions. Please reword those comments. Whether the interface ids copied from that header are acceptable under `docs/asset-policy.md` is for the maintainer to decide. --- _Generated by [Claude Code](https://claude.ai/code)_
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/1958/head:github-bot/gh-1958'
git switch 'github-bot/gh-1958'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1958'
git switch 'github-bot/gh-1958'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1958'
git switch 'github-bot/gh-1958'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1958'
git switch 'main'
git merge --squash 'github-bot/gh-1958'
git switch 'main'
git merge --ff-only 'github-bot/gh-1958'
git switch 'main'
git merge 'github-bot/gh-1958'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1958
No description provided.