View Full Version : gl_PrimitiveID bug in AMD Cards?

07-01-2013, 03:34 PM

We are developing a CAD application where the meshes usually are very big. For improve the performance we are painting in a unique batch all the primitives using glDrawElements.
We are using the follow shader to generate Picking info over a FBO. With small mesh (around 2 million of primitives), all works fine but with mesh greater than of 8 millions of primitives the gl_PrimitiveID became invalid. It looks like if in a previous state, the gl_PrimitiveID was reset to zero. Is gl_PrimitiveID limited to a max number of Primitives? or is just a bug?

The shaders we are using are this:

// Vertex
#version 330
#define POSITION 0

uniform mat4 MVP_Matrix;

layout(location = POSITION) in vec4 VertexPosition;

void main(void)
gl_Position = MVP_Matrix * VertexPosition;

// Fragment
#version 330
#extension GL_EXT_gpu_shader4 : enable
uniform uint gEntyID; // Object Id
uniform uint gSubEntyID; // Element Id
uvec3 outFragColor;
void main()
outFragColor = uvec3 (gEntyID,gSubEntyID,gl_PrimitiveID);



07-05-2013, 02:02 PM
We avoided this situation by drawing large meshes in chunks (500K tris), though not specifically for this case (Windows likes to reset the driver if it's not responsive after 2s, which is easily accomplished by sending a large rendering batch to low-end hardware, which was the main issue). By passing a BasePrimID uniform to the shader and adding it to the gl_PrimitiveID, the original primitive ID can be determined. This might solve the problem for your large mesh case.

However, this does seem to be a bug with the driver.

07-06-2013, 06:48 AM
Hi Malexander,

Thank you for your reply.
I have resolved it using the same technique that you propose. In my coding I am using chunk of 1Million of primitives for a firepro 4900.