Sign in to follow this  

Questions about batching and shaders

This topic is 3722 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

Hi there, I've been playing around a bit lately with DX9 and doing some reading. I have read some presentations that can be referenced from the NeXe batching page, and also reading some other sites. These have left me with a question that I hope you can all help with. I'm using shaders, and at the moment I am sorting my list of objects to draw by shader technique, so that I change shaders as little as possible. Then I simply run through all the objects that I have for each technique, and draw them. The next thing that I want to add in is basic texture support, and some of the things that I read suggested that sorting by textures was a good thing as well. Is there a better approach between changing shaders rarely and changing textures rarely, or are they about the same? Or would sorting by one and then the other be a good idea? Another question I have had has to do with transformations and shaders. It seems to me that every time that I change the transformation that is used by the shader then I am going to have to send off another batch. This is talking about the generic world-view-projection. Is there a way to mash multiple objects through a shader that are each supposed to be at different places in the scene and are moving about from frame to frame, without having to call the Draw*Primitive for each one as I change the WVP matrix? Finally, these never seem to make as much sense once I've typed them out as when I think them in my head. I hope that I have made this all make sense, as they are things that I have been thinking about for a wee while now. Any advice or guidance is appreciated. Thanks, Schmacker

Share this post


Link to post
Share on other sites
The questions are fine, they ought to be answered:

1) Sorting by shader is indeed a good idea. Sorting by texture to minimize texture switches is a good idea aswell. At this point, you have conflicting interests. There are algorithms to solve two-dimensional routing problems like this, but my experience says that it is not necessary to solve this problem at all. Simply sort by shader, sub-sort by texture set. It's an suboptimal solution to the problem so you might have some more texture switches than absolutely necessary, but you actually don't miss that much of an improvement opportunity by doing this.

2) The normal way does indeed allow a single transformation chain for one Draw*Primitive. For many small objects, such as foliage for example, this approach is not feasible due to its heavy performance overhead. There are several ways out of this: you can collect many small instances in a larger buffer or you use instancing. Instancing is a method to draw multiple instances of one batch, where each instance gets some individual instance data out of a separate vertex buffer. With instance data being for example the model matrix. Have a look at the instancing examples in the DX SDK, but be warned that these techniques require advanced graphics cards. Gamedev.net does also provide some very good discussions on this topic.

Bye, Thomas

Share this post


Link to post
Share on other sites

This topic is 3722 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.

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