Skip to content

gameinput: report and drive force-feedback and haptic motors through SDL3 haptics (RT-160) - #2552

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
HQasper:rt-160-haptics
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
HQasper:rt-160-haptics

Conversation

@HQasper

@HQasper HQasper commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Tracker: RT-160 — GameInput force feedback and haptics (#2300).

What was unimplemented

docs/gameinput.md said it, and runtime/shims/gameinput.cpp did it:

| IGameInputDevice | device info, status, battery, SetRumbleState | force feedback and haptic motors (none reported), raw device I/O, power off, input synchronization (no-ops) |

GameInputDeviceInfo reported forceFeedbackMotorCount and hapticFeedbackMotorCount as 0, CreateForceFeedbackEffect
answered E_INVALIDARG, IsForceFeedbackMotorPoweredOn returned false, SetForceFeedbackMotorGain was a no-op and
SetHapticMotorState returned E_INVALIDARG. SetRumbleState worked. A title that asks a pad for force-feedback or
haptic motors found none, so its only output was rumble — on a wheel, nothing at all.

What this does

Motors reported from what the pad can back. A pad SDL opens as a haptic device (SDL_OpenHapticFromJoystick, which
it does for a wheel or a stick, never for a gamepad) reports one force-feedback motor at index 0: supportedAxes
GameInputFeedbackAxisLinearX, location chassis, maxSimultaneousEffects from SDL_GetMaxHapticEffects, and one
is…EffectSupported flag per effect kind from SDL_GetHapticFeatures. A pad with trigger motors (Xbox impulse
triggers, or a DualSense with LEONIDA_DS_TRIGGERS on) reports two haptic motors, left and right trigger, each with one
waveform. A pad with neither — the keyboard pad included — keeps the previous answers: no motors, E_INVALIDARG,
false, no-op.

GameInput kind SDL type fields
Constant SDL_HAPTIC_CONSTANT level = magnitude × gain
Ramp SDL_HAPTIC_RAMP start/end from start/end magnitude
SineWave, SquareWave, TriangleWave, SawtoothUpWave, SawtoothDownWave SDL_HAPTIC_SINE, SQUARE, TRIANGLE, SAWTOOTHUP, SAWTOOTHDOWN period = 1000/frequency ms, magnitude, offset = bias, phase = degrees × 100
Spring, Friction, Damper, Inertia SDL_HAPTIC_SPRING, FRICTION, DAMPER, INERTIA positive/negative coefficient, saturation and dead zone on three axes, center from the magnitude

Threading unchanged. SetParams, SetGain, SetState, SetForceFeedbackMotorGain and SetHapticMotorState only
record a change under the state lock and bump a version; apply_output() on the poll thread creates, updates, runs and
stops the SDL effects, and destroys a retired one. A title call still costs a lock and a copy.

Duration/refresh. The envelope's attack and release become SDL's attack/fade lengths with their gains, sustainGain
scales the magnitude, attack+sustain+release is SDL's length, and playCount is the iteration count (0 = until
stopped). An effect with no duration is a 60 s SDL length re-run every 20 s — the same refresh the rumble motors get —
so an unchanged effect is one call, not one per poll. A finished effect reports GameInputFeedbackStopped.

Gains. SetForceFeedbackMotorGain is SDL's device gain (SDL_SetHapticGain, 0..100), sent once on open and once
per change; IGameInputForceFeedbackEffect::SetGain scales that one effect's levels.

Haptics are an approximation, and documented as one. SDL exposes no waveform table, so each trigger motor reports a
single intensity waveform (usage 0x0F/0x58) and plays any request as an intensity on the existing trigger output; the
trigger rumble level and the haptic intensity share the one message, the stronger winning. A waveform index other than 0
is E_INVALIDARG. LEONIDA_RUMBLE=0 silences force feedback and haptics as well as rumble.

DualSense and rumble paths unchanged: SDL_RumbleGamepad, SDL_RumbleGamepadTriggers, the LEONIDA_DS_TRIGGERS
effect bytes, LEONIDA_RUMBLE=0 and the keyboard pad all still pass, and the DualSense branch no longer returns early
(so force feedback is still applied on a DualSense with the trigger effects off).

ABI

