Shader pipeline

Once the vertex data is uploaded, a shader program needs to be run to process the data. Shader programs are programs that run on the GPU and are very similar to CPU programs. They reside in memory and can access data structures in memory, they are composed of assembly instructions (GPU assembly), and they run on a processor (the GPU execution units). They differ in that shader programs run as part of the graphics pipeline and have defined roles in processing graphics. They also cannot currently recurse or access heap memory.

The two primary shaders are the vertex shader and the fragment shader. The vertex shader takes as input vertex attributes and outputs at least a vertex position. The fragment shader takes as input interpolated vertex attibutes and outputs a color (almost always). The pipeline looks like this:

Example programmable pipeline

The shaders are the blue boxes. The white boxes represent automatic steps that take place. After the vertex shader, the vertex attributes are interpolated across the primitive surface. These interpolated fragments are the input to the fragment shader. After the fragment shader, the fragments are composed into the final output image.