c++ - DirectX::XMMATRIX __declspec(align ('16' )) 不会对齐

标签 c++ windows visual-studio-2012 directx directx-11

我正在使用 DirectXMath 构建我的 3D 模拟项目

   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);
   }

我可能在 DirectXMath 中的 SIMD 标志上遇到了这类编译器错误:

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

有没有不转为DirectX::XMFLOAT4X4的其他方式?
顺便说一句,我正在使用 x86 机器并在 Visual Studio 2012 Express 上编译。

最佳答案

通过 const 引用而不是值传递值。

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

关于c++ - DirectX::XMMATRIX __declspec(align ('16' )) 不会对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15245378/

相关文章:

c++ - jpeg 全尺寸解码速度最快的解码器是什么?

c++ - 知道哪个编译器用 C++ 生成特定的二进制文件至关重要吗?

windows - 是否可以在 Linux 机器上编译 Windows 二进制文件?

c++ - 从 Visual Studio 2012 或 MS SQL 2012 中捕获 SQL 语句

c++ - 为什么在c++中使用ios::sync_with_stdio(false)后printf先于cout执行?

c++ - 发布项目 - 当我在 Eclipse 中完成 C++ 项目后该怎么办?

c++ - 使用 CMake 安装的 PDB 文件

windows - Perl Excel::Writer::XLSX-> new( 'myfile.xlsx' ) 在 Windows 8 环境中生成不适当的 I/O 错误

windows-8 - Win8 : Registration of the app in the layout folder . .. 失败

visual-studio-2012 - 解决方案资源管理器中的 Visual Studio 2012 蓝色警告图标