Jump to content
  • Advertisement
Sign in to follow this  

FXMVECTOR,is this correct?

This topic is 2298 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I just started learning Dx 11 and getting used to the new xna math functions and all that stuff.

So,the book gives me some rules:
1.Use XMVECTOR for local and global variables
2.Use XMFLOAT2,XMFLOAT3 and XMFLOAT4 for class data members
3.Use loading functions to convert from XMFLOAT* to XMVECTOR before doing calculations.
4.Do calculations with XMVECTOR instances
5.Use storage functions to convert from XMVECTOR to XMFLOAT*

Later the book gives a demo.But it uses the cout << to output data,so it needs to overload the << operator.

[source lang="cpp"]ostream& operator<<(ostream& os, FXMVECTOR v)
XMFLOAT4 dest;
XMStoreFloat4(&dest, v);

os << "(" << dest.x << ", " << dest.y << ", " << dest.z << ", " << dest.w << ")";
return os;

FXMVECTOR is defined as an XMVECTOR so why do we need to use an XMFLOAT4 in order to show the data?the first rule says use XMVECTOR for local and global variables.
We get FXMVECTOR as an argument.

So,do we use XMFLOAT to show the data because the operator<< is part of a class?

Share this post

Link to post
Share on other sites
It seems like you're not too familiar with SIMD, so I'd recommend reading about it and the general best practices and you will begin to make sense of where these rules come from. There is a good article on Gamasutra that looks into the performance of different libs, including XNAMath or whatever they call it now.

To fully explain what's going on would require understanding on SIMD, LHS, alignment, and a few other things. So I will just lie and tell you this:

Think of XMVECTOR as a 128-bit built-in type with no operations defined on it. The only thing you can do to it is pass it to other functions. So to get data into that type, you need to call a function to load it (from an array of floats). Try to keep the data in an XMVECTOR as long as possible, since number crunching is pretty fast, loading/storing is not. So once all your calculations are done, you can't really "read" it directly, so you need to store it back into a format you do understand (floats).

So with that in mind, you have a 128-bit value that is meaningless. How do you print it out? Convert it to something you do understand (floats), and print those instead. And don't get too caught up on the FXMVECTOR thing, it's explain in the docs if you're interested, but it's about squeezing out maximum performance out of SIMD across x86, x64, and PPC, but it will always be passing XMVECTOR by reference or value.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!