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
|
@ -22,9 +22,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
// tr_shade.c
|
||||
|
||||
#include "tr_local.h"
|
||||
#if idppc_altivec && !defined(__APPLE__)
|
||||
#include <altivec.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
|
@ -163,7 +160,7 @@ instead of using the single glDrawElements call that may be inefficient
|
|||
without compiled vertex arrays.
|
||||
==================
|
||||
*/
|
||||
static void R_DrawElements( int numIndexes, const glIndex_t *indexes ) {
|
||||
void R_DrawElements( int numIndexes, const glIndex_t *indexes ) {
|
||||
int primitives;
|
||||
|
||||
primitives = r_primitives->integer;
|
||||
|
@ -407,189 +404,6 @@ ProjectDlightTexture
|
|||
Perform dynamic lighting with another rendering pass
|
||||
===================
|
||||
*/
|
||||
#if idppc_altivec
|
||||
static void ProjectDlightTexture_altivec( void ) {
|
||||
int i, l;
|
||||
vec_t origin0, origin1, origin2;
|
||||
float texCoords0, texCoords1;
|
||||
vector float floatColorVec0, floatColorVec1;
|
||||
vector float modulateVec, colorVec, zero;
|
||||
vector short colorShort;
|
||||
vector signed int colorInt;
|
||||
vector unsigned char floatColorVecPerm, modulatePerm, colorChar;
|
||||
vector unsigned char vSel = VECCONST_UINT8(0x00, 0x00, 0x00, 0xff,
|
||||
0x00, 0x00, 0x00, 0xff,
|
||||
0x00, 0x00, 0x00, 0xff,
|
||||
0x00, 0x00, 0x00, 0xff);
|
||||
float *texCoords;
|
||||
byte *colors;
|
||||
byte clipBits[SHADER_MAX_VERTEXES];
|
||||
float texCoordsArray[SHADER_MAX_VERTEXES][2];
|
||||
byte colorArray[SHADER_MAX_VERTEXES][4];
|
||||
glIndex_t hitIndexes[SHADER_MAX_INDEXES];
|
||||
int numIndexes;
|
||||
float scale;
|
||||
float radius;
|
||||
vec3_t floatColor;
|
||||
float modulate = 0.0f;
|
||||
|
||||
if ( !backEnd.refdef.num_dlights ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// There has to be a better way to do this so that floatColor
|
||||
// and/or modulate are already 16-byte aligned.
|
||||
floatColorVecPerm = vec_lvsl(0,(float *)floatColor);
|
||||
modulatePerm = vec_lvsl(0,(float *)&modulate);
|
||||
modulatePerm = (vector unsigned char)vec_splat((vector unsigned int)modulatePerm,0);
|
||||
zero = (vector float)vec_splat_s8(0);
|
||||
|
||||
for ( l = 0 ; l < backEnd.refdef.num_dlights ; l++ ) {
|
||||
dlight_t *dl;
|
||||
|
||||
if ( !( tess.dlightBits & ( 1 << l ) ) ) {
|
||||
continue; // this surface definitely doesn't have any of this light
|
||||
}
|
||||
texCoords = texCoordsArray[0];
|
||||
colors = colorArray[0];
|
||||
|
||||
dl = &backEnd.refdef.dlights[l];
|
||||
origin0 = dl->transformed[0];
|
||||
origin1 = dl->transformed[1];
|
||||
origin2 = dl->transformed[2];
|
||||
radius = dl->radius;
|
||||
scale = 1.0f / radius;
|
||||
|
||||
if(r_greyscale->integer)
|
||||
{
|
||||
float luminance;
|
||||
|
||||
luminance = LUMA(dl->color[0], dl->color[1], dl->color[2]) * 255.0f;
|
||||
floatColor[0] = floatColor[1] = floatColor[2] = luminance;
|
||||
}
|
||||
else if(r_greyscale->value)
|
||||
{
|
||||
float luminance;
|
||||
|
||||
luminance = LUMA(dl->color[0], dl->color[1], dl->color[2]) * 255.0f;
|
||||
floatColor[0] = LERP(dl->color[0] * 255.0f, luminance, r_greyscale->value);
|
||||
floatColor[1] = LERP(dl->color[1] * 255.0f, luminance, r_greyscale->value);
|
||||
floatColor[2] = LERP(dl->color[2] * 255.0f, luminance, r_greyscale->value);
|
||||
}
|
||||
else
|
||||
{
|
||||
floatColor[0] = dl->color[0] * 255.0f;
|
||||
floatColor[1] = dl->color[1] * 255.0f;
|
||||
floatColor[2] = dl->color[2] * 255.0f;
|
||||
}
|
||||
floatColorVec0 = vec_ld(0, floatColor);
|
||||
floatColorVec1 = vec_ld(11, floatColor);
|
||||
floatColorVec0 = vec_perm(floatColorVec0,floatColorVec0,floatColorVecPerm);
|
||||
for ( i = 0 ; i < tess.numVertexes ; i++, texCoords += 2, colors += 4 ) {
|
||||
int clip = 0;
|
||||
vec_t dist0, dist1, dist2;
|
||||
|
||||
dist0 = origin0 - tess.xyz[i][0];
|
||||
dist1 = origin1 - tess.xyz[i][1];
|
||||
dist2 = origin2 - tess.xyz[i][2];
|
||||
|
||||
backEnd.pc.c_dlightVertexes++;
|
||||
|
||||
texCoords0 = 0.5f + dist0 * scale;
|
||||
texCoords1 = 0.5f + dist1 * scale;
|
||||
|
||||
if( !r_dlightBacks->integer &&
|
||||
// dist . tess.normal[i]
|
||||
( dist0 * tess.normal[i][0] +
|
||||
dist1 * tess.normal[i][1] +
|
||||
dist2 * tess.normal[i][2] ) < 0.0f ) {
|
||||
clip = 63;
|
||||
} else {
|
||||
if ( texCoords0 < 0.0f ) {
|
||||
clip |= 1;
|
||||
} else if ( texCoords0 > 1.0f ) {
|
||||
clip |= 2;
|
||||
}
|
||||
if ( texCoords1 < 0.0f ) {
|
||||
clip |= 4;
|
||||
} else if ( texCoords1 > 1.0f ) {
|
||||
clip |= 8;
|
||||
}
|
||||
texCoords[0] = texCoords0;
|
||||
texCoords[1] = texCoords1;
|
||||
|
||||
// modulate the strength based on the height and color
|
||||
if ( dist2 > radius ) {
|
||||
clip |= 16;
|
||||
modulate = 0.0f;
|
||||
} else if ( dist2 < -radius ) {
|
||||
clip |= 32;
|
||||
modulate = 0.0f;
|
||||
} else {
|
||||
dist2 = Q_fabs(dist2);
|
||||
if ( dist2 < radius * 0.5f ) {
|
||||
modulate = 1.0f;
|
||||
} else {
|
||||
modulate = 2.0f * (radius - dist2) * scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
clipBits[i] = clip;
|
||||
|
||||
modulateVec = vec_ld(0,(float *)&modulate);
|
||||
modulateVec = vec_perm(modulateVec,modulateVec,modulatePerm);
|
||||
colorVec = vec_madd(floatColorVec0,modulateVec,zero);
|
||||
colorInt = vec_cts(colorVec,0); // RGBx
|
||||
colorShort = vec_pack(colorInt,colorInt); // RGBxRGBx
|
||||
colorChar = vec_packsu(colorShort,colorShort); // RGBxRGBxRGBxRGBx
|
||||
colorChar = vec_sel(colorChar,vSel,vSel); // RGBARGBARGBARGBA replace alpha with 255
|
||||
vec_ste((vector unsigned int)colorChar,0,(unsigned int *)colors); // store color
|
||||
}
|
||||
|
||||
// build a list of triangles that need light
|
||||
numIndexes = 0;
|
||||
for ( i = 0 ; i < tess.numIndexes ; i += 3 ) {
|
||||
int a, b, c;
|
||||
|
||||
a = tess.indexes[i];
|
||||
b = tess.indexes[i+1];
|
||||
c = tess.indexes[i+2];
|
||||
if ( clipBits[a] & clipBits[b] & clipBits[c] ) {
|
||||
continue; // not lighted
|
||||
}
|
||||
hitIndexes[numIndexes] = a;
|
||||
hitIndexes[numIndexes+1] = b;
|
||||
hitIndexes[numIndexes+2] = c;
|
||||
numIndexes += 3;
|
||||
}
|
||||
|
||||
if ( !numIndexes ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
qglEnableClientState( GL_TEXTURE_COORD_ARRAY );
|
||||
qglTexCoordPointer( 2, GL_FLOAT, 0, texCoordsArray[0] );
|
||||
|
||||
qglEnableClientState( GL_COLOR_ARRAY );
|
||||
qglColorPointer( 4, GL_UNSIGNED_BYTE, 0, colorArray );
|
||||
|
||||
GL_Bind( tr.dlightImage );
|
||||
// include GLS_DEPTHFUNC_EQUAL so alpha tested surfaces don't add light
|
||||
// where they aren't rendered
|
||||
if ( dl->additive ) {
|
||||
GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL );
|
||||
}
|
||||
else {
|
||||
GL_State( GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL );
|
||||
}
|
||||
R_DrawElements( numIndexes, hitIndexes );
|
||||
backEnd.pc.c_totalIndexes += numIndexes;
|
||||
backEnd.pc.c_dlightIndexes += numIndexes;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static void ProjectDlightTexture_scalar( void ) {
|
||||
int i, l;
|
||||
vec3_t origin;
|
||||
|
@ -745,7 +559,7 @@ static void ProjectDlightTexture_scalar( void ) {
|
|||
static void ProjectDlightTexture( void ) {
|
||||
#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.
|
||||
ProjectDlightTexture_altivec();
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue