feat(agc): select the swapchain present mode with ANYPS5_PRESENT_MODE #4106

Merged
fma-rc merged 1 commit from upstream-pr/4106 into main 2026-10-12 10:53:47 +00:00
fma-rc commented 2026-10-11 23:26:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-11T23:26:38Z.


What

The presenter always creates its swapchain with VK_PRESENT_MODE_FIFO_KHR. ANYPS5_PRESENT_MODE now selects fifo (default, unchanged), fifo_latest_ready, mailbox or immediate. Any other value fails the start, and so does a mode the surface does not list in vkGetPhysicalDeviceSurfacePresentModesKHR; there is no fallback. Both swapchain creation sites (constructor and Resize) use the selected mode. When fifo_latest_ready is requested, the device enables VK_KHR_present_mode_fifo_latest_ready (or the EXT one) if the driver reports the feature; with any other value or the variable unset, device creation is as on main. Flip pacing does not depend on the present mode (it waits on the 59.94 Hz vblank timer in VideoOutDriver.cpp).

Why: on Hyprland with the NVIDIA driver a window on a workspace that is not shown gets about one FIFO present per second, so a title left on another workspace runs at 1 FPS. fifo_latest_ready and immediate keep it at its normal rate, which makes unattended test runs independent of what the desktop shows (fifo_latest_ready is defined as a FIFO variant that does not tear; tearing was not compared by eye).

Tested

Arch Linux, RTX 5080 (NVIDIA 615.78.08), Hyprland, main 2ccbd376f with this commit for the tests (rebased 2026-10-12 over a conflict in VulkanDevice.cpp with the sample-locations change; both blocks kept); the Balatro runs were on 7a84b2226.

agc_driver_present_mode passes on NVIDIA, RADV (gfx1036) and lavapipe, and so do agc_driver_flip and agc_driver_flip_compute. It covers the selection function only (default, the four names, wrong case, empty value, unsupported mode, empty list) and needs no GPU; without the change it does not compile. The swapchain wiring needs a window, so no ctest covers it. For that, Balatro (PPSA21402) with its window on a hidden workspace, frames counted over 15 s from the window title's frame counter: fifo 15 frames, fifo_latest_ready 900, immediate 900 (immediate on the previous head, which differs only in when the extension is enabled). mailbox stops at start with the surface does not support the requested present mode (this surface offers fifo, immediate and fifo_latest_ready; the mailbox refusal was run on the earlier head, on main bca7a29d2).

Windows: built with WinLibs GCC 15.2 (UCRT) in a Windows Server 2025 VM without a GPU; agc_driver_present_mode, agc_driver_flip and agc_driver_flip_compute pass there. An earlier head of this PR did not compile on Windows (the flip test target lacked the Vulkan-Headers include directory); that is fixed.

