i965/fs: Use a separate variable to keep track of the last uniform index seen.
authorFrancisco Jerez <currojerez@riseup.net>
Wed, 19 Feb 2014 14:27:01 +0000 (15:27 +0100)
committerFrancisco Jerez <currojerez@riseup.net>
Wed, 19 Feb 2014 18:03:56 +0000 (19:03 +0100)
Like the VEC4 back-end does.  It will make dynamic allocation of the
param_size array easier in a future commit.

Reviewed-by: Paul Berry <stereotype441@gmail.com>
src/mesa/drivers/dri/i965/brw_fs.cpp
src/mesa/drivers/dri/i965/brw_fs.h
src/mesa/drivers/dri/i965/brw_fs_fp.cpp
src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
src/mesa/drivers/dri/i965/brw_wm.c

index b7495f4a3fbc70acf6e832389da509ad85f91f3d..0fd9e908f58b8d7d8c0e8f60d3b04229e0e90f1a 100644 (file)
@@ -904,7 +904,7 @@ fs_visitor::setup_uniform_values(ir_variable *ir)
     * order we'd walk the type, so walk the list of storage and find anything
     * with our name, or the prefix of a component that starts with our name.
     */
-   unsigned params_before = stage_prog_data->nr_params;
+   unsigned params_before = uniforms;
    for (unsigned u = 0; u < shader_prog->NumUserUniformStorage; u++) {
       struct gl_uniform_storage *storage = &shader_prog->UniformStorage[u];
 
@@ -920,14 +920,12 @@ fs_visitor::setup_uniform_values(ir_variable *ir)
          slots *= storage->array_elements;
 
       for (unsigned i = 0; i < slots; i++) {
-         stage_prog_data->param[stage_prog_data->nr_params++] =
-            &storage->storage[i].f;
+         stage_prog_data->param[uniforms++] = &storage->storage[i].f;
       }
    }
 
    /* Make sure we actually initialized the right amount of stuff here. */
-   assert(params_before + ir->type->component_slots() ==
-          stage_prog_data->nr_params);
+   assert(params_before + ir->type->component_slots() == uniforms);
    (void)params_before;
 }
 
@@ -960,7 +958,7 @@ fs_visitor::setup_builtin_uniform_values(ir_variable *ir)
            break;
         last_swiz = swiz;
 
-        stage_prog_data->param[stage_prog_data->nr_params++] =
+         stage_prog_data->param[uniforms++] =
             &fp->Base.Parameters->ParameterValues[index][swiz].f;
       }
    }
