From c0ba626c8009b22310b3923e8170e5db2a021253 Mon Sep 17 00:00:00 2001 From: Xiaohong Bao Date: Mon, 15 Oct 2012 21:34:29 -0600 Subject: For SH-3333: Design and implement a new object cache system on viewer side --- indra/newview/lldrawable.cpp | 349 +++++++++++++++++++++---------------------- 1 file changed, 170 insertions(+), 179 deletions(-) (limited to 'indra/newview/lldrawable.cpp') diff --git a/indra/newview/lldrawable.cpp b/indra/newview/lldrawable.cpp index 46ec1abec1..e29551e83c 100644 --- a/indra/newview/lldrawable.cpp +++ b/indra/newview/lldrawable.cpp @@ -49,6 +49,7 @@ #include "llspatialpartition.h" #include "llviewerobjectlist.h" #include "llviewerwindow.h" +#include "llvocache.h" const F32 MIN_INTERPOLATE_DISTANCE_SQUARED = 0.001f * 0.001f; const F32 MAX_INTERPOLATE_DISTANCE_SQUARED = 10.f * 10.f; @@ -75,7 +76,6 @@ extern bool gShiftFrame; // // static -U32 LLDrawable::sCurVisible = 0; U32 LLDrawable::sNumZombieDrawables = 0; F32 LLDrawable::sCurPixelAngle = 0; LLDynamicArrayPtr > LLDrawable::sDeadList; @@ -85,33 +85,59 @@ LLDynamicArrayPtr > LLDrawable::sDeadList; // static void LLDrawable::incrementVisible() { - sCurVisible++; + LLViewerOctreeEntryData::incrementVisible(); sCurPixelAngle = (F32) gViewerWindow->getWindowHeightRaw()/LLViewerCamera::getInstance()->getView(); } -void LLDrawable::init() +LLDrawable::LLDrawable(LLViewerObject *vobj, bool new_entry) + : LLViewerOctreeEntryData(LLViewerOctreeEntry::LLDRAWABLE), + mVObjp(vobj) +{ + init(new_entry); +} + +void LLDrawable::init(bool new_entry) { // mXform mParent = NULL; mRenderType = 0; mCurrentScale = LLVector3(1,1,1); - mDistanceWRTCamera = 0.0f; - mPositionGroup.clear(); - mExtents[0].clear(); - mExtents[1].clear(); - + mDistanceWRTCamera = 0.0f; mState = 0; - mVObjp = NULL; - // mFaces - mSpatialGroupp = NULL; - mVisible = sCurVisible - 2;//invisible for the current frame and the last frame. - mRadius = 0.f; - mGeneration = -1; - mBinRadius = 1.f; - mBinIndex = -1; - + // mFaces + mRadius = 0.f; + mGeneration = -1; mSpatialBridge = NULL; + + LLViewerOctreeEntry* entry = NULL; + LLVOCacheEntry* vo_entry = NULL; + if(!new_entry && mVObjp && getRegion() != NULL) + { + vo_entry = getRegion()->getCacheEntryForOctree(mVObjp->getLocalID()); + if(vo_entry) + { + entry = vo_entry->getEntry(); + } + } + setOctreeEntry(entry); + if(vo_entry) + { + if(!entry) + { + vo_entry->setOctreeEntry(mEntry); + } + else if(vo_entry->getNumOfChildren() > 0) + { + getRegion()->addVisibleCacheEntry(vo_entry); //to load all children. + } + + getRegion()->addActiveCacheEntry(vo_entry); + } + + llassert(!vo_entry || vo_entry->getEntry() == mEntry); + + initVisible(sCurVisible - 2);//invisible for the current frame and the last frame. } // static @@ -155,6 +181,7 @@ void LLDrawable::markDead() llwarns << "Warning! Marking dead multiple times!" << llendl; return; } + setState(DEAD); if (mSpatialBridge) { @@ -164,8 +191,7 @@ void LLDrawable::markDead() sNumZombieDrawables++; - // We're dead. Free up all of our references to other objects - setState(DEAD); + // We're dead. Free up all of our references to other objects cleanupReferences(); // sDeadList.put(this); } @@ -219,6 +245,8 @@ void LLDrawable::cleanupReferences() gPipeline.unlinkDrawable(this); + removeFromOctree(); + { LLFastTimer t(FTM_DEREF_DRAWABLE); // Cleanup references to other objects @@ -227,6 +255,21 @@ void LLDrawable::cleanupReferences() } } +void LLDrawable::removeFromOctree() +{ + if(!mEntry) + { + return; + } + + mEntry->removeData(this); + if(mEntry->hasVOCacheEntry()) + { + getRegion()->removeActiveCacheEntry((LLVOCacheEntry*)mEntry->getVOCacheEntry(), this); + } + mEntry = NULL; +} + void LLDrawable::cleanupDeadDrawables() { /* @@ -715,7 +758,7 @@ void LLDrawable::updateDistance(LLCamera& camera, bool force_update) LLVOVolume* volume = getVOVolume(); if (volume) { - if (getSpatialGroup()) + if (getGroup()) { pos.set(getPositionGroup().getF32ptr()); } @@ -833,9 +876,7 @@ void LLDrawable::shiftPos(const LLVector4a &shift_vector) } } - mExtents[0].add(shift_vector); - mExtents[1].add(shift_vector); - mPositionGroup.add(shift_vector); + shift(shift_vector); } else if (mSpatialBridge) { @@ -843,9 +884,7 @@ void LLDrawable::shiftPos(const LLVector4a &shift_vector) } else if (isAvatar()) { - mExtents[0].add(shift_vector); - mExtents[1].add(shift_vector); - mPositionGroup.add(shift_vector); + shift(shift_vector); } mVObjp->onShift(shift_vector); @@ -857,40 +896,24 @@ const LLVector3& LLDrawable::getBounds(LLVector3& min, LLVector3& max) const return mXform.getPositionW(); } -const LLVector4a* LLDrawable::getSpatialExtents() const -{ - return mExtents; -} - -void LLDrawable::setSpatialExtents(const LLVector3& min, const LLVector3& max) -{ - mExtents[0].load3(min.mV); - mExtents[1].load3(max.mV); -} - -void LLDrawable::setSpatialExtents(const LLVector4a& min, const LLVector4a& max) -{ - mExtents[0] = min; - mExtents[1] = max; -} - -void LLDrawable::setPositionGroup(const LLVector4a& pos) -{ - mPositionGroup = pos; -} - void LLDrawable::updateSpatialExtents() { if (mVObjp) { - mVObjp->updateSpatialExtents(mExtents[0], mExtents[1]); + const LLVector4a* exts = getSpatialExtents(); + LLVector4a extents[2]; + extents[0] = exts[0]; + extents[1] = exts[1]; + + mVObjp->updateSpatialExtents(extents[0], extents[1]); + setSpatialExtents(extents[0], extents[1]); } updateBinRadius(); if (mSpatialBridge.notNull()) { - mPositionGroup.splat(0.f); + getGroupPosition().splat(0.f); } } @@ -899,11 +922,11 @@ void LLDrawable::updateBinRadius() { if (mVObjp.notNull()) { - mBinRadius = llmin(mVObjp->getBinRadius(), 256.f); + setBinRadius(llmin(mVObjp->getBinRadius(), 256.f)); } else { - mBinRadius = llmin(getRadius()*4.f, 256.f); + setBinRadius(llmin(getRadius()*4.f, 256.f)); } } @@ -937,20 +960,48 @@ void LLDrawable::updateUVMinMax() { } -LLSpatialGroup* LLDrawable::getSpatialGroup() const -{ - llassert((mSpatialGroupp == NULL) ? getBinIndex() == -1 : getBinIndex() != -1); - return mSpatialGroupp; +//virtual +bool LLDrawable::isVisible() const +{ + if (LLViewerOctreeEntryData::isVisible()) + { + return true; + } + + { + LLviewerOctreeGroup* group = mEntry->getGroup(); + if (group && group->isVisible()) + { + LLViewerOctreeEntryData::setVisible(); + return true; + } + } + + return false; } -void LLDrawable::setSpatialGroup(LLSpatialGroup *groupp) +//virtual +bool LLDrawable::isRecentlyVisible() const { -/*if (mSpatialGroupp && (groupp != mSpatialGroupp)) + //currently visible or visible in the previous frame. + bool vis = LLViewerOctreeEntryData::isRecentlyVisible(); + + if(!vis) { - mSpatialGroupp->setState(LLSpatialGroup::GEOM_DIRTY); - }*/ + LLviewerOctreeGroup* group = getGroup(); + if (group && group->isRecentlyVisible()) + { + LLViewerOctreeEntryData::setVisible(); + vis = TRUE ; + } + } + + return vis ; +} - if (mSpatialGroupp != groupp && getVOVolume()) +void LLDrawable::setGroup(LLviewerOctreeGroup *groupp) +{ + if (getGroup() != groupp && getVOVolume()) { //NULL out vertex buffer references for volumes on spatial group change to maintain //requirement that every face vertex buffer is either NULL or points to a vertex buffer //contained by its drawable's spatial group @@ -964,9 +1015,7 @@ void LLDrawable::setSpatialGroup(LLSpatialGroup *groupp) } } - mSpatialGroupp = groupp; - - llassert((mSpatialGroupp == NULL) ? getBinIndex() == -1 : getBinIndex() != -1); + LLViewerOctreeEntryData::setGroup(groupp); } LLSpatialPartition* LLDrawable::getSpatialPartition() @@ -985,11 +1034,11 @@ LLSpatialPartition* LLDrawable::getSpatialPartition() { if (mVObjp->isHUDAttachment()) { - setSpatialBridge(new LLHUDBridge(this)); + setSpatialBridge(new LLHUDBridge(this, getRegion())); } else { - setSpatialBridge(new LLVolumeBridge(this)); + setSpatialBridge(new LLVolumeBridge(this, getRegion())); } } return mSpatialBridge->asPartition(); @@ -1008,89 +1057,26 @@ LLSpatialPartition* LLDrawable::getSpatialPartition() return retval; } -const S32 MIN_VIS_FRAME_RANGE = 2 ; //two frames:the current one and the last one. -//static -S32 LLDrawable::getMinVisFrameRange() +//virtual +S32 LLDrawable::getMinVisFrameRange() const { - return MIN_VIS_FRAME_RANGE ; -} - -BOOL LLDrawable::isRecentlyVisible() const -{ - //currently visible or visible in the previous frame. - BOOL vis = isVisible() || (sCurVisible - mVisible < MIN_VIS_FRAME_RANGE) ; - - if(!vis) - { - LLSpatialGroup* group = getSpatialGroup(); - if (group && group->isRecentlyVisible()) - { - mVisible = sCurVisible; - vis = TRUE ; - } - } - - return vis ; -} - -BOOL LLDrawable::isVisible() const -{ - if (mVisible == sCurVisible) - { - return TRUE; - } - -#if 0 - //disabling this code fixes DEV-20105. Leaving in place in case some other bug pops up as a a result. - //should be safe to just always ask the spatial group for visibility. - if (isActive()) - { - if (isRoot()) - { - LLSpatialGroup* group = mSpatialBridge.notNull() ? mSpatialBridge->getSpatialGroup() : - getSpatialGroup(); - if (group && group->isVisible()) - { - mVisible = sCurVisible; - return TRUE; - } - } - else - { - if (getParent()->isVisible()) - { - mVisible = sCurVisible; - return TRUE; - } - } - } - else -#endif - { - LLSpatialGroup* group = getSpatialGroup(); - if (group && group->isVisible()) - { - mVisible = sCurVisible; - return TRUE; - } - } + const S32 MIN_VIS_FRAME_RANGE = 2 ; //two frames:the current one and the last one. - return FALSE; + return MIN_VIS_FRAME_RANGE ; } //======================================= // Spatial Partition Bridging Drawable //======================================= -LLSpatialBridge::LLSpatialBridge(LLDrawable* root, BOOL render_by_group, U32 data_mask) -: LLSpatialPartition(data_mask, render_by_group, GL_STREAM_DRAW_ARB) +LLSpatialBridge::LLSpatialBridge(LLDrawable* root, BOOL render_by_group, U32 data_mask, LLViewerRegion* regionp) : + LLDrawable(root->getVObj(), true), + LLSpatialPartition(data_mask, render_by_group, GL_STREAM_DRAW_ARB, regionp) { mBridge = this; mDrawable = root; root->setSpatialBridge(this); - mBinIndex = -1; - mRenderType = mDrawable->mRenderType; mDrawableType = mDrawable->mRenderType; @@ -1111,10 +1097,13 @@ LLSpatialBridge::LLSpatialBridge(LLDrawable* root, BOOL render_by_group, U32 dat LLSpatialBridge::~LLSpatialBridge() { - LLSpatialGroup* group = getSpatialGroup(); - if (group) + if(mEntry) { - group->mSpatialPartition->remove(this, group); + LLSpatialGroup* group = getSpatialGroup(); + if (group) + { + group->mSpatialPartition->remove(this, group); + } } //delete octree here so listeners will still be able to access bridge specific state @@ -1136,8 +1125,9 @@ void LLSpatialBridge::updateSpatialExtents() root->rebound(); } + const LLVector4a* root_bounds = root->getBounds(); LLVector4a offset; - LLVector4a size = root->mBounds[1]; + LLVector4a size = root_bounds[1]; //VECTORIZE THIS LLMatrix4a mat; @@ -1149,7 +1139,7 @@ void LLSpatialBridge::updateSpatialExtents() LLVector4a center; mat.affineTransform(t, center); - mat.rotate(root->mBounds[0], offset); + mat.rotate(root_bounds[0], offset); center.add(offset); LLVector4a v[4]; @@ -1171,12 +1161,9 @@ void LLSpatialBridge::updateSpatialExtents() scale.mul(size); mat.rotate(scale, v[3]); - - LLVector4a& newMin = mExtents[0]; - LLVector4a& newMax = mExtents[1]; - - newMin = newMax = center; - + LLVector4a newMin; + LLVector4a newMax; + newMin = newMax = center; for (U32 i = 0; i < 4; i++) { LLVector4a delta; @@ -1189,19 +1176,21 @@ void LLSpatialBridge::updateSpatialExtents() newMin.setMin(newMin, min); newMax.setMax(newMax, max); } - + setSpatialExtents(newMin, newMax); + LLVector4a diagonal; diagonal.setSub(newMax, newMin); mRadius = diagonal.getLength3().getF32() * 0.5f; - mPositionGroup.setAdd(newMin,newMax); - mPositionGroup.mul(0.5f); + LLVector4a& pos = getGroupPosition(); + pos.setAdd(newMin,newMax); + pos.mul(0.5f); updateBinRadius(); } void LLSpatialBridge::updateBinRadius() { - mBinRadius = llmin( mOctree->getSize()[0]*0.5f, 256.f); + setBinRadius(llmin( mOctree->getSize()[0]*0.5f, 256.f)); } LLCamera LLSpatialBridge::transformCamera(LLCamera& camera) @@ -1236,7 +1225,7 @@ LLCamera LLSpatialBridge::transformCamera(LLCamera& camera) void LLDrawable::setVisible(LLCamera& camera, std::vector* results, BOOL for_select) { - mVisible = sCurVisible; + LLViewerOctreeEntryData::setVisible(); #if 0 && !LL_RELEASE_FOR_DOWNLOAD //crazy paranoid rules checking @@ -1271,21 +1260,21 @@ void LLDrawable::setVisible(LLCamera& camera, std::vector* results, #endif } -class LLOctreeMarkNotCulled: public LLOctreeTraveler +class LLOctreeMarkNotCulled: public OctreeTraveler { public: LLCamera* mCamera; LLOctreeMarkNotCulled(LLCamera* camera_in) : mCamera(camera_in) { } - virtual void traverse(const LLOctreeNode* node) + virtual void traverse(const OctreeNode* node) { LLSpatialGroup* group = (LLSpatialGroup*) node->getListener(0); group->setVisible(); - LLOctreeTraveler::traverse(node); + OctreeTraveler::traverse(node); } - void visit(const LLOctreeNode* branch) + void visit(const OctreeNode* branch) { gPipeline.markNotCulled((LLSpatialGroup*) branch->getListener(0), *mCamera); } @@ -1329,7 +1318,7 @@ void LLSpatialBridge::setVisible(LLCamera& camera_in, std::vector* } if (!group || - LLDrawable::getCurrentFrame() - av->mVisible > 1 || + LLDrawable::getCurrentFrame() - av->getVisible() > 1 || impostor || !loaded) { @@ -1343,16 +1332,17 @@ void LLSpatialBridge::setVisible(LLCamera& camera_in, std::vector* group->rebound(); LLVector4a center; - center.setAdd(mExtents[0], mExtents[1]); + const LLVector4a* exts = getSpatialExtents(); + center.setAdd(exts[0], exts[1]); center.mul(0.5f); LLVector4a size; - size.setSub(mExtents[1], mExtents[0]); + size.setSub(exts[1], exts[0]); size.mul(0.5f); if ((LLPipeline::sShadowRender && camera_in.AABBInFrustum(center, size)) || LLPipeline::sImpostorRender || (camera_in.AABBInFrustumNoFarClip(center, size) && - AABBSphereIntersect(mExtents[0], mExtents[1], camera_in.getOrigin(), camera_in.mFrustumCornerDist))) + AABBSphereIntersect(exts[0], exts[1], camera_in.getOrigin(), camera_in.mFrustumCornerDist))) { if (!LLPipeline::sImpostorRender && !LLPipeline::sShadowRender && @@ -1467,22 +1457,28 @@ BOOL LLSpatialBridge::updateMove() void LLSpatialBridge::shiftPos(const LLVector4a& vec) { - mExtents[0].add(vec); - mExtents[1].add(vec); - mPositionGroup.add(vec); + LLDrawable::shift(vec); } void LLSpatialBridge::cleanupReferences() { + LLPointer dummy_entry; + if (mDrawable && mDrawable->isDead() && mDrawable->getEntry()->hasVOCacheEntry()) + { + //create a dummy entry to insert the entire LLSpatialBridge to the vo_cache partition so it can be reloaded. + + dummy_entry = new LLVOCacheEntry(); + dummy_entry->setOctreeEntry(mEntry); + dummy_entry->addChild((LLVOCacheEntry*)mDrawable->getEntry()->getVOCacheEntry()); + llassert(!mDrawable->getParent()); + + mDrawable->mParent = this; + } + LLDrawable::cleanupReferences(); if (mDrawable) { - LLSpatialGroup* group = mDrawable->getSpatialGroup(); - if (group) - { - group->mOctreeNode->remove(mDrawable); - mDrawable->setSpatialGroup(NULL); - } + mDrawable->setGroup(NULL); if (mDrawable->getVObj()) { @@ -1494,12 +1490,7 @@ void LLSpatialBridge::cleanupReferences() LLDrawable* drawable = child->mDrawable; if (drawable) { - LLSpatialGroup* group = drawable->getSpatialGroup(); - if (group) - { - group->mOctreeNode->remove(drawable); - drawable->setSpatialGroup(NULL); - } + drawable->setGroup(NULL); } } } @@ -1571,8 +1562,8 @@ void LLDrawable::updateFaceSize(S32 idx) } } -LLBridgePartition::LLBridgePartition() -: LLSpatialPartition(0, FALSE, 0) +LLBridgePartition::LLBridgePartition(LLViewerRegion* regionp) +: LLSpatialPartition(0, FALSE, 0, regionp) { mDrawableType = LLPipeline::RENDER_TYPE_AVATAR; mPartitionType = LLViewerRegion::PARTITION_BRIDGE; @@ -1580,8 +1571,8 @@ LLBridgePartition::LLBridgePartition() mSlopRatio = 0.25f; } -LLHUDBridge::LLHUDBridge(LLDrawable* drawablep) -: LLVolumeBridge(drawablep) +LLHUDBridge::LLHUDBridge(LLDrawable* drawablep, LLViewerRegion* regionp) +: LLVolumeBridge(drawablep, regionp) { mDrawableType = LLPipeline::RENDER_TYPE_HUD; mPartitionType = LLViewerRegion::PARTITION_HUD; -- cgit v1.3 From c2859e4663c405950b6f433270ae558852330c76 Mon Sep 17 00:00:00 2001 From: Xiaohong Bao Date: Thu, 8 Nov 2012 21:36:47 -0700 Subject: for SH-3472: prioritize object loading --- indra/newview/lldrawable.cpp | 17 +- indra/newview/llviewerobjectlist.cpp | 85 +++++----- indra/newview/llviewerobjectlist.h | 2 +- indra/newview/llvieweroctree.cpp | 9 +- indra/newview/llvieweroctree.h | 8 +- indra/newview/llviewerregion.cpp | 317 ++++++++++++++++++++++------------- indra/newview/llviewerregion.h | 6 +- indra/newview/llvocache.cpp | 136 +++++++++++---- indra/newview/llvocache.h | 69 ++++++-- 9 files changed, 423 insertions(+), 226 deletions(-) (limited to 'indra/newview/lldrawable.cpp') diff --git a/indra/newview/lldrawable.cpp b/indra/newview/lldrawable.cpp index e29551e83c..c782fbfe7e 100644 --- a/indra/newview/lldrawable.cpp +++ b/indra/newview/lldrawable.cpp @@ -470,7 +470,13 @@ void LLDrawable::makeActive() } updatePartition(); } - + else if (!isRoot() && !mParent->isActive()) //this should not happen, but occasionally it does... + { + mParent->makeActive(); + //NOTE: linked set will now NEVER become static + mParent->setState(LLDrawable::ACTIVE_CHILD); + } + llassert(isAvatar() || isRoot() || mParent->isActive()); } @@ -1093,6 +1099,11 @@ LLSpatialBridge::LLSpatialBridge(LLDrawable* root, BOOL render_by_group, U32 dat { part->put(this); } + + if(mDrawable->getEntry()->hasVOCacheEntry()) + { + ((LLVOCacheEntry*)mDrawable->getEntry()->getVOCacheEntry())->setBridgeChild(); + } } LLSpatialBridge::~LLSpatialBridge() @@ -1470,9 +1481,9 @@ void LLSpatialBridge::cleanupReferences() dummy_entry = new LLVOCacheEntry(); dummy_entry->setOctreeEntry(mEntry); dummy_entry->addChild((LLVOCacheEntry*)mDrawable->getEntry()->getVOCacheEntry()); - llassert(!mDrawable->getParent()); + //llassert(!mDrawable->getParent()); - mDrawable->mParent = this; + //mDrawable->mParent = this; } LLDrawable::cleanupReferences(); diff --git a/indra/newview/llviewerobjectlist.cpp b/indra/newview/llviewerobjectlist.cpp index d41eee5926..f3552e2c2b 100644 --- a/indra/newview/llviewerobjectlist.cpp +++ b/indra/newview/llviewerobjectlist.cpp @@ -376,7 +376,7 @@ LLViewerObject* LLViewerObjectList::processObjectUpdateFromCache(LLVOCacheEntry* void LLViewerObjectList::processObjectUpdate(LLMessageSystem *mesgsys, void **user_data, const EObjectUpdateType update_type, - bool cached, bool compressed) + bool compressed) { LLFastTimer t(FTM_PROCESS_OBJECTS); @@ -395,7 +395,7 @@ void LLViewerObjectList::processObjectUpdate(LLMessageSystem *mesgsys, num_objects = mesgsys->getNumberOfBlocksFast(_PREHASH_ObjectData); // I don't think this case is ever hit. TODO* Test this. - if (!cached && !compressed && update_type != OUT_FULL) + if (!compressed && update_type != OUT_FULL) { //llinfos << "TEST: !cached && !compressed && update_type != OUT_FULL" << llendl; gTerseObjectUpdates += num_objects; @@ -439,7 +439,6 @@ void LLViewerObjectList::processObjectUpdate(LLMessageSystem *mesgsys, U8 compressed_dpbuffer[2048]; LLDataPackerBinaryBuffer compressed_dp(compressed_dpbuffer, 2048); - LLDataPacker *cached_dpp = NULL; LLViewerStatsRecorder& recorder = LLViewerStatsRecorder::instance(); for (i = 0; i < num_objects; i++) @@ -449,34 +448,7 @@ void LLViewerObjectList::processObjectUpdate(LLMessageSystem *mesgsys, BOOL justCreated = FALSE; S32 msg_size = 0; - if (cached) - { - U32 id; - U32 crc; - mesgsys->getU32Fast(_PREHASH_ObjectData, _PREHASH_ID, id, i); - mesgsys->getU32Fast(_PREHASH_ObjectData, _PREHASH_CRC, crc, i); - msg_size += sizeof(U32) * 2; - - // Lookup data packer and add this id to cache miss lists if necessary. - U8 cache_miss_type = LLViewerRegion::CACHE_MISS_TYPE_NONE; - cached_dpp = regionp->getDP(id, crc, cache_miss_type); - if (cached_dpp) - { - // Cache Hit. - cached_dpp->reset(); - cached_dpp->unpackUUID(fullid, "ID"); - cached_dpp->unpackU32(local_id, "LocalID"); - cached_dpp->unpackU8(pcode, "PCode"); - } - else - { - // Cache Miss. - recorder.cacheMissEvent(id, update_type, cache_miss_type, msg_size); - - continue; // no data packer, skip this object - } - } - else if (compressed) + if (compressed) { S32 uncompressed_length = 2048; compressed_dp.reset(); @@ -575,9 +547,6 @@ void LLViewerObjectList::processObjectUpdate(LLMessageSystem *mesgsys, continue; } } - else if (cached) // Cache hit only? - { - } else { if (update_type != OUT_FULL) @@ -610,7 +579,7 @@ void LLViewerObjectList::processObjectUpdate(LLMessageSystem *mesgsys, } justCreated = TRUE; mNumNewObjects++; - sCacheHitRate.addValue(cached ? 100.f : 0.f); + sCacheHitRate.addValue(0.f); } @@ -641,11 +610,6 @@ void LLViewerObjectList::processObjectUpdate(LLMessageSystem *mesgsys, } } } - else if (cached) // Cache hit only? - { - objectp->mLocalID = local_id; - processUpdateCore(objectp, user_data, i, update_type, cached_dpp, justCreated); - } else { if (update_type == OUT_FULL) @@ -668,14 +632,51 @@ void LLViewerObjectList::processCompressedObjectUpdate(LLMessageSystem *mesgsys, void **user_data, const EObjectUpdateType update_type) { - processObjectUpdate(mesgsys, user_data, update_type, false, true); + processObjectUpdate(mesgsys, user_data, update_type, true); } void LLViewerObjectList::processCachedObjectUpdate(LLMessageSystem *mesgsys, void **user_data, const EObjectUpdateType update_type) { - processObjectUpdate(mesgsys, user_data, update_type, true, false); + //processObjectUpdate(mesgsys, user_data, update_type, true, false); + + S32 num_objects = mesgsys->getNumberOfBlocksFast(_PREHASH_ObjectData); + gFullObjectUpdates += num_objects; + + U64 region_handle; + mesgsys->getU64Fast(_PREHASH_RegionData, _PREHASH_RegionHandle, region_handle); + LLViewerRegion *regionp = LLWorld::getInstance()->getRegionFromHandle(region_handle); + if (!regionp) + { + llwarns << "Object update from unknown region! " << region_handle << llendl; + return; + } + + LLViewerStatsRecorder& recorder = LLViewerStatsRecorder::instance(); + + for (S32 i = 0; i < num_objects; i++) + { + S32 msg_size = 0; + U32 id; + U32 crc; + mesgsys->getU32Fast(_PREHASH_ObjectData, _PREHASH_ID, id, i); + mesgsys->getU32Fast(_PREHASH_ObjectData, _PREHASH_CRC, crc, i); + msg_size += sizeof(U32) * 2; + + // Lookup data packer and add this id to cache miss lists if necessary. + U8 cache_miss_type = LLViewerRegion::CACHE_MISS_TYPE_NONE; + if(!regionp->probeCache(id, crc, cache_miss_type)) + { + // Cache Miss. + recorder.cacheMissEvent(id, update_type, cache_miss_type, msg_size); + + continue; // no data packer, skip this object + } + sCacheHitRate.addValue(100.f); + } + + return; } void LLViewerObjectList::dirtyAllObjectInventory() diff --git a/indra/newview/llviewerobjectlist.h b/indra/newview/llviewerobjectlist.h index 1476f44215..17c8c86ff5 100644 --- a/indra/newview/llviewerobjectlist.h +++ b/indra/newview/llviewerobjectlist.h @@ -83,7 +83,7 @@ public: void processUpdateCore(LLViewerObject* objectp, void** data, U32 block, const EObjectUpdateType update_type, LLDataPacker* dpp, bool justCreated, bool from_cache = false); LLViewerObject* processObjectUpdateFromCache(LLVOCacheEntry* entry, LLViewerRegion* regionp); - void processObjectUpdate(LLMessageSystem *mesgsys, void **user_data, EObjectUpdateType update_type, bool cached=false, bool compressed=false); + void processObjectUpdate(LLMessageSystem *mesgsys, void **user_data, EObjectUpdateType update_type, bool compressed=false); void processCompressedObjectUpdate(LLMessageSystem *mesgsys, void **user_data, EObjectUpdateType update_type); void processCachedObjectUpdate(LLMessageSystem *mesgsys, void **user_data, EObjectUpdateType update_type); void updateApparentAngles(LLAgent &agent); diff --git a/indra/newview/llvieweroctree.cpp b/indra/newview/llvieweroctree.cpp index 143f2a6819..b6e0674a95 100644 --- a/indra/newview/llvieweroctree.cpp +++ b/indra/newview/llvieweroctree.cpp @@ -126,13 +126,14 @@ S32 AABBSphereIntersectR2(const LLVector4a& min, const LLVector4a& max, const LL //----------------------------------------------------------------------------------- //class LLViewerOctreeEntry definitions //----------------------------------------------------------------------------------- -LLViewerOctreeEntry::LLViewerOctreeEntry() : mGroup(NULL) +LLViewerOctreeEntry::LLViewerOctreeEntry() + : mGroup(NULL), + mBinRadius(0.f), + mBinIndex(-1) { mPositionGroup.clear(); mExtents[0].clear(); - mExtents[1].clear(); - mBinRadius = 0.f; - mBinIndex = -1; + mExtents[1].clear(); for(S32 i = 0; i < NUM_DATA_TYPE; i++) { diff --git a/indra/newview/llvieweroctree.h b/indra/newview/llvieweroctree.h index 498ec3e75d..b89014119c 100644 --- a/indra/newview/llvieweroctree.h +++ b/indra/newview/llvieweroctree.h @@ -135,7 +135,7 @@ public: const LLVector4a* getSpatialExtents() const; LLviewerOctreeGroup* getGroup()const; const LLVector4a& getPositionGroup() const; - + void setBinRadius(F32 rad) {mEntry->mBinRadius = rad;} void setSpatialExtents(const LLVector3& min, const LLVector3& max); void setSpatialExtents(const LLVector4a& min, const LLVector4a& max); @@ -247,9 +247,9 @@ protected: U32 mState; OctreeNode* mOctreeNode; - LL_ALIGN_16(LLVector4a mBounds[2]); // bounding box (center, size) of this node and all its children (tight fit to objects) - LL_ALIGN_16(LLVector4a mObjectBounds[2]); // bounding box (center, size) of objects in this node - LL_ALIGN_16(LLVector4a mExtents[2]); // extents (min, max) of this node and all its children + LL_ALIGN_16(LLVector4a mBounds[2]); // bounding box (center, size) of this node and all its children (tight fit to objects) + LL_ALIGN_16(LLVector4a mObjectBounds[2]); // bounding box (center, size) of objects in this node + LL_ALIGN_16(LLVector4a mExtents[2]); // extents (min, max) of this node and all its children LL_ALIGN_16(LLVector4a mObjectExtents[2]); // extents (min, max) of objects in this node public: diff --git a/indra/newview/llviewerregion.cpp b/indra/newview/llviewerregion.cpp index 1adab15d70..24bd68825b 100644 --- a/indra/newview/llviewerregion.cpp +++ b/indra/newview/llviewerregion.cpp @@ -100,6 +100,8 @@ public: mSeedCapMaxAttemptsBeforeLogin(MAX_SEED_CAP_ATTEMPTS_BEFORE_LOGIN), mSeedCapAttempts(0), mHttpResponderID(0), + mLastCameraUpdate(0), + mLastCameraOrigin(), // I'd prefer to set the LLCapabilityListener name to match the region // name -- it's disappointing that's not available at construction time. // We could instead store an LLCapabilityListener*, making @@ -136,13 +138,14 @@ public: // Misc LLVLComposition *mCompositionp; // Composition layer for the surface - LLVOCacheEntry::vocache_entry_map_t mCacheMap; //all cached entries - LLVOCacheEntry::vocache_entry_set_t mActiveSet; //all active entries; - LLVOCacheEntry::vocache_entry_set_t mWaitingSet; //entries waiting for LLDrawable to be generated. - LLVOCacheEntry::vocache_entry_set_t mVisibleEntries; //visible root entries of a linked set. + LLVOCacheEntry::vocache_entry_map_t mCacheMap; //all cached entries + LLVOCacheEntry::vocache_entry_set_t mActiveSet; //all active entries; + LLVOCacheEntry::vocache_entry_set_t mWaitingSet; //entries waiting for LLDrawable to be generated. std::set< LLPointer > mDummyEntries; //dummy vo cache entries, for LLSpatialBridge use. - std::set< LLviewerOctreeGroup* > mVisibleGroups; //visible llspatialgroup - LLVOCachePartition* mVOCachePartition; + std::set< LLviewerOctreeGroup* > mVisibleGroups; //visible groupa + LLVOCachePartition* mVOCachePartition; + 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. // time? // LRU info? @@ -168,6 +171,9 @@ public: //spatial partitions for objects in this region std::vector mObjectPartition; + + LLVector3 mLastCameraOrigin; + U32 mLastCameraUpdate; }; // support for secondlife:///app/region/{REGION} SLapps @@ -736,27 +742,16 @@ void LLViewerRegion::dirtyHeights() void LLViewerRegion::replaceCacheEntry(LLVOCacheEntry* old_entry, LLVOCacheEntry* new_entry) { - LLPointer oct_entry; U32 state = LLVOCacheEntry::INACTIVE; if(old_entry) { - oct_entry = old_entry->getEntry(); + new_entry->copy(old_entry); state = old_entry->getState(); - - while(old_entry->getNumOfChildren() > 0) - { - new_entry->addChild(old_entry->getNextChild()); - } - killCacheEntry(old_entry); } mImpl->mCacheMap[new_entry->getLocalID()] = new_entry; - if(oct_entry.notNull()) - { - new_entry->setOctreeEntry(oct_entry); - } if(state == LLVOCacheEntry::ACTIVE) { @@ -767,7 +762,7 @@ void LLViewerRegion::replaceCacheEntry(LLVOCacheEntry* old_entry, LLVOCacheEntry { mImpl->mWaitingSet.insert(new_entry); } - else if(old_entry && oct_entry) + else if(old_entry && new_entry->getEntry()) { addToVOCacheTree(new_entry); } @@ -790,19 +785,23 @@ void LLViewerRegion::killCacheEntry(LLVOCacheEntry* entry) else if(entry->isState(LLVOCacheEntry::WAITING)) { mImpl->mWaitingSet.erase(entry); - } - - //2, kill LLViewerObject if exists - //this should be done by the rendering pipeline automatically. - - //3, remove from mVOCachePartition - if(entry->isState(LLVOCacheEntry::INACTIVE) && entry->getEntry()) + } + else if(entry->isState(LLVOCacheEntry::IN_QUEUE)) { + mImpl->mVisibleEntries.erase(entry); + } + else if(entry->isState(LLVOCacheEntry::INACTIVE)) + { + //remove from mVOCachePartition removeFromVOCacheTree(entry); } + //kill LLViewerObject if exists + //this should be done by the rendering pipeline automatically. + entry->setState(LLVOCacheEntry::INACTIVE); - //4, remove from mCacheMap, real deletion + + //remove from mCacheMap, real deletion mImpl->mCacheMap.erase(entry->getLocalID()); } @@ -885,7 +884,10 @@ void LLViewerRegion::addToVOCacheTree(LLVOCacheEntry* entry) { return; } - llassert(!entry->getGroup()); + if(entry->getGroup()) //already in octree. + { + return; + } mImpl->mVOCachePartition->addEntry(entry->getEntry()); } @@ -896,18 +898,31 @@ void LLViewerRegion::removeFromVOCacheTree(LLVOCacheEntry* entry) { return; } + if(!entry->getGroup()) + { + return; + } mImpl->mVOCachePartition->removeEntry(entry->getEntry()); } -//add the visible root entry of a linked set +//add the visible entries void LLViewerRegion::addVisibleCacheEntry(LLVOCacheEntry* entry) { - if(mDead || !entry || !entry->getNumOfChildren()) + if(mDead || !entry) { - return; //no child entries + return; } + if(entry->isState(LLVOCacheEntry::IN_QUEUE)) + { + return; + } + + if(entry->isState(LLVOCacheEntry::INACTIVE)) + { + entry->setState(LLVOCacheEntry::IN_QUEUE); + } mImpl->mVisibleEntries.insert(entry); } @@ -922,124 +937,148 @@ void LLViewerRegion::clearVisibleGroup(LLviewerOctreeGroup* group) mImpl->mVisibleGroups.erase(group); } - -//return time left -F32 LLViewerRegion::addLinkedSetChildren(F32 max_time, S32& max_num_objects) + +F32 LLViewerRegion::updateVisibleEntries(F32 max_time) { - if(mImpl->mVisibleEntries.empty()) + if(mImpl->mVisibleGroups.empty() && mImpl->mVisibleEntries.empty()) { return max_time; } LLTimer update_timer; - bool timeout = false; + + const LLVector3 camera_origin = LLViewerCamera::getInstance()->getOrigin(); + const U32 cur_frame = LLViewerOctreeEntryData::getCurrentFrame(); + bool needs_update = ((cur_frame - mImpl->mLastCameraUpdate) > 5) && ((camera_origin - mImpl->mLastCameraOrigin).lengthSquared() > 10.f); + + //process visible entries + max_time *= 0.5f; //only use up to half available time to update entries. for(LLVOCacheEntry::vocache_entry_set_t::iterator iter = mImpl->mVisibleEntries.begin(); iter != mImpl->mVisibleEntries.end();) { - LLVOCacheEntry* entry = *iter; - LLVOCacheEntry* child = entry->getNextChild(); - while(child != NULL) + LLVOCacheEntry* vo_entry = *iter; + vo_entry->calcSceneContribution(camera_origin, needs_update, mImpl->mLastCameraUpdate); + + if(vo_entry->getState() < LLVOCacheEntry::WAITING && !vo_entry->isDummy()) + { + mImpl->mWaitingList.insert(vo_entry); + } + + LLVOCacheEntry* child; + S32 num_child = vo_entry->getNumOfChildren(); + S32 num_done = 0; + for(S32 i = 0; i < num_child; i++) { - if(child->isState(LLVOCacheEntry::INACTIVE)) + child = vo_entry->getChild(i); + if(child->getState() < LLVOCacheEntry::WAITING) { - addNewObject(child); - - if(max_num_objects-- < 0 && update_timer.getElapsedTimeF32() > max_time) - { - timeout = true; //timeout - break; - } + child->setSceneContribution(vo_entry->getSceneContribution()); + mImpl->mWaitingList.insert(child); } - child = entry->getNextChild(); - } - if(!child) - { - if(entry->isDummy()) + else { - mImpl->mDummyEntries.erase(entry); + num_done++; } } - - if(!timeout) + if(num_done == num_child) { - iter = mImpl->mVisibleEntries.erase(iter); + vo_entry->clearChildrenList(); + } + + if(!vo_entry->getNumOfChildren()) + { + if(vo_entry->isDummy()) + { + mImpl->mDummyEntries.erase(vo_entry); + iter = mImpl->mVisibleEntries.erase(iter); + } + else if(vo_entry->getState() >= LLVOCacheEntry::WAITING) + { + iter = mImpl->mVisibleEntries.erase(iter); + } + else + { + ++iter; + } } else { - break; //timeout + ++iter; } - } - if(timeout) - { - return -1.f; - } - return max_time - update_timer.getElapsedTimeF32(); //time left -} - -F32 LLViewerRegion::addVisibleObjects(F32 max_time, S32& max_num_objects) -{ - if(mImpl->mVisibleGroups.empty()) - { - return max_time; + //if(update_timer.getElapsedTimeF32() > max_time) + //{ + // break; + //} } - LLTimer update_timer; - bool timeout = false; - + //process visible groups std::set< LLviewerOctreeGroup* >::iterator group_iter = mImpl->mVisibleGroups.begin(); - while(group_iter != mImpl->mVisibleGroups.end()) + for(; group_iter != mImpl->mVisibleGroups.end(); ++group_iter) { LLviewerOctreeGroup* group = *group_iter; if(!group->getOctreeNode() || group->isEmpty()) { - mImpl->mVisibleGroups.erase(group_iter); - group_iter = mImpl->mVisibleGroups.begin(); continue; } - std::vector entry_list; for (LLviewerOctreeGroup::element_iter i = group->getDataBegin(); i != group->getDataEnd(); ++i) { - //group data contents could change during creating new objects, so copy all contents first. - entry_list.push_back(*i); - } - - for(S32 i = 0; i < entry_list.size(); i++) - { - LLViewerOctreeEntry* entry = entry_list[i]; - if(entry && entry->hasVOCacheEntry()) + if((*i)->hasVOCacheEntry()) { - LLVOCacheEntry* vo_entry = (LLVOCacheEntry*)entry->getVOCacheEntry(); + LLVOCacheEntry* vo_entry = (LLVOCacheEntry*)(*i)->getVOCacheEntry(); if(vo_entry->isDummy()) { addVisibleCacheEntry(vo_entry); //for LLSpatialBridge. + continue; } - else if(vo_entry->isState(LLVOCacheEntry::INACTIVE)) - { - addNewObject(vo_entry); - if(max_num_objects-- < 0 && update_timer.getElapsedTimeF32() > max_time) - { - timeout = true; - break; - } - } + + vo_entry->calcSceneContribution(camera_origin, needs_update, mImpl->mLastCameraUpdate); + mImpl->mWaitingList.insert(vo_entry); } } - entry_list.clear(); - if(timeout) - { - break; - } - mImpl->mVisibleGroups.erase(group); - group_iter = mImpl->mVisibleGroups.begin(); - } + //if(update_timer.getElapsedTimeF32() > max_time) + //{ + // break; + //} + } + mImpl->mVisibleGroups.clear(); + + if(needs_update) + { + mImpl->mLastCameraOrigin = camera_origin; + mImpl->mLastCameraUpdate = cur_frame; + } + + return 2.0f * max_time - update_timer.getElapsedTimeF32(); +} + +F32 LLViewerRegion::createVisibleObjects(F32 max_time) +{ + if(mImpl->mWaitingList.empty()) + { + return max_time; + } - if(timeout) + LLTimer update_timer; + S32 max_num_objects = 64; //minimum number of new objects to be added + for(LLVOCacheEntry::vocache_entry_priority_list_t::iterator iter = mImpl->mWaitingList.begin(); + iter != mImpl->mWaitingList.end(); ++iter) { - return -1.0f; + LLVOCacheEntry* vo_entry = *iter; + + if(vo_entry->getState() < LLVOCacheEntry::WAITING) + { + addNewObject(vo_entry); + if(max_num_objects-- < 0 && update_timer.getElapsedTimeF32() > max_time) + { + break; + } + } } + mImpl->mWaitingList.clear(); + return max_time - update_timer.getElapsedTimeF32(); } @@ -1057,7 +1096,7 @@ BOOL LLViewerRegion::idleUpdate(F32 max_update_time) } max_update_time -= update_timer.getElapsedTimeF32(); - if(max_update_time < 0.f) + if(max_update_time < 0.f || mImpl->mCacheMap.empty()) { return did_update; } @@ -1065,20 +1104,14 @@ BOOL LLViewerRegion::idleUpdate(F32 max_update_time) sCurRegionp = this; //kill invisible objects - max_update_time = killInvisibleObjects(max_update_time); - - S32 new_object_count = 64; //minimum number of new objects to be added + max_update_time = killInvisibleObjects(max_update_time); - //add childrens of visible objects to the rendering pipeline - max_update_time = addLinkedSetChildren(max_update_time, new_object_count); - - //add objects in the visible groups to the rendering pipeline - if(max_update_time > 0.f) - { - addVisibleObjects(max_update_time, new_object_count); - } + max_update_time = updateVisibleEntries(max_update_time); + createVisibleObjects(max_update_time); mImpl->mVisibleGroups.clear(); + mImpl->mWaitingList.clear(); + sCurRegionp = NULL; return did_update; } @@ -1687,7 +1720,7 @@ LLVOCacheEntry* LLViewerRegion::getCacheEntry(U32 local_id) // Get data packer for this object, if we have cached data // AND the CRC matches. JC -LLDataPacker *LLViewerRegion::getDP(U32 local_id, U32 crc, U8 &cache_miss_type) +bool LLViewerRegion::probeCache(U32 local_id, U32 crc, U8 &cache_miss_type) { //llassert(mCacheLoaded); This assert failes often, changing to early-out -- davep, 2010/10/18 @@ -1702,7 +1735,51 @@ LLDataPacker *LLViewerRegion::getDP(U32 local_id, U32 crc, U8 &cache_miss_type) entry->recordHit(); cache_miss_type = CACHE_MISS_TYPE_NONE; - return entry->getDP(crc); + if(entry->getGroup() || !entry->isState(LLVOCacheEntry::INACTIVE)) + { + return true; + } + + addVisibleCacheEntry(entry); +#if 0 + if(entry->isBridgeChild()) //bridge child + { + addVisibleCacheEntry(entry); + } + else + { + U32 parent_id = entry->getParentID(); + if(parent_id > 0) //has parent + { + LLVOCacheEntry* parent = getCacheEntry(parent_id); + + if(parent) //parent cached + { + parent->addChild(entry); + + if(parent->isState(LLVOCacheEntry::INACTIVE)) + { + //addToVOCacheTree(parent); + addVisibleCacheEntry(parent); + } + else //parent visible + { + addVisibleCacheEntry(parent); + } + } + else //parent not cached. This should not happen, but just in case... + { + addVisibleCacheEntry(entry); + } + } + else //root node + { + //addToVOCacheTree(entry); + addVisibleCacheEntry(entry); + } + } +#endif + return true; } else { @@ -1718,7 +1795,7 @@ LLDataPacker *LLViewerRegion::getDP(U32 local_id, U32 crc, U8 &cache_miss_type) mCacheMissFull.put(local_id); } - return NULL; + return false; } void LLViewerRegion::addCacheMissFull(const U32 local_id) diff --git a/indra/newview/llviewerregion.h b/indra/newview/llviewerregion.h index 86d3ee0d8c..9a47227f1c 100644 --- a/indra/newview/llviewerregion.h +++ b/indra/newview/llviewerregion.h @@ -317,7 +317,7 @@ public: // handle a full update message eCacheUpdateResult cacheFullUpdate(LLViewerObject* objectp, LLDataPackerBinaryBuffer &dp); LLVOCacheEntry* getCacheEntryForOctree(U32 local_id); - LLDataPacker *getDP(U32 local_id, U32 crc, U8 &cache_miss_type); + bool probeCache(U32 local_id, U32 crc, U8 &cache_miss_type); void requestCacheMisses(); void addCacheMissFull(const U32 local_id); @@ -354,8 +354,8 @@ private: void killCacheEntry(LLVOCacheEntry* entry); //physically delete the cache entry F32 killInvisibleObjects(F32 max_time); - F32 addLinkedSetChildren(F32 max_time, S32& max_num_objects); - F32 addVisibleObjects(F32 max_time, S32& max_num_objects); + F32 createVisibleObjects(F32 max_time); + F32 updateVisibleEntries(F32 max_time); //update visible entries public: struct CompareDistance diff --git a/indra/newview/llvocache.cpp b/indra/newview/llvocache.cpp index db6aa9cd00..ec8585852b 100644 --- a/indra/newview/llvocache.cpp +++ b/indra/newview/llvocache.cpp @@ -32,6 +32,7 @@ #include "llviewerobjectlist.h" #include "lldrawable.h" #include "llviewerregion.h" +#include "pipeline.h" BOOL check_read(LLAPRFile* apr_file, void* src, S32 n_bytes) { @@ -57,11 +58,24 @@ LLVOCacheEntry::LLVOCacheEntry(U32 local_id, U32 crc, LLDataPackerBinaryBuffer & mCRCChangeCount(0), mState(INACTIVE), mRepeatedVisCounter(0), - mVisFrameRange(64) + mVisFrameRange(64), + mSceneContrib(0.f) { mBuffer = new U8[dp.getBufferSize()]; mDP.assignBuffer(mBuffer, dp.getBufferSize()); mDP = dp; + + if(dp.getBufferSize() > 0) + { + U32 parent_id = 0; + dp.reset(); + dp.unpackU32(parent_id, "ParentID"); + dp.reset(); + if(parent_id > 0) + { + mState |= CHILD; //is a child + } + } } LLVOCacheEntry::LLVOCacheEntry() @@ -74,7 +88,8 @@ LLVOCacheEntry::LLVOCacheEntry() mBuffer(NULL), mState(INACTIVE), mRepeatedVisCounter(0), - mVisFrameRange(64) + mVisFrameRange(64), + mSceneContrib(0.f) { mDP.assignBuffer(mBuffer, 0); } @@ -84,7 +99,8 @@ LLVOCacheEntry::LLVOCacheEntry(LLAPRFile* apr_file) mBuffer(NULL), mState(INACTIVE), mRepeatedVisCounter(0), - mVisFrameRange(64) + mVisFrameRange(64), + mSceneContrib(0.f) { S32 size = -1; BOOL success; @@ -110,6 +126,10 @@ LLVOCacheEntry::LLVOCacheEntry(LLAPRFile* apr_file) success = check_read(apr_file, &mCRCChangeCount, sizeof(S32)); } if(success) + { + success = check_read(apr_file, &mState, sizeof(U32)); + } + if(success) { F32 ext[8]; success = check_read(apr_file, (void*)ext, sizeof(F32) * 8); @@ -174,6 +194,7 @@ LLVOCacheEntry::LLVOCacheEntry(LLAPRFile* apr_file) mCRCChangeCount = 0; mBuffer = NULL; mEntry = NULL; + mState = 0; } } @@ -203,11 +224,40 @@ void LLVOCacheEntry::setOctreeEntry(LLViewerOctreeEntry* entry) LLViewerOctreeEntryData::setOctreeEntry(entry); } +void LLVOCacheEntry::setBridgeChild() +{ + mState |= BRIDGE_CHILD; +} + +void LLVOCacheEntry::clearBridgeChild() +{ + mState &= ~BRIDGE_CHILD; +} + +void LLVOCacheEntry::copy(LLVOCacheEntry* entry) +{ + //copy LLViewerOctreeEntry + LLViewerOctreeEntry* oct_entry = entry->getEntry(); + if(!oct_entry) + { + setOctreeEntry(oct_entry); + } + + //copy children + S32 num_children = entry->getNumOfChildren(); + for(S32 i = 0; i < num_children; i++) + { + addChild(entry->getChild(i)); + } +} + void LLVOCacheEntry::setState(U32 state) { - mState = state; + mState &= 0xffff0000; //clear the low 16 bits + state &= 0x0000ffff; //clear the high 16 bits; + mState |= state; - if(mState == ACTIVE) + if(getState() == ACTIVE) { const S32 MIN_REAVTIVE_INTERVAL = 20; U32 last_visible = getVisible(); @@ -247,37 +297,6 @@ void LLVOCacheEntry::addChild(LLVOCacheEntry* entry) mChildrenList.push_back(entry); } -LLVOCacheEntry* LLVOCacheEntry::getNextChild() -{ - S32 size = mChildrenList.size(); - if(!size) - { - return NULL; - } - - LLVOCacheEntry* entry = mChildrenList[size - 1]; - mChildrenList.pop_back(); //remove the entry; - - return entry; -} - -// New CRC means the object has changed. -void LLVOCacheEntry::assignCRC(U32 crc, LLDataPackerBinaryBuffer &dp) -{ - if ( (mCRC != crc) - ||(mDP.getBufferSize() == 0)) - { - mCRC = crc; - mHitCount = 0; - mCRCChangeCount++; - - mDP.freeBuffer(); - mBuffer = new U8[dp.getBufferSize()]; - mDP.assignBuffer(mBuffer, dp.getBufferSize()); - mDP = dp; - } -} - LLDataPackerBinaryBuffer *LLVOCacheEntry::getDP(U32 crc) { if ( (mCRC != crc) @@ -343,6 +362,11 @@ BOOL LLVOCacheEntry::writeToFile(LLAPRFile* apr_file) const success = check_write(apr_file, (void*)&mCRCChangeCount, sizeof(S32)); } if(success) + { + U32 state = mState & 0xffff0000; //only store the high 16 bits. + success = check_write(apr_file, (void*)&state, sizeof(U32)); + } + if(success) { const LLVector4a* exts = getSpatialExtents() ; LLVector4 ext(exts[0][0], exts[0][1], exts[0][2], exts[0][3]); @@ -378,6 +402,46 @@ 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(); +} + +U32 LLVOCacheEntry::getParentID() +{ + if(!(mState & CHILD)) + { + return 0; //not a child + } + + U32 parent_id = 0; + LLDataPackerBinaryBuffer* dp = getDP(); + if(dp) + { + dp->reset(); + dp->unpackU32(parent_id, "ParentID"); + dp->reset(); + } + return parent_id; +} + //------------------------------------------------------------------- //LLVOCachePartition //------------------------------------------------------------------- diff --git a/indra/newview/llvocache.h b/indra/newview/llvocache.h index 675c12a3eb..ded29dd990 100644 --- a/indra/newview/llvocache.h +++ b/indra/newview/llvocache.h @@ -36,17 +36,47 @@ //--------------------------------------------------------------------------- // Cache entries class LLVOCacheEntry; +class LLCamera; class LLVOCacheEntry : public LLViewerOctreeEntryData { public: enum { - INACTIVE = 0, - WAITING, - ACTIVE + INACTIVE = 0x00000000, //not visible + IN_QUEUE = 0x00000001, //in visible queue, object to be created + WAITING = 0x00000002, //object creation request sent + ACTIVE = 0x00000004 //object created, and in rendering pipeline. }; + enum + { + CHILD = 0x00010000, //has parent + BRIDGE_CHILD = 0x00020000 //is a child of a spatial bridge. + }; + + struct CompareVOCacheEntry + { + bool operator()(const LLVOCacheEntry* const& lhs, const LLVOCacheEntry* const& rhs) + { + F32 lpa = lhs->getSceneContribution(); + F32 rpa = rhs->getSceneContribution(); + + //larger pixel area first + if(lpa > rpa) + { + return true; + } + else if(lpa < rpa) + { + return false; + } + else + { + return lhs < rhs; + } + } + }; protected: ~LLVOCacheEntry(); public: @@ -55,33 +85,45 @@ public: LLVOCacheEntry(); void setState(U32 state); - bool isState(U32 state) {return mState == state;} - U32 getState() const {return mState;} + bool isState(U32 state) {return (mState & 0xffff) == state;} + U32 getState() const {return (mState & 0xffff);} + U32 getFullState() const {return mState;} + + void setBridgeChild(); + void clearBridgeChild(); + bool isBridgeChild() {return mState & BRIDGE_CHILD;} U32 getLocalID() const { return mLocalID; } U32 getCRC() const { return mCRC; } S32 getHitCount() const { return mHitCount; } S32 getCRCChangeCount() const { return mCRCChangeCount; } - S32 getMinVisFrameRange()const; + S32 getMinVisFrameRange()const; + U32 getParentID(); + + void calcSceneContribution(const LLVector3& camera_origin, bool needs_update, U32 last_update); + void setSceneContribution(F32 scene_contrib) {mSceneContrib = scene_contrib;} + F32 getSceneContribution() const { return mSceneContrib;} void dump() const; BOOL writeToFile(LLAPRFile* apr_file) const; - void assignCRC(U32 crc, LLDataPackerBinaryBuffer &dp); LLDataPackerBinaryBuffer *getDP(U32 crc); LLDataPackerBinaryBuffer *getDP(); void recordHit(); void recordDupe() { mDupeCount++; } + void copy(LLVOCacheEntry* entry); //copy variables /*virtual*/ void setOctreeEntry(LLViewerOctreeEntry* entry); void addChild(LLVOCacheEntry* entry); - LLVOCacheEntry* getNextChild(); - S32 getNumOfChildren() {return mChildrenList.size();} - bool isDummy() {return !mBuffer;} + LLVOCacheEntry* getChild(S32 i) {return mChildrenList[i];} + S32 getNumOfChildren() {return mChildrenList.size();} + void clearChildrenList() {mChildrenList.clear();} + bool isDummy() {return !mBuffer;} public: - typedef std::map > vocache_entry_map_t; - typedef std::set vocache_entry_set_t; + typedef std::map > vocache_entry_map_t; + typedef std::set vocache_entry_set_t; + typedef std::set vocache_entry_priority_list_t; protected: U32 mLocalID; @@ -92,9 +134,10 @@ protected: LLDataPackerBinaryBuffer mDP; U8 *mBuffer; + F32 mSceneContrib; //projected scene contributuion of this object. S32 mVisFrameRange; S32 mRepeatedVisCounter; //number of repeatedly visible within a short time. - U32 mState; + U32 mState; //high 16 bits reserved for special use. std::vector mChildrenList; //children entries in a linked set. }; -- cgit v1.3 From e1247d631f24065a31d9668915cb8bc84f3abc7f Mon Sep 17 00:00:00 2001 From: Xiaohong Bao Date: Tue, 18 Dec 2012 14:36:46 -0700 Subject: fix for SH-3619: some objects are missing --- indra/llmath/llcamera.cpp | 50 ++++++++++++++++++-- indra/llmath/llcamera.h | 8 +++- indra/newview/lldrawable.cpp | 13 ------ indra/newview/llvieweroctree.cpp | 50 ++++++++++++++++++-- indra/newview/llvieweroctree.h | 19 ++++++-- indra/newview/llviewerregion.cpp | 98 ++++++++++++---------------------------- indra/newview/llviewerregion.h | 1 + indra/newview/llvocache.cpp | 49 ++++++++++---------- indra/newview/llvocache.h | 2 - indra/newview/llworld.cpp | 1 + 10 files changed, 168 insertions(+), 123 deletions(-) (limited to 'indra/newview/lldrawable.cpp') diff --git a/indra/llmath/llcamera.cpp b/indra/llmath/llcamera.cpp index 22ba26f99b..6551b52462 100644 --- a/indra/llmath/llcamera.cpp +++ b/indra/llmath/llcamera.cpp @@ -161,7 +161,7 @@ size_t LLCamera::readFrustumFromBuffer(const char *buffer) // ---------------- test methods ---------------- -S32 LLCamera::AABBInFrustum(const LLVector4a ¢er, const LLVector4a& radius) +S32 LLCamera::AABBInFrustum(const LLVector4a ¢er, const LLVector4a& radius, const LLPlane* planes) { static const LLVector4a scaler[] = { LLVector4a(-1,-1,-1), @@ -174,6 +174,12 @@ S32 LLCamera::AABBInFrustum(const LLVector4a ¢er, const LLVector4a& radius) LLVector4a( 1, 1, 1) }; + if(!planes) + { + //use agent space + planes = mAgentPlanes; + } + U8 mask = 0; bool result = false; LLVector4a rscale, maxp, minp; @@ -183,7 +189,7 @@ S32 LLCamera::AABBInFrustum(const LLVector4a ¢er, const LLVector4a& radius) mask = mPlaneMask[i]; if (mask != 0xff) { - const LLPlane& p(mAgentPlanes[i]); + const LLPlane& p(planes[i]); p.getAt<3>(d); rscale.setMul(radius, scaler[mask]); minp.setSub(center, rscale); @@ -204,8 +210,14 @@ S32 LLCamera::AABBInFrustum(const LLVector4a ¢er, const LLVector4a& radius) return result?1:2; } +//exactly same as the function AABBInFrustum(...) +//except uses mRegionPlanes instead of mAgentPlanes. +S32 LLCamera::AABBInRegionFrustum(const LLVector4a& center, const LLVector4a& radius) +{ + return AABBInFrustum(center, radius, mRegionPlanes); +} -S32 LLCamera::AABBInFrustumNoFarClip(const LLVector4a& center, const LLVector4a& radius) +S32 LLCamera::AABBInFrustumNoFarClip(const LLVector4a& center, const LLVector4a& radius, const LLPlane* planes) { static const LLVector4a scaler[] = { LLVector4a(-1,-1,-1), @@ -218,6 +230,12 @@ S32 LLCamera::AABBInFrustumNoFarClip(const LLVector4a& center, const LLVector4a& LLVector4a( 1, 1, 1) }; + if(!planes) + { + //use agent space + planes = mAgentPlanes; + } + U8 mask = 0; bool result = false; LLVector4a rscale, maxp, minp; @@ -227,7 +245,7 @@ S32 LLCamera::AABBInFrustumNoFarClip(const LLVector4a& center, const LLVector4a& mask = mPlaneMask[i]; if ((i != 5) && (mask != 0xff)) { - const LLPlane& p(mAgentPlanes[i]); + const LLPlane& p(planes[i]); p.getAt<3>(d); rscale.setMul(radius, scaler[mask]); minp.setSub(center, rscale); @@ -248,6 +266,13 @@ S32 LLCamera::AABBInFrustumNoFarClip(const LLVector4a& center, const LLVector4a& return result?1:2; } +//exactly same as the function AABBInFrustumNoFarClip(...) +//except uses mRegionPlanes instead of mAgentPlanes. +S32 LLCamera::AABBInRegionFrustumNoFarClip(const LLVector4a& center, const LLVector4a& radius) +{ + return AABBInFrustumNoFarClip(center, radius, mRegionPlanes); +} + int LLCamera::sphereInFrustumQuick(const LLVector3 &sphere_center, const F32 radius) { LLVector3 dist = sphere_center-mFrustCenter; @@ -584,6 +609,23 @@ void LLCamera::calcAgentFrustumPlanes(LLVector3* frust) } } +//calculate regional planes from mAgentPlanes. +//vector "shift" is the vector of the region origin in the agent space. +void LLCamera::calcRegionFrustumPlanes(const LLVector3& shift) +{ + F32 d; + LLVector3 n; + for(S32 i = 0 ; i < 7; i++) + { + if (mPlaneMask[i] != 0xff) + { + n.setVec(mAgentPlanes[i][0], mAgentPlanes[i][1], mAgentPlanes[i][2]); + d = mAgentPlanes[i][3] - n * shift; + mRegionPlanes[i].setVec(n, d); + } + } +} + void LLCamera::calculateFrustumPlanes(F32 left, F32 right, F32 top, F32 bottom) { LLVector3 a, b, c; diff --git a/indra/llmath/llcamera.h b/indra/llmath/llcamera.h index 0b591be622..898d73ed7e 100644 --- a/indra/llmath/llcamera.h +++ b/indra/llmath/llcamera.h @@ -109,6 +109,7 @@ public: private: LL_ALIGN_16(LLPlane mAgentPlanes[7]); //frustum planes in agent space a la gluUnproject (I'm a bastard, I know) - DaveP + LL_ALIGN_16(LLPlane mRegionPlanes[7]); //frustum planes in a local region space, derived from mAgentPlanes U8 mPlaneMask[8]; // 8 for alignment F32 mView; // angle between top and bottom frustum planes in radians. @@ -178,6 +179,7 @@ public: // Return number of bytes copied. size_t readFrustumFromBuffer(const char *buffer); void calcAgentFrustumPlanes(LLVector3* frust); + void calcRegionFrustumPlanes(const LLVector3& shift); //calculate regional planes from mAgentPlanes. void ignoreAgentFrustumPlane(S32 idx); // Returns 1 if partly in, 2 if fully in. @@ -186,8 +188,10 @@ public: S32 sphereInFrustum(const LLVector3 ¢er, const F32 radius) const; S32 pointInFrustum(const LLVector3 &point) const { return sphereInFrustum(point, 0.0f); } S32 sphereInFrustumFull(const LLVector3 ¢er, const F32 radius) const { return sphereInFrustum(center, radius); } - S32 AABBInFrustum(const LLVector4a& center, const LLVector4a& radius); - S32 AABBInFrustumNoFarClip(const LLVector4a& center, const LLVector4a& radius); + S32 AABBInFrustum(const LLVector4a& center, const LLVector4a& radius, const LLPlane* planes = NULL); + S32 AABBInRegionFrustum(const LLVector4a& center, const LLVector4a& radius); + S32 AABBInFrustumNoFarClip(const LLVector4a& center, const LLVector4a& radius, const LLPlane* planes = NULL); + S32 AABBInRegionFrustumNoFarClip(const LLVector4a& center, const LLVector4a& radius); //does a quick 'n dirty sphere-sphere check S32 sphereInFrustumQuick(const LLVector3 &sphere_center, const F32 radius); diff --git a/indra/newview/lldrawable.cpp b/indra/newview/lldrawable.cpp index c782fbfe7e..1b7a98ba54 100644 --- a/indra/newview/lldrawable.cpp +++ b/indra/newview/lldrawable.cpp @@ -1473,19 +1473,6 @@ void LLSpatialBridge::shiftPos(const LLVector4a& vec) void LLSpatialBridge::cleanupReferences() { - LLPointer dummy_entry; - if (mDrawable && mDrawable->isDead() && mDrawable->getEntry()->hasVOCacheEntry()) - { - //create a dummy entry to insert the entire LLSpatialBridge to the vo_cache partition so it can be reloaded. - - dummy_entry = new LLVOCacheEntry(); - dummy_entry->setOctreeEntry(mEntry); - dummy_entry->addChild((LLVOCacheEntry*)mDrawable->getEntry()->getVOCacheEntry()); - //llassert(!mDrawable->getParent()); - - //mDrawable->mParent = this; - } - LLDrawable::cleanupReferences(); if (mDrawable) { diff --git a/indra/newview/llvieweroctree.cpp b/indra/newview/llvieweroctree.cpp index b6e0674a95..7f502a6c51 100644 --- a/indra/newview/llvieweroctree.cpp +++ b/indra/newview/llvieweroctree.cpp @@ -675,6 +675,8 @@ void LLViewerOctreeCull::traverse(const OctreeNode* n) } } +//------------------------------------------ +//agent space group culling S32 LLViewerOctreeCull::AABBInFrustumNoFarClipGroupBounds(const LLviewerOctreeGroup* group) { return mCamera->AABBInFrustumNoFarClip(group->mBounds[0], group->mBounds[1]); @@ -685,6 +687,14 @@ S32 LLViewerOctreeCull::AABBSphereIntersectGroupExtents(const LLviewerOctreeGrou return AABBSphereIntersect(group->mExtents[0], group->mExtents[1], mCamera->getOrigin(), mCamera->mFrustumCornerDist); } +S32 LLViewerOctreeCull::AABBInFrustumGroupBounds(const LLviewerOctreeGroup* group) +{ + return mCamera->AABBInFrustum(group->mBounds[0], group->mBounds[1]); +} +//------------------------------------------ + +//------------------------------------------ +//agent space object set culling S32 LLViewerOctreeCull::AABBInFrustumNoFarClipObjectBounds(const LLviewerOctreeGroup* group) { return mCamera->AABBInFrustumNoFarClip(group->mObjectBounds[0], group->mObjectBounds[1]); @@ -695,15 +705,47 @@ S32 LLViewerOctreeCull::AABBSphereIntersectObjectExtents(const LLviewerOctreeGro return AABBSphereIntersect(group->mObjectExtents[0], group->mObjectExtents[1], mCamera->getOrigin(), mCamera->mFrustumCornerDist); } -S32 LLViewerOctreeCull::AABBInFrustumGroupBounds(const LLviewerOctreeGroup* group) +S32 LLViewerOctreeCull::AABBInFrustumObjectBounds(const LLviewerOctreeGroup* group) { - return mCamera->AABBInFrustum(group->mBounds[0], group->mBounds[1]); + return mCamera->AABBInFrustum(group->mObjectBounds[0], group->mObjectBounds[1]); } +//------------------------------------------ -S32 LLViewerOctreeCull::AABBInFrustumObjectBounds(const LLviewerOctreeGroup* group) +//------------------------------------------ +//local regional space group culling +S32 LLViewerOctreeCull::AABBInRegionFrustumNoFarClipGroupBounds(const LLviewerOctreeGroup* group) { - return mCamera->AABBInFrustum(group->mObjectBounds[0], group->mObjectBounds[1]); + return mCamera->AABBInRegionFrustumNoFarClip(group->mBounds[0], group->mBounds[1]); +} + +S32 LLViewerOctreeCull::AABBInRegionFrustumGroupBounds(const LLviewerOctreeGroup* group) +{ + return mCamera->AABBInRegionFrustum(group->mBounds[0], group->mBounds[1]); +} + +S32 LLViewerOctreeCull::AABBRegionSphereIntersectGroupExtents(const LLviewerOctreeGroup* group, const LLVector3& shift) +{ + return AABBSphereIntersect(group->mExtents[0], group->mExtents[1], mCamera->getOrigin() - shift, mCamera->mFrustumCornerDist); +} +//------------------------------------------ + +//------------------------------------------ +//local regional space object culling +S32 LLViewerOctreeCull::AABBInRegionFrustumObjectBounds(const LLviewerOctreeGroup* group) +{ + return mCamera->AABBInRegionFrustum(group->mObjectBounds[0], group->mObjectBounds[1]); +} + +S32 LLViewerOctreeCull::AABBInRegionFrustumNoFarClipObjectBounds(const LLviewerOctreeGroup* group) +{ + return mCamera->AABBInRegionFrustumNoFarClip(group->mObjectBounds[0], group->mObjectBounds[1]); +} + +S32 LLViewerOctreeCull::AABBRegionSphereIntersectObjectExtents(const LLviewerOctreeGroup* group, const LLVector3& shift) +{ + return AABBSphereIntersect(group->mObjectExtents[0], group->mObjectExtents[1], mCamera->getOrigin() - shift, mCamera->mFrustumCornerDist); } +//------------------------------------------ //virtual bool LLViewerOctreeCull::checkObjects(const OctreeNode* branch, const LLviewerOctreeGroup* group) diff --git a/indra/newview/llvieweroctree.h b/indra/newview/llvieweroctree.h index b89014119c..f6ad3ac327 100644 --- a/indra/newview/llvieweroctree.h +++ b/indra/newview/llvieweroctree.h @@ -280,13 +280,26 @@ public: virtual bool earlyFail(LLviewerOctreeGroup* group); virtual void traverse(const OctreeNode* n); - S32 AABBInFrustumNoFarClipGroupBounds(const LLviewerOctreeGroup* group); + //agent space group cull + S32 AABBInFrustumNoFarClipGroupBounds(const LLviewerOctreeGroup* group); S32 AABBSphereIntersectGroupExtents(const LLviewerOctreeGroup* group); - S32 AABBInFrustumNoFarClipObjectBounds(const LLviewerOctreeGroup* group); - S32 AABBSphereIntersectObjectExtents(const LLviewerOctreeGroup* group); S32 AABBInFrustumGroupBounds(const LLviewerOctreeGroup* group); + + //agent space object set cull + S32 AABBInFrustumNoFarClipObjectBounds(const LLviewerOctreeGroup* group); + S32 AABBSphereIntersectObjectExtents(const LLviewerOctreeGroup* group); S32 AABBInFrustumObjectBounds(const LLviewerOctreeGroup* group); + //local region space group cull + S32 AABBInRegionFrustumNoFarClipGroupBounds(const LLviewerOctreeGroup* group); + S32 AABBInRegionFrustumGroupBounds(const LLviewerOctreeGroup* group); + S32 AABBRegionSphereIntersectGroupExtents(const LLviewerOctreeGroup* group, const LLVector3& shift); + + //local region space object set cull + S32 AABBInRegionFrustumNoFarClipObjectBounds(const LLviewerOctreeGroup* group); + S32 AABBInRegionFrustumObjectBounds(const LLviewerOctreeGroup* group); + S32 AABBRegionSphereIntersectObjectExtents(const LLviewerOctreeGroup* group, const LLVector3& shift); + virtual S32 frustumCheck(const LLviewerOctreeGroup* group) = 0; virtual S32 frustumCheckObjects(const LLviewerOctreeGroup* group) = 0; diff --git a/indra/newview/llviewerregion.cpp b/indra/newview/llviewerregion.cpp index ab692308b0..33e8348660 100644 --- a/indra/newview/llviewerregion.cpp +++ b/indra/newview/llviewerregion.cpp @@ -87,6 +87,7 @@ const F32 CAP_REQUEST_TIMEOUT = 18; const S32 MAX_CAP_REQUEST_ATTEMPTS = 30; LLViewerRegion* LLViewerRegion::sCurRegionp = NULL; +BOOL LLViewerRegion::sVOCacheCullingEnabled = FALSE; typedef std::map CapabilityMap; @@ -141,7 +142,6 @@ public: LLVOCacheEntry::vocache_entry_map_t mCacheMap; //all cached entries LLVOCacheEntry::vocache_entry_set_t mActiveSet; //all active entries; LLVOCacheEntry::vocache_entry_set_t mWaitingSet; //entries waiting for LLDrawable to be generated. - std::set< LLPointer > mDummyEntries; //dummy vo cache entries, for LLSpatialBridge use. std::set< LLviewerOctreeGroup* > mVisibleGroups; //visible groupa LLVOCachePartition* mVOCachePartition; LLVOCacheEntry::vocache_entry_set_t mVisibleEntries; //must-be-created visible entries wait for objects creation. @@ -841,17 +841,8 @@ void LLViewerRegion::removeActiveCacheEntry(LLVOCacheEntry* entry, LLDrawable* d { return; } - if(entry->isDummy()) - { - mImpl->mDummyEntries.insert(entry); //keep a copy to prevent from being deleted. - addToVOCacheTree(entry); - } - else if(!drawablep->getParent()) //root node - { - addToVOCacheTree(entry); - mImpl->mVisibleEntries.erase(entry); - } - else //child node + + if(drawablep->getParent()) //child object { LLViewerOctreeEntry* parent_oct_entry = drawablep->getParent()->getEntry(); if(parent_oct_entry && parent_oct_entry->hasVOCacheEntry()) @@ -860,7 +851,19 @@ void LLViewerRegion::removeActiveCacheEntry(LLVOCacheEntry* entry, LLDrawable* d parent->addChild(entry); } } + else //insert to vo cache tree. + { + //shift to the local regional space from agent space + const LLVector3 pos = drawablep->getVObj()->getPositionRegion(); + LLVector4a vec(pos[0], pos[1], pos[2]); + LLVector4a shift; + shift.setSub(vec, entry->getPositionGroup()); + entry->shift(shift); + + addToVOCacheTree(entry); + } + mImpl->mVisibleEntries.erase(entry); mImpl->mActiveSet.erase(entry); mImpl->mWaitingSet.erase(entry); entry->setState(LLVOCacheEntry::INACTIVE); @@ -878,7 +881,10 @@ void LLViewerRegion::addVisibleGroup(LLviewerOctreeGroup* group) void LLViewerRegion::addToVOCacheTree(LLVOCacheEntry* entry) { - static BOOL vo_cache_culling_enabled = gSavedSettings.getBOOL("ObjectCacheViewCullingEnabled"); + if(!sVOCacheCullingEnabled) + { + return; + } if(mDead || !entry || !entry->getEntry()) { @@ -954,12 +960,13 @@ F32 LLViewerRegion::updateVisibleEntries(F32 max_time) //process visible entries max_time *= 0.5f; //only use up to half available time to update entries. +#if 1 for(LLVOCacheEntry::vocache_entry_set_t::iterator iter = mImpl->mVisibleEntries.begin(); iter != mImpl->mVisibleEntries.end();) { LLVOCacheEntry* vo_entry = *iter; vo_entry->calcSceneContribution(camera_origin, needs_update, mImpl->mLastCameraUpdate); - if(vo_entry->getState() < LLVOCacheEntry::WAITING && !vo_entry->isDummy()) + if(vo_entry->getState() < LLVOCacheEntry::WAITING) { mImpl->mWaitingList.insert(vo_entry); } @@ -987,12 +994,7 @@ F32 LLViewerRegion::updateVisibleEntries(F32 max_time) if(!vo_entry->getNumOfChildren()) { - if(vo_entry->isDummy()) - { - mImpl->mDummyEntries.erase(vo_entry); - iter = mImpl->mVisibleEntries.erase(iter); - } - else if(vo_entry->getState() >= LLVOCacheEntry::WAITING) + if(vo_entry->getState() >= LLVOCacheEntry::WAITING) { iter = mImpl->mVisibleEntries.erase(iter); } @@ -1011,6 +1013,7 @@ F32 LLViewerRegion::updateVisibleEntries(F32 max_time) // break; //} } +#endif //process visible groups std::set< LLviewerOctreeGroup* >::iterator group_iter = mImpl->mVisibleGroups.begin(); @@ -1027,11 +1030,6 @@ F32 LLViewerRegion::updateVisibleEntries(F32 max_time) if((*i)->hasVOCacheEntry()) { LLVOCacheEntry* vo_entry = (LLVOCacheEntry*)(*i)->getVOCacheEntry(); - if(vo_entry->isDummy()) - { - addVisibleCacheEntry(vo_entry); //for LLSpatialBridge. - continue; - } vo_entry->calcSceneContribution(camera_origin, needs_update, mImpl->mLastCameraUpdate); mImpl->mWaitingList.insert(vo_entry); @@ -1118,6 +1116,11 @@ BOOL LLViewerRegion::idleUpdate(F32 max_update_time) F32 LLViewerRegion::killInvisibleObjects(F32 max_time) { + if(!sVOCacheCullingEnabled) + { + return max_time; + } + std::vector delete_list; for(LLVOCacheEntry::vocache_entry_set_t::iterator iter = mImpl->mActiveSet.begin(); iter != mImpl->mActiveSet.end(); ++iter) @@ -1695,13 +1698,6 @@ LLViewerRegion::eCacheUpdateResult LLViewerRegion::cacheFullUpdate(LLViewerObjec LLVOCacheEntry* LLViewerRegion::getCacheEntryForOctree(U32 local_id) { - static BOOL vo_cache_culling_enabled = gSavedSettings.getBOOL("ObjectCacheViewCullingEnabled"); - - if(!vo_cache_culling_enabled) - { - return NULL; - } - LLVOCacheEntry* entry = getCacheEntry(local_id); removeFromVOCacheTree(entry); @@ -1741,44 +1737,6 @@ bool LLViewerRegion::probeCache(U32 local_id, U32 crc, U8 &cache_miss_type) } addVisibleCacheEntry(entry); -#if 0 - if(entry->isBridgeChild()) //bridge child - { - addVisibleCacheEntry(entry); - } - else - { - U32 parent_id = entry->getParentID(); - if(parent_id > 0) //has parent - { - LLVOCacheEntry* parent = getCacheEntry(parent_id); - - if(parent) //parent cached - { - parent->addChild(entry); - - if(parent->isState(LLVOCacheEntry::INACTIVE)) - { - //addToVOCacheTree(parent); - addVisibleCacheEntry(parent); - } - else //parent visible - { - addVisibleCacheEntry(parent); - } - } - else //parent not cached. This should not happen, but just in case... - { - addVisibleCacheEntry(entry); - } - } - else //root node - { - //addToVOCacheTree(entry); - addVisibleCacheEntry(entry); - } - } -#endif return true; } else diff --git a/indra/newview/llviewerregion.h b/indra/newview/llviewerregion.h index 9a47227f1c..dbc59cee8f 100644 --- a/indra/newview/llviewerregion.h +++ b/indra/newview/llviewerregion.h @@ -392,6 +392,7 @@ public: LLDynamicArray mMapAvatarIDs; static LLViewerRegion* sCurRegionp; + static BOOL sVOCacheCullingEnabled; //vo cache culling enabled or not. private: LLViewerRegionImpl * mImpl; diff --git a/indra/newview/llvocache.cpp b/indra/newview/llvocache.cpp index 8ea79dbae6..59645fdbe9 100644 --- a/indra/newview/llvocache.cpp +++ b/indra/newview/llvocache.cpp @@ -424,24 +424,6 @@ void LLVOCacheEntry::calcSceneContribution(const LLVector3& camera_origin, bool setVisible(); } -U32 LLVOCacheEntry::getParentID() -{ - if(!(mState & CHILD)) - { - return 0; //not a child - } - - U32 parent_id = 0; - LLDataPackerBinaryBuffer* dp = getDP(); - if(dp) - { - dp->reset(); - dp->unpackU32(parent_id, "ParentID"); - dp->reset(); - } - return parent_id; -} - //------------------------------------------------------------------- //LLVOCachePartition //------------------------------------------------------------------- @@ -471,24 +453,31 @@ void LLVOCachePartition::removeEntry(LLViewerOctreeEntry* entry) class LLVOCacheOctreeCull : public LLViewerOctreeCull { public: - LLVOCacheOctreeCull(LLCamera* camera, LLViewerRegion* regionp) : LLViewerOctreeCull(camera), mRegionp(regionp) {} + LLVOCacheOctreeCull(LLCamera* camera, LLViewerRegion* regionp, const LLVector3& shift) : LLViewerOctreeCull(camera), mRegionp(regionp) + { + mLocalShift = shift; + } virtual S32 frustumCheck(const LLviewerOctreeGroup* group) { - S32 res = AABBInFrustumNoFarClipGroupBounds(group); + //S32 res = AABBInRegionFrustumGroupBounds(group); + + S32 res = AABBInRegionFrustumNoFarClipGroupBounds(group); if (res != 0) { - res = llmin(res, AABBSphereIntersectGroupExtents(group)); + res = llmin(res, AABBRegionSphereIntersectGroupExtents(group, mLocalShift)); } return res; } virtual S32 frustumCheckObjects(const LLviewerOctreeGroup* group) { - S32 res = AABBInFrustumNoFarClipObjectBounds(group); + //S32 res = AABBInRegionFrustumObjectBounds(group); + + S32 res = AABBInRegionFrustumNoFarClipObjectBounds(group); if (res != 0) { - res = llmin(res, AABBSphereIntersectObjectExtents(group)); + res = llmin(res, AABBRegionSphereIntersectObjectExtents(group, mLocalShift)); } return res; } @@ -500,10 +489,16 @@ public: private: LLViewerRegion* mRegionp; + LLVector3 mLocalShift; //shift vector from agent space to local region space. }; S32 LLVOCachePartition::cull(LLCamera &camera) { + if(!LLViewerRegion::sVOCacheCullingEnabled) + { + return 0; + } + if(mVisitedTime == LLViewerOctreeEntryData::getCurrentFrame()) { return 0; //already visited. @@ -511,8 +506,12 @@ S32 LLVOCachePartition::cull(LLCamera &camera) mVisitedTime = LLViewerOctreeEntryData::getCurrentFrame(); ((LLviewerOctreeGroup*)mOctree->getListener(0))->rebound(); - - LLVOCacheOctreeCull culler(&camera, mRegionp); + + //localize the camera + LLVector3 region_agent = mRegionp->getOriginAgent(); + camera.calcRegionFrustumPlanes(region_agent); + + LLVOCacheOctreeCull culler(&camera, mRegionp, region_agent); culler.traverse(mOctree); return 0; diff --git a/indra/newview/llvocache.h b/indra/newview/llvocache.h index 4d058ffdac..f5cc5d2f75 100644 --- a/indra/newview/llvocache.h +++ b/indra/newview/llvocache.h @@ -98,7 +98,6 @@ public: S32 getHitCount() const { return mHitCount; } S32 getCRCChangeCount() const { return mCRCChangeCount; } S32 getMinVisFrameRange()const; - U32 getParentID(); void calcSceneContribution(const LLVector3& camera_origin, bool needs_update, U32 last_update); void setSceneContribution(F32 scene_contrib) {mSceneContrib = scene_contrib;} @@ -118,7 +117,6 @@ public: LLVOCacheEntry* getChild(S32 i) {return mChildrenList[i];} S32 getNumOfChildren() {return mChildrenList.size();} void clearChildrenList() {mChildrenList.clear();} - bool isDummy() {return !mBuffer;} public: typedef std::map > vocache_entry_map_t; diff --git a/indra/newview/llworld.cpp b/indra/newview/llworld.cpp index aed2835e4a..7a7d6a7b43 100644 --- a/indra/newview/llworld.cpp +++ b/indra/newview/llworld.cpp @@ -110,6 +110,7 @@ LLWorld::LLWorld() : gGL.getTexUnit(0)->bind(mDefaultWaterTexturep); mDefaultWaterTexturep->setAddressMode(LLTexUnit::TAM_CLAMP); + LLViewerRegion::sVOCacheCullingEnabled = (BOOL)gSavedSettings.getBOOL("ObjectCacheViewCullingEnabled"); } -- cgit v1.3 From 4e22f3e3ef15e24d7e9e0ad156e60d4cd1b2d5c9 Mon Sep 17 00:00:00 2001 From: Xiaohong Bao Date: Tue, 18 Dec 2012 23:16:50 -0700 Subject: fix for SH-3624: Object deletion does not work --- indra/newview/lldrawable.cpp | 5 ----- indra/newview/llviewerobject.cpp | 16 ++++++++++++++++ indra/newview/llviewerobject.h | 1 + indra/newview/llviewerobjectlist.cpp | 3 ++- indra/newview/llviewerobjectlist.h | 2 +- indra/newview/llviewerregion.cpp | 6 +++++- indra/newview/llvocache.cpp | 22 ---------------------- indra/newview/llvocache.h | 18 ++++++++---------- 8 files changed, 33 insertions(+), 40 deletions(-) (limited to 'indra/newview/lldrawable.cpp') diff --git a/indra/newview/lldrawable.cpp b/indra/newview/lldrawable.cpp index 1b7a98ba54..3c68ac231e 100644 --- a/indra/newview/lldrawable.cpp +++ b/indra/newview/lldrawable.cpp @@ -1099,11 +1099,6 @@ LLSpatialBridge::LLSpatialBridge(LLDrawable* root, BOOL render_by_group, U32 dat { part->put(this); } - - if(mDrawable->getEntry()->hasVOCacheEntry()) - { - ((LLVOCacheEntry*)mDrawable->getEntry()->getVOCacheEntry())->setBridgeChild(); - } } LLSpatialBridge::~LLSpatialBridge() diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp index dbccb2a4d9..2aa0e15fc3 100644 --- a/indra/newview/llviewerobject.cpp +++ b/indra/newview/llviewerobject.cpp @@ -323,6 +323,22 @@ void LLViewerObject::deleteTEImages() mTEImages = NULL; } +//if enabled, add this object to vo cache tree when removed from rendering. +void LLViewerObject::EnableToCacheTree(bool enabled) +{ + if(mDrawable.notNull() && mDrawable->getEntry() && mDrawable->getEntry()->hasVOCacheEntry()) + { + if(enabled) + { + ((LLVOCacheEntry*)mDrawable->getEntry()->getVOCacheEntry())->addState(LLVOCacheEntry::ADD_TO_CACHE_TREE); + } + else + { + ((LLVOCacheEntry*)mDrawable->getEntry()->getVOCacheEntry())->clearState(LLVOCacheEntry::ADD_TO_CACHE_TREE); + } + } +} + void LLViewerObject::markDead() { if (!mDead) diff --git a/indra/newview/llviewerobject.h b/indra/newview/llviewerobject.h index 02b4f84785..74b86600d4 100644 --- a/indra/newview/llviewerobject.h +++ b/indra/newview/llviewerobject.h @@ -132,6 +132,7 @@ public: BOOL isDead() const {return mDead;} BOOL isOrphaned() const { return mOrphaned; } BOOL isParticleSource() const; + void EnableToCacheTree(bool enabled); virtual LLVOAvatar* asAvatar(); diff --git a/indra/newview/llviewerobjectlist.cpp b/indra/newview/llviewerobjectlist.cpp index 5b2214f3b3..6e7ce103b5 100644 --- a/indra/newview/llviewerobjectlist.cpp +++ b/indra/newview/llviewerobjectlist.cpp @@ -1326,7 +1326,7 @@ void LLViewerObjectList::removeDrawable(LLDrawable* drawablep) } } -BOOL LLViewerObjectList::killObject(LLViewerObject *objectp) +BOOL LLViewerObjectList::killObject(LLViewerObject *objectp, bool cache_enabled) { // Don't ever kill gAgentAvatarp, just force it to the agent's region // unless region is NULL which is assumed to mean you are logging out. @@ -1341,6 +1341,7 @@ BOOL LLViewerObjectList::killObject(LLViewerObject *objectp) if (objectp) { + objectp->EnableToCacheTree(cache_enabled); //enable to add to VO cache tree if set. objectp->markDead(); // does the right thing if object already dead return TRUE; } diff --git a/indra/newview/llviewerobjectlist.h b/indra/newview/llviewerobjectlist.h index 3b26df7de6..0e2b34cb34 100644 --- a/indra/newview/llviewerobjectlist.h +++ b/indra/newview/llviewerobjectlist.h @@ -72,7 +72,7 @@ public: LLViewerObject *replaceObject(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp); // TomY: hack to switch VO instances on the fly - BOOL killObject(LLViewerObject *objectp); + BOOL killObject(LLViewerObject *objectp, bool cache_enabled = false); void killObjects(LLViewerRegion *regionp); // Kill all objects owned by a particular region. void killAllObjects(); void removeDrawable(LLDrawable* drawablep); diff --git a/indra/newview/llviewerregion.cpp b/indra/newview/llviewerregion.cpp index 33e8348660..c4b6cacae2 100644 --- a/indra/newview/llviewerregion.cpp +++ b/indra/newview/llviewerregion.cpp @@ -894,6 +894,10 @@ void LLViewerRegion::addToVOCacheTree(LLVOCacheEntry* entry) { return; } + if(!entry->hasState(LLVOCacheEntry::ADD_TO_CACHE_TREE)) + { + return; //can not add to vo cache tree. + } mImpl->mVOCachePartition->addEntry(entry->getEntry()); } @@ -1132,7 +1136,7 @@ F32 LLViewerRegion::killInvisibleObjects(F32 max_time) } for(S32 i = 0; i < delete_list.size(); i++) { - gObjectList.killObject(delete_list[i]->getVObj()); + gObjectList.killObject(delete_list[i]->getVObj(), true); } delete_list.clear(); diff --git a/indra/newview/llvocache.cpp b/indra/newview/llvocache.cpp index 59645fdbe9..86cfbb1d74 100644 --- a/indra/newview/llvocache.cpp +++ b/indra/newview/llvocache.cpp @@ -64,18 +64,6 @@ LLVOCacheEntry::LLVOCacheEntry(U32 local_id, U32 crc, LLDataPackerBinaryBuffer & mBuffer = new U8[dp.getBufferSize()]; mDP.assignBuffer(mBuffer, dp.getBufferSize()); mDP = dp; - - if(dp.getBufferSize() > 0) - { - U32 parent_id = 0; - dp.reset(); - dp.unpackU32(parent_id, "ParentID"); - dp.reset(); - if(parent_id > 0) - { - mState |= CHILD; //is a child - } - } } LLVOCacheEntry::LLVOCacheEntry() @@ -224,16 +212,6 @@ void LLVOCacheEntry::setOctreeEntry(LLViewerOctreeEntry* entry) LLViewerOctreeEntryData::setOctreeEntry(entry); } -void LLVOCacheEntry::setBridgeChild() -{ - mState |= BRIDGE_CHILD; -} - -void LLVOCacheEntry::clearBridgeChild() -{ - mState &= ~BRIDGE_CHILD; -} - void LLVOCacheEntry::copyTo(LLVOCacheEntry* new_entry) { //copy LLViewerOctreeEntry diff --git a/indra/newview/llvocache.h b/indra/newview/llvocache.h index f5cc5d2f75..c631e12739 100644 --- a/indra/newview/llvocache.h +++ b/indra/newview/llvocache.h @@ -51,8 +51,7 @@ public: enum { - CHILD = 0x00010000, //has parent - BRIDGE_CHILD = 0x00020000 //is a child of a spatial bridge. + ADD_TO_CACHE_TREE = 0x00010000, //has parent }; struct CompareVOCacheEntry @@ -85,14 +84,13 @@ public: LLVOCacheEntry(); void setState(U32 state); - bool isState(U32 state) {return (mState & 0xffff) == state;} - U32 getState() const {return (mState & 0xffff);} - U32 getFullState() const {return mState;} - - void setBridgeChild(); - void clearBridgeChild(); - bool isBridgeChild() {return mState & BRIDGE_CHILD;} - + void clearState(U32 state) {mState &= ~state;} + void addState(U32 state) {mState |= state;} + bool isState(U32 state) {return (mState & 0xffff) == state;} + bool hasState(U32 state) {return mState & state;} + U32 getState() const {return (mState & 0xffff);} + U32 getFullState() const {return mState;} + U32 getLocalID() const { return mLocalID; } U32 getCRC() const { return mCRC; } S32 getHitCount() const { return mHitCount; } -- cgit v1.3