XMMath is a newer version of the math library based of the Xbox math library, So basically it is meant to supersede D3DX math.
Or that is my understanding of it.
Not only is XNAMath (XM, which is now renamed to DirectXMath already) newer it also supports SSE2 by default where D3DXMath didnt, it did if you turned the compile options in VS for it on. DirectXMath actually in the header detects whether the target it is being compiled for supports SSE2 and if so starts using SSE2 intrinsics and all the proper ways of using these.
As already pointed out the structure must be 16byte-aligned, this is not the cast with your vector3. You should change it to:
struct ConstantBuffer
{
D3DXMATRIX matWorld;
D3DXMATRIX matView;
D3DXMATRIX matProjection;
D3DXVECTOR3 vLightDir;
float padding; // unused
D3DXVECTOR4 vLightCol;
};
or
struct ConstantBuffer
{
D3DXMATRIX matWorld;
D3DXMATRIX matView;
D3DXMATRIX matProjection;
D3DXVECTOR4 vLightCol;
D3DXVECTOR3 vLightDir;
float padding;
};
or simply modify the return of sizeof(ConstantBuffer) to be a multiple of 16.
You dont need to add padding just :
__declspec( align ( 16 ) ) float;
#define ALIGN16 __declspec( align(16) )
ALIGN16 float
When using the declspec or macro the compiler will automatically add padding when needed without you having to write this explicitly, it keeps your code slightly cleaner and easier to understand.
As an example
struct MaterialContent
{
MaterialContent()
{
m_ambient[0] = 0.2f;
m_ambient[1] = 0.2f;
m_ambient[2] = 0.2f;
m_ambient[3] = 1.0f;
m_diffuse[0] = 0.8f;
m_diffuse[1] = 0.8f;
m_diffuse[2] = 0.8f;
m_diffuse[3] = 1.0f;
m_specular[0] = 0.0f;
m_specular[1] = 0.0f;
m_specular[2] = 0.0f;
m_specular[3] = 1.0f;
m_emissive[0] = 0.0f;
m_emissive[1] = 0.0f;
m_emissive[2] = 0.0f;
m_emissive[3] = 1.0f;
m_shininess = 1000.0f;
}
float m_ambient[4];
float m_diffuse[4];
float m_specular[4];
float m_emissive[4];
ALIGN16 float m_shininess;
};