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

Custom EffectStateManagers causes huge amount of memory allocations
Gillissie
Sounds good!
Thanks for the answer Tom!
chisanga
Thanks!