Understanding OpenGL benchmarking

Thomahawk

Newcomer
Hello all,

In my app (win32, c++, opengl), calls to SwapBuffers take about 20ms. What's generally going to cause a wait like that? My algorithm is this:

Code:
while(1){
  start_time = time();
  SwapBuffers(HDC);
  print time() - start_time; //20ms
  
  start_time = time();
  Render();
  print time() - start_time; //6ms
  
  start_time = time();
  DoPhysics();
  print time() - start_time; //2ms

}

Swapbuffers takes more time than Render and DoPhysics combined.

Also, I'm using nvidia's perfmon extensions, and they're informing me that the the program is CPU bound, with the gpu and the driver being idle almost 50% of the time.

I'm so confused as to how this could be? For one thing, I thought SwapBuffers didn't block until you made an opengl call.

-Thomas
 
For GPU timing, you need to make sure you flush the pipe before getting the GPU time. Swap buffers will always cause a pipeline flush, stalling until the GPU finishes all the draw commands, whereas your render calls will not.
 
For best performance, I would suggest the following order:

Render
glFlush() // will force GPu to start working
DoPhysics() // will work while GPU is busy
SwapBuffers()
 
In my app (win32, c++, opengl), calls to SwapBuffers take about 20ms. What's generally going to cause a wait like that?
VSync causes it. Go into your graphics driver's control panel and disable it.
You can also turn it off from the application if you know how to use OpenGL extensions. WGL_EXT_swap_control is the one you need.
 
It's likely Vsync or you're graphics bound, all swap buffers does is put a token in the command buffer.

However if you are running significantly faster (from a CPU standpoint) than you can render it will stall until the next swap before continuing. Most PC drivers this is 2-3 frames, i.e. there can't be more than 2-3 frames of latency between a primitive submit and you seeing it on screen.
 
Cool, but looking at the vsync issue, shouldn't I be getting more like 1/60ms=16.666 or 1/75ms=13ms latency? 20 ms seems high.

-Thomas
 
Back
Top