fix(videoout): create the window and the device when VideoOut starts #1367

Merged
Raghav314 merged 1 commit from upstream-pr/1367 into main 2026-10-09 08:03:11 +00:00
Raghav314 commented 2026-10-08 00:27:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-08T00:27:48Z.


What

The driver created a windowless Vulkan device at the first dispatch and replaced it with a windowed one at the first flip. The replacement built a second device and re-imported the host imports (#284), and the first flip waited for both. #59, #110, #284 and #373 fix problems caused by the replacement.

shadPS4, KytyPS5 and SharpEmu create the window first and build one device with its surface:

  • shadPS4: emulator.cpp creates the window at startup; gnmdriver.cpp RegisterLib creates Vulkan::Presenter(*g_window).
  • KytyPS5: agc.cpp Initialize calls WindowInit, which creates the window and the Vulkan device, before VideoOutInit.
  • SharpEmu: VulkanVideoPresenter.Initialize creates the instance, the surface, the device, then the swapchain.

This change does the same at the first VideoOut call. AnyPS5 has no hook before the guest's entry point, and the libraries' static initializers can't create a window (loader lock on Windows).

  • VideoOut creates its window on the presentation thread when it starts, at the default 1920x1080 output, and attaches it with AgcDriverAttachWindow before the call returns. The driver creates its device with that window.
  • Present no longer creates or replaces a device. A device created by GPU work submitted before VideoOut started is still replaced, now in AttachWindow.
  • A failure to create the window or the device is thrown from the first VideoOut call. Before, it terminated the process from the presentation thread.
  • The window opens at the first VideoOut call and stays empty until the first flip. It always starts at 16:9; buffers of another aspect are letterboxed as before.

Tests that open VideoOut now need a display and a Vulkan device. guest_video_out_wqhd_detection writes a param.json for the window title and is skipped without a display or Vulkan device unless ANYPS5_REQUIRE_DISPLAY is set. ANYPS5_REQUIRE_VULKAN can't be used: the Linux job sets it, but its SDL is built without X11 and Wayland, so neither CI job can create a Vulkan window and the test is skipped in both.

Hades II (PPSA36082) also needs this to load: its 512 MiB upload pool is freed only after a GPU fence, and creating the device at the first dispatch was one of the delays in front of that fence. With this change and some local changes, it gets past loading; without this change it overflows the pool and crashes (2/2 runs).

Tested

Linux (CachyOS), x86-64, GCC, 7800X3D / RTX 4090.

  • video_out_flip_tests onedevice (new): GPU work, then a flip, leaves one device. Fails on main (two devices); dropping the attach at start fails it.
  • pacing relied on the first flip creating the device to span several vblanks. It now queues GPU work ahead of the flip and checks that lastFlipVblank is at least 3 vblanks behind the vblank the presentation finished at, so it doesn't depend on which vblank the flip reaches the presenter at. Moving the lastFlipVblank store back after the present fails it.
  • unavailable now expects the failure from sceVideoOutOpen, and the same failure from a second open (run without a Vulkan driver).
  • onedevice, pacing, aftergpu, present, backtoback, dcc, controls, decode, unavailable pass.
  • Windows: cross-built on Linux with MinGW-w64 GCC 15.2.0 (UCRT, posix threads, SEH, mingw-w64 14.0.0, as in CI) and run under Wine 11.19 on the same GPU. The flip modes above pass, unavailable with Vulkan disabled.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4780127667 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1367). Originally posted by [Raghav314](https://github.com/Raghav314) on 2026-10-08T00:27:48Z. --- ### What The driver created a windowless Vulkan device at the first dispatch and replaced it with a windowed one at the first flip. The replacement built a second device and re-imported the host imports (#284), and the first flip waited for both. #59, #110, #284 and #373 fix problems caused by the replacement. shadPS4, KytyPS5 and SharpEmu create the window first and build one device with its surface: - shadPS4: `emulator.cpp` creates the window at startup; `gnmdriver.cpp` `RegisterLib` creates `Vulkan::Presenter(*g_window)`. - KytyPS5: `agc.cpp` `Initialize` calls `WindowInit`, which creates the window and the Vulkan device, before `VideoOutInit`. - SharpEmu: `VulkanVideoPresenter.Initialize` creates the instance, the surface, the device, then the swapchain. This change does the same at the first VideoOut call. AnyPS5 has no hook before the guest's entry point, and the libraries' static initializers can't create a window (loader lock on Windows). - VideoOut creates its window on the presentation thread when it starts, at the default 1920x1080 output, and attaches it with `AgcDriverAttachWindow` before the call returns. The driver creates its device with that window. - `Present` no longer creates or replaces a device. A device created by GPU work submitted before VideoOut started is still replaced, now in `AttachWindow`. - A failure to create the window or the device is thrown from the first VideoOut call. Before, it terminated the process from the presentation thread. - The window opens at the first VideoOut call and stays empty until the first flip. It always starts at 16:9; buffers of another aspect are letterboxed as before. Tests that open VideoOut now need a display and a Vulkan device. `guest_video_out_wqhd_detection` writes a `param.json` for the window title and is skipped without a display or Vulkan device unless `ANYPS5_REQUIRE_DISPLAY` is set. `ANYPS5_REQUIRE_VULKAN` can't be used: the Linux job sets it, but its SDL is built without X11 and Wayland, so neither CI job can create a Vulkan window and the test is skipped in both. Hades II (PPSA36082) also needs this to load: its 512 MiB upload pool is freed only after a GPU fence, and creating the device at the first dispatch was one of the delays in front of that fence. With this change and some local changes, it gets past loading; without this change it overflows the pool and crashes (2/2 runs). ### Tested Linux (CachyOS), x86-64, GCC, 7800X3D / RTX 4090. - `video_out_flip_tests onedevice` (new): GPU work, then a flip, leaves one device. Fails on main (two devices); dropping the attach at start fails it. - `pacing` relied on the first flip creating the device to span several vblanks. It now queues GPU work ahead of the flip and checks that `lastFlipVblank` is at least 3 vblanks behind the vblank the presentation finished at, so it doesn't depend on which vblank the flip reaches the presenter at. Moving the `lastFlipVblank` store back after the present fails it. - `unavailable` now expects the failure from `sceVideoOutOpen`, and the same failure from a second open (run without a Vulkan driver). - `onedevice`, `pacing`, `aftergpu`, `present`, `backtoback`, `dcc`, `controls`, `decode`, `unavailable` pass. - Windows: cross-built on Linux with MinGW-w64 GCC 15.2.0 (UCRT, posix threads, SEH, mingw-w64 14.0.0, as in CI) and run under Wine 11.19 on the same GPU. The flip modes above pass, `unavailable` with Vulkan disabled. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-08 13:17:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T13:17:46Z.


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
#1575 core/libs/prx/libSceVideoOut/CMakeLists.txt L29-33
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6060739572 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1367#issuecomment-6060739572). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T13:17:46Z. --- <!-- pr-overlap --> 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 | |---|---|---|---| | #1575 | `core/libs/prx/libSceVideoOut/CMakeLists.txt` [L29-33](https://github.com/boykopovar/AnyPS5/blob/4b005b229e24be9ec3f185def9e59cbc03aa9e4a/core/libs/prx/libSceVideoOut/CMakeLists.txt#L29-L33) | | |
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!1367
No description provided.