Not tested: presentation on Windows, X11, AMD presentation, a driver without the extension.

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:4823190460 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4106). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-11T23:26:38Z. --- ### What The presenter always creates its swapchain with `VK_PRESENT_MODE_FIFO_KHR`. `ANYPS5_PRESENT_MODE` now selects `fifo` (default, unchanged), `fifo_latest_ready`, `mailbox` or `immediate`. Any other value fails the start, and so does a mode the surface does not list in `vkGetPhysicalDeviceSurfacePresentModesKHR`; there is no fallback. Both swapchain creation sites (constructor and `Resize`) use the selected mode. When `fifo_latest_ready` is requested, the device enables `VK_KHR_present_mode_fifo_latest_ready` (or the EXT one) if the driver reports the feature; with any other value or the variable unset, device creation is as on `main`. Flip pacing does not depend on the present mode (it waits on the 59.94 Hz vblank timer in `VideoOutDriver.cpp`). Why: on Hyprland with the NVIDIA driver a window on a workspace that is not shown gets about one FIFO present per second, so a title left on another workspace runs at 1 FPS. `fifo_latest_ready` and `immediate` keep it at its normal rate, which makes unattended test runs independent of what the desktop shows (`fifo_latest_ready` is defined as a FIFO variant that does not tear; tearing was not compared by eye). ### Tested Arch Linux, RTX 5080 (NVIDIA 615.78.08), Hyprland, main 2ccbd376f with this commit for the tests (rebased 2026-10-12 over a conflict in `VulkanDevice.cpp` with the sample-locations change; both blocks kept); the Balatro runs were on 7a84b2226. `agc_driver_present_mode` passes on NVIDIA, RADV (gfx1036) and lavapipe, and so do `agc_driver_flip` and `agc_driver_flip_compute`. It covers the selection function only (default, the four names, wrong case, empty value, unsupported mode, empty list) and needs no GPU; without the change it does not compile. The swapchain wiring needs a window, so no ctest covers it. For that, Balatro (PPSA21402) with its window on a hidden workspace, frames counted over 15 s from the window title's frame counter: `fifo` 15 frames, `fifo_latest_ready` 900, `immediate` 900 (`immediate` on the previous head, which differs only in when the extension is enabled). `mailbox` stops at start with `the surface does not support the requested present mode` (this surface offers fifo, immediate and fifo_latest_ready; the mailbox refusal was run on the earlier head, on main bca7a29d2). Windows: built with WinLibs GCC 15.2 (UCRT) in a Windows Server 2025 VM without a GPU; `agc_driver_present_mode`, `agc_driver_flip` and `agc_driver_flip_compute` pass there. An earlier head of this PR did not compile on Windows (the flip test target lacked the Vulkan-Headers include directory); that is fixed. Not tested: presentation on Windows, X11, AMD presentation, a driver without the extension. ### 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
XairRrR commented 2026-10-12 00:26:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-12T00:26:25Z.


Same symptom here, from another title: Uncharted: Legacy of Thieves Collection (PPSA05684), Arch Linux, RTX 4070 Ti SUPER, NVIDIA 615.78.08, Hyprland. The menu dropped to exactly one frame per second whenever its window was on a workspace that wasn't shown.

Stack snapshots taken during the stall (eu-stack every 5 s) showed the presenter blocked in drmSyncobjTimelineWait under vkAcquireNextImageKHR, called from VulkanDevice::AcquireImage (FIFO, 5 s timeout). It appeared in every snapshot taken during a stall and in none outside one. The driver hands out about one image per second while the window is hidden, and the guest's flip waits for that acquire.

An alternative that fixes the default without an environment variable is not to wait in the acquire:

const auto acquired = vkAcquireNextImageKHR(device, swapchain, 0, VK_NULL_HANDLE, acquireFence, &index);
if (acquired == VK_ERROR_OUT_OF_DATE_KHR) { /* unchanged */ }
if (acquired == VK_NOT_READY || acquired == VK_TIMEOUT) return false; // drop this presentation, the flip completes

Driver::Present already handles a false from AcquireImage the way it handles an out-of-date swapchain: it skips the presentation and still calls gpuReady, so the flip completes. Flip pacing stays on the vblank timer, as you note.

Measured with FIFO, the game window moved to an empty workspace for 50 s, then back:

  • while hidden: 7.5 fps (max frame gap 235 ms) instead of 1 fps; about 65 presentations dropped and about 10 shown per 10 s
  • while visible: 0 drops per 10 s, frame rate unchanged

I counted the drops with an extra field in the APS5_PROFILE_DRAW [present] line.

