PDA

View Full Version : glDrawArrays and gl_VertexID (Nvidia/ATI diff)



cameni
03-11-2010, 01:08 AM
Hi,

Calling glDrawArrays(mode,first,count) with non-zero first parameter behaves differently on ATI/Nvidia with respect to the gl_VertexID built-in variable. On Nvidia, the gl_VertexID contains the values from first to first+count, but on ATI the indices always start from zero.

I'm not sure what is the correct behavior. The specification says only that "gl_VertexID holds the integer index i implicitly passed by DrawArrays or one of the other drawing commands ..". As far as I can see it doesn't explicitly say what the indices should be with respect to the value of first.

Can anyone tell what should be the correct interpretation?

Thanks.

PS: Tested with mode=GL_POINTS, Nvidia 196.21 driver and ATI 10.2 driver.

Alfonse Reinheart
03-11-2010, 02:12 AM
This is an unfortunate case where the 3.2 core spec is missing vital information provided by the 3.2 compatibility spec.

The value 'i' is the implicit value that is used for glArrayElement; all of the array commands are defined in terms of this function. Of course, since this function isn't in 3.2 core, it is removed as well as explicit references to it. Implicit references to it, like referring to the index 'i', are not.

In any case, the NVIDIA behavior is (not unsurprisingly) correct in this case.

Pierre Boudier
03-11-2010, 03:11 AM
do you see the same behavior for both client side data and vertex side data (on either nvidia/amd) ?

cameni
03-11-2010, 03:20 AM
We are only using it with GPU side VBOs, but I can test it with CPU-side buffers, if it can help.

Pierre Boudier
03-11-2010, 07:25 AM
(fyi, I think that you will see the same behavior on amd with vertexid starting from 0)

cameni
03-11-2010, 01:00 PM
Yes, it's the same behavior. So, is it a bug in amd driver?

cameni
03-19-2010, 04:42 AM
A quick note: apparently when using the basevertex in glDrawElementsBaseVertex, gl_VertexID contains the values from the index buffer, without basevertex value being added to it (tested on Nvidia)

Is this the correct behavior in this case?

Pierre Boudier
03-19-2010, 06:47 AM
Yes, it's the same behavior. So, is it a bug in amd driver?

the behavior you describe is the expected one in our current implementation (i.e. no offset on either client/server). we will try to clarify the expected behavior and get back to you

cameni
03-06-2011, 12:28 PM
Update on the status of the problem:

With recent AMD drivers, when using glDrawElementsBaseVertex the built-in shader variable gl_VertexID now contains the value of basevertex+index, which is I believe the correct behavior.

However, several releases ago Nvidia drivers started to exhibit the (wrong) behavior as well (gl_Vertex containing just the index), so the behavior is again different between the two :(