i
i
i
i
i
i
i
i
18.3. Processing Geometry into Pixels 455
you is that you essentially have a multi-processor machine. This turns out to be
a good way to think about your graphics hardware, since it means that you may
be able to use the graphics hardware processor to relieve the load on the CPU in
some of your applications. The graphics hardware processors are often referred
to as GPUs. GPU stands for graphics processing unit and highlights the fact
that graphics hardware components now contain a separate processor dedicated
to graphics-related computations.
Historical: Programming
the pipeline is not entirely
new. One of the first
introductions of a graphics
hardware architecture
designed for program-
ming flexibility were the
PixelFlow architectures
and shading languages
from UNC (Molnar et
al., 1992; Lastra et al.,
1995; Olano & Lastra,
1998). Additional efforts
to provide custom shading
techniques have included
shade trees (Cook,
1984), RenderMan (Pixar,
2000), accelerated multi-
pass rendering using
OpenGL
TM
(Peercy et al.,
2000), and other real-time
shading languages (Proud-
foot et al., 2001; McCool et
al., 2004).
Interestingly, modern GPUs contain more transistors than modern CPUs. For
the time being, GPUs are utilizing most of these transistors for computations and
less for memory or cache management operations.
However, this will not always be the case as graphics hardware continues to
advance. And just because the computations are geared towards 3D graphics,
it does not mean that you cannot perform computations unrelated to computer
graphics on the GPU. The manner in which the GPU is programmed is differ-
ent from your general purpose CPU and will require a slightly modified way of
thinking about how to solve problems and program the graphics hardware.
The GPU is a stream processor that excels at 3D vector operations such as
vector multiplication, vector addition, dot products, and other operations neces-
sary for basic lighting of surfaces and texture mapping. As stream processors,
both the vertex and fragment processing components include the ability to pro-
cess multiple primitives at the same time. In this regard, the GPU acts as a SIMD
(Single Instruction, Multiple Data) processor, and in certain hardware implemen-
tations of the fragment processor, up to 16 pixels can be processed at a time.
When you write programs for these processing components, it will be helpful, at
least conceptually, to think of the computations being performed concurrently on
your data. In other words, the vertex shader program will run for all vertices at
the same time. The vertex computations will then be followed by a stage in which
your fragment shader program will execute simultaneously on all fragments. It
is important to note that while the computations on vertices or fragments occur
concurrently, the staging of the pipeline components still occur in the same order.
The manner in which vertex and fragment shaders work is simple. You write
a vertex shader program and a fragment shader program and send it to the graph-
ics hardware. These programs can be used on specific geometry, and when your
geometry is processed, the vertex shader is used to transform and light the ver-
tices, while the fragment shader performs the final shading of the geometry on a
per-pixel basis. Just as you can texture map different images onto different pieces
of geometry, you can also write different shader programs to act upon different
objects in your application. Shader programs are a part of the graphics state so
you do need to be concerned with how your shader programs might get swapped
in and out based on the geometry being rendered.