<div dir="ltr"><div>I did a quick skim. LGTM. Series is<br><br></div><div>Acked-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 16, 2016 at 4:46 PM, Connor Abbott <span dir="ltr"><<a href="mailto:cwabbott0@gmail.com" target="_blank">cwabbott0@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Mon, May 16, 2016 at 12:54 PM, Rob Clark <<a href="mailto:robdclark@gmail.com">robdclark@gmail.com</a>> wrote:<br>
> From: Rob Clark <<a href="mailto:robclark@freedesktop.org">robclark@freedesktop.org</a>><br>
><br>
> Log all the errors, and at the end dump the shader w/ error annotations<br>
> to make it easier to see where the problems are.<br>
><br>
> Signed-off-by: Rob Clark <<a href="mailto:robclark@freedesktop.org">robclark@freedesktop.org</a>><br>
> Reviewed-by: Eduardo Lima Mitev <<a href="mailto:elima@igalia.com">elima@igalia.com</a>><br>
> ---<br>
> src/compiler/nir/nir_validate.c | 60 ++++++++++++++++++++++++++++++++++++++++-<br>
> 1 file changed, 59 insertions(+), 1 deletion(-)<br>
><br>
> diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c<br>
> index 4e786d4..3e650df 100644<br>
> --- a/src/compiler/nir/nir_validate.c<br>
> +++ b/src/compiler/nir/nir_validate.c<br>
> @@ -69,6 +69,9 @@ typedef struct {<br>
> /* the current instruction being validated */<br>
> nir_instr *instr;<br>
><br>
> + /* the current variable being validated */<br>
> + nir_variable *var;<br>
> +<br>
> /* the current basic block being validated */<br>
> nir_block *block;<br>
><br>
> @@ -95,9 +98,30 @@ typedef struct {<br>
><br>
> /* map of local variable -> function implementation where it is defined */<br>
> struct hash_table *var_defs;<br>
> +<br>
> + /* map of instruction/var/etc to failed assert string */<br>
> + struct hash_table *errors;<br>
> } validate_state;<br>
><br>
> -#define validate_assert(state, cond) assert(cond)<br>
> +static void<br>
> +log_error(validate_state *state, const char *failed)<br>
> +{<br>
> + const void *obj;<br>
> +<br>
> + if (state->instr)<br>
> + obj = state->instr;<br>
> + else if (state->var)<br>
> + obj = state->var;<br>
> + else<br>
> + obj = failed;<br>
> +<br>
> + _mesa_hash_table_insert(state->errors, obj, (void *)failed);<br>
> +}<br>
> +<br>
> +#define validate_assert(state, cond) do { \<br>
> + if (!(cond)) \<br>
> + log_error(state, "error: "#cond); \<br>
<br>
</div></div>Maybe add the line number to make the assertion easier to find? Other<br>
than that the series gets my r-b.<br>
<div class="HOEnZb"><div class="h5"><br>
> + } while (0)<br>
><br>
> static void validate_src(nir_src *src, validate_state *state);<br>
><br>
> @@ -903,6 +927,8 @@ postvalidate_reg_decl(nir_register *reg, validate_state *state)<br>
> static void<br>
> validate_var_decl(nir_variable *var, bool is_global, validate_state *state)<br>
> {<br>
> + state->var = var;<br>
> +<br>
> validate_assert(state, is_global == nir_variable_is_global(var));<br>
><br>
> /* Must have exactly one mode set */<br>
> @@ -916,6 +942,8 @@ validate_var_decl(nir_variable *var, bool is_global, validate_state *state)<br>
> if (!is_global) {<br>
> _mesa_hash_table_insert(state->var_defs, var, state->impl);<br>
> }<br>
> +<br>
> + state->var = NULL;<br>
> }<br>
><br>
> static bool<br>
> @@ -1044,7 +1072,12 @@ init_validate_state(validate_state *state)<br>
> state->regs_found = NULL;<br>
> state->var_defs = _mesa_hash_table_create(NULL, _mesa_hash_pointer,<br>
> _mesa_key_pointer_equal);<br>
> + state->errors = _mesa_hash_table_create(NULL, _mesa_hash_pointer,<br>
> + _mesa_key_pointer_equal);<br>
> +<br>
> state->loop = NULL;<br>
> + state->instr = NULL;<br>
> + state->var = NULL;<br>
> }<br>
><br>
> static void<br>
> @@ -1055,6 +1088,28 @@ destroy_validate_state(validate_state *state)<br>
> free(state->ssa_defs_found);<br>
> free(state->regs_found);<br>
> _mesa_hash_table_destroy(state->var_defs, NULL);<br>
> + _mesa_hash_table_destroy(state->errors, NULL);<br>
> +}<br>
> +<br>
> +static void<br>
> +dump_errors(validate_state *state)<br>
> +{<br>
> + struct hash_table *errors = state->errors;<br>
> +<br>
> + fprintf(stderr, "%d errors:\n", _mesa_hash_table_num_entries(errors));<br>
> +<br>
> + nir_print_shader_annotated(state->shader, stderr, errors);<br>
> +<br>
> + if (_mesa_hash_table_num_entries(errors) > 0) {<br>
> + fprintf(stderr, "%d additional errors:\n",<br>
> + _mesa_hash_table_num_entries(errors));<br>
> + struct hash_entry *entry;<br>
> + hash_table_foreach(errors, entry) {<br>
> + fprintf(stderr, "%s\n", (char *)entry->data);<br>
> + }<br>
> + }<br>
> +<br>
> + abort();<br>
> }<br>
><br>
> void<br>
> @@ -1114,6 +1169,9 @@ nir_validate_shader(nir_shader *shader)<br>
> postvalidate_reg_decl(reg, &state);<br>
> }<br>
><br>
> + if (_mesa_hash_table_num_entries(state.errors) > 0)<br>
> + dump_errors(&state);<br>
> +<br>
> destroy_validate_state(&state);<br>
> }<br>
><br>
> --<br>
> 2.5.5<br>
><br>
</div></div></blockquote></div><br></div>