Jump to content
  • Advertisement
Sign in to follow this  
sepul

Unity SSE weird problems ...

This topic is 3333 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've been having weird SSE implementation problems, that made to shut it out for a long time, now that I need to use it in my engine, and problems still arise and I'm really confused about this. I would be really glad if someone could help and give me a hint or something on this. first of all I'm using the MSVC2008(9.0)-SP1 compiler and the CPU is intel dual core 5200 check out my previous post on this topic, it describes the whole problem : http://www.gamedev.net/community/forums/topic.asp?topic_id=464043 the weird thing about this, is the memory exception is triggered randomly, most of the times in my MFC editor app, and sometimes in my win32 test bed app. I guess it has to do something with the memory alignment, because when I change the 'movaps' instruction to 'movups', I get no errors ... but how can be random ? I tried using __declspec(align(16)) in every way for the matrix and vector member vars, and it didn't change anything. another thing ... here is the following code that calls the matrix multiplication and the error arises :
	_cam->setProjSize( (float)getRttWidth(), (float)getRttHeight() );
	const hmrMatrix44& projMat = _cam->getProjMat();
	const hmrMatrix44& viewMat = _cam->getViewMat();

	hmrMatrix44::mul( viewMat, projMat, viewProjMat );  // <-- bang, 'movaps' exception
	frustum->calculatePlanes( viewProjMat );

when I change the code to this ....
	_cam->setProjSize( (float)getRttWidth(), (float)getRttHeight() );
	hmrMatrix44 projMat = _cam->getProjMat();
	hmrMatrix44 viewMat = _cam->getViewMat();

	hmrMatrix44::mul( viewMat, projMat, viewProjMat );  // <-- no exception
	frustum->calculatePlanes( viewProjMat );

the problem is gone, even when I multiply some other matrices, it's ok . here is the mul function definition :
	static void mul( const hmrMatrix44& m1, const hmrMatrix44& m2, hmrMatrix44& r );

the funny thing is, if this piece runs ok, I get some other (same) problem somewhere else, this time with vector operations . the code is also open source, you can download the whole math library here and test it for yourself. It has gone really frustrating for me, and can't figure it out, do I have to change some compiling options or something ? what's the problem ? thanks

Share this post


Link to post
Share on other sites
Advertisement
Quote:
how are you allocating the hmrMatrix44 which is being returned from the camera?

sorry, but what did you mean by that ?
the matrices returned by getViewMat, getProjMat functions are members of camera class.
actually the problem is not with that, like I said, the problem arises in some app, where it's ok in another one, with the exact same code and library.

I even got the exception on my win32 test app, rebuild the app again and the problem was gone. but In one of my mfc apps, I always get the same problem.

even when I skip this matrix*matrix part, I get some other SIMD memory exception for vector operations in some other part of the code.

Share this post


Link to post
Share on other sites
Then how do you allocate the camera instance - on the stack, or the heap? If on the heap, do you use a 16 byte aligned memory allocator? Or, if the camera class is allocated as part of a enclosing parent class, how is the instance of that class allocated?

Although the vector/matrix class will be padded to be 16 byte aligned relative to the camera class, you still have to ensure that the camera class is then allocated with 16 byte alignment if you are using dynamic allocations.

Share this post


Link to post
Share on other sites
Quote:
Although the vector/matrix class will be padded to be 16 byte aligned relative to the camera class, you still have to ensure that the camera class is then allocated with 16 byte alignment if you are using dynamic allocations.


wow, man that was really helpful, I didn't knew that

here is the class structure related to the camera ...
object->entity->camera

the camera has these hmrMatrix44 members which are 16byte aligned (viewMat, projMat) and I create the camera dynamically by the 'new' operator

as you said I overrided new operator on the camera class :

class hmrCamera : public hmrEntity {
//... blah blah
void* operator new( size_t s )
{
return _aligned_malloc( s, 16 );
}

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

protected:
hmrMatrix44 _viewMat;
hmrMatrix44 _projMat;
}




... and the exception is gone ! you were right !
but let me get this straight for myself, do I have to override every class' allocation operators that has vector/matrix members, for 16byte alignment to ensure the byte padding ?

thank you very much

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!