mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-12 15:14:35 +00:00
Hardware Skinning Support
- Supports GL, D3D9 & D3D11 - Extends vertex formats & shadergen to support blend indices and weights - Adds basic support for using 4x3 matrices for shader constants - Supports software fallback
This commit is contained in:
parent
507c239a87
commit
3496c549b5
72 changed files with 2533 additions and 1327 deletions
|
|
@ -26,19 +26,13 @@
|
|||
#if defined(TORQUE_CPU_X86)
|
||||
# // x86 CPU family implementations
|
||||
extern void zero_vert_normal_bulk_SSE(const dsize_t count, U8 * __restrict const outPtr, const dsize_t outStride);
|
||||
extern void m_matF_x_BatchedVertWeightList_SSE(const MatrixF &mat, const dsize_t count, const TSSkinMesh::BatchData::BatchedVertWeight * __restrict batch, U8 * const __restrict outPtr, const dsize_t outStride);
|
||||
#if (_MSC_VER >= 1500)
|
||||
extern void m_matF_x_BatchedVertWeightList_SSE4(const MatrixF &mat, const dsize_t count, const TSSkinMesh::BatchData::BatchedVertWeight * __restrict batch, U8 * const __restrict outPtr, const dsize_t outStride);
|
||||
#endif
|
||||
#
|
||||
#elif defined(TORQUE_CPU_PPC)
|
||||
# // PPC CPU family implementations
|
||||
# if defined(TORQUE_OS_XENON)
|
||||
extern void zero_vert_normal_bulk_X360(const dsize_t count, U8 * __restrict const outPtr, const dsize_t outStride);
|
||||
extern void m_matF_x_BatchedVertWeightList_X360(const MatrixF &mat, const dsize_t count, const TSSkinMesh::BatchData::BatchedVertWeight * __restrict batch, U8 * const __restrict outPtr, const dsize_t outStride);
|
||||
# else
|
||||
extern void zero_vert_normal_bulk_gccvec(const dsize_t count, U8 * __restrict const outPtr, const dsize_t outStride);
|
||||
extern void m_matF_x_BatchedVertWeightList_gccvec(const MatrixF &mat, const dsize_t count, const TSSkinMesh::BatchData::BatchedVertWeight * __restrict batch, U8 * const __restrict outPtr, const dsize_t outStride);
|
||||
# endif
|
||||
#
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -67,117 +67,4 @@ void zero_vert_normal_bulk_SSE(const dsize_t count, U8 * __restrict const outPtr
|
|||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void m_matF_x_BatchedVertWeightList_SSE(const MatrixF &mat,
|
||||
const dsize_t count,
|
||||
const TSSkinMesh::BatchData::BatchedVertWeight * __restrict batch,
|
||||
U8 * const __restrict outPtr,
|
||||
const dsize_t outStride)
|
||||
{
|
||||
const char * __restrict iPtr = reinterpret_cast<const char *>(batch);
|
||||
const dsize_t inStride = sizeof(TSSkinMesh::BatchData::BatchedVertWeight);
|
||||
|
||||
// SSE intrinsic version
|
||||
// Based on: http://www.cortstratton.org/articles/HugiCode.html
|
||||
|
||||
// Load matrix, transposed, into registers
|
||||
MatrixF transMat;
|
||||
mat.transposeTo(transMat);
|
||||
register __m128 sseMat[4];
|
||||
|
||||
sseMat[0] = _mm_loadu_ps(&transMat[0]);
|
||||
sseMat[1] = _mm_loadu_ps(&transMat[4]);
|
||||
sseMat[2] = _mm_loadu_ps(&transMat[8]);
|
||||
sseMat[3] = _mm_loadu_ps(&transMat[12]);
|
||||
|
||||
// mask
|
||||
const __m128 _w_mask = { 1.0f, 1.0f, 1.0f, 0.0f };
|
||||
|
||||
// temp registers
|
||||
register __m128 tempPos;
|
||||
register __m128 tempNrm;
|
||||
register __m128 scratch0;
|
||||
register __m128 scratch1;
|
||||
register __m128 inPos;
|
||||
register __m128 inNrm;
|
||||
|
||||
// pre-populate cache
|
||||
const TSSkinMesh::BatchData::BatchedVertWeight &firstElem = batch[0];
|
||||
for(S32 i = 0; i < 8; i++)
|
||||
{
|
||||
_mm_prefetch(reinterpret_cast<const char *>(iPtr + inStride * i), _MM_HINT_T0);
|
||||
_mm_prefetch(reinterpret_cast<const char *>(outPtr + outStride * (i + firstElem.vidx)), _MM_HINT_T0);
|
||||
}
|
||||
|
||||
for(register S32 i = 0; i < count; i++)
|
||||
{
|
||||
const TSSkinMesh::BatchData::BatchedVertWeight &inElem = batch[i];
|
||||
TSMesh::__TSMeshVertexBase *outElem = reinterpret_cast<TSMesh::__TSMeshVertexBase *>(outPtr + inElem.vidx * outStride);
|
||||
|
||||
// process x (hiding the prefetches in the delays)
|
||||
inPos = _mm_load_ps(inElem.vert);
|
||||
inNrm = _mm_load_ps(inElem.normal);
|
||||
|
||||
// prefetch input
|
||||
#define INPUT_PREFETCH_LOOKAHEAD 64
|
||||
const char *prefetchInput = reinterpret_cast<const char *>(batch) + inStride * (i + INPUT_PREFETCH_LOOKAHEAD);
|
||||
_mm_prefetch(prefetchInput, _MM_HINT_T0);
|
||||
|
||||
// propagate the .x elements across the vectors
|
||||
tempPos = _mm_shuffle_ps(inPos, inPos, _MM_SHUFFLE(0, 0, 0, 0));
|
||||
tempNrm = _mm_shuffle_ps(inNrm, inNrm, _MM_SHUFFLE(0, 0, 0, 0));
|
||||
|
||||
// prefetch ouput with half the lookahead distance of the input
|
||||
#define OUTPUT_PREFETCH_LOOKAHEAD (INPUT_PREFETCH_LOOKAHEAD >> 1)
|
||||
const char *outPrefetch = reinterpret_cast<const char*>(outPtr) + outStride * (inElem.vidx + OUTPUT_PREFETCH_LOOKAHEAD);
|
||||
_mm_prefetch(outPrefetch, _MM_HINT_T0);
|
||||
|
||||
// mul by column 0
|
||||
tempPos = _mm_mul_ps(tempPos, sseMat[0]);
|
||||
tempNrm = _mm_mul_ps(tempNrm, sseMat[0]);
|
||||
|
||||
// process y
|
||||
scratch0 = _mm_shuffle_ps(inPos, inPos, _MM_SHUFFLE(1, 1, 1, 1));
|
||||
scratch1 = _mm_shuffle_ps(inNrm, inNrm, _MM_SHUFFLE(1, 1, 1, 1));
|
||||
|
||||
scratch0 = _mm_mul_ps(scratch0, sseMat[1]);
|
||||
scratch1 = _mm_mul_ps(scratch1, sseMat[1]);
|
||||
|
||||
tempPos = _mm_add_ps(tempPos, scratch0);
|
||||
tempNrm = _mm_add_ps(tempNrm, scratch1);
|
||||
|
||||
|
||||
// process z
|
||||
scratch0 = _mm_shuffle_ps(inPos, inPos, _MM_SHUFFLE(2, 2, 2, 2));
|
||||
scratch1 = _mm_shuffle_ps(inNrm, inNrm, _MM_SHUFFLE(2, 2, 2, 2));
|
||||
|
||||
scratch0 = _mm_mul_ps(scratch0, sseMat[2]);
|
||||
scratch1 = _mm_mul_ps(scratch1, sseMat[2]);
|
||||
|
||||
tempPos = _mm_add_ps(tempPos, scratch0);
|
||||
|
||||
inNrm = _mm_load_ps(outElem->_normal); //< load normal for accumulation
|
||||
scratch0 = _mm_shuffle_ps(inPos, inPos, _MM_SHUFFLE(3, 3, 3, 3));//< load bone weight across all elements of scratch0
|
||||
|
||||
tempNrm = _mm_add_ps(tempNrm, scratch1);
|
||||
|
||||
scratch0 = _mm_mul_ps(scratch0, _w_mask); //< mask off last
|
||||
|
||||
// Translate the position by adding the 4th column of the matrix to it
|
||||
tempPos = _mm_add_ps(tempPos, sseMat[3]);
|
||||
|
||||
// now multiply by the blend weight, and mask out the W component of both vectors
|
||||
tempPos = _mm_mul_ps(tempPos, scratch0);
|
||||
tempNrm = _mm_mul_ps(tempNrm, scratch0);
|
||||
|
||||
inPos = _mm_load_ps(outElem->_vert); //< load position for accumulation
|
||||
|
||||
// accumulate with previous values
|
||||
tempNrm = _mm_add_ps(tempNrm, inNrm);
|
||||
tempPos = _mm_add_ps(tempPos, inPos);
|
||||
|
||||
_mm_store_ps(outElem->_vert, tempPos); //< output position
|
||||
_mm_store_ps(outElem->_normal, tempNrm); //< output normal
|
||||
}
|
||||
}
|
||||
|
||||
#endif // TORQUE_CPU_X86
|
||||
|
|
@ -25,84 +25,4 @@
|
|||
#include "ts/tsMeshIntrinsics.h"
|
||||
#include <smmintrin.h>
|
||||
|
||||
void m_matF_x_BatchedVertWeightList_SSE4(const MatrixF &mat,
|
||||
const dsize_t count,
|
||||
const TSSkinMesh::BatchData::BatchedVertWeight * __restrict batch,
|
||||
U8 * const __restrict outPtr,
|
||||
const dsize_t outStride)
|
||||
{
|
||||
const char * __restrict iPtr = reinterpret_cast<const char *>(batch);
|
||||
const dsize_t inStride = sizeof(TSSkinMesh::BatchData::BatchedVertWeight);
|
||||
|
||||
__m128 sseMat[3];
|
||||
sseMat[0] = _mm_loadu_ps(&mat[0]);
|
||||
sseMat[1] = _mm_loadu_ps(&mat[4]);
|
||||
sseMat[2] = _mm_loadu_ps(&mat[8]);
|
||||
|
||||
// temp registers
|
||||
__m128 inPos, tempPos;
|
||||
__m128 inNrm, tempNrm;
|
||||
__m128 temp0, temp1, temp2, temp3;
|
||||
|
||||
// pre-populate cache
|
||||
const TSSkinMesh::BatchData::BatchedVertWeight &firstElem = batch[0];
|
||||
for(S32 i = 0; i < 8; i++)
|
||||
{
|
||||
_mm_prefetch(reinterpret_cast<const char *>(iPtr + inStride * i), _MM_HINT_T0);
|
||||
_mm_prefetch(reinterpret_cast<const char *>(outPtr + outStride * (i + firstElem.vidx)), _MM_HINT_T0);
|
||||
}
|
||||
|
||||
for(S32 i = 0; i < count; i++)
|
||||
{
|
||||
const TSSkinMesh::BatchData::BatchedVertWeight &inElem = batch[i];
|
||||
TSMesh::__TSMeshVertexBase *outElem = reinterpret_cast<TSMesh::__TSMeshVertexBase *>(outPtr + inElem.vidx * outStride);
|
||||
|
||||
// process x (hiding the prefetches in the delays)
|
||||
inPos = _mm_load_ps(inElem.vert);
|
||||
inNrm = _mm_load_ps(inElem.normal);
|
||||
|
||||
// prefetch input
|
||||
#define INPUT_PREFETCH_LOOKAHEAD 64
|
||||
const char *prefetchInput = reinterpret_cast<const char *>(batch) + inStride * (i + INPUT_PREFETCH_LOOKAHEAD);
|
||||
_mm_prefetch(prefetchInput, _MM_HINT_T0);
|
||||
|
||||
// prefetch ouput with half the lookahead distance of the input
|
||||
#define OUTPUT_PREFETCH_LOOKAHEAD (INPUT_PREFETCH_LOOKAHEAD >> 1)
|
||||
const char *outPrefetch = reinterpret_cast<const char*>(outPtr) + outStride * (inElem.vidx + OUTPUT_PREFETCH_LOOKAHEAD);
|
||||
_mm_prefetch(outPrefetch, _MM_HINT_T0);
|
||||
|
||||
// Multiply position
|
||||
tempPos = _mm_dp_ps(inPos, sseMat[0], 0xF1);
|
||||
temp0 = _mm_dp_ps(inPos, sseMat[1], 0xF2);
|
||||
temp1 = _mm_dp_ps(inPos, sseMat[2], 0xF4);
|
||||
|
||||
temp0 = _mm_or_ps(temp0, temp1);
|
||||
tempPos = _mm_or_ps(tempPos, temp0);
|
||||
|
||||
// Multiply normal
|
||||
tempNrm = _mm_dp_ps(inNrm, sseMat[0], 0x71);
|
||||
temp2 = _mm_dp_ps(inNrm, sseMat[1], 0x72);
|
||||
temp3 = _mm_dp_ps(inNrm, sseMat[2], 0x74);
|
||||
|
||||
temp2 = _mm_or_ps(temp2, temp3);
|
||||
tempNrm = _mm_or_ps(tempNrm, temp2);
|
||||
|
||||
// Load bone weight and multiply
|
||||
temp3 = _mm_shuffle_ps(inPos, inPos, _MM_SHUFFLE(3, 3, 3, 3));
|
||||
|
||||
tempPos = _mm_mul_ps(tempPos, temp3);
|
||||
tempNrm = _mm_mul_ps(tempNrm, temp3);
|
||||
|
||||
inPos = _mm_load_ps(outElem->_vert); //< load position for accumulation
|
||||
inNrm = _mm_load_ps(outElem->_normal); //< load normal for accumulation
|
||||
|
||||
// accumulate with previous values
|
||||
tempNrm = _mm_add_ps(tempNrm, inNrm);
|
||||
tempPos = _mm_add_ps(tempPos, inPos);
|
||||
|
||||
_mm_store_ps(outElem->_vert, tempPos); //< output position
|
||||
_mm_store_ps(outElem->_normal, tempNrm); //< output normal
|
||||
}
|
||||
}
|
||||
|
||||
#endif // TORQUE_CPU_X86
|
||||
Loading…
Add table
Add a link
Reference in a new issue