SetRenderState Optimization

Started by
3 comments, last by Bretttido 21 years, 7 months ago
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
Advertisement
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.
Stephen ManchesterSenior Technical LeadVirtual Media Vision, Inc.stephen@virtualmediavision.com(310) 930-7349
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.
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]
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?!?!
WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!

This topic is closed to new replies.

Advertisement