DirectX Graphics Concepts

MSDN Documentation

Geometry Processing

Geometry processing is a fundamental stage in the real-time graphics rendering pipeline. It's responsible for taking raw geometric data—typically defined by vertices and primitives like triangles—and transforming it into a format suitable for rasterization and pixel shading. This process involves a series of fixed-function stages and programmable shader stages that manipulate vertex data.

The Geometry Processing Pipeline Stages

The geometry processing part of the DirectX rendering pipeline involves several key stages:

1. Input Assembler (IA) Stage

The Input Assembler stage is the entry point for geometric data. It reads vertex data from memory (usually buffers) and organizes it into primitives (points, lines, triangles, etc.) based on the defined topology. This stage is typically handled by the CPU but can also be influenced by GPU commands.

2. Vertex Shader (VS) Stage

The Vertex Shader is a programmable stage that processes each vertex individually. Its primary role is to transform the vertex's position from its model-space coordinates into clip-space coordinates. It can also manipulate other vertex attributes, such as texture coordinates or normals, and pass them to subsequent stages.

// Example Vertex Shader (HLSL)
struct VS_INPUT
{
    float4 Pos : POSITION;
    float2 Tex : TEXCOORD0;
};

struct VS_OUTPUT
{
    float4 Pos : SV_POSITION;
    float2 Tex : TEXCOORD0;
};

VS_OUTPUT main(VS_INPUT input)
{
    VS_OUTPUT output = (VS_OUTPUT)0;
    // Apply model-view-projection matrix (assuming it's a constant buffer)
    output.Pos = mul(input.Pos, g_WorldViewProjection);
    output.Tex = input.Tex;
    return output;
}

3. Hull Shader (HS) and Domain Shader (DS) Stages (Tessellation)

For advanced geometry manipulation, DirectX supports tessellation, which involves the Hull Shader and Domain Shader stages. These stages allow for dynamically generating more geometric detail from a simpler base mesh.

4. Geometry Shader (GS) Stage

The Geometry Shader is another programmable stage that can operate on entire primitives (points, lines, or triangles) as input. It can generate new primitives, discard existing ones, or modify their attributes. This stage is powerful for effects like generating fur, grass, or particle systems from a single point.

5. Stream Output (SO) Stage

The Stream Output stage is optional and allows the output of processed vertex data (from the VS, HS, DS, or GS stage) to be written to vertex buffers. This data can then be used as input for subsequent draw calls, enabling multi-pass rendering techniques or data analysis.

6. Rasterizer (RS) Stage

The Rasterizer stage is a fixed-function stage that takes the geometric primitives (transformed into clip-space) and converts them into fragments (potential pixels) that will be rendered on the screen. It performs clipping (removing primitives outside the view frustum), perspective division, and viewport transformation.

Simplified Geometry Processing Flow

Simplified Geometry Processing Pipeline Diagram

Note: HS, DS, GS, and SO are optional stages.

Key Concepts in Geometry Processing