GlFinish() performance boost?
by Marcelo Oliveira · in Torque Game Engine · 07/15/2004 (6:24 am) · 8 replies
Hi there,
By profiling my code I saw that the function glFinish() (at gui\guiCanvas.cc) is eating about 40% of the frame processing time, by removing it I obtained a good performance boost (from 55 to 75fps) with no artifacts.
There's any reason for this function to be there? Maybe some problems with some cpu/gpu combinations?
By profiling my code I saw that the function glFinish() (at gui\guiCanvas.cc) is eating about 40% of the frame processing time, by removing it I obtained a good performance boost (from 55 to 75fps) with no artifacts.
There's any reason for this function to be there? Maybe some problems with some cpu/gpu combinations?
About the author
#2
07/15/2004 (9:08 am)
But the driver somehow doesn't do it by himself? By forcing the glFinish() you don't kill the CPU/GPU paralelism?
#3
I shared this optimization (via Clark's .plan) with Britton at GDC and he said that it gave him a big boost.
07/15/2004 (9:26 am)
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=3730Quote:
1. glFinish. Go into guiCanvas.cc and get rid of the call to glFinish. It simply isn't needed. I've never been able to find any resource on the net or any book suggesting it should be used for real-time work. If you can find such a thing, let me know and I'll eat my hat. Removing this will improve framerates as much as 30% on low end machines. Note: even the "Before" framerates above had this optimization, so in a sense those numbers are understated.
I shared this optimization (via Clark's .plan) with Britton at GDC and he said that it gave him a big boost.
#4
Anyone can clarify this?
@Matthew: Nevermind, thanks. :)
07/15/2004 (9:35 am)
Hmm, I remember reading somewhere on GameDev that rarely in production code do you call glFinish(), as you indeed want the parallelism of the GPU working async of the CPU. But that it's best to leave it in for benchmarking, when you need to know the real fps (or more useful, seconds-per-frame.)Anyone can clarify this?
@Matthew: Nevermind, thanks. :)
#5
I'll take a stab at it.
You can get a performance increase by removing calls to glFinish, since you get back parallelism between the CPU and GPU. Not necessarily as much as the FPS figures report, since accurate benchmarking kind've flies out the window when you remove glFinish - hence my comment about decoupling the FPS counter.
Depending on your driver, when you swap video buffers, you might be getting an implicit glFinish anyway - then again, you might not. Depends on the implementation.
glFinish is mostly used in production code when you're doing something to the graphics buffer with the CPU - like if you wanted to do some of your graphics in OpenGL, and then some more on top in GDI, for example.
07/15/2004 (10:33 am)
Quote:Anyone can clarify this?
I'll take a stab at it.
You can get a performance increase by removing calls to glFinish, since you get back parallelism between the CPU and GPU. Not necessarily as much as the FPS figures report, since accurate benchmarking kind've flies out the window when you remove glFinish - hence my comment about decoupling the FPS counter.
Depending on your driver, when you swap video buffers, you might be getting an implicit glFinish anyway - then again, you might not. Depends on the implementation.
glFinish is mostly used in production code when you're doing something to the graphics buffer with the CPU - like if you wanted to do some of your graphics in OpenGL, and then some more on top in GDI, for example.
#6
07/15/2004 (1:14 pm)
A major concern here is that if you allow extreme parallelism between CPU and GPU the input will lag - in some cases unplayably!
#7
07/15/2004 (2:17 pm)
We can't use some other function such as glFlush() instead of glFinish() to prevent it? or implement a skip count instead of running it every frame?
#8
07/15/2004 (4:01 pm)
You can do whatever you want here... I'd be interested in seeing what your results are with different approaches.
Torque Owner Mz
You haven't boosted performance by taking it out - you've just decoupled your framerate counter from the actual framerate.
www.mevis.de/~uwe/opengl/glFinish.html