Sign in to follow this  
jeffason

Optimizing D3DXVECTOR usage..

Recommended Posts

jeffason    138
I read in the docs I should add this to our program to optimize D3DX functions use of D3DXVECTORs: #define D3DX_ALIGN16 __declspec(align(16)) Where exactly do I need to put this or does it matter?

Share this post


Link to post
Share on other sites
S1CA    1418

D3DX_ALIGN16 D3DXVECTOR4 m_blah;


The compilers preprocessor turns that into:

__declspec(align(16)) D3DXVECTOR4 m_blah;


__declspec() is a standard MSVC thing, align(16) is a standard MSVC.NET thing (or MSVC 6 with the processor pack installed).


You won't see much benefit from aligned vectors and matrices unless you process lots of them in one go. An example of this would be using D3DXVec3TransformArray() to transform a few hundred vectors.

Look out for the D3DX*Array() functions, and try to use them on reasonable amounts of data (i.e. more than 50 items or so)

Share this post


Link to post
Share on other sites
paic    645
Hi,

The align(16) tell your compiler to try aligning the structure on 16 bytes (means the starting address of the structure is a 16 bytes multiple)

It allows to use SSE2 instructions on those structure for example (because many of those instructions work on 16 bytes blocks, and you can't use them if your datas are not aligned on 16 bytes)

So, maybe there's a D3DX version optimized for SSE2 which might take advantage of aligning D3DXVECTORS on 16 bytes ...
An other example of that is the D3DXMATRIXA16 which is only a D3DXMATRIX ... but aligned on 16 bytes ^^ And the doc recommend to use the A16 version of the matrix for performance.

Share this post


Link to post
Share on other sites
Quote:
Original post by S1CA
__declspec() is a standard MSVC thing, align(16) is a standard MSVC.NET thing (or MSVC 6 with the processor pack installed).

While the documentation says align 16 should work on MSVC6 (I think I saw it in the comments in the A16 matrix definition .h file), in my brief testing, it didn't. If you're using MSVC6, I'd suggest double checking that it actually does or does not work yourself.

Share this post


Link to post
Share on other sites
S1CA    1418
Quote:
Original post by Namethatnobodyelsetook
Quote:
Original post by S1CA
__declspec() is a standard MSVC thing, align(16) is a standard MSVC.NET thing (or MSVC 6 with the processor pack installed).

While the documentation says align 16 should work on MSVC6 (I think I saw it in the comments in the A16 matrix definition .h file), in my brief testing, it didn't. If you're using MSVC6, I'd suggest double checking that it actually does or does not work yourself.


Yeah, MSVC 6 "out of the box" doesn't support align 16. But I remember that it does support it if you install the latest MSVC 6 service pack and the Processor Pack; ISTR SSE and 3DNow! support was added to the inline assembler in the same update. I was using the align declspec (and some 3DNow!) with MSVC 6 Professional, not sure if the other editions support the processor pack though.


Quote:
Original post by RavNaz
also you'll find that consoles work optimally having their data aligned to however many bits etc.....


Yep, the PC does in some situations too. Many non x86 CPUs require data to be aligned (most common is alignment to an even address) or they'll generate an exception.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this