input: add gyroscope and motion sensor support #634
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!634
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/634/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@dylanriverajw138-stack on GitHub · 2026-09-16 11:34 UTC · original
dylanriverajw138-stack:feat/gyro-support→main· +129 −2 · 3 files · 1 commits · merged 2026-09-17 08:28 UTCCapture gyroscope and accelerometer samples through SDL controller events, retaining each sample for buffered pad reads. Convert acceleration to G, preserve gyro values in radians per second and their axis directions, and integrate timestamped gyro samples into a normalized relative orientation.
Wire motion enable/disable and orientation reset to controller state. Preserve motion during UI input resets and skip integration across long sensor-report gaps. The controller data layout stays unchanged; advanced motion filters remain unimplemented.
Validation: Linux emulator build and CLI smoke test passed. A focused test harness passed checks for units, axes, sample history, quaternion rotations and composition, reset, enable/disable, reconnection, report gaps, reserved bytes, and concurrent reads. Three independent audits completed, including a final compactness and cleanliness review. Physical controller and gameplay testing is pending.
@coderabbitai[bot] on GitHub · 2026-09-16 11:34 UTC · original · edited 2026-09-17 08:21 UTC
📝 Walkthrough
Walkthrough
The change adds accelerometer and gyroscope support for SDL controllers. Sensor events are forwarded with microsecond timestamps. Controller state stores acceleration, angular velocity, and quaternion orientation. Gyroscope samples update orientation for positive intervals up to 100 ms. Motion enablement resets motion values, orientation reset restores identity, and input reset preserves motion state. New public APIs expose sensor submission and motion controls.
Suggested reviewers:
nmzikPriority: ⬇️ Low
Change: Feature
Merge Risk: 🟠 High · up to
cb04aThe change can lose controller input transitions and produce incorrect motion orientation, while several existing controller, vibration, and presentation failures remain open. These issues should be fixed before merge.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Comment
@coderabbitai helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-09-16 11:45 UTC · original
On
src/graphics/presentation/videoOut.cppline 1113 (outdated):🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Update flip status and flip events for dropped requests.
The skip loop removes
Readyrequests that the guest already submitted. For each removed request the code does not triggerVideoOutEventKind::Flip, does not updateflip_status(count,flipArg,currentBuffer,flipPendingNum), and does not decrementgcQueueNumforFlipRequestSource::GpuEop. Consequences:flip_status.gcQueueNumgrows monotonically, soVideoOutIsFlipPendingandgcQueueNumbecome wrong.WaitForSubmitSlotwaiters stay blocked until the next completed flip.Retire each dropped request through the same status and event path as a presented flip, then signal
m_submit_slot_cond_varandm_done_cond_var.🤖 Prompt for AI Agents
@coderabbitai[bot] on GitHub · 2026-09-16 11:45 UTC · original
On
src/graphics/presentation/window/swapchain.cppline 431 (outdated):🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 11039
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 12477
Honor the configured present mode.
Createalways selectseMailbox, theneImmediate, and only theneFifo. This ignoresGetPresentMode()and prevents a configured FIFO mode on surfaces that support Mailbox or Immediate. Use the configured mode when supported, then apply the current order as the fallback.GetPresentMode()has no callers and is currently unused.🤖 Prompt for AI Agents
@coderabbitai[bot] on GitHub · 2026-09-16 11:45 UTC · original
On
src/libs/controller.cppline 233 (outdated):🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
The fixed sensitivity factors distort the reported sensor units.
angular_velocity_*is a physical quantity in radians per second. Multiplying bySENSITIVITY = 0.75f, and the orientation angles by0.8fat Lines 242-243, reports values that do not match the device. Games that apply their own sensitivity curve or calibrate against gravity then compute wrong motion. Report the converted values unscaled and move any comfort tuning into user configuration.🤖 Prompt for AI Agents
@coderabbitai[bot] on GitHub · 2026-09-16 11:45 UTC · original
On
src/libs/controller.cppline 604 (outdated):🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
The fallback loop passes a device index to an instance-ID lookup.
SDL_NumJoysticks()returns device indices.SDL_GameControllerFromInstanceIDexpects an instance ID. The two namespaces differ, so this loop returnsnullptror an unrelated pad, and vibration silently fails on the fallback path. Convert the index first.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents
@coderabbitai[bot] on GitHub · 2026-09-16 11:45 UTC · original
On
src/libs/controller.cppline 619 (outdated):🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
SetVibrationnever caches the motor values, so dependent payloads send zero.m_vibr_large,m_vibr_small,m_motor_left, andm_motor_rightare declared at Lines 180-187 but no code assigns them. Downstream consumers read those zeros:SetTriggerEffectsetsenable_bits |= 0x01 | 0x02and then writesreserve[0]/reserve[1]as zero, so any trigger-effect update stops an active rumble.SendDualSenseOutputalways sends zero motor values.Store the requested values in
SetVibration.Proposed fix
🤖 Prompt for AI Agents
@coderabbitai[bot] on GitHub · 2026-09-16 11:45 UTC · original
On
src/libs/controller.cppline 923 (outdated):🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 1193
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 4947
Keep deadband state separate from motion-sensor state.
PadSetAngularVelocityDeadbandStatecallsGameController::SetMotionSensorState, which changesm_motion_enabled. When that flag is false,PollSensorsdoes not read new accelerometer or gyroscope data.GameController::SetAngularVelocityDeadbandStateis not declared or defined, so calling it would not compile. Remove the motion-sensor call and store the deadband setting separately if the filtering behavior is required.📝 Committable suggestion
🤖 Prompt for AI Agents
@coderabbitai[bot] on GitHub · 2026-09-16 11:45 UTC · original
On
src/libs/controller.cppline 1022 (outdated):🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Return the invalid-handle error for a bad handle.
An invalid handle now returns
PAD_ERROR_INVALID_ARG. Other entry points in this file returnPAD_ERROR_INVALID_HANDLEfor the same condition, and games distinguish the two codes. Separate the checks.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents
@coderabbitai[bot] on GitHub · 2026-09-16 11:45 UTC · original · reviewed
Actionable comments posted: 7
🧹 Nitpick comments (1)
🤖 Prompt for all review comments with AI agents
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Advanced
Run ID:
7352e807-b0a6-4770-acda-7d236541baae📥 Commits
Reviewing files that changed from the base of the PR and between
ded6964953and 70070a291cafcc4b7348f992b34a8dc9a54a443a.📒 Files selected for processing (5)
src/graphics/presentation/videoOut.cppsrc/graphics/presentation/window/swapchain.cppsrc/libs/controller.cppsrc/libs/libPad.cppsrc/libs/padData.hIncluded review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@Nico00007566 on GitHub · 2026-09-16 21:06 UTC · original
I hope it will be added soon. I want to run some tests with gyro.
@ -716,0 +722,4 @@sensor.data,sensor.timestamp_us != 0? sensor.timestamp_us: static_cast<uint64_t>(sensor.timestamp) * 1000);@coderabbitai[bot] on GitHub · 2026-09-17 08:18 UTC · original
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 4838
🌐 Web query:
SDL2 SDL_ControllerSensorEvent timestamp_us timestamp semantics zero batched sensor events documentation💡 Result:
<search_synthesis>
In SDL2, the SDL_ControllerSensorEvent and SDL_SensorEvent structures contain a timestamp_us field, which provides the timestamp of the sensor reading in microseconds, provided the hardware supplies this information [1][2][3][4]. Regarding the semantics of timestamp_us and the value zero: 1. Semantics: This field represents a hardware-provided timestamp for the sensor measurement [1][3]. It is distinct from the general event timestamp (which is typically populated via SDL_GetTicks in milliseconds and is synchronized with the system clock) [1][2][4]. 2. Value Zero: If the hardware does not provide a specific timestamp for a sensor reading, or if the functionality is unavailable for that particular device, the timestamp_us field is set to 0 [5][6]. 3. Batched Events: SDL2 does not implement native buffering or batching of sensor events in a way that modifies the timestamp_us field to represent a "batch" duration. Each SDL_ControllerSensorEvent or SDL_SensorEvent represents a specific update dispatched to the event queue [7]. When sensors report multiple samples (e.g., at a higher frequency than the SDL event loop), SDL processes these updates individually, and the timestamp_us reflects the specific timing of the hardware sample reported by the driver [8][7]. Important Note on Evolution: Users should be aware that in the transition to SDL3, this field was renamed to sensor_timestamp and its unit was changed from microseconds to nanoseconds [9][10]. Unlike the standard event timestamp, this hardware-provided timestamp is not necessarily synchronized with the system clock used for general SDL timing functions [9][10].
</search_synthesis>
<source_evidence>
https://wiki.libsdl.org/SDL2/SDL_ControllerSensorEvent SDL2/SDL_ControllerSensorEvent - SDL2 Wiki # SDL_ControllerSensorEvent Game controller sensor event structure (event.csensor.*) ## Header File ## Syntax ``` typedef struct SDL_ControllerSensorEvent { Uint32 type; /**< SDL_CONTROLLERSENSORUPDATE */ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ SDL_JoystickID which; /**< The joystick instance id */ Sint32 sensor; /**< The type of the sensor, one of the values of SDL_SensorType */ float data[3]; /**< Up to 3 values from the sensor, as defined in SDL_sensor.h */ Uint64 timestamp_us; /**< The timestamp of the sensor reading in microseconds, if the hardware provides this information. */ } SDL_ControllerSensorEvent; ``` https://github.com/libsdl-org/SDL/blob/SDL2/include/SDL_events.h /** * Game controller sensor event structure (event.csensor.*) */ typedef struct SDL_ControllerSensorEvent ... { Uint32 type; /**< SDL_CONTROLLERSENSORUPDATE */ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ SDL_JoystickID which; /**< The joystick instance id */ Sint32 sensor; /**< The type of the sensor, one of the values of SDL_SensorType */ float data[3]; /**< Up to 3 values from the sensor, as defined in SDL_sensor.h */ Uint64 timestamp_us; /**< The timestamp of the sensor reading in microseconds, if the hardware provides this information. */ } SDL_ControllerSensorEvent; ... /** * Sensor event structure (event.sensor.*) */ typedef struct SDL_SensorEvent ... { Uint32 type; /**< SDL_SENSORUPDATE */ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ Sint32 which; /**< The instance ID of the sensor */ float data[6]; /**< Up to 6 values from the sensor - additional values can be queried using SDL_SensorGetData() */ Uint64 timestamp_us; /**< The timestamp of the sensor reading in microseconds, if the hardware provides this information. */ } SDL_SensorEvent; https://fossies.org/dox/SDL2-2.32.10/structSDL__ControllerSensorEvent.html SDL2: SDL_ControllerSensorEvent Struct Reference - doxygen documentation | Fossies Dox SDL2 2.32.10 About: SDL2(Simple DirectMedia Layer) is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL, and Direct3D. Fossies Dox: SDL2-2.32.10.tar.gz("unofficial" and yet experimental* doxygen-generated source code documentation) Loading... Searching... No Matches SDL_ControllerSensorEvent Struct Reference Game controller sensor event structure (event.csensor. More... SDL_events.h`#include <>` ## Data Fields | Uint32 | type | | --- | --- | | SDL_CONTROLLERSENSORUPDATE. | | Uint32 | timestamp | | In milliseconds, populated using SDL_GetTicks(). | | SDL_JoystickID | which | | The joystick instance id. | | Sint32 | sensor | | The type of the sensor, one of the values of SDL_SensorType. | | float | data [3] | | Up to 3 values from the sensor, as defined in SDL_sensor.h. | | Uint64 | timestamp_us | | The timestamp of the sensor reading in microseconds, if the hardware provides this information. | ## Detailed Description Game controller sensor event structure (event.csensor. *) Definition at line 505 of file SDL_events.h. ## Field Documentation ## ◆ data | float data [3] | | --- | Up to 3 values from the sensor, as defined in SDL_sensor.h. Definition at line 511 of file SDL_events.h. ## ◆ sensor The type of the sensor, one of the values of SDL_SensorType. Definition at line 510 of file SDL_events.h. ## ◆ timestamp In milliseconds, populated using SDL_GetTicks(). Definition at line 508 of file SDL_events.h. ## ◆ timestamp_us The timestamp of the sensor reading in microseconds, if the hardware provides this information. Definition at line 512 of file SDL_events.h. ## ◆ type SDL_CONTROLLERSENSORUPDATE. Definition at line 507 of file SDL_events.h. ## ◆ which The joystick instance id. Definition at line 509 of file SDL_events.h. --- The documentation for this struct was generated from the following file: - SDL_ControllerSensorEvent - Generated by 1.15.0 https://wiki.libsdl.org/SDL2/SDL_SensorEvent SDL2/SDL_SensorEvent - SDL2 Wiki # SDL_SensorEvent Sensor event structure (event.sensor.*) ## Header File ## Syntax ``` typedef struct SDL_SensorEvent { Uint32 type; /**< SDL_SENSORUPDATE */ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ Sint32 which; /**< The instance ID of the sensor */ float data[6]; /**< Up to 6 values from the sensor - additional values can be queried using SDL_SensorGetData() */ Uint64 timestamp_us; /**< The timestamp of the sensor reading in microseconds, if the hardware provides this information. */ } SDL_SensorEvent; ``` CategoryAPI, CategoryAPIStruct, CategoryEvents https://github.com/libsdl-org/SDL/blob/SDL2/include/SDL_sensor.h sensors defined by SDL. * * Additional sensors may be available, using platform dependent semantics ... * ... Here are the additional Android sensors: ... android/hardware ... html#values * ... /** * Get the current state of an opened sensor. * * The number of values and interpretation of the data is sensor dependent. * * \param sensor The SDL_Sensor object to query. * \param data A pointer filled with the current sensor state. * \param num_values The number of values to write to data. ... * \returns 0 or -1 if an error occurred. * * \since This function is available since SDL 2.0.9. */ ... extern DECLSPEC int SDLCALL SDL ... SensorGetData(SDL ... Sensor *sensor, float *data, int num_values); ... /** * Get the current state of an opened sensor with the timestamp of the last * update. * * The number of values and interpretation of the data is sensor dependent. * * \param sensor The SDL_Sensor object to query. * \param timestamp A pointer filled with the timestamp in microseconds of the * current sensor reading if available, or 0 if not. * \param data A pointer filled with the current sensor state. * \param num_values The number of values to write to data. * \returns 0 or -1 if an error occurred. * * \since This function is available since SDL 2.26.0. */ extern DECLSPEC int SDLCALL SDL_SensorGetDataWithTimestamp(SDL_Sensor *sensor, Uint64 *timestamp, float *data, int num_values); ... /** * Update the current state of the open sensors. * * This is called automatically by the event loop if sensor events are * enabled. * * This needs to be called from the thread that initialized the sensor * subsystem. * * \since This function is available since SDL 2.0.9. */ extern DECLSPEC void SDLCALL SDL_SensorUpdate(void);Citations:
github.com/libsdl-org/SDL@41f07949/src/sensor/SDL_sensor.c🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 6059
🤖 get_repo_knowledge executed:
get_repo_knowledge KytyPS5/KytyPS5 /tmp/coderabbit-repo-knowledge/kytyps5-kytyps5-b6cddd0bLength of output: 1870
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 6254
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 2413
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 404
Do not use the millisecond event timestamp for gyro integration.
When
timestamp_usis zero, SDL allows that value when the hardware does not provide a sensor-reading timestamp. The fallback usestimestamp, which SDL defines as the event time in milliseconds. Multiple gyro events can therefore receive the same converted timestamp.GameController::Motionintegrates only whentime_us > m_gyro_time, so equal-timestamp samples are skipped. A later sample can then be integrated across the interval since the last distinct timestamp.Do not use a sensor-rate fallback without a reliable SDL contract. When
timestamp_usis zero, pass no integration timestamp instead of treating the event timestamp as a sample timestamp.@ -405,0 +478,4 @@m_gyro_time = time_us;}m_state.time = LibKernel::KernelGetProcessTime();AddState();@coderabbitai[bot] on GitHub · 2026-09-17 08:18 UTC · original
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 7685
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 20407
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 3943
Do not enqueue one pad state for every sensor event.
Each accepted accelerometer or gyroscope event updates
m_stateand callsAddState(). When the 64-entry ring is full,AddState()discards its oldest entry, even ifPadReadhas not consumed it. A sensor burst can therefore discard queued button, touch, or axis transitions.Do not call
AddState()for every sensor sample unless the queued motion behavior is preserved. Updating onlym_stateprevents ring pressure, butPadReadreads queued states and would not receive motion-only updates. Update the newest queued state or change the read path to sample the current motion state.@coderabbitai[bot] on GitHub · 2026-09-17 08:18 UTC · original · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
1ea4e263-cbee-4604-90a5-a518d8977bff📥 Commits
Reviewing files that changed from the base of the PR and between 70070a291cafcc4b7348f992b34a8dc9a54a443a and
cb04a7bb5d.📒 Files selected for processing (3)
src/graphics/presentation/window/window.cppsrc/libs/controller.cppsrc/libs/controller.hIncluded review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.