Skip to main content
GameDev.net gamedev.net
🔒 Locked

D3DXMATRIX vs. D3DXMATRIXA16 ?

Started by oxygen728 Sep 1, 2004 at 1:38 AM 2 replies 4.5k views
Original Post
oxygen728
oxygen728
Hey, sorry to be a bother.... but this is really confusing me... I spent a while trying to figure out why I kept getting the error (when trying to create a std::vector c:\Program Files\VS2003\Vc7\include\vector(507): error C2719: '_Val': formal parameter with __declspec(align('16')) won't be aligned Basically, When I switched out my D3DXMATRIXA16's with D3DXMATRIX's , things worked fine. Why is this? I appreciate it. I am worried that I may take a performance hit in the long run by not using A16's. Clarification: For example: THIS WORKS FINE: ------------------------------- class X { public: X():val_(0){} X(int val):val_(val){} int get(){return val_;} void set(int val){val_=val;} private: long Speed; double Size; double TimeTilStart; double DistanceToTravel; //////////////////////////////// <------------------------------------ D3DXMATRIX matTemp; //////////////////////////////// int val_; }; std::vector hi; THIS DOES NOT WORK FINE ------------------------------- class X { public: X():val_(0){} X(int val):val_(val){} int get(){return val_;} void set(int val){val_=val;} private: long Speed; double Size; double TimeTilStart; double DistanceToTravel; //////////////////////////////// <------------------------------- D3DXMATRIXA16 matTemp; //////////////////////////////// int val_; }; std::vector hi;
darookie
darookie
This might sound a bit stupid, but have you tried putting D3DXMATRIXA16 to the last position of your member variables?
class X{public:X():val_(0){}X(int val):val_(val){}int get(){return val_;}void set(int val){val_=val;}private:long Speed;double Size;double TimeTilStart;double DistanceToTravel;int val_;D3DXMATRIXA16 matTemp;};
vajuras
vajuras
D3DXMATRIXA16 is a 16 byte aligned structure. It cannot be copied-by-value by the VS .NET compiler because STL Vector does not guarantee that your matrix will be 16 byte aligned if it's copied as a member of a class. D3DXMATRIXA16 is defined using the align(16) macro.

You can copy your class by pointer. so if you have this:

class Bone{   D3DXMATRIXA16 mat;};std::vector<Bone*> bones;


What I've seen described in a few books/articles is that they take the 16 byte aligned struct and make it sperate in it's own array (AOS).

There are some other workarounds too but that is the gist of it. you can find more info on '16 byte alignment' at msdn.

[Edited by - vajuras on September 1, 2004 7:32:14 AM]
oxygen728
oxygen728
Thanks both of you, much appreciated.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.