From c26da94b4c546230b9902c528c565eb15c914106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Wed, 27 Nov 2024 22:34:40 -0500 Subject: [PATCH] nir/opt_varyings: replace options::lower_varying_from_uniform with a cost number This is a simple way for drivers to enable uniform expression propagation without having to set any callbacks for it. It replaces the old option. Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir.h | 23 ++++++++++++++--------- src/compiler/nir/nir_linking_helpers.c | 2 +- src/compiler/nir/nir_opt_varyings.c | 3 ++- src/gallium/drivers/lima/lima_program.c | 4 ++-- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 15d17a94170..ea8e6e54672 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -4330,15 +4330,6 @@ typedef struct nir_shader_compiler_options { uint8_t support_indirect_inputs; uint8_t support_indirect_outputs; - /** - * Remove varying loaded from uniform, let fragment shader load the - * uniform directly. GPU passing varying by memory can benifit from it - * for sure; but GPU passing varying by on chip resource may not. - * Because it saves on chip resource but may increase memory pressure when - * fragment task is far more than vertex one, so better left it disabled. - */ - bool lower_varying_from_uniform; - /** store the variable offset into the instrinsic range_base instead * of adding it to the image index. */ @@ -4422,6 +4413,20 @@ typedef struct nir_shader_compiler_options { * When this callback isn't set, nir_opt_varyings uses its own version. */ unsigned (*varying_estimate_instr_cost)(struct nir_instr *instr); + + /** + * When the varying_expression_max_cost callback isn't set, this specifies + * the maximum cost of a uniform expression that is allowed to be moved + * from output stores into the next shader stage to eliminate those output + * stores and corresponding inputs. + * + * 0 only allows propagating constants written to output stores to + * the next shader. + * + * At least 2 is required for moving a uniform stored in an output into + * the next shader according to default_varying_estimate_instr_cost. + */ + unsigned max_varying_expression_cost; } nir_shader_compiler_options; typedef struct nir_shader { diff --git a/src/compiler/nir/nir_linking_helpers.c b/src/compiler/nir/nir_linking_helpers.c index c94c0dfc92a..0c940ae8e05 100644 --- a/src/compiler/nir/nir_linking_helpers.c +++ b/src/compiler/nir/nir_linking_helpers.c @@ -1410,7 +1410,7 @@ nir_link_opt_varyings(nir_shader *producer, nir_shader *consumer) nir_scalar uni_scalar; if (is_direct_uniform_load(ssa, &uni_scalar)) { - if (consumer->options->lower_varying_from_uniform) { + if (consumer->options->max_varying_expression_cost >= 2) { progress |= replace_varying_input_by_uniform_load(consumer, intr, &uni_scalar); continue; diff --git a/src/compiler/nir/nir_opt_varyings.c b/src/compiler/nir/nir_opt_varyings.c index 59e8baefc34..8b930dd1e48 100644 --- a/src/compiler/nir/nir_opt_varyings.c +++ b/src/compiler/nir/nir_opt_varyings.c @@ -4886,7 +4886,8 @@ init_linkage(nir_shader *producer, nir_shader *consumer, bool spirv, .max_varying_expression_cost = producer->options->varying_expression_max_cost ? - producer->options->varying_expression_max_cost(producer, consumer) : 0, + producer->options->varying_expression_max_cost(producer, consumer) : + producer->options->max_varying_expression_cost, .varying_estimate_instr_cost = producer->options->varying_estimate_instr_cost ? producer->options->varying_estimate_instr_cost : diff --git a/src/gallium/drivers/lima/lima_program.c b/src/gallium/drivers/lima/lima_program.c index ddf884ab3c2..82169791512 100644 --- a/src/gallium/drivers/lima/lima_program.c +++ b/src/gallium/drivers/lima/lima_program.c @@ -62,9 +62,9 @@ static const nir_shader_compiler_options vs_nir_options = { .lower_insert_word = true, .force_indirect_unrolling = nir_var_all, .force_indirect_unrolling_sampler = true, - .lower_varying_from_uniform = true, .max_unroll_iterations = 32, .no_integers = true, + .max_varying_expression_cost = 2, }; static const nir_shader_compiler_options fs_nir_options = { @@ -85,9 +85,9 @@ static const nir_shader_compiler_options fs_nir_options = { .lower_vector_cmp = true, .force_indirect_unrolling = (nir_var_shader_out | nir_var_function_temp), .force_indirect_unrolling_sampler = true, - .lower_varying_from_uniform = true, .max_unroll_iterations = 32, .no_integers = true, + .max_varying_expression_cost = 2, }; const void *