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.
This commit is contained in:
		
							parent
							
								
									6c481e5eb8
								
							
						
					
					
						commit
						282d547ad4
					
				
					 7 changed files with 1 additions and 279 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										16
									
								
								src/gl-fun.h
									
										
									
									
									
								
							
							
						
						
									
										16
									
								
								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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,7 +33,6 @@
 | 
			
		|||
#include "bitmap.h"
 | 
			
		||||
#include "etc-internal.h"
 | 
			
		||||
#include "binding.h"
 | 
			
		||||
#include "perftimer.h"
 | 
			
		||||
#include "debugwriter.h"
 | 
			
		||||
 | 
			
		||||
#include <SDL_video.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -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()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,205 +0,0 @@
 | 
			
		|||
#include "perftimer.h"
 | 
			
		||||
 | 
			
		||||
#include <SDL_timer.h>
 | 
			
		||||
 | 
			
		||||
#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();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue