View Full Version : Horrific uniform buffers bug on NVidia drivers

09-16-2009, 11:52 AM
Is anyone else experiencing errors with instanced rendering on NVidia drivers with OpenGL 2.1? I have objects randomly dancing around the screen, as if the matrix data in the uniform buffer is not being updated from the last batch. I tried an old application of mine that was working fine a year ago, and it displays the same error. The driver is 190.62 (the latest).

Alfonse Reinheart
09-16-2009, 12:03 PM
What kind of instancing are you using?

09-16-2009, 12:21 PM
glDrawElementsInstancedARB() and using uniform buffers for storing the matrices.

I think this is a uniform buffer bug because it does not occur when I store the data in a float texture.

09-16-2009, 03:00 PM
Smells like data layout problem. Check if you 're updating your uniform buffer correctly.

09-16-2009, 06:27 PM
The same program worked perfectly with older drivers. It's just an array of matrices, and the shader uses gl_Instance_ID for the index of the matrix:

bindable uniform mat4 instancematrix[ MAX_PASS_SIZE ];

Is anyone using bindable uniforms in OpenGL 2.1 with success?

Here is my code:

At startup create one uniform buffer and allocate the size:

glgetIntegerv GL_MAX_BINDABLE_UNIFORM_SIZE_EXT,Varptr TBatch.MaxPassSize' get max uniform buffer size
TBatch.MaxPassSize=Floor(TBatch.MaxPassSize/64)' divide by 64 for max number of instances
glgenbuffersarb 1,Varptr InstancingMatrixBuffer' create a buffer
glBindBufferARB GL_TEXTURE_BUFFER_EXT,InstancingMatrixBuffer' bind the buffer to the texture buffer slot
glBindBufferARB GL_UNIFORM_BUFFER_EXT,InstancingMatrixBuffer' bind the buffer to the uniform buffer slot
glBufferDataARB GL_UNIFORM_BUFFER_EXT,TBatch.MaxPassSize*64,Null,G L_STATIC_READ' set the buffer size

When each shader is loaded, set the uniform buffer:

glUniformBufferEXT program,uniform_InstanceMatrix.index,TWorld.Instan cingMatrixBuffer

In the batch rendering routine, send the data to the uniform buffer:

glBufferDataARB GL_UNIFORM_BUFFER_EXT,count*64,Varptr instancematrix[n*MaxPassSize*16],GL_STATIC_READ

In the vertex shader, get the instance matrix:

mat=instancematrix[ gl_InstanceID ];

09-21-2009, 03:42 PM
JoshKlint, can you provide me with some more details? you said it worked with older drivers. Do you know which version? A repro case with source code would be ideal so that we can debug this.

(with my NVIDIA hat on)

09-22-2009, 11:38 PM
Download the engine's evaluation kit:

Open the SDK browser and click the "Demo Launcher" link. Run either scene with any settings.

09-28-2009, 12:06 PM

Thanks for the pointer to the engine. We found the bug and are working on a fix.

(with my NVIDIA hat on)

09-29-2009, 01:02 PM
Thanks! Sorry I didn't have time to produce a smaller example.