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

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

问题描述

好吧,所以我在自己的DirectX框架上工作所有的教程关于制作一个DirectX框架是旧的,使用弃用的东西,所以我只是做了我自己的一个,虽然我从旧的教程,并更新他们使用新的Windows 8.1 SDK
和这里的问题,我得到错误与 XMMATRIX 原始代码使用 D3DXMATRIX

 (33):error C2719:'unnamed-parameter':带有__declspec(align('16'))对齐
(40):错误C2719:'unnamed-parameter':带__declspec(align('16')的形式参数)不对齐
(42):error C2719:'worldMatrix' :带有__declspec(align('16'))的形参不会对齐
(42):错误C2719:'viewMatrix':带有__declspec(align('16'))
(42):错误C2719:'projectionMatrix':带有__declspec(align('16'))的正式参数不会对齐

这是来自S_SHADER.h的第33行:

  bool Render(ID3D11DeviceContext *, int,XMMATRIX,XMMATRIX,XMMATRIX); 

这是第40行,来自S_SHADER.h:

  bool SetSHaderParameters(ID3D11DeviceContext *,XMMATRIX,XMMATRIX,XMMATRIX); 

,这是第42行的S_SHADER.cpp:

  41  -  bool S_SHADER :: Render(ID3D11DeviceContext * deviceContext,int indexCount,DirectX :: XMMATRIX worldMatrix,DirectX :: XMMATRIX viewMatrix,DirectX :: XMMATRIX projectionMatrix)
42 - {

实际上41有所有代码,42只有开放括号,做错了?



编辑:
不要以为这将有所帮助,但
i有一个windows 7 64位计算机与视觉工作室2013

解决方案

这是相当复杂的,并且覆盖在MSDN



简短的答案你需要使用调用约定友好的typedef,它们与x86 __fastcall,x64 __fastcall,ARM __fastcall和新的VS 2013 x86 / x64 __vectorcall的各种组合一起使用。



理想的解决方案是:

  bool XM_CALLCONV Render(ID3D11DeviceContext *,int,FXMMATRIX,CXMMATRIX,CXMMATRIX); 

bool XM_CALLCONV SetSHaderParameters(ID3D11DeviceContext *,FXMMATRIX,CXMMATRIX,CXMMATRIX);

您的原始版本实际上是为x64本机编译的,但是每个XMMATRIX都被压入堆栈,通过寄存器内。 x64 native保证栈变量的16字节对齐。



对于x86和x64,VS 2013支持一个新的调用约定__vectorcall,它可以传递寄存器中的前六个__m128值,包括异质向量聚合(HVAs)如XMMATRIX。



对于VS 2012及以下版本,x86 __fastcall通过了'const引用',而不是'前三个(3)__m128寄存器中的值,但不能通过寄存器中的HVAs。



对于VS 2012及以下版本,x64 __fastcall从不会通过寄存器中的__m128值。虽然栈的自然对齐允许XMVECTOR和XMMATRIX通过'value'作为堆栈上的副本,但通过'const引用'可能更有效。



对于ARM,__fastcall通过寄存器中的前四个(4)__n128值,并支持HVA。在这种情况下,这将是一个XMMATRIX。



因此DirectXMath的惯例使用 FXMVECTOR GXMVECTOR HXMVECTOR CXMVECTOR FXMMATRIX CXMMATRIX ,而不是使用 XMVECTOR XMMATRIX 直接。这可能有点复杂,但由于编译器抱怨,你看到与Win32,你可以解决不寻常或复杂的情况下一点试验和(编译器)错误。



或者,您不必担心向量和矩阵值的最优寄存器传递行为,只需选择简单的像:

  bool Render(ID3D11DeviceContext *,int,const XMMATRIX& const XMMATRIX& const XMMATRIX&); 

bool SetSHaderParameters(ID3D11DeviceContext *,const XMMATRIX& const XMMATRIX& const XMMATRIX&);

这在所有架构和调用约定中应该可以正常工作。


Ok so im working on my own DirectX framework all tutorials about making a DirectX framework are old and use deprecated stuff so i just made my own one , though i took somethings from the old tutorials and updated them to work with the new Windows 8.1 SDK and here comes The problem , i get errors with XMMATRIX the original code uses D3DXMATRIX

(33): error C2719: 'unnamed-parameter': formal parameter with __declspec(align('16')) won't be aligned
(40): error C2719: 'unnamed-parameter': formal parameter with __declspec(align('16')) won't be aligned
(42): error C2719: 'worldMatrix': formal parameter with __declspec(align('16')) won't be aligned
(42): error C2719: 'viewMatrix': formal parameter with __declspec(align('16')) won't be aligned
(42): error C2719: 'projectionMatrix': formal parameter with __declspec(align('16')) won't be aligned

this is Line 33 from S_SHADER.h :

bool Render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX);

