Jump to content
  • Advertisement
Sign in to follow this  

setting shader constants

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

Advertisement
If they're truly constant (i.e. don't change), then setting them inside the shader will be the fastest because they'll be defined and uploaded with the shader microcode when the shader is set. The performance benefit is mostly to the CPU rather than GPU.

Additionally, if you're using HLSL and the constant is declared "const", as with C++ compilers, the HLSL compiler can potentially generate more optimal code because it knows you aren't going to be changing the value of that register arbitrarily.

Share this post


Link to post
Share on other sites
thanks for your help, but I've heard that shader codes (including constant setting) run per-vertex, is it true?
thanks again...

Share this post


Link to post
Share on other sites
The constant-definition instructions aren't run per-vertex; they're interpreted by DirectX when you set the shader and turn into D3DXSet*ShaderConstant calls. So setting constants in your shader code is more efficient, and like said above, can improve the compiler's intelligence.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!