Module: vkd3d Branch: master Commit: f08c0a7c035286bdb8339c642de0de7d87abae93 URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/f08c0a7c035286bdb8339c642de0de...
Author: Francisco Casas fcasas@codeweavers.com Date: Mon Jan 23 17:02:40 2023 -0300
vkd3d-shader/hlsl: Find compatible function overloads.
But still throw hlsl_fixme() when there is more than one. Prioritizing among multiple compatible function overloads in the same way as the native compiler would require systematic testing.
---
libs/vkd3d-shader/hlsl.y | 45 ++++++++++++++++++++++++++---- tests/array-parameters.shader_test | 12 ++++---- tests/cast-broadcast.shader_test | 6 ++-- tests/cast-componentwise-equal.shader_test | 6 ++-- tests/hlsl-intrinsic-override.shader_test | 10 +++---- 5 files changed, 56 insertions(+), 23 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index d1ca91b8..42acbd95 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2220,8 +2220,10 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
struct find_function_call_args { + struct hlsl_ctx *ctx; const struct parse_initializer *params; struct hlsl_ir_function_decl *decl; + unsigned int compatible_overloads_count; };
static void find_function_call_exact(struct rb_entry *entry, void *context) @@ -2241,10 +2243,31 @@ static void find_function_call_exact(struct rb_entry *entry, void *context) args->decl = decl; }
+static void find_function_call_compatible(struct rb_entry *entry, void *context) +{ + struct hlsl_ir_function_decl *decl = RB_ENTRY_VALUE(entry, struct hlsl_ir_function_decl, entry); + struct find_function_call_args *args = context; + unsigned int i; + + if (decl->parameters.count != args->params->args_count) + return; + + for (i = 0; i < decl->parameters.count; ++i) + { + if (!implicit_compatible_data_types(args->ctx, args->params->args[i]->data_type, + decl->parameters.vars[i]->data_type)) + return; + } + + args->compatible_overloads_count++; + args->decl = decl; +} + static struct hlsl_ir_function_decl *find_function_call(struct hlsl_ctx *ctx, - const char *name, const struct parse_initializer *params) + const char *name, const struct parse_initializer *params, + const struct vkd3d_shader_location *loc) { - struct find_function_call_args args = {.params = params}; + struct find_function_call_args args = {.ctx = ctx, .params = params}; struct hlsl_ir_function *func; struct rb_entry *entry;
@@ -2254,7 +2277,13 @@ static struct hlsl_ir_function_decl *find_function_call(struct hlsl_ctx *ctx,
rb_for_each_entry(&func->overloads, find_function_call_exact, &args); if (!args.decl) - FIXME("Search for compatible overloads.\n"); + { + rb_for_each_entry(&func->overloads, find_function_call_compatible, &args); + if (args.compatible_overloads_count > 1) + { + hlsl_fixme(ctx, loc, "Prioritize between multiple compatible function overloads."); + } + } return args.decl; }
@@ -3055,7 +3084,7 @@ static struct list *add_call(struct hlsl_ctx *ctx, const char *name, struct intrinsic_function *intrinsic; struct hlsl_ir_function_decl *decl;
- if ((decl = find_function_call(ctx, name, args))) + if ((decl = find_function_call(ctx, name, args, loc))) { struct hlsl_ir_node *call; unsigned int i; @@ -3069,8 +3098,12 @@ static struct list *add_call(struct hlsl_ctx *ctx, const char *name,
if (!hlsl_types_are_equal(arg->data_type, param->data_type)) { - hlsl_fixme(ctx, &arg->loc, "Implicit cast of a function argument."); - continue; + struct hlsl_ir_node *cast; + + if (!(cast = add_cast(ctx, args->instrs, arg, param->data_type, &arg->loc))) + goto fail; + args->args[i] = cast; + arg = cast; }
if (param->storage_modifiers & HLSL_STORAGE_IN) diff --git a/tests/array-parameters.shader_test b/tests/array-parameters.shader_test index 3b7d628d..6e866ceb 100644 --- a/tests/array-parameters.shader_test +++ b/tests/array-parameters.shader_test @@ -139,7 +139,7 @@ float4 main() : sv_target
% Arrays with the same number of components are allowed. -[pixel shader todo] +[pixel shader] float fun(float a[2][3]) { return 100*a[0][0] + 10*a[0][2] + a[1][2]; @@ -153,11 +153,11 @@ float4 main() : sv_target }
[test] -todo draw quad -todo probe all rgba (136.0, 136.0, 136.0, 136.0) +draw quad +probe all rgba (136.0, 136.0, 136.0, 136.0)
-[pixel shader todo] +[pixel shader] float fun(float a[2][3]) { return 100*a[0][0] + 10*a[1][0] + a[1][2]; @@ -171,5 +171,5 @@ float4 main() : sv_target }
[test] -todo draw quad -todo probe all rgba (702.0, 702.0, 702.0, 702.0) +draw quad +probe all rgba (702.0, 702.0, 702.0, 702.0) diff --git a/tests/cast-broadcast.shader_test b/tests/cast-broadcast.shader_test index a7462e76..3ec9cd40 100644 --- a/tests/cast-broadcast.shader_test +++ b/tests/cast-broadcast.shader_test @@ -82,7 +82,7 @@ float4 PSMain() : SV_TARGET }
-[pixel shader todo] +[pixel shader] float4 fun(float3 f) { return f.xyxy; @@ -94,5 +94,5 @@ float4 main() : SV_TARGET }
[test] -todo draw quad -todo probe all rgba (33.0, 33.0, 33.0, 33.0) +draw quad +probe all rgba (33.0, 33.0, 33.0, 33.0) diff --git a/tests/cast-componentwise-equal.shader_test b/tests/cast-componentwise-equal.shader_test index 7fe9304b..4a25f6dd 100644 --- a/tests/cast-componentwise-equal.shader_test +++ b/tests/cast-componentwise-equal.shader_test @@ -124,7 +124,7 @@ draw quad probe all rgba (4.0, 4.0, 4.0, 4.0)
-[pixel shader todo] +[pixel shader] Texture2D tex;
struct apple @@ -154,8 +154,8 @@ float4 main() : sv_target }
[test] -todo draw quad -todo probe all rgba (5.0, 5.0, 5.0, 5.0) +draw quad +probe all rgba (5.0, 5.0, 5.0, 5.0)
[pixel shader] diff --git a/tests/hlsl-intrinsic-override.shader_test b/tests/hlsl-intrinsic-override.shader_test index f9233a5c..13e1752d 100644 --- a/tests/hlsl-intrinsic-override.shader_test +++ b/tests/hlsl-intrinsic-override.shader_test @@ -1,4 +1,4 @@ -[pixel shader todo] +[pixel shader]
float2 max(float2 a, float2 b) { @@ -11,10 +11,10 @@ float4 main() : sv_target }
[test] -todo draw quad -probe all rgba (0.3, 0.3, 0.4, 0.6) +draw quad +todo probe all rgba (0.3, 0.3, 0.4, 0.6)
-[pixel shader todo] +[pixel shader]
float2 max(float2 a, float3 b) { @@ -27,5 +27,5 @@ float4 main() : sv_target }
[test] -todo draw quad +draw quad probe all rgba (0.3, 0.3, 0.3, 0.4)