From 5746af444606b77e30309d5b85bc116d64df2cf4 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 20 May 2020 10:09:05 -0500 Subject: [PATCH 1/1] nir: Take a mode in remove_unused_io_vars Reviewed-by: Jose Maria Casanova Crespo Part-of: --- src/broadcom/compiler/vir.c | 4 ++-- src/compiler/nir/nir.h | 2 +- src/compiler/nir/nir_linking_helpers.c | 14 +++++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/broadcom/compiler/vir.c b/src/broadcom/compiler/vir.c index 749a38f6028..4482f7825a6 100644 --- a/src/broadcom/compiler/vir.c +++ b/src/broadcom/compiler/vir.c @@ -809,7 +809,7 @@ v3d_nir_lower_vs_early(struct v3d_compile *c) used_outputs[comp] |= 1ull << slot; } NIR_PASS_V(c->s, nir_remove_unused_io_vars, - &c->s->outputs, used_outputs, NULL); /* demotes to globals */ + nir_var_shader_out, used_outputs, NULL); /* demotes to globals */ NIR_PASS_V(c->s, nir_lower_global_vars_to_local); v3d_optimize_nir(c->s); NIR_PASS_V(c->s, nir_remove_dead_variables, nir_var_shader_in, NULL); @@ -840,7 +840,7 @@ v3d_nir_lower_gs_early(struct v3d_compile *c) used_outputs[comp] |= 1ull << slot; } NIR_PASS_V(c->s, nir_remove_unused_io_vars, - &c->s->outputs, used_outputs, NULL); /* demotes to globals */ + nir_var_shader_out, used_outputs, NULL); /* demotes to globals */ NIR_PASS_V(c->s, nir_lower_global_vars_to_local); v3d_optimize_nir(c->s); NIR_PASS_V(c->s, nir_remove_dead_variables, nir_var_shader_in, NULL); diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 71143ffb0fc..02d0a6000da 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -3941,7 +3941,7 @@ void nir_assign_var_locations(struct exec_list *var_list, unsigned *size, /* Some helpers to do very simple linking */ bool nir_remove_unused_varyings(nir_shader *producer, nir_shader *consumer); -bool nir_remove_unused_io_vars(nir_shader *shader, struct exec_list *var_list, +bool nir_remove_unused_io_vars(nir_shader *shader, nir_variable_mode mode, uint64_t *used_by_other_stage, uint64_t *used_by_other_stage_patches); void nir_compact_varyings(nir_shader *producer, nir_shader *consumer, diff --git a/src/compiler/nir/nir_linking_helpers.c b/src/compiler/nir/nir_linking_helpers.c index e626326c7a5..74508440eb1 100644 --- a/src/compiler/nir/nir_linking_helpers.c +++ b/src/compiler/nir/nir_linking_helpers.c @@ -109,8 +109,7 @@ tcs_add_output_reads(nir_shader *shader, uint64_t *read, uint64_t *patches_read) * * Example usage is: * - * progress = nir_remove_unused_io_vars(producer, - * &producer->outputs, + * progress = nir_remove_unused_io_vars(producer, nir_var_shader_out, * read, patches_read) || * progress; * @@ -120,13 +119,18 @@ tcs_add_output_reads(nir_shader *shader, uint64_t *read, uint64_t *patches_read) * variable is used! */ bool -nir_remove_unused_io_vars(nir_shader *shader, struct exec_list *var_list, +nir_remove_unused_io_vars(nir_shader *shader, + nir_variable_mode mode, uint64_t *used_by_other_stage, uint64_t *used_by_other_stage_patches) { bool progress = false; uint64_t *used; + assert(mode == nir_var_shader_in || mode == nir_var_shader_out); + struct exec_list *var_list = + mode == nir_var_shader_in ? &shader->inputs : &shader->outputs; + nir_foreach_variable_safe(var, var_list) { if (var->data.patch) used = used_by_other_stage_patches; @@ -203,10 +207,10 @@ nir_remove_unused_varyings(nir_shader *producer, nir_shader *consumer) tcs_add_output_reads(producer, read, patches_read); bool progress = false; - progress = nir_remove_unused_io_vars(producer, &producer->outputs, read, + progress = nir_remove_unused_io_vars(producer, nir_var_shader_out, read, patches_read); - progress = nir_remove_unused_io_vars(consumer, &consumer->inputs, written, + progress = nir_remove_unused_io_vars(consumer, nir_var_shader_in, written, patches_written) || progress; return progress; -- 2.30.2