A suggestion to optimize a bit the instanced mesh scene node
Posted: Sun Jan 11, 2015 2:19 am
The current implementation isn't the best actually, if you ask me i'd do it other way, i don't know how big can a constants buffer be in DX11 (i don't know either on GL) but it is larger than DX9, that's for sure.
The current implementation adds an extra transformation matrix per vertex. Isn't that overkill? (unless i am missing something that is) Isn't it easier to add an integer that refers to a transformation matrix inside an array instead? And that's using shader instancing, not the "true" instancing DX provides. Since DX9 it is possible to use a secondary buffer to store transformation matrices and indices, i don't know exactly the details, but it gets the one mesh-multiple-copies thing that can be expected of an instancing system. None the less, this is just a small criticism, the current system is really nice.
What i propose though is the usage of a map (and irrlicht has one implemented) instead of an array. The maps provide a much convenient way to add and remove objects from a set which need to be identified, so you can remove an object by its identifier directly, instead of checking through the entire array linearly (which can be, obviously, big) constantly, and the objects can still be accessed iteratively because maps support iterators, thus, if you need to process every item of the map it is also possible. The access time to an item in a map is logaritmic because the map actually "sorts" (i.e. stores the items in a red-black tree) the items when you insert them, so i think it could be an interesting thing to try.
The current implementation adds an extra transformation matrix per vertex. Isn't that overkill? (unless i am missing something that is) Isn't it easier to add an integer that refers to a transformation matrix inside an array instead? And that's using shader instancing, not the "true" instancing DX provides. Since DX9 it is possible to use a secondary buffer to store transformation matrices and indices, i don't know exactly the details, but it gets the one mesh-multiple-copies thing that can be expected of an instancing system. None the less, this is just a small criticism, the current system is really nice.
What i propose though is the usage of a map (and irrlicht has one implemented) instead of an array. The maps provide a much convenient way to add and remove objects from a set which need to be identified, so you can remove an object by its identifier directly, instead of checking through the entire array linearly (which can be, obviously, big) constantly, and the objects can still be accessed iteratively because maps support iterators, thus, if you need to process every item of the map it is also possible. The access time to an item in a map is logaritmic because the map actually "sorts" (i.e. stores the items in a red-black tree) the items when you insert them, so i think it could be an interesting thing to try.