0

I have recently begun profiling and optimizing a DirectX 11 application that has been historically developed using the x64 platform configuration. After switching over to x86 to test behavior when using extended instruction sets, I began to notice certain objects of mine were being optimized away, most specifically stack allocated XMMATRIX objects. This only happens when building in x86 Release configuration (works fine in x64 release), and I have ensured to link against the correct libraries. I have also tested a fresh project to ensure I didn't accidentally change a buried project setting. I have verified that turning off C++ code optimization stops the problem. Are there any specific usage requirements that I have overlooked when trying to use the XNAMATH library when developing for the Windows x86 platform?

updated with code snippet

class Camera : public InputListener
{

public:
    Camera();
    ~Camera();

            /* Public functions here */ 
private:
    XMMATRIX mViewMatrix;
    XMMATRIX mInvView;
    XMMATRIX mProjectionMatrix;
    XMMATRIX mRotationMatrix;
    XMVECTOR mPosition;
    XMVECTOR mLookAt;

       /* Other variables and private funcctions here */

};



Camera::Camera() : mViewMatrix(),
               mProjectionMatrix(),
               mRightHold(false),
               mRotationMatrix(),
               mPosition(),
               /*other initializations*/
{
InputManager::GetInstance().RegisterListener(this);

mAspectRatio = (float)mViewWidth/(float)mViewHeight;

mProjectionMatrix = XMMatrixPerspectiveFovLH( mAngle, mAspectRatio, mNearClipDist, mFarClipDist );

mPosition = XMVectorSet( 0, 0, -100.0f,0.0f );
XMVECTOR Up = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f );
mViewMatrix = XMMatrixLookAtLH(mPosition,XMVectorSet(0,0,0,0),Up);

mHeightReciprocal = 1/(float)mViewHeight;
mWidthReciprocal = 1/(float)mViewWidth;
mAngleTangent = tanf(mAngle * 0.5f);
 }
Evan
  • 279
  • 1
  • 2
  • 11
  • Can you show us [some code](http://sscce.org/) that has this problem? What behaviour is making you believe the `XMMATRIX` objects are being optimised away? – Mankarse May 26 '13 at 03:29
  • Updated to reflect the first encountered usage of XMMATRIX (or any XNAMATH) during program flow. Camera is heap allocated during construction of a scene. The behavior I get are simply null pointer exceptions, first encountered when trying to construct the projection matrix. Seeing as my XMMATRIX is a stack allocated structure, I assumed it is either being optimized out (and the error is simply misleading), or it is a symptom of something else within the XNAMATH function call. – Evan May 26 '13 at 03:40

1 Answers1

1

Possibly connected to a similar issue I was having with memory alignment?

Crash after m = XMMatrixIdentity() - aligment memory in classes? in-classes

Community
  • 1
  • 1
David
  • 1,050
  • 1
  • 16
  • 31
  • 1
    This was indeed the issue. I was storing an XMMATRIX as a class data member. Resolved a while ago, but thanks for bringing it back up. – Evan Jul 18 '13 at 13:36