Jump to content
  • Advertisement
Sign in to follow this  
g0nzo

[HLSL] If statement or separate technique?

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

Hi, I'm doing a shader where I can use either interpolated or non-interpolated value. The values are read from the same texture (they are in different channels). Should I pass a bool variable "useInterpolatedValue" to a shader and just create if statement to read the value from specific channel or should I create 2 separate techniques? Will this if statement have big impact on performance or I shouldn't worry about it?

Share this post


Link to post
Share on other sites
Advertisement
It depends. In cards that are relatively new and support true branching, the only hit in performance would be evaluating the "if" statement. In older cards, no instruction is skipped. For example:


if (useInterpolatedValue)
{
ComputeInterpolated();//this is executed
}
else
{
ComputeNonInterpolated();//this is executed too
}



All calculations, interpolated and non-interpolated will be executed, and at the end the shader just throws away the results it doesn't want.

Share this post


Link to post
Share on other sites
Thanks!

I didn't know that both branches are executed. Fortunately my shader uses it just for defining variable, so no calculation are done inside the branches.

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!