cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

soconnell
Journeyman III

glDrawArraysIndirect not setting gl_VertexID correctly?

I'm not 100% positive what the correct behavior is here, but on NVIDIA hardware, gl_VertexID = first + [vertex index].  So if I specify first=2, count = 6, then the values for gl_VertexID in each instance of the shader are: 2, 3, 4, 5, 6, 7.  However on AMD hardware, gl_VertexID always starts at 0.  When calling glDrawArrays with no bound attributes, the behavior between NVIDIA and AMD is the same and correct.  Has anybody else experienced this issue on AMD hardware?

//-------------------------Create and set up indirect draw buffer-------------------------

typedef struct

{

    GLuint count;

    GLuint primCount;

    GLuint first;

    GLuint baseInstance;

} DrawArraysIndirectCommand;

DrawArraysIndirectCommand command;

command.count = 6;

command.primCount= 1;

command.first = 2;

command.baseInstance = 0;

glGenBuffers(1, &indirectBuffer);

glBindBuffer(GL_DRAW_INDIRECT_BUFFER, indirectBuffer);

glBufferData(GL_DRAW_INDIRECT_BUFFER, sizeof(DrawArraysIndirectCommand), &command, GL_STATIC_DRAW);

glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0);

//-------------------------Make indirect draw call-------------------------

glBindVertexArray(dummyVao);

glBindBuffer(GL_DRAW_INDIRECT_BUFFER, indirectBuffer);

glDrawArraysIndirect(GL_POINTS, 0);

glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0);

glBindVertexArray(0);

//-------------------------VERTEX SHADER--------------------------

#version 430 core

layout (std430, binding = 0) buffer BufferObject

{

    int data[];

};

uniform mat4 ModelViewProjectionMatrix;

void main()

{

    data[gl_VertexID] = gl_VertexID;

    gl_Position = ModelViewProjectionMatrix * vec4(gl_VertexID, 0.0, 0.0, 1.0);

}

0 Likes
1 Reply
cameni
Journeyman III

I haven't tested it with glDrawArraysIndirect, but for example with glDrawElementsBaseVertex(mode,count,type,indices,basevertex):

   - on AMD series 2 to 6, the built-in shader variable gl_VertexID contains basevertex+index

   - on AMD series 7, the built-in shader variable gl_VertexID contains just the index

   - on Nvidia, the built-in shader variable gl_VertexID contains just the index

Today I tested the 4.3 preview driver 13.15.100.1, and there it seems to be even worse: previously I could at least detect & treat it, but here with some shaders on series 7 it is the index, on others (usually more complex ones) it's basevertex+index ...

0 Likes