z-clear performance

silenius

Newcomer
Hi

i know it clearing a z buffer is expensive, but I still have a strange behaviour. I use shadow map so i need to use a z buffer for the shadow.

my shadow map is quite big (2048*2048), i know me crazy. I should off course clear this buffer each frame, but if i do so the performance drop (from 200 fps to 70 fps). So i simulate a fast clear with a pixel shader. In fact this allow me a lot of other optimisations wich make the shadow map generation very fast (like 5% of the total rendering time), so I am pretty happy with it.

anyway i wonder if its normal for the z clear to be so slow. (because some time i need to clear the buffer, and when i do we can feel a little break in the animation).

is there an optimum time to make the zclear (curently it's made in the middle of the render). I tried to make it at the begining of the render, but as I need to change the rendertarget to clear the z that wasn't efficient.

is there a way to clear the z even if it's not the active zbuffer?

thanks
 
silenius said:
Hi
i know it clearing a z buffer is expensive,
Not necessarily. It can be extremely fast - certainly on PowerVR cards and I think I've also seen recommendations by the other IHVs for developers to use clears rather than the old hack of splitting Z space into 2 halves and only clearing every second frame.
So i simulate a fast clear with a pixel shader.
Could you elaborate?
 
Clearing only Z without clearing Stencil at the same time is very slow. This is likely the cause of your problem.
 
the principle is very easy i use a frame counter.

at the begining of the frame i increase the frame counter by one.

once in the pixel shader as the texture contain the depth value I can do a ztest on the texture.

if (current pixel frame counter > stored framecounter)
keep new pixel
else
keep new pixel if ztest succed


so i don't need to clear the z buffer (i wonder if it's this way they do fast clear but it seems very easy and fast for me (you need to really clear the zbuffer from time to time (when you reach the max of the framecounter))

in fact there is a way to make it without any clear, but you need to be sure all screen is redraw at least once every max_framecount time.
 
If you are SURE that you don't have a stencil buffer, then my suggestion is wrong :)
But try passing D3DCLEAR_STENCIL (from memory, could be wrong) and see if it makes any speed difference.
 
Back
Top