PDA

View Full Version : Conditional Calculations



BishGada
06-11-2007, 09:35 PM
Hi,
I had expirienced a phenomenon with the GLSL on nVidia board.

I have code something like that:



if(condition)
{
// some heavy calculations
}
now when the condition applies and when it doesn't apply I get the same performance (FPS).

when I remove the conditional code I get much higher performance.

my guess is that the compiled code makes the conditional calculations anyway, but don't use the results.

any idea how to check the compiled code and/or how to control compilation optimizations?

thanks,
Guy.

Zengar
06-12-2007, 02:01 AM
Some (older) Nvidia boards have no real brachning, but just conditional writes. Actually I believe this applies to every board before G80. You can check teh compiled code by downloading the NVemulate tool and select all the "write * assembly". Nvidia then stores the assembly code of compiled programs in the application path.

My advice: if condition depends on a uniform (per-model) value, just use two different shaders. But if it depends on some varying inputs, you have tough luck.

mfort
06-12-2007, 02:43 AM
Read GPU Gems 2, There is nice article about it.

The branching is supported on older NV chips but
you have to meet certain requirements:
- The code that is skipped must be pretty large.
(definitely not few instructions)
- Spatial coherence: NV process the pixels in blocks, all pixels in this block must go in the same branch. If not, you get penalty of executing both branches with conditional write as Zengar said. Blocks depend on particular gfx chips. In general it is like 4x4 pixels.
- branching on NV4x/G70 is better then NV3x

Branches are magic a bit.

V-man
06-12-2007, 03:48 AM
Also, it depends on whether it is VS or FS.
VS should be able to do branching even on Geforce FX but it is still possible the driver is doing a bad (or good) job.
Like Zengar said, NVemulate.