summaryrefslogtreecommitdiff
path: root/indra/newview/llviewertexture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llviewertexture.cpp')
-rw-r--r--indra/newview/llviewertexture.cpp318
1 files changed, 204 insertions, 114 deletions
diff --git a/indra/newview/llviewertexture.cpp b/indra/newview/llviewertexture.cpp
index ca01bb46aa..949e71a4c9 100644
--- a/indra/newview/llviewertexture.cpp
+++ b/indra/newview/llviewertexture.cpp
@@ -184,6 +184,7 @@ void LLViewerTextureManager::findFetchedTextures(const LLUUID& id, std::vector<L
void LLViewerTextureManager::findTextures(const LLUUID& id, std::vector<LLViewerTexture*> &output)
{
+ LL_PROFILE_ZONE_SCOPED;
std::vector<LLViewerFetchedTexture*> fetched_output;
gTextureList.findTexturesByID(id, fetched_output);
std::vector<LLViewerFetchedTexture*>::iterator iter = fetched_output.begin();
@@ -208,6 +209,7 @@ void LLViewerTextureManager::findTextures(const LLUUID& id, std::vector<LLViewe
LLViewerFetchedTexture* LLViewerTextureManager::findFetchedTexture(const LLUUID& id, S32 tex_type)
{
+ LL_PROFILE_ZONE_SCOPED;
return gTextureList.findImage(id, (ETexListType)tex_type);
}
@@ -484,6 +486,7 @@ static LLTrace::BlockTimerStatHandle FTM_TEXTURE_MEMORY_CHECK("Memory Check");
//static
bool LLViewerTexture::isMemoryForTextureLow()
{
+ LL_PROFILE_ZONE_SCOPED;
// Note: we need to figure out a better source for 'min' values,
// what is free for low end at minimal settings is 'nothing left'
// for higher end gpus at high settings.
@@ -500,6 +503,7 @@ bool LLViewerTexture::isMemoryForTextureLow()
//static
bool LLViewerTexture::isMemoryForTextureSuficientlyFree()
{
+ LL_PROFILE_ZONE_SCOPED;
const S32Megabytes DESIRED_FREE_TEXTURE_MEMORY(50);
const S32Megabytes DESIRED_FREE_MAIN_MEMORY(200);
@@ -513,6 +517,7 @@ bool LLViewerTexture::isMemoryForTextureSuficientlyFree()
//static
void LLViewerTexture::getGPUMemoryForTextures(S32Megabytes &gpu, S32Megabytes &physical)
{
+ LL_PROFILE_ZONE_SCOPED;
static LLFrameTimer timer;
static S32Megabytes gpu_res = S32Megabytes(S32_MAX);
static S32Megabytes physical_res = S32Megabytes(S32_MAX);
@@ -525,27 +530,29 @@ void LLViewerTexture::getGPUMemoryForTextures(S32Megabytes &gpu, S32Megabytes &p
}
timer.reset();
- LL_RECORD_BLOCK_TIME(FTM_TEXTURE_MEMORY_CHECK);
-
- if (gGLManager.mHasATIMemInfo)
{
- S32 meminfo[4];
- glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, meminfo);
- gpu_res = (S32Megabytes)meminfo[0];
+ LL_RECORD_BLOCK_TIME(FTM_TEXTURE_MEMORY_CHECK);
- //check main memory, only works for windows.
- LLMemory::updateMemoryInfo();
- physical_res = LLMemory::getAvailableMemKB();
- }
- else if (gGLManager.mHasNVXMemInfo)
- {
- S32 free_memory;
- glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &free_memory);
- gpu_res = (S32Megabytes)(free_memory / 1024);
- }
+ if (gGLManager.mHasATIMemInfo)
+ {
+ S32 meminfo[4];
+ glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, meminfo);
+ gpu_res = (S32Megabytes)meminfo[0];
- gpu = gpu_res;
- physical = physical_res;
+ //check main memory, only works for windows.
+ LLMemory::updateMemoryInfo();
+ physical_res = LLMemory::getAvailableMemKB();
+ }
+ else if (gGLManager.mHasNVXMemInfo)
+ {
+ S32 free_memory;
+ glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &free_memory);
+ gpu_res = (S32Megabytes)(free_memory / 1024);
+ }
+
+ gpu = gpu_res;
+ physical = physical_res;
+ }
}
static LLTrace::BlockTimerStatHandle FTM_TEXTURE_UPDATE_MEDIA("Media");
@@ -554,6 +561,7 @@ static LLTrace::BlockTimerStatHandle FTM_TEXTURE_UPDATE_TEST("Test");
//static
void LLViewerTexture::updateClass(const F32 velocity, const F32 angular_velocity)
{
+ LL_PROFILE_ZONE_SCOPED;
sCurrentTime = gFrameTimeSeconds;
LLTexturePipelineTester* tester = (LLTexturePipelineTester*)LLMetricPerformanceTesterBasic::getTester(sTesterName);
@@ -703,6 +711,7 @@ void LLViewerTexture::cleanup()
void LLViewerTexture::notifyAboutCreatingTexture()
{
+ LL_PROFILE_ZONE_SCOPED;
for(U32 ch = 0; ch < LLRender::NUM_TEXTURE_CHANNELS; ++ch)
{
for(U32 f = 0; f < mNumFaces[ch]; f++)
@@ -714,6 +723,7 @@ void LLViewerTexture::notifyAboutCreatingTexture()
void LLViewerTexture::notifyAboutMissingAsset()
{
+ LL_PROFILE_ZONE_SCOPED;
for(U32 ch = 0; ch < LLRender::NUM_TEXTURE_CHANNELS; ++ch)
{
for(U32 f = 0; f < mNumFaces[ch]; f++)
@@ -726,6 +736,7 @@ void LLViewerTexture::notifyAboutMissingAsset()
// virtual
void LLViewerTexture::dump()
{
+ LL_PROFILE_ZONE_SCOPED;
LLGLTexture::dump();
LL_INFOS() << "LLViewerTexture"
@@ -761,6 +772,7 @@ bool LLViewerTexture::isActiveFetching()
bool LLViewerTexture::bindDebugImage(const S32 stage)
{
+ LL_PROFILE_ZONE_SCOPED;
if (stage < 0) return false;
bool res = true;
@@ -779,6 +791,7 @@ bool LLViewerTexture::bindDebugImage(const S32 stage)
bool LLViewerTexture::bindDefaultImage(S32 stage)
{
+ LL_PROFILE_ZONE_SCOPED;
if (stage < 0) return false;
bool res = true;
@@ -821,6 +834,7 @@ void LLViewerTexture::forceImmediateUpdate()
void LLViewerTexture::addTextureStats(F32 virtual_size, BOOL needs_gltexture) const
{
+ LL_PROFILE_ZONE_SCOPED;
if(needs_gltexture)
{
mNeedsGLTexture = TRUE;
@@ -831,14 +845,14 @@ void LLViewerTexture::addTextureStats(F32 virtual_size, BOOL needs_gltexture) co
{
//flag to reset the values because the old values are used.
resetMaxVirtualSizeResetCounter();
- mMaxVirtualSize = virtual_size;
- mAdditionalDecodePriority = 0.f;
+ mMaxVirtualSize = virtual_size;
+ mAdditionalDecodePriority = 0.f;
mNeedsGLTexture = needs_gltexture;
}
else if (virtual_size > mMaxVirtualSize)
{
mMaxVirtualSize = virtual_size;
- }
+ }
}
void LLViewerTexture::resetTextureStats()
@@ -863,6 +877,7 @@ void LLViewerTexture::setKnownDrawSize(S32 width, S32 height)
//virtual
void LLViewerTexture::addFace(U32 ch, LLFace* facep)
{
+ LL_PROFILE_ZONE_SCOPED;
llassert(ch < LLRender::NUM_TEXTURE_CHANNELS);
if(mNumFaces[ch] >= mFaceList[ch].size())
@@ -878,6 +893,7 @@ void LLViewerTexture::addFace(U32 ch, LLFace* facep)
//virtual
void LLViewerTexture::removeFace(U32 ch, LLFace* facep)
{
+ LL_PROFILE_ZONE_SCOPED;
llassert(ch < LLRender::NUM_TEXTURE_CHANNELS);
if(mNumFaces[ch] > 1)
@@ -918,6 +934,7 @@ S32 LLViewerTexture::getNumFaces(U32 ch) const
//virtual
void LLViewerTexture::addVolume(U32 ch, LLVOVolume* volumep)
{
+ LL_PROFILE_ZONE_SCOPED;
if (mNumVolumes[ch] >= mVolumeList[ch].size())
{
mVolumeList[ch].resize(2 * mNumVolumes[ch] + 1);
@@ -931,6 +948,7 @@ void LLViewerTexture::addVolume(U32 ch, LLVOVolume* volumep)
//virtual
void LLViewerTexture::removeVolume(U32 ch, LLVOVolume* volumep)
{
+ LL_PROFILE_ZONE_SCOPED;
if (mNumVolumes[ch] > 1)
{
S32 index = volumep->getIndexInTex(ch);
@@ -954,6 +972,7 @@ S32 LLViewerTexture::getNumVolumes(U32 ch) const
void LLViewerTexture::reorganizeFaceList()
{
+ LL_PROFILE_ZONE_SCOPED;
static const F32 MAX_WAIT_TIME = 20.f; // seconds
static const U32 MAX_EXTRA_BUFFER_SIZE = 4;
@@ -977,6 +996,7 @@ void LLViewerTexture::reorganizeFaceList()
void LLViewerTexture::reorganizeVolumeList()
{
+ LL_PROFILE_ZONE_SCOPED;
static const F32 MAX_WAIT_TIME = 20.f; // seconds
static const U32 MAX_EXTRA_BUFFER_SIZE = 4;
@@ -1179,6 +1199,7 @@ FTType LLViewerFetchedTexture::getFTType() const
void LLViewerFetchedTexture::cleanup()
{
+ LL_PROFILE_ZONE_SCOPED;
for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
iter != mLoadedCallbackList.end(); )
{
@@ -1204,6 +1225,7 @@ void LLViewerFetchedTexture::cleanup()
//access the fast cache
void LLViewerFetchedTexture::loadFromFastCache()
{
+ LL_PROFILE_ZONE_SCOPED;
if(!mInFastCacheList)
{
return; //no need to access the fast cache.
@@ -1349,6 +1371,7 @@ void LLViewerFetchedTexture::dump()
// ONLY called from LLViewerFetchedTextureList
void LLViewerFetchedTexture::destroyTexture()
{
+ LL_PROFILE_ZONE_SCOPED;
if(LLImageGL::sGlobalTextureMemory < sMaxDesiredTextureMem * 0.95f)//not ready to release unused memory.
{
return ;
@@ -1365,6 +1388,7 @@ void LLViewerFetchedTexture::destroyTexture()
void LLViewerFetchedTexture::addToCreateTexture()
{
+ LL_PROFILE_ZONE_SCOPED;
bool force_update = false;
if (getComponents() != mRawImage->getComponents())
{
@@ -1406,6 +1430,7 @@ void LLViewerFetchedTexture::addToCreateTexture()
}
else
{
+ LL_PROFILE_ZONE_SCOPED;
#if 1
//
//if mRequestedDiscardLevel > mDesiredDiscardLevel, we assume the required image res keep going up,
@@ -1450,99 +1475,100 @@ void LLViewerFetchedTexture::addToCreateTexture()
}
}
#endif
- mNeedsCreateTexture = TRUE;
- gTextureList.mCreateTextureList.insert(this);
- }
+ scheduleCreateTexture();
+ }
return;
}
// ONLY called from LLViewerTextureList
-BOOL LLViewerFetchedTexture::createTexture(S32 usename/*= 0*/)
+BOOL LLViewerFetchedTexture::preCreateTexture(S32 usename/*= 0*/)
{
- if (!mNeedsCreateTexture)
- {
- destroyRawImage();
- return FALSE;
- }
- mNeedsCreateTexture = FALSE;
- if (mRawImage.isNull())
- {
- LL_ERRS() << "LLViewerTexture trying to create texture with no Raw Image" << LL_ENDL;
- }
- if (mRawImage->isBufferInvalid())
- {
- LL_WARNS() << "Can't create a texture: invalid image data" << LL_ENDL;
- destroyRawImage();
- return FALSE;
- }
-// LL_INFOS() << llformat("IMAGE Creating (%d) [%d x %d] Bytes: %d ",
-// mRawDiscardLevel,
-// mRawImage->getWidth(), mRawImage->getHeight(),mRawImage->getDataSize())
-// << mID.getString() << LL_ENDL;
- BOOL res = TRUE;
+ LL_PROFILE_ZONE_SCOPED;
+ if (!mNeedsCreateTexture)
+ {
+ destroyRawImage();
+ return FALSE;
+ }
+ mNeedsCreateTexture = FALSE;
- // store original size only for locally-sourced images
- if (mUrl.compare(0, 7, "file://") == 0)
- {
- mOrigWidth = mRawImage->getWidth();
- mOrigHeight = mRawImage->getHeight();
+ if (mRawImage.isNull())
+ {
+ LL_ERRS() << "LLViewerTexture trying to create texture with no Raw Image" << LL_ENDL;
+ }
+ if (mRawImage->isBufferInvalid())
+ {
+ LL_WARNS() << "Can't create a texture: invalid image data" << LL_ENDL;
+ destroyRawImage();
+ return FALSE;
+ }
+ // LL_INFOS() << llformat("IMAGE Creating (%d) [%d x %d] Bytes: %d ",
+ // mRawDiscardLevel,
+ // mRawImage->getWidth(), mRawImage->getHeight(),mRawImage->getDataSize())
+ // << mID.getString() << LL_ENDL;
+ BOOL res = TRUE;
+
+ // store original size only for locally-sourced images
+ if (mUrl.compare(0, 7, "file://") == 0)
+ {
+ mOrigWidth = mRawImage->getWidth();
+ mOrigHeight = mRawImage->getHeight();
// This is only safe because it's a local image and fetcher doesn't use raw data
// from local images, but this might become unsafe in case of changes to fetcher
- if (mBoostLevel == BOOST_PREVIEW)
- {
- mRawImage->biasedScaleToPowerOfTwo(1024);
- }
- else
- { // leave black border, do not scale image content
- mRawImage->expandToPowerOfTwo(MAX_IMAGE_SIZE, FALSE);
- }
-
- mFullWidth = mRawImage->getWidth();
- mFullHeight = mRawImage->getHeight();
- setTexelsPerImage();
- }
- else
- {
- mOrigWidth = mFullWidth;
- mOrigHeight = mFullHeight;
- }
+ if (mBoostLevel == BOOST_PREVIEW)
+ {
+ mRawImage->biasedScaleToPowerOfTwo(1024);
+ }
+ else
+ { // leave black border, do not scale image content
+ mRawImage->expandToPowerOfTwo(MAX_IMAGE_SIZE, FALSE);
+ }
- bool size_okay = true;
+ mFullWidth = mRawImage->getWidth();
+ mFullHeight = mRawImage->getHeight();
+ setTexelsPerImage();
+ }
+ else
+ {
+ mOrigWidth = mFullWidth;
+ mOrigHeight = mFullHeight;
+ }
- S32 discard_level = mRawDiscardLevel;
- if (mRawDiscardLevel < 0)
- {
- LL_DEBUGS() << "Negative raw discard level when creating image: " << mRawDiscardLevel << LL_ENDL;
- discard_level = 0;
- }
+ bool size_okay = true;
- U32 raw_width = mRawImage->getWidth() << discard_level;
- U32 raw_height = mRawImage->getHeight() << discard_level;
+ S32 discard_level = mRawDiscardLevel;
+ if (mRawDiscardLevel < 0)
+ {
+ LL_DEBUGS() << "Negative raw discard level when creating image: " << mRawDiscardLevel << LL_ENDL;
+ discard_level = 0;
+ }
- if( raw_width > MAX_IMAGE_SIZE || raw_height > MAX_IMAGE_SIZE )
- {
- LL_INFOS() << "Width or height is greater than " << MAX_IMAGE_SIZE << ": (" << raw_width << "," << raw_height << ")" << LL_ENDL;
- size_okay = false;
- }
-
- if (!LLImageGL::checkSize(mRawImage->getWidth(), mRawImage->getHeight()))
- {
- // A non power-of-two image was uploaded (through a non standard client)
- LL_INFOS() << "Non power of two width or height: (" << mRawImage->getWidth() << "," << mRawImage->getHeight() << ")" << LL_ENDL;
- size_okay = false;
- }
-
- if( !size_okay )
- {
- // An inappropriately-sized image was uploaded (through a non standard client)
- // We treat these images as missing assets which causes them to
- // be renderd as 'missing image' and to stop requesting data
- LL_WARNS() << "!size_ok, setting as missing" << LL_ENDL;
- setIsMissingAsset();
- destroyRawImage();
- return FALSE;
- }
+ U32 raw_width = mRawImage->getWidth() << discard_level;
+ U32 raw_height = mRawImage->getHeight() << discard_level;
+
+ if (raw_width > MAX_IMAGE_SIZE || raw_height > MAX_IMAGE_SIZE)
+ {
+ LL_INFOS() << "Width or height is greater than " << MAX_IMAGE_SIZE << ": (" << raw_width << "," << raw_height << ")" << LL_ENDL;
+ size_okay = false;
+ }
+
+ if (!LLImageGL::checkSize(mRawImage->getWidth(), mRawImage->getHeight()))
+ {
+ // A non power-of-two image was uploaded (through a non standard client)
+ LL_INFOS() << "Non power of two width or height: (" << mRawImage->getWidth() << "," << mRawImage->getHeight() << ")" << LL_ENDL;
+ size_okay = false;
+ }
+
+ if (!size_okay)
+ {
+ // An inappropriately-sized image was uploaded (through a non standard client)
+ // We treat these images as missing assets which causes them to
+ // be renderd as 'missing image' and to stop requesting data
+ LL_WARNS() << "!size_ok, setting as missing" << LL_ENDL;
+ setIsMissingAsset();
+ destroyRawImage();
+ return FALSE;
+ }
if (mGLTexturep->getHasExplicitFormat())
{
@@ -1564,19 +1590,79 @@ BOOL LLViewerFetchedTexture::createTexture(S32 usename/*= 0*/)
}
}
- res = mGLTexturep->createGLTexture(mRawDiscardLevel, mRawImage, usename, TRUE, mBoostLevel);
+ return res;
+}
- notifyAboutCreatingTexture();
+BOOL LLViewerFetchedTexture::createTexture(S32 usename/*= 0*/)
+{
+ if (!mNeedsCreateTexture)
+ {
+ return FALSE;
+ }
- setActive();
+ BOOL res = mGLTexturep->createGLTexture(mRawDiscardLevel, mRawImage, usename, TRUE, mBoostLevel);
+
+ return res;
+}
- if (!needsToSaveRawImage())
- {
- mNeedsAux = FALSE;
- destroyRawImage();
- }
+void LLViewerFetchedTexture::postCreateTexture()
+{
+ if (!mNeedsCreateTexture)
+ {
+ return;
+ }
- return res;
+ notifyAboutCreatingTexture();
+
+ setActive();
+
+ if (!needsToSaveRawImage())
+ {
+ mNeedsAux = FALSE;
+ destroyRawImage();
+ }
+
+ mNeedsCreateTexture = FALSE;
+}
+
+void LLViewerFetchedTexture::scheduleCreateTexture()
+{
+ ref();
+ mNeedsCreateTexture = TRUE;
+ if (preCreateTexture())
+ {
+ mNeedsCreateTexture = TRUE;
+#if LL_WINDOWS //flip to 0 to revert to single-threaded OpenGL texture uploads
+ if (!LLImageGLThread::sInstance->post([this]()
+ {
+ //actually create the texture on a background thread
+ createTexture();
+ {
+ LL_PROFILE_ZONE_NAMED("iglt - sync");
+ if (gGLManager.mHasSync)
+ {
+ auto sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
+ glClientWaitSync(sync, 0, 0);
+ glDeleteSync(sync);
+ }
+ else
+ {
+ glFinish();
+ }
+ }
+ LLImageGLThread::sInstance->postCallback([this]()
+ {
+ //finalize on main thread
+ postCreateTexture();
+ unref();
+ });
+ }))
+#endif
+ {
+ gTextureList.mCreateTextureList.insert(this);
+ unref();
+ }
+ }
}
// Call with 0,0 to turn this feature off.
@@ -1868,6 +1954,7 @@ void LLViewerFetchedTexture::setAdditionalDecodePriority(F32 priority)
void LLViewerFetchedTexture::updateVirtualSize()
{
+ LL_PROFILE_ZONE_SCOPED;
if(!mMaxVirtualSizeResetCounter)
{
addTextureStats(0.f, FALSE);//reset
@@ -1959,6 +2046,7 @@ bool LLViewerFetchedTexture::isActiveFetching()
bool LLViewerFetchedTexture::updateFetch()
{
+ LL_PROFILE_ZONE_SCOPED;
static LLCachedControl<bool> textures_decode_disabled(gSavedSettings,"TextureDecodeDisabled", false);
static LLCachedControl<F32> sCameraMotionThreshold(gSavedSettings,"TextureCameraMotionThreshold", 0.2);
static LLCachedControl<S32> sCameraMotionBoost(gSavedSettings,"TextureCameraMotionBoost", 3);
@@ -2061,7 +2149,7 @@ bool LLViewerFetchedTexture::updateFetch()
}
else
{
- mIsRawImageValid = TRUE;
+ mIsRawImageValid = TRUE;
addToCreateTexture();
}
@@ -2889,6 +2977,7 @@ void LLViewerFetchedTexture::destroyRawImage()
//virtual
void LLViewerFetchedTexture::switchToCachedImage()
{
+ LL_PROFILE_ZONE_SCOPED;
if(mCachedRawImage.notNull())
{
mRawImage = mCachedRawImage;
@@ -2900,12 +2989,12 @@ void LLViewerFetchedTexture::switchToCachedImage()
mComponents = mRawImage->getComponents();
mGLTexturep->setComponents(mComponents);
gTextureList.dirtyImage(this);
- }
+ }
mIsRawImageValid = TRUE;
mRawDiscardLevel = mCachedRawDiscardLevel;
- gTextureList.mCreateTextureList.insert(this);
- mNeedsCreateTexture = TRUE;
+
+ scheduleCreateTexture();
}
}
@@ -3179,6 +3268,7 @@ bool LLViewerLODTexture::isUpdateFrozen()
//virtual
void LLViewerLODTexture::processTextureStats()
{
+ LL_PROFILE_ZONE_SCOPED;
updateVirtualSize();
static LLCachedControl<bool> textures_fullres(gSavedSettings,"TextureLoadFullRes", false);