Skip to content

fix(libSceVideoOut): start the controller subsystem on the input thread - #22189

Open
ycbuzi wants to merge 1 commit into
boykopovar:mainfrom
ycbuzi:fix/pad-controller-input-thread
Open

ycbuzi wants to merge 1 commit into
boykopovar:mainfrom
ycbuzi:fix/pad-controller-input-thread

Conversation

@ycbuzi

@ycbuzi ycbuzi commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

What

On Windows a DualSense (or any controller) plugged in after the game started was never connected; it only worked when it was plugged in before launch.

OnMainThread runs its function inline on Windows, so VideoOutDriver's constructor initialised SDL_INIT_GAMECONTROLLER on whichever guest thread first used video output, while the present thread creates the window and pumps the events. SDL creates its HIDAPI device-notification window on the thread that initialises the joystick subsystem, and that window only receives WM_DEVICECHANGE when its thread pumps messages. The guest thread never does, so SDL never rescans and no SDL_CONTROLLERDEVICEADDED arrives.

PadInput now takes its own reference on SDL_INIT_GAMECONTROLLER where it is constructed (the present thread, inside presentLoop) and drops it in its destructor; the driver only initialises and quits SDL_INIT_VIDEO. Linux and macOS behave as before (udev does not depend on the thread; on macOS both already ran on the main thread).

Tested

Windows 11, MinGW GCC 15.2.0, USB DualSense.

  • Reproduced the cause with a standalone SDL 2.33.0 program built against the bundled SDL: video and game controller initialised on one thread, window and SDL_PollEvent on another. Restarting the DualSense's HID device (pnputil /restart-device, the same as unplugging and plugging it) gives removed and then nothing, SDL_NumJoysticks() == 0 at the end. With the game controller subsystem initialised on the pumping thread the same restart gives removed, added 0, one joystick at the end.
  • A game (Luna Abyss, build 502288c) running when the controller was plugged in logged no Pad: connected game controller line and ignored the controller; at least 15 other games started with it already plugged in connected it.
  • pad_sdl checks that PadInput constructed on a worker thread starts the game controller subsystem and stops it when destroyed, and that a reference taken elsewhere survives a PadInput. Without the PadInput change the test aborts (exit 0xc0000409); with it pad_sdl, pad_keyboard_mouse and mouse_input pass. pad_sdl ran with SDL_JOYSTICK_HIDAPI=0 SDL_JOYSTICK_RAWINPUT=0 SDL_XINPUT_ENABLED=0 SDL_JOYSTICK_WGI=0 SDL_DIRECTINPUT_ENABLED=0 so the plugged-in controller did not make it skip.
  • These tests create no Vulkan instance; with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation the log has no VUID- lines. The window and flip tests were not run because they open a window on a machine in use.
  • Not yet run in a game built with this change.

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: NVIDIA GeForce RTX 4070 SUPER, driver 32.0.16.2114, Windows 11 (input tests only; no Vulkan path changed)
  • AI-assisted: yes

🤖 Generated with Claude Code

On Windows OnMainThread runs its function on the calling thread, so the
video driver's constructor initialised the game controller subsystem on
whichever guest thread first used video output, while the present
thread creates the window and pumps the events. SDL creates its HIDAPI
device-notification window on the thread that initialises the joystick
subsystem and only sees arrivals when that thread pumps messages, so a
DualSense or DualShock plugged in after the game started was never
opened: the controller only worked when it was connected before launch.

PadInput now takes its own reference on SDL_INIT_GAMECONTROLLER where it
is constructed, on the thread that pumps the events, and releases it
when destroyed; the driver only initialises the video subsystem.

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

domx4q commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Ran the VideoOut and pad tests on Linux with a Wayland display, the Khronos validation layer and an NVIDIA GPU; CI skips pad_sdl and the window tests because it has no display.

Setup: Arch Linux (kernel 7.3.4), GCC 16.2.1, Release, -DANYPS5_VIDEO_OUT_TEST_DRIVER=wayland, Hyprland session (ANYPS5_REQUIRE_DISPLAY=1), NVIDIA GeForce RTX 4090 (vendor 0x10de, device 0x2684, Ada), proprietary driver 620.70.06, Vulkan 1.4.357, Khronos validation layer 1.4.363.1. Head 48b7a61e3e merged onto main f0c01bc69d with --no-ff, clean merge (Git merged core/libs/prx/libSceVideoOut/src/VideoOutDriver.cpp automatically). Main baseline is a Release build of f0c01bc69d with the same options on the same machine.

ANYPS5_REQUIRE_DISPLAY=1 ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer \
ctest --test-dir build -R 'video_out|pad_' -V
main f0c01bc69d this PR
Result 103 passed, 6 skipped, 1 failed, of 110 103 passed, 6 skipped, 1 failed, of 110
Insert instance layer "VK_LAYER_KHRONOS_validation" 52 52
was not found but was requested by env var VK_INSTANCE_LAYERS 0 0
VUID- none none

