This is a quite wide subject which implies a lot of topics such as the platform or the compiler, but I think that it could be useful for everyone to know more about this.

A common mistake is to think that conditionals are bad when writing shader but the real bad thing is branching, right ?

I would love to know more about the difference between conditionals and branching with simple concrete examples and how to solve common issues.


  • 1
    $\begingroup$ Pretty much any 'divergence' is going to cause a relative loss in peak shader efficiency: If A SIMD GPU has N parallel units but only M of them are doing 'useful' work, be that because of a 'mask bit' or branching, it's still only going to be achieving M/N efficiency. $\endgroup$ – Simon F Jul 17 '20 at 13:42
  • $\begingroup$ This problem was discussed on stackoverflow link: stackoverflow.com/questions/37827216/… $\endgroup$ – Thomas Jul 17 '20 at 16:02
  • 1
    $\begingroup$ one example would be: if(uniformVariable == 1)... not branching, because every invocation is end up in the same condition.. but if(texture(tex,interpolatedCoordinate) == 1) this is branching, because some will go into the condition and other invocations not $\endgroup$ – Thomas Jul 17 '20 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.