Custom EffectStateManagers causes huge amount of memory allocations

Custom EffectStateManagers are cool and allow the engine to get informed about state changes done by effects. However, it seems there is a big drawback when using custom EffectStateManagers with the current version of MDX.
When calling effect.BeginPass or effect.CommitChanges, all state changes have to be converted from the unmangaged to the managed world. This is done via

<Module>.Microsoft.DirectX.PrivateImplementationDetails.
ManagedD3DXEffectStateManager.Set...

 
calls.
Unfortunately this methods allocate a new Texture, VertexShader, PixelShader or GraphicsStream object for every state
change or shader constant change before they pass the new object to out EffectStateManager.
 
For a simple game with just a few effects like http://www.punchncrunch.com this causes about
3500 Texture allocations per second (280 KB/s)
2000 GraphicsStream allocations per second (70 KB/s)
500 VertexShader allocations per second (15 KB)
500 PixelShader allocations per second (15 KB)
 
all in all this methods generate almost 400 KB/s second which results into many gen0 and also some gen1 garbage collections. If I don't use a custom EffectStateManager the data doesn't have to be converted to the managed world and the number of garbage collections goes down to almost zero (no gen1 collections anymore).
 
So is there a way to use custom EffectStateManagers without the memory allocation problem
Is there a way to reuse GraphicStream objects when locking buffers I know these objects are mostly gen0. However wouldn't it a good idea to use object pools
Will this be changed in the future


Answer this question

Custom EffectStateManagers causes huge amount of memory allocations

  • Gillissie

    Sounds good!
    Thanks for the answer Tom!



  • chisanga

    This is something i've actually known about for a while but couldn't really change for various reasons.  With the CLR2.0 version of MDX I have a lot more freedom in things I can change and this is high on the list of such changes.  It will definitely be addressed within one of our next two SDK releases.

    Thanks!

  • Custom EffectStateManagers causes huge amount of memory allocations