[Mesa-dev] [PATCH 2/2] nir/validate: dump annotated shader with error msgs

Connor Abbott cwabbott0 at gmail.com
Sun May 15 16:48:14 UTC 2016


On Sat, May 14, 2016 at 3:47 PM, Rob Clark <robdclark at gmail.com> wrote:
> From: Rob Clark <robclark at freedesktop.org>
>
> Log all the errors, and at the end dump the shader w/ error annotations
> to make it easier to see where the problems are.
>
> Signed-off-by: Rob Clark <robclark at freedesktop.org>
> ---
>  src/compiler/nir/nir_validate.c | 58 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 58 insertions(+)
>
> diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c
> index 84334d4..a26f480 100644
> --- a/src/compiler/nir/nir_validate.c
> +++ b/src/compiler/nir/nir_validate.c
> @@ -69,6 +69,9 @@ typedef struct {
>     /* the current instruction being validated */
>     nir_instr *instr;
>
> +   /* the current variable being validated */
> +   nir_variable *var;
> +
>     /* the current basic block being validated */
>     nir_block *block;
>
> @@ -95,8 +98,29 @@ typedef struct {
>
>     /* map of local variable -> function implementation where it is defined */
>     struct hash_table *var_defs;
> +
> +   /* map of instruction/var/etc to failed assert string */
> +   struct hash_table *errors;
>  } validate_state;
>
> +static void
> +log_error(validate_state *state, const char *failed)
> +{
> +   const void *obj;
> +
> +   if (state->instr)
> +      obj = state->instr;
> +   else if (state->var)
> +      obj = state->var;
> +   else
> +      obj = failed;
> +
> +   _mesa_hash_table_insert(state->errors, obj, (void *)failed);
> +}
> +
> +#undef assert
> +#define assert(x) do { if (!(x)) log_error(state, "error: "#x); } while (0)

Redefining assert here, and also implicitly using "state", isn't so
great. I'd rather we first did s/assert(foo)/validate_assert(foo,
state)/ before this patch.

> +
>  static void validate_src(nir_src *src, validate_state *state);
>
>  static void
> @@ -901,6 +925,8 @@ postvalidate_reg_decl(nir_register *reg, validate_state *state)
>  static void
>  validate_var_decl(nir_variable *var, bool is_global, validate_state *state)
>  {
> +   state->var = var;
> +
>     assert(is_global == nir_variable_is_global(var));
>
>     /* Must have exactly one mode set */
> @@ -914,6 +940,8 @@ validate_var_decl(nir_variable *var, bool is_global, validate_state *state)
>     if (!is_global) {
>        _mesa_hash_table_insert(state->var_defs, var, state->impl);
>     }
> +
> +   state->var = NULL;
>  }
>
>  static bool
> @@ -1042,7 +1070,12 @@ init_validate_state(validate_state *state)
>     state->regs_found = NULL;
>     state->var_defs = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
>                                               _mesa_key_pointer_equal);
> +   state->errors = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
> +                                           _mesa_key_pointer_equal);
> +
>     state->loop = NULL;
> +   state->instr = NULL;
> +   state->var = NULL;
>  }
>
>  static void
> @@ -1053,6 +1086,28 @@ destroy_validate_state(validate_state *state)
>     free(state->ssa_defs_found);
>     free(state->regs_found);
>     _mesa_hash_table_destroy(state->var_defs, NULL);
> +   _mesa_hash_table_destroy(state->errors, NULL);
> +}
> +
> +static void
> +dump_errors(validate_state *state)
> +{
> +   struct hash_table *errors = state->errors;
> +
> +   fprintf(stderr, "%d errors:\n", _mesa_hash_table_num_entries(errors));
> +
> +   nir_print_shader_annotated(state->shader, stderr, errors);
> +
> +   if (_mesa_hash_table_num_entries(errors) > 0) {
> +      fprintf(stderr, "%d additional errors:\n",
> +              _mesa_hash_table_num_entries(errors));
> +      struct hash_entry *entry;
> +      hash_table_foreach(errors, entry) {
> +         fprintf(stderr, "%s\n", (char *)entry->data);
> +      }
> +   }
> +
> +   abort();
>  }
>
>  void
> @@ -1112,6 +1167,9 @@ nir_validate_shader(nir_shader *shader)
>        postvalidate_reg_decl(reg, &state);
>     }
>
> +   if (_mesa_hash_table_num_entries(state.errors) > 0)
> +      dump_errors(&state);
> +
>     destroy_validate_state(&state);
>  }
>
> --
> 2.5.5
>


More information about the mesa-dev mailing list