Until recently I’ve been a pretty big fan of the ‘if’ node, but have recently discovered / been enlightened by something called ‘branch prediction’ that might potentially make the node a lot more expensive than I thought it was.
For those who don’t know, Branch Prediction (at it’s most basic) basically means that the CPU (and possibly, GPU too) will intelligently predict the outcome of an if-else statement, and is actually an almost necessary part of modern day computing since without it, you’d be forever waiting on tasks to complete and wasting huge chunks of your available resource time.
However I have been advised that using If nodes in shaders can potentially be a bad thing, since there’s often not really any way a processing unit can ‘predict’ the outcome of an IF node in shader languages, and you end up doing much more computational work. I’m just interested to know if this is actually the case and whether Shaders do any form of Branch Prediction at all? If so, how much performance am I realistically likely to gain from refactoring shaders to use different networks as opposed to If nodes? There are times where that isn’t possible of course and I just have to suck it up… but it’s an interesting topic nonetheless!