PDA

View Full Version : glClear too slow?



vince
03-13-2004, 01:19 PM
Hi, this should probably go in the advanced forum, but it doesn't seem to work, so I'll post it here.

Calling a glClear (GL_COLOR_DUFFER_BIT | GL_DEPTH_BUFFER_BIT) is a pretty easy function that should take no time to execute. Most of the time it's true, I experience no problem with the function which execute in aroud 0.03ms.

But here and there a have a spike in that function. The spikes last approx. 7ms. Any idea why that would be slow?

P.S. OS is win2000, computer is a SimFusion (home made card base on Radeon 9700 chips.

roffe
03-13-2004, 03:11 PM
Originally posted by vince:
Calling a glClear (GL_COLOR_DUFFER_BIT | GL_DEPTH_BUFFER_BIT) is a pretty easy function that should take no time to execute.

Clearing buffers is one of the most expensive operations you can make. You should keep it to a minimum. Use scissoring if you want to try to 'save' on clearing parts of the buffer. Personally I would look elsewhere for performance gains.


[This message has been edited by roffe (edited 03-13-2004).]

MrShoe
03-13-2004, 05:37 PM
One thing you can try to do is that if every frame your rendering over every pixel (for example, if you hgave a skybox), then just clear the depth buffer and not the color buffer. This is because you dont need to clear the color buffer since every pixel will be re-rendered anyway.

ZbuffeR
03-14-2004, 02:25 AM
Most of the time it's true, I experience no problem with the function which execute in aroud 0.03ms.

But here and there a have a spike in that function. The spikes last approx. 7ms. Any idea why that would be slow?

Might it be caused by vsync, or a background task running ?

vince
03-14-2004, 04:44 AM
That's weird. I moved my clear screen somewhere else in the code and I don't see the problem with the glClear any more. But it's is somewhere in a different gl function. I don't have any glError and my process is realtime with time critical priority. Don't see what can have a higher priority than that.

SmutMonkey
03-14-2004, 05:49 AM
If you have a very simple scene then it's possible the driver is queueing up a whole load of data and only evicting it once the queue is full. As it's batching you'll see functions returning almost immediately, once the queue is full then a whole load of work needs to be done and you see what should be a simple function take way longer than expected.

If you have an interactive application then you should be able to notice this as input will feel laggy as the driver batches.

One test of this theory would be to read a single pixel from the frame buffer after each frame. You should see overall worse, but more level performance as the driver has to flush the queue constantly to ensure the correct value is returned.

[edited for clarity]

[This message has been edited by SmutMonkey (edited 03-14-2004).]

Jan
03-14-2004, 07:12 AM
Or you could just throw in a glFlush and a glFinish and look if anything changes.

Jan.