[PR #303] [MERGED] Move presentation to separate thread/improve sync #1465

Closed
opened 2026-02-27 21:12:39 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/shadps4-emu/shadPS4/pull/303
Author: @raphaelthegreat
Created: 7/18/2024
Status: Merged
Merged: 7/28/2024
Merged by: @psucien

Base: mainHead: present2


📝 Commits (10+)

  • cc81ba6 video_out: Move presentation to separate thread
  • 2e4f32a liverpool: Better sync for CPU flips
  • 502dc1c driver: Make flip blocking
  • fb325e3 videoout: Proper flip rate and vblank management
  • 6d86c6f config: Add vblank divider option
  • 621d50e clang format
  • 4d3b993 videoout: added sceVideoOutWaitVblank
  • 1f60b3d clang format
  • c9a1395 vk_scheduler: Silly merge conflict
  • 72e5462 externals: Add renderdoc API

📊 Changes

32 files changed (+1259 additions, -224 deletions)

View changed files

📝 .reuse/dep5 (+4 -0)
📝 CMakeLists.txt (+4 -1)
📝 externals/CMakeLists.txt (+7 -0)
externals/renderdoc/renderdoc_app.h (+741 -0)
📝 src/common/config.cpp (+16 -2)
📝 src/common/config.h (+2 -0)
📝 src/common/path_util.cpp (+1 -0)
📝 src/common/path_util.h (+2 -0)
📝 src/core/libraries/gnmdriver/gnmdriver.cpp (+2 -2)
📝 src/core/libraries/kernel/event_queue.cpp (+1 -3)
📝 src/core/libraries/libs.cpp (+1 -1)
📝 src/core/libraries/videoout/driver.cpp (+63 -40)
📝 src/core/libraries/videoout/driver.h (+31 -7)
📝 src/core/libraries/videoout/video_out.cpp (+14 -8)
📝 src/core/libraries/videoout/video_out.h (+2 -4)
📝 src/emulator.cpp (+19 -8)
📝 src/sdl_window.cpp (+7 -1)
📝 src/video_core/amdgpu/liverpool.cpp (+29 -6)
📝 src/video_core/amdgpu/liverpool.h (+22 -0)
📝 src/video_core/amdgpu/pm4_cmds.h (+8 -6)

...and 12 more files

📄 Description

  • Moves presentation to dedicated thread instead of sharing the same thread as input polling. Gives us better control over presentation rate and reduces input latency. Swapchain could block for up to 16ms before preventing inputs during that time.
  • More proper vblank event firing. Before vblank was triggered on every present request which could be a lot more often than 16.6ms. Now we keep track of time when it should actually get triggered.
  • Proper emulation of flip rate limiting. Games can set the number of vblank intervals that need to occur before a flip request can be processed. This means that games like Sonic Mania run at normal speed now.
  • Fix sync problems with cpu side flips. Phyre engine games like Flow and Journey perform flips by calling sceVideooutSubmitFlip directly instead of using gpu flips. The flip also comes from a different thread than main, so using the drawing scheduler that could be in use by the gpu thread is a bad idea. Assign different command buffer scheduler in this case to resolve problem.
  • Small overhaul to scheduler sync interface. It now receives a struct where all sync info like semaphores and fences is stored which gives us more flexibility

Todo:

  • Make presentation rate configurable as from now on FPS will be locked to 60
  • Make use of more advanced extensions like VK_GOOGLE_display_timing and VK_KHR_present_wait for better latency control and to query the refresh rate of the monitor accurately.
  • Test this as it might break things

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/shadps4-emu/shadPS4/pull/303 **Author:** [@raphaelthegreat](https://github.com/raphaelthegreat) **Created:** 7/18/2024 **Status:** ✅ Merged **Merged:** 7/28/2024 **Merged by:** [@psucien](https://github.com/psucien) **Base:** `main` ← **Head:** `present2` --- ### 📝 Commits (10+) - [`cc81ba6`](https://github.com/shadps4-emu/shadPS4/commit/cc81ba6793418f364065546c2f7478a112915a14) video_out: Move presentation to separate thread - [`2e4f32a`](https://github.com/shadps4-emu/shadPS4/commit/2e4f32a8407e8062bed841dd6ce769d5fd087d6d) liverpool: Better sync for CPU flips - [`502dc1c`](https://github.com/shadps4-emu/shadPS4/commit/502dc1cbf38bc38d7f5d232d9651757754c677e2) driver: Make flip blocking - [`fb325e3`](https://github.com/shadps4-emu/shadPS4/commit/fb325e33bd6ce795f3930b28defd5650cade54ae) videoout: Proper flip rate and vblank management - [`6d86c6f`](https://github.com/shadps4-emu/shadPS4/commit/6d86c6f9bfe71d68191a7ed4beacf8745fc47af5) config: Add vblank divider option - [`621d50e`](https://github.com/shadps4-emu/shadPS4/commit/621d50e6817f4aca5bb5054bbd7606431d6629b2) clang format - [`4d3b993`](https://github.com/shadps4-emu/shadPS4/commit/4d3b9932855c686f8cad2e32f5cc9fb3465a73a3) videoout: added `sceVideoOutWaitVblank` - [`1f60b3d`](https://github.com/shadps4-emu/shadPS4/commit/1f60b3d3d274a5ecd0a2b70f977b047dbd192533) clang format - [`c9a1395`](https://github.com/shadps4-emu/shadPS4/commit/c9a13955a1854f4cdee7bd782ad44e559498621a) vk_scheduler: Silly merge conflict - [`72e5462`](https://github.com/shadps4-emu/shadPS4/commit/72e54621c1950164914b662d084213e189231daf) externals: Add renderdoc API ### 📊 Changes **32 files changed** (+1259 additions, -224 deletions) <details> <summary>View changed files</summary> 📝 `.reuse/dep5` (+4 -0) 📝 `CMakeLists.txt` (+4 -1) 📝 `externals/CMakeLists.txt` (+7 -0) ➕ `externals/renderdoc/renderdoc_app.h` (+741 -0) 📝 `src/common/config.cpp` (+16 -2) 📝 `src/common/config.h` (+2 -0) 📝 `src/common/path_util.cpp` (+1 -0) 📝 `src/common/path_util.h` (+2 -0) 📝 `src/core/libraries/gnmdriver/gnmdriver.cpp` (+2 -2) 📝 `src/core/libraries/kernel/event_queue.cpp` (+1 -3) 📝 `src/core/libraries/libs.cpp` (+1 -1) 📝 `src/core/libraries/videoout/driver.cpp` (+63 -40) 📝 `src/core/libraries/videoout/driver.h` (+31 -7) 📝 `src/core/libraries/videoout/video_out.cpp` (+14 -8) 📝 `src/core/libraries/videoout/video_out.h` (+2 -4) 📝 `src/emulator.cpp` (+19 -8) 📝 `src/sdl_window.cpp` (+7 -1) 📝 `src/video_core/amdgpu/liverpool.cpp` (+29 -6) 📝 `src/video_core/amdgpu/liverpool.h` (+22 -0) 📝 `src/video_core/amdgpu/pm4_cmds.h` (+8 -6) _...and 12 more files_ </details> ### 📄 Description * Moves presentation to dedicated thread instead of sharing the same thread as input polling. Gives us better control over presentation rate and reduces input latency. Swapchain could block for up to 16ms before preventing inputs during that time. * More proper vblank event firing. Before vblank was triggered on every present request which could be a lot more often than 16.6ms. Now we keep track of time when it should actually get triggered. * Proper emulation of flip rate limiting. Games can set the number of vblank intervals that need to occur before a flip request can be processed. This means that games like Sonic Mania run at normal speed now. * Fix sync problems with cpu side flips. Phyre engine games like Flow and Journey perform flips by calling sceVideooutSubmitFlip directly instead of using gpu flips. The flip also comes from a different thread than main, so using the drawing scheduler that could be in use by the gpu thread is a bad idea. Assign different command buffer scheduler in this case to resolve problem. * Small overhaul to scheduler sync interface. It now receives a struct where all sync info like semaphores and fences is stored which gives us more flexibility Todo: * Make presentation rate configurable as from now on FPS will be locked to 60 * Make use of more advanced extensions like VK_GOOGLE_display_timing and VK_KHR_present_wait for better latency control and to query the refresh rate of the monitor accurately. * Test this as it might break things --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 21:12:39 +03:00
Sign in to join this conversation.
No milestone
No project
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.

Dependencies

No dependencies set.

Reference
starred/shadPS4#1465
No description provided.