summaryrefslogtreecommitdiff
path: root/indra/newview/llvocache.cpp
diff options
context:
space:
mode:
authorRichard Linden <none@none>2013-06-05 19:05:43 -0700
committerRichard Linden <none@none>2013-06-05 19:05:43 -0700
commit0a96b47663c99914c587cdcb8bcdc096bbf55fa3 (patch)
tree67bca4958927ed7f6df423de05e42cd271292391 /indra/newview/llvocache.cpp
parentdcfb18373eca7986a73d8b9a1d34970cc0a23ed9 (diff)
parenta74b5dfa923f8eeccc9b786143f0f832de3ad450 (diff)
merge with viewer-release
Diffstat (limited to 'indra/newview/llvocache.cpp')
-rwxr-xr-xindra/newview/llvocache.cpp372
1 files changed, 308 insertions, 64 deletions
diff --git a/indra/newview/llvocache.cpp b/indra/newview/llvocache.cpp
index 7db19c5c1b..5e2d2efc5e 100755
--- a/indra/newview/llvocache.cpp
+++ b/indra/newview/llvocache.cpp
@@ -29,6 +29,12 @@
#include "llerror.h"
#include "llregionhandle.h"
#include "llviewercontrol.h"
+#include "llviewerobjectlist.h"
+#include "lldrawable.h"
+#include "llviewerregion.h"
+#include "pipeline.h"
+
+LLTrace::MemStatHandle LLVOCachePartition::sMemStat("LLVOCachePartition");
BOOL check_read(LLAPRFile* apr_file, void* src, S32 n_bytes)
{
@@ -46,12 +52,18 @@ BOOL check_write(LLAPRFile* apr_file, void* src, S32 n_bytes)
//---------------------------------------------------------------------------
LLVOCacheEntry::LLVOCacheEntry(U32 local_id, U32 crc, LLDataPackerBinaryBuffer &dp)
- :
+ : LLViewerOctreeEntryData(LLViewerOctreeEntry::LLVOCACHEENTRY),
mLocalID(local_id),
mCRC(crc),
+ mUpdateFlags(-1),
mHitCount(0),
mDupeCount(0),
- mCRCChangeCount(0)
+ mCRCChangeCount(0),
+ mState(INACTIVE),
+ mMinFrameRange(64),
+ mSceneContrib(0.f),
+ mTouched(TRUE),
+ mParentID(0)
{
mBuffer = new U8[dp.getBufferSize()];
mDP.assignBuffer(mBuffer, dp.getBufferSize());
@@ -59,24 +71,39 @@ LLVOCacheEntry::LLVOCacheEntry(U32 local_id, U32 crc, LLDataPackerBinaryBuffer &
}
LLVOCacheEntry::LLVOCacheEntry()
- :
+ : LLViewerOctreeEntryData(LLViewerOctreeEntry::LLVOCACHEENTRY),
mLocalID(0),
mCRC(0),
+ mUpdateFlags(-1),
mHitCount(0),
mDupeCount(0),
mCRCChangeCount(0),
- mBuffer(NULL)
+ mBuffer(NULL),
+ mState(INACTIVE),
+ mMinFrameRange(64),
+ mSceneContrib(0.f),
+ mTouched(TRUE),
+ mParentID(0)
{
mDP.assignBuffer(mBuffer, 0);
}
LLVOCacheEntry::LLVOCacheEntry(LLAPRFile* apr_file)
- : mBuffer(NULL)
+ : LLViewerOctreeEntryData(LLViewerOctreeEntry::LLVOCACHEENTRY),
+ mBuffer(NULL),
+ mUpdateFlags(-1),
+ mState(INACTIVE),
+ mMinFrameRange(64),
+ mSceneContrib(0.f),
+ mTouched(FALSE),
+ mParentID(0)
{
S32 size = -1;
BOOL success;
mDP.assignBuffer(mBuffer, 0);
+ setOctreeEntry(NULL);
+
success = check_read(apr_file, &mLocalID, sizeof(U32));
if(success)
{
@@ -132,32 +159,88 @@ LLVOCacheEntry::LLVOCacheEntry(LLAPRFile* apr_file)
mDupeCount = 0;
mCRCChangeCount = 0;
mBuffer = NULL;
+ mEntry = NULL;
+ mState = 0;
}
}
LLVOCacheEntry::~LLVOCacheEntry()
{
mDP.freeBuffer();
+ //llassert(mState == INACTIVE);
}
+//virtual
+void LLVOCacheEntry::setOctreeEntry(LLViewerOctreeEntry* entry)
+{
+ if(!entry && mDP.getBufferSize() > 0)
+ {
+ LLUUID fullid;
+ LLViewerObject::unpackUUID(&mDP, fullid, "ID");
+
+ LLViewerObject* obj = gObjectList.findObject(fullid);
+ if(obj && obj->mDrawable)
+ {
+ entry = obj->mDrawable->getEntry();
+ }
+ }
-// New CRC means the object has changed.
-void LLVOCacheEntry::assignCRC(U32 crc, LLDataPackerBinaryBuffer &dp)
+ LLViewerOctreeEntryData::setOctreeEntry(entry);
+}
+
+void LLVOCacheEntry::moveTo(LLVOCacheEntry* new_entry)
{
- if ( (mCRC != crc)
- ||(mDP.getBufferSize() == 0))
+ //copy LLViewerOctreeEntry
+ if(mEntry.notNull())
{
- mCRC = crc;
- mHitCount = 0;
- mCRCChangeCount++;
+ new_entry->setOctreeEntry(mEntry);
+ mEntry = NULL;
+ }
+
+ //copy children
+ S32 num_children = getNumOfChildren();
+ for(S32 i = 0; i < num_children; i++)
+ {
+ new_entry->addChild(getChild(i));
+ }
+ mChildrenList.clear();
+}
- mDP.freeBuffer();
- mBuffer = new U8[dp.getBufferSize()];
- mDP.assignBuffer(mBuffer, dp.getBufferSize());
- mDP = dp;
+void LLVOCacheEntry::setState(U32 state)
+{
+ mState = state;
+
+ if(getState() == ACTIVE)
+ {
+ const S32 MIN_REAVTIVE_INTERVAL = 32;
+ U32 last_visible = getVisible();
+
+ setVisible();
+
+ if(getVisible() - last_visible < MIN_REAVTIVE_INTERVAL + mMinFrameRange)
+ {
+ mMinFrameRange = llmin(mMinFrameRange * 2, 2048);
+ }
+ else
+ {
+ mMinFrameRange = 64; //reset
+ }
}
}
+//virtual
+S32 LLVOCacheEntry::getMinFrameRange()const
+{
+ return mMinFrameRange;
+}
+
+void LLVOCacheEntry::addChild(LLVOCacheEntry* entry)
+{
+ llassert(entry != NULL);
+
+ mChildrenList.push_back(entry);
+}
+
LLDataPackerBinaryBuffer *LLVOCacheEntry::getDP(U32 crc)
{
if ( (mCRC != crc)
@@ -170,9 +253,20 @@ LLDataPackerBinaryBuffer *LLVOCacheEntry::getDP(U32 crc)
return &mDP;
}
+LLDataPackerBinaryBuffer *LLVOCacheEntry::getDP()
+{
+ if (mDP.getBufferSize() == 0)
+ {
+ //llinfos << "Not getting cache entry, invalid!" << llendl;
+ return NULL;
+ }
+
+ return &mDP;
+}
void LLVOCacheEntry::recordHit()
{
+ setTouched();
mHitCount++;
}
@@ -189,6 +283,11 @@ void LLVOCacheEntry::dump() const
BOOL LLVOCacheEntry::writeToFile(LLAPRFile* apr_file) const
{
+ if(!mEntry)
+ {
+ return FALSE;
+ }
+
BOOL success;
success = check_write(apr_file, (void*)&mLocalID, sizeof(U32));
if(success)
@@ -221,49 +320,183 @@ BOOL LLVOCacheEntry::writeToFile(LLAPRFile* apr_file) const
return success ;
}
+void LLVOCacheEntry::calcSceneContribution(const LLVector3& camera_origin, bool needs_update, U32 last_update)
+{
+ if(!needs_update && getVisible() >= last_update)
+ {
+ return; //no need to update
+ }
+
+ const LLVector4a& center = getPositionGroup();
+
+ LLVector4a origin;
+ origin.load3(camera_origin.mV);
+
+ LLVector4a lookAt;
+ lookAt.setSub(center, origin);
+ F32 squared_dist = lookAt.dot3(lookAt).getF32();
+
+ F32 rad = getBinRadius();
+ mSceneContrib = rad * rad / squared_dist;
+
+ setVisible();
+}
+
+void LLVOCacheEntry::setBoundingInfo(const LLVector3& pos, const LLVector3& scale)
+{
+ LLVector4a center, newMin, newMax;
+ center.load3(pos.mV);
+ LLVector4a size;
+ size.load3(scale.mV);
+ newMin.setSub(center, size);
+ newMax.setAdd(center, size);
+
+ setPositionGroup(center);
+ setSpatialExtents(newMin, newMax);
+ setBinRadius(llmin(size.getLength3().getF32() * 4.f, 256.f));
+}
+
//-------------------------------------------------------------------
-//LLVOCache
+//LLVOCachePartition
//-------------------------------------------------------------------
-// Format string used to construct filename for the object cache
-static const char OBJECT_CACHE_FILENAME[] = "objects_%d_%d.slc";
+LLVOCachePartition::LLVOCachePartition(LLViewerRegion* regionp)
+{
+ mLODPeriod = 16;
+ mRegionp = regionp;
+ mPartitionType = LLViewerRegion::PARTITION_VO_CACHE;
+
+ new LLOcclusionCullingGroup(mOctree, this);
+}
-const U32 MAX_NUM_OBJECT_ENTRIES = 128 ;
-const U32 MIN_ENTRIES_TO_PURGE = 16 ;
-const U32 INVALID_TIME = 0 ;
-const char* object_cache_dirname = "objectcache";
-const char* header_filename = "object.cache";
+void LLVOCachePartition::addEntry(LLViewerOctreeEntry* entry)
+{
+ llassert(entry->hasVOCacheEntry());
-LLVOCache* LLVOCache::sInstance = NULL;
+ mOctree->insert(entry);
+}
+
+void LLVOCachePartition::removeEntry(LLViewerOctreeEntry* entry)
+{
+ entry->getVOCacheEntry()->setGroup(NULL);
-//static
-LLVOCache* LLVOCache::getInstance()
-{
- if(!sInstance)
+ llassert(!entry->getGroup());
+}
+
+class LLVOCacheOctreeCull : public LLViewerOctreeCull
+{
+public:
+ LLVOCacheOctreeCull(LLCamera* camera, LLViewerRegion* regionp, const LLVector3& shift, bool use_object_cache_occlusion)
+ : LLViewerOctreeCull(camera),
+ mRegionp(regionp)
{
- sInstance = new LLVOCache() ;
+ mLocalShift = shift;
+ mUseObjectCacheOcclusion = (use_object_cache_occlusion && LLPipeline::sUseOcclusion);
}
- return sInstance ;
-}
-//static
-BOOL LLVOCache::hasInstance()
-{
- return sInstance != NULL ;
-}
+ virtual bool earlyFail(LLviewerOctreeGroup* base_group)
+ {
+ if( mUseObjectCacheOcclusion &&
+ base_group->getOctreeNode()->getParent()) //never occlusion cull the root node
+ {
+ LLOcclusionCullingGroup* group = (LLOcclusionCullingGroup*)base_group;
+ if(group->needsUpdate())
+ {
+ return false; //needs to issue new occlusion culling check.
+ }
+
+ group->checkOcclusion();
+
+ if (group->isOcclusionState(LLSpatialGroup::OCCLUDED))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ virtual S32 frustumCheck(const LLviewerOctreeGroup* group)
+ {
+ S32 res = AABBInRegionFrustumGroupBounds(group);
+
+ //S32 res = AABBInRegionFrustumNoFarClipGroupBounds(group);
+ if (res != 0)
+ {
+ res = llmin(res, AABBRegionSphereIntersectGroupExtents(group, mLocalShift));
+ }
+ return res;
+ }
+
+ virtual S32 frustumCheckObjects(const LLviewerOctreeGroup* group)
+ {
+ S32 res = AABBInRegionFrustumObjectBounds(group);
+
+ //S32 res = AABBInRegionFrustumNoFarClipObjectBounds(group);
+ if (res != 0)
+ {
+ res = llmin(res, AABBRegionSphereIntersectObjectExtents(group, mLocalShift));
+ }
+ return res;
+ }
-//static
-void LLVOCache::destroyClass()
+ virtual void processGroup(LLviewerOctreeGroup* base_group)
+ {
+ if(mUseObjectCacheOcclusion && base_group->getOctreeNode()->getParent())
+ {
+ LLOcclusionCullingGroup* group = (LLOcclusionCullingGroup*)base_group;
+ if (group->needsUpdate() || group->mVisible[LLViewerCamera::sCurCameraID] < LLDrawable::getCurrentFrame() - 1)
+ {
+ ((LLOcclusionCullingGroup*)group)->doOcclusion(mCamera);
+ group->setVisible();
+ return; //wait for occlusion culling results
+ }
+ }
+ mRegionp->addVisibleGroup(base_group);
+ }
+
+private:
+ LLViewerRegion* mRegionp;
+ LLVector3 mLocalShift; //shift vector from agent space to local region space.
+ bool mUseObjectCacheOcclusion;
+};
+
+S32 LLVOCachePartition::cull(LLCamera &camera)
{
- if(sInstance)
+ static LLCachedControl<bool> use_object_cache_occlusion(gSavedSettings,"UseObjectCacheOcclusion");
+
+ if(!LLViewerRegion::sVOCacheCullingEnabled)
{
- delete sInstance ;
- sInstance = NULL ;
+ return 0;
}
+
+ ((LLviewerOctreeGroup*)mOctree->getListener(0))->rebound();
+
+ //localize the camera
+ LLVector3 region_agent = mRegionp->getOriginAgent();
+ camera.calcRegionFrustumPlanes(region_agent);
+
+ LLVOCacheOctreeCull culler(&camera, mRegionp, region_agent, use_object_cache_occlusion);
+ culler.traverse(mOctree);
+
+ return 0;
}
+//-------------------------------------------------------------------
+//LLVOCache
+//-------------------------------------------------------------------
+// Format string used to construct filename for the object cache
+static const char OBJECT_CACHE_FILENAME[] = "objects_%d_%d.slc";
+
+const U32 MAX_NUM_OBJECT_ENTRIES = 128 ;
+const U32 MIN_ENTRIES_TO_PURGE = 16 ;
+const U32 INVALID_TIME = 0 ;
+const char* object_cache_dirname = "objectcache";
+const char* header_filename = "object.cache";
+
+
LLVOCache::LLVOCache():
- mInitialized(FALSE),
- mReadOnly(TRUE),
+ mInitialized(false),
+ mReadOnly(true),
mNumEntries(0),
mCacheSize(1)
{
@@ -300,7 +533,7 @@ void LLVOCache::initCache(ELLPath location, U32 size, U32 cache_version)
llwarns << "Cache already initialized." << llendl;
return ;
}
- mInitialized = TRUE ;
+ mInitialized = true;
setDirNames(location);
if (!mReadOnly)
@@ -325,13 +558,19 @@ void LLVOCache::initCache(ELLPath location, U32 size, U32 cache_version)
}
}
-void LLVOCache::removeCache(ELLPath location)
+void LLVOCache::removeCache(ELLPath location, bool started)
{
+ if(started)
+ {
+ removeCache();
+ return;
+ }
+
if(mReadOnly)
{
llwarns << "Not removing cache at " << location << ": Cache is currently in read-only mode." << llendl;
return ;
- }
+ }
llinfos << "about to remove the object cache due to settings." << llendl ;
@@ -342,22 +581,25 @@ void LLVOCache::removeCache(ELLPath location)
LLFile::rmdir(cache_dir);
clearCacheInMemory();
- mInitialized = FALSE ;
+ mInitialized = false;
}
void LLVOCache::removeCache()
{
- llassert_always(mInitialized) ;
+ if(!mInitialized)
+ {
+ //OK to remove cache even it is not initialized.
+ llwarns << "Object cache is not initialized yet." << llendl;
+ }
+
if(mReadOnly)
{
llwarns << "Not clearing object cache: Cache is currently in read-only mode." << llendl;
return ;
}
- llinfos << "about to remove the object cache due to some error." << llendl ;
-
std::string mask = "*";
- llinfos << "Removing cache at " << mObjectCacheDirName << llendl;
+ llinfos << "Removing object cache at " << mObjectCacheDirName << llendl;
gDirUtilp->deleteFilesInDir(mObjectCacheDirName, mask);
clearCacheInMemory() ;
@@ -366,23 +608,23 @@ void LLVOCache::removeCache()
void LLVOCache::removeEntry(HeaderEntryInfo* entry)
{
- llassert_always(mInitialized) ;
+ llassert_always(mInitialized);
if(mReadOnly)
{
- return ;
+ return;
}
if(!entry)
{
- return ;
+ return;
}
- header_entry_queue_t::iterator iter = mHeaderEntryQueue.find(entry) ;
+ header_entry_queue_t::iterator iter = mHeaderEntryQueue.find(entry);
if(iter != mHeaderEntryQueue.end())
{
- mHandleEntryMap.erase(entry->mHandle) ;
- mHeaderEntryQueue.erase(iter) ;
- removeFromCache(entry) ;
- delete entry ;
+ mHandleEntryMap.erase(entry->mHandle);
+ mHeaderEntryQueue.erase(iter);
+ removeFromCache(entry);
+ delete entry;
mNumEntries = mHandleEntryMap.size() ;
}
@@ -625,11 +867,10 @@ void LLVOCache::readFromCache(U64 handle, const LLUUID& id, LLVOCacheEntry::voca
{
for (S32 i = 0; i < num_entries; i++)
{
- LLVOCacheEntry* entry = new LLVOCacheEntry(&apr_file);
+ LLPointer<LLVOCacheEntry> entry = new LLVOCacheEntry(&apr_file);
if (!entry->getLocalID())
{
llwarns << "Aborting cache file load for " << filename << ", cache file corruption!" << llendl;
- delete entry ;
success = false ;
break ;
}
@@ -665,7 +906,7 @@ void LLVOCache::purgeEntries(U32 size)
mNumEntries = mHandleEntryMap.size() ;
}
-void LLVOCache::writeToCache(U64 handle, const LLUUID& id, const LLVOCacheEntry::vocache_entry_map_t& cache_entry_map, BOOL dirty_cache)
+void LLVOCache::writeToCache(U64 handle, const LLUUID& id, const LLVOCacheEntry::vocache_entry_map_t& cache_entry_map, BOOL dirty_cache, bool removal_enabled)
{
if(!mEnabled)
{
@@ -738,7 +979,10 @@ void LLVOCache::writeToCache(U64 handle, const LLUUID& id, const LLVOCacheEntry:
for (LLVOCacheEntry::vocache_entry_map_t::const_iterator iter = cache_entry_map.begin(); success && iter != cache_entry_map.end(); ++iter)
{
- success = iter->second->writeToFile(&apr_file) ;
+ if(!removal_enabled || iter->second->isTouched())
+ {
+ success = iter->second->writeToFile(&apr_file) ;
+ }
}
}
}