<p dir="ltr"><br>
On May 14, 2016 12:48 PM, "Rob Clark" <<a href="mailto:robdclark@gmail.com">robdclark@gmail.com</a>> wrote:<br>
><br>
> From: Rob Clark <<a href="mailto:robclark@freedesktop.org">robclark@freedesktop.org</a>><br>
><br>
> Caller can pass a hashtable mapping NIR object (currently instr or var,<br>
> but I guess others could be added as needed) to annotation msg to print<br>
> inline with the shader dump. As the annotation msg is printed, it is<br>
> removed from the hashtable to give the caller a way to know about any<br>
> unassociated msgs.<br>
><br>
> This is used in the next patch, for nir_validate to try to associate<br>
> error msgs to nir_print dump.<br>
><br>
> Signed-off-by: Rob Clark <<a href="mailto:robclark@freedesktop.org">robclark@freedesktop.org</a>><br>
> ---<br>
> src/compiler/nir/nir.h | 1 +<br>
> src/compiler/nir/nir_print.c | 41 ++++++++++++++++++++++++++++++++++++++++-<br>
> 2 files changed, 41 insertions(+), 1 deletion(-)<br>
><br>
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h<br>
> index ade584c..5f2cc8e 100644<br>
> --- a/src/compiler/nir/nir.h<br>
> +++ b/src/compiler/nir/nir.h<br>
> @@ -2196,6 +2196,7 @@ unsigned nir_index_instrs(nir_function_impl *impl);<br>
> void nir_index_blocks(nir_function_impl *impl);<br>
><br>
> void nir_print_shader(nir_shader *shader, FILE *fp);<br>
> +void nir_print_shader_annotated(nir_shader *shader, FILE *fp, struct hash_table *errors);<br>
> void nir_print_instr(const nir_instr *instr, FILE *fp);<br>
><br>
> nir_shader *nir_shader_clone(void *mem_ctx, const nir_shader *s);<br>
> diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c<br>
> index a36561e..70ed73f 100644<br>
> --- a/src/compiler/nir/nir_print.c<br>
> +++ b/src/compiler/nir/nir_print.c<br>
> @@ -53,8 +53,28 @@ typedef struct {<br>
><br>
> /* an index used to make new non-conflicting names */<br>
> unsigned index;<br>
> +<br>
> + /**<br>
> + * Optional table of annotations mapping nir object<br>
> + * (such as instr or var) to message to print.<br>
> + */<br>
> + struct hash_table *annotations;<br>
> } print_state;<br>
><br>
> +static const char *<br>
> +get_annotation(print_state *state, void *obj)<br>
> +{<br>
> + if (!state->annotations)<br>
> + return NULL;<br>
> +<br>
> + struct hash_entry *entry = _mesa_hash_table_search(state->annotations, obj);<br>
> + if (entry) {<br>
> + _mesa_hash_table_remove(state->annotations, entry);<br>
> + return entry->data;<br>
> + }<br>
> + return NULL;<br>
> +}<br>
> +<br>
> static void<br>
> print_register(nir_register *reg, print_state *state)<br>
> {<br>
> @@ -413,6 +433,11 @@ print_var_decl(nir_variable *var, print_state *state)<br>
> }<br>
><br>
> fprintf(fp, "\n");<br>
> +<br>
> + const char *note = get_annotation(state, var);<br>
> + if (note) {<br>
> + fprintf(stderr, "%s\n", note);<br>
> + }<br>
> }<br>
><br>
> static void<br>
> @@ -918,6 +943,11 @@ print_block(nir_block *block, print_state *state, unsigned tabs)<br>
> nir_foreach_instr(instr, block) {<br>
> print_instr(instr, state, tabs);<br>
> fprintf(fp, "\n");<br>
> +<br>
> + const char *note = get_annotation(state, instr);<br>
> + if (note) {<br>
> + fprintf(stderr, "%s\n", note);<br>
> + }</p>
<p dir="ltr">How about you just roll this into get_annotation and call it print_annotation?</p>
<p dir="ltr">> }<br>
><br>
> print_tabs(tabs, fp);<br>
> @@ -1090,11 +1120,14 @@ destroy_print_state(print_state *state)<br>
> }<br>
><br>
> void<br>
> -nir_print_shader(nir_shader *shader, FILE *fp)<br>
> +nir_print_shader_annotated(nir_shader *shader, FILE *fp,<br>
> + struct hash_table *annotations)<br>
> {<br>
> print_state state;<br>
> init_print_state(&state, shader, fp);<br>
><br>
> + state.annotations = annotations;<br>
> +<br>
> fprintf(fp, "shader: %s\n", gl_shader_stage_name(shader->stage));<br>
><br>
> if (shader-><a href="http://info.name">info.name</a>)<br>
> @@ -1144,6 +1177,12 @@ nir_print_shader(nir_shader *shader, FILE *fp)<br>
> }<br>
><br>
> void<br>
> +nir_print_shader(nir_shader *shader, FILE *fp)<br>
> +{<br>
> + nir_print_shader_annotated(shader, fp, NULL);<br>
> +}<br>
> +<br>
> +void<br>
> nir_print_instr(const nir_instr *instr, FILE *fp)<br>
> {<br>
> print_state state = {<br>
> --<br>
> 2.5.5<br>
><br>
</p>