]> git.cworth.org Git - apitrace/commitdiff
Fixed gpu profiling under multiple contexts.
authorJames Benton <jbenton@vmware.com>
Mon, 23 Jul 2012 17:12:27 +0000 (18:12 +0100)
committerJames Benton <jbenton@vmware.com>
Mon, 23 Jul 2012 17:12:27 +0000 (18:12 +0100)
Now flushes the results for all queries on context switch.

retrace/glretrace.hpp
retrace/glretrace_main.cpp
retrace/glretrace_ws.cpp

index 2ab85e03fda624da0d1e51b7cee6a10d2fba5f34..a39f9c1f367477e22832f783f031d9563c8dc854 100644 (file)
@@ -70,6 +70,7 @@ void frame_complete(trace::Call &call);
 
 void updateDrawable(int width, int height);
 
+void flushQueries();
 void beginProfileGPU(trace::Call &call);
 void endProfileGPU(trace::Call &call);
 
index a865b74433faf5ca52daeb5ebdb398b36a1ecaa2..ee19a69bb8ee3eeb6874492662a87182a62c4b5d 100644 (file)
@@ -37,6 +37,17 @@ namespace glretrace {
 bool insideList = false;
 bool insideGlBeginEnd = false;
 
+struct CallQuery
+{
+    GLuint ids[2];
+    unsigned call;
+    const trace::FunctionSig *sig;
+};
+
+static bool firstFrame = true;
+static std::list<CallQuery> callQueries;
+static const int maxActiveCallQueries = 100;
+
 
 void
 checkGlError(trace::Call &call) {
@@ -83,27 +94,14 @@ checkGlError(trace::Call &call) {
     os << "\n";
 }
 
-struct CallQuery
-{
-    GLuint ids[2];
-    unsigned call;
-    const trace::FunctionSig *sig;
-};
-
-static const int maxActiveCallQueries = 256;
-static std::list<CallQuery> callQueries;
-static bool firstFrame = true;
-
 static GLuint64
 getTimestamp() {
-    GLuint query;
-    GLuint64 timestamp;
+    GLuint query = 0;
+    GLuint64 timestamp = 0;
 
     glGenQueries(1, &query);
-
     glQueryCounter(query, GL_TIMESTAMP);
     glGetQueryObjectui64vEXT(query, GL_QUERY_RESULT, &timestamp);
-
     glDeleteQueries(1, &query);
 
     return timestamp;
@@ -112,7 +110,7 @@ getTimestamp() {
 static void
 completeCallQuery(CallQuery& query) {
     /* Get call start and duration */
-    GLuint64 timestamp, duration;
+    GLuint64 timestamp = 0, duration = 0;
     glGetQueryObjectui64vEXT(query.ids[0], GL_QUERY_RESULT, &timestamp);
     glGetQueryObjectui64vEXT(query.ids[1], GL_QUERY_RESULT, &duration);
     glDeleteQueries(2, query.ids);
@@ -121,6 +119,15 @@ completeCallQuery(CallQuery& query) {
     retrace::profiler.addCall(query.call, query.sig->name, timestamp, duration);
 }
 
+void
+flushQueries() {
+    for (std::list<CallQuery>::iterator itr = callQueries.begin(); itr != callQueries.end(); ++itr) {
+        completeCallQuery(*itr);
+    }
+
+    callQueries.clear();
+}
+
 void
 beginProfileGPU(trace::Call &call) {
     if (firstFrame) {
@@ -163,11 +170,7 @@ void
 frame_complete(trace::Call &call) {
     if (retrace::profileGPU) {
         /* Complete any remaining queries */
-        for (std::list<CallQuery>::iterator itr = callQueries.begin(); itr != callQueries.end(); ++itr) {
-            completeCallQuery(*itr);
-        }
-
-        callQueries.clear();
+        flushQueries();
 
         /* Indicate end of current frame */
         retrace::profiler.addFrameEnd(getTimestamp());
@@ -233,6 +236,7 @@ retrace::dumpState(std::ostream &os)
 
 void
 retrace::flushRendering(void) {
+    glretrace::flushQueries();
     glFlush();
 }
 
index ceb5d7f3db9f292c93450334b84a4fea69863c93..fcaa2129dd13b3839427a623c985a128c0a19fd2 100644 (file)
@@ -121,6 +121,8 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, glws::Context *context)
         }
     }
 
+    flushQueries();
+
     bool success = glws::makeCurrent(drawable, context);
 
     if (!success) {