/indra/newview/llviewerjointmesh_sse2.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 121 lines · 60 code · 20 blank · 41 comment · 4 complexity · 84c950f22aa42af8901d91af6107efd2 MD5 · raw file

  1. /**
  2. * @file llviewerjointmesh_sse2.cpp
  3. * @brief SSE vectorized joint skinning code, only used when video card does
  4. * not support avatar vertex programs.
  5. *
  6. * *NOTE: Disabled on Windows builds. See llv4math.h for details.
  7. *
  8. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  9. * Second Life Viewer Source Code
  10. * Copyright (C) 2010, Linden Research, Inc.
  11. *
  12. * This library is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU Lesser General Public
  14. * License as published by the Free Software Foundation;
  15. * version 2.1 of the License only.
  16. *
  17. * This library is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * Lesser General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Lesser General Public
  23. * License along with this library; if not, write to the Free Software
  24. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  25. *
  26. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  27. * $/LicenseInfo$
  28. */
  29. // Visual Studio required settings for this file:
  30. // Precompiled Headers OFF
  31. // Code Generation: SSE2
  32. //-----------------------------------------------------------------------------
  33. // Header Files
  34. //-----------------------------------------------------------------------------
  35. #include "llviewerprecompiledheaders.h"
  36. #include "llviewerjointmesh.h"
  37. // project includes
  38. #include "llface.h"
  39. #include "llpolymesh.h"
  40. // library includes
  41. #include "lldarray.h"
  42. #include "llstrider.h"
  43. #include "llv4math.h" // for LL_VECTORIZE
  44. #include "llv4matrix3.h"
  45. #include "llv4matrix4.h"
  46. #include "m4math.h"
  47. #include "v3math.h"
  48. #if LL_VECTORIZE
  49. inline void matrix_translate(LLV4Matrix4& m, const LLMatrix4* w, const LLVector3& j)
  50. {
  51. m.mV[VX] = _mm_loadu_ps(w->mMatrix[VX]);
  52. m.mV[VY] = _mm_loadu_ps(w->mMatrix[VY]);
  53. m.mV[VZ] = _mm_loadu_ps(w->mMatrix[VZ]);
  54. m.mV[VW] = _mm_loadu_ps(w->mMatrix[VW]);
  55. m.mV[VW] = _mm_add_ps(m.mV[VW], _mm_mul_ps(_mm_set1_ps(j.mV[VX]), m.mV[VX])); // ( ax * vx ) + vw
  56. m.mV[VW] = _mm_add_ps(m.mV[VW], _mm_mul_ps(_mm_set1_ps(j.mV[VY]), m.mV[VY]));
  57. m.mV[VW] = _mm_add_ps(m.mV[VW], _mm_mul_ps(_mm_set1_ps(j.mV[VZ]), m.mV[VZ]));
  58. }
  59. // static
  60. void LLViewerJointMesh::updateGeometrySSE2(LLFace *face, LLPolyMesh *mesh)
  61. {
  62. // This cannot be a file-level static because it will be initialized
  63. // before main() using SSE code, which will crash on non-SSE processors.
  64. static LLV4Matrix4 sJointMat[32];
  65. LLDynamicArray<LLJointRenderData*>& joint_data = mesh->getReferenceMesh()->mJointRenderData;
  66. //upload joint pivots/matrices
  67. for(S32 j = 0, jend = joint_data.count(); j < jend ; ++j )
  68. {
  69. matrix_translate(sJointMat[j], joint_data[j]->mWorldMatrix,
  70. joint_data[j]->mSkinJoint ?
  71. joint_data[j]->mSkinJoint->mRootToJointSkinOffset
  72. : joint_data[j+1]->mSkinJoint->mRootToParentJointSkinOffset);
  73. }
  74. F32 weight = F32_MAX;
  75. LLV4Matrix4 blend_mat;
  76. LLStrider<LLVector3> o_vertices;
  77. LLStrider<LLVector3> o_normals;
  78. LLVertexBuffer *buffer = face->getVertexBuffer();
  79. buffer->getVertexStrider(o_vertices, mesh->mFaceVertexOffset);
  80. buffer->getNormalStrider(o_normals, mesh->mFaceVertexOffset);
  81. const F32* weights = mesh->getWeights();
  82. const LLVector3* coords = (const LLVector3*)mesh->getCoords();
  83. const LLVector3* normals = (const LLVector3*)mesh->getNormals();
  84. for (U32 index = 0, index_end = mesh->getNumVertices(); index < index_end; ++index)
  85. {
  86. if( weight != weights[index])
  87. {
  88. S32 joint = llfloor(weight = weights[index]);
  89. blend_mat.lerp(sJointMat[joint], sJointMat[joint+1], weight - joint);
  90. }
  91. blend_mat.multiply(coords[index], o_vertices[index]);
  92. ((LLV4Matrix3)blend_mat).multiply(normals[index], o_normals[index]);
  93. }
  94. //setBuffer(0) called in LLVOAvatar::renderSkinned
  95. }
  96. #else
  97. void LLViewerJointMesh::updateGeometrySSE2(LLFace *face, LLPolyMesh *mesh)
  98. {
  99. LLViewerJointMesh::updateGeometryVectorized(face, mesh);
  100. }
  101. #endif