How to measure timing in OpenGL?

The only sentence that could be understood as blocking-wait until object is available is:

There may be an indeterminate delay before the above query returns.

But all code examples in [b]timer_query.txt/b waits until GL_QUERY_RESULT_AVAILABLE is true. One vague sentence against three pretty clean code examples. We could try to find out how some specific implementation (with drivers that we are currently using) deals with that, but it will not prove anything. Nevertheless, I’ll try it. :wink:

Excuse me for my temper, Dan. :frowning:
You are right about NV 257.21 drivers. glGetQueryObject*() is a blocking function call with a severe performance penalty.


// First approach

	CCounter count;
	count.StartCounter();
//-------------------------------------------------
	GLint available = 0;
	glGetQueryObjectiv(m_iTimeQuery, GL_QUERY_RESULT_AVAILABLE, &available);
	if(available) 
	{
		glGetQueryObjectuiv(m_iTimeQuery, GL_QUERY_RESULT, &m_timeElapsed_ns);
		glBeginQuery(GL_TIME_ELAPSED, m_iTimeQuery);
	}
//-------------------------------------------------
	DrawScene();
//-------------------------------------------------
	if(available) 
		glEndQuery(GL_TIME_ELAPSED);
//-------------------------------------------------
	cpuTime = count.StopCounter(RTT_SEC);
	gpuTime = m_timeElapsed_ns;

cpuTime < 1.1ms
gpuTime = 12.2ms


// Second approach

	CCounter count;
	count.StartCounter();
//-------------------------------------------------
	glBeginQuery(GL_TIME_ELAPSED, m_iTimeQuery);
//-------------------------------------------------
	DrawScene();
//-------------------------------------------------
	glEndQuery(GL_TIME_ELAPSED);
	glGetQueryObjectuiv(m_iTimeQuery, GL_QUERY_RESULT, &m_timeElapsed_ns);
//-------------------------------------------------
	cpuTime = count.StopCounter(RTT_SEC);
	gpuTime = m_timeElapsed_ns;

cpuTime = 13.8ms
gpuTime = 12.2ms

As we can see, in the first approach CPU utilization is very low (about 1ms for the whole drawing cycle plus four additional function calls and two condition checkings), although GPU drawing time is about 12ms. In the second approach, CPU needs more than 13ms.

Is it the same with ATI?

FWIW so late after this post, from memory, yes, querying the result also forces a sync on ATI.