Commits

Brad Kittenbrink  committed 063f88f

Fix up alignment problems for debug build.
reviewed by davep.

  • Participants
  • Parent commits 8960339

Comments (0)

Files changed (5)

File indra/llcommon/llmemory.h

 
 #include "llmemtype.h"
 
-#if 0  //DON'T use ll_aligned_foo now that we use tcmalloc everywhere (tcmalloc aligns automatically at appropriate intervals)
+#if LL_DEBUG
 inline void* ll_aligned_malloc( size_t size, int align )
 {
 	void* mem = malloc( size + (align - 1) + sizeof(void*) );
 	free(p); // posix_memalign() is compatible with heap deallocator
 #endif
 }
-#endif
+#else // LL_DEBUG
+// ll_aligned_foo are noops now that we use tcmalloc everywhere (tcmalloc aligns automatically at appropriate intervals)
+#define ll_aligned_malloc( size, align ) malloc(size)
+#define ll_aligned_free( ptr ) free(ptr)
+#define ll_aligned_malloc_16 malloc
+#define ll_aligned_free_16 free
+#define ll_aligned_malloc_32 malloc
+#define ll_aligned_free_32 free
+#endif // LL_DEBUG
 
 class LL_COMMON_API LLMemory
 {

File indra/llmath/llvolume.cpp

 	mProfilep = NULL;
 	mVolumeFaces.clear();
 
-	free(mHullPoints);
+	ll_aligned_free_16(mHullPoints);
 	mHullPoints = NULL;
-	free(mHullIndices);
+	ll_aligned_free_16(mHullIndices);
 	mHullIndices = NULL;
 }
 
 {
 	if (!mData)
 	{
-		mData = (LLVector4a*) malloc(sizeof(LLVector4a)*2);
+		mData = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*2);
 	}
 }
 
 
 LLVolumeFace::VertexData::~VertexData()
 {
-	free(mData);
+	ll_aligned_free_16(mData);
 	mData = NULL;
 }
 
 	mWeights(NULL),
 	mOctree(NULL)
 {
-	mExtents = (LLVector4a*) malloc(sizeof(LLVector4a)*3);
+	mExtents = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*3);
 	mCenter = mExtents+2;
 }
 
 	mWeights(NULL),
 	mOctree(NULL)
 { 
-	mExtents = (LLVector4a*) malloc(sizeof(LLVector4a)*3);
+	mExtents = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*3);
 	mCenter = mExtents+2;
 	*this = src;
 }
 		}
 		else
 		{
-			free(mBinormals);
+			ll_aligned_free_16(mBinormals);
 			mBinormals = NULL;
 		}
 
 		}
 		else
 		{
-			free(mWeights);
+			ll_aligned_free_16(mWeights);
 			mWeights = NULL;
 		}
 	}
 
 LLVolumeFace::~LLVolumeFace()
 {
-	free(mExtents);
+	ll_aligned_free_16(mExtents);
 	mExtents = NULL;
 
 	freeData();
 
 void LLVolumeFace::freeData()
 {
-	free(mPositions);
+	ll_aligned_free_16(mPositions);
 	mPositions = NULL;
-	free( mNormals);
+	ll_aligned_free_16( mNormals);
 	mNormals = NULL;
-	free(mTexCoords);
+	ll_aligned_free_16(mTexCoords);
 	mTexCoords = NULL;
-	free(mIndices);
+	ll_aligned_free_16(mIndices);
 	mIndices = NULL;
-	free(mBinormals);
+	ll_aligned_free_16(mBinormals);
 	mBinormals = NULL;
-	free(mWeights);
+	ll_aligned_free_16(mWeights);
 	mWeights = NULL;
 
 	delete mOctree;
 	
 	//allocate space for new buffer
 	S32 num_verts = mNumVertices;
-	LLVector4a* pos = (LLVector4a*) malloc(sizeof(LLVector4a)*num_verts);
-	LLVector4a* norm = (LLVector4a*) malloc(sizeof(LLVector4a)*num_verts);
+	LLVector4a* pos = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts);
+	LLVector4a* norm = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts);
 	S32 size = ((num_verts*sizeof(LLVector2)) + 0xF) & ~0xF;
