Skip to content

feat(usbd): add native synchronous USB backend - #2224

Closed
obojeoboje wants to merge 1 commit into
boykopovar:mainfrom
obojeoboje:feat/usbd-libusb-backend
Closed

obojeoboje wants to merge 1 commit into
boykopovar:mainfrom
obojeoboje:feat/usbd-libusb-backend

Conversation

@obojeoboje

Copy link
Copy Markdown

What

Replace 22 throwing libSceUsbd exports with a synchronous host USB backend using libusb 1.0.30. Previously the library always returned an empty device list and threw on all device operations. It now enumerates real host devices, reads device/configuration/string descriptors, manages device references and handles, claims/releases interfaces, performs control transfers, and exposes native configuration/reset/driver operations.

Add libusb as a pinned submodule (libusb/libusb-cmake, tag v1.0.30-0, commit c8477c10ac2ac6b1718d4d498e102b9f18b776f5) and build it statically from source. Linux uses the bundled netlink enumeration backend rather than a system libudev dependency. Hide native libusb exports from the guest library.

Use the signatures, native descriptor layouts and USB error conversion documented by shadPS4 usbd.h and usbd.cpp, with locally written wrappers. Own a separate reference-counted libusb context and convert the guest's 64-bit timeval fields to the host representation.

Transfer allocation/free and interrupt-transfer preparation work, preserving the guest callback pointer. Asynchronous submit/cancel and sceUsbdCheckConnected remain throwing stubs. Host permissions and USB drivers apply; console lifecycle and invalid-argument error precedence remain unverified. Record these limits in TechnicalDebt and remove the obsolete no-device silent-stub entry.

The progress scanner changes from 2578/3044 (84.69%) to 2600/3044 (85.41%), +22 implementations and +0.72 percentage points.

Tested

Windows, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON:

  • Native USB tests enumerated 9 host devices, read cached device descriptors and available configuration descriptors, checked device/list reference lifetimes, repeated initialization/exit, transfer allocation/preparation, SysV guest callback invocation, invalid arguments, and remaining throwing paths.

  • Deterministic control-transfer tests replace only the native libusb control-transfer call at link time. They verify setup fields, byte counts and buffer output, error conversion (including OTHER), zero/maximum/invalid lengths, string-descriptor requests, and that invalid calls never reach the backend.

  • Native libusb functions are not exported from the built guest library.

  • Test registration and conventions checks passed.

  • cmake --build build --parallel 12 completed successfully, as did cmake --build build --target libs --parallel 12.

  • ctest --test-dir build --output-on-failure --parallel 4 --timeout 30: 506 passed, 1 skipped (guest_video_out_wqhd_detection_no_vulkan), 1 timed out (agc_driver_flat_store). The timeout was 30.06 s; no timeout setting was raised.

  • Re-ran agc_driver_flat_store, guest_usbd and guest_usbd_control sequentially with the same 30-second limit: all 3 passed (24.19 s, 0.10 s, 0.01 s respectively).

No game or homebrew was tested. Physical devices were enumerated and their descriptors read; control-transfer payload tests used the test backend. Linux has not been tested locally.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#2351 docs/dev/TechnicalDebt.md L246
#2364 docs/dev/TechnicalDebt.md L23-24

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing: no title reaches these Usbd calls on main, and a new libusb dependency needs one that does. If you find a title that talks to a USB device, please reopen with its ID and the log line.

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.

2 participants