Skip to content
Snippets Groups Projects
Commit b6b4938f authored by Rye Mutt's avatar Rye Mutt :bread:
Browse files

Optimize texture list with hash maps

parent b02b43c0
No related branches found
No related tags found
No related merge requests found
...@@ -116,6 +116,7 @@ void LLViewerTextureList::doPreloadImages() ...@@ -116,6 +116,7 @@ void LLViewerTextureList::doPreloadImages()
llassert_always(mInitialized) ; llassert_always(mInitialized) ;
llassert_always(mImageList.empty()) ; llassert_always(mImageList.empty()) ;
llassert_always(mUUIDMap.empty()) ; llassert_always(mUUIDMap.empty()) ;
llassert_always(mUUIDHashMap.empty());
// Set the "missing asset" image // Set the "missing asset" image
LLViewerFetchedTexture::sMissingAssetImagep = LLViewerTextureManager::getFetchedTextureFromFile("missing_asset.tga", FTT_LOCAL_FILE, MIPMAP_NO, LLViewerFetchedTexture::BOOST_UI); LLViewerFetchedTexture::sMissingAssetImagep = LLViewerTextureManager::getFetchedTextureFromFile("missing_asset.tga", FTT_LOCAL_FILE, MIPMAP_NO, LLViewerFetchedTexture::BOOST_UI);
...@@ -229,8 +230,8 @@ void LLViewerTextureList::doPrefetchImages() ...@@ -229,8 +230,8 @@ void LLViewerTextureList::doPrefetchImages()
file.close(); file.close();
} }
S32 texture_count = 0; S32 texture_count = 0;
for (LLSD::array_iterator iter = imagelist.beginArray(); for (LLSD::array_const_iterator iter = imagelist.beginArray(), end = imagelist.endArray();
iter != imagelist.endArray(); ++iter) iter != end; ++iter)
{ {
LLSD imagesd = *iter; LLSD imagesd = *iter;
LLUUID uuid = imagesd["uuid"]; LLUUID uuid = imagesd["uuid"];
...@@ -266,10 +267,8 @@ void LLViewerTextureList::shutdown() ...@@ -266,10 +267,8 @@ void LLViewerTextureList::shutdown()
// Write out list of currently loaded textures for precaching on startup // Write out list of currently loaded textures for precaching on startup
typedef std::set<std::pair<S32,LLViewerFetchedTexture*> > image_area_list_t; typedef std::set<std::pair<S32,LLViewerFetchedTexture*> > image_area_list_t;
image_area_list_t image_area_list; image_area_list_t image_area_list;
for (image_priority_list_t::iterator iter = mImageList.begin(); for (LLViewerFetchedTexture* image : mImageList)
iter != mImageList.end(); ++iter)
{ {
LLViewerFetchedTexture* image = *iter;
if (!image->hasGLTexture() || if (!image->hasGLTexture() ||
!image->getUseDiscard() || !image->getUseDiscard() ||
image->needsAux() || image->needsAux() ||
...@@ -287,7 +286,7 @@ void LLViewerTextureList::shutdown() ...@@ -287,7 +286,7 @@ void LLViewerTextureList::shutdown()
if (desired >= 0 && desired < MAX_DISCARD_LEVEL) if (desired >= 0 && desired < MAX_DISCARD_LEVEL)
{ {
S32 pixel_area = image->getWidth(desired) * image->getHeight(desired); S32 pixel_area = image->getWidth(desired) * image->getHeight(desired);
image_area_list.insert(std::make_pair(pixel_area, image)); image_area_list.emplace(pixel_area, image);
} }
} }
...@@ -327,7 +326,8 @@ void LLViewerTextureList::shutdown() ...@@ -327,7 +326,8 @@ void LLViewerTextureList::shutdown()
mLoadingStreamList.clear(); mLoadingStreamList.clear();
mCreateTextureList.clear(); mCreateTextureList.clear();
mFastCacheList.clear(); mFastCacheList.clear();
mUUIDHashMap.clear();
mUUIDMap.clear(); mUUIDMap.clear();
mImageList.clear(); mImageList.clear();
...@@ -338,15 +338,14 @@ void LLViewerTextureList::shutdown() ...@@ -338,15 +338,14 @@ void LLViewerTextureList::shutdown()
void LLViewerTextureList::dump() void LLViewerTextureList::dump()
{ {
LL_INFOS() << "LLViewerTextureList::dump()" << LL_ENDL; LL_INFOS() << "LLViewerTextureList::dump()" << LL_ENDL;
for (image_priority_list_t::iterator it = mImageList.begin(); it != mImageList.end(); ++it) for (LLViewerFetchedTexture* image : mImageList)
{ {
LLViewerFetchedTexture* image = *it;
LL_INFOS() << "priority " << image->getDecodePriority() LL_INFOS() << "priority " << image->getDecodePriority()
<< " boost " << image->getBoostLevel() << " boost " << image->getBoostLevel()
<< " size " << image->getWidth() << "x" << image->getHeight() << " size " << image->getWidth() << "x" << image->getHeight()
<< " discard " << image->getDiscardLevel() << " discard " << image->getDiscardLevel()
<< " desired " << image->getDesiredDiscardLevel() << " desired " << image->getDesiredDiscardLevel()
<< " references " << image->getNumRefs()
<< " http://asset.siva.lindenlab.com/" << image->getID() << ".texture" << " http://asset.siva.lindenlab.com/" << image->getID() << ".texture"
<< LL_ENDL; << LL_ENDL;
} }
...@@ -625,8 +624,8 @@ void LLViewerTextureList::findTexturesByID(const LLUUID &image_id, std::vector<L ...@@ -625,8 +624,8 @@ void LLViewerTextureList::findTexturesByID(const LLUUID &image_id, std::vector<L
LLViewerFetchedTexture *LLViewerTextureList::findImage(const LLTextureKey &search_key) LLViewerFetchedTexture *LLViewerTextureList::findImage(const LLTextureKey &search_key)
{ {
uuid_map_t::iterator iter = mUUIDMap.find(search_key); auto iter = mUUIDHashMap.find(search_key);
if (iter == mUUIDMap.end()) if (iter == mUUIDHashMap.cend())
return NULL; return NULL;
return iter->second; return iter->second;
} }
...@@ -678,8 +677,8 @@ void LLViewerTextureList::removeImageFromList(LLViewerFetchedTexture *image) ...@@ -678,8 +677,8 @@ void LLViewerTextureList::removeImageFromList(LLViewerFetchedTexture *image)
<< " but doesn't have mInImageList set" << " but doesn't have mInImageList set"
<< " ref count is " << image->getNumRefs() << " ref count is " << image->getNumRefs()
<< LL_ENDL; << LL_ENDL;
uuid_map_t::iterator iter = mUUIDMap.find(LLTextureKey(image->getID(), (ETexListType)image->getTextureListType())); auto iter = mUUIDHashMap.find(LLTextureKey(image->getID(), (ETexListType)image->getTextureListType()));
if(iter == mUUIDMap.end()) if(iter == mUUIDHashMap.cend())
{ {
LL_INFOS() << "Image " << image->getID() << " is also not in mUUIDMap!" << LL_ENDL ; LL_INFOS() << "Image " << image->getID() << " is also not in mUUIDMap!" << LL_ENDL ;
} }
...@@ -721,7 +720,8 @@ void LLViewerTextureList::addImage(LLViewerFetchedTexture *new_image, ETexListTy ...@@ -721,7 +720,8 @@ void LLViewerTextureList::addImage(LLViewerFetchedTexture *new_image, ETexListTy
sNumImages++; sNumImages++;
addImageToList(new_image); addImageToList(new_image);
mUUIDMap[key] = new_image; mUUIDMap.insert_or_assign(key, new_image);
mUUIDHashMap.insert_or_assign(key, new_image);
new_image->setTextureListType(tex_type); new_image->setTextureListType(tex_type);
} }
...@@ -736,6 +736,7 @@ void LLViewerTextureList::deleteImage(LLViewerFetchedTexture *image) ...@@ -736,6 +736,7 @@ void LLViewerTextureList::deleteImage(LLViewerFetchedTexture *image)
} }
LLTextureKey key(image->getID(), (ETexListType)image->getTextureListType()); LLTextureKey key(image->getID(), (ETexListType)image->getTextureListType());
llverify(mUUIDMap.erase(key) == 1); llverify(mUUIDMap.erase(key) == 1);
llverify(mUUIDHashMap.erase(key) == 1);
sNumImages--; sNumImages--;
removeImageFromList(image); removeImageFromList(image);
} }
...@@ -856,10 +857,8 @@ void LLViewerTextureList::clearFetchingRequests() ...@@ -856,10 +857,8 @@ void LLViewerTextureList::clearFetchingRequests()
LLAppViewer::getTextureFetch()->deleteAllRequests(); LLAppViewer::getTextureFetch()->deleteAllRequests();
for (image_priority_list_t::iterator iter = mImageList.begin(); for (LLViewerFetchedTexture* imagep : mImageList)
iter != mImageList.end(); ++iter) {
{
LLViewerFetchedTexture* imagep = *iter;
imagep->forceToDeleteRequest() ; imagep->forceToDeleteRequest() ;
} }
} }
...@@ -1205,16 +1204,14 @@ void LLViewerTextureList::decodeAllImages(F32 max_time) ...@@ -1205,16 +1204,14 @@ void LLViewerTextureList::decodeAllImages(F32 max_time)
iter != mImageList.end(); ) iter != mImageList.end(); )
{ {
LLViewerFetchedTexture* imagep = *iter++; LLViewerFetchedTexture* imagep = *iter++;
image_list.push_back(imagep); image_list.emplace_back(imagep);
imagep->setInImageList(FALSE) ; imagep->setInImageList(FALSE) ;
} }
llassert_always(image_list.size() == mImageList.size()) ; llassert_always(image_list.size() == mImageList.size()) ;
mImageList.clear(); mImageList.clear();
for (std::vector<LLPointer<LLViewerFetchedTexture> >::iterator iter = image_list.begin(); for (LLViewerFetchedTexture* imagep : image_list)
iter != image_list.end(); ++iter)
{ {
LLViewerFetchedTexture* imagep = *iter;
imagep->processTextureStats(); imagep->processTextureStats();
F32 decode_priority = imagep->calcDecodePriority(); F32 decode_priority = imagep->calcDecodePriority();
imagep->setDecodePriority(decode_priority); imagep->setDecodePriority(decode_priority);
......
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
#include <set> #include <set>
#include "lluiimage.h" #include "lluiimage.h"
#include "absl/container/flat_hash_map.h"
const U32 LL_IMAGE_REZ_LOSSLESS_CUTOFF = 128; const U32 LL_IMAGE_REZ_LOSSLESS_CUTOFF = 128;
const BOOL MIPMAP_YES = TRUE; const BOOL MIPMAP_YES = TRUE;
...@@ -83,6 +85,17 @@ struct LLTextureKey ...@@ -83,6 +85,17 @@ struct LLTextureKey
return key1.textureType < key2.textureType; return key1.textureType < key2.textureType;
} }
} }
friend bool operator==(const LLTextureKey& lhs, const LLTextureKey& rhs)
{
return lhs.textureId == rhs.textureId && lhs.textureType == rhs.textureType;
}
template <typename H>
friend H AbslHashValue(H h, const LLTextureKey& id)
{
return H::combine(std::move(h), id.textureId, id.textureType);
}
}; };
class LLViewerTextureList class LLViewerTextureList
...@@ -194,7 +207,7 @@ class LLViewerTextureList ...@@ -194,7 +207,7 @@ class LLViewerTextureList
// Request image from a specific host, used for baked avatar textures. // Request image from a specific host, used for baked avatar textures.
// Implemented in header in case someone changes default params above. JC // Implemented in header in case someone changes default params above. JC
LLViewerFetchedTexture* getImageFromHost(const LLUUID& image_id, FTType f_type, LLHost host) LLViewerFetchedTexture* getImageFromHost(const LLUUID& image_id, FTType f_type, const LLHost& host)
{ return getImage(image_id, f_type, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE, 0, 0, host); } { return getImage(image_id, f_type, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE, 0, 0, host); }
public: public:
...@@ -210,8 +223,10 @@ class LLViewerTextureList ...@@ -210,8 +223,10 @@ class LLViewerTextureList
BOOL mForceResetTextureStats; BOOL mForceResetTextureStats;
private: private:
typedef std::map< LLTextureKey, LLPointer<LLViewerFetchedTexture> > uuid_map_t; using uuid_map_t = std::map< LLTextureKey, LLPointer<LLViewerFetchedTexture> >;
using uuid_hash_map_t = absl::flat_hash_map< LLTextureKey, LLViewerFetchedTexture* >;
uuid_map_t mUUIDMap; uuid_map_t mUUIDMap;
uuid_hash_map_t mUUIDHashMap;
LLTextureKey mLastUpdateKey; LLTextureKey mLastUpdateKey;
LLTextureKey mLastFetchKey; LLTextureKey mLastFetchKey;
...@@ -268,7 +283,7 @@ class LLUIImageList final : public LLImageProviderInterface, public LLSingleton< ...@@ -268,7 +283,7 @@ class LLUIImageList final : public LLImageProviderInterface, public LLSingleton<
LLRect mImageClipRegion; LLRect mImageClipRegion;
}; };
typedef std::map< std::string, LLPointer<LLUIImage> > uuid_ui_image_map_t; typedef absl::flat_hash_map< std::string, LLPointer<LLUIImage> > uuid_ui_image_map_t;
uuid_ui_image_map_t mUIImages; uuid_ui_image_map_t mUIImages;
// //
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment