Just so you know, SemanticName can be whatever you want it to be, so the second position you have can have a little more descriptive name.
HLSL packs constant buffers into 16 byte chunks, so you need to make sure that you take that into account. for example, if your vertex structure looks like this:
struct VertexInfo
{
int pos; // 4 bytes
XMFLOAT4A color; // i'm not sure, but 16 bytes here?
};
the above would throw an error, because it would take the pos variable (4 bytes), then the first 12 bytes of the color variable to finish the 16 byte block. you can fix it by either putting color first in the structure (12 bytes would be added to the end of the structure to complete the 16 byte alignment), or you can add padding between the pos and color variables:
struct VertexInfo
{
int pos; // 4 bytes
int pad1; // 4 bytes
int pad2; // 4 bytes
int pad3; // 4 bytes
XMFLOAT4A color; // i'm not sure, but 16 bytes here?
};
looking at your code, your vertex structure looks like this:
struct VertexInfo
{
XMFLOAT4A positions; // 16 bytes
XMFLOAT4A normals ; // 16 bytes
XMFLOAT4A texCoords ; // 16 bytes
};
this is a total of 48 bytes, where each variable is 16 bytes. now look at the input layout you provided:
D3D11_INPUT_ELEMENT_DESC layout[6];
layout[indexLayout].SemanticName = "POSITION";
layout[indexLayout].SemanticIndex = 0;
layout[indexLayout].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;//16 bytes
layout[indexLayout].InputSlot = 0;
layout[indexLayout].AlignedByteOffset = 0;
layout[indexLayout].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
layout[indexLayout].InstanceDataStepRate = 0;
indexLayout++ ;
layout[indexLayout].SemanticName = "NORMAL";
layout[indexLayout].SemanticIndex = 0;
layout[indexLayout].Format = DXGI_FORMAT_R16G16B16A16_FLOAT;//8 bytes
layout[indexLayout].InputSlot = 0;
layout[indexLayout].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
layout[indexLayout].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
layout[indexLayout].InstanceDataStepRate = 0;
indexLayout++ ;
layout[indexLayout].SemanticName = "COLOR";
layout[indexLayout].SemanticIndex = 0;
layout[indexLayout].Format = DXGI_FORMAT_R8G8B8A8_UNORM;//DXGI_FORMAT_R32G32B32A32_FLOAT a la place ?? //4 bytes
layout[indexLayout].InputSlot = 0;
layout[indexLayout].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
layout[indexLayout].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
layout[indexLayout].InstanceDataStepRate = 0;
indexLayout++ ;
layout[indexLayout].SemanticName = "TEXCOORD";
layout[indexLayout].SemanticIndex = 0;
layout[indexLayout].Format = DXGI_FORMAT_R8G8B8A8_UNORM;//4 bytes
layout[indexLayout].InputSlot = 0;
layout[indexLayout].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
layout[indexLayout].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
layout[indexLayout].InstanceDataStepRate = 0;
indexLayout++ ;
layout[indexLayout].SemanticName = "SV_POSITION";
layout[indexLayout].SemanticIndex = 0;
layout[indexLayout].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;//laisser à 32 ? //16 bytes
layout[indexLayout].InputSlot = 0;
layout[indexLayout].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
layout[indexLayout].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
layout[indexLayout].InstanceDataStepRate = 0;
indexLayout++ ;
layout[indexLayout].SemanticName = "POSITION";
layout[indexLayout].SemanticIndex = 1;
layout[indexLayout].Format = DXGI_FORMAT_R32G32B32A32_FLOAT; //16 bytes
layout[indexLayout].InputSlot = 0;
layout[indexLayout].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
layout[indexLayout].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
layout[indexLayout].InstanceDataStepRate = 0;
indexLayout++ ;
that is a total of 64 bytes. the problems is that for the first vertex you pass in, hlsl is expecting 64 bytes for it. you provide only 48. what happens is it will take the first 16 bytes of the next vertex. when you pass in all your vertices, its more like a chunk of data, not an array. hlsl grabs chunks from this data in increments of whatever you specified for the input layout.
so say you have 3 vertices. because of your vertex structure, you are passing in a total of 144 bytes.
HLSL will grab the first 64 bytes for the first vertex, which is your actual first vertex, and 16 bytes of the next vertex. that leaves you with 80 bytes of vertices left after hlsl grabs the first vertex. for the second vertex, it grabs another 64 bytes, which is the rest of your second vertex, and part of the last vertex, leaving you with 16 bytes. for the third vertex, it tries for another 64 bytes, but there is only 16 bytes left.
and your vs input just has to match with your input layout, which it does not here. (you have 6 parts to your input layout, and only 4 parts here)
struct vsIn
{
float4 position : POSITION ;
float4 normal : NORMAL ;
float4 color : COLOR0 ;
float4 texCoord : TEXCOORD0 ;
};
So, if your looking for everything to work with the vs input structure you have above, you'll want this code:
struct VertexInfo
{
XMFLOAT4A positions; // 16 bytes
XMFLOAT4A normals ; // 16 bytes
XMFLOAT4A color; // 16 bytes
XMFLOAT4A texCoord; // 16 bytes
};
D3D11_INPUT_ELEMENT_DESC layout[6];
layout[indexLayout].SemanticName = "SV_POSITION";
layout[indexLayout].SemanticIndex = 0;
layout[indexLayout].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;//16 bytes
layout[indexLayout].InputSlot = 0;
layout[indexLayout].AlignedByteOffset = 0;
layout[indexLayout].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
layout[indexLayout].InstanceDataStepRate = 0;
indexLayout++ ;
layout[indexLayout].SemanticName = "NORMAL";
layout[indexLayout].SemanticIndex = 0;
layout[indexLayout].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;//16 bytes
layout[indexLayout].InputSlot = 0;
layout[indexLayout].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
layout[indexLayout].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
layout[indexLayout].InstanceDataStepRate = 0;
indexLayout++ ;
layout[indexLayout].SemanticName = "COLOR";
layout[indexLayout].SemanticIndex = 0;
layout[indexLayout].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;//16 bytes
layout[indexLayout].InputSlot = 0;
layout[indexLayout].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
layout[indexLayout].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
layout[indexLayout].InstanceDataStepRate = 0;
indexLayout++ ;
layout[indexLayout].SemanticName = "TEXCOORD";
layout[indexLayout].SemanticIndex = 0;
layout[indexLayout].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;//16 bytes
layout[indexLayout].InputSlot = 0;
layout[indexLayout].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
layout[indexLayout].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
layout[indexLayout].InstanceDataStepRate = 0;
indexLayout++ ;
you can leave your vs input structure the way it is.
Also, SemanticName can be whatever you want, but there are a couple SemanticNames that are actually system value semantics, SV_POSITION is one of them. you can read more about them here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb509647(v=vs.85).aspx#System_Value