Repository navigation
gameinput: report and drive force-feedback and haptic motors through SDL3 haptics (RT-160) - #2552
Conversation
…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.
|
Code read (no wheel attached here — RX 7800 XT desktop), and one cross-PR gap worth settling before either lands.
One question, not a finding: what does The motor-from-haptics-capabilities part looks right to me: one motor at index 0, |
|
Tested af330fc merged onto main 77444fa on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:
AI-assisted (Claude Code). |
|
Tested
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. |
Tracker: RT-160 — GameInput force feedback and haptics (#2300).
What was unimplemented
docs/gameinput.mdsaid it, andruntime/shims/gameinput.cppdid it:GameInputDeviceInforeportedforceFeedbackMotorCountandhapticFeedbackMotorCountas 0,CreateForceFeedbackEffectanswered
E_INVALIDARG,IsForceFeedbackMotorPoweredOnreturned false,SetForceFeedbackMotorGainwas a no-op andSetHapticMotorStatereturnedE_INVALIDARG.SetRumbleStateworked. A title that asks a pad for force-feedback orhaptic 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, whichit does for a wheel or a stick, never for a gamepad) reports one force-feedback motor at index 0:
supportedAxesGameInputFeedbackAxisLinearX,locationchassis,maxSimultaneousEffectsfromSDL_GetMaxHapticEffects, and oneis…EffectSupportedflag per effect kind fromSDL_GetHapticFeatures. A pad with trigger motors (Xbox impulsetriggers, or a DualSense with
LEONIDA_DS_TRIGGERSon) reports two haptic motors, left and right trigger, each with onewaveform. A pad with neither — the keyboard pad included — keeps the previous answers: no motors,
E_INVALIDARG,false, no-op.
ConstantSDL_HAPTIC_CONSTANTlevel= magnitude × gainRampSDL_HAPTIC_RAMPstart/endfrom start/end magnitudeSineWave,SquareWave,TriangleWave,SawtoothUpWave,SawtoothDownWaveSDL_HAPTIC_SINE,SQUARE,TRIANGLE,SAWTOOTHUP,SAWTOOTHDOWNperiod= 1000/frequency ms,magnitude,offset= bias,phase= degrees × 100Spring,Friction,Damper,InertiaSDL_HAPTIC_SPRING,FRICTION,DAMPER,INERTIAcenterfrom the magnitudeThreading unchanged.
SetParams,SetGain,SetState,SetForceFeedbackMotorGainandSetHapticMotorStateonlyrecord a change under the state lock and bump a version;
apply_output()on the poll thread creates, updates, runs andstops 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,
sustainGainscales the magnitude, attack+sustain+release is SDL's
length, andplayCountis the iteration count (0 = untilstopped). 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.
SetForceFeedbackMotorGainis SDL's device gain (SDL_SetHapticGain, 0..100), sent once on open and onceper change;
IGameInputForceFeedbackEffect::SetGainscales 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=0silences force feedback and haptics as well as rumble.DualSense and rumble paths unchanged:
SDL_RumbleGamepad,SDL_RumbleGamepadTriggers, theLEONIDA_DS_TRIGGERSeffect bytes,
LEONIDA_RUMBLE=0and 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.hgains the v0 declarations this needs:GameInputLocation,GameInputFeedbackAxes,GameInputFeedbackEffectState,GameInputForceFeedbackEffectKind,GameInputForceFeedbackMotorInfo,GameInputHapticWaveformInfo,GameInputHapticFeedbackMotorInfo, the envelope/magnitude/condition/constant/periodic/rampparameter structs,
GameInputForceFeedbackParams,GameInputHapticFeedbackParams,IGameInputForceFeedbackEffectandits IID. Every size and offset is pinned with
static_assert(GameInputForceFeedbackMotorInfo28,GameInputHapticWaveformInfo16,GameInputHapticFeedbackMotorInfo24, 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, sothis is the one place the ABI rests on a transcription, and the static asserts are the check.
docs/gameinput.mdsaysso.
What I ran (Windows 11, MSVC 19.x from VS 18 BuildTools, SDK 10.0.26100, Ninja, SDL3 3.4.20 fetched by CMake)
All of these were measured on
af330fcc, the pushed head:261isgameinput_testwith and withoutLEONIDA_GAMEINPUT_THREAD=0,117/110/7is the fullctest, and232/3is the negative control below. The201isgameinput_testbuilt and run atorigin/main49475796.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_testatorigin/main(49475796) andrunning it:
201 checks, 0 failures. The 60 new ones cover the motor report, the effect mapping, the gains, theenvelope, the finished state,
Paused,LEONIDA_RUMBLE=0, the SDL effect's lifetime, and the haptic trigger motors.Negative control
With
i.forceFeedbackMotorCountforced back to0(the pre-change answer) infill_info, the same test binary:232 checks, 3 failures—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 newVERIFYbullets indocs/gameinput.mdlist 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
phaseas degrees.gameinput_probenowprints
forcefeedback=andhaptic=per pad, so the report side is one command on a machine that has one.Docs
docs/gameinput.md: theIGameInputDevicerow of the API table, a new "Force feedback and haptics" section (the twokinds of motor, the mapping table, the envelope and gain rules, what haptics drops and why),
LEONIDA_RUMBLEin theenvironment-variable table, the "how it runs" sentence, the test list, the ABI note and five new
VERIFYbullets.docs/README.mdandruntime/README.mdmention the feature.AI-assisted.Depends on: #2413
Depends on: #1937
Depends on: #2162
Depends on: #2239
Depends on: #2276
Depends on: #2420