Optimizing D3DXVECTOR usage..

Started by
5 comments, last by S1CA 18 years, 5 months ago
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?
Advertisement

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)

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

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.
Thanks both of you for the helpful information!
also you'll find that consoles work optimally having their data aligned to however many bits etc.....
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.
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.

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

This topic is closed to new replies.

Advertisement