Optimizing glFlush()
I am currently trying to optimize my render loop. I am getting a passable framerate, but I would like to improve it.
VTune tells me that I am spending 13,700,000 mcs in my render loop.
Of that time, 11,601,000 mcs are spent inside (or below) the glFlush() call that is itself below wglSwapBuffers().
I'm fairly sure that this can be optimized. I'm also not sure why wglSwapBuffers() calls glFinish() instead of glFlush()... do I really want a blocking call here? I have vsync turned off in my driver.
I haven't tested this on more than one machine, yet; but here are the specs:
2.4 Ghz Xeon, 512 MB ram, GeForce FX 5200 (latest beta drivers)
Try this :
wglSwapIntervalEXT(1); // enable
wglSwapIntervalEXT(0); // disable
Maybe you'll notice difference...
wglSwapIntervalEXT(1); // enable
wglSwapIntervalEXT(0); // disable
Maybe you'll notice difference...
glFinish()/glFlush() tend to involve a ton of work; most other GL calls these days simply buffer operations rather than executing them. You optimize this by doing general graphics optimization.
I also find it interesting that your total time is almost exactly 1/72 of a second. Are you **SURE** that vsync is disabled?
I also find it interesting that your total time is almost exactly 1/72 of a second. Are you **SURE** that vsync is disabled?
Quote:Original post by thewfool
I'm also not sure why wglSwapBuffers() calls glFinish() instead of glFlush()... do I really want a blocking call here?
You want it to swap the buffers before it finishes rendering the frame?
Enigma
Interestingly enough, the driver clearly says "Vertical Sync Off" (as opposed to "Application Controled" or "on") but wglSwapIntervalEXT(0) doubles my framerate. That will teach me to trust my drivers.
Enigma, I want it to *start* swapping the buffers when I call SwapBuffers(). The idea is that the frame render/buffer swap (GPU) and the scene update (CPU) can run in paralell for a portion of the total frame time.
Thanks for the quick help!
Enigma, I want it to *start* swapping the buffers when I call SwapBuffers(). The idea is that the frame render/buffer swap (GPU) and the scene update (CPU) can run in paralell for a portion of the total frame time.
Thanks for the quick help!
Instead of
Loop {
Do CPU Stuff
Do GPU Stuff
glFlush();
}
do
Loop {
Do CPU Stuff
glFlush(); the previous frame of stuff.
Do Current frame GPU stuff.
}
but you have to be certain that your CPU Stuff section does not effect any memory that OpenGL thinks is one of its own vertex or textures.
Quote:Original post by Tinyn
but you have to be certain that your CPU Stuff section does not effect any memory that OpenGL thinks is one of its own vertex or textures.
Can you, please, give an example of "memory that OpenGL thinks is one of its own textures"?
Quote:Original post by thewfool
Interestingly enough, the driver clearly says "Vertical Sync Off" (as opposed to "Application Controled" or "on") but wglSwapIntervalEXT(0) doubles my framerate. That will teach me to trust my drivers.
Enigma, I want it to *start* swapping the buffers when I call SwapBuffers(). The idea is that the frame render/buffer swap (GPU) and the scene update (CPU) can run in paralell for a portion of the total frame time.
Thanks for the quick help!
I suppose you have an NVIDIA card right ? If you have read my post about VBO you know the problem I have with these drivers!
Another interesting consideration is that with a PREVIOUS version of the driver I was able to force enable/disable vsync via configuration panel; now the driver use ALWAYS vsync ON !!!
But I can disable it with wglSwapIntervalEXT(0) via application.
However I dont suggest you to swap before the card has finished the job!!! I dont think this is possible...it it is possible you will see a corrupted animation !!!
Another solution could be call glFlush in other points of your program (to force the card to empty its buffers) although it could be unuseful. I also never seen great difference by using Finish istead of Flush.
Quote:Original post by Tinyn
do
Loop {
Do CPU Stuff
glFlush(); the previous frame of stuff.
Do Current frame GPU stuff.
}
That won't help at all, as glFlush exits immediately. Only glFinish stops and waits until frame is rendered. So, your loop should look like:
GPU Stuff
glFlush();
CPU Stuff
SwapBuffers(); // Which implicitly called glFinish();
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement