Archived

This topic is now archived and is closed to further replies.

SetRenderState Optimization

This topic is 5587 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''m sure many of you have encountered the DirectX debug output when set to the maximum level: Direct3D8: (WARN) :Ignoring redundant SetRenderState - 8 My question is... do these calls inflict a performance penalty that justifies creating a wrapper function for setting the RenderState? I have already created a wrapper function; but there''s a problem. It works fine and dandy when I''m the only one modifying the RenderStates, but that''s not the case. Some other classes in my program like D3DXMesh and D3DXFont make a ton of changes to the RenderState that completely messes up my wrapper function. So I guess my question is.. what should I do? implement GetRenderState into the wrapper function? Does GetRenderState perform less of a penalty than SetRenderState (if it indeed does have a penalty)? D3DRENDERSTATETYPE renderState[256]; void CDirectX::SetRenderState(D3DRENDERSTATETYPE state, DWORD value) { device->SetRenderState(state, value); return; if (state < 0 || state > 255) CHECKERROR(E_FAIL); if (renderState[state] != value) { renderState[state] = value; device->SetRenderState(state, value); } } Thanks -Brett

Share this post


Link to post
Share on other sites
D3D already optimizes out rendundant SetRenderStates. Those warnings are just telling you that. It would cost more to do a GetRenderState and then set it that just to set it. The biggest cost your paying for is the API call itself. Since D3D already checks to see if the render state actually needs to be changed, you would be duplicating effort across the API boundry.

Either set it or don''t, there''s not much you can do about D3DXMesh and D3DXFont, except replace them with your own code.

Share this post


Link to post
Share on other sites
Thanks for the info. I think i will indeed be creating my own classes to handle fonts and models sense I really dont like them messing around with the RenderState variables. Plus it will lead to mroe optimized batch-processing.

Share this post


Link to post
Share on other sites
Direct3D8: (WARN) :Ignoring redundant SetRenderState - 8

I think this warning says that if it's already set to this it is ignored, so DX already does that job for you.

So you sould not make a wraper that takes any cpu time what so ever to check if it must be changed or not.

Edit:
Sorry, I took to long to write my post...

[edited by - Kern on August 29, 2002 3:53:19 PM]

Share this post


Link to post
Share on other sites
You **should** check to ensure renderstates are not ignored. For D3D to check for you (which it must do to be able to check if the state needs to be changed). I implemented a simple function which filled an array with the values and then a macro which checks the array and sets renderstate only if necessary. Performance went up (by how much is irrelevant - it will depend on how many redundant calls you make).

Neil

WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!

Share this post


Link to post
Share on other sites