fix(videoout): wait for flips with the high-resolution condition on Windows #1655

Merged
mohdfaour03 merged 2 commits from upstream-pr/1655 into main 2026-10-11 09:27:48 +00:00
mohdfaour03 commented 2026-10-08 15:48:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mohdfaour03 on 2026-10-08T15:48:21Z.


What

One of the host waits #1471 lists as still affected: VideoOutDriver::presentLoop waits on flipQueue->changed (a std::condition_variable) with a 10 ms timeout while no flip is queued, and pumps SDL events and the pad after each wake. On Windows that wait goes through winpthreads, which ends timed waits on GetTickCount64 steps, so the poll ended 11 to 24 ms later instead of 10 ms. WaitForFlipRoom waits on the same condition with a 60 s bound and has the same granularity.

A plain high-resolution sleep is not a replacement here: a flip submitted while the present thread waits must wake it at once. libkernel already has the notify-capable precise wait the guest side uses, TimedWait::Condition (event plus high-resolution waitable timer per waiting thread, std::condition_variable_any under APS5_COARSE_TIMED_WAITS), and libSceVideoOut already links libkernel. The change makes FlipQueue::changed a TimedWait::Condition, turns the two timed waits into WaitUntil with the same bounds and predicates, and the eight notify_all into NotifyAll. On Linux TimedWait::Condition is the condition_variable_any path, so nothing changes there. This is the first use of TimedWait::Condition outside libkernel.

Tested

Windows 11 (10.0.26200), WinLibs GCC 15.2.0 (15.2.0posix-14.0.0-ucrt-r7), Release, BUILD_TESTING=ON.

  • Standalone measurement against the built libkernel.prx, tick raised to 0.5 ms as Time.cpp does, 60 iterations each:

    wait p50 min max
    std::condition_variable::wait_for(10 ms), no notify 11.65 ms 10.86 24.43
    TimedWait::Condition::WaitUntil(10 ms), no notify 10.01 ms 10.00 11.25
    TimedWait::Condition::WaitUntil(10 ms), notified from another thread 0.13 ms 0.06 1.54
    std::condition_variable::wait_for(10 ms), notified from another thread 0.14 ms 0.06 2.36

    The notified rows show the wake-on-flip path is unchanged.

  • cmake --build build --target libSceVideoOut video_out_flip_tests; video_out_flip_tests decode and video_out_flip_tests controls with SDL_VIDEODRIVER=dummy exit 0 (the modes #1040 reports as passing on main; the others need a param.json).

  • python tools/check_conventions.py --base upstream/main and git diff --check pass.

  • No title run; no Linux host here (the Linux path is the unchanged condition_variable_any fallback inside TimedWait::Condition).

Checklist

  • Based on current main; no other open PR implements the same functions (#1225 and #1601 do not touch presentLoop; #1472 and #1474 covered the other VideoOut and queue waits)
  • 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 — none added
  • 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 — none added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4789350542 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1655). Originally posted by [mohdfaour03](https://github.com/mohdfaour03) on 2026-10-08T15:48:21Z. --- ### What One of the host waits #1471 lists as still affected: `VideoOutDriver::presentLoop` waits on `flipQueue->changed` (a `std::condition_variable`) with a 10 ms timeout while no flip is queued, and pumps SDL events and the pad after each wake. On Windows that wait goes through winpthreads, which ends timed waits on `GetTickCount64` steps, so the poll ended 11 to 24 ms later instead of 10 ms. `WaitForFlipRoom` waits on the same condition with a 60 s bound and has the same granularity. A plain high-resolution sleep is not a replacement here: a flip submitted while the present thread waits must wake it at once. libkernel already has the notify-capable precise wait the guest side uses, `TimedWait::Condition` (event plus high-resolution waitable timer per waiting thread, `std::condition_variable_any` under `APS5_COARSE_TIMED_WAITS`), and libSceVideoOut already links libkernel. The change makes `FlipQueue::changed` a `TimedWait::Condition`, turns the two timed waits into `WaitUntil` with the same bounds and predicates, and the eight `notify_all` into `NotifyAll`. On Linux `TimedWait::Condition` is the `condition_variable_any` path, so nothing changes there. This is the first use of `TimedWait::Condition` outside libkernel. ### Tested Windows 11 (10.0.26200), WinLibs GCC 15.2.0 (`15.2.0posix-14.0.0-ucrt-r7`), Release, `BUILD_TESTING=ON`. - Standalone measurement against the built `libkernel.prx`, tick raised to 0.5 ms as `Time.cpp` does, 60 iterations each: | wait | p50 | min | max | |---|---|---|---| | `std::condition_variable::wait_for(10 ms)`, no notify | 11.65 ms | 10.86 | 24.43 | | `TimedWait::Condition::WaitUntil(10 ms)`, no notify | 10.01 ms | 10.00 | 11.25 | | `TimedWait::Condition::WaitUntil(10 ms)`, notified from another thread | 0.13 ms | 0.06 | 1.54 | | `std::condition_variable::wait_for(10 ms)`, notified from another thread | 0.14 ms | 0.06 | 2.36 | The notified rows show the wake-on-flip path is unchanged. - `cmake --build build --target libSceVideoOut video_out_flip_tests`; `video_out_flip_tests decode` and `video_out_flip_tests controls` with `SDL_VIDEODRIVER=dummy` exit 0 (the modes #1040 reports as passing on `main`; the others need a `param.json`). - `python tools/check_conventions.py --base upstream/main` and `git diff --check` pass. - No title run; no Linux host here (the Linux path is the unchanged `condition_variable_any` fallback inside `TimedWait::Condition`). ### Checklist - [x] Based on current `main`; no other open PR implements the same functions (#1225 and #1601 do not touch `presentLoop`; #1472 and #1474 covered the other VideoOut and queue waits) - [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) — none added - [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 — none added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
oneandonlydean commented 2026-10-10 02:22:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T02:22:34Z.


This breaks loading on Linux. With this PR on main (25cc6fae6b), libSceVideoOut.prx imports TimedWait::DeadlineNanos (_ZN9TimedWait13DeadlineNanosEm), which libkernel.prx contains but doesn't export, so a title stops at load with symbol lookup error ... undefined symbol and patched_libraries fails. nm -D on the PR's own build shows the same, so it isn't from main. Could you either export it from libkernel or keep the helper inside libSceVideoOut?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6092677306 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1655#issuecomment-6092677306). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T02:22:34Z. --- This breaks loading on Linux. With this PR on main (25cc6fae6b), `libSceVideoOut.prx` imports `TimedWait::DeadlineNanos` (`_ZN9TimedWait13DeadlineNanosEm`), which `libkernel.prx` contains but doesn't export, so a title stops at load with `symbol lookup error ... undefined symbol` and `patched_libraries` fails. `nm -D` on the PR's own build shows the same, so it isn't from main. Could you either export it from libkernel or keep the helper inside libSceVideoOut?
adriadam10 commented 2026-10-10 07:19:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T07:19:28Z.

Review: CHANGES_REQUESTED


Thanks @oneandonlydean for catching this. Confirmed from the diff: VideoOutDriver.cpp now calls TimedWait::DeadlineNanos (declared in libkernel/Time/include/TimedWait.hpp:15), a plain function that libkernel.prx contains but doesn't export. libSceVideoOut.prx therefore imports an unresolved symbol and the title stops at load.

To fix, either:

  • export the TimedWait API that libSceVideoOut needs from libkernel (and check patched_libraries passes), or
  • keep the deadline computation inside libSceVideoOut (e.g. a local steady_clock-based deadline) and only use what libkernel already exports.

Please also run patched_libraries (and a load of a module importing it) before pushing; the PR CI no longer builds/runs ctest, so it won't show there.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5478111520 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1655#pullrequestreview-5478111520). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T07:19:28Z. **Review:** CHANGES_REQUESTED --- Thanks @oneandonlydean for catching this. Confirmed from the diff: `VideoOutDriver.cpp` now calls `TimedWait::DeadlineNanos` (declared in `libkernel/Time/include/TimedWait.hpp:15`), a plain function that `libkernel.prx` contains but doesn't export. `libSceVideoOut.prx` therefore imports an unresolved symbol and the title stops at load. To fix, either: - export the `TimedWait` API that `libSceVideoOut` needs from libkernel (and check `patched_libraries` passes), or - keep the deadline computation inside `libSceVideoOut` (e.g. a local `steady_clock`-based deadline) and only use what libkernel already exports. Please also run `patched_libraries` (and a load of a module importing it) before pushing; the PR CI no longer builds/runs ctest, so it won't show there.
adriadam10 commented 2026-10-11 09:22:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T09:22:55Z.

Review: APPROVED


Thanks @oneandonlydean for catching this. Confirmed: libkernel.prx doesn't export TimedWait::*, so libSceVideoOut.prx had an unresolved import.

Fixed on the branch:

  • rebased onto current main (conflict in FlipRequest::Fail after ReleaseLocked; the new notify_all is now NotifyAll)
  • TimedWait.cpp (self-contained) is compiled into libSceVideoOut (CMakeLists.txt) instead of being imported from libkernel

Checked: nm -D libSceVideoOut.prx has no TimedWait undefined symbol; patched_libraries and the VideoOut ctest group pass (flip modes needing a Vulkan window skip). The Windows timing numbers are the author's and weren't reproduced here. Merging on green CI.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5482741738 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1655#pullrequestreview-5482741738). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T09:22:55Z. **Review:** APPROVED --- Thanks @oneandonlydean for catching this. Confirmed: `libkernel.prx` doesn't export `TimedWait::*`, so `libSceVideoOut.prx` had an unresolved import. Fixed on the branch: - rebased onto current `main` (conflict in `FlipRequest::Fail` after `ReleaseLocked`; the new `notify_all` is now `NotifyAll`) - `TimedWait.cpp` (self-contained) is compiled into `libSceVideoOut` (`CMakeLists.txt`) instead of being imported from libkernel Checked: `nm -D libSceVideoOut.prx` has no `TimedWait` undefined symbol; `patched_libraries` and the VideoOut ctest group pass (flip modes needing a Vulkan window skip). The Windows timing numbers are the author's and weren't reproduced here. Merging on green CI.
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!1655
No description provided.