diff options
author | Brad Kittenbrink <brad@lindenlab.com> | 2022-11-11 10:00:37 -0800 |
---|---|---|
committer | Brad Kittenbrink <brad@lindenlab.com> | 2022-11-14 11:26:34 -0800 |
commit | 1971839517519657fc895c9cb12c47317dde6b39 (patch) | |
tree | e80246534ac9ca4a083b06ddd4d8948fb99a5aaa | |
parent | 97277e74a9d966ed441e51f844f9012f55cca3dc (diff) |
Basic solution for SL-18458 vocache implementation for material overrides
-rw-r--r-- | indra/newview/llgltfmateriallist.cpp | 48 | ||||
-rw-r--r-- | indra/newview/llgltfmateriallist.h | 5 | ||||
-rwxr-xr-x | indra/newview/llviewerregion.cpp | 48 | ||||
-rw-r--r-- | indra/newview/llviewerregion.h | 6 | ||||
-rw-r--r-- | indra/newview/llvocache.cpp | 13 | ||||
-rw-r--r-- | indra/newview/llvocache.h | 15 |
6 files changed, 123 insertions, 12 deletions
diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 19cef5dffd..07c6d9ff93 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -27,6 +27,7 @@ #include "llgltfmateriallist.h" +#include "llagent.h" #include "llassetstorage.h" #include "lldispatcher.h" #include "llfetchedgltfmaterial.h" @@ -37,9 +38,11 @@ #include "llviewercontrol.h" #include "llviewergenericmessage.h" #include "llviewerobjectlist.h" +#include "llviewerregion.h" #include "llviewerstats.h" #include "llcorehttputil.h" #include "llagent.h" +#include "llworld.h" #include "tinygltf/tiny_gltf.h" #include <strstream> @@ -163,8 +166,14 @@ public: { LL_WARNS() << "LLGLTFMaterialOverrideDispatchHandler: Attempted to read parameter data into LLSD but failed:" << llsdRaw << LL_ENDL; } + LLGLTFMaterialList::writeCacheOverrides(message, llsdRaw); } - + else + { + // malformed message, nothing we can do to handle it + return false; + } + LL::WorkQueue::ptr_t main_queue = LL::WorkQueue::getInstance("mainloop"); LL::WorkQueue::ptr_t general_queue = LL::WorkQueue::getInstance("General"); @@ -676,3 +685,40 @@ void LLGLTFMaterialList::modifyMaterialCoro(std::string cap_url, LLSD overrides, done_callback(success); } } + +void LLGLTFMaterialList::writeCacheOverrides(LLSD const & message, std::string const & llsdRaw) +{ + LL_DEBUGS() << "material overrides cache" << LL_ENDL; + + // default to main region if message doesn't specify + LLViewerRegion * region = gAgent.getRegion();; + + if (message.has("region_handle")) + { + // TODO start requiring this once server sends this for all messages + std::vector<U8> const & buffer = message["region_handle"].asBinary(); + if (buffer.size() == sizeof(U64)) + { + U64 region_handle = ntohll(*reinterpret_cast<U64 const *>(&buffer[0])); + region = LLWorld::instance().getRegionFromHandle(region_handle); + } + else + { + LL_WARNS() << "bad region_handle in material override message" << LL_ENDL; + llassert(false); + } + } + + if (region) { + region->cacheFullUpdateExtras(message, llsdRaw); + } else { + LL_WARNS() << "could not access region for material overrides message cache, region_handle: " << LL_ENDL; + } +} + +void LLGLTFMaterialList::loadCacheOverrides(std::string const & message) +{ + std::vector<std::string> strings(1, message); + + handle_gltf_override_message(nullptr, "", LLUUID::null, strings); +} diff --git a/indra/newview/llgltfmateriallist.h b/indra/newview/llgltfmateriallist.h index c4eabc8ef7..805b477248 100644 --- a/indra/newview/llgltfmateriallist.h +++ b/indra/newview/llgltfmateriallist.h @@ -89,6 +89,11 @@ public: // any override data that arrived before the object was ready to receive it void applyQueuedOverrides(LLViewerObject* obj); + // takes both the parsed message and its raw text to avoid unnecessary re serialization + static void writeCacheOverrides(LLSD const & message, std::string const & llsdRaw); + + static void loadCacheOverrides(std::string const & message_raw); + private: friend class LLGLTFMaterialOverrideDispatchHandler; // save an override update that we got from the simulator for later (for example, if an override arrived for an unknown object) diff --git a/indra/newview/llviewerregion.cpp b/indra/newview/llviewerregion.cpp index 36d8fffa7c..0e7fd63c7f 100755 --- a/indra/newview/llviewerregion.cpp +++ b/indra/newview/llviewerregion.cpp @@ -53,6 +53,7 @@ #include "llfloatergodtools.h" #include "llfloaterreporter.h" #include "llfloaterregioninfo.h" +#include "llgltfmateriallist.h" #include "llhttpnode.h" #include "llregioninfomodel.h" #include "llsdutil.h" @@ -214,6 +215,7 @@ public: LLVOCacheEntry::vocache_entry_set_t mVisibleEntries; //must-be-created visible entries wait for objects creation. LLVOCacheEntry::vocache_entry_priority_list_t mWaitingList; //transient list storing sorted visible entries waiting for object creation. std::set<U32> mNonCacheableCreatedList; //list of local ids of all non-cacheable objects + LLVOCacheEntry::vocache_extras_entry_map_t mCacheExtraJson; // for materials // time? // LRU info? @@ -782,7 +784,10 @@ void LLViewerRegion::loadObjectCache() if(LLVOCache::instanceExists()) { - LLVOCache::getInstance()->readFromCache(mHandle, mImpl->mCacheID, mImpl->mCacheMap) ; + LLVOCache & vocache = LLVOCache::instance(); + vocache.readFromCache(mHandle, mImpl->mCacheID, mImpl->mCacheMap) ; + vocache.readGenericExtrasFromCache(mHandle, mImpl->mCacheID, mImpl->mCacheExtraJson); + if (mImpl->mCacheMap.empty()) { mCacheDirty = TRUE; @@ -807,8 +812,10 @@ void LLViewerRegion::saveObjectCache() { const F32 start_time_threshold = 600.0f; //seconds bool removal_enabled = sVOCacheCullingEnabled && (mRegionTimer.getElapsedTimeF32() > start_time_threshold); //allow to remove invalid objects from object cache file. - - LLVOCache::getInstance()->writeToCache(mHandle, mImpl->mCacheID, mImpl->mCacheMap, mCacheDirty, removal_enabled) ; + + LLVOCache & instance = LLVOCache::instance(); + instance.writeToCache(mHandle, mImpl->mCacheID, mImpl->mCacheMap, mCacheDirty, removal_enabled) ; + instance.writeGenericExtrasToCache(mHandle, mImpl->mCacheID, mImpl->mCacheExtraJson, mCacheDirty, removal_enabled); mCacheDirty = FALSE; } @@ -1823,7 +1830,7 @@ LLViewerObject* LLViewerRegion::addNewObject(LLVOCacheEntry* entry) LLViewerObject* obj = NULL; if(!entry->getEntry()->hasDrawable()) //not added to the rendering pipeline yet - { + { //add the object obj = gObjectList.processObjectUpdateFromCache(entry, this); if(obj) @@ -2598,7 +2605,7 @@ LLViewerRegion::eCacheUpdateResult LLViewerRegion::cacheFullUpdate(LLDataPackerB LL_DEBUGS("AnimatedObjects") << " got update for local_id " << local_id << LL_ENDL; dumpStack("AnimatedObjectsStack"); - // Update the cache entry + // Update the cache entry entry->updateEntry(crc, dp); decodeBoundingInfo(entry); @@ -2615,7 +2622,7 @@ LLViewerRegion::eCacheUpdateResult LLViewerRegion::cacheFullUpdate(LLDataPackerB // Create new entry and add to map result = CACHE_UPDATE_ADDED; entry = new LLVOCacheEntry(local_id, crc, dp); - record(LLStatViewer::OBJECT_CACHE_HIT_RATE, LLUnits::Ratio::fromValue(0)); + record(LLStatViewer::OBJECT_CACHE_HIT_RATE, LLUnits::Ratio::fromValue(0)); mImpl->mCacheMap[local_id] = entry; @@ -2633,6 +2640,22 @@ LLViewerRegion::eCacheUpdateResult LLViewerRegion::cacheFullUpdate(LLViewerObjec return result; } +void LLViewerRegion::cacheFullUpdateExtras(LLSD const & extras, std::string const & extras_raw) +{ + LLUUID object_id = extras["object_id"].asUUID(); + LLViewerObject * obj = gObjectList.findObject(object_id); + if (obj != nullptr) + { + U32 local_id = obj->getLocalID(); + + mImpl->mCacheExtraJson[local_id] = LLVOCacheEntry::ExtrasEntry{extras, extras_raw}; + } + else + { + LL_WARNS() << "got material override for unknown object_id, cannot cache it" << LL_ENDL; + } +} + LLVOCacheEntry* LLViewerRegion::getCacheEntryForOctree(U32 local_id) { if(!sVOCacheCullingEnabled) @@ -2657,7 +2680,7 @@ LLVOCacheEntry* LLViewerRegion::getCacheEntry(U32 local_id, bool valid) } } return NULL; - } +} void LLViewerRegion::addCacheMiss(U32 id, LLViewerRegion::eCacheMissType miss_type) { @@ -2731,6 +2754,9 @@ bool LLViewerRegion::probeCache(U32 local_id, U32 crc, U32 flags, U8 &cache_miss entry->setValid(); decodeBoundingInfo(entry); + + loadCacheMiscExtras(local_id, entry, crc); + return true; } else @@ -3514,3 +3540,11 @@ std::string LLViewerRegion::getSimHostName() return std::string("..."); } +void LLViewerRegion::loadCacheMiscExtras(U32 local_id, LLVOCacheEntry * entry, U32 crc) +{ + auto iter = mImpl->mCacheExtraJson.find(local_id); + if (iter != mImpl->mCacheExtraJson.end()) + { + LLGLTFMaterialList::loadCacheOverrides(iter->second.extras_raw); + } +} diff --git a/indra/newview/llviewerregion.h b/indra/newview/llviewerregion.h index 8b27004f1d..85f5b48b48 100644 --- a/indra/newview/llviewerregion.h +++ b/indra/newview/llviewerregion.h @@ -348,7 +348,9 @@ public: // handle a full update message eCacheUpdateResult cacheFullUpdate(LLDataPackerBinaryBuffer &dp, U32 flags); - eCacheUpdateResult cacheFullUpdate(LLViewerObject* objectp, LLDataPackerBinaryBuffer &dp, U32 flags); + eCacheUpdateResult cacheFullUpdate(LLViewerObject* objectp, LLDataPackerBinaryBuffer &dp, U32 flags); + void cacheFullUpdateExtras(LLSD const & extras, std::string const & extras_raw); + LLVOCacheEntry* getCacheEntryForOctree(U32 local_id); LLVOCacheEntry* getCacheEntry(U32 local_id, bool valid = true); bool probeCache(U32 local_id, U32 crc, U32 flags, U8 &cache_miss_type); @@ -419,6 +421,8 @@ private: void decodeBoundingInfo(LLVOCacheEntry* entry); bool isNonCacheableObjectCreated(U32 local_id); + void loadCacheMiscExtras(U32 local_id, LLVOCacheEntry * entry, U32 crc); + public: struct CompareDistance { diff --git a/indra/newview/llvocache.cpp b/indra/newview/llvocache.cpp index 55fc663496..2b93460d25 100644 --- a/indra/newview/llvocache.cpp +++ b/indra/newview/llvocache.cpp @@ -170,7 +170,7 @@ LLVOCacheEntry::~LLVOCacheEntry() } void LLVOCacheEntry::updateEntry(U32 crc, LLDataPackerBinaryBuffer &dp) -{ +{ if(mCRC != crc) { mCRC = crc; @@ -1435,7 +1435,12 @@ void LLVOCache::readFromCache(U64 handle, const LLUUID& id, LLVOCacheEntry::voca return ; } - + +void LLVOCache::readGenericExtrasFromCache(U64 handle, const LLUUID& id, LLVOCacheEntry::vocache_extras_entry_map_t& cache_extras_entry_map) +{ + LL_DEBUGS() << "TODO" << LL_ENDL; +} + void LLVOCache::purgeEntries(U32 size) { while(mHeaderEntryQueue.size() > size) @@ -1572,3 +1577,7 @@ void LLVOCache::writeToCache(U64 handle, const LLUUID& id, const LLVOCacheEntry: return ; } + +void LLVOCache::writeGenericExtrasToCache(U64 handle, const LLUUID& id, const LLVOCacheEntry::vocache_extras_entry_map_t& cache_extras_entry_map, BOOL dirty_cache, bool removal_enabled) +{ +} diff --git a/indra/newview/llvocache.h b/indra/newview/llvocache.h index 55a13d934d..33c1dfef8d 100644 --- a/indra/newview/llvocache.h +++ b/indra/newview/llvocache.h @@ -33,6 +33,8 @@ #include "llvieweroctree.h" #include "llapr.h" +#include <unordered_map> + //--------------------------------------------------------------------------- // Cache entries class LLCamera; @@ -79,6 +81,13 @@ public: } } }; + + struct ExtrasEntry + { + LLSD extras; + std::string extras_raw; + }; + protected: ~LLVOCacheEntry(); public: @@ -142,7 +151,8 @@ private: public: typedef std::map<U32, LLPointer<LLVOCacheEntry> > vocache_entry_map_t; typedef std::set<LLVOCacheEntry*> vocache_entry_set_t; - typedef std::set<LLVOCacheEntry*, CompareVOCacheEntry> vocache_entry_priority_list_t; + typedef std::set<LLVOCacheEntry*, CompareVOCacheEntry> vocache_entry_priority_list_t; + typedef std::unordered_map<U32, ExtrasEntry> vocache_extras_entry_map_t; S32 mLastCameraUpdated; protected: @@ -265,7 +275,10 @@ public: void removeCache(ELLPath location, bool started = false) ; void readFromCache(U64 handle, const LLUUID& id, LLVOCacheEntry::vocache_entry_map_t& cache_entry_map) ; + void readGenericExtrasFromCache(U64 handle, const LLUUID& id, LLVOCacheEntry::vocache_extras_entry_map_t& cache_extras_entry_map); + void writeToCache(U64 handle, const LLUUID& id, const LLVOCacheEntry::vocache_entry_map_t& cache_entry_map, BOOL dirty_cache, bool removal_enabled); + void writeGenericExtrasToCache(U64 handle, const LLUUID& id, const LLVOCacheEntry::vocache_extras_entry_map_t& cache_extras_entry_map, BOOL dirty_cache, bool removal_enabled); void removeEntry(U64 handle) ; U32 getCacheEntries() { return mNumEntries; } |