feat(pad): support up to 4 controllers with dynamic user discovery #7881
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7881"
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?
Imported from boykopovar/AnyPS5. Originally posted by slugzero on 2026-10-19T12:12:58Z.
What
Before this change,
libScePadandlibSceVideoOutsupported only a single controller handle (handle 1 / port 0). Connecting additional controllers had no effect, andlibSceUserServiceonly knew a single initial user ("Player",0x10000000).This implements support for up to 4 simultaneous game controllers (
PAD_MAX_CONTROLLERS = 4) and dynamic multi-user discovery:libScePad:PadSlot slots[PAD_MAX_CONTROLLERS]) tracking independent input states, queue histories, sensor fusion orientations (quaternion, tilt correction, angular velocity deadband), touch contact IDs, haptic queues, and connection flags per port.PadPublishInputForPort_nid_postfix,PadFetchOutputForPort_nid_postfix,PadSubmitAudioHapticsForPort_nid_postfix, andPadSetPortConnected_nid_postfix. The parameterless legacy exports continue to map to port 0.scePadOpenandscePadGetHandleto allocate handlesPAD_HANDLE_BASE + portfor user IDs0x10000000 + port(ports 0 to 3).scePadGetInfoto enumerate all currently connected ports and assign distinct simulated Bluetooth MAC addresses (PAD_BD_ADDRESSwith port offset).libSceUserService:USER_SERVICE_USER_NAMES("Player", "Player2", "Player3", "Player4") for user IDs0x10000000through0x10000003.UserServiceSetUserConnected_nid_postfixto toggle user connection state and enqueueSceUserServiceEventlogin (EventTypeLogin = 0) and logout (EventTypeLogout = 1) events when controllers connect or disconnect at runtime. User 0 remains permanently logged in.sceUserServiceGetLoginUserIdListandsceUserServiceGetRegisteredUserIdListto return active user IDs and fill unused slots withUSER_SERVICE_USER_ID_INVALID(-1).sceUserServiceGetUserName,sceUserServiceGetUserNumber(1–4), andsceUserServiceGetUserColor(0: Blue, 1: Red, 2: Green, 3: Pink).libSceVideoOut(PadInput):PadInputwithstd::array<ControllerSlot, PAD_MAX_CONTROLLERS> slots.Pad::KeyboardMouse, preserving existing keyboard and mouse bindings, mouse-as-right-stick capture, and input configuration behavior without regressions.SDL_CONTROLLERDEVICEADDED) and removal (SDL_CONTROLLERDEVICEREMOVED) notifyPadSetPortConnected_nid_postfixandUserServiceSetUserConnected_nid_postfix.applyOutputfetches and routes rumble, trigger effects, sensor enable flags, and default player LED colors (Blue, Red, Green, Pink) independently per controller slot.Documentation:
docs/user/INPUT_MAPPING.mdto describe multi-controller input assignment and dynamic hotplugging for players 1 to 4.docs/dev/debt/libScePad.mdto note per-port tracking for angular velocity deadbands.docs/dev/debt/libSceUserService.mdregarding multi-user color indices and user names.Tested
Linux x86_64 (Kernel 6.8, GCC 13.3):
ninja -C build libs) and test targets cleanly.guest_pad_tests: verified multi-controller open (user = 0x10000001-> handle 2), independent input publication on port 1 (Triangle) without altering port 0 state, per-handle vibration mode setting, multi-port enumeration inscePadGetInfo(verifyingconnectedCount[0] == 2and port indices 0 and 1), and handle validation across opened and unopened slots.guest_user_service_tests: verifiedsceUserServiceGetUserName("Player" for initial user, "Player2" for second user, error on buffer too short or invalid ID),sceUserServiceGetUserNumber(1 and 2),sceUserServiceGetUserColor(0 and 1), and dynamic registration list updates onUserServiceSetUserConnected_nid_postfix(1, true)and disconnect.guest_user_service_lifecycle_tests: verified login event queueing on initialize, dynamicEventTypeLoginevent delivery upon connecting user 2,sceUserServiceGetLoginUserIdListreporting both users,EventTypeLogoutdelivery upon disconnecting user 2, and list updating.guest_pad_vibration_mode_tests,pad_sdl_tests,pad_input_mapping_tests,pad_keyboard_mouse_tests, andvideo_out_mouse_testsall pass without errors.python3 -m unittest discover tools/testspasses (596 tests passed, 14 skipped).python3 tools/check_conventions.py --base origin/mainpasses with zero errors.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T18:01:29Z.
Review: CHANGES_REQUESTED
Thanks for the multi-controller work. Points to fix before this can merge:
libScePad/Export.cppandlibSceUserService/Export.cppre-indent (1 → 4 spaces) every function the PR does not change, and existing comments are deleted (sceUserServiceGetEvent,sceUserServiceGetGamePresets,sceUserServiceGetPlatformPrivacyWs1,APS5_NO_PAD_INPUTinPadInput.cpp). Keep the original formatting and only touch the lines that change; this also reduces conflicts with #6337, #7059, #6990 and #7298, which touch the same lines ofPadState.cpp,PadInput.cpp/.hppandlibSceUserService/Export.cpp. List them under Depends on or rebase after they land.Pad::Initialize(PadState.cpp) resetsslots[i].connected = (i == 0), butPadInput::openControllercallsPadSetPortConnected_nid_postfix(slot, true)when the window is created, which can be before the title callsscePadInit. The second pad then reportsconnected == falseuntil a hotplug event, whileuserConnectedin libSceUserService is not reset, so the two disagree. Don't resetconnectedinInitialize, and add a test that connects the port first and then callsscePadInit.docs/dev/debt/libSceUserService.mdthat they are assumed, not measured.PadQueueLegacyAudioHaptics/PadClearLegacyAudioHapticsstill go only to port 0, which also needs a line inlibScePad.md.scePadGetControllerInformationstill reportsconnectedCount = 1.eventQueuein libSceUserService grows with every connect/disconnect if the title never callssceUserServiceGetEvent. Cap it (or collapse login/logout pairs for the same user).PadInput(slot assignment, removal of slot 0 while slot 1 stays, the same device added twice).info.connectedCount[0] >= 1inGuestPad.cpppins nothing; assert the exact count for the state beforePadSetPortConnected_nid_postfix(1, true).Initialize/Initialize2login-queue code is duplicated; use one helper.Imported from boykopovar/AnyPS5. Originally posted by alexpournaras on 2026-10-20T16:52:35Z.
Tested this PR with Call of Duty: Black Ops (PPSA34501) in local multiplayer split-screen.
All four controllers were detected, and 4-player split-screen gameplay worked successfully!
Great work!
Imported from boykopovar/AnyPS5. Originally posted by slugzero on 2026-10-20T22:03:56Z.
Thank you a lot @adriadam10 for your review and for the detailed feedback. I will fix the points and update the PR accordingly.
Imported from boykopovar/AnyPS5. Originally posted by mehmetbayoglu on 2026-10-20T22:17:53Z.
Thanks for this. I wrote the same change independently for Call of Duty: Black Ops (PPSA34501) before I found this PR, so I'll drop mine and build on yours. Two additions I can send as a follow-up PR with
Depends on: #7881, if that suits you:APS5_KEYBOARD_USER=2to4: the keyboard and mouse play as that user instead of user 1, and that user is logged in at startup, so split screen works with one controller. Tested in Black Ops Zombies split screen with a DualSense as player 1 and the keyboard as player 2.APS5_PAD_SKIP_CONTROLLERS=N: a copy leaves the first N host controllers to another copy, so two copies on one computer (a LAN party) don't both read the same controller.Imported from boykopovar/AnyPS5. Originally posted by norton62 on 2026-10-21T14:52:00Z.
Heads-up: #9178 touches the same lines in
libScePad/Export.cpp. It gives the system remote-control port (type 16) its own disconnected handle (0x10) instead of mapping it to port 0, because mapping it to the DualSense makes SDL titles see every Cross press as Return (it broke Raptor's on-screen keyboard). Happy to rebase onto yours.Imported from boykopovar/AnyPS5. Originally posted by slugzero on 2026-10-21T21:20:15Z.
Thanks everyone!
@adriadam10 Thanks for the review and approval! For reference, all review items were addressed in dedicated atomic commits and rebased cleanly onto latest
main:Pad::Initialize()with test coverage.libSceUserService.md(assumed usernames/colors/hotplug events) andlibScePad.md(port-0 legacy audio haptics & single pad count).eventQueuebounded to ≤ 4 by collapsing unconsumed opposite events.PadSdl.cppand pinned exact connected count.@alexpournaras Appreciate you testing 4-player split-screen and confirming!
@norton62 Thanks for the heads-up on #9178!
@mehmetbayoglu Both follow-ups sound like great additions!
APS5_KEYBOARD_USER=2..4: Keeping keyboard/mouse composed with Player 1 by default and havingAPS5_KEYBOARD_USERopt-in to assign it to a dedicated player slot makes total sense for split-screen.APS5_PAD_SKIP_CONTROLLERS=N: My understanding (though correct me if I'm mistaken) is that Instance 1 would still grab all controllers up to 4 unless it has a matching cap, and in SDL2device_indexshifts when a controller disconnects, which might scramble the skip offset on hotplug/unplug. Maybe an explicit device list/range on both instances (e.g.APS5_PAD_DEVICES=0,1and2,3) or slot caps would be more resilient? Happy to see your thoughts and review your PR once this merges!Imported from boykopovar/AnyPS5. Originally posted by mehmetbayoglu on 2026-10-21T21:53:34Z.
@slugzero Thanks, you are right on both points. With only a skip count, the first copy still opens every controller, and the offset follows SDL's device index, which shifts on unplug, so a reconnected controller can land in the other copy.
I'll drop
APS5_PAD_SKIP_CONTROLLERSand do it by identity instead:APS5_PAD_DEVICEStakes a list of controllers by their serial (or HID path when a controller reports no serial), which AnyPS5 prints when each controller connects. A copy opens only the listed controllers, in list order for users 1 to 4, so each copy gets its own list and a controller that reconnects goes back to the same copy and user.APS5_KEYBOARD_USERstays as described. I'll send both as one follow-up withDepends on: #7881once this merges.Imported from boykopovar/AnyPS5. Originally posted by norton62 on 2026-10-22T08:28:12Z.
@slugzero thanks! One concrete point from the review on #9178:
PortForUserstill maps the system remote port (user 0xff, type 16) to slot 0, so once both land the remote would read the DualSense again. Since #7881 is approved and will likely merge first, I'll rebase #9178 onto it and keep the remote port out of the per-port slots (its own disconnected handle outsidePAD_HANDLE_BASE + port). Does that work for you?Imported from boykopovar/AnyPS5. Originally posted by slugzero on 2026-10-22T13:04:49Z.
@norton62 understood, thanks. And sure, that works for me! Left an approving comment in your PR.