HLE: native 4-motor Xbox impulse trigger haptics via Windows.Gaming.Input with XInput fallback #1357

Open
github-bot wants to merge 1 commit from github-bot/gh-1357 into main AGit
Owner

@⁠wbkepler on GitHub · 2026-11-24 17:35 UTC · original
wbkepler:hle/gameinput-impulse-triggers → main · +618 −31 · 1 files · 1 commits · open

Summary

  • Propagates all four GameInputRumbleParams motors (low_frequency, high_frequency, left_trigger, right_trigger) through a clamped finite Rumble struct and reports 0xF in DeviceInfo::rumble_motors.
  • Drives all four motors on Windows via dynamically loaded combase.dll WinRT Windows.Gaming.Input.Gamepad (IGamepadStatics::get_Gamepads + IGamepad::put_Vibration) with zero extra crate dependencies, falling back cleanly to 2-motor XInputSetState when WinRT or a matching gamepad is unavailable.
  • Dispatches rumble asynchronously via a dedicated coalescing RumbleWorker background thread (Hub::rumble_sink) so SetRumbleState never contends with XInputGetState polling or stalls the title's render/simulation thread.
  • Automatically zeroes active motors on pad disconnect, window unfocus, and worker teardown.
  • Adds deterministic unit tests covering clamping/non-finite sanitization, disconnect zeroing, 4-motor delivery + 2-motor fallback + drop zeroing on RumbleWorker, and live WinRT probing/teardown safety.

Verification

  • cargo clippy --workspace --all-targets & -p victory --features diagnostics --all-targets — passed (0 new warnings)
  • cargo test --workspace — passed (victory-hle gameinput: 10/10)
  • cargo xtask policy — passed (151 files ok)
**@⁠wbkepler** on GitHub · 2026-11-24 17:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/1357) `wbkepler:hle/gameinput-impulse-triggers` → `main` · +618 −31 · 1 files · 1 commits · open ## Summary - Propagates all four `GameInputRumbleParams` motors (`low_frequency`, `high_frequency`, `left_trigger`, `right_trigger`) through a clamped finite `Rumble` struct and reports `0xF` in `DeviceInfo::rumble_motors`. - Drives all four motors on Windows via dynamically loaded `combase.dll` WinRT `Windows.Gaming.Input.Gamepad` (`IGamepadStatics::get_Gamepads` + `IGamepad::put_Vibration`) with zero extra crate dependencies, falling back cleanly to 2-motor `XInputSetState` when WinRT or a matching gamepad is unavailable. - Dispatches rumble asynchronously via a dedicated coalescing `RumbleWorker` background thread (`Hub::rumble_sink`) so `SetRumbleState` never contends with `XInputGetState` polling or stalls the title's render/simulation thread. - Automatically zeroes active motors on pad disconnect, window unfocus, and worker teardown. - Adds deterministic unit tests covering clamping/non-finite sanitization, disconnect zeroing, 4-motor delivery + 2-motor fallback + drop zeroing on `RumbleWorker`, and live WinRT probing/teardown safety. ## Verification - `cargo clippy --workspace --all-targets` & `-p victory --features diagnostics --all-targets` — passed (0 new warnings) - `cargo test --workspace` — passed (`victory-hle` `gameinput`: 10/10) - `cargo xtask policy` — passed (151 files ok)
- Propagate all four `GameInputRumbleParams` motors (`low_frequency`,
  `high_frequency`, `left_trigger`, `right_trigger`) through a clamped
  finite `Rumble` struct and report `0xF` in `DeviceInfo::rumble_motors`.
- Drive all four motors on Windows via dynamically loaded `combase.dll`
  WinRT `Windows.Gaming.Input.Gamepad` (`IGamepadStatics::get_Gamepads` +
  `IGamepad::put_Vibration`) with zero extra crate dependencies, falling back
  cleanly to 2-motor `XInputSetState` when WinRT or a matching gamepad is
  unavailable.
- Dispatch rumble asynchronously via a dedicated coalescing `RumbleWorker`
  background thread (`Hub::rumble_sink`) so `SetRumbleState` never contends
  with `XInputGetState` polling or stalls the title's render/simulation thread
  on COM/WinRT/HID I/O.
