[g3dvl] move z-coord generation for multiple render targets into vertex shader
[mesa.git] / src / gallium / drivers / r300 / r300_debug.c
index c83e8526cf7938f4ec8430f15282dd05828d23b5..f78fe34790c47847fd69bdca08c621fb3beb7bb1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009 Corbin Simpson <MostAwesomeDude@gmail.com>
+ * Copyright 2009 Nicolai Haehnle <nhaehnle@gmail.com>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  * USE OR OTHER DEALINGS IN THE SOFTWARE. */
 
-#include "r300_debug.h"
+#include "r300_context.h"
 
-void r3xx_dump_fs(struct r3xx_fragment_shader* fs)
-{
-    int i;
+#include "util/u_debug.h"
 
-    for (i = 0; i < fs->alu_instruction_count; i++) {
-    }
-}
+#include <stdio.h>
 
-void r5xx_fs_dump(struct r5xx_fragment_shader* fs)
+static const struct debug_named_value debug_options[] = {
+    { "fp", DBG_FP, "Log fragment program compilation" },
+    { "vp", DBG_VP, "Log vertex program compilation" },
+    { "pstat", DBG_P_STAT, "Log vertex/fragment program stats" },
+    { "draw", DBG_DRAW, "Log draw calls" },
+    { "swtcl", DBG_SWTCL, "Log SWTCL-specific info" },
+    { "rsblock", DBG_RS_BLOCK, "Log rasterizer registers" },
+    { "psc", DBG_PSC, "Log vertex stream registers" },
+    { "tex", DBG_TEX, "Log basic info about textures" },
+    { "texalloc", DBG_TEXALLOC, "Log texture mipmap tree info" },
+    { "fall", DBG_FALL, "Log fallbacks" },
+    { "rs", DBG_RS, "Log rasterizer" },
+    { "fb", DBG_FB, "Log framebuffer" },
+    { "cbzb", DBG_CBZB, "Log fast color clear info" },
+    { "stats", DBG_STATS, "Log emission statistics" },
+    { "hyperz", DBG_HYPERZ, "Log HyperZ info" },
+    { "scissor", DBG_SCISSOR, "Log scissor info" },
+    { "fakeocc", DBG_FAKE_OCC, "Use fake occlusion queries" },
+    { "anisohq", DBG_ANISOHQ, "Use high quality anisotropic filtering" },
+    { "notiling", DBG_NO_TILING, "Disable tiling" },
+    { "noimmd", DBG_NO_IMMD, "Disable immediate mode" },
+    { "noopt", DBG_NO_OPT, "Disable shader optimizations" },
+    { "nocbzb", DBG_NO_CBZB, "Disable fast color clear" },
+
+    /* must be last */
+    DEBUG_NAMED_VALUE_END
+};
+
+void r300_init_debug(struct r300_screen * screen)
 {
-    int i;
-    uint32_t inst;
-
-    for (i = 0; i < fs->instruction_count; i++) {
-        inst = fs->instructions[i].inst0;
-        debug_printf("%d:  0: CMN_INST   0x%08x:", i, inst);
-        switch (inst & 0x3) {
-            case R500_INST_TYPE_ALU:
-                debug_printf("ALU ");
-                break;
-            case R500_INST_TYPE_OUT:
-                debug_printf("OUT ");
-                break;
-            case R500_INST_TYPE_FC:
-                debug_printf("FC  ");
-                break;
-            case R500_INST_TYPE_TEX:
-                debug_printf("TEX ");
-                break;
-        }
-        debug_printf("%s %s %s %s ",
-                inst & R500_INST_TEX_SEM_WAIT ? "TEX_WAIT" : "",
-                inst & R500_INST_LAST ? "LAST" : "",
-                inst & R500_INST_NOP ? "NOP" : "",
-                inst & R500_INST_ALU_WAIT ? "ALU_WAIT" : "");
-        debug_printf("wmask: %s omask: %s\n",
-                r5xx_fs_mask[(inst >> 11) & 0xf],
-                r5xx_fs_mask[(inst >> 15) & 0xf]);
-        switch (inst & 0x3) {
-            case R500_INST_TYPE_ALU:
-            case R500_INST_TYPE_OUT:
-                inst = fs->instructions[i].inst1;
-                debug_printf("    1: RGB_ADDR   0x%08x:", inst);
-                debug_printf("Addr0: %d%c, Addr1: %d%c, "
-                        "Addr2: %d%c, srcp:%d\n",
-                        inst & 0xff, (inst & (1 << 8)) ? 'c' : 't',
-                        (inst >> 10) & 0xff, (inst & (1 << 18)) ? 'c' : 't',
-                        (inst >> 20) & 0xff, (inst & (1 << 28)) ? 'c' : 't',
-                        (inst >> 30));
-
-                inst = fs->instructions[i].inst2;
-                debug_printf("    2: ALPHA_ADDR 0x%08x:", inst);
-                debug_printf("Addr0: %d%c, Addr1: %d%c, "
-                        "Addr2: %d%c, srcp:%d\n",
-                        inst & 0xff, (inst & (1 << 8)) ? 'c' : 't',
-                        (inst >> 10) & 0xff, (inst & (1 << 18)) ? 'c' : 't',
-                        (inst >> 20) & 0xff, (inst & (1 << 28)) ? 'c' : 't',
-                        (inst >> 30));
-
-                inst = fs->instructions[i].inst3;
-                debug_printf("    3: RGB_INST   0x%08x:", inst);
-                debug_printf("rgb_A_src:%d %s/%s/%s %d "
-                        "rgb_B_src:%d %s/%s/%s %d\n",
-                        inst & 0x3, r5xx_fs_swiz[(inst >> 2) & 0x7],
-                        r5xx_fs_swiz[(inst >> 5) & 0x7],
-                        r5xx_fs_swiz[(inst >> 8) & 0x7],
-                        (inst >> 11) & 0x3, (inst >> 13) & 0x3,
-                        r5xx_fs_swiz[(inst >> 15) & 0x7],
-                        r5xx_fs_swiz[(inst >> 18) & 0x7],
-                        r5xx_fs_swiz[(inst >> 21) & 0x7],
-                        (inst >> 24) & 0x3);
-
-                inst = fs->instructions[i].inst4;
-                debug_printf("    4: ALPHA_INST 0x%08x:", inst);
-                debug_printf("%s dest:%d%s alp_A_src:%d %s %d "
-                        "alp_B_src:%d %s %d w:%d\n",
-                        r5xx_fs_op_alpha[inst & 0xf], (inst >> 4) & 0x7f,
-                        inst & (1<<11) ? "(rel)":"", (inst >> 12) & 0x3,
-                        r5xx_fs_swiz[(inst >> 14) & 0x7], (inst >> 17) & 0x3,
-                        (inst >> 19) & 0x3, r5xx_fs_swiz[(inst >> 21) & 0x7],
-                        (inst >> 24) & 0x3, (inst >> 31) & 0x1);
-
-                inst = fs->instructions[i].inst5;
-                debug_printf("    5: RGBA_INST  0x%08x:", inst);
-                debug_printf("%s dest:%d%s rgb_C_src:%d %s/%s/%s %d "
-                        "alp_C_src:%d %s %d\n",
-                        r5xx_fs_op_rgb[inst & 0xf], (inst >> 4) & 0x7f,
-                        inst & (1 << 11) ? "(rel)":"", (inst >> 12) & 0x3,
-                        r5xx_fs_swiz[(inst >> 14) & 0x7],
-                        r5xx_fs_swiz[(inst >> 17) & 0x7],
-                        r5xx_fs_swiz[(inst >> 20) & 0x7],
-                        (inst >> 23) & 0x3, (inst >> 25) & 0x3,
-                        r5xx_fs_swiz[(inst >> 27) & 0x7], (inst >> 30) & 0x3);
-                break;
-            case R500_INST_TYPE_FC:
-                /* XXX don't even bother yet */
-                break;
-            case R500_INST_TYPE_TEX:
-                inst = fs->instructions[i].inst1;
-                debug_printf("    1: TEX_INST   0x%08x: id: %d "
-                        "op:%s, %s, %s %s\n",
-                        inst, (inst >> 16) & 0xf,
-                        r5xx_fs_tex[(inst >> 22) & 0x7],
-                        (inst & (1 << 25)) ? "ACQ" : "",
-                        (inst & (1 << 26)) ? "IGNUNC" : "",
-                        (inst & (1 << 27)) ? "UNSCALED" : "SCALED");
-
-                inst = fs->instructions[i].inst2;
-                debug_printf("    2: TEX_ADDR   0x%08x: "
-                        "src: %d%s %s/%s/%s/%s dst: %d%s %s/%s/%s/%s\n",
-                        inst, inst & 0x7f, inst & (1 << 7) ? "(rel)" : "",
-                        r5xx_fs_swiz[(inst >> 8) & 0x3],
-                        r5xx_fs_swiz[(inst >> 10) & 0x3],
-                        r5xx_fs_swiz[(inst >> 12) & 0x3],
-                        r5xx_fs_swiz[(inst >> 14) & 0x3],
-                        (inst >> 16) & 0x7f, inst & (1 << 23) ? "(rel)" : "",
-                        r5xx_fs_swiz[(inst >> 24) & 0x3],
-                        r5xx_fs_swiz[(inst >> 26) & 0x3],
-                        r5xx_fs_swiz[(inst >> 28) & 0x3],
-                        r5xx_fs_swiz[(inst >> 30) & 0x3]);
-                
-                inst = fs->instructions[i].inst3;
-                debug_printf("    3: TEX_DXDY   0x%08x\n", inst);
-                break;
-        }
-    }
+    screen->debug = debug_get_flags_option("RADEON_DEBUG", debug_options, 0);
 }
 
