1
votes

I use an OpenGL shader to plot graphs. Every span of the graph has the form:

enter image description here

The vertex shader just passes the a's and b's to a geometry shader that then evaluates the curve at max_vertices points.

The problem is that sometimes the geometry shader seems to become "overloaded" and stops spitting out points:

enter image description here

Both curves actually have the exact same values, but for some reason the bottom one has some kind of failure of the geometry shader to generate points.

When I change max_vertices in the following line of my geometry shader:

layout (triangle_strip, max_vertices = ${max_vertices}) out;

from 1024 (the result of gl.glGetInteger(gl.GL_MAX_GEOMETRY_OUTPUT_VERTICES)) to 256, then I get the desired output:

enter image description here

What is happening? What is the true maximum number of vertices? Why is the top graph unaffected, but the bottom one corrupted? They have the same data.

1

1 Answers

4
votes

Geometry shaders have two competing sets of limitations. The first is the number of vertices in each GS invocation, and the second is the total number of components you output from a GS invocation (retrieved from GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS). You must stay within both to get defined behavior.

1024 is the required minimum value for GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS; all implementations will support at least that many. If an implementation only supports that number, and you tried to output 1024 vertices, you could only output a single component of data for each such vertex (a single float or int or whatever, not even a vec2).

Overall, it would be better to avoid this problem entirely. What you're trying to do seems like it'd be more easily done via a compute shader or at the very least, geometry shader instancing.