this->fields.structure = copied_struct;
}
-glsl_type::glsl_type(const glsl_type *return_type,
- const glsl_function_param *params, unsigned num_params) :
- gl_type(0),
- base_type(GLSL_TYPE_FUNCTION), sampled_type(GLSL_TYPE_VOID),
- sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
- interface_packing(0), interface_row_major(0), packed(0),
- vector_elements(0), matrix_columns(0),
- length(num_params), explicit_stride(0), explicit_alignment(0)
-{
- unsigned int i;
-
- this->mem_ctx = ralloc_context(NULL);
- assert(this->mem_ctx != NULL);
-
- this->name = "";
-
- struct glsl_function_param *copied_params =
- rzalloc_array(this->mem_ctx, glsl_function_param, num_params + 1);
-
- /* We store the return type as the first parameter */
- copied_params[0].type = return_type;
- copied_params[0].in = false;
- copied_params[0].out = true;
-
- /* We store the i'th parameter in slot i+1 */
- for (i = 0; i < length; i++) {
- copied_params[i + 1].type = params[i].type;
- copied_params[i + 1].in = params[i].in;
- copied_params[i + 1].out = params[i].out;
- }
-
- this->fields.parameters = copied_params;
-}
-
glsl_type::glsl_type(const char *subroutine_name) :
gl_type(0),
base_type(GLSL_TYPE_SUBROUTINE), sampled_type(GLSL_TYPE_VOID),
case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_VOID:
case GLSL_TYPE_SUBROUTINE:
- case GLSL_TYPE_FUNCTION:
case GLSL_TYPE_ERROR:
return this;
}
return t;
}
-
-static bool
-function_key_compare(const void *a, const void *b)
-{
- const glsl_type *const key1 = (glsl_type *) a;
- const glsl_type *const key2 = (glsl_type *) b;
-
- if (key1->length != key2->length)
- return false;
-
- return memcmp(key1->fields.parameters, key2->fields.parameters,
- (key1->length + 1) * sizeof(*key1->fields.parameters)) == 0;
-}
-
-
-static uint32_t
-function_key_hash(const void *a)
-{
- const glsl_type *const key = (glsl_type *) a;
- return _mesa_hash_data(key->fields.parameters,
- (key->length + 1) * sizeof(*key->fields.parameters));
-}
-
-const glsl_type *
-glsl_type::get_function_instance(const glsl_type *return_type,
- const glsl_function_param *params,
- unsigned num_params)
-{
- const glsl_type key(return_type, params, num_params);
- const uint32_t key_hash = function_key_hash(&key);
-
- simple_mtx_lock(&glsl_type::hash_mutex);
- assert(glsl_type_users > 0);
-
- if (function_types == NULL) {
- function_types = _mesa_hash_table_create(NULL, function_key_hash,
- function_key_compare);
- }
-
- struct hash_entry *entry = _mesa_hash_table_search_pre_hashed(function_types, key_hash, &key);
- if (entry == NULL) {
- const glsl_type *t = new glsl_type(return_type, params, num_params);
-
- entry = _mesa_hash_table_insert_pre_hashed(function_types, key_hash, t, (void *) t);
- }
-
- auto t = (const glsl_type *)entry->data;
- simple_mtx_unlock(&glsl_type::hash_mutex);
-
- assert(t->base_type == GLSL_TYPE_FUNCTION);
- assert(t->length == num_params);
-
- return t;
-}
-
-
const glsl_type *
glsl_type::get_mul_type(const glsl_type *type_a, const glsl_type *type_b)
{
case GLSL_TYPE_SUBROUTINE:
return 1;
- case GLSL_TYPE_FUNCTION:
case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_VOID:
case GLSL_TYPE_ERROR:
case GLSL_TYPE_SUBROUTINE:
return 1;
- case GLSL_TYPE_FUNCTION:
case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_VOID:
case GLSL_TYPE_ERROR:
case GLSL_TYPE_SUBROUTINE:
return 1;
- case GLSL_TYPE_FUNCTION:
case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_VOID:
case GLSL_TYPE_ERROR:
return 1;
case GLSL_TYPE_VOID:
case GLSL_TYPE_ERROR:
- case GLSL_TYPE_FUNCTION:
default:
unreachable("invalid type in st_glsl_type_dword_size()");
}
GLSL_TYPE_ARRAY,
GLSL_TYPE_VOID,
GLSL_TYPE_SUBROUTINE,
- GLSL_TYPE_FUNCTION,
GLSL_TYPE_ERROR
};
*/
union {
const struct glsl_type *array; /**< Type of array elements. */
- const struct glsl_function_param *parameters; /**< Parameters to function. */
const struct glsl_struct_field *structure; /**< List of struct fields. */
} fields;
static const glsl_type *get_subroutine_instance(const char *subroutine_name);
/**
- * Get the instance of a function type
- */
- static const glsl_type *get_function_instance(const struct glsl_type *return_type,
- const glsl_function_param *parameters,
- unsigned num_params);
-
- /**
* Get the type resulting from a multiplication of \p type_a * \p type_b
*/
static const glsl_type *get_mul_type(const glsl_type *type_a,
enum glsl_interface_packing packing,
bool row_major, const char *name);
- /** Constructor for interface types */
- glsl_type(const glsl_type *return_type,
- const glsl_function_param *params, unsigned num_params);
-
/** Constructors for array types */
glsl_type(const glsl_type *array, unsigned length, unsigned explicit_stride);
#endif
};
-struct glsl_function_param {
- const struct glsl_type *type;
-
- bool in;
- bool out;
-};
-
#endif /* GLSL_TYPES_H */
}
const glsl_type *
-glsl_get_function_return_type(const glsl_type *type)
-{
- return type->fields.parameters[0].type;
-}
-
-const glsl_function_param *
-glsl_get_function_param(const glsl_type *type, unsigned index)
-{
- return &type->fields.parameters[index + 1];
-}
-
-const glsl_type *
glsl_texture_type_to_sampler(const glsl_type *type, bool is_shadow)
{
assert(glsl_type_is_texture(type));
}
const glsl_type *
-glsl_function_type(const glsl_type *return_type,
- const glsl_function_param *params, unsigned num_params)
-{
- return glsl_type::get_function_instance(return_type, params, num_params);
-}
-
-const glsl_type *
glsl_transposed_type(const struct glsl_type *type)
{
assert(glsl_type_is_matrix(type));
case GLSL_TYPE_SUBROUTINE:
case GLSL_TYPE_VOID:
case GLSL_TYPE_ERROR:
- case GLSL_TYPE_FUNCTION:
unreachable("type does not have a natural size");
}
}
case GLSL_TYPE_SUBROUTINE:
case GLSL_TYPE_VOID:
case GLSL_TYPE_ERROR:
- case GLSL_TYPE_FUNCTION:
unreachable("type does not make sense for glsl_get_vec4_size_align_bytes()");
}
}