freedreno/ir3: standalone compiler updates for ir3test
authorRob Clark <robclark@freedesktop.org>
Fri, 24 Oct 2014 21:05:49 +0000 (17:05 -0400)
committerRob Clark <robclark@freedesktop.org>
Sat, 25 Oct 2014 13:08:15 +0000 (09:08 -0400)
In order to test compiler changes more easily, spit out the assembled
shader with some header information so that we can know about
inputs/outputs more easily.

See: git://people.freedesktop.org/~robclark/ir3test

In ir3test we have a big collection of tgsi shaders and reference
ir3_compiler outputs.  When making compiler changes, regenerate the
compiler outputs and feed to ir3test to compare the new vs reference
shader.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
src/gallium/drivers/freedreno/ir3/disasm-a3xx.c
src/gallium/drivers/freedreno/ir3/ir3.h
src/gallium/drivers/freedreno/ir3/ir3_cmdline.c
src/gallium/drivers/freedreno/ir3/ir3_compiler.c

index 8c3704bf658fc3493ad8dee9a6738b9034b1d22e..602be6508f32e8550a0284cdf9baaf716847f99b 100644 (file)
@@ -749,16 +749,8 @@ static void print_instr(uint32_t *dwords, int level, int n)
        uint32_t opc = instr_opc(instr);
        const char *name;
 
-       printf("%s%04d[%08xx_%08xx] ", levels[level], n, dwords[1], dwords[0]);
-
-#if 0
-       /* print unknown bits: */
-       if (debug & PRINT_RAW)
-               printf("[%08xx_%08xx] ", dwords[1] & 0x001ff800, dwords[0] & 0x00000000);
-
        if (debug & PRINT_VERBOSE)
-               printf("%d,%02d ", instr->opc_cat, opc);
-#endif
+               printf("%s%04d[%08xx_%08xx] ", levels[level], n, dwords[1], dwords[0]);
 
        /* NOTE: order flags are printed is a bit fugly.. but for now I
         * try to match the order in llvm-a3xx disassembler for easy
index 21992f68ced5c02e6fe738385f31d6fa09ea49ca..20d97bafdfeda22ebae7a141608b86a0a452b03d 100644 (file)
@@ -230,6 +230,7 @@ struct ir3 {
        struct ir3_instruction **instrs;
        unsigned baryfs_count, baryfs_sz;
        struct ir3_instruction **baryfs;
+       struct ir3_block *block;
        unsigned heap_idx;
        struct ir3_heap_chunk *chunk;
 };
index 652ec163f8032f15f3a77f531f41f2969e6d66dd..b2e55372d8690ab53e53b90019bbd5dbcf3e9e84 100644 (file)
@@ -42,7 +42,7 @@
 #include "instr-a3xx.h"
 #include "ir3.h"
 
-static void dump_info(struct ir3_shader_variant *so)
+static void dump_info(struct ir3_shader_variant *so, const char *str)
 {
        struct ir3_info info;
        uint32_t *bin;
@@ -51,12 +51,32 @@ static void dump_info(struct ir3_shader_variant *so)
        // for debug, dump some before/after info:
        bin = ir3_assemble(so->ir, &info);
        if (fd_mesa_debug & FD_DBG_DISASM) {
+               struct ir3_block *block = so->ir->block;
                unsigned i;
 
-               debug_printf("%s: disasm:\n", type);
+               debug_printf("; %s: %s\n", type, str);
+
+               for (i = 0; i < block->ninputs; i++) {
+                       uint8_t regid;
+                       if (!block->inputs[i])
+                               continue;
+                       regid = block->inputs[i]->regs[0]->num;
+                       debug_printf("@in(r%d.%c)\tin%d\n",
+                                       (regid >> 2), "xyzw"[regid & 0x3], i);
+               }
+
+               for (i = 0; i < block->noutputs; i++) {
+                       uint8_t regid;
+                       if (!block->outputs[i])
+                               continue;
+                       regid = block->outputs[i]->regs[0]->num;
+                       debug_printf("@out(r%d.%c)\tout%d\n",
+                                       (regid >> 2), "xyzw"[regid & 0x3], i);
+               }
+
                disasm_a3xx(bin, info.sizedwords, 0, so->type);
 
-               debug_printf("%s: outputs:", 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 +85,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,7 +98,7 @@ static void dump_info(struct ir3_shader_variant *so)
                }
                debug_printf("\n");
        }
-       debug_printf("%s: %u instructions, %d half, %d full\n\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);
        free(bin);
 }
@@ -144,13 +164,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;
@@ -159,42 +186,49 @@ 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;
@@ -213,6 +247,7 @@ int main(int argc, char **argv)
 
                break;
        }
+       debug_printf("\n");
 
        filename = argv[n];
 
@@ -243,22 +278,26 @@ int main(int argc, char **argv)
 
        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");
                }
        }
 
-       if (ret)
+       if (ret) {
+               info = "old compiler";
                ret = ir3_compile_shader_old(&v, toks, key);
+       }
 
        if (ret) {
                fprintf(stderr, "old compiler failed!\n");
                return ret;
        }
-       dump_info(&v);
+       dump_info(&v, info);
 }
index 233f1748b05ac03bcfa1f91e50379a29f3794b77..681545bd31397d1bef95b1b3423b841813f75052 100644 (file)
@@ -3102,6 +3102,7 @@ ir3_compile_shader(struct ir3_shader_variant *so,
        compile_instructions(&ctx);
 
        block = ctx.block;
+       so->ir->block = block;
 
        /* keep track of the inputs from TGSI perspective.. */
        inputs = block->inputs;