Add scalar-swizzling tests for int and bool types.

Boolean scalar-swizzling is currently not working.

Change-Id: Icd965e4b64a12311d098168f65622110d5fb3437
Bug: skia:12195
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/427038
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
John Stiles 2021-07-12 14:59:19 -04:00 committed by Skia Commit-Bot
parent 0742e6ba2d
commit 7f56b41fc0
14 changed files with 205 additions and 53 deletions

View File

@ -378,6 +378,8 @@ sksl_shared_tests = [
"/sksl/shared/SwizzleLTRB.sksl", "/sksl/shared/SwizzleLTRB.sksl",
"/sksl/shared/SwizzleOpt.sksl", "/sksl/shared/SwizzleOpt.sksl",
"/sksl/shared/SwizzleScalar.sksl", "/sksl/shared/SwizzleScalar.sksl",
"/sksl/shared/SwizzleScalarBool.sksl",
"/sksl/shared/SwizzleScalarInt.sksl",
"/sksl/shared/TernaryAsLValueEntirelyFoldable.sksl", "/sksl/shared/TernaryAsLValueEntirelyFoldable.sksl",
"/sksl/shared/TernaryAsLValueFoldableTest.sksl", "/sksl/shared/TernaryAsLValueFoldableTest.sksl",
"/sksl/shared/TernaryExpression.sksl", "/sksl/shared/TernaryExpression.sksl",

View File

@ -1,12 +1,10 @@
uniform half unknownInput; // 1 uniform half unknownInput; // 1
half4 main(float2 coords) { half4 main(float2 coords) {
half x = unknownInput; half4 h4 = unknownInput.xxxx;
h4 = unknownInput.xx01;
h4 = unknownInput.0x10;
h4 = unknownInput.0x0x;
half4 v = x.xx01; return h4;
v = unknownInput.xx01;
v = unknownInput.0x10;
v = unknownInput.0x0x;
return v;
} }

View File

@ -0,0 +1,11 @@
uniform half unknownInput; // 1
half4 main(float2 coords) {
bool b = bool(unknownInput);
bool4 b4 = b.xxxx;
b4 = b.xx01;
b4 = b.0x10;
b4 = b.0x0x;
return half4(b4);
}

View File

@ -0,0 +1,11 @@
uniform half unknownInput; // 1
half4 main(float2 coords) {
int i = int(unknownInput);
int4 i4 = i.xxxx;
i4 = i.xx01;
i4 = i.0x10;
i4 = i.0x0x;
return half4(i4);
}

View File

@ -278,6 +278,8 @@ SKSL_TEST(SkSLSwizzleConstants, "shared/SwizzleConstants.sksl")
SKSL_TEST(SkSLSwizzleLTRB, "shared/SwizzleLTRB.sksl") SKSL_TEST(SkSLSwizzleLTRB, "shared/SwizzleLTRB.sksl")
SKSL_TEST(SkSLSwizzleOpt, "shared/SwizzleOpt.sksl") SKSL_TEST(SkSLSwizzleOpt, "shared/SwizzleOpt.sksl")
SKSL_TEST(SkSLSwizzleScalar, "shared/SwizzleScalar.sksl") SKSL_TEST(SkSLSwizzleScalar, "shared/SwizzleScalar.sksl")
//SKSL_TEST(SkSLSwizzleScalarBool, "shared/SwizzleScalarBool.sksl")
SKSL_TEST(SkSLSwizzleScalarInt, "shared/SwizzleScalarInt.sksl")
SKSL_TEST(SkSLTernaryAsLValueEntirelyFoldable, "shared/TernaryAsLValueEntirelyFoldable.sksl") SKSL_TEST(SkSLTernaryAsLValueEntirelyFoldable, "shared/TernaryAsLValueEntirelyFoldable.sksl")
SKSL_TEST(SkSLTernaryAsLValueFoldableTest, "shared/TernaryAsLValueFoldableTest.sksl") SKSL_TEST(SkSLTernaryAsLValueFoldableTest, "shared/TernaryAsLValueFoldableTest.sksl")
SKSL_TEST(SkSLTernaryExpression, "shared/TernaryExpression.sksl") SKSL_TEST(SkSLTernaryExpression, "shared/TernaryExpression.sksl")

View File

@ -9,8 +9,7 @@ OpName %_UniformBuffer "_UniformBuffer"
OpMemberName %_UniformBuffer 0 "unknownInput" OpMemberName %_UniformBuffer 0 "unknownInput"
OpName %_entrypoint_v "_entrypoint_v" OpName %_entrypoint_v "_entrypoint_v"
OpName %main "main" OpName %main "main"
OpName %x "x" OpName %h4 "h4"
OpName %v "v"
OpDecorate %sk_FragColor RelaxedPrecision OpDecorate %sk_FragColor RelaxedPrecision
OpDecorate %sk_FragColor Location 0 OpDecorate %sk_FragColor Location 0
OpDecorate %sk_FragColor Index 0 OpDecorate %sk_FragColor Index 0
@ -20,9 +19,9 @@ OpMemberDecorate %_UniformBuffer 0 RelaxedPrecision
OpDecorate %_UniformBuffer Block OpDecorate %_UniformBuffer Block
OpDecorate %10 Binding 0 OpDecorate %10 Binding 0
OpDecorate %10 DescriptorSet 0 OpDecorate %10 DescriptorSet 0
OpDecorate %x RelaxedPrecision OpDecorate %h4 RelaxedPrecision
OpDecorate %32 RelaxedPrecision OpDecorate %32 RelaxedPrecision
OpDecorate %v RelaxedPrecision OpDecorate %33 RelaxedPrecision
OpDecorate %35 RelaxedPrecision OpDecorate %35 RelaxedPrecision
OpDecorate %36 RelaxedPrecision OpDecorate %36 RelaxedPrecision
OpDecorate %37 RelaxedPrecision OpDecorate %37 RelaxedPrecision
@ -30,15 +29,10 @@ OpDecorate %38 RelaxedPrecision
OpDecorate %40 RelaxedPrecision OpDecorate %40 RelaxedPrecision
OpDecorate %42 RelaxedPrecision OpDecorate %42 RelaxedPrecision
OpDecorate %43 RelaxedPrecision OpDecorate %43 RelaxedPrecision
OpDecorate %44 RelaxedPrecision
OpDecorate %45 RelaxedPrecision OpDecorate %45 RelaxedPrecision
OpDecorate %46 RelaxedPrecision OpDecorate %47 RelaxedPrecision
OpDecorate %48 RelaxedPrecision OpDecorate %48 RelaxedPrecision
OpDecorate %49 RelaxedPrecision OpDecorate %49 RelaxedPrecision
OpDecorate %51 RelaxedPrecision
OpDecorate %53 RelaxedPrecision
OpDecorate %54 RelaxedPrecision
OpDecorate %55 RelaxedPrecision
%float = OpTypeFloat 32 %float = OpTypeFloat 32
%v4float = OpTypeVector %float 4 %v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float %_ptr_Output_v4float = OpTypePointer Output %v4float
@ -56,11 +50,10 @@ OpDecorate %55 RelaxedPrecision
%19 = OpConstantComposite %v2float %float_0 %float_0 %19 = OpConstantComposite %v2float %float_0 %float_0
%_ptr_Function_v2float = OpTypePointer Function %v2float %_ptr_Function_v2float = OpTypePointer Function %v2float
%23 = OpTypeFunction %v4float %_ptr_Function_v2float %23 = OpTypeFunction %v4float %_ptr_Function_v2float
%_ptr_Function_float = OpTypePointer Function %float %_ptr_Function_v4float = OpTypePointer Function %v4float
%_ptr_Uniform_float = OpTypePointer Uniform %float %_ptr_Uniform_float = OpTypePointer Uniform %float
%int = OpTypeInt 32 1 %int = OpTypeInt 32 1
%int_0 = OpConstant %int 0 %int_0 = OpConstant %int 0
%_ptr_Function_v4float = OpTypePointer Function %v4float
%float_1 = OpConstant %float 1 %float_1 = OpConstant %float 1
%_entrypoint_v = OpFunction %void None %15 %_entrypoint_v = OpFunction %void None %15
%16 = OpLabel %16 = OpLabel
@ -73,34 +66,28 @@ OpFunctionEnd
%main = OpFunction %v4float None %23 %main = OpFunction %v4float None %23
%24 = OpFunctionParameter %_ptr_Function_v2float %24 = OpFunctionParameter %_ptr_Function_v2float
%25 = OpLabel %25 = OpLabel
%x = OpVariable %_ptr_Function_float Function %h4 = OpVariable %_ptr_Function_v4float Function
%v = OpVariable %_ptr_Function_v4float Function
%28 = OpAccessChain %_ptr_Uniform_float %10 %int_0 %28 = OpAccessChain %_ptr_Uniform_float %10 %int_0
%32 = OpLoad %float %28 %32 = OpLoad %float %28
OpStore %x %32 %33 = OpCompositeConstruct %v4float %32 %32 %32 %32
%35 = OpLoad %float %x OpStore %h4 %33
%34 = OpAccessChain %_ptr_Uniform_float %10 %int_0
%35 = OpLoad %float %34
%36 = OpCompositeConstruct %v2float %35 %35 %36 = OpCompositeConstruct %v2float %35 %35
%37 = OpCompositeExtract %float %36 0 %37 = OpCompositeExtract %float %36 0
%38 = OpCompositeExtract %float %36 1 %38 = OpCompositeExtract %float %36 1
%40 = OpCompositeConstruct %v4float %37 %38 %float_0 %float_1 %40 = OpCompositeConstruct %v4float %37 %38 %float_0 %float_1
OpStore %v %40 OpStore %h4 %40
%41 = OpAccessChain %_ptr_Uniform_float %10 %int_0 %41 = OpAccessChain %_ptr_Uniform_float %10 %int_0
%42 = OpLoad %float %41 %42 = OpLoad %float %41
%43 = OpCompositeConstruct %v2float %42 %42 %43 = OpCompositeConstruct %v4float %float_0 %42 %float_1 %float_0
%44 = OpCompositeExtract %float %43 0 OpStore %h4 %43
%45 = OpCompositeExtract %float %43 1 %44 = OpAccessChain %_ptr_Uniform_float %10 %int_0
%46 = OpCompositeConstruct %v4float %44 %45 %float_0 %float_1 %45 = OpLoad %float %44
OpStore %v %46 %46 = OpAccessChain %_ptr_Uniform_float %10 %int_0
%47 = OpAccessChain %_ptr_Uniform_float %10 %int_0 %47 = OpLoad %float %46
%48 = OpLoad %float %47 %48 = OpCompositeConstruct %v4float %float_0 %45 %float_0 %47
%49 = OpCompositeConstruct %v4float %float_0 %48 %float_1 %float_0 OpStore %h4 %48
OpStore %v %49 %49 = OpLoad %v4float %h4
%50 = OpAccessChain %_ptr_Uniform_float %10 %int_0 OpReturnValue %49
%51 = OpLoad %float %50
%52 = OpAccessChain %_ptr_Uniform_float %10 %int_0
%53 = OpLoad %float %52
%54 = OpCompositeConstruct %v4float %float_0 %51 %float_0 %53
OpStore %v %54
%55 = OpLoad %v4float %v
OpReturnValue %55
OpFunctionEnd OpFunctionEnd

View File

@ -2,10 +2,9 @@
out vec4 sk_FragColor; out vec4 sk_FragColor;
uniform float unknownInput; uniform float unknownInput;
vec4 main() { vec4 main() {
float x = unknownInput; vec4 h4 = vec4(unknownInput);
vec4 v = vec4(vec2(x), 0.0, 1.0); h4 = vec4(vec2(unknownInput), 0.0, 1.0);
v = vec4(vec2(unknownInput), 0.0, 1.0); h4 = vec4(0.0, unknownInput, 1.0, 0.0);
v = vec4(0.0, unknownInput, 1.0, 0.0); h4 = vec4(0.0, unknownInput, 0.0, unknownInput);
v = vec4(0.0, unknownInput, 0.0, unknownInput); return h4;
return v;
} }

View File

@ -12,11 +12,10 @@ struct Outputs {
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Outputs _out; Outputs _out;
(void)_out; (void)_out;
float x = _uniforms.unknownInput; float4 h4 = float4(_uniforms.unknownInput);
float4 v = float4(float2(x), 0.0, 1.0); h4 = float4(float2(_uniforms.unknownInput), 0.0, 1.0);
v = float4(float2(_uniforms.unknownInput), 0.0, 1.0); h4 = float4(0.0, _uniforms.unknownInput, 1.0, 0.0);
v = float4(0.0, _uniforms.unknownInput, 1.0, 0.0); h4 = float4(0.0, _uniforms.unknownInput, 0.0, _uniforms.unknownInput);
v = float4(0.0, _uniforms.unknownInput, 0.0, _uniforms.unknownInput); _out.sk_FragColor = h4;
_out.sk_FragColor = v;
return _out; return _out;
} }

