4

So a vertex shader is executed for each vertex and a fragment shader for each fragment (right?).

How many times is a geometry shader executed?

colithium
  • 10,269
  • 5
  • 42
  • 57
clamp
  • 33,000
  • 75
  • 203
  • 299
  • 2
    Not to nitpick but it's a "fragment shader", not a "pixel shader". A fragment has things a pixel doesn't, namely: depth. There can be a lot of fragments that each map to the same pixel x/y. Lots of people call it a "pixel shader" but even if you're going to do so, it's incorrect to say a pixel shader is executed once for each pixel because, in fact, it can be executed more than once for each pixel. – colithium Dec 14 '11 at 06:48

1 Answers1

4

It's executed once for each primitive (triangle, line or point) after the vertex shader has transformed the constituent vertices.

andrewmu
  • 14,276
  • 4
  • 39
  • 37
  • aha thanks, so let's say i render a quad using GL_QUADS in openGL, is it executed twice? – clamp May 05 '11 at 17:43
  • I think it would be executed once - the quad is a single primitive (even if it might be rasterised as triangles underneath). – andrewmu May 09 '11 at 12:31
  • 3
    Geometry shaders can only receive: Point, Line, Line with Adjacency, Triangle, Triangle with Adjacency. So it would be called twice with Quads because it's already broken down into triangles when it reaches the geometry shader – colithium Dec 12 '11 at 11:56
  • @colithium right, the geometry shader would receive triangles. Just for predictability I imagine it would be better to stick to triangles further up the pipeline. – andrewmu Dec 13 '11 at 15:49