Just discovered this excellent post all about branches on GPUs and how they're fine. THEY'RE FINE. Stop worrying about them.
https://medium.com/@jasonbooth_86226/branching-on-a-gpu-18bfc83694f2
Branching on a GPU - Jason Booth - Medium

If you consult the internet about writing a branch of a GPU, you might think they open the gates of hell and let demons in. They will say you should avoid them at all costs, and that you can avoid…

Medium

@TomF But Tom, don’t you like that fuzzy feeling you get when adding yet another permutation?

“Drop the amount of shaders you use from 10% to 5% with this one weird trick!”

@TomF I mean, the whole point of the article is that they're fine until they're not.

@TomF That's a great article, though it's kinda sad that the most important thing in it isn't mentioned in the title and probably isn't noticed by most people:

Creating ways to visually profile the performance of your code is probably the #1 best way to know A) what needs to be optimized and B) whether or not what you did actually optimized it.

Hey, out there! You! Yes, you, the rendering engineer or technical artist! Add more visualization options to your shaders and code! Visual tuning FTW.

@TomF it’s… more complicated. Especially if you consider compute path instead of render.
This is another good post about IFs and branching by @BartWronski

https://bartwronski.com/2021/01/18/is-this-a-branch/

Is this a branch?

Let’s try a new format – “shorts”; small blog posts where I elaborate on ideas that I’d discuss at my twitter, but they either come back over and over, or the short form doesn’t convey all th…

Bart Wronski

@nemo @TomF @BartWronski I do love people explaining how ‘it’s more complicated than that’ TO THE MAN WHO WRITES THE ASSEMBLY LANGUAGE THAT SHADERS RUN ON.

Also Tom, don’t say you ‘discovered’ this post when you asked him to write in the first place because you didn’t want to:)

@jakesimpson @nemo @TomF i don't think it's ok to dismiss and ridicule people commenting on *specific takes* based on the bio or authority of the speaker.
Unproductive and unkind fallacy.

@jakesimpson @nemo @BartWronski As Jake points out, I am a GPU architect and one of my specialities is the bit that controls divergent branching :-)

Bart's post is also excellent. It's a very important point that:

-If you write an "if", the compiler can convert that to a select/step

-If you write a select/step, the compiler can't always convert it back to an "if"

Always be nice to your GPU compiler!

@jakesimpson @TomF @BartWronski although I don’t know the details, If I didn’t know Tom was a professional in my field, I probably wouldn’t be following them.
I appreciate when people talk from a place of specific knowledge, although this still doesn’t make my statement untrue..?
I guess what this kind of exchange is supposed to do is foster discussion (hopefully about the original topic 😉).
@nemo @jakesimpson @BartWronski It's all good - Jake just likes a bit of hyperbole and drama :-)