return vtn_value(b, value_id, vtn_value_type_block)->block;
}
-static struct vtn_pointer *
-vtn_load_param_pointer(struct vtn_builder *b,
- struct vtn_type *param_type,
- uint32_t param_idx)
-{
- struct vtn_type *ptr_type = param_type;
- assert(param_type->base_type == vtn_base_type_image ||
- param_type->base_type == vtn_base_type_sampler);
- ptr_type = rzalloc(b, struct vtn_type);
- ptr_type->base_type = vtn_base_type_pointer;
- ptr_type->deref = param_type;
- ptr_type->storage_class = SpvStorageClassUniformConstant;
-
- return vtn_pointer_from_ssa(b, nir_load_param(&b->nb, param_idx), ptr_type);
-}
-
static unsigned
glsl_type_count_function_params(const struct glsl_type *type)
{
}
}
-static unsigned
-vtn_type_count_function_params(struct vtn_type *type)
-{
- switch (type->base_type) {
- case vtn_base_type_scalar:
- case vtn_base_type_vector:
- case vtn_base_type_array:
- case vtn_base_type_matrix:
- case vtn_base_type_struct:
- case vtn_base_type_pointer:
- return glsl_type_count_function_params(type->type);
-
- case vtn_base_type_sampled_image:
- return 2;
-
- default:
- return 1;
- }
-}
-
static void
glsl_type_add_to_function_params(const struct glsl_type *type,
nir_function *func,
}
}
-static void
-vtn_type_add_to_function_params(struct vtn_type *type,
- nir_function *func,
- unsigned *param_idx)
-{
- static const nir_parameter nir_deref_param = {
- .num_components = 1,
- .bit_size = 32,
- };
-
- switch (type->base_type) {
- case vtn_base_type_scalar:
- case vtn_base_type_vector:
- case vtn_base_type_array:
- case vtn_base_type_matrix:
- case vtn_base_type_struct:
- case vtn_base_type_pointer:
- glsl_type_add_to_function_params(type->type, func, param_idx);
- break;
-
- case vtn_base_type_sampled_image:
- func->params[(*param_idx)++] = nir_deref_param;
- func->params[(*param_idx)++] = nir_deref_param;
- break;
-
- case vtn_base_type_image:
- case vtn_base_type_sampler:
- func->params[(*param_idx)++] = nir_deref_param;
- break;
-
- default:
- unreachable("Unsupported type");
- }
-}
-
static void
vtn_ssa_value_add_to_call_params(struct vtn_builder *b,
struct vtn_ssa_value *value,
}
for (unsigned i = 0; i < vtn_callee->type->length; i++) {
- struct vtn_type *arg_type = vtn_callee->type->params[i];
- unsigned arg_id = w[4 + i];
-
- if (arg_type->base_type == vtn_base_type_sampled_image) {
- struct vtn_sampled_image *sampled_image =
- vtn_value(b, arg_id, vtn_value_type_sampled_image)->sampled_image;
-
- call->params[param_idx++] =
- nir_src_for_ssa(vtn_pointer_to_ssa(b, sampled_image->image));
- call->params[param_idx++] =
- nir_src_for_ssa(vtn_pointer_to_ssa(b, sampled_image->sampler));
- } else if (arg_type->base_type == vtn_base_type_image ||
- arg_type->base_type == vtn_base_type_sampler) {
- struct vtn_pointer *pointer =
- vtn_value(b, arg_id, vtn_value_type_pointer)->pointer;
- call->params[param_idx++] =
- nir_src_for_ssa(vtn_pointer_to_ssa(b, pointer));
- } else {
- struct vtn_ssa_value *arg = vtn_ssa_value(b, arg_id);
- vtn_assert(arg->type == glsl_get_bare_type(arg_type->type));
- vtn_ssa_value_add_to_call_params(b, arg, call, ¶m_idx);
- }
+ vtn_ssa_value_add_to_call_params(b, vtn_ssa_value(b, w[4 + i]),
+ call, ¶m_idx);
}
assert(param_idx == call->num_params);
unsigned num_params = 0;
for (unsigned i = 0; i < func_type->length; i++)
- num_params += vtn_type_count_function_params(func_type->params[i]);
+ num_params += glsl_type_count_function_params(func_type->params[i]->type);
/* Add one parameter for the function return value */
if (func_type->return_type->base_type != vtn_base_type_void)
}
for (unsigned i = 0; i < func_type->length; i++)
- vtn_type_add_to_function_params(func_type->params[i], func, &idx);
+ glsl_type_add_to_function_params(func_type->params[i]->type, func, &idx);
assert(idx == num_params);
b->func->impl = nir_function_impl_create(func);
break;
case SpvOpFunctionParameter: {
- struct vtn_type *type = vtn_get_type(b, w[1]);
-
vtn_assert(b->func_param_idx < b->func->impl->function->num_params);
-
- if (type->base_type == vtn_base_type_sampled_image) {
- /* Sampled images are actually two parameters. The first is the
- * image and the second is the sampler.
- */
- struct vtn_value *val =
- vtn_push_value(b, w[2], vtn_value_type_sampled_image);
-
- val->sampled_image = ralloc(b, struct vtn_sampled_image);
-
- struct vtn_type *image_type = rzalloc(b, struct vtn_type);
- image_type->base_type = vtn_base_type_image;
- image_type->type = type->type;
-
- struct vtn_type *sampler_type = rzalloc(b, struct vtn_type);
- sampler_type->base_type = vtn_base_type_sampler;
- sampler_type->type = glsl_bare_sampler_type();
-
- val->sampled_image->image =
- vtn_load_param_pointer(b, image_type, b->func_param_idx++);
- val->sampled_image->sampler =
- vtn_load_param_pointer(b, sampler_type, b->func_param_idx++);
- } else if (type->base_type == vtn_base_type_image ||
- type->base_type == vtn_base_type_sampler) {
- vtn_push_pointer(b, w[2], vtn_load_param_pointer(b, type, b->func_param_idx++));
- } else {
- /* We're a regular SSA value. */
- struct vtn_ssa_value *value = vtn_create_ssa_value(b, type->type);
- vtn_ssa_value_load_function_param(b, value, &b->func_param_idx);
- vtn_push_ssa_value(b, w[2], value);
- }
+ struct vtn_type *type = vtn_get_type(b, w[1]);
+ struct vtn_ssa_value *value = vtn_create_ssa_value(b, type->type);
+ vtn_ssa_value_load_function_param(b, value, &b->func_param_idx);
+ vtn_push_ssa_value(b, w[2], value);
break;
}