mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-02-17 23:40:29 +01:00
glsl_to_nir: merge function param handling
Here we remove the special handling for input params that was hard to work with and unite it with the output and inout params. Here a mediump test needs to be updated to what is a more expected outcome anyway. We also need to update the code that inserts software f64 to the new way input params are handled. Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27108>
This commit is contained in:
parent
5a852bd24c
commit
7afce96b80
3 changed files with 36 additions and 43 deletions
|
|
@ -667,13 +667,8 @@ nir_visitor::create_function(ir_function_signature *ir)
|
|||
/* FINISHME: pass arrays, structs, etc by reference? */
|
||||
assert(glsl_type_is_vector(param->type) || glsl_type_is_scalar(param->type));
|
||||
|
||||
if (param->data.mode == ir_var_function_in) {
|
||||
func->params[np].num_components = param->type->vector_elements;
|
||||
func->params[np].bit_size = glsl_get_bit_size(param->type);
|
||||
} else {
|
||||
func->params[np].num_components = 1;
|
||||
func->params[np].bit_size = 32;
|
||||
}
|
||||
func->params[np].num_components = 1;
|
||||
func->params[np].bit_size = 32;
|
||||
np++;
|
||||
}
|
||||
assert(np == func->num_params);
|
||||
|
|
@ -710,20 +705,6 @@ nir_visitor::visit(ir_function_signature *ir)
|
|||
|
||||
b = nir_builder_at(nir_after_impl(impl));
|
||||
|
||||
unsigned i = (ir->return_type != &glsl_type_builtin_void) ? 1 : 0;
|
||||
|
||||
foreach_in_list(ir_variable, param, &ir->parameters) {
|
||||
nir_variable *var =
|
||||
nir_local_variable_create(impl, param->type, param->name);
|
||||
|
||||
if (param->data.mode == ir_var_function_in) {
|
||||
nir_store_var(&b, var, nir_load_param(&b, i), ~0);
|
||||
}
|
||||
|
||||
_mesa_hash_table_insert(var_table, param, var);
|
||||
i++;
|
||||
}
|
||||
|
||||
visit_exec_list(&ir->body, this);
|
||||
|
||||
this->is_global = true;
|
||||
|
|
@ -837,6 +818,12 @@ deref_get_qualifier(nir_deref_instr *deref)
|
|||
nir_deref_path path;
|
||||
nir_deref_path_init(&path, deref, NULL);
|
||||
|
||||
/* Function params can lead to a deref cast just return zero as these
|
||||
* params have no qualifers anyway.
|
||||
*/
|
||||
if (path.path[0]->deref_type != nir_deref_type_var)
|
||||
return (gl_access_qualifier) 0;
|
||||
|
||||
unsigned qualifiers = path.path[0]->var->data.access;
|
||||
|
||||
const glsl_type *parent_type = path.path[0]->type;
|
||||
|
|
@ -1532,25 +1519,20 @@ nir_visitor::visit(ir_call *ir)
|
|||
ir_rvalue *param_rvalue = (ir_rvalue *) actual_node;
|
||||
ir_variable *sig_param = (ir_variable *) formal_node;
|
||||
|
||||
if (sig_param->data.mode == ir_var_function_out ||
|
||||
nir_variable *param =
|
||||
nir_local_variable_create(this->impl, sig_param->type, "param");
|
||||
param->data.precision = sig_param->data.precision;
|
||||
nir_deref_instr *param_deref = nir_build_deref_var(&b, param);
|
||||
|
||||
if (sig_param->data.mode == ir_var_function_in ||
|
||||
sig_param->data.mode == ir_var_function_inout) {
|
||||
nir_variable *out_param =
|
||||
nir_local_variable_create(this->impl, sig_param->type, "param");
|
||||
out_param->data.precision = sig_param->data.precision;
|
||||
nir_deref_instr *out_param_deref = nir_build_deref_var(&b, out_param);
|
||||
|
||||
if (sig_param->data.mode == ir_var_function_inout) {
|
||||
nir_store_deref(&b, out_param_deref,
|
||||
nir_load_deref(&b, evaluate_deref(param_rvalue)),
|
||||
~0);
|
||||
}
|
||||
|
||||
call->params[i] = nir_src_for_ssa(&out_param_deref->def);
|
||||
} else if (sig_param->data.mode == ir_var_function_in) {
|
||||
nir_def *val = evaluate_rvalue(param_rvalue);
|
||||
call->params[i] = nir_src_for_ssa(val);
|
||||
nir_store_deref(&b, param_deref,
|
||||
evaluate_rvalue(param_rvalue),
|
||||
~0);
|
||||
}
|
||||
|
||||
call->params[i] = nir_src_for_ssa(¶m_deref->def);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
|
|
@ -2509,7 +2491,8 @@ void
|
|||
nir_visitor::visit(ir_dereference_variable *ir)
|
||||
{
|
||||
if (ir->variable_referenced()->data.mode == ir_var_function_out ||
|
||||
ir->variable_referenced()->data.mode == ir_var_function_inout) {
|
||||
ir->variable_referenced()->data.mode == ir_var_function_inout ||
|
||||
ir->variable_referenced()->data.mode == ir_var_function_in) {
|
||||
unsigned i = (sig->return_type != &glsl_type_builtin_void) ? 1 : 0;
|
||||
|
||||
foreach_in_list(ir_variable, param, &sig->parameters) {
|
||||
|
|
|
|||
|
|
@ -438,10 +438,7 @@ TEST_F(gl_nir_lower_mediump_test, func_args_in_mediump)
|
|||
|
||||
EXPECT_PRED_FORMAT2(glsl_ir_contains, fs_ir, "expression float f162f (expression float16_t * (expression float16_t f2fmp (var_ref x) ) (expression float16_t f2fmp (var_ref y) ) )");
|
||||
|
||||
/* NIR optimization will notice that we downconvert the highp to mediump just
|
||||
* to multiply and cast back up, and just multiply in highp instead.
|
||||
*/
|
||||
EXPECT_EQ(op_dest_bits(nir_op_fmul), 32);
|
||||
EXPECT_EQ(op_dest_bits(nir_op_fmul), 16);
|
||||
}
|
||||
|
||||
TEST_F(gl_nir_lower_mediump_test, func_args_inout_mediump)
|
||||
|
|
|
|||
|
|
@ -645,8 +645,21 @@ lower_doubles_instr_to_soft(nir_builder *b, nir_alu_instr *instr,
|
|||
|
||||
assert(nir_op_infos[instr->op].num_inputs + 1 == func->num_params);
|
||||
for (unsigned i = 0; i < nir_op_infos[instr->op].num_inputs; i++) {
|
||||
nir_alu_type n_type =
|
||||
nir_alu_type_get_base_type(nir_op_infos[instr->op].input_types[i]);
|
||||
/* Add bitsize */
|
||||
n_type = n_type | instr->src[0].src.ssa->bit_size;
|
||||
|
||||
const struct glsl_type *param_type =
|
||||
glsl_scalar_type(nir_get_glsl_base_type_for_nir_type(n_type));
|
||||
|
||||
nir_variable *param =
|
||||
nir_local_variable_create(b->impl, param_type, "param");
|
||||
nir_deref_instr *param_deref = nir_build_deref_var(b, param);
|
||||
nir_store_deref(b, param_deref, nir_mov_alu(b, instr->src[i], 1), ~0);
|
||||
|
||||
assert(i + 1 < ARRAY_SIZE(params));
|
||||
params[i + 1] = nir_mov_alu(b, instr->src[i], 1);
|
||||
params[i + 1] = ¶m_deref->def;
|
||||
}
|
||||
|
||||
nir_inline_function_impl(b, func->impl, params, NULL);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue