Pixel Shader assembly is better than anything you've ever seen. Seriously, I'm implementing a compiler right now and everything's not so hard (although it ain't a walk in the park...), but pixel shaders, man. What crazy guys.
In pixel shaders, you have
n pipelines. This means you can process
n pixels at once. Now, branching is
really bad, because it
stalls all pipelines, just for one pipeline. Branching is terrible. So what does the compiler do? It turns this code:
// 1: directional lightelse if (light_used == 1) { L = -light_direction;}// 2: point lightelse if (light_used == 2) { L = light_position - position;}
into something like this...
_itmp = light_used - 1L = (-light_direction * (1 - _itmp)) + ( (light_position - position) * _itmp );
Pow, branch removed. Faster. But it can do it with way more complex examples. It took me a while to think up something as simple as that, but it can handle way more involved logic. And it can do it with switch statements, everything. Incredible.