Sign in to follow this  

Cost of redundant state changes

Recommended Posts


while I tried fixing some memory leaks with my directx-application, I noticed a whole lot of warnings about redundant state changes. Not that I perform (m)any state changes in the code myself, instead I am using the directx effect framework, thus getting many things set automatically like:

[code] CullMode = none;
Zenable = false;
StencilEnable = false;
AlphaBlendEnable = true;
Srcblend = One;
Destblend = One;
AlphaTestEnable = false;
ColorWriteEnable = red | green | blue;[/code]

Many times repeatetly. Now, before I start trying out to eliminate these state changes, I just wanted to ask: Is there potential for performance improvements? Like if I render 100 objects with a shader like above, should I try to eliminate the redundand sets of the same states in the effect-file or is it neglegible? (would be quite a lot of work so I only want to try&profile if there is a chance to improve things)..

Share this post

Link to post
Share on other sites
Extra state change calls can definitely add up and introduce additional CPU overhead. Obviously it depends on how many redundant calls there are, but if you start getting into several hundred per frame then it can definitely be worth it to reduce them. For effects, you can implement an ID3DXEffectStateManager in order to filter out redundant state calls. There's a sample in the SDK that shows you how to do it.

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