Input layout

We have now created both the vertex data buffer, and the shaders which use the vertex data. However, it may not be clear how the two are linked. This is because we have not specified how they are linked.

The object intended to do so is the ID3D11InputLayout. Creation of this object follows.

result = renderer->device->lpVtbl->CreateInputLayout (
    renderer->device,
    (D3D11_INPUT_ELEMENT_DESC[ATTRIBUTE_COUNT]){
        [ATTRIBUTE_POSITION] = {
            .SemanticName   = "POSITION",
            .Format         = DXGI_FORMAT_R32G32B32_FLOAT,
            .InputSlot      = ATTRIBUTE_POSITION,
            .InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA,
        },
        [ATTRIBUTE_TEXCOORD] = {
            .SemanticName   = "TEXCOORD",
            .Format         = DXGI_FORMAT_R32G32_FLOAT,
            .InputSlot      = ATTRIBUTE_TEXCOORD,
            .InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA,
        },
    },
    ATTRIBUTE_COUNT,
    vsAsset->data,
    vsAsset->size,
    &renderer->il
);
if ( !SUCCEEDED ( result ) )
    RETURN_ERROR(-1, "CreateInputLayout failed (0x%08X)", result );

A few things should be of note. The input elements specified contain a SemanticName and SemanticIndex property, which are linked to the semantics in the HLSL vertex shader. (See: ApplicationToVertex) The InputSlot property specifies the index of the vertex buffer description when setting the property before rendering. InputSlotClass specifies whether the vertex index or instance index should be used to pick an element from the vertex buffer. The Format property specifies how many elements there are per property and of what type.

Last, but certainly not least: The bytecode of the vertex shader is required when creating the input layout. This is in order to determine the layout in the vertex shader to map the elements you specified to.