From 3c1917983bdb516599ec8e24634b0d03d9eb36f5 Mon Sep 17 00:00:00 2001 From: John Stiles Date: Wed, 13 Jan 2021 13:09:13 -0500 Subject: [PATCH] Update VectorConstructor unit test with mixed-type ctors. GLSL allows mixed types inside a vector constructor, but SkSL currently doesn't handle it well; some cases don't compile, and others generate bad code. This will be fixed in a followup CL. Change-Id: Ia98b498f320b8fa91595404730f6cdc836615140 Bug: skia:11164 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353577 Commit-Queue: John Stiles Commit-Queue: Brian Osman Reviewed-by: Brian Osman Auto-Submit: John Stiles --- .../sksl/errors/ConstructorArgumentCount.sksl | 1 + .../sksl/errors/ConstructorTypeMismatch.sksl | 11 +- .../golden/ConstructorArgumentCount.glsl | 3 +- .../golden/ConstructorTypeMismatch.glsl | 17 ++- tests/sksl/shared/VectorConstructors.sksl | 15 ++- .../shared/golden/VectorConstructors.asm.frag | 110 ++---------------- .../shared/golden/VectorConstructors.glsl | 21 ++-- .../shared/golden/VectorConstructors.metal | 42 ++----- 8 files changed, 61 insertions(+), 159 deletions(-) diff --git a/tests/sksl/errors/ConstructorArgumentCount.sksl b/tests/sksl/errors/ConstructorArgumentCount.sksl index 30e0a0db75..6aece5058b 100644 --- a/tests/sksl/errors/ConstructorArgumentCount.sksl +++ b/tests/sksl/errors/ConstructorArgumentCount.sksl @@ -1,2 +1,3 @@ void construct_float3_from_float_float() { float3 x = float3(1.0, 2.0); } void construct_float3_from_float_float_float_float() { float3 x = float3(1.0, 2.0, 3.0, 4.0); } +void construct_bool_from_int3() { bool x = bool(int3(77)); } diff --git a/tests/sksl/errors/ConstructorTypeMismatch.sksl b/tests/sksl/errors/ConstructorTypeMismatch.sksl index ef176d3cd3..039b3a1091 100644 --- a/tests/sksl/errors/ConstructorTypeMismatch.sksl +++ b/tests/sksl/errors/ConstructorTypeMismatch.sksl @@ -1,11 +1,10 @@ struct Foo { int x; }; Foo foo; -void construct_float2_from_float_bool() { float2 x = float2(1.0, false); } -void construct_float2_from_bool2() { float2 x = float2(bool2(false)); } -void construct_bool2_from_float2() { bool2 x = bool2(float2(1)); } -void construct_bool_from_int3() { bool x = bool(int3(77)); } -void construct_struct_from_int() { Foo x = Foo(5); } +void construct_struct_from_int() { Foo x = Foo(5); } // NOT YET IMPLEMENTED +void construct_struct_from_float2x2() { Foo x = Foo(float2x2(0)); } void construct_float_from_struct() { float x = float(foo); } void construct_float2_from_struct() { float2 x = float2(foo); } -void construct_float2x2_from_bool() { float2x2 x = float2x2(true); } +void construct_float2x2_from_struct() { float2x2 x = float2x2(foo); } +void construct_float2x2_from_type() { float2x2 x = float2x2(int); } +void construct_float2x2_from_function() { float2x2 x = float2x2(sqrt); } diff --git a/tests/sksl/errors/golden/ConstructorArgumentCount.glsl b/tests/sksl/errors/golden/ConstructorArgumentCount.glsl index f52e0b4b3c..087a932265 100644 --- a/tests/sksl/errors/golden/ConstructorArgumentCount.glsl +++ b/tests/sksl/errors/golden/ConstructorArgumentCount.glsl @@ -2,4 +2,5 @@ error: 1: invalid arguments to 'float3' constructor (expected 3 scalars, but found 2) error: 2: invalid arguments to 'float3' constructor (expected 3 scalars, but found 4) -2 errors +error: 3: invalid argument to 'bool' constructor (expected a number or bool, but found 'int3') +3 errors diff --git a/tests/sksl/errors/golden/ConstructorTypeMismatch.glsl b/tests/sksl/errors/golden/ConstructorTypeMismatch.glsl index 2d233d92b4..34ee9f8548 100644 --- a/tests/sksl/errors/golden/ConstructorTypeMismatch.glsl +++ b/tests/sksl/errors/golden/ConstructorTypeMismatch.glsl @@ -1,11 +1,10 @@ ### Compilation failed: -error: 4: expected 'float', but found 'bool' -error: 5: 'bool2' is not a valid parameter to 'float2' constructor -error: 6: 'float2' is not a valid parameter to 'bool2' constructor -error: 7: invalid argument to 'bool' constructor (expected a number or bool, but found 'int3') -error: 8: cannot construct 'Foo' -error: 9: invalid argument to 'float' constructor (expected a number or bool, but found 'Foo') -error: 10: 'Foo' is not a valid parameter to 'float2' constructor -error: 11: expected 'float', but found 'bool' -8 errors +error: 4: cannot construct 'Foo' +error: 5: cannot construct 'Foo' +error: 6: invalid argument to 'float' constructor (expected a number or bool, but found 'Foo') +error: 7: 'Foo' is not a valid parameter to 'float2' constructor +error: 8: 'Foo' is not a valid parameter to 'float2x2' constructor +error: 9: '' is not a valid parameter to 'float2x2' constructor +error: 10: '' is not a valid parameter to 'float2x2' constructor +7 errors diff --git a/tests/sksl/shared/VectorConstructors.sksl b/tests/sksl/shared/VectorConstructors.sksl index 42cae820ba..07cd0706d1 100644 --- a/tests/sksl/shared/VectorConstructors.sksl +++ b/tests/sksl/shared/VectorConstructors.sksl @@ -5,7 +5,20 @@ float3 v4 = float3(float2(1), 1.0); int2 v5 = int2(1); int2 v6 = int2(float2(1, 2)); float2 v7 = float2(int2(1, 2)); +float2 v8 = float2(v5); +float4 v9 = float4(v6.x, sqrt(2), int2(3, 4)); +int2 v10 = int2(3.14, v1.x); +bool4 v11 = bool4(bool2(true, false), true, false); +float2 v12 = float2(1.0, false); +float2 v13 = float2(false); +float2 v14 = float2(bool2(false)); +bool2 v15 = bool2(1.0); +bool2 v16 = bool2(float2(1)); +bool3 v17 = bool3(1.0, int2(77)); void main() { - sk_FragColor.r = half(v1.x + v2.x + v3.x + v4.x + v5.x + v6.x + v7.x); + sk_FragColor.r = half(v1.x) + half(v2.x) + half(v3.x) + half(v4.x) + half(v5.x) + half(v6.x) + + half(v7.x) + half(v8.x) + half(v9.x) + half(v10.x) + half(v11.x) + + half(v12.x) + half(v13.x) + half(v14.x) + half(v15.x) + half(v16.x) + + half(v17.x); } diff --git a/tests/sksl/shared/golden/VectorConstructors.asm.frag b/tests/sksl/shared/golden/VectorConstructors.asm.frag index 8ed6136eb1..0082e042f5 100644 --- a/tests/sksl/shared/golden/VectorConstructors.asm.frag +++ b/tests/sksl/shared/golden/VectorConstructors.asm.frag @@ -1,99 +1,11 @@ -OpCapability Shader -%1 = OpExtInstImport "GLSL.std.450" -OpMemoryModel Logical GLSL450 -OpEntryPoint Fragment %main "main" %sk_FragColor %sk_Clockwise -OpExecutionMode %main OriginUpperLeft -OpName %sk_FragColor "sk_FragColor" -OpName %sk_Clockwise "sk_Clockwise" -OpName %v1 "v1" -OpName %v2 "v2" -OpName %v3 "v3" -OpName %v4 "v4" -OpName %v5 "v5" -OpName %v6 "v6" -OpName %v7 "v7" -OpName %main "main" -OpDecorate %sk_FragColor RelaxedPrecision -OpDecorate %sk_FragColor Location 0 -OpDecorate %sk_FragColor Index 0 -OpDecorate %sk_Clockwise RelaxedPrecision -OpDecorate %sk_Clockwise BuiltIn FrontFacing -%float = OpTypeFloat 32 -%v4float = OpTypeVector %float 4 -%_ptr_Output_v4float = OpTypePointer Output %v4float -%sk_FragColor = OpVariable %_ptr_Output_v4float Output -%bool = OpTypeBool -%_ptr_Input_bool = OpTypePointer Input %bool -%sk_Clockwise = OpVariable %_ptr_Input_bool Input -%v2float = OpTypeVector %float 2 -%_ptr_Private_v2float = OpTypePointer Private %v2float -%v1 = OpVariable %_ptr_Private_v2float Private -%float_1 = OpConstant %float 1 -%14 = OpConstantComposite %v2float %float_1 %float_1 -%v2 = OpVariable %_ptr_Private_v2float Private -%float_2 = OpConstant %float 2 -%17 = OpConstantComposite %v2float %float_1 %float_2 -%v3 = OpVariable %_ptr_Private_v2float Private -%v3float = OpTypeVector %float 3 -%_ptr_Private_v3float = OpTypePointer Private %v3float -%v4 = OpVariable %_ptr_Private_v3float Private -%22 = OpConstantComposite %v3float %float_1 %float_1 %float_1 -%int = OpTypeInt 32 1 -%v2int = OpTypeVector %int 2 -%_ptr_Private_v2int = OpTypePointer Private %v2int -%v5 = OpVariable %_ptr_Private_v2int Private -%int_1 = OpConstant %int 1 -%28 = OpConstantComposite %v2int %int_1 %int_1 -%v6 = OpVariable %_ptr_Private_v2int Private -%v7 = OpVariable %_ptr_Private_v2float Private -%int_2 = OpConstant %int 2 -%37 = OpConstantComposite %v2int %int_1 %int_2 -%void = OpTypeVoid -%44 = OpTypeFunction %void -%_ptr_Output_float = OpTypePointer Output %float -%int_0 = OpConstant %int 0 -%main = OpFunction %void None %44 -%45 = OpLabel -OpStore %v1 %14 -OpStore %v2 %17 -OpStore %v3 %14 -OpStore %v4 %22 -OpStore %v5 %28 -%30 = OpCompositeExtract %float %17 0 -%31 = OpConvertFToS %int %30 -%32 = OpCompositeExtract %float %17 1 -%33 = OpConvertFToS %int %32 -%34 = OpCompositeConstruct %v2int %31 %33 -OpStore %v6 %34 -%38 = OpCompositeExtract %int %37 0 -%39 = OpConvertSToF %float %38 -%40 = OpCompositeExtract %int %37 1 -%41 = OpConvertSToF %float %40 -%42 = OpCompositeConstruct %v2float %39 %41 -OpStore %v7 %42 -%46 = OpLoad %v2float %v1 -%47 = OpCompositeExtract %float %46 0 -%48 = OpLoad %v2float %v2 -%49 = OpCompositeExtract %float %48 0 -%50 = OpFAdd %float %47 %49 -%51 = OpLoad %v2float %v3 -%52 = OpCompositeExtract %float %51 0 -%53 = OpFAdd %float %50 %52 -%54 = OpLoad %v3float %v4 -%55 = OpCompositeExtract %float %54 0 -%56 = OpFAdd %float %53 %55 -%58 = OpLoad %v2int %v5 -%59 = OpCompositeExtract %int %58 0 -%57 = OpConvertSToF %float %59 -%60 = OpFAdd %float %56 %57 -%62 = OpLoad %v2int %v6 -%63 = OpCompositeExtract %int %62 0 -%61 = OpConvertSToF %float %63 -%64 = OpFAdd %float %60 %61 -%65 = OpLoad %v2float %v7 -%66 = OpCompositeExtract %float %65 0 -%67 = OpFAdd %float %64 %66 -%68 = OpAccessChain %_ptr_Output_float %sk_FragColor %int_0 -OpStore %68 %67 -OpReturn -OpFunctionEnd +### Compilation failed: + +error: 10: expected 'int', but found 'float' +error: 12: expected 'float', but found 'bool' +error: 13: expected 'float', but found 'bool' +error: 14: 'bool2' is not a valid parameter to 'float2' constructor +error: 15: expected 'bool', but found 'float' +error: 16: 'float2' is not a valid parameter to 'bool2' constructor +error: 17: expected 'bool', but found 'float' +error: 21: unknown identifier 'v10' +8 errors diff --git a/tests/sksl/shared/golden/VectorConstructors.glsl b/tests/sksl/shared/golden/VectorConstructors.glsl index 2605864092..0082e042f5 100644 --- a/tests/sksl/shared/golden/VectorConstructors.glsl +++ b/tests/sksl/shared/golden/VectorConstructors.glsl @@ -1,12 +1,11 @@ +### Compilation failed: -out vec4 sk_FragColor; -vec2 v1 = vec2(1.0); -vec2 v2 = vec2(1.0, 2.0); -vec2 v3 = vec2(1.0); -vec3 v4 = vec3(vec2(1.0), 1.0); -ivec2 v5 = ivec2(1); -ivec2 v6 = ivec2(vec2(1.0, 2.0)); -vec2 v7 = vec2(ivec2(1, 2)); -void main() { - sk_FragColor.x = (((((v1.x + v2.x) + v3.x) + v4.x) + float(v5.x)) + float(v6.x)) + v7.x; -} +error: 10: expected 'int', but found 'float' +error: 12: expected 'float', but found 'bool' +error: 13: expected 'float', but found 'bool' +error: 14: 'bool2' is not a valid parameter to 'float2' constructor +error: 15: expected 'bool', but found 'float' +error: 16: 'float2' is not a valid parameter to 'bool2' constructor +error: 17: expected 'bool', but found 'float' +error: 21: unknown identifier 'v10' +8 errors diff --git a/tests/sksl/shared/golden/VectorConstructors.metal b/tests/sksl/shared/golden/VectorConstructors.metal index 366fbf6d1f..0082e042f5 100644 --- a/tests/sksl/shared/golden/VectorConstructors.metal +++ b/tests/sksl/shared/golden/VectorConstructors.metal @@ -1,33 +1,11 @@ -#include -#include -using namespace metal; -struct Inputs { -}; -struct Outputs { - float4 sk_FragColor [[color(0)]]; -}; -struct Globals { - float2 v1; - float2 v2; - float2 v3; - float3 v4; - int2 v5; - int2 v6; - float2 v7; -}; +### Compilation failed: - - - - - - -fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { - Globals globalStruct{float2(1.0), float2(1.0, 2.0), float2(1.0), float3(float2(1.0), 1.0), int2(1), int2(float2(1.0, 2.0)), float2(int2(1, 2))}; - thread Globals* _globals = &globalStruct; - (void)_globals; - Outputs _outputStruct; - thread Outputs* _out = &_outputStruct; - _out->sk_FragColor.x = (((((_globals->v1.x + _globals->v2.x) + _globals->v3.x) + _globals->v4.x) + float(_globals->v5.x)) + float(_globals->v6.x)) + _globals->v7.x; - return *_out; -} +error: 10: expected 'int', but found 'float' +error: 12: expected 'float', but found 'bool' +error: 13: expected 'float', but found 'bool' +error: 14: 'bool2' is not a valid parameter to 'float2' constructor +error: 15: expected 'bool', but found 'float' +error: 16: 'float2' is not a valid parameter to 'bool2' constructor +error: 17: expected 'bool', but found 'float' +error: 21: unknown identifier 'v10' +8 errors