From 0a77c674423a5c291b0aa9964590dd67ca40d36a Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Tue, 21 Jul 2020 09:51:05 -0500 Subject: [PATCH] nir/lower_io_to_temporaries: Use a separate list for new inputs Part-of: --- .../nir/nir_lower_io_to_temporaries.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/compiler/nir/nir_lower_io_to_temporaries.c b/src/compiler/nir/nir_lower_io_to_temporaries.c index a3ee6e4ed6a..ae5f64dcef2 100644 --- a/src/compiler/nir/nir_lower_io_to_temporaries.c +++ b/src/compiler/nir/nir_lower_io_to_temporaries.c @@ -39,6 +39,8 @@ struct lower_io_state { nir_function_impl *entrypoint; struct exec_list old_outputs; struct exec_list old_inputs; + struct exec_list new_outputs; + struct exec_list new_inputs; /* map from temporary to new input */ struct hash_table *input_map; @@ -92,13 +94,13 @@ emit_output_copies_impl(struct lower_io_state *state, nir_function_impl *impl) if (intrin->intrinsic == nir_intrinsic_emit_vertex || intrin->intrinsic == nir_intrinsic_emit_vertex_with_counter) { b.cursor = nir_before_instr(&intrin->instr); - emit_copies(&b, &state->shader->outputs, &state->old_outputs); + emit_copies(&b, &state->new_outputs, &state->old_outputs); } } } } else if (impl == state->entrypoint) { b.cursor = nir_before_block(nir_start_block(impl)); - emit_copies(&b, &state->old_outputs, &state->shader->outputs); + emit_copies(&b, &state->old_outputs, &state->new_outputs); /* For all other shader types, we need to do the copies right before * the jumps to the end block. @@ -106,7 +108,7 @@ emit_output_copies_impl(struct lower_io_state *state, nir_function_impl *impl) set_foreach(impl->end_block->predecessors, block_entry) { struct nir_block *block = (void *)block_entry->key; b.cursor = nir_after_block_before_jump(block); - emit_copies(&b, &state->shader->outputs, &state->old_outputs); + emit_copies(&b, &state->new_outputs, &state->old_outputs); } } } @@ -278,7 +280,7 @@ emit_input_copies_impl(struct lower_io_state *state, nir_function_impl *impl) nir_builder b; nir_builder_init(&b, impl); b.cursor = nir_before_block(nir_start_block(impl)); - emit_copies(&b, &state->old_inputs, &state->shader->inputs); + emit_copies(&b, &state->old_inputs, &state->new_inputs); if (state->shader->info.stage == MESA_SHADER_FRAGMENT) fixup_interpolation(state, impl, &b); } @@ -333,18 +335,21 @@ nir_lower_io_to_temporaries(nir_shader *shader, nir_function_impl *entrypoint, else exec_list_make_empty(&state.old_outputs); + exec_list_make_empty(&state.new_inputs); + exec_list_make_empty(&state.new_outputs); + /* Walk over all of the outputs turn each output into a temporary and * make a new variable for the actual output. */ nir_foreach_variable(var, &state.old_outputs) { nir_variable *output = create_shadow_temp(&state, var); - exec_list_push_tail(&shader->outputs, &output->node); + exec_list_push_tail(&state.new_outputs, &output->node); } /* and same for inputs: */ nir_foreach_variable(var, &state.old_inputs) { nir_variable *input = create_shadow_temp(&state, var); - exec_list_push_tail(&shader->inputs, &input->node); + exec_list_push_tail(&state.new_inputs, &input->node); _mesa_hash_table_insert(state.input_map, var, input); } @@ -362,6 +367,8 @@ nir_lower_io_to_temporaries(nir_shader *shader, nir_function_impl *entrypoint, nir_metadata_dominance); } + exec_list_append(&shader->inputs, &state.new_inputs); + exec_list_append(&shader->outputs, &state.new_outputs); exec_list_append(&shader->globals, &state.old_inputs); exec_list_append(&shader->globals, &state.old_outputs); -- 2.30.2