Skip to content

libusb: support hotplug - #16580

Merged
Megamouse merged 13 commits into
RPCS3:masterfrom
sanjay900:master
Jan 23, 2025
Merged

Megamouse merged 13 commits into
RPCS3:masterfrom
sanjay900:master

Conversation

@sanjay900

@sanjay900 sanjay900 commented Jan 19, 2025 •

Copy link
Copy Markdown
Contributor

Implement hotplug using hotplug events where supported, and a periodic scan where hotplug isn't available

For windows, the periodic scan in some scenarios had negative effects on controller responsiveness, as libusb_get_device_list can take a few seconds on some machines, so I've opted to instead hook into the nativeEventFilter and implement a native hotplug myself.

  • migrated from lambda calls to const whitelist structure, and have merged the emulation aspect into this
  • Use a combination of the device port, address and vid and pid for differentiating devices, as suggested by some sample code from libusb
  • Implemented native hotplug with a small delay as usb hotplug events tend to arrive before devices are fully enumerated
  • If multiple LDDs match a device, only the first LDD wins and creates a device
  • Close any open pipes when a device gets disconnected
  • Set a pads status to disconnected when unregistering an LDD pad

Changes are based on #9096

Fixes #9071
Fixes #15074

Comment thread rpcs3/Emu/Io/Buzz.cpp Outdated
Comment thread rpcs3/Emu/Io/Buzz.cpp Outdated
Comment thread rpcs3/Emu/Io/Buzz.h Outdated
Comment thread rpcs3/Emu/Io/usb_device.h Outdated
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp Outdated
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp Outdated
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp Outdated
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp Outdated
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp Outdated
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp Outdated
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp Outdated
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp Outdated
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp Outdated
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp Outdated
@sanjay900
sanjay900 force-pushed the master branch 2 times, most recently from 54b2811 to 34c56fa Compare January 20, 2025 20:08
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp Outdated
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp Outdated
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp
@sanjay900
sanjay900 force-pushed the master branch 4 times, most recently from 4ce37d3 to fc5f7bd Compare January 20, 2025 23:19
@sanjay900

sanjay900 commented Jan 23, 2025 •

Copy link
Copy Markdown
Contributor Author

It seems on some windows machines, libusb_get_device_list can take a few seconds to run, which is really not acceptable as it means every 4 seconds you end up with a dropped input.

Since we are only really using hotplug events as an indication of when to rescan, its easy enough to hook into the windows device change events, and then use that as an indication of when to run the rescan next

@sanjay900
sanjay900 force-pushed the master branch 2 times, most recently from cdb95c3 to 5d8bbed Compare January 23, 2025 08:38
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp Outdated
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.h Outdated
Comment thread rpcs3/rpcs3qt/gui_application.cpp Outdated
Comment thread rpcs3/rpcs3qt/gui_application.cpp Outdated
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp Outdated
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp Outdated
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp Outdated
Comment thread rpcs3/rpcs3qt/gui_application.cpp Outdated
Comment thread rpcs3/rpcs3qt/gui_application.cpp Outdated
Comment thread rpcs3/rpcs3qt/gui_application.cpp Outdated
Comment thread rpcs3/rpcs3qt/gui_application.cpp Outdated
Comment thread rpcs3/rpcs3qt/gui_application.cpp Outdated
Comment thread rpcs3/rpcs3qt/gui_application.h Outdated
Comment thread rpcs3/rpcs3qt/gui_application.cpp
Comment thread rpcs3/rpcs3qt/gui_application.cpp Outdated
sanjay900 and others added 2 commits January 24, 2025 09:07
Co-authored-by: Megamouse <studienricky89@googlemail.com>
Co-authored-by: Megamouse <studienricky89@googlemail.com>
@sanjay900
sanjay900 force-pushed the master branch 2 times, most recently from 4ced6d0 to 11545fd Compare January 23, 2025 20:20
Comment thread rpcs3/rpcs3qt/gui_application.cpp
Comment thread rpcs3/rpcs3qt/gui_application.cpp Outdated
sanjay900 and others added 3 commits January 24, 2025 09:25
Co-authored-by: Megamouse <studienricky89@googlemail.com>
Co-authored-by: Megamouse <studienricky89@googlemail.com>
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp Outdated
Comment thread rpcs3/Emu/Cell/lv2/sys_usbd.cpp Outdated
sanjay900 and others added 3 commits January 24, 2025 10:29
Co-authored-by: Megamouse <studienricky89@googlemail.com>
Co-authored-by: Megamouse <studienricky89@googlemail.com>
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.

[Feature request] USB passthrough hotplug Does not handle Skylanders portal disconnections/reconnections

5 participants