Sign in to follow this  
Metus

Reducing Set[Texture/Render/Sampler][Stage]States

Recommended Posts

I've just implemented my material / texture system in my game engine and found out that it can be up to a 20 + (16 * TexturePass) Set[Texture/Render/Sampler][Stage]States per mesh. A just-bypassed-optimization was to implement the IDirect3DStateblock to batch the states; however, a little question popped my popsicles; what is the cost of the Get[Texture/Render/Sampler][Stage] in comparison to the equivalent Set-function?
unsigned long current_state
pDevice->GetRenderState(D3DRS_ZENABLE, ¤t_state)
if(current_state != new_state) pDevice->SetRenderState(D3DRS_ZENABLE, new_state);
However, instead of 20 + (16 * TexturePass) direct Set-functions, this implementation will be 20 + (16 * TexturePass) if's and an eventual Set for each state... Any opinions?

Share this post


Link to post
Share on other sites
I do this in my Direct3D wrapper so I can create a pure device, which supposedly gives better performance, and you can't do Get*() calls on a pure device. I don't think there's much of a difference though, but don't quote me on that :P

Share this post


Link to post
Share on other sites
You don't need to be thinking about the cost of 'if's nowadays until your profiler points you to something. Basically, this should be faster because it avoids the transition from your app to Direct3D, and if on a PURE device, the transition to the driver too.

Share this post


Link to post
Share on other sites
This should be the job of your scenegraph. It should organize the entities that you want to render based on various criteria, including shader, textures, renderstates, constants, matrices, ect... I use a tree organized like this:


Shader
|- Textures
   |- Renderstates/Texturestates
      |- Non-Matrix Constants
         |- Matrix Constants

Share this post


Link to post
Share on other sites
Thank you all for your replies. Even I have the option to create a pure device so the Get* calls will probably fail or return 0. The reason I "optimized" this part of my engine is that I know that settings states *can* be very expensive.

And ofcource as circlesoft mentioned; this is a job for my scenegraph to sort meshes depending on previously mentioned states.
Thank you again.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this