summaryrefslogtreecommitdiff
path: root/indra/llrender
diff options
context:
space:
mode:
authorDave Parks <davep@lindenlab.com>2012-05-24 10:50:48 -0500
committerDave Parks <davep@lindenlab.com>2012-05-24 10:50:48 -0500
commitefda0814cbae7917fde634c5e245c81915b17a9c (patch)
treeb9557284c32016de2d4a32f484e66a8fcad47b2c /indra/llrender
parentf2c2b88033e912be00ba0c08bc7f074d6881d1d5 (diff)
MAINT-616 Fix for corrupted mipmaps. Cleanup based on code review feedback.
Diffstat (limited to 'indra/llrender')
-rw-r--r--indra/llrender/llcubemap.cpp2
-rw-r--r--indra/llrender/llgl.h2
-rw-r--r--indra/llrender/llimagegl.cpp74
-rw-r--r--indra/llrender/llimagegl.h10
-rw-r--r--indra/llrender/llrendertarget.cpp11
-rw-r--r--indra/llrender/llrendertarget.h1
-rw-r--r--indra/llrender/llvertexbuffer.cpp71
7 files changed, 65 insertions, 106 deletions
diff --git a/indra/llrender/llcubemap.cpp b/indra/llrender/llcubemap.cpp
index 32e4c0d18e..362452d837 100644
--- a/indra/llrender/llcubemap.cpp
+++ b/indra/llrender/llcubemap.cpp
@@ -81,7 +81,7 @@ void LLCubeMap::initGL()
{
U32 texname = 0;
- LLImageGL::generateTextures(LLTexUnit::TT_CUBE_MAP, 1, &texname);
+ LLImageGL::generateTextures(LLTexUnit::TT_CUBE_MAP, GL_RGB8, 1, &texname);
for (int i = 0; i < 6; i++)
{
diff --git a/indra/llrender/llgl.h b/indra/llrender/llgl.h
index c26b75eff7..964495a3ab 100644
--- a/indra/llrender/llgl.h
+++ b/indra/llrender/llgl.h
@@ -419,7 +419,7 @@ public:
virtual void updateGL() = 0;
};
-const U32 FENCE_WAIT_TIME_NANOSECONDS = 10000; //1 ms
+const U32 FENCE_WAIT_TIME_NANOSECONDS = 1000; //1 ms
class LLGLFence
{
diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp
index 2d3762135a..bb585cc49c 100644
--- a/indra/llrender/llimagegl.cpp
+++ b/indra/llrender/llimagegl.cpp
@@ -51,7 +51,7 @@ S32 LLImageGL::sGlobalTextureMemoryInBytes = 0;
S32 LLImageGL::sBoundTextureMemoryInBytes = 0;
S32 LLImageGL::sCurBoundTextureMemory = 0;
S32 LLImageGL::sCount = 0;
-std::list<U32> LLImageGL::sDeadTextureList[LLTexUnit::TT_NONE];
+LLImageGL::dead_texturelist_t LLImageGL::sDeadTextureList[LLTexUnit::TT_NONE];
U32 LLImageGL::sCurTexName = 1;
BOOL LLImageGL::sGlobalUseAnisotropic = FALSE;
@@ -766,6 +766,9 @@ void LLImageGL::setImage(const U8* data_in, BOOL data_hasmips)
if (gGLManager.mHasFramebufferObject)
{
+ gGL.getTexUnit(0)->unbind(mBindTarget);
+ gGL.getTexUnit(0)->bind(this);
+
glGenerateMipmap(LLTexUnit::getInternalType(mBindTarget));
}
}
@@ -1094,14 +1097,24 @@ BOOL LLImageGL::setSubImageFromFrameBuffer(S32 fb_x, S32 fb_y, S32 x_pos, S32 y_
}
// static
-void LLImageGL::generateTextures(LLTexUnit::eTextureType type, S32 numTextures, U32 *textures)
+void LLImageGL::generateTextures(LLTexUnit::eTextureType type, U32 format, S32 numTextures, U32 *textures)
{
+ bool empty = true;
+
+ dead_texturelist_t::iterator iter = sDeadTextureList[type].find(format);
+
+ if (iter != sDeadTextureList[type].end())
+ {
+ empty = iter->second.empty();
+ }
+
for (S32 i = 0; i < numTextures; ++i)
{
- if (!sDeadTextureList[type].empty())
+ if (!empty)
{
- textures[i] = sDeadTextureList[type].front();
- sDeadTextureList[type].pop_front();
+ textures[i] = iter->second.front();
+ iter->second.pop_front();
+ empty = iter->second.empty();
}
else
{
@@ -1111,28 +1124,35 @@ void LLImageGL::generateTextures(LLTexUnit::eTextureType type, S32 numTextures,
}
// static
-void LLImageGL::deleteTextures(LLTexUnit::eTextureType type, S32 numTextures, U32 *textures, bool immediate)
+void LLImageGL::deleteTextures(LLTexUnit::eTextureType type, U32 format, S32 numTextures, U32 *textures, bool immediate)
{
if (gGLManager.mInited)
{
- for (S32 i = 0; i < numTextures; ++i)
- { //remove texture from VRAM by setting its size to zero
- gGL.getTexUnit(0)->bindManual(type, textures[i]);
+ if (format == 0)
+ { //unknown internal format, not safe to reuse
+ glDeleteTextures(numTextures, textures);
+ }
+ else
+ {
+ for (S32 i = 0; i < numTextures; ++i)
+ { //remove texture from VRAM by setting its size to zero
+ gGL.getTexUnit(0)->bindManual(type, textures[i]);
- if (type == LLTexUnit::TT_CUBE_MAP)
- {
- glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- }
- else
- {
- glTexImage2D(LLTexUnit::getInternalType(type), 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ if (type == LLTexUnit::TT_CUBE_MAP)
+ {
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ }
+ else
+ {
+ glTexImage2D(LLTexUnit::getInternalType(type), 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ }
+ sDeadTextureList[type][format].push_back(textures[i]);
}
- sDeadTextureList[type].push_back(textures[i]);
}
}
@@ -1264,11 +1284,11 @@ BOOL LLImageGL::createGLTexture()
if(mTexName)
{
- LLImageGL::deleteTextures(mBindTarget, 1, (reinterpret_cast<GLuint*>(&mTexName))) ;
+ LLImageGL::deleteTextures(mBindTarget, mFormatInternal, 1, (reinterpret_cast<GLuint*>(&mTexName))) ;
}
- LLImageGL::generateTextures(mBindTarget, 1, &mTexName);
+ LLImageGL::generateTextures(mBindTarget, mFormatInternal, 1, &mTexName);
stop_glerror();
if (!mTexName)
{
@@ -1381,7 +1401,7 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_
}
else
{
- LLImageGL::generateTextures(mBindTarget, 1, &mTexName);
+ LLImageGL::generateTextures(mBindTarget, mFormatInternal, 1, &mTexName);
stop_glerror();
{
llverify(gGL.getTexUnit(0)->bind(this));
@@ -1431,7 +1451,7 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_
decTextureCounter(mTextureMemory, mComponents, mCategory) ;
}
- LLImageGL::deleteTextures(mBindTarget,1, &old_name);
+ LLImageGL::deleteTextures(mBindTarget, mFormatInternal, 1, &old_name);
stop_glerror();
}
@@ -1608,7 +1628,7 @@ void LLImageGL::destroyGLTexture()
mTextureMemory = 0;
}
- LLImageGL::deleteTextures(mBindTarget, 1, &mTexName);
+ LLImageGL::deleteTextures(mBindTarget, mFormatInternal, 1, &mTexName);
mTexName = 0;
mCurrentDiscardLevel = -1 ; //invalidate mCurrentDiscardLevel.
mGLTextureCreated = FALSE ;
diff --git a/indra/llrender/llimagegl.h b/indra/llrender/llimagegl.h
index 8c9cea111e..34efafb015 100644
--- a/indra/llrender/llimagegl.h
+++ b/indra/llrender/llimagegl.h
@@ -46,11 +46,15 @@ class LLImageGL : public LLRefCount
friend class LLTexUnit;
public:
static U32 sCurTexName;
- static std::list<U32> sDeadTextureList[LLTexUnit::TT_NONE];
+
+ //previously used but now available texture names
+ // sDeadTextureList[<usage>][<internal format>]
+ typedef std::map<U32, std::list<U32> > dead_texturelist_t;
+ static dead_texturelist_t sDeadTextureList[LLTexUnit::TT_NONE];
// These 2 functions replace glGenTextures() and glDeleteTextures()
- static void generateTextures(LLTexUnit::eTextureType type, S32 numTextures, U32 *textures);
- static void deleteTextures(LLTexUnit::eTextureType type, S32 numTextures, U32 *textures, bool immediate = false);
+ static void generateTextures(LLTexUnit::eTextureType type, U32 format, S32 numTextures, U32 *textures);
+ static void deleteTextures(LLTexUnit::eTextureType type, U32 format, S32 numTextures, U32 *textures, bool immediate = false);
static void deleteDeadTextures();
// Size calculation
diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp
index f0dd6f3bd6..ced6b013ec 100644
--- a/indra/llrender/llrendertarget.cpp
+++ b/indra/llrender/llrendertarget.cpp
@@ -55,7 +55,6 @@ bool LLRenderTarget::sUseFBO = false;
LLRenderTarget::LLRenderTarget() :
mResX(0),
mResY(0),
- mTex(0),
mFBO(0),
mDepth(0),
mStencil(0),
@@ -135,7 +134,7 @@ bool LLRenderTarget::addColorAttachment(U32 color_fmt)
}
U32 tex;
- LLImageGL::generateTextures(mUsage, 1, &tex);
+ LLImageGL::generateTextures(mUsage, color_fmt, 1, &tex);
gGL.getTexUnit(0)->bindManual(mUsage, tex);
stop_glerror();
@@ -193,6 +192,7 @@ bool LLRenderTarget::addColorAttachment(U32 color_fmt)
}
mTex.push_back(tex);
+ mInternalFormat.push_back(color_fmt);
if (gDebugGL)
{ //bind and unbind to validate target
@@ -217,7 +217,7 @@ bool LLRenderTarget::allocateDepth()
}
else
{
- LLImageGL::generateTextures(mUsage, 1, &mDepth);
+ LLImageGL::generateTextures(mUsage, GL_DEPTH_COMPONENT24, 1, &mDepth);
gGL.getTexUnit(0)->bindManual(mUsage, mDepth);
U32 internal_type = LLTexUnit::getInternalType(mUsage);
@@ -294,7 +294,7 @@ void LLRenderTarget::release()
}
else
{
- LLImageGL::deleteTextures(mUsage, 1, &mDepth, true);
+ LLImageGL::deleteTextures(mUsage, 0, 1, &mDepth, true);
stop_glerror();
}
mDepth = 0;
@@ -326,8 +326,9 @@ void LLRenderTarget::release()
if (mTex.size() > 0)
{
sBytesAllocated -= mResX*mResY*4*mTex.size();
- LLImageGL::deleteTextures(mUsage, mTex.size(), &mTex[0], true);
+ LLImageGL::deleteTextures(mUsage, mInternalFormat[0], mTex.size(), &mTex[0], true);
mTex.clear();
+ mInternalFormat.clear();
}
mResX = mResY = 0;
diff --git a/indra/llrender/llrendertarget.h b/indra/llrender/llrendertarget.h
index 2735ab21c5..8360458840 100644
--- a/indra/llrender/llrendertarget.h
+++ b/indra/llrender/llrendertarget.h
@@ -142,6 +142,7 @@ protected:
U32 mResX;
U32 mResY;
std::vector<U32> mTex;
+ std::vector<U32> mInternalFormat;
U32 mFBO;
U32 mDepth;
bool mStencil;
diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp
index ca7c9deff2..f4bf744e3c 100644
--- a/indra/llrender/llvertexbuffer.cpp
+++ b/indra/llrender/llvertexbuffer.cpp
@@ -38,8 +38,6 @@
#include "llglslshader.h"
#include "llmemory.h"
-#define LL_VBO_POOLING 1
-
//Next Highest Power Of Two
//helper function, returns first number > v that is a power of 2, or v if v is already a power of 2
U32 nhpo2(U32 v)
@@ -165,33 +163,24 @@ LLVBOPool::LLVBOPool(U32 vboUsage, U32 vboType)
std::fill(mMissCount.begin(), mMissCount.end(), 0);
}
-static LLFastTimer::DeclareTimer FTM_VBO_GEN_BUFFER("gen buffers");
-static LLFastTimer::DeclareTimer FTM_VBO_BUFFER_DATA("glBufferData");
-
-
volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed)
{
llassert(vbo_block_size(size) == size);
volatile U8* ret = NULL;
-#if LL_VBO_POOLING
-
U32 i = vbo_block_index(size);
if (mFreeList.size() <= i)
{
mFreeList.resize(i+1);
- mMissCount.resize(i+1);
}
if (mFreeList[i].empty() || for_seed)
{
//make a new buffer
- {
- LLFastTimer t(FTM_VBO_GEN_BUFFER);
- name = genBuffer();
- }
+ name = genBuffer();
+
glBindBufferARB(mType, name);
if (!for_seed && i < LL_VBO_POOL_SEED_COUNT)
@@ -215,7 +204,6 @@ volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed)
}
else
{ //always use a true hint of static draw when allocating non-client-backed buffers
- LLFastTimer t(FTM_VBO_BUFFER_DATA);
glBufferDataARB(mType, size, 0, GL_STATIC_DRAW_ARB);
}
@@ -256,33 +244,6 @@ volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed)
mFreeList[i].pop_front();
}
-#else //no pooling
-
- glGenBuffersARB(1, &name);
- glBindBufferARB(mType, name);
-
- if (mType == GL_ARRAY_BUFFER_ARB)
- {
- LLVertexBuffer::sAllocatedBytes += size;
- }
- else
- {
- LLVertexBuffer::sAllocatedIndexBytes += size;
- }
-
- if (LLVertexBuffer::sDisableVBOMapping || mUsage != GL_DYNAMIC_DRAW_ARB)
- {
- glBufferDataARB(mType, size, 0, mUsage);
- ret = (U8*) ll_aligned_malloc_16(size);
- }
- else
- { //always use a true hint of static draw when allocating non-client-backed buffers
- glBufferDataARB(mType, size, 0, GL_STATIC_DRAW_ARB);
- }
-
- glBindBufferARB(mType, 0);
-
-#endif
return ret;
}
@@ -291,33 +252,6 @@ void LLVBOPool::release(U32 name, volatile U8* buffer, U32 size)
{
llassert(vbo_block_size(size) == size);
-#if 0 && LL_VBO_POOLING
-
- U32 i = vbo_block_index(size);
-
- llassert(mFreeList.size() > i);
-
- Record rec;
- rec.mGLName = name;
- rec.mClientData = buffer;
-
- if (buffer == NULL)
- {
- glDeleteBuffersARB(1, &rec.mGLName);
- }
- else
- {
- if (mType == GL_ARRAY_BUFFER_ARB)
- {
- sBytesPooled += size;
- }
- else
- {
- sIndexBytesPooled += size;
- }
- mFreeList[i].push_back(rec);
- }
-#else //no pooling
deleteBuffer(name);
ll_aligned_free_16((U8*) buffer);
@@ -329,7 +263,6 @@ void LLVBOPool::release(U32 name, volatile U8* buffer, U32 size)
{
LLVertexBuffer::sAllocatedIndexBytes -= size;
}
-#endif
}
void LLVBOPool::seedPool()