Sign in to follow this  
vcGamer

setting shader constants

Recommended Posts

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this