aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/SkSLGLSLTest.cpp
diff options
context:
space:
mode:
authorGravatar ethannicholas <ethannicholas@google.com>2016-11-09 13:26:45 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-11-09 13:26:45 -0800
commit08a9211a8492a84e1f4a6899759f8f37ed5aec3e (patch)
tree8fe430d685b62467d0a59aa374ef7b98d6a3db4a /tests/SkSLGLSLTest.cpp
parentf2b024db6777a904d986c68a21ba0bc41f956f6e (diff)
added constant folding & branch elimination to skslc
Diffstat (limited to 'tests/SkSLGLSLTest.cpp')
-rw-r--r--tests/SkSLGLSLTest.cpp105
1 files changed, 101 insertions, 4 deletions
diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp
index 610ff2b5ab..38fce87e87 100644
--- a/tests/SkSLGLSLTest.cpp
+++ b/tests/SkSLGLSLTest.cpp
@@ -43,7 +43,7 @@ DEF_TEST(SkSLHelloWorld, r) {
DEF_TEST(SkSLControl, r) {
test(r,
"void main() {"
- "if (1 + 2 + 3 > 5) { sk_FragColor = vec4(0.75); } else { discard; }"
+ "if (sqrt(2) > 5) { sk_FragColor = vec4(0.75); } else { discard; }"
"int i = 0;"
"while (i < 10) sk_FragColor *= 0.5;"
"do { sk_FragColor += 0.01; } while (sk_FragColor.x < 0.7);"
@@ -55,7 +55,7 @@ DEF_TEST(SkSLControl, r) {
default_caps(),
"#version 400\n"
"void main() {\n"
- " if ((1 + 2) + 3 > 5) {\n"
+ " if (sqrt(2.0) > 5.0) {\n"
" gl_FragColor = vec4(0.75);\n"
" } else {\n"
" discard;\n"
@@ -104,7 +104,7 @@ DEF_TEST(SkSLOperators, r) {
"x = x + y * z * x * (y - z);"
"y = x / y / z;"
"z = (z / 2 % 3 << 4) >> 2 << 1;"
- "bool b = (x > 4) == x < 2 || 2 >= 5 && y <= z && 12 != 11;"
+ "bool b = (x > 4) == x < 2 || 2 >= sqrt(2) && y <= z;"
"x += 12;"
"x -= 12;"
"x *= y /= z = 10;"
@@ -126,7 +126,7 @@ DEF_TEST(SkSLOperators, r) {
" 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.0 == x < 2.0 || (2 >= 5 && y <= float(z)) && 12 != 11;\n"
+ " bool b = x > 4.0 == x < 2.0 || 2.0 >= sqrt(2.0) && y <= float(z);\n"
" x += 12.0;\n"
" x -= 12.0;\n"
" x *= (y /= float(z = 10));\n"
@@ -430,3 +430,100 @@ DEF_TEST(SkSLDerivatives, r) {
" float x = dFdx(1.0);\n"
"}\n");
}
+
+DEF_TEST(SkSLConstantFolding, r) {
+ test(r,
+ "void main() {"
+ "float f_add = 32 + 2;"
+ "float f_sub = 32 - 2;"
+ "float f_mul = 32 * 2;"
+ "float f_div = 32 / 2;"
+ "float mixed = (12 > 2.0) ? (10 * 2 / 5 + 18 - 3) : 0;"
+ "int i_add = 32 + 2;"
+ "int i_sub = 32 - 2;"
+ "int i_mul = 32 * 2;"
+ "int i_div = 32 / 2;"
+ "int i_or = 12 | 6;"
+ "int i_and = 254 & 7;"
+ "int i_xor = 2 ^ 7;"
+ "int i_shl = 1 << 4;"
+ "int i_shr = 128 >> 2;"
+ "bool gt_it = 6 > 5;"
+ "bool gt_if = 6 > 6;"
+ "bool gt_ft = 6.0 > 5.0;"
+ "bool gt_ff = 6.0 > 6.0;"
+ "bool gte_it = 6 >= 6;"
+ "bool gte_if = 6 >= 7;"
+ "bool gte_ft = 6.0 >= 6.0;"
+ "bool gte_ff = 6.0 >= 7.0;"
+ "bool lte_it = 6 <= 6;"
+ "bool lte_if = 6 <= 5;"
+ "bool lte_ft = 6.0 <= 6.0;"
+ "bool lte_ff = 6.0 <= 5.0;"
+ "bool or_t = 1 == 1 || 2 == 8;"
+ "bool or_f = 1 > 1 || 2 == 8;"
+ "bool and_t = 1 == 1 && 2 <= 8;"
+ "bool and_f = 1 == 2 && 2 == 8;"
+ "bool xor_t = 1 == 1 ^^ 1 != 1;"
+ "bool xor_f = 1 == 1 ^^ 1 == 1;"
+ "int ternary = 10 > 5 ? 10 : 5;"
+ "}",
+ default_caps(),
+ "#version 400\n"
+ "void main() {\n"
+ " float f_add = 34.0;\n"
+ " float f_sub = 30.0;\n"
+ " float f_mul = 64.0;\n"
+ " float f_div = 16.0;\n"
+ " float mixed = 19.0;\n"
+ " int i_add = 34;\n"
+ " int i_sub = 30;\n"
+ " int i_mul = 64;\n"
+ " int i_div = 16;\n"
+ " int i_or = 14;\n"
+ " int i_and = 6;\n"
+ " int i_xor = 5;\n"
+ " int i_shl = 16;\n"
+ " int i_shr = 32;\n"
+ " bool gt_it = true;\n"
+ " bool gt_if = false;\n"
+ " bool gt_ft = true;\n"
+ " bool gt_ff = false;\n"
+ " bool gte_it = true;\n"
+ " bool gte_if = false;\n"
+ " bool gte_ft = true;\n"
+ " bool gte_ff = false;\n"
+ " bool lte_it = true;\n"
+ " bool lte_if = false;\n"
+ " bool lte_ft = true;\n"
+ " bool lte_ff = false;\n"
+ " bool or_t = true;\n"
+ " bool or_f = false;\n"
+ " bool and_t = true;\n"
+ " bool and_f = false;\n"
+ " bool xor_t = true;\n"
+ " bool xor_f = false;\n"
+ " int ternary = 10;\n"
+ "}\n");
+}
+
+DEF_TEST(SkSLStaticIf, r) {
+ test(r,
+ "void main() {"
+ "int x;"
+ "if (true) x = 1;"
+ "if (2 > 1) x = 2; else x = 3;"
+ "if (1 > 2) x = 4; else x = 5;"
+ "if (false) x = 6;"
+ "}",
+ default_caps(),
+ "#version 400\n"
+ "void main() {\n"
+ " int x;\n"
+ " x = 1;\n"
+ " x = 2;\n"
+ " x = 5;\n"
+ " {\n"
+ " }\n"
+ "}\n");
+}