Jump to content
  • Advertisement
Sign in to follow this  
Funkymunky

shader slowdown based on color value?

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

I have a pixel shader that runs a huge for loop with many multiplications. I calculate my ultimate pixel color as a grayscale value "ff". So at the end of the program, I have "return float4(ff, ff, ff, 1.0);" This causes a big slowdown when my program is run, especially when the mesh with this pixel shader on it fills up the frame. However, if I leave the loop and all the multiplication stuff but add something like "ff = 0.2;" right before the return statement, it runs at hundreds of frames per second?! I'm still doing all the same calculations, I just set it to a dark gray before returning. What does that mean? What would cause the slowdown?

Share this post


Link to post
Share on other sites
Advertisement
it probably means that the shader compiler is good enough to realize that all your calculations are useless when you add ff=0.2; (thus they can be discarded).

Share this post


Link to post
Share on other sites
Yeah it's pretty easy to optimize away dead code in shaders (as there are no pointers, and no side effects). Therefore any computation that doesn't contribute to the output of the shader will be removed from the compiled program. You should be able to see this by viewing the compiled output of the program (in shader assembly).

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!