diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp index add895121fd..c5de8ae17c9 100644 --- a/src/compiler/glsl/glsl_parser_extras.cpp +++ b/src/compiler/glsl/glsl_parser_extras.cpp @@ -1033,56 +1033,6 @@ _mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp, return true; } -bool -_mesa_glsl_can_implicitly_convert(const glsl_type *from, const glsl_type *desired, - bool has_implicit_conversions, - bool has_implicit_int_to_uint_conversion) -{ - if (from == desired) - return true; - - /* GLSL 1.10 and ESSL do not allow implicit conversions. */ - if (!has_implicit_conversions) - return false; - - /* There is no conversion among matrix types. */ - if (from->matrix_columns > 1 || desired->matrix_columns > 1) - return false; - - /* Vector size must match. */ - if (from->vector_elements != desired->vector_elements) - return false; - - /* int and uint can be converted to float. */ - if (glsl_type_is_float(desired) && (glsl_type_is_integer_32(from) || - glsl_type_is_float_16(from))) - return true; - - /* With GLSL 4.0, ARB_gpu_shader5, or MESA_shader_integer_functions, int - * can be converted to uint. Note that state may be NULL here, when - * resolving function calls in the linker. By this time, all the - * state-dependent checks have already happened though, so allow anything - * that's allowed in any shader version. - */ - if (has_implicit_int_to_uint_conversion && - desired->base_type == GLSL_TYPE_UINT && from->base_type == GLSL_TYPE_INT) - return true; - - /* No implicit conversions from double. */ - if (glsl_type_is_double(from)) - return false; - - /* Conversions from different types to double. */ - if (glsl_type_is_double(desired)) { - if (glsl_type_is_float_16_32(from)) - return true; - if (glsl_type_is_integer_32(from)) - return true; - } - - return false; -} - /** * Recurses through and if is an aggregate initializer * and sets 's field to . Gives later functions diff --git a/src/compiler/glsl/glsl_parser_extras.h b/src/compiler/glsl/glsl_parser_extras.h index 68cff2abcc8..98f5ec589bd 100644 --- a/src/compiler/glsl/glsl_parser_extras.h +++ b/src/compiler/glsl/glsl_parser_extras.h @@ -1071,45 +1071,6 @@ extern bool _mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp, YYLTYPE *behavior_locp, _mesa_glsl_parse_state *state); - -/** - * \brief Can \c from be implicitly converted to \c desired - * - * \return True if the types are identical or if \c from type can be converted - * to \c desired according to Section 4.1.10 of the GLSL spec. - * - * \verbatim - * From page 25 (31 of the pdf) of the GLSL 1.50 spec, Section 4.1.10 - * Implicit Conversions: - * - * In some situations, an expression and its type will be implicitly - * converted to a different type. The following table shows all allowed - * implicit conversions: - * - * Type of expression | Can be implicitly converted to - * -------------------------------------------------- - * int float - * uint - * - * ivec2 vec2 - * uvec2 - * - * ivec3 vec3 - * uvec3 - * - * ivec4 vec4 - * uvec4 - * - * There are no implicit array or structure conversions. For example, - * an array of int cannot be implicitly converted to an array of float. - * There are no implicit conversions between signed and unsigned - * integers. - * \endverbatim - */ -extern bool _mesa_glsl_can_implicitly_convert(const glsl_type *from, const glsl_type *desired, - bool has_implicit_conversions, - bool has_implicit_int_to_uint_conversion); - #endif /* __cplusplus */ diff --git a/src/compiler/glsl/ir_function.cpp b/src/compiler/glsl/ir_function.cpp index 4f696ff8a77..7560761a914 100644 --- a/src/compiler/glsl/ir_function.cpp +++ b/src/compiler/glsl/ir_function.cpp @@ -24,6 +24,7 @@ #include "compiler/glsl_types.h" #include "ir.h" #include "glsl_parser_extras.h" +#include "linker_util.h" #include "main/errors.h" typedef enum { diff --git a/src/compiler/glsl/linker_util.cpp b/src/compiler/glsl/linker_util.cpp index 5c6766d5144..41adec6a9da 100644 --- a/src/compiler/glsl/linker_util.cpp +++ b/src/compiler/glsl/linker_util.cpp @@ -459,3 +459,53 @@ interpolation_string(unsigned interpolation) assert(!"Should not get here."); return ""; } + +bool +_mesa_glsl_can_implicitly_convert(const glsl_type *from, const glsl_type *desired, + bool has_implicit_conversions, + bool has_implicit_int_to_uint_conversion) +{ + if (from == desired) + return true; + + /* GLSL 1.10 and ESSL do not allow implicit conversions. */ + if (!has_implicit_conversions) + return false; + + /* There is no conversion among matrix types. */ + if (from->matrix_columns > 1 || desired->matrix_columns > 1) + return false; + + /* Vector size must match. */ + if (from->vector_elements != desired->vector_elements) + return false; + + /* int and uint can be converted to float. */ + if (glsl_type_is_float(desired) && (glsl_type_is_integer_32(from) || + glsl_type_is_float_16(from))) + return true; + + /* With GLSL 4.0, ARB_gpu_shader5, or MESA_shader_integer_functions, int + * can be converted to uint. Note that state may be NULL here, when + * resolving function calls in the linker. By this time, all the + * state-dependent checks have already happened though, so allow anything + * that's allowed in any shader version. + */ + if (has_implicit_int_to_uint_conversion && + desired->base_type == GLSL_TYPE_UINT && from->base_type == GLSL_TYPE_INT) + return true; + + /* No implicit conversions from double. */ + if (glsl_type_is_double(from)) + return false; + + /* Conversions from different types to double. */ + if (glsl_type_is_double(desired)) { + if (glsl_type_is_float_16_32(from)) + return true; + if (glsl_type_is_integer_32(from)) + return true; + } + + return false; +} diff --git a/src/compiler/glsl/linker_util.h b/src/compiler/glsl/linker_util.h index fc59a46c99e..f927b2b3414 100644 --- a/src/compiler/glsl/linker_util.h +++ b/src/compiler/glsl/linker_util.h @@ -142,6 +142,44 @@ link_util_mark_array_elements_referenced(const struct array_deref_range *dr, */ const char *interpolation_string(unsigned interpolation); +/** + * \brief Can \c from be implicitly converted to \c desired + * + * \return True if the types are identical or if \c from type can be converted + * to \c desired according to Section 4.1.10 of the GLSL spec. + * + * \verbatim + * From page 25 (31 of the pdf) of the GLSL 1.50 spec, Section 4.1.10 + * Implicit Conversions: + * + * In some situations, an expression and its type will be implicitly + * converted to a different type. The following table shows all allowed + * implicit conversions: + * + * Type of expression | Can be implicitly converted to + * -------------------------------------------------- + * int float + * uint + * + * ivec2 vec2 + * uvec2 + * + * ivec3 vec3 + * uvec3 + * + * ivec4 vec4 + * uvec4 + * + * There are no implicit array or structure conversions. For example, + * an array of int cannot be implicitly converted to an array of float. + * There are no implicit conversions between signed and unsigned + * integers. + * \endverbatim + */ +extern bool _mesa_glsl_can_implicitly_convert(const glsl_type *from, const glsl_type *desired, + bool has_implicit_conversions, + bool has_implicit_int_to_uint_conversion); + #ifdef __cplusplus } #endif