Isolate the Altivec code so non-Altivec PPC targets can use the same binary.
Moved all the code using Altivec intrinsics to separate files. This means we can optionally use GCC's -maltivec on just these files, which are chosen at runtime if the CPU supports Altivec, and compile the rest without it, making a single binary that has Altivec optimizations but can still work on G3. Unlike SSE and similar extensions on x86, there does not seem to be a way to enable conditional, targeted use of Altivec based on runtime detection (which is what ioquake3 wants to do) without also giving the compiler permission to use Altivec in code generation; so to not crash on CPUs that do not implement Altivec, we'll have to turn it off altogether, except in translation units that are only entered when runtime Altivec detection is successful. This has been tested on Linux PPC (on an Altivec-enabled CPU), but we may need further work after testing trickles out to other PowerPC devices and ancient Mac OS X builds. I did a little work on this patch, but the majority of the effort belongs to Simon McVittie (thanks!).
This commit is contained in:
parent
2326a060b9
commit
5909b9a1cf
12 changed files with 686 additions and 607 deletions
|
@ -21,9 +21,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
*/
|
||||
// tr_surf.c
|
||||
#include "tr_local.h"
|
||||
#if idppc_altivec && !defined(__APPLE__)
|
||||
#include <altivec.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
|
@ -557,7 +554,7 @@ static void RB_SurfaceLightningBolt( void ) {
|
|||
* The inputs to this routing seem to always be close to length = 1.0 (about 0.6 to 2.0)
|
||||
* This means that we don't have to worry about zero length or enormously long vectors.
|
||||
*/
|
||||
static void VectorArrayNormalize(vec4_t *normals, unsigned int count)
|
||||
void VectorArrayNormalize(vec4_t *normals, unsigned int count)
|
||||
{
|
||||
// assert(count);
|
||||
|
||||
|
@ -612,136 +609,6 @@ static void VectorArrayNormalize(vec4_t *normals, unsigned int count)
|
|||
/*
|
||||
** LerpMeshVertexes
|
||||
*/
|
||||
#if idppc_altivec
|
||||
static void LerpMeshVertexes_altivec(md3Surface_t *surf, float backlerp)
|
||||
{
|
||||
short *oldXyz, *newXyz, *oldNormals, *newNormals;
|
||||
float *outXyz, *outNormal;
|
||||
float oldXyzScale QALIGN(16);
|
||||
float newXyzScale QALIGN(16);
|
||||
float oldNormalScale QALIGN(16);
|
||||
float newNormalScale QALIGN(16);
|
||||
int vertNum;
|
||||
unsigned lat, lng;
|
||||
int numVerts;
|
||||
|
||||
outXyz = tess.xyz[tess.numVertexes];
|
||||
outNormal = tess.normal[tess.numVertexes];
|
||||
|
||||
newXyz = (short *)((byte *)surf + surf->ofsXyzNormals)
|
||||
+ (backEnd.currentEntity->e.frame * surf->numVerts * 4);
|
||||
newNormals = newXyz + 3;
|
||||
|
||||
newXyzScale = MD3_XYZ_SCALE * (1.0 - backlerp);
|
||||
newNormalScale = 1.0 - backlerp;
|
||||
|
||||
numVerts = surf->numVerts;
|
||||
|
||||
if ( backlerp == 0 ) {
|
||||
vector signed short newNormalsVec0;
|
||||
vector signed short newNormalsVec1;
|
||||
vector signed int newNormalsIntVec;
|
||||
vector float newNormalsFloatVec;
|
||||
vector float newXyzScaleVec;
|
||||
vector unsigned char newNormalsLoadPermute;
|
||||
vector unsigned char newNormalsStorePermute;
|
||||
vector float zero;
|
||||
|
||||
newNormalsStorePermute = vec_lvsl(0,(float *)&newXyzScaleVec);
|
||||
newXyzScaleVec = *(vector float *)&newXyzScale;
|
||||
newXyzScaleVec = vec_perm(newXyzScaleVec,newXyzScaleVec,newNormalsStorePermute);
|
||||
newXyzScaleVec = vec_splat(newXyzScaleVec,0);
|
||||
newNormalsLoadPermute = vec_lvsl(0,newXyz);
|
||||
newNormalsStorePermute = vec_lvsr(0,outXyz);
|
||||
zero = (vector float)vec_splat_s8(0);
|
||||
//
|
||||
// just copy the vertexes
|
||||
//
|
||||
for (vertNum=0 ; vertNum < numVerts ; vertNum++,
|
||||
newXyz += 4, newNormals += 4,
|
||||
outXyz += 4, outNormal += 4)
|
||||
{
|
||||
newNormalsLoadPermute = vec_lvsl(0,newXyz);
|
||||
newNormalsStorePermute = vec_lvsr(0,outXyz);
|
||||
newNormalsVec0 = vec_ld(0,newXyz);
|
||||
newNormalsVec1 = vec_ld(16,newXyz);
|
||||
newNormalsVec0 = vec_perm(newNormalsVec0,newNormalsVec1,newNormalsLoadPermute);
|
||||
newNormalsIntVec = vec_unpackh(newNormalsVec0);
|
||||
newNormalsFloatVec = vec_ctf(newNormalsIntVec,0);
|
||||
newNormalsFloatVec = vec_madd(newNormalsFloatVec,newXyzScaleVec,zero);
|
||||
newNormalsFloatVec = vec_perm(newNormalsFloatVec,newNormalsFloatVec,newNormalsStorePermute);
|
||||
//outXyz[0] = newXyz[0] * newXyzScale;
|
||||
//outXyz[1] = newXyz[1] * newXyzScale;
|
||||
//outXyz[2] = newXyz[2] * newXyzScale;
|
||||
|
||||
lat = ( newNormals[0] >> 8 ) & 0xff;
|
||||
lng = ( newNormals[0] & 0xff );
|
||||
lat *= (FUNCTABLE_SIZE/256);
|
||||
lng *= (FUNCTABLE_SIZE/256);
|
||||
|
||||
// decode X as cos( lat ) * sin( long )
|
||||
// decode Y as sin( lat ) * sin( long )
|
||||
// decode Z as cos( long )
|
||||
|
||||
outNormal[0] = tr.sinTable[(lat+(FUNCTABLE_SIZE/4))&FUNCTABLE_MASK] * tr.sinTable[lng];
|
||||
outNormal[1] = tr.sinTable[lat] * tr.sinTable[lng];
|
||||
outNormal[2] = tr.sinTable[(lng+(FUNCTABLE_SIZE/4))&FUNCTABLE_MASK];
|
||||
|
||||
vec_ste(newNormalsFloatVec,0,outXyz);
|
||||
vec_ste(newNormalsFloatVec,4,outXyz);
|
||||
vec_ste(newNormalsFloatVec,8,outXyz);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// interpolate and copy the vertex and normal
|
||||
//
|
||||
oldXyz = (short *)((byte *)surf + surf->ofsXyzNormals)
|
||||
+ (backEnd.currentEntity->e.oldframe * surf->numVerts * 4);
|
||||
oldNormals = oldXyz + 3;
|
||||
|
||||
oldXyzScale = MD3_XYZ_SCALE * backlerp;
|
||||
oldNormalScale = backlerp;
|
||||
|
||||
for (vertNum=0 ; vertNum < numVerts ; vertNum++,
|
||||
oldXyz += 4, newXyz += 4, oldNormals += 4, newNormals += 4,
|
||||
outXyz += 4, outNormal += 4)
|
||||
{
|
||||
vec3_t uncompressedOldNormal, uncompressedNewNormal;
|
||||
|
||||
// interpolate the xyz
|
||||
outXyz[0] = oldXyz[0] * oldXyzScale + newXyz[0] * newXyzScale;
|
||||
outXyz[1] = oldXyz[1] * oldXyzScale + newXyz[1] * newXyzScale;
|
||||
outXyz[2] = oldXyz[2] * oldXyzScale + newXyz[2] * newXyzScale;
|
||||
|
||||
// FIXME: interpolate lat/long instead?
|
||||
lat = ( newNormals[0] >> 8 ) & 0xff;
|
||||
lng = ( newNormals[0] & 0xff );
|
||||
lat *= 4;
|
||||
lng *= 4;
|
||||
uncompressedNewNormal[0] = tr.sinTable[(lat+(FUNCTABLE_SIZE/4))&FUNCTABLE_MASK] * tr.sinTable[lng];
|
||||
uncompressedNewNormal[1] = tr.sinTable[lat] * tr.sinTable[lng];
|
||||
uncompressedNewNormal[2] = tr.sinTable[(lng+(FUNCTABLE_SIZE/4))&FUNCTABLE_MASK];
|
||||
|
||||
lat = ( oldNormals[0] >> 8 ) & 0xff;
|
||||
lng = ( oldNormals[0] & 0xff );
|
||||
lat *= 4;
|
||||
lng *= 4;
|
||||
|
||||
uncompressedOldNormal[0] = tr.sinTable[(lat+(FUNCTABLE_SIZE/4))&FUNCTABLE_MASK] * tr.sinTable[lng];
|
||||
uncompressedOldNormal[1] = tr.sinTable[lat] * tr.sinTable[lng];
|
||||
uncompressedOldNormal[2] = tr.sinTable[(lng+(FUNCTABLE_SIZE/4))&FUNCTABLE_MASK];
|
||||
|
||||
outNormal[0] = uncompressedOldNormal[0] * oldNormalScale + uncompressedNewNormal[0] * newNormalScale;
|
||||
outNormal[1] = uncompressedOldNormal[1] * oldNormalScale + uncompressedNewNormal[1] * newNormalScale;
|
||||
outNormal[2] = uncompressedOldNormal[2] * oldNormalScale + uncompressedNewNormal[2] * newNormalScale;
|
||||
|
||||
// VectorNormalize (outNormal);
|
||||
}
|
||||
VectorArrayNormalize((vec4_t *)tess.normal[tess.numVertexes], numVerts);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void LerpMeshVertexes_scalar(md3Surface_t *surf, float backlerp)
|
||||
{
|
||||
short *oldXyz, *newXyz, *oldNormals, *newNormals;
|
||||
|
@ -844,7 +711,7 @@ static void LerpMeshVertexes(md3Surface_t *surf, float backlerp)
|
|||
{
|
||||
#if idppc_altivec
|
||||
if (com_altivec->integer) {
|
||||
// must be in a separate function or G3 systems will crash.
|
||||
// must be in a separate translation unit or G3 systems will crash.
|
||||
LerpMeshVertexes_altivec( surf, backlerp );
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue