[Mesa-dev] [PATCH 11/17] i965/vs: move VS-specific data members to vs_vec4_visitor.

Paul Berry stereotype441 at gmail.com
Sun Apr 7 15:54:04 PDT 2013


This patch moves the following data structures from vec4_visitor to
vec4_vs_visitor, since they contain VS-specific data:

- struct brw_vs_compile *c
- struct brw_vs_prog_data *prog_data
- src_reg *vp_temp_regs
- src_reg vp_addr_reg

Since brw_vs_compile and brw_vs_prog_data also contain vec4-generic
data, the following pointers are added to the base class, to allow it
to access the vec4-generic portions of these data structures:

- struct brw_vec4_compile *vec4_compile
- struct brw_vec4_prog_key *vec4_key
- struct brw_vec4_prog_data *vec4_prog_data
---
 src/mesa/drivers/dri/i965/brw_vec4.cpp             | 26 ++++-----
 src/mesa/drivers/dri/i965/brw_vec4.h               | 19 +++---
 .../drivers/dri/i965/brw_vec4_reg_allocate.cpp     | 12 ++--
 src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp     | 67 ++++++++++++----------
 .../dri/i965/test_vec4_register_coalesce.cpp       | 12 ++--
 5 files changed, 72 insertions(+), 64 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_vec4.cpp b/src/mesa/drivers/dri/i965/brw_vec4.cpp
index 5f9372d..847adc7 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4.cpp
@@ -410,8 +410,8 @@ vec4_visitor::pack_uniform_registers()
 
 	 /* Move the references to the data */
 	 for (int j = 0; j < size; j++) {
-	    prog_data->base.param[dst * 4 + new_chan[src] + j] =
-	       prog_data->base.param[src * 4 + j];
+	    vec4_prog_data->param[dst * 4 + new_chan[src] + j] =
+	       vec4_prog_data->param[src * 4 + j];
 	 }
 
 	 this->uniform_vector_size[dst] += size;
@@ -562,16 +562,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->base.param[i];
+	 const float **values = &vec4_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->base.nr_pull_params; j += 4) {
+	 for (unsigned int j = 0; j < vec4_prog_data->nr_pull_params; j += 4) {
 	    int matches;
 
 	    for (matches = 0; matches < 4; matches++) {
-	       if (prog_data->base.pull_param[j + matches] != values[matches])
+	       if (vec4_prog_data->pull_param[j + matches] != values[matches])
 		  break;
 	    }
 
@@ -582,11 +582,11 @@ vec4_visitor::move_push_constants_to_pull_constants()
 	 }
 
 	 if (pull_constant_loc[i / 4] == -1) {
-	    assert(prog_data->base.nr_pull_params % 4 == 0);
-	    pull_constant_loc[i / 4] = prog_data->base.nr_pull_params / 4;
+	    assert(vec4_prog_data->nr_pull_params % 4 == 0);
+	    pull_constant_loc[i / 4] = vec4_prog_data->nr_pull_params / 4;
 
 	    for (int j = 0; j < 4; j++) {
-	       prog_data->base.pull_param[prog_data->base.nr_pull_params++] = values[j];
+	       vec4_prog_data->pull_param[vec4_prog_data->nr_pull_params++] = values[j];
 	    }
 	 }
       }
@@ -646,7 +646,7 @@ vec4_visitor::opt_set_dependency_control()
 
    cfg_t cfg(this);
 
-   assert(prog_data->base.total_grf ||
+   assert(vec4_prog_data->total_grf ||
           !"Must be called after register allocation");
 
    for (int i = 0; i < cfg.num_blocks; i++) {
@@ -1259,7 +1259,7 @@ vec4_visitor::setup_uniforms(int reg)
       for (unsigned int i = 0; i < 4; i++) {
 	 unsigned int slot = this->uniforms * 4 + i;
 	 static float zero = 0.0;
-	 prog_data->base.param[slot] = &zero;
+	 vec4_prog_data->param[slot] = &zero;
       }
 
       this->uniforms++;
@@ -1268,9 +1268,9 @@ vec4_visitor::setup_uniforms(int reg)
       reg += ALIGN(uniforms, 2) / 2;
    }
 
-   prog_data->base.nr_params = this->uniforms * 4;
+   vec4_prog_data->nr_params = this->uniforms * 4;
 
-   prog_data->base.curb_read_length = reg - 1;
+   vec4_prog_data->curb_read_length = reg - 1;
 
    return reg;
 }
@@ -1403,7 +1403,7 @@ vec4_visitor::run()
    }
    base_ir = NULL;
 
