nir/spirv: Rework function argument setup
authorJason Ekstrand <jason@jlekstrand.net>
Thu, 29 Jun 2017 17:33:40 +0000 (10:33 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Wed, 5 Jul 2017 22:26:56 +0000 (15:26 -0700)
Now that we have proper pointer types, we can be more sensible about the
way we set up function arguments and deal with the two cases of pointer
vs. SSA parameters distinctly.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
src/compiler/spirv/spirv_to_nir.c
src/compiler/spirv/vtn_cfg.c
src/compiler/spirv/vtn_variables.c

index 462b0494f96beddab6684baf3404b787e03c6525..1743d8915a1be976b558bbddcd870958196066a0 100644 (file)
@@ -185,10 +185,6 @@ vtn_ssa_value(struct vtn_builder *b, uint32_t value_id)
    case vtn_value_type_ssa:
       return val->ssa;
 
-   case vtn_value_type_pointer:
-      /* This is needed for function parameters */
-      return vtn_variable_load(b, val->pointer);
-
    default:
       unreachable("Invalid type for an SSA value");
    }
index c1677b49aaa560c29ebeddbfd25d0beb75fcce23..df54b3c48517cb325a10ae84f0d75e02661be7d8 100644 (file)
@@ -65,6 +65,7 @@ vtn_cfg_handle_prepass_instruction(struct vtn_builder *b, SpvOp opcode,
       func->return_type = func_type->return_type->type;
 
       b->func->impl = nir_function_impl_create(func);
+      b->nb.cursor = nir_before_cf_list(&b->func->impl->body);
 
       b->func_param_idx = 0;
       break;
@@ -77,40 +78,47 @@ vtn_cfg_handle_prepass_instruction(struct vtn_builder *b, SpvOp opcode,
 
    case SpvOpFunctionParameter: {
       struct vtn_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;
-      if (type->base_type == vtn_base_type_pointer) {
-         type = type->deref;
-         assert(type->base_type != vtn_base_type_pointer);
-      }
 
       assert(b->func_param_idx < b->func->impl->num_params);
       nir_variable *param = b->func->impl->params[b->func_param_idx++];
 
-      assert(type->type == param->type);
+      if (type->base_type == vtn_base_type_pointer) {
+         struct vtn_variable *vtn_var = rzalloc(b, struct vtn_variable);
+         vtn_var->type = type->deref;
+         vtn_var->var = param;
+
+         assert(vtn_var->type->type == param->type);
+
+         struct vtn_type *without_array = vtn_var->type;
+         while(glsl_type_is_array(without_array->type))
+            without_array = without_array->array_element;
+
+         if (glsl_type_is_image(without_array->type)) {
+            vtn_var->mode = vtn_variable_mode_image;
+            param->interface_type = without_array->type;
+         } else if (glsl_type_is_sampler(without_array->type)) {
+            vtn_var->mode = vtn_variable_mode_sampler;
+            param->interface_type = without_array->type;
+         } else {
+            vtn_var->mode = vtn_variable_mode_param;
+         }
 
-      struct vtn_variable *vtn_var = rzalloc(b, struct vtn_variable);
-      vtn_var->type = type;
-      vtn_var->var = param;
+         struct vtn_value *val =
+            vtn_push_value(b, w[2], vtn_value_type_pointer);
 
-      struct vtn_type *without_array = type;
-      while(glsl_type_is_array(without_array->type))
-         without_array = without_array->array_element;
+         /* Name the parameter so it shows up nicely in NIR */
+         param->name = ralloc_strdup(param, val->name);
 
-      if (glsl_type_is_image(without_array->type)) {
-         vtn_var->mode = vtn_variable_mode_image;
-         param->interface_type = without_array->type;
-      } else if (glsl_type_is_sampler(without_array->type)) {
-         vtn_var->mode = vtn_variable_mode_sampler;
-         param->interface_type = without_array->type;
+         val->pointer = vtn_pointer_for_variable(b, vtn_var, type);
       } else {
-         vtn_var->mode = vtn_variable_mode_param;
-      }
+         /* We're a regular SSA value. */
+         struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
 
-      struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_pointer);
+         /* Name the parameter so it shows up nicely in NIR */
+         param->name = ralloc_strdup(param, val->name);
 
-      /* Name the parameter so it shows up nicely in NIR */
-      param->name = ralloc_strdup(param, val->name);
-
-      val->pointer = vtn_pointer_for_variable(b, vtn_var, NULL);
+         val->ssa = vtn_local_load(b, nir_deref_var_create(b, param));
+      }
       break;
    }
 
index 1ff7427ffb9c4737f389223a59dfe757df1d95fa..5af27bfdb112d98e0fe24081ba31da1eba968b89 100644 (file)
@@ -233,6 +233,8 @@ vtn_pointer_for_variable(struct vtn_builder *b,
 
    pointer->mode = var->mode;
    pointer->type = var->type;
+   assert(ptr_type->base_type == vtn_base_type_pointer);
+   assert(ptr_type->deref->type == var->type->type);
    pointer->ptr_type = ptr_type;
    pointer->var = var;