Skip to content

Commit

Permalink
[HACK] vkd3d-shader/hlsl: Prioritize exact match on function overload…
Browse files Browse the repository at this point in the history
…s, again.

This patch is aimed for proton_9.0-4 to avoid regressions after commit
fef1185.

This is marked as a HACK because in some rare multiple compatible
overload edge cases the exact match is not prioritized.
  • Loading branch information
Francisco Casas authored and ivyl committed Nov 21, 2024
1 parent 5c00766 commit 0c0a55c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
27 changes: 27 additions & 0 deletions libs/vkd3d-shader/hlsl.y
Original file line number Diff line number Diff line change
Expand Up @@ -2965,6 +2965,30 @@ static struct hlsl_block *initialize_vars(struct hlsl_ctx *ctx, struct list *var
return initializers;
}

static bool func_is_exact_match(const struct hlsl_ir_function_decl *decl,
bool is_compile, const struct parse_initializer *args)
{
unsigned int i, k;

k = 0;
for (i = 0; i < decl->parameters.count; ++i)
{
if (is_compile && !(decl->parameters.vars[i]->storage_modifiers & HLSL_STORAGE_UNIFORM))
continue;

if (k >= args->args_count)
return false;

if (!hlsl_types_are_equal(decl->parameters.vars[i]->data_type, args->args[i]->data_type))
return false;

++k;
}
if (k < args->args_count)
return false;
return true;
}

static bool func_is_compatible_match(struct hlsl_ctx *ctx, const struct hlsl_ir_function_decl *decl,
bool is_compile, const struct parse_initializer *args)
{
Expand Down Expand Up @@ -3007,6 +3031,9 @@ static struct hlsl_ir_function_decl *find_function_call(struct hlsl_ctx *ctx,

LIST_FOR_EACH_ENTRY(decl, &func->overloads, struct hlsl_ir_function_decl, entry)
{
if (func_is_exact_match(decl, is_compile, args))
return decl;

if (func_is_compatible_match(ctx, decl, is_compile, args))
{
if (compatible_match)
Expand Down
6 changes: 3 additions & 3 deletions tests/hlsl/function-overload.shader_test
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ float4 main() : sv_target
}


[pixel shader todo]
[pixel shader]
float func(int arg)
{
return 1.0;
Expand All @@ -78,8 +78,8 @@ float4 main() : sv_target
}

[test]
todo(sm<6) draw quad
todo(sm<6) probe (0,0) rgba (1.0, 2.0, 2.0, 2.0)
draw quad
probe (0,0) rgba (1.0, 2.0, 2.0, 2.0)


% float and float1 can be defined separately...
Expand Down
4 changes: 2 additions & 2 deletions tests/hlsl/refract.shader_test
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ float4 main() : sv_target
return refract(r, n, i);
}

[pixel shader todo(sm<6)]
[pixel shader]
float4 r;
float4 n;
float i;
Expand All @@ -228,6 +228,6 @@ float4 main() : sv_target
}

[test]
todo(sm<6) draw quad
draw quad
if(sm<6) probe (0,0) rgba (2.0, 1.0, 1.0, 1.0)
if(sm>=6) probe (0,0) rgba (1.0, 1.0, 1.0, 1.0)

0 comments on commit 0c0a55c

Please sign in to comment.