runtime/shims/gameinput_abi.h gains the v0 declarations this needs: GameInputLocation, GameInputFeedbackAxes,
GameInputFeedbackEffectState, GameInputForceFeedbackEffectKind, GameInputForceFeedbackMotorInfo,
GameInputHapticWaveformInfo, GameInputHapticFeedbackMotorInfo, the envelope/magnitude/condition/constant/periodic/ramp
parameter structs, GameInputForceFeedbackParams, GameInputHapticFeedbackParams, IGameInputForceFeedbackEffect and
its IID. Every size and offset is pinned with static_assert (GameInputForceFeedbackMotorInfo 28,
GameInputHapticWaveformInfo 16, GameInputHapticFeedbackMotorInfo 24, envelope 48, condition 52, constant 80,
periodic 88, ramp 104, params 112 with its union at 8, haptic params 32). They were transcribed from the public v0
header's source (microsoftconnect/GameInput, include/v0/GameInput.h); the header itself is not in the repository, so
this is the one place the ABI rests on a transcription, and the static asserts are the check. docs/gameinput.md says
so.

What I ran (Windows 11, MSVC 19.x from VS 18 BuildTools, SDK 10.0.26100, Ninja, SDL3 3.4.20 fetched by CMake)

powershell -ExecutionPolicy Bypass -File scripts\build_runtime.ps1 -FetchSdl3   -> built, no warnings
ctest --test-dir runtime/build -C RelWithDebInfo -R gameinput                   -> 1/1 passed
runtime\build\gameinput_test.exe                                                -> 261 checks, 0 failures
set LEONIDA_GAMEINPUT_THREAD=0
runtime\build\gameinput_test.exe                                                -> 261 checks, 0 failures
ctest --test-dir runtime/build -C RelWithDebInfo                                -> 117 tests, 110 passed, 7 skipped, 0 failed

All of these were measured on af330fcc, the pushed head: 261 is gameinput_test with and without
LEONIDA_GAMEINPUT_THREAD=0, 117/110/7 is the full ctest, and 232/3 is the negative control below. The
201 is gameinput_test built and run at origin/main 49475796.

The 7 skipped are the usual ones that need game files or specific hardware (shader_library_corpus, bink_decode,
bink_audio, fsr_dispatch, bvh_builder, vk_sync_validation, d3d12_rgb9e5_rtv), unchanged by this PR.

The test count went from 201 to 261 checks, measured by building gameinput_test at origin/main (49475796) and
running it: 201 checks, 0 failures. The 60 new ones cover the motor report, the effect mapping, the gains, the
envelope, the finished state, Paused, LEONIDA_RUMBLE=0, the SDL effect's lifetime, and the haptic trigger motors.

Negative control

With i.forceFeedbackMotorCount forced back to 0 (the pre-change answer) in fill_info, the same test binary:
232 checks, 3 failures —

FAIL force feedback: the device reports one force-feedback motor
FAIL force feedback: motor 0 is powered on, and motor 1 does not exist
FAIL force feedback: CreateForceFeedbackEffect

The force-feedback section stops at its first fatal failure, which is why fewer checks run. Source restored
(git checkout -- runtime/shims/gameinput.cpp), rebuilt, 261/261 again.

Needs hardware

No force-feedback device was attached: this machine has no wheel or stick, only a pad, and SDL 3.4.20 on Windows opens
only DirectInput force-feedback devices and G29/G27 wheels as haptic anyway. So the shim's SDL calls are exercised
through a fake haptic backend (rt::gameinput::set_haptic_source), and the new VERIFY bullets in docs/gameinput.md
list what a wheel has to settle: which pads SDL opens as haptic and with how many motors, whether LinearX is the axis a
wheel wants, how the 1:1 magnitudes feel in game, and whether GameInput reads phase as degrees. gameinput_probe now
prints forcefeedback= and haptic= per pad, so the report side is one command on a machine that has one.

Docs

docs/gameinput.md: the IGameInputDevice row of the API table, a new "Force feedback and haptics" section (the two
kinds of motor, the mapping table, the envelope and gain rules, what haptics drops and why), LEONIDA_RUMBLE in the
environment-variable table, the "how it runs" sentence, the test list, the ABI note and five new VERIFY bullets.
docs/README.md and runtime/README.md mention the feature.

