Brandon Bloom

Back when state blocks were brand spanking new, they yeilded poor performance. I haven't really looked at them since. As I understand it, Effect.Begin(SaveStateMode.SaveState) would use state blocks internally.

Is it ok to rely on this I would like to set all render state in my .fx file techniques rather than in the code. To do this, I would just use .SaveState on everything. Will this hurt performance Are there other things to worry about with this

Thanks,

Brandon



Re: XNA Framework SaveStateMode.SaveState performance

clayman

as i know, use SaveStateMode.SaveState to save all states is a slow operation.
if you use it frequently in your code,will hurt the performance
it's better to manually save those states you need




Re: XNA Framework SaveStateMode.SaveState performance

Brandon Bloom

I was hoping that was not the case :-/ (Maybe someone else will jump in and say that it actually isn't true )

Let's say I have to manally save and manage state...

Is there any interface to see which states are set in the technique I rather not have to hardcode the state changes in C#, I'd prefer that occur in the .fx file and the C# code automagically handle it (even if I have to write that automatic system).





Re: XNA Framework SaveStateMode.SaveState performance

Brandon Bloom

I found this post:

http://blogs.msdn.com/shawnhar/archive/2006/11/13/spritebatch-and-renderstates.aspx

Recent and trusted source... saving state can be slow...

I think this is a big opertunity for improvement in D3D and Xna. It seems to me that this mundane state management could be solved at the driver or framework level.





Re: XNA Framework SaveStateMode.SaveState performance

Brandon Bloom

I keep replying to myself; that usually means I am too tired to be coding and I probably should just go to sleep...

In any case, if I have maybe a dozen different effects, sort by them, and only call Effect.Begin about for each effect, will the state block cost be negligible





Re: XNA Framework SaveStateMode.SaveState performance

Leaf.

There is an interface for managing render state changes within .fx files but it is not yet part of XNA.

You could still manage render state within .fx files with a little discipline and some extra organisation in your application. You could create techniques/passes that are only for setting states. You might have an extra pass for each technique that resets the state for that technique back to some common render state set, so that each effect can assume a common render state set and only set/reset those states that differ. You could even have cascaded sets of state to reduce state changes further (e.g. set alpha blending in one 'group' technique so that all your alpha blending effects don't have to).

Cheers,
Leaf.