DirectX::XMMATRIX __declspec(align('16')) won't be aligned

c++, directx, directx-11, visual-studio-2012, windows

Solution

Pass the values by const reference instead of by value.

void SetConstantBuffer(
    ID3D11DeviceContext*_device_context,
    const DirectX::XMMATRIX &_world,
    const DirectX::XMMATRIX &_view,
    const DirectX::XMMATRIX &_projection)

Problem

I am using DirectXMath in building my 3D simulation project ``` void SetConstantBuffer(ID3D11DeviceContext*_device_context, DirectX::XMMATRIX _world, DirectX::XMMATRIX _view, DirectX::XMMATRIX _projection) { ConstantBuffer const_buffer; const_buffer.View = DirectX::XMMatrixTranspose(_world); const_buffer.World = DirectX::XMMatrixTranspose(_view); const_buffer.Projection = DirectX::XMMatrixTranspose(_projection); _device_context->UpdateSubresource(m_const_buffer, 0, NULL, &const_buffer, 0, 0); } ``` I get these kind of compiler errors probably on SIMD flag inside DirectXMath: error C2719: '_world': formal parameter with __declspec(align('16')) won't be aligned error C2719: '_view': formal parameter with __declspec(align('16')) won't be aligned error C2719: '_projection': formal parameter with __declspec(align('16')) won't be aligned Is there any other way without converting it to DirectX::XMFLOAT4X4? By the way I'm using an x86 machine and compiling on Visual Studio 2012 Express.

Original source