summaryrefslogtreecommitdiffstats
path: root/src/compiler/nir/nir_validate.c
diff options
context:
space:
mode:
authorRob Clark <[email protected]>2016-05-14 15:40:54 -0400
committerRob Clark <[email protected]>2016-05-17 10:05:20 -0400
commite8beffb1b3e989035b49b79a76b58f8cbf446ea4 (patch)
tree4a38ae44dc5a0bb5121be4740a30383dbdd6c8bc /src/compiler/nir/nir_validate.c
parent54ecfcc162fd1598e49c7f7aba9b0fde7f4a97e2 (diff)
nir/validate: dump annotated shader with error msgs
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 <[email protected]> Reviewed-by: Eduardo Lima Mitev <[email protected]> Reviewed-by: Connor Abbott <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir_validate.c')
-rw-r--r--src/compiler/nir/nir_validate.c63
1 files changed, 62 insertions, 1 deletions
diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c
index 4e786d4dfe8..b186fd5bf51 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,9 +98,33 @@ 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;
-#define validate_assert(state, cond) assert(cond)
+static void
+log_error(validate_state *state, const char *cond, const char *file, int line)
+{
+ const void *obj;
+
+ if (state->instr)
+ obj = state->instr;
+ else if (state->var)
+ obj = state->var;
+ else
+ obj = cond;
+
+ char *msg = ralloc_asprintf(state->errors, "error: %s (%s:%d)",
+ cond, file, line);
+
+ _mesa_hash_table_insert(state->errors, obj, msg);
+}
+
+#define validate_assert(state, cond) do { \
+ if (!(cond)) \
+ log_error(state, #cond, __FILE__, __LINE__); \
+ } while (0)
static void validate_src(nir_src *src, validate_state *state);
@@ -903,6 +930,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;
+
validate_assert(state, is_global == nir_variable_is_global(var));
/* Must have exactly one mode set */
@@ -916,6 +945,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
@@ -1044,7 +1075,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
@@ -1055,6 +1091,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
@@ -1114,6 +1172,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);
}