Conditional Calculations

I had expirienced a phenomenon with the GLSL on nVidia board.

I have code something like that:

    // 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?


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.

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.

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.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.