From ccb1dd8f267f9d7fe7c9d0ce222ebc81b41853b3 Mon Sep 17 00:00:00 2001 From: ethannicholas Date: Tue, 11 Oct 2016 08:47:04 -0700 Subject: Turned on SkSL->GLSL compiler GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2288033003 Committed: https://skia.googlesource.com/skia/+/9b0fe3d125f237d9884732a48414fa85fc71b4e3 Committed: https://skia.googlesource.com/skia/+/b12b3c6908c62c908b3680be01e3b5bfd30de310 Committed: https://skia.googlesource.com/skia/+/f008b0a59f45c0d4bea3e66faf3b01805009ec89 Committed: https://skia.googlesource.com/skia/+/08b2ccf398e2b81bc05d2c105837e5419899469b Committed: https://skia.googlesource.com/skia/+/dcfe6dba4a335e50e86ff68e3252065d4197432c Review-Url: https://codereview.chromium.org/2288033003 --- tests/SkSLErrorTest.cpp | 4 +- tests/SkSLGLSLTest.cpp | 226 +++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 185 insertions(+), 45 deletions(-) (limited to 'tests') diff --git a/tests/SkSLErrorTest.cpp b/tests/SkSLErrorTest.cpp index 75fa20d7e3..400ab6dc57 100644 --- a/tests/SkSLErrorTest.cpp +++ b/tests/SkSLErrorTest.cpp @@ -263,8 +263,8 @@ DEF_TEST(SkSLBadIndex, r) { "void main() { int x = 2[0]; }", "error: 1: expected array, but found 'int'\n1 error\n"); test_failure(r, - "void main() { vec2 x = vec2(0); int y = x[0]; }", - "error: 1: expected array, but found 'vec2'\n1 error\n"); + "void main() { vec2 x = vec2(0); int y = x[0][0]; }", + "error: 1: expected array, but found 'float'\n1 error\n"); } DEF_TEST(SkSLTernaryMismatch, r) { diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp index 3906f67115..dedddad1f8 100644 --- a/tests/SkSLGLSLTest.cpp +++ b/tests/SkSLGLSLTest.cpp @@ -26,46 +26,52 @@ static void test(skiatest::Reporter* r, const char* src, SkSL::GLCaps caps, cons } } +static SkSL::GLCaps default_caps() { + return { + 400, + SkSL::GLCaps::kGL_Standard, + false, // isCoreProfile + false, // usesPrecisionModifiers; + false, // mustDeclareFragmentShaderOutput + true // canUseMinAndAbsTogether + }; +} + DEF_TEST(SkSLHelloWorld, r) { - SkSL::GLCaps caps = { 400, SkSL::GLCaps::kGL_Standard }; test(r, - "out vec4 fragColor; void main() { fragColor = vec4(0.75); }", - caps, + "void main() { sk_FragColor = vec4(0.75); }", + default_caps(), "#version 400\n" - "out vec4 fragColor;\n" "void main() {\n" - " fragColor = vec4(0.75);\n" + " gl_FragColor = vec4(0.75);\n" "}\n"); } DEF_TEST(SkSLControl, r) { - SkSL::GLCaps caps = { 400, SkSL::GLCaps::kGL_Standard }; test(r, - "out vec4 fragColor;" "void main() {" - "if (1 + 2 + 3 > 5) { fragColor = vec4(0.75); } else { discard; }" + "if (1 + 2 + 3 > 5) { sk_FragColor = vec4(0.75); } else { discard; }" "int i = 0;" - "while (i < 10) fragColor *= 0.5;" - "do { fragColor += 0.01; } while (fragColor.x < 0.7);" + "while (i < 10) sk_FragColor *= 0.5;" + "do { sk_FragColor += 0.01; } while (sk_FragColor.x < 0.7);" "for (int i = 0; i < 10; i++) {" "if (i % 0 == 1) break; else continue;" "}" "return;" "}", - caps, + default_caps(), "#version 400\n" - "out vec4 fragColor;\n" "void main() {\n" " if ((1 + 2) + 3 > 5) {\n" - " fragColor = vec4(0.75);\n" + " gl_FragColor = vec4(0.75);\n" " } else {\n" " discard;\n" " }\n" " int i = 0;\n" - " while (i < 10) fragColor *= 0.5;\n" + " while (i < 10) gl_FragColor *= 0.5;\n" " do {\n" - " fragColor += 0.01;\n" - " } while (fragColor.x < 0.7);\n" + " gl_FragColor += 0.01;\n" + " } while (gl_FragColor.x < 0.7);\n" " for (int i = 0;i < 10; i++) {\n" " if (i % 0 == 1) break; else continue;\n" " }\n" @@ -74,34 +80,30 @@ DEF_TEST(SkSLControl, r) { } DEF_TEST(SkSLFunctions, r) { - SkSL::GLCaps caps = { 400, SkSL::GLCaps::kGL_Standard }; test(r, - "out vec4 fragColor;" "float foo(float v[2]) { return v[0] * v[1]; }" "void bar(inout float x) { float y[2], z; y[0] = x; y[1] = x * 2; z = foo(y); x = z; }" - "void main() { float x = 10; bar(x); fragColor = vec4(x); }", - caps, + "void main() { float x = 10; bar(x); sk_FragColor = vec4(x); }", + default_caps(), "#version 400\n" - "out vec4 fragColor;\n" - "float foo(in float[2] v) {\n" + "float foo(in float v[2]) {\n" " return v[0] * v[1];\n" "}\n" "void bar(inout float x) {\n" " float y[2], z;\n" " y[0] = x;\n" - " y[1] = x * 2;\n" + " y[1] = x * 2.0;\n" " z = foo(y);\n" " x = z;\n" "}\n" "void main() {\n" - " float x = 10;\n" + " float x = 10.0;\n" " bar(x);\n" - " fragColor = vec4(x);\n" + " gl_FragColor = vec4(x);\n" "}\n"); } DEF_TEST(SkSLOperators, r) { - SkSL::GLCaps caps = { 400, SkSL::GLCaps::kGL_Standard }; test(r, "void main() {" "float x = 1, y = 2;" @@ -123,17 +125,17 @@ DEF_TEST(SkSLOperators, r) { "z <<= 4;" "z %= 5;" "}", - caps, + default_caps(), "#version 400\n" "void main() {\n" - " float x = 1, y = 2;\n" + " float x = 1.0, y = 2.0;\n" " int z = 3;\n" " x = x + ((y * float(z)) * x) * (y - float(z));\n" " y = (x / y) / float(z);\n" " z = (((z / 2) % 3 << 4) >> 2) << 1;\n" - " bool b = x > 4 == x < 2 || (2 >= 5 && y <= float(z)) && 12 != 11;\n" - " x += 12;\n" - " x -= 12;\n" + " bool b = x > 4.0 == x < 2.0 || (2 >= 5 && y <= float(z)) && 12 != 11;\n" + " x += 12.0;\n" + " x -= 12.0;\n" " x *= (y /= float(z = 10));\n" " b ||= false;\n" " b &&= true;\n" @@ -148,7 +150,6 @@ DEF_TEST(SkSLOperators, r) { } DEF_TEST(SkSLMatrices, r) { - SkSL::GLCaps caps = { 400, SkSL::GLCaps::kGL_Standard }; test(r, "void main() {" "mat2x4 x = mat2x4(1);" @@ -157,19 +158,18 @@ DEF_TEST(SkSLMatrices, r) { "vec3 v1 = mat3(1) * vec3(1);" "vec3 v2 = vec3(1) * mat3(1);" "}", - caps, + default_caps(), "#version 400\n" "void main() {\n" - " mat2x4 x = mat2x4(1);\n" - " mat3x2 y = mat3x2(1, 0, 0, 1, vec2(2, 2));\n" + " mat2x4 x = mat2x4(1.0);\n" + " mat3x2 y = mat3x2(1.0, 0.0, 0.0, 1.0, vec2(2.0, 2.0));\n" " mat3x4 z = x * y;\n" - " vec3 v1 = mat3(1) * vec3(1);\n" - " vec3 v2 = vec3(1) * mat3(1);\n" + " vec3 v1 = mat3(1.0) * vec3(1.0);\n" + " vec3 v2 = vec3(1.0) * mat3(1.0);\n" "}\n"); } DEF_TEST(SkSLInterfaceBlock, r) { - SkSL::GLCaps caps = { 400, SkSL::GLCaps::kGL_Standard }; test(r, "uniform testBlock {" "float x;" @@ -179,12 +179,12 @@ DEF_TEST(SkSLInterfaceBlock, r) { "};" "void main() {" "}", - caps, + default_caps(), "#version 400\n" "uniform testBlock {\n" " float x;\n" " float[2] y;\n" - " layout (binding = 12)mat3x2 z;\n" + " layout (binding = 12) mat3x2 z;\n" " bool w;\n" "};\n" "void main() {\n" @@ -192,7 +192,6 @@ DEF_TEST(SkSLInterfaceBlock, r) { } DEF_TEST(SkSLStructs, r) { - SkSL::GLCaps caps = { 400, SkSL::GLCaps::kGL_Standard }; test(r, "struct A {" "int x;" @@ -207,7 +206,7 @@ DEF_TEST(SkSLStructs, r) { "B b1, b2, b3;" "void main() {" "}", - caps, + default_caps(), "#version 400\n" "struct A {\n" " int x;\n" @@ -218,10 +217,151 @@ DEF_TEST(SkSLStructs, r) { "struct B {\n" " float x;\n" " float[2] y;\n" - " layout (binding = 1)A z;\n" + " layout (binding = 1) A z;\n" "}\n" " b1, b2, b3;\n" "void main() {\n" "}\n"); +} + +DEF_TEST(SkSLVersion, r) { + SkSL::GLCaps caps = default_caps(); + caps.fVersion = 450; + caps.fIsCoreProfile = true; + test(r, + "in float test; void main() { sk_FragColor = vec4(0.75); }", + caps, + "#version 450 core\n" + "in float test;\n" + "void main() {\n" + " gl_FragColor = vec4(0.75);\n" + "}\n"); + caps.fVersion = 110; + caps.fIsCoreProfile = false; + test(r, + "in float test; void main() { sk_FragColor = vec4(0.75); }", + caps, + "#version 110\n" + "varying float test;\n" + "void main() {\n" + " gl_FragColor = vec4(0.75);\n" + "}\n"); +} + +DEF_TEST(SkSLDeclareOutput, r) { + SkSL::GLCaps caps = default_caps(); + caps.fMustDeclareFragmentShaderOutput = true; + test(r, + "void main() { sk_FragColor = vec4(0.75); }", + caps, + "#version 400\n" + "out vec4 sk_FragColor;\n" + "void main() {\n" + " sk_FragColor = vec4(0.75);\n" + "}\n"); +} +DEF_TEST(SkSLUsesPrecisionModifiers, r) { + SkSL::GLCaps caps = default_caps(); + test(r, + "void main() { float x = 0.75; highp float y = 1; }", + caps, + "#version 400\n" + "void main() {\n" + " float x = 0.75;\n" + " float y = 1.0;\n" + "}\n"); + caps.fStandard = SkSL::GLCaps::kGLES_Standard; + caps.fUsesPrecisionModifiers = true; + test(r, + "void main() { float x = 0.75; highp float y = 1; }", + caps, + "#version 400 es\n" + "precision highp float;\n" + "void main() {\n" + " float x = 0.75;\n" + " highp float y = 1.0;\n" + "}\n"); +} + +DEF_TEST(SkSLMinAbs, r) { + test(r, + "void main() {" + "float x = -5;" + "x = min(abs(x), 6);" + "}", + default_caps(), + "#version 400\n" + "void main() {\n" + " float x = -5.0;\n" + " x = min(abs(x), 6.0);\n" + "}\n"); + + SkSL::GLCaps caps = default_caps(); + caps.fCanUseMinAndAbsTogether = false; + test(r, + "void main() {" + "float x = -5.0;" + "x = min(abs(x), 6.0);" + "}", + caps, + "#version 400\n" + "void main() {\n" + " float minAbsHackVar0;\n" + " float minAbsHackVar1;\n" + " float x = -5.0;\n" + " x = ((minAbsHackVar0 = abs(x)) < (minAbsHackVar1 = 6.0) ? minAbsHackVar0 : " + "minAbsHackVar1);\n" + "}\n"); +} + +DEF_TEST(SkSLModifiersDeclaration, r) { + test(r, + "layout(blend_support_all_equations) out;" + "void main() { }", + default_caps(), + "#version 400\n" + "layout (blend_support_all_equations) out ;\n" + "void main() {\n" + "}\n"); +} + +DEF_TEST(SkSLHex, r) { + test(r, + "void main() {" + "int i1 = 0x0;" + "int i2 = 0x1234abcd;" + "int i3 = 0x7fffffff;" + "int i4 = 0xffffffff;" + "int i5 = -0xbeef;" + "uint u1 = 0x0;" + "uint u2 = 0x1234abcd;" + "uint u3 = 0x7fffffff;" + "uint u4 = 0xffffffff;" + "}", + default_caps(), + "#version 400\n" + "void main() {\n" + " int i1 = 0;\n" + " int i2 = 305441741;\n" + " int i3 = 2147483647;\n" + " int i4 = -1;\n" + " int i5 = -48879;\n" + " uint u1 = 0u;\n" + " uint u2 = 305441741u;\n" + " uint u3 = 2147483647u;\n" + " uint u4 = 4294967295u;\n" + "}\n"); +} + +DEF_TEST(SkSLArrayConstructors, r) { + test(r, + "float test1[] = float[](1, 2, 3, 4);" + "vec2 test2[] = vec2[](vec2(1, 2), vec2(3, 4));" + "mat4 test3[] = mat4[]();", + default_caps(), + "#version 400\n" + "float test1[] = float[](1.0, 2.0, 3.0, 4.0);\n" + "vec2 test2[] = vec2[](vec2(1.0, 2.0), vec2(3.0, 4.0));\n" + "mat4 test3[] = mat4[]();\n"); } -- cgit v1.2.3