Skip to content

Commit

Permalink
Merge pull request #17868 from hrydgard/present-wait-thread-fixes
Browse files Browse the repository at this point in the history
Turn off the present-wait thread
  • Loading branch information
hrydgard committed Aug 8, 2023
2 parents a044d8c + 86db919 commit 38357a2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Common/GPU/MiscTypes.h
Expand Up @@ -21,6 +21,9 @@ typedef std::function<void(InvalidationCallbackFlags)> InvalidationCallback;
// Also, this might be joined with more non-GPU timing information later.
struct FrameTimeData {
uint64_t frameId;

int waitCount;

double frameBegin;
double afterFenceWait;
double firstSubmit;
Expand Down
2 changes: 2 additions & 0 deletions Common/GPU/Vulkan/VulkanFrameData.cpp
Expand Up @@ -113,6 +113,8 @@ VkResult FrameData::QueuePresent(VulkanContext *vulkan, FrameDataShared &shared)
// Can't move these into the if.
VkPresentIdKHR presentID{ VK_STRUCTURE_TYPE_PRESENT_ID_KHR };
VkPresentTimesInfoGOOGLE presentGOOGLE{ VK_STRUCTURE_TYPE_PRESENT_TIMES_INFO_GOOGLE };

uint64_t frameId = this->frameId;
VkPresentTimeGOOGLE presentTimeGOOGLE{ (uint32_t)frameId, 0 }; // it's ok to truncate this. it'll wrap around and work (if we ever reach 4 billion frames..)
if (vulkan->Extensions().KHR_present_id && vulkan->GetDeviceFeatures().enabled.presentId.presentId) {
presentID.pPresentIds = &frameId;
Expand Down
11 changes: 9 additions & 2 deletions Common/GPU/Vulkan/VulkanRenderManager.cpp
Expand Up @@ -25,6 +25,9 @@
#define UINT64_MAX 0xFFFFFFFFFFFFFFFFULL
#endif


#define USE_PRESENT_WAIT 0

using namespace PPSSPP_VK;

// renderPass is an example of the "compatibility class" or RenderPassType type.
Expand Down Expand Up @@ -304,7 +307,7 @@ bool VulkanRenderManager::CreateBackbuffers() {
INFO_LOG(G3D, "Starting Vulkan compiler thread");
compileThread_ = std::thread(&VulkanRenderManager::CompileThreadFunc, this);

if (vulkan_->GetDeviceFeatures().enabled.presentWait.presentWait) {
if (USE_PRESENT_WAIT && vulkan_->Extensions().KHR_present_wait && vulkan_->GetPresentMode() == VK_PRESENT_MODE_FIFO_KHR) {
INFO_LOG(G3D, "Starting Vulkan present wait thread");
presentWaitThread_ = std::thread(&VulkanRenderManager::PresentWaitThreadFunc, this);
}
Expand Down Expand Up @@ -550,7 +553,12 @@ void VulkanRenderManager::PresentWaitThreadFunc() {
const uint64_t timeout = 1000000000ULL; // 1 sec
if (VK_SUCCESS == vkWaitForPresentKHR(vulkan_->GetDevice(), vulkan_->GetSwapchain(), waitedId, timeout)) {
frameTimeData_[waitedId].actualPresent = time_now_d();
frameTimeData_[waitedId].waitCount++;
waitedId++;
} else {
// We caught up somehow, which is a bad sign (we should have blocked, right?). Maybe we should break out of the loop?
sleep_ms(1);
frameTimeData_[waitedId].waitCount++;
}
_dbg_assert_(waitedId <= frameIdGen_);
}
Expand Down Expand Up @@ -583,7 +591,6 @@ void VulkanRenderManager::PollPresentTiming() {
}
}


void VulkanRenderManager::BeginFrame(bool enableProfiling, bool enableLogProfiler) {
double frameBeginTime = time_now_d()
VLOG("BeginFrame");
Expand Down
7 changes: 6 additions & 1 deletion UI/DebugOverlay.cpp
Expand Up @@ -114,9 +114,11 @@ static void DrawFrameTiming(UIContext *ctx, const Bounds &bounds) {

for (int i = 0; i < 8; i++) {
FrameTimeData data = ctx->GetDrawContext()->GetFrameTimeData(6 + i);
FrameTimeData prevData = ctx->GetDrawContext()->GetFrameTimeData(7 + i);
if (data.frameBegin == 0.0) {
snprintf(statBuf, sizeof(statBuf), "(No frame time data)");
} else {
double stride = data.frameBegin - prevData.frameBegin;
double fenceLatency_s = data.afterFenceWait - data.frameBegin;
double submitLatency_s = data.firstSubmit - data.frameBegin;
double queuePresentLatency_s = data.queuePresent - data.frameBegin;
Expand All @@ -135,11 +137,14 @@ static void DrawFrameTiming(UIContext *ctx, const Bounds &bounds) {
computedMargin * 1000.0);
}
snprintf(statBuf, sizeof(statBuf),
"%llu: From start of frame to event:\n"
"* Stride: %0.1f (waits: %d)\n"
"%llu: From start:\n"
"* Past fence: %0.1f ms\n"
"* Submit #1: %0.1f ms\n"
"* Queue-p: %0.1f ms\n"
"%s",
stride * 1000.0,
data.waitCount,
(long long)data.frameId,
fenceLatency_s * 1000.0,
submitLatency_s * 1000.0,
Expand Down

0 comments on commit 38357a2

Please sign in to comment.