Advertisement Jump to content
Sign in to follow this  
Muzzy A

D3D11 XMVECTOR - Is it safe to always keep loaded?

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

I'm making a math library to make doing the XMVECTOR and XMMATRIX math a bit simpler, I want it optimized as much as possible so I want to load the vector as few times as possible... unless it's fast enough I don't have to worry about it?

 

Is it safe to always have data loaded for SIMD instructions? If not, is it going to slow the process down if I Load the XMVECTOR every time I do an operation?

 

I haven't messed with SIMD instructions much..

Share this post


Link to post
Share on other sites
Advertisement

XMVECTOR and XMMATRIX are already easy to use. Even if you make own library it won't differ much and most likely will be slower.

 

 

 

Is it safe to always have data loaded for SIMD instructions? If not, is it going to slow the process down if I Load the XMVECTOR every time I do an operation?

 

What do you mean by "always have data loaded"?

Edited by Zaoshi Kaba

Share this post


Link to post
Share on other sites

if i do this

 

XMVECTOR someVec = XMLoadFloat3( XMFLOAT3( 1,1,1 ) );

 

is it safe to store that as a data member?

Share this post


Link to post
Share on other sites

It's safe to store it as a member as long as the thing it's a member of is allocated on a 16-byte boundary.

 

If it's heap allocated, that means you need to override global operator new and delete to get that alignment right. Unfortunately the standard Windows heap allocation functions only align to 8 bytes.

Share this post


Link to post
Share on other sites

ok I see thanks for the help.

 

I wish I understood how aligning bytes worked better, I didn't learn much about it in school and it seems confusing as hell when I look online lol.

Share this post


Link to post
Share on other sites

You just need to declare four new functions at global scope:

void* operator new (size_t size)
{
return _aligned_malloc(size, 16);
}

void operator delete (void *p)
{
_aligned_free(p);
}

void *operator new[](std::size_t size)
{
return _aligned_malloc(size, 16);
}

void operator delete[](void *p)
{
_aligned_free(p);
}

There's a slight complication that for completeness you'll probably want to overload the nothrow versions too, so you need 8 functions in total.
 
You may also want to make new throw appropriate exceptions, if you use them.

Edited by Adam_42

Share this post


Link to post
Share on other sites


is it safe to store that as a data member?

 

Load and Save operation are pretty much same as the ones in games; unless you save value it'll never get changed.

These functions exist because of data alignment. As Adam_42 mentioned you can overload new/delete operators.

This problem doesn't exist on 64 bit programs because alignment is suitable there, therefore you don't need Load/Save operations.

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!