[Mesa-dev] [PATCH 2/2] st/mesa: remove _min(), _maxf(), _clamp()

Brian Paul brianp at vmware.com
Thu Jan 9 11:21:10 PST 2014


Just use the existing MIN2, MAX2 and CLAMP macros.
---
 src/mesa/state_tracker/st_extensions.c |   80 ++++++++++++++------------------
 1 file changed, 34 insertions(+), 46 deletions(-)

diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index cc63b36..faf0e77 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -41,26 +41,6 @@
 #include "st_program.h"
 
 
-static unsigned _min(unsigned a, unsigned b)
-{
-   return (a < b) ? a : b;
-}
-
-static float _maxf(float a, float b)
-{
-   return (a > b) ? a : b;
-}
-
-static int _clamp(int a, int min, int max)
-{
-   if (a < min)
-      return min;
-   else if (a > max)
-      return max;
-   else
-      return a;
-}
-
 
 /**
  * Query driver to get implementation limits.
@@ -74,25 +54,25 @@ void st_init_limits(struct st_context *st)
    int i;
 
    c->MaxTextureLevels
-      = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS),
+      = MIN2(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS),
             MAX_TEXTURE_LEVELS);
 
    c->Max3DTextureLevels
-      = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_3D_LEVELS),
+      = MIN2(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_3D_LEVELS),
             MAX_3D_TEXTURE_LEVELS);
 
    c->MaxCubeTextureLevels
-      = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS),
+      = MIN2(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS),
             MAX_CUBE_TEXTURE_LEVELS);
 
    c->MaxTextureRectSize
-      = _min(1 << (c->MaxTextureLevels - 1), MAX_TEXTURE_RECT_SIZE);
+      = MIN2(1 << (c->MaxTextureLevels - 1), MAX_TEXTURE_RECT_SIZE);
 
    c->MaxArrayTextureLayers
       = screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS);
 
    c->MaxCombinedTextureImageUnits
-      = _min(screen->get_param(screen, PIPE_CAP_MAX_COMBINED_SAMPLERS),
+      = MIN2(screen->get_param(screen, PIPE_CAP_MAX_COMBINED_SAMPLERS),
              MAX_COMBINED_TEXTURE_IMAGE_UNITS);
 
    /* Define max viewport size and max renderbuffer size in terms of
@@ -104,26 +84,27 @@ void st_init_limits(struct st_context *st)
    c->MaxRenderbufferSize = c->MaxTextureRectSize;
 
    c->MaxDrawBuffers = c->MaxColorAttachments =
-      _clamp(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS),
+      CLAMP(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS),
              1, MAX_DRAW_BUFFERS);
 
-   c->MaxDualSourceDrawBuffers
-      = _clamp(screen->get_param(screen, PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS),
-              0, MAX_DRAW_BUFFERS);
+   c->MaxDualSourceDrawBuffers =
+      CLAMP(screen->get_param(screen,
+                              PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS),
+            0, MAX_DRAW_BUFFERS);
 
    c->MaxLineWidth
-      = _maxf(1.0f, screen->get_paramf(screen,
-                                       PIPE_CAPF_MAX_LINE_WIDTH));
+      = MAX2(1.0f, screen->get_paramf(screen,
+                                      PIPE_CAPF_MAX_LINE_WIDTH));
    c->MaxLineWidthAA
-      = _maxf(1.0f, screen->get_paramf(screen,
-                                       PIPE_CAPF_MAX_LINE_WIDTH_AA));
+      = MAX2(1.0f, screen->get_paramf(screen,
+                                      PIPE_CAPF_MAX_LINE_WIDTH_AA));
 
    c->MaxPointSize
-      = _maxf(1.0f, screen->get_paramf(screen,
-                                       PIPE_CAPF_MAX_POINT_WIDTH));
+      = MAX2(1.0f, screen->get_paramf(screen,
+                                      PIPE_CAPF_MAX_POINT_WIDTH));
    c->MaxPointSizeAA
-      = _maxf(1.0f, screen->get_paramf(screen,
-                                       PIPE_CAPF_MAX_POINT_WIDTH_AA));
+      = MAX2(1.0f, screen->get_paramf(screen,
+                                      PIPE_CAPF_MAX_POINT_WIDTH_AA));
    /* called after _mesa_create_context/_mesa_init_point, fix default user
     * settable max point size up
     */
