aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llviewerjointmesh_sse.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/llviewerjointmesh_sse.cpp')
-rw-r--r--linden/indra/newview/llviewerjointmesh_sse.cpp114
1 files changed, 114 insertions, 0 deletions
diff --git a/linden/indra/newview/llviewerjointmesh_sse.cpp b/linden/indra/newview/llviewerjointmesh_sse.cpp
new file mode 100644
index 0000000..95d621a
--- /dev/null
+++ b/linden/indra/newview/llviewerjointmesh_sse.cpp
@@ -0,0 +1,114 @@
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 * Copyright (c) 2007-2007, Linden Research, Inc.
9 *
10 * Second Life Viewer Source Code
11 * The source code in this file ("Source Code") is provided by Linden Lab
12 * to you under the terms of the GNU General Public License, version 2.0
13 * ("GPL"), unless you have obtained a separate licensing agreement
14 * ("Other License"), formally executed by you and Linden Lab. Terms of
15 * the GPL can be found in doc/GPL-license.txt in this distribution, or
16 * online at http://secondlife.com/developers/opensource/gplv2
17 *
18 * There are special exceptions to the terms and conditions of the GPL as
19 * it is applied to this Source Code. View the full text of the exception
20 * in the file doc/FLOSS-exception.txt in this software distribution, or
21 * online at http://secondlife.com/developers/opensource/flossexception
22 *
23 * By copying, modifying or distributing this software, you acknowledge
24 * that you have read and understood your obligations described above,
25 * and agree to abide by those obligations.
26 *
27 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
28 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
29 * COMPLETENESS OR PERFORMANCE.
30 */
31
32//-----------------------------------------------------------------------------
33// Header Files
34//-----------------------------------------------------------------------------
35
36#include "llviewerprecompiledheaders.h"
37
38#include "llviewerjointmesh.h"
39
40// project includes
41#include "llface.h"
42#include "llpolymesh.h"
43
44// library includes
45#include "lldarray.h"
46#include "llv4math.h" // for LL_VECTORIZE
47#include "llv4matrix3.h"
48#include "llv4matrix4.h"
49#include "v3math.h"
50
51
52#if LL_VECTORIZE
53
54inline void matrix_translate(LLV4Matrix4& m, const LLMatrix4* w, const LLVector3& j)
55{
56 m.mV[VX] = _mm_loadu_ps(w->mMatrix[VX]);
57 m.mV[VY] = _mm_loadu_ps(w->mMatrix[VY]);
58 m.mV[VZ] = _mm_loadu_ps(w->mMatrix[VZ]);
59 m.mV[VW] = _mm_loadu_ps(w->mMatrix[VW]);
60 m.mV[VW] = _mm_add_ps(m.mV[VW], _mm_mul_ps(_mm_set1_ps(j.mV[VX]), m.mV[VX])); // ( ax * vx ) + vw
61 m.mV[VW] = _mm_add_ps(m.mV[VW], _mm_mul_ps(_mm_set1_ps(j.mV[VY]), m.mV[VY]));
62 m.mV[VW] = _mm_add_ps(m.mV[VW], _mm_mul_ps(_mm_set1_ps(j.mV[VZ]), m.mV[VZ]));
63}
64
65// static
66void LLViewerJointMesh::updateGeometrySSE(LLFace *face, LLPolyMesh *mesh)
67{
68 // This cannot be a file-level static because it will be initialized
69 // before main() using SSE code, which will crash on non-SSE processors.
70 static LLV4Matrix4 sJointMat[32];
71 LLDynamicArray<LLJointRenderData*>& joint_data = mesh->getReferenceMesh()->mJointRenderData;
72
73 //upload joint pivots/matrices
74 for(S32 j = 0, jend = joint_data.count(); j < jend ; ++j )
75 {
76 matrix_translate(sJointMat[j], joint_data[j]->mWorldMatrix,
77 joint_data[j]->mSkinJoint ?
78 joint_data[j]->mSkinJoint->mRootToJointSkinOffset
79 : joint_data[j+1]->mSkinJoint->mRootToParentJointSkinOffset);
80 }
81
82 F32 weight = F32_MAX;
83 LLV4Matrix4 blend_mat;
84
85 LLStrider<LLVector3> o_vertices;
86 LLStrider<LLVector3> o_normals;
87
88 LLVertexBuffer *buffer = face->mVertexBuffer;
89 buffer->getVertexStrider(o_vertices, mesh->mFaceVertexOffset);
90 buffer->getNormalStrider(o_normals, mesh->mFaceVertexOffset);
91
92 const F32* weights = mesh->getWeights();
93 const LLVector3* coords = mesh->getCoords();
94 const LLVector3* normals = mesh->getNormals();
95 for (U32 index = 0, index_end = mesh->getNumVertices(); index < index_end; ++index)
96 {
97 if( weight != weights[index])
98 {
99 S32 joint = llfloor(weight = weights[index]);
100 blend_mat.lerp(sJointMat[joint], sJointMat[joint+1], weight - joint);
101 }
102 blend_mat.multiply(coords[index], o_vertices[index]);
103 ((LLV4Matrix3)blend_mat).multiply(normals[index], o_normals[index]);
104 }
105}
106
107#else
108
109void LLViewerJointMesh::updateGeometrySSE(LLFace *face, LLPolyMesh *mesh)
110{
111 LLViewerJointMesh::updateGeometryVectorized(face, mesh);
112}
113
114#endif