[Mesa-dev] [PATCH 04/23] i965: Move up duplicated fields from stage-specific prog_data to brw_stage_prog_data.

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


There doesn't seem to be any reason for nr_params, nr_pull_params,
param, and pull_param to be duplicated in the stage-specific
subclasses of brw_stage_prog_data.  Moving their definition to the
common base class will allow some code sharing in a future commit, the
removal of brw_vec4_prog_data_compare and brw_*_prog_data_free, and
the simplification of the stage-specific brw_*_prog_data_compare.
---
 src/mesa/drivers/dri/i965/brw_context.h          | 32 ++++++---------
 src/mesa/drivers/dri/i965/brw_curbe.c            | 12 +++---
 src/mesa/drivers/dri/i965/brw_fs.cpp             | 38 +++++++++---------
 src/mesa/drivers/dri/i965/brw_fs_fp.cpp          |  2 +-
 src/mesa/drivers/dri/i965/brw_fs_visitor.cpp     |  6 +--
 src/mesa/drivers/dri/i965/brw_program.c          | 28 +++++++++++++
 src/mesa/drivers/dri/i965/brw_program.h          |  6 +++
 src/mesa/drivers/dri/i965/brw_state_cache.c      |  6 +--
 src/mesa/drivers/dri/i965/brw_vec4.cpp           | 51 ++++++------------------
 src/mesa/drivers/dri/i965/brw_vec4.h             |  3 --
 src/mesa/drivers/dri/i965/brw_vec4_gs.c          | 21 ++++------
 src/mesa/drivers/dri/i965/brw_vec4_gs.h          |  1 -
 src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp   | 14 +++----
 src/mesa/drivers/dri/i965/brw_vec4_vp.cpp        |  6 +--
 src/mesa/drivers/dri/i965/brw_vs.c               | 20 +++-------
 src/mesa/drivers/dri/i965/brw_vs.h               |  1 -
 src/mesa/drivers/dri/i965/brw_vs_surface_state.c | 10 ++---
 src/mesa/drivers/dri/i965/brw_wm.c               | 28 +++++--------
 src/mesa/drivers/dri/i965/brw_wm.h               |  1 -
 src/mesa/drivers/dri/i965/brw_wm_surface_state.c |  8 ++--
 src/mesa/drivers/dri/i965/gen6_vs_state.c        | 10 ++---
 src/mesa/drivers/dri/i965/gen6_wm_state.c        | 14 +++----
 src/mesa/drivers/dri/i965/gen7_wm_state.c        |  2 +-
 23 files changed, 146 insertions(+), 174 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index 97f8906..1387aa9 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -330,8 +330,7 @@ struct brw_shader {
 };
 
 /* Note: If adding fields that need anything besides a normal memcmp() for
- * comparing them, be sure to go fix the the stage-specific
- * prog_data_compare().
+ * comparing them, be sure to go fix brw_stage_prog_data_compare().
  */
 struct brw_stage_prog_data {
    struct {
@@ -349,6 +348,18 @@ struct brw_stage_prog_data {
       uint32_t shader_time_start;
       /** @} */
    } binding_table;
+
+   GLuint nr_params;       /**< number of float params/constants */
+   GLuint nr_pull_params;
+
+   /* Pointers to tracked values (only valid once
+    * _mesa_load_state_parameters has been called at runtime).
+    *
+    * These must be the last fields of the struct (see
+    * brw_stage_prog_data_compare()).
+    */
+   const float **param;
+   const float **pull_param;
 };
 
 /* Data about a particular attempt to compile a program.  Note that
@@ -379,8 +390,6 @@ struct brw_wm_prog_data {
       /** @} */
    } binding_table;
 
-   GLuint nr_params;       /**< number of float params/constants */
-   GLuint nr_pull_params;
    bool dual_src_blend;
    bool uses_pos_offset;
    bool uses_omask;
@@ -398,15 +407,6 @@ struct brw_wm_prog_data {
     * For varying slots that are not used by the FS, the value is -1.
     */
    int urb_setup[VARYING_SLOT_MAX];
-
-   /* Pointers to tracked values (only valid once
-    * _mesa_load_state_parameters has been called at runtime).
-    *
-    * These must be the last fields of the struct (see
-    * brw_wm_prog_data_compare()).
-    */
-   const float **param;
-   const float **pull_param;
 };
 
 /**
@@ -588,8 +588,6 @@ struct brw_vec4_prog_data {
    GLuint curb_read_length;
    GLuint urb_read_length;
    GLuint total_grf;
-   GLuint nr_params;       /**< number of float params/constants */
-   GLuint nr_pull_params; /**< number of dwords referenced by pull_param[] */
    GLuint total_scratch;
 
    /* Used for calculating urb partitions.  In the VS, this is the size of the
@@ -597,10 +595,6 @@ struct brw_vec4_prog_data {
     * is the size of the URB entry used for output.
     */
    GLuint urb_entry_size;
-
-   /* These pointers must appear last.  See brw_vec4_prog_data_compare(). */
-   const float **param;
-   const float **pull_param;
 };
 
 
