compiler/types: Flip wrapping of various type identification checks

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25470>
This commit is contained in:
Caio Oliveira 2023-09-01 23:49:26 -07:00 committed by Marge Bot
parent dd9ced45f5
commit f94377915e
4 changed files with 165 additions and 227 deletions

View file

@ -3364,4 +3364,71 @@ glsl_get_sampler_dim_coordinate_components(enum glsl_sampler_dim dim)
}
}
bool
glsl_type_is_vector(const struct glsl_type *t)
{
return t->vector_elements > 1 &&
t->matrix_columns == 1 &&
t->base_type >= GLSL_TYPE_UINT &&
t->base_type <= GLSL_TYPE_BOOL;
}
bool
glsl_type_is_scalar(const struct glsl_type *t)
{
return t->vector_elements == 1 &&
t->base_type >= GLSL_TYPE_UINT &&
t->base_type <= GLSL_TYPE_IMAGE;
}
bool
glsl_type_is_vector_or_scalar(const struct glsl_type *t)
{
return glsl_type_is_vector(t) || glsl_type_is_scalar(t);
}
bool
glsl_type_is_matrix(const struct glsl_type *t)
{
/* GLSL only has float matrices. */
return t->matrix_columns > 1 && (t->base_type == GLSL_TYPE_FLOAT ||
t->base_type == GLSL_TYPE_DOUBLE ||
t->base_type == GLSL_TYPE_FLOAT16);
}
bool
glsl_type_is_array_or_matrix(const struct glsl_type *t)
{
return glsl_type_is_array(t) || glsl_type_is_matrix(t);
}
bool
glsl_type_is_dual_slot(const struct glsl_type *t)
{
return glsl_type_is_64bit(t) && t->vector_elements > 2;
}
const struct glsl_type *
glsl_get_array_element(const struct glsl_type *t)
{
if (glsl_type_is_matrix(t))
return t->column_type();
else if (glsl_type_is_vector(t))
return t->get_scalar_type();
return t->fields.array;
}
bool
glsl_type_is_leaf(const struct glsl_type *t)
{
if (glsl_type_is_struct_or_ifc(t) ||
(glsl_type_is_array(t) &&
(glsl_type_is_array(glsl_get_array_element(t)) ||
glsl_type_is_struct_or_ifc(glsl_get_array_element(t))))) {
return false;
} else {
return true;
}
}
}

View file

@ -1174,6 +1174,20 @@ static inline bool glsl_type_is_cmat(const struct glsl_type *t) { return t->base
static inline bool glsl_type_is_void(const struct glsl_type *t) { return t->base_type == GLSL_TYPE_VOID; }
static inline bool glsl_type_is_subroutine(const struct glsl_type *t) { return t->base_type == GLSL_TYPE_SUBROUTINE; }
static inline bool glsl_type_is_error(const struct glsl_type *t) { return t->base_type == GLSL_TYPE_ERROR; }
static inline bool glsl_type_is_double(const struct glsl_type *t) { return t->base_type == GLSL_TYPE_DOUBLE; }
static inline bool
glsl_type_is_numeric(const struct glsl_type *t)
{
return t->base_type >= GLSL_TYPE_UINT &&
t->base_type <= GLSL_TYPE_INT64;
}
static inline bool
glsl_type_is_integer(const struct glsl_type *t)
{
return glsl_base_type_is_integer(t->base_type);
}
static inline bool
glsl_type_is_struct_or_ifc(const struct glsl_type *t)
@ -1181,17 +1195,50 @@ glsl_type_is_struct_or_ifc(const struct glsl_type *t)
return glsl_type_is_struct(t) || glsl_type_is_interface(t);
}
bool glsl_type_is_packed(const struct glsl_type *t);
bool glsl_type_is_16bit(const struct glsl_type *t);
bool glsl_type_is_32bit(const struct glsl_type *t);
bool glsl_type_is_64bit(const struct glsl_type *t);
static inline bool
glsl_type_is_packed(const struct glsl_type *t)
{
return t->packed;
}
static inline bool
glsl_type_is_16bit(const struct glsl_type *t)
{
return glsl_base_type_is_16bit(t->base_type);
}
static inline bool
glsl_type_is_32bit(const struct glsl_type *t)
{
return t->base_type == GLSL_TYPE_UINT ||
t->base_type == GLSL_TYPE_INT ||
t->base_type == GLSL_TYPE_FLOAT;
}
static inline bool
glsl_type_is_64bit(const struct glsl_type *t)
{
return glsl_base_type_is_64bit(t->base_type);
}
static inline bool
glsl_type_is_unsized_array(const struct glsl_type *t)
{
return glsl_type_is_array(t) && t->length == 0;
}
static inline bool
glsl_type_is_array_of_arrays(const struct glsl_type *t)
{
return glsl_type_is_array(t) && glsl_type_is_array(t->fields.array);
}
static inline bool
glsl_type_is_bare_sampler(const struct glsl_type *t)
{
return glsl_type_is_sampler(t) && t->sampled_type == GLSL_TYPE_VOID;
}
bool glsl_type_is_unsized_array(const struct glsl_type *t);
bool glsl_type_is_numeric(const struct glsl_type *t);
bool glsl_type_is_integer(const struct glsl_type *t);
bool glsl_type_is_double(const struct glsl_type *t);
bool glsl_type_is_array_of_arrays(const struct glsl_type *t);
bool glsl_type_is_bare_sampler(const struct glsl_type *t);
bool glsl_type_is_vector(const struct glsl_type *t);
bool glsl_type_is_scalar(const struct glsl_type *t);
bool glsl_type_is_vector_or_scalar(const struct glsl_type *t);
@ -1200,10 +1247,35 @@ bool glsl_type_is_array_or_matrix(const struct glsl_type *t);
bool glsl_type_is_dual_slot(const struct glsl_type *t);
bool glsl_type_is_leaf(const struct glsl_type *type);
bool glsl_matrix_type_is_row_major(const struct glsl_type *t);
bool glsl_sampler_type_is_shadow(const struct glsl_type *t);
bool glsl_sampler_type_is_array(const struct glsl_type *t);
bool glsl_struct_type_is_packed(const struct glsl_type *t);
static inline bool
glsl_matrix_type_is_row_major(const struct glsl_type *t)
{
assert((glsl_type_is_matrix(t) && t->explicit_stride) || glsl_type_is_interface(t));
return t->interface_row_major;
}
static inline bool
glsl_sampler_type_is_shadow(const struct glsl_type *t)
{
assert(glsl_type_is_sampler(t));
return t->sampler_shadow;
}
static inline bool
glsl_sampler_type_is_array(const struct glsl_type *t)
{
assert(glsl_type_is_sampler(t) ||
glsl_type_is_texture(t) ||
glsl_type_is_image(t));
return t->sampler_array;
}
static inline bool
glsl_struct_type_is_packed(const struct glsl_type *t)
{
assert(glsl_type_is_struct(t));
return t->packed;
}
const struct glsl_type *glsl_get_bare_type(const struct glsl_type *t);

