From 07ee4bd69fdd524b00ea7c6311fa4042bcfd4263 Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Fri, 8 Sep 2023 09:50:45 -0700 Subject: [PATCH] compiler/types: Add remaining type extraction functions and use them in C++ Reviewed-by: Kenneth Graunke Part-of: --- src/compiler/glsl_types.cpp | 39 ++++++++++++++++++++------------------- src/compiler/glsl_types.h | 4 ++++ src/compiler/glsl_types_impl.h | 2 ++ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp index c23495a..bd8c894 100644 --- a/src/compiler/glsl_types.cpp +++ b/src/compiler/glsl_types.cpp @@ -309,49 +309,50 @@ glsl_type_contains_image(const struct glsl_type *t) } } -const struct glsl_type *glsl_type::get_base_type() const +extern "C" const struct glsl_type * +glsl_get_base_glsl_type(const struct glsl_type *t) { - switch (base_type) { + switch (t->base_type) { case GLSL_TYPE_UINT: - return uint_type; + return &glsl_type_builtin_uint; case GLSL_TYPE_UINT16: - return uint16_t_type; + return &glsl_type_builtin_uint16_t; case GLSL_TYPE_UINT8: - return uint8_t_type; + return &glsl_type_builtin_uint8_t; case GLSL_TYPE_INT: - return int_type; + return &glsl_type_builtin_int; case GLSL_TYPE_INT16: - return int16_t_type; + return &glsl_type_builtin_int16_t; case GLSL_TYPE_INT8: - return int8_t_type; + return &glsl_type_builtin_int8_t; case GLSL_TYPE_FLOAT: - return float_type; + return &glsl_type_builtin_float; case GLSL_TYPE_FLOAT16: - return float16_t_type; + return &glsl_type_builtin_float16_t; case GLSL_TYPE_DOUBLE: - return double_type; + return &glsl_type_builtin_double; case GLSL_TYPE_BOOL: - return bool_type; + return &glsl_type_builtin_bool; case GLSL_TYPE_UINT64: - return uint64_t_type; + return &glsl_type_builtin_uint64_t; case GLSL_TYPE_INT64: - return int64_t_type; + return &glsl_type_builtin_int64_t; default: - return error_type; + return &glsl_type_builtin_error; } } - -const struct glsl_type *glsl_type::get_scalar_type() const +extern "C" const struct glsl_type * +glsl_get_scalar_type(const struct glsl_type *t) { - const struct glsl_type *type = this; + const struct glsl_type *type = t; /* Handle arrays */ while (type->base_type == GLSL_TYPE_ARRAY) type = type->fields.array; const struct glsl_type *scalar_type = type->get_base_type(); - if (scalar_type == error_type) + if (scalar_type == &glsl_type_builtin_error) return type; return scalar_type; diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h index 800ff62..4f717df 100644 --- a/src/compiler/glsl_types.h +++ b/src/compiler/glsl_types.h @@ -1277,6 +1277,8 @@ glsl_struct_type_is_packed(const struct glsl_type *t) } const struct glsl_type *glsl_get_bare_type(const struct glsl_type *t); +const struct glsl_type *glsl_get_scalar_type(const struct glsl_type *t); +const struct glsl_type *glsl_get_base_glsl_type(const struct glsl_type *t); unsigned glsl_get_length(const struct glsl_type *t); @@ -1298,6 +1300,8 @@ glsl_get_matrix_columns(const struct glsl_type *t) return t->matrix_columns; } +const struct glsl_type *glsl_type_wrap_in_arrays(const struct glsl_type *t, + const struct glsl_type *arrays); static inline int glsl_array_size(const struct glsl_type *t) { diff --git a/src/compiler/glsl_types_impl.h b/src/compiler/glsl_types_impl.h index 66df1da..68f8316 100644 --- a/src/compiler/glsl_types_impl.h +++ b/src/compiler/glsl_types_impl.h @@ -88,6 +88,8 @@ inline const glsl_type *glsl_type::get_explicit_interface_type(bool supports_std inline const glsl_type *glsl_type::row_type() const { return glsl_get_row_type(this); } inline const glsl_type *glsl_type::column_type() const { return glsl_get_column_type(this); } inline const glsl_type *glsl_type::get_bare_type() const { return glsl_get_bare_type(this); } +inline const glsl_type *glsl_type::get_base_type() const { return glsl_get_base_glsl_type(this); } +inline const glsl_type *glsl_type::get_scalar_type() const { return glsl_get_scalar_type(this); } inline const glsl_type *glsl_type::get_float16_type() const { return glsl_float16_type(this); } inline const glsl_type *glsl_type::get_int16_type() const { return glsl_int16_type(this); } -- 2.7.4