Render state management in xen (Overview)

Managing render state is very important for two reasons: Reducing bugs and performance.

When an object changes the render state, it's all too easy for that state change to effect the next object that is being drawn.
Further, changing render state can be very expensive. In some situations, removing redundant render state changes can double an applications frame rate.

Every part of xen that deals with render state - be it device render state (things like alpha blending, etc), texture state (texture filtering, etc) right down to what shaders/vertex buffers/textures/constants are bound - they are all internally tracked.
Because they are tracked, redundant changes are skipped, and many changes can be deferred.

For example, If you change the xen alpha blending state, then all you are doing is modifying a value in a structure. It's not until geometry is drawn that the render state will be evaluated, and any differences are set on the GraphicsDevice.

Device render state in xen is bit packed. The majority of XNAs RenderState (and almost every state supported by the Xbox) is stored in a series of four structures. This entire render state totals 16 bytes, the size of a Vector4.

This means swapping render states in and out is very efficient. Pushing and Popping the entire render state is practically instant.
An application can then pre-compute and store the render states it will use. This means assigning render state can be as simple as a one line operation.

The following example can be found in Tutorial 06 (Render state)
//push the render state
//change the alpha blend state (and only the alpha blend state) using a static blend state...
//AlphaBlendState.Additive is a static already setup with additive blending. 
//this line is the complexity equivalent of assigning an integer
state.RenderState.AlphaBlend = AlphaBlendState.Additive;
//pop the render state (Restores the render state to what it was when 'PushRenderState()' was called)

Read about render targets in xen

Home Current Release Documentation Screenshots

Last edited Apr 8, 2010 at 11:55 PM by StatusUnknown, version 20


No comments yet.