From 9a8710a57c38598600d56c91c6d17b9d67cdb05f Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Thu, 23 May 2024 21:52:24 +0200 Subject: [PATCH] Cap UI overlay rate No need to update each frame, esp. for samples with high frame rates --- base/VulkanUIOverlay.h | 1 + base/vulkanexamplebase.cpp | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/base/VulkanUIOverlay.h b/base/VulkanUIOverlay.h index 3371e799..7169add9 100644 --- a/base/VulkanUIOverlay.h +++ b/base/VulkanUIOverlay.h @@ -65,6 +65,7 @@ namespace vks bool visible{ true }; bool updated{ false }; float scale{ 1.0f }; + float updateTimer{ 0.0f }; UIOverlay(); ~UIOverlay(); diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index e4ea1d10..d80d4b90 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -307,7 +307,6 @@ void VulkanExampleBase::nextFrame() } tPrevEnd = tEnd; - // TODO: Cap UI overlay update rates updateOverlay(); } @@ -690,6 +689,15 @@ void VulkanExampleBase::updateOverlay() if (!settings.overlay) return; + // The overlay does not need to be updated with each frame, so we limit the update rate + // Not only does this save performance but it also makes display of fast changig values like fps more stable + UIOverlay.updateTimer -= frameTimer; + if (UIOverlay.updateTimer >= 0.0f) { + return; + } + // Update at max. rate of 30 fps + UIOverlay.updateTimer = 1.0f / 30.0f; + ImGuiIO& io = ImGui::GetIO(); io.DisplaySize = ImVec2((float)width, (float)height);