🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Is branching logic in shaders really still a problem?

Started by
10 comments, last by MJP 2 years ago

@alexpanter that really depends on the low-level ISA of the GPU you're running on. Different GPUs have different setups for how they handle branching and jumps at a low-level, and those ISAs can change quite a bit between architectures and vendors. If you look at how AMD handles a switch on their latest architecture, you'll see they do not generate a jump table and instead they generate multiple compares and branch instructions: https://shader-playground.timjones.io/0616c9387972598b033c0e27074f57c3

Either way, you'll see the same basic high-level behavior with a switch (or loop) as you would with an if statement: any place where different threads within a wave can potentially take a different path, you can end up with multiple paths being executed and your registers will have to be allocated for the worst case (even if that worst case is never executed). In terms of loops this typically means that the shader will execute the loop for the maximum of the iterations within a wave.

This topic is closed to new replies.

Advertisement