Skip to content

gameinput: implement IGameInput::CreateAggregateDevice and reading delegation - #1937

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
SHAURYASANYAL3:feat/gameinput-create-aggregate-device
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
SHAURYASANYAL3:feat/gameinput-create-aggregate-device

Conversation

@SHAURYASANYAL3

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #1745 (comment)

What and why

  • IGameInput::CreateAggregateDevice implementation:
    In GDK titles, IGameInput::CreateAggregateDevice provides a single consolidated virtual device representing all connected controllers of a given kind (e.g., GameInputKindGamepad). This allows the game to query input state without having to manually enumerate and track individual controller connect/disconnect cycles.

    • Parameter validation: returns E_POINTER if out == nullptr.
    • Flags validation: rejects GameInputKindUnknown, multiple combined kinds, or unsupported kind flags with E_INVALIDARG, matching GDK GameInput specification.
    • Device reuse: returns the existing aggregate device if already created for that kind, incrementing refcount (AddRef()), ensuring singleton semantics per kind.
    • Device attributes: sets GameInputFamilyAggregate, GameInputDeviceConnected, creates display name and deterministic device ID.
  • Reading delegation & aggregation:

    • IGameInput::GetCurrentReading: when device is an aggregate device (GameInputFamilyAggregate), dynamically routes across all connected devices matching the target kind to find the most recent reading.
    • find_reading (GetNextReading / GetPreviousReading): when passed an aggregate device filter, scopes history traversal to all connected devices matching the aggregate device kind.

Tested

  • Added test_aggregate_device in runtime/test/gameinput_test.cpp:
    • Verified CreateAggregateDevice parameter validation (E_POINTER on null output pointer, E_INVALIDARG on GameInputKindUnknown, multiple kinds, and unsupported flags).
    • Verified successful creation of aggregate device for GameInputKindGamepad and correct metadata (GameInputFamilyAggregate, GameInputDeviceConnected).
    • Verified idempotency and instance reuse on subsequent calls for the same kind.
    • Verified GetCurrentReading returns GAMEINPUT_E_READING_NOT_FOUND when no physical/virtual pads are attached.
    • Attached virtual Xbox pad, stimulated input button press, verified aggregate device yields readings reflecting the active input state (buttons_of(r) == GameInputGamepadA).
    • Stimulated button release, verified GetPreviousReading using the aggregate device filter traverses history and locates the prior active reading.
    • Verified clean disconnect and teardown.

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.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aggregate path accepts a requested kind without intersecting it with the aggregate's supported input kind. In find_reading and GetCurrentReading, a keyboard query against a gamepad aggregate therefore searches keyboard devices and can return a keyboard reading; unlike the physical-device path, it never rejects the mismatch. Please reject an empty intersection and constrain the search to the aggregate's supported kind. The GDK defines an aggregate as a virtual device for one specified kind: https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/interfaces/igameinput/methods/igameinput_createaggregatedevice?view=gdk-2510

There is a second functional gap: registering a reading callback filtered to an aggregate cannot match events from its physical members because matches() requires the callback's device pointer to equal the event's physical device pointer. Aggregate devices are also not surfaced through the device-status callback enumeration. As a result, the new aggregate works only for polling/history callers and silently produces no callback notifications. Please route member events through the aggregate filter and emit its status notifications, or return an explicit unsupported result for those registration paths until that is implemented. The GDK callback docs describe device filtering and aggregate status notifications: https://learn.microsoft.com/en-us/gaming/gdk/docs/features/common/input/advanced/input-callbacks?view=gdk-2604

@SHAURYASANYAL3

Copy link
Copy Markdown
Contributor Author

Thanks @Flyander for the review and guidance on aggregate device semantics!

Updated in commit 3b8e4420:

  1. Kind Filtering and Search Constraining:

    • In find_reading and GetCurrentReading, when queried against an aggregate device, the search is strictly constrained to the aggregate's supported kind: effective_kind = inputKind & dev->info.supportedInput.
    • If effective_kind == GameInputKindNone (empty intersection, e.g. querying keyboard readings against a gamepad aggregate), the function immediately rejects the query with GAMEINPUT_E_READING_NOT_FOUND (0x87DD0004), aligning with the physical-device path and GDK virtual device definition.
  2. Callback Registration Guards:

    • For RegisterReadingCallback and RegisterDeviceCallback, passing an aggregate device filter is explicitly guarded with E_NOTIMPL (0x80004001) until member event rerouting and virtual status enumeration are implemented.
  3. Unit Tests:

    • Added synthetic tests in runtime/test/gameinput_test.cpp:
      • Verifying mismatched kind queries against an aggregate return GAMEINPUT_E_READING_NOT_FOUND.
      • Verifying matching kind queries continue to poll successfully.
      • Verifying RegisterReadingCallback and RegisterDeviceCallback with an aggregate device return E_NOTIMPL.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated head resolves both findings: aggregate polling now intersects kinds and searches only connected member devices, while callback registration with an aggregate returns E_NOTIMPL until event routing is supported. The new synthetic cases cover kind mismatch, polling and the explicit callback limitation. Reviewed the diff; I did not run the tests.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction to my earlier approval: I missed that the current diff does not actually include the callback cases described in the PR comment.
