summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/draw
diff options
context:
space:
mode:
authorRoland Scheidegger <[email protected]>2013-11-11 15:11:59 +0000
committerRoland Scheidegger <[email protected]>2013-11-12 19:08:58 +0000
commit50f19e3a668b1b589bf00613d33c7c7c4e6a4954 (patch)
tree935ead207e3501e91c31c1590f40a0d751de2dea /src/gallium/auxiliary/draw
parent2d77e4f922a8c34541d8b187e171738006bd6f4d (diff)
draw,llvmpipe: use exponent manipulation instead of exp2 for polygon offset
Since we explicitly require a integer input we should avoid using exp2 math (even if we were using optimized versions), which turns the exp2 into a int sub (plus some casts). v2: fix bogus uint (needs to be int) math spotted by Matthew, fix comments Reviewed-by: Jose Fonseca <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/draw')
-rw-r--r--src/gallium/auxiliary/draw/draw_pipe_offset.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/gallium/auxiliary/draw/draw_pipe_offset.c b/src/gallium/auxiliary/draw/draw_pipe_offset.c
index 8071bc77b80..34114035ac8 100644
--- a/src/gallium/auxiliary/draw/draw_pipe_offset.c
+++ b/src/gallium/auxiliary/draw/draw_pipe_offset.c
@@ -90,18 +90,23 @@ static void do_offset_tri( struct draw_stage *stage,
float dzdx = fabsf(a * inv_det);
float dzdy = fabsf(b * inv_det);
- float zoffset, maxz, bias, mult;
+ float zoffset, mult;
mult = MAX2(dzdx, dzdy) * offset->scale;
if (stage->draw->floating_point_depth) {
- maxz = MAX3(v0[2], v1[2], v2[2]);
-
- /**
- * XXX: TODO optimize this to quickly resolve a pow2 number through
- * an exponent only operation.
- */
- bias = offset->units * util_fast_exp2(util_get_float32_exponent(maxz) - 23);
+ float bias;
+ union fi maxz;
+ maxz.f = MAX3(v0[2], v1[2], v2[2]);
+ /* just do the math directly on shifted number */
+ maxz.ui &= 0xff << 23;
+ maxz.i -= 23 << 23;
+ /* Clamping to zero means mrd will be zero for very small numbers,
+ * but specs do not indicate this should be prevented by clamping
+ * mrd to smallest normal number instead. */
+ maxz.i = MAX2(maxz.i, 0);
+
+ bias = offset->units * maxz.f;
zoffset = bias + mult;
} else {
zoffset = offset->units + mult;