galahad: do map/unmap counting for resources
[mesa.git] / src / gallium / drivers / i965 / brw_wm_fp.c
index 57933afbbee4fb18ae745e262aebfad66b569cfc..f7ee55cc1c85b03b3a37276b0155a726fe978d2a 100644 (file)
@@ -31,7 +31,6 @@
                
 
 #include "pipe/p_shader_tokens.h"
-#include "pipe/p_error.h"
 
 #include "util/u_math.h"
 #include "util/u_memory.h"
 #include "tgsi/tgsi_util.h"
 
 #include "brw_wm.h"
-#include "brw_util.h"
 #include "brw_debug.h"
 
 
-#define X    0
-#define Y    1
-#define Z    2
-#define W    3
-#define GET_SWZ(swz, comp) (((swz) >> ((comp)*2)) & 0x3)
-
-
-static const char *wm_opcode_strings[] = {
-   "PIXELXY",
-   "DELTAXY",
-   "PIXELW",
-   "LINTERP",
-   "PINTERP",
-   "CINTERP",
-   "WPOSXY",
-   "FB_WRITE",
-   "FRONTFACING",
-};
-
 /***********************************************************************
  * Source regs
  */
@@ -100,10 +79,10 @@ static struct brw_fp_src src_swizzle( struct brw_fp_src reg, int x, int y, int z
 {
    unsigned swz = reg.swizzle;
 
-   reg.swizzle = ( GET_SWZ(swz, x) << 0 |
-                  GET_SWZ(swz, y) << 2 |
-                  GET_SWZ(swz, z) << 4 |
-                  GET_SWZ(swz, w) << 6 );
+   reg.swizzle = ( BRW_GET_SWZ(swz, x) << 0 |
+                  BRW_GET_SWZ(swz, y) << 2 |
+                  BRW_GET_SWZ(swz, z) << 4 |
+                  BRW_GET_SWZ(swz, w) << 6 );
 
    return reg;
 }
@@ -206,10 +185,10 @@ out:
       swizzle |= (swizzle & 0x3) << (j * 2);
 
    return src_swizzle( src_reg( TGSI_FILE_IMMEDIATE, i ),
-                      GET_SWZ(swizzle, X),
-                      GET_SWZ(swizzle, Y),
-                      GET_SWZ(swizzle, Z),
-                      GET_SWZ(swizzle, W) );
+                      BRW_GET_SWZ(swizzle, X),
+                      BRW_GET_SWZ(swizzle, Y),
+                      BRW_GET_SWZ(swizzle, Z),
+                      BRW_GET_SWZ(swizzle, W) );
 }
 
 
@@ -243,6 +222,7 @@ static struct brw_fp_dst dst_reg(GLuint file, GLuint idx)
    reg.index = idx;
    reg.writemask = BRW_WRITEMASK_XYZW;
    reg.indirect = 0;
+   reg.saturate = 0;
    return reg;
 }
 
