PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Optimize z-buffered texturing

oki, here is another one. it's the inner loop that does piecewise interpolation for texturing.

spanw is 8, spans is 3.
u0,u1,v0,v1,du,dv,w & Width are simple integers.
OneOverZ, dOneOverZdX__, UOverZ, dUOverZdX__, VOverZ, dVOverZdX__, runZ, ZStep & Z are objects of a class that wrapps the GPP fixed point routines.

Code:

while(Width>spanw) {
OneOverZ += dOneOverZdX__;
UOverZ += dUOverZdX__;
VOverZ += dVOverZdX__;

Z = OneOverZ;
inverse(Z);
u1 = sgl_cast_int(UOverZ * Z)<<8;
v1 = sgl_cast_int(VOverZ * Z)<<8;

du = (u1-u0)>>spans;
dv = (v1-v0)>>spans;
w = spanw;

while(w--)
{
int curZ = sgl_cast_int(runZ);
if(curZ < *dstZ)
{
*dstZ = curZ;
*dstC = *(texturePixels + ((u0>>8)&wMask;) + (((v0>>8)&hMask;) << wShift));
}

runZ += ZStep;
dstC++;
dstZ++;

u0 += du;
v0 += dv;
}

Width -= spanw;
u0 = u1;
v0 = v1;
}


i would have liked to post the asm code, but it's quite long (~180 lines only for the code above). so i put it to http://www.ims.tuwien.ac.at/~daniel/innerloop.cod

any ideas on optimizing that?
in fact when i look at what the compiler produced i think that using the GPP fixed point methods natively might be here really worth instead of wrapping it into a class as i do for the rest of my code.

DANIEL