View File

@ -0,0 +1,4 @@
### Compilation failed:
error: 5: cannot swizzle value of type 'bool'
1 error

View File

@ -0,0 +1,4 @@
### Compilation failed:
error: 5: cannot swizzle value of type 'bool'
1 error

View File

@ -0,0 +1,4 @@
### Compilation failed:
error: 5: cannot swizzle value of type 'bool'
1 error

View File

@ -0,0 +1,98 @@
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %_entrypoint_v "_entrypoint" %sk_FragColor %sk_Clockwise
OpExecutionMode %_entrypoint_v OriginUpperLeft
OpName %sk_FragColor "sk_FragColor"
OpName %sk_Clockwise "sk_Clockwise"
OpName %_UniformBuffer "_UniformBuffer"
OpMemberName %_UniformBuffer 0 "unknownInput"
OpName %_entrypoint_v "_entrypoint_v"
OpName %main "main"
OpName %i "i"
OpName %i4 "i4"
OpDecorate %sk_FragColor RelaxedPrecision
OpDecorate %sk_FragColor Location 0
OpDecorate %sk_FragColor Index 0
OpDecorate %sk_Clockwise BuiltIn FrontFacing
OpMemberDecorate %_UniformBuffer 0 Offset 0
OpMemberDecorate %_UniformBuffer 0 RelaxedPrecision
OpDecorate %_UniformBuffer Block
OpDecorate %10 Binding 0
OpDecorate %10 DescriptorSet 0
OpDecorate %32 RelaxedPrecision
OpDecorate %53 RelaxedPrecision
OpDecorate %55 RelaxedPrecision
OpDecorate %57 RelaxedPrecision
OpDecorate %59 RelaxedPrecision
OpDecorate %60 RelaxedPrecision
%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
%_UniformBuffer = OpTypeStruct %float
%_ptr_Uniform__UniformBuffer = OpTypePointer Uniform %_UniformBuffer
%10 = OpVariable %_ptr_Uniform__UniformBuffer Uniform
%void = OpTypeVoid
%15 = OpTypeFunction %void
%v2float = OpTypeVector %float 2
%float_0 = OpConstant %float 0
%19 = OpConstantComposite %v2float %float_0 %float_0
%_ptr_Function_v2float = OpTypePointer Function %v2float
%23 = OpTypeFunction %v4float %_ptr_Function_v2float
%int = OpTypeInt 32 1
%_ptr_Function_int = OpTypePointer Function %int
%_ptr_Uniform_float = OpTypePointer Uniform %float
%int_0 = OpConstant %int 0
%v4int = OpTypeVector %int 4
%_ptr_Function_v4int = OpTypePointer Function %v4int
%v2int = OpTypeVector %int 2
%int_1 = OpConstant %int 1
%_entrypoint_v = OpFunction %void None %15
%16 = OpLabel
%20 = OpVariable %_ptr_Function_v2float Function
OpStore %20 %19
%22 = OpFunctionCall %v4float %main %20
OpStore %sk_FragColor %22
OpReturn
OpFunctionEnd
%main = OpFunction %v4float None %23
%24 = OpFunctionParameter %_ptr_Function_v2float
%25 = OpLabel
%i = OpVariable %_ptr_Function_int Function
%i4 = OpVariable %_ptr_Function_v4int Function
%29 = OpAccessChain %_ptr_Uniform_float %10 %int_0
%32 = OpLoad %float %29
%33 = OpConvertFToS %int %32
OpStore %i %33
%37 = OpLoad %int %i
%38 = OpCompositeConstruct %v4int %37 %37 %37 %37
OpStore %i4 %38
%39 = OpLoad %int %i
%40 = OpCompositeConstruct %v2int %39 %39
%42 = OpCompositeExtract %int %40 0
%43 = OpCompositeExtract %int %40 1
%45 = OpCompositeConstruct %v4int %42 %43 %int_0 %int_1
OpStore %i4 %45
%46 = OpLoad %int %i
%47 = OpCompositeConstruct %v4int %int_0 %46 %int_1 %int_0
OpStore %i4 %47
%48 = OpLoad %int %i
%49 = OpLoad %int %i
%50 = OpCompositeConstruct %v4int %int_0 %48 %int_0 %49
OpStore %i4 %50
%51 = OpLoad %v4int %i4
%52 = OpCompositeExtract %int %51 0
%53 = OpConvertSToF %float %52
%54 = OpCompositeExtract %int %51 1
%55 = OpConvertSToF %float %54
%56 = OpCompositeExtract %int %51 2
%57 = OpConvertSToF %float %56
%58 = OpCompositeExtract %int %51 3
%59 = OpConvertSToF %float %58
%60 = OpCompositeConstruct %v4float %53 %55 %57 %59
OpReturnValue %60
OpFunctionEnd

View File

@ -0,0 +1,11 @@
out vec4 sk_FragColor;
uniform float unknownInput;
vec4 main() {
int i = int(unknownInput);
ivec4 i4 = ivec4(i);
i4 = ivec4(ivec2(i), 0, 1);
i4 = ivec4(0, i, 1, 0);
i4 = ivec4(0, i, 0, i);
return vec4(i4);
}

View File

@ -0,0 +1,22 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct Uniforms {
float unknownInput;
};
struct Inputs {
};
struct Outputs {
float4 sk_FragColor [[color(0)]];
};
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Outputs _out;
(void)_out;
int i = int(_uniforms.unknownInput);
int4 i4 = int4(i);
i4 = int4(int2(i), 0, 1);
i4 = int4(0, i, 1, 0);
i4 = int4(0, i, 0, i);
_out.sk_FragColor = float4(i4);
return _out;
}