mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-25 02:10:11 +01:00
compiler: Move can_implicitly_convert_to helper to glsl module from glsl_types.h
This move is done for decouple glsl_types from glsl_parser_extras Reviewed-by: Caio Oliveira <caio.oliveira@intel.com> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23420>
This commit is contained in:
parent
f9860a84b3
commit
ab73f717d9
7 changed files with 95 additions and 95 deletions
|
|
@ -1112,7 +1112,7 @@ implicitly_convert_component(ir_rvalue * &from, const glsl_base_type to,
|
|||
from->type->vector_elements,
|
||||
from->type->matrix_columns);
|
||||
|
||||
if (from->type->can_implicitly_convert_to(desired_type, state)) {
|
||||
if (_mesa_glsl_can_implicitly_convert(from->type, desired_type, state)) {
|
||||
/* Even though convert_component() implements the constructor
|
||||
* conversion rules (not the implicit conversion rules), its safe
|
||||
* to use it here because we already checked that the implicit
|
||||
|
|
|
|||
|
|
@ -7110,8 +7110,7 @@ ast_case_label::hir(exec_list *instructions,
|
|||
|
||||
/* Check if int->uint implicit conversion is supported. */
|
||||
bool integer_conversion_supported =
|
||||
glsl_type::int_type->can_implicitly_convert_to(glsl_type::uint_type,
|
||||
state);
|
||||
_mesa_glsl_can_implicitly_convert(glsl_type::int_type, glsl_type::uint_type, state);
|
||||
|
||||
if ((!type_a->is_integer_32() || !type_b->is_integer_32()) ||
|
||||
!integer_conversion_supported) {
|
||||
|
|
|
|||
|
|
@ -918,6 +918,56 @@ _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,
|
||||
_mesa_glsl_parse_state *state)
|
||||
{
|
||||
if (from == desired)
|
||||
return true;
|
||||
|
||||
/* GLSL 1.10 and ESSL do not allow implicit conversions. If there is no
|
||||
* state, we're doing intra-stage function linking where these checks have
|
||||
* already been done.
|
||||
*/
|
||||
if (state && !state->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 (desired->is_float() && from->is_integer_32())
|
||||
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 ((!state || state->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 ((!state || state->has_double()) && from->is_double())
|
||||
return false;
|
||||
|
||||
/* Conversions from different types to double. */
|
||||
if ((!state || state->has_double()) && desired->is_double()) {
|
||||
if (from->is_float())
|
||||
return true;
|
||||
if (from->is_integer_32())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recurses through <type> and <expr> if <expr> is an aggregate initializer
|
||||
|
|
|
|||
|
|
@ -1042,6 +1042,44 @@ 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,
|
||||
_mesa_glsl_parse_state *state);
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -84,12 +84,12 @@ parameter_lists_match(_mesa_glsl_parse_state *state,
|
|||
case ir_var_const_in:
|
||||
case ir_var_function_in:
|
||||
if (param->data.implicit_conversion_prohibited ||
|
||||
!actual->type->can_implicitly_convert_to(param->type, state))
|
||||
!_mesa_glsl_can_implicitly_convert(actual->type, param->type, state))
|
||||
return PARAMETER_LIST_NO_MATCH;
|
||||
break;
|
||||
|
||||
case ir_var_function_out:
|
||||
if (!param->type->can_implicitly_convert_to(actual->type, state))
|
||||
if (!_mesa_glsl_can_implicitly_convert(param->type, actual->type, state))
|
||||
return PARAMETER_LIST_NO_MATCH;
|
||||
break;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,10 +22,11 @@
|
|||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "main/macros.h"
|
||||
#include "compiler/glsl/glsl_parser_extras.h"
|
||||
#include "glsl_types.h"
|
||||
#include "util/compiler.h"
|
||||
#include "util/hash_table.h"
|
||||
#include "util/macros.h"
|
||||
#include "util/u_math.h"
|
||||
#include "util/u_string.h"
|
||||
|
||||
|
||||
|
|
@ -1941,57 +1942,6 @@ glsl_type::varying_count() const
|
|||
}
|
||||
}
|
||||
|
||||
bool
|
||||
glsl_type::can_implicitly_convert_to(const glsl_type *desired,
|
||||
_mesa_glsl_parse_state *state) const
|
||||
{
|
||||
if (this == desired)
|
||||
return true;
|
||||
|
||||
/* GLSL 1.10 and ESSL do not allow implicit conversions. If there is no
|
||||
* state, we're doing intra-stage function linking where these checks have
|
||||
* already been done.
|
||||
*/
|
||||
if (state && !state->has_implicit_conversions())
|
||||
return false;
|
||||
|
||||
/* There is no conversion among matrix types. */
|
||||
if (this->matrix_columns > 1 || desired->matrix_columns > 1)
|
||||
return false;
|
||||
|
||||
/* Vector size must match. */
|
||||
if (this->vector_elements != desired->vector_elements)
|
||||
return false;
|
||||
|
||||
/* int and uint can be converted to float. */
|
||||
if (desired->is_float() && this->is_integer_32())
|
||||
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 ((!state || state->has_implicit_int_to_uint_conversion()) &&
|
||||
desired->base_type == GLSL_TYPE_UINT && this->base_type == GLSL_TYPE_INT)
|
||||
return true;
|
||||
|
||||
/* No implicit conversions from double. */
|
||||
if ((!state || state->has_double()) && this->is_double())
|
||||
return false;
|
||||
|
||||
/* Conversions from different types to double. */
|
||||
if ((!state || state->has_double()) && desired->is_double()) {
|
||||
if (this->is_float())
|
||||
return true;
|
||||
if (this->is_integer_32())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned
|
||||
glsl_type::std140_base_alignment(bool row_major) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -695,43 +695,6 @@ public:
|
|||
*/
|
||||
unsigned explicit_size(bool align_to_stride=false) const;
|
||||
|
||||
/**
|
||||
* \brief Can this type be implicitly converted to another?
|
||||
*
|
||||
* \return True if the types are identical or if this 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
|
||||
*/
|
||||
bool can_implicitly_convert_to(const glsl_type *desired,
|
||||
_mesa_glsl_parse_state *state) const;
|
||||
|
||||
/**
|
||||
* Query whether or not a type is a scalar (non-vector and non-matrix).
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue