Skip to content

fix(videoout): start the game controller subsystem on the thread that pumps events - #8964

Closed
BunnyFl wants to merge 1 commit into
boykopovar:mainfrom
BunnyFl:fix/videoout-controller-hotplug-thread
Closed

BunnyFl wants to merge 1 commit into
boykopovar:mainfrom
BunnyFl:fix/videoout-controller-hotplug-thread

Conversation

@BunnyFl

@BunnyFl BunnyFl commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What

On Windows, a controller that is unplugged and plugged in again is never seen: the title keeps running without input until it restarts.

SDL learns of device changes on Windows through message-only windows that its HIDAPI backend (SDL_HIDAPI_DEVICE_DETECTION, src/hidapi/SDL_hidapi.c) and, without SDL_HINT_JOYSTICK_THREAD, its Windows joystick backend (src/joystick/windows/SDL_windowsjoystick.c) create on the thread that initializes the game controller subsystem, and Windows delivers their WM_DEVICECHANGE messages only to that thread's queue. SDL's own note in SDL_hidapi.c: "We'll only get messages on the same thread that created the window"; it leaves them to the usual SDL_PumpEvents loop. VideoOutDriver initialized SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER on the first thread that used video output (VideoOutDriver::Get), while SDL_PollEvent runs on the presentation thread, so SDL_CONTROLLERDEVICEADDED never arrived and PadInput::HandleEvent never reopened the controller.

This PR:

  • VideoOutDriver initializes and quits only SDL_INIT_VIDEO.
  • PadInput, which the presentation thread creates before its event loop, already initialized the game controller subsystem when nothing else had; it now does so on that thread and quits it in its destructor, on the same thread (a window can only be destroyed by its own thread). The SDL hints set in the VideoOutDriver constructor are still set before.
  • If the game controller subsystem fails to initialize, PadInput logs Pad: SDL game controller init failed and the title runs with keyboard and mouse input, instead of video output failing to open.

Not tested: hot-plug on Linux and macOS, where SDL's device notifications do not go through a window message queue.

Overlap (tools/pr_overlap.py): #8658 (macOS host) moves the same SDL_InitSubSystem call to the main thread on macOS, and #6879 (wasm) edits the line next to the Shutdown quit; either merges with this by keeping both changes. Of the pull requests the overlap check could not compare: #7201 (macOS port) also starts the subsystem on the presentation thread, but only when LibcMainThreadServing is set, so not on Windows; #7881 (four controllers) replaces openFirstAvailableController, so the second to merge moves the subsystem ownership into its replacement; #674, #5021 and #7499 do not change where the subsystem is initialized.

Tested

Windows 11 Pro 10.0.26200, AMD Radeon RX 9070 XT (AMD proprietary driver 26.10.1, LLPC), WinLibs GCC 15.2.0 r7, DualSense over USB, main 86b8424 (the PR is rebased onto 0c50cbf, whose new commits touch none of these files; the 41 video_out|pad tests pass there too).

Ball X Pit (PPSA31872), the DualSense unplugged and plugged in again while the title runs:

Pad: connected game controller lines in the log input after plugging in again
main 1 (at start) none
this PR 3 (at start, then 23.8 s and 31.7 s, one for each time it was plugged in again) yes

ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build -R "video_out|pad" -V on main and on this PR: 41 of 41 passed on both. 14 skip on both: the video_out_flip_* tests and guest_video_out_wqhd_detection_no_vulkan, because the offscreen SDL driver they run with has no Vulkan on Windows. The validation layer loaded (no was not found but was requested by env var VK_INSTANCE_LAYERS) and neither log has a VUID- error.

As these are the tests that start VideoOutDriver, I also ran video_out_flip_tests with SDL_VIDEODRIVER=windows and the same three variables for controls, cpuflip, decode, eop, eop_aftergpu, eop_main, labels, labels_main, overlay, ps4, reopen and unopened: on main and on this PR, the same 11 passed and controls failed with pre-vblank event missing on both; no VUID- error.

tools/check_conventions.py --base upstream/main passes.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 9070 XT, AMD proprietary driver 26.10.1 (LLPC), Windows 11 Pro 10.0.26200
  • AI-assisted: yes

The investigation, the change and this description were prepared with AI assistance (Claude Code); the controller tests in the title were done by me.

🤖 Generated with Claude Code

… pumps events

SDL notices a controller plugged in on Windows through a message-only window
that its HIDAPI and joystick backends create on the thread that initializes
the game controller subsystem, and those messages reach only that thread's
queue. VideoOutDriver initialized it with video on the first thread that
used video output, while SDL_PollEvent runs on the presentation thread, so
a controller unplugged and plugged in again was never seen.

PadInput, which the presentation thread creates, now initializes the
subsystem when nothing else has, and quits it when it is destroyed on that
same thread. VideoOutDriver initializes and quits only video.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@clairtonmichel

Copy link
Copy Markdown

Tested on Fedora Linux (AMD Ryzen 7 9800X3D, RX 7900 XTX), Mesa/RADV.
Clean compile with no errors on the current branch commit. Great work fixing the controller subsystem thread initialization!

@BunnyFl
BunnyFl force-pushed the fix/videoout-controller-hotplug-thread branch from 3b04ff6 to d318dc9 Compare October 21, 2026 07:50
@github-actions

github-actions Bot commented Oct 21, 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
PR 7881 core/libs/prx/libSceVideoOut/include/PadInput.hpp L34-38
core/libs/prx/libSceVideoOut/src/PadInput.cpp L29
PR 8658 core/libs/prx/libSceVideoOut/src/VideoOutDriver.cpp L279-281

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 674 core/libs/prx/libSceVideoOut/include/PadInput.hpp
core/libs/prx/libSceVideoOut/src/PadInput.cpp
core/libs/prx/libSceVideoOut/src/VideoOutDriver.cpp
PR 5021 core/libs/prx/libSceVideoOut/src/VideoOutDriver.cpp
PR 6879 core/libs/prx/libSceVideoOut/src/VideoOutDriver.cpp
PR 7201 core/libs/prx/libSceVideoOut/src/VideoOutDriver.cpp
PR 7499 core/libs/prx/libSceVideoOut/src/PadInput.cpp

@github-actions github-actions Bot added the prx label Oct 21, 2026
@BunnyFl

BunnyFl commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Closing to keep to the open pull request limit in CONTRIBUTING.md (one open pull request with none merged; #8932 is open). PR intake failed on this one with a GitHub API error (HTTP 500) instead of closing it. I'll reopen it once #8932 is merged or closed.

AI-assisted: yes (Claude Code)

@BunnyFl BunnyFl closed this Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants