v3d: Hook up some shader-db output to GL_ARB_debug_output.
authorEric Anholt <eric@anholt.net>
Thu, 20 Dec 2018 15:45:58 +0000 (07:45 -0800)
committerEric Anholt <eric@anholt.net>
Sun, 30 Dec 2018 16:03:51 +0000 (08:03 -0800)
This allows the original shader-db project's run.c runner to parse things
easily, and is probably a good thing to have for GL_ARB_debug_output in
general.  I formatted it more like Intel's so I can mostly reuse their
report script.

src/broadcom/compiler/nir_to_vir.c
src/broadcom/compiler/v3d_compiler.h
src/broadcom/compiler/vir.c
src/gallium/drivers/v3d/v3d_program.c

index ada0dd69921fa3408ac56238519e83c42c809e32..b6dd188778aa3f141606cfd63016001ab5523460 100644 (file)
@@ -1895,6 +1895,8 @@ ntq_emit_loop(struct v3d_compile *c, nir_loop *loop)
 
         c->loop_break_block = save_loop_break_block;
         c->loop_cont_block = save_loop_cont_block;
+
+        c->loops++;
 }
 
 static void
index ec5fd87083c2f71defd58f5bf2ca6089ee4ae304..2d9167a27a09a66b58f728b12532eab403c955b8 100644 (file)
@@ -457,6 +457,10 @@ struct v3d_compile {
         struct exec_list *cf_node_list;
         const struct v3d_compiler *compiler;
 
+        void (*debug_output)(const char *msg,
+                             void *debug_output_data);
+        void *debug_output_data;
+
         /**
          * Mapping from nir_register * or nir_ssa_def * to array of struct
          * qreg for the values.
@@ -529,8 +533,8 @@ struct v3d_compile {
          * space needs to be available in the spill BO per thread per QPU.
          */
         uint32_t spill_size;
-        /* Shader-db stats for register spilling. */
-        uint32_t spills, fills;
+        /* Shader-db stats */
+        uint32_t spills, fills, loops;
         /**
          * Register spilling's per-thread base address, shared between each
          * spill/fill's addressing calculations.
@@ -706,6 +710,9 @@ uint64_t *v3d_compile_vs(const struct v3d_compiler *compiler,
                          struct v3d_vs_key *key,
                          struct v3d_vs_prog_data *prog_data,
                          nir_shader *s,
+                         void (*debug_output)(const char *msg,
+                                              void *debug_output_data),
+                         void *debug_output_data,
                          int program_id, int variant_id,
                          uint32_t *final_assembly_size);
 
@@ -713,6 +720,9 @@ uint64_t *v3d_compile_fs(const struct v3d_compiler *compiler,
                          struct v3d_fs_key *key,
                          struct v3d_fs_prog_data *prog_data,
                          nir_shader *s,
+                         void (*debug_output)(const char *msg,
+                                              void *debug_output_data),
+                         void *debug_output_data,
                          int program_id, int variant_id,
                          uint32_t *final_assembly_size);
 
index 9bec5e54e134642d01cb71c75ce7f6909912183b..8880a2820457230e45ef5e15fb8ce34dfda9dfca 100644 (file)
@@ -558,6 +558,9 @@ static struct v3d_compile *
 vir_compile_init(const struct v3d_compiler *compiler,
                  struct v3d_key *key,
                  nir_shader *s,
+                 void (*debug_output)(const char *msg,
+                                      void *debug_output_data),
+                 void *debug_output_data,
                  int program_id, int variant_id)
 {
         struct v3d_compile *c = rzalloc(NULL, struct v3d_compile);
@@ -568,6 +571,8 @@ vir_compile_init(const struct v3d_compiler *compiler,
         c->program_id = program_id;
         c->variant_id = variant_id;
         c->threads = 4;
+        c->debug_output = debug_output;
+        c->debug_output_data = debug_output_data;
 
         s = nir_shader_clone(c, s);
         c->s = s;
@@ -702,6 +707,22 @@ v3d_return_qpu_insts(struct v3d_compile *c, uint32_t *final_assembly_size)
 
         memcpy(qpu_insts, c->qpu_insts, *final_assembly_size);
 
+        char *shaderdb;
+        int ret = asprintf(&shaderdb,
+                           "%s shader: %d inst, %d threads, %d loops, "
+                           "%d uniforms, %d:%d spills:fills",
+                           vir_get_stage_name(c),
+                           c->qpu_inst_count,
+                           c->threads,
+                           c->loops,
+                           c->num_uniforms,
+                           c->spills,
+                           c->fills);
+        if (ret >= 0) {
+                c->debug_output(shaderdb, c->debug_output_data);
+                free(shaderdb);
+        }
+
         vir_compile_destroy(c);
 
         return qpu_insts;
@@ -711,10 +732,14 @@ uint64_t *v3d_compile_vs(const struct v3d_compiler *compiler,
                          struct v3d_vs_key *key,
                          struct v3d_vs_prog_data *prog_data,
                          nir_shader *s,
+                         void (*debug_output)(const char *msg,
+                                              void *debug_output_data),
+                         void *debug_output_data,
                          int program_id, int variant_id,
                          uint32_t *final_assembly_size)
 {
         struct v3d_compile *c = vir_compile_init(compiler, &key->base, s,
+                                                 debug_output, debug_output_data,
                                                  program_id, variant_id);
 
         c->vs_key = key;
@@ -874,10 +899,14 @@ uint64_t *v3d_compile_fs(const struct v3d_compiler *compiler,
                          struct v3d_fs_key *key,
                          struct v3d_fs_prog_data *prog_data,
                          nir_shader *s,
+                         void (*debug_output)(const char *msg,
+                                              void *debug_output_data),
+                         void *debug_output_data,
                          int program_id, int variant_id,
                          uint32_t *final_assembly_size)
 {
         struct v3d_compile *c = vir_compile_init(compiler, &key->base, s,
+                                                 debug_output, debug_output_data,
                                                  program_id, variant_id);
 
         c->fs_key = key;
index d635068293697d0a283c51561a33f9057e95c416..759fac117f2adf75ffcf26a869659caccadcb5dd 100644 (file)
@@ -307,6 +307,14 @@ v3d_shader_state_create(struct pipe_context *pctx,
         return so;
 }
 
+static void
+v3d_shader_debug_output(const char *message, void *data)
+{
+        struct v3d_context *v3d = data;
+
+        pipe_debug_message(&v3d->debug, SHADER_INFO, "%s", message);
+}
+
 static struct v3d_compiled_shader *
 v3d_get_compiled_shader(struct v3d_context *v3d, struct v3d_key *key)
 {
@@ -343,6 +351,8 @@ v3d_get_compiled_shader(struct v3d_context *v3d, struct v3d_key *key)
                 qpu_insts = v3d_compile_vs(v3d->screen->compiler,
                                            (struct v3d_vs_key *)key,
                                            shader->prog_data.vs, s,
+                                           v3d_shader_debug_output,
+                                           v3d,
                                            program_id, variant_id,
                                            &shader_size);
                 break;
@@ -352,6 +362,8 @@ v3d_get_compiled_shader(struct v3d_context *v3d, struct v3d_key *key)
                 qpu_insts = v3d_compile_fs(v3d->screen->compiler,
                                            (struct v3d_fs_key *)key,
                                            shader->prog_data.fs, s,
+                                           v3d_shader_debug_output,
+                                           v3d,
                                            program_id, variant_id,
                                            &shader_size);
                 break;