Jump to content
  • Advertisement
Sign in to follow this  
Perceptron

OpenGL Static & Dynamic Branching in Cg

This topic is 3833 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

Hey guys! I'm quite sure that this question was asked rather often, but I simply didn't find them, so I ask again: How could you use Static & Dynamic Branching with Cg and OpenGL? From what I've heard, Dynamic Branching is just if-else. If so, this question would be answered. But how can you use static branching? I've seen #ifdef and #endif statements in some shaders, but I'm not sure wether they are static branching or how to activate a branch from within C++. If someone has a link to a description or to an post, that would be already fine. Thanks in advance Gregor

Share this post


Link to post
Share on other sites
Advertisement
Actually what you describe (#ifdef etc.) is not actual branching but just compile-time code processing (just like macros in C) - e.g. it will get resolved by the shader compiler and code that gets sent to GPU will not contain any branches. Static branching is when you got classic if/else conditional but the branch taken is known before GPU executes the shader for the vertex/fragment/etc. - eg. you send uniform or attribute variable 'var' and then have code such as "if (var>0.5)". Dynamic branching is where the branch taken depends on computation done on the shader eg. "y = sin(x); if (y>0.5) ...".

Share this post


Link to post
Share on other sites
Ahh, okay. But are static branches faster than dynamic branches?
AS I heard, the GPU desides before executing the shaders which branch to use, so the if-condition won't be processed. Is that true?

Share this post


Link to post
Share on other sites
The actual speed always depends on implementation, but generally, yes. The main point is however, that dynamic branching (unlike static) is only supported on cards with SM3.0 and higher.

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!