View file

@ -25,72 +25,18 @@ inline bool glsl_type::is_error() const { return glsl_type_is_error(this); }
inline bool glsl_type::is_subroutine() const { return glsl_type_is_subroutine(this); }
inline bool glsl_type::is_atomic_uint() const { return glsl_type_is_atomic_uint(this); }
inline bool
glsl_type::is_scalar() const
{
return (vector_elements == 1)
&& (base_type >= GLSL_TYPE_UINT)
&& (base_type <= GLSL_TYPE_IMAGE);
}
inline bool glsl_type::is_scalar() const { return glsl_type_is_scalar(this); }
inline bool glsl_type::is_vector() const { return glsl_type_is_vector(this); }
inline bool glsl_type::is_matrix() const { return glsl_type_is_matrix(this); }
inline bool glsl_type::is_numeric() const { return glsl_type_is_numeric(this); }
inline bool glsl_type::is_integer() const { return glsl_type_is_integer(this); }
inline bool glsl_type::is_double() const { return glsl_type_is_double(this); }
inline bool
glsl_type::is_vector() const
{
return (vector_elements > 1)
&& (matrix_columns == 1)
&& (base_type >= GLSL_TYPE_UINT)
&& (base_type <= GLSL_TYPE_BOOL);
}
inline bool
glsl_type::is_matrix() const
{
/* GLSL only has float matrices. */
return (matrix_columns > 1) && (base_type == GLSL_TYPE_FLOAT ||
base_type == GLSL_TYPE_DOUBLE ||
base_type == GLSL_TYPE_FLOAT16);
}
inline bool
glsl_type::is_numeric() const
{
return (base_type >= GLSL_TYPE_UINT) && (base_type <= GLSL_TYPE_INT64);
}
inline bool glsl_type::is_integer() const { return glsl_base_type_is_integer(base_type); }
inline bool glsl_type::is_double() const { return base_type == GLSL_TYPE_DOUBLE; }
inline bool
glsl_type::is_array_of_arrays() const
{
return is_array() && fields.array->is_array();
}
inline bool
glsl_type::is_dual_slot() const
{
return is_64bit() && vector_elements > 2;
}
inline bool
glsl_type::is_64bit() const
{
return glsl_base_type_is_64bit(base_type);
}
inline bool
glsl_type::is_16bit() const
{
return glsl_base_type_is_16bit(base_type);
}
inline bool
glsl_type::is_32bit() const
{
return base_type == GLSL_TYPE_UINT ||
base_type == GLSL_TYPE_INT ||
base_type == GLSL_TYPE_FLOAT;
}
inline bool glsl_type::is_array_of_arrays() const { return glsl_type_is_array_of_arrays(this); }
inline bool glsl_type::is_dual_slot() const { return glsl_type_is_dual_slot(this); }
inline bool glsl_type::is_16bit() const { return glsl_type_is_16bit(this); }
inline bool glsl_type::is_32bit() const { return glsl_type_is_32bit(this); }
inline bool glsl_type::is_64bit() const { return glsl_type_is_64bit(this); }
inline unsigned
glsl_type::components() const
@ -291,11 +237,7 @@ glsl_type::array_size() const
return is_array() ? length : -1;
}
inline bool
glsl_type::is_unsized_array() const
{
return is_array() && length == 0;
}
inline bool glsl_type::is_unsized_array() const { return glsl_type_is_unsized_array(this); }
inline enum glsl_interface_packing
glsl_type::get_interface_packing() const

