DirectX::XMMATRIX __declspec(align('16')) 不会对齐 [英] DirectX::XMMATRIX __declspec(align('16')) won't be aligned

查看:30
本文介绍了DirectX::XMMATRIX __declspec(align('16')) 不会对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我可能在 DirectXMath 中的 SIMD 标志上收到此类编译器错误:

I get these kind of compiler errors probably on SIMD flag inside DirectXMath:

错误 C2719:'_world':带有 __declspec(align('16')) 的形参将不会对齐
错误 C2719:_view":带有 __declspec(align('16')) 的形参将不会对齐
错误 C2719:_projection":带有 __declspec(align('16')) 的形参将不会对齐

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 上进行编译.

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.

推荐答案

通过常量引用而不是通过值传递值.

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)

这篇关于DirectX::XMMATRIX __declspec(align('16')) 不会对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