From cdf6100fe5708ffb23f74eb7844263d67f3bb8f5 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Tue, 10 Dec 2024 20:53:43 +0100 Subject: [PATCH] tests: Add yet more overload resolution tests. --- tests/hlsl/function-overload.shader_test | 123 +++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/tests/hlsl/function-overload.shader_test b/tests/hlsl/function-overload.shader_test index 6f666f4a..c371cb74 100644 --- a/tests/hlsl/function-overload.shader_test +++ b/tests/hlsl/function-overload.shader_test @@ -153,6 +153,16 @@ float4 main() : sv_target return func(float4(0.0, 0.0, 0.0, 0.0)); } +% That applies to widening as well. +[pixel shader fail] +float f(float3 x) { return 1.0; } +float f(float4 x) { return 2.0; } + +float4 main() : sv_target +{ + return f(float(0.0)); +} + % Even if one axis has less narrowing. [pixel shader fail] @@ -173,6 +183,34 @@ float4 main() : sv_target return func(mtx); } +% An exact match is preferred over widening. +[pixel shader todo] +float f(float x) { return 1.0; } +float f(float2 x) { return 2.0; } + +float4 main() : sv_target +{ + return f(float(0.0)); +} + +[test] +todo(sm<6) draw quad +probe (0, 0) rgba(1.0, 1.0, 1.0, 1.0) + +% Component type narrowing is preferred over component count narrowing. +[pixel shader todo] +float f(half4 x) { return 1.0; } +float f(float2 x) { return 2.0; } + +float4 main() : sv_target +{ + return f(float4(0.0, 0.0, 0.0, 0.0)); +} + +[test] +todo(sm<6) draw quad +probe (0, 0) rgba(1.0, 1.0, 1.0, 1.0) + % Let C be the common type that would be produced in an arithmetic expression % between the parameter and argument types. If C is the same as the parameter, the % overload is preferred to the case where C is the same base type as the argument but @@ -208,10 +246,40 @@ todo(sm<6) probe (0, 0) rgba(0.0, 0.0, 0.0, 0.0) % the first function (same as the argument) and "float" for the second function % (same as the parameter), so the first function is preferred. +% This is ambiguous; "bool" is no closer to "int" than it is to "float". +[pixel shader fail] +float f(int x) { return 1.0; } +float f(float x) { return 2.0; } + +float4 main() : sv_target +{ + return f(true); +} + [require] % No minimum precision types prior to SM4. shader model >= 4.0 +% The amount of component type narrowing doesn't matter. +[pixel shader fail] +float f(min16float x) { return 1.0; } +float f(min10float x) { return 2.0; } + +float4 main() : sv_target +{ + return f(float(0.0)); +} + +% Even for half to min16float conversion. +[pixel shader fail] +float f(min16float x) { return 1.0; } +float f(min10float x) { return 2.0; } + +float4 main() : sv_target +{ + return f(half(0.0)); +} + [pixel shader todo(sm<6)] float4 func(min16int x) @@ -283,6 +351,20 @@ float4 main() : sv_target todo(sm<6) draw quad todo(sm<6) probe (0, 0) rgba(2.0, 2.0, 2.0, 2.0) +% An exact match is preferred for minimum precision types as well. +[pixel shader todo] +float f(min16int x) { return 1.0; } +float f(int x) { return 2.0; } + +float4 main() : sv_target +{ + return f(min16int(0)); +} + +[test] +todo(sm<6) draw quad +probe (0, 0) rgba(1.0, 1.0, 1.0, 1.0) + [require] % Need SM5 for doubles. shader model >= 5.0 @@ -315,6 +397,47 @@ float4 main() : sv_target todo(sm<6) draw quad todo(sm<6) probe (0, 0) rgba(2.0, 2.0, 2.0, 2.0) +% Component type widening is preferred over component type narrowing. +[pixel shader todo] +float f(half x) { return 1.0; } +float f(double x) { return 2.0; } + +float4 main() : sv_target +{ + return f(float(0.0)); +} + +[test] +todo(sm<6) draw quad +probe (0, 0) rgba(2.0, 2.0, 2.0, 2.0) + +% Component count widening is preferred over component type narrowing. +[pixel shader todo] +float f(half x) { return 1.0; } +float f(double2 x) { return 2.0; } + +float4 main() : sv_target +{ + return f(float(0.0)); +} + +[test] +todo(sm<6) draw quad +probe (0, 0) rgba(2.0, 2.0, 2.0, 2.0) + +% Component count widening is preferred over component type class conversion. +[pixel shader todo] +float f(int x) { return 1.0; } +float f(double2 x) { return 2.0; } + +float4 main() : sv_target +{ + return f(float(0.0)); +} + +[test] +todo(sm<6) draw quad +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 % between the parameter and argument types. If C has the same base type as the argument, % but with more components, it is preferred over all other cases.