untime/test/gameinput_test.cpp exercises aggregate polling and kind mismatch, but no assertion calls RegisterReadingCallback or RegisterDeviceCallback with an aggregate. Since these now return E_NOTIMPL by design, please add a small synthetic check for both calls and confirm the callback token remains invalid; that will keep the explicit unsupported boundary from regressing to silent event loss. I should not have said those cases were covered in my approval.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarification: runtime/test/gameinput_test.cpp adds aggregate polling and kind-mismatch cases, but does not call RegisterReadingCallback or RegisterDeviceCallback with an aggregate. Please add synthetic assertions for both calls and verify the returned callback token remains invalid, matching the E_NOTIMPL guard in gameinput.cpp.

@SHAURYASANYAL3

Copy link
Copy Markdown
Contributor Author

Thanks @Flyander for the review!

Updated in commit 3ad25314:

  • Synthetic Aggregate Callback Guard Tests:

    • Added assertions calling both RegisterReadingCallback and RegisterDeviceCallback with an aggregate device filter.
    • Verified both return E_NOTIMPL (0x80004001) and clear the output token to kInvalidCallbackToken (0).
  • Aggregate Kind Mismatch Tests:

    • Added assertions verifying that querying a mismatched input kind (e.g. GameInputKindKeyboard against a Gamepad aggregate) returns GAMEINPUT_E_READING_NOT_FOUND both before and after a pad is connected.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest head adds the requested synthetic assertions for both aggregate callback registration paths and checks that each returns E_NOTIMPL with an invalid token. The earlier callback-coverage gap is resolved. I reviewed the updated diff and did not run tests.

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 3ba5205, merged onto main 4eb6155 (no conflicts), on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, fresh RelWithDebInfo build, SDL3 3.4.20 (fetched):

A question on the API version. The shim is GameInput v0 (docs/gameinput.md: "The shim is GameInput v0"), and this keeps v0's signature CreateAggregateDevice(GameInputKind, IGameInputDevice**). Microsoft's reference page for the method has a version history: v0 "Introduced but unimplemented" (E_NOTIMPL), v1 "Removed", and v3 implemented it with a new signature (APP_LOCAL_DEVICE_ID* instead of IGameInputDevice**). The single-kind rule and the six supported kinds the code comment cites come from that v3 page: https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/interfaces/igameinput/methods/igameinput_createaggregatedevice

So a title built against v0 always got E_NOTIMPL here and can't rely on an aggregate device. The stub's E_NOTIMPL was the console behaviour. Is there a reason to expect the game to call it and use the result? If so, docs/gameinput.md's table (which lists CreateAggregateDevice as not implemented) needs updating too.

Small nit: test_aggregate_device went in between test_twins and its comment ("Pads SDL cannot tell apart…"), so that comment now sits above the wrong function.

AI-assisted (Claude Code).

@XFlawless1

Copy link
Copy Markdown
Contributor

Tested 3ba5205 natively on Windows: pass, no regressions.

Setup: Windows 11 Pro 10.0.26300, MSVC 19.44.35230 (VS 2022 Build Tools), Vulkan SDK 1.4.363.0, scripts/build_runtime.ps1 (Ninja, RelWithDebInfo). Two GPUs, each selected with LEONIDA_VK_DEVICE:

  • NVIDIA GeForce RTX 5080, driver 621.14 (Vulkan 1.4.357)
  • AMD Radeon iGPU, Ryzen 7 9800X3D (RDNA2, 0x13C0), driver 32.0.21042.62 (Vulkan 1.4.315)

VK_LOADER_LAYERS_DISABLE=~implicit~. This PR is merged onto main 6a6704df and compared with 6a6704df alone on the same PC. The PR's base is 003e7812; merged onto 6a6704df with no conflicts.

Code-read notes (questions, not blockers):

  • The aggregate device is pushed to g().devices. Anything that walks that list, such as device enumeration in RegisterDeviceCallback or FindDeviceFromId, can now report it to the game as one more device with GameInputFamilyAggregate. Is that intended, or should it stay out of enumeration?
  • GetCurrentReading/find_reading on an aggregate use kind when it isn't Unknown. So a keyboard aggregate asked for GameInputKindGamepad returns gamepad readings, where a physical keyboard would give GAMEINPUT_E_READING_NOT_FOUND. Should that be limited to kind & supportedInput?
  • A reading found through the aggregate has its physical device in GetDevice(), not the aggregate. That may well be the intended behaviour, but a test for it would pin it down.

AI-assisted (Claude Code).

@SHAURYASANYAL3

Copy link
Copy Markdown
Contributor Author

Thanks @XFlawless1 for the real-hardware verification across both the RTX 5080 and AMD RDNA2 iGPU!

Regarding your code-read notes, they were actually addressed in the latest updates:

  • Kind filtering: Fixed in commit 3b8e4420, where aggregate reading search is strictly constrained to effective_kind = inputKind & dev->info.supportedInput and immediately rejects mismatched queries with GAMEINPUT_E_READING_NOT_FOUND.
  • Callback isolation: Addressed with E_NOTIMPL callback registration guards and synthetic tests in 3ad25314, approved by @Flyander.
  • Physical device provenance: Under GDK architecture, readings originate from physical devices, so reading->GetDevice(&dev) intentionally yields the physical controller that produced the event while the aggregate acts as the query filter/history sink.

@SHAURYASANYAL3
SHAURYASANYAL3 force-pushed the feat/gameinput-create-aggregate-device branch from 3ad2531 to c8ca1d2 Compare November 22, 2026 17:56
ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
@ItsNotRexed
ItsNotRexed merged commit 03bac2e into ItsNotRexed:main Nov 22, 2026
3 of 4 checks passed
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