Jump to content
  • Advertisement
Sign in to follow this  
thewfool

Optimizing glFlush()

This topic is 4835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)

Share this post


Link to post
Share on other sites
Advertisement
Try this :

wglSwapIntervalEXT(1); // enable
wglSwapIntervalEXT(0); // disable

Maybe you'll notice difference...

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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"?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!