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 <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32390>
This commit is contained in:
Marek Olšák 2024-11-27 22:34:40 -05:00 committed by Marge Bot
parent 428613b690
commit c26da94b4c
4 changed files with 19 additions and 13 deletions

View file

@ -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 {

View file

@ -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;

View file

@ -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 :

View file

@ -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 *