PageRenderTime 25ms CodeModel.GetById 12ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

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