Instancing question d3d11

Started by
5 comments, last by dblack 12 years, 9 months ago
Suppose I have a vertex buffer that stores 3 meshes. I want to draw the first mesh 5 times, the second mesh 4 times, and the third mesh 7 times, with different world space transformations.

Is it possible to use instancing to do this in 1 draw call? I think I will need at least 3 draw calls.
-----Quat
Advertisement

Suppose I have a vertex buffer that stores 3 meshes. I want to draw the first mesh 5 times, the second mesh 4 times, and the third mesh 7 times, with different world space transformations.

Is it possible to use instancing to do this in 1 draw call? I think I will need at least 3 draw calls.


It is probably possible if you keep your vertices and indices in some sort of random access buffer(eg a structured buffer) and just instance a single triangle an appropraite number of times using the instance index to figure out which vertices to fetch. Not sure about the performance implications of this or if you will run into any limits.


David
If each mesh has it's own vertex/index buffer, then you will need to do it 3 draw calls.
I can merge them into one vertex/index buffer. But still how would you draw them in one draw call? If you drew the entire buffers, then each "instance" is really 3 meshes, which is not what I want, since each 3 needs its own world matrix. I can, of course, only draw a subset of the buffers, but then I am back to breaking this up over 3 Draw Calls.
-----Quat

I can merge them into one vertex/index buffer. But still how would you draw them in one draw call? If you drew the entire buffers, then each "instance" is really 3 meshes, which is not what I want, since each 3 needs its own world matrix. I can, of course, only draw a subset of the buffers, but then I am back to breaking this up over 3 Draw Calls.


You could use the primitive/vertex id to select the instance data you want to use based on which mesh it belongs to. But that would limit you to drawing each mesh the same number of times if you only use one draw call.

This would be similar to a skinned mesh with a bunch of individual components, except you could perhaps remove the need for a per vertex index/weight.


David
You could play some games with your instance data to make it work, but I don't think it would be very efficient. In essence, you would do a normal instanced draw call over all three of the models. Then you could set up your instance data so that it will transform the unwanted copies of each mesh to somewhere else (i.e. off screen or to a single point), but that would require comparing the instance ID with a per-vertex identifier (or maybe a constant buffer with a range to indicate where the mesh boundaries are), and then dynamically deciding what to do with each vertex.

I think just doing three separate draw calls will be much faster :)


I think just doing three separate draw calls will be much faster :)


Yeah, but there does seem to be a bit of an API gap, what would be really handy would be a DrawAuto*Array() function which is similar to DrawAuto() but it takes multiple sets of draw call parameters. Then you can just stream or generate draw call ranges.


David

This topic is closed to new replies.

Advertisement