diff --git a/src/mesa/drivers/dri/i965/brw_curbe.c b/src/mesa/drivers/dri/i965/brw_curbe.c
index e0b4083..2644cb6 100644
--- a/src/mesa/drivers/dri/i965/brw_curbe.c
+++ b/src/mesa/drivers/dri/i965/brw_curbe.c
@@ -57,10 +57,10 @@ static void calculate_curbe_offsets( struct brw_context *brw )
 {
    struct gl_context *ctx = &brw->ctx;
    /* CACHE_NEW_WM_PROG */
-   const GLuint nr_fp_regs = (brw->wm.prog_data->nr_params + 15) / 16;
+   const GLuint nr_fp_regs = (brw->wm.prog_data->base.nr_params + 15) / 16;
    
    /* BRW_NEW_VERTEX_PROGRAM */
-   const GLuint nr_vp_regs = (brw->vs.prog_data->base.nr_params + 15) / 16;
+   const GLuint nr_vp_regs = (brw->vs.prog_data->base.base.nr_params + 15) / 16;
    GLuint nr_clip_regs = 0;
    GLuint total_regs;
 
@@ -199,8 +199,8 @@ brw_upload_constant_buffer(struct brw_context *brw)
       GLuint offset = brw->curbe.wm_start * 16;
 
       /* copy float constants */
-      for (i = 0; i < brw->wm.prog_data->nr_params; i++) {
-	 buf[offset + i] = *brw->wm.prog_data->param[i];
+      for (i = 0; i < brw->wm.prog_data->base.nr_params; i++) {
+	 buf[offset + i] = *brw->wm.prog_data->base.param[i];
       }
    }
 
@@ -237,8 +237,8 @@ brw_upload_constant_buffer(struct brw_context *brw)
    if (brw->curbe.vs_size) {
       GLuint offset = brw->curbe.vs_start * 16;
 
-      for (i = 0; i < brw->vs.prog_data->base.nr_params; i++) {
-         buf[offset + i] = *brw->vs.prog_data->base.param[i];
+      for (i = 0; i < brw->vs.prog_data->base.base.nr_params; i++) {
+         buf[offset + i] = *brw->vs.prog_data->base.base.param[i];
       }
    }
 
diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index bc66e4a..37e531d 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -898,10 +898,8 @@ fs_visitor::setup_uniform_values(ir_variable *ir)
       if (storage->array_elements)
          slots *= storage->array_elements;
 
-      for (unsigned i = 0; i < slots; i++) {
-         c->prog_data.param[uniforms++] =
-            &storage->storage[i].f;
-      }
+      for (unsigned i = 0; i < slots; i++)
+         stage_prog_data->param[uniforms++] = &storage->storage[i].f;
    }
 
    /* Make sure we actually initialized the right amount of stuff here. */
@@ -938,7 +936,7 @@ fs_visitor::setup_builtin_uniform_values(ir_variable *ir)
 	    break;
 	 last_swiz = swiz;
 
-	 c->prog_data.param[uniforms++] =
+         stage_prog_data->param[uniforms++] =
             &fp->Base.Parameters->ParameterValues[index][swiz].f;
       }
    }
