DirectX Pipeline Stages

The DirectX graphics pipeline is a series of programmable and fixed-function stages that process geometry and pixels to render an image on the screen. Understanding these stages is crucial for optimizing performance and achieving desired visual effects.

Input Assembler (IA)

The Input Assembler is the first stage of the graphics pipeline. It reads vertex data from application-defined buffers and organizes it into primitives (points, lines, triangles) that are sent to the rest of the pipeline.

Key Responsibilities:

  • Fetching vertex data from vertex buffers.
  • Interpreting vertex data based on input layout definitions.
  • Assembling vertices into primitives (points, lines, triangles, etc.).
  • Handling indexed drawing for efficiency.

Related APIs:

  • D3D11_INPUT_ELEMENT_DESC
  • ID3D11InputLayout
  • IASetInputLayout
  • IASetPrimitiveTopology

Vertex Shader (VS)

The Vertex Shader is a programmable stage that operates on individual vertices. Its primary role is to transform vertices from model space to clip space, calculate lighting, and pass data to the next stage.

Key Responsibilities:

  • Applying transformations (world, view, projection).
  • Performing vertex lighting calculations.
  • Generating vertex attributes for subsequent stages (e.g., texture coordinates, normals).
  • Outputting vertex positions in clip-space coordinates.

Related APIs:

  • HLSL Vertex Shader Language
  • VSSetShader
  • VSSetConstantBuffers
  • VSSetShaderResources

Hull Shader (HS) & Domain Shader (DS)

These stages are part of the Tessellation pipeline, allowing for dynamic subdivision of primitives to add geometric detail.

Hull Shader:

  • Controls tessellation factors.
  • Generates tessellation factors based on control points.
  • Outputs tessellation factors and control point data.

Domain Shader:

  • Generates new vertices by interpolating control points.
  • Receives tessellated patches and outputs final vertex data.

Related APIs:

  • HLSL Hull Shader Language
  • HLSL Domain Shader Language
  • HSSetShader, DSSetShader

Geometry Shader (GS)

The Geometry Shader is a programmable stage that can generate or remove primitives. It operates on entire primitives (points, lines, triangles) and can output new primitives.

Key Responsibilities:

  • Generating new primitives (e.g., creating line strips from points).
  • Discarding primitives.
  • Replicating vertices.
  • Performing per-primitive operations.

Related APIs:

  • HLSL Geometry Shader Language
  • GSSetShader

Rasterizer (RS)

The Rasterizer stage converts geometric primitives into a set of screen-space pixels (fragments) that will be processed by the pixel shader.

Key Responsibilities:

  • Clipping primitives against the view frustum.
  • Performing perspective division.
  • Performing screen-space coordinate transformation.
  • Generating fragments for each pixel covered by a primitive.
  • Performing depth/stencil testing for early Z rejection.

Related APIs:

  • RSSetState
  • RSSetViewports
  • RSSetScissorRects

Pixel Shader (PS)

The Pixel Shader is a programmable stage that operates on individual fragments (pixels). Its main task is to determine the final color of each pixel.

Key Responsibilities:

  • Performing texturing and sampling.
  • Calculating fragment lighting and color.
  • Interpolating vertex data across the primitive.
  • Outputting the final color to a render target.

Related APIs:

  • HLSL Pixel Shader Language
  • PSSetShader
  • PSSetSamplers
  • PSSetShaderResources
  • PSSetConstantBuffers

Output Merger (OM)

The Output Merger stage combines the output of the pixel shader with the existing contents of the render target and depth-stencil buffer.

Key Responsibilities:

  • Performing blending operations.
  • Performing depth testing and writing.
  • Performing stencil testing and writing.
  • Writing the final pixel color to the render target.

Related APIs:

  • OMSetRenderTargets
  • OMSetBlendState
  • OMSetDepthStencilState