galahad: do map/unmap counting for resources
[mesa.git] / src / gallium / drivers / i965 / brw_wm_debug.c
index c6659646f2cd8b184a5b2104d72edc6f4317979d..1b2aa93befc7a5424c63d93a15899083729f141a 100644 (file)
   * Authors:
   *   Keith Whitwell <keith@tungstengraphics.com>
   */
-               
+
+#include "tgsi/tgsi_info.h"
 
 #include "brw_context.h"
 #include "brw_wm.h"
 
+static void print_writemask( unsigned writemask )
+{
+   if (writemask != BRW_WRITEMASK_XYZW)
+      debug_printf(".%s%s%s%s", 
+                  (writemask & BRW_WRITEMASK_X) ? "x" : "",
+                  (writemask & BRW_WRITEMASK_Y) ? "y" : "",
+                  (writemask & BRW_WRITEMASK_Z) ? "z" : "",
+                  (writemask & BRW_WRITEMASK_W) ? "w" : "");
+}
+
+static void print_swizzle( unsigned swizzle )
+{
+   char *swz = "xyzw";
+   if (swizzle != BRW_SWIZZLE_XYZW)
+      debug_printf(".%c%c%c%c", 
+                  swz[BRW_GET_SWZ(swizzle, X)],
+                  swz[BRW_GET_SWZ(swizzle, Y)],
+                  swz[BRW_GET_SWZ(swizzle, Z)],
+                  swz[BRW_GET_SWZ(swizzle, W)]);
+}
+
+static void print_opcode( unsigned opcode )
+{
+   switch (opcode) {
+   case WM_PIXELXY:
+      debug_printf("PIXELXY");
+      break;
+   case WM_DELTAXY:
+      debug_printf("DELTAXY");
+      break;
+   case WM_PIXELW:
+      debug_printf("PIXELW");
+      break;
+   case WM_WPOSXY:
+      debug_printf("WPOSXY");
+      break;
+   case WM_PINTERP:
+      debug_printf("PINTERP");
+      break;
+   case WM_LINTERP:
+      debug_printf("LINTERP");
+      break;
+   case WM_CINTERP:
+      debug_printf("CINTERP");
+      break;
+   case WM_FB_WRITE:
+      debug_printf("FB_WRITE");
+      break;
+   case WM_FRONTFACING:
+      debug_printf("FRONTFACING");
+      break;
+   default:
+      debug_printf("%s", tgsi_get_opcode_info(opcode)->mnemonic);
+      break;
+   }
+}
 
 void brw_wm_print_value( struct brw_wm_compile *c,
                       struct brw_wm_value *value )
@@ -41,21 +98,21 @@ void brw_wm_print_value( struct brw_wm_compile *c,
    if (c->state >= PASS2_DONE) 
       brw_print_reg(value->hw_reg);
    else if( value == &c->undef_value )
-      _mesa_printf("undef");
+      debug_printf("undef");
    else if( value - c->vreg >= 0 &&
            value - c->vreg < BRW_WM_MAX_VREG)
-      _mesa_printf("r%d", value - c->vreg);
+      debug_printf("r%ld", (long) (value - c->vreg));
    else if (value - c->creg >= 0 &&
            value - c->creg < BRW_WM_MAX_PARAM)
-      _mesa_printf("c%d", value - c->creg);
+      debug_printf("c%ld", (long) (value - c->creg));
    else if (value - c->payload.input_interp >= 0 &&
-           value - c->payload.input_interp < FRAG_ATTRIB_MAX)
-      _mesa_printf("i%d", value - c->payload.input_interp);
+           value - c->payload.input_interp < PIPE_MAX_SHADER_INPUTS)
+      debug_printf("i%ld", (long) (value - c->payload.input_interp));
    else if (value - c->payload.depth >= 0 &&
-           value - c->payload.depth < FRAG_ATTRIB_MAX)
-      _mesa_printf("d%d", value - c->payload.depth);
+           value - c->payload.depth < PIPE_MAX_SHADER_INPUTS)
+      debug_printf("d%ld", (long) (value - c->payload.depth));
    else 
