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