@@ -1396,13 +1394,17 @@ fs_visitor::emit_math(enum opcode opcode, fs_reg dst, fs_reg src0, fs_reg src1)
 void
 fs_visitor::assign_curb_setup()
 {
-   c->prog_data.curb_read_length = ALIGN(stage_prog_data->nr_params, 8) / 8;
    if (dispatch_width == 8) {
       c->prog_data.first_curbe_grf = c->nr_payload_regs;
+      stage_prog_data->nr_params = uniforms;
    } else {
       c->prog_data.first_curbe_grf_16 = c->nr_payload_regs;
+      /* Make sure we didn't try to sneak in an extra uniform */
+      assert(uniforms == 0);
    }
 
+   c->prog_data.curb_read_length = ALIGN(stage_prog_data->nr_params, 8) / 8;
+
    /* Map the offsets in the UNIFORM file to fixed HW regs. */
    foreach_list(node, &this->instructions) {
       fs_inst *inst = (fs_inst *)node;
@@ -1725,10 +1727,10 @@ bool
 fs_visitor::remove_dead_constants()
 {
    if (dispatch_width == 8) {
-      this->params_remap = ralloc_array(mem_ctx, int, stage_prog_data->nr_params);
-      this->nr_params_remap = stage_prog_data->nr_params;
+      this->params_remap = ralloc_array(mem_ctx, int, uniforms);
+      this->nr_params_remap = uniforms;
 
-      for (unsigned int i = 0; i < stage_prog_data->nr_params; i++)
+      for (unsigned int i = 0; i < uniforms; i++)
         this->params_remap[i] = -1;
 
       /* Find which params are still in use. */
@@ -1746,8 +1748,7 @@ fs_visitor::remove_dead_constants()
             *     "Out-of-bounds reads return undefined values, which include
             *     values from other variables of the active program or zero."
             */
-           if (constant_nr < 0 ||
-                constant_nr >= (int)stage_prog_data->nr_params) {
+           if (constant_nr < 0 || constant_nr >= (int)uniforms) {
               constant_nr = 0;
            }
 
@@ -1765,14 +1766,14 @@ fs_visitor::remove_dead_constants()
        * now we don't care.
        */
       unsigned int new_nr_params = 0;
-      for (unsigned int i = 0; i < stage_prog_data->nr_params; i++) {
+      for (unsigned int i = 0; i < uniforms; i++) {
         if (this->params_remap[i] != -1) {
            this->params_remap[i] = new_nr_params++;
         }
       }
 
       /* Update the list of params to be uploaded to match our new numbering. */
-      for (unsigned int i = 0; i < stage_prog_data->nr_params; i++) {
+      for (unsigned int i = 0; i < uniforms; i++) {
         int remapped = this->params_remap[i];
 
         if (remapped == -1)
@@ -1781,7 +1782,7 @@ fs_visitor::remove_dead_constants()
         stage_prog_data->param[remapped] = stage_prog_data->param[i];
       }
 
-      stage_prog_data->nr_params = new_nr_params;
+      uniforms = new_nr_params;
    } else {
       /* This should have been generated in the SIMD8 pass already. */
       assert(this->params_remap);
@@ -1825,9 +1826,9 @@ fs_visitor::remove_dead_constants()
 void
 fs_visitor::move_uniform_array_access_to_pull_constants()
 {
-   int pull_constant_loc[stage_prog_data->nr_params];
+   int pull_constant_loc[uniforms];
 
-   for (unsigned int i = 0; i < stage_prog_data->nr_params; i++) {
+   for (unsigned int i = 0; i < uniforms; i++) {
       pull_constant_loc[i] = -1;
    }
 
@@ -1898,7 +1899,7 @@ fs_visitor::setup_pull_constants()
 {
    /* Only allow 16 registers (128 uniform components) as push constants. */
    unsigned int max_uniform_components = 16 * 8;
-   if (stage_prog_data->nr_params <= max_uniform_components)
+   if (uniforms <= max_uniform_components)
       return;
 
    if (dispatch_width == 16) {
@@ -1911,8 +1912,8 @@ fs_visitor::setup_pull_constants()
     */
    unsigned int pull_uniform_base = max_uniform_components;
 
-   int pull_constant_loc[stage_prog_data->nr_params];
-   for (unsigned int i = 0; i < stage_prog_data->nr_params; i++) {
+   int pull_constant_loc[uniforms];
+   for (unsigned int i = 0; i < uniforms; i++) {
       if (i < pull_uniform_base) {
          pull_constant_loc[i] = -1;
       } else {
@@ -1933,7 +1934,7 @@ fs_visitor::setup_pull_constants()
          }
       }
    }
-   stage_prog_data->nr_params = pull_uniform_base;
+   uniforms = pull_uniform_base;
 
    foreach_list(node, &this->instructions) {
       fs_inst *inst = (fs_inst *)node;
@@ -3307,7 +3308,6 @@ bool
 fs_visitor::run()
 {
    sanity_param_count = fp->Base.Parameters->NumParameters;
-   uint32_t orig_nr_params = stage_prog_data->nr_params;
    bool allocated_without_spills;
 
    assign_binding_table_offsets();
@@ -3451,16 +3451,11 @@ fs_visitor::run()
    if (!allocated_without_spills)
       schedule_instructions(SCHEDULE_POST);
 
-   if (dispatch_width == 8) {
+   if (dispatch_width == 8)
       c->prog_data.reg_blocks = brw_register_blocks(grf_used);
-   } else {
+   else
       c->prog_data.reg_blocks_16 = brw_register_blocks(grf_used);
 
-      /* Make sure we didn't try to sneak in an extra uniform */
-      assert(orig_nr_params == stage_prog_data->nr_params);
-      (void) orig_nr_params;
-   }
-
    /* If any state parameters were appended, then ParameterValues could have
     * been realloced, in which case the driver uniform storage set up by
     * _mesa_associate_uniform_storage() would point to freed memory.  Make
index 5f9cb596539c34840648f8d51a2d6abaa3fbc8c0..0362c5d3cd7153961683aab3bba5690dec362964 100644 (file)
@@ -502,6 +502,9 @@ public:
 
    int *regs_live_at_ip;
 
+   /** Number of uniform variable components visited. */
+   unsigned uniforms;
+
    /* This is the map from UNIFORM hw_reg + reg_offset as generated by
     * the visitor to the packed uniform number after
     * remove_dead_constants() that represents the actual uploaded
index 5a677a7df3c268f84fa22913af4bc06e5143e04a..49eaf0544069a768435a8721e8fcb6a6f5e670ca 100644 (file)
@@ -586,7 +586,7 @@ fs_visitor::setup_fp_regs()
       for (unsigned p = 0;
            p < prog->Parameters->NumParameters; p++) {
          for (unsigned int i = 0; i < 4; i++) {
-            stage_prog_data->param[stage_prog_data->nr_params++] =
+            stage_prog_data->param[uniforms++] =
                &prog->Parameters->ParameterValues[p][i].f;
          }
       }
index 169eaf1279b1e542c435c96f2e54574e10f7c7f5..b0fed9eecdac43b8630dc89fcda0068ab02d48f5 100644 (file)
@@ -102,7 +102,7 @@ fs_visitor::visit(ir_variable *ir)
         }
       }
    } else if (ir->data.mode == ir_var_uniform) {
-      int param_index = stage_prog_data->nr_params;
+      int param_index = uniforms;
 
       /* Thanks to the lower_ubo_reference pass, we will see only
        * ir_binop_ubo_load expressions and not ir_dereference_variable for UBO
@@ -1467,14 +1467,14 @@ fs_visitor::rescale_texcoord(ir_texture *ir, fs_reg coordinate,
         return coordinate;
       }
 
-      scale_x = fs_reg(UNIFORM, stage_prog_data->nr_params);
-      scale_y = fs_reg(UNIFORM, stage_prog_data->nr_params + 1);
+      scale_x = fs_reg(UNIFORM, uniforms);
+      scale_y = fs_reg(UNIFORM, uniforms + 1);
 
       GLuint index = _mesa_add_state_reference(params,
                                               (gl_state_index *)tokens);
-      stage_prog_data->param[stage_prog_data->nr_params++] =
+      stage_prog_data->param[uniforms++] =
          &prog->Parameters->ParameterValues[index][0].f;
-      stage_prog_data->param[stage_prog_data->nr_params++] =
+      stage_prog_data->param[uniforms++] =
          &prog->Parameters->ParameterValues[index][1].f;
    }
 
@@ -2984,6 +2984,7 @@ fs_visitor::fs_visitor(struct brw_context *brw,
    this->live_intervals = NULL;
    this->regs_live_at_ip = NULL;
 
+   this->uniforms = 0;
    this->params_remap = NULL;
    this->nr_params_remap = 0;
 
index 31c68f4c3f421308efc32b1093ba21b407693cb5..0d0d6ec82ff43e796855f9723892fdc484cf16c2 100644 (file)
@@ -171,6 +171,7 @@ bool do_wm_prog(struct brw_context *brw,
    c->prog_data.base.param = rzalloc_array(NULL, const float *, param_count);
    c->prog_data.base.pull_param =
       rzalloc_array(NULL, const float *, param_count);
+   c->prog_data.base.nr_params = param_count;
 
    memcpy(&c->key, key, sizeof(*key));