PageRenderTime 77ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llviewerjointmesh_sse.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 114 lines | 59 code | 18 blank | 37 comment | 4 complexity | aad79bcaf0045cc30a8d8556d4acc729 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llviewerjointmesh_sse.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. //-----------------------------------------------------------------------------
  30. // Header Files
  31. //-----------------------------------------------------------------------------
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llviewerjointmesh.h"
  34. // project includes
  35. #include "llface.h"
  36. #include "llpolymesh.h"
  37. // library includes
  38. #include "lldarray.h"
  39. #include "llv4math.h" // for LL_VECTORIZE
  40. #include "llv4matrix3.h"
  41. #include "llv4matrix4.h"
  42. #include "v3math.h"
  43. #if LL_VECTORIZE
  44. inline void matrix_translate(LLV4Matrix4& m, const LLMatrix4* w, const LLVector3& j)
  45. {
  46. m.mV[VX] = _mm_loadu_ps(w->mMatrix[VX]);
  47. m.mV[VY] = _mm_loadu_ps(w->mMatrix[VY]);
  48. m.mV[VZ] = _mm_loadu_ps(w->mMatrix[VZ]);
  49. m.mV[VW] = _mm_loadu_ps(w->mMatrix[VW]);
  50. m.mV[VW] = _mm_add_ps(m.mV[VW], _mm_mul_ps(_mm_set1_ps(j.mV[VX]), m.mV[VX])); // ( ax * vx ) + vw
  51. m.mV[VW] = _mm_add_ps(m.mV[VW], _mm_mul_ps(_mm_set1_ps(j.mV[VY]), m.mV[VY]));
  52. m.mV[VW] = _mm_add_ps(m.mV[VW], _mm_mul_ps(_mm_set1_ps(j.mV[VZ]), m.mV[VZ]));
  53. }
  54. // static
  55. void LLViewerJointMesh::updateGeometrySSE(LLFace *face, LLPolyMesh *mesh)
  56. {
  57. // This cannot be a file-level static because it will be initialized
  58. // before main() using SSE code, which will crash on non-SSE processors.
  59. static LLV4Matrix4 sJointMat[32];
  60. LLDynamicArray<LLJointRenderData*>& joint_data = mesh->getReferenceMesh()->mJointRenderData;
  61. //upload joint pivots/matrices
  62. for(S32 j = 0, jend = joint_data.count(); j < jend ; ++j )
  63. {
  64. matrix_translate(sJointMat[j], joint_data[j]->mWorldMatrix,
  65. joint_data[j]->mSkinJoint ?
  66. joint_data[j]->mSkinJoint->mRootToJointSkinOffset
  67. : joint_data[j+1]->mSkinJoint->mRootToParentJointSkinOffset);
  68. }
  69. F32 weight = F32_MAX;
  70. LLV4Matrix4 blend_mat;
  71. LLStrider<LLVector3> o_vertices;
  72. LLStrider<LLVector3> o_normals;
  73. LLVertexBuffer *buffer = face->getVertexBuffer();
  74. buffer->getVertexStrider(o_vertices, mesh->mFaceVertexOffset);
  75. buffer->getNormalStrider(o_normals, mesh->mFaceVertexOffset);
  76. const F32* weights = mesh->getWeights();
  77. const LLVector3* coords = (const LLVector3*)mesh->getCoords();
  78. const LLVector3* normals = (const LLVector3*)mesh->getNormals();
  79. for (U32 index = 0, index_end = mesh->getNumVertices(); index < index_end; ++index)
  80. {
  81. if( weight != weights[index])
  82. {
  83. S32 joint = llfloor(weight = weights[index]);
  84. blend_mat.lerp(sJointMat[joint], sJointMat[joint+1], weight - joint);
  85. }
  86. blend_mat.multiply(coords[index], o_vertices[index]);
  87. ((LLV4Matrix3)blend_mat).multiply(normals[index], o_normals[index]);
  88. }
  89. buffer->setBuffer(0);
  90. }
  91. #else
  92. void LLViewerJointMesh::updateGeometrySSE(LLFace *face, LLPolyMesh *mesh)
  93. {
  94. LLViewerJointMesh::updateGeometryVectorized(face, mesh);
  95. }
  96. #endif