freedreno/ir3: remove old compiler
[mesa.git] / src / gallium / drivers / freedreno / ir3 / ir3_cmdline.c
index f28ce27a00dba9035eb6f3f6b13b0ef025c3b786..bf6bcb8213106b3aed2fb81985616dd2dcf0f542 100644 (file)
 #include "instr-a3xx.h"
 #include "ir3.h"
 
+static void dump_reg(const char *name, uint32_t r)
+{
+       if (r != regid(63,0))
+               debug_printf("; %s: r%d.%c\n", name, r >> 2, "xyzw"[r & 0x3]);
+}
+
+static void dump_semantic(struct ir3_shader_variant *so,
+               unsigned sem, const char *name)
+{
+       uint32_t regid;
+       regid = ir3_find_output_regid(so, ir3_semantic_name(sem, 0));
+       dump_reg(name, regid);
+}
+
 static void dump_info(struct ir3_shader_variant *so, const char *str)
 {
-       struct ir3_info info;
        uint32_t *bin;
        const char *type = (so->type == SHADER_VERTEX) ? "VERT" : "FRAG";
 
        // for debug, dump some before/after info:
        // TODO make gpu_id configurable on cmdline
-       bin = ir3_assemble(so->ir, &info, 320);
+       bin = ir3_shader_assemble(so, 320);
        if (fd_mesa_debug & FD_DBG_DISASM) {
                struct ir3_block *block = so->ir->block;
                struct ir3_register *reg;
@@ -59,9 +72,12 @@ static void dump_info(struct ir3_shader_variant *so, const char *str)
 
                debug_printf("; %s: %s\n", type, str);
 
+if (block) {
                for (i = 0; i < block->ninputs; i++) {
-                       if (!block->inputs[i])
+                       if (!block->inputs[i]) {
+                               debug_printf("; in%d unused\n", i);
                                continue;
+                       }
                        reg = block->inputs[i]->regs[0];
                        regid = reg->num;
                        debug_printf("@in(%sr%d.%c)\tin%d\n",
@@ -70,8 +86,10 @@ static void dump_info(struct ir3_shader_variant *so, const char *str)
                }
 
                for (i = 0; i < block->noutputs; i++) {
-                       if (!block->outputs[i])
+                       if (!block->outputs[i]) {
+                               debug_printf("; out%d unused\n", i);
                                continue;
+                       }
                        /* kill shows up as a virtual output.. skip it! */
                        if (is_kill(block->outputs[i]))
                                continue;
@@ -81,8 +99,30 @@ static void dump_info(struct ir3_shader_variant *so, const char *str)
                                        (reg->flags & IR3_REG_HALF) ? "h" : "",
                                        (regid >> 2), "xyzw"[regid & 0x3], i);
                }
+} else {
+               /* hack to deal w/ old compiler:
+                * TODO maybe we can just keep this path?  I guess should
+                * be good enough (other than not able to deal w/ half)
+                */
+               for (i = 0; i < so->inputs_count; i++) {
+                       unsigned j, regid = so->inputs[i].regid;
+                       for (j = 0; j < so->inputs[i].ncomp; j++) {
+                               debug_printf("@in(r%d.%c)\tin%d\n",
+                                               (regid >> 2), "xyzw"[regid & 0x3], (i * 4) + j);
+                               regid++;
+                       }
+               }
+               for (i = 0; i < so->outputs_count; i++) {
+                       unsigned j, regid = so->outputs[i].regid;
+                       for (j = 0; j < 4; j++) {
+                               debug_printf("@out(r%d.%c)\tout%d\n",
+                                               (regid >> 2), "xyzw"[regid & 0x3], (i * 4) + j);
+                               regid++;
+                       }
+               }
+}
 
-               disasm_a3xx(bin, info.sizedwords, 0, so->type);
+               disasm_a3xx(bin, so->info.sizedwords, 0, so->type);
 
                debug_printf("; %s: outputs:", type);
                for (i = 0; i < so->outputs_count; i++) {
@@ -106,9 +146,37 @@ static void dump_info(struct ir3_shader_variant *so, const char *str)
                }
                debug_printf("\n");
        }
-       debug_printf("; %s: %u instructions, %d half, %d full\n\n",
-                       type, info.instrs_count, info.max_half_reg + 1, info.max_reg + 1);
+
+       /* print generic shader info: */
+       debug_printf("; %s: %u instructions, %d half, %d full\n", type,
+                       so->info.instrs_count,
+                       so->info.max_half_reg + 1,
+                       so->info.max_reg + 1);
+
+       /* print shader type specific info: */
+       switch (so->type) {
+       case SHADER_VERTEX:
+               dump_semantic(so, TGSI_SEMANTIC_POSITION, "pos");
+               dump_semantic(so, TGSI_SEMANTIC_PSIZE, "psize");
+               break;
+       case SHADER_FRAGMENT:
+               dump_reg("pos (bary)", so->pos_regid);
+               dump_semantic(so, TGSI_SEMANTIC_POSITION, "posz");
+               dump_semantic(so, TGSI_SEMANTIC_COLOR, "color");
+               /* these two are hard-coded since we don't know how to
+                * program them to anything but all 0's...
+                */
+               if (so->frag_coord)
+                       debug_printf("; fragcoord: r0.x\n");
+               if (so->frag_face)
+                       debug_printf("; fragface: hr0.x\n");
+               break;
+       case SHADER_COMPUTE:
+               break;
+       }
        free(bin);
+
+       debug_printf("\n");
 }
 
 
@@ -142,7 +210,7 @@ read_file(const char *filename, void **ptr, size_t *size)
 
 static void reset_variant(struct ir3_shader_variant *v, const char *msg)
 {
-       debug_error(msg);
+       printf("; %s\n", msg);
        v->inputs_count = 0;
        v->outputs_count = 0;
        v->total_in = 0;
@@ -268,6 +336,9 @@ int main(int argc, char **argv)
                return ret;
        }
 
+       if (fd_mesa_debug & FD_DBG_OPTMSGS)
+               debug_printf("%s\n", (char *)ptr);
+
        if (!tgsi_text_translate(ptr, toks, Elements(toks)))
                errx(1, "could not parse `%s'", filename);
 
@@ -284,27 +355,17 @@ int main(int argc, char **argv)
                break;
        }
 
-       if (!(fd_mesa_debug & FD_DBG_NOOPT)) {
-               /* with new compiler: */
-               info = "new compiler";
-               ret = ir3_compile_shader(&v, toks, key, true);
-
-               if (ret) {
-                       reset_variant(&v, "new compiler failed, trying without copy propagation!");
-                       info = "new compiler (no copy propagation)";
-                       ret = ir3_compile_shader(&v, toks, key, false);
-                       if (ret)
-                               reset_variant(&v, "new compiler failed, trying fallback!\n");
-               }
-       }
+       info = "compiler";
+       ret = ir3_compile_shader(&v, toks, key, true);
 
        if (ret) {
-               info = "old compiler";
-               ret = ir3_compile_shader_old(&v, toks, key);
+               reset_variant(&v, "compiler failed, trying without copy propagation!");
+               info = "compiler (no copy propagation)";
+               ret = ir3_compile_shader(&v, toks, key, false);
        }
 
        if (ret) {
-               fprintf(stderr, "old compiler failed!\n");
+               fprintf(stderr, "compiler failed!\n");
                return ret;
        }
        dump_info(&v, info);