From adc40aee25e73602a413fb65805ad0888a8fc9b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sun, 27 Oct 2024 13:26:12 -0400 Subject: [PATCH] glsl: lower IO in the linker if enabled, don't lower it later This removes the useless codepath that kept IO derefs until st_finalize_nir. It was used before nir_opt_varyings existed. Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/glsl/gl_nir_linker.c | 17 ++++++++--------- src/compiler/nir/nir.h | 8 +------- src/mesa/main/glspirv.c | 3 +-- src/mesa/state_tracker/st_glsl_to_nir.cpp | 15 +-------------- 4 files changed, 11 insertions(+), 32 deletions(-) diff --git a/src/compiler/glsl/gl_nir_linker.c b/src/compiler/glsl/gl_nir_linker.c index bdf5b1e6b9a..0add54ffff4 100644 --- a/src/compiler/glsl/gl_nir_linker.c +++ b/src/compiler/glsl/gl_nir_linker.c @@ -1497,6 +1497,7 @@ gl_nir_lower_optimize_varyings(const struct gl_constants *consts, unsigned num_shaders = 0; unsigned max_ubos = UINT_MAX; unsigned max_uniform_comps = UINT_MAX; + bool optimize_io = true; for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { struct gl_linked_shader *shader = prog->_LinkedShaders[i]; @@ -1506,11 +1507,8 @@ gl_nir_lower_optimize_varyings(const struct gl_constants *consts, nir_shader *nir = shader->Program->nir; - if (nir->info.stage == MESA_SHADER_COMPUTE) - return; - - if (!(nir->options->io_options & nir_io_glsl_lower_derefs) || - !(nir->options->io_options & nir_io_glsl_opt_varyings)) + if (nir->info.stage == MESA_SHADER_COMPUTE || + !(nir->options->io_options & nir_io_glsl_lower_derefs)) return; shaders[num_shaders] = nir; @@ -1518,14 +1516,15 @@ gl_nir_lower_optimize_varyings(const struct gl_constants *consts, consts->Program[i].MaxUniformComponents); max_ubos = MIN2(max_ubos, consts->Program[i].MaxUniformBlocks); num_shaders++; + optimize_io &= nir->options->io_options & nir_io_glsl_opt_varyings; } /* Lower IO derefs to load and store intrinsics. */ - for (unsigned i = 0; i < num_shaders; i++) { - nir_shader *nir = shaders[i]; + for (unsigned i = 0; i < num_shaders; i++) + nir_lower_io_passes(shaders[i], true); - nir_lower_io_passes(nir, true); - } + if (!optimize_io) + return; /* There is nothing to optimize for only 1 shader. */ if (num_shaders == 1) { diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 7478820bc6f..8e6332f669e 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -3843,13 +3843,7 @@ typedef enum { nir_io_glsl_lower_derefs = BITFIELD_BIT(16), /** - * Run nir_opt_varyings in the GLSL linker. If false, optimize varyings - * the old way and lower IO later. - * - * nir_io_lower_to_intrinsics must be set for this to take effect. - * - * TODO: remove this and default to enabled once we are sure that this - * codepath is solid. + * Run nir_opt_varyings in the GLSL linker. */ nir_io_glsl_opt_varyings = BITFIELD_BIT(17), } nir_io_options; diff --git a/src/mesa/main/glspirv.c b/src/mesa/main/glspirv.c index dd5c89ad674..7ef949d7263 100644 --- a/src/mesa/main/glspirv.c +++ b/src/mesa/main/glspirv.c @@ -335,8 +335,7 @@ _mesa_spirv_to_nir(struct gl_context *ctx, NIR_PASS(_, nir, nir_split_per_member_structs); if (nir->info.stage == MESA_SHADER_VERTEX && - (!(nir->options->io_options & nir_io_glsl_lower_derefs) || - !(nir->options->io_options & nir_io_glsl_opt_varyings))) + !(nir->options->io_options & nir_io_glsl_lower_derefs)) nir_remap_dual_slot_attributes(nir, &linked_shader->Program->DualSlotInputs); NIR_PASS(_, nir, nir_lower_frexp); diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp index e553a222368..5ba25a6bd7c 100644 --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp @@ -737,8 +737,7 @@ st_link_glsl_to_nir(struct gl_context *ctx, prog->info.num_abos = old_info.num_abos; if (prog->info.stage == MESA_SHADER_VERTEX) { - if (prog->nir->info.io_lowered && - prog->nir->options->io_options & nir_io_glsl_opt_varyings) { + if (prog->nir->info.io_lowered) { prog->info.inputs_read = prog->nir->info.inputs_read; prog->DualSlotInputs = prog->nir->info.dual_slot_inputs; } else { @@ -910,18 +909,6 @@ st_finalize_nir(struct st_context *st, struct gl_program *prog, st_nir_assign_varying_locations(st, nir); st_nir_assign_uniform_locations(st->ctx, prog, nir); - /* Lower load_deref/store_deref of inputs and outputs. - * This depends on st_nir_assign_varying_locations. - * - * TODO: remove this once nir_io_glsl_opt_varyings is enabled by default. - */ - if (!is_draw_shader && nir->options->io_options & nir_io_glsl_lower_derefs && - !(nir->options->io_options & nir_io_glsl_opt_varyings)) { - nir_lower_io_passes(nir, false); - NIR_PASS(_, nir, nir_remove_dead_variables, - nir_var_shader_in | nir_var_shader_out, NULL); - } - /* Set num_uniforms in number of attribute slots (vec4s) */ nir->num_uniforms = DIV_ROUND_UP(prog->Parameters->NumParameterValues, 4);