diff options
Diffstat (limited to 'indra/newview/llviewertexturelist.cpp')
-rwxr-xr-x | indra/newview/llviewertexturelist.cpp | 356 |
1 files changed, 185 insertions, 171 deletions
diff --git a/indra/newview/llviewertexturelist.cpp b/indra/newview/llviewertexturelist.cpp index 2efe4665fa..dae76272ec 100755 --- a/indra/newview/llviewertexturelist.cpp +++ b/indra/newview/llviewertexturelist.cpp @@ -30,7 +30,6 @@ #include "llviewertexturelist.h" -#include "imageids.h" #include "llgl.h" // fot gathering stats from GL #include "llimagegl.h" #include "llimagebmp.h" @@ -58,24 +57,19 @@ #include "pipeline.h" #include "llappviewer.h" #include "llxuiparser.h" +#include "lltracerecording.h" #include "llviewerdisplay.h" - +#include "llviewerwindow.h" +#include "llprogressview.h" //////////////////////////////////////////////////////////////////////////// void (*LLViewerTextureList::sUUIDCallback)(void **, const LLUUID&) = NULL; -U32 LLViewerTextureList::sTextureBits = 0; -U32 LLViewerTextureList::sTexturePackets = 0; S32 LLViewerTextureList::sNumImages = 0; -LLStat LLViewerTextureList::sNumImagesStat("Num Images", 32, TRUE); -LLStat LLViewerTextureList::sNumRawImagesStat("Num Raw Images", 32, TRUE); -LLStat LLViewerTextureList::sGLTexMemStat("GL Texture Mem", 32, TRUE); -LLStat LLViewerTextureList::sGLBoundMemStat("GL Bound Mem", 32, TRUE); -LLStat LLViewerTextureList::sRawMemStat("Raw Image Mem", 32, TRUE); -LLStat LLViewerTextureList::sFormattedMemStat("Formatted Image Mem", 32, TRUE); LLViewerTextureList gTextureList; -static LLFastTimer::DeclareTimer FTM_PROCESS_IMAGES("Process Images"); +static LLTrace::BlockTimerStatHandle FTM_PROCESS_IMAGES("Process Images"); + /////////////////////////////////////////////////////////////////////////////// @@ -93,11 +87,11 @@ void LLViewerTextureList::init() mInitialized = TRUE ; sNumImages = 0; mUpdateStats = TRUE; - mMaxResidentTexMemInMegaBytes = 0; - mMaxTotalTextureMemInMegaBytes = 0 ; + mMaxResidentTexMemInMegaBytes = (U32Bytes)0; + mMaxTotalTextureMemInMegaBytes = (U32Bytes)0; // Update how much texture RAM we're allowed to use. - updateMaxResidentTexMem(0); // 0 = use current + updateMaxResidentTexMem(S32Megabytes(0)); // 0 = use current doPreloadImages(); } @@ -292,18 +286,18 @@ void LLViewerTextureList::shutdown() void LLViewerTextureList::dump() { - llinfos << "LLViewerTextureList::dump()" << llendl; + LL_INFOS() << "LLViewerTextureList::dump()" << LL_ENDL; for (image_priority_list_t::iterator it = mImageList.begin(); it != mImageList.end(); ++it) { LLViewerFetchedTexture* image = *it; - llinfos << "priority " << image->getDecodePriority() + LL_INFOS() << "priority " << image->getDecodePriority() << " boost " << image->getBoostLevel() << " size " << image->getWidth() << "x" << image->getHeight() << " discard " << image->getDiscardLevel() << " desired " << image->getDesiredDiscardLevel() << " http://asset.siva.lindenlab.com/" << image->getID() << ".texture" - << llendl; + << LL_ENDL; } } @@ -327,7 +321,7 @@ void LLViewerTextureList::restoreGL() /////////////////////////////////////////////////////////////////////////////// -LLViewerFetchedTexture* LLViewerTextureList::getImageFromFile(const std::string& filename, +LLViewerFetchedTexture* LLViewerTextureList::getImageFromFile(const std::string& filename, FTType f_type, BOOL usemipmaps, LLViewerTexture::EBoostLevel boost_priority, @@ -344,7 +338,7 @@ LLViewerFetchedTexture* LLViewerTextureList::getImageFromFile(const std::string& std::string full_path = gDirUtilp->findSkinnedFilename("textures", filename); if (full_path.empty()) { - llwarns << "Failed to find local image file: " << filename << llendl; + LL_WARNS() << "Failed to find local image file: " << filename << LL_ENDL; return LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); } @@ -379,13 +373,13 @@ LLViewerFetchedTexture* LLViewerTextureList::getImageFromUrl(const std::string& } LLPointer<LLViewerFetchedTexture> imagep = findImage(new_id); - + if (!imagep.isNull()) { LLViewerFetchedTexture *texture = imagep.get(); if (texture->getUrl().empty()) { - llwarns << "Requested texture " << new_id << " already exists but does not have a URL" << llendl; + LL_WARNS() << "Requested texture " << new_id << " already exists but does not have a URL" << LL_ENDL; } else if (texture->getUrl() != url) { @@ -393,7 +387,7 @@ LLViewerFetchedTexture* LLViewerTextureList::getImageFromUrl(const std::string& // e.g. could be two avatars wearing the same outfit. LL_DEBUGS("Avatar") << "Requested texture " << new_id << " already exists with a different url, requested: " << url - << " current: " << texture->getUrl() << llendl; + << " current: " << texture->getUrl() << LL_ENDL; } } @@ -408,7 +402,7 @@ LLViewerFetchedTexture* LLViewerTextureList::getImageFromUrl(const std::string& imagep = new LLViewerLODTexture(url, f_type, new_id, usemipmaps); break ; default: - llerrs << "Invalid texture type " << texture_type << llendl ; + LL_ERRS() << "Invalid texture type " << texture_type << LL_ENDL ; } if (internal_format && primary_format) @@ -435,7 +429,7 @@ LLViewerFetchedTexture* LLViewerTextureList::getImageFromUrl(const std::string& } -LLViewerFetchedTexture* LLViewerTextureList::getImage(const LLUUID &image_id, +LLViewerFetchedTexture* LLViewerTextureList::getImage(const LLUUID &image_id, FTType f_type, BOOL usemipmaps, LLViewerTexture::EBoostLevel boost_priority, @@ -465,20 +459,20 @@ LLViewerFetchedTexture* LLViewerTextureList::getImage(const LLUUID &image_id, if (request_from_host.isOk() && !texture->getTargetHost().isOk()) { - llwarns << "Requested texture " << image_id << " already exists but does not have a host" << llendl; + LL_WARNS() << "Requested texture " << image_id << " already exists but does not have a host" << LL_ENDL; } else if (request_from_host.isOk() && texture->getTargetHost().isOk() && request_from_host != texture->getTargetHost()) { - llwarns << "Requested texture " << image_id << " already exists with a different target host, requested: " - << request_from_host << " current: " << texture->getTargetHost() << llendl; + LL_WARNS() << "Requested texture " << image_id << " already exists with a different target host, requested: " + << request_from_host << " current: " << texture->getTargetHost() << LL_ENDL; } if (f_type != FTT_DEFAULT && imagep->getFTType() != f_type) { - llwarns << "FTType mismatch: requested " << f_type << " image has " << imagep->getFTType() << llendl; + LL_WARNS() << "FTType mismatch: requested " << f_type << " image has " << imagep->getFTType() << LL_ENDL; } - + } if (imagep.isNull()) { @@ -491,7 +485,7 @@ LLViewerFetchedTexture* LLViewerTextureList::getImage(const LLUUID &image_id, } //when this function is called, there is no such texture in the gTextureList with image_id. -LLViewerFetchedTexture* LLViewerTextureList::createImage(const LLUUID &image_id, +LLViewerFetchedTexture* LLViewerTextureList::createImage(const LLUUID &image_id, FTType f_type, BOOL usemipmaps, LLViewerTexture::EBoostLevel boost_priority, @@ -512,7 +506,7 @@ LLViewerFetchedTexture* LLViewerTextureList::createImage(const LLUUID &image_id, imagep = new LLViewerLODTexture(image_id, f_type, request_from_host, usemipmaps); break ; default: - llerrs << "Invalid texture type " << texture_type << llendl ; + LL_ERRS() << "Invalid texture type " << texture_type << LL_ENDL ; } if (internal_format && primary_format) @@ -562,13 +556,13 @@ void LLViewerTextureList::addImageToList(LLViewerFetchedTexture *image) llassert(image); if (image->isInImageList()) { // Flag is already set? - llwarns << "LLViewerTextureList::addImageToList - image " << image->getID() << " already in list" << llendl; + LL_WARNS() << "LLViewerTextureList::addImageToList - image " << image->getID() << " already in list" << LL_ENDL; } else { if((mImageList.insert(image)).second != true) { - llwarns << "Error happens when insert image " << image->getID() << " into mImageList!" << llendl ; + LL_WARNS() << "Error happens when insert image " << image->getID() << " into mImageList!" << LL_ENDL ; } image->setInImageList(TRUE) ; } @@ -586,36 +580,36 @@ void LLViewerTextureList::removeImageFromList(LLViewerFetchedTexture *image) count = mImageList.erase(image) ; if(count != 1) { - llinfos << "Image " << image->getID() + LL_INFOS() << "Image " << image->getID() << " had mInImageList set but mImageList.erase() returned " << count - << llendl; + << LL_ENDL; } } else { // Something is wrong, image is expected in list or callers should check first - llinfos << "Calling removeImageFromList() for " << image->getID() + LL_INFOS() << "Calling removeImageFromList() for " << image->getID() << " but doesn't have mInImageList set" << " ref count is " << image->getNumRefs() - << llendl; + << LL_ENDL; uuid_map_t::iterator iter = mUUIDMap.find(image->getID()); if(iter == mUUIDMap.end()) { - llinfos << "Image " << image->getID() << " is also not in mUUIDMap!" << llendl ; + LL_INFOS() << "Image " << image->getID() << " is also not in mUUIDMap!" << LL_ENDL ; } else if (iter->second != image) { - llinfos << "Image " << image->getID() << " was in mUUIDMap but with different pointer" << llendl ; + LL_INFOS() << "Image " << image->getID() << " was in mUUIDMap but with different pointer" << LL_ENDL ; } else { - llinfos << "Image " << image->getID() << " was in mUUIDMap with same pointer" << llendl ; + LL_INFOS() << "Image " << image->getID() << " was in mUUIDMap with same pointer" << LL_ENDL ; } count = mImageList.erase(image) ; if(count != 0) { // it was in the list already? - llwarns << "Image " << image->getID() + LL_WARNS() << "Image " << image->getID() << " had mInImageList false but mImageList.erase() returned " << count - << llendl; + << LL_ENDL; } } @@ -634,7 +628,7 @@ void LLViewerTextureList::addImage(LLViewerFetchedTexture *new_image) LLViewerFetchedTexture *image = findImage(image_id); if (image) { - llinfos << "Image with ID " << image_id << " already in list" << llendl; + LL_INFOS() << "Image with ID " << image_id << " already in list" << LL_ENDL; } sNumImages++; @@ -669,16 +663,18 @@ void LLViewerTextureList::dirtyImage(LLViewerFetchedTexture *image) } //////////////////////////////////////////////////////////////////////////// -static LLFastTimer::DeclareTimer FTM_IMAGE_MARK_DIRTY("Dirty Images"); -static LLFastTimer::DeclareTimer FTM_IMAGE_UPDATE_PRIORITIES("Prioritize"); -static LLFastTimer::DeclareTimer FTM_IMAGE_CALLBACKS("Callbacks"); -static LLFastTimer::DeclareTimer FTM_IMAGE_FETCH("Fetch"); -static LLFastTimer::DeclareTimer FTM_FAST_CACHE_IMAGE_FETCH("Fast Cache Fetch"); -static LLFastTimer::DeclareTimer FTM_IMAGE_CREATE("Create"); -static LLFastTimer::DeclareTimer FTM_IMAGE_STATS("Stats"); +static LLTrace::BlockTimerStatHandle FTM_IMAGE_MARK_DIRTY("Dirty Images"); +static LLTrace::BlockTimerStatHandle FTM_IMAGE_UPDATE_PRIORITIES("Prioritize"); +static LLTrace::BlockTimerStatHandle FTM_IMAGE_CALLBACKS("Callbacks"); +static LLTrace::BlockTimerStatHandle FTM_IMAGE_FETCH("Fetch"); +static LLTrace::BlockTimerStatHandle FTM_FAST_CACHE_IMAGE_FETCH("Fast Cache Fetch"); +static LLTrace::BlockTimerStatHandle FTM_IMAGE_CREATE("Create"); +static LLTrace::BlockTimerStatHandle FTM_IMAGE_STATS("Stats"); +static LLTrace::BlockTimerStatHandle FTM_UPDATE_IMAGES("Update Images"); void LLViewerTextureList::updateImages(F32 max_time) { + LL_RECORD_BLOCK_TIME(FTM_UPDATE_IMAGES); static BOOL cleared = FALSE; if(gTeleportDisplay) { @@ -692,48 +688,51 @@ void LLViewerTextureList::updateImages(F32 max_time) } cleared = FALSE; - LLAppViewer::getTextureFetch()->setTextureBandwidth(LLViewerStats::getInstance()->mTextureKBitStat.getMeanPerSec()); + LLAppViewer::getTextureFetch()->setTextureBandwidth(LLTrace::get_frame_recording().getPeriodMeanPerSec(LLStatViewer::TEXTURE_NETWORK_DATA_RECEIVED).value()); - LLViewerStats::getInstance()->mNumImagesStat.addValue(sNumImages); - LLViewerStats::getInstance()->mNumRawImagesStat.addValue(LLImageRaw::sRawImageCount); - LLViewerStats::getInstance()->mGLTexMemStat.addValue((F32)BYTES_TO_MEGA_BYTES(LLImageGL::sGlobalTextureMemoryInBytes)); - LLViewerStats::getInstance()->mGLBoundMemStat.addValue((F32)BYTES_TO_MEGA_BYTES(LLImageGL::sBoundTextureMemoryInBytes)); - LLViewerStats::getInstance()->mRawMemStat.addValue((F32)BYTES_TO_MEGA_BYTES(LLImageRaw::sGlobalRawMemory)); - LLViewerStats::getInstance()->mFormattedMemStat.addValue((F32)BYTES_TO_MEGA_BYTES(LLImageFormatted::sGlobalFormattedMemory)); + { + 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 - LLFastTimer t(FTM_FAST_CACHE_IMAGE_FETCH); + LL_RECORD_BLOCK_TIME(FTM_FAST_CACHE_IMAGE_FETCH); max_time -= updateImagesLoadingFastCache(max_time); } { - LLFastTimer t(FTM_IMAGE_UPDATE_PRIORITIES); + LL_RECORD_BLOCK_TIME(FTM_IMAGE_UPDATE_PRIORITIES); updateImagesDecodePriorities(); } F32 total_max_time = max_time; { - LLFastTimer t(FTM_IMAGE_FETCH); + LL_RECORD_BLOCK_TIME(FTM_IMAGE_FETCH); max_time -= updateImagesFetchTextures(max_time); } { - LLFastTimer t(FTM_IMAGE_CREATE); + LL_RECORD_BLOCK_TIME(FTM_IMAGE_CREATE); max_time = llmax(max_time, total_max_time*.50f); // at least 50% of max_time max_time -= updateImagesCreateTextures(max_time); } if (!mDirtyTextureList.empty()) { - LLFastTimer t(FTM_IMAGE_MARK_DIRTY); + LL_RECORD_BLOCK_TIME(FTM_IMAGE_MARK_DIRTY); gPipeline.dirtyPoolObjectTextures(mDirtyTextureList); mDirtyTextureList.clear(); } { - LLFastTimer t(FTM_IMAGE_CALLBACKS); + LL_RECORD_BLOCK_TIME(FTM_IMAGE_CALLBACKS); bool didone = false; for (image_list_t::iterator iter = mCallbackList.begin(); iter != mCallbackList.end(); ) @@ -754,7 +753,7 @@ void LLViewerTextureList::updateImages(F32 max_time) } { - LLFastTimer t(FTM_IMAGE_STATS); + LL_RECORD_BLOCK_TIME(FTM_IMAGE_STATS); updateImagesUpdateStats(); } } @@ -780,8 +779,15 @@ void LLViewerTextureList::updateImagesDecodePriorities() { // 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) + 1, MAX_PRIO_UPDATES); + 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(mLastUpdateUUID); while ((update_counter-- > 0) && !mUUIDMap.empty()) @@ -803,14 +809,14 @@ void LLViewerTextureList::updateImagesDecodePriorities() // // Flush formatted images using a lazy flush // - const F32 LAZY_FLUSH_TIMEOUT = 30.f; // stop decoding - const F32 MAX_INACTIVE_TIME = 20.f; // actually delete - S32 min_refs = 3; // 1 for mImageList, 1 for mUUIDMap, 1 for local reference - S32 num_refs = imagep->getNumRefs(); if (num_refs == min_refs) { - if (imagep->getLastReferencedTimer()->getElapsedTimeF32() > LAZY_FLUSH_TIMEOUT) + if(reset_timer) + { + imagep->getLastReferencedTimer()->reset(); + } + else if (imagep->getLastReferencedTimer()->getElapsedTimeF32() > lazy_flush_timeout) { // Remove the unused image from the image list deleteImage(imagep); @@ -822,7 +828,7 @@ void LLViewerTextureList::updateImagesDecodePriorities() { if(imagep->hasSavedRawImage()) { - if(imagep->getElapsedLastReferencedSavedRawImageTime() > MAX_INACTIVE_TIME) + if(imagep->getElapsedLastReferencedSavedRawImageTime() > max_inactive_time) { imagep->destroySavedRawImage() ; } @@ -839,7 +845,11 @@ void LLViewerTextureList::updateImagesDecodePriorities() } else if(imagep->isInactive()) { - if (imagep->getLastReferencedTimer()->getElapsedTimeF32() > MAX_INACTIVE_TIME) + if(reset_timer) + { + imagep->getLastReferencedTimer()->reset(); + } + else if (imagep->getLastReferencedTimer()->getElapsedTimeF32() > max_inactive_time) { imagep->setDeletionCandidate() ; } @@ -917,11 +927,11 @@ void LLViewerTextureList::setDebugFetching(LLViewerFetchedTexture* tex, S32 debu if (type_from_host == LLImageBase::TYPE_NORMAL && type_from_boost == LLImageBase::TYPE_AVATAR_BAKE) { - llwarns << "TAT: get_image_type() type_from_host doesn't match type_from_boost" + LL_WARNS() << "TAT: get_image_type() type_from_host doesn't match type_from_boost" << " host " << target_host << " boost " << imagep->getBoostLevel() << " imageid " << imagep->getID() - << llendl; + << LL_ENDL; imagep->dump(); } return type_from_host; @@ -1015,11 +1025,11 @@ F32 LLViewerTextureList::updateImagesFetchTextures(F32 max_time) 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)+1, MAX_HIGH_PRIO_COUNT); + 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)+1, MAX_UPDATE_COUNT); + 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 @@ -1195,13 +1205,13 @@ BOOL LLViewerTextureList::createUploadFile(const std::string& filename, if (compressedImage.isNull()) { image->setLastError("Couldn't convert the image to jpeg2000."); - llinfos << "Couldn't convert to j2c, file : " << filename << llendl; + LL_INFOS() << "Couldn't convert to j2c, file : " << filename << LL_ENDL; return FALSE; } if (!compressedImage->save(out_filename)) { image->setLastError("Couldn't create the jpeg2000 image for upload."); - llinfos << "Couldn't create output file : " << out_filename << llendl; + LL_INFOS() << "Couldn't create output file : " << out_filename << LL_ENDL; return FALSE; } // Test to see if the encode and save worked @@ -1209,7 +1219,7 @@ BOOL LLViewerTextureList::createUploadFile(const std::string& filename, if (!integrity_test->loadAndValidate( out_filename )) { image->setLastError("The created jpeg2000 image is corrupt."); - llinfos << "Image file : " << out_filename << " is corrupt" << llendl; + LL_INFOS() << "Image file : " << out_filename << " is corrupt" << LL_ENDL; return FALSE; } return TRUE; @@ -1234,13 +1244,13 @@ LLPointer<LLImageJ2C> LLViewerTextureList::convertToUploadFile(LLPointer<LLImage // Read the blocks and precincts size settings S32 block_size = gSavedSettings.getS32("Jpeg2000BlocksSize"); S32 precinct_size = gSavedSettings.getS32("Jpeg2000PrecinctsSize"); - llinfos << "Advanced JPEG2000 Compression: precinct = " << precinct_size << ", block = " << block_size << llendl; + LL_INFOS() << "Advanced JPEG2000 Compression: precinct = " << precinct_size << ", block = " << block_size << LL_ENDL; compressedImage->initEncode(*raw_image, block_size, precinct_size, 0); } if (!compressedImage->encode(raw_image, 0.0f)) { - llinfos << "convertToUploadFile : encode returns with error!!" << llendl; + LL_INFOS() << "convertToUploadFile : encode returns with error!!" << LL_ENDL; // Clear up the pointer so we don't leak that one compressedImage = NULL; } @@ -1252,28 +1262,28 @@ const S32 MIN_VIDEO_RAM = 32; const S32 MAX_VIDEO_RAM = 512; // 512MB max for performance reasons. // Returns min setting for TextureMemory (in MB) -S32 LLViewerTextureList::getMinVideoRamSetting() +S32Megabytes LLViewerTextureList::getMinVideoRamSetting() { - S32 system_ram = (S32)BYTES_TO_MEGA_BYTES(gSysMemory.getPhysicalMemoryClamped()); + S32Megabytes system_ram = gSysMemory.getPhysicalMemoryClamped(); //min texture mem sets to 64M if total physical mem is more than 1.5GB - return (system_ram > 1500) ? 64 : MIN_VIDEO_RAM_IN_MEGA_BYTES ; + return (system_ram > S32Megabytes(1500)) ? S32Megabytes(64) : gMinVideoRam ; } //static // Returns max setting for TextureMemory (in MB) -S32 LLViewerTextureList::getMaxVideoRamSetting(bool get_recommended, float mem_multiplier) +S32Megabytes LLViewerTextureList::getMaxVideoRamSetting(bool get_recommended, float mem_multiplier) { - S32 max_texmem; + 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 - S32 max_vram = gGLManager.mVRAM; + S32Megabytes max_vram(gGLManager.mVRAM); if(gGLManager.mIsATI) { //shrink the availabe vram for ATI cards because some of them do not handel texture swapping well. - max_vram = (S32)(max_vram * 0.75f); + max_vram = max_vram * 0.75f; } max_vram = llmax(max_vram, getMinVideoRamSetting()); @@ -1285,48 +1295,48 @@ S32 LLViewerTextureList::getMaxVideoRamSetting(bool get_recommended, float mem_m { if (!get_recommended) { - max_texmem = 512; + max_texmem = (S32Megabytes)512; } else if (gSavedSettings.getBOOL("NoHardwareProbe")) //did not do hardware detection at startup { - max_texmem = 512; + max_texmem = (S32Megabytes)512; } else { - max_texmem = 128; + max_texmem = (S32Megabytes)128; } - llwarns << "VRAM amount not detected, defaulting to " << max_texmem << " MB" << llendl; + LL_WARNS() << "VRAM amount not detected, defaulting to " << max_texmem << " MB" << LL_ENDL; } - S32 system_ram = (S32)BYTES_TO_MEGA_BYTES(gSysMemory.getPhysicalMemoryClamped()); // In MB - //llinfos << "*** DETECTED " << system_ram << " MB of system memory." << llendl; + S32Megabytes system_ram = gSysMemory.getPhysicalMemoryClamped(); // In MB + //LL_INFOS() << "*** DETECTED " << system_ram << " MB of system memory." << LL_ENDL; if (get_recommended) - max_texmem = llmin(max_texmem, (S32)(system_ram/2)); + max_texmem = llmin(max_texmem, system_ram/2); else - max_texmem = llmin(max_texmem, (S32)(system_ram)); - + 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, (S32) (mem_multiplier * (F32) max_texmem)); + max_texmem = llmin(max_texmem, (S32Megabytes) (mem_multiplier * max_texmem)); - max_texmem = llclamp(max_texmem, getMinVideoRamSetting(), MAX_VIDEO_RAM_IN_MEGA_BYTES); + max_texmem = llclamp(max_texmem, getMinVideoRamSetting(), gMaxVideoRam); return max_texmem; } -const S32 VIDEO_CARD_FRAMEBUFFER_MEM = 12; // MB -const S32 MIN_MEM_FOR_NON_TEXTURE = 512 ; //MB -void LLViewerTextureList::updateMaxResidentTexMem(S32 mem) +const S32Megabytes VIDEO_CARD_FRAMEBUFFER_MEM(12); +const S32Megabytes MIN_MEM_FOR_NON_TEXTURE(512); +void LLViewerTextureList::updateMaxResidentTexMem(S32Megabytes mem) { // Initialize the image pipeline VRAM settings - S32 cur_mem = gSavedSettings.getS32("TextureMemory"); + S32Megabytes cur_mem(gSavedSettings.getS32("TextureMemory")); F32 mem_multiplier = gSavedSettings.getF32("RenderTextureMemoryMultiple"); - S32 default_mem = getMaxVideoRamSetting(true, mem_multiplier); // recommended default - if (mem == 0) + S32Megabytes default_mem = getMaxVideoRamSetting(true, mem_multiplier); // recommended default + if (mem == (S32Bytes)0) { - mem = cur_mem > 0 ? cur_mem : default_mem; + mem = cur_mem > (S32Bytes)0 ? cur_mem : default_mem; } - else if (mem < 0) + else if (mem < (S32Bytes)0) { mem = default_mem; } @@ -1334,38 +1344,38 @@ void LLViewerTextureList::updateMaxResidentTexMem(S32 mem) mem = llclamp(mem, getMinVideoRamSetting(), getMaxVideoRamSetting(false, mem_multiplier)); if (mem != cur_mem) { - gSavedSettings.setS32("TextureMemory", mem); + gSavedSettings.setS32("TextureMemory", mem.value()); return; //listener will re-enter this function } // TODO: set available resident texture mem based on use by other subsystems // currently max(12MB, VRAM/4) assumed... - S32 vb_mem = mem; - S32 fb_mem = llmax(VIDEO_CARD_FRAMEBUFFER_MEM, vb_mem/4); + 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 > 640) + if (mMaxResidentTexMemInMegaBytes > (S32Megabytes)640) { - mMaxTotalTextureMemInMegaBytes -= (mMaxResidentTexMemInMegaBytes >> 2); + mMaxTotalTextureMemInMegaBytes -= (mMaxResidentTexMemInMegaBytes / 4); } //system mem - S32 system_ram = (S32)BYTES_TO_MEGA_BYTES(gSysMemory.getPhysicalMemoryClamped()); // In MB + S32Megabytes system_ram = gSysMemory.getPhysicalMemoryClamped(); //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. - S32 min_non_texture_mem = llmin(system_ram / 2, MIN_MEM_FOR_NON_TEXTURE) ; + 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 ; } - llinfos << "Total Video Memory set to: " << vb_mem << " MB" << llendl; - llinfos << "Available Texture Memory set to: " << (vb_mem - fb_mem) << " MB" << llendl; + 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; } /////////////////////////////////////////////////////////////////////////////// @@ -1375,7 +1385,7 @@ void LLViewerTextureList::receiveImageHeader(LLMessageSystem *msg, void **user_d { static LLCachedControl<bool> log_texture_traffic(gSavedSettings,"LogTextureNetworkTraffic") ; - LLFastTimer t(FTM_PROCESS_IMAGES); + LL_RECORD_BLOCK_TIME(FTM_PROCESS_IMAGES); // Receive image header, copy into image object and decompresses // if this is a one-packet image. @@ -1385,17 +1395,17 @@ void LLViewerTextureList::receiveImageHeader(LLMessageSystem *msg, void **user_d char ip_string[256]; u32_to_ip_string(msg->getSenderIP(),ip_string); - U32 received_size ; + U32Bytes received_size ; if (msg->getReceiveCompressedSize()) { - received_size = msg->getReceiveCompressedSize() ; + received_size = (U32Bytes)msg->getReceiveCompressedSize() ; } else { - received_size = msg->getReceiveSize() ; + received_size = (U32Bytes)msg->getReceiveSize() ; } - gTextureList.sTextureBits += received_size * 8; - gTextureList.sTexturePackets++; + add(LLStatViewer::TEXTURE_NETWORK_DATA_RECEIVED, received_size); + add(LLStatViewer::TEXTURE_PACKETS, 1); U8 codec; U16 packets; @@ -1414,8 +1424,8 @@ void LLViewerTextureList::receiveImageHeader(LLMessageSystem *msg, void **user_d { // msg->getSizeFast() is probably trying to tell us there // was an error. - llerrs << "image header chunk size was negative: " - << data_size << llendl; + LL_ERRS() << "image header chunk size was negative: " + << data_size << LL_ENDL; return; } @@ -1447,7 +1457,7 @@ void LLViewerTextureList::receiveImagePacket(LLMessageSystem *msg, void **user_d { static LLCachedControl<bool> log_texture_traffic(gSavedSettings,"LogTextureNetworkTraffic") ; - LLFastTimer t(FTM_PROCESS_IMAGES); + LL_RECORD_BLOCK_TIME(FTM_PROCESS_IMAGES); // Receives image packet, copy into image object, // checks if all packets received, decompresses if so. @@ -1458,17 +1468,18 @@ void LLViewerTextureList::receiveImagePacket(LLMessageSystem *msg, void **user_d char ip_string[256]; u32_to_ip_string(msg->getSenderIP(),ip_string); - U32 received_size ; + U32Bytes received_size ; if (msg->getReceiveCompressedSize()) { - received_size = msg->getReceiveCompressedSize() ; + received_size = (U32Bytes)msg->getReceiveCompressedSize() ; } else { - received_size = msg->getReceiveSize() ; + received_size = (U32Bytes)msg->getReceiveSize() ; } - gTextureList.sTextureBits += received_size * 8; - gTextureList.sTexturePackets++; + + 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); @@ -1483,13 +1494,13 @@ void LLViewerTextureList::receiveImagePacket(LLMessageSystem *msg, void **user_d { // msg->getSizeFast() is probably trying to tell us there // was an error. - llerrs << "image data chunk size was negative: " - << data_size << llendl; + LL_ERRS() << "image data chunk size was negative: " + << data_size << LL_ENDL; return; } if (data_size > MTUBYTES) { - llerrs << "image data chunk too large: " << data_size << " bytes" << llendl; + LL_ERRS() << "image data chunk too large: " << data_size << " bytes" << LL_ENDL; return; } U8 *data = new U8[data_size]; @@ -1519,35 +1530,18 @@ void LLViewerTextureList::receiveImagePacket(LLMessageSystem *msg, void **user_d // static void LLViewerTextureList::processImageNotInDatabase(LLMessageSystem *msg,void **user_data) { - LLFastTimer t(FTM_PROCESS_IMAGES); + LL_RECORD_BLOCK_TIME(FTM_PROCESS_IMAGES); LLUUID image_id; msg->getUUIDFast(_PREHASH_ImageID, _PREHASH_ID, image_id); LLViewerFetchedTexture* image = gTextureList.findImage( image_id ); if( image ) { - llwarns << "not in db" << llendl; + LL_WARNS() << "not in db" << LL_ENDL; image->setIsMissingAsset(); } } -/////////////////////////////////////////////////////////////////////////////// - -//static -const U32 SIXTEEN_MEG = 0x1000000; -S32 LLViewerTextureList::calcMaxTextureRAM() -{ - // Decide the maximum amount of RAM we should allow the user to allocate to texture cache - LLMemoryInfo memory_info; - U32 available_memory = memory_info.getPhysicalMemoryClamped(); - - clamp_rescale((F32)available_memory, - (F32)(SIXTEEN_MEG * 16), - (F32)U32_MAX, - (F32)(SIXTEEN_MEG * 4), - (F32)(U32_MAX >> 1)); - return available_memory; -} /////////////////////////////////////////////////////////////////////////////// @@ -1594,28 +1588,31 @@ LLUIImagePtr LLUIImageList::getUIImage(const std::string& image_name, S32 priori } LLUIImagePtr LLUIImageList::loadUIImageByName(const std::string& name, const std::string& filename, - BOOL use_mips, const LLRect& scale_rect, const LLRect& clip_rect, LLViewerTexture::EBoostLevel boost_priority ) + BOOL use_mips, const LLRect& scale_rect, const LLRect& clip_rect, LLViewerTexture::EBoostLevel boost_priority, + LLUIImage::EScaleStyle scale_style) { if (boost_priority == LLGLTexture::BOOST_NONE) { boost_priority = LLGLTexture::BOOST_UI; } LLViewerFetchedTexture* imagep = LLViewerTextureManager::getFetchedTextureFromFile(filename, FTT_LOCAL_FILE, MIPMAP_NO, boost_priority); - return loadUIImage(imagep, name, use_mips, scale_rect, clip_rect); + return loadUIImage(imagep, name, use_mips, scale_rect, clip_rect, scale_style); } LLUIImagePtr LLUIImageList::loadUIImageByID(const LLUUID& id, - BOOL use_mips, const LLRect& scale_rect, const LLRect& clip_rect, LLViewerTexture::EBoostLevel boost_priority) + BOOL use_mips, const LLRect& scale_rect, const LLRect& clip_rect, LLViewerTexture::EBoostLevel boost_priority, + LLUIImage::EScaleStyle scale_style) { if (boost_priority == LLGLTexture::BOOST_NONE) { boost_priority = LLGLTexture::BOOST_UI; } LLViewerFetchedTexture* imagep = LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, MIPMAP_NO, boost_priority); - return loadUIImage(imagep, id.asString(), use_mips, scale_rect, clip_rect); + return loadUIImage(imagep, id.asString(), use_mips, scale_rect, clip_rect, scale_style); } -LLUIImagePtr LLUIImageList::loadUIImage(LLViewerFetchedTexture* imagep, const std::string& name, BOOL use_mips, const LLRect& scale_rect, const LLRect& clip_rect) +LLUIImagePtr LLUIImageList::loadUIImage(LLViewerFetchedTexture* imagep, const std::string& name, BOOL use_mips, const LLRect& scale_rect, const LLRect& clip_rect, + LLUIImage::EScaleStyle scale_style) { if (!imagep) return NULL; @@ -1628,6 +1625,8 @@ LLUIImagePtr LLUIImageList::loadUIImage(LLViewerFetchedTexture* imagep, const st imagep->setNoDelete(); LLUIImagePtr new_imagep = new LLUIImage(name, imagep); + new_imagep->setScaleStyle(scale_style); + mUIImages.insert(std::make_pair(name, new_imagep)); mUITextureList.push_back(imagep); @@ -1646,17 +1645,17 @@ LLUIImagePtr LLUIImageList::loadUIImage(LLViewerFetchedTexture* imagep, const st return new_imagep; } -LLUIImagePtr LLUIImageList::preloadUIImage(const std::string& name, const std::string& filename, BOOL use_mips, const LLRect& scale_rect, const LLRect& clip_rect) +LLUIImagePtr LLUIImageList::preloadUIImage(const std::string& name, const std::string& filename, BOOL use_mips, const LLRect& scale_rect, const LLRect& clip_rect, LLUIImage::EScaleStyle scale_style) { // look for existing image uuid_ui_image_map_t::iterator found_it = mUIImages.find(name); if (found_it != mUIImages.end()) { // image already loaded! - llerrs << "UI Image " << name << " already loaded." << llendl; + LL_ERRS() << "UI Image " << name << " already loaded." << LL_ENDL; } - return loadUIImageByName(name, filename, use_mips, scale_rect, clip_rect); + return loadUIImageByName(name, filename, use_mips, scale_rect, clip_rect, LLGLTexture::BOOST_UI, scale_style); } //static @@ -1716,14 +1715,28 @@ void LLUIImageList::onUIImageLoaded( BOOL success, LLViewerFetchedTexture *src_v } } +namespace LLInitParam +{ + template<> + struct TypeValues<LLUIImage::EScaleStyle> : public TypeValuesHelper<LLUIImage::EScaleStyle> + { + static void declareValues() + { + declare("scale_inner", LLUIImage::SCALE_INNER); + declare("scale_outer", LLUIImage::SCALE_OUTER); + } + }; +} + struct UIImageDeclaration : public LLInitParam::Block<UIImageDeclaration> { - Mandatory<std::string> name; - Optional<std::string> file_name; - Optional<bool> preload; - Optional<LLRect> scale; - Optional<LLRect> clip; - Optional<bool> use_mips; + Mandatory<std::string> name; + Optional<std::string> file_name; + Optional<bool> preload; + Optional<LLRect> scale; + Optional<LLRect> clip; + Optional<bool> use_mips; + Optional<LLUIImage::EScaleStyle> scale_type; UIImageDeclaration() : name("name"), @@ -1731,7 +1744,8 @@ struct UIImageDeclaration : public LLInitParam::Block<UIImageDeclaration> preload("preload", false), scale("scale"), clip("clip"), - use_mips("use_mips", false) + use_mips("use_mips", false), + scale_type("scale_type", LLUIImage::SCALE_INNER) {} }; @@ -1756,7 +1770,7 @@ bool LLUIImageList::initFromFile() std::vector<std::string>::const_iterator pi(textures_paths.begin()), pend(textures_paths.end()); if (pi == pend) { - llwarns << "No textures.xml found in skins directories" << llendl; + LL_WARNS() << "No textures.xml found in skins directories" << LL_ENDL; return false; } @@ -1764,12 +1778,12 @@ bool LLUIImageList::initFromFile() LLXMLNodePtr root; if (!LLXMLNode::parseFile(*pi, root, NULL)) { - llwarns << "Unable to parse UI image list file " << *pi << llendl; + LL_WARNS() << "Unable to parse UI image list file " << *pi << LL_ENDL; return false; } if (!root->hasAttribute("version")) { - llwarns << "No valid version number in UI image list file " << *pi << llendl; + LL_WARNS() << "No valid version number in UI image list file " << *pi << LL_ENDL; return false; } @@ -1819,7 +1833,7 @@ bool LLUIImageList::initFromFile() { continue; } - preloadUIImage(image.name, file_name, image.use_mips, image.scale, image.clip); + preloadUIImage(image.name, file_name, image.use_mips, image.scale, image.clip, image.scale_type); } if (cur_pass == PASS_DECODE_NOW && !gSavedSettings.getBOOL("NoPreload")) |