summaryrefslogtreecommitdiff
path: root/indra/newview/llviewertexturelist.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llviewertexturelist.cpp')
-rw-r--r--indra/newview/llviewertexturelist.cpp674
1 files changed, 151 insertions, 523 deletions
diff --git a/indra/newview/llviewertexturelist.cpp b/indra/newview/llviewertexturelist.cpp
index da3c860ddb..338aac2ccc 100644
--- a/indra/newview/llviewertexturelist.cpp
+++ b/indra/newview/llviewertexturelist.cpp
@@ -50,6 +50,7 @@
#include "llviewercontrol.h"
#include "llviewertexture.h"
#include "llviewermedia.h"
+#include "llviewernetwork.h"
#include "llviewerregion.h"
#include "llviewerstats.h"
#include "pipeline.h"
@@ -89,8 +90,6 @@ LLTextureKey::LLTextureKey(LLUUID id, ETexListType tex_type)
LLViewerTextureList::LLViewerTextureList()
: mForceResetTextureStats(FALSE),
- mMaxResidentTexMemInMegaBytes(0),
- mMaxTotalTextureMemInMegaBytes(0),
mInitialized(FALSE)
{
}
@@ -99,12 +98,6 @@ void LLViewerTextureList::init()
{
mInitialized = TRUE ;
sNumImages = 0;
- mMaxResidentTexMemInMegaBytes = (U32Bytes)0;
- mMaxTotalTextureMemInMegaBytes = (U32Bytes)0;
-
- // Update how much texture RAM we're allowed to use.
- updateMaxResidentTexMem(S32Megabytes(0)); // 0 = use current
-
doPreloadImages();
}
@@ -128,7 +121,10 @@ void LLViewerTextureList::doPreloadImages()
// Set the default flat normal map
LLViewerFetchedTexture::sFlatNormalImagep = LLViewerTextureManager::getFetchedTextureFromFile("flatnormal.tga", FTT_LOCAL_FILE, MIPMAP_NO, LLViewerFetchedTexture::BOOST_BUMP);
-
+
+ // PBR: irradiance
+ LLViewerFetchedTexture::sDefaultIrradiancePBRp = LLViewerTextureManager::getFetchedTextureFromFile("default_irradiance.png", FTT_LOCAL_FILE, MIPMAP_YES, LLViewerFetchedTexture::BOOST_UI);
+
image_list->initFromFile();
// turn off clamping and bilinear filtering for uv picking images
@@ -160,12 +156,6 @@ void LLViewerTextureList::doPreloadImages()
image->setAddressMode(LLTexUnit::TAM_WRAP);
mImagePreloads.insert(image);
}
- image = LLViewerTextureManager::getFetchedTexture(DEFAULT_WATER_NORMAL, FTT_DEFAULT, MIPMAP_YES, LLViewerFetchedTexture::BOOST_UI);
- if (image)
- {
- image->setAddressMode(LLTexUnit::TAM_WRAP);
- mImagePreloads.insert(image);
- }
image = LLViewerTextureManager::getFetchedTextureFromFile("transparent.j2c", FTT_LOCAL_FILE, MIPMAP_YES, LLViewerFetchedTexture::BOOST_UI, LLViewerTexture::FETCHED_TEXTURE,
0, 0, IMG_TRANSPARENT);
if (image)
@@ -198,16 +188,32 @@ void LLViewerTextureList::doPreloadImages()
static std::string get_texture_list_name()
{
- return gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "texture_list_" + gSavedSettings.getString("LoginLocation") + "." + gDirUtilp->getUserName() + ".xml");
+ if (LLGridManager::getInstance()->isInProductionGrid())
+ {
+ return gDirUtilp->getExpandedFilename(LL_PATH_CACHE,
+ "texture_list_" + gSavedSettings.getString("LoginLocation") + "." + gDirUtilp->getUserName() + ".xml");
+ }
+ else
+ {
+ const std::string& grid_id_str = LLGridManager::getInstance()->getGridId();
+ const std::string& grid_id_lower = utf8str_tolower(grid_id_str);
+ return gDirUtilp->getExpandedFilename(LL_PATH_CACHE,
+ "texture_list_" + gSavedSettings.getString("LoginLocation") + "." + gDirUtilp->getUserName() + "." + grid_id_lower + ".xml");
+ }
}
void LLViewerTextureList::doPrefetchImages()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
- gTextureTimer.start();
- gTextureTimer.pause();
- if (LLAppViewer::instance()->getPurgeCache())
+ LLViewerFetchedTexture* imagep = LLViewerTextureManager::getFetchedTexture(DEFAULT_WATER_NORMAL, FTT_DEFAULT, MIPMAP_YES, LLViewerFetchedTexture::BOOST_UI);
+ if (imagep)
+ {
+ imagep->setAddressMode(LLTexUnit::TAM_WRAP);
+ mImagePreloads.insert(imagep);
+ }
+
+ if (LLAppViewer::instance()->getPurgeCache())
{
// cache was purged, no point
return;
@@ -342,7 +348,7 @@ void LLViewerTextureList::dump()
{
LLViewerFetchedTexture* image = *it;
- LL_INFOS() << "priority " << image->getDecodePriority()
+ LL_INFOS() << "priority " << image->getMaxVirtualSize()
<< " boost " << image->getBoostLevel()
<< " size " << image->getWidth() << "x" << image->getHeight()
<< " discard " << image->getDiscardLevel()
@@ -667,13 +673,14 @@ void LLViewerTextureList::removeImageFromList(LLViewerFetchedTexture *image)
assert_main_thread();
llassert_always(mInitialized) ;
llassert(image);
+ image->validateRefCount();
S32 count = 0;
if (image->isInImageList())
{
count = mImageList.erase(image) ;
if(count != 1)
- {
+ {
LL_INFOS() << "Image " << image->getID()
<< " had mInImageList set but mImageList.erase() returned " << count
<< LL_ENDL;
@@ -699,6 +706,7 @@ void LLViewerTextureList::removeImageFromList(LLViewerFetchedTexture *image)
LL_INFOS() << "Image " << image->getID() << " was in mUUIDMap with same pointer" << LL_ENDL ;
}
count = mImageList.erase(image) ;
+ llassert(count != 0);
if(count != 0)
{ // it was in the list already?
LL_WARNS() << "Image " << image->getID()
@@ -784,17 +792,12 @@ void LLViewerTextureList::updateImages(F32 max_time)
using namespace LLStatViewer;
sample(NUM_IMAGES, sNumImages);
sample(NUM_RAW_IMAGES, LLImageRaw::sRawImageCount);
- sample(GL_TEX_MEM, LLImageGL::sGlobalTextureMemory);
- sample(GL_BOUND_MEM, LLImageGL::sBoundTextureMemory);
- sample(RAW_MEM, F64Bytes(LLImageRaw::sGlobalRawMemory));
sample(FORMATTED_MEM, F64Bytes(LLImageFormatted::sGlobalFormattedMemory));
}
//loading from fast cache
max_time -= updateImagesLoadingFastCache(max_time);
- updateImagesDecodePriorities();
-
F32 total_max_time = max_time;
max_time -= updateImagesFetchTextures(max_time);
@@ -825,7 +828,6 @@ void LLViewerTextureList::updateImages(F32 max_time)
didone = image->doLoadedCallbacks();
}
}
-
updateImagesUpdateStats();
}
@@ -848,120 +850,78 @@ void LLViewerTextureList::clearFetchingRequests()
}
}
-void LLViewerTextureList::updateImagesDecodePriorities()
+void LLViewerTextureList::updateImageDecodePriority(LLViewerFetchedTexture* imagep)
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
- // Update the decode priority for N images each frame
- {
- F32 lazy_flush_timeout = 30.f; // stop decoding
- F32 max_inactive_time = 20.f; // actually delete
- S32 min_refs = 3; // 1 for mImageList, 1 for mUUIDMap, 1 for local reference
-
- //reset imagep->getLastReferencedTimer() when screen is showing the progress view to avoid removing pre-fetched textures too soon.
- bool reset_timer = gViewerWindow->getProgressView()->getVisible();
-
- static const S32 MAX_PRIO_UPDATES = gSavedSettings.getS32("TextureFetchUpdatePriorities"); // default: 32
- const size_t max_update_count = llmin((S32) (MAX_PRIO_UPDATES*MAX_PRIO_UPDATES*gFrameIntervalSeconds.value()) + 1, MAX_PRIO_UPDATES);
- S32 update_counter = llmin(max_update_count, mUUIDMap.size());
- uuid_map_t::iterator iter = mUUIDMap.upper_bound(mLastUpdateKey);
- while ((update_counter-- > 0) && !mUUIDMap.empty())
- {
- if (iter == mUUIDMap.end())
- {
- iter = mUUIDMap.begin();
+ if (imagep->isInDebug() || imagep->isUnremovable())
+ {
+ //update_counter--;
+ return; //is in debug, ignore.
+ }
+
+ F32 lazy_flush_timeout = 30.f; // stop decoding
+ F32 max_inactive_time = 20.f; // actually delete
+ S32 min_refs = 3; // 1 for mImageList, 1 for mUUIDMap, 1 for local reference
+
+ //
+ // Flush formatted images using a lazy flush
+ //
+ S32 num_refs = imagep->getNumRefs();
+ if (num_refs == min_refs)
+ {
+ if (imagep->getLastReferencedTimer()->getElapsedTimeF32() > lazy_flush_timeout)
+ {
+ // Remove the unused image from the image list
+ deleteImage(imagep);
+ imagep = NULL; // should destroy the image
+ }
+ return;
+ }
+ else
+ {
+ if (imagep->hasSavedRawImage())
+ {
+ if (imagep->getElapsedLastReferencedSavedRawImageTime() > max_inactive_time)
+ {
+ imagep->destroySavedRawImage();
}
- mLastUpdateKey = iter->first;
- LLPointer<LLViewerFetchedTexture> imagep = iter->second;
- ++iter; // safe to increment now
+ }
- if(imagep->isInDebug() || imagep->isUnremovable())
- {
- update_counter--;
- continue; //is in debug, ignore.
- }
+ if (imagep->isDeleted())
+ {
+ return;
+ }
+ else if (imagep->isDeletionCandidate())
+ {
+ imagep->destroyTexture();
+ return;
+ }
+ else if (imagep->isInactive())
+ {
+ if (imagep->getLastReferencedTimer()->getElapsedTimeF32() > max_inactive_time)
+ {
+ imagep->setDeletionCandidate();
+ }
+ return;
+ }
+ else
+ {
+ imagep->getLastReferencedTimer()->reset();
- //
- // Flush formatted images using a lazy flush
- //
- S32 num_refs = imagep->getNumRefs();
- if (num_refs == min_refs)
- {
- if(reset_timer)
- {
- imagep->getLastReferencedTimer()->reset();
- }
- else if (imagep->getLastReferencedTimer()->getElapsedTimeF32() > lazy_flush_timeout)
- {
- // Remove the unused image from the image list
- deleteImage(imagep);
- imagep = NULL; // should destroy the image
- }
- continue;
- }
- else
- {
- if(imagep->hasSavedRawImage())
- {
- if(imagep->getElapsedLastReferencedSavedRawImageTime() > max_inactive_time)
- {
- imagep->destroySavedRawImage() ;
- }
- }
-
- if(imagep->isDeleted())
- {
- continue ;
- }
- else if(imagep->isDeletionCandidate())
- {
- imagep->destroyTexture() ;
- continue ;
- }
- else if(imagep->isInactive())
- {
- if(reset_timer)
- {
- imagep->getLastReferencedTimer()->reset();
- }
- else if (imagep->getLastReferencedTimer()->getElapsedTimeF32() > max_inactive_time)
- {
- imagep->setDeletionCandidate() ;
- }
- continue ;
- }
- else
- {
- imagep->getLastReferencedTimer()->reset();
-
- //reset texture state.
- imagep->setInactive() ;
- }
- }
+ //reset texture state.
+ imagep->setInactive();
+ }
+ }
- if (!imagep->isInImageList())
- {
- continue;
- }
- if(imagep->isInFastCacheList())
- {
- continue; //wait for loading from the fast cache.
- }
+ if (!imagep->isInImageList())
+ {
+ return;
+ }
+ if (imagep->isInFastCacheList())
+ {
+ return; //wait for loading from the fast cache.
+ }
- imagep->processTextureStats();
- F32 old_priority = imagep->getDecodePriority();
- F32 old_priority_test = llmax(old_priority, 0.0f);
- F32 decode_priority = imagep->calcDecodePriority();
- F32 decode_priority_test = llmax(decode_priority, 0.0f);
- // Ignore < 20% difference
- if ((decode_priority_test < old_priority_test * .8f) ||
- (decode_priority_test > old_priority_test * 1.25f))
- {
- mImageList.erase(imagep) ;
- imagep->setDecodePriority(decode_priority);
- mImageList.insert(imagep);
- }
- }
- }
+ imagep->processTextureStats();
}
void LLViewerTextureList::setDebugFetching(LLViewerFetchedTexture* tex, S32 debug_level)
@@ -973,17 +933,9 @@ void LLViewerTextureList::setDebugFetching(LLViewerFetchedTexture* tex, S32 debu
}
const F32 DEBUG_PRIORITY = 100000.f;
- F32 old_priority_test = llmax(tex->getDecodePriority(), 0.0f);
- F32 decode_priority_test = DEBUG_PRIORITY;
-
- // Ignore < 20% difference
- if ((decode_priority_test < old_priority_test * .8f) ||
- (decode_priority_test > old_priority_test * 1.25f))
- {
- removeImageFromList(tex);
- tex->setDecodePriority(decode_priority_test);
- addImageToList(tex);
- }
+ removeImageFromList(tex);
+ tex->mMaxVirtualSize = DEBUG_PRIORITY;
+ addImageToList(tex);
}
/*
@@ -1033,10 +985,6 @@ F32 LLViewerTextureList::updateImagesCreateTextures(F32 max_time)
LLViewerFetchedTexture *imagep = *curiter;
imagep->createTexture();
imagep->postCreateTexture();
- if (create_timer.getElapsedTimeF32() > max_time)
- {
- break;
- }
}
mCreateTextureList.erase(mCreateTextureList.begin(), enditer);
return create_timer.getElapsedTimeF32();
@@ -1064,10 +1012,6 @@ F32 LLViewerTextureList::updateImagesLoadingFastCache(F32 max_time)
enditer = iter;
LLViewerFetchedTexture *imagep = *curiter;
imagep->loadFromFastCache();
- if (timer.getElapsedTimeF32() > max_time)
- {
- break;
- }
}
mFastCacheList.erase(mFastCacheList.begin(), enditer);
return timer.getElapsedTimeF32();
@@ -1086,8 +1030,7 @@ void LLViewerTextureList::forceImmediateUpdate(LLViewerFetchedTexture* imagep)
}
imagep->processTextureStats();
- F32 decode_priority = LLViewerFetchedTexture::maxDecodePriority() ;
- imagep->setDecodePriority(decode_priority);
+ imagep->sMaxVirtualSize = LLViewerFetchedTexture::sMaxVirtualSize;
addImageToList(imagep);
return ;
@@ -1096,75 +1039,55 @@ void LLViewerTextureList::forceImmediateUpdate(LLViewerFetchedTexture* imagep)
F32 LLViewerTextureList::updateImagesFetchTextures(F32 max_time)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
- LLTimer image_op_timer;
-
- // Update fetch for N images each frame
- static const S32 MAX_HIGH_PRIO_COUNT = gSavedSettings.getS32("TextureFetchUpdateHighPriority"); // default: 32
- static const S32 MAX_UPDATE_COUNT = gSavedSettings.getS32("TextureFetchUpdateMaxMediumPriority"); // default: 256
- static const S32 MIN_UPDATE_COUNT = gSavedSettings.getS32("TextureFetchUpdateMinMediumPriority"); // default: 32
- static const F32 MIN_PRIORITY_THRESHOLD = gSavedSettings.getF32("TextureFetchUpdatePriorityThreshold"); // default: 0.0
- static const bool SKIP_LOW_PRIO = gSavedSettings.getBOOL("TextureFetchUpdateSkipLowPriority"); // default: false
-
- size_t max_priority_count = llmin((S32) (MAX_HIGH_PRIO_COUNT*MAX_HIGH_PRIO_COUNT*gFrameIntervalSeconds.value())+1, MAX_HIGH_PRIO_COUNT);
- max_priority_count = llmin(max_priority_count, mImageList.size());
-
- size_t total_update_count = mUUIDMap.size();
- size_t max_update_count = llmin((S32) (MAX_UPDATE_COUNT*MAX_UPDATE_COUNT*gFrameIntervalSeconds.value())+1, MAX_UPDATE_COUNT);
- max_update_count = llmin(max_update_count, total_update_count);
-
- // MAX_HIGH_PRIO_COUNT high priority entries
- typedef std::vector<LLViewerFetchedTexture*> entries_list_t;
- entries_list_t entries;
- size_t update_counter = max_priority_count;
- image_priority_list_t::iterator iter1 = mImageList.begin();
- while(update_counter > 0)
- {
- entries.push_back(*iter1);
-
- ++iter1;
- update_counter--;
- }
-
- // MAX_UPDATE_COUNT cycled entries
- update_counter = max_update_count;
- if(update_counter > 0)
- {
- uuid_map_t::iterator iter2 = mUUIDMap.upper_bound(mLastFetchKey);
- while ((update_counter > 0) && (total_update_count > 0))
- {
- if (iter2 == mUUIDMap.end())
- {
- iter2 = mUUIDMap.begin();
- }
- LLViewerFetchedTexture* imagep = iter2->second;
- // Skip the textures where there's really nothing to do so to give some times to others. Also skip the texture if it's already in the high prio set.
- if (!SKIP_LOW_PRIO || (SKIP_LOW_PRIO && ((imagep->getDecodePriority() > MIN_PRIORITY_THRESHOLD) || imagep->hasFetcher())))
+ LLTimer image_op_timer;
+
+ typedef std::vector<LLPointer<LLViewerFetchedTexture> > entries_list_t;
+ entries_list_t entries;
+
+ // update N textures at beginning of mImageList
+ U32 update_count = 0;
+ static const S32 MIN_UPDATE_COUNT = gSavedSettings.getS32("TextureFetchUpdateMinCount"); // default: 32
+ // WIP -- dumb code here
+ //update MIN_UPDATE_COUNT or 5% of other textures, whichever is greater
+ update_count = llmax((U32) MIN_UPDATE_COUNT, (U32) mUUIDMap.size()/20);
+ update_count = llmin(update_count, (U32) mUUIDMap.size());
+
+ {
+ LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("vtluift - copy");
+
+ // copy entries out of UUID map for updating
+ entries.reserve(update_count);
+ uuid_map_t::iterator iter = mUUIDMap.upper_bound(mLastUpdateKey);
+ while (update_count-- > 0)
+ {
+ if (iter == mUUIDMap.end())
+ {
+ iter = mUUIDMap.begin();
+ }
+
+ if (iter->second->getGLTexture())
{
- entries.push_back(imagep);
- update_counter--;
+ entries.push_back(iter->second);
}
+ ++iter;
+ }
+ }
- iter2++;
- total_update_count--;
- }
- }
+ for (auto& imagep : entries)
+ {
+ if (imagep->getNumRefs() > 1) // make sure this image hasn't been deleted before attempting to update (may happen as a side effect of some other image updating)
+ {
+ updateImageDecodePriority(imagep);
+ imagep->updateFetch();
+ }
+ }
+
+ if (entries.size() > 0)
+ {
+ LLViewerFetchedTexture* imagep = *entries.rbegin();
+ mLastUpdateKey = LLTextureKey(imagep->getID(), (ETexListType)imagep->getTextureListType());
+ }
- size_t min_update_count = llmin(MIN_UPDATE_COUNT,(S32)(entries.size()-max_priority_count));
- S32 min_count = max_priority_count + min_update_count;
- for (entries_list_t::iterator iter3 = entries.begin();
- iter3 != entries.end(); )
- {
- LLViewerFetchedTexture* imagep = *iter3++;
- imagep->updateFetch();
- if (min_count <= min_update_count)
- {
- mLastFetchKey = LLTextureKey(imagep->getID(), (ETexListType)imagep->getTextureListType());
- }
- if ((min_count-- <= 0) && (image_op_timer.getElapsedTimeF32() > max_time))
- {
- break;
- }
- }
return image_op_timer.getElapsedTimeF32();
}
@@ -1208,8 +1131,6 @@ void LLViewerTextureList::decodeAllImages(F32 max_time)
{
LLViewerFetchedTexture* imagep = *iter;
imagep->processTextureStats();
- F32 decode_priority = imagep->calcDecodePriority();
- imagep->setDecodePriority(decode_priority);
addImageToList(imagep);
}
image_list.clear();
@@ -1316,15 +1237,18 @@ BOOL LLViewerTextureList::createUploadFile(const std::string& filename,
}
// note: modifies the argument raw_image!!!!
-LLPointer<LLImageJ2C> LLViewerTextureList::convertToUploadFile(LLPointer<LLImageRaw> raw_image, const S32 max_image_dimentions)
+LLPointer<LLImageJ2C> LLViewerTextureList::convertToUploadFile(LLPointer<LLImageRaw> raw_image, const S32 max_image_dimentions, bool force_lossless)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
raw_image->biasedScaleToPowerOfTwo(max_image_dimentions);
LLPointer<LLImageJ2C> compressedImage = new LLImageJ2C();
- if (gSavedSettings.getBOOL("LosslessJ2CUpload") &&
- (raw_image->getWidth() * raw_image->getHeight() <= LL_IMAGE_REZ_LOSSLESS_CUTOFF * LL_IMAGE_REZ_LOSSLESS_CUTOFF))
- compressedImage->setReversible(TRUE);
+ if (force_lossless ||
+ (gSavedSettings.getBOOL("LosslessJ2CUpload") &&
+ (raw_image->getWidth() * raw_image->getHeight() <= LL_IMAGE_REZ_LOSSLESS_CUTOFF * LL_IMAGE_REZ_LOSSLESS_CUTOFF)))
+ {
+ compressedImage->setReversible(TRUE);
+ }
if (gSavedSettings.getBOOL("Jpeg2000AdvancedCompression"))
@@ -1349,304 +1273,8 @@ LLPointer<LLImageJ2C> LLViewerTextureList::convertToUploadFile(LLPointer<LLImage
return compressedImage;
}
-// Returns min setting for TextureMemory (in MB)
-S32Megabytes LLViewerTextureList::getMinVideoRamSetting()
-{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
- U32Megabytes system_ram = gSysMemory.getPhysicalMemoryKB();
- //min texture mem sets to 64M if total physical mem is more than 1.5GB
- return (system_ram > U32Megabytes(1500)) ? S32Megabytes(64) : gMinVideoRam ;
-}
-
-//static
-// Returns max setting for TextureMemory (in MB)
-S32Megabytes LLViewerTextureList::getMaxVideoRamSetting(bool get_recommended, float mem_multiplier)
-{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
- S32Megabytes max_texmem;
- if (gGLManager.mVRAM != 0)
- {
- // Treat any card with < 32 MB (shudder) as having 32 MB
- // - it's going to be swapping constantly regardless
- S32Megabytes max_vram(gGLManager.mVRAM);
-
- if(gGLManager.mIsAMD)
- {
- //shrink the availabe vram for ATI cards because some of them do not handel texture swapping well.
- max_vram = max_vram * 0.75f;
- }
-
- max_vram = llmax(max_vram, getMinVideoRamSetting());
- max_texmem = max_vram;
- if (!get_recommended)
- max_texmem *= 2;
- }
- else
- {
- if (!get_recommended)
- {
- max_texmem = (S32Megabytes)512;
- }
- else if (gSavedSettings.getBOOL("NoHardwareProbe")) //did not do hardware detection at startup
- {
- max_texmem = (S32Megabytes)512;
- }
- else
- {
- max_texmem = (S32Megabytes)128;
- }
- }
-
- S32Megabytes system_ram = gSysMemory.getPhysicalMemoryKB(); // In MB
- //LL_INFOS() << "*** DETECTED " << system_ram << " MB of system memory." << LL_ENDL;
- if (get_recommended)
- max_texmem = llmin(max_texmem, system_ram/2);
- else
- max_texmem = llmin(max_texmem, system_ram);
-
- // limit the texture memory to a multiple of the default if we've found some cards to behave poorly otherwise
- max_texmem = llmin(max_texmem, (S32Megabytes) (mem_multiplier * max_texmem));
-
- max_texmem = llclamp(max_texmem, getMinVideoRamSetting(), gMaxVideoRam);
-
- return max_texmem;
-}
-
-bool LLViewerTextureList::isPrioRequestsFetched()
-{
- static LLCachedControl<F32> prio_threshold(gSavedSettings, "TextureFetchUpdatePriorityThreshold", 0.0f);
- static LLCachedControl<F32> fetching_textures_threshold(gSavedSettings, "TextureListFetchingThreshold", 0.97f);
- S32 fetching_tex_count = 0;
- S32 tex_count_threshold = gTextureList.mImageList.size() * (1 - fetching_textures_threshold);
-
- for (LLViewerTextureList::image_priority_list_t::iterator iter = gTextureList.mImageList.begin();
- iter != gTextureList.mImageList.end(); )
- {
- LLPointer<LLViewerFetchedTexture> imagep = *iter++;
- if (imagep->getDecodePriority() > prio_threshold)
- {
- if (imagep->hasFetcher() || imagep->isFetching())
- {
- fetching_tex_count++;
- if (fetching_tex_count >= tex_count_threshold)
- {
- return false;
- }
- }
- }
- }
-
- return true;
-}
-
-const S32Megabytes VIDEO_CARD_FRAMEBUFFER_MEM(12);
-const S32Megabytes MIN_MEM_FOR_NON_TEXTURE(512);
-void LLViewerTextureList::updateMaxResidentTexMem(S32Megabytes mem)
-{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
- // Initialize the image pipeline VRAM settings
- S32Megabytes cur_mem(gSavedSettings.getS32("TextureMemory"));
- F32 mem_multiplier = gSavedSettings.getF32("RenderTextureMemoryMultiple");
- S32Megabytes default_mem = getMaxVideoRamSetting(true, mem_multiplier); // recommended default
- if (mem == (S32Bytes)0)
- {
- mem = cur_mem > (S32Bytes)0 ? cur_mem : default_mem;
- }
- else if (mem < (S32Bytes)0)
- {
- mem = default_mem;
- }
-
- mem = llclamp(mem, getMinVideoRamSetting(), getMaxVideoRamSetting(false, mem_multiplier));
- if (mem != cur_mem)
- {
- gSavedSettings.setS32("TextureMemory", mem.value());
- return; //listener will re-enter this function
- }
-
- if (gGLManager.mVRAM == 0)
- {
- LL_WARNS() << "VRAM amount not detected, defaulting to " << mem << " MB" << LL_ENDL;
- }
-
- // TODO: set available resident texture mem based on use by other subsystems
- // currently max(12MB, VRAM/4) assumed...
-
- S32Megabytes vb_mem = mem;
- S32Megabytes fb_mem = llmax(VIDEO_CARD_FRAMEBUFFER_MEM, vb_mem/4);
- mMaxResidentTexMemInMegaBytes = (vb_mem - fb_mem) ; //in MB
-
- mMaxTotalTextureMemInMegaBytes = mMaxResidentTexMemInMegaBytes * 2;
- if (mMaxResidentTexMemInMegaBytes > (S32Megabytes)640)
- {
- mMaxTotalTextureMemInMegaBytes -= (mMaxResidentTexMemInMegaBytes / 4);
- }
-
- //system mem
- S32Megabytes system_ram = gSysMemory.getPhysicalMemoryKB();
-
- //minimum memory reserved for non-texture use.
- //if system_raw >= 1GB, reserve at least 512MB for non-texture use;
- //otherwise reserve half of the system_ram for non-texture use.
- S32Megabytes min_non_texture_mem = llmin(system_ram / 2, MIN_MEM_FOR_NON_TEXTURE) ;
-
- if (mMaxTotalTextureMemInMegaBytes > system_ram - min_non_texture_mem)
- {
- mMaxTotalTextureMemInMegaBytes = system_ram - min_non_texture_mem ;
- }
-
- LL_INFOS() << "Total Video Memory set to: " << vb_mem << " MB" << LL_ENDL;
- LL_INFOS() << "Available Texture Memory set to: " << (vb_mem - fb_mem) << " MB" << LL_ENDL;
-}
-
///////////////////////////////////////////////////////////////////////////////
-// static
-void LLViewerTextureList::receiveImageHeader(LLMessageSystem *msg, void **user_data)
-{
- static LLCachedControl<bool> log_texture_traffic(gSavedSettings,"LogTextureNetworkTraffic", false) ;
-
- LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-
- // Receive image header, copy into image object and decompresses
- // if this is a one-packet image.
-
- LLUUID id;
-
- char ip_string[256];
- u32_to_ip_string(msg->getSenderIP(),ip_string);
-
- U32Bytes received_size ;
- if (msg->getReceiveCompressedSize())
- {
- received_size = (U32Bytes)msg->getReceiveCompressedSize() ;
- }
- else
- {
- received_size = (U32Bytes)msg->getReceiveSize() ;
- }
- add(LLStatViewer::TEXTURE_NETWORK_DATA_RECEIVED, received_size);
- add(LLStatViewer::TEXTURE_PACKETS, 1);
-
- U8 codec;
- U16 packets;
- U32 totalbytes;
- msg->getUUIDFast(_PREHASH_ImageID, _PREHASH_ID, id);
- msg->getU8Fast(_PREHASH_ImageID, _PREHASH_Codec, codec);
- msg->getU16Fast(_PREHASH_ImageID, _PREHASH_Packets, packets);
- msg->getU32Fast(_PREHASH_ImageID, _PREHASH_Size, totalbytes);
-
- S32 data_size = msg->getSizeFast(_PREHASH_ImageData, _PREHASH_Data);
- if (!data_size)
- {
- return;
- }
- if (data_size < 0)
- {
- // msg->getSizeFast() is probably trying to tell us there
- // was an error.
- LL_ERRS() << "image header chunk size was negative: "
- << data_size << LL_ENDL;
- return;
- }
-
- // this buffer gets saved off in the packet list
- U8 *data = new U8[data_size];
- msg->getBinaryDataFast(_PREHASH_ImageData, _PREHASH_Data, data, data_size);
-
- LLViewerFetchedTexture *image = LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
- if (!image)
- {
- delete [] data;
- return;
- }
- if(log_texture_traffic)
- {
- gTotalTextureBytesPerBoostLevel[image->getBoostLevel()] += received_size ;
- }
-
- //image->getLastPacketTimer()->reset();
- bool res = LLAppViewer::getTextureFetch()->receiveImageHeader(msg->getSender(), id, codec, packets, totalbytes, data_size, data);
- if (!res)
- {
- delete[] data;
- }
-}
-
-// static
-void LLViewerTextureList::receiveImagePacket(LLMessageSystem *msg, void **user_data)
-{
- static LLCachedControl<bool> log_texture_traffic(gSavedSettings,"LogTextureNetworkTraffic", false) ;
-
- LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-
- // Receives image packet, copy into image object,
- // checks if all packets received, decompresses if so.
-
- LLUUID id;
- U16 packet_num;
-
- char ip_string[256];
- u32_to_ip_string(msg->getSenderIP(),ip_string);
-
- U32Bytes received_size ;
- if (msg->getReceiveCompressedSize())
- {
- received_size = (U32Bytes)msg->getReceiveCompressedSize() ;
- }
- else
- {
- received_size = (U32Bytes)msg->getReceiveSize() ;
- }
-
- add(LLStatViewer::TEXTURE_NETWORK_DATA_RECEIVED, F64Bytes(received_size));
- add(LLStatViewer::TEXTURE_PACKETS, 1);
-
- //llprintline("Start decode, image header...");
- msg->getUUIDFast(_PREHASH_ImageID, _PREHASH_ID, id);
- msg->getU16Fast(_PREHASH_ImageID, _PREHASH_Packet, packet_num);
- S32 data_size = msg->getSizeFast(_PREHASH_ImageData, _PREHASH_Data);
-
- if (!data_size)
- {
- return;
- }
- if (data_size < 0)
- {
- // msg->getSizeFast() is probably trying to tell us there
- // was an error.
- LL_ERRS() << "image data chunk size was negative: "
- << data_size << LL_ENDL;
- return;
- }
- if (data_size > MTUBYTES)
- {
- LL_ERRS() << "image data chunk too large: " << data_size << " bytes" << LL_ENDL;
- return;
- }
- U8 *data = new U8[data_size];
- msg->getBinaryDataFast(_PREHASH_ImageData, _PREHASH_Data, data, data_size);
-
- LLViewerFetchedTexture *image = LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
- if (!image)
- {
- delete [] data;
- return;
- }
- if(log_texture_traffic)
- {
- gTotalTextureBytesPerBoostLevel[image->getBoostLevel()] += received_size ;
- }
-
- //image->getLastPacketTimer()->reset();
- bool res = LLAppViewer::getTextureFetch()->receiveImagePacket(msg->getSender(), id, packet_num, data_size, data);
- if (!res)
- {
- delete[] data;
- }
-}
-
-
// We've been that the asset server does not contain the requested image id.
// static
void LLViewerTextureList::processImageNotInDatabase(LLMessageSystem *msg,void **user_data)