diff --git a/gn/sksl_tests.gni b/gn/sksl_tests.gni index 8a21c2877b..c42e86ca6a 100644 --- a/gn/sksl_tests.gni +++ b/gn/sksl_tests.gni @@ -55,6 +55,9 @@ sksl_glsl_tests_sources = [ "$_tests/sksl/glsl/Switch.sksl", "$_tests/sksl/glsl/SwitchContainingDeadCode.sksl", "$_tests/sksl/glsl/SwitchWithFallthrough.sksl", + "$_tests/sksl/glsl/SwizzleConstants.sksl", + "$_tests/sksl/glsl/SwizzleOpt.sksl", + "$_tests/sksl/glsl/SwizzleScalar.sksl", "$_tests/sksl/glsl/UnusedVariables.sksl", "$_tests/sksl/glsl/VectorConstructors.sksl", "$_tests/sksl/glsl/VectorFolding.sksl", diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp index 1ef91d51f8..d66322bedd 100644 --- a/tests/SkSLGLSLTest.cpp +++ b/tests/SkSLGLSLTest.cpp @@ -1172,149 +1172,6 @@ DEF_TEST(SkSLSwizzleLTRB, r) { ); } -DEF_TEST(SkSLSwizzleConstants, r) { - test(r, - "void main() {" - " half4 v = half4(half(sqrt(1)));" - " sk_FragColor = half4(v.x, 1, 1, 1);" - " sk_FragColor = half4(v.xy, 1, 1);" - " sk_FragColor = half4(v.x1, 1, 1);" - " sk_FragColor = half4(v.0y, 1, 1);" - " sk_FragColor = half4(v.xyz, 1);" - " sk_FragColor = half4(v.xy1, 1);" - " sk_FragColor = half4(v.x0z, 1);" - " sk_FragColor = half4(v.x10, 1);" - " sk_FragColor = half4(v.1yz, 1);" - " sk_FragColor = half4(v.0y1, 1);" - " sk_FragColor = half4(v.11z, 1);" - " sk_FragColor = v.xyzw;" - " sk_FragColor = v.xyz1;" - " sk_FragColor = v.xy0w;" - " sk_FragColor = v.xy10;" - " sk_FragColor = v.x1zw;" - " sk_FragColor = v.x0z1;" - " sk_FragColor = v.x11w;" - " sk_FragColor = v.x101;" - " sk_FragColor = v.1yzw;" - " sk_FragColor = v.0yz1;" - " sk_FragColor = v.0y1w;" - " sk_FragColor = v.1y11;" - " sk_FragColor = v.00zw;" - " sk_FragColor = v.00z1;" - " sk_FragColor = v.011w;" - "}", - *SkSL::ShaderCapsFactory::RemovePowWithConstantExponent(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " vec4 v = vec4(sqrt(1.0));\n" - " sk_FragColor = vec4(v.x, 1.0, 1.0, 1.0);\n" - " sk_FragColor = vec4(v.xy, 1.0, 1.0);\n" - " sk_FragColor = vec4(vec2(v.x, 1.0), 1.0, 1.0);\n" - " sk_FragColor = vec4(vec2(v.y, 0.0).yx, 1.0, 1.0);\n" - " sk_FragColor = vec4(v.xyz, 1.0);\n" - " sk_FragColor = vec4(vec3(v.xy, 1.0), 1.0);\n" - " sk_FragColor = vec4(vec3(v.xz, 0.0).xzy, 1.0);\n" - " sk_FragColor = vec4(vec3(v.x, 1.0, 0.0), 1.0);\n" - " sk_FragColor = vec4(vec3(v.yz, 1.0).zxy, 1.0);\n" - " sk_FragColor = vec4(vec3(v.y, 0.0, 1.0).yxz, 1.0);\n" - " sk_FragColor = vec4(vec3(v.z, 1.0, 1.0).yzx, 1.0);\n" - " sk_FragColor = v;\n" - " sk_FragColor = vec4(v.xyz, 1.0);\n" - " sk_FragColor = vec4(v.xyw, 0.0).xywz;\n" - " sk_FragColor = vec4(v.xy, 1.0, 0.0);\n" - " sk_FragColor = vec4(v.xzw, 1.0).xwyz;\n" - " sk_FragColor = vec4(v.xz, 0.0, 1.0).xzyw;\n" - " sk_FragColor = vec4(v.xw, 1.0, 1.0).xzwy;\n" - " sk_FragColor = vec4(v.x, 1.0, 0.0, 1.0);\n" - " sk_FragColor = vec4(v.yzw, 1.0).wxyz;\n" - " sk_FragColor = vec4(v.yz, 0.0, 1.0).zxyw;\n" - " sk_FragColor = vec4(v.yw, 0.0, 1.0).zxwy;\n" - " sk_FragColor = vec4(v.y, 1.0, 1.0, 1.0).yxzw;\n" - " sk_FragColor = vec4(v.zw, 0.0, 0.0).zwxy;\n" - " sk_FragColor = vec4(v.z, 0.0, 0.0, 1.0).yzxw;\n" - " sk_FragColor = vec4(v.w, 0.0, 1.0, 1.0).yzwx;\n" - "}\n", - SkSL::Program::kFragment_Kind - ); -} - -DEF_TEST(SkSLSwizzleOpt, r) { - test(r, - "void main() {" - " half v = half(sqrt(1));" - " sk_FragColor = half4(v).rgba;" - " sk_FragColor = half4(v).rgb0.abgr;" - " sk_FragColor = half4(v).rgba.00ra;" - " sk_FragColor = half4(v).rgba.rrra.00ra.11ab;" - " sk_FragColor = half4(v).abga.gb11;" - " sk_FragColor = half4(v).abgr.abgr;" - " sk_FragColor = half4(half4(v).rrrr.bb, 1, 1);" - " sk_FragColor = half4(half4(v).ba.grgr);" - "}", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " float v = sqrt(1.0);\n" - " sk_FragColor = vec4(v);\n" - " sk_FragColor = vec4(vec4(v).xyz, 0.0).wzyx;\n" - " sk_FragColor = vec4(vec4(v).xw, 0.0, 0.0).zwxy;\n" - " sk_FragColor = vec4(vec4(vec4(v).xw, 0.0, 0.0).yx, 1.0, 1.0).zwxy;\n" - " sk_FragColor = vec4(vec4(v).zy, 1.0, 1.0);\n" - " sk_FragColor = vec4(v);\n" - " sk_FragColor = vec4(vec4(v).xx, 1.0, 1.0);\n" - " sk_FragColor = vec4(v).wzwz;\n" - "}\n", - SkSL::Program::kFragment_Kind - ); -} - -DEF_TEST(SkSLSwizzleScalar, r) { - test(r, - "void main() {" - " half x = half(sqrt(4));" - " sk_FragColor = x.xx01;" - "}", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " float x = sqrt(4.0);\n" - " sk_FragColor = vec4(vec2(x), 0.0, 1.0);\n" - "}\n"); - test(r, - "void main() {" - " sk_FragColor = half(sqrt(4)).xx01;" - "}", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " sk_FragColor = vec4(vec2(sqrt(4.0)), 0.0, 1.0);\n" - "}\n"); - test(r, - "void main() {" - " sk_FragColor = half(sqrt(4)).0x01;" - "}", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " sk_FragColor = vec4(sqrt(4.0), 0.0, 0.0, 1.0).yxzw;\n" - "}\n"); - test(r, - "void main() {" - " sk_FragColor = half(sqrt(4)).0x0x;" - "}", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " sk_FragColor = vec4(vec2(sqrt(4.0)), 0.0, 0.0).zxwy;\n" - "}\n"); -} - DEF_TEST(SkSLStackingVectorCasts, r) { test(r, "void main() {" diff --git a/tests/sksl/glsl/SwizzleConstants.sksl b/tests/sksl/glsl/SwizzleConstants.sksl new file mode 100644 index 0000000000..b3435cb693 --- /dev/null +++ b/tests/sksl/glsl/SwizzleConstants.sksl @@ -0,0 +1,29 @@ +void main() { + half4 v = half4(half(sqrt(1))); + sk_FragColor = half4(v.x, 1, 1, 1); + sk_FragColor = half4(v.xy, 1, 1); + sk_FragColor = half4(v.x1, 1, 1); + sk_FragColor = half4(v.0y, 1, 1); + sk_FragColor = half4(v.xyz, 1); + sk_FragColor = half4(v.xy1, 1); + sk_FragColor = half4(v.x0z, 1); + sk_FragColor = half4(v.x10, 1); + sk_FragColor = half4(v.1yz, 1); + sk_FragColor = half4(v.0y1, 1); + sk_FragColor = half4(v.11z, 1); + sk_FragColor = v.xyzw; + sk_FragColor = v.xyz1; + sk_FragColor = v.xy0w; + sk_FragColor = v.xy10; + sk_FragColor = v.x1zw; + sk_FragColor = v.x0z1; + sk_FragColor = v.x11w; + sk_FragColor = v.x101; + sk_FragColor = v.1yzw; + sk_FragColor = v.0yz1; + sk_FragColor = v.0y1w; + sk_FragColor = v.1y11; + sk_FragColor = v.00zw; + sk_FragColor = v.00z1; + sk_FragColor = v.011w; +} diff --git a/tests/sksl/glsl/SwizzleOpt.sksl b/tests/sksl/glsl/SwizzleOpt.sksl new file mode 100644 index 0000000000..a7f5241609 --- /dev/null +++ b/tests/sksl/glsl/SwizzleOpt.sksl @@ -0,0 +1,11 @@ +void main() { + half v = half(sqrt(1)); + sk_FragColor = half4(v).rgba; + sk_FragColor = half4(v).rgb0.abgr; + sk_FragColor = half4(v).rgba.00ra; + sk_FragColor = half4(v).rgba.rrra.00ra.11ab; + sk_FragColor = half4(v).abga.gb11; + sk_FragColor = half4(v).abgr.abgr; + sk_FragColor = half4(half4(v).rrrr.bb, 1, 1); + sk_FragColor = half4(half4(v).ba.grgr); +} diff --git a/tests/sksl/glsl/SwizzleScalar.sksl b/tests/sksl/glsl/SwizzleScalar.sksl new file mode 100644 index 0000000000..b595e456e6 --- /dev/null +++ b/tests/sksl/glsl/SwizzleScalar.sksl @@ -0,0 +1,7 @@ +void main() { + half x = half(sqrt(4)); + sk_FragColor = x.xx01; + sk_FragColor = half(sqrt(4)).xx01; + sk_FragColor = half(sqrt(4)).0x01; + sk_FragColor = half(sqrt(4)).0x0x; +} diff --git a/tests/sksl/glsl/golden/SwizzleConstants.glsl b/tests/sksl/glsl/golden/SwizzleConstants.glsl new file mode 100644 index 0000000000..922540270f --- /dev/null +++ b/tests/sksl/glsl/golden/SwizzleConstants.glsl @@ -0,0 +1,31 @@ + +out vec4 sk_FragColor; +void main() { + vec4 v = vec4(sqrt(1.0)); + sk_FragColor = vec4(v.x, 1.0, 1.0, 1.0); + sk_FragColor = vec4(v.xy, 1.0, 1.0); + sk_FragColor = vec4(vec2(v.x, 1.0), 1.0, 1.0); + sk_FragColor = vec4(vec2(v.y, 0.0).yx, 1.0, 1.0); + sk_FragColor = vec4(v.xyz, 1.0); + sk_FragColor = vec4(vec3(v.xy, 1.0), 1.0); + sk_FragColor = vec4(vec3(v.xz, 0.0).xzy, 1.0); + sk_FragColor = vec4(vec3(v.x, 1.0, 0.0), 1.0); + sk_FragColor = vec4(vec3(v.yz, 1.0).zxy, 1.0); + sk_FragColor = vec4(vec3(v.y, 0.0, 1.0).yxz, 1.0); + sk_FragColor = vec4(vec3(v.z, 1.0, 1.0).yzx, 1.0); + sk_FragColor = v; + sk_FragColor = vec4(v.xyz, 1.0); + sk_FragColor = vec4(v.xyw, 0.0).xywz; + sk_FragColor = vec4(v.xy, 1.0, 0.0); + sk_FragColor = vec4(v.xzw, 1.0).xwyz; + sk_FragColor = vec4(v.xz, 0.0, 1.0).xzyw; + sk_FragColor = vec4(v.xw, 1.0, 1.0).xzwy; + sk_FragColor = vec4(v.x, 1.0, 0.0, 1.0); + sk_FragColor = vec4(v.yzw, 1.0).wxyz; + sk_FragColor = vec4(v.yz, 0.0, 1.0).zxyw; + sk_FragColor = vec4(v.yw, 0.0, 1.0).zxwy; + sk_FragColor = vec4(v.y, 1.0, 1.0, 1.0).yxzw; + sk_FragColor = vec4(v.zw, 0.0, 0.0).zwxy; + sk_FragColor = vec4(v.z, 0.0, 0.0, 1.0).yzxw; + sk_FragColor = vec4(v.w, 0.0, 1.0, 1.0).yzwx; +} diff --git a/tests/sksl/glsl/golden/SwizzleOpt.glsl b/tests/sksl/glsl/golden/SwizzleOpt.glsl new file mode 100644 index 0000000000..d89c1fb285 --- /dev/null +++ b/tests/sksl/glsl/golden/SwizzleOpt.glsl @@ -0,0 +1,13 @@ + +out vec4 sk_FragColor; +void main() { + float v = sqrt(1.0); + sk_FragColor = vec4(v); + sk_FragColor = vec4(vec4(v).xyz, 0.0).wzyx; + sk_FragColor = vec4(vec4(v).xw, 0.0, 0.0).zwxy; + sk_FragColor = vec4(vec4(vec4(v).xw, 0.0, 0.0).yx, 1.0, 1.0).zwxy; + sk_FragColor = vec4(vec4(v).zy, 1.0, 1.0); + sk_FragColor = vec4(v); + sk_FragColor = vec4(vec4(v).xx, 1.0, 1.0); + sk_FragColor = vec4(v).wzwz; +} diff --git a/tests/sksl/glsl/golden/SwizzleScalar.glsl b/tests/sksl/glsl/golden/SwizzleScalar.glsl new file mode 100644 index 0000000000..73225f839c --- /dev/null +++ b/tests/sksl/glsl/golden/SwizzleScalar.glsl @@ -0,0 +1,9 @@ + +out vec4 sk_FragColor; +void main() { + float x = sqrt(4.0); + sk_FragColor = vec4(vec2(x), 0.0, 1.0); + sk_FragColor = vec4(vec2(sqrt(4.0)), 0.0, 1.0); + sk_FragColor = vec4(sqrt(4.0), 0.0, 0.0, 1.0).yxzw; + sk_FragColor = vec4(vec2(sqrt(4.0)), 0.0, 0.0).zxwy; +}