vc4: Add debug output to match shaderdb info to program dumps.
authorEric Anholt <eric@anholt.net>
Wed, 22 Oct 2014 17:02:18 +0000 (18:02 +0100)
committerEric Anholt <eric@anholt.net>
Fri, 24 Oct 2014 17:04:26 +0000 (18:04 +0100)
I'm going to be using VC4_DEBUG=shaderdb,norast to do shaderdb stats, but
when debugging regressions, I want to match shaderdb output to shader
disassembly.

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

index 45dfa020551470ee036c5a7c60148cece3a2a4bd..d0b280a3b6d47972606c4a061645a60e556d4414 100644 (file)
@@ -79,6 +79,10 @@ struct vc4_shader_uniform_info {
 };
 
 struct vc4_uncompiled_shader {
+        /** A name for this program, so you can track it in shader-db output. */
+        uint32_t program_id;
+        /** How many variants of this program were compiled, for shader-db. */
+        uint32_t compiled_variant_count;
         struct pipe_shader_state base;
         const struct tgsi_token *twoside_tokens;
 };
@@ -183,6 +187,7 @@ struct vc4_context {
         struct primconvert_context *primconvert;
 
         struct util_hash_table *fs_cache, *vs_cache;
+        uint32_t next_uncompiled_program_id;
         uint64_t next_compiled_program_id;
 
         struct ra_regs *regs;
index c6d9fb31603e2f5269d2a95a46b95500969f4d8b..01941f88428ff58623a3b00864f7690967220995 100644 (file)
@@ -1827,6 +1827,8 @@ vc4_shader_tgsi_to_qir(struct vc4_context *vc4, enum qstage stage,
 
         c->stage = stage;
         c->shader_state = &key->shader_state->base;
+        c->program_id = key->shader_state->program_id;
+        c->variant_id = key->shader_state->compiled_variant_count++;
 
         c->key = key;
         switch (stage) {
@@ -1874,7 +1876,9 @@ vc4_shader_tgsi_to_qir(struct vc4_context *vc4, enum qstage stage,
         assert(ret == TGSI_PARSE_OK);
 
         if (vc4_debug & VC4_DEBUG_TGSI) {
-                fprintf(stderr, "TGSI:\n");
+                fprintf(stderr, "%s prog %d/%d TGSI:\n",
+                        qir_get_stage_name(c->stage),
+                        c->program_id, c->variant_id);
                 tgsi_dump(tokens, 0);
         }
 
@@ -1918,17 +1922,23 @@ vc4_shader_tgsi_to_qir(struct vc4_context *vc4, enum qstage stage,
         qir_optimize(c);
 
         if (vc4_debug & VC4_DEBUG_QIR) {
-                fprintf(stderr, "QIR:\n");
+                fprintf(stderr, "%s prog %d/%d QIR:\n",
+                        qir_get_stage_name(c->stage),
+                        c->program_id, c->variant_id);
                 qir_dump(c);
         }
         qir_reorder_uniforms(c);
         vc4_generate_code(vc4, c);
 
         if (vc4_debug & VC4_DEBUG_SHADERDB) {
-                fprintf(stderr, "SHADER-DB: %s: %d instructions\n",
-                        qir_get_stage_name(c->stage), c->qpu_inst_count);
-                fprintf(stderr, "SHADER-DB: %s: %d uniforms\n",
-                        qir_get_stage_name(c->stage), c->num_uniforms);
+                fprintf(stderr, "SHADER-DB: %s prog %d/%d: %d instructions\n",
+                        qir_get_stage_name(c->stage),
+                        c->program_id, c->variant_id,
+                        c->qpu_inst_count);
+                fprintf(stderr, "SHADER-DB: %s prog %d/%d: %d uniforms\n",
+                        qir_get_stage_name(c->stage),
+                        c->program_id, c->variant_id,
+                        c->num_uniforms);
         }
 
         return c;
@@ -1938,6 +1948,7 @@ static void *
 vc4_shader_state_create(struct pipe_context *pctx,
                         const struct pipe_shader_state *cso)
 {
+        struct vc4_context *vc4 = vc4_context(pctx);
         struct vc4_uncompiled_shader *so = CALLOC_STRUCT(vc4_uncompiled_shader);
         if (!so)
                 return NULL;
@@ -1961,6 +1972,7 @@ vc4_shader_state_create(struct pipe_context *pctx,
         so->base.tokens = tgsi_transform_lowering(&lowering_config, cso->tokens, &info);
         if (!so->base.tokens)
                 so->base.tokens = tgsi_dup_tokens(cso->tokens);
+        so->program_id = vc4->next_uncompiled_program_id++;
 
         return so;
 }
index b95dbc33d515953d3393edd2b3a2ae2810c4421a..c2f83a7e92378dc0e86639085bee724ab01c276f 100644 (file)
@@ -289,6 +289,9 @@ struct vc4_compile {
         uint32_t qpu_inst_count;
         uint32_t qpu_inst_size;
         uint32_t num_inputs;
+
+        uint32_t program_id;
+        uint32_t variant_id;
 };
 
 struct vc4_compile *qir_compile_init(void);
index 99e634eb49349293b27d799985c1fec57d2e1365..1d9bff39fe0b82ce9f652b2085dd6cb86b421270 100644 (file)
@@ -30,7 +30,9 @@
 static void
 vc4_dump_program(struct vc4_compile *c)
 {
-        fprintf(stderr, "%s:\n", qir_get_stage_name(c->stage));
+        fprintf(stderr, "%s prog %d/%d QPU:\n",
+                qir_get_stage_name(c->stage),
+                c->program_id, c->variant_id);
 
         for (int i = 0; i < c->qpu_inst_count; i++) {
                 fprintf(stderr, "0x%016"PRIx64" ", c->qpu_insts[i]);