demos: Add testing features for smoke
authorjoey-lunarg <joey@lunarg.com>
Thu, 3 Nov 2016 19:49:49 +0000 (13:49 -0600)
committerjoey-lunarg <joey@lunarg.com>
Thu, 10 Nov 2016 16:54:00 +0000 (09:54 -0700)
Smoketest will now output # of frames rendered and elapsed ms.
Command line argument added to limit the rendered frames,
usage: 'smoketest --c <framecount>'

Change-Id: Id6bc0186169b6511823c4406be655f6d8ca18324

demos/smoke/CMakeLists.txt
demos/smoke/Game.h
demos/smoke/Smoke.cpp

index 756b648..bbc0085 100644 (file)
@@ -21,6 +21,7 @@ glsl_to_spirv(Smoke.vert)
 glsl_to_spirv(Smoke.push_constant.vert)
 
 set(sources
+    Game.cpp
     Game.h
     Helpers.h
     HelpersDispatchTable.cpp
index 65357ae..15d3d66 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef GAME_H
 #define GAME_H
 
+#include <chrono>
+#include <iostream>
 #include <string>
 #include <vector>
 
@@ -44,6 +46,8 @@ public:
         bool no_tick;
         bool no_render;
         bool no_present;
+
+        int max_frame_count;
     };
     const Settings &settings() const { return settings_; }
 
@@ -68,7 +72,12 @@ public:
 
     virtual void on_frame(float frame_pred) {}
 
-protected:
+    void print_stats();
+    void quit();
+  protected:
+    int frame_count;
+    std::chrono::time_point<std::chrono::system_clock> start_time;
+
     Game(const std::string &name, const std::vector<std::string> &args)
         : settings_(), shell_(nullptr)
     {
@@ -88,7 +97,13 @@ protected:
         settings_.no_render = false;
         settings_.no_present = false;
 
+        settings_.max_frame_count = -1;
+
         parse_args(args);
+
+        frame_count = 0;
+        // Record start time for printing stats later
+        start_time = std::chrono::system_clock::now();
     }
 
     Settings settings_;
@@ -119,6 +134,9 @@ private:
                 settings_.no_render = true;
             } else if (*it == "-np") {
                 settings_.no_present = true;
+            } else if (*it == "--c") {
+                ++it;
+                settings_.max_frame_count = std::stoi(*it);
             }
         }
     }
index 76a9a90..68f949d 100644 (file)
@@ -734,7 +734,7 @@ void Smoke::on_key(Key key)
     switch (key) {
     case KEY_SHUTDOWN:
     case KEY_ESC:
-        shell_->quit();
+        quit();
         break;
     case KEY_UP:
         camera_.eye_pos -= glm::vec3(0.05f);
@@ -763,6 +763,14 @@ void Smoke::on_tick()
 
 void Smoke::on_frame(float frame_pred)
 {
+    // Limit number of frames if argument was specified
+    if (settings_.max_frame_count != -1 &&
+        frame_count == settings_.max_frame_count) {
+        quit();
+        return;
+    }
+    frame_count++;
+
     auto &data = frame_data_[frame_data_index_];
 
     // wait for the last submission since we reuse frame data