[graphics pipeline] who and when decides which and how many fragments/vertices gets calculated?

I have this big doubt about the pipeline, particularly in complex case where the vertex function "remodel" the geometry, how can the rasterization decide to add sampling points etc?

Take for example those hair shader or bumps etc, obviously the base triangle must be sampled and drawn many more times since from the starting few point it generates a whole new shape, but how many times? where does this process happen and how?

Also side question, assuming a very complex and eventually wrong vertex/geometry shader can you ever have an equivalent of stack overflow due to a circular geometry function or something similar?

Posted Oct 27, 2017, 10:22 AM UTC

616
nicolasgz•

Take for example those hair shader or bumps etc, obviously the base triangle must be sampled and drawn many more times since from the starting few point it generates a whole new shape, but how many times? where does this process happen and how?

Sounds like you're looking for the tessellation shader stages.

Also side question, assuming a very complex and eventually wrong vertex/geometry shader can you ever have an equivalent of stack overflow due to a circular geometry function or something similar?

No, the geometry shader is not recursive (none of the graphics pipeline is recursive actually.) It also has implementation-specified limits on the amount of data it can output.

6
_mess_OP•

Sounds like you're looking for the tessellation shader stages.

Yup but all the docs I found talk about linear stuff and that is pretty much obvious anyway, any explanation on different kind of geometry ?

No, the geometry shader is not recursive (none of the graphics pipeline is recursive actually.) It also has implementation-specified limits on the amount of data it can output.

I meant more if the curve of the new geometry produces a very complex shape, would the shader follow the geometry or would it follow the screen, is the limit a machine limit or based on the actual fragment needed to render each specific geometry ?

1
nicolasgz•

Yup but all the docs I found talk about linear stuff and that is pretty much obvious anyway, any explanation on different kind of geometry ?

I've mostly seen it used for either sampling a parametric surface (defined using eg. a spline coefficient matrix) or by sampling a bump map for displacements, or both (creating a spline from bump map samples.)

I meant more if the curve of the new geometry produces a very complex shape, would the shader follow the geometry or would it follow the screen, is the limit a machine limit or based on the actual fragment needed to render each specific geometry ?

I would say that, in general, every primitive is handled independently. It doesn't "follow the geometry" any more than it just renders each point/line/triangle independently. In general, rendering small geometry is very inefficient for that reason. You generally want to aim your tessellation to create geometry no smaller than 2x2 pixels.

2
_mess_OP•

yup I get it, but more than practical suggestions(which are great anyway) I wanted to understand the process of tesselation in relation to displacements

lets say my inizial vertices are 1,0 2,0 3,0

and my geometry shader moves them to 1,0 2,50 3,0

Then obviousy 3 fragments arent enough to the render, so when and how the graphic card or the compiler or whatever understand that the tesselation must change and how does it calculate the missing links between the fragments?

1
nicolasgz•

Note: Your initial vertices produce a flat line, which is a degenerate triangle that occupies 0 pixels, so the triangle would be discarded very early during rasterization and produce no output.

But I think I understand what your question is. I think the piece that you're missing is that there's a separation between the processing of geometry and the rasterization. Anything that happens during the vertex shader, geometry shader, and tessellation shaders are totally unrelated to pixels. Only the final primitives outputted by that whole multi-stage geometry processing pipeline are passed on to the rasterizer.

The rasterizer takes as input vertices in clip space (ie. the output of transforming by your projection matrix) and per-vertex attributes, and it will invoke the pixel shader (aka. fragment shader) on all pixels covered by that primitive. The rasterizer doesn't care about what processing steps happened to the primitive before it was submitted for rasterization.

Note: This explanation is somewhat assuming you're using an immediate mode rasterizer (like all desktop GPUs.) A bunch of weird stuff happens in tile-based rasterizers that are used in mobile GPUs.

1
aleksigron•

The best explanation of the graphics pipeline I’ve seen comes from Fabian Giesen: https://fgiesen.wordpress.com/2011/07/09/a-trip-through-the-graphics-pipeline-2011-index/

You’ll find an answer to pretty much any question you might have in there.

4
agenthex•

I think your first mistake is assuming that the rasterizer modifies geometry. In truth, this is done before rasterization, likely with a geometry shader that constructs a mesh based on functions and parameters such as Level of Detail or some other procedure.

1