aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/cell
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2008-10-17 09:09:57 -0600
committerBrian Paul <[email protected]>2008-10-17 14:14:23 -0600
commit81724da4f61f2ba678e2e0376209e1b754e1ecab (patch)
treef6f10a5ecbdf16ef452a72a8ddddbb1b389f467f /src/gallium/drivers/cell
parent9fa8671c73fa44a95e2ea7fed6047bddb042796f (diff)
cell: use an approximation in compute_lambda_2d() to avoid sqrt
Though, the logf() call still needs attention.
Diffstat (limited to 'src/gallium/drivers/cell')
-rw-r--r--src/gallium/drivers/cell/spu/spu_texture.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/gallium/drivers/cell/spu/spu_texture.c b/src/gallium/drivers/cell/spu/spu_texture.c
index 4e12a116cdc..69784c89788 100644
--- a/src/gallium/drivers/cell/spu/spu_texture.c
+++ b/src/gallium/drivers/cell/spu/spu_texture.c
@@ -414,7 +414,7 @@ sample_texture_2d_bilinear_int(vector float s, vector float t,
/**
* Compute level of detail factor from texcoords.
*/
-static float
+static INLINE float
compute_lambda_2d(uint unit, vector float s, vector float t)
{
uint baseLevel = 0;
@@ -424,11 +424,21 @@ compute_lambda_2d(uint unit, vector float s, vector float t)
float dsdy = width * (spu_extract(s, 2) - spu_extract(s, 0));
float dtdx = height * (spu_extract(t, 1) - spu_extract(t, 0));
float dtdy = height * (spu_extract(t, 2) - spu_extract(t, 0));
+#if 0
+ /* ideal value */
float x = dsdx * dsdx + dtdx * dtdx;
float y = dsdy * dsdy + dtdy * dtdy;
float rho = x > y ? x : y;
rho = sqrtf(rho);
- float lambda = logf(rho) * 1.442695f;
+#else
+ /* approximation */
+ dsdx = fabsf(dsdx);
+ dsdy = fabsf(dsdy);
+ dtdx = fabsf(dtdx);
+ dtdy = fabsf(dtdy);
+ float rho = (dsdx + dsdy + dtdx + dtdy) * 0.5;
+#endif
+ float lambda = logf(rho) * 1.442695f; /* compute logbase2(rho) */
return lambda;
}