Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: tests/SkSLGLSLTest.cpp

Issue 2494523002: Revert of added constant folding & branch elimination to skslc (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/SkSLErrorTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkSLCompiler.h" 8 #include "SkSLCompiler.h"
9 9
10 #include "Test.h" 10 #include "Test.h"
(...skipping 25 matching lines...) Expand all
36 default_caps(), 36 default_caps(),
37 "#version 400\n" 37 "#version 400\n"
38 "void main() {\n" 38 "void main() {\n"
39 " gl_FragColor = vec4(0.75);\n" 39 " gl_FragColor = vec4(0.75);\n"
40 "}\n"); 40 "}\n");
41 } 41 }
42 42
43 DEF_TEST(SkSLControl, r) { 43 DEF_TEST(SkSLControl, r) {
44 test(r, 44 test(r,
45 "void main() {" 45 "void main() {"
46 "if (sqrt(2) > 5) { sk_FragColor = vec4(0.75); } else { discard; }" 46 "if (1 + 2 + 3 > 5) { sk_FragColor = vec4(0.75); } else { discard; }"
47 "int i = 0;" 47 "int i = 0;"
48 "while (i < 10) sk_FragColor *= 0.5;" 48 "while (i < 10) sk_FragColor *= 0.5;"
49 "do { sk_FragColor += 0.01; } while (sk_FragColor.x < 0.7);" 49 "do { sk_FragColor += 0.01; } while (sk_FragColor.x < 0.7);"
50 "for (int i = 0; i < 10; i++) {" 50 "for (int i = 0; i < 10; i++) {"
51 "if (i % 0 == 1) break; else continue;" 51 "if (i % 0 == 1) break; else continue;"
52 "}" 52 "}"
53 "return;" 53 "return;"
54 "}", 54 "}",
55 default_caps(), 55 default_caps(),
56 "#version 400\n" 56 "#version 400\n"
57 "void main() {\n" 57 "void main() {\n"
58 " if (sqrt(2.0) > 5.0) {\n" 58 " if ((1 + 2) + 3 > 5) {\n"
59 " gl_FragColor = vec4(0.75);\n" 59 " gl_FragColor = vec4(0.75);\n"
60 " } else {\n" 60 " } else {\n"
61 " discard;\n" 61 " discard;\n"
62 " }\n" 62 " }\n"
63 " int i = 0;\n" 63 " int i = 0;\n"
64 " while (i < 10) gl_FragColor *= 0.5;\n" 64 " while (i < 10) gl_FragColor *= 0.5;\n"
65 " do {\n" 65 " do {\n"
66 " gl_FragColor += 0.01;\n" 66 " gl_FragColor += 0.01;\n"
67 " } while (gl_FragColor.x < 0.7);\n" 67 " } while (gl_FragColor.x < 0.7);\n"
68 " for (int i = 0;i < 10; i++) {\n" 68 " for (int i = 0;i < 10; i++) {\n"
(...skipping 28 matching lines...) Expand all
97 } 97 }
98 98
99 DEF_TEST(SkSLOperators, r) { 99 DEF_TEST(SkSLOperators, r) {
100 test(r, 100 test(r,
101 "void main() {" 101 "void main() {"
102 "float x = 1, y = 2;" 102 "float x = 1, y = 2;"
103 "int z = 3;" 103 "int z = 3;"
104 "x = x + y * z * x * (y - z);" 104 "x = x + y * z * x * (y - z);"
105 "y = x / y / z;" 105 "y = x / y / z;"
106 "z = (z / 2 % 3 << 4) >> 2 << 1;" 106 "z = (z / 2 % 3 << 4) >> 2 << 1;"
107 "bool b = (x > 4) == x < 2 || 2 >= sqrt(2) && y <= z;" 107 "bool b = (x > 4) == x < 2 || 2 >= 5 && y <= z && 12 != 11;"
108 "x += 12;" 108 "x += 12;"
109 "x -= 12;" 109 "x -= 12;"
110 "x *= y /= z = 10;" 110 "x *= y /= z = 10;"
111 "b ||= false;" 111 "b ||= false;"
112 "b &&= true;" 112 "b &&= true;"
113 "b ^^= false;" 113 "b ^^= false;"
114 "z |= 0;" 114 "z |= 0;"
115 "z &= -1;" 115 "z &= -1;"
116 "z ^= 0;" 116 "z ^= 0;"
117 "z >>= 2;" 117 "z >>= 2;"
118 "z <<= 4;" 118 "z <<= 4;"
119 "z %= 5;" 119 "z %= 5;"
120 "}", 120 "}",
121 default_caps(), 121 default_caps(),
122 "#version 400\n" 122 "#version 400\n"
123 "void main() {\n" 123 "void main() {\n"
124 " float x = 1.0, y = 2.0;\n" 124 " float x = 1.0, y = 2.0;\n"
125 " int z = 3;\n" 125 " int z = 3;\n"
126 " x = x + ((y * float(z)) * x) * (y - float(z));\n" 126 " x = x + ((y * float(z)) * x) * (y - float(z));\n"
127 " y = (x / y) / float(z);\n" 127 " y = (x / y) / float(z);\n"
128 " z = (((z / 2) % 3 << 4) >> 2) << 1;\n" 128 " z = (((z / 2) % 3 << 4) >> 2) << 1;\n"
129 " bool b = x > 4.0 == x < 2.0 || 2.0 >= sqrt(2.0) && y <= float(z);\ n" 129 " bool b = x > 4.0 == x < 2.0 || (2 >= 5 && y <= float(z)) && 12 != 11;\n"
130 " x += 12.0;\n" 130 " x += 12.0;\n"
131 " x -= 12.0;\n" 131 " x -= 12.0;\n"
132 " x *= (y /= float(z = 10));\n" 132 " x *= (y /= float(z = 10));\n"
133 " b ||= false;\n" 133 " b ||= false;\n"
134 " b &&= true;\n" 134 " b &&= true;\n"
135 " b ^^= false;\n" 135 " b ^^= false;\n"
136 " z |= 0;\n" 136 " z |= 0;\n"
137 " z &= -1;\n" 137 " z &= -1;\n"
138 " z ^= 0;\n" 138 " z ^= 0;\n"
139 " z >>= 2;\n" 139 " z >>= 2;\n"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 "}\n"); 423 "}\n");
424 test(r, 424 test(r,
425 "void main() { float x = dFdx(1); }", 425 "void main() { float x = dFdx(1); }",
426 caps, 426 caps,
427 "#version 400\n" 427 "#version 400\n"
428 "#extension GL_OES_standard_derivatives : require\n" 428 "#extension GL_OES_standard_derivatives : require\n"
429 "void main() {\n" 429 "void main() {\n"
430 " float x = dFdx(1.0);\n" 430 " float x = dFdx(1.0);\n"
431 "}\n"); 431 "}\n");
432 } 432 }
433
434 DEF_TEST(SkSLConstantFolding, r) {
435 test(r,
436 "void main() {"
437 "float f_add = 32 + 2;"
438 "float f_sub = 32 - 2;"
439 "float f_mul = 32 * 2;"
440 "float f_div = 32 / 2;"
441 "float mixed = (12 > 2.0) ? (10 * 2 / 5 + 18 - 3) : 0;"
442 "int i_add = 32 + 2;"
443 "int i_sub = 32 - 2;"
444 "int i_mul = 32 * 2;"
445 "int i_div = 32 / 2;"
446 "int i_or = 12 | 6;"
447 "int i_and = 254 & 7;"
448 "int i_xor = 2 ^ 7;"
449 "int i_shl = 1 << 4;"
450 "int i_shr = 128 >> 2;"
451 "bool gt_it = 6 > 5;"
452 "bool gt_if = 6 > 6;"
453 "bool gt_ft = 6.0 > 5.0;"
454 "bool gt_ff = 6.0 > 6.0;"
455 "bool gte_it = 6 >= 6;"
456 "bool gte_if = 6 >= 7;"
457 "bool gte_ft = 6.0 >= 6.0;"
458 "bool gte_ff = 6.0 >= 7.0;"
459 "bool lte_it = 6 <= 6;"
460 "bool lte_if = 6 <= 5;"
461 "bool lte_ft = 6.0 <= 6.0;"
462 "bool lte_ff = 6.0 <= 5.0;"
463 "bool or_t = 1 == 1 || 2 == 8;"
464 "bool or_f = 1 > 1 || 2 == 8;"
465 "bool and_t = 1 == 1 && 2 <= 8;"
466 "bool and_f = 1 == 2 && 2 == 8;"
467 "bool xor_t = 1 == 1 ^^ 1 != 1;"
468 "bool xor_f = 1 == 1 ^^ 1 == 1;"
469 "int ternary = 10 > 5 ? 10 : 5;"
470 "}",
471 default_caps(),
472 "#version 400\n"
473 "void main() {\n"
474 " float f_add = 34.0;\n"
475 " float f_sub = 30.0;\n"
476 " float f_mul = 64.0;\n"
477 " float f_div = 16.0;\n"
478 " float mixed = 19.0;\n"
479 " int i_add = 34;\n"
480 " int i_sub = 30;\n"
481 " int i_mul = 64;\n"
482 " int i_div = 16;\n"
483 " int i_or = 14;\n"
484 " int i_and = 6;\n"
485 " int i_xor = 5;\n"
486 " int i_shl = 16;\n"
487 " int i_shr = 32;\n"
488 " bool gt_it = true;\n"
489 " bool gt_if = false;\n"
490 " bool gt_ft = true;\n"
491 " bool gt_ff = false;\n"
492 " bool gte_it = true;\n"
493 " bool gte_if = false;\n"
494 " bool gte_ft = true;\n"
495 " bool gte_ff = false;\n"
496 " bool lte_it = true;\n"
497 " bool lte_if = false;\n"
498 " bool lte_ft = true;\n"
499 " bool lte_ff = false;\n"
500 " bool or_t = true;\n"
501 " bool or_f = false;\n"
502 " bool and_t = true;\n"
503 " bool and_f = false;\n"
504 " bool xor_t = true;\n"
505 " bool xor_f = false;\n"
506 " int ternary = 10;\n"
507 "}\n");
508 }
509
510 DEF_TEST(SkSLStaticIf, r) {
511 test(r,
512 "void main() {"
513 "int x;"
514 "if (true) x = 1;"
515 "if (2 > 1) x = 2; else x = 3;"
516 "if (1 > 2) x = 4; else x = 5;"
517 "if (false) x = 6;"
518 "}",
519 default_caps(),
520 "#version 400\n"
521 "void main() {\n"
522 " int x;\n"
523 " x = 1;\n"
524 " x = 2;\n"
525 " x = 5;\n"
526 " {\n"
527 " }\n"
528 "}\n");
529 }
OLDNEW
« no previous file with comments | « tests/SkSLErrorTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698