gallium: stop using ifloor(), FABSF(), etc

This commit is contained in:
Brian Paul
2008-08-22 15:51:02 -06:00
parent 120270def7
commit 9935e3b730
2 changed files with 44 additions and 42 deletions

View File

@@ -44,6 +44,8 @@
#include "draw/draw_vertex.h" #include "draw/draw_vertex.h"
#include "pipe/p_util.h" #include "pipe/p_util.h"
#include "pipe/p_shader_tokens.h" #include "pipe/p_shader_tokens.h"
#include "util/u_math.h"
#define DEBUG_VERTS 0 #define DEBUG_VERTS 0
#define DEBUG_FRAGS 0 #define DEBUG_FRAGS 0
@@ -611,18 +613,18 @@ static void setup_tri_edges( struct setup_context *setup )
float vmid_y = setup->vmid[0][1] - 0.5f; float vmid_y = setup->vmid[0][1] - 0.5f;
float vmax_y = setup->vmax[0][1] - 0.5f; float vmax_y = setup->vmax[0][1] - 0.5f;
setup->emaj.sy = CEILF(vmin_y); setup->emaj.sy = ceilf(vmin_y);
setup->emaj.lines = (int) CEILF(vmax_y - setup->emaj.sy); setup->emaj.lines = (int) ceilf(vmax_y - setup->emaj.sy);
setup->emaj.dxdy = setup->emaj.dx / setup->emaj.dy; setup->emaj.dxdy = setup->emaj.dx / setup->emaj.dy;
setup->emaj.sx = vmin_x + (setup->emaj.sy - vmin_y) * setup->emaj.dxdy; setup->emaj.sx = vmin_x + (setup->emaj.sy - vmin_y) * setup->emaj.dxdy;
setup->etop.sy = CEILF(vmid_y); setup->etop.sy = ceilf(vmid_y);
setup->etop.lines = (int) CEILF(vmax_y - setup->etop.sy); setup->etop.lines = (int) ceilf(vmax_y - setup->etop.sy);
setup->etop.dxdy = setup->etop.dx / setup->etop.dy; setup->etop.dxdy = setup->etop.dx / setup->etop.dy;
setup->etop.sx = vmid_x + (setup->etop.sy - vmid_y) * setup->etop.dxdy; setup->etop.sx = vmid_x + (setup->etop.sy - vmid_y) * setup->etop.dxdy;
setup->ebot.sy = CEILF(vmin_y); setup->ebot.sy = ceilf(vmin_y);
setup->ebot.lines = (int) CEILF(vmid_y - setup->ebot.sy); setup->ebot.lines = (int) ceilf(vmid_y - setup->ebot.sy);
setup->ebot.dxdy = setup->ebot.dx / setup->ebot.dy; setup->ebot.dxdy = setup->ebot.dx / setup->ebot.dy;
setup->ebot.sx = vmin_x + (setup->ebot.sy - vmin_y) * setup->ebot.dxdy; setup->ebot.sx = vmin_x + (setup->ebot.sy - vmin_y) * setup->ebot.dxdy;
} }

View File