AI-assisted.

Depends on: #2413
Depends on: #1937
Depends on: #2162
Depends on: #2239
Depends on: #2276
Depends on: #2420

…SDL3 haptics (RT-160)

IGameInputDevice answered the force-feedback and haptic half of the API with
nothing: no motors in GameInputDeviceInfo, E_INVALIDARG from
CreateForceFeedbackEffect, false from IsForceFeedbackMotorPoweredOn, a no-op
SetForceFeedbackMotorGain and E_INVALIDARG from SetHapticMotorState. A pad SDL
opens as a haptic device now reports one force-feedback motor with the effect
kinds SDL lists, and a pad with trigger motors reports two haptic motors.

Force feedback goes to SDL_CreateHapticEffect/RunHapticEffect on the poll
thread, so title calls still never touch SDL; the eleven GameInput effect kinds
are SDL's eleven force-feedback effects. The trigger haptic motors play their
one waveform as an intensity on the existing trigger output. A pad with neither
keeps the old answers, and LEONIDA_RUMBLE=0 silences both. gameinput_test drives
all of it through a fake haptic backend, because SDL's virtual joysticks report
no haptics.

AI-assisted.
… (RT-160)

HapticApi carried SDL_GetNumHapticAxes and SDL_HapticEffectSupported, which
nothing calls: the motor's axes are the shim's choice and the effect kinds are
gated on SDL_GetHapticFeatures. They are gone from the table, its SDL
implementation and the test's fake, so the seam is exactly the calls a pad's
force feedback makes.

AI-assisted.
@UNYTIX

UNYTIX commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Code read (no wheel attached here — RX 7800 XT desktop), and one cross-PR gap worth settling before either lands.

open_pad() calls haptics().open_joystick(SDL_GetGamepadJoystick(p)), so force feedback exists only for devices SDL maps as a gamepad. #2612 (UNYTIX:rt-164-gameinput-wheel-stick, racing wheel / flight stick / arcade stick readings) adds exactly the devices SDL does not map: they are opened with SDL_OpenJoystick, held as d->js, and report GameInputKindRacingWheel / FlightStick / ArcadeStick with GetRacingWheelState and friends. If both land with this PR first, a wheel SDL cannot map would report its kind and its state but still forceFeedbackMotorCount == 0 — the "on a wheel, nothing at all" case in the description. Whoever rebases second would need to open the haptic from d->js in that branch too (SDL_OpenHapticFromJoystick takes the same SDL_Joystick*), close it next to SDL_CloseJoystick, and set has_trigger_output / sent.force_feedback from that path. Nothing else in this PR depends on which way the device was opened, so it is a small addition either way.

One question, not a finding: what does CreateForceFeedbackEffect do on a device whose status is GameInputDeviceNoStatus (unplugged, the effect object still held)? close_pad() keeps objects alive and orphan()s them so they pick up on replug, which reads as intentional; but info.forceFeedbackMotorCount stays 1 after the unplug, so a title can still call in. Whichever way it goes, a sentence in docs/gameinput.md next to the replug note would settle it.

The motor-from-haptics-capabilities part looks right to me: one motor at index 0, maxSimultaneousEffects from SDL's limit, and each effect flag gated on the feature bit, so a title is never offered an effect SDL would refuse.

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested af330fc merged onto main 77444fa 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).

@bielfreedom

Copy link
Copy Markdown

Tested af330fcc (on its base 49475796) on Windows 11 Pro build 26200, MSVC build of runtime/ with -DLEONIDA_SDL3_FETCH=ON (so the SDL3 shim is built), AMD Radeon RX 9070 XT (driver 32.0.32029.2010), Vulkan validation on: pass.

  • gameinput_test: 261 checks, 0 failures, including the new haptics cases (for example haptics: SetRumbleState still drives the trigger motor, the stronger of the two wins on one trigger, releasing both leaves the trigger silent).
  • ctest on that build: 109/109 pass, 0 validation errors.

No physical controller was connected, so this covers the test's virtual pad, not real force-feedback hardware.

AI-assisted (Claude Code). No game files.

@ItsNotRexed
ItsNotRexed merged commit c1543e3 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