-	LLVector2* tc = (LLVector2*) malloc(size);
+	LLVector2* tc = (LLVector2*) ll_aligned_malloc_16(size);
 
 	LLVector4a* wght = NULL;
 	if (mWeights)
 	{
-		wght = (LLVector4a*) malloc(sizeof(LLVector4a)*num_verts);
+		wght = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts);
 	}
 
 	LLVector4a* binorm = NULL;
 	if (mBinormals)
 	{
-		binorm = (LLVector4a*) malloc(sizeof(LLVector4a)*num_verts);
+		binorm = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts);
 	}
 
 	//allocate mapping of old indices to new indices
 		mIndices[i] = new_idx[mIndices[i]];
 	}
 	
-	free(mPositions);
-	free(mNormals);
-	free(mTexCoords);
-	free(mWeights);
-	free(mBinormals);
+	ll_aligned_free_16(mPositions);
+	ll_aligned_free_16(mNormals);
+	ll_aligned_free_16(mTexCoords);
+	ll_aligned_free_16(mWeights);
+	ll_aligned_free_16(mBinormals);
 
 	mPositions = pos;
 	mNormals = norm;
 
 void LLVolumeFace::resizeVertices(S32 num_verts)
 {
-	free(mPositions);
-	free(mNormals);
-	free(mBinormals);
-	free(mTexCoords);
+	ll_aligned_free_16(mPositions);
+	ll_aligned_free_16(mNormals);
+	ll_aligned_free_16(mBinormals);
+	ll_aligned_free_16(mTexCoords);
 
 	mBinormals = NULL;
 
 	if (num_verts)
 	{
-		mPositions = (LLVector4a*) malloc(sizeof(LLVector4a)*num_verts);
+		mPositions = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts);
 		assert_aligned(mPositions, 16);
-		mNormals = (LLVector4a*) malloc(sizeof(LLVector4a)*num_verts);
+		mNormals = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts);
 		assert_aligned(mNormals, 16);
 
 		//pad texture coordinate block end to allow for QWORD reads
 		S32 size = ((num_verts*sizeof(LLVector2)) + 0xF) & ~0xF;
-		mTexCoords = (LLVector2*) malloc(size);
+		mTexCoords = (LLVector2*) ll_aligned_malloc_16(size);
 		assert_aligned(mTexCoords, 16);
 	}
 	else
 	
 
 	//just clear binormals
