[Mesa-dev] [PATCH 06/13] i965/fs: don't use ir->coordinate in emit_texture_*

Connor Abbott cwabbott0 at gmail.com
Mon Aug 4 14:28:10 PDT 2014


Signed-off-by: Connor Abbott <connor.abbott at intel.com>
---
 src/mesa/drivers/dri/i965/brw_fs.h           | 15 ++++---
 src/mesa/drivers/dri/i965/brw_fs_fp.cpp      |  9 ++--
 src/mesa/drivers/dri/i965/brw_fs_visitor.cpp | 67 +++++++++++++++-------------
 3 files changed, 49 insertions(+), 42 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
index 21b7f23..3f45f35 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.h
+++ b/src/mesa/drivers/dri/i965/brw_fs.h
@@ -373,14 +373,17 @@ public:
    fs_reg rescale_texcoord(fs_reg coordinate, const glsl_type *coord_type,
                            bool is_rect, int sampler, int texunit);
    fs_inst *emit_texture_gen4(ir_texture *ir, fs_reg dst, fs_reg coordinate,
-                              fs_reg shadow_comp, fs_reg lod, fs_reg lod2);
+                              int coord_components, fs_reg shadow_comp,
+                              fs_reg lod, fs_reg lod2);
    fs_inst *emit_texture_gen5(ir_texture *ir, fs_reg dst, fs_reg coordinate,
-                              fs_reg shadow_comp, fs_reg lod, fs_reg lod2,
-                              fs_reg sample_index, bool has_offset);
+                              int coord_components, fs_reg shadow_comp,
+                              fs_reg lod, fs_reg lod2, fs_reg sample_index,
+                              bool has_offset);
    fs_inst *emit_texture_gen7(ir_texture *ir, fs_reg dst, fs_reg coordinate,
-                              fs_reg shadow_comp, fs_reg lod, fs_reg lod2,
-                              fs_reg sample_index, bool has_offset,
-                              fs_reg offset, fs_reg mcs, int sampler);
+                              int coord_components, fs_reg shadow_comp,
+                              fs_reg lod, fs_reg lod2, fs_reg sample_index,
+                              bool has_offset, fs_reg offset, fs_reg mcs,
+                              int sampler);
    fs_reg emit_mcs_fetch(fs_reg coordinate, int components, int sampler);
    void emit_gen6_gather_wa(uint8_t wa, fs_reg dst);
    fs_reg fix_math_operand(fs_reg src);
diff --git a/src/mesa/drivers/dri/i965/brw_fs_fp.cpp b/src/mesa/drivers/dri/i965/brw_fs_fp.cpp
index a8f0133..c9215f4 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_fp.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_fp.cpp
@@ -478,8 +478,7 @@ fs_visitor::emit_fragment_program_code()
             unreachable("not reached");
          }
 
-         ir_constant_data junk_data;
-         ir->coordinate = new(mem_ctx) ir_constant(coordinate_type, &junk_data);
+         int coord_components = coordinate_type->vector_elements;
 
          if (fpi->TexShadow)
             shadow_c = offset(coordinate, 2);
@@ -490,11 +489,11 @@ fs_visitor::emit_fragment_program_code()
 
          fs_inst *inst;
          if (brw->gen >= 7) {
-            inst = emit_texture_gen7(ir, dst, coordinate, shadow_c, lod, dpdy, sample_index, false, offset_reg, fs_reg(0u), fpi->TexSrcUnit);
+            inst = emit_texture_gen7(ir, dst, coordinate, coord_components, shadow_c, lod, dpdy, sample_index, false, offset_reg, fs_reg(0u), fpi->TexSrcUnit);
          } else if (brw->gen >= 5) {
-            inst = emit_texture_gen5(ir, dst, coordinate, shadow_c, lod, dpdy, sample_index, false);
+            inst = emit_texture_gen5(ir, dst, coordinate, coord_components, shadow_c, lod, dpdy, sample_index, false);
          } else {
-            inst = emit_texture_gen4(ir, dst, coordinate, shadow_c, lod, dpdy);
+            inst = emit_texture_gen4(ir, dst, coordinate, coord_components, shadow_c, lod, dpdy);
          }
 
          inst->sampler = fpi->TexSrcUnit;
diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
index 876847d..107d0eb 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -1095,7 +1095,8 @@ fs_visitor::visit(ir_assignment *ir)
 
 fs_inst *
 fs_visitor::emit_texture_gen4(ir_texture *ir, fs_reg dst, fs_reg coordinate,
-                              fs_reg shadow_c, fs_reg lod, fs_reg dPdy)
+                              int coord_components, fs_reg shadow_c,
+                              fs_reg lod, fs_reg dPdy)
 {
    int mlen;
    int base_mrf = 1;
@@ -1106,7 +1107,7 @@ fs_visitor::emit_texture_gen4(ir_texture *ir, fs_reg dst, fs_reg coordinate,
    mlen = 1;
 
    if (shadow_c.file != BAD_FILE) {
-      for (int i = 0; i < ir->coordinate->type->vector_elements; i++) {
+      for (int i = 0; i < coord_components; i++) {
          emit(MOV(fs_reg(MRF, base_mrf + mlen + i), coordinate));
          coordinate.reg_offset++;
       }
@@ -1114,7 +1115,7 @@ fs_visitor::emit_texture_gen4(ir_texture *ir, fs_reg dst, fs_reg coordinate,
       /* gen4's SIMD8 sampler always has the slots for u,v,r present.
        * the unused slots must be zeroed.
        */
-      for (int i = ir->coordinate->type->vector_elements; i < 3; i++) {
+      for (int i = coord_components; i < 3; i++) {
          emit(MOV(fs_reg(MRF, base_mrf + mlen + i), fs_reg(0.0f)));
       }
       mlen += 3;
@@ -1135,12 +1136,12 @@ fs_visitor::emit_texture_gen4(ir_texture *ir, fs_reg dst, fs_reg coordinate,
       emit(MOV(fs_reg(MRF, base_mrf + mlen), shadow_c));
       mlen++;
    } else if (ir->op == ir_tex) {
-      for (int i = 0; i < ir->coordinate->type->vector_elements; i++) {
+      for (int i = 0; i < coord_components; i++) {
          emit(MOV(fs_reg(MRF, base_mrf + mlen + i), coordinate));
          coordinate.reg_offset++;
       }
       /* zero the others. */
-      for (int i = ir->coordinate->type->vector_elements; i<3; i++) {
+      for (int i = coord_components; i<3; i++) {
          emit(MOV(fs_reg(MRF, base_mrf + mlen + i), fs_reg(0.0f)));
       }
       /* gen4's SIMD8 sampler always has the slots for u,v,r present. */
@@ -1148,12 +1149,12 @@ fs_visitor::emit_texture_gen4(ir_texture *ir, fs_reg dst, fs_reg coordinate,
    } else if (ir->op == ir_txd) {
       fs_reg &dPdx = lod;
 
-      for (int i = 0; i < ir->coordinate->type->vector_elements; i++) {
+      for (int i = 0; i < coord_components; i++) {
          emit(MOV(fs_reg(MRF, base_mrf + mlen + i), coordinate));
          coordinate.reg_offset++;
       }
       /* the slots for u and v are always present, but r is optional */
-      mlen += MAX2(ir->coordinate->type->vector_elements, 2);
+      mlen += MAX2(coord_components, 2);
 
       /*  P   = u, v, r
        * dPdx = dudx, dvdx, drdx
@@ -1192,7 +1193,7 @@ fs_visitor::emit_texture_gen4(ir_texture *ir, fs_reg dst, fs_reg coordinate,
       simd16 = true;
       assert(ir->op == ir_txb || ir->op == ir_txl || ir->op == ir_txf);
 
-      for (int i = 0; i < ir->coordinate->type->vector_elements; i++) {
+      for (int i = 0; i < coord_components; i++) {
          emit(MOV(fs_reg(MRF, base_mrf + mlen + i * 2, coordinate.type),
                   coordinate));
          coordinate.reg_offset++;
@@ -1201,7 +1202,7 @@ fs_visitor::emit_texture_gen4(ir_texture *ir, fs_reg dst, fs_reg coordinate,
       /* Initialize the rest of u/v/r with 0.0.  Empirically, this seems to
        * be necessary for TXF (ld), but seems wise to do for all messages.
        */
-      for (int i = ir->coordinate->type->vector_elements; i < 3; i++) {
+      for (int i = coord_components; i < 3; i++) {
          emit(MOV(fs_reg(MRF, base_mrf + mlen + i * 2), fs_reg(0.0f)));
       }
 
@@ -1276,15 +1277,14 @@ fs_visitor::emit_texture_gen4(ir_texture *ir, fs_reg dst, fs_reg coordinate,
  */
 fs_inst *
 fs_visitor::emit_texture_gen5(ir_texture *ir, fs_reg dst, fs_reg coordinate,
-                              fs_reg shadow_c, fs_reg lod, fs_reg lod2,
-                              fs_reg sample_index, bool has_offset)
+                              int coord_components, fs_reg shadow_c,
+                              fs_reg lod, fs_reg lod2, fs_reg sample_index,
+                              bool has_offset)
 {
    int mlen = 0;
    int base_mrf = 2;
    int reg_width = dispatch_width / 8;
    bool header_present = false;
-   const int vector_elements =
-      ir->coordinate ? ir->coordinate->type->vector_elements : 0;
 
    if (has_offset) {
       /* The offsets set up by the ir_texture visitor are in the
@@ -1295,12 +1295,12 @@ fs_visitor::emit_texture_gen5(ir_texture *ir, fs_reg dst, fs_reg coordinate,
       base_mrf--;
    }
 
-   for (int i = 0; i < vector_elements; i++) {
+   for (int i = 0; i < coord_components; i++) {
       emit(MOV(fs_reg(MRF, base_mrf + mlen + i * reg_width, coordinate.type),
                coordinate));
       coordinate.reg_offset++;
    }
-   mlen += vector_elements * reg_width;
+   mlen += coord_components * reg_width;
 
    if (shadow_c.file != BAD_FILE) {
       mlen = MAX2(mlen, header_present + 4 * reg_width);
@@ -1403,9 +1403,10 @@ fs_visitor::emit_texture_gen5(ir_texture *ir, fs_reg dst, fs_reg coordinate,
 
 fs_inst *
 fs_visitor::emit_texture_gen7(ir_texture *ir, fs_reg dst, fs_reg coordinate,
-                              fs_reg shadow_c, fs_reg lod, fs_reg lod2,
-                              fs_reg sample_index, bool has_offset,
-                              fs_reg offset, fs_reg mcs, int sampler)
+                              int coord_components, fs_reg shadow_c,
+                              fs_reg lod, fs_reg lod2, fs_reg sample_index,
+                              bool has_offset, fs_reg offset, fs_reg mcs,
+                              int sampler)
 {
    int reg_width = dispatch_width / 8;
    bool header_present = false;
@@ -1459,7 +1460,7 @@ fs_visitor::emit_texture_gen7(ir_texture *ir, fs_reg dst, fs_reg coordinate,
       /* Load dPdx and the coordinate together:
        * [hdr], [ref], x, dPdx.x, dPdy.x, y, dPdx.y, dPdy.y, z, dPdx.z, dPdy.z
        */
-      for (int i = 0; i < ir->coordinate->type->vector_elements; i++) {
+      for (int i = 0; i < coord_components; i++) {
          emit(MOV(sources[length], coordinate));
          coordinate.reg_offset++;
          length++;
@@ -1498,7 +1499,7 @@ fs_visitor::emit_texture_gen7(ir_texture *ir, fs_reg dst, fs_reg coordinate,
       emit(MOV(retype(sources[length], BRW_REGISTER_TYPE_D), lod));
       length++;
 
-      for (int i = 1; i < ir->coordinate->type->vector_elements; i++) {
+      for (int i = 1; i < coord_components; i++) {
          emit(MOV(retype(sources[length], BRW_REGISTER_TYPE_D), coordinate));
          coordinate.reg_offset++;
          length++;
@@ -1517,7 +1518,7 @@ fs_visitor::emit_texture_gen7(ir_texture *ir, fs_reg dst, fs_reg coordinate,
       /* there is no offsetting for this message; just copy in the integer
        * texture coordinates
        */
-      for (int i = 0; i < ir->coordinate->type->vector_elements; i++) {
+      for (int i = 0; i < coord_components; i++) {
          emit(MOV(retype(sources[length], BRW_REGISTER_TYPE_D), coordinate));
          coordinate.reg_offset++;
          length++;
@@ -1543,7 +1544,7 @@ fs_visitor::emit_texture_gen7(ir_texture *ir, fs_reg dst, fs_reg coordinate,
             length++;
          }
 
-         if (ir->coordinate->type->vector_elements == 3) { /* r if present */
+         if (coord_components == 3) { /* r if present */
             emit(MOV(sources[length], coordinate));
             coordinate.reg_offset++;
             length++;
@@ -1555,8 +1556,8 @@ fs_visitor::emit_texture_gen7(ir_texture *ir, fs_reg dst, fs_reg coordinate,
    }
 
    /* Set up the coordinate (except for cases where it was done above) */
-   if (ir->coordinate && !coordinate_done) {
-      for (int i = 0; i < ir->coordinate->type->vector_elements; i++) {
+   if (!coordinate_done) {
+      for (int i = 0; i < coord_components; i++) {
          emit(MOV(sources[length], coordinate));
          coordinate.reg_offset++;
          length++;
@@ -1803,6 +1804,9 @@ fs_visitor::visit(ir_texture *ir)
                                     sampler, texunit);
    }
 
+   int coord_components =
+      ir->coordinate ? ir->coordinate->type->vector_elements : 0;
+
    fs_reg shadow_comparitor;
    if (ir->shadow_comparitor) {
       ir->shadow_comparitor->accept(this);
@@ -1860,15 +1864,16 @@ fs_visitor::visit(ir_texture *ir)
    }
 
    if (brw->gen >= 7) {
-      inst = emit_texture_gen7(ir, dst, coordinate, shadow_comparitor,
-                               lod, lod2, sample_index, has_offset, offset,
-                               mcs, sampler);
+      inst = emit_texture_gen7(ir, dst, coordinate, coord_components,
+                               shadow_comparitor, lod, lod2, sample_index,
+                               has_offset, offset, mcs, sampler);
    } else if (brw->gen >= 5) {
-      inst = emit_texture_gen5(ir, dst, coordinate, shadow_comparitor,
-                               lod, lod2, sample_index, has_offset);
+      inst = emit_texture_gen5(ir, dst, coordinate, coord_components,
+                               shadow_comparitor, lod, lod2, sample_index,
+                               has_offset);
    } else {
-      inst = emit_texture_gen4(ir, dst, coordinate, shadow_comparitor,
-                               lod, lod2);
+      inst = emit_texture_gen4(ir, dst, coordinate, coord_components,
+                               shadow_comparitor, lod, lod2);
    }
 
    if (ir->offset != NULL && ir->op != ir_txf)
-- 
1.9.3



More information about the mesa-dev mailing list