This page contains useful tutorials, sample applications, a glossary and a collection of frequently asked questions, all related to (legacy) general purpose GPU programming through graphics APIs and shader languages.
- Recommended Reading
- Frequently Asked Questions
- Code Tutorials
- Code Samples and Applications
- Utility Code and Libraries
The following articles and book chapters are recommended to get started programming GPUs:
- The book GPU Gems 2 contains 20 chapters on GPGPU, including an 8-chapter introductory section that covers the basics. Mark Harris’s Chapter 31, “Mapping Computational Concepts to GPUs”, is a must-read.
- Its predecessor, GPU GEMS 1, is also recommended.
- The GPGPU STAR (State of the Art Report), A Survey of General-Purpose Computation on Graphics Hardware, provides a great overview of the field as of August 2005, especially with respect to applications that have been mapped successfully to the GPU.
- The SIGGRAPH 2005 GPGPU Course and IEEE Visualization 2004 GPGPU Course pages contain notes and slides from introductory courses presented by experts in the field of GPGPU.
The GPGPU.org FAQ contains a wealth of knowledge for developers and others interested in the field, such as:
- Common programming issues
- Floating-point specific problems of legacy hardware
- Small code samples and links
- and much more
The GPGPU.org Glossary explains many (graphics-related) terms needed for programming graphics APIs for GPGPU.
GPGPU programming can be tricky. The simple examples provided here should help new GPGPU programmers get started.
Tutorial 0: “Hello GPGPU”
This introductory tutorial teaches five essential GPGPU concepts through the example application of a real-time edge detection filter.
- Texture = Array
- Fragment Program = Computational Kernel
- One-to-one Pixel-to-Texel Mapping:
- Data-Dimensioned Viewport, and
- Orthographic Projection
- Viewport-Sized Quad = Data Stream Generator
- Copy To Texture = Feedback
Note: You can also download the GLSL Version
Tutorial 1: “Basic Concepts”
This tutorial, kindly provided by Dominik Göddeke, expands on “Hello GPGPU” and discusses the various GPGPU programming concepts in much detail. It is highly recommended for every beginner in the field of GPGPU programming to work through this tutorial. OpenGL code using GLSL and Cg as shading languages for a simple application that adds large floating point vectors on the GPU is included.
Tutorial 2: “Reductions”
The term “reduction” refers to operations that compute scalar values from vector data in parallel processing. Examples include maximum, minimum, dot products, norms etc. This tutorial explains how this important building block can be implemented on GPUs.
Tutorial 3: “Fast Transfers”
The AGP or PCIe bus can be a bottleneck in GPGPU applications, especially if much data needs to be transferred to and from the GPU. This tutorial explains how to increase transfer speed on NVIDIA GPUs by taking advantage of the OpenGL pixel buffer extension.
Tutorial 4: “Multiple Render Targets”
Outputting more than a scalar or RGBA value per fragment shader can be tremendously useful in certain applications. This tutorial explains how to use multiple render targets in combination with GLSL or Cg shaders.
The following presents example applications. Click on the images to download the source code.
Fluid Dynamics Simulation
This sample from the NVIDIA SDK demonstrates fast, realistic fluid dynamics simulation on the GPU. The sample solves the Navier-Stokes equations for incompressible fluid flow using a technique originally presented at SIGGRAPH 1999 by Jos Stam. The sample allows the user to draw arbitrary obstacles and flow viscous or inviscid fluid around them.
This sample from the NVIDIA SDK creates a disturbing dynamic disease effect. It simulates a phenomenon known as chemical reaction-diffusion, by solving the governing partial differential equations in a fragment program. The result is an endless variety of changing patterns that are then used to generate bump and texture maps which are applied to a mesh with various shaders.
This sample implements a large-scale particle system entirely on the GPU. The positions and velocities of each particle are stored in floating point textures. Fragment programs are used to update the velocities and positions of the particles by rendering to texture each time step. The particles also collide against a sphere object, and a terrain heightfield which is stored in a texture. If available, the multiple draw buffers extension (MRT) is used to update the position and velocities in a single pass. The particles are rendered as point sprites. The position texture is converted into a vertex array for rendering the particles using the vertex buffer and pixel buffer object extensions (VBO and PBO). On the GeForce 6800, this method can render a million particles at about 20 frames per second. This example is inspired by Lutz Latta’s talk from GDC 2004, “Building a Million Particle System”. http://www.2ld.de/gdc2004/
If you have useful code you would like to share with the GPGPU community, use the contact form on the right to tell the webmaster about it.
Framebuffer Object (FBO) Class
This class is a minimal abstraction of the OpenGL framebuffer object (FBO) specification. FBO enables flexible, efficient render-to-texture in OpenGL and obviates the use of pbuffers. Included with this distribution is an example application that uses the FBO class (a slightly modified version of the “Hello GPGPU” tutorial). This code is generously provided by Aaron Lefohn.
Please check SourceForge for updates to the FBO Class.
Note: RenderTexture uses pbuffers, which are being replaced in OpenGL by the new FBO extension. See above. RenderTexture is a wrapper class that abstracts the process of creating and rendering to off-screen color and depth buffers in OpenGL. It supports Windows and Linux on NVIDIA and ATI graphics processors.
RenderTexture 2.0 is the latest incarnation of RenderTexture.
RenderTexture 1.0 is an older version with fewer features that may be more stable on some configurations.
Please check SourceForge for updates to RenderTexture.