this is line 40 from S_SHADER.h :

bool SetSHaderParameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX);

and this is line 42 from S_SHADER.cpp :

41 - bool S_SHADER::Render(ID3D11DeviceContext* deviceContext, int indexCount, DirectX::XMMATRIX worldMatrix,  DirectX::XMMATRIX viewMatrix, DirectX::XMMATRIX projectionMatrix)
42 - {

actually 41 has all the code and 42 has only the open brackets , anyways what am i doing wrong ?

EDIT : dont think this will help but i have a windows 7 64 bit computer with visual studio 2013

解决方案

This turns out to be rather complicated, and is covered on MSDN.

The short answer is you need to use calling-convention friendly typedefs that work with the various combinations of x86 __fastcall, x64 __fastcall, ARM __fastcall, and the new VS 2013 x86/x64 __vectorcall.

The 'ideal' solution is:

bool XM_CALLCONV Render(ID3D11DeviceContext*, int, FXMMATRIX, CXMMATRIX, CXMMATRIX);

bool XM_CALLCONV SetSHaderParameters(ID3D11DeviceContext*, FXMMATRIX, CXMMATRIX, CXMMATRIX);

Your original version would actually compile for x64 native, but each XMMATRIX is pushed onto the stack and is not passed "in-register". x64 native guarantees 16-byte alignment for stack variables. Win32 and ARM do not.

For x86 and x64, VS 2013 supports a new calling convention "__vectorcall" which can pass the first six (6) __m128 values in register including Heterogeneous Vector Aggregates (HVAs) like XMMATRIX. However, anything that doesn't fit into register should be passed by 'const reference' rather than by 'value'.

For VS 2012 and below, x86 __fastcall passes the first three (3) __m128 values in register, but cannot pass HVAs in register. The remainder have to be passed by 'const reference' rather than by 'value' due to the natural alignment of stack variables.

For VS 2012 and below, x64 __fastcall never passes __m128 values in register. While the natural alignment of the stack allows XMVECTOR and XMMATRIX to be passed by 'value' as a copy on the stack, it's likely more efficient to pass by 'const reference' instead.

For ARM, __fastcall passes the first four (4) __n128 values in register, and supports HVA. In this case, that would be one XMMATRIX.

Hence DirectXMath's conventions of using FXMVECTOR, GXMVECTOR, HXMVECTOR, CXMVECTOR, FXMMATRIX, and CXMMATRIX for parameters rather than using XMVECTOR or XMMATRIX directly. This can be a little complicated at first, but since the compiler complains as you've seen with Win32, you can work out unusual or complicated cases with a little trial and (compiler) error.

Alternately, you can not worry about 'optimal' register passing behavior of vector and matrix values, and just opt for something simple like:

bool Render(ID3D11DeviceContext*, int, const XMMATRIX&, const XMMATRIX&, const XMMATRIX&);

bool SetSHaderParameters(ID3D11DeviceContext*, const XMMATRIX&, const XMMATRIX&, const XMMATRIX&);

This should work fine across all the architectures and calling-conventions.

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

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