diff --git a/src/compiler/nir/nir_opt_dce.c b/src/compiler/nir/nir_opt_dce.c index a24877bf272..0e89627455d 100644 --- a/src/compiler/nir/nir_opt_dce.c +++ b/src/compiler/nir/nir_opt_dce.c @@ -114,6 +114,17 @@ struct loop_state { static void remove_instr(nir_instr *instr, struct exec_list *dead_instrs) { +#ifndef NDEBUG + /* Fail an assertion if an input load is dead. This is a debug option. */ + if (instr->type == nir_instr_type_intrinsic) { + nir_shader *nir = + nir_cf_node_get_function(&instr->block->cf_node)->function->shader; + + if (nir->info.assert_inputs_not_dead) + assert(!nir_is_input_load(nir_instr_as_intrinsic(instr))); + } +#endif + nir_instr_remove(instr); exec_list_push_tail(dead_instrs, &instr->node); } diff --git a/src/compiler/shader_info.h b/src/compiler/shader_info.h index 65e95699345..e082d7adf27 100644 --- a/src/compiler/shader_info.h +++ b/src/compiler/shader_info.h @@ -258,6 +258,17 @@ typedef struct shader_info { */ bool io_lowered:1; + /* If true, fail an assertion in nir_opt_dce if a dead input is eliminated. + * + * This is a debug aid to easily identify passes that cause shader inputs + * to become dead after nir_opt_varyings when it's preferrable that dead + * shader inputs are identified before nir_opt_varyings. + * + * It shouldn't be enabled by default because inputs can become dead late + * for all sorts of reasons. + */ + bool assert_inputs_not_dead : 1; + /** Has nir_lower_var_copies called. To avoid calling any * lowering/optimization that would introduce any copy_deref later. */