I haven't really seen any guidelines about efficient shader coding, but
I've come across a few statements here and in the forum now and then,
which I so far assumed to be true. I've now spent the last few days
benchmarking my lightfield/terrain haze framework to see if I can't
squeeze a bit more performance out. Since the results somewhat
contradicted things I have assumed to be true before, I thought I might
share my observations.

1) vertex shader is fast and efficient, fragment and geometry shaders are
comparatively slow and cost performance

I don't know who stated that here, but I intuitively assumed that this
must be right. You can imagine that I was surprised that when I
trivialized the fragment part of my code, the performance didn't change at
all, but when I trivialized the vertex part, the performance doubled.

So it seems like the whole performance drain of my code is caused by an
overworked vertex shader. I then transferred the haze color computations
to the fragment shader, which improved overall performance in my
benchmarks by 20-40%. It seems the optimal results appear for a shared
workload between vertex and fragment shader.

Since for instance 3d clouds run almost exclusively via vertex shader,
this may not be an otherwise irrelevant observation.

2) vertex count doesn't matter

I've read that in the forum as advice to model-builders quite often. For
all I can test, that's wrong. In order to get the same framerate in
default scenery and custom Italy CORINE scenery, I have to set the
visibility range ~a factor 10 different. That's consistent with a hundred
times higher vertex count in the CORINE scenery, or with a factor 10
higher linear resolution of landcover and elevation data, which seems
about right. So the vertex count more or less directly sets my framerate.

This is also relevant for models, because having a cluster of ~ 5 AI
planes (which happened to be stuck into each other) in my view or not
caused a 25% change in framerate, so the vertex count of models matters
compared with the vertex count of scenery and is not some insignificant
correction.

3) shifting constant-per-frame computations out of the shader doesn't
improve performance significantly.

I suggested that here as an idea to improve performance of the cloud
shaders. I was now able to construct a test case for the idea. The
computation in question involved getting a per-frame constant from other
constants, i.e. to compute sqrt(2 * hazeAlt * EarthRadius) where hazeAlt
is the altitude up to which the haze extends which is passed as a uniform.

Computing two of such square root expressions inside the vertex shader or
not computing it makes the difference between 21 and 22 fps in a high
vertex count benchmark test, i.e. 5%. Which is not that much in itself,
but if we would find, track and eliminate all these occasions, the sum of
such small improvements might well go into the 20-30%.

I don't know how much of all that is specific for my system (NVIDIA
GeForce 8600M GT) and how much is general, but my conclusion is that these
things should be tested systematically, and I very much invite others to
test the before/after version of the haze shader code.

(I know that Vivian and Emilian are still working on separating the fog
and light function out, but that's going to take, and if anyone could help
me to get the correct xml conditionals so that the whole framework can be
switched on and off along with the skydome shader, so that the whole thing
can be committed and tested easily, that'd be terrific. I tried, but I
keep messing the effect file up...)

Cheers,

* Thorsten


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to