Shaders and input

When rendering any geometry in Direct3D, a shader is always required. Shaders are small applications run on the GPU transforming input data to output data. There are several shader combinations, where every shader has a separate purpose.

The most important stage in rendering, and the stage that is always required, is the Vertex Shader. This shader stage is generally responsible for taking in data, and returning a vertex position in clip-space. This clip-space coordinate is then used to clip the incoming geometry to fit within the render area, and to convert into a screen coordinate. These positions are then used to render the geometry - commonly triangles - on the screen.

The second most common stage, is the pixel shader. The pixel shader is responsible for receiving data from the vertex shader, and determining the color of the pixel within the geometry. This is usually done by taking input data interpolated from the data from the vertex shader, and that sampled from textures.

Shaders are written in HLSL and compiled to bytecode before being passed to the API.

Input layout

In order to pass vertex data to the vertex shader, Direct3D 11 uses the input layout, which is an object matching input semantics in the shader to an input slot for the vertex buffers. For example, the vertex shader might expect to obtain 3 floats per vertex from the application. Rather than taking a slot ID, the application provides each slot with a semantic indicating a human-readable name for the slot. So position attributes might be named POSITION, indicating the receiving point for positional data.

This simplifies portability of shaders by allowing slots to be defined out-of-order, and allows the runtime to map the application slots to the shader slots dynamically.