Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: using the new "invocation count" feature in geometry shaders

Hybrid View

  1. #1

    using the new "invocation count" feature in geometry shaders

    Modern OpenGL lets you specify an invocation count in your geometry shader:

    layout(triangles, invocations = 3) in;

    I'm updating some old GLSL and I wish to use this functionality because it lets me avoid looping over verts. However, I'm either doing something incorrectly or hitting a driver issue. Here's my old code:

    for (int i = 0; i < 3; i++) { gl_Position = gl_in[i].gl_Position; EmitVertex(); }
    EndPrimitive();

    Here's my new code:

    gl_Position = gl_in[gl_InvocationID].gl_Position;
    EmitVertex();
    if (gl_InvocationID == 2) EndPrimitive();

    This renders bad triangles, so what am doing wrong? Do I need to synchronize the invocations before calling EndPrimitive? If so, how?

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941
    You've misunderstood how instanced geometry shaders work.

    A single geometry invocation still has to emit the complete primitive. You cannot "distribute" the processing of a single primitive across invocations. You can only "distribute" separate primitives between invocations.

    The sample you've presented could not be made more parallel with instanced geometry shader, however, if you would have to emit 3 separate triangles then you could do it by performing 3 invocations and emit only one triangle in each invocation. Geometry shader invocations still have to emit complete primitives.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  3. #3
    Perfect, thanks for the help!

Posting Permissions

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