-static void
-vtn_handle_function_call(struct vtn_builder *b, SpvOp opcode,
- const uint32_t *w, unsigned count)
-{
- struct vtn_type *res_type = vtn_value(b, w[1], vtn_value_type_type)->type;
- struct vtn_function *vtn_callee =
- vtn_value(b, w[3], vtn_value_type_function)->func;
- struct nir_function *callee = vtn_callee->impl->function;
-
- vtn_callee->referenced = true;
-
- nir_call_instr *call = nir_call_instr_create(b->nb.shader, callee);
- for (unsigned i = 0; i < call->num_params; i++) {
- unsigned arg_id = w[4 + i];
- struct vtn_value *arg = vtn_untyped_value(b, arg_id);
- if (arg->value_type == vtn_value_type_pointer &&
- arg->pointer->ptr_type->type == NULL) {
- nir_deref_var *d = vtn_pointer_to_deref(b, arg->pointer);
- call->params[i] = nir_deref_var_clone(d, call);
- } else {
- struct vtn_ssa_value *arg_ssa = vtn_ssa_value(b, arg_id);
-
- /* Make a temporary to store the argument in */
- nir_variable *tmp =
- nir_local_variable_create(b->nb.impl, arg_ssa->type, "arg_tmp");
- call->params[i] = nir_deref_var_create(call, tmp);
-
- vtn_local_store(b, arg_ssa, call->params[i]);
- }
- }
-
- nir_variable *out_tmp = NULL;
- vtn_assert(res_type->type == callee->return_type);
- if (!glsl_type_is_void(callee->return_type)) {
- out_tmp = nir_local_variable_create(b->nb.impl, callee->return_type,
- "out_tmp");
- call->return_deref = nir_deref_var_create(call, out_tmp);
- }
-
- nir_builder_instr_insert(&b->nb, &call->instr);
-
- if (glsl_type_is_void(callee->return_type)) {
- vtn_push_value(b, w[2], vtn_value_type_undef);
- } else {
- vtn_push_ssa(b, w[2], res_type, vtn_local_load(b, call->return_deref));
- }
-}
-