aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2018-03-21 23:16:20 +0100
committerAndreas Grois <andi@grois.info>2018-03-21 23:16:20 +0100
commitcca3254becdf793b9335a1f21bcda2c0909f4d1a (patch)
tree9f6f38f57774cf08e6968052a1c77dd2941dc194
parent0c7b45b4e84aa197ada7391007f7d1610c92476c (diff)
Initial benchmark support.
Finally no more manual stopwatch usage...
-rw-r--r--BuddhaTest/include/Helpers.h4
-rw-r--r--BuddhaTest/src/BuddhaTest.cpp14
-rw-r--r--BuddhaTest/src/Helpers.cpp14
3 files changed, 26 insertions, 6 deletions
diff --git a/BuddhaTest/include/Helpers.h b/BuddhaTest/include/Helpers.h
index b4954c0..2b0ea88 100644
--- a/BuddhaTest/include/Helpers.h
+++ b/BuddhaTest/include/Helpers.h
@@ -14,6 +14,8 @@ namespace Helpers
void WriteOutputPNG(const std::string& path, const std::vector<uint32_t>& data, unsigned int width, unsigned int bufferHeight, double gamma, double colorScale);
+ void PrintBenchmarkScore(const std::vector<uint32_t>& data);
+
/** Wraps around a C file descriptor. Libpng could be taught to use C++ streams, but I'm too lazy and rather wrap this ugly thing up, so it gets cleaned... */
class ScopedCFileDescriptor
{
@@ -56,6 +58,8 @@ namespace Helpers
unsigned int ignoreMaxBufferSize = 0;
unsigned int printDebugOutput = 0;
+ unsigned int benchmarkTime = 0;
+
bool CheckValidity();
bool ParseCommandLine(int argc, char * argv[]);
};
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<std::chrono::seconds>(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<std::chrono::microseconds>(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<uint32_t> 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
diff --git a/BuddhaTest/src/Helpers.cpp b/BuddhaTest/src/Helpers.cpp
index 2a687d2..b4c39c0 100644
--- a/BuddhaTest/src/Helpers.cpp
+++ b/BuddhaTest/src/Helpers.cpp
@@ -338,7 +338,8 @@ namespace Helpers
{"--imageColorScale",&pngColorScale},
{"--output", &pngFilename},
{"--ignoreMaxBufferSize", &ignoreMaxBufferSize},
- {"--printDebugOutput", &printDebugOutput}
+ {"--printDebugOutput", &printDebugOutput},
+ {"--benchmark", &benchmarkTime}
};
for(int i=1; i < argc;++i)
@@ -368,6 +369,7 @@ namespace Helpers
"--globalWorkgroupSizeZ [integer] : How often the local work group should be invoked per frame. Values up to 65535 are guaranteed to work. Default is 1." << std::endl <<
"--targetFrameRate [integer] : The number of iterations per frame will dynamically adjust to approximately reach this framerate. Default: 60." << std::endl <<
"--printDebugOutput [0,1] : If set to 1, every orbitLength a message will be printed to stdout. Default 0." << std::endl <<
+ "--benchmark [integer] : Run the application for this many seconds, and then print the maximum non-normalized color value. 0 by default, meaning no benchmark." << std::endl <<
"--ignoreMaxBufferSize [0,1] : If set to 1, a failed maximum buffer size check is not treated as error. Some graphics drivers report lower values than their absolute limit. Do this on your own risk, though." << std::endl;
return false;
}
@@ -414,7 +416,15 @@ namespace Helpers
bool DoesFileExist(const std::string &path)
{
std::ifstream f(path);
- return f.good();
+ return f.good();
+ }
+
+ void PrintBenchmarkScore(const std::vector<uint32_t> &data)
+ {
+ uint32_t maxValue{0};
+ for(auto entry : data)
+ maxValue = std::max(maxValue,entry);
+ std::cout << "Benchmark Score (can only be compared for same parameters): " << maxValue << std::endl;
}
}