- Automatically zero active motors on pad disconnect, window unfocus, and
  worker teardown.

Adds deterministic unit tests covering clamping/non-finite sanitization,
disconnect zeroing, 4-motor delivery + 2-motor fallback + drop zeroing on
`RumbleWorker`, and live WinRT probing/teardown safety.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:28:38 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 18:01 UTC · original

Coordination: this overlaps #312 (open) and the older #26 / #1104, all of which change the same rumble plumbing.

  • #312 changes Source::rumble to [f32; 4] and adds an SDL3 source (SDL_RumbleGamepad + SDL_RumbleGamepadTriggers), for Linux/Wine pads.
  • this PR changes it to a Rumble struct and adds the WinRT four-motor path + worker + zeroing.
  • #26 and #1104 also carry the four motor levels (struct / XInputSetStateEx).

git merge-tree between #312 and this head conflicts in gameinput.rs. The Rumble struct here looks like the better common signature; #312 could rebase onto it and keep only the SDL3 backend (its XInput path would then come from this PR). Worth picking one signature before more of these land.

I can test this on AMD/Wine (RX 9060 XT, Wine 11.22 + vkd3d 3.2) if a build is useful — though WinRT may be unavailable under Wine, so the XInput fallback is what would be exercised.

**@⁠DaviTostes** on GitHub · 2026-11-24 18:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1357#issuecomment-7140052660) Coordination: this overlaps **#312** (open) and the older #26 / #1104, all of which change the same rumble plumbing. - #312 changes `Source::rumble` to `[f32; 4]` and adds an SDL3 source (SDL_RumbleGamepad + SDL_RumbleGamepadTriggers), for Linux/Wine pads. - this PR changes it to a `Rumble` struct and adds the WinRT four-motor path + worker + zeroing. - #26 and #1104 also carry the four motor levels (struct / XInputSetStateEx). `git merge-tree` between #312 and this head conflicts in `gameinput.rs`. The `Rumble` struct here looks like the better common signature; #312 could rebase onto it and keep only the SDL3 backend (its XInput path would then come from this PR). Worth picking one signature before more of these land. I can test this on AMD/Wine (RX 9060 XT, Wine 11.22 + vkd3d 3.2) if a build is useful — though WinRT may be unavailable under Wine, so the XInput fallback is what would be exercised.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:24 UTC · original

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-hle/src/modules/gameinput.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/1357#issuecomment-7149506293) <!-- victory-triage v1 head=cdec26e9dd4527ff0bac2f4c7a9542438860823d verdict=needs-rebase at=2026-11-25T01:24:03Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-hle/src/modules/gameinput.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠kilolimaVI on GitHub · 2026-11-26 21:58 UTC · original

This no longer merges onto current main (conflict in crates/victory-hle/src/modules/gameinput.rs). #1958 and #2095 do the same and merge cleanly; comparison on #1958.

AI-assisted (Claude).

**@⁠kilolimaVI** on GitHub · 2026-11-26 21:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/1357#issuecomment-7204236911) This no longer merges onto current main (conflict in `crates/victory-hle/src/modules/gameinput.rs`). #1958 and #2095 do the same and merge cleanly; comparison on #1958. AI-assisted (Claude).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 22:29 UTC · original · requested changes

Checked cdec26e9:

  • Merging onto current main (63bcca43) hits 4 merge conflicts in crates/victory-hle/src/modules/gameinput.rs (Source trait, Hub::poll, FakeHost, Fake, due to VICTORY_KEYS/scripted_keys). Also note that main's all-zero XInput connection filter means disconnect_zeroes_active_rumble_for_that_slot (using PadState::default()) will need a non-zero pad report after rebasing.
  • At cdec26e9, cargo test --locked -p victory-hle --lib modules::gameinput:: passes (10/10, default and --features diagnostics), and the new hunks are rustfmt-clean (clippy fails only on pre-existing xmem.rs:747 at that older base).

