unsigned array_size = 1;
nir_deref *tail = &deref->deref;
while (tail->child) {
- if (tail->child->deref_type == nir_deref_type_array) {
- /* Multiply by the parent's type. */
- if (glsl_type_is_matrix(tail->type)) {
- array_size *= glsl_get_matrix_columns(tail->type);
- } else {
- assert(glsl_get_length(tail->type) > 0);
- array_size *= glsl_get_length(tail->type);
- }
- }
+ if (tail->child->deref_type == nir_deref_type_array)
+ array_size *= glsl_get_length(tail->type);
tail = tail->child;
}
return deref;
}
-static int
-type_get_length(const struct glsl_type *type)
-{
- switch (glsl_get_base_type(type)) {
- case GLSL_TYPE_STRUCT:
- case GLSL_TYPE_ARRAY:
- return glsl_get_length(type);
- case GLSL_TYPE_FLOAT:
- case GLSL_TYPE_INT:
- case GLSL_TYPE_UINT:
- case GLSL_TYPE_BOOL:
- if (glsl_type_is_matrix(type))
- return glsl_get_matrix_columns(type);
- else
- return glsl_get_vector_elements(type);
- default:
- unreachable("Invalid deref base type");
- }
-}
-
/* This function recursively walks the given deref chain and replaces the
* given copy instruction with an equivalent sequence load/store
* operations.
nir_deref_array *src_arr = nir_deref_as_array(src_arr_parent->child);
nir_deref_array *dest_arr = nir_deref_as_array(dest_arr_parent->child);
- unsigned length = type_get_length(src_arr_parent->type);
+ unsigned length = glsl_get_length(src_arr_parent->type);
/* The wildcards should represent the same number of elements */
- assert(length == type_get_length(dest_arr_parent->type));
+ assert(length == glsl_get_length(dest_arr_parent->type));
assert(length > 0);
/* Walk over all of the elements that this wildcard refers to and
struct hash_table *phi_table;
};
-static int
-type_get_length(const struct glsl_type *type)
-{
- switch (glsl_get_base_type(type)) {
- case GLSL_TYPE_STRUCT:
- case GLSL_TYPE_ARRAY:
- return glsl_get_length(type);
- case GLSL_TYPE_FLOAT:
- case GLSL_TYPE_INT:
- case GLSL_TYPE_UINT:
- case GLSL_TYPE_BOOL:
- if (glsl_type_is_matrix(type))
- return glsl_get_matrix_columns(type);
- else
- return glsl_get_vector_elements(type);
- default:
- unreachable("Invalid deref base type");
- }
-}
-
static struct deref_node *
deref_node_create(struct deref_node *parent,
const struct glsl_type *type, nir_shader *shader)
{
size_t size = sizeof(struct deref_node) +
- type_get_length(type) * sizeof(struct deref_node *);
+ glsl_get_length(type) * sizeof(struct deref_node *);
struct deref_node *node = rzalloc_size(shader, size);
node->type = type;
case nir_deref_type_struct: {
nir_deref_struct *deref_struct = nir_deref_as_struct(tail);
- assert(deref_struct->index < type_get_length(node->type));
+ assert(deref_struct->index < glsl_get_length(node->type));
if (node->children[deref_struct->index] == NULL)
node->children[deref_struct->index] =
* out-of-bounds offset. We need to handle this at least
* somewhat gracefully.
*/
- if (arr->base_offset >= type_get_length(node->type))
+ if (arr->base_offset >= glsl_get_length(node->type))
return NULL;
if (node->children[arr->base_offset] == NULL)
unsigned
glsl_get_length(const struct glsl_type *type)
{
- return type->length;
+ return type->is_matrix() ? type->matrix_columns : type->length;
}
const char *