   [DX 10] Something I still don't get about Instancing
  Let's take an example case: I've got two vertex buffers representing the two frames of an animated cube which, say, morphs into a sphere (Linear Interpolation - performed withing the Vertex Shader).I want to render 1000 of those, each one with a different position - texture - and a different "interpolation moment" too. Without entering, for now, in detail: is this an instancing scenario?   
  i think it's an instancing problem, and can be solved via stream instancingstream 0 ->src vertices[cube vertices]stream 1 ->dest vertices[sphere vertices]stream 2->time or some morph factor[if you want differend spheres morph differently]matrix[position/rotation e.t..c.c]texture index[you can create texture_array and index it]as alternative you can do it as blend shapes[see nvidia sample along with instancing10 sample in nvidia sdk]if you can use dx11 you can also do that with tesselation shader   ;  Basically you'll just have a third vertex buffer, where each "vertex" is the set of data required for each instance. So in your case it would be a position (or world matrix, if you want orientation too), a texture index, and your interpolation moment. Then you would draw with 1000 instances, and all of the vertices in each instance would get the same set of instance data. You would then use the position and moment, and pass the texture index to your pixel shader where you could use it to index into a texture array.   ;  Thanks both! As a matter of curiosity I now wonder how/why instancing helps rendering speed that much given that after all everything is changing between "drawings": vertices have to be reinterpolated and retransformed everytime anyway - for example. The only thing that the driver seems to save on, is draw calls...   ;  1. no DrawCall overhead as well as setvb/setib/setil2. no Vertex buffer restart, just use same data   ;Quote:Original post by resleThe only thing that the driver seems to save on, is draw calls...That is the only real benefit of instancing: reducing draw call overhead.;Quote:Original post by MJPQuote:Original post by resleThe only thing that the driver seems to save on, is draw calls...That is the only real benefit of instancing: reducing draw call overhead.I think of it, and it is important to state what (what calls) draw call is.Is it DrawIndexedPrimitive() call only, or is it mainly the SetStreamSource, or SetIndicies, or Effect::Begin, or Effect::BeginPass.Lets have a 1000 calls To DrawIndexedPrimitive, while calling SetStreamSorce once per frame. Lets even not change effect technique during whole frame, only uniforms.If per every cube out of your 1000 cubes you will during its render,call to Effect::BeginEffect,Effect::SetTechnique,Effect::BeginPass,Device::SetStreamSource,Device::SetIndicies,Device::SetTexture you have no GPU instancing involved, you only saved GPU memory , if using shared source of verticies of course.But I do not use GPU calls instancing myself, I expect every object to be a different mesh, so I like the idea that I reset streams for every object.In case your objects use different effects, you should reorder them in pattern of shaders you use so you call to Effect::BeginEffect only few times.;  I do not know so I can not tell which draw calls are most expensive, maybe pix can show, drow calls like:-SetStreamSource-SetIndices-DrawIndexedPrimitive-SetTexture-SetUniform-CommitChanges-BeginPass-Begin;Regarding the overhead of Draw calls, I'll chip in the mandatory link to this article. It goes into some detail on the performance issues, mainly that the driver/runtime will do very little with all your Set* calls until you actually draw something. The article was written in the DX9 era, but I think the concepts should still apply (?);  Draw calls are usually the biggest killer in terms of CPU overhead. After that setting shader constants can also be pretty huge...when you start drawing 100's or 1000's of instances of something, the overhead of setting the world matrix starts to really hamper performance since every SetShaderConstant call means appending the data to the command buffer. Instancing offers a much nicer alternative...you simply lock a vertex buffer and memcpy in all of your data. Thus you avoid overloading the GPU's command buffer, and you send all of the data in one operation.So I guess what I said before wasn't really accurate at all, since there's at least 2 main benefits of instancing. :P   