Texture bind performance ?

We encountered a strange performance slowdown in our object renderer on NVIDIA hardware. I didn’t have mesh sorting by material id implemented yet; I knew that this could be issue but I thought it could take 1ms top. But the actual slowdown was way bigger. Later I found out that it was indeed caused by glBindMultiTextureEXT. So I ran a couple of tests, first using one big texture (2048x2048) for all meshes, then adding the sorting by material id.

Times for my test scene (the final object pass):
Objects in the test scene had about 400k tris, ~250 meshes and 42 textures
all textures had the same format, diffuse DXT1, normal 3DC/ATI2 etc.
NV460, drv 306.97, 306.94, 310.33 / AMD 6850 drv 12.10
without sorting: 15ms / 5.0ms
one texture: 3.3ms / 4.0ms
sort by material: 6.8ms 4.3ms

Those numbers are pretty bad for NVIDIA. But the weird thing is that we have no such issue in the terrain renderer, which uses unique textures for every terrain tile, making about ~200 meshes/textures per frame, but the performance there is great. There is no difference in the render states, object renderer follows immediately after the terrain renderer without any changes to the render states. I have tried a lot of tests - a simple shader, non-DSA functions for texture binding, render without terrain etc., without luck - every time I started to change the textures per mesh I hit the wall. (I used two textures for this test and the time was almost 15 ms).

There is a workaround described at [url]http://outerra.blogspot.sk/2012/11/opengl-notes-2-texture-bind-performance.html[/url]

Does anyone have an idea what can cause this large slowdown?

Try to use Texture Atlas. How you are sending shader contants to shaders ? Use Uniform Buffer Objects extension instead of the separate calling glUniform*
Do use glDrawElementsBaseVertex without glDrawElements ?
Try to use NVIDIA Nsight tools.

This is really interesting, and something I will have to look into later on in our project. If there is no conclusion/result here by then I will return with more information. But it might take several months before I get time to look in to this any further.

I wish you the best of luck, and please update with more information if you find out anything more!

http://www.opengl.org/registry/specs/NV/bindless_texture.txt

will give you very fast texture binds, you could even put texture references inside gpu buffers as 64 bit value.