Previous Object Programming: Advanced Rendering Using Shader Objects Next

How Shaders Enhance Performance

Using a shader lets you take advantage of the processing power of the graphics card processing unit (GPU) instead of relying solely on the system CPU. The ability to offload computationally intensive tasks means applications run faster and operate more interactively. Also, the GPU can operate on multiple data streams simultaneously. For example, some GPUs can execute a fragment shader on up to 24 fragments (pixels) simultaneously, which provides a significant performance advantage over a CPU which can only process one pixel at a time.

Consider a typical image processing application that applies several transforms or operations to a set of image data, stores the result in an IDLgrImage object and then displays the image. In the following figure, the application applies several image operations and creates intermediate images (that may be reused). This process requires a significant amount of computation and data movement before the final image is copied into the image object and the graphic device's texture memory. Additionally, all or most of this process must be repeated any time the parameters of an operation change, reducing interactive performance.

Figure 14-3: Image Processing Pipeline without Shader Program

Figure 14-3: Image Processing Pipeline without Shader Program

Consider the same image processing application that uses a shader program to apply the operations. In the following figure, the entire processing cycle is accomplished on the graphics card with the exception of passing in a small amount of data containing operation parameters.

Figure 14-4: Image Processing Pipeline with Shader Program

Figure 14-4: Image Processing Pipeline with Shader Program

Without a shader program and suitable hardware, updating an image may require several tenths of a second when the image is large and complex operations are applied. Noticeable display updates may occur with CPU processing. With a shader program, the display rate with the same amount of processing can be hundreds of frames per second. Display updates will be smooth with GPU processing. Display rates of hundreds of frames per second are not always useful, but when lower rates are used, more CPU resources are available for other operations.

  IDL Online Help (March 06, 2007)