View file

@ -46,16 +46,6 @@ glsl_array_size(const struct glsl_type *type)
return type->array_size();
}
const struct glsl_type *
glsl_get_array_element(const struct glsl_type* type)
{
if (type->is_matrix())
return type->column_type();
else if (type->is_vector())
return type->get_scalar_type();
return type->fields.array;
}
const struct glsl_type *
glsl_without_array(const struct glsl_type *type)
{
@ -250,120 +240,6 @@ glsl_get_struct_location_offset(const struct glsl_type *type,
return type->struct_location_offset(length);
}
bool
glsl_type_is_16bit(const struct glsl_type *type)
{
return type->is_16bit();
}
bool
glsl_type_is_32bit(const struct glsl_type *type)
{
return type->is_32bit();
}
bool
glsl_type_is_64bit(const struct glsl_type *type)
{
return type->is_64bit();
}
bool
glsl_type_is_vector(const struct glsl_type *type)
{
return type->is_vector();
}
bool
glsl_type_is_scalar(const struct glsl_type *type)
{
return type->is_scalar();
}
bool
glsl_type_is_vector_or_scalar(const struct glsl_type *type)
{
return type->is_vector() || type->is_scalar();
}
bool
glsl_type_is_matrix(const struct glsl_type *type)
{
return type->is_matrix();
}
bool
glsl_matrix_type_is_row_major(const struct glsl_type *type)
{
assert((type->is_matrix() && type->explicit_stride) || type->is_interface());
return type->interface_row_major;
}
bool
glsl_type_is_unsized_array(const struct glsl_type *type)
{
return type->is_unsized_array();
}
bool
glsl_type_is_array_of_arrays(const struct glsl_type *type)
{
return type->is_array_of_arrays();
}
bool
glsl_type_is_array_or_matrix(const struct glsl_type *type)
{
return type->is_array() || type->is_matrix();
}
bool
glsl_type_is_bare_sampler(const struct glsl_type *type)
{
return type->is_sampler() && type->sampled_type == GLSL_TYPE_VOID;
}
bool
glsl_sampler_type_is_shadow(const struct glsl_type *type)
{
assert(glsl_type_is_sampler(type));
return type->sampler_shadow;
}
bool
glsl_sampler_type_is_array(const struct glsl_type *type)
{
assert(glsl_type_is_sampler(type) ||
glsl_type_is_texture(type) ||
glsl_type_is_image(type));
return type->sampler_array;
}
bool
glsl_struct_type_is_packed(const struct glsl_type *type)
{
assert(glsl_type_is_struct(type));
return type->packed;
}
bool
glsl_type_is_dual_slot(const struct glsl_type *type)
{
return type->is_dual_slot();
}
bool
glsl_type_is_numeric(const struct glsl_type *type)
{
return type->is_numeric();
}
bool
glsl_type_is_integer(const struct glsl_type *type)
{
return type->is_integer();
}
bool
glsl_type_contains_64bit(const struct glsl_type *type)
{
@ -1006,25 +882,6 @@ glsl_get_explicit_alignment(const struct glsl_type *type)
return type->explicit_alignment;
}
bool
glsl_type_is_packed(const struct glsl_type *type)
{
return type->packed;
}
bool
glsl_type_is_leaf(const struct glsl_type *type)
{
if (glsl_type_is_struct_or_ifc(type) ||
(glsl_type_is_array(type) &&
(glsl_type_is_array(glsl_get_array_element(type)) ||
glsl_type_is_struct_or_ifc(glsl_get_array_element(type))))) {
return false;
} else {
return true;
}
}
const struct glsl_type *
glsl_get_explicit_type_for_size_align(const struct glsl_type *type,
glsl_type_size_align_func type_info,