i965/fs: Don't use ir->lod_info.grad.dPd<x,y> in emit_texture_*.
authorConnor Abbott <connor.abbott@intel.com>
Fri, 1 Aug 2014 23:24:44 +0000 (16:24 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 16 Oct 2014 00:05:00 +0000 (17:05 -0700)
This drops a dependency on ir_texture objects.

v2 (Ken): Rename lod_components to grad_components, as it only has a
          meaningful value for ir_txd.  We could set it to 1 for TXL,
          but there's no real need.

Signed-off-by: Connor Abbott <connor.abbott@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
src/mesa/drivers/dri/i965/brw_fs.h
src/mesa/drivers/dri/i965/brw_fs_fp.cpp
src/mesa/drivers/dri/i965/brw_fs_visitor.cpp

index 961148721c05bd4129c78cc59cacae7fcdd6531f..54410313e9f00ac039282be32ade88aaa74a37c1 100644 (file)
@@ -472,16 +472,19 @@ public:
                            bool is_rect, uint32_t sampler, int texunit);
    fs_inst *emit_texture_gen4(ir_texture *ir, fs_reg dst,
                               fs_reg coordinate, int coord_components,
-                              fs_reg shadow_comp, fs_reg lod, fs_reg lod2,
+                              fs_reg shadow_comp,
+                              fs_reg lod, fs_reg lod2, int grad_components,
                               uint32_t sampler);
    fs_inst *emit_texture_gen5(ir_texture *ir, fs_reg dst,
                               fs_reg coordinate, int coord_components,
-                              fs_reg shadow_comp, fs_reg lod, fs_reg lod2,
+                              fs_reg shadow_comp,
+                              fs_reg lod, fs_reg lod2, int grad_components,
                               fs_reg sample_index, uint32_t sampler,
                               bool has_offset);
    fs_inst *emit_texture_gen7(ir_texture *ir, fs_reg dst,
                               fs_reg coordinate, int coord_components,
-                              fs_reg shadow_comp, fs_reg lod, fs_reg lod2,
+                              fs_reg shadow_comp,
+                              fs_reg lod, fs_reg lod2, int grad_components,
                               fs_reg sample_index, fs_reg mcs, fs_reg sampler,
                               fs_reg offset_value);
    fs_reg emit_mcs_fetch(fs_reg coordinate, int components, fs_reg sampler);
index 27bc928fec376d55110055e6ef81720b22d92fc3..a77769b2086418bf8b7c5a164d838c7a70002cfd 100644 (file)
@@ -487,11 +487,11 @@ fs_visitor::emit_fragment_program_code()
 
          fs_inst *inst;
          if (brw->gen >= 7) {
-            inst = emit_texture_gen7(ir, dst, coordinate, coord_components, shadow_c, lod, dpdy, sample_index, fs_reg(0u), fs_reg(fpi->TexSrcUnit), texel_offset);
+            inst = emit_texture_gen7(ir, dst, coordinate, coord_components, shadow_c, lod, dpdy, 0, sample_index, fs_reg(0u), fs_reg(fpi->TexSrcUnit), texel_offset);
          } else if (brw->gen >= 5) {
-            inst = emit_texture_gen5(ir, dst, coordinate, coord_components, shadow_c, lod, dpdy, sample_index, fpi->TexSrcUnit, false);
+            inst = emit_texture_gen5(ir, dst, coordinate, coord_components, shadow_c, lod, dpdy, 0, sample_index, fpi->TexSrcUnit, false);
          } else {
-            inst = emit_texture_gen4(ir, dst, coordinate, coord_components, shadow_c, lod, dpdy, fpi->TexSrcUnit);
+            inst = emit_texture_gen4(ir, dst, coordinate, coord_components, shadow_c, lod, dpdy, 0, fpi->TexSrcUnit);
          }
 
          inst->shadow_compare = fpi->TexShadow;
