"}\n");
}
-DEF_TEST(SkSLConstantFolding, r) {
+
+DEF_TEST(SkSLIntFolding, r) {
test(r,
"void main() {"
- "float f_add = 32 + 2;"
- "sk_FragColor.r = f_add;"
- "float f_sub = 32 - 2;"
- "sk_FragColor.r = f_sub;"
- "float f_mul = 32 * 2;"
- "sk_FragColor.r = f_mul;"
- "float f_div = 32 / 2;"
- "sk_FragColor.r = f_div;"
- "float mixed = (12 > 2.0) ? (10 * 2 / 5 + 18 - 3) : 0;"
- "sk_FragColor.r = mixed;"
- "int i_add = 32 + 2;"
- "sk_FragColor.r = i_add;"
- "int i_sub = 32 - 2;"
- "sk_FragColor.r = i_sub;"
- "int i_mul = 32 * 2;"
- "sk_FragColor.r = i_mul;"
- "int i_div = 32 / 2;"
- "sk_FragColor.r = i_div;"
- "int i_or = 12 | 6;"
- "sk_FragColor.r = i_or;"
- "int i_and = 254 & 7;"
- "sk_FragColor.r = i_and;"
- "int i_xor = 2 ^ 7;"
- "sk_FragColor.r = i_xor;"
- "int i_shl = 1 << 4;"
- "sk_FragColor.r = i_shl;"
- "int i_shr = 128 >> 2;"
- "sk_FragColor.r = i_shr;"
- "bool gt_it = 6 > 5;"
- "sk_FragColor.r = true ? 1 : 0;"
- "bool gt_if = 6 > 6;"
- "sk_FragColor.r = gt_if ? 1 : 0;"
- "bool gt_ft = 6.0 > 5.0;"
- "sk_FragColor.r = gt_ft ? 1 : 0;"
- "bool gt_ff = 6.0 > 6.0;"
- "sk_FragColor.r = gt_ff ? 1 : 0;"
- "bool gte_it = 6 >= 6;"
- "sk_FragColor.r = gte_it ? 1 : 0;"
- "bool gte_if = 6 >= 7;"
- "sk_FragColor.r = gte_if ? 1 : 0;"
- "bool gte_ft = 6.0 >= 6.0;"
- "sk_FragColor.r = gte_ft ? 1 : 0;"
- "bool gte_ff = 6.0 >= 7.0;"
- "sk_FragColor.r = gte_ff ? 1 : 0;"
- "bool lte_it = 6 <= 6;"
- "sk_FragColor.r = lte_it ? 1 : 0;"
- "bool lte_if = 6 <= 5;"
- "sk_FragColor.r = lte_if ? 1 : 0;"
- "bool lte_ft = 6.0 <= 6.0;"
- "sk_FragColor.r = lte_ft ? 1 : 0;"
- "bool lte_ff = 6.0 <= 5.0;"
- "sk_FragColor.r = lte_ff ? 1 : 0;"
- "bool or_t = 1 == 1 || 2 == 8;"
- "sk_FragColor.r = or_t ? 1 : 0;"
- "bool or_f = 1 > 1 || 2 == 8;"
- "sk_FragColor.r = or_f ? 1 : 0;"
- "bool and_t = 1 == 1 && 2 <= 8;"
- "sk_FragColor.r = and_t ? 1 : 0;"
- "bool and_f = 1 == 2 && 2 == 8;"
- "sk_FragColor.r = and_f ? 1 : 0;"
- "bool xor_t = 1 == 1 ^^ 1 != 1;"
- "sk_FragColor.r = xor_t ? 1 : 0;"
- "bool xor_f = 1 == 1 ^^ 1 == 1;"
- "sk_FragColor.r = xor_f ? 1 : 0;"
- "int ternary = 10 > 5 ? 10 : 5;"
- "sk_FragColor.r = ternary;"
- "sk_FragColor.r = vec4(0.5, 1, 1, 1).x;"
- "sk_FragColor = vec4(vec2(1), vec2(2, 3)) + vec4(5, 6, 7, 8);"
- "sk_FragColor = vec4(8, vec3(10)) - vec4(1);"
- "sk_FragColor = vec4(2) * vec4(1, 2, 3, 4);"
- "sk_FragColor = vec4(12) / vec4(1, 2, 3, 4);"
- "sk_FragColor.r = (vec4(12) / vec4(1, 2, 3, 4)).y;"
- "sk_FragColor.x = vec4(1) == vec4(1) ? 1.0 : 0.0;"
- "sk_FragColor.x = vec4(1) == vec4(2) ? 1.0 : 0.0;"
- "sk_FragColor.x = vec2(1) == vec2(1, 1) ? 1.0 : 0.0;"
- "sk_FragColor.x = vec2(1, 1) == vec2(1, 1) ? 1.0 : 0.0;"
- "sk_FragColor.x = vec2(1) == vec2(1, 0) ? 1.0 : 0.0;"
- "sk_FragColor.x = vec4(1) == vec4(vec2(1), vec2(1)) ? 1.0 : 0.0;"
- "sk_FragColor.x = vec4(vec3(1), 1) == vec4(vec2(1), vec2(1)) ? 1.0 : 0.0;"
- "sk_FragColor.x = vec4(vec3(1), 1) == vec4(vec2(1), 1, 0) ? 1.0 : 0.0;"
- "sk_FragColor.x = mat2(vec2(1.0, 0.0), vec2(0.0, 1.0)) == "
- "mat2(vec2(1.0, 0.0), vec2(0.0, 1.0)) ? 1.0 : 0.0;"
- "sk_FragColor.x = mat2(vec2(1.0, 0.0), vec2(1.0, 1.0)) == "
- "mat2(vec2(1.0, 0.0), vec2(0.0, 1.0)) ? 1.0 : 0.0;"
- "sk_FragColor.x = mat2(1) == mat2(1) ? 1.0 : 0.0;"
- "sk_FragColor.x = mat2(1) == mat2(0) ? 1.0 : 0.0;"
- "sk_FragColor.x = mat2(1) == mat2(vec2(1.0, 0.0), vec2(0.0, 1.0)) ? 1.0 : 0.0;"
- "sk_FragColor.x = mat2(2) == mat2(vec2(1.0, 0.0), vec2(0.0, 1.0)) ? 1.0 : 0.0;"
- "sk_FragColor.x = mat3x2(2) == mat3x2(vec2(2.0, 0.0), vec2(0.0, 2.0), vec2(0.0)) ? "
- "1.0 : 0.0;"
- "sk_FragColor.x = vec2(1) != vec2(1, 0) ? 1.0 : 0.0;"
- "sk_FragColor.x = vec4(1) != vec4(vec2(1), vec2(1)) ? 1.0 : 0.0;"
- "sk_FragColor.x = mat2(1) != mat2(1) ? 1.0 : 0.0;"
- "sk_FragColor.x = mat2(1) != mat2(0) ? 1.0 : 0.0;"
- "sk_FragColor.x = mat3(vec3(1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, 0.0, 0.0)) == "
- "mat3(mat2(1.0)) ? 1.0 : 0.0;"
- "sk_FragColor.x = mat2(mat3(1.0)) == mat2(1.0) ? 1.0 : 0.0;"
- "sk_FragColor.x = mat2(vec4(1.0, 0.0, 0.0, 1.0)) == mat2(1.0) ? 1.0 : 0.0;"
- "sk_FragColor.x = mat2(1.0, 0.0, vec2(0.0, 1.0)) == mat2(1.0) ? 1.0 : 0.0;"
- "sk_FragColor.x = mat2(vec2(1.0, 0.0), 0.0, 1.0) == mat2(1.0) ? 1.0 : 0.0;"
+ "sk_FragColor.r = 32 + 2;"
+ "sk_FragColor.r = 32 - 2;"
+ "sk_FragColor.r = 32 * 2;"
+ "sk_FragColor.r = 32 / 2;"
+ "sk_FragColor.r = 12 | 6;"
+ "sk_FragColor.r = 254 & 7;"
+ "sk_FragColor.r = 2 ^ 7;"
+ "sk_FragColor.r = 1 << 4;"
+ "sk_FragColor.r = 128 >> 2;"
+ "sk_FragColor.r = -1 == -1 ? 1 : -1;"
+ "sk_FragColor.r = -1 == -2 ? 2 : -2;"
+ "sk_FragColor.r = 0 != 1 ? 3 : -3;"
+ "sk_FragColor.r = 0 != 0 ? 4 : -4;"
+ "sk_FragColor.r = 6 > 5 ? 5 : -5;"
+ "sk_FragColor.r = 6 > 6 ? 6 : -6;"
+ "sk_FragColor.r = -1 < 0 ? 7 : -7;"
+ "sk_FragColor.r = 1 < 0 ? 8 : -8;"
+ "sk_FragColor.r = 6 >= 6 ? 9 : -9;"
+ "sk_FragColor.r = 6 >= 7 ? 10 : -10;"
+ "sk_FragColor.r = 6 <= 6 ? 11 : -11;"
+ "sk_FragColor.r = 6 <= 5 ? 12 : -12;"
"}",
*SkSL::ShaderCapsFactory::Default(),
"#version 400\n"
" sk_FragColor.x = 30.0;\n"
" sk_FragColor.x = 64.0;\n"
" sk_FragColor.x = 16.0;\n"
- " sk_FragColor.x = 19.0;\n"
- " sk_FragColor.x = 34.0;\n"
- " sk_FragColor.x = 30.0;\n"
- " sk_FragColor.x = 64.0;\n"
- " sk_FragColor.x = 16.0;\n"
" sk_FragColor.x = 14.0;\n"
" sk_FragColor.x = 6.0;\n"
" sk_FragColor.x = 5.0;\n"
" sk_FragColor.x = 16.0;\n"
" sk_FragColor.x = 32.0;\n"
" sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 0.0;\n"
- " sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 0.0;\n"
- " sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 0.0;\n"
- " sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 0.0;\n"
- " sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 0.0;\n"
- " sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 0.0;\n"
- " sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 0.0;\n"
+ " sk_FragColor.x = -2.0;\n"
+ " sk_FragColor.x = 3.0;\n"
+ " sk_FragColor.x = -4.0;\n"
+ " sk_FragColor.x = 5.0;\n"
+ " sk_FragColor.x = -6.0;\n"
+ " sk_FragColor.x = 7.0;\n"
+ " sk_FragColor.x = -8.0;\n"
+ " sk_FragColor.x = 9.0;\n"
+ " sk_FragColor.x = -10.0;\n"
+ " sk_FragColor.x = 11.0;\n"
+ " sk_FragColor.x = -12.0;\n"
+ "}\n");
+}
+
+DEF_TEST(SkSLFloatFolding, r) {
+ test(r,
+ "void main() {"
+ "sk_FragColor.r = 32.0 + 2.0;"
+ "sk_FragColor.r = 32.0 - 2.0;"
+ "sk_FragColor.r = 32.0 * 2.0;"
+ "sk_FragColor.r = 32.0 / 2.0;"
+ "sk_FragColor.r = (12 > 2.0) ? (10 * 2 / 5 + 18 - 3) : 0;"
+ "sk_FragColor.r = 0.0 == 0.0 ? 1 : -1;"
+ "sk_FragColor.r = 0.0 == 1.0 ? 2 : -2;"
+ "sk_FragColor.r = 0.0 != 1.0 ? 3 : -3;"
+ "sk_FragColor.r = 0.0 != 0.0 ? 4 : -4;"
+ "sk_FragColor.r = 6.0 > 5.0 ? 5 : -5;"
+ "sk_FragColor.r = 6.0 > 6.0 ? 6 : -6;"
+ "sk_FragColor.r = 6.0 >= 6.0 ? 7 : -7;"
+ "sk_FragColor.r = 6.0 >= 7.0 ? 8 : -8;"
+ "sk_FragColor.r = 5.0 < 6.0 ? 9 : -9;"
+ "sk_FragColor.r = 6.0 < 6.0 ? 10 : -10;"
+ "sk_FragColor.r = 6.0 <= 6.0 ? 11 : -11;"
+ "sk_FragColor.r = 6.0 <= 5.0 ? 12 : -12;"
+ "}",
+ *SkSL::ShaderCapsFactory::Default(),
+ "#version 400\n"
+ "out vec4 sk_FragColor;\n"
+ "void main() {\n"
+ " sk_FragColor.x = 34.0;\n"
+ " sk_FragColor.x = 30.0;\n"
+ " sk_FragColor.x = 64.0;\n"
+ " sk_FragColor.x = 16.0;\n"
+ " sk_FragColor.x = 19.0;\n"
" sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 0.0;\n"
+ " sk_FragColor.x = -2.0;\n"
+ " sk_FragColor.x = 3.0;\n"
+ " sk_FragColor.x = -4.0;\n"
+ " sk_FragColor.x = 5.0;\n"
+ " sk_FragColor.x = -6.0;\n"
+ " sk_FragColor.x = 7.0;\n"
+ " sk_FragColor.x = -8.0;\n"
+ " sk_FragColor.x = 9.0;\n"
+ " sk_FragColor.x = -10.0;\n"
+ " sk_FragColor.x = 11.0;\n"
+ " sk_FragColor.x = -12.0;\n"
+ "}\n");
+}
+
+DEF_TEST(SkSLBoolFolding, r) {
+ test(r,
+ "void main() {"
+ "sk_FragColor.r = 1 == 1 || 2 == 8 ? 1 : -1;"
+ "sk_FragColor.r = 1 > 1 || 2 == 8 ? 2 : -2;"
+ "sk_FragColor.r = 1 == 1 && 2 <= 8 ? 3 : -3;"
+ "sk_FragColor.r = 1 == 2 && 2 == 8 ? 4 : -4;"
+ "sk_FragColor.r = 1 == 1 ^^ 1 != 1 ? 5 : -5;"
+ "sk_FragColor.r = 1 == 1 ^^ 1 == 1 ? 6 : -6;"
+ "}",
+ *SkSL::ShaderCapsFactory::Default(),
+ "#version 400\n"
+ "out vec4 sk_FragColor;\n"
+ "void main() {\n"
" sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 0.0;\n"
- " sk_FragColor.x = 10.0;\n"
+ " sk_FragColor.x = -2.0;\n"
+ " sk_FragColor.x = 3.0;\n"
+ " sk_FragColor.x = -4.0;\n"
+ " sk_FragColor.x = 5.0;\n"
+ " sk_FragColor.x = -6.0;\n"
+ "}\n");
+}
+
+DEF_TEST(SkSLVecFolding, r) {
+ test(r,
+ "void main() {"
+ "sk_FragColor.r = vec4(0.5, 1, 1, 1).x;"
+ "sk_FragColor = vec4(vec2(1), vec2(2, 3)) + vec4(5, 6, 7, 8);"
+ "sk_FragColor = vec4(8, vec3(10)) - vec4(1);"
+ "sk_FragColor = vec4(2) * vec4(1, 2, 3, 4);"
+ "sk_FragColor = vec4(12) / vec4(1, 2, 3, 4);"
+ "sk_FragColor.r = (vec4(12) / vec4(1, 2, 3, 4)).y;"
+ "sk_FragColor.x = vec4(1) == vec4(1) ? 1.0 : -1.0;"
+ "sk_FragColor.x = vec4(1) == vec4(2) ? 2.0 : -2.0;"
+ "sk_FragColor.x = vec2(1) == vec2(1, 1) ? 3.0 : -3.0;"
+ "sk_FragColor.x = vec2(1, 1) == vec2(1, 1) ? 4.0 : -4.0;"
+ "sk_FragColor.x = vec2(1) == vec2(1, 0) ? 5.0 : -5.0;"
+ "sk_FragColor.x = vec4(1) == vec4(vec2(1), vec2(1)) ? 6.0 : -6.0;"
+ "sk_FragColor.x = vec4(vec3(1), 1) == vec4(vec2(1), vec2(1)) ? 7.0 : -7.0;"
+ "sk_FragColor.x = vec4(vec3(1), 1) == vec4(vec2(1), 1, 0) ? 8.0 : -8.0;"
+ "sk_FragColor.x = vec2(1) != vec2(1, 0) ? 9.0 : -9.0;"
+ "sk_FragColor.x = vec4(1) != vec4(vec2(1), vec2(1)) ? 10.0 : -10.0;"
+ "}",
+ *SkSL::ShaderCapsFactory::Default(),
+ "#version 400\n"
+ "out vec4 sk_FragColor;\n"
+ "void main() {\n"
" sk_FragColor.x = 0.5;\n"
" sk_FragColor = vec4(6.0, 7.0, 9.0, 11.0);\n"
" sk_FragColor = vec4(7.0, 9.0, 9.0, 9.0);\n"
" sk_FragColor = vec4(12.0, 6.0, 4.0, 3.0);\n"
" sk_FragColor.x = 6.0;\n"
" sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 0.0;\n"
- " sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 0.0;\n"
- " sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 0.0;\n"
- " sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 0.0;\n"
- " sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 0.0;\n"
- " sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 0.0;\n"
- " sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 0.0;\n"
- " sk_FragColor.x = 0.0;\n"
- " sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 1.0;\n"
- " sk_FragColor.x = 1.0;\n"
+ " sk_FragColor.x = -2.0;\n"
+ " sk_FragColor.x = 3.0;\n"
+ " sk_FragColor.x = 4.0;\n"
+ " sk_FragColor.x = -5.0;\n"
+ " sk_FragColor.x = 6.0;\n"
+ " sk_FragColor.x = 7.0;\n"
+ " sk_FragColor.x = -8.0;\n"
+ " sk_FragColor.x = 9.0;\n"
+ " sk_FragColor.x = -10.0;\n"
+ "}\n");
+}
+
+DEF_TEST(SkSLMatFolding, r) {
+ test(r,
+ "void main() {"
+ "sk_FragColor.x = mat2(vec2(1.0, 0.0), vec2(0.0, 1.0)) == "
+ "mat2(vec2(1.0, 0.0), vec2(0.0, 1.0)) ? 1 : -1;"
+ "sk_FragColor.x = mat2(vec2(1.0, 0.0), vec2(1.0, 1.0)) == "
+ "mat2(vec2(1.0, 0.0), vec2(0.0, 1.0)) ? 2 : -2;"
+ "sk_FragColor.x = mat2(1) == mat2(1) ? 3 : -3;"
+ "sk_FragColor.x = mat2(1) == mat2(0) ? 4 : -4;"
+ "sk_FragColor.x = mat2(1) == mat2(vec2(1.0, 0.0), vec2(0.0, 1.0)) ? 5 : -5;"
+ "sk_FragColor.x = mat2(2) == mat2(vec2(1.0, 0.0), vec2(0.0, 1.0)) ? 6 : -6;"
+ "sk_FragColor.x = mat3x2(2) == mat3x2(vec2(2.0, 0.0), vec2(0.0, 2.0), vec2(0.0)) ? 7 : -7;"
+ "sk_FragColor.x = mat2(1) != mat2(1) ? 8 : -8;"
+ "sk_FragColor.x = mat2(1) != mat2(0) ? 9 : -9;"
+ "sk_FragColor.x = mat3(vec3(1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, 0.0, 0.0)) == "
+ "mat3(mat2(1.0)) ? 10 : -10;"
+ "sk_FragColor.x = mat2(mat3(1.0)) == mat2(1.0) ? 11 : -11;"
+ "sk_FragColor.x = mat2(vec4(1.0, 0.0, 0.0, 1.0)) == mat2(1.0) ? 12 : -12;"
+ "sk_FragColor.x = mat2(1.0, 0.0, vec2(0.0, 1.0)) == mat2(1.0) ? 13 : -13;"
+ "sk_FragColor.x = mat2(vec2(1.0, 0.0), 0.0, 1.0) == mat2(1.0) ? 14 : -14;"
+ "}",
+ *SkSL::ShaderCapsFactory::Default(),
+ "#version 400\n"
+ "out vec4 sk_FragColor;\n"
+ "void main() {\n"
" sk_FragColor.x = 1.0;\n"
+ " sk_FragColor.x = -2.0;\n"
+ " sk_FragColor.x = 3.0;\n"
+ " sk_FragColor.x = -4.0;\n"
+ " sk_FragColor.x = 5.0;\n"
+ " sk_FragColor.x = -6.0;\n"
+ " sk_FragColor.x = 7.0;\n"
+ " sk_FragColor.x = -8.0;\n"
+ " sk_FragColor.x = 9.0;\n"
+ " sk_FragColor.x = 10.0;\n"
+ " sk_FragColor.x = 11.0;\n"
+ " sk_FragColor.x = 12.0;\n"
+ " sk_FragColor.x = 13.0;\n"
+ " sk_FragColor.x = 14.0;\n"
"}\n");
}