i
i
i
i
i
i
i
i
18.3. Processing Geometry into Pixels 465
strung together to form the overall computation. The first kernel completes the
first part of the computation, the second kernel works on the first kernel’s data,
and so on, until the calculation is complete. In this style of programming, working
with data and data structures on the GPU is different than conventional program-
ming and does require a bit of thought. Fortunately, recent efforts are providing
abstractions and information for creating efficient data structures for GPU pro-
gramming (A. Lefohn et al., 2005).
Using the GPU for general purpose programming does require that you un-
derstand how to program the graphics hardware. For instance, most applications
that perform GPGPU will render a simple quadrilateral, or sets of quadrilater-
als, with vertex and fragment shaders operating on that geometry. The geometry
doesn’t have to be visible, or drawn to the screen, but it is necessary to allow
the vertex and fragment operations to occur. This focus on graphics does make
the learning curve for general purpose computing on this hardware an adventure.
Fortunately, recent efforts are working to make the interface to the GPU more like
traditional programming. The Brook for GPUs project (Buck et al., n.d.) is a sys-
tem that provides a C-like interface to afford stream computations on the GPU,
which should allow more people to take advantage of the computational power on
modern graphics hardware.
Frequently Asked Questions
• How do I debug shader programs?
On most platforms, debugging both vertex shaders and fragment shaders is not
simple. There is very little runtime support for debugging graphics applications
in general, and even less available for runtime debugging of shader programs.
However, this is starting to change. In the latest versions of Mac OS X, Linux,
and Windows, support for shader programming is incorporated. A good solution
for debugging shader programs is to use one of the shader development tools
available from various graphics hardware manufacturers.
Notes
There are many good resources available to learn more about the technical de-
tails involved with programming graphics hardware. A good starting point might
be the OpenGL
TM
Programming Guide (Shreiner et al., 2004). The OpenGL
TM
Shading Language (Rost, 2004) and The Cg Tutorial (Fernando & Killgard, 2003)