compiler/types: Add a wrap_in_arrays helper

This has been copied+pasted 3 times now.

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13389>
This commit is contained in:
Jason Ekstrand 2021-10-15 16:26:32 -05:00 committed by Marge Bot
parent 5818d47ae6
commit b62b2fa4b9
5 changed files with 20 additions and 41 deletions

View file

@ -432,17 +432,6 @@ nir_visitor::constant_copy(ir_constant *ir, void *mem_ctx)
return ret;
}
static const glsl_type *
wrap_type_in_array(const glsl_type *elem_type, const glsl_type *array_type)
{
if (!array_type->is_array())
return elem_type;
elem_type = wrap_type_in_array(elem_type, array_type->fields.array);
return glsl_type::get_array_instance(elem_type, array_type->length);
}
static unsigned
get_nir_how_declared(unsigned how_declared)
{
@ -588,7 +577,7 @@ nir_visitor::visit(ir_variable *ir)
/* If the type contains the interface, wrap the explicit type in the
* right number of arrays.
*/
var->type = wrap_type_in_array(explicit_ifc_type, ir->type);
var->type = glsl_type_wrap_in_arrays(explicit_ifc_type, ir->type);
} else {
/* Otherwise, this variable is one entry in the interface */
UNUSED bool found = false;

View file

@ -78,19 +78,6 @@ struct field {
nir_variable *var;
};
static const struct glsl_type *
wrap_type_in_array(const struct glsl_type *type,
const struct glsl_type *array_type)
{
if (!glsl_type_is_array(array_type))
return type;
const struct glsl_type *elem_type =
wrap_type_in_array(type, glsl_get_array_element(array_type));
assert(glsl_get_explicit_stride(array_type) == 0);
return glsl_array_type(elem_type, glsl_get_length(array_type), 0);
}
static int
num_array_levels_in_array_of_vector_type(const struct glsl_type *type)
{
@ -141,7 +128,7 @@ init_field_for_type(struct field *field, struct field *parent,
} else {
const struct glsl_type *var_type = type;
for (struct field *f = field->parent; f; f = f->parent)
var_type = wrap_type_in_array(var_type, f->type);
var_type = glsl_type_wrap_in_arrays(var_type, f->type);
nir_variable_mode mode = state->base_var->data.mode;
if (mode == nir_var_function_temp) {

View file

@ -1048,6 +1048,19 @@ glsl_get_explicit_type_for_size_align(const struct glsl_type *type,
return type->get_explicit_type_for_size_align(type_info, size, align);
}
const struct glsl_type *
glsl_type_wrap_in_arrays(const struct glsl_type *type,
const struct glsl_type *arrays)
{
if (!glsl_type_is_array(arrays))
return type;
const glsl_type *elem_type =
glsl_type_wrap_in_arrays(type, glsl_get_array_element(arrays));
return glsl_array_type(elem_type, glsl_get_length(arrays),
glsl_get_explicit_stride(arrays));
}
const struct glsl_type *
glsl_type_replace_vec3_with_vec4(const struct glsl_type *type)
{

View file

@ -248,6 +248,9 @@ const struct glsl_type *glsl_get_explicit_type_for_size_align(const struct glsl_
glsl_type_size_align_func type_info,
unsigned *size, unsigned *align);
const struct glsl_type *glsl_type_wrap_in_arrays(const struct glsl_type *type,
const struct glsl_type *arrays);
const struct glsl_type *glsl_type_replace_vec3_with_vec4(const struct glsl_type *type);
unsigned glsl_type_get_sampler_count(const struct glsl_type *type);

View file

@ -853,19 +853,6 @@ vtn_type_copy(struct vtn_builder *b, struct vtn_type *src)
return dest;
}
static const struct glsl_type *
wrap_type_in_array(const struct glsl_type *type,
const struct glsl_type *array_type)
{
if (!glsl_type_is_array(array_type))
return type;
const struct glsl_type *elem_type =
wrap_type_in_array(type, glsl_get_array_element(array_type));
return glsl_array_type(elem_type, glsl_get_length(array_type),
glsl_get_explicit_stride(array_type));
}
static bool
vtn_type_needs_explicit_layout(struct vtn_builder *b, struct vtn_type *type,
enum vtn_variable_mode mode)
@ -907,7 +894,7 @@ vtn_type_get_nir_type(struct vtn_builder *b, struct vtn_type *type,
vtn_fail_if(glsl_without_array(type->type) != glsl_uint_type(),
"Variables in the AtomicCounter storage class should be "
"(possibly arrays of arrays of) uint.");
return wrap_type_in_array(glsl_atomic_uint_type(), type->type);
return glsl_type_wrap_in_arrays(glsl_atomic_uint_type(), type->type);
}
if (mode == vtn_variable_mode_uniform) {
@ -968,7 +955,7 @@ vtn_type_get_nir_type(struct vtn_builder *b, struct vtn_type *type,
if (mode == vtn_variable_mode_image) {
struct vtn_type *image_type = vtn_type_without_array(type);
vtn_assert(image_type->base_type == vtn_base_type_image);
return wrap_type_in_array(image_type->glsl_image, type->type);
return glsl_type_wrap_in_arrays(image_type->glsl_image, type->type);
}
/* Layout decorations are allowed but ignored in certain conditions,