Created
April 6, 2020 08:30
-
-
Save haxpor/8f9a14f02ed00cfd2fbaeef4055f38dc to your computer and use it in GitHub Desktop.
Patch including FPS computation logic on top of source code so far at https://vulkan-tutorial.com/Drawing_a_triangle/Drawing/Rendering_and_presentation (grab its source looking at the bottom of C++ link). Apply patch via `patch main.cpp < patch`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- main-ref.cpp 2020-04-06 15:22:30.210006554 +0700 | |
+++ main2.cpp 2020-04-06 15:23:11.217588339 +0700 | |
@@ -13,11 +13,13 @@ | |
#include <cstdint> | |
#include <optional> | |
#include <set> | |
+#include <iomanip> | |
const int WIDTH = 800; | |
const int HEIGHT = 600; | |
const int MAX_FRAMES_IN_FLIGHT = 2; | |
+const float FPS_GRANULARITY_SEC = 1.0f; // how often to update FPS | |
const std::vector<const char*> validationLayers = { | |
"VK_LAYER_KHRONOS_validation" | |
@@ -106,6 +108,10 @@ | |
std::vector<VkFence> imagesInFlight; | |
size_t currentFrame = 0; | |
+ uint32_t numRenderedFrames = 0; | |
+ float fps = 0.0f; | |
+ double prevTime = 0.0f; | |
+ | |
void initWindow() { | |
glfwInit(); | |
@@ -135,6 +141,16 @@ | |
while (!glfwWindowShouldClose(window)) { | |
glfwPollEvents(); | |
drawFrame(); | |
+ | |
+ ++numRenderedFrames; | |
+ const double currTime = glfwGetTime(); | |
+ const double diffTime = currTime - prevTime; | |
+ if (diffTime >= FPS_GRANULARITY_SEC) { | |
+ prevTime = currTime; | |
+ fps = numRenderedFrames / diffTime; | |
+ std::cout << std::fixed << std::setprecision(2) << std::setfill('0') << fps << " FPS\n"; | |
+ numRenderedFrames = 0; | |
+ } | |
} | |
vkDeviceWaitIdle(device); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment