Is my depth pass correct?

Started by
4 comments, last by Ashaman73 14 years, 10 months ago
I've been trying to incorporate a depth pass into my terrain rendering pipeline as, in principal, I might get an improvement in performance. My pipeline is like this (with average CPU timings per operation): RenderPrep (produce a list of patches to be drawn) ~0.05 ms RenderDepth (switch on ZWriteEnable; switch off ColorWrite; iterate through patches drawing each using very bare minimum shaders - return float4(0,0,0,0)) ~0.35ms RenderColour (switch off ZWriteEnable; switch on ColorWrite; iterate through patches drawing each using full shaders) ~0.5ms A typical view of my map is ~50 DIP consisting of ~102,400 triangles (since one patch/DIP call is always 2048 tris - 32x32 tilesize). I don't actually get any improvement in framerate with the depth pass, in fact it's quite a bit worse. I think this is partly because the particular area of my terrain that I test with isn't overly 'occlusive', i.e. there aren't that many pixels hidden by closer pixels and partly because I'm not sure if I'm setting up the depth pass correctly. I thought it might get quicker if I view the terrain by positioning the camera in front of a steep slope which occludes most of the terrain, but the performance is still poor. I could maybe try using a bigger patch size (8192 tris - 64x64) which would result in a quarter of the DIP calls, but then I might end up with a lot more 'wasted' triangles, i.e. those that are clipped by the viewport - maybe this doesn't matter so much nowadays. Is this generally the right method for incorporating a Depth Pass? Is it correct also that in some places it's actually going to degrade performance if not many pixels are hidden by closer pixels? Thanks
Advertisement
It seems right,but maybe your pixel shader isn't heavy enough? Vertex buffer switch,transformation in vertex shader,two passes and so on-it may increase total time.
Try to do occlusion query in first Z-pass,and use this info.
The depth only pass typically helps the most (in my experience) when your pixel shading is very expensive. Something like sampling 4 shadow maps, a reflection map, an SSAO map, and some fancy lighting model on top of that would be pretty expensive if you have a high overdraw. Depending on how irregular your terrain is, you may or may not see enough saved pixel shader invocations to make it worth the extra rendering pass.

However, where you can save some performance is when you need the depth pass already. If you are using D3D10, you could utilize the depth pass for SSAO calculations, some motion blur techniques, and some depth of field techniques as well. If you stack up the algorithms that need that information, then the overall benefits will start to add up.

What type of pixel shading are you using for your terrain?
In article about making cryengine 2 some guy from crytek said that early z-pass is good in complicated scenes ( like in crysis ). If you are using early z-pass only with terrain it's going to be slower then without it. But if you are going to put a lot of geometry with highly complicated pixel shaders into the scene its going to change and then you will see benefits from using early z-pass.

So don't worry be happy :)
Thanks for the responses, very useful info. I've removed the depth pass for now as I've profiled another area and got a great boost in performance. I may reinstate it when I add more effects.

Thanks
Some advices:

1. Performance testing the GPU by CPU timing is always a bad idea. In fact you tested the time you need to transfer your data/commands to the GPU, but you don't tested the actual rendering time. So transfering your scene two times is indeed slower than just one time ;_) Take a look at your timing, you got 0.8ms for all your rendering calls which leads to an theoretical fps of ~1250, but I'm sure your actual fps will be lower than that.

2. Just rendering terrain will not really have a heavy impact on the overdraw rate. As soon as you add plants, trees, buildings, characters your overdraw rate will increase, independent from your shader costs. Well, in a forward render engine a pre-z pass will finally be a good idea, as long as you don't have extrem high poly number and batch calls combined with very cheap pixel shaders.

3. Optimizing separated parts of your engine is somewhat inefficient. It's always a time sink leading to more misstakes than improvements :) Try to add more things to your engine before optimizing. It just doesn't matter if your terrain engine runs with 500 or 2000 fps, but it does matter if your final engine runs with 40 instead of 20 fps :)

Well, keep your pre-z pass in and add more things ^^


--
Ashaman

This topic is closed to new replies.

Advertisement