-   if (c->key.base.userclip_active && !c->key.base.uses_clip_distance)
+   if (vec4_key->userclip_active && !vec4_key->uses_clip_distance)
       setup_uniform_clipplane_values();
 
    emit_thread_end();
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.h b/src/mesa/drivers/dri/i965/brw_vec4.h
index 54109e4..a5aa996 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.h
+++ b/src/mesa/drivers/dri/i965/brw_vec4.h
@@ -210,8 +210,10 @@ class vec4_visitor : public backend_visitor
 {
 public:
    vec4_visitor(struct brw_context *brw,
-                struct brw_vs_compile *c,
-                struct brw_vs_prog_data *prog_data,
+                struct brw_vec4_compile *vec4_compile,
+                struct gl_program *p,
+                const struct brw_vec4_prog_key *vec4_key,
+                struct brw_vec4_prog_data *vec4_prog_data,
 		struct gl_shader_program *prog,
 		struct brw_shader *shader,
 		void *mem_ctx);
@@ -228,8 +230,9 @@ public:
    }
 
    struct gl_program *p;
-   struct brw_vs_compile *c;
-   struct brw_vs_prog_data *prog_data;
+   struct brw_vec4_compile *vec4_compile;
+   const struct brw_vec4_prog_key *vec4_key;
+   struct brw_vec4_prog_data *vec4_prog_data;
    unsigned int sanity_param_count;
 
    char *fail_msg;
@@ -251,9 +254,6 @@ public:
    int *virtual_grf_use;
    dst_reg userplane[MAX_CLIP_PLANES];
 
-   src_reg *vp_temp_regs;
-   src_reg vp_addr_reg;
-
    /**
     * This is the size to be used for an array with an element per
     * reg_offset
@@ -507,6 +507,11 @@ private:
    void setup_vp_regs();
    dst_reg get_vp_dst_reg(const prog_dst_register &dst);
    src_reg get_vp_src_reg(const prog_src_register &src);
+
+   struct brw_vs_compile * const c;
+   struct brw_vs_prog_data * const prog_data;
+   src_reg *vp_temp_regs;
+   src_reg vp_addr_reg;
 };
 
 /**
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp b/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp
index f9ebc3c..1fe7ab7 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp
@@ -76,7 +76,7 @@ vec4_visitor::reg_allocate_trivial()
 	 next += this->virtual_grf_sizes[i];
       }
    }
-   prog_data->base.total_grf = next;
+   vec4_prog_data->total_grf = next;
 
    foreach_iter(exec_list_iterator, iter, this->instructions) {
       vec4_instruction *inst = (vec4_instruction *)iter.get();
@@ -87,9 +87,9 @@ vec4_visitor::reg_allocate_trivial()
       assign(hw_reg_mapping, &inst->src[2]);
    }
 
-   if (prog_data->base.total_grf > max_grf) {
+   if (vec4_prog_data->total_grf > max_grf) {
       fail("Ran out of regs on trivial allocator (%d/%d)\n",
-	   prog_data->base.total_grf, max_grf);
+	   vec4_prog_data->total_grf, max_grf);
       return false;
    }
 
@@ -221,12 +221,12 @@ vec4_visitor::reg_allocate()
     * regs in the register classes back down to real hardware reg
     * numbers.
     */
