When I multiply matrices on CPU
D3DXMATRIX mb = mbb.matWorld * mbb.matView * mbb.matProj;
D3D11_BUFFER_DESC bd;
ZeroMemory(&bd, sizeof(bd));
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof(D3DXMATRIX);
bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
bd.CPUAccessFlags = 0;
D3D11_SUBRESOURCE_DATA initData;
ZeroMemory(&initData, sizeof(initData));
initData.pSysMem = &mb;
//*****************************************
cbuffer ConstantBuffer : register(cb0)
{
matrix mat;
float4 vs(float4 pos : POSITION) : SV_POSITION
{
float4 ret = mul(pos, mat);
return ret;
}
It works great. But when I do it on GPU
struct Buffer
{
D3DXMATRIX mat[3];
};
Buffer b;
// b[..] = ....
D3D11_BUFFER_DESC bd;
ZeroMemory(&bd, sizeof(bd));
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof(D3DXMATRIX) * 3;
bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
bd.CPUAccessFlags = 0;
D3D11_SUBRESOURCE_DATA initData;
ZeroMemory(&initData, sizeof(initData));
initData.pSysMem = &b;
//*****************************************
cbuffer ConstantBuffer : register(cb0)
{
matrix matWorld;
matrix matView;
matrix matProj;
}
float4 vs(float4 pos : POSITION)
{
float4 ret = mul(pos, matWorld);
ret = mul(ret, matView);
ret = mul(ret, matProj);
return ret;
}
Nothing is rendered on the screen. What's wrong?
I've been debugging with PIX and it shows that in both versions post-vs vertices are the same.
I noticed that it's caused by projection matrix. For my projection matrix I do:
D3DXMatrixPerspectiveFovLH(&mbb.matProj, D3DX_PI / 2, (float) init_params.width / init_params.height, 0.01f, 100.0f)
FIXED
I have to transpose matrices before passing them to vertex shader.