GPU Rendering, Pipeline Hazards and Workload Fit
System DesignModel answerLast updated
Walk through how a GPU turns triangles into pixels, how pipelines resolve register read-after-write hazards, and which workloads GPUs handle well or badly.
You are asked three connected questions about processor and graphics hardware. Answer each one in a structured way, using concrete hardware terms.
- Rendering a triangle. Describe the path a triangle takes on a modern GPU, from the input vertices to the final pixels in the framebuffer. Name the stages in order and say which are programmable and which are fixed-function.
- Register dependencies. In a pipelined processor or a GPU execution pipeline, an instruction can need a register value that an earlier instruction has not finished producing (a read-after-write, or RAW, dependency). Explain how such dependencies are detected and handled, and how the GPU approach differs from the classic CPU approach.
- Workload fit. Which kinds of operations are GPUs especially good at, which are they poor at, and why?
Concentrate on throughput, memory behavior and how execution is scheduled. You do not need to write production code, but a small illustration of your reasoning is welcome.
Hints
Hint 1
For part 1, list the stages in order (fetch, vertex shading, assembly and clipping, rasterization, depth test, fragment shading, blending) and label each as programmable or fixed-function. Then mention how tile-based and immediate-mode designs differ in memory traffic.
Hint 2
For part 2, start with the CPU toolbox (forwarding, stalls, scoreboarding, out-of-order execution, compiler scheduling). Then ask what a GPU does when a memory load takes hundreds of cycles and there is no big out-of-order engine.
Hint 3
For part 3, think in terms of arithmetic intensity, uniform control flow and regular memory access. Then flip each property to find what GPUs are bad at (divergence, pointer chasing, serial code).
Model answer
Easy Try it yourself first — then compare your approach, complexity and edge cases.
Overview
A strong answer shows a correct mental model in three areas: the graphics pipeline, hazard handling (and why GPUs differ from CPUs), and what throughput-oriented hardware is suited for. The unifying theme is that GPUs trade single-thread latency for aggregate throughput.
1. From vertices to pixels
- Input assembly. Index and vertex buffers are read and attributes (position, normal, UV) are gathered. A post-transform cache lets vertices shared between triangles skip re-shading.
- Vertex shader (programmable). Transforms positions from model space to clip space and produces per-vertex outputs (varyings). Tessellation, geometry or mesh shaders may follow on hardware that supports them.
- Primitive assembly, clipping, culling (fixed-function). Vertices are grouped into triangles and clipped against the view volume. The perspective divide (x/w, y/w, z/w) and viewport transform map them to screen space. Back-facing and zero-area triangles are discarded.
- Rasterization (fixed-function). Triangle setup computes edge equations. Coverage is tested, usually hierarchically over tiles, and covered samples become fragments. Fragments are emitted in 2x2 quads so that screen-space derivatives exist for texture mip selection. Varyings are interpolated with perspective correction.
- Early depth/stencil test. Fragments hidden behind nearer geometry are rejected before the expensive shading step. This is disabled or limited if the shader writes depth or uses discard.
- Fragment shader (programmable). Computes color, mostly through ALU math and texture sampling. Dedicated texture units do addressing, filtering and decompression.
- Late depth/stencil, blending, output (fixed-function ROP). Blending and MSAA resolve happen here, and results are written to the framebuffer.
Immediate-mode vs tile-based rendering.
- Immediate-mode GPUs shade primitives in submission order and send depth and color traffic to DRAM.
- Tile-based GPUs (common on mobile) first run a binning pass that transforms vertices and sorts triangles into screen tiles (for example 16x16 pixels). They then process each tile completely in fast on-chip memory, writing only the final color to DRAM. Depth, MSAA samples and blending never leave the chip, which saves bandwidth and power. Extras such as hidden-fragment killing and skipping writes of unchanged tiles save further traffic.
2. Read-after-write hazards
A RAW hazard occurs when an instruction tries to read a register before an earlier instruction has written it.
Classic CPU techniques
- Forwarding (bypassing): route the result from the execute or memory stage output directly to the dependent instruction's input, skipping writeback.
- Interlock / stall: when forwarding cannot help (for example a load followed immediately by its consumer), insert bubbles.
- Scoreboarding: track a pending bit per register; issue only when all sources are ready.
- Out-of-order execution: register renaming removes false (WAR, WAW) dependencies, and reservation stations (Tomasulo) let independent instructions proceed while others wait.
- Compiler scheduling: place independent instructions between a producer and its consumer.
GPU approach: hide latency with parallelism
GPUs avoid costly out-of-order machinery per thread. Instead:
- Each warp/wavefront has its own scoreboard. If its next instruction has an unready source, that warp is simply ineligible this cycle.
- A warp scheduler picks another ready warp every cycle. With enough resident warps, a ~400-cycle memory load is covered by useful work from other warps. This needs a large register file and good occupancy.
- Many GPUs let the compiler encode dependency and latency information in the instruction stream, reducing dynamic checking hardware.
- Issue within a warp is mostly in-order, with bypass paths for short fixed-latency ALU results.
Trade-off: poor single-thread latency, excellent throughput per watt and per unit of silicon area. Occupancy is limited by registers and shared memory per thread, so heavy kernels can lose their ability to hide latency.
Small illustration
def run_in_order(program, forwarding=True, wb_penalty=2):
# program: list of (dst, srcs, latency)
ready, cycle, stalls = {}, 0, 0
for dst, srcs, lat in program:
earliest = max((ready.get(r, 0) for r in srcs), default=0)
if earliest > cycle: # RAW stall
stalls += earliest - cycle
cycle = earliest
if dst:
ready[dst] = cycle + lat + (0 if forwarding else wb_penalty)
cycle += 1
return cycle, stalls
A single thread stalls whenever a consumer follows a long-latency producer. A GPU-style scheduler interleaves several such programs, issuing from whichever has ready operands, so the issue slot stays busy and stalls effectively disappear once enough warps are resident.
3. What GPUs are good and bad at
Good at
- Data-parallel, uniform work: the same operation over many independent elements (pixels, vertices, matrix and tensor math, convolutions, image processing, simulation).
- High arithmetic intensity: many FLOPs per byte moved. Wide SIMD/SIMT lanes amortize instruction fetch and decode over many threads.
- Regular, coalesced memory access: neighboring threads touching neighboring addresses form wide transactions that exploit high-bandwidth memory.
- Fixed-function acceleration: texture filtering, rasterization, blending, compression, matrix/tensor units.
Poor at
- Divergent branches: lanes in a warp that take different paths are serialized with masks, wasting throughput.
- Pointer chasing and irregular gathers: these defeat coalescing and caching.
- Serial, latency-bound code: there is no parallelism to hide latency.
- Tiny kernels or heavy global synchronization: launch and sync overhead dominates.
Common mistakes
- Saying GPUs use out-of-order execution to handle dependencies; they mostly rely on multithreading.
- Forgetting that rasterization works on 2x2 quads, or that early depth test can be disabled by shader side effects.
- Treating tile-based rendering as just a software trick instead of a memory-bandwidth and power optimization.
- Claiming GPUs are simply "faster"; they are higher-throughput but worse at single-thread latency.