Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deps: Update to SDL3 #12311

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open

Deps: Update to SDL3 #12311

wants to merge 22 commits into from

Conversation

TheLastRar
Copy link
Contributor

@TheLastRar TheLastRar commented Feb 15, 2025

Description of Changes

  • Updates SDL to 3.2.4
  • Adjust logic for Controllers using single motor haptic feedback
  • Use correct icons for PS buttons in FSUI controller settings
  • Use correct names for PS buttons in controller settings window
  • DInputSource will display the axes names as per Windows controller test.
  • Adjust how bindings are displayed in the controller settings window
    • Buttons/axis are now spaced
    • "&" is replaced with "+" in chord binds, matching the FSUI.
    • Buttons are shown starting from 1 instead of 0, matching the numbers typically printed on the DInput style controllers
      • axes and hats also have the same change.
  • Save SDL non-gamepad axis/buttons as an index starting from 0 instead of 21
  • Handle conversion of SDL2's label based button assignment to SDL3's positional based assignment
    • The controller will need to be plugged in for this conversion to be performed

Rationale behind Changes

SDL3 is the hip new thing in town!

Single motor haptic feedback logic seemed incorrect

SDL allows us to fetch information about the connected controller, allowing us to display a name matching its buttons.
The above put in place infrastructure that then allows us to display more readable text for binds, and other sources got the same treatment for consistency.

RFC

SDL3 provides a default value for output latency (Sample frames in SDL terms) and recommends that we use that
I've opted instead to specify the user set value (via SDL_HINT_AUDIO_DEVICE_SAMPLE_FRAMES)
Do we want to offer UI for the default rate? or always use the default value, or keep what I've done?
Note: This value gets ignored on Windows (matching SDL2 here) so this would only effect Linux (and Mac?).

SDL3's audio system requires us to call a function to put data, instead of copying into a memory buffer like with SDL2/Cubeb.
Currently a temporary buffer is used, rather then adapting AudioStream::ReadFrames() to be able to use a function.
Is this suitable? or would we want ReadFrames() to be able to use a Put function?

SDL3 renamed the face buttons to compass directions (with a function to get the label).
I, however, have retained the old names in our ConvertKeyToString() as this is what gets saved to our config file, in addition to what is displayed in the config screen.

How are we wanting the commits squashed? given both me and Tech worked on this?

Suggested Testing Steps

Note that the new or migrated binds may not work on SDL2 builds after testing with this PR

  • Test the SDL Audio backend
  • Test Controllers
  • Test Controllers that use haptics instead of gamepad (Logged as "Rumble is supported on via haptic")
    • Both controllers that support SDL_HAPTIC_LEFTRIGHT, and those that don't.
  • Test wheels with FFB
  • Test loading binds made int SDL2 (master) to SDL3 (this PR) (note if you go back to SDL2 you will need to rebind)
    • Nintendo controllers as they needed extra handling for migrating the face buttons
    • Controllers with "Button* or "Axis*" binds
  • Test display of binds (both in and out of BPM) for all input sources

Copy link
Contributor

@TheTechnician27 TheTechnician27 left a comment

Choose a reason for hiding this comment

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

A look through the code comparing some of the basic stuff with the SDL3 migration manual seems good, but somebody more qualified is going to need to take a look at more complex migration stuff like SDLInputSource.cpp lines 732 to 755 to see if they track. Testing for about 20 minutes revealed no obvious errors introduced or fixed in the audio or controller.

@TheLastRar
Copy link
Contributor Author

Rebased to include the SDL audio hint

I'm now using SDL_GetRealGamepadType() and SDL_GetGamepadButtonLabel() to determine the best icons for FSUI
For the names, that work is still in progress

Regarding TellowKrinkle's comments, I think I will go with the approach of breaking old binds

@TheLastRar TheLastRar marked this pull request as draft February 16, 2025 22:32
Except for our own ControllerData structure, which retains its name
@TheLastRar
Copy link
Contributor Author

TheLastRar commented Feb 18, 2025

I had missed that SDL3 added additional buttons to the standard gamepad (asserts have been added to catch this in future)

Adding support for these buttons required adjusting how unmapped* joystick bindings where done, as internally we offset these to after the standard gamepad buttons.
It was decided that new binds for unmapped* joysticks should be added, with old binds automatically migrated over.
Note that the new or migrated binds will not work on PCSX2 builds still using SDL2.

The following steps will be performed
SDL-X/ButtonN will be translated to SDL-X/JoyButtonM, where M is N - 21
SDL-X/*AxisN will be translated to SDL-X/*JoyAxisM, where M is N - 6

*unmapped refers to SDL not having gamepad mappings for its standard layout, instead having numbered buttons and axes.
SDL3 refers to unmapped controllers as joysticks, and mapped controllers as gamepads
Note that mapped controllers can still have unmapped buttons/axes, such as the PS3 pressure sense axes

@TheLastRar
Copy link
Contributor Author

Added generating more readable text for UI, for SDL this will also reflect the label on the buttons for PS controllers (and the ABXY labels for Nintendo controllers as per SDL2)

Add migration from SDL2's label based assignment to SDL3's positional based assignment
The following steps will be performed;
SDL-X/A, SDL-X/B, SDL-X/X, SDL-X/Y
will be translated to
SDL-X/FaceSouth, SDL-X/FaceEast, SDL-X/FaceWest, SDL-X/FaceNorth
based on what SDL3 provides for the label layout (or as the Xbox layout for PS and unknown controllers) for the controller that is connected at the time of conversion
If no controller if connected for player X, then the conversion is delayed.

@TheLastRar TheLastRar force-pushed the SDL3 branch 2 times, most recently from 83783ea to f553a6e Compare February 21, 2025 23:44
@TheLastRar TheLastRar marked this pull request as ready for review February 22, 2025 12:11
@TheLastRar
Copy link
Contributor Author

I think this is ready for review and further testing
This picked up a fair few more changes along the way, a mix of handling old binds and UI work

@TellowKrinkle
Copy link
Member

TellowKrinkle commented Feb 23, 2025

Just tested FSUI with a switch controller and A is back and B is forwards.

Also minor nitpick: If you shift-click a binding and add that way, the internal button name is used instead of the display name until you close and reopen the interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants