OSDN Git Service

vc4: Add VC4_DEBUG env option
authorEric Anholt <eric@anholt.net>
Sat, 28 Jun 2014 21:36:26 +0000 (14:36 -0700)
committerEric Anholt <eric@anholt.net>
Sat, 9 Aug 2014 01:59:46 +0000 (18:59 -0700)
v2: Fix an accidental deletion of some characters from the copyright
    message (caught by Ilia Mirkin)

src/gallium/drivers/vc4/vc4_context.c
src/gallium/drivers/vc4/vc4_program.c
src/gallium/drivers/vc4/vc4_qpu_emit.c
src/gallium/drivers/vc4/vc4_screen.c
src/gallium/drivers/vc4/vc4_screen.h

index 66cba1f..032d606 100644 (file)
@@ -110,13 +110,16 @@ vc4_flush(struct pipe_context *pctx)
         submit.shader_record_len = vc4->shader_rec.next - vc4->shader_rec.base;
         submit.shader_record_count = vc4->shader_rec_count;
 
+        if (!(vc4_debug & VC4_DEBUG_NORAST)) {
 #ifndef USE_VC4_SIMULATOR
-        int ret = drmIoctl(vc4->fd, DRM_IOCTL_VC4_SUBMIT_CL, &submit);
-        if (ret)
-                errx(1, "VC4 submit failed\n");
+                int ret = drmIoctl(vc4->fd, DRM_IOCTL_VC4_SUBMIT_CL, &submit);
+                if (ret)
+                        errx(1, "VC4 submit failed\n");
 #else
-        vc4_simulator_flush(vc4, csurf);
+                vc4_simulator_flush(vc4, csurf);
 #endif
+        }
+
         vc4_reset_cl(&vc4->bcl);
         vc4_reset_cl(&vc4->rcl);
         vc4_reset_cl(&vc4->shader_rec);
@@ -158,6 +161,10 @@ vc4_context_create(struct pipe_screen *pscreen, void *priv)
         struct vc4_screen *screen = vc4_screen(pscreen);
         struct vc4_context *vc4;
 
+        /* Prevent dumping of the shaders built during context setup. */
+        uint32_t saved_shaderdb_flag = vc4_debug & VC4_DEBUG_SHADERDB;
+        vc4_debug &= ~VC4_DEBUG_SHADERDB;
+
         vc4 = CALLOC_STRUCT(vc4_context);
         if (vc4 == NULL)
                 return NULL;
@@ -194,6 +201,8 @@ vc4_context_create(struct pipe_screen *pscreen, void *priv)
         if (!vc4->primconvert)
                 goto fail;
 
+        vc4_debug |= saved_shaderdb_flag;
+
         return &vc4->base;
 
 fail:
index 4742c54..8d71212 100644 (file)
@@ -274,8 +274,6 @@ emit_tgsi_instruction(struct tgsi_to_qir *trans,
         if (tgsi_op == TGSI_OPCODE_END)
                 return;
 
-        tgsi_dump_instruction(tgsi_inst, asdf++);
-
         if (tgsi_op > ARRAY_SIZE(op_trans) || !op_trans[tgsi_op].func) {
                 fprintf(stderr, "unknown tgsi inst: ");
                 tgsi_dump_instruction(tgsi_inst, asdf++);
@@ -329,7 +327,7 @@ emit_frag_init(struct tgsi_to_qir *trans, struct vc4_shader_state *so)
 {
         /* XXX: lols */
         for (int i = 0; i < 4; i++) {
-                trans->inputs[i] = qir_uniform_ui(trans, fui(i / 4.0));
+                trans->inputs[i] = qir_uniform_ui(trans, fui(1.0));
         }
 
 }
@@ -457,8 +455,10 @@ vc4_shader_tgsi_to_qir(struct vc4_shader_state *so, enum qstage stage)
         ret = tgsi_parse_init(&trans->parser, so->base.tokens);
         assert(ret == TGSI_PARSE_OK);
 
-        fprintf(stderr, "TGSI:\n");
-        tgsi_dump(so->base.tokens, 0);
+        if (vc4_debug & VC4_DEBUG_TGSI) {
+                fprintf(stderr, "TGSI:\n");
+                tgsi_dump(so->base.tokens, 0);
+        }
 
         switch (stage) {
         case QSTAGE_FRAG:
@@ -500,13 +500,23 @@ vc4_shader_tgsi_to_qir(struct vc4_shader_state *so, enum qstage stage)
                 break;
         }
 
-        qir_dump(c);
+        if (vc4_debug & VC4_DEBUG_QIR) {
+                fprintf(stderr, "QIR:\n");
+                qir_dump(c);
+        }
 
         tgsi_parse_free(&trans->parser);
         free(trans->temps);
 
         vc4_generate_code(c);
 
+        if (vc4_debug & VC4_DEBUG_SHADERDB) {
+                fprintf(stderr, "SHADER-DB: %s: %d instructions\n",
+                        qir_get_stage_name(c->stage), c->num_qpu_insts);
+                fprintf(stderr, "SHADER-DB: %s: %d uniforms\n",
+                        qir_get_stage_name(c->stage), trans->num_uniforms);
+        }
+
         return trans;
 }
 
@@ -629,7 +639,7 @@ vc4_get_uniform_bo(struct vc4_context *vc4, struct vc4_shader_state *shader,
                         map[i] = fui(vc4->framebuffer.height * -16.0f / 2.0f);
                         break;
                 }
-#if 1
+#if 0
                 fprintf(stderr, "%p/%d: %d: 0x%08x (%f)\n",
                         shader, shader_index, i, map[i], uif(map[i]));
 #endif
index d0f7f89..4591c6b 100644 (file)
@@ -363,7 +363,9 @@ vc4_generate_code(struct qcompile *c)
         c->qpu_insts = insts;
         c->num_qpu_insts = ni;
 
-        vc4_dump_program(c);
+        if (vc4_debug & VC4_DEBUG_QPU)
+                vc4_dump_program(c);
+
         vc4_qpu_validate(insts, ni);
 }
 
index 7c7ed4c..59ac1e2 100644 (file)
 #include "vc4_resource.h"
 
 static const struct debug_named_value debug_options[] = {
-        {"cl",      VC4_DBG_CL,   "Dump command list during creation"},
+        { "cl",       VC4_DEBUG_CL,
+          "Dump command list during creation" },
+        { "qpu",      VC4_DEBUG_QPU,
+          "Dump generated QPU instructions" },
+        { "qir",      VC4_DEBUG_QIR,
+          "Dump QPU IR during program compile" },
+        { "tgsi",     VC4_DEBUG_TGSI,
+          "Dump TGSI during program compile" },
+        { "shaderdb", VC4_DEBUG_SHADERDB,
+          "Dump program compile information for shader-db analysis" },
+        { "perf",     VC4_DEBUG_PERF,
+          "Print during performance-related events" },
+        { "norast",   VC4_DEBUG_NORAST,
+          "Skip actual hardware execution of commands" },
 };
 
+DEBUG_GET_ONCE_FLAGS_OPTION(vc4_debug, "VC4_DEBUG", debug_options, 0)
+uint32_t vc4_debug;
+
 static const char *
 vc4_screen_get_name(struct pipe_screen *pscreen)
 {
@@ -381,6 +397,10 @@ vc4_screen_create(int fd)
 
         screen->fd = fd;
 
+       vc4_debug = debug_get_option_vc4_debug();
+        if (vc4_debug & VC4_DEBUG_SHADERDB)
+                vc4_debug |= VC4_DEBUG_NORAST;
+
 #if USE_VC4_SIMULATOR
         vc4_simulator_init(screen);
 #endif
index 64bd2cf..1fe5ce1 100644 (file)
 
 struct vc4_bo;
 
-#define VC4_DBG_CL        0x0001
+#define VC4_DEBUG_CL        0x0001
+#define VC4_DEBUG_QPU       0x0002
+#define VC4_DEBUG_QIR       0x0004
+#define VC4_DEBUG_TGSI      0x0008
+#define VC4_DEBUG_SHADERDB  0x0010
+#define VC4_DEBUG_PERF      0x0020
+#define VC4_DEBUG_NORAST    0x0040
 
 #define VC4_MAX_MIP_LEVELS 11
 
@@ -60,4 +66,6 @@ vc4_screen_bo_from_handle(struct pipe_screen *pscreen,
 
 uint8_t vc4_get_texture_format(enum pipe_format format);
 
+extern uint32_t vc4_debug;
+
 #endif /* VC4_SCREEN_H */