freedreno/ir3: remove old compiler
[mesa.git] / src / gallium / drivers / freedreno / ir3 / ir3_cmdline.c
index 86239b45465d83c2cbbf388c6192a501a96b77d2..bf6bcb8213106b3aed2fb81985616dd2dcf0f542 100644 (file)
 #include "instr-a3xx.h"
 #include "ir3.h"
 
-static void dump_info(struct ir3_shader_variant *so)
+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:
-       bin = ir3_assemble(so->ir, &info);
+       // TODO make gpu_id configurable on cmdline
+       bin = ir3_shader_assemble(so, 320);
        if (fd_mesa_debug & FD_DBG_DISASM) {
+               struct ir3_block *block = so->ir->block;
+               struct ir3_register *reg;
+               uint8_t regid;
                unsigned i;
 
-               debug_printf("%s: disasm:\n", type);
-               disasm_a3xx(bin, info.sizedwords, 0, so->type);
+               debug_printf("; %s: %s\n", type, str);
+
+if (block) {
+               for (i = 0; i < block->ninputs; 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",
+                                       (reg->flags & IR3_REG_HALF) ? "h" : "",
+                                       (regid >> 2), "xyzw"[regid & 0x3], i);
+               }
+
+               for (i = 0; i < block->noutputs; 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;
+                       reg = block->outputs[i]->regs[0];
+                       regid = reg->num;
+                       debug_printf("@out(%sr%d.%c)\tout%d\n",
+                                       (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++;
+                       }
+               }
+}
 
-               debug_printf("%s: outputs:", type);
+               disasm_a3xx(bin, so->info.sizedwords, 0, so->type);
+
+               debug_printf("; %s: outputs:", type);
                for (i = 0; i < so->outputs_count; i++) {
                        uint8_t regid = so->outputs[i].regid;
                        ir3_semantic sem = so->outputs[i].semantic;
@@ -65,7 +133,7 @@ static void dump_info(struct ir3_shader_variant *so)
                                        sem2name(sem), sem2idx(sem));
                }
                debug_printf("\n");
-               debug_printf("%s: inputs:", type);
+               debug_printf("%s: inputs:", type);
                for (i = 0; i < so->inputs_count; i++) {
                        uint8_t regid = so->inputs[i].regid;
                        ir3_semantic sem = so->inputs[i].semantic;
@@ -78,9 +146,37 @@ static void dump_info(struct ir3_shader_variant *so)
                }
                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");
 }
 
 
@@ -114,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;
@@ -133,6 +229,7 @@ static void print_usage(void)
        printf("    --saturate-s MASK - bitmask of samplers to saturate S coord\n");
        printf("    --saturate-t MASK - bitmask of samplers to saturate T coord\n");
        printf("    --saturate-r MASK - bitmask of samplers to saturate R coord\n");
+       printf("    --nocp            - disable copy propagation\n");
        printf("    --help            - show this message\n");
 }
 
@@ -143,13 +240,20 @@ int main(int argc, char **argv)
        struct tgsi_token toks[65536];
        struct tgsi_parse_context parse;
        struct ir3_shader_variant v;
-       struct ir3_shader_key key = {
-       };
+       struct ir3_shader_key key = {};
+       const char *info;
        void *ptr;
        size_t size;
 
        fd_mesa_debug |= FD_DBG_DISASM;
 
+       /* cmdline args which impact shader variant get spit out in a
+        * comment on the first line..  a quick/dirty way to preserve
+        * that info so when ir3test recompiles the shader with a new
+        * compiler version, we use the same shader-key settings:
+        */
+       debug_printf("; options:");
+
        while (n < argc) {
                if (!strcmp(argv[n], "--verbose")) {
                        fd_mesa_debug |=  FD_DBG_OPTDUMP | FD_DBG_MSGS | FD_DBG_OPTMSGS;
@@ -158,47 +262,60 @@ int main(int argc, char **argv)
                }
 
                if (!strcmp(argv[n], "--binning-pass")) {
+                       debug_printf(" %s", argv[n]);
                        key.binning_pass = true;
                        n++;
                        continue;
                }
 
                if (!strcmp(argv[n], "--color-two-side")) {
+                       debug_printf(" %s", argv[n]);
                        key.color_two_side = true;
                        n++;
                        continue;
                }
 
                if (!strcmp(argv[n], "--half-precision")) {
+                       debug_printf(" %s", argv[n]);
                        key.half_precision = true;
                        n++;
                        continue;
                }
 
                if (!strcmp(argv[n], "--alpha")) {
+                       debug_printf(" %s", argv[n]);
                        key.alpha = true;
                        n++;
                        continue;
                }
 
                if (!strcmp(argv[n], "--saturate-s")) {
+                       debug_printf(" %s %s", argv[n], argv[n+1]);
                        key.vsaturate_s = key.fsaturate_s = strtol(argv[n+1], NULL, 0);
                        n += 2;
                        continue;
                }
 
                if (!strcmp(argv[n], "--saturate-t")) {
+                       debug_printf(" %s %s", argv[n], argv[n+1]);
                        key.vsaturate_t = key.fsaturate_t = strtol(argv[n+1], NULL, 0);
                        n += 2;
                        continue;
                }
 
                if (!strcmp(argv[n], "--saturate-r")) {
+                       debug_printf(" %s %s", argv[n], argv[n+1]);
                        key.vsaturate_r = key.fsaturate_r = strtol(argv[n+1], NULL, 0);
                        n += 2;
                        continue;
                }
 
+               if (!strcmp(argv[n], "--nocp")) {
+                       fd_mesa_debug |= FD_DBG_NOCP;
+                       n++;
+                       continue;
+               }
+
                if (!strcmp(argv[n], "--help")) {
                        print_usage();
                        return 0;
@@ -206,6 +323,7 @@ int main(int argc, char **argv)
 
                break;
        }
+       debug_printf("\n");
 
        filename = argv[n];
 
@@ -218,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);
 
@@ -234,24 +355,18 @@ int main(int argc, char **argv)
                break;
        }
 
-       if (!(fd_mesa_debug & FD_DBG_NOOPT)) {
-               /* with new compiler: */
-               ret = ir3_compile_shader(&v, toks, key, true);
+       info = "compiler";
+       ret = ir3_compile_shader(&v, toks, key, true);
 
-               if (ret) {
-                       reset_variant(&v, "new compiler failed, trying without copy propagation!");
-                       ret = ir3_compile_shader(&v, toks, key, false);
-                       if (ret)
-                               reset_variant(&v, "new compiler failed, trying fallback!\n");
-               }
+       if (ret) {
+               reset_variant(&v, "compiler failed, trying without copy propagation!");
+               info = "compiler (no copy propagation)";
+               ret = ir3_compile_shader(&v, toks, key, false);
        }
 
-       if (ret)
-               ret = ir3_compile_shader_old(&v, toks, key);
-
        if (ret) {
-               fprintf(stderr, "old compiler failed!\n");
+               fprintf(stderr, "compiler failed!\n");
                return ret;
        }
-       dump_info(&v);
+       dump_info(&v, info);
 }