[Mesa-dev] [PATCH 1/3] nir/print: add support for print annotations

Rob Clark robdclark at gmail.com
Mon May 16 16:54:45 UTC 2016


From: Rob Clark <robclark at freedesktop.org>

Caller can pass a hashtable mapping NIR object (currently instr or var,
but I guess others could be added as needed) to annotation msg to print
inline with the shader dump.  As the annotation msg is printed, it is
removed from the hashtable to give the caller a way to know about any
unassociated msgs.

This is used in the next patch, for nir_validate to try to associate
error msgs to nir_print dump.

Signed-off-by: Rob Clark <robclark at freedesktop.org>
Reviewed-by: Eduardo Lima Mitev <elima at igalia.com>
---
 src/compiler/nir/nir.h       |  1 +
 src/compiler/nir/nir_print.c | 35 ++++++++++++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 2227910..594d5da 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2207,6 +2207,7 @@ unsigned nir_index_instrs(nir_function_impl *impl);
 void nir_index_blocks(nir_function_impl *impl);
 
 void nir_print_shader(nir_shader *shader, FILE *fp);
+void nir_print_shader_annotated(nir_shader *shader, FILE *fp, struct hash_table *errors);
 void nir_print_instr(const nir_instr *instr, FILE *fp);
 
 nir_shader *nir_shader_clone(void *mem_ctx, const nir_shader *s);
diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c
index 583f66c..021f0d6 100644
--- a/src/compiler/nir/nir_print.c
+++ b/src/compiler/nir/nir_print.c
@@ -53,9 +53,31 @@ typedef struct {
 
    /* an index used to make new non-conflicting names */
    unsigned index;
+
+   /**
+    * Optional table of annotations mapping nir object
+    * (such as instr or var) to message to print.
+    */
+   struct hash_table *annotations;
 } print_state;
 
 static void
+print_annotation(print_state *state, void *obj)
+{
+   if (!state->annotations)
+      return;
+
+   struct hash_entry *entry = _mesa_hash_table_search(state->annotations, obj);
+   if (!entry)
+      return;
+
+   const char *note = entry->data;
+   _mesa_hash_table_remove(state->annotations, entry);
+
+   fprintf(stderr, "%s\n\n", note);
+}
+
+static void
 print_register(nir_register *reg, print_state *state)
 {
    FILE *fp = state->fp;
@@ -413,6 +435,7 @@ print_var_decl(nir_variable *var, print_state *state)
    }
 
    fprintf(fp, "\n");
+   print_annotation(state, var);
 }
 
 static void
@@ -924,6 +947,7 @@ print_block(nir_block *block, print_state *state, unsigned tabs)
    nir_foreach_instr(instr, block) {
       print_instr(instr, state, tabs);
       fprintf(fp, "\n");
+      print_annotation(state, instr);
    }
 
    print_tabs(tabs, fp);
@@ -1096,11 +1120,14 @@ destroy_print_state(print_state *state)
 }
 
 void
-nir_print_shader(nir_shader *shader, FILE *fp)
+nir_print_shader_annotated(nir_shader *shader, FILE *fp,
+                           struct hash_table *annotations)
 {
    print_state state;
    init_print_state(&state, shader, fp);
 
+   state.annotations = annotations;
+
    fprintf(fp, "shader: %s\n", gl_shader_stage_name(shader->stage));
 
    if (shader->info.name)
@@ -1150,6 +1177,12 @@ nir_print_shader(nir_shader *shader, FILE *fp)
 }
 
 void
+nir_print_shader(nir_shader *shader, FILE *fp)
+{
+   nir_print_shader_annotated(shader, fp, NULL);
+}
+
+void
 nir_print_instr(const nir_instr *instr, FILE *fp)
 {
    print_state state = {
-- 
2.5.5



More information about the mesa-dev mailing list