[Mesa-dev] [PATCH 01/23] i965/fs: Use a separate variable to keep track of the last uniform index seen.

Francisco Jerez currojerez at riseup.net
Mon Dec 2 11:31:06 PST 2013


Like the VEC4 back-end does.  It will make dynamic allocation of the
param_size array easier in a future commit.
---
 src/mesa/drivers/dri/i965/brw_fs.cpp         | 51 +++++++++++++---------------
 src/mesa/drivers/dri/i965/brw_fs.h           |  3 ++
 src/mesa/drivers/dri/i965/brw_fs_fp.cpp      |  2 +-
 src/mesa/drivers/dri/i965/brw_fs_visitor.cpp | 11 +++---
 4 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index eecde62..bc66e4a 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -883,7 +883,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 = c->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];
 
@@ -899,14 +899,13 @@ fs_visitor::setup_uniform_values(ir_variable *ir)
          slots *= storage->array_elements;
 
       for (unsigned i = 0; i < slots; i++) {
-         c->prog_data.param[c->prog_data.nr_params++] =
+         c->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() ==
-          c->prog_data.nr_params);
+   assert(params_before + ir->type->component_slots() == uniforms);
    (void)params_before;
 }
 
@@ -939,7 +938,7 @@ fs_visitor::setup_builtin_uniform_values(ir_variable *ir)
 	    break;
 	 last_swiz = swiz;
 
-	 c->prog_data.param[c->prog_data.nr_params++] =
+	 c->prog_data.param[uniforms++] =
             &fp->Base.Parameters->ParameterValues[index][swiz].f;
       }
    }
@@ -1368,13 +1367,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(c->prog_data.nr_params, 8) / 8;
    if (dispatch_width == 8) {
       c->prog_data.first_curbe_grf = c->nr_payload_regs;
+      c->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(c->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;
@@ -1695,10 +1698,10 @@ bool
 fs_visitor::remove_dead_constants()
 {
    if (dispatch_width == 8) {
-      this->params_remap = ralloc_array(mem_ctx, int, c->prog_data.nr_params);
-      this->nr_params_remap = c->prog_data.nr_params;
+      this->params_remap = ralloc_array(mem_ctx, int, uniforms);
+      this->nr_params_remap = uniforms;
 
-      for (unsigned int i = 0; i < c->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. */
@@ -1716,7 +1719,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)c->prog_data.nr_params) {
+	    if (constant_nr < 0 || constant_nr >= (int)uniforms) {
 	       constant_nr = 0;
 	    }
 
@@ -1734,14 +1737,14 @@ fs_visitor::remove_dead_constants()
        * now we don't care.
        */
       unsigned int new_nr_params = 0;
-      for (unsigned int i = 0; i < c->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 < c->prog_data.nr_params; i++) {
+      for (unsigned int i = 0; i < uniforms; i++) {
 	 int remapped = this->params_remap[i];
 
 	 if (remapped == -1)
@@ -1750,7 +1753,7 @@ fs_visitor::remove_dead_constants()
 	 c->prog_data.param[remapped] = c->prog_data.param[i];
       }
 
-      c->prog_data.nr_params = new_nr_params;
+      uniforms = new_nr_params;
    } else {
       /* This should have been generated in the 8-wide pass already. */
       assert(this->params_remap);
@@ -1794,9 +1797,9 @@ fs_visitor::remove_dead_constants()
 void
 fs_visitor::move_uniform_array_access_to_pull_constants()
 {
-   int pull_constant_loc[c->prog_data.nr_params];
+   int pull_constant_loc[uniforms];
 
-   for (unsigned int i = 0; i < c->prog_data.nr_params; i++) {
+   for (unsigned int i = 0; i < uniforms; i++) {
       pull_constant_loc[i] = -1;
    }
 
@@ -1867,7 +1870,7 @@ fs_visitor::setup_pull_constants()
 {
    /* Only allow 16 registers (128 uniform components) as push constants. */
    unsigned int max_uniform_components = 16 * 8;
-   if (c->prog_data.nr_params <= max_uniform_components)
+   if (uniforms <= max_uniform_components)
       return;
 
    if (dispatch_width == 16) {
@@ -1880,8 +1883,8 @@ fs_visitor::setup_pull_constants()
     */
    unsigned int pull_uniform_base = max_uniform_components;
 
-   int pull_constant_loc[c->prog_data.nr_params];
-   for (unsigned int i = 0; i < c->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 {
@@ -1902,7 +1905,7 @@ fs_visitor::setup_pull_constants()
          }
       }
    }
-   c->prog_data.nr_params = pull_uniform_base;
+   uniforms = pull_uniform_base;
 
    foreach_list(node, &this->instructions) {
       fs_inst *inst = (fs_inst *)node;
@@ -3194,7 +3197,6 @@ bool
 fs_visitor::run()
 {
    sanity_param_count = fp->Base.Parameters->NumParameters;
-   uint32_t orig_nr_params = c->prog_data.nr_params;
    bool allocated_without_spills;
 
    assign_binding_table_offsets();
@@ -3336,16 +3338,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 == c->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
diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
index 7991b87..9f4a1be 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.h
+++ b/src/mesa/drivers/dri/i965/brw_fs.h
@@ -441,6 +441,9 @@ public:
    int *virtual_grf_end;
    brw::fs_live_variables *live_intervals;
 
+   /** 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
diff --git a/src/mesa/drivers/dri/i965/brw_fs_fp.cpp b/src/mesa/drivers/dri/i965/brw_fs_fp.cpp
index 1ebaa4f..d51e679 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_fp.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_fp.cpp
@@ -593,7 +593,7 @@ fs_visitor::setup_fp_regs()
       for (unsigned p = 0;
            p < prog->Parameters->NumParameters; p++) {
          for (unsigned int i = 0; i < 4; i++) {
-            c->prog_data.param[c->prog_data.nr_params++] =
+            c->prog_data.param[uniforms++] =
                &prog->Parameters->ParameterValues[p][i].f;
          }
       }
diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
index 3b08f6f..a045100 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -102,7 +102,7 @@ fs_visitor::visit(ir_variable *ir)
 	 }
       }
    } else if (ir->mode == ir_var_uniform) {
-      int param_index = c->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
@@ -1447,14 +1447,14 @@ fs_visitor::rescale_texcoord(ir_texture *ir, fs_reg coordinate,
 	 return coordinate;
       }
 
-      scale_x = fs_reg(UNIFORM, c->prog_data.nr_params);
-      scale_y = fs_reg(UNIFORM, c->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);
-      c->prog_data.param[c->prog_data.nr_params++] =
+      c->prog_data.param[uniforms++] =
          &prog->Parameters->ParameterValues[index][0].f;
-      c->prog_data.param[c->prog_data.nr_params++] =
+      c->prog_data.param[uniforms++] =
          &prog->Parameters->ParameterValues[index][1].f;
    }
 
@@ -2917,6 +2917,7 @@ fs_visitor::fs_visitor(struct brw_context *brw,
    this->virtual_grf_end = NULL;
    this->live_intervals = NULL;
 
+   this->uniforms = 0;
    this->params_remap = NULL;
    this->nr_params_remap = 0;
 
-- 
1.8.3.4



More information about the mesa-dev mailing list