The WinRT worker thread lifetime (RoInitialize/RoUninitialize pairing, release order before FreeLibrary, // SAFETY: coverage, and #[cfg(windows)] gating) is clean, but a few issues need changes:

  1. XInput slot index used directly as WinRT Gamepad.Gamepads index (gameinput.rs:1323, 1478, 1581): Gamepad.Gamepads is a dense list whose ordering does not track sparse XInput user slots 0..3. If XInput slot 0 disconnects while slot 1 remains connected (now at WinRT index 0), the disconnect zero for slot 0 stops the surviving controller while slot 1 goes out of range and falls back to 2-motor XInput (or drives the wrong device when multiple pads differ in order). Please associate devices rather than indexing WinRT by XInput slot.
  2. Additional items to tighten during rebase:
    • HStringHeader([usize; 3]) (1188) is only 12 bytes on 32-bit Windows where WinRT requires 20 bytes.
    • If RoInitialize returns RPC_E_CHANGED_MODE (1270), fall back to XInput instead of using WinRT on an STA thread without a message pump.
    • If RumbleWorker::new fails to spawn (1444), Host::rumble_sink still returns Some(...) and silently drops fallback XInput rumble.
    • Reporting rumble_motors = 0xF unconditionally (254) advertises trigger motors even when falling back to 2-motor XInput, and focus-loss zeroing (1595) can be overwritten by subsequent SetRumbleState calls while unfocused.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 22:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/1357#pullrequestreview-6081129027) · **requested changes** Checked `cdec26e9`: - Merging onto current `main` (`63bcca43`) hits **4 merge conflicts** in `crates/victory-hle/src/modules/gameinput.rs` (`Source` trait, `Hub::poll`, `FakeHost`, `Fake`, due to `VICTORY_KEYS`/`scripted_keys`). Also note that `main`'s all-zero XInput connection filter means `disconnect_zeroes_active_rumble_for_that_slot` (using `PadState::default()`) will need a non-zero pad report after rebasing. - At `cdec26e9`, `cargo test --locked -p victory-hle --lib modules::gameinput::` passes (**10/10**, default and `--features diagnostics`), and the new hunks are `rustfmt`-clean (`clippy` fails only on pre-existing `xmem.rs:747` at that older base). The WinRT worker thread lifetime (`RoInitialize`/`RoUninitialize` pairing, release order before `FreeLibrary`, `// SAFETY:` coverage, and `#[cfg(windows)]` gating) is clean, but a few issues need changes: 1. **XInput slot index used directly as WinRT `Gamepad.Gamepads` index (`gameinput.rs:1323, 1478, 1581`)**: `Gamepad.Gamepads` is a dense list whose ordering does not track sparse XInput user slots `0..3`. If XInput slot `0` disconnects while slot `1` remains connected (now at WinRT index `0`), the disconnect zero for slot `0` stops the surviving controller while slot `1` goes out of range and falls back to 2-motor XInput (or drives the wrong device when multiple pads differ in order). Please associate devices rather than indexing WinRT by XInput slot. 2. **Additional items to tighten during rebase**: - `HStringHeader([usize; 3])` (`1188`) is only 12 bytes on 32-bit Windows where WinRT requires 20 bytes. - If `RoInitialize` returns `RPC_E_CHANGED_MODE` (`1270`), fall back to XInput instead of using WinRT on an STA thread without a message pump. - If `RumbleWorker::new` fails to spawn (`1444`), `Host::rumble_sink` still returns `Some(...)` and silently drops fallback XInput rumble. - Reporting `rumble_motors = 0xF` unconditionally (`254`) advertises trigger motors even when falling back to 2-motor XInput, and focus-loss zeroing (`1595`) can be overwritten by subsequent `SetRumbleState` calls while unfocused.
This pull request has changes conflicting with the target branch.
  • crates/victory-hle/src/modules/gameinput.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1357/head:github-bot/gh-1357'
git switch 'github-bot/gh-1357'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1357'
git switch 'github-bot/gh-1357'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1357'
git switch 'github-bot/gh-1357'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1357'
git switch 'main'
git merge --squash 'github-bot/gh-1357'
git switch 'main'
git merge --ff-only 'github-bot/gh-1357'
git switch 'main'
git merge 'github-bot/gh-1357'
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!1357
No description provided.