From cca3254becdf793b9335a1f21bcda2c0909f4d1a Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Wed, 21 Mar 2018 23:16:20 +0100 Subject: Initial benchmark support. Finally no more manual stopwatch usage... --- BuddhaTest/src/BuddhaTest.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'BuddhaTest/src/BuddhaTest.cpp') diff --git a/BuddhaTest/src/BuddhaTest.cpp b/BuddhaTest/src/BuddhaTest.cpp index 55fe2c2..0ae94b0 100644 --- a/BuddhaTest/src/BuddhaTest.cpp +++ b/BuddhaTest/src/BuddhaTest.cpp @@ -169,8 +169,10 @@ int main(int argc, char * argv[]) uint64_t totalIterationCount{0}; uint64_t lastMessage{0}; + const auto startTime{std::chrono::high_resolution_clock::now()}; + auto frameStop{startTime}; /* Loop until the user closes the window */ - while (!glfwWindowShouldClose(window)) + while (!glfwWindowShouldClose(window) && (settings.benchmarkTime == 0 || std::chrono::duration_cast(frameStop-startTime).count() < settings.benchmarkTime)) { auto frameStart{std::chrono::high_resolution_clock::now()}; totalIterationCount += iterationsPerFrame; @@ -205,7 +207,7 @@ int main(int argc, char * argv[]) /* Poll for and process events */ glfwPollEvents(); - auto frameStop{std::chrono::high_resolution_clock::now()}; + frameStop = std::chrono::high_resolution_clock::now(); const auto dur{std::chrono::duration_cast(frameStop-frameStart)}; auto frameDuration{dur.count()}; if(frameDuration > 0) @@ -227,14 +229,18 @@ int main(int argc, char * argv[]) } //settings.pngFilename = "Don'tForgetToRemoveThisLine.png"; - if(!settings.pngFilename.empty()) + if(!settings.pngFilename.empty() || settings.benchmarkTime != 0) { glMemoryBarrier(GL_ALL_BARRIER_BITS); std::vector readBackBuffer(pixelCount*3); glBindBuffer(GL_SHADER_STORAGE_BUFFER, drawBuffer); glGetBufferSubData(GL_SHADER_STORAGE_BUFFER,0,4 *3* pixelCount,readBackBuffer.data()); - Helpers::WriteOutputPNG(settings.pngFilename,readBackBuffer,settings.imageWidth,bufferHeight, settings.pngGamma, settings.pngColorScale); + if(settings.benchmarkTime != 0) + Helpers::PrintBenchmarkScore(readBackBuffer); + + if(!settings.pngFilename.empty()) + Helpers::WriteOutputPNG(settings.pngFilename,readBackBuffer,settings.imageWidth,bufferHeight, settings.pngGamma, settings.pngColorScale); } //a bit of cleanup -- cgit v1.2.3