-	free(mBinormals);
+	ll_aligned_free_16(mBinormals);
 	mBinormals = NULL;
 
 	mPositions[mNumVertices] = pos;
 
 void LLVolumeFace::allocateBinormals(S32 num_verts)
 {
-	free(mBinormals);
-	mBinormals = (LLVector4a*) malloc(sizeof(LLVector4a)*num_verts);
+	ll_aligned_free_16(mBinormals);
+	mBinormals = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts);
 }
 
 void LLVolumeFace::allocateWeights(S32 num_verts)
 {
-	free(mWeights);
-	mWeights = (LLVector4a*) malloc(sizeof(LLVector4a)*num_verts);
+	ll_aligned_free_16(mWeights);
+	mWeights = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts);
 }
 
 void LLVolumeFace::resizeIndices(S32 num_indices)
 {
-	free(mIndices);
+	ll_aligned_free_16(mIndices);
 	
 	if (num_indices)
 	{
 		//pad index block end to allow for QWORD reads
 		S32 size = ((num_indices*sizeof(U16)) + 0xF) & ~0xF;
 		
-		mIndices = (U16*) malloc(size);
+		mIndices = (U16*) ll_aligned_malloc_16(size);
 	}
 	else
 	{

File indra/llrender/llvertexbuffer.cpp

 	{
 		static int gl_buffer_idx = 0;
 		mGLBuffer = ++gl_buffer_idx;
-		mMappedData = (U8*) malloc(size);
+		mMappedData = (U8*) ll_aligned_malloc_16(size);
 	}
 }
 
 	}
 	else
 	{
-		mMappedIndexData = (U8*) malloc(size);
+		mMappedIndexData = (U8*) ll_aligned_malloc_16(size);
 		static int gl_buffer_idx = 0;
 		mGLIndices = ++gl_buffer_idx;
 	}
 		}
 		else
 		{
-			free(mMappedData);
+			ll_aligned_free_16(mMappedData);
 			mMappedData = NULL;
 			mEmpty = TRUE;
 		}
 		}
 		else
 		{
-			free(mMappedIndexData);
+			ll_aligned_free_16(mMappedIndexData);
 			mMappedIndexData = NULL;
 			mEmpty = TRUE;
 		}
 			{
 				if (!useVBOs())
 				{
-					free(mMappedData);
-					mMappedData = (U8*) malloc(newsize);
+					ll_aligned_free_16(mMappedData);
+					mMappedData = (U8*) ll_aligned_malloc_16(newsize);
 				}
 				mResized = TRUE;
 			}
 			{
 				if (!useVBOs())
 				{
-					free(mMappedIndexData);
-					mMappedIndexData = (U8*) malloc(new_index_size);
+					ll_aligned_free_16(mMappedIndexData);
+					mMappedIndexData = (U8*) ll_aligned_malloc_16(new_index_size);
 				}
 				mResized = TRUE;
 			}
 {
 	if(useVBOs() && sDisableVBOMapping && (mMappedData || mMappedIndexData))
 	{
-		free(mMappedData) ;
-		free(mMappedIndexData) ;
+		ll_aligned_free_16(mMappedData) ;
+		ll_aligned_free_16(mMappedIndexData) ;
 		mMappedData = NULL ;
 		mMappedIndexData = NULL ;
 	}
 {
 	if(!mMappedData)
 	{
-		mMappedData = (U8*)malloc(getSize());
+		mMappedData = (U8*)ll_aligned_malloc_16(getSize());
 	}
 }
 
 {
 	if(!mMappedIndexData)
 	{
-		mMappedIndexData = (U8*)malloc(getIndicesSize());
+		mMappedIndexData = (U8*)ll_aligned_malloc_16(getIndicesSize());
 	}
 }
 

File indra/newview/llpolymesh.cpp

 		int nverts = mSharedData->mNumVertices;
 		int nfloats = nverts * (2*4 + 3*3 + 2 + 4);
 		//use 16 byte aligned vertex data to make LLPolyMesh SSE friendly
-		mVertexData = (F32*) malloc(nfloats*4);
+		mVertexData = (F32*) ll_aligned_malloc_16(nfloats*4);
 		int offset = 0;
 		mCoords				= 	(LLVector4*)(mVertexData + offset); offset += 4*nverts;
 		mNormals			=	(LLVector4*)(mVertexData + offset); offset += 4*nverts;
                 mJointRenderData[i] = NULL;
         }
 
-		free(mVertexData);
+		ll_aligned_free_16(mVertexData);
 
 }
 

File indra/newview/llspatialpartition.cpp

 					LLConvexDecomposition::getInstance()->generateSingleHullMeshFromMesh( &mesh, &res );
 
 					//copy res into phys_volume
-					phys_volume->mHullPoints = (LLVector4a*) malloc(sizeof(LLVector4a)*res.mNumVertices);
+					phys_volume->mHullPoints = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*res.mNumVertices);
 					phys_volume->mNumHullPoints = res.mNumVertices;
 
 					S32 idx_size = (res.mNumTriangles*3*2+0xF) & ~0xF;
-					phys_volume->mHullIndices = (U16*) malloc(idx_size);
+					phys_volume->mHullIndices = (U16*) ll_aligned_malloc_16(idx_size);
 					phys_volume->mNumHullIndices = res.mNumTriangles*3;
 
 					const F32* v = res.mVertexBase;