2

I have a large 2D Triangle(not Triangle Strip) mesh with about 2+ million polygons. Many of these polygons are redundant which can be determined using one of the attribute variables in vertex shader. But since discarding a vertex in vertex shader is not possible. I am exploring the idea of discarding primitives in Geometry shader as an optimization. It is guaranteed that all three vertices of this primitive will have same attribute value.

I have a few doubts here

  1. Will this really optimize rendering in terms of speed and GPU memory?
  2. Is this even possible in geometry shader and are geometry shaders are suitable for this?
Abhishek Bansal
  • 5,197
  • 4
  • 40
  • 69
  • 1
    "*Many of these polygons are redundant which can be determined using one of the attribute variables in vertex shader.*" If the redundancy of a triangle can be determined a priori from its mesh data... why can't you simply detect this on the CPU and just not upload that data? – Nicol Bolas Oct 09 '19 at 13:28
  • yeah, that occurred to me later after I posted this question. Did not delete the question because I still wanted to know if discarding primitives in geometry shader will have any performance impact. Thanks for the suggestion! – Abhishek Bansal Oct 09 '19 at 17:16

1 Answers1

3

But since discarding a vertex in vertex shader is not possible.

Nonsense. Oh sure, the VS cannot "discard" a triangle, but that doesn't mean it has no power.

Triangles which appear wholly off-screen will generally get minimal processing done on them. So at a minimum, you can have the VS adjust the final gl_Position value to be off screen based on whether the attribute in question has the property you are looking for.

If you have access to OpenGL 4.6, you can get even fancier by employing cull planes, which allow the VS to cull triangles more directly.

Will this really optimize rendering in terms of speed and GPU memory?

Broadly speaking, you should never assume Geometry Shaders will increase the performance of any algorithm you apply it to. There may be cases where a GS could be used in optimizing an algorithm, but absent actual performance data, you should start from the assumption that employing it will only make performance worse.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982