From 282d547ad4d4c89c10f8307974a6e1d4fc7ca29e Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Fri, 13 Jun 2014 18:56:10 +0200 Subject: [PATCH] Remove Perftimer classes Performance can still be crudely measured by turning off the framelimit and observing the FPS count. For everything else, there's always callgrind / apitrace. --- CMakeLists.txt | 2 - mkxp.pro | 2 - src/gl-fun.cpp | 21 ----- src/gl-fun.h | 16 +--- src/graphics.cpp | 16 ---- src/perftimer.cpp | 205 ---------------------------------------------- src/perftimer.h | 18 ---- 7 files changed, 1 insertion(+), 279 deletions(-) delete mode 100644 src/perftimer.cpp delete mode 100644 src/perftimer.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b8a802f..9329a92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,7 +128,6 @@ set(MAIN_HEADERS src/util.h src/config.h src/tileatlas.h - src/perftimer.h src/sharedstate.h src/al-util.h src/boost-hash.h @@ -161,7 +160,6 @@ set(MAIN_SOURCE src/etc.cpp src/config.cpp src/tileatlas.cpp - src/perftimer.cpp src/sharedstate.cpp src/gl-fun.cpp ) diff --git a/mkxp.pro b/mkxp.pro index 50356a2..736575b 100644 --- a/mkxp.pro +++ b/mkxp.pro @@ -120,7 +120,6 @@ HEADERS += \ src/util.h \ src/config.h \ src/tileatlas.h \ - src/perftimer.h \ src/sharedstate.h \ src/al-util.h \ src/boost-hash.h \ @@ -152,7 +151,6 @@ SOURCES += \ src/etc.cpp \ src/config.cpp \ src/tileatlas.cpp \ - src/perftimer.cpp \ src/sharedstate.cpp \ src/gl-fun.cpp diff --git a/src/gl-fun.cpp b/src/gl-fun.cpp index 8f7f3bb..63dda6d 100644 --- a/src/gl-fun.cpp +++ b/src/gl-fun.cpp @@ -108,27 +108,6 @@ void initGLFunctions() GL_VAO_FUN; } - if (HAVE_EXT(ARB_timer_query)) - { - gl.timerQuery = true; - -#undef EXT_SUFFIX -#define EXT_SUFFIX "" - GL_TIMER_QUERY_FUN; - } - else if (HAVE_EXT(EXT_timer_query)) - { - gl.timerQuery = true; - -#undef EXT_SUFFIX -#define EXT_SUFFIX "EXT" - GL_TIMER_QUERY_FUN; - } - else - { - gl.timerQuery = false; - } - if (HAVE_EXT(KHR_debug)) { #undef EXT_SUFFIX diff --git a/src/gl-fun.h b/src/gl-fun.h index 1ff5227..f337238 100644 --- a/src/gl-fun.h +++ b/src/gl-fun.h @@ -90,13 +90,7 @@ typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKPROC) (GLDEBUGPROC callback, co /* Vertex attribute */ \ GL_FUN(BindAttribLocation, PFNGLBINDATTRIBLOCATIONPROC) \ GL_FUN(EnableVertexAttribArray, PFNGLENABLEVERTEXATTRIBARRAYPROC) \ - GL_FUN(VertexAttribPointer, PFNGLVERTEXATTRIBPOINTERPROC) \ - /* Queries */ \ - GL_FUN(GenQueries, PFNGLGENQUERIESPROC) \ - GL_FUN(DeleteQueries, PFNGLDELETEQUERIESPROC) \ - GL_FUN(BeginQuery, PFNGLBEGINQUERYPROC) \ - GL_FUN(EndQuery, PFNGLENDQUERYPROC) \ - GL_FUN(GetQueryObjectiv, PFNGLGETQUERYOBJECTIVPROC) + GL_FUN(VertexAttribPointer, PFNGLVERTEXATTRIBPOINTERPROC) #define GL_FBO_FUN \ /* Framebuffer object */ \ @@ -118,10 +112,6 @@ typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKPROC) (GLDEBUGPROC callback, co GL_FUN(DeleteVertexArrays, PFNGLDELETEVERTEXARRAYSPROC) \ GL_FUN(BindVertexArray, PFNGLBINDVERTEXARRAYPROC) -#define GL_TIMER_QUERY_FUN \ - GL_FUN(GetQueryObjecti64v, PFNGLGETQUERYOBJECTI64VPROC) \ - GL_FUN(GetQueryObjectui64v, PFNGLGETQUERYOBJECTUI64VPROC) - #define GL_DEBUG_KHR_FUN \ GL_FUN(DebugMessageCallback, PFNGLDEBUGMESSAGECALLBACKPROC) @@ -133,10 +123,6 @@ struct GLFunctions GL_20_FUN GL_FBO_FUN GL_VAO_FUN - - bool timerQuery; - GL_TIMER_QUERY_FUN - GL_DEBUG_KHR_FUN #undef GL_FUN diff --git a/src/graphics.cpp b/src/graphics.cpp index c5b259f..0da6f53 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -33,7 +33,6 @@ #include "bitmap.h" #include "etc-internal.h" #include "binding.h" -#include "perftimer.h" #include "debugwriter.h" #include @@ -399,9 +398,6 @@ struct GraphicsPrivate FPSLimiter fpsLimiter; - PerfTimer *gpuTimer; - PerfTimer *cpuTimer; - bool frozen; TEXFBO frozenScene; TEXFBO currentScene; @@ -421,9 +417,6 @@ struct GraphicsPrivate fpsLimiter(frameRate), frozen(false) { - gpuTimer = createGPUTimer(frameRate); - cpuTimer = createCPUTimer(frameRate); - TEXFBO::init(frozenScene); TEXFBO::allocEmpty(frozenScene, scRes.x, scRes.y); TEXFBO::linkFBO(frozenScene); @@ -442,9 +435,6 @@ struct GraphicsPrivate ~GraphicsPrivate() { - delete gpuTimer; - delete cpuTimer; - TEXFBO::fini(frozenScene); TEXFBO::fini(currentScene); @@ -556,9 +546,6 @@ void Graphics::update() { shState->checkShutdown(); -// p->cpuTimer->endTiming(); -// p->gpuTimer->startTiming(); - if (p->frozen) return; @@ -582,9 +569,6 @@ void Graphics::update() p->checkResize(); p->redrawScreen(); - -// p->gpuTimer->endTiming(); -// p->cpuTimer->startTiming(); } void Graphics::freeze() diff --git a/src/perftimer.cpp b/src/perftimer.cpp deleted file mode 100644 index 8e59004..0000000 --- a/src/perftimer.cpp +++ /dev/null @@ -1,205 +0,0 @@ -#include "perftimer.h" - -#include - -#include "gl-fun.h" -#include "debugwriter.h" - -struct TimerQuery -{ - GLuint query; - static bool queryActive; - bool thisQueryActive; - - TimerQuery() - : thisQueryActive(false) - { - gl.GenQueries(1, &query); - } - - void begin() - { - if (queryActive) - return; - - if (thisQueryActive) - return; - - gl.BeginQuery(GL_TIME_ELAPSED, query); - queryActive = true; - thisQueryActive = true; - } - - void end() - { - if (!thisQueryActive) - return; - - gl.EndQuery(GL_TIME_ELAPSED); - queryActive = false; - thisQueryActive = false; - } - - bool getResult(GLuint64 *result) - { - if (thisQueryActive) - return false; - - GLint isReady = GL_FALSE; - gl.GetQueryObjectiv(query, GL_QUERY_RESULT_AVAILABLE, &isReady); - - if (isReady != GL_TRUE) - return false; - - gl.GetQueryObjectui64v(query, GL_QUERY_RESULT, result); - - if (gl.GetError() == GL_INVALID_OPERATION) - return false; - - return true; - } - - GLuint64 getResultSync() - { - if (thisQueryActive) - return 0; - - GLuint64 result; - GLint isReady = GL_FALSE; - - while (isReady == GL_FALSE) - gl.GetQueryObjectiv(query, GL_QUERY_RESULT_AVAILABLE, &isReady); - - gl.GetQueryObjectui64v(query, GL_QUERY_RESULT, &result); - - return result; - } - - ~TimerQuery() - { - if (thisQueryActive) - end(); - - gl.DeleteQueries(1, &query); - } -}; - -bool TimerQuery::queryActive = false; - -#define GPU_QUERIES 2 - -struct GPUTimerGLQuery : public PerfTimer -{ - TimerQuery queries[GPU_QUERIES]; - const int iter; - - uint8_t ind; - uint64_t acc; - int32_t counter; - bool first; - - GPUTimerGLQuery(int iter) - : iter(iter), - ind(0), - acc(0), - counter(0), - first(true) - {} - - void startTiming() - { - queries[ind].begin(); - } - - void endTiming() - { - queries[ind].end(); - - swapInd(); - - if (first) - { - first = false; - return; - } - - GLuint64 result; - if (!queries[ind].getResult(&result)) - return; - - acc += result; - - if (++counter < iter) - return; - - Debug() << " " - "Avg. GPU time:" << ((double) acc / (iter * 1000 * 1000)) << "ms"; - - acc = counter = 0; - } - - void swapInd() - { - if (++ind > GPU_QUERIES) - ind = 0; - } -}; - -struct GPUTimerDummy : public PerfTimer -{ - void startTiming() {} - void endTiming() {} -}; - -struct CPUTimer : public PerfTimer -{ - const int iter; - - uint64_t acc; - int32_t counter; - Uint64 ticks; - Uint64 perfFreq; - - CPUTimer(int iter) - : iter(iter), - acc(0), - counter(0), - ticks(0) - { - perfFreq = SDL_GetPerformanceFrequency(); - } - - void startTiming() - { - ticks = SDL_GetPerformanceCounter(); - } - - void endTiming() - { - acc += SDL_GetPerformanceCounter() - ticks; - - if (++counter < iter) - return; - - Debug() << "Avg. CPU time:" << ((double) acc / (iter * (perfFreq / 1000))) << "ms"; - acc = counter = 0; - } -}; - -PerfTimer *createCPUTimer(int iter) -{ - return new CPUTimer(iter); -} - -PerfTimer *createGPUTimer(int iter) -{ - if (gl.timerQuery) - { - return new GPUTimerGLQuery(iter); - } - else - { - Debug() << "GL_EXT_timer_query not present: cannot measure GPU performance"; - return new GPUTimerDummy(); - } -} diff --git a/src/perftimer.h b/src/perftimer.h deleted file mode 100644 index 2208e3e..0000000 --- a/src/perftimer.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef PERFTIMER_H -#define PERFTIMER_H - -struct PerfTimer -{ - virtual ~PerfTimer() {} - virtual void startTiming() = 0; - virtual void endTiming() = 0; -}; - -/* Create timers that run on either CPU or GPU. - * After 'iter' pairs of startTiming()/endTiming(), - * they will calculate the average measurement and - * print it to the console */ -PerfTimer *createGPUTimer(int iter); -PerfTimer *createCPUTimer(int iter); - -#endif // PERFTIMER_H