From 9ef48676d45dcb90f282cc304135a9f023f4630b Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Tue, 3 Jan 2023 14:35:27 +0200 Subject: SL-18874 Rigged mesh upload crash when using Bounding Box physics --- indra/llprimitive/llmodel.cpp | 114 ++++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 49 deletions(-) (limited to 'indra/llprimitive/llmodel.cpp') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index 805af55299..220e0fbe84 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -832,55 +832,69 @@ LLSD LLModel::writeModel( if (skinning) { - //write out skin weights - - //each influence list entry is up to 4 24-bit values - // first 8 bits is bone index - // last 16 bits is bone influence weight - // a bone index of 0xFF signifies no more influences for this vertex - - std::stringstream ostr; - - for (U32 j = 0; j < face.mNumVertices; ++j) - { - LLVector3 pos(face.mPositions[j].getF32ptr()); - - weight_list& weights = model[idx]->getJointInfluences(pos); - - S32 count = 0; - for (weight_list::iterator iter = weights.begin(); iter != weights.end(); ++iter) - { - // Note joint index cannot exceed 255. - if (iter->mJointIdx < 255 && iter->mJointIdx >= 0) - { - U8 idx = (U8) iter->mJointIdx; - ostr.write((const char*) &idx, 1); - - U16 influence = (U16) (iter->mWeight*65535); - ostr.write((const char*) &influence, 2); - - ++count; - } - } - U8 end_list = 0xFF; - if (count < 4) - { - ostr.write((const char*) &end_list, 1); - } - } - - //copy ostr to binary buffer - std::string data = ostr.str(); - const U8* buff = (U8*) data.data(); - U32 bytes = data.size(); - - LLSD::Binary w(bytes); - for (U32 j = 0; j < bytes; ++j) - { - w[j] = buff[j]; - } - - mdl[model_names[idx]][i]["Weights"] = w; + if (!model[idx]->mSkinWeights.empty()) + { + //write out skin weights + + //each influence list entry is up to 4 24-bit values + // first 8 bits is bone index + // last 16 bits is bone influence weight + // a bone index of 0xFF signifies no more influences for this vertex + + std::stringstream ostr; + for (U32 j = 0; j < face.mNumVertices; ++j) + { + LLVector3 pos(face.mPositions[j].getF32ptr()); + + weight_list& weights = model[idx]->getJointInfluences(pos); + + S32 count = 0; + for (weight_list::iterator iter = weights.begin(); iter != weights.end(); ++iter) + { + // Note joint index cannot exceed 255. + if (iter->mJointIdx < 255 && iter->mJointIdx >= 0) + { + U8 idx = (U8)iter->mJointIdx; + ostr.write((const char*)&idx, 1); + + U16 influence = (U16)(iter->mWeight * 65535); + ostr.write((const char*)&influence, 2); + + ++count; + } + } + U8 end_list = 0xFF; + if (count < 4) + { + ostr.write((const char*)&end_list, 1); + } + } + + //copy ostr to binary buffer + std::string data = ostr.str(); + const U8* buff = (U8*)data.data(); + U32 bytes = data.size(); + + LLSD::Binary w(bytes); + for (U32 j = 0; j < bytes; ++j) + { + w[j] = buff[j]; + } + + mdl[model_names[idx]][i]["Weights"] = w; + } + else + { + if (idx == LLModel::LOD_PHYSICS) + { + // Ex: using "bounding box" + LL_DEBUGS("MESHSKININFO") << "Using physics model without skin weights" << LL_ENDL; + } + else + { + LL_WARNS("MESHSKININFO") << "Attempting to use skinning without having skin weights" << LL_ENDL; + } + } } } } @@ -982,6 +996,8 @@ LLModel::weight_list& LLModel::getJointInfluences(const LLVector3& pos) //1. If a vertex has been weighted then we'll find it via pos and return its weight list weight_map::iterator iterPos = mSkinWeights.begin(); weight_map::iterator iterEnd = mSkinWeights.end(); + + llassert(!mSkinWeights.empty()); for ( ; iterPos!=iterEnd; ++iterPos ) { -- cgit v1.2.3 From 9438ef5f79fdac11080c3fa10c518e335fd7d8d6 Mon Sep 17 00:00:00 2001 From: Henri Beauchamp Date: Tue, 31 Jan 2023 17:42:51 +0100 Subject: SL-19110 Fast hashing classes for use in place of the slow LLMD5, where speed matters. (#64) This commit adds the HBXX64 and HBXX128 classes for use as a drop-in replacement for the slow LLMD5 hashing class, where speed matters and backward compatibility (with standard hashing algorithms) and/or cryptographic hashing qualities are not required. It also replaces LLMD5 with HBXX* in a few existing hot (well, ok, just "warm" for some) paths meeting the above requirements, while paving the way for future use cases, such as in the DRTVWR-559 and sibling branches where the slow LLMD5 is used (e.g. to hash materials and vertex buffer cache entries), and could be use such a (way) faster algorithm with very significant benefits and no negative impact. Here is the comment I added in indra/llcommon/hbxx.h: // HBXXH* classes are to be used where speed matters and cryptographic quality // is not required (no "one-way" guarantee, though they are likely not worst in // this respect than MD5 which got busted and is now considered too weak). The // xxHash code they are built upon is vectorized and about 50 times faster than // MD5. A 64 bits hash class is also provided for when 128 bits of entropy are // not needed. The hashes collision rate is similar to MD5's. // See https://github.com/Cyan4973/xxHash#readme for details. --- indra/llprimitive/llmodel.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'indra/llprimitive/llmodel.cpp') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index 220e0fbe84..3921ebfca3 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -31,7 +31,7 @@ #include "llconvexdecomposition.h" #include "llsdserialize.h" #include "llvector4a.h" -#include "llmd5.h" +#include "hbxxh.h" #ifdef LL_USESYSTEMLIBS # include @@ -1537,7 +1537,7 @@ LLSD LLMeshSkinInfo::asLLSD(bool include_joints, bool lock_scale_if_joint_positi void LLMeshSkinInfo::updateHash() { // get hash of data relevant to render batches - LLMD5 hash; + HBXXH64 hash; //mJointNames for (auto& name : mJointNames) @@ -1546,24 +1546,19 @@ void LLMeshSkinInfo::updateHash() } //mJointNums - hash.update((U8*)&(mJointNums[0]), sizeof(S32) * mJointNums.size()); + hash.update((const void*)mJointNums.data(), sizeof(S32) * mJointNums.size()); //mInvBindMatrix F32* src = mInvBindMatrix[0].getF32ptr(); - for (int i = 0; i < mInvBindMatrix.size() * 16; ++i) + for (size_t i = 0, count = mInvBindMatrix.size() * 16; i < count; ++i) { S32 t = llround(src[i] * 10000.f); - hash.update((U8*)&t, sizeof(S32)); + hash.update((const void*)&t, sizeof(S32)); } - //hash.update((U8*)&(mInvBindMatrix[0]), sizeof(LLMatrix4a) * mInvBindMatrix.size()); + //hash.update((const void*)mInvBindMatrix.data(), sizeof(LLMatrix4a) * mInvBindMatrix.size()); - hash.finalize(); - - U64 digest[2]; - hash.raw_digest((U8*) digest); - - mHash = digest[0]; + mHash = hash.digest(); } U32 LLMeshSkinInfo::sizeBytes() const -- cgit v1.2.3