@@ -299,18 +279,26 @@ static struct brw_fp_instruction *get_fp_inst(struct brw_wm_compile *c)
 static struct brw_fp_instruction * emit_tex_op(struct brw_wm_compile *c,
                                             GLuint op,
                                             struct brw_fp_dst dest,
-                                            GLuint tex_src_unit,
-                                            GLuint tex_src_target,
+                                            GLuint tex_unit,
+                                            GLuint target,
+                                            GLuint sampler,
                                             struct brw_fp_src src0,
                                             struct brw_fp_src src1,
                                             struct brw_fp_src src2 )
 {
    struct brw_fp_instruction *inst = get_fp_inst(c);
 
+   if (tex_unit || target)
+      assert(op == TGSI_OPCODE_TXP ||
+             op == TGSI_OPCODE_TXB ||
+             op == TGSI_OPCODE_TEX ||
+             op == WM_FB_WRITE);
+
    inst->opcode = op;
    inst->dst = dest;
-   inst->tex_unit = tex_src_unit;
-   inst->tex_target = tex_src_target;
+   inst->tex_unit = tex_unit;
+   inst->target = target;
+   inst->sampler = sampler;
    inst->src[0] = src0;
    inst->src[1] = src1;
    inst->src[2] = src2;
@@ -326,7 +314,7 @@ static INLINE void emit_op3(struct brw_wm_compile *c,
                            struct brw_fp_src src1,
                            struct brw_fp_src src2 )
 {
-   emit_tex_op(c, op, dest, 0, 0, src0, src1, src2);
+   emit_tex_op(c, op, dest, 0, 0, 0, src0, src1, src2);
 }
 
 
@@ -336,7 +324,7 @@ static INLINE void emit_op2(struct brw_wm_compile *c,
                            struct brw_fp_src src0,
                            struct brw_fp_src src1)
 {
-   emit_tex_op(c, op, dest, 0, 0, src0, src1, src_undef());
+   emit_tex_op(c, op, dest, 0, 0, 0, src0, src1, src_undef());
 }
 
 static INLINE void emit_op1(struct brw_wm_compile *c,
@@ -344,14 +332,14 @@ static INLINE void emit_op1(struct brw_wm_compile *c,
                            struct brw_fp_dst dest,
                            struct brw_fp_src src0)
 {
-   emit_tex_op(c, op, dest, 0, 0, src0, src_undef(), src_undef());
+   emit_tex_op(c, op, dest, 0, 0, 0, src0, src_undef(), src_undef());
 }
 
 static INLINE void emit_op0(struct brw_wm_compile *c,
                           GLuint op,
                           struct brw_fp_dst dest)
 {
-   emit_tex_op(c, op, dest, 0, 0, src_undef(), src_undef(), src_undef());
+   emit_tex_op(c, op, dest, 0, 0, 0, src_undef(), src_undef(), src_undef());
 }
 
 
@@ -687,9 +675,10 @@ static void precalc_tex( struct brw_wm_compile *c,
                         struct brw_fp_dst dst,
                         unsigned target,
                         unsigned unit,
-                        struct brw_fp_src src0 )
+                        struct brw_fp_src src0,
+                        struct brw_fp_src sampler )
 {
-   struct brw_fp_src coord = src_undef();
+   struct brw_fp_src coord;
    struct brw_fp_dst tmp = dst_undef();
 
    assert(unit < BRW_MAX_TEX_UNIT);
@@ -764,6 +753,7 @@ static void precalc_tex( struct brw_wm_compile *c,
                   dst_saturate(tmp, dst.saturate),
                   unit,
                   target,
+                  sampler.index,
                   coord,
                   src_undef(),
                   src_undef());
@@ -815,6 +805,7 @@ static void precalc_tex( struct brw_wm_compile *c,
                   dst,
                   unit,
                   target,
+                  sampler.index,
                   coord,
                   src_undef(),
                   src_undef());
@@ -849,8 +840,8 @@ static GLboolean projtex( struct brw_wm_compile *c,
       return GL_FALSE;  /* ut2004 gun rendering !?! */
    
    if (src.file == TGSI_FILE_INPUT && 
-       GET_SWZ(src.swizzle, W) == W &&
-       (c->key.proj_attrib_mask & (1 << src.index)) == 0)
+       BRW_GET_SWZ(src.swizzle, W) == W &&
+       c->fp->info.input_interpolate[src.index] != TGSI_INTERPOLATE_PERSPECTIVE)
       return GL_FALSE;
 
    return GL_TRUE;
@@ -864,7 +855,8 @@ static void precalc_txp( struct brw_wm_compile *c,
                         struct brw_fp_dst dst,
                         unsigned target,
                         unsigned unit,
-                        struct brw_fp_src src0 )
+                        struct brw_fp_src src0,
+                         struct brw_fp_src sampler )
 {
    if (projtex(c, target, src0)) {
       struct brw_fp_dst tmp = get_temp(c);
@@ -890,7 +882,8 @@ static void precalc_txp( struct brw_wm_compile *c,
                  dst,
                  target,
                  unit,
-                 src_reg_from_dst(tmp));
+                 src_reg_from_dst(tmp),
+                  sampler );
 
       release_temp(c, tmp);
    }
@@ -898,7 +891,7 @@ static void precalc_txp( struct brw_wm_compile *c,
    {
       /* dst = TEX src0
        */
-      precalc_tex(c, dst, target, unit, src0);
+      precalc_tex(c, dst, target, unit, src0, sampler);
    }
 }
 
@@ -919,8 +912,11 @@ find_output_by_semantic( struct brw_wm_compile *c,
         return src_reg( TGSI_FILE_OUTPUT, i );
 
    /* If not found, return some arbitrary immediate value:
+    *
+    * XXX: this is a good idea but immediates are up generating extra
+    * curbe entries atm, as they would have in the original driver.
     */
-   return src_imm1f(c, 1.0);
+   return src_reg( TGSI_FILE_OUTPUT, 0 ); /* src_imm1f(c, 1.0); */
 }
 
 
@@ -935,23 +931,18 @@ static void emit_fb_write( struct brw_wm_compile *c )
 
    for (i = 0 ; i < c->key.nr_cbufs; i++) {
       struct brw_fp_src outcolor;
-      unsigned target = 1<<i;
-
-      /* Set EOT flag on last inst:
-       */
-      if (i == c->key.nr_cbufs - 1)
-        target |= 1;
       
       outcolor = find_output_by_semantic(c, TGSI_SEMANTIC_COLOR, i);
 
-      /* Use emit_tex_op so that we can specify the inst->tex_target
+      /* Use emit_tex_op so that we can specify the inst->target
        * field, which is abused to contain the FB write target and the
        * EOT marker
        */
       emit_tex_op(c, WM_FB_WRITE,
                  dst_undef(),
-                 target,
-                 0,
+                 (i == c->key.nr_cbufs - 1), /* EOT */
+                 i,
+                  0,            /* no sampler */
                  outcolor,
                  payload_r0_depth,
                  outdepth);
@@ -965,15 +956,15 @@ static struct brw_fp_dst translate_dst( struct brw_wm_compile *c,
 {
    struct brw_fp_dst out;
 
-   out.file = dst->DstRegister.File;
-   out.index = dst->DstRegister.Index;
-   out.writemask = dst->DstRegister.WriteMask;
-   out.indirect = dst->DstRegister.Indirect;
+   out.file = dst->Register.File;
+   out.index = dst->Register.Index;
+   out.writemask = dst->Register.WriteMask;
+   out.indirect = dst->Register.Indirect;
    out.saturate = (saturate == TGSI_SAT_ZERO_ONE);
    
    if (out.indirect) {
-      assert(dst->DstRegisterInd.File == TGSI_FILE_ADDRESS);
-      assert(dst->DstRegisterInd.Index == 0);
+      assert(dst->Indirect.File == TGSI_FILE_ADDRESS);
+      assert(dst->Indirect.Index == 0);
    }
    
    return out;
@@ -985,14 +976,14 @@ static struct brw_fp_src translate_src( struct brw_wm_compile *c,
 {
    struct brw_fp_src out;
 
-   out.file = src->SrcRegister.File;
-   out.index = src->SrcRegister.Index;
-   out.indirect = src->SrcRegister.Indirect;
+   out.file = src->Register.File;
+   out.index = src->Register.Index;
+   out.indirect = src->Register.Indirect;
 
-   out.swizzle = ((src->SrcRegister.SwizzleX << 0) |
-                 (src->SrcRegister.SwizzleY << 2) |
-                 (src->SrcRegister.SwizzleZ << 4) |
-                 (src->SrcRegister.SwizzleW << 6));
+   out.swizzle = ((src->Register.SwizzleX << 0) |
+                 (src->Register.SwizzleY << 2) |
+                 (src->Register.SwizzleZ << 4) |
+                 (src->Register.SwizzleW << 6));
    
    switch (tgsi_util_get_full_src_register_sign_mode( src, 0 )) {
    case TGSI_UTIL_SIGN_CLEAR:
@@ -1018,8 +1009,8 @@ static struct brw_fp_src translate_src( struct brw_wm_compile *c,
    }
 
    if (out.indirect) {
-      assert(src->SrcRegisterInd.File == TGSI_FILE_ADDRESS);
-      assert(src->SrcRegisterInd.Index == 0);
+      assert(src->Indirect.File == TGSI_FILE_ADDRESS);
+      assert(src->Indirect.Index == 0);
    }
    
    return out;
@@ -1035,11 +1026,11 @@ static void emit_insn( struct brw_wm_compile *c,
    struct brw_fp_src src[3];
    int i;
 
-   dst = translate_dst( c, &inst->FullDstRegisters[0],
+   dst = translate_dst( c, &inst->Dst[0],
                        inst->Instruction.Saturate );
 
    for (i = 0; i < inst->Instruction.NumSrcRegs; i++)
-      src[i] = translate_src( c, &inst->FullSrcRegisters[0] );
+      src[i] = translate_src( c, &inst->Src[i] );
    
    switch (opcode) {
    case TGSI_OPCODE_ABS:
@@ -1071,25 +1062,28 @@ static void emit_insn( struct brw_wm_compile *c,
 
    case TGSI_OPCODE_TEX:
       precalc_tex(c, dst,
-                 inst->InstructionExtTexture.Texture,
-                 src[0].file,  /* sampler unit */
-                 src[1] );
+                 inst->Texture.Texture,
+                 src[1].index, /* use sampler unit for tex idx */
+                 src[0],       /* coord */
+                  src[1]);      /* sampler */
       break;
 
    case TGSI_OPCODE_TXP:
       precalc_txp(c, dst,
-                 inst->InstructionExtTexture.Texture,
-                 src[0].file,  /* sampler unit */
-                 src[1] );
+                 inst->Texture.Texture,
+                 src[1].index, /* use sampler unit for tex idx */
+                 src[0],       /* coord */
+                  src[1]);      /* sampler */
       break;
 
    case TGSI_OPCODE_TXB:
       /* XXX: TXB not done
        */
       precalc_tex(c, dst,
-                 inst->InstructionExtTexture.Texture,
-                 src[0].file,  /* sampler unit */
-                 src[1] );
+                 inst->Texture.Texture,
+                 src[1].index, /* use sampler unit for tex idx*/
+                 src[0],
+                  src[1]);
       break;
 
    case TGSI_OPCODE_XPD: 
@@ -1174,14 +1168,14 @@ int brw_wm_pass_fp( struct brw_wm_compile *c )
             unsigned first, last, mask;
             unsigned attrib;
 
-            first = decl->DeclarationRange.First;
-            last = decl->DeclarationRange.Last;
+            first = decl->Range.First;
+            last = decl->Range.Last;
             mask = decl->Declaration.UsageMask;
 
             for (attrib = first; attrib <= last; attrib++) {
               emit_interp(c, 
                           attrib, 
-                          decl->Semantic.SemanticName,
+                          decl->Semantic.Name,
                           decl->Declaration.Interpolate );
             }
          }
@@ -1220,8 +1214,7 @@ int brw_wm_pass_fp( struct brw_wm_compile *c )
    }
 
    if (BRW_DEBUG & DEBUG_WM) {
-      debug_printf("pass_fp:\n");
-      //brw_print_program( c->fp_brw_program );
+      brw_wm_print_fp_program( c, "pass_fp" );
       debug_printf("\n");
    }