Impact of variable-length loops on GPU shaders

Posted by Will on Game Development See other posts from Game Development or by Will
Published on 2012-07-06T08:32:04Z Indexed on 2012/07/06 9:24 UTC
Read the original article Hit count: 309

Filed under:
|
|
|

Its popular to render procedural content inside the GPU e.g. in the demoscene (drawing a single quad to fill the screen and letting the GPU compute the pixels).

Ray marching is popular:

enter image description here

This means the GPU is executing some unknown number of loop iterations per pixel (although you can have an upper bound like maxIterations).

How does having a variable-length loop affect shader performance?

Imagine the simple ray-marching psuedocode:

t = 0.f;
while(t < maxDist) {
    p = rayStart + rayDir * t;
    d = DistanceFunc(p);
    t += d;
    if(d < epsilon) {
       ... emit p
       return;
    }
}

How are the various mainstream GPU families (Nvidia, ATI, PowerVR, Mali, Intel, etc) affected? Vertex shaders, but particularly fragment shaders?

How can it be optimised?

© Game Development or respective owner

Related posts about opengl

Related posts about glsl