This would complement your PR rather than replace it: ANYPS5_PRESENT_MODE remains useful for choosing immediate or mailbox on purpose, while the non-blocking acquire keeps the default FIFO from tying the guest to the compositor. Happy to open it as a separate small PR if that's preferred, or you can fold it into this one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115586275 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4106#issuecomment-6115586275). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-12T00:26:25Z. --- Same symptom here, from another title: Uncharted: Legacy of Thieves Collection (PPSA05684), Arch Linux, RTX 4070 Ti SUPER, NVIDIA 615.78.08, Hyprland. The menu dropped to exactly one frame per second whenever its window was on a workspace that wasn't shown. Stack snapshots taken during the stall (`eu-stack` every 5 s) showed the presenter blocked in `drmSyncobjTimelineWait` under `vkAcquireNextImageKHR`, called from `VulkanDevice::AcquireImage` (FIFO, 5 s timeout). It appeared in every snapshot taken during a stall and in none outside one. The driver hands out about one image per second while the window is hidden, and the guest's flip waits for that acquire. An alternative that fixes the default without an environment variable is not to wait in the acquire: ```cpp const auto acquired = vkAcquireNextImageKHR(device, swapchain, 0, VK_NULL_HANDLE, acquireFence, &index); if (acquired == VK_ERROR_OUT_OF_DATE_KHR) { /* unchanged */ } if (acquired == VK_NOT_READY || acquired == VK_TIMEOUT) return false; // drop this presentation, the flip completes ``` `Driver::Present` already handles a `false` from `AcquireImage` the way it handles an out-of-date swapchain: it skips the presentation and still calls `gpuReady`, so the flip completes. Flip pacing stays on the vblank timer, as you note. Measured with FIFO, the game window moved to an empty workspace for 50 s, then back: - while hidden: 7.5 fps (max frame gap 235 ms) instead of 1 fps; about 65 presentations dropped and about 10 shown per 10 s - while visible: 0 drops per 10 s, frame rate unchanged I counted the drops with an extra field in the `APS5_PROFILE_DRAW` `[present]` line. This would complement your PR rather than replace it: `ANYPS5_PRESENT_MODE` remains useful for choosing `immediate` or `mailbox` on purpose, while the non-blocking acquire keeps the default FIFO from tying the guest to the compositor. Happy to open it as a separate small PR if that's preferred, or you can fold it into this one.
fma-rc commented 2026-10-12 00:44:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-12T00:44:09Z.


A separate PR is the better fit. The non-blocking acquire changes the default path and comes with its own measurement, and this one stays the explicit switch. Your snapshots match what I saw under FIFO, one acquire per second while hidden. With immediate the hidden window keeps its full rate here (900 frames in 15 s), so the two changes do not overlap.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115744299 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4106#issuecomment-6115744299). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-12T00:44:09Z. --- A separate PR is the better fit. The non-blocking acquire changes the default path and comes with its own measurement, and this one stays the explicit switch. Your snapshots match what I saw under FIFO, one acquire per second while hidden. With `immediate` the hidden window keeps its full rate here (900 frames in 15 s), so the two changes do not overlap.
fma-rc commented 2026-10-12 00:55:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-12T00:55:54Z.


Pushed a fourth value, fifo_latest_ready. It needs VK_KHR_present_mode_fifo_latest_ready (or the EXT one), which is enabled only when that value is requested and the driver reports the feature, so device creation with the variable unset is the same as on main.

On the RTX 5080 it fixes the hidden-workspace case like immediate does. The extension defines it as a FIFO variant that does not tear; I have not compared the two by eye. Balatro on a hidden workspace, 15 s: fifo 15 frames, fifo_latest_ready 900. The description has the details.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115847797 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4106#issuecomment-6115847797). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-12T00:55:54Z. --- Pushed a fourth value, `fifo_latest_ready`. It needs `VK_KHR_present_mode_fifo_latest_ready` (or the EXT one), which is enabled only when that value is requested and the driver reports the feature, so device creation with the variable unset is the same as on `main`. On the RTX 5080 it fixes the hidden-workspace case like `immediate` does. The extension defines it as a FIFO variant that does not tear; I have not compared the two by eye. Balatro on a hidden workspace, 15 s: `fifo` 15 frames, `fifo_latest_ready` 900. The description has the details.
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!4106
No description provided.