From 896b7146e7301c03cc5652b77df47e464c5f964b Mon Sep 17 00:00:00 2001 From: Shyotl Date: Wed, 10 Aug 2011 02:01:53 -0500 Subject: [PATCH] Fixed vertex corruption if avatar shaders are off and jointmesh is not vectorized. Also, now preventing usage of unsupported vectorization paths. --- indra/newview/floatersculptpreview.cpp | 10 +++--- indra/newview/llface.cpp | 15 ++++++--- indra/newview/llviewerjointmesh.cpp | 43 ++++++++++++++------------ 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/indra/newview/floatersculptpreview.cpp b/indra/newview/floatersculptpreview.cpp index add283067..97d20083f 100644 --- a/indra/newview/floatersculptpreview.cpp +++ b/indra/newview/floatersculptpreview.cpp @@ -747,15 +747,13 @@ void LLPreviewSculpted::setPreviewTarget(LLImageRaw* imagep, F32 distance) // build vertices and normals for (U32 i = 0; (S32)i < num_vertices; i++) { - (vertex_strider++)->set(vf.mPositions[i].getF32ptr()); - LLVector3 normal(vf.mNormals[i].getF32ptr()); - normal.normalize(); - *(normal_strider++) = normal; + LLVector4a normal = vf.mNormals[i]; + normal.normalize3(); + (normal_strider++)->set(normal.getF32ptr()); } //build vertices - vertex_strider.assignArray((U8*)vf.mPositions,sizeof(vf.mPositions[0]),num_indices); - + vertex_strider.assignArray((U8*)vf.mPositions,sizeof(vf.mPositions[0]),num_vertices); // build indices index_strider.assignArray((U8*)vf.mIndices,sizeof(vf.mIndices[0]),num_indices); } diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp index a557d0d56..1de535812 100644 --- a/indra/newview/llface.cpp +++ b/indra/newview/llface.cpp @@ -1484,6 +1484,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, if (rebuild_pos) { + llassert(num_vertices > 0); mVertexBuffer->getVertexStrider(vertices, mGeomIndex); LLMatrix4a mat_vert; mat_vert.loadu(mat_vert_in); @@ -1514,7 +1515,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, LLVector4a normal; mat_normal.rotate(vf.mNormals[i], normal); normal.normalize3fast(); - *(LLVector4a*)&(normals[i]) = normal; + normals[i].set(normal.getF32ptr()); } //mVertexBuffer->setBuffer(0); @@ -1528,7 +1529,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, LLVector4a binormal; mat_normal.rotate(vf.mBinormals[i], binormal); binormal.normalize3fast(); - *(LLVector4a*)&(binormals[i]) = binormal; + binormals[i].set(binormal.getF32ptr()); } //mVertexBuffer->setBuffer(0); @@ -1780,10 +1781,10 @@ BOOL LLFace::verify(const U32* indices_array) const } // First, check whether the face data fits within the pool's range. - if ((mGeomIndex + mGeomCount) > mVertexBuffer->getNumVerts()) + if ((mGeomIndex + mGeomCount) > mVertexBuffer->getRequestedVerts()) { ok = FALSE; - llinfos << "Face not within pool range!" << llendl; + llinfos << "Face references invalid vertices!" << llendl; } S32 indices_count = (S32)getIndicesCount(); @@ -1799,6 +1800,12 @@ BOOL LLFace::verify(const U32* indices_array) const llinfos << "Face has bogus indices count" << llendl; } + if (mIndicesIndex + mIndicesCount > (U32)mVertexBuffer->getRequestedIndices()) + { + ok = FALSE; + llinfos << "Face references invalid indices!" << llendl; + } + #if 0 S32 geom_start = getGeomStart(); S32 geom_count = mGeomCount; diff --git a/indra/newview/llviewerjointmesh.cpp b/indra/newview/llviewerjointmesh.cpp index 3b595e30a..d457a1a2d 100644 --- a/indra/newview/llviewerjointmesh.cpp +++ b/indra/newview/llviewerjointmesh.cpp @@ -712,8 +712,7 @@ void LLViewerJointMesh::updateFaceData(LLFace *face, F32 pixel_area, BOOL damp_w verticesp.assignArray((U8*)mMesh->getCoords(), sizeof(mMesh->getCoords()[0]), num_verts); //LLVector4a::memcpyNonAliased16(n, (F32*) mMesh->getNormals(), words*sizeof(F32)); normalsp.assignArray((U8*)mMesh->getNormals(), sizeof(mMesh->getNormals()[0]), num_verts); - - + if (!terse_update) { vertex_weightsp += mMesh->mFaceVertexOffset; @@ -729,7 +728,7 @@ void LLViewerJointMesh::updateFaceData(LLFace *face, F32 pixel_area, BOOL damp_w //LLVector4a::memcpyNonAliased16(vw, (F32*) mMesh->getWeights(), num_verts*sizeof(F32)); vertex_weightsp.assignArray((U8*)mMesh->getWeights(), sizeof(mMesh->getWeights()[0]), num_verts); //LLVector4a::memcpyNonAliased16(cw, (F32*) mMesh->getClothingWeights(), num_verts*4*sizeof(F32)); - clothing_weightsp.assignArray((U8*)mMesh->getClothingWeights(), sizeof(mMesh->getClothingWeights()[0]), num_verts); + clothing_weightsp.assignArray((U8*)mMesh->getClothingWeights(), sizeof(mMesh->getClothingWeights()[0]), num_verts); } const U32 idx_count = mMesh->getNumFaces()*3; @@ -772,16 +771,16 @@ void LLViewerJointMesh::updateGeometryOriginal(LLFace *mFace, LLPolyMesh *mMesh) buffer->getVertexStrider(o_vertices, 0); buffer->getNormalStrider(o_normals, 0); - F32* __restrict vert = o_vertices[0].mV; - F32* __restrict norm = o_normals[0].mV; + //F32* __restrict vert = o_vertices[0].mV; + //F32* __restrict norm = o_normals[0].mV; const F32* __restrict weights = mMesh->getWeights(); const LLVector4a* __restrict coords = (LLVector4a*) mMesh->getCoords(); const LLVector4a* __restrict normals = (LLVector4a*) mMesh->getNormals(); - U32 offset = mMesh->mFaceVertexOffset*4; - vert += offset; - norm += offset; + U32 offset = mMesh->mFaceVertexOffset; + o_vertices += offset; + o_normals += offset; for (U32 index = 0; index < mMesh->getNumVertices(); index++) { @@ -799,17 +798,21 @@ void LLViewerJointMesh::updateGeometryOriginal(LLFace *mFace, LLPolyMesh *mMesh) LLVector4a res; gBlendMat.affineTransform(coords[index], res); - res.store4a(vert+index*4); + (o_vertices++)->set(res.getF32ptr()); + //res.store4a(vert+index*4); gBlendMat.rotate(normals[index], res); - res.store4a(norm+index*4); + (o_normals++)->set(res.getF32ptr()); + //res.store4a(norm+index*4); } else { // No lerp required in this case. LLVector4a res; gJointMatAligned[joint].affineTransform(coords[index], res); - res.store4a(vert+index*4); + (o_vertices++)->set(res.getF32ptr()); + //res.store4a(vert+index*4); gJointMatAligned[joint].rotate(normals[index], res); - res.store4a(norm+index*4); + (o_normals++)->set(res.getF32ptr()); + //res.store4a(norm+index*4); } } @@ -852,31 +855,33 @@ void LLViewerJointMesh::updateVectorize() LL_INFOS("AppInit") << "Vectorization : " << ( vectorizeEnable ? "ENABLED" : "DISABLED" ) << LL_ENDL ; LL_INFOS("AppInit") << "Vector Processor : " << vp << LL_ENDL ; LL_INFOS("AppInit") << "Vectorized Skinning : " << ( vectorizeSkin ? "ENABLED" : "DISABLED" ) << LL_ENDL ; + + sUpdateGeometryFunc = &updateGeometryOriginal; + if(vectorizeEnable && vectorizeSkin) { switch(sVectorizeProcessor) { case 2: - sUpdateGeometryFunc = &updateGeometrySSE2; if(!supportsSSE2()) LL_INFOS("AppInit") << "VectorizeProcessor set to unsupported implementation! (SSE2)" << LL_ENDL ; + else + sUpdateGeometryFunc = &updateGeometrySSE2; break; case 1: - sUpdateGeometryFunc = &updateGeometrySSE; if(!supportsSSE()) LL_INFOS("AppInit") << "VectorizeProcessor set to unsupported implementation! (SSE)" << LL_ENDL ; + else + sUpdateGeometryFunc = &updateGeometrySSE; break; default: - sUpdateGeometryFunc = &updateGeometryVectorized; if(!gSysCPU.hasAltivec()) LL_INFOS("AppInit") << "VectorizeProcessor set to unsupported implementation! (Altivec)" << LL_ENDL ; + else + sUpdateGeometryFunc = &updateGeometryVectorized; break; } } - else - { - sUpdateGeometryFunc = &updateGeometryOriginal; - } } void LLViewerJointMesh::updateJointGeometry()