--- src/amd/vulkan/radv_shader.c | 4 +-- src/compiler/nir/nir.h | 12 +++---- src/compiler/nir/nir_validate.c | 14 ++++++--- src/compiler/nir/tests/vars_tests.cpp | 38 +++++++++++------------ src/intel/compiler/brw_nir.c | 8 ++--- src/intel/vulkan/anv_pipeline.c | 2 +- src/mesa/drivers/dri/i965/brw_program.c | 4 +-- src/mesa/main/glspirv.c | 2 +- src/mesa/state_tracker/st_glsl_to_nir.cpp | 2 +- 9 files changed, 46 insertions(+), 40 deletions(-)
diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c index 15c9de1e020..edeaefbc1a2 100644 --- a/src/amd/vulkan/radv_shader.c +++ b/src/amd/vulkan/radv_shader.c @@ -189,7 +189,7 @@ radv_shader_compile_to_nir(struct radv_device *device, * and just use the NIR shader */ nir = module->nir; nir->options = &nir_options; - nir_validate_shader(nir); + nir_validate_shader(nir, "in internal shader"); assert(exec_list_length(&nir->functions) == 1); struct exec_node *node = exec_list_get_head(&nir->functions); @@ -251,7 +251,7 @@ radv_shader_compile_to_nir(struct radv_device *device, &spirv_options, &nir_options); nir = entry_point->shader; assert(nir->info.stage == stage); - nir_validate_shader(nir); + nir_validate_shader(nir, "after spirv_to_nir"); free(spec_entries); diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 0ba19cbb25d..93d0fb5271c 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 1852224b520..60d64f9c7a1 100644 --- a/src/compiler/nir/nir_validate.c +++ b/src/compiler/nir/nir_validate.c @@ -1146,11 +1146,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); @@ -1167,7 +1173,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) @@ -1230,7 +1236,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 02c53804b84..18c38334296 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); diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c index 297845b89b7..1cd56861578 100644 --- a/src/intel/compiler/brw_nir.c +++ b/src/intel/compiler/brw_nir.c @@ -725,8 +725,8 @@ brw_nir_link_shaders(const struct brw_compiler *compiler, nir_shader **producer, nir_shader **consumer) { nir_lower_io_arrays_to_elements(*producer, *consumer); - nir_validate_shader(*producer); - nir_validate_shader(*consumer); + nir_validate_shader(*producer, "after nir_lower_io_arrays_to_elements"); + nir_validate_shader(*consumer, "after nir_lower_io_arrays_to_elements"); const bool p_is_scalar = compiler->scalar_stage[(*producer)->info.stage]; @@ -879,7 +879,7 @@ brw_nir_apply_sampler_key(nir_shader *nir, tex_options.lower_xy_uxvx_external = key_tex->xy_uxvx_image_mask; if (nir_lower_tex(nir, &tex_options)) { - nir_validate_shader(nir); + nir_validate_shader(nir, "after nir_lower_tex"); nir = brw_nir_optimize(nir, compiler, is_scalar, false); } @@ -1034,7 +1034,7 @@ brw_nir_create_passthrough_tcs(void *mem_ctx, const struct brw_compiler *compile varyings &= ~BITFIELD64_BIT(varying); } - nir_validate_shader(nir); + nir_validate_shader(nir, "in brw_nir_create_passthrough_tcs"); nir = brw_preprocess_nir(compiler, nir); diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c index be05c11f45d..7c9b1230115 100644 --- a/src/intel/vulkan/anv_pipeline.c +++ b/src/intel/vulkan/anv_pipeline.c @@ -165,7 +165,7 @@ anv_shader_compile_to_nir(struct anv_pipeline *pipeline, stage, entrypoint_name, &spirv_options, nir_options); nir_shader *nir = entry_point->shader; assert(nir->info.stage == stage); - nir_validate_shader(nir); + nir_validate_shader(nir, "after spirv_to_nir"); ralloc_steal(mem_ctx, nir); free(spec_entries); diff --git a/src/mesa/drivers/dri/i965/brw_program.c b/src/mesa/drivers/dri/i965/brw_program.c index f5ebd3c3b05..78050cda359 100644 --- a/src/mesa/drivers/dri/i965/brw_program.c +++ b/src/mesa/drivers/dri/i965/brw_program.c @@ -91,14 +91,14 @@ brw_create_nir(struct brw_context *brw, nir_remove_dead_variables(nir, nir_var_shader_in | nir_var_shader_out); nir_lower_returns(nir); - nir_validate_shader(nir); + nir_validate_shader(nir, NULL); NIR_PASS_V(nir, nir_lower_io_to_temporaries, nir_shader_get_entrypoint(nir), true, false); } else { nir = prog_to_nir(prog, options); NIR_PASS_V(nir, nir_lower_regs_to_ssa); /* turn registers into SSA */ } - nir_validate_shader(nir); + nir_validate_shader(nir, NULL); nir = brw_preprocess_nir(brw->screen->compiler, nir); diff --git a/src/mesa/main/glspirv.c b/src/mesa/main/glspirv.c index 972989055e9..98b7ea77348 100644 --- a/src/mesa/main/glspirv.c +++ b/src/mesa/main/glspirv.c @@ -234,7 +234,7 @@ _mesa_spirv_to_nir(struct gl_context *ctx, ralloc_asprintf(nir, "SPIRV:%s:%d", _mesa_shader_stage_to_abbrev(nir->info.stage), prog->Name); - nir_validate_shader(nir); + nir_validate_shader(nir, "after spirv_to_nir"); nir->info.separate_shader = linked_shader->Program->info.separate_shader; diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp index 911284401e0..fe85eeb458d 100644 --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp @@ -721,7 +721,7 @@ st_link_nir(struct gl_context *ctx, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER); if (nir_lower_wpos_ytransform(nir, &wpos_options)) { - nir_validate_shader(nir); + nir_validate_shader(nir, "after nir_lower_wpos_ytransform"); _mesa_add_state_reference(shader->Program->Parameters, wposTransformState); } -- 2.19.1 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev