Evan
Evan

Reputation: 279

Stack Allocated Objects Optimized Away With XNAMATH

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);
 }

Upvotes: 0

Views: 157

Answers (1)

David
David

Reputation: 1017

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

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

Upvotes: 1

Related Questions