@@ -135,7 +116,7 @@ void st_init_limits(struct st_context *st)
    c->MinPointSizeAA = 0.0f;
 
    c->MaxTextureMaxAnisotropy
-      = _maxf(2.0f, screen->get_paramf(screen,
+      = MAX2(2.0f, screen->get_paramf(screen,
                                  PIPE_CAPF_MAX_TEXTURE_ANISOTROPY));
 
    c->MaxTextureLodBias
@@ -159,7 +140,7 @@ void st_init_limits(struct st_context *st)
       struct gl_program_constants *pc = &c->Program[i];
 
       pc->MaxTextureImageUnits =
-         _min(screen->get_shader_param(screen, sh,
+         MIN2(screen->get_shader_param(screen, sh,
                                        PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS),
               MAX_TEXTURE_IMAGE_UNITS);
 
@@ -176,7 +157,7 @@ void st_init_limits(struct st_context *st)
       pc->MaxTemps           = pc->MaxNativeTemps           =
          screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEMPS);
       pc->MaxAddressRegs     = pc->MaxNativeAddressRegs     =
-         _min(screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_ADDRS),
+         MIN2(screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_ADDRS),
               MAX_PROGRAM_ADDRESS_REGS);
       pc->MaxParameters      = pc->MaxNativeParameters      =
          screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONSTS);
@@ -187,7 +168,7 @@ void st_init_limits(struct st_context *st)
          screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONST_BUFFERS);
       if (pc->MaxUniformBlocks)
          pc->MaxUniformBlocks -= 1; /* The first one is for ordinary uniforms. */
-      pc->MaxUniformBlocks = _min(pc->MaxUniformBlocks, MAX_UNIFORM_BUFFERS);
+      pc->MaxUniformBlocks = MIN2(pc->MaxUniformBlocks, MAX_UNIFORM_BUFFERS);
 
       pc->MaxCombinedUniformComponents = (pc->MaxUniformComponents +
                                           c->MaxUniformBlockSize / 4 *
@@ -224,7 +205,10 @@ void st_init_limits(struct st_context *st)
       }
 
       if (options->EmitNoLoops)
-         options->MaxUnrollIterations = MIN2(screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INSTRUCTIONS), 65536);
+         options->MaxUnrollIterations =
+            MIN2(screen->get_shader_param(screen, sh,
+                                          PIPE_SHADER_CAP_MAX_INSTRUCTIONS),
+                 65536);
       else
          options->MaxUnrollIterations = 255; /* SM3 limit */
       options->LowerClipDistance = true;
@@ -232,11 +216,15 @@ void st_init_limits(struct st_context *st)
 
    /* This depends on program constants. */
    c->MaxTextureCoordUnits
-      = _min(c->Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits, MAX_TEXTURE_COORD_UNITS);
+      = MIN2(c->Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits,
+             MAX_TEXTURE_COORD_UNITS);
 
-   c->MaxTextureUnits = _min(c->Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits, c->MaxTextureCoordUnits);
+   c->MaxTextureUnits =
+      MIN2(c->Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits,
+           c->MaxTextureCoordUnits);
 
-   c->Program[MESA_SHADER_VERTEX].MaxAttribs = MIN2(c->Program[MESA_SHADER_VERTEX].MaxAttribs, 16);
+   c->Program[MESA_SHADER_VERTEX].MaxAttribs =
+      MIN2(c->Program[MESA_SHADER_VERTEX].MaxAttribs, 16);
 
    /* PIPE_SHADER_CAP_MAX_INPUTS for the FS specifies the maximum number
     * of inputs. It's always 2 colors + N generic inputs. */
@@ -734,7 +722,7 @@ void st_init_extensions(struct st_context *st)
       ctx->Extensions.ARB_texture_buffer_object = GL_TRUE;
 
       ctx->Const.MaxTextureBufferSize =
-         _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE),
+         MIN2(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE),
               (1u << 31) - 1);
       ctx->Const.TextureBufferOffsetAlignment =
          screen->get_param(screen, PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT);
-- 
1.7.10.4



More information about the mesa-dev mailing list