Skip to content

Commit 16437af

Browse files
committed
viewer#3070 Improve handling of duplciate requests
1 parent b622868 commit 16437af

File tree

2 files changed

+59
-46
lines changed

2 files changed

+59
-46
lines changed

indra/newview/llmeshrepository.cpp

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ void LLMeshRepoThread::run()
11091109
}
11101110
else
11111111
{
1112-
LL_DEBUGS() << "mDecompositionRequests failed: " << req.mId << LL_ENDL;
1112+
LL_DEBUGS(LOG_MESH) << "mDecompositionRequests failed: " << req.mId << LL_ENDL;
11131113
}
11141114
}
11151115
}
@@ -1145,7 +1145,7 @@ void LLMeshRepoThread::run()
11451145
}
11461146
else
11471147
{
1148-
LL_DEBUGS() << "mPhysicsShapeRequests failed: " << req.mId << LL_ENDL;
1148+
LL_DEBUGS(LOG_MESH) << "mPhysicsShapeRequests failed: " << req.mId << LL_ENDL;
11491149
}
11501150
}
11511151
}
@@ -1206,6 +1206,25 @@ void LLMeshRepoThread::loadMeshLOD(const LLVolumeParams& mesh_params, S32 lod)
12061206
const LLUUID& mesh_id = mesh_params.getSculptID();
12071207
LLMutexLock lock(mMutex);
12081208
LLMutexLock header_lock(mHeaderMutex);
1209+
loadMeshLOD(mesh_id, mesh_params, lod);
1210+
}
1211+
1212+
void LLMeshRepoThread::loadMeshLODs(const lod_list_t& list)
1213+
{ //could be called from any thread
1214+
LLMutexLock lock(mMutex);
1215+
LLMutexLock header_lock(mHeaderMutex);
1216+
for (auto lod_pair : list)
1217+
{
1218+
const LLVolumeParams& mesh_params = lod_pair.first;
1219+
const LLUUID& mesh_id = mesh_params.getSculptID();
1220+
S32 lod = lod_pair.second;
1221+
loadMeshLOD(mesh_id, mesh_params, lod);
1222+
}
1223+
}
1224+
1225+
void LLMeshRepoThread::loadMeshLOD(const LLUUID& mesh_id, const LLVolumeParams& mesh_params, S32 lod)
1226+
{
1227+
// must be mutex locked by caller
12091228
mesh_header_map::iterator iter = mMeshHeader.find(mesh_id);
12101229
if (iter != mMeshHeader.end())
12111230
{ //if we have the header, request LOD byte range
@@ -1222,50 +1241,25 @@ void LLMeshRepoThread::loadMeshLOD(const LLVolumeParams& mesh_params, S32 lod)
12221241
pending_lod_map::iterator pending = mPendingLOD.find(mesh_id);
12231242

12241243
if (pending != mPendingLOD.end())
1225-
{ //append this lod request to existing header request
1226-
pending->second.push_back(lod);
1227-
llassert(pending->second.size() <= LLModel::NUM_LODS);
1228-
}
1229-
else
1230-
{ //if no header request is pending, fetch header
1231-
mHeaderReqQ.push(req);
1232-
mPendingLOD[mesh_id].push_back(lod);
1233-
}
1234-
}
1235-
}
1236-
1237-
void LLMeshRepoThread::loadMeshLODs(const lod_list_t& list)
1238-
{ //could be called from any thread
1239-
LLMutexLock lock(mMutex);
1240-
LLMutexLock header_lock(mHeaderMutex);
1241-
for (auto lod_pair : list)
1242-
{
1243-
const LLVolumeParams& mesh_params = lod_pair.first;
1244-
const LLUUID& mesh_id = mesh_params.getSculptID();
1245-
S32 lod = lod_pair.second;
1246-
mesh_header_map::iterator iter = mMeshHeader.find(mesh_id);
1247-
if (iter != mMeshHeader.end())
1248-
{ // if we have the header, request LOD byte range
1249-
LODRequest req(mesh_params, lod);
1244+
{
1245+
//append this lod request to existing header request
1246+
if (lod < LLModel::NUM_LODS && lod >= 0)
12501247
{
1251-
mLODReqQ.push(req);
1252-
LLMeshRepository::sLODProcessing++;
1248+
pending->second[lod]++;
12531249
}
1250+
else
1251+
{
1252+
LL_WARNS(LOG_MESH) << "Invalid LOD request: " << lod << "for mesh" << mesh_id << LL_ENDL;
1253+
}
1254+
llassert_msg(lod < LLModel::NUM_LODS, "Requested lod is out of bounds");
12541255
}
12551256
else
12561257
{
1257-
HeaderRequest req(mesh_params);
1258-
pending_lod_map::iterator pending = mPendingLOD.find(mesh_id);
1259-
if (pending != mPendingLOD.end())
1260-
{ // append this lod request to existing header request
1261-
pending->second.push_back(lod);
1262-
llassert(pending->second.size() <= LLModel::NUM_LODS);
1263-
}
1264-
else
1265-
{ // if no header request is pending, fetch header
1266-
mHeaderReqQ.push(req);
1267-
mPendingLOD[mesh_id].push_back(lod);
1268-
}
1258+
//if no header request is pending, fetch header
1259+
mHeaderReqQ.push(req);
1260+
auto& array = mPendingLOD[mesh_id];
1261+
std::fill(array.begin(), array.end(), 0);
1262+
array[lod]++;
12691263
}
12701264
}
12711265
}
@@ -2024,11 +2018,27 @@ EMeshProcessingResult LLMeshRepoThread::headerReceived(const LLVolumeParams& mes
20242018
pending_lod_map::iterator iter = mPendingLOD.find(mesh_id);
20252019
if (iter != mPendingLOD.end())
20262020
{
2027-
for (U32 i = 0; i < iter->second.size(); ++i)
2021+
for (S32 i = 0; i < iter->second.size(); ++i)
20282022
{
2029-
LODRequest req(mesh_params, iter->second[i]);
2030-
mLODReqQ.push(req);
2031-
LLMeshRepository::sLODProcessing++;
2023+
if (iter->second[i] > 1)
2024+
{
2025+
// mLoadingMeshes should be protecting from dupplciates, but looks
2026+
// like this is possible if object rezzes, unregisterMesh, then
2027+
// rezzes again before first request completes.
2028+
// mLoadingMeshes might need to change a bit to not rerequest if
2029+
// mesh is already pending.
2030+
//
2031+
// Todo: Improve mLoadingMeshes and once done turn this into an assert.
2032+
// Low priority since such situation should be relatively rare
2033+
LL_INFOS(LOG_MESH) << "Multiple dupplicate requests for mesd ID: " << mesh_id << " LOD: " << i
2034+
<< LL_ENDL;
2035+
}
2036+
if (iter->second[i] > 0)
2037+
{
2038+
LODRequest req(mesh_params, i);
2039+
mLODReqQ.push(req);
2040+
LLMeshRepository::sLODProcessing++;
2041+
}
20322042
}
20332043
mPendingLOD.erase(iter);
20342044
}

indra/newview/llmeshrepository.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ class LLMeshRepoThread : public LLThread
433433
std::deque<LoadedMesh> mLoadedQ;
434434

435435
//map of pending header requests and currently desired LODs
436-
typedef std::unordered_map<LLUUID, std::vector<S32> > pending_lod_map;
436+
typedef std::unordered_map<LLUUID, std::array<S32, LLModel::NUM_LODS> > pending_lod_map;
437437
pending_lod_map mPendingLOD;
438438

439439
// map of mesh ID to skin info (mirrors LLMeshRepository::mSkinMap)
@@ -525,6 +525,9 @@ class LLMeshRepoThread : public LLThread
525525
LLCore::HttpHandle getByteRange(const std::string & url,
526526
size_t offset, size_t len,
527527
const LLCore::HttpHandler::ptr_t &handler);
528+
529+
// Mutex: mMutex must be alerady locked when calling
530+
void loadMeshLOD(const LLUUID &mesh_id, const LLVolumeParams& mesh_params, S32 lod);
528531
};
529532

530533

0 commit comments

Comments
 (0)