Thanks,
The assembly innerloops should help with optimizing. I'm not using tiled textures, so I don't think I can do much about cache coherency. Another hurdle is that for textured triangles there's no point in reading 32 bits (2 pixels) of the texture at a time, since consecutive pixels in uv do not necessarily map to consecutive pixels in xy.
So the only points where I can optimize is reducing to 1 division/triangle and making the innerloop as tight as possible.
Interestingly, a more efficient use of the cache and 32bit reads are possible if instead one were to do an affine transformation FROM the texture uv coordinates TO the screen xy coordinates. However that entails gaps between pixels for stretched textures and overwrites for compressed textures... Though perhaps it is worth investigating if one knows beforehand that the texture will never be stretched...
Anyway I am having some trouble reducing to 1 division due to limited fixed point range. Here's some sample code:
- Code:
//A,B,C,invC are in 24.8 fixed pt
int C = (X2 - X1) * (Y3 - Y1) - (X3 - X1) * (Y2 - Y1);
if (C == 0) return;
int invC = (1<<8) / C; // <--- not enough accuracy
int A = (U3 - U1) * (Y2 - Y1) - (U2 - U1) * (Y3 - Y1);
int B = (X3 - X1) * (U2 - U1) - (X2 - X1) * (U3 - U1);
//dudx, dudy are 16.16 fixed pt
const int dudx = -(A*invC);
const int dudy = -(B*invC);
I tried making invC 16.16 fixed pt, but without much gain. The texture still jitters. Would you recommend using floating point instead? Or perhaps I should try using Intel's gppMul_16_32s to gain some more accuracy?