Sign in to follow this  

GLSL : branching is pretty much expensive, isn't it?

This topic is 3461 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my fragment program I used an if/else branches to skip 8 dot products depending on some values. But I was surprised to see a huge gain in performance when I removed the if/else branches so the dot products are always performed... Should I use branching only skip very expensive computations? I have a fairly old hardware , GeForce 6600. Does this apply to new videocards too? What about ATI videocards?

Share this post


Link to post
Share on other sites
Branching is not so expensive, but different fragments in a group (usually 3x3 groups) need to be coherent between each them, as threads that processes them need to take the same branch in the fragment group. If not, both branches are executed anyway, and the correct one taken for each fragment, which is expensive and might affect performance.

Also, a GeForce 8 might speed up, as better branching was implemented. nVidia was sucky in branching before the GeForce 8 came out.

Share this post


Link to post
Share on other sites
Branching can be very slow or very fast, depending on how you use it. As has been said, coherence between nearby fragments is very important to get it fast. And the number of branching should obviously be kept to a minimum.

Now, you can gain a lot from branching, if you use it to skip very expensive but seldom used code parts. Skipping a dot product, however, doesn't make a lot of sense, because a dot product is a very, very fast operation. So you introduce a lot of overhead while gaining very little from skipping an already highly optimized operation.

Oh and on the subject of branching - keep in mind that mipmapped texture access within a conditional branch is very often undefined, unless you manually supply the derivatives !

Share this post


Link to post
Share on other sites
Just one question

Is it better a product without sense (let's say color*1.0) that a branching to avoid it? I mean, their cost on the gpu?

Thnaks.

Share this post


Link to post
Share on other sites
In the Nvidia cascades demo secrets paper, nvidia even avoids braching in their parallax occlusion shader. Tested around with this, and I came to the conclusion that you only should use brachning to avoid very expensive computations, elsewhere avoid it.

Share this post


Link to post
Share on other sites

This topic is 3461 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this