@@ -51,7 +51,7 @@
* Also note, FRAC(x) doesn't truly return the fractional part of x for x < 0. * Also note, FRAC(x) doesn't truly return the fractional part of x for x < 0.
* Instead, if x < 0 then FRAC(x) = 1 - true_frac(x). * Instead, if x < 0 then FRAC(x) = 1 - true_frac(x).
*/ */
#define FRAC(f) ((f) - ifloor(f)) #define FRAC(f) ((f) - util_ifloor(f))
/** /**
@@ -100,7 +100,7 @@ nearest_texcoord(unsigned wrapMode, float s, unsigned size)
case PIPE_TEX_WRAP_REPEAT: case PIPE_TEX_WRAP_REPEAT:
/* s limited to [0,1) */ /* s limited to [0,1) */
/* i limited to [0,size-1] */ /* i limited to [0,size-1] */
i = ifloor(s * size); i = util_ifloor(s * size);
i = REMAINDER(i, size); i = REMAINDER(i, size);
return i; return i;
case PIPE_TEX_WRAP_CLAMP: case PIPE_TEX_WRAP_CLAMP:
@@ -111,7 +111,7 @@ nearest_texcoord(unsigned wrapMode, float s, unsigned size)
else if (s >= 1.0F) else if (s >= 1.0F)
i = size - 1; i = size - 1;
else else
i = ifloor(s * size); i = util_ifloor(s * size);
return i; return i;
case PIPE_TEX_WRAP_CLAMP_TO_EDGE: case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
{ {
@@ -124,7 +124,7 @@ nearest_texcoord(unsigned wrapMode, float s, unsigned size)
else if (s > max) else if (s > max)
i = size - 1; i = size - 1;
else else
i = ifloor(s * size); i = util_ifloor(s * size);
} }
return i; return i;
case PIPE_TEX_WRAP_CLAMP_TO_BORDER: case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
@@ -138,14 +138,14 @@ nearest_texcoord(unsigned wrapMode, float s, unsigned size)
else if (s >= max) else if (s >= max)
i = size; i = size;
else else
i = ifloor(s * size); i = util_ifloor(s * size);
} }
return i; return i;
case PIPE_TEX_WRAP_MIRROR_REPEAT: case PIPE_TEX_WRAP_MIRROR_REPEAT:
{ {
const float min = 1.0F / (2.0F * size); const float min = 1.0F / (2.0F * size);
const float max = 1.0F - min; const float max = 1.0F - min;
const int flr = ifloor(s); const int flr = util_ifloor(s);
float u; float u;
if (flr & 1) if (flr & 1)
u = 1.0F - (s - (float) flr); u = 1.0F - (s - (float) flr);
@@ -156,20 +156,20 @@ nearest_texcoord(unsigned wrapMode, float s, unsigned size)
else if (u > max) else if (u > max)
i = size - 1; i = size - 1;
else else
i = ifloor(u * size); i = util_ifloor(u * size);
} }
return i; return i;
case PIPE_TEX_WRAP_MIRROR_CLAMP: case PIPE_TEX_WRAP_MIRROR_CLAMP:
{ {
/* s limited to [0,1] */ /* s limited to [0,1] */
/* i limited to [0,size-1] */ /* i limited to [0,size-1] */
const float u = FABSF(s); const float u = fabsf(s);
if (u <= 0.0F) if (u <= 0.0F)
i = 0; i = 0;
else if (u >= 1.0F) else if (u >= 1.0F)
i = size - 1; i = size - 1;
else else
i = ifloor(u * size); i = util_ifloor(u * size);
} }
return i; return i;
case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
@@ -178,13 +178,13 @@ nearest_texcoord(unsigned wrapMode, float s, unsigned size)
/* i limited to [0, size-1] */ /* i limited to [0, size-1] */
const float min = 1.0F / (2.0F * size); const float min = 1.0F / (2.0F * size);
const float max = 1.0F - min; const float max = 1.0F - min;
const float u = FABSF(s); const float u = fabsf(s);
if (u < min) if (u < min)
i = 0; i = 0;
else if (u > max) else if (u > max)
i = size - 1; i = size - 1;
else else
i = ifloor(u * size); i = util_ifloor(u * size);
} }
return i; return i;
case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
@@ -193,13 +193,13 @@ nearest_texcoord(unsigned wrapMode, float s, unsigned size)
/* i limited to [0, size-1] */ /* i limited to [0, size-1] */
const float min = -1.0F / (2.0F * size); const float min = -1.0F / (2.0F * size);
const float max = 1.0F - min; const float max = 1.0F - min;
const float u = FABSF(s); const float u = fabsf(s);
if (u < min) if (u < min)
i = -1; i = -1;
else if (u > max) else if (u > max)
i = size; i = size;
else else
i = ifloor(u * size); i = util_ifloor(u * size);
} }
return i; return i;
default: default:
@@ -226,7 +226,7 @@ linear_texcoord(unsigned wrapMode, float s, unsigned size,
switch (wrapMode) { switch (wrapMode) {
case PIPE_TEX_WRAP_REPEAT: case PIPE_TEX_WRAP_REPEAT:
u = s * size - 0.5F; u = s * size - 0.5F;
*i0 = REMAINDER(ifloor(u), size); *i0 = REMAINDER(util_ifloor(u), size);
*i1 = REMAINDER(*i0 + 1, size); *i1 = REMAINDER(*i0 + 1, size);
break; break;
case PIPE_TEX_WRAP_CLAMP: case PIPE_TEX_WRAP_CLAMP:
@@ -237,7 +237,7 @@ linear_texcoord(unsigned wrapMode, float s, unsigned size,
else else
u = s * size; u = s * size;
u -= 0.5F; u -= 0.5F;
*i0 = ifloor(u); *i0 = util_ifloor(u);
*i1 = *i0 + 1; *i1 = *i0 + 1;
break; break;
case PIPE_TEX_WRAP_CLAMP_TO_EDGE: case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
@@ -248,7 +248,7 @@ linear_texcoord(unsigned wrapMode, float s, unsigned size,
else else
u = s * size; u = s * size;
u -= 0.5F; u -= 0.5F;
*i0 = ifloor(u); *i0 = util_ifloor(u);
*i1 = *i0 + 1; *i1 = *i0 + 1;
if (*i0 < 0) if (*i0 < 0)
*i0 = 0; *i0 = 0;
@@ -266,19 +266,19 @@ linear_texcoord(unsigned wrapMode, float s, unsigned size,
else else
u = s * size; u = s * size;
u -= 0.5F; u -= 0.5F;
*i0 = ifloor(u); *i0 = util_ifloor(u);
*i1 = *i0 + 1; *i1 = *i0 + 1;
} }
break; break;
case PIPE_TEX_WRAP_MIRROR_REPEAT: case PIPE_TEX_WRAP_MIRROR_REPEAT:
{ {
const int flr = ifloor(s); const int flr = util_ifloor(s);
if (flr & 1) if (flr & 1)
u = 1.0F - (s - (float) flr); u = 1.0F - (s - (float) flr);
else else
u = s - (float) flr; u = s - (float) flr;
u = (u * size) - 0.5F; u = (u * size) - 0.5F;
*i0 = ifloor(u); *i0 = util_ifloor(u);
*i1 = *i0 + 1; *i1 = *i0 + 1;
if (*i0 < 0) if (*i0 < 0)
*i0 = 0; *i0 = 0;
@@ -287,23 +287,23 @@ linear_texcoord(unsigned wrapMode, float s, unsigned size,
} }
break; break;
case PIPE_TEX_WRAP_MIRROR_CLAMP: case PIPE_TEX_WRAP_MIRROR_CLAMP:
u = FABSF(s); u = fabsf(s);
if (u >= 1.0F) if (u >= 1.0F)
u = (float) size; u = (float) size;
else else
u *= size; u *= size;
u -= 0.5F; u -= 0.5F;
*i0 = ifloor(u); *i0 = util_ifloor(u);
*i1 = *i0 + 1; *i1 = *i0 + 1;
break; break;
case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
u = FABSF(s); u = fabsf(s);
if (u >= 1.0F) if (u >= 1.0F)
u = (float) size; u = (float) size;
else else
u *= size; u *= size;
u -= 0.5F; u -= 0.5F;
*i0 = ifloor(u); *i0 = util_ifloor(u);
*i1 = *i0 + 1; *i1 = *i0 + 1;
if (*i0 < 0) if (*i0 < 0)
*i0 = 0; *i0 = 0;
@@ -314,7 +314,7 @@ linear_texcoord(unsigned wrapMode, float s, unsigned size,
{ {
const float min = -1.0F / (2.0F * size); const float min = -1.0F / (2.0F * size);
const float max = 1.0F - min; const float max = 1.0F - min;
u = FABSF(s); u = fabsf(s);
if (u <= min) if (u <= min)
u = min * size; u = min * size;
else if (u >= max) else if (u >= max)
@@ -322,7 +322,7 @@ linear_texcoord(unsigned wrapMode, float s, unsigned size,
else else
u *= size; u *= size;
u -= 0.5F; u -= 0.5F;
*i0 = ifloor(u); *i0 = util_ifloor(u);
*i1 = *i0 + 1; *i1 = *i0 + 1;
} }
break; break;
@@ -343,12 +343,12 @@ nearest_texcoord_unnorm(unsigned wrapMode, float s, unsigned size)
int i; int i;
switch (wrapMode) { switch (wrapMode) {
case PIPE_TEX_WRAP_CLAMP: case PIPE_TEX_WRAP_CLAMP:
i = ifloor(s); i = util_ifloor(s);
return CLAMP(i, 0, (int) size-1); return CLAMP(i, 0, (int) size-1);
case PIPE_TEX_WRAP_CLAMP_TO_EDGE: case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
/* fall-through */ /* fall-through */
case PIPE_TEX_WRAP_CLAMP_TO_BORDER: case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
return ifloor( CLAMP(s, 0.5F, (float) size - 0.5F) ); return util_ifloor( CLAMP(s, 0.5F, (float) size - 0.5F) );
default: default:
assert(0); assert(0);
return 0; return 0;
@@ -368,7 +368,7 @@ linear_texcoord_unnorm(unsigned wrapMode, float s, unsigned size,
case PIPE_TEX_WRAP_CLAMP: case PIPE_TEX_WRAP_CLAMP:
/* Not exactly what the spec says, but it matches NVIDIA output */ /* Not exactly what the spec says, but it matches NVIDIA output */
s = CLAMP(s - 0.5F, 0.0f, (float) size - 1.0f); s = CLAMP(s - 0.5F, 0.0f, (float) size - 1.0f);
*i0 = ifloor(s); *i0 = util_ifloor(s);
*i1 = *i0 + 1; *i1 = *i0 + 1;
break; break;
case PIPE_TEX_WRAP_CLAMP_TO_EDGE: case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
@@ -376,7 +376,7 @@ linear_texcoord_unnorm(unsigned wrapMode, float s, unsigned size,
case PIPE_TEX_WRAP_CLAMP_TO_BORDER: case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
s = CLAMP(s, 0.5F, (float) size - 0.5F); s = CLAMP(s, 0.5F, (float) size - 0.5F);
s -= 0.5F; s -= 0.5F;
*i0 = ifloor(s); *i0 = util_ifloor(s);
*i1 = *i0 + 1; *i1 = *i0 + 1;
if (*i1 > (int) size - 1) if (*i1 > (int) size - 1)
*i1 = size - 1; *i1 = size - 1;
@@ -402,7 +402,7 @@ choose_cube_face(float rx, float ry, float rz, float *newS, float *newT)
+rz TEXTURE_CUBE_MAP_POSITIVE_Z_EXT +rx -ry rz +rz TEXTURE_CUBE_MAP_POSITIVE_Z_EXT +rx -ry rz
-rz TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT -rx -ry rz -rz TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT -rx -ry rz
*/ */
const float arx = FABSF(rx), ary = FABSF(ry), arz = FABSF(rz); const float arx = fabsf(rx), ary = fabsf(ry), arz = fabsf(rz);
unsigned face; unsigned face;
float sc, tc, ma; float sc, tc, ma;
@@ -477,16 +477,16 @@ compute_lambda(struct tgsi_sampler *sampler,
{ {
float dsdx = s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]; float dsdx = s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT];
float dsdy = s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]; float dsdy = s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT];
dsdx = FABSF(dsdx); dsdx = fabsf(dsdx);
dsdy = FABSF(dsdy); dsdy = fabsf(dsdy);
rho = MAX2(dsdx, dsdy) * sampler->texture->width[0]; rho = MAX2(dsdx, dsdy) * sampler->texture->width[0];
} }
if (t) { if (t) {
float dtdx = t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]; float dtdx = t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT];
float dtdy = t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT]; float dtdy = t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT];
float max; float max;
dtdx = FABSF(dtdx); dtdx = fabsf(dtdx);
dtdy = FABSF(dtdy); dtdy = fabsf(dtdy);
max = MAX2(dtdx, dtdy) * sampler->texture->height[0]; max = MAX2(dtdx, dtdy) * sampler->texture->height[0];
rho = MAX2(rho, max); rho = MAX2(rho, max);
} }
@@ -494,8 +494,8 @@ compute_lambda(struct tgsi_sampler *sampler,
float dpdx = p[QUAD_BOTTOM_RIGHT] - p[QUAD_BOTTOM_LEFT]; float dpdx = p[QUAD_BOTTOM_RIGHT] - p[QUAD_BOTTOM_LEFT];
float dpdy = p[QUAD_TOP_LEFT] - p[QUAD_BOTTOM_LEFT]; float dpdy = p[QUAD_TOP_LEFT] - p[QUAD_BOTTOM_LEFT];
float max; float max;
dpdx = FABSF(dpdx); dpdx = fabsf(dpdx);
dpdy = FABSF(dpdy); dpdy = fabsf(dpdy);
max = MAX2(dpdx, dpdy) * sampler->texture->depth[0]; max = MAX2(dpdx, dpdy) * sampler->texture->depth[0];
rho = MAX2(rho, max); rho = MAX2(rho, max);
} }