st/mesa: replace Elements() with ARRAY_SIZE()
authorBrian Paul <brianp@vmware.com>
Sat, 28 Feb 2015 16:01:33 +0000 (09:01 -0700)
committerBrian Paul <brianp@vmware.com>
Mon, 2 Mar 2015 15:55:30 +0000 (08:55 -0700)
Acked-by: Ilia Mirkin <imirkin@alum.mit.edu>
src/mesa/state_tracker/st_atom.c
src/mesa/state_tracker/st_cb_drawpixels.c
src/mesa/state_tracker/st_cb_rasterpos.c
src/mesa/state_tracker/st_cb_xformfb.c
src/mesa/state_tracker/st_context.c
src/mesa/state_tracker/st_extensions.c
src/mesa/state_tracker/st_format.c
src/mesa/state_tracker/st_glsl_to_tgsi.cpp
src/mesa/state_tracker/st_mesa_to_tgsi.c
src/mesa/state_tracker/st_program.c

index 625ea2965feb2af1e8358242e944275d3625a521..8cc6af26082e4534656454fc34d1239f8ab3eeac 100644 (file)
@@ -197,7 +197,7 @@ void st_validate_state( struct st_context *st )
       memset(&examined, 0, sizeof(examined));
       prev = *state;
 
-      for (i = 0; i < Elements(atoms); i++) {   
+      for (i = 0; i < ARRAY_SIZE(atoms); i++) {         
         const struct st_tracked_state *atom = atoms[i];
         struct st_state_flags generated;
         
@@ -228,7 +228,7 @@ void st_validate_state( struct st_context *st )
 
    }
    else {
-      for (i = 0; i < Elements(atoms); i++) {   
+      for (i = 0; i < ARRAY_SIZE(atoms); i++) {         
         if (check_state(state, &atoms[i]->dirty))
            atoms[i]->update( st );
       }
index 14fc13952356c9c5efac5e9bb0c8e2d9143484bd..3edf31bad52d490c26a382cc977ad2722b25ffb6 100644 (file)
@@ -201,7 +201,7 @@ st_make_drawpix_z_stencil_program(struct st_context *st,
    GLuint ic = 0;
    const GLuint shaderIndex = write_depth * 2 + write_stencil;
 
-   assert(shaderIndex < Elements(st->drawpix.shaders));
+   assert(shaderIndex < ARRAY_SIZE(st->drawpix.shaders));
 
    if (st->drawpix.shaders[shaderIndex]) {
       /* already have the proper shader */
@@ -1684,7 +1684,7 @@ st_destroy_drawpix(struct st_context *st)
 {
    GLuint i;
 
-   for (i = 0; i < Elements(st->drawpix.shaders); i++) {
+   for (i = 0; i < ARRAY_SIZE(st->drawpix.shaders); i++) {
       if (st->drawpix.shaders[i])
          _mesa_reference_fragprog(st->ctx, &st->drawpix.shaders[i], NULL);
    }
index b051aedab9e1eaec4216aa9e3eac7f7caf7966dc..272cbb91d52fa955395b365eea3c660af89cf985 100644 (file)
@@ -191,7 +191,7 @@ new_draw_rastpos_stage(struct gl_context *ctx, struct draw_context *draw)
    rs->stage.destroy = rastpos_destroy;
    rs->ctx = ctx;
 
-   for (i = 0; i < Elements(rs->array); i++) {
+   for (i = 0; i < ARRAY_SIZE(rs->array); i++) {
       rs->array[i].Size = 4;
       rs->array[i].Type = GL_FLOAT;
       rs->array[i].Format = GL_RGBA;
index 39d0b61c874b4a632bfe3f1c064fd0eea057cd1c..07c118e227bbf964b820d563f6094dafebc78f7b 100644 (file)
@@ -95,7 +95,7 @@ st_delete_transform_feedback(struct gl_context *ctx,
       pipe_so_target_reference(&sobj->targets[i], NULL);
    }
 
-   for (i = 0; i < Elements(sobj->base.Buffers); i++) {
+   for (i = 0; i < ARRAY_SIZE(sobj->base.Buffers); i++) {
       _mesa_reference_buffer_object(ctx, &sobj->base.Buffers[i], NULL);
    }
 
@@ -115,8 +115,8 @@ st_begin_transform_feedback(struct gl_context *ctx, GLenum mode,
    unsigned i, max_num_targets;
    unsigned offsets[PIPE_MAX_SO_BUFFERS] = {0};
 
-   max_num_targets = MIN2(Elements(sobj->base.Buffers),
-                          Elements(sobj->targets));
+   max_num_targets = MIN2(ARRAY_SIZE(sobj->base.Buffers),
+                          ARRAY_SIZE(sobj->targets));
 
    /* Convert the transform feedback state into the gallium representation. */
    for (i = 0; i < max_num_targets; i++) {
@@ -185,7 +185,7 @@ st_transform_feedback_get_draw_target(struct gl_transform_feedback_object *obj)
          st_transform_feedback_object(obj);
    unsigned i;
 
-   for (i = 0; i < Elements(sobj->targets); i++) {
+   for (i = 0; i < ARRAY_SIZE(sobj->targets); i++) {
       if (sobj->targets[i]) {
          return sobj->targets[i];
       }
index 5834ebad3be0defc3a4e43c07fa9f923b3114cd6..5fe132ac245f8c7ad691b161e534ee51838d0e9f 100644 (file)
@@ -117,8 +117,8 @@ st_destroy_context_priv(struct st_context *st)
    st_destroy_drawpix(st);
    st_destroy_drawtex(st);
 
-   for (shader = 0; shader < Elements(st->state.sampler_views); shader++) {
-      for (i = 0; i < Elements(st->state.sampler_views[0]); i++) {
+   for (shader = 0; shader < ARRAY_SIZE(st->state.sampler_views); shader++) {
+      for (i = 0; i < ARRAY_SIZE(st->state.sampler_views[0]); i++) {
          pipe_sampler_view_release(st->pipe,
                                    &st->state.sampler_views[shader][i]);
       }
@@ -200,7 +200,7 @@ st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe,
    /* Vertex element objects used for drawing rectangles for glBitmap,
     * glDrawPixels, glClear, etc.
     */
-   for (i = 0; i < Elements(st->velems_util_draw); i++) {
+   for (i = 0; i < ARRAY_SIZE(st->velems_util_draw); i++) {
       memset(&st->velems_util_draw[i], 0, sizeof(struct pipe_vertex_element));
       st->velems_util_draw[i].src_offset = i * 4 * sizeof(float);
       st->velems_util_draw[i].instance_divisor = 0;
index ce29d076c2c792560208af44f4399f4f301bf3d4..bc20f73230da98b092dca6b3b5493e93b953665c 100644 (file)
@@ -347,8 +347,8 @@ init_format_extensions(struct pipe_screen *screen,
    GLboolean *extension_table = (GLboolean *) extensions;
    unsigned i;
    int j;
-   int num_formats = Elements(mapping->format);
-   int num_ext = Elements(mapping->extension_offset);
+   int num_formats = ARRAY_SIZE(mapping->format);
+   int num_ext = ARRAY_SIZE(mapping->extension_offset);
 
    for (i = 0; i < num_mappings; i++) {
       int num_supported = 0;
@@ -630,7 +630,7 @@ void st_init_extensions(struct pipe_screen *screen,
    extensions->OES_draw_texture = GL_TRUE;
 
    /* Expose the extensions which directly correspond to gallium caps. */
-   for (i = 0; i < Elements(cap_mapping); i++) {
+   for (i = 0; i < ARRAY_SIZE(cap_mapping); i++) {
       if (screen->get_param(screen, cap_mapping[i].cap)) {
          extension_table[cap_mapping[i].extension_offset] = GL_TRUE;
       }
@@ -638,16 +638,16 @@ void st_init_extensions(struct pipe_screen *screen,
 
    /* Expose the extensions which directly correspond to gallium formats. */
    init_format_extensions(screen, extensions, rendertarget_mapping,
-                          Elements(rendertarget_mapping), PIPE_TEXTURE_2D,
+                          ARRAY_SIZE(rendertarget_mapping), PIPE_TEXTURE_2D,
                           PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW);
    init_format_extensions(screen, extensions, depthstencil_mapping,
-                          Elements(depthstencil_mapping), PIPE_TEXTURE_2D,
+                          ARRAY_SIZE(depthstencil_mapping), PIPE_TEXTURE_2D,
                           PIPE_BIND_DEPTH_STENCIL | PIPE_BIND_SAMPLER_VIEW);
    init_format_extensions(screen, extensions, texture_mapping,
-                          Elements(texture_mapping), PIPE_TEXTURE_2D,
+                          ARRAY_SIZE(texture_mapping), PIPE_TEXTURE_2D,
                           PIPE_BIND_SAMPLER_VIEW);
    init_format_extensions(screen, extensions, vertex_mapping,
-                          Elements(vertex_mapping), PIPE_BUFFER,
+                          ARRAY_SIZE(vertex_mapping), PIPE_BUFFER,
                           PIPE_BIND_VERTEX_BUFFER);
 
    /* Figure out GLSL support. */
@@ -758,22 +758,22 @@ void st_init_extensions(struct pipe_screen *screen,
       };
 
       consts->MaxSamples =
-         get_max_samples_for_formats(screen, Elements(color_formats),
+         get_max_samples_for_formats(screen, ARRAY_SIZE(color_formats),
                                      color_formats, 16,
                                      PIPE_BIND_RENDER_TARGET);
 
       consts->MaxColorTextureSamples =
-         get_max_samples_for_formats(screen, Elements(color_formats),
+         get_max_samples_for_formats(screen, ARRAY_SIZE(color_formats),
                                      color_formats, consts->MaxSamples,
                                      PIPE_BIND_SAMPLER_VIEW);
 
       consts->MaxDepthTextureSamples =
-         get_max_samples_for_formats(screen, Elements(depth_formats),
+         get_max_samples_for_formats(screen, ARRAY_SIZE(depth_formats),
                                      depth_formats, consts->MaxSamples,
                                      PIPE_BIND_SAMPLER_VIEW);
 
       consts->MaxIntegerSamples =
-         get_max_samples_for_formats(screen, Elements(int_formats),
+         get_max_samples_for_formats(screen, ARRAY_SIZE(int_formats),
                                      int_formats, consts->MaxSamples,
                                      PIPE_BIND_SAMPLER_VIEW);
    }
@@ -831,7 +831,7 @@ void st_init_extensions(struct pipe_screen *screen,
          extensions->ARB_texture_buffer_range = GL_TRUE;
 
       init_format_extensions(screen, extensions, tbo_rgb32,
-                             Elements(tbo_rgb32), PIPE_BUFFER,
+                             ARRAY_SIZE(tbo_rgb32), PIPE_BUFFER,
                              PIPE_BIND_SAMPLER_VIEW);
    }
 
index 7868bb501ea92ea9c7c63949196d46daa08b684c..72dbf3bd4c0a47011db7e00eded90b5b79b5fc7c 100644 (file)
@@ -1855,7 +1855,7 @@ st_choose_format(struct st_context *st, GLenum internalFormat,
       return pf;
 
    /* search table for internalFormat */
-   for (i = 0; i < Elements(format_map); i++) {
+   for (i = 0; i < ARRAY_SIZE(format_map); i++) {
       const struct format_mapping *mapping = &format_map[i];
       for (j = 0; mapping->glFormats[j]; j++) {
          if (mapping->glFormats[j] == internalFormat) {
index b305507659173da825bdfc90cf331039ad178dac..bd191d864fe600ee13b72b5766dcba98e31ec8dd 100644 (file)
@@ -1497,7 +1497,7 @@ void
 glsl_to_tgsi_visitor::visit(ir_expression *ir)
 {
    unsigned int operand;
-   st_src_reg op[Elements(ir->operands)];
+   st_src_reg op[ARRAY_SIZE(ir->operands)];
    st_src_reg result_src;
    st_dst_reg result_dst;
 
@@ -4022,7 +4022,7 @@ glsl_to_tgsi_visitor::eliminate_dead_code(void)
          /* Continuing the block, clear any channels from the write array that
           * are read by this instruction.
           */
-         for (unsigned i = 0; i < Elements(inst->src); i++) {
+         for (unsigned i = 0; i < ARRAY_SIZE(inst->src); i++) {
             if (inst->src[i].file == PROGRAM_TEMPORARY && inst->src[i].reladdr){
                /* Any temporary might be read, so no dead code elimination
                 * across this instruction.
@@ -4067,7 +4067,7 @@ glsl_to_tgsi_visitor::eliminate_dead_code(void)
        * If there is already an instruction in the write array for one or more
        * of the channels, flag that channel write as dead.
        */
-      for (unsigned i = 0; i < Elements(inst->dst); i++) {
+      for (unsigned i = 0; i < ARRAY_SIZE(inst->dst); i++) {
          if (inst->dst[i].file == PROGRAM_TEMPORARY &&
              !inst->dst[i].reladdr &&
              !inst->saturate) {
@@ -4625,7 +4625,7 @@ dst_register(struct st_translate *t,
    case PROGRAM_ARRAY:
       array = index >> 16;
 
-      assert(array < Elements(t->arrays));
+      assert(array < ARRAY_SIZE(t->arrays));
 
       if (ureg_dst_is_undef(t->arrays[array]))
          t->arrays[array] = ureg_DECL_array_temporary(
@@ -4642,7 +4642,7 @@ dst_register(struct st_translate *t,
       else
          assert(index < VARYING_SLOT_MAX);
 
-      assert(t->outputMapping[index] < Elements(t->outputs));
+      assert(t->outputMapping[index] < ARRAY_SIZE(t->outputs));
 
       return t->outputs[t->outputMapping[index]];
 
@@ -4685,18 +4685,18 @@ src_register(struct st_translate *t, const st_src_reg *reg)
       return t->immediates[reg->index];
 
    case PROGRAM_INPUT:
-      assert(t->inputMapping[reg->index] < Elements(t->inputs));
+      assert(t->inputMapping[reg->index] < ARRAY_SIZE(t->inputs));
       return t->inputs[t->inputMapping[reg->index]];
 
    case PROGRAM_OUTPUT:
-      assert(t->outputMapping[reg->index] < Elements(t->outputs));
+      assert(t->outputMapping[reg->index] < ARRAY_SIZE(t->outputs));
       return ureg_src(t->outputs[t->outputMapping[reg->index]]); /* not needed? */
 
    case PROGRAM_ADDRESS:
       return ureg_src(t->address[reg->index]);
 
    case PROGRAM_SYSTEM_VALUE:
-      assert(reg->index < (int) Elements(t->systemValues));
+      assert(reg->index < (int) ARRAY_SIZE(t->systemValues));
       return t->systemValues[reg->index];
 
    default:
@@ -4824,7 +4824,7 @@ translate_tex_offset(struct st_translate *t,
       array = in_offset->index >> 16;
 
       assert(array >= 0);
-      assert(array < (int) Elements(t->arrays));
+      assert(array < (int) ARRAY_SIZE(t->arrays));
 
       dst = t->arrays[array];
       offset.File = dst.File;
@@ -5200,8 +5200,8 @@ st_translate_program(
    unsigned i;
    enum pipe_error ret = PIPE_OK;
 
-   assert(numInputs <= Elements(t->inputs));
-   assert(numOutputs <= Elements(t->outputs));
+   assert(numInputs <= ARRAY_SIZE(t->inputs));
+   assert(numOutputs <= ARRAY_SIZE(t->outputs));
 
    assert(_mesa_sysval_to_semantic[SYSTEM_VALUE_FRONT_FACE] ==
           TGSI_SEMANTIC_FACE);
index 4684421b52514c66c775f2e939288b4e30ff77e3..2f10161106721ab9f807d8cae9ea3bb5e649e4fe 100644 (file)
@@ -172,7 +172,7 @@ dst_register( struct st_translate *t,
       else
          assert(index < VARYING_SLOT_MAX);
 
-      assert(t->outputMapping[index] < Elements(t->outputs));
+      assert(t->outputMapping[index] < ARRAY_SIZE(t->outputs));
 
       return t->outputs[t->outputMapping[index]];
 
@@ -200,7 +200,7 @@ src_register( struct st_translate *t,
 
    case PROGRAM_TEMPORARY:
       assert(index >= 0);
-      assert(index < Elements(t->temps));
+      assert(index < ARRAY_SIZE(t->temps));
       if (ureg_dst_is_undef(t->temps[index]))
          t->temps[index] = ureg_DECL_temporary( t->ureg );
       return ureg_src(t->temps[index]);
@@ -216,18 +216,18 @@ src_register( struct st_translate *t,
          return t->constants[index];
 
    case PROGRAM_INPUT:
-      assert(t->inputMapping[index] < Elements(t->inputs));
+      assert(t->inputMapping[index] < ARRAY_SIZE(t->inputs));
       return t->inputs[t->inputMapping[index]];
 
    case PROGRAM_OUTPUT:
-      assert(t->outputMapping[index] < Elements(t->outputs));
+      assert(t->outputMapping[index] < ARRAY_SIZE(t->outputs));
       return ureg_src(t->outputs[t->outputMapping[index]]); /* not needed? */
 
    case PROGRAM_ADDRESS:
       return ureg_src(t->address[index]);
 
    case PROGRAM_SYSTEM_VALUE:
-      assert(index < Elements(t->systemValues));
+      assert(index < ARRAY_SIZE(t->systemValues));
       return t->systemValues[index];
 
    default:
@@ -1027,8 +1027,8 @@ st_translate_mesa_program(
    unsigned i;
    enum pipe_error ret = PIPE_OK;
 
-   assert(numInputs <= Elements(t->inputs));
-   assert(numOutputs <= Elements(t->outputs));
+   assert(numInputs <= ARRAY_SIZE(t->inputs));
+   assert(numOutputs <= ARRAY_SIZE(t->outputs));
 
    t = &translate;
    memset(t, 0, sizeof *t);
index 8ce461eb36afebe0e7874244cc2073fc869f6384..4cfd817cee4240991106fc337c12ddaf7126d8bd 100644 (file)
@@ -1054,7 +1054,7 @@ st_translate_geometry_program(struct st_context *st,
             /* fall through */
          case VARYING_SLOT_VAR0:
          default:
-            assert(slot < Elements(gs_output_semantic_name));
+            assert(slot < ARRAY_SIZE(gs_output_semantic_name));
             assert(attr >= VARYING_SLOT_VAR0);
             gs_output_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
             gs_output_semantic_index[slot] =
@@ -1247,7 +1247,7 @@ destroy_shader_program_variants_cb(GLuint key, void *data, void *userData)
             destroy_program_variants(st, shProg->Shaders[i]->Program);
          }
 
-        for (i = 0; i < Elements(shProg->_LinkedShaders); i++) {
+        for (i = 0; i < ARRAY_SIZE(shProg->_LinkedShaders); i++) {
            if (shProg->_LinkedShaders[i])
                destroy_program_variants(st, shProg->_LinkedShaders[i]->Program);
         }