D3D12_INPUT_ELEMENT_DESC
The D3D12_INPUT_ELEMENT_DESC
structure describes an element in a vertex buffer layout. It is used when creating an input layout for the graphics pipeline.
Syntax
typedef struct D3D12_INPUT_ELEMENT_DESC {
LPCSTR SemanticName;
UINT SemanticIndex;
DXGI_FORMAT Format;
UINT InputSlot;
UINT AlignedByteOffset;
D3D12_INPUT_CLASSIFICATION InputSlotClass;
UINT InstanceDataStepRate;
} D3D12_INPUT_ELEMENT_DESC;
Members
Member | Type | Description |
---|---|---|
SemanticName |
LPCSTR | Identifier for the element (e.g., "POSITION", "NORMAL"). |
SemanticIndex |
UINT | Index for semantic when multiple elements share the same name. |
Format |
DXGI_FORMAT | Data format of the element (e.g., DXGI_FORMAT_R32G32B32_FLOAT ). |
InputSlot |
UINT | Zero‑based slot index of the vertex buffer containing this element. |
AlignedByteOffset |
UINT | Byte offset from the start of the vertex. Use D3D12_APPEND_ALIGNED_ELEMENT to have the API compute the offset. |
InputSlotClass |
D3D12_INPUT_CLASSIFICATION | Specifies whether the data is per‑vertex or per‑instance (D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA or D3D12_INPUT_CLASSIFICATION_PER_INSTANCE_DATA ). |
InstanceDataStepRate |
UINT | Number of instances to draw using the same per‑instance data before advancing to the next element. Set to 0 for per‑vertex data. |
Example
// Define an input layout for a simple vertex with position and color
D3D12_INPUT_ELEMENT_DESC inputLayout[] = {
{
"POSITION", // SemanticName
0, // SemanticIndex
DXGI_FORMAT_R32G32B32_FLOAT, // Format
0, // InputSlot
0, // AlignedByteOffset
D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA,
0 // InstanceDataStepRate
},
{
"COLOR", // SemanticName
0,
DXGI_FORMAT_R32G32B32A32_FLOAT,
0,
D3D12_APPEND_ALIGNED_ELEMENT, // Auto‑calculate offset
D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA,
0
}
};
// Create the input layout descriptor
D3D12_INPUT_LAYOUT_DESC layoutDesc = {};
layoutDesc.pInputElementDescs = inputLayout;
layoutDesc.NumElements = _countof(inputLayout);
// When creating the pipeline state object:
pipelineStateDesc.InputLayout = layoutDesc;