Handling zero-area triangles

How does GL handle drawing vertex buffers which contain some zero-area tris (degenerate polygon?)? For example, suppose I have some tris in VBO for which all vertices are just 0,0,0 (E.g. since they were allocated space in the buffer that never got used in marching-cubes algorithm). Will it discard them or are they a significant performance hit? (E.g. suppose there are 10 or 100 times as many zero-area tris as real tris (comprising the isosurface)?)

Is there a way these can be rejected in the pipeline to improve performance, without requiring a return to host?
Will vertex shader instance be invoked for each 0 vertex in each zero-area tri?
Will primitive assembly succeed or can it be forced to fail in this case (how)?

The vertex shader will be invoked for all vertices. The geometry shader (if present) will be invoked for all triangles. If the triangle’s 2D projection has zero area and anti-aliasing is disabled, no fragments will be generated. It’s unclear (to me) what should happen for zero-area polygons if anti-aliasing is enabled (apart from anything else, back-face culling is problematic for a zero-area polygon).

The implementation cannot discard them without executing the vertex shader (and geometry shader if present) as the actual vertex coordinates aren’t known until those stages have completed.

In the absence of anti-aliasing, whether or not primitive assembly succeeds is largely moot; even if it succeeds no fragments will be generated, so there’s no fragment shader overhead. Degenerate triangles could be discarded by a geometry shader, but geometry shaders can have a significant overhead (much of this stems from the fact that shared vertices get duplicated; if you don’t have any shared vertices, this is less of an issue), and they can’t eliminate the vertex shader overhead.

Eliminating them from the vertex stream without CPU intervention could be done with a compute shader. E.g. by re-ordering the vertices so that the unused vertices are at the end of the buffer and just setting the count parameter in the draw call appropriately.

1 Like

E.g. 2016 Optimizing the Graphics Pipeline With Compute.

1 Like