aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gallium/auxiliary/util/u_math.h23
-rw-r--r--src/mesa/state_tracker/st_cb_texture.c17
2 files changed, 22 insertions, 18 deletions
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index e5003af01d8..30e6e2f6b37 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -216,23 +216,23 @@ util_fast_exp2(float x)
int32_t ipart;
float fpart, mpart;
union fi epart;
-
+
if(x > 129.00000f)
return 3.402823466e+38f;
-
+
if(x < -126.99999f)
return 0.0f;
ipart = (int32_t) x;
fpart = x - (float) ipart;
-
+
/* same as
* epart.f = (float) (1 << ipart)
* but faster and without integer overflow for ipart > 31 */
epart.i = (ipart + 127 ) << 23;
-
+
mpart = pow2_table[POW2_TABLE_OFFSET + (int)(fpart * POW2_TABLE_SCALE)];
-
+
return epart.f * mpart;
}
@@ -409,6 +409,19 @@ float_to_ubyte(float f)
}
+/**
+ * Calc log base 2
+ */
+static INLINE unsigned
+util_logbase2(unsigned n)
+{
+ unsigned log2 = 0;
+ while (n >>= 1)
+ ++log2;
+ return log2;
+}
+
+
#define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) )
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index ee71c012c64..e8d7f70ad65 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -59,6 +59,7 @@
#include "util/u_tile.h"
#include "util/u_blit.h"
#include "util/u_surface.h"
+#include "util/u_math.h"
#define DBG if (0) printf
@@ -237,16 +238,6 @@ do_memcpy(void *dest, const void *src, size_t n)
}
-static INLINE unsigned
-logbase2(unsigned n)
-{
- unsigned log2 = 0;
- while (n >>= 1)
- ++log2;
- return log2;
-}
-
-
/**
* Return default texture usage bitmask for the given texture format.
*/
@@ -340,9 +331,9 @@ guess_and_alloc_texture(struct st_context *st,
lastLevel = firstLevel;
}
else {
- GLuint l2width = logbase2(width);
- GLuint l2height = logbase2(height);
- GLuint l2depth = logbase2(depth);
+ GLuint l2width = util_logbase2(width);
+ GLuint l2height = util_logbase2(height);
+ GLuint l2depth = util_logbase2(depth);
lastLevel = firstLevel + MAX2(MAX2(l2width, l2height), l2depth);
}