compiler/types: Add glsl_get_mul_type() and use it in C++

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25129>
This commit is contained in:
Caio Oliveira 2023-09-07 19:50:36 -07:00 committed by Marge Bot
parent 795bf4244c
commit 3ce4d5e033
3 changed files with 17 additions and 15 deletions

View file

@ -1637,8 +1637,8 @@ glsl_subroutine_type(const char *subroutine_name)
return t;
}
const struct glsl_type *
glsl_type::get_mul_type(const struct glsl_type *type_a, const struct glsl_type *type_b)
extern "C" const struct glsl_type *
glsl_get_mul_type(const struct glsl_type *type_a, const struct glsl_type *type_b)
{
if (type_a->is_matrix() && type_b->is_matrix()) {
/* Matrix multiply. The columns of A must match the rows of B. Given
@ -1653,10 +1653,10 @@ glsl_type::get_mul_type(const struct glsl_type *type_a, const struct glsl_type *
* transpose (size of a row) is done for B.
*/
const struct glsl_type *const type =
get_instance(type_a->base_type,
type_a->column_type()->vector_elements,
type_b->row_type()->vector_elements);
assert(type != error_type);
glsl_type::get_instance(type_a->base_type,
type_a->column_type()->vector_elements,
type_b->row_type()->vector_elements);
assert(type != &glsl_type_builtin_error);
return type;
}
@ -1672,10 +1672,10 @@ glsl_type::get_mul_type(const struct glsl_type *type_a, const struct glsl_type *
/* The resulting vector has a number of elements equal to
* the number of rows of matrix A. */
const struct glsl_type *const type =
get_instance(type_a->base_type,
type_a->column_type()->vector_elements,
1);
assert(type != error_type);
glsl_type::get_instance(type_a->base_type,
type_a->column_type()->vector_elements,
1);
assert(type != &glsl_type_builtin_error);
return type;
}
@ -1691,16 +1691,16 @@ glsl_type::get_mul_type(const struct glsl_type *type_a, const struct glsl_type *
/* The resulting vector has a number of elements equal to
* the number of columns of matrix B. */
const struct glsl_type *const type =
get_instance(type_a->base_type,
type_b->row_type()->vector_elements,
1);
assert(type != error_type);
glsl_type::get_instance(type_a->base_type,
type_b->row_type()->vector_elements,
1);
assert(type != &glsl_type_builtin_error);
return type;
}
}
return error_type;
return &glsl_type_builtin_error;
}

View file

@ -1552,6 +1552,7 @@ glsl_sampler_type_to_texture(const struct glsl_type *t)
const struct glsl_type *glsl_replace_vector_type(const struct glsl_type *t, unsigned components);
const struct glsl_type *glsl_channel_type(const struct glsl_type *t);
const struct glsl_type *glsl_get_mul_type(const struct glsl_type *type_a, const struct glsl_type *type_b);
unsigned glsl_type_get_sampler_count(const struct glsl_type *t);
unsigned glsl_type_get_texture_count(const struct glsl_type *t);

View file

@ -169,6 +169,7 @@ glsl_type::get_explicit_type_for_size_align(glsl_type_size_align_func type_info,
}
inline const glsl_type *glsl_type::replace_vec3_with_vec4() const { return glsl_type_replace_vec3_with_vec4(this); }
inline const glsl_type *glsl_type::get_mul_type(const glsl_type *type_a, const glsl_type *type_b) { return glsl_get_mul_type(type_a, type_b); }
inline bool
glsl_type::is_integer_16() const