nir/spirv: Rework function argument setup
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>
This commit is contained in:

committed by
Jason Ekstrand

parent
0bdc622d43
commit
ab1939aea8
@@ -185,10 +185,6 @@ vtn_ssa_value(struct vtn_builder *b, uint32_t value_id)
|
|||||||
case vtn_value_type_ssa:
|
case vtn_value_type_ssa:
|
||||||
return val->ssa;
|
return val->ssa;
|
||||||
|
|
||||||
case vtn_value_type_pointer:
|
|
||||||
/* This is needed for function parameters */
|
|
||||||
return vtn_variable_load(b, val->pointer);
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
unreachable("Invalid type for an SSA value");
|
unreachable("Invalid type for an SSA value");
|
||||||
}
|
}
|
||||||
|
@@ -65,6 +65,7 @@ vtn_cfg_handle_prepass_instruction(struct vtn_builder *b, SpvOp opcode,
|
|||||||
func->return_type = func_type->return_type->type;
|
func->return_type = func_type->return_type->type;
|
||||||
|
|
||||||
b->func->impl = nir_function_impl_create(func);
|
b->func->impl = nir_function_impl_create(func);
|
||||||
|
b->nb.cursor = nir_before_cf_list(&b->func->impl->body);
|
||||||
|
|
||||||
b->func_param_idx = 0;
|
b->func_param_idx = 0;
|
||||||
break;
|
break;
|
||||||
@@ -77,40 +78,47 @@ vtn_cfg_handle_prepass_instruction(struct vtn_builder *b, SpvOp opcode,
|
|||||||
|
|
||||||
case SpvOpFunctionParameter: {
|
case SpvOpFunctionParameter: {
|
||||||
struct vtn_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;
|
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);
|
assert(b->func_param_idx < b->func->impl->num_params);
|
||||||
nir_variable *param = b->func->impl->params[b->func_param_idx++];
|
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;
|
||||||
|
|
||||||
struct vtn_variable *vtn_var = rzalloc(b, struct vtn_variable);
|
assert(vtn_var->type->type == param->type);
|
||||||
vtn_var->type = type;
|
|
||||||
vtn_var->var = param;
|
|
||||||
|
|
||||||
struct vtn_type *without_array = type;
|
struct vtn_type *without_array = vtn_var->type;
|
||||||
while(glsl_type_is_array(without_array->type))
|
while(glsl_type_is_array(without_array->type))
|
||||||
without_array = without_array->array_element;
|
without_array = without_array->array_element;
|
||||||
|
|
||||||
if (glsl_type_is_image(without_array->type)) {
|
if (glsl_type_is_image(without_array->type)) {
|
||||||
vtn_var->mode = vtn_variable_mode_image;
|
vtn_var->mode = vtn_variable_mode_image;
|
||||||
param->interface_type = without_array->type;
|
param->interface_type = without_array->type;
|
||||||
} else if (glsl_type_is_sampler(without_array->type)) {
|
} else if (glsl_type_is_sampler(without_array->type)) {
|
||||||
vtn_var->mode = vtn_variable_mode_sampler;
|
vtn_var->mode = vtn_variable_mode_sampler;
|
||||||
param->interface_type = without_array->type;
|
param->interface_type = without_array->type;
|
||||||
|
} else {
|
||||||
|
vtn_var->mode = vtn_variable_mode_param;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
val->pointer = vtn_pointer_for_variable(b, vtn_var, type);
|
||||||
} else {
|
} 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);
|
||||||
|
|
||||||
|
/* Name the parameter so it shows up nicely in NIR */
|
||||||
|
param->name = ralloc_strdup(param, val->name);
|
||||||
|
|
||||||
|
val->ssa = vtn_local_load(b, nir_deref_var_create(b, param));
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
val->pointer = vtn_pointer_for_variable(b, vtn_var, NULL);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -233,6 +233,8 @@ vtn_pointer_for_variable(struct vtn_builder *b,
|
|||||||
|
|
||||||
pointer->mode = var->mode;
|
pointer->mode = var->mode;
|
||||||
pointer->type = var->type;
|
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->ptr_type = ptr_type;
|
||||||
pointer->var = var;
|
pointer->var = var;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user