From fac9b1c594b5ca8cbf9847d9ebb9d829d0dc0384 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Tue, 9 Jan 2024 16:47:31 +1100 Subject: [PATCH] glsl_to_nir: support conversion of struct/array function params MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds support for array and struct function params in the glsl to nir pass allowing us to avoid extra calls to the glsl IR optimisation loop. Reviewed-by: Marek Olšák Part-of: --- src/compiler/glsl/glsl_to_nir.cpp | 24 +++++++++++++++--------- src/compiler/glsl/linker.cpp | 5 ----- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp index 27d6d4c3b9e..84ce94831b8 100644 --- a/src/compiler/glsl/glsl_to_nir.cpp +++ b/src/compiler/glsl/glsl_to_nir.cpp @@ -664,9 +664,6 @@ nir_visitor::create_function(ir_function_signature *ir) } foreach_in_list(ir_variable, param, &ir->parameters) { - /* FINISHME: pass arrays, structs, etc by reference? */ - assert(glsl_type_is_vector(param->type) || glsl_type_is_scalar(param->type)); - func->params[np].num_components = 1; func->params[np].bit_size = 32; np++; @@ -1526,9 +1523,13 @@ nir_visitor::visit(ir_call *ir) if (sig_param->data.mode == ir_var_function_in || sig_param->data.mode == ir_var_function_inout) { - nir_store_deref(&b, param_deref, - evaluate_rvalue(param_rvalue), - ~0); + if (glsl_type_is_vector_or_scalar(param->type)) { + nir_store_deref(&b, param_deref, + evaluate_rvalue(param_rvalue), + ~0); + } else { + nir_copy_deref(&b, param_deref, evaluate_deref(param_rvalue)); + } } call->params[i] = nir_src_for_ssa(¶m_deref->def); @@ -1549,9 +1550,14 @@ nir_visitor::visit(ir_call *ir) if (sig_param->data.mode == ir_var_function_out || sig_param->data.mode == ir_var_function_inout) { - nir_store_deref(&b, evaluate_deref(param_rvalue), - nir_load_deref(&b, nir_src_as_deref(call->params[i])), - ~0); + if (glsl_type_is_vector_or_scalar(sig_param->type)) { + nir_store_deref(&b, evaluate_deref(param_rvalue), + nir_load_deref(&b, nir_src_as_deref(call->params[i])), + ~0); + } else { + nir_copy_deref(&b, evaluate_deref(param_rvalue), + nir_src_as_deref(call->params[i])); + } } i++; diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp index e5fe4c4fad3..67a016553c3 100644 --- a/src/compiler/glsl/linker.cpp +++ b/src/compiler/glsl/linker.cpp @@ -2601,11 +2601,6 @@ public: return visit_continue; foreach_in_list(ir_variable, param, &ir->parameters) { - if (!glsl_type_is_vector_or_scalar(param->type)) { - unsupported = true; - return visit_stop; - } - if (param->data.mode != ir_var_function_in && param->data.mode != ir_var_const_in) continue;