X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=glretrace_main.cpp;h=11f34ce8200ca16215780c0fbfce976f918ca414;hb=8c5ab641f8481289a9ea18eec621a3eacc1e1caf;hp=fdc52ab740beb5283324400587f1e61b2b79e851;hpb=2ccef5448acf58e536a647780dd9c4c0a236d7d2;p=apitrace diff --git a/glretrace_main.cpp b/glretrace_main.cpp index fdc52ab..11f34ce 100644 --- a/glretrace_main.cpp +++ b/glretrace_main.cpp @@ -26,9 +26,12 @@ #include +#include "os_binary.hpp" #include "os_string.hpp" +#include "os_time.hpp" #include "image.hpp" #include "retrace.hpp" +#include "trace_callset.hpp" #include "glproc.hpp" #include "glstate.hpp" #include "glretrace.hpp" @@ -40,7 +43,7 @@ bool double_buffer = true; bool insideGlBeginEnd = false; trace::Parser parser; glws::Profile defaultProfile = glws::PROFILE_COMPAT; -glws::Visual *visual = NULL; +glws::Visual *visual[glws::PROFILE_MAX]; glws::Drawable *drawable = NULL; glws::Context *context = NULL; @@ -49,9 +52,10 @@ long long startTime = 0; bool wait = false; bool benchmark = false; -const char *compare_prefix = NULL; -const char *snapshot_prefix = NULL; -enum frequency snapshot_frequency = FREQUENCY_NEVER; +static const char *compare_prefix = NULL; +static const char *snapshot_prefix = NULL; +static trace::CallSet snapshot_frequency; +static trace::CallSet compare_frequency; unsigned dump_state = ~0; @@ -118,6 +122,11 @@ updateDrawable(int width, int height) { return; } + // Ignore zero area viewports + if (width == 0 || height == 0) { + return; + } + // Check for bound framebuffer last, as this may have a performance impact. GLint draw_framebuffer = 0; glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &draw_framebuffer); @@ -132,9 +141,11 @@ updateDrawable(int width, int height) { } -void snapshot(unsigned call_no) { - if (!drawable || - (!snapshot_prefix && !compare_prefix)) { +static void +snapshot(unsigned call_no) { + assert(snapshot_prefix || compare_prefix); + + if (!drawable) { return; } @@ -151,7 +162,7 @@ void snapshot(unsigned call_no) { } } - image::Image *src = glstate::getDrawBufferImage(GL_RGBA); + image::Image *src = glstate::getDrawBufferImage(); if (!src) { return; } @@ -188,11 +199,6 @@ void frame_complete(trace::Call &call) { if (!drawable->visible) { retrace::warning(call) << "could not infer drawable size (glViewport never called)\n"; } - - if (snapshot_frequency == FREQUENCY_FRAME || - snapshot_frequency == FREQUENCY_FRAMEBUFFER) { - snapshot(call.no); - } } @@ -209,8 +215,32 @@ static void display(void) { trace::Call *call; while ((call = parser.parse_call())) { + bool swapRenderTarget = call->flags & trace::CALL_FLAG_SWAP_RENDERTARGET; + bool doSnapshot = + snapshot_frequency.contains(*call) || + compare_frequency.contains(*call) + ; + + // For calls which cause rendertargets to be swaped, we take the + // snapshot _before_ swapping the rendertargets. + if (doSnapshot && swapRenderTarget) { + if (call->flags & trace::CALL_FLAG_END_FRAME) { + // For swapbuffers/presents we still use this call number, + // spite not have been executed yet. + snapshot(call->no); + } else { + // Whereas for ordinate fbo/rendertarget changes we use the + // previous call's number. + snapshot(call->no - 1); + } + } + retracer.retrace(*call); + if (doSnapshot && !swapRenderTarget) { + snapshot(call->no); + } + if (!insideGlBeginEnd && drawable && context && call->no >= dump_state) { @@ -225,9 +255,9 @@ static void display(void) { glFlush(); long long endTime = os::getTime(); - float timeInterval = (endTime - startTime) * 1.0E-6; + float timeInterval = (endTime - startTime) * (1.0 / os::timeFrequency); - if (retrace::verbosity >= -1) { + if ((retrace::verbosity >= -1) || (retrace::profiling)) { std::cout << "Rendered " << frame << " frames" " in " << timeInterval << " secs," @@ -248,13 +278,15 @@ static void usage(void) { "Replay TRACE.\n" "\n" " -b benchmark mode (no error checking or warning messages)\n" + " -p profiling mode (run whole trace, dump profiling info)\n" " -c PREFIX compare against snapshots\n" + " -C CALLSET calls to compare (default is every frame)\n" " -core use core profile\n" " -db use a double buffer visual (default)\n" " -sb use a single buffer visual\n" " -s PREFIX take snapshots; `-` for PNM stdout output\n" - " -S FREQUENCY snapshot frequency: frame (default), framebuffer, or draw\n" - " -v verbose output\n" + " -S CALLSET calls to snapshot (default is every frame)\n" + " -v increase output verbosity\n" " -D CALLNO dump state at specific call no\n" " -w wait on final frame\n"; } @@ -262,6 +294,8 @@ static void usage(void) { extern "C" int main(int argc, char **argv) { + assert(compare_frequency.empty()); + assert(snapshot_frequency.empty()); int i; for (i = 1; i < argc; ++i) { @@ -277,10 +311,19 @@ int main(int argc, char **argv) benchmark = true; retrace::verbosity = -1; glws::debug = false; + } else if (!strcmp(arg, "-p")) { + retrace::profiling = true; + retrace::verbosity = -1; + glws::debug = false; } else if (!strcmp(arg, "-c")) { compare_prefix = argv[++i]; - if (snapshot_frequency == FREQUENCY_NEVER) { - snapshot_frequency = FREQUENCY_FRAME; + if (compare_frequency.empty()) { + compare_frequency = trace::CallSet(trace::FREQUENCY_FRAME); + } + } else if (!strcmp(arg, "-C")) { + compare_frequency = trace::CallSet(argv[++i]); + if (compare_prefix == NULL) { + compare_prefix = ""; } } else if (!strcmp(arg, "-D")) { dump_state = atoi(argv[++i]); @@ -296,25 +339,15 @@ int main(int argc, char **argv) return 0; } else if (!strcmp(arg, "-s")) { snapshot_prefix = argv[++i]; - if (snapshot_frequency == FREQUENCY_NEVER) { - snapshot_frequency = FREQUENCY_FRAME; + if (snapshot_frequency.empty()) { + snapshot_frequency = trace::CallSet(trace::FREQUENCY_FRAME); } if (snapshot_prefix[0] == '-' && snapshot_prefix[1] == 0) { + os::setBinaryMode(stdout); retrace::verbosity = -2; } } else if (!strcmp(arg, "-S")) { - arg = argv[++i]; - if (!strcmp(arg, "frame")) { - snapshot_frequency = FREQUENCY_FRAME; - } else if (!strcmp(arg, "framebuffer")) { - snapshot_frequency = FREQUENCY_FRAMEBUFFER; - } else if (!strcmp(arg, "draw")) { - snapshot_frequency = FREQUENCY_DRAW; - } else { - std::cerr << "error: unknown frequency " << arg << "\n"; - usage(); - return 1; - } + snapshot_frequency = trace::CallSet(argv[++i]); if (snapshot_prefix == NULL) { snapshot_prefix = ""; } @@ -330,7 +363,10 @@ int main(int argc, char **argv) } glws::init(); - visual = glws::createVisual(double_buffer, defaultProfile); + visual[glws::PROFILE_COMPAT] = glws::createVisual(double_buffer, glws::PROFILE_COMPAT); + visual[glws::PROFILE_CORE] = glws::createVisual(double_buffer, glws::PROFILE_CORE); + visual[glws::PROFILE_ES1] = glws::createVisual(double_buffer, glws::PROFILE_ES1); + visual[glws::PROFILE_ES2] = glws::createVisual(double_buffer, glws::PROFILE_ES2); for ( ; i < argc; ++i) { if (!parser.open(argv[i])) { @@ -342,8 +378,11 @@ int main(int argc, char **argv) parser.close(); } - - delete visual; + + for (int n = 0; n < glws::PROFILE_MAX; n++) { + delete visual[n]; + } + glws::cleanup(); return 0;