summaryrefslogtreecommitdiffstats
path: root/src/compiler/nir
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/nir')
-rw-r--r--src/compiler/nir/nir.h12
-rw-r--r--src/compiler/nir/nir_validate.c14
-rw-r--r--src/compiler/nir/tests/vars_tests.cpp38
3 files changed, 35 insertions, 29 deletions
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 60ea4fbc7ff..a0ae9a4430e 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2664,7 +2664,7 @@ nir_variable *nir_variable_clone(const nir_variable *c, nir_shader *shader);
nir_shader *nir_shader_serialize_deserialize(void *mem_ctx, nir_shader *s);
#ifndef NDEBUG
-void nir_validate_shader(nir_shader *shader);
+void nir_validate_shader(nir_shader *shader, const char *when);
void nir_metadata_set_validation_flag(nir_shader *shader);
void nir_metadata_check_validation_flag(nir_shader *shader);
@@ -2698,7 +2698,7 @@ should_print_nir(void)
return should_print;
}
#else
-static inline void nir_validate_shader(nir_shader *shader) { (void) shader; }
+static inline void nir_validate_shader(nir_shader *shader, const char *when) { (void) shader; (void)when; }
static inline void nir_metadata_set_validation_flag(nir_shader *shader) { (void) shader; }
static inline void nir_metadata_check_validation_flag(nir_shader *shader) { (void) shader; }
static inline bool should_clone_nir(void) { return false; }
@@ -2706,9 +2706,9 @@ static inline bool should_serialize_deserialize_nir(void) { return false; }
static inline bool should_print_nir(void) { return false; }
#endif /* NDEBUG */
-#define _PASS(nir, do_pass) do { \
+#define _PASS(pass, nir, do_pass) do { \
do_pass \
- nir_validate_shader(nir); \
+ nir_validate_shader(nir, "after " #pass); \
if (should_clone_nir()) { \
nir_shader *clone = nir_shader_clone(ralloc_parent(nir), nir); \
ralloc_free(nir); \
@@ -2720,7 +2720,7 @@ static inline bool should_print_nir(void) { return false; }
} \
} while (0)
-#define NIR_PASS(progress, nir, pass, ...) _PASS(nir, \
+#define NIR_PASS(progress, nir, pass, ...) _PASS(pass, nir, \
nir_metadata_set_validation_flag(nir); \
if (should_print_nir()) \
printf("%s\n", #pass); \
@@ -2732,7 +2732,7 @@ static inline bool should_print_nir(void) { return false; }
} \
)
-#define NIR_PASS_V(nir, pass, ...) _PASS(nir, \
+#define NIR_PASS_V(nir, pass, ...) _PASS(pass, nir, \
if (should_print_nir()) \
printf("%s\n", #pass); \
pass(nir, ##__VA_ARGS__); \
diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c
index cf7ef91f08c..62893cad87e 100644
--- a/src/compiler/nir/nir_validate.c
+++ b/src/compiler/nir/nir_validate.c
@@ -1140,11 +1140,17 @@ destroy_validate_state(validate_state *state)
}
static void
-dump_errors(validate_state *state)
+dump_errors(validate_state *state, const char *when)
{
struct hash_table *errors = state->errors;
- fprintf(stderr, "%d errors:\n", _mesa_hash_table_num_entries(errors));
+ if (when) {
+ fprintf(stderr, "NIR validation failed %s\n", when);
+ fprintf(stderr, "%d errors:\n", _mesa_hash_table_num_entries(errors));
+ } else {
+ fprintf(stderr, "NIR validation failed with %d errors:\n",
+ _mesa_hash_table_num_entries(errors));
+ }
nir_print_shader_annotated(state->shader, stderr, errors);
@@ -1160,7 +1166,7 @@ dump_errors(validate_state *state)
}
void
-nir_validate_shader(nir_shader *shader)
+nir_validate_shader(nir_shader *shader, const char *when)
{
static int should_validate = -1;
if (should_validate < 0)
@@ -1223,7 +1229,7 @@ nir_validate_shader(nir_shader *shader)
}
if (_mesa_hash_table_num_entries(state.errors) > 0)
- dump_errors(&state);
+ dump_errors(&state, when);
destroy_validate_state(&state);
}
diff --git a/src/compiler/nir/tests/vars_tests.cpp b/src/compiler/nir/tests/vars_tests.cpp
index a7bbeb02277..32763d2db64 100644
--- a/src/compiler/nir/tests/vars_tests.cpp
+++ b/src/compiler/nir/tests/vars_tests.cpp
@@ -147,14 +147,14 @@ TEST_F(nir_redundant_load_vars_test, duplicated_load)
nir_store_var(b, out[0], nir_load_var(b, in), 1);
nir_store_var(b, out[1], nir_load_var(b, in), 1);
- nir_validate_shader(b->shader);
+ nir_validate_shader(b->shader, NULL);
ASSERT_EQ(count_intrinsics(nir_intrinsic_load_deref), 2);
bool progress = nir_opt_copy_prop_vars(b->shader);
EXPECT_TRUE(progress);
- nir_validate_shader(b->shader);
+ nir_validate_shader(b->shader, NULL);
ASSERT_EQ(count_intrinsics(nir_intrinsic_load_deref), 1);
}
@@ -173,14 +173,14 @@ TEST_F(nir_redundant_load_vars_test, duplicated_load_in_two_blocks)
nir_store_var(b, out[1], nir_load_var(b, in), 1);
- nir_validate_shader(b->shader);
+ nir_validate_shader(b->shader, NULL);
ASSERT_EQ(count_intrinsics(nir_intrinsic_load_deref), 2);
bool progress = nir_opt_copy_prop_vars(b->shader);
EXPECT_TRUE(progress);
- nir_validate_shader(b->shader);
+ nir_validate_shader(b->shader, NULL);
ASSERT_EQ(count_intrinsics(nir_intrinsic_load_deref), 1);
}
@@ -210,7 +210,7 @@ TEST_F(nir_redundant_load_vars_test, invalidate_inside_if_block)
nir_store_var(b, out[1], nir_load_var(b, g[1]), 1);
nir_store_var(b, out[2], nir_load_var(b, g[2]), 1);
- nir_validate_shader(b->shader);
+ nir_validate_shader(b->shader, NULL);
bool progress = nir_opt_copy_prop_vars(b->shader);
EXPECT_TRUE(progress);
@@ -265,12 +265,12 @@ TEST_F(nir_copy_prop_vars_test, simple_copies)
nir_copy_var(b, temp, in);
nir_copy_var(b, out, temp);
- nir_validate_shader(b->shader);
+ nir_validate_shader(b->shader, NULL);
bool progress = nir_opt_copy_prop_vars(b->shader);
EXPECT_TRUE(progress);
- nir_validate_shader(b->shader);
+ nir_validate_shader(b->shader, NULL);
nir_intrinsic_instr *copy = NULL;
copy = find_next_intrinsic(nir_intrinsic_copy_deref, copy);
@@ -293,12 +293,12 @@ TEST_F(nir_copy_prop_vars_test, simple_store_load)
nir_ssa_def *read_value = nir_load_var(b, v[0]);
nir_store_var(b, v[1], read_value, mask);
- nir_validate_shader(b->shader);
+ nir_validate_shader(b->shader, NULL);
bool progress = nir_opt_copy_prop_vars(b->shader);
EXPECT_TRUE(progress);
- nir_validate_shader(b->shader);
+ nir_validate_shader(b->shader, NULL);
ASSERT_EQ(count_intrinsics(nir_intrinsic_store_deref), 2);
@@ -324,12 +324,12 @@ TEST_F(nir_copy_prop_vars_test, store_store_load)
nir_ssa_def *read_value = nir_load_var(b, v[0]);
nir_store_var(b, v[1], read_value, mask);
- nir_validate_shader(b->shader);
+ nir_validate_shader(b->shader, NULL);
bool progress = nir_opt_copy_prop_vars(b->shader);
EXPECT_TRUE(progress);
- nir_validate_shader(b->shader);
+ nir_validate_shader(b->shader, NULL);
/* Store to v[1] should use second_value directly. */
nir_intrinsic_instr *store_to_v1 = NULL;
@@ -356,15 +356,15 @@ TEST_F(nir_copy_prop_vars_test, store_store_load_different_components)
nir_ssa_def *read_value = nir_load_var(b, v[0]);
nir_store_var(b, v[1], read_value, 1 << 1);
- nir_validate_shader(b->shader);
+ nir_validate_shader(b->shader, NULL);
bool progress = nir_opt_copy_prop_vars(b->shader);
EXPECT_TRUE(progress);
- nir_validate_shader(b->shader);
+ nir_validate_shader(b->shader, NULL);
nir_opt_constant_folding(b->shader);
- nir_validate_shader(b->shader);
+ nir_validate_shader(b->shader, NULL);
/* Store to v[1] should use first_value directly. The write of
* second_value did not overwrite the component it uses.
@@ -401,7 +401,7 @@ TEST_F(nir_copy_prop_vars_test, store_store_load_different_components_in_many_bl
nir_ssa_def *read_value = nir_load_var(b, v[0]);
nir_store_var(b, v[1], read_value, 1 << 1);
- nir_validate_shader(b->shader);
+ nir_validate_shader(b->shader, NULL);
nir_print_shader(b->shader, stdout);
@@ -410,10 +410,10 @@ TEST_F(nir_copy_prop_vars_test, store_store_load_different_components_in_many_bl
nir_print_shader(b->shader, stdout);
- nir_validate_shader(b->shader);
+ nir_validate_shader(b->shader, NULL);
nir_opt_constant_folding(b->shader);
- nir_validate_shader(b->shader);
+ nir_validate_shader(b->shader, NULL);
/* Store to v[1] should use first_value directly. The write of
* second_value did not overwrite the component it uses.
@@ -471,12 +471,12 @@ TEST_F(nir_copy_prop_vars_test, simple_store_load_in_two_blocks)
nir_ssa_def *read_value = nir_load_var(b, v[0]);
nir_store_var(b, v[1], read_value, mask);
- nir_validate_shader(b->shader);
+ nir_validate_shader(b->shader, NULL);
bool progress = nir_opt_copy_prop_vars(b->shader);
EXPECT_TRUE(progress);
- nir_validate_shader(b->shader);
+ nir_validate_shader(b->shader, NULL);
ASSERT_EQ(count_intrinsics(nir_intrinsic_store_deref), 2);