Archived

This topic is now archived and is closed to further replies.

Worth it minimizing render state changes?

This topic is 5578 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The way I wrote my Direct3D wrapper a while back goes out of its way to minimize any and all render state changes and other similar things. So each time it draws a material, it does stuff like this:
  
if( ms_FillMode != Material->FillMode )
{
    ms_FillMode = Material->FillMode;
    m_Device->SetRenderState( D3DRS_FILLMODE, ms_FillMode );
}
  
ms_FillMode is a static member variable. My question is, is this worth it or is there no real speed improvement? I''m not going to attempt to check it because it might be different on other systems or hard to tell the difference on mine. I''m wondering this now because I was about to add material sorting into the wrapper, so there would be an absolute minimum of render changes - meaning all materials with the same texture will be drawn in a row, and within that category, all ones drawn solid will be drawn in a row, and all ones with gouraud shading, etc. But I''ve been wondering for a while whether it''s even necessary. ~CGameProgrammer( );

Share this post


Link to post
Share on other sites
I don''t know but I''d like to, too! I''ve an idea that as long as you don''t use a pure device, D3D keeps track of render states and returns ~instantly if your change is not actually changing anything. But what do I know? Can anyone confirm or squash this idea (preferably with reliable evidence)?



Read about my game, project #1
NEW (9th September)diaries for week #5

Also I''m selling a few programming books very useful to games coders. Titles on my site.


John 3:16

Share this post


Link to post
Share on other sites

Any method invocation has a cost, so even if it trivially discards your call, you''ve wasted time.

Better to just sort all the data and not have to waste time doing the check, or making changes that you don''t need to.

Share this post


Link to post
Share on other sites
Render State changes are expensive, so yes it is very much worth it to mimimize them. The most efficient method I know of is to use a scene graph. When you render your scene, traverse the scene graph, set any render states that need to be set, render the current node and all of it''s children. Ideally, each state change would add to the exisiting sates already turned on in the current branch. Once you''ve reached a leaf, traverse back up and turn off each renderstate you turned on. Then repeat the process for the next branch.

There are several approaches to this. Dave Eberly discusses this in his book 3D Game Engine Design, and there are several resources online.

Share this post


Link to post
Share on other sites