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 <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2021-01-13 13:09:13 -05:00
parent d8e9436a78
commit 3c1917983b
8 changed files with 61 additions and 159 deletions

View File

@ -1,2 +1,3 @@
void construct_float3_from_float_float() { float3 x = float3(1.0, 2.0); } 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_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)); }

View File

@ -1,11 +1,10 @@
struct Foo { int x; }; struct Foo { int x; };
Foo foo; Foo foo;
void construct_float2_from_float_bool() { float2 x = float2(1.0, false); } void construct_struct_from_int() { Foo x = Foo(5); } // NOT YET IMPLEMENTED
void construct_float2_from_bool2() { float2 x = float2(bool2(false)); } void construct_struct_from_float2x2() { Foo x = Foo(float2x2(0)); }
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_float_from_struct() { float x = float(foo); } void construct_float_from_struct() { float x = float(foo); }
void construct_float2_from_struct() { float2 x = float2(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); }

View File

@ -2,4 +2,5 @@
error: 1: invalid arguments to 'float3' constructor (expected 3 scalars, but found 2) 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) 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

View File

@ -1,11 +1,10 @@
### Compilation failed: ### Compilation failed:
error: 4: expected 'float', but found 'bool' error: 4: cannot construct 'Foo'
error: 5: 'bool2' is not a valid parameter to 'float2' constructor error: 5: cannot construct 'Foo'
error: 6: 'float2' is not a valid parameter to 'bool2' constructor error: 6: invalid argument to 'float' constructor (expected a number or bool, but found 'Foo')
error: 7: invalid argument to 'bool' constructor (expected a number or bool, but found 'int3') error: 7: 'Foo' is not a valid parameter to 'float2' constructor
error: 8: cannot construct 'Foo' error: 8: 'Foo' is not a valid parameter to 'float2x2' constructor
error: 9: invalid argument to 'float' constructor (expected a number or bool, but found 'Foo') error: 9: '<INVALID>' is not a valid parameter to 'float2x2' constructor
error: 10: 'Foo' is not a valid parameter to 'float2' constructor error: 10: '<INVALID>' is not a valid parameter to 'float2x2' constructor
error: 11: expected 'float', but found 'bool' 7 errors
8 errors

View File

@ -5,7 +5,20 @@ float3 v4 = float3(float2(1), 1.0);
int2 v5 = int2(1); int2 v5 = int2(1);
int2 v6 = int2(float2(1, 2)); int2 v6 = int2(float2(1, 2));
float2 v7 = float2(int2(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() { 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);
} }

View File

@ -1,99 +1,11 @@
OpCapability Shader ### Compilation failed:
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450 error: 10: expected 'int', but found 'float'
OpEntryPoint Fragment %main "main" %sk_FragColor %sk_Clockwise error: 12: expected 'float', but found 'bool'
OpExecutionMode %main OriginUpperLeft error: 13: expected 'float', but found 'bool'
OpName %sk_FragColor "sk_FragColor" error: 14: 'bool2' is not a valid parameter to 'float2' constructor
OpName %sk_Clockwise "sk_Clockwise" error: 15: expected 'bool', but found 'float'
OpName %v1 "v1" error: 16: 'float2' is not a valid parameter to 'bool2' constructor
OpName %v2 "v2" error: 17: expected 'bool', but found 'float'
OpName %v3 "v3" error: 21: unknown identifier 'v10'
OpName %v4 "v4" 8 errors
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

View File

@ -1,12 +1,11 @@
### Compilation failed:
out vec4 sk_FragColor; error: 10: expected 'int', but found 'float'
vec2 v1 = vec2(1.0); error: 12: expected 'float', but found 'bool'
vec2 v2 = vec2(1.0, 2.0); error: 13: expected 'float', but found 'bool'
vec2 v3 = vec2(1.0); error: 14: 'bool2' is not a valid parameter to 'float2' constructor
vec3 v4 = vec3(vec2(1.0), 1.0); error: 15: expected 'bool', but found 'float'
ivec2 v5 = ivec2(1); error: 16: 'float2' is not a valid parameter to 'bool2' constructor
ivec2 v6 = ivec2(vec2(1.0, 2.0)); error: 17: expected 'bool', but found 'float'
vec2 v7 = vec2(ivec2(1, 2)); error: 21: unknown identifier 'v10'
void main() { 8 errors
sk_FragColor.x = (((((v1.x + v2.x) + v3.x) + v4.x) + float(v5.x)) + float(v6.x)) + v7.x;
}

View File

@ -1,33 +1,11 @@
#include <metal_stdlib> ### Compilation failed:
#include <simd/simd.h>
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;
};
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
fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { error: 17: expected 'bool', but found 'float'
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))}; error: 21: unknown identifier 'v10'
thread Globals* _globals = &globalStruct; 8 errors
(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;
}