Jump to content
  • Advertisement
Sign in to follow this  
jsg007

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

This topic is 3802 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
Advertisement
Yes :(

NVidia says that the recommended maximum use for dynamic branching should be a little portion of pixel such 18x18 or something similar...

I've an 8500 video NVidia card.

Share this post


Link to post
Share on other sites
Wait, branching == if/else statements(to put it short)?!

Yeah, if/else statements don't always seem to be so fast on the gpu.

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
The single product is a very cheap operation and it doesn’t make sense to use branching (that can have a huge impact on performance) to avoid it.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!