Page 9: Graphics Performance

Spring 2026 Sample Solution

Trying to make things go fast is a moving target: as the hardware and software evolves, the bottlenecks become different, so the best ways to make most efficient use of system change as well.

Here, we focus on waste: spending our resources to draw triangles that the user will never see. Effort spend drawing these triangles has no benefit.

There are two categories of triangles that the user won’t see that we will consider separately:

  1. Triangles (or parts of triangles) that are outside of view (not on the screen).
  2. Triangles (or parts of triangles) that are occluded by other triangles: they would be on the screen, but some other triangle is in from of them.

The latter case is potentially very wasteful. In the normal rasterization process, a fragment from a triangle might make it all the way the way to the Z-buffer test which involves all of the pipeline stages, including potentially very expensive fragment coloring computations, only to fail the Z-test. Or worse, it might pass the Z-test, be written to the frame buffer, only to have some later fragment from another triangle overwrite it.

Much of the secret for graphics performance is to find ways to avoid wastefulness: determining that a triangle or fragment will not be seen before effort is wasted computing things about its appearance.

Backface culling

One special case: if a triangle is “one sided” (which is actually the default), we only need to draw it if we are looking at its front (outward facing) side. If the front side of the triangle is pointing away from the camera, we don’t need to draw it. This backface culling can happen in the clipping (or triangle processing) part of the pipeline, saving the effort of rasterization and fragment processing.

Backface culling is simple, but really helpful: if our objects have volume (so we don’t care about the “insides”) it cuts the number of triangles in half!

In practice, backfacing is determine by the triangle winding order, not the surface normal (since some triangles don’t have surface normals). This is why it is so important to have the winding directions of the triangles in our meshes correct!

Avoiding off-screen triangles

If a triangle is off screen, the clipping phase of the pipeline will discard it before rasterization. This happens after vertex processing, so the effort to process vertices is wasted. However, we might need to do the vertex processing in order to know the screen space coordinates (so we know that it is off the screen).

In practice, transforming the vertices is rarely a bottleneck in modern graphics applications, so its easier just to draw all the triangles and allow clipping to do its work.

There are strategies for culling triangles before they are drawn. They usually involve a pre-processing stage where spatial data structures are used to organize the triangles, so large groups of them can be removed (culled) quickly.

The strategy of preprocessing the geometry into spatial data structures that allow for fast testing of groups of triangles at once was a core part of historical game graphics. These data structures, such as binary space partitioning (BSP) trees were a central part of game graphics. They can also be used for doing occlusion culling.

Avoiding wasted fragment shading

In a modern, high-performance graphics application, the critical bottleneck is often fragment shading, and in particular, the memory bandwidth required. We have many fragments, and for each one, we often want to use a fancy lighting model that reads from multiple textures (with multiple memory reads from each texture to do some filtering strategy).

There are two reasons a fragment might not appear:

  1. It fails the Z-test
  2. A later fragment overwrites it

Early/Late Z

Problem #1 (failing the Z-test after fragment processing) is the result of a curious architectural decision: we put the write and test after fragment processing. This is called a late Z-test In the past, when fragment shading was not the bottleneck this was a reasonable decision because:

  1. The memory accesses all happen in one place, so its easier to design the memory system to do a “read-test-modify-write” operation efficiently. This is important because of the latency and caching issues.
  2. The fragment shader is allowed to modify the Z value.

The alternative to late Z-test is an early Z-test: performing the read/test before fragment processing. Importantly, it requires a major change to the hardware (a different memory architecture). And, to be flexible, a system probably needs to support late Z as well (in case of fragments that do modify the Z-values).

For all this added complexity, there is little added value: we still waste the work by performing fragment processing for fragments that will pass the Z-test, but be over-written by a later triangle’s fragment.

Deferred Shading

The idea of deferred shading has a long history - early deferred shading systems existed in the late 1980s, although it was motivated by different challenge. As fragment processing became the bottleneck, programmers returned to the concept.

The basic idea of deferred shading is to put off the lighting calculations (and other expensive per-fragment shading) until after all of the drawing is done. It’s a multi-pass algorithm: we first draw all of the triangles using minimal fragment processing; and then we make a second pass where we do fragment processing for the fragments that ultimately had become pixels. The trick: when the fragments are drawn the first time, they write enough information in the frame buffer that the second pass can compute the fragment’s color without having to re-render the triangle. This means that the second pass can be drawn as one giant rectangle that covers the whole screen. The expensive shading computations happen once per pixel.

Deferred shading works in two passes:

  1. The geometry pass where all triangles are drawn. In this pass, information about the fragments is written into a geometry buffer that stores information about the fragments that is required for later shading. The color stored is the object color (before lighting). The depth value is stored (for Z-Buffering). But additional information, such as the normal direction, texture coordinates, and material properties (e.g., roughness, metalness), is also stored.
  2. A second pass where each pixel is processed, reading the geometry buffer as its input. The color of each pixel is computed based on the information that the fragment provided and access to “global” information such as lighting information and textures.

Deferred shading has many benefits:

  1. Deferred shading avoids the wasted effort of expensive fragment shading being discarded: we only do the fragment shading for the fragments that are visible.
  2. The fragments are processed in pixel order in the second pass, which means there can be more coherence.
  3. If the fragment program is too complex to run in a single pass, it is easy to make the “send pass” consist of multiple redraws of the same single triangle, each one doing part of the work.
  4. By splitting the fragment shading into sub-passes, they can be designed for coherence of memory access. For example, there can be a separate pass that does the environment map lookups for reflections. That pass only needs to access that one texture. More generally, each pass can access a different texture, reducing the amount of memory bandwidth needed (relative to using many textures for each fragment).

There are downsides. A big conceptual problem is that all information needed by the second pass shading must be stored by the first pass. It also assumes a certain uniformity of the fragment shading computations: all objects will be processed by the same shader. The model that we are used to with “object oriented” graphics, where each object can have its own, independent, material, is difficult to apply.

There are workarounds for these downsides. For example, using information in the G-Buffer to select between different shading algorithms and applying different shading algorithms selectively in different screen-space passes.

Deferred shading is very common in high-performance games. Especially on mobile platforms where memory bandwidth and fragment shader complexity are limited.

What can we do in class?

In general, the things we do in class are small/simple enough that performance is not an issue.

But, you should understand:

  1. How the standard rasterization pipeline leads to wastefulness because it spends time drawing things that the viewer will not see.
  2. How we can use culling strategies to avoid drawing triangles that are offscreen.
  3. Methods for avoiding wasted fragment computations and optimizing memory usage. We won’t use deferred shading in class, but you are likely to encounter it if you try to make a game or interactive graphics programn that tries to squeeze as much out of the hardware as possible.

Before we go on…

In the next set of pages we’ll move on to discuss how we use texturing tricks to work around some of the limitations of the rasterization pipeline.

Here are a few questions to check your understanding. Answer them in your own words. And then make a checkpoint in case something happens to the localstore.

Question 1: Having one-sided triangles is often a hassle as it forces us to orient triangles correctly. What is the benefit?

Question 2: How can deferred shading help with memory bandwidth to the fragment shaders?

Kind Kind of rubric items:
standard - expected from all students
advanced - used to get a better grade
creative - an opportunity to do something creative
levels - rubric item graded by selected achievement level
optional - not required, but encouraged
Description
standard Pipeline Questions
Next: Page  10 - Texturing Hacks