index 4580527510cd6cdbcda0e1c96c365cade9a4f54e..3096e3fd8d6a1106ef987321c3be68b3f0823c4f 100644 (file)
@@ -1168,7 +1168,8 @@ fs_visitor::visit(ir_assignment *ir)
 fs_inst *
 fs_visitor::emit_texture_gen4(ir_texture *ir, fs_reg dst,
                               fs_reg coordinate, int coord_components,
-                              fs_reg shadow_c, fs_reg lod, fs_reg dPdy,
+                              fs_reg shadow_c,
+                              fs_reg lod, fs_reg dPdy, int grad_components,
                               uint32_t sampler)
 {
    int mlen;
@@ -1243,17 +1244,17 @@ fs_visitor::emit_texture_gen4(ir_texture *ir, fs_reg dst,
        *        dPdx.x dPdx.y dPdx.z dPdy.x dPdy.y dPdy.z
        *        m5     m6     m7     m8     m9     m10
        */
-      for (int i = 0; i < ir->lod_info.grad.dPdx->type->vector_elements; i++) {
+      for (int i = 0; i < grad_components; i++) {
         emit(MOV(fs_reg(MRF, base_mrf + mlen), dPdx));
         dPdx = offset(dPdx, 1);
       }
-      mlen += MAX2(ir->lod_info.grad.dPdx->type->vector_elements, 2);
+      mlen += MAX2(grad_components, 2);
 
-      for (int i = 0; i < ir->lod_info.grad.dPdy->type->vector_elements; i++) {
+      for (int i = 0; i < grad_components; i++) {
         emit(MOV(fs_reg(MRF, base_mrf + mlen), dPdy));
         dPdy = offset(dPdy, 1);
       }
-      mlen += MAX2(ir->lod_info.grad.dPdy->type->vector_elements, 2);
+      mlen += MAX2(grad_components, 2);
    } else if (ir->op == ir_txs) {
       /* There's no SIMD8 resinfo message on Gen4.  Use SIMD16 instead. */
       simd16 = true;
@@ -1342,7 +1343,8 @@ fs_visitor::emit_texture_gen4(ir_texture *ir, fs_reg dst,
 fs_inst *
 fs_visitor::emit_texture_gen5(ir_texture *ir, fs_reg dst,
                               fs_reg coordinate, int vector_elements,
-                              fs_reg shadow_c, fs_reg lod, fs_reg lod2,
+                              fs_reg shadow_c,
+                              fs_reg lod, fs_reg lod2, int grad_components,
                               fs_reg sample_index, uint32_t sampler,
                               bool has_offset)
 {
@@ -1402,7 +1404,7 @@ fs_visitor::emit_texture_gen5(ir_texture *ir, fs_reg dst,
        * - dPdx.x dPdy.x dPdx.y dPdy.y dPdx.z dPdy.z
        */
       msg_end = msg_lod;
-      for (int i = 0; i < ir->lod_info.grad.dPdx->type->vector_elements; i++) {
+      for (int i = 0; i < grad_components; i++) {
          emit(MOV(msg_end, lod));
          lod = offset(lod, 1);
          msg_end = offset(msg_end, 1);
@@ -1482,7 +1484,8 @@ is_high_sampler(struct brw_context *brw, fs_reg sampler)
 fs_inst *
 fs_visitor::emit_texture_gen7(ir_texture *ir, fs_reg dst,
                               fs_reg coordinate, int coord_components,
-                              fs_reg shadow_c, fs_reg lod, fs_reg lod2,
+                              fs_reg shadow_c,
+                              fs_reg lod, fs_reg lod2, int grad_components,
                               fs_reg sample_index, fs_reg mcs, fs_reg sampler,
                               fs_reg offset_value)
 {
@@ -1548,7 +1551,7 @@ fs_visitor::emit_texture_gen7(ir_texture *ir, fs_reg dst,
          /* For cube map array, the coordinate is (u,v,r,ai) but there are
           * only derivatives for (u, v, r).
           */
-         if (i < ir->lod_info.grad.dPdx->type->vector_elements) {
+         if (i < grad_components) {
             emit(MOV(sources[length], lod));
             lod = offset(lod, 1);
             length++;
@@ -1957,6 +1960,7 @@ fs_visitor::visit(ir_texture *ir)
    }
 
    fs_reg lod, lod2, sample_index, mcs;
+   int grad_components = 0;
    switch (ir->op) {
    case ir_tex:
    case ir_lod:
@@ -1973,6 +1977,8 @@ fs_visitor::visit(ir_texture *ir)
 
       ir->lod_info.grad.dPdy->accept(this);
       lod2 = this->result;
+
+      grad_components = ir->lod_info.grad.dPdx->type->vector_elements;
       break;
    case ir_txf:
    case ir_txl:
@@ -2002,16 +2008,20 @@ fs_visitor::visit(ir_texture *ir)
    if (brw->gen >= 7) {
       inst = emit_texture_gen7(ir, dst, coordinate, coord_components,
                                shadow_comparitor,
-                               lod, lod2, sample_index, mcs, sampler_reg,
+                               lod, lod2, grad_components,
+                               sample_index, mcs, sampler_reg,
                                offset_value);
    } else if (brw->gen >= 5) {
       inst = emit_texture_gen5(ir, dst, coordinate, coord_components,
                                shadow_comparitor,
-                               lod, lod2, sample_index, sampler,
+                               lod, lod2, grad_components,
+                               sample_index, sampler,
                                ir->offset != NULL);
    } else {
       inst = emit_texture_gen4(ir, dst, coordinate, coord_components,
-                               shadow_comparitor, lod, lod2, sampler);
+                               shadow_comparitor,
+                               lod, lod2, grad_components,
+                               sampler);
    }
 
    if (offset_value.file == IMM)