-      _mesa_printf("?");
+      debug_printf("?");
 }
 
 void brw_wm_print_ref( struct brw_wm_compile *c,
@@ -64,16 +121,16 @@ void brw_wm_print_ref( struct brw_wm_compile *c,
    struct brw_reg hw_reg = ref->hw_reg;
 
    if (ref->unspill_reg)
-      _mesa_printf("UNSPILL(%x)/", ref->value->spill_slot);
+      debug_printf("UNSPILL(%x)/", ref->value->spill_slot);
 
    if (c->state >= PASS2_DONE)
       brw_print_reg(ref->hw_reg);
    else {
-      _mesa_printf("%s", hw_reg.negate ? "-" : "");
-      _mesa_printf("%s", hw_reg.abs ? "abs/" : "");
+      debug_printf("%s", hw_reg.negate ? "-" : "");
+      debug_printf("%s", hw_reg.abs ? "abs/" : "");
       brw_wm_print_value(c, ref->value);
       if ((hw_reg.nr&1) || hw_reg.subnr) {
-        _mesa_printf("->%d.%d", (hw_reg.nr&1), hw_reg.subnr);
+        debug_printf("->%d.%d", (hw_reg.nr&1), hw_reg.subnr);
       }
    }
 }
@@ -84,81 +141,45 @@ void brw_wm_print_insn( struct brw_wm_compile *c,
    GLuint i, arg;
    GLuint nr_args = brw_wm_nr_args(inst->opcode);
 
-   _mesa_printf("[");
+   debug_printf("[");
    for (i = 0; i < 4; i++) {
       if (inst->dst[i]) {
         brw_wm_print_value(c, inst->dst[i]);
         if (inst->dst[i]->spill_slot)
-           _mesa_printf("/SPILL(%x)",inst->dst[i]->spill_slot);
+           debug_printf("/SPILL(%x)",inst->dst[i]->spill_slot);
       }
       else
-        _mesa_printf("#");
+        debug_printf("#");
       if (i < 3)      
-        _mesa_printf(",");
+        debug_printf(",");
    }
-   _mesa_printf("]");
-
-   if (inst->writemask != BRW_WRITEMASK_XYZW)
-      _mesa_printf(".%s%s%s%s", 
-                  GET_BIT(inst->writemask, 0) ? "x" : "",
-                  GET_BIT(inst->writemask, 1) ? "y" : "",
-                  GET_BIT(inst->writemask, 2) ? "z" : "",
-                  GET_BIT(inst->writemask, 3) ? "w" : "");
-
-   switch (inst->opcode) {
-   case WM_PIXELXY:
-      _mesa_printf(" = PIXELXY");
-      break;
-   case WM_DELTAXY:
-      _mesa_printf(" = DELTAXY");
-      break;
-   case WM_PIXELW:
-      _mesa_printf(" = PIXELW");
-      break;
-   case WM_WPOSXY:
-      _mesa_printf(" = WPOSXY");
-      break;
-   case WM_PINTERP:
-      _mesa_printf(" = PINTERP");
-      break;
-   case WM_LINTERP:
-      _mesa_printf(" = LINTERP");
-      break;
-   case WM_CINTERP:
-      _mesa_printf(" = CINTERP");
-      break;
-   case WM_FB_WRITE:
-      _mesa_printf(" = FB_WRITE");
-      break;
-   case WM_FRONTFACING:
-      _mesa_printf(" = FRONTFACING");
-      break;
-   default:
-      _mesa_printf(" = %s", _mesa_opcode_string(inst->opcode));
-      break;
-   }
-
+   debug_printf("]");
+   print_writemask(inst->writemask);
+   
+   debug_printf(" = ");
+   print_opcode(inst->opcode);
+  
    if (inst->saturate)
-      _mesa_printf("_SAT");
+      debug_printf("_SAT");
 
    for (arg = 0; arg < nr_args; arg++) {
 
-      _mesa_printf(" [");
+      debug_printf(" [");
 
       for (i = 0; i < 4; i++) {
         if (inst->src[arg][i]) {
            brw_wm_print_ref(c, inst->src[arg][i]);
         }
         else
-           _mesa_printf("%%");
+           debug_printf("%%");
 
         if (i < 3) 
-           _mesa_printf(",");
+           debug_printf(",");
         else
-           _mesa_printf("]");
+           debug_printf("]");
       }
    }
-   _mesa_printf("\n");
+   debug_printf("\n");
 }
 
 void brw_wm_print_program( struct brw_wm_compile *c,
@@ -166,9 +187,71 @@ void brw_wm_print_program( struct brw_wm_compile *c,
 {
    GLuint insn;
 
-   _mesa_printf("%s:\n", stage);
+   debug_printf("%s:\n", stage);
    for (insn = 0; insn < c->nr_insns; insn++)
       brw_wm_print_insn(c, &c->instruction[insn]);
-   _mesa_printf("\n");
+   debug_printf("\n");
+}
+
+static const char *file_strings[TGSI_FILE_COUNT+1] = {
+   "NULL",
+   "CONST",
+   "IN",
+   "OUT",
+   "TEMP",
+   "SAMPLER",
+   "ADDR",
+   "IMM",
+   "PRED",
+   "SV",
+   "PAYLOAD"
+};
+
+static void brw_wm_print_fp_insn( struct brw_wm_compile *c,
+                                  struct brw_fp_instruction *inst )
+{
+   GLuint i;
+   GLuint nr_args = brw_wm_nr_args(inst->opcode);
+
+   print_opcode(inst->opcode);
+   if (inst->dst.saturate)
+      debug_printf("_SAT");
+   debug_printf(" ");
+
+   if (inst->dst.indirect)
+      debug_printf("[");
+
+   debug_printf("%s[%d]",
+                file_strings[inst->dst.file],
+                inst->dst.index );
+   print_writemask(inst->dst.writemask);
+
+   if (inst->dst.indirect)
+      debug_printf("]");
+
+   debug_printf(nr_args ? ", " : "\n");
+   
+   for (i = 0; i < nr_args; i++) {
+      debug_printf("%s%s%s[%d]%s",
+                   inst->src[i].negate ? "-" : "",
+                   inst->src[i].abs ? "ABS(" : "",
+                   file_strings[inst->src[i].file],
+                   inst->src[i].index,
+                   inst->src[i].abs ? ")" : "");
+      print_swizzle(inst->src[i].swizzle);
+      debug_printf("%s", i == nr_args - 1 ? "\n" : ", ");
+   }
+}
+
+
+void brw_wm_print_fp_program( struct brw_wm_compile *c,
+                              const char *stage )
+{
+   GLuint insn;
+
+   debug_printf("%s:\n", stage);
+   for (insn = 0; insn < c->nr_fp_insns; insn++)
+      brw_wm_print_fp_insn(c, &c->fp_instructions[insn]);
+   debug_printf("\n");
 }