DrawIndexed vs DrawIndexedInstanced

Started by
1 comment, last by NathanRidley 10 years, 2 months ago

Just a quick one. It seems to be me that when creating a basic 3D engine, unless you're creating something that you know for a fact ahead of time that is only ever going to exist in one place in your scene (e.g. the ground terrain mesh), then it simplifies things if the default class for rendering meshes always assumes that multiple instances might exist, and therefore caters for that in terms of making an instance buffer available, and the shaders taking instancing information.

So I guess what I'm asking is, is it normal to set things up so you're using DrawIndexInstanced for most scene items, and DrawIndexed for the few other remaining things, or is it more normal to simply render each instance individually with DrawIndexed and leave DrawIndexInstanced for things like particles?

Advertisement

In my experience, it is easier to implement just one of the above for mesh rendering for example. It is rather small as an optimization to handle single mesh drawing as efficiently as possible versus drawing many meshes optimally, so in my opinion it isn't worth the extra code paths or extra shader code.

I had both code paths originally, but eventually I dropped support for single drawing calls as that functionality exists still with the instanced draw calls.

Of course there are cases which are much simpler to handle with single draw calls or cases where instancing is less usefull (such as full screen quads). Also, particles can be drawn with geometry shader so instancing may not be the best approach (geometry shader is used to create the quads on screen from a singular vertex position).

Terrain is another beast then, if you had one unique modelled mesh for a terrain, then instancing may sound unnecessary, but again, if it is a mesh, then your mesh class should have only one code path for drawing 1 or many meshes, so the first answer stands here too. On the other hand, if you are using something like a quadtree terrain LOD, then instancing can be used with drawing different terrain chunks.

Cheers!

Thanks kauna, that was very helpful!

This topic is closed to new replies.

Advertisement