From a065a09d229fd2990467ad8eee53f7086d542e6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Fri, 4 Jul 2025 13:17:35 -0400 Subject: [PATCH] glsl: don't lower outputs to temps unconditionally It's done later in nir_lower_io_passes only for shader stages not supporting indirect access. Unfortunately we have add a hack into nir_lower_io_passes to get rid of output loads. A later commit will remove it. Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/glsl/gl_nir_linker.c | 3 --- src/compiler/nir/nir_lower_io.c | 12 ++++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/compiler/glsl/gl_nir_linker.c b/src/compiler/glsl/gl_nir_linker.c index 861349ff211..6d2e7d0b0f8 100644 --- a/src/compiler/glsl/gl_nir_linker.c +++ b/src/compiler/glsl/gl_nir_linker.c @@ -1326,9 +1326,6 @@ preprocess_shader(const struct gl_constants *consts, (nir->info.outputs_written & (VARYING_BIT_CLIP_DIST0 | VARYING_BIT_CLIP_DIST1))) NIR_PASS(_, nir, gl_nir_zero_initialize_clip_distance); - NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries, - nir_shader_get_entrypoint(nir), true, false); - NIR_PASS(_, nir, nir_lower_global_vars_to_local); NIR_PASS(_, nir, nir_split_var_copies); NIR_PASS(_, nir, nir_lower_var_copies); diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c index 06f11a06a1b..49c8c4b2468 100644 --- a/src/compiler/nir/nir_lower_io.c +++ b/src/compiler/nir/nir_lower_io.c @@ -1038,6 +1038,18 @@ 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: This is a hack until a better solution is available. + * For all shaders except TCS, lower all outputs to temps because: + * - there can be output loads (nobody expects those outside of TCS) + * - drivers don't expect when an output is only written in control flow + * + * "has_indirect_outputs = false" causes all outputs to be lowered to temps. + * which lowers indirect stores, eliminates output loads, and moves all + * output stores to the end or GS emits. + */ + if (nir->info.stage != MESA_SHADER_TESS_CTRL) + has_indirect_outputs = false; + /* TODO: Sorting variables by location is required due to some bug * in nir_lower_io_vars_to_temporaries. If variables are not sorted, * dEQP-GLES31.functional.separate_shader.random.0 fails.