2010-03-11 14:50:30 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2010 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "glsl_types.h"
|
|
|
|
|
#include "ir.h"
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
type_compare(const glsl_type *a, const glsl_type *b)
|
|
|
|
|
{
|
2010-03-25 13:05:43 -07:00
|
|
|
/* If the types are the same, they trivially match.
|
|
|
|
|
*/
|
|
|
|
|
if (a == b)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2010-03-11 14:50:30 -08:00
|
|
|
switch (a->base_type) {
|
|
|
|
|
case GLSL_TYPE_UINT:
|
|
|
|
|
case GLSL_TYPE_INT:
|
|
|
|
|
case GLSL_TYPE_BOOL:
|
2010-04-02 11:45:06 -07:00
|
|
|
/* There is no implicit conversion to or from integer types or bool.
|
|
|
|
|
*/
|
|
|
|
|
if ((a->is_integer() != b->is_integer())
|
|
|
|
|
|| (a->is_boolean() != b->is_boolean()))
|
2010-03-11 14:50:30 -08:00
|
|
|
return -1;
|
|
|
|
|
|
2010-04-02 11:45:06 -07:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
|
|
case GLSL_TYPE_FLOAT:
|
|
|
|
|
if ((a->vector_elements != b->vector_elements)
|
|
|
|
|
|| (a->matrix_columns != b->matrix_columns))
|
2010-03-11 14:50:30 -08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case GLSL_TYPE_SAMPLER:
|
|
|
|
|
case GLSL_TYPE_STRUCT:
|
2010-03-25 13:05:43 -07:00
|
|
|
/* Samplers and structures must match exactly.
|
|
|
|
|
*/
|
|
|
|
|
return -1;
|
2010-03-11 14:50:30 -08:00
|
|
|
|
|
|
|
|
case GLSL_TYPE_ARRAY:
|
|
|
|
|
if ((b->base_type != GLSL_TYPE_ARRAY)
|
|
|
|
|
|| (a->length != b->length))
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
/* From GLSL 1.50 spec, page 27 (page 33 of the PDF):
|
|
|
|
|
* "There are no implicit array or structure conversions."
|
|
|
|
|
*
|
|
|
|
|
* If the comparison of the array element types detects that a conversion
|
|
|
|
|
* would be required, the array types do not match.
|
|
|
|
|
*/
|
|
|
|
|
return (type_compare(a->fields.array, b->fields.array) == 0) ? 0 : -1;
|
|
|
|
|
|
|
|
|
|
case GLSL_TYPE_VOID:
|
|
|
|
|
case GLSL_TYPE_ERROR:
|
|
|
|
|
default:
|
|
|
|
|
/* These are all error conditions. It is invalid for a parameter to
|
|
|
|
|
* a function to be declared as error, void, or a function.
|
|
|
|
|
*/
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This point should be unreachable.
|
|
|
|
|
*/
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2010-07-15 13:09:25 -07:00
|
|
|
parameter_lists_match(const exec_list *list_a, const exec_list *list_b)
|
2010-03-11 14:50:30 -08:00
|
|
|
{
|
2010-07-15 13:09:25 -07:00
|
|
|
const exec_node *node_a = list_a->head;
|
|
|
|
|
const exec_node *node_b = list_b->head;
|
2010-03-11 14:50:30 -08:00
|
|
|
int total_score = 0;
|
|
|
|
|
|
2010-07-15 13:09:25 -07:00
|
|
|
for (/* empty */
|
2010-07-29 13:52:25 -07:00
|
|
|
; !node_a->is_tail_sentinel()
|
2010-07-15 13:09:25 -07:00
|
|
|
; node_a = node_a->next, node_b = node_b->next) {
|
2010-03-11 14:50:30 -08:00
|
|
|
/* If all of the parameters from the other parameter list have been
|
|
|
|
|
* exhausted, the lists have different length and, by definition,
|
|
|
|
|
* do not match.
|
|
|
|
|
*/
|
2010-07-29 13:52:25 -07:00
|
|
|
if (node_b->is_tail_sentinel())
|
2010-03-11 14:50:30 -08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
|
2010-07-15 13:09:25 -07:00
|
|
|
const ir_variable *const param = (ir_variable *) node_a;
|
|
|
|
|
const ir_instruction *const actual = (ir_instruction *) node_b;
|
2010-03-11 14:50:30 -08:00
|
|
|
|
|
|
|
|
/* Determine whether or not the types match. If the types are an
|
|
|
|
|
* exact match, the match score is zero. If the types don't match
|
|
|
|
|
* but the actual parameter can be coerced to the type of the declared
|
|
|
|
|
* parameter, the match score is one.
|
|
|
|
|
*/
|
|
|
|
|
int score;
|
|
|
|
|
switch ((enum ir_variable_mode)(param->mode)) {
|
|
|
|
|
case ir_var_auto:
|
|
|
|
|
case ir_var_uniform:
|
2010-07-19 17:12:42 -07:00
|
|
|
case ir_var_temporary:
|
2010-03-11 14:50:30 -08:00
|
|
|
/* These are all error conditions. It is invalid for a parameter to
|
|
|
|
|
* a function to be declared as auto (not in, out, or inout) or
|
|
|
|
|
* as uniform.
|
|
|
|
|
*/
|
|
|
|
|
assert(0);
|
|
|
|
|
return -1;
|
|
|
|
|
|
2011-01-12 15:37:37 -08:00
|
|
|
case ir_var_const_in:
|
2010-03-11 14:50:30 -08:00
|
|
|
case ir_var_in:
|
|
|
|
|
score = type_compare(param->type, actual->type);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ir_var_out:
|
|
|
|
|
score = type_compare(actual->type, param->type);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ir_var_inout:
|
|
|
|
|
/* Since there are no bi-directional automatic conversions (e.g.,
|
|
|
|
|
* there is int -> float but no float -> int), inout parameters must
|
|
|
|
|
* be exact matches.
|
|
|
|
|
*/
|
|
|
|
|
score = (type_compare(actual->type, param->type) == 0) ? 0 : -1;
|
|
|
|
|
break;
|
2010-08-21 20:38:07 -07:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
assert(false);
|
2010-03-11 14:50:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (score < 0)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
total_score += score;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If all of the parameters from the other parameter list have been
|
|
|
|
|
* exhausted, the lists have different length and, by definition, do not
|
|
|
|
|
* match.
|
|
|
|
|
*/
|
2010-07-29 13:52:25 -07:00
|
|
|
if (!node_b->is_tail_sentinel())
|
2010-03-11 14:50:30 -08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
return total_score;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-07-12 18:35:20 -07:00
|
|
|
ir_function_signature *
|
2010-07-15 13:09:25 -07:00
|
|
|
ir_function::matching_signature(const exec_list *actual_parameters)
|
2010-03-11 14:50:30 -08:00
|
|
|
{
|
|
|
|
|
ir_function_signature *match = NULL;
|
glsl: Find the "closest" signature when there are multiple matches.
Previously, ir_function::matching_signature had a fatal bug: if a
function had more than one non-exact match, it would simply return NULL.
This occured, for example, when looking for max(uvec3, uvec3):
- max(vec3, vec3) -> score 1 (found first)
- max(ivec3, ivec3) -> score 1 (found second...used to return NULL here)
- max(uvec3, uvec3) -> score 0 (exact match...the right answer)
This did not occur for max(ivec3, ivec3) since the second match found
was an exact match.
The new behavior is to return a match with the lowest score. If there
is an exact match, that will be returned. Otherwise, a match with the
least number of implicit conversions is chosen.
Fixes piglit tests max-uvec3.vert and glsl-inexact-overloads.shader_test.
NOTE: This is a candidate for the 7.10 and 7.11 branches.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
2011-06-14 16:28:32 -07:00
|
|
|
int matched_score;
|
2010-03-11 14:50:30 -08:00
|
|
|
|
|
|
|
|
foreach_iter(exec_list_iterator, iter, signatures) {
|
|
|
|
|
ir_function_signature *const sig =
|
|
|
|
|
(ir_function_signature *) iter.get();
|
|
|
|
|
|
|
|
|
|
const int score = parameter_lists_match(& sig->parameters,
|
|
|
|
|
actual_parameters);
|
|
|
|
|
|
glsl: Find the "closest" signature when there are multiple matches.
Previously, ir_function::matching_signature had a fatal bug: if a
function had more than one non-exact match, it would simply return NULL.
This occured, for example, when looking for max(uvec3, uvec3):
- max(vec3, vec3) -> score 1 (found first)
- max(ivec3, ivec3) -> score 1 (found second...used to return NULL here)
- max(uvec3, uvec3) -> score 0 (exact match...the right answer)
This did not occur for max(ivec3, ivec3) since the second match found
was an exact match.
The new behavior is to return a match with the lowest score. If there
is an exact match, that will be returned. Otherwise, a match with the
least number of implicit conversions is chosen.
Fixes piglit tests max-uvec3.vert and glsl-inexact-overloads.shader_test.
NOTE: This is a candidate for the 7.10 and 7.11 branches.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
2011-06-14 16:28:32 -07:00
|
|
|
/* If we found an exact match, simply return it */
|
2010-03-11 14:50:30 -08:00
|
|
|
if (score == 0)
|
|
|
|
|
return sig;
|
|
|
|
|
|
glsl: Find the "closest" signature when there are multiple matches.
Previously, ir_function::matching_signature had a fatal bug: if a
function had more than one non-exact match, it would simply return NULL.
This occured, for example, when looking for max(uvec3, uvec3):
- max(vec3, vec3) -> score 1 (found first)
- max(ivec3, ivec3) -> score 1 (found second...used to return NULL here)
- max(uvec3, uvec3) -> score 0 (exact match...the right answer)
This did not occur for max(ivec3, ivec3) since the second match found
was an exact match.
The new behavior is to return a match with the lowest score. If there
is an exact match, that will be returned. Otherwise, a match with the
least number of implicit conversions is chosen.
Fixes piglit tests max-uvec3.vert and glsl-inexact-overloads.shader_test.
NOTE: This is a candidate for the 7.10 and 7.11 branches.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
2011-06-14 16:28:32 -07:00
|
|
|
/* If we found a match with fewer conversions, use that instead */
|
|
|
|
|
if (score > 0 && (match == NULL || score < matched_score)) {
|
2010-03-11 14:50:30 -08:00
|
|
|
match = sig;
|
glsl: Find the "closest" signature when there are multiple matches.
Previously, ir_function::matching_signature had a fatal bug: if a
function had more than one non-exact match, it would simply return NULL.
This occured, for example, when looking for max(uvec3, uvec3):
- max(vec3, vec3) -> score 1 (found first)
- max(ivec3, ivec3) -> score 1 (found second...used to return NULL here)
- max(uvec3, uvec3) -> score 0 (exact match...the right answer)
This did not occur for max(ivec3, ivec3) since the second match found
was an exact match.
The new behavior is to return a match with the lowest score. If there
is an exact match, that will be returned. Otherwise, a match with the
least number of implicit conversions is chosen.
Fixes piglit tests max-uvec3.vert and glsl-inexact-overloads.shader_test.
NOTE: This is a candidate for the 7.10 and 7.11 branches.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
2011-06-14 16:28:32 -07:00
|
|
|
matched_score = score;
|
2010-03-11 14:50:30 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return match;
|
|
|
|
|
}
|
2010-04-28 12:04:23 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
2010-07-15 13:09:25 -07:00
|
|
|
parameter_lists_match_exact(const exec_list *list_a, const exec_list *list_b)
|
2010-04-28 12:04:23 -07:00
|
|
|
{
|
2010-07-15 13:09:25 -07:00
|
|
|
const exec_node *node_a = list_a->head;
|
|
|
|
|
const exec_node *node_b = list_b->head;
|
2010-04-28 12:04:23 -07:00
|
|
|
|
2010-07-15 13:09:25 -07:00
|
|
|
for (/* empty */
|
2010-07-29 13:52:25 -07:00
|
|
|
; !node_a->is_tail_sentinel() && !node_b->is_tail_sentinel()
|
2010-07-15 13:09:25 -07:00
|
|
|
; node_a = node_a->next, node_b = node_b->next) {
|
|
|
|
|
ir_variable *a = (ir_variable *) node_a;
|
|
|
|
|
ir_variable *b = (ir_variable *) node_b;
|
2010-04-28 12:04:23 -07:00
|
|
|
|
|
|
|
|
/* If the types of the parameters do not match, the parameters lists
|
|
|
|
|
* are different.
|
|
|
|
|
*/
|
|
|
|
|
if (a->type != b->type)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Unless both lists are exhausted, they differ in length and, by
|
|
|
|
|
* definition, do not match.
|
|
|
|
|
*/
|
2010-07-29 13:52:25 -07:00
|
|
|
return (node_a->is_tail_sentinel() == node_b->is_tail_sentinel());
|
2010-04-28 12:04:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ir_function_signature *
|
2010-07-15 13:09:25 -07:00
|
|
|
ir_function::exact_matching_signature(const exec_list *actual_parameters)
|
2010-04-28 12:04:23 -07:00
|
|
|
{
|
|
|
|
|
foreach_iter(exec_list_iterator, iter, signatures) {
|
|
|
|
|
ir_function_signature *const sig =
|
|
|
|
|
(ir_function_signature *) iter.get();
|
|
|
|
|
|
|
|
|
|
if (parameter_lists_match_exact(&sig->parameters, actual_parameters))
|
|
|
|
|
return sig;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|