diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index accb906dea4..2d173434a27 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -4978,6 +4978,7 @@ bool nir_lower_amul(nir_shader *shader, bool nir_lower_ubo_vec4(nir_shader *shader); +void nir_sort_variables_by_location(nir_shader *shader, nir_variable_mode mode); void nir_assign_io_var_locations(nir_shader *shader, nir_variable_mode mode, unsigned *size, diff --git a/src/compiler/nir/nir_linking_helpers.c b/src/compiler/nir/nir_linking_helpers.c index 0d37738f1b0..4ba7d717cfb 100644 --- a/src/compiler/nir/nir_linking_helpers.c +++ b/src/compiler/nir/nir_linking_helpers.c @@ -1473,6 +1473,15 @@ sort_varyings(nir_shader *shader, nir_variable_mode mode, } } +void +nir_sort_variables_by_location(nir_shader *shader, nir_variable_mode mode) +{ + struct exec_list vars; + + sort_varyings(shader, mode, &vars); + exec_list_append(&shader->variables, &vars); +} + void nir_assign_io_var_locations(nir_shader *shader, nir_variable_mode mode, unsigned *size, gl_shader_stage stage) diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c index cdf64e9a1ee..67988a1716e 100644 --- a/src/compiler/nir/nir_lower_io.c +++ b/src/compiler/nir/nir_lower_io.c @@ -3127,6 +3127,19 @@ nir_lower_io_passes(nir_shader *nir, bool renumber_vs_inputs) (nir->options->support_indirect_outputs >> nir->info.stage) & 0x1 && nir->xfb_info == NULL; + /* TODO: Sorting variables by location is required due to some bug + * in nir_lower_io_to_temporaries. If variables are not sorted, + * dEQP-GLES31.functional.separate_shader.random.0 fails. + * + * This isn't needed if nir_assign_io_var_locations is called because it + * also sorts variables. However, if IO is lowered sooner than that, we + * must sort explicitly here to get what nir_assign_io_var_locations does. + */ + unsigned varying_var_mask = + (nir->info.stage != MESA_SHADER_VERTEX ? nir_var_shader_in : 0) | + (nir->info.stage != MESA_SHADER_FRAGMENT ? nir_var_shader_out : 0); + nir_sort_variables_by_location(nir, varying_var_mask); + if (!has_indirect_inputs || !has_indirect_outputs) { NIR_PASS_V(nir, nir_lower_io_to_temporaries, nir_shader_get_entrypoint(nir), !has_indirect_outputs,