nir: Add a ptr_as_array deref type
[mesa.git] / src / compiler / spirv / vtn_cfg.c
index 726f717e8d588686a716f5a5a901b013ebc4fe51..9cec036d46217f76c5056bd65d80e62f9754f7c3 100644 (file)
@@ -47,6 +47,7 @@ vtn_type_count_function_params(struct vtn_type *type)
 {
    switch (type->base_type) {
    case vtn_base_type_array:
+   case vtn_base_type_matrix:
       return type->length * vtn_type_count_function_params(type->array_element);
 
    case vtn_base_type_struct: {
@@ -76,6 +77,7 @@ vtn_type_add_to_function_params(struct vtn_type *type,
 
    switch (type->base_type) {
    case vtn_base_type_array:
+   case vtn_base_type_matrix:
       for (unsigned i = 0; i < type->length; i++)
          vtn_type_add_to_function_params(type->array_element, func, param_idx);
       break;
@@ -123,6 +125,7 @@ vtn_ssa_value_add_to_call_params(struct vtn_builder *b,
 {
    switch (type->base_type) {
    case vtn_base_type_array:
+   case vtn_base_type_matrix:
       for (unsigned i = 0; i < type->length; i++) {
          vtn_ssa_value_add_to_call_params(b, value->elems[i],
                                           type->array_element,
@@ -152,6 +155,7 @@ vtn_ssa_value_load_function_param(struct vtn_builder *b,
 {
    switch (type->base_type) {
    case vtn_base_type_array:
+   case vtn_base_type_matrix:
       for (unsigned i = 0; i < type->length; i++) {
          vtn_ssa_value_load_function_param(b, value->elems[i],
                                            type->array_element, param_idx);
@@ -190,7 +194,9 @@ vtn_handle_function_call(struct vtn_builder *b, SpvOp opcode,
    struct vtn_type *ret_type = vtn_callee->type->return_type;
    if (ret_type->base_type != vtn_base_type_void) {
       nir_variable *ret_tmp =
-         nir_local_variable_create(b->nb.impl, ret_type->type, "return_tmp");
+         nir_local_variable_create(b->nb.impl,
+                                   glsl_get_bare_type(ret_type->type),
+                                   "return_tmp");
       ret_deref = nir_build_deref_var(&b->nb, ret_tmp);
       call->params[param_idx++] = nir_src_for_ssa(&ret_deref->dest.ssa);
    }
@@ -874,9 +880,11 @@ vtn_emit_cf_list(struct vtn_builder *b, struct list_head *cf_list,
                         vtn_base_type_void,
                         "Return with a value from a function returning void");
             struct vtn_ssa_value *src = vtn_ssa_value(b, block->branch[1]);
+            const struct glsl_type *ret_type =
+               glsl_get_bare_type(b->func->type->return_type->type);
             nir_deref_instr *ret_deref =
                nir_build_deref_cast(&b->nb, nir_load_param(&b->nb, 0),
-                                    nir_var_local, src->type);
+                                    nir_var_local, ret_type, 0);
             vtn_local_store(b, src, ret_deref);
          }
 
@@ -1049,6 +1057,8 @@ vtn_function_emit(struct vtn_builder *b, struct vtn_function *func,
    vtn_foreach_instruction(b, func->start_block->label, func->end,
                            vtn_handle_phi_second_pass);
 
+   nir_rematerialize_derefs_in_use_blocks_impl(func->impl);
+
    /* Continue blocks for loops get inserted before the body of the loop
     * but instructions in the continue may use SSA defs in the loop body.
     * Therefore, we need to repair SSA to insert the needed phi nodes.