Jump to content
  • Advertisement
Sign in to follow this  
savail

XMVECTOR vs XMFLOAT4 in classes

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

Hey,

I'm wondering how should I get around with those types. I've read that I should use XMFLOATs in classes for storage purposes but for calculations convert it to local XMVECTOR objects.

 

1. Doesn't converting from one type to another, whenever I need to calculate sth, slow down the performance? Isn't it better to properly align class and then always use XMVECTOR in it?

 

2. If I should use XMFLOAT for storage purposes, does it mean that I should use XMFLOAT for filling the data as well? Or is it faster and preferred to use XMVECTOR to fill data  in there and then store it in XMFLOAT?

 

I would be very grateful for answering 2 of my questions!

Edited by savail

Share this post


Link to post
Share on other sites
Advertisement

thanks for answer!

 


 Isn't it better to properly align class and then always use XMVECTOR in it?

 

 

A lot of libs (I'm using Bullet Math) follow that pattern. You should be very careful again, with passing aligned values, type casting ect. (http://msdn.microsoft.com/en-us/library/83ythb65.aspx)

 So it's a better solution if I want my program / game run as smoothly and quickly as possible?

 

According to my 2. question I mean:

I have a XMFLOAT3A Position in my class and

Should I use something like this:

DirectX::XMStoreFloat3A(&Position, DirectX::XMVectorSet(-1.0f, -1.0f, 0.0f, 0.0f));

or:

Position.x = -1.0f;
Position.y = -1.0f
Position.z = 0.0f;

to fill the Position vector? What's faster and better to use? or it doesn't matter at all?

Edited by savail

Share this post


Link to post
Share on other sites

Should I use something like this:

DirectX::XMStoreFloat3A(&Position, DirectX::XMVectorSet(-1.0f, -1.0f, 0.0f, 0.0f));

or:

 

 

Position.x = -1.0f;
Position.y = -1.0f
Position.z = 0.0f;

 

 

 
Well if you click "Go to Definition" for the XMVectorSet :
 
 
inline XMVECTOR XMVectorSet
(
    float x, 
    float y, 
    float z, 
    float w
)
{
#if defined(_XM_NO_INTRINSICS_)
    XMVECTORF32 vResult = {x,y,z,w};
    return vResult.v;
#elif defined(_XM_ARM_NEON_INTRINSICS_)
    __n64 V0 = vcreate_f32(((uint64_t)*(const uint32_t *)&x) | ((uint64_t)(*(const uint32_t *)&y) << 32));
    __n64 V1 = vcreate_f32(((uint64_t)*(const uint32_t *)&z) | ((uint64_t)(*(const uint32_t *)&w) << 32));
    return vcombine_f32(V0, V1);
#elif defined(_XM_SSE_INTRINSICS_)
    return _mm_set_ps( w, z, y, x );
#else // _XM_VMX128_INTRINSICS_
#endif // _XM_VMX128_INTRINSICS_
}

So if you use XMStoreFloat3A approch: a temp object will be generated from XMVectorSet later it will be passed by value to XMStoreFloat3A(wich is ok because of the registers).
So more instruction will be generated, well the compiler will try optimize that but don't count on this...

 

"postion.x = something" won't generate some useless instructions and i think it is cleaner than the other approch.
 

 So it's a better solution if I want my program / game run as smoothly and quickly as possible?

 

 

Well probably yes. 

 

The point is that loading/storing unaligned values into the aligned vars is slow, but it isn't a big deal. That part of the program won't give you the desired 30 to 60 fps jump.

 

If you're asking me for an advice I would tell you to use the aligned data. Because:

 

- for x64 achitecture there will be no overhead when 'converting' from XMFLOAT* to XMVECTOR

- the code is more readable 

Edited by imoogiBG

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!