@@ -1369,14 +1367,14 @@ fs_visitor::assign_curb_setup()
 {
    if (dispatch_width == 8) {
       c->prog_data.first_curbe_grf = c->nr_payload_regs;
-      c->prog_data.nr_params = uniforms;
+      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(c->prog_data.nr_params, 8) / 8;
+   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) {
@@ -1750,7 +1748,7 @@ fs_visitor::remove_dead_constants()
 	 if (remapped == -1)
 	    continue;
 
-	 c->prog_data.param[remapped] = c->prog_data.param[i];
+	 stage_prog_data->param[remapped] = stage_prog_data->param[i];
       }
 
       uniforms = new_nr_params;
@@ -1822,15 +1820,15 @@ fs_visitor::move_uniform_array_access_to_pull_constants()
           * add it.
           */
          if (pull_constant_loc[uniform] == -1) {
-            const float **values = &c->prog_data.param[uniform];
+            const float **values = &stage_prog_data->param[uniform];
 
-            pull_constant_loc[uniform] = c->prog_data.nr_pull_params;
+            pull_constant_loc[uniform] = stage_prog_data->nr_pull_params;
 
             assert(param_size[uniform]);
 
             for (int j = 0; j < param_size[uniform]; j++) {
-               c->prog_data.pull_param[c->prog_data.nr_pull_params++] =
-                  values[j];
+               stage_prog_data->pull_param[stage_prog_data->nr_pull_params++]
+                  = values[j];
             }
          }
 
@@ -1838,7 +1836,7 @@ fs_visitor::move_uniform_array_access_to_pull_constants()
          base_ir = inst->ir;
          current_annotation = inst->annotation;
 
-         fs_reg surf_index = fs_reg(c->prog_data.base.binding_table.pull_constants_start);
+         fs_reg surf_index(stage_prog_data->binding_table.pull_constants_start);
          fs_reg temp = fs_reg(this, glsl_type::float_type);
          exec_list list = VARYING_PULL_CONSTANT_LOAD(temp,
                                                      surf_index,
@@ -1892,16 +1890,16 @@ fs_visitor::setup_pull_constants()
          /* If our constant is already being uploaded for reladdr purposes,
           * reuse it.
           */
-         for (unsigned int j = 0; j < c->prog_data.nr_pull_params; j++) {
-            if (c->prog_data.pull_param[j] == c->prog_data.param[i]) {
+         for (unsigned int j = 0; j < stage_prog_data->nr_pull_params; j++) {
+            if (stage_prog_data->pull_param[j] == stage_prog_data->param[i]) {
                pull_constant_loc[i] = j;
                break;
             }
          }
          if (pull_constant_loc[i] == -1) {
-            int pull_index = c->prog_data.nr_pull_params++;
-            c->prog_data.pull_param[pull_index] = c->prog_data.param[i];
-            pull_constant_loc[i] = pull_index;;
+            int pull_index = stage_prog_data->nr_pull_params++;
+            stage_prog_data->pull_param[pull_index] = stage_prog_data->param[i];
+            pull_constant_loc[i] = pull_index;
          }
       }
    }
@@ -1922,7 +1920,7 @@ fs_visitor::setup_pull_constants()
          assert(!inst->src[i].reladdr);
 
 	 fs_reg dst = fs_reg(this, glsl_type::float_type);
-	 fs_reg index = fs_reg(c->prog_data.base.binding_table.pull_constants_start);
+	 fs_reg index(stage_prog_data->binding_table.pull_constants_start);
 	 fs_reg offset = fs_reg((unsigned)(pull_index * 4) & ~15);
 	 fs_inst *pull =
             new(mem_ctx) fs_inst(FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD,
@@ -3402,7 +3400,7 @@ brw_wm_fs_emit(struct brw_context *brw, struct brw_wm_compile *c,
    exec_list *simd16_instructions = NULL;
    fs_visitor v2(brw, c, prog, fp, 16);
    if (brw->gen >= 5 && likely(!(INTEL_DEBUG & DEBUG_NO16))) {
-      if (c->prog_data.nr_pull_params == 0) {
+      if (c->prog_data.base.nr_pull_params == 0) {
          /* Try a 16-wide compile */
          v2.import_uniforms(&v);
          if (!v2.run()) {
diff --git a/src/mesa/drivers/dri/i965/brw_fs_fp.cpp b/src/mesa/drivers/dri/i965/brw_fs_fp.cpp
index d51e679..b537a5a 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[uniforms++] =
+            stage_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 a66fe38..3f065e7 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -1452,9 +1452,9 @@ fs_visitor::rescale_texcoord(ir_texture *ir, fs_reg coordinate,
 
       GLuint index = _mesa_add_state_reference(params,
 					       (gl_state_index *)tokens);
-      c->prog_data.param[uniforms++] =
+      stage_prog_data->param[uniforms++] =
          &prog->Parameters->ParameterValues[index][0].f;
-      c->prog_data.param[uniforms++] =
+      stage_prog_data->param[uniforms++] =
          &prog->Parameters->ParameterValues[index][1].f;
    }
 
@@ -2925,7 +2925,7 @@ fs_visitor::fs_visitor(struct brw_context *brw,
 
    this->spilled_any_registers = false;
 
-   this->param_size = rzalloc_array(mem_ctx, int, c->prog_data.nr_params);
+   this->param_size = rzalloc_array(mem_ctx, int, stage_prog_data->nr_params);
 }
 
 fs_visitor::~fs_visitor()
diff --git a/src/mesa/drivers/dri/i965/brw_program.c b/src/mesa/drivers/dri/i965/brw_program.c
index 9a517be..a494bc2 100644
--- a/src/mesa/drivers/dri/i965/brw_program.c
+++ b/src/mesa/drivers/dri/i965/brw_program.c
@@ -525,3 +525,31 @@ brw_destroy_shader_time(struct brw_context *brw)
    drm_intel_bo_unreference(brw->shader_time.bo);
    brw->shader_time.bo = NULL;
 }
+
+bool
+brw_stage_prog_data_compare(const void *in_a, const void *in_b)
+{
+   const struct brw_stage_prog_data *a = in_a;
+   const struct brw_stage_prog_data *b = in_b;
+
+   /* Compare all the struct up to the pointers. */
+   if (memcmp(a, b, offsetof(struct brw_stage_prog_data, param)))
+      return false;
+
+   if (memcmp(a->param, b->param, a->nr_params * sizeof(void *)))
+      return false;
+
+   if (memcmp(a->pull_param, b->pull_param, a->nr_pull_params * sizeof(void *)))
+      return false;
+
+   return true;
+}
+
+void
+brw_stage_prog_data_free(const void *p)
+{
+   struct brw_stage_prog_data *prog_data = (struct brw_stage_prog_data *)p;
+
+   ralloc_free(prog_data->param);
+   ralloc_free(prog_data->pull_param);
+}
diff --git a/src/mesa/drivers/dri/i965/brw_program.h b/src/mesa/drivers/dri/i965/brw_program.h
index 07be4a0..0bf8aef 100644
--- a/src/mesa/drivers/dri/i965/brw_program.h
+++ b/src/mesa/drivers/dri/i965/brw_program.h
@@ -60,6 +60,12 @@ bool brw_debug_recompile_sampler_key(struct brw_context *brw,
                                      const struct brw_sampler_prog_key_data *key);
 void brw_add_texrect_params(struct gl_program *prog);
 
+bool
+brw_stage_prog_data_compare(const void *in_a, const void *in_b);
+
+void
+brw_stage_prog_data_free(const void *prog_data);
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
diff --git a/src/mesa/drivers/dri/i965/brw_state_cache.c b/src/mesa/drivers/dri/i965/brw_state_cache.c
index 9ccd2bc..8de9828 100644
--- a/src/mesa/drivers/dri/i965/brw_state_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_state_cache.c
@@ -342,9 +342,9 @@ brw_init_caches(struct brw_context *brw)
    cache->aux_compare[BRW_VS_PROG] = brw_vs_prog_data_compare;
    cache->aux_compare[BRW_GS_PROG] = brw_gs_prog_data_compare;
    cache->aux_compare[BRW_WM_PROG] = brw_wm_prog_data_compare;
-   cache->aux_free[BRW_VS_PROG] = brw_vs_prog_data_free;
-   cache->aux_free[BRW_GS_PROG] = brw_gs_prog_data_free;
-   cache->aux_free[BRW_WM_PROG] = brw_wm_prog_data_free;
+   cache->aux_free[BRW_VS_PROG] = brw_stage_prog_data_free;
+   cache->aux_free[BRW_GS_PROG] = brw_stage_prog_data_free;
+   cache->aux_free[BRW_WM_PROG] = brw_stage_prog_data_free;
 }
 
 static void
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.cpp b/src/mesa/drivers/dri/i965/brw_vec4.cpp
index 4458e76..7b9fbf1 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4.cpp
@@ -442,8 +442,8 @@ vec4_visitor::pack_uniform_registers()
 
 	 /* Move the references to the data */
 	 for (int j = 0; j < size; j++) {
-	    prog_data->param[dst * 4 + new_chan[src] + j] =
-	       prog_data->param[src * 4 + j];
+	    stage_prog_data->param[dst * 4 + new_chan[src] + j] =
+	       stage_prog_data->param[src * 4 + j];
 	 }
 
 	 this->uniform_vector_size[dst] += size;
@@ -594,16 +594,16 @@ vec4_visitor::move_push_constants_to_pull_constants()
       pull_constant_loc[i / 4] = -1;
 
       if (i >= max_uniform_components) {
-	 const float **values = &prog_data->param[i];
+	 const float **values = &stage_prog_data->param[i];
 
 	 /* Try to find an existing copy of this uniform in the pull
 	  * constants if it was part of an array access already.
 	  */
-	 for (unsigned int j = 0; j < prog_data->nr_pull_params; j += 4) {
+	 for (unsigned int j = 0; j < stage_prog_data->nr_pull_params; j += 4) {
 	    int matches;
 
 	    for (matches = 0; matches < 4; matches++) {
-	       if (prog_data->pull_param[j + matches] != values[matches])
+	       if (stage_prog_data->pull_param[j + matches] != values[matches])
 		  break;
 	    }
 
@@ -614,11 +614,12 @@ vec4_visitor::move_push_constants_to_pull_constants()
 	 }
 
 	 if (pull_constant_loc[i / 4] == -1) {
-	    assert(prog_data->nr_pull_params % 4 == 0);
-	    pull_constant_loc[i / 4] = prog_data->nr_pull_params / 4;
+	    assert(stage_prog_data->nr_pull_params % 4 == 0);
+	    pull_constant_loc[i / 4] = stage_prog_data->nr_pull_params / 4;
 
 	    for (int j = 0; j < 4; j++) {
-	       prog_data->pull_param[prog_data->nr_pull_params++] = values[j];
+	       stage_prog_data->pull_param[stage_prog_data->nr_pull_params++] =
+                  values[j];
 	    }
 	 }
       }
@@ -1325,11 +1326,12 @@ vec4_visitor::setup_uniforms(int reg)
    if (brw->gen < 6 && this->uniforms == 0) {
       this->uniform_vector_size[this->uniforms] = 1;
 
-      prog_data->param = reralloc(NULL, prog_data->param, const float *, 4);
+      stage_prog_data->param =
+         reralloc(NULL, stage_prog_data->param, const float *, 4);
       for (unsigned int i = 0; i < 4; i++) {
 	 unsigned int slot = this->uniforms * 4 + i;
 	 static float zero = 0.0;
-	 prog_data->param[slot] = &zero;
+	 stage_prog_data->param[slot] = &zero;
       }
 
       this->uniforms++;
@@ -1338,7 +1340,7 @@ vec4_visitor::setup_uniforms(int reg)
       reg += ALIGN(uniforms, 2) / 2;
    }
 
-   prog_data->nr_params = this->uniforms * 4;
+   stage_prog_data->nr_params = this->uniforms * 4;
 
    prog_data->curb_read_length = reg - prog_data->dispatch_grf_start_reg;
 
@@ -1647,31 +1649,4 @@ brw_vec4_setup_prog_key_for_precompile(struct gl_context *ctx,
    }
 }
 
-
-bool
-brw_vec4_prog_data_compare(const struct brw_vec4_prog_data *a,
-                           const struct brw_vec4_prog_data *b)
-{
-   /* Compare all the struct (including the base) up to the pointers. */
-   if (memcmp(a, b, offsetof(struct brw_vec4_prog_data, param)))
-      return false;
-
-   if (memcmp(a->param, b->param, a->nr_params * sizeof(void *)))
-      return false;
-
-   if (memcmp(a->pull_param, b->pull_param, a->nr_pull_params * sizeof(void *)))
-      return false;
-
-   return true;
-}
-
-
-void
-brw_vec4_prog_data_free(const struct brw_vec4_prog_data *prog_data)
-{
-   ralloc_free((void *)prog_data->param);
-   ralloc_free((void *)prog_data->pull_param);
-}
-
-
 } /* extern "C" */
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.h b/src/mesa/drivers/dri/i965/brw_vec4.h
index 4b1e86a..666a0fb4 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.h
+++ b/src/mesa/drivers/dri/i965/brw_vec4.h
@@ -78,9 +78,6 @@ void
 brw_vec4_setup_prog_key_for_precompile(struct gl_context *ctx,
                                        struct brw_vec4_prog_key *key,
                                        GLuint id, struct gl_program *prog);
-bool brw_vec4_prog_data_compare(const struct brw_vec4_prog_data *a,
-                                const struct brw_vec4_prog_data *b);
-void brw_vec4_prog_data_free(const struct brw_vec4_prog_data *prog_data);
 
 #ifdef __cplusplus
 } /* extern "C" */
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_gs.c b/src/mesa/drivers/dri/i965/brw_vec4_gs.c
index 018b0b6..8dbd1e8 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_gs.c
+++ b/src/mesa/drivers/dri/i965/brw_vec4_gs.c
@@ -62,8 +62,10 @@ do_gs_prog(struct brw_context *brw,
    /* We also upload clip plane data as uniforms */
    param_count += MAX_CLIP_PLANES * 4;
 
-   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.base.param =
+      rzalloc_array(NULL, const float *, param_count);
+   c.prog_data.base.base.pull_param =
+      rzalloc_array(NULL, const float *, param_count);
 
    if (gp->program.OutputType == GL_POINTS) {
       /* When the output type is points, the geometry shader may output data
@@ -353,12 +355,12 @@ brw_gs_prog_data_compare(const void *in_a, const void *in_b)
    const struct brw_gs_prog_data *a = in_a;
    const struct brw_gs_prog_data *b = in_b;
 
-   /* Compare the base vec4 structure. */
-   if (!brw_vec4_prog_data_compare(&a->base, &b->base))
+   /* Compare the base structure. */
+   if (!brw_stage_prog_data_compare(&a->base.base, &b->base.base))
       return false;
 
    /* Compare the rest of the struct. */
-   const unsigned offset = sizeof(struct brw_vec4_prog_data);
+   const unsigned offset = sizeof(struct brw_stage_prog_data);
    if (memcmp(((char *) a) + offset, ((char *) b) + offset,
               sizeof(struct brw_gs_prog_data) - offset)) {
       return false;
@@ -366,12 +368,3 @@ brw_gs_prog_data_compare(const void *in_a, const void *in_b)
 
    return true;
 }
-
-
-void
-brw_gs_prog_data_free(const void *in_prog_data)
-{
-   const struct brw_gs_prog_data *prog_data = in_prog_data;
-
-   brw_vec4_prog_data_free(&prog_data->base);
-}
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_gs.h b/src/mesa/drivers/dri/i965/brw_vec4_gs.h
index b209d80..5d4244e 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_gs.h
+++ b/src/mesa/drivers/dri/i965/brw_vec4_gs.h
@@ -35,7 +35,6 @@ struct gl_shader_program;
 
 bool brw_gs_precompile(struct gl_context *ctx, struct gl_shader_program *prog);
 bool brw_gs_prog_data_compare(const void *a, const void *b);
-void brw_gs_prog_data_free(const void *in_prog_data);
 
 #ifdef __cplusplus
 } /* extern "C" */
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
index a13eafb..180a138 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
@@ -666,12 +666,12 @@ vec4_visitor::setup_uniform_values(ir_variable *ir)
 
          int i;
          for (i = 0; i < uniform_vector_size[uniforms]; i++) {
-            prog_data->param[uniforms * 4 + i] = &components->f;
+            stage_prog_data->param[uniforms * 4 + i] = &components->f;
             components++;
          }
          for (; i < 4; i++) {
             static float zero = 0;
-            prog_data->param[uniforms * 4 + i] = &zero;
+            stage_prog_data->param[uniforms * 4 + i] = &zero;
          }
 
          uniforms++;
@@ -689,7 +689,7 @@ vec4_visitor::setup_uniform_clipplane_values()
       this->userplane[i] = dst_reg(UNIFORM, this->uniforms);
       this->userplane[i].type = BRW_REGISTER_TYPE_F;
       for (int j = 0; j < 4; ++j) {
-         prog_data->param[this->uniforms * 4 + j] = &clip_planes[i][j];
+         stage_prog_data->param[this->uniforms * 4 + j] = &clip_planes[i][j];
       }
       ++this->uniforms;
    }
@@ -724,7 +724,7 @@ vec4_visitor::setup_builtin_uniform_values(ir_variable *ir)
 	 int swiz = GET_SWZ(slots[i].swizzle, j);
 	 last_swiz = swiz;
 
-	 prog_data->param[this->uniforms * 4 + j] = &values[swiz];
+	 stage_prog_data->param[this->uniforms * 4 + j] = &values[swiz];
 	 if (swiz <= last_swiz)
 	    this->uniform_vector_size[this->uniforms]++;
       }
@@ -3193,12 +3193,12 @@ vec4_visitor::move_uniform_array_access_to_pull_constants()
 	  * add it.
 	  */
 	 if (pull_constant_loc[uniform] == -1) {
-	    const float **values = &prog_data->param[uniform * 4];
+	    const float **values = &stage_prog_data->param[uniform * 4];
 
-	    pull_constant_loc[uniform] = prog_data->nr_pull_params / 4;
+	    pull_constant_loc[uniform] = stage_prog_data->nr_pull_params / 4;
 
 	    for (int j = 0; j < uniform_size[uniform] * 4; j++) {
-	       prog_data->pull_param[prog_data->nr_pull_params++]
+	       stage_prog_data->pull_param[stage_prog_data->nr_pull_params++]
                   = values[j];
 	    }
 	 }
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_vp.cpp b/src/mesa/drivers/dri/i965/brw_vec4_vp.cpp
index d98bad1..0ec37c1 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_vp.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_vp.cpp
@@ -415,10 +415,10 @@ vec4_vs_visitor::emit_program_code()
          vs_compile->vp->program.Base.Parameters;
       unsigned i;
       for (i = 0; i < params->NumParameters * 4; i++) {
-         prog_data->pull_param[i] =
+         stage_prog_data->pull_param[i] =
             &params->ParameterValues[i / 4][i % 4].f;
       }
-      prog_data->nr_pull_params = i;
+      stage_prog_data->nr_pull_params = i;
    }
 }
 
@@ -446,7 +446,7 @@ vec4_vs_visitor::setup_vp_regs()
       this->uniform_size[this->uniforms] = 1; /* 1 vec4 */
       this->uniform_vector_size[this->uniforms] = components;
       for (unsigned i = 0; i < 4; i++) {
-         prog_data->param[this->uniforms * 4 + i] = i >= components
+         stage_prog_data->param[this->uniforms * 4 + i] = i >= components
             ? 0 : &plist->ParameterValues[p][i].f;
       }
       this->uniforms++; /* counted in vec4 units */
diff --git a/src/mesa/drivers/dri/i965/brw_vs.c b/src/mesa/drivers/dri/i965/brw_vs.c
index b5c8b63..e9f92d4 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.c
+++ b/src/mesa/drivers/dri/i965/brw_vs.c
@@ -181,12 +181,12 @@ brw_vs_prog_data_compare(const void *in_a, const void *in_b)
    const struct brw_vs_prog_data *a = in_a;
    const struct brw_vs_prog_data *b = in_b;
 
-   /* Compare the base vec4 structure. */
-   if (!brw_vec4_prog_data_compare(&a->base, &b->base))
+   /* Compare the base structure. */
+   if (!brw_stage_prog_data_compare(&a->base.base, &b->base.base))
       return false;
 
    /* Compare the rest of the struct. */
-   const unsigned offset = sizeof(struct brw_vec4_prog_data);
+   const unsigned offset = sizeof(struct brw_stage_prog_data);
    if (memcmp(((char *) a) + offset, ((char *) b) + offset,
               sizeof(struct brw_vs_prog_data) - offset)) {
       return false;
@@ -205,6 +205,7 @@ do_vs_prog(struct brw_context *brw,
    const GLuint *program;
    struct brw_vs_compile c;
    struct brw_vs_prog_data prog_data;
+   struct brw_stage_prog_data *stage_prog_data = &prog_data.base.base;
    void *mem_ctx;
    int i;
    struct gl_shader *vs = NULL;
@@ -240,8 +241,8 @@ do_vs_prog(struct brw_context *brw,
     */
    param_count += c.key.base.nr_userclip_plane_consts * 4;
 
-   prog_data.base.param = rzalloc_array(NULL, const float *, param_count);
-   prog_data.base.pull_param = rzalloc_array(NULL, const float *, param_count);
+   stage_prog_data->param = rzalloc_array(NULL, const float *, param_count);
+   stage_prog_data->pull_param = rzalloc_array(NULL, const float *, param_count);
 
    GLbitfield64 outputs_written = vp->program.Base.OutputsWritten;
    prog_data.inputs_read = vp->program.Base.InputsRead;
@@ -543,12 +544,3 @@ brw_vs_precompile(struct gl_context *ctx, struct gl_shader_program *prog)
 
    return success;
 }
-
-
-void
-brw_vs_prog_data_free(const void *in_prog_data)
-{
-   const struct brw_vs_prog_data *prog_data = in_prog_data;
-
-   brw_vec4_prog_data_free(&prog_data->base);
-}
diff --git a/src/mesa/drivers/dri/i965/brw_vs.h b/src/mesa/drivers/dri/i965/brw_vs.h
index 5d62e47..6982f58 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.h
+++ b/src/mesa/drivers/dri/i965/brw_vs.h
@@ -94,7 +94,6 @@ void brw_vs_debug_recompile(struct brw_context *brw,
                             struct gl_shader_program *prog,
                             const struct brw_vs_prog_key *key);
 bool brw_vs_prog_data_compare(const void *a, const void *b);
-void brw_vs_prog_data_free(const void *in_prog_data);
 
 #ifdef __cplusplus
 } /* extern "C" */
diff --git a/src/mesa/drivers/dri/i965/brw_vs_surface_state.c b/src/mesa/drivers/dri/i965/brw_vs_surface_state.c
index 9834c11..9553ad9 100644
--- a/src/mesa/drivers/dri/i965/brw_vs_surface_state.c
+++ b/src/mesa/drivers/dri/i965/brw_vs_surface_state.c
@@ -51,7 +51,7 @@ brw_upload_vec4_pull_constants(struct brw_context *brw,
     */
    _mesa_load_state_parameters(&brw->ctx, prog->Parameters);
 
-   if (!prog_data->nr_pull_params) {
+   if (!prog_data->base.nr_pull_params) {
       if (stage_state->const_bo) {
 	 drm_intel_bo_unreference(stage_state->const_bo);
 	 stage_state->const_bo = NULL;
@@ -63,20 +63,20 @@ brw_upload_vec4_pull_constants(struct brw_context *brw,
 
    /* _NEW_PROGRAM_CONSTANTS */
    drm_intel_bo_unreference(stage_state->const_bo);
-   uint32_t size = prog_data->nr_pull_params * 4;
+   uint32_t size = prog_data->base.nr_pull_params * 4;
    stage_state->const_bo = drm_intel_bo_alloc(brw->bufmgr, "vec4_const_buffer",
                                            size, 64);
 
    drm_intel_gem_bo_map_gtt(stage_state->const_bo);
 
-   for (i = 0; i < prog_data->nr_pull_params; i++) {
+   for (i = 0; i < prog_data->base.nr_pull_params; i++) {
       memcpy(stage_state->const_bo->virtual + i * 4,
-	     prog_data->pull_param[i],
+	     prog_data->base.pull_param[i],
 	     4);
    }
 
    if (0) {
-      for (i = 0; i < ALIGN(prog_data->nr_pull_params, 4) / 4; i++) {
+      for (i = 0; i < ALIGN(prog_data->base.nr_pull_params, 4) / 4; i++) {
 	 float *row = (float *)stage_state->const_bo->virtual + i * 4;
 	 printf("const surface %3d: %4.3f %4.3f %4.3f %4.3f\n",
 		i, row[0], row[1], row[2], row[3]);
diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c
index b745d8f..d78d8e3 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -109,28 +109,19 @@ brw_wm_prog_data_compare(const void *in_a, const void *in_b)
    const struct brw_wm_prog_data *a = in_a;
    const struct brw_wm_prog_data *b = in_b;
 
-   /* Compare all the struct (including the base) up to the pointers. */
-   if (memcmp(a, b, offsetof(struct brw_wm_prog_data, param)))
+   /* Compare the base structure. */
+   if (!brw_stage_prog_data_compare(&a->base, &b->base))
       return false;
 
-   if (memcmp(a->param, b->param, a->nr_params * sizeof(void *)))
-      return false;
-
-   if (memcmp(a->pull_param, b->pull_param, a->nr_pull_params * sizeof(void *)))
+   /* Compare the rest of the structure. */
+   const unsigned offset = sizeof(struct brw_stage_prog_data);
+   if (memcmp(((char *) a) + offset, ((char *) b) + offset,
+              sizeof(struct brw_wm_prog_data) - offset))
       return false;
 
    return true;
 }
 
-void
-brw_wm_prog_data_free(const void *in_prog_data)
-{
-   const struct brw_wm_prog_data *prog_data = in_prog_data;
-
-   ralloc_free((void *)prog_data->param);
-   ralloc_free((void *)prog_data->pull_param);
-}
-
 /**
  * All Mesa program -> GPU code generation goes through this function.
  * Depending on the instructions used (i.e. flow control instructions)
@@ -163,9 +154,10 @@ bool do_wm_prog(struct brw_context *brw,
    }
    /* The backend also sometimes adds params for texture size. */
    param_count += 2 * BRW_MAX_TEX_UNIT;
-   c->prog_data.param = rzalloc_array(NULL, const float *, param_count);
-   c->prog_data.pull_param = rzalloc_array(NULL, const float *, param_count);
-   c->prog_data.nr_params = param_count;
+   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));
 
diff --git a/src/mesa/drivers/dri/i965/brw_wm.h b/src/mesa/drivers/dri/i965/brw_wm.h
index df5fb4c..9ef4c3c 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.h
+++ b/src/mesa/drivers/dri/i965/brw_wm.h
@@ -120,6 +120,5 @@ void brw_wm_debug_recompile(struct brw_context *brw,
                             struct gl_shader_program *prog,
                             const struct brw_wm_prog_key *key);
 bool brw_wm_prog_data_compare(const void *a, const void *b);
-void brw_wm_prog_data_free(const void *in_prog_data);
 
 #endif
diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
index fd6954b..6bd4751 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
@@ -438,7 +438,7 @@ brw_upload_wm_pull_constants(struct brw_context *brw)
    struct brw_fragment_program *fp =
       (struct brw_fragment_program *) brw->fragment_program;
    struct gl_program_parameter_list *params = fp->program.Base.Parameters;
-   const int size = brw->wm.prog_data->nr_pull_params * sizeof(float);
+   const int size = brw->wm.prog_data->base.nr_pull_params * sizeof(float);
    const int surf_index =
       brw->wm.prog_data->base.binding_table.pull_constants_start;
    float *constants;
@@ -447,7 +447,7 @@ brw_upload_wm_pull_constants(struct brw_context *brw)
    _mesa_load_state_parameters(ctx, params);
 
    /* CACHE_NEW_WM_PROG */
-   if (brw->wm.prog_data->nr_pull_params == 0) {
+   if (brw->wm.prog_data->base.nr_pull_params == 0) {
       if (brw->wm.base.const_bo) {
 	 drm_intel_bo_unreference(brw->wm.base.const_bo);
 	 brw->wm.base.const_bo = NULL;
@@ -464,8 +464,8 @@ brw_upload_wm_pull_constants(struct brw_context *brw)
    /* _NEW_PROGRAM_CONSTANTS */
    drm_intel_gem_bo_map_gtt(brw->wm.base.const_bo);
    constants = brw->wm.base.const_bo->virtual;
-   for (i = 0; i < brw->wm.prog_data->nr_pull_params; i++) {
-      constants[i] = *brw->wm.prog_data->pull_param[i];
+   for (i = 0; i < brw->wm.prog_data->base.nr_pull_params; i++) {
+      constants[i] = *brw->wm.prog_data->base.pull_param[i];
    }
    drm_intel_gem_bo_unmap_gtt(brw->wm.base.const_bo);
 
diff --git a/src/mesa/drivers/dri/i965/gen6_vs_state.c b/src/mesa/drivers/dri/i965/gen6_vs_state.c
index 80129cd..99b2885 100644
--- a/src/mesa/drivers/dri/i965/gen6_vs_state.c
+++ b/src/mesa/drivers/dri/i965/gen6_vs_state.c
@@ -48,7 +48,7 @@ gen6_upload_vec4_push_constants(struct brw_context *brw,
    /* XXX: Should this happen somewhere before to get our state flag set? */
    _mesa_load_state_parameters(ctx, prog->Parameters);
 
-   if (prog_data->nr_params == 0) {
+   if (prog_data->base.nr_params == 0) {
       stage_state->push_const_size = 0;
    } else {
       int params_uploaded;
@@ -56,7 +56,7 @@ gen6_upload_vec4_push_constants(struct brw_context *brw,
       int i;
 
       param = brw_state_batch(brw, type,
-			      prog_data->nr_params * sizeof(float),
+			      prog_data->base.nr_params * sizeof(float),
 			      32, &stage_state->push_const_offset);
 
       /* _NEW_PROGRAM_CONSTANTS
@@ -65,10 +65,10 @@ gen6_upload_vec4_push_constants(struct brw_context *brw,
        * side effect of dereferencing uniforms, so _NEW_PROGRAM_CONSTANTS
        * wouldn't be set for them.
       */
-      for (i = 0; i < prog_data->nr_params; i++) {
-         param[i] = *prog_data->param[i];
+      for (i = 0; i < prog_data->base.nr_params; i++) {
+         param[i] = *prog_data->base.param[i];
       }
-      params_uploaded = prog_data->nr_params / 4;
+      params_uploaded = prog_data->base.nr_params / 4;
 
       if (0) {
 	 printf("Constant buffer:\n");
diff --git a/src/mesa/drivers/dri/i965/gen6_wm_state.c b/src/mesa/drivers/dri/i965/gen6_wm_state.c
index 83a1708..aec99cb 100644
--- a/src/mesa/drivers/dri/i965/gen6_wm_state.c
+++ b/src/mesa/drivers/dri/i965/gen6_wm_state.c
@@ -51,23 +51,23 @@ gen6_upload_wm_push_constants(struct brw_context *brw)
    /* XXX: Should this happen somewhere before to get our state flag set? */
    _mesa_load_state_parameters(ctx, fp->program.Base.Parameters);
 
-   if (prog_data->nr_params == 0) {
+   if (prog_data->base.nr_params == 0) {
       brw->wm.base.push_const_size = 0;
    } else {
       float *constants;
       unsigned int i;
 
       constants = brw_state_batch(brw, AUB_TRACE_WM_CONSTANTS,
-				  prog_data->nr_params * sizeof(float),
+				  prog_data->base.nr_params * sizeof(float),
 				  32, &brw->wm.base.push_const_offset);
 
-      for (i = 0; i < prog_data->nr_params; i++) {
-	 constants[i] = *prog_data->param[i];
+      for (i = 0; i < prog_data->base.nr_params; i++) {
+	 constants[i] = *prog_data->base.param[i];
       }
 
       if (0) {
 	 printf("WM constants:\n");
-	 for (i = 0; i < prog_data->nr_params; i++) {
+	 for (i = 0; i < prog_data->base.nr_params; i++) {
 	    if ((i & 7) == 0)
 	       printf("g%d: ", prog_data->first_curbe_grf + i / 8);
 	    printf("%8f ", constants[i]);
@@ -79,7 +79,7 @@ gen6_upload_wm_push_constants(struct brw_context *brw)
 	 printf("\n");
       }
 
-      brw->wm.base.push_const_size = ALIGN(prog_data->nr_params, 8) / 8;
+      brw->wm.base.push_const_size = ALIGN(prog_data->base.nr_params, 8) / 8;
    }
 }
 
@@ -105,7 +105,7 @@ upload_wm_state(struct brw_context *brw)
    bool multisampled_fbo = ctx->DrawBuffer->Visual.samples > 1;
 
     /* CACHE_NEW_WM_PROG */
-   if (brw->wm.prog_data->nr_params == 0) {
+   if (brw->wm.prog_data->base.nr_params == 0) {
       /* Disable the push constant buffers. */
       BEGIN_BATCH(5);
       OUT_BATCH(_3DSTATE_CONSTANT_PS << 16 | (5 - 2));
diff --git a/src/mesa/drivers/dri/i965/gen7_wm_state.c b/src/mesa/drivers/dri/i965/gen7_wm_state.c
index 65c9bbf..50a87e2 100644
--- a/src/mesa/drivers/dri/i965/gen7_wm_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_wm_state.c
@@ -179,7 +179,7 @@ upload_ps_state(struct brw_context *brw)
    dw4 |= (brw->max_wm_threads - 1) << max_threads_shift;
 
    /* CACHE_NEW_WM_PROG */
-   if (brw->wm.prog_data->nr_params > 0)
+   if (brw->wm.prog_data->base.nr_params > 0)
       dw4 |= GEN7_PS_PUSH_CONSTANT_ENABLE;
 
    /* From the IVB PRM, volume 2 part 1, page 287:
-- 
1.8.3.4



More information about the mesa-dev mailing list