-static void r300_vs_op_dump(uint32_t op)
+void r500_dump_rs_block(struct r300_rs_block *rs)
 {
-    debug_printf(" dst: %d%s op: ",
-            (op >> 13) & 0x7f, r300_vs_dst_debug[(op >> 8) & 0x7]);
-    if (op & 0x80) {
-        if (op & 0x1) {
-            debug_printf("PVS_MACRO_OP_2CLK_M2X_ADD\n");
-        } else {
-            debug_printf("   PVS_MACRO_OP_2CLK_MADD\n");
+    unsigned count, ip, it_count, ic_count, i, j;
+    unsigned tex_ptr;
+    unsigned col_ptr, col_fmt;
+
+    count = rs->inst_count & 0xf;
+    count++;
+
+    it_count = rs->count & 0x7f;
+    ic_count = (rs->count >> 7) & 0xf;
+
+    fprintf(stderr, "RS Block: %d texcoords (linear), %d colors (perspective)\n",
+        it_count, ic_count);
+    fprintf(stderr, "%d instructions\n", count);
+
+    for (i = 0; i < count; i++) {
+        if (rs->inst[i] & 0x10) {
+            ip = rs->inst[i] & 0xf;
+            fprintf(stderr, "texture: ip %d to psf %d\n",
+                ip, (rs->inst[i] >> 5) & 0x7f);
+
+            tex_ptr = rs->ip[ip] & 0xffffff;
+            fprintf(stderr, "       : ");
+
+            j = 3;
+            do {
+                if ((tex_ptr & 0x3f) == 63) {
+                    fprintf(stderr, "1.0");
+                } else if ((tex_ptr & 0x3f) == 62) {
+                    fprintf(stderr, "0.0");
+                } else {
+                    fprintf(stderr, "[%d]", tex_ptr & 0x3f);
+                }
+            } while (j-- && fprintf(stderr, "/"));
+            fprintf(stderr, "\n");
         }
-    } else if (op & 0x40) {
-        debug_printf("%s\n", r300_vs_me_ops[op & 0x1f]);
-    } else {
-        debug_printf("%s\n", r300_vs_ve_ops[op & 0x1f]);
-    }
-}
 
-void r300_vs_src_dump(uint32_t src)
-{
-    debug_printf(" reg: %d%s swiz: %s%s/%s%s/%s%s/%s%s\n",
-            (src >> 5) & 0x7f, r300_vs_src_debug[src & 0x3],
-            src & (1 << 25) ? "-" : " ",
-            r300_vs_swiz_debug[(src >> 13) & 0x7],
-            src & (1 << 26) ? "-" : " ",
-            r300_vs_swiz_debug[(src >> 16) & 0x7],
-            src & (1 << 27) ? "-" : " ",
-            r300_vs_swiz_debug[(src >> 19) & 0x7],
-            src & (1 << 28) ? "-" : " ",
-            r300_vs_swiz_debug[(src >> 22) & 0x7]);
-}
+        if (rs->inst[i] & 0x10000) {
+            ip = (rs->inst[i] >> 12) & 0xf;
+            fprintf(stderr, "color: ip %d to psf %d\n",
+                ip, (rs->inst[i] >> 18) & 0x7f);
 
-void r300_vs_dump(struct r300_vertex_shader* vs)
-{
-    int i;
-
-    for (i = 0; i < vs->instruction_count; i++) {
-        debug_printf("%d: op: 0x%08x", i, vs->instructions[i].inst0);
-        r300_vs_op_dump(vs->instructions[i].inst0);
-        debug_printf(" src0: 0x%08x", vs->instructions[i].inst1);
-        r300_vs_src_dump(vs->instructions[i].inst1);
-        debug_printf(" src1: 0x%08x", vs->instructions[i].inst2);
-        r300_vs_src_dump(vs->instructions[i].inst2);
-        debug_printf(" src2: 0x%08x", vs->instructions[i].inst3);
-        r300_vs_src_dump(vs->instructions[i].inst3);
+            col_ptr = (rs->ip[ip] >> 24) & 0x7;
+            col_fmt = (rs->ip[ip] >> 27) & 0xf;
+            fprintf(stderr, "     : offset %d ", col_ptr);
+
+            switch (col_fmt) {
+                case 0:
+                    fprintf(stderr, "(R/G/B/A)");
+                    break;
+                case 1:
+                    fprintf(stderr, "(R/G/B/0)");
+                    break;
+                case 2:
+                    fprintf(stderr, "(R/G/B/1)");
+                    break;
+                case 4:
+                    fprintf(stderr, "(0/0/0/A)");
+                    break;
+                case 5:
+                    fprintf(stderr, "(0/0/0/0)");
+                    break;
+                case 6:
+                    fprintf(stderr, "(0/0/0/1)");
+                    break;
+                case 8:
+                    fprintf(stderr, "(1/1/1/A)");
+                    break;
+                case 9:
+                    fprintf(stderr, "(1/1/1/0)");
+                    break;
+                case 10:
+                    fprintf(stderr, "(1/1/1/1)");
+                    break;
+            }
+            fprintf(stderr, "\n");
+        }
     }
 }