vkd3d-shader/hlsl: Prefer overload candidates with matching component type classes.

This commit is contained in:
Henri Verbeet 2024-12-10 22:00:07 +01:00
parent 63fce3062e
commit 6b8878377f
Notes: Henri Verbeet 2024-12-16 17:26:51 +01:00
Approved-by: Francisco Casas (@fcasas)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1313
2 changed files with 39 additions and 8 deletions

View File

@ -2998,11 +2998,32 @@ static bool func_is_compatible_match(struct hlsl_ctx *ctx, const struct hlsl_ir_
return true; return true;
} }
static enum hlsl_base_type hlsl_base_type_class(enum hlsl_base_type t)
{
switch (t)
{
case HLSL_TYPE_HALF:
case HLSL_TYPE_FLOAT:
case HLSL_TYPE_DOUBLE:
return HLSL_TYPE_FLOAT;
case HLSL_TYPE_INT:
case HLSL_TYPE_UINT:
return HLSL_TYPE_INT;
case HLSL_TYPE_BOOL:
return HLSL_TYPE_BOOL;
}
return 0;
}
static int function_parameter_compare(const struct hlsl_ir_var *candidate, static int function_parameter_compare(const struct hlsl_ir_var *candidate,
const struct hlsl_ir_var *ref, const struct hlsl_ir_node *arg) const struct hlsl_ir_var *ref, const struct hlsl_ir_node *arg)
{ {
struct struct
{ {
enum hlsl_base_type class;
unsigned int count; unsigned int count;
} c, r, a; } c, r, a;
int ret; int ret;
@ -3011,8 +3032,13 @@ static int function_parameter_compare(const struct hlsl_ir_var *candidate,
if (!hlsl_is_numeric_type(arg->data_type)) if (!hlsl_is_numeric_type(arg->data_type))
return 0; return 0;
c.class = hlsl_base_type_class(candidate->data_type->e.numeric.type);
c.count = hlsl_type_component_count(candidate->data_type); c.count = hlsl_type_component_count(candidate->data_type);
r.class = hlsl_base_type_class(ref->data_type->e.numeric.type);
r.count = hlsl_type_component_count(ref->data_type); r.count = hlsl_type_component_count(ref->data_type);
a.class = hlsl_base_type_class(arg->data_type->e.numeric.type);
a.count = hlsl_type_component_count(arg->data_type); a.count = hlsl_type_component_count(arg->data_type);
/* Prefer candidates without component count narrowing. E.g., given an /* Prefer candidates without component count narrowing. E.g., given an
@ -3020,6 +3046,11 @@ static int function_parameter_compare(const struct hlsl_ir_var *candidate,
if ((ret = (a.count > r.count) - (a.count > c.count))) if ((ret = (a.count > r.count) - (a.count > c.count)))
return ret; return ret;
/* Prefer candidates with matching component type classes. E.g., given a
* float argument, double is a better match than int. */
if ((ret = (a.class == c.class) - (a.class == r.class)))
return ret;
return 0; return 0;
} }

View File

@ -280,7 +280,7 @@ float4 main() : sv_target
return f(half(0.0)); return f(half(0.0));
} }
[pixel shader todo(sm<6)] [pixel shader]
float4 func(min16int x) float4 func(min16int x)
{ {
@ -298,8 +298,8 @@ float4 main() : sv_target
} }
[test] [test]
todo(sm<6) draw quad draw quad
todo(sm<6) probe (0, 0) rgba(2.0, 2.0, 2.0, 2.0) probe (0, 0) rgba(2.0, 2.0, 2.0, 2.0)
% Let C be the common type that would be produced in an arithmetic expression % Let C be the common type that would be produced in an arithmetic expression
% between the parameter and argument types. If C is "int" and the parameter is "uint", the % between the parameter and argument types. If C is "int" and the parameter is "uint", the
@ -376,7 +376,7 @@ shader model >= 5.0
% E.g. in the following example, C is "double" for the first function (a promoted % E.g. in the following example, C is "double" for the first function (a promoted
% type of the "float" argument) and "float" for the second function. % type of the "float" argument) and "float" for the second function.
[pixel shader todo] [pixel shader]
float4 func(double x) float4 func(double x)
{ {
@ -394,8 +394,8 @@ float4 main() : sv_target
} }
[test] [test]
todo(sm<6) draw quad draw quad
todo(sm<6) probe (0, 0) rgba(2.0, 2.0, 2.0, 2.0) probe (0, 0) rgba(2.0, 2.0, 2.0, 2.0)
% Component type widening is preferred over component type narrowing. % Component type widening is preferred over component type narrowing.
[pixel shader todo] [pixel shader todo]
@ -426,7 +426,7 @@ todo(sm<6) draw quad
probe (0, 0) rgba(2.0, 2.0, 2.0, 2.0) probe (0, 0) rgba(2.0, 2.0, 2.0, 2.0)
% Component count widening is preferred over component type class conversion. % Component count widening is preferred over component type class conversion.
[pixel shader todo] [pixel shader]
float f(int x) { return 1.0; } float f(int x) { return 1.0; }
float f(double2 x) { return 2.0; } float f(double2 x) { return 2.0; }
@ -436,7 +436,7 @@ float4 main() : sv_target
} }
[test] [test]
todo(sm<6) draw quad draw quad
probe (0, 0) rgba(2.0, 2.0, 2.0, 2.0) probe (0, 0) rgba(2.0, 2.0, 2.0, 2.0)
% Let C be the common type that would be produced in an arithmetic expression % Let C be the common type that would be produced in an arithmetic expression
% between the parameter and argument types. If C has the same base type as the argument, % between the parameter and argument types. If C has the same base type as the argument,