Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Number of invocation of vertex shader

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2012

    Number of invocation of vertex shader


    I'm wondering about the number of time a vertex shader can be called It is written on the specification that a vertex shader can be executed many times per vertex, depending on implementation specific details.

    For example a vertex can be shared between many triangles, say two for the example.. The associated vertex shader can be called once and cached between all the triangles or twice.

    This is not an issue as long as your shader does not do any side effect (such as writing on a shader buffer storage of GL 4.3), but if you want to do some side effect, you need guarantees on the number of shader invocation.

    My question is about drawing GL_POINTS in not indexed mode (ie: glDrawArrays). Can I be sure (I mean, does the specification enforce this?) that my vertex shader will be called only one time per vertex?

    For example, I want to create a particule system where each particule is defined by a position and a velocity and draw by a glDrawArrays(). My vertex shader may looks like that:

    Code :
    struct Particules
        vec3 position;
        vec3 velocity;
    buffer Data
         struct Particule particules[];
    void main()
         // update the position *
         particules[gl_VertexID].position += particules[gl_VertexID].velocity;
         gl_Position = particules[gl_VertexID].position;

    The issue is with the * line, where the position of each particule is updated by the velocity. If my vertex shader is called multiples times, the result will be wrong.

    Another safe solution is to update the position using a compute shader and use a really simple vertex shader to draw the particules, but the first solution will be more efficient because it reduce the amount of loaded data.

    tl; dr;

    Is there any guarantee that the number of vertex shader invocations done by a DrawArrays on any primitive without vertices sharing will be one?

  2. #2
    Senior Member OpenGL Lord
    Join Date
    May 2009
    I'm curious as to where you read that the number of invocations are undefined. I'm not saying you're wrong, but it'd be a good place to start looking for the answer.

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Logically a vertex shader will need to be called twice if the second triangle sharing the vertex is not referenced until the vertex cache has been flushed by other vertices; but for a point array no vertices are shared by different primitives so there should be no need to re-evaluate that vertex.

  4. #4
    Member Regular Contributor
    Join Date
    Dec 2009
    Quote Originally Posted by Alfonse Reinheart View Post
    I'm curious as to where you read that the number of invocations are undefined. I'm not saying you're wrong, but it'd be a good place to start looking for the answer.
    From chapter 7.12 of the OpenGL 4.3 spec:
    While a vertex or tessellation evaluation shader will be executed at least once
    for each unique vertex specified by the application (vertex shaders) or gener-
    ated by the tessellation primitive generator (tessellation evaluation shaders),
    it may be executed more than once for implementation-dependent reasons.
    Additionally, if the same vertex is specified multiple times in a collection
    of primitives (e.g., repeating an index in DrawElements), the vertex shader
    might be run only once.
    So the spec does not enforce that the shader is invoked only once per vertex.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts