+ /* Set the next shader stage hint for VS and TES. */
+ if (!nir->info.separate_shader &&
+ (nir->info.stage == MESA_SHADER_VERTEX ||
+ nir->info.stage == MESA_SHADER_TESS_EVAL)) {
+
+ unsigned prev_stages = (1 << (prog->info.stage + 1)) - 1;
+ unsigned stages_mask =
+ ~prev_stages & shader_program->data->linked_stages;
+
+ nir->info.next_stage = stages_mask ?
+ (gl_shader_stage) ffs(stages_mask) : MESA_SHADER_FRAGMENT;
+ } else {
+ nir->info.next_stage = MESA_SHADER_FRAGMENT;
+ }
+
+ nir_variable_mode mask =
+ (nir_variable_mode) (nir_var_shader_in | nir_var_shader_out);
+ nir_remove_dead_variables(nir, mask);
+
+ if (options->lower_all_io_to_temps ||
+ nir->info.stage == MESA_SHADER_VERTEX ||
+ nir->info.stage == MESA_SHADER_GEOMETRY) {
+ NIR_PASS_V(nir, nir_lower_io_to_temporaries,
+ nir_shader_get_entrypoint(nir),
+ true, true);
+ } else if (nir->info.stage == MESA_SHADER_FRAGMENT) {
+ NIR_PASS_V(nir, nir_lower_io_to_temporaries,
+ nir_shader_get_entrypoint(nir),
+ true, false);
+ }
+
+ NIR_PASS_V(nir, nir_lower_global_vars_to_local);
+ NIR_PASS_V(nir, nir_split_var_copies);
+ NIR_PASS_V(nir, nir_lower_var_copies);
+
+ st_nir_opts(nir, is_scalar);