This machine has two controllers attached, so pad_sdl, the four pad_identify_* tests and pad_port0 skip on both sides (pad_sdl: skipped, SDL sees 2 host joysticks, which take the pad slots this test checks). To run them anyway I ran them again on both sides with the same environment inside bwrap --dev-bind / / --tmpfs /dev/input plus --ro-bind /dev/null over each /dev/hidraw*, so SDL sees no host joysticks:

ctest --test-dir build -R '^(pad_sdl|pad_identify_[a-z]+|pad_port0|pad_status_sdl)$' -V
host joysticks hidden main f0c01bc69d this PR
Result 7 of 7 passed 7 of 7 passed, 2 of 2 runs
pad_sdl passed (5.17 s) passed (5.20 s, 5.21 s)
VUID- none none

With the joysticks hidden, pad_sdl runs the new checks (the game controller subsystem is live while a PadInput built on a worker thread exists and is shut down after it, and stays up while the shared one remains) and passes. The one failure in the first run is video_out_host_fullscreen_window (leaving a fullscreen start did not give the creation size), which fails the same way on main: the tiling compositor does not give the window its creation size back. Every Vulkan test selected the RTX 4090, and the layer logs no validation warnings on either side. I did not test controller hotplug.

No new VUID- errors; all focused tests except the pre-existing fullscreen failure pass on Ada.

AI-assisted: yes (Claude Code)

@ycbuzi

ycbuzi commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @domx4q. The joystick-hidden bwrap run is exactly what was needed — it exercises the new subsystem-lifetime checks (up while the worker-thread PadInput lives, down after it, up while the shared one remains) and they pass on Ada with no new VUIDs. The fullscreen failure is the known pre-existing tiling-compositor one, so that's fine. Hotplug being untested is okay here; this change is the startup thread, not the hotplug path.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

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 12863 core/libs/prx/libSceVideoOut/src/VideoOutDriver.cpp
PR 15973 core/libs/prx/libSceVideoOut/src/VideoOutDriver.cpp
PR 16791 core/libs/prx/libSceVideoOut/src/VideoOutDriver.cpp
PR 20315 core/libs/prx/libSceVideoOut/src/VideoOutDriver.cpp
PR 22995 core/libs/prx/libSceVideoOut/src/VideoOutDriver.cpp
PR 23637 core/libs/prx/libSceVideoOut/include/PadInput.hpp
core/libs/prx/libSceVideoOut/src/PadInput.cpp
PR 24003 core/libs/prx/libSceVideoOut/src/PadInput.cpp
PR 24699 core/libs/prx/libSceVideoOut/src/VideoOutDriver.cpp
PR 25772 core/libs/prx/libSceVideoOut/src/PadInput.cpp
core/libs/prx/libSceVideoOut/tests/PadSdl.cpp

@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 48b7a61e3e, applied with git apply on main fd4aeed483 together with the other 28 PRs of one batch (#19470, #20317, #21336, #22888, #23474, #24467, #24489, #20216, #22048, #22111, #22319, #22422, #22841, #23127, #9547, #18247, #21720, #22375, #23405, #24134, #14851, #18324, #19650, #19986, #20447, #21078, #22362, #22702). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
pad_sdl (1 test, matched by name to the test file this PR changes) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6526 tests) on the RTX 3080 has 9 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked, guest_raise_short_sleep_without_wake, agc_driver_store_over_untracked. Failing tests I could not trace to a single PR (reverting the likely candidates did not clear them): guest_agc_driver_unknown, guest_load_ranges, tool_script_modes. The 2127 agc_/video tests on the iGPU have 2 failing: agc_driver_stencil_plane_memory, agc_driver_store_over_untracked (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

This was referenced Nov 21, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed — looks good

The change moves game controller subsystem ownership to PadInput on the event-pumping thread, and the inspected construction and teardown paths support that behavior.

What I ran

Reviewed head 48b7a61e3ec7b4b61728c0297c4cb551e228e428 using the prepared diff and pinned reader. No tests or build commands were run; reported test results below are author supplied.

Results

Check Result Note
Changed code review passed All four changed files read
Author reported checks not run Windows input tests reported in PR description
Local tests and build not run No commands run

Findings

Blocking

None.

Non-blocking

None.

Not verified

The PR description reports Windows 11 testing and specific input tests, but these were not run during this review. No Vulkan window or game run was verified. files.json was unavailable through the reader; the manifest lists four changed files, all marked included, and all four were read: PadInput.hpp, PadInput.cpp, VideoOutDriver.cpp, and PadSdl.cpp. No files were excluded per the supplied manifest.

To get this to a good state

Nothing is required.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with main, rebase needed prx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants