From f37e32b78b1e66c864e8741e9df3a1668894fd7c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Fri, 1 Sep 2023 18:56:10 -0400 Subject: [PATCH] nir: sort variables by location in nir_lower_io_passes to work around a bug I don't know why this is necessary, but it unblocks the work on varying optimizations. Reviewed-By: Mike Blumenkrantz Part-of: --- src/compiler/nir/nir.h | 1 + src/compiler/nir/nir_linking_helpers.c | 9 +++++++++ src/compiler/nir/nir_lower_io.c | 13 +++++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index accb906..2d17343 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 0d37738..4ba7d71 100644 --- a/src/compiler/nir/nir_linking_helpers.c +++ b/src/compiler/nir/nir_linking_helpers.c @@ -1474,6 +1474,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 cdf64e9..67988a1 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, -- 2.7.4