i965/fs: Use a separate variable to keep track of the last uniform index seen.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_fs.cpp
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