-   prog_data->base.total_grf = first_assigned_grf;
+   vec4_prog_data->total_grf = first_assigned_grf;
    for (int i = 0; i < virtual_grf_count; i++) {
       int reg = ra_get_node_reg(g, i);
 
       hw_reg_mapping[i] = first_assigned_grf + brw->vs.ra_reg_to_grf[reg];
-      prog_data->base.total_grf = MAX2(prog_data->base.total_grf,
+      vec4_prog_data->total_grf = MAX2(vec4_prog_data->total_grf,
 				  hw_reg_mapping[i] + virtual_grf_sizes[i]);
    }
 
@@ -321,7 +321,7 @@ void
 vec4_visitor::spill_reg(int spill_reg_nr)
 {
    assert(virtual_grf_sizes[spill_reg_nr] == 1);
-   unsigned int spill_offset = c->base.last_scratch++;
+   unsigned int spill_offset = vec4_compile->last_scratch++;
 
    /* Generate spill/unspill instructions for the objects being spilled. */
    foreach_list(node, &this->instructions) {
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
index 79fd6a8..18f17c8 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
@@ -605,12 +605,12 @@ vec4_visitor::setup_uniform_values(ir_variable *ir)
 
          int i;
          for (i = 0; i < uniform_vector_size[uniforms]; i++) {
-            prog_data->base.param[uniforms * 4 + i] = &components->f;
+            vec4_prog_data->param[uniforms * 4 + i] = &components->f;
             components++;
          }
          for (; i < 4; i++) {
             static float zero = 0;
-            prog_data->base.param[uniforms * 4 + i] = &zero;
+            vec4_prog_data->param[uniforms * 4 + i] = &zero;
          }
 
          uniforms++;
@@ -632,14 +632,14 @@ vec4_visitor::setup_uniform_clipplane_values()
        */
       int compacted_clipplane_index = 0;
       for (int i = 0; i < MAX_CLIP_PLANES; ++i) {
-	 if (!(c->key.base.userclip_planes_enabled_gen_4_5 & (1 << i)))
+	 if (!(vec4_key->userclip_planes_enabled_gen_4_5 & (1 << i)))
 	    continue;
 
 	 this->uniform_vector_size[this->uniforms] = 4;
 	 this->userplane[compacted_clipplane_index] = dst_reg(UNIFORM, this->uniforms);
 	 this->userplane[compacted_clipplane_index].type = BRW_REGISTER_TYPE_F;
 	 for (int j = 0; j < 4; ++j) {
-	    prog_data->base.param[this->uniforms * 4 + j] = &clip_planes[i][j];
+	    vec4_prog_data->param[this->uniforms * 4 + j] = &clip_planes[i][j];
 	 }
 	 ++compacted_clipplane_index;
 	 ++this->uniforms;
@@ -648,12 +648,12 @@ vec4_visitor::setup_uniform_clipplane_values()
       /* In Gen6 and later, we don't compact clip planes, because this
        * simplifies the implementation of gl_ClipDistance.
        */
-      for (int i = 0; i < c->key.base.nr_userclip_plane_consts; ++i) {
+      for (int i = 0; i < vec4_key->nr_userclip_plane_consts; ++i) {
 	 this->uniform_vector_size[this->uniforms] = 4;
 	 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->base.param[this->uniforms * 4 + j] = &clip_planes[i][j];
+	    vec4_prog_data->param[this->uniforms * 4 + j] = &clip_planes[i][j];
 	 }
 	 ++this->uniforms;
       }
@@ -689,7 +689,7 @@ vec4_visitor::setup_builtin_uniform_values(ir_variable *ir)
 	 int swiz = GET_SWZ(slots[i].swizzle, j);
 	 last_swiz = swiz;
 
-	 prog_data->base.param[this->uniforms * 4 + j] = &values[swiz];
+	 vec4_prog_data->param[this->uniforms * 4 + j] = &values[swiz];
 	 if (swiz <= last_swiz)
 	    this->uniform_vector_size[this->uniforms]++;
       }
@@ -2303,7 +2303,7 @@ vec4_visitor::visit(ir_texture *ir)
 void
 vec4_visitor::swizzle_result(ir_texture *ir, src_reg orig_val, int sampler)
 {
-   int s = c->key.base.tex.swizzles[sampler];
+   int s = vec4_key->tex.swizzles[sampler];
 
    this->result = src_reg(this, ir->type);
    dst_reg swizzled_result(this->result);
@@ -2417,8 +2417,8 @@ void
 vec4_visitor::emit_psiz_and_flags(struct brw_reg reg)
 {
    if (intel->gen < 6 &&
-       ((prog_data->base.vue_map.slots_valid & VARYING_BIT_PSIZ) ||
-        c->key.base.userclip_active || brw->has_negative_rhw_bug)) {
+       ((vec4_prog_data->vue_map.slots_valid & VARYING_BIT_PSIZ) ||
+        vec4_key->userclip_active || brw->has_negative_rhw_bug)) {
       dst_reg header1 = dst_reg(this, glsl_type::uvec4_type);
       dst_reg header1_w = header1;
       header1_w.writemask = WRITEMASK_W;
@@ -2426,7 +2426,7 @@ vec4_visitor::emit_psiz_and_flags(struct brw_reg reg)
 
       emit(MOV(header1, 0u));
 
-      if (prog_data->base.vue_map.slots_valid & VARYING_BIT_PSIZ) {
+      if (vec4_prog_data->vue_map.slots_valid & VARYING_BIT_PSIZ) {
 	 src_reg psiz = src_reg(output_reg[VARYING_SLOT_PSIZ]);
 
 	 current_annotation = "Point size";
@@ -2435,7 +2435,7 @@ vec4_visitor::emit_psiz_and_flags(struct brw_reg reg)
       }
 
       current_annotation = "Clipping flags";
-      for (i = 0; i < c->key.base.nr_userclip_plane_consts; i++) {
+      for (i = 0; i < vec4_key->nr_userclip_plane_consts; i++) {
 	 vec4_instruction *inst;
 
 	 inst = emit(DP4(dst_null_f(), src_reg(output_reg[VARYING_SLOT_POS]),
@@ -2471,7 +2471,7 @@ vec4_visitor::emit_psiz_and_flags(struct brw_reg reg)
       emit(MOV(retype(reg, BRW_REGISTER_TYPE_UD), 0u));
    } else {
       emit(MOV(retype(reg, BRW_REGISTER_TYPE_D), src_reg(0)));
-      if (prog_data->base.vue_map.slots_valid & VARYING_BIT_PSIZ) {
+      if (vec4_prog_data->vue_map.slots_valid & VARYING_BIT_PSIZ) {
          emit(MOV(brw_writemask(reg, WRITEMASK_W),
                   src_reg(output_reg[VARYING_SLOT_PSIZ])));
       }
@@ -2502,11 +2502,11 @@ vec4_visitor::emit_clip_distances(struct brw_reg reg, int offset)
     * if the user wrote to it; otherwise we use gl_Position.
     */
    gl_varying_slot clip_vertex = VARYING_SLOT_CLIP_VERTEX;
-   if (!(prog_data->base.vue_map.slots_valid & VARYING_BIT_CLIP_VERTEX)) {
+   if (!(vec4_prog_data->vue_map.slots_valid & VARYING_BIT_CLIP_VERTEX)) {
       clip_vertex = VARYING_SLOT_POS;
    }
 
-   for (int i = 0; i + offset < c->key.base.nr_userclip_plane_consts && i < 4;
+   for (int i = 0; i + offset < vec4_key->nr_userclip_plane_consts && i < 4;
         ++i) {
       emit(DP4(dst_reg(brw_writemask(reg, 1 << i)),
                src_reg(output_reg[clip_vertex]),
@@ -2527,7 +2527,7 @@ vec4_visitor::emit_generic_urb_slot(dst_reg reg, int varying)
         varying == VARYING_SLOT_COL1 ||
         varying == VARYING_SLOT_BFC0 ||
         varying == VARYING_SLOT_BFC1) &&
-       c->key.base.clamp_vertex_color) {
+       vec4_key->clamp_vertex_color) {
       inst->saturate = true;
    }
 }
@@ -2556,7 +2556,7 @@ vec4_visitor::emit_urb_slot(int mrf, int varying)
       break;
    case VARYING_SLOT_CLIP_DIST0:
    case VARYING_SLOT_CLIP_DIST1:
-      if (this->c->key.base.uses_clip_distance) {
+      if (this->vec4_key->uses_clip_distance) {
          emit_generic_urb_slot(reg, varying);
       } else {
          current_annotation = "user clip distances";
@@ -2828,8 +2828,8 @@ vec4_visitor::move_grf_array_access_to_scratch()
 
       if (inst->dst.file == GRF && inst->dst.reladdr &&
 	  scratch_loc[inst->dst.reg] == -1) {
-	 scratch_loc[inst->dst.reg] = c->base.last_scratch;
-	 c->base.last_scratch += this->virtual_grf_sizes[inst->dst.reg];
+	 scratch_loc[inst->dst.reg] = vec4_compile->last_scratch;
+	 vec4_compile->last_scratch += this->virtual_grf_sizes[inst->dst.reg];
       }
 
       for (int i = 0 ; i < 3; i++) {
@@ -2837,8 +2837,8 @@ vec4_visitor::move_grf_array_access_to_scratch()
 
 	 if (src->file == GRF && src->reladdr &&
 	     scratch_loc[src->reg] == -1) {
-	    scratch_loc[src->reg] = c->base.last_scratch;
-	    c->base.last_scratch += this->virtual_grf_sizes[src->reg];
+	    scratch_loc[src->reg] = vec4_compile->last_scratch;
+	    vec4_compile->last_scratch += this->virtual_grf_sizes[src->reg];
 	 }
       }
    }
@@ -2937,12 +2937,12 @@ vec4_visitor::move_uniform_array_access_to_pull_constants()
 	  * add it.
 	  */
 	 if (pull_constant_loc[uniform] == -1) {
-	    const float **values = &prog_data->base.param[uniform * 4];
+	    const float **values = &vec4_prog_data->param[uniform * 4];
 
-	    pull_constant_loc[uniform] = prog_data->base.nr_pull_params / 4;
+	    pull_constant_loc[uniform] = vec4_prog_data->nr_pull_params / 4;
 
 	    for (int j = 0; j < uniform_size[uniform] * 4; j++) {
-	       prog_data->base.pull_param[prog_data->base.nr_pull_params++]
+	       vec4_prog_data->pull_param[vec4_prog_data->nr_pull_params++]
                   = values[j];
 	    }
 	 }
@@ -2984,13 +2984,14 @@ vec4_visitor::resolve_ud_negate(src_reg *reg)
 }
 
 vec4_visitor::vec4_visitor(struct brw_context *brw,
-			   struct brw_vs_compile *c,
-                           struct brw_vs_prog_data *prog_data,
+                           struct brw_vec4_compile *vec4_compile,
+                           struct gl_program *p,
+                           const struct brw_vec4_prog_key *vec4_key,
+                           struct brw_vec4_prog_data *vec4_prog_data,
 			   struct gl_shader_program *prog,
 			   struct brw_shader *shader,
 			   void *mem_ctx)
 {
-   this->c = c;
    this->brw = brw;
    this->intel = &brw->intel;
    this->ctx = &intel->ctx;
@@ -3004,9 +3005,10 @@ vec4_visitor::vec4_visitor(struct brw_context *brw,
    this->current_annotation = NULL;
    memset(this->output_reg_annotation, 0, sizeof(this->output_reg_annotation));
 
-   this->c = c;
-   this->p = &c->vp->program.Base;
-   this->prog_data = prog_data;
+   this->vec4_compile = vec4_compile;
+   this->p = p;
+   this->vec4_key = vec4_key;
+   this->vec4_prog_data = vec4_prog_data;
 
    this->variable_ht = hash_table_ctor(0,
 				       hash_table_pointer_hash,
@@ -3038,7 +3040,10 @@ vec4_vs_visitor::vec4_vs_visitor(struct brw_context *brw,
                                  struct gl_shader_program *prog,
                                  struct brw_shader *shader,
                                  void *mem_ctx)
-   : vec4_visitor(brw, c, prog_data, prog, shader, mem_ctx)
+   : vec4_visitor(brw, &c->base, &c->vp->program.Base, &c->key.base,
+                  &prog_data->base, prog, shader, mem_ctx),
+     c(c),
+     prog_data(prog_data)
 {
 }
 
diff --git a/src/mesa/drivers/dri/i965/test_vec4_register_coalesce.cpp b/src/mesa/drivers/dri/i965/test_vec4_register_coalesce.cpp
index 8408e9f..6d2bbf8 100644
--- a/src/mesa/drivers/dri/i965/test_vec4_register_coalesce.cpp
+++ b/src/mesa/drivers/dri/i965/test_vec4_register_coalesce.cpp
@@ -38,7 +38,7 @@ public:
    struct intel_context *intel;
    struct gl_context *ctx;
    struct gl_shader_program *shader_prog;
-   struct brw_vs_compile *c;
+   struct brw_vertex_program *vp;
    vec4_visitor *v;
 };
 
@@ -47,9 +47,8 @@ class register_coalesce_vec4_visitor : public vec4_visitor
 {
 public:
    register_coalesce_vec4_visitor(struct brw_context *brw,
-                                  struct brw_vs_compile *c,
                                   struct gl_shader_program *prog)
-      : vec4_visitor(brw, c, NULL, prog, NULL, NULL)
+      : vec4_visitor(brw, NULL, NULL, NULL, NULL, prog, NULL, NULL)
    {
    }
 
@@ -89,14 +88,13 @@ void register_coalesce_test::SetUp()
    intel = &brw->intel;
    ctx = &intel->ctx;
 
-   c = ralloc(NULL, struct brw_vs_compile);
-   c->vp = ralloc(NULL, struct brw_vertex_program);
+   vp = ralloc(NULL, struct brw_vertex_program);
 
    shader_prog = ralloc(NULL, struct gl_shader_program);
 
-   v = new register_coalesce_vec4_visitor(brw, c, shader_prog);
+   v = new register_coalesce_vec4_visitor(brw, shader_prog);
 
-   _mesa_init_vertex_program(ctx, &c->vp->program, GL_VERTEX_SHADER, 0);
+   _mesa_init_vertex_program(ctx, &vp->program, GL_VERTEX_SHADER, 0);
 
    intel->gen = 4;
 }
-- 
1.8.2



More information about the mesa-dev mailing list