From ef6880fd16a41c2e758a907068e571f155276daf Mon Sep 17 00:00:00 2001 From: James Benton Date: Mon, 23 Jul 2012 18:12:27 +0100 Subject: [PATCH] Fixed gpu profiling under multiple contexts. Now flushes the results for all queries on context switch. --- retrace/glretrace.hpp | 1 + retrace/glretrace_main.cpp | 46 +++++++++++++++++++++----------------- retrace/glretrace_ws.cpp | 2 ++ 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/retrace/glretrace.hpp b/retrace/glretrace.hpp index 2ab85e0..a39f9c1 100644 --- a/retrace/glretrace.hpp +++ b/retrace/glretrace.hpp @@ -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); diff --git a/retrace/glretrace_main.cpp b/retrace/glretrace_main.cpp index a865b74..ee19a69 100644 --- a/retrace/glretrace_main.cpp +++ b/retrace/glretrace_main.cpp @@ -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 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 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, ×tamp); - 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, ×tamp); 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::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::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(); } diff --git a/retrace/glretrace_ws.cpp b/retrace/glretrace_ws.cpp index ceb5d7f..fcaa212 100644 --- a/retrace/glretrace_ws.cpp +++ b/retrace/glretrace_ws.cpp @@ -121,6 +121,8 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, glws::Context *context) } } + flushQueries(); + bool success = glws::makeCurrent(drawable, context); if (!success) { -- 2.43.0