From f4ff1430f0d6ae7dd5a6be0bd665678b30a63aca Mon Sep 17 00:00:00 2001 From: Xiaohong Bao Date: Fri, 3 Dec 2010 22:16:16 -0700 Subject: first iteration of memory pool code --- indra/llrender/llvertexbuffer.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 02160b09c4..19269c2a31 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -33,6 +33,7 @@ #include "llglheaders.h" #include "llmemtype.h" #include "llrender.h" +#include "llmemory.h" //============================================================================ @@ -857,11 +858,8 @@ U8* LLVertexBuffer::mapBuffer(S32 access) log_glerror(); //check the availability of memory - U32 avail_phy_mem, avail_vir_mem; - LLMemoryInfo::getAvailableMemoryKB(avail_phy_mem, avail_vir_mem) ; - llinfos << "Available physical mwmory(KB): " << avail_phy_mem << llendl ; - llinfos << "Available virtual memory(KB): " << avail_vir_mem << llendl; - + LLMemory::logMemoryInfo(TRUE) ; + //-------------------- //print out more debug info before crash llinfos << "vertex buffer size: (num verts : num indices) = " << getNumVerts() << " : " << getNumIndices() << llendl ; @@ -884,6 +882,7 @@ U8* LLVertexBuffer::mapBuffer(S32 access) if (!mMappedIndexData) { log_glerror(); + LLMemory::logMemoryInfo(TRUE) ; GLint buff; glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &buff); -- cgit v1.2.3 From 844bf22d250833b000d306b9179580d6e032a632 Mon Sep 17 00:00:00 2001 From: Xiaohong Bao Date: Wed, 23 Feb 2011 19:48:08 -0700 Subject: apply private pool to VBO --- indra/llrender/llvertexbuffer.cpp | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 2417f88050..6b1fd78733 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -43,6 +43,7 @@ LLVBOPool LLVertexBuffer::sDynamicVBOPool; LLVBOPool LLVertexBuffer::sStreamIBOPool; LLVBOPool LLVertexBuffer::sDynamicIBOPool; +LLPrivateMemoryPool* LLVertexBuffer::sPrivatePoolp = NULL ; U32 LLVertexBuffer::sBindCount = 0; U32 LLVertexBuffer::sSetCount = 0; S32 LLVertexBuffer::sCount = 0; @@ -317,6 +318,11 @@ void LLVertexBuffer::initClass(bool use_vbo, bool no_vbo_mapping) LLGLNamePool::registerPool(&sDynamicIBOPool); LLGLNamePool::registerPool(&sStreamVBOPool); LLGLNamePool::registerPool(&sStreamIBOPool); + + if(!sPrivatePoolp) + { + sPrivatePoolp = LLPrivateMemoryPoolManager::getInstance()->newPool(LLPrivateMemoryPool::STATIC) ; + } } //static @@ -345,6 +351,12 @@ void LLVertexBuffer::cleanupClass() LLMemType mt2(LLMemType::MTYPE_VERTEX_CLEANUP_CLASS); unbind(); clientCopy(); // deletes GL buffers + + if(sPrivatePoolp) + { + LLPrivateMemoryPoolManager::getInstance()->deletePool(sPrivatePoolp) ; + sPrivatePoolp = NULL ; + } } void LLVertexBuffer::clientCopy(F64 max_time) @@ -532,7 +544,7 @@ void LLVertexBuffer::createGLBuffer() { static int gl_buffer_idx = 0; mGLBuffer = ++gl_buffer_idx; - mMappedData = new U8[size]; + mMappedData = (U8*)sPrivatePoolp->allocate(size); memset(mMappedData, 0, size); } } @@ -562,7 +574,7 @@ void LLVertexBuffer::createGLIndices() } else { - mMappedIndexData = new U8[size]; + mMappedIndexData = (U8*)sPrivatePoolp->allocate(size); memset(mMappedIndexData, 0, size); static int gl_buffer_idx = 0; mGLIndices = ++gl_buffer_idx; @@ -586,7 +598,7 @@ void LLVertexBuffer::destroyGLBuffer() } else { - delete [] mMappedData; + sPrivatePoolp->free(mMappedData) ; mMappedData = NULL; mEmpty = TRUE; } @@ -615,7 +627,7 @@ void LLVertexBuffer::destroyGLIndices() } else { - delete [] mMappedIndexData; + sPrivatePoolp->free(mMappedIndexData) ; mMappedIndexData = NULL; mEmpty = TRUE; } @@ -747,7 +759,7 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) if (!useVBOs()) { U8* old = mMappedData; - mMappedData = new U8[newsize]; + mMappedData = (U8*)sPrivatePoolp->allocate(newsize); if (old) { memcpy(mMappedData, old, llmin(newsize, oldsize)); @@ -756,7 +768,7 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) memset(mMappedData+oldsize, 0, newsize-oldsize); } - delete [] old; + sPrivatePoolp->free(old); } else { @@ -784,7 +796,7 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) { //delete old buffer, keep GL buffer for now U8* old = mMappedIndexData; - mMappedIndexData = new U8[new_index_size]; + mMappedIndexData = (U8*)sPrivatePoolp->allocate(new_index_size); if (old) { @@ -793,7 +805,7 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) { memset(mMappedIndexData+old_index_size, 0, new_index_size - old_index_size); } - delete [] old; + sPrivatePoolp->free(old); } else { @@ -840,8 +852,8 @@ void LLVertexBuffer::freeClientBuffer() { if(useVBOs() && sDisableVBOMapping && (mMappedData || mMappedIndexData)) { - delete[] mMappedData ; - delete[] mMappedIndexData ; + sPrivatePoolp->free(mMappedData) ; + sPrivatePoolp->free(mMappedIndexData) ; mMappedData = NULL ; mMappedIndexData = NULL ; } @@ -852,7 +864,7 @@ void LLVertexBuffer::allocateClientVertexBuffer() if(!mMappedData) { U32 size = getSize() ; - mMappedData = new U8[size]; + mMappedData = (U8*)sPrivatePoolp->allocate(size); memset(mMappedData, 0, size); } } @@ -862,7 +874,7 @@ void LLVertexBuffer::allocateClientIndexBuffer() if(!mMappedIndexData) { U32 size = getIndicesSize(); - mMappedIndexData = new U8[size]; + mMappedIndexData = (U8*)sPrivatePoolp->allocate(size); memset(mMappedIndexData, 0, size); } } -- cgit v1.2.3 From fc106df53085f549acdbb2f8149ca75e400532fa Mon Sep 17 00:00:00 2001 From: Xiaohong Bao Date: Thu, 24 Feb 2011 19:47:55 -0700 Subject: fix the compiling error: "free" is defined and in use globally. --- indra/llrender/llvertexbuffer.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 6b1fd78733..fd2a04373b 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -598,7 +598,7 @@ void LLVertexBuffer::destroyGLBuffer() } else { - sPrivatePoolp->free(mMappedData) ; + sPrivatePoolp->freeMem(mMappedData) ; mMappedData = NULL; mEmpty = TRUE; } @@ -627,7 +627,7 @@ void LLVertexBuffer::destroyGLIndices() } else { - sPrivatePoolp->free(mMappedIndexData) ; + sPrivatePoolp->freeMem(mMappedIndexData) ; mMappedIndexData = NULL; mEmpty = TRUE; } @@ -768,7 +768,7 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) memset(mMappedData+oldsize, 0, newsize-oldsize); } - sPrivatePoolp->free(old); + sPrivatePoolp->freeMem(old); } else { @@ -805,7 +805,7 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) { memset(mMappedIndexData+old_index_size, 0, new_index_size - old_index_size); } - sPrivatePoolp->free(old); + sPrivatePoolp->freeMem(old); } else { @@ -852,8 +852,8 @@ void LLVertexBuffer::freeClientBuffer() { if(useVBOs() && sDisableVBOMapping && (mMappedData || mMappedIndexData)) { - sPrivatePoolp->free(mMappedData) ; - sPrivatePoolp->free(mMappedIndexData) ; + sPrivatePoolp->freeMem(mMappedData) ; + sPrivatePoolp->freeMem(mMappedIndexData) ; mMappedData = NULL ; mMappedIndexData = NULL ; } -- cgit v1.2.3 From b594d3b04d3095f15750436910debdd5a602a872 Mon Sep 17 00:00:00 2001 From: Xiaohong Bao Date: Tue, 10 May 2011 21:02:20 -0600 Subject: add debug mode to track the memory allocation/deallocation. --- indra/llrender/llvertexbuffer.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index fd2a04373b..67417aea43 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -544,7 +544,7 @@ void LLVertexBuffer::createGLBuffer() { static int gl_buffer_idx = 0; mGLBuffer = ++gl_buffer_idx; - mMappedData = (U8*)sPrivatePoolp->allocate(size); + mMappedData = (U8*)ALLOCATE_MEM(sPrivatePoolp, size); memset(mMappedData, 0, size); } } @@ -574,7 +574,7 @@ void LLVertexBuffer::createGLIndices() } else { - mMappedIndexData = (U8*)sPrivatePoolp->allocate(size); + mMappedIndexData = (U8*)ALLOCATE_MEM(sPrivatePoolp, size); memset(mMappedIndexData, 0, size); static int gl_buffer_idx = 0; mGLIndices = ++gl_buffer_idx; @@ -598,7 +598,7 @@ void LLVertexBuffer::destroyGLBuffer() } else { - sPrivatePoolp->freeMem(mMappedData) ; + FREE_MEM(sPrivatePoolp, mMappedData) ; mMappedData = NULL; mEmpty = TRUE; } @@ -627,7 +627,7 @@ void LLVertexBuffer::destroyGLIndices() } else { - sPrivatePoolp->freeMem(mMappedIndexData) ; + FREE_MEM(sPrivatePoolp, mMappedIndexData) ; mMappedIndexData = NULL; mEmpty = TRUE; } @@ -759,7 +759,7 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) if (!useVBOs()) { U8* old = mMappedData; - mMappedData = (U8*)sPrivatePoolp->allocate(newsize); + mMappedData = (U8*)ALLOCATE_MEM(sPrivatePoolp, newsize); if (old) { memcpy(mMappedData, old, llmin(newsize, oldsize)); @@ -768,7 +768,7 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) memset(mMappedData+oldsize, 0, newsize-oldsize); } - sPrivatePoolp->freeMem(old); + FREE_MEM(sPrivatePoolp, old); } else { @@ -796,7 +796,7 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) { //delete old buffer, keep GL buffer for now U8* old = mMappedIndexData; - mMappedIndexData = (U8*)sPrivatePoolp->allocate(new_index_size); + mMappedIndexData = (U8*)ALLOCATE_MEM(sPrivatePoolp, new_index_size); if (old) { @@ -805,7 +805,7 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) { memset(mMappedIndexData+old_index_size, 0, new_index_size - old_index_size); } - sPrivatePoolp->freeMem(old); + FREE_MEM(sPrivatePoolp, old); } else { @@ -852,8 +852,8 @@ void LLVertexBuffer::freeClientBuffer() { if(useVBOs() && sDisableVBOMapping && (mMappedData || mMappedIndexData)) { - sPrivatePoolp->freeMem(mMappedData) ; - sPrivatePoolp->freeMem(mMappedIndexData) ; + FREE_MEM(sPrivatePoolp, mMappedData) ; + FREE_MEM(sPrivatePoolp, mMappedIndexData) ; mMappedData = NULL ; mMappedIndexData = NULL ; } @@ -864,7 +864,7 @@ void LLVertexBuffer::allocateClientVertexBuffer() if(!mMappedData) { U32 size = getSize() ; - mMappedData = (U8*)sPrivatePoolp->allocate(size); + mMappedData = (U8*)ALLOCATE_MEM(sPrivatePoolp, size); memset(mMappedData, 0, size); } } @@ -874,7 +874,7 @@ void LLVertexBuffer::allocateClientIndexBuffer() if(!mMappedIndexData) { U32 size = getIndicesSize(); - mMappedIndexData = (U8*)sPrivatePoolp->allocate(size); + mMappedIndexData = (U8*)ALLOCATE_MEM(sPrivatePoolp, size); memset(mMappedIndexData, 0, size); } } -- cgit v1.2.3