Jump to content
  • Advertisement
Sign in to follow this  
Adaline

DirectXMath : when to use XMVECTOR ? when to use XMFLOATx ?

This topic is 2126 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

Hello

 

I'm new with DirectXMath and I'm confused with the vector types. I understand that XMVECTOR is a typedef on __m128, and XMFLOATx are just structures, but I don't know when I should use one or another sad.png since in D3DX all vector types were structures.

So it would be great if someone could point me out some tutos, demos or something.

 

I suppose I should always use XMVECTOR and convert them in XMFLOATx when needed (constant buffers, access to elements) ?

 

Thanks in advance

Edited by Tournicoti

Share this post


Link to post
Share on other sites
Advertisement

I'm no expert by any means, but my experience using directxmath types for x64 targets has been to use XMFLOATx for variables I won't be doing any maths on (for example light colours), since they only ever get loaded with values, there's no real benefit to using an SSE type (to my limited knowledge).  

 

For variables I will need to do math operations on, like position vectors, I use an __m128 type XMVECTOR for storage, since SSE operations can be used on them directly.  I think ultimately the choice of type depends on how you'll use the variable, so if you'll be doing more math operations than reading/writing individual elements, use an __m128 type.

 

If you're targetting x86 instead of x64 it's a bit more complicated and probably more straightforward to always use struct types for storage, and only store/load into __m128 types for involved math operations.  If you're comfortable handling alignment on the stack and heap though, you should be fine using them the same as you would in x64.

 

Worth noting also, you don't need to store for example an XMVECTOR into an XMFLOAT4 to copy it into a constant buffer.  You can just copy it directly.  The same for XMMATRIX, it can be copied directly to a mapped buffer's .pData without first storing into an XMFLOAT4X4.  At least that has been my experience.

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!