ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/sksl/SkSLCompiler.h" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "tests/Test.h" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 11 | |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 12 | // Note that the optimizer will aggressively kill dead code and substitute constants in place of |
| 13 | // variables, so we have to jump through a few hoops to ensure that the code in these tests has the |
| 14 | // necessary side-effects to remain live. In some cases we rely on the optimizer not (yet) being |
| 15 | // smart enough to optimize around certain constructs; as the optimizer gets smarter it will |
| 16 | // undoubtedly end up breaking some of these tests. That is a good thing, as long as the new code is |
| 17 | // equivalent! |
| 18 | |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 19 | static void test(skiatest::Reporter* r, const char* src, const SkSL::Program::Settings& settings, |
Ethan Nicholas | a51740c | 2017-02-07 14:53:32 -0500 | [diff] [blame] | 20 | const char* expected, SkSL::Program::Inputs* inputs, |
| 21 | SkSL::Program::Kind kind = SkSL::Program::kFragment_Kind) { |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 22 | SkSL::Compiler compiler; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 23 | SkSL::String output; |
Brian Osman | 93ba0a4 | 2017-08-14 14:48:10 -0400 | [diff] [blame] | 24 | std::unique_ptr<SkSL::Program> program = compiler.convertProgram(kind, SkSL::String(src), |
| 25 | settings); |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 26 | if (!program) { |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 27 | SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().c_str()); |
| 28 | } |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 29 | REPORTER_ASSERT(r, program); |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 30 | if (program) { |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 31 | *inputs = program->fInputs; |
| 32 | REPORTER_ASSERT(r, compiler.toGLSL(*program, &output)); |
| 33 | if (program) { |
| 34 | SkSL::String skExpected(expected); |
| 35 | if (output != skExpected) { |
| 36 | SkDebugf("GLSL MISMATCH:\nsource:\n%s\n\nexpected:\n'%s'\n\nreceived:\n'%s'", src, |
| 37 | expected, output.c_str()); |
| 38 | } |
| 39 | REPORTER_ASSERT(r, output == skExpected); |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 40 | } |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 44 | static void test(skiatest::Reporter* r, const char* src, const GrShaderCaps& caps, |
Ethan Nicholas | a51740c | 2017-02-07 14:53:32 -0500 | [diff] [blame] | 45 | const char* expected, SkSL::Program::Kind kind = SkSL::Program::kFragment_Kind) { |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 46 | SkSL::Program::Settings settings; |
| 47 | settings.fCaps = ∩︀ |
| 48 | SkSL::Program::Inputs inputs; |
Ethan Nicholas | a51740c | 2017-02-07 14:53:32 -0500 | [diff] [blame] | 49 | test(r, src, settings, expected, &inputs, kind); |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 50 | } |
| 51 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 52 | DEF_TEST(SkSLHelloWorld, r) { |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 53 | test(r, |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 54 | "void main() { sk_FragColor = half4(0.75); }", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 55 | *SkSL::ShaderCapsFactory::Default(), |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 56 | "#version 400\n" |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 57 | "out vec4 sk_FragColor;\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 58 | "void main() {\n" |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 59 | " sk_FragColor = vec4(0.75);\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 60 | "}\n"); |
| 61 | } |
| 62 | |
| 63 | DEF_TEST(SkSLControl, r) { |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 64 | test(r, |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 65 | "void main() {" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 66 | "if (sqrt(2) > 5) { sk_FragColor = half4(0.75); } else { discard; }" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 67 | "int i = 0;" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 68 | "while (i < 10) { sk_FragColor *= 0.5; i++; }" |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 69 | "do { sk_FragColor += 0.25; } while (sk_FragColor.x < 0.75);" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 70 | "for (int i = 0; i < 10; i++) {" |
Ethan Nicholas | 86a4340 | 2017-01-19 13:32:00 -0500 | [diff] [blame] | 71 | "if (i % 2 == 1) break; else continue;" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 72 | "}" |
| 73 | "return;" |
| 74 | "}", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 75 | *SkSL::ShaderCapsFactory::Default(), |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 76 | "#version 400\n" |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 77 | "out vec4 sk_FragColor;\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 78 | "void main() {\n" |
ethannicholas | 08a9211 | 2016-11-09 13:26:45 -0800 | [diff] [blame] | 79 | " if (sqrt(2.0) > 5.0) {\n" |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 80 | " sk_FragColor = vec4(0.75);\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 81 | " } else {\n" |
| 82 | " discard;\n" |
| 83 | " }\n" |
| 84 | " int i = 0;\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 85 | " while (i < 10) {\n" |
| 86 | " sk_FragColor *= 0.5;\n" |
| 87 | " i++;\n" |
| 88 | " }\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 89 | " do {\n" |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 90 | " sk_FragColor += 0.25;\n" |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 91 | " } while (sk_FragColor.x < 0.75);\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 92 | " for (int i = 0;i < 10; i++) {\n" |
Ethan Nicholas | 86a4340 | 2017-01-19 13:32:00 -0500 | [diff] [blame] | 93 | " if (i % 2 == 1) break; else continue;\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 94 | " }\n" |
| 95 | " return;\n" |
| 96 | "}\n"); |
| 97 | } |
| 98 | |
| 99 | DEF_TEST(SkSLFunctions, r) { |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 100 | test(r, |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 101 | "float foo(float v[2]) { return v[0] * v[1]; }" |
| 102 | "void bar(inout float x) { float y[2], z; y[0] = x; y[1] = x * 2; z = foo(y); x = z; }" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 103 | "void main() { float x = 10; bar(x); sk_FragColor = half4(half(x)); }", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 104 | *SkSL::ShaderCapsFactory::Default(), |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 105 | "#version 400\n" |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 106 | "out vec4 sk_FragColor;\n" |
Ethan Nicholas | c6f5e10 | 2017-03-31 14:53:17 -0400 | [diff] [blame] | 107 | "float foo(float v[2]) {\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 108 | " return v[0] * v[1];\n" |
| 109 | "}\n" |
| 110 | "void bar(inout float x) {\n" |
| 111 | " float y[2], z;\n" |
| 112 | " y[0] = x;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 113 | " y[1] = x * 2.0;\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 114 | " z = foo(y);\n" |
| 115 | " x = z;\n" |
| 116 | "}\n" |
| 117 | "void main() {\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 118 | " float x = 10.0;\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 119 | " bar(x);\n" |
| 120 | " sk_FragColor = vec4(x);\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 121 | "}\n"); |
| 122 | } |
| 123 | |
| 124 | DEF_TEST(SkSLOperators, r) { |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 125 | test(r, |
| 126 | "void main() {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 127 | "float x = 1, y = 2;" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 128 | "int z = 3;" |
Ethan Nicholas | 86a4340 | 2017-01-19 13:32:00 -0500 | [diff] [blame] | 129 | "x = x - x + y * z * x * (y - z);" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 130 | "y = x / y / z;" |
| 131 | "z = (z / 2 % 3 << 4) >> 2 << 1;" |
ethannicholas | 08a9211 | 2016-11-09 13:26:45 -0800 | [diff] [blame] | 132 | "bool b = (x > 4) == x < 2 || 2 >= sqrt(2) && y <= z;" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 133 | "x += 12;" |
| 134 | "x -= 12;" |
| 135 | "x *= y /= z = 10;" |
| 136 | "b ||= false;" |
| 137 | "b &&= true;" |
| 138 | "b ^^= false;" |
| 139 | "z |= 0;" |
| 140 | "z &= -1;" |
| 141 | "z ^= 0;" |
| 142 | "z >>= 2;" |
| 143 | "z <<= 4;" |
| 144 | "z %= 5;" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 145 | "x = (float2(sqrt(1)) , 6);" |
| 146 | "z = (float2(sqrt(1)) , 6);" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 147 | "}", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 148 | *SkSL::ShaderCapsFactory::Default(), |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 149 | "#version 400\n" |
| 150 | "void main() {\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 151 | " float x = 1.0, y = 2.0;\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 152 | " int z = 3;\n" |
Ethan Nicholas | 86a4340 | 2017-01-19 13:32:00 -0500 | [diff] [blame] | 153 | " x = -6.0;\n" |
| 154 | " y = -1.0;\n" |
| 155 | " z = 8;\n" |
Michael Ludwig | 7b429ae | 2018-09-06 17:01:38 -0400 | [diff] [blame] | 156 | " bool b = false == true || 2.0 >= sqrt(2.0);\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 157 | " x += 12.0;\n" |
| 158 | " x -= 12.0;\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 159 | " x *= (y /= float(z = 10));\n" |
| 160 | " b ||= false;\n" |
| 161 | " b &&= true;\n" |
| 162 | " b ^^= false;\n" |
| 163 | " z |= 0;\n" |
| 164 | " z &= -1;\n" |
| 165 | " z ^= 0;\n" |
| 166 | " z >>= 2;\n" |
| 167 | " z <<= 4;\n" |
| 168 | " z %= 5;\n" |
Ethan Nicholas | 4b330df | 2017-05-17 10:52:55 -0400 | [diff] [blame] | 169 | " x = float((vec2(sqrt(1.0)) , 6));\n" |
| 170 | " z = (vec2(sqrt(1.0)) , 6);\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 171 | "}\n"); |
| 172 | } |
| 173 | |
| 174 | DEF_TEST(SkSLMatrices, r) { |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 175 | test(r, |
| 176 | "void main() {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 177 | "float2x4 x = float2x4(1);" |
| 178 | "float3x2 y = float3x2(1, 0, 0, 1, float2(2, 2));" |
| 179 | "float3x4 z = x * y;" |
| 180 | "float3 v1 = float3x3(1) * float3(2);" |
| 181 | "float3 v2 = float3(2) * float3x3(1);" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 182 | "sk_FragColor = half4(half(z[0].x), half3(v1 + v2));" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 183 | "}", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 184 | *SkSL::ShaderCapsFactory::Default(), |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 185 | "#version 400\n" |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 186 | "out vec4 sk_FragColor;\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 187 | "void main() {\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 188 | " mat3x4 z = mat2x4(1.0) * mat3x2(1.0, 0.0, 0.0, 1.0, vec2(2.0, 2.0));\n" |
Ethan Nicholas | fe53e58 | 2017-04-27 16:24:51 -0400 | [diff] [blame] | 189 | " vec3 v1 = mat3(1.0) * vec3(2.0);\n" |
| 190 | " vec3 v2 = vec3(2.0) * mat3(1.0);\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 191 | " sk_FragColor = vec4(z[0].x, v1 + v2);\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 192 | "}\n"); |
| 193 | } |
| 194 | |
| 195 | DEF_TEST(SkSLInterfaceBlock, r) { |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 196 | test(r, |
| 197 | "uniform testBlock {" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 198 | "half x;" |
| 199 | "half y[2];" |
| 200 | "layout(binding=12) half3x2 z;" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 201 | "bool w;" |
| 202 | "};" |
| 203 | "void main() {" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 204 | " sk_FragColor = half4(x, y[0], y[1], 0);" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 205 | "}", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 206 | *SkSL::ShaderCapsFactory::Default(), |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 207 | "#version 400\n" |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 208 | "out vec4 sk_FragColor;\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 209 | "uniform testBlock {\n" |
| 210 | " float x;\n" |
| 211 | " float[2] y;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 212 | " layout (binding = 12) mat3x2 z;\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 213 | " bool w;\n" |
| 214 | "};\n" |
| 215 | "void main() {\n" |
Ethan Nicholas | 50afc17 | 2017-02-16 14:49:57 -0500 | [diff] [blame] | 216 | " sk_FragColor = vec4(x, y[0], y[1], 0.0);\n" |
| 217 | "}\n"); |
| 218 | test(r, |
| 219 | "uniform testBlock {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 220 | "float x;" |
Ethan Nicholas | 50afc17 | 2017-02-16 14:49:57 -0500 | [diff] [blame] | 221 | "} test;" |
| 222 | "void main() {" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 223 | " sk_FragColor = half4(half(test.x));" |
Ethan Nicholas | 50afc17 | 2017-02-16 14:49:57 -0500 | [diff] [blame] | 224 | "}", |
| 225 | *SkSL::ShaderCapsFactory::Default(), |
| 226 | "#version 400\n" |
| 227 | "out vec4 sk_FragColor;\n" |
| 228 | "uniform testBlock {\n" |
| 229 | " float x;\n" |
| 230 | "} test;\n" |
| 231 | "void main() {\n" |
| 232 | " sk_FragColor = vec4(test.x);\n" |
| 233 | "}\n"); |
| 234 | test(r, |
| 235 | "uniform testBlock {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 236 | "float x;" |
Ethan Nicholas | 50afc17 | 2017-02-16 14:49:57 -0500 | [diff] [blame] | 237 | "} test[2];" |
| 238 | "void main() {" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 239 | " sk_FragColor = half4(half(test[1].x));" |
Ethan Nicholas | 50afc17 | 2017-02-16 14:49:57 -0500 | [diff] [blame] | 240 | "}", |
| 241 | *SkSL::ShaderCapsFactory::Default(), |
| 242 | "#version 400\n" |
| 243 | "out vec4 sk_FragColor;\n" |
| 244 | "uniform testBlock {\n" |
| 245 | " float x;\n" |
| 246 | "} test[2];\n" |
| 247 | "void main() {\n" |
| 248 | " sk_FragColor = vec4(test[1].x);\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 249 | "}\n"); |
| 250 | } |
| 251 | |
| 252 | DEF_TEST(SkSLStructs, r) { |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 253 | test(r, |
| 254 | "struct A {" |
| 255 | "int x;" |
| 256 | "int y;" |
| 257 | "} a1, a2;" |
| 258 | "A a3;" |
| 259 | "struct B {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 260 | "float x;" |
| 261 | "float y[2];" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 262 | "layout(binding=1) A z;" |
| 263 | "};" |
| 264 | "B b1, b2, b3;" |
| 265 | "void main() {" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 266 | " a1.x = 0;" |
| 267 | " b1.x = 0;" |
| 268 | " sk_FragColor.r = half(a1.x + b1.x);" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 269 | "}", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 270 | *SkSL::ShaderCapsFactory::Default(), |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 271 | "#version 400\n" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 272 | "out vec4 sk_FragColor;\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 273 | "struct A {\n" |
| 274 | " int x;\n" |
| 275 | " int y;\n" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 276 | "} a1;\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 277 | "struct B {\n" |
| 278 | " float x;\n" |
| 279 | " float[2] y;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 280 | " layout (binding = 1) A z;\n" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 281 | "} b1;\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 282 | "void main() {\n" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 283 | " a1.x = 0;\n" |
| 284 | " b1.x = 0.0;\n" |
| 285 | " sk_FragColor.x = float(a1.x) + b1.x;\n" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 286 | "}\n"); |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 287 | } |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 288 | |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 289 | DEF_TEST(SkSLVersion, r) { |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 290 | test(r, |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 291 | "in float test; void main() { sk_FragColor.r = half(test); }", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 292 | *SkSL::ShaderCapsFactory::Version450Core(), |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 293 | "#version 450 core\n" |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 294 | "out vec4 sk_FragColor;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 295 | "in float test;\n" |
| 296 | "void main() {\n" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 297 | " sk_FragColor.x = test;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 298 | "}\n"); |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 299 | test(r, |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 300 | "in float test; void main() { sk_FragColor.r = half(test); }", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 301 | *SkSL::ShaderCapsFactory::Version110(), |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 302 | "#version 110\n" |
| 303 | "varying float test;\n" |
| 304 | "void main() {\n" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 305 | " gl_FragColor.x = test;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 306 | "}\n"); |
| 307 | } |
| 308 | |
Leon Scroggins | 857cb97 | 2016-11-11 18:44:37 +0000 | [diff] [blame] | 309 | DEF_TEST(SkSLUsesPrecisionModifiers, r) { |
Leon Scroggins | 857cb97 | 2016-11-11 18:44:37 +0000 | [diff] [blame] | 310 | test(r, |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 311 | "void main() { half x = 0.75; float y = 1; x++; y++;" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 312 | "sk_FragColor.rg = half2(x, half(y)); }", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 313 | *SkSL::ShaderCapsFactory::Default(), |
Leon Scroggins | 857cb97 | 2016-11-11 18:44:37 +0000 | [diff] [blame] | 314 | "#version 400\n" |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 315 | "out vec4 sk_FragColor;\n" |
Leon Scroggins | 857cb97 | 2016-11-11 18:44:37 +0000 | [diff] [blame] | 316 | "void main() {\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 317 | " float x = 0.75;\n" |
| 318 | " float y = 1.0;\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 319 | " x++;\n" |
| 320 | " y++;\n" |
| 321 | " sk_FragColor.xy = vec2(x, y);\n" |
| 322 | "}\n"); |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 323 | test(r, |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 324 | "void main() { half x = 0.75; float y = 1; x++; y++;" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 325 | "sk_FragColor.rg = half2(x, half(y)); }", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 326 | *SkSL::ShaderCapsFactory::UsesPrecisionModifiers(), |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 327 | "#version 400\n" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 328 | "precision mediump float;\n" |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 329 | "precision mediump sampler2D;\n" |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 330 | "out mediump vec4 sk_FragColor;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 331 | "void main() {\n" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 332 | " mediump float x = 0.75;\n" |
| 333 | " highp float y = 1.0;\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 334 | " x++;\n" |
| 335 | " y++;\n" |
| 336 | " sk_FragColor.xy = vec2(x, y);\n" |
| 337 | "}\n"); |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | DEF_TEST(SkSLMinAbs, r) { |
| 341 | test(r, |
| 342 | "void main() {" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 343 | "half x = -5;" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 344 | "sk_FragColor.r = min(abs(x), 6);" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 345 | "}", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 346 | *SkSL::ShaderCapsFactory::Default(), |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 347 | "#version 400\n" |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 348 | "out vec4 sk_FragColor;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 349 | "void main() {\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 350 | " sk_FragColor.x = min(abs(-5.0), 6.0);\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 351 | "}\n"); |
| 352 | |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 353 | test(r, |
| 354 | "void main() {" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 355 | "half x = -5.0;" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 356 | "sk_FragColor.r = min(abs(x), 6.0);" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 357 | "}", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 358 | *SkSL::ShaderCapsFactory::CannotUseMinAndAbsTogether(), |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 359 | "#version 400\n" |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 360 | "out vec4 sk_FragColor;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 361 | "void main() {\n" |
| 362 | " float minAbsHackVar0;\n" |
| 363 | " float minAbsHackVar1;\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 364 | " sk_FragColor.x = ((minAbsHackVar0 = abs(-5.0)) < (minAbsHackVar1 = 6.0) ? " |
| 365 | "minAbsHackVar0 : minAbsHackVar1);\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 366 | "}\n"); |
| 367 | } |
| 368 | |
Florin Malita | 3b30c4f | 2017-08-08 15:47:35 -0400 | [diff] [blame] | 369 | DEF_TEST(SkSLFractNegative, r) { |
| 370 | static constexpr char input[] = |
| 371 | "void main() {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 372 | "float x = -42.0;" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 373 | "sk_FragColor.r = half(fract(x));" |
Florin Malita | 3b30c4f | 2017-08-08 15:47:35 -0400 | [diff] [blame] | 374 | "}"; |
| 375 | static constexpr char output_default[] = |
| 376 | "#version 400\n" |
| 377 | "out vec4 sk_FragColor;\n" |
| 378 | "void main() {\n" |
| 379 | " sk_FragColor.x = fract(-42.0);\n" |
| 380 | "}\n"; |
| 381 | static constexpr char output_workaround[] = |
| 382 | "#version 400\n" |
| 383 | "out vec4 sk_FragColor;\n" |
| 384 | "void main() {\n" |
| 385 | " sk_FragColor.x = (0.5 - sign(-42.0) * (0.5 - fract(abs(-42.0))));\n" |
| 386 | "}\n"; |
| 387 | |
| 388 | test(r, input, *SkSL::ShaderCapsFactory::Default(), output_default); |
| 389 | test(r, input, *SkSL::ShaderCapsFactory::CannotUseFractForNegativeValues(), output_workaround); |
| 390 | } |
| 391 | |
ethannicholas | ad146f6 | 2016-10-14 06:40:02 -0700 | [diff] [blame] | 392 | DEF_TEST(SkSLNegatedAtan, r) { |
| 393 | test(r, |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 394 | "void main() { float2 x = float2(sqrt(2)); sk_FragColor.r = half(atan(x.x, -x.y)); }", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 395 | *SkSL::ShaderCapsFactory::Default(), |
ethannicholas | ad146f6 | 2016-10-14 06:40:02 -0700 | [diff] [blame] | 396 | "#version 400\n" |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 397 | "out vec4 sk_FragColor;\n" |
ethannicholas | ad146f6 | 2016-10-14 06:40:02 -0700 | [diff] [blame] | 398 | "void main() {\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 399 | " vec2 x = vec2(sqrt(2.0));\n" |
| 400 | " sk_FragColor.x = atan(x.x, -x.y);\n" |
ethannicholas | ad146f6 | 2016-10-14 06:40:02 -0700 | [diff] [blame] | 401 | "}\n"); |
ethannicholas | ad146f6 | 2016-10-14 06:40:02 -0700 | [diff] [blame] | 402 | test(r, |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 403 | "void main() { float2 x = float2(sqrt(2)); sk_FragColor.r = half(atan(x.x, -x.y)); }", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 404 | *SkSL::ShaderCapsFactory::MustForceNegatedAtanParamToFloat(), |
ethannicholas | ad146f6 | 2016-10-14 06:40:02 -0700 | [diff] [blame] | 405 | "#version 400\n" |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 406 | "out vec4 sk_FragColor;\n" |
ethannicholas | ad146f6 | 2016-10-14 06:40:02 -0700 | [diff] [blame] | 407 | "void main() {\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 408 | " vec2 x = vec2(sqrt(2.0));\n" |
| 409 | " sk_FragColor.x = atan(x.x, -1.0 * x.y);\n" |
ethannicholas | ad146f6 | 2016-10-14 06:40:02 -0700 | [diff] [blame] | 410 | "}\n"); |
| 411 | } |
| 412 | |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 413 | DEF_TEST(SkSLModifiersDeclaration, r) { |
| 414 | test(r, |
| 415 | "layout(blend_support_all_equations) out;" |
Ethan Nicholas | 39204fd | 2017-11-27 13:12:30 -0500 | [diff] [blame] | 416 | "layout(blend_support_all_equations) out;" |
| 417 | "layout(blend_support_multiply) out;" |
| 418 | "layout(blend_support_screen) out;" |
| 419 | "layout(blend_support_overlay) out;" |
| 420 | "layout(blend_support_darken) out;" |
| 421 | "layout(blend_support_lighten) out;" |
| 422 | "layout(blend_support_colordodge) out;" |
| 423 | "layout(blend_support_colorburn) out;" |
| 424 | "layout(blend_support_hardlight) out;" |
| 425 | "layout(blend_support_softlight) out;" |
| 426 | "layout(blend_support_difference) out;" |
| 427 | "layout(blend_support_exclusion) out;" |
| 428 | "layout(blend_support_hsl_hue) out;" |
| 429 | "layout(blend_support_hsl_saturation) out;" |
| 430 | "layout(blend_support_hsl_color) out;" |
| 431 | "layout(blend_support_hsl_luminosity) out;" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 432 | "void main() { }", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 433 | *SkSL::ShaderCapsFactory::Default(), |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 434 | "#version 400\n" |
| 435 | "layout (blend_support_all_equations) out ;\n" |
Ethan Nicholas | 39204fd | 2017-11-27 13:12:30 -0500 | [diff] [blame] | 436 | "layout (blend_support_all_equations) out ;\n" |
| 437 | "layout (blend_support_multiply) out ;\n" |
| 438 | "layout (blend_support_screen) out ;\n" |
| 439 | "layout (blend_support_overlay) out ;\n" |
| 440 | "layout (blend_support_darken) out ;\n" |
| 441 | "layout (blend_support_lighten) out ;\n" |
| 442 | "layout (blend_support_colordodge) out ;\n" |
| 443 | "layout (blend_support_colorburn) out ;\n" |
| 444 | "layout (blend_support_hardlight) out ;\n" |
| 445 | "layout (blend_support_softlight) out ;\n" |
| 446 | "layout (blend_support_difference) out ;\n" |
| 447 | "layout (blend_support_exclusion) out ;\n" |
| 448 | "layout (blend_support_hsl_hue) out ;\n" |
| 449 | "layout (blend_support_hsl_saturation) out ;\n" |
| 450 | "layout (blend_support_hsl_color) out ;\n" |
| 451 | "layout (blend_support_hsl_luminosity) out ;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 452 | "void main() {\n" |
| 453 | "}\n"); |
| 454 | } |
| 455 | |
| 456 | DEF_TEST(SkSLHex, r) { |
| 457 | test(r, |
| 458 | "void main() {" |
| 459 | "int i1 = 0x0;" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 460 | "i1++;" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 461 | "int i2 = 0x1234abcd;" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 462 | "i2++;" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 463 | "int i3 = 0x7fffffff;" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 464 | "i3++;" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 465 | "int i4 = 0xffffffff;" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 466 | "i4++;" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 467 | "int i5 = -0xbeef;" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 468 | "i5++;" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 469 | "uint u1 = 0x0;" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 470 | "u1++;" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 471 | "uint u2 = 0x1234abcd;" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 472 | "u2++;" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 473 | "uint u3 = 0x7fffffff;" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 474 | "u3++;" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 475 | "uint u4 = 0xffffffff;" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 476 | "u4++;" |
Ethan Nicholas | 58d5648 | 2017-12-19 09:29:22 -0500 | [diff] [blame] | 477 | "ushort u5 = 0xffff;" |
| 478 | "u5++;" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 479 | "}", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 480 | *SkSL::ShaderCapsFactory::Default(), |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 481 | "#version 400\n" |
| 482 | "void main() {\n" |
| 483 | " int i1 = 0;\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 484 | " i1++;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 485 | " int i2 = 305441741;\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 486 | " i2++;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 487 | " int i3 = 2147483647;\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 488 | " i3++;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 489 | " int i4 = -1;\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 490 | " i4++;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 491 | " int i5 = -48879;\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 492 | " i5++;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 493 | " uint u1 = 0u;\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 494 | " u1++;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 495 | " uint u2 = 305441741u;\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 496 | " u2++;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 497 | " uint u3 = 2147483647u;\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 498 | " u3++;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 499 | " uint u4 = 4294967295u;\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 500 | " u4++;\n" |
Ethan Nicholas | 58d5648 | 2017-12-19 09:29:22 -0500 | [diff] [blame] | 501 | " uint u5 = 65535u;\n" |
| 502 | " u5++;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 503 | "}\n"); |
| 504 | } |
| 505 | |
Ethan Nicholas | 4578a8e | 2016-11-01 11:57:42 -0400 | [diff] [blame] | 506 | DEF_TEST(SkSLVectorConstructors, r) { |
| 507 | test(r, |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 508 | "float2 v1 = float2(1);" |
| 509 | "float2 v2 = float2(1, 2);" |
| 510 | "float2 v3 = float2(float2(1));" |
| 511 | "float3 v4 = float3(float2(1), 1.0);" |
Ethan Nicholas | 5af9ea3 | 2017-07-28 15:19:46 -0400 | [diff] [blame] | 512 | "int2 v5 = int2(1);" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 513 | "int2 v6 = int2(float2(1, 2));" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 514 | "float2 v7 = float2(int2(1, 2));" |
| 515 | "void main() {" |
| 516 | "sk_FragColor.r = half(v1.x + v2.x + v3.x + v4.x + v5.x + v6.x + v7.x);" |
| 517 | "}", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 518 | *SkSL::ShaderCapsFactory::Default(), |
Ethan Nicholas | 4578a8e | 2016-11-01 11:57:42 -0400 | [diff] [blame] | 519 | "#version 400\n" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 520 | "out vec4 sk_FragColor;\n" |
Ethan Nicholas | 4578a8e | 2016-11-01 11:57:42 -0400 | [diff] [blame] | 521 | "vec2 v1 = vec2(1.0);\n" |
| 522 | "vec2 v2 = vec2(1.0, 2.0);\n" |
| 523 | "vec2 v3 = vec2(1.0);\n" |
Ethan Nicholas | 84645e3 | 2017-02-09 13:57:14 -0500 | [diff] [blame] | 524 | "vec3 v4 = vec3(vec2(1.0), 1.0);\n" |
| 525 | "ivec2 v5 = ivec2(1);\n" |
| 526 | "ivec2 v6 = ivec2(vec2(1.0, 2.0));\n" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 527 | "vec2 v7 = vec2(ivec2(1, 2));\n" |
| 528 | "void main() {\n" |
| 529 | " sk_FragColor.x = (((((v1.x + v2.x) + v3.x) + v4.x) + float(v5.x)) + float(v6.x)) + " |
| 530 | "v7.x;\n" |
| 531 | "}\n"); |
Ethan Nicholas | 4578a8e | 2016-11-01 11:57:42 -0400 | [diff] [blame] | 532 | } |
| 533 | |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 534 | DEF_TEST(SkSLArrayConstructors, r) { |
| 535 | test(r, |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 536 | "float test1[] = float[](1, 2, 3, 4);" |
| 537 | "float2 test2[] = float2[](float2(1, 2), float2(3, 4));" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 538 | "float4x4 test3[] = float4x4[]();" |
| 539 | "void main() {" |
| 540 | "sk_FragColor.r = half(test1[0] + test2[0].x + test3[0][0][0]);" |
| 541 | "}", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 542 | *SkSL::ShaderCapsFactory::Default(), |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 543 | "#version 400\n" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 544 | "out vec4 sk_FragColor;\n" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 545 | "float test1[] = float[](1.0, 2.0, 3.0, 4.0);\n" |
| 546 | "vec2 test2[] = vec2[](vec2(1.0, 2.0), vec2(3.0, 4.0));\n" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 547 | "mat4 test3[] = mat4[]();\n" |
| 548 | "void main() {\n" |
| 549 | " sk_FragColor.x = (test1[0] + test2[0].x) + test3[0][0][0];\n" |
| 550 | "}\n"); |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 551 | } |
ethannicholas | ddb37d6 | 2016-10-20 09:54:00 -0700 | [diff] [blame] | 552 | |
Ethan Nicholas | 3908059 | 2019-07-22 14:54:43 -0400 | [diff] [blame] | 553 | DEF_TEST(SkSLConstArray, r) { |
| 554 | test(r, |
| 555 | "const half test[] = half[](1, 2, 3, 4);" |
| 556 | "void main() {" |
| 557 | "sk_FragColor = half4(test[0], test[1], test[2], test[3]);" |
| 558 | "}", |
| 559 | *SkSL::ShaderCapsFactory::Default(), |
| 560 | "#version 400\n" |
| 561 | "out vec4 sk_FragColor;\n" |
| 562 | "const float test[] = float[](1.0, 2.0, 3.0, 4.0);\n" |
| 563 | "void main() {\n" |
| 564 | " sk_FragColor = vec4(test[0], test[1], test[2], test[3]);\n" |
| 565 | "}\n"); |
| 566 | } |
| 567 | |
ethannicholas | ddb37d6 | 2016-10-20 09:54:00 -0700 | [diff] [blame] | 568 | DEF_TEST(SkSLDerivatives, r) { |
| 569 | test(r, |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 570 | "void main() { sk_FragColor.r = half(dFdx(1)); }", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 571 | *SkSL::ShaderCapsFactory::Default(), |
ethannicholas | ddb37d6 | 2016-10-20 09:54:00 -0700 | [diff] [blame] | 572 | "#version 400\n" |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 573 | "out vec4 sk_FragColor;\n" |
ethannicholas | ddb37d6 | 2016-10-20 09:54:00 -0700 | [diff] [blame] | 574 | "void main() {\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 575 | " sk_FragColor.x = dFdx(1.0);\n" |
ethannicholas | ddb37d6 | 2016-10-20 09:54:00 -0700 | [diff] [blame] | 576 | "}\n"); |
ethannicholas | ddb37d6 | 2016-10-20 09:54:00 -0700 | [diff] [blame] | 577 | test(r, |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 578 | "void main() { sk_FragColor.r = 1; }", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 579 | *SkSL::ShaderCapsFactory::ShaderDerivativeExtensionString(), |
ethannicholas | ddb37d6 | 2016-10-20 09:54:00 -0700 | [diff] [blame] | 580 | "#version 400\n" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 581 | "precision mediump float;\n" |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 582 | "precision mediump sampler2D;\n" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 583 | "out mediump vec4 sk_FragColor;\n" |
ethannicholas | ddb37d6 | 2016-10-20 09:54:00 -0700 | [diff] [blame] | 584 | "void main() {\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 585 | " sk_FragColor.x = 1.0;\n" |
ethannicholas | ddb37d6 | 2016-10-20 09:54:00 -0700 | [diff] [blame] | 586 | "}\n"); |
| 587 | test(r, |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 588 | "void main() { sk_FragColor.r = half(dFdx(1)); }", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 589 | *SkSL::ShaderCapsFactory::ShaderDerivativeExtensionString(), |
ethannicholas | ddb37d6 | 2016-10-20 09:54:00 -0700 | [diff] [blame] | 590 | "#version 400\n" |
| 591 | "#extension GL_OES_standard_derivatives : require\n" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 592 | "precision mediump float;\n" |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 593 | "precision mediump sampler2D;\n" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 594 | "out mediump vec4 sk_FragColor;\n" |
ethannicholas | ddb37d6 | 2016-10-20 09:54:00 -0700 | [diff] [blame] | 595 | "void main() {\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 596 | " sk_FragColor.x = dFdx(1.0);\n" |
ethannicholas | ddb37d6 | 2016-10-20 09:54:00 -0700 | [diff] [blame] | 597 | "}\n"); |
Chris Dalton | b8af5ad | 2019-02-25 14:54:21 -0700 | [diff] [blame] | 598 | |
| 599 | SkSL::Program::Settings settings; |
| 600 | settings.fFlipY = false; |
| 601 | auto caps = SkSL::ShaderCapsFactory::Default(); |
| 602 | settings.fCaps = caps.get(); |
| 603 | SkSL::Program::Inputs inputs; |
| 604 | test(r, |
| 605 | "void main() { sk_FragColor.r = half(dFdx(1)), sk_FragColor.g = half(dFdy(1)); }", |
| 606 | settings, |
| 607 | "#version 400\n" |
| 608 | "out vec4 sk_FragColor;\n" |
| 609 | "void main() {\n" |
| 610 | " (sk_FragColor.x = dFdx(1.0) , sk_FragColor.y = dFdy(1.0));\n" |
| 611 | "}\n", |
| 612 | &inputs); |
| 613 | settings.fFlipY = true; |
| 614 | test(r, |
| 615 | "void main() { sk_FragColor.r = half(dFdx(1)), sk_FragColor.g = half(dFdy(1)); }", |
| 616 | settings, |
| 617 | "#version 400\n" |
| 618 | "out vec4 sk_FragColor;\n" |
| 619 | "void main() {\n" |
| 620 | " (sk_FragColor.x = dFdx(1.0) , sk_FragColor.y = -dFdy(1.0));\n" |
| 621 | "}\n", |
| 622 | &inputs); |
ethannicholas | ddb37d6 | 2016-10-20 09:54:00 -0700 | [diff] [blame] | 623 | } |
ethannicholas | 08a9211 | 2016-11-09 13:26:45 -0800 | [diff] [blame] | 624 | |
Ethan Nicholas | c81d22f | 2017-04-26 11:25:18 -0400 | [diff] [blame] | 625 | |
| 626 | DEF_TEST(SkSLIntFolding, r) { |
ethannicholas | 08a9211 | 2016-11-09 13:26:45 -0800 | [diff] [blame] | 627 | test(r, |
| 628 | "void main() {" |
Ethan Nicholas | c81d22f | 2017-04-26 11:25:18 -0400 | [diff] [blame] | 629 | "sk_FragColor.r = 32 + 2;" |
| 630 | "sk_FragColor.r = 32 - 2;" |
| 631 | "sk_FragColor.r = 32 * 2;" |
| 632 | "sk_FragColor.r = 32 / 2;" |
| 633 | "sk_FragColor.r = 12 | 6;" |
| 634 | "sk_FragColor.r = 254 & 7;" |
| 635 | "sk_FragColor.r = 2 ^ 7;" |
| 636 | "sk_FragColor.r = 1 << 4;" |
| 637 | "sk_FragColor.r = 128 >> 2;" |
| 638 | "sk_FragColor.r = -1 == -1 ? 1 : -1;" |
| 639 | "sk_FragColor.r = -1 == -2 ? 2 : -2;" |
| 640 | "sk_FragColor.r = 0 != 1 ? 3 : -3;" |
| 641 | "sk_FragColor.r = 0 != 0 ? 4 : -4;" |
| 642 | "sk_FragColor.r = 6 > 5 ? 5 : -5;" |
| 643 | "sk_FragColor.r = 6 > 6 ? 6 : -6;" |
| 644 | "sk_FragColor.r = -1 < 0 ? 7 : -7;" |
| 645 | "sk_FragColor.r = 1 < 0 ? 8 : -8;" |
| 646 | "sk_FragColor.r = 6 >= 6 ? 9 : -9;" |
| 647 | "sk_FragColor.r = 6 >= 7 ? 10 : -10;" |
| 648 | "sk_FragColor.r = 6 <= 6 ? 11 : -11;" |
| 649 | "sk_FragColor.r = 6 <= 5 ? 12 : -12;" |
Ethan Nicholas | fe53e58 | 2017-04-27 16:24:51 -0400 | [diff] [blame] | 650 | "sk_FragColor.r = int(sqrt(1)) + 0;" |
| 651 | "sk_FragColor.r = 0 + int(sqrt(2));" |
| 652 | "sk_FragColor.r = int(sqrt(3)) - 0;" |
| 653 | "sk_FragColor.r = int(sqrt(4)) * 0;" |
| 654 | "sk_FragColor.r = int(sqrt(5)) * 1;" |
| 655 | "sk_FragColor.r = 1 * int(sqrt(6));" |
| 656 | "sk_FragColor.r = 0 * int(sqrt(7));" |
| 657 | "sk_FragColor.r = int(sqrt(8)) / 1;" |
| 658 | "sk_FragColor.r = 0 / int(sqrt(9));" |
| 659 | "int x = int(sqrt(2));" |
| 660 | "x += 1;" |
| 661 | "x += 0;" |
| 662 | "x -= 1;" |
| 663 | "x -= 0;" |
| 664 | "x *= 1;" |
| 665 | "x *= 2;" |
| 666 | "x /= 1;" |
| 667 | "x /= 2;" |
| 668 | "sk_FragColor.r = x;" |
ethannicholas | 08a9211 | 2016-11-09 13:26:45 -0800 | [diff] [blame] | 669 | "}", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 670 | *SkSL::ShaderCapsFactory::Default(), |
ethannicholas | 08a9211 | 2016-11-09 13:26:45 -0800 | [diff] [blame] | 671 | "#version 400\n" |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 672 | "out vec4 sk_FragColor;\n" |
ethannicholas | 08a9211 | 2016-11-09 13:26:45 -0800 | [diff] [blame] | 673 | "void main() {\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 674 | " sk_FragColor.x = 34.0;\n" |
| 675 | " sk_FragColor.x = 30.0;\n" |
| 676 | " sk_FragColor.x = 64.0;\n" |
| 677 | " sk_FragColor.x = 16.0;\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 678 | " sk_FragColor.x = 14.0;\n" |
| 679 | " sk_FragColor.x = 6.0;\n" |
| 680 | " sk_FragColor.x = 5.0;\n" |
| 681 | " sk_FragColor.x = 16.0;\n" |
| 682 | " sk_FragColor.x = 32.0;\n" |
| 683 | " sk_FragColor.x = 1.0;\n" |
Ethan Nicholas | c81d22f | 2017-04-26 11:25:18 -0400 | [diff] [blame] | 684 | " sk_FragColor.x = -2.0;\n" |
| 685 | " sk_FragColor.x = 3.0;\n" |
| 686 | " sk_FragColor.x = -4.0;\n" |
| 687 | " sk_FragColor.x = 5.0;\n" |
| 688 | " sk_FragColor.x = -6.0;\n" |
| 689 | " sk_FragColor.x = 7.0;\n" |
| 690 | " sk_FragColor.x = -8.0;\n" |
| 691 | " sk_FragColor.x = 9.0;\n" |
| 692 | " sk_FragColor.x = -10.0;\n" |
| 693 | " sk_FragColor.x = 11.0;\n" |
| 694 | " sk_FragColor.x = -12.0;\n" |
Ethan Nicholas | fe53e58 | 2017-04-27 16:24:51 -0400 | [diff] [blame] | 695 | " sk_FragColor.x = float(int(sqrt(1.0)));\n" |
| 696 | " sk_FragColor.x = float(int(sqrt(2.0)));\n" |
| 697 | " sk_FragColor.x = float(int(sqrt(3.0)));\n" |
| 698 | " sk_FragColor.x = 0.0;\n" |
| 699 | " sk_FragColor.x = float(int(sqrt(5.0)));\n" |
| 700 | " sk_FragColor.x = float(int(sqrt(6.0)));\n" |
| 701 | " sk_FragColor.x = 0.0;\n" |
| 702 | " sk_FragColor.x = float(int(sqrt(8.0)));\n" |
| 703 | " sk_FragColor.x = 0.0;\n" |
| 704 | " int x = int(sqrt(2.0));\n" |
| 705 | " x += 1;\n" |
| 706 | " x -= 1;\n" |
| 707 | " x *= 2;\n" |
| 708 | " x /= 2;\n" |
| 709 | " sk_FragColor.x = float(x);\n" |
Ethan Nicholas | c81d22f | 2017-04-26 11:25:18 -0400 | [diff] [blame] | 710 | "}\n"); |
| 711 | } |
| 712 | |
| 713 | DEF_TEST(SkSLFloatFolding, r) { |
| 714 | test(r, |
| 715 | "void main() {" |
| 716 | "sk_FragColor.r = 32.0 + 2.0;" |
| 717 | "sk_FragColor.r = 32.0 - 2.0;" |
| 718 | "sk_FragColor.r = 32.0 * 2.0;" |
| 719 | "sk_FragColor.r = 32.0 / 2.0;" |
| 720 | "sk_FragColor.r = (12 > 2.0) ? (10 * 2 / 5 + 18 - 3) : 0;" |
| 721 | "sk_FragColor.r = 0.0 == 0.0 ? 1 : -1;" |
| 722 | "sk_FragColor.r = 0.0 == 1.0 ? 2 : -2;" |
| 723 | "sk_FragColor.r = 0.0 != 1.0 ? 3 : -3;" |
| 724 | "sk_FragColor.r = 0.0 != 0.0 ? 4 : -4;" |
| 725 | "sk_FragColor.r = 6.0 > 5.0 ? 5 : -5;" |
| 726 | "sk_FragColor.r = 6.0 > 6.0 ? 6 : -6;" |
| 727 | "sk_FragColor.r = 6.0 >= 6.0 ? 7 : -7;" |
| 728 | "sk_FragColor.r = 6.0 >= 7.0 ? 8 : -8;" |
| 729 | "sk_FragColor.r = 5.0 < 6.0 ? 9 : -9;" |
| 730 | "sk_FragColor.r = 6.0 < 6.0 ? 10 : -10;" |
| 731 | "sk_FragColor.r = 6.0 <= 6.0 ? 11 : -11;" |
| 732 | "sk_FragColor.r = 6.0 <= 5.0 ? 12 : -12;" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 733 | "sk_FragColor.r = half(sqrt(1) + 0);" |
| 734 | "sk_FragColor.r = half(0 + sqrt(2));" |
| 735 | "sk_FragColor.r = half(sqrt(3) - 0);" |
| 736 | "sk_FragColor.r = half(sqrt(4) * 0);" |
| 737 | "sk_FragColor.r = half(sqrt(5) * 1);" |
| 738 | "sk_FragColor.r = half(1 * sqrt(6));" |
| 739 | "sk_FragColor.r = half(0 * sqrt(7));" |
| 740 | "sk_FragColor.r = half(sqrt(8) / 1);" |
| 741 | "sk_FragColor.r = half(0 / sqrt(9));" |
Ethan Nicholas | fe53e58 | 2017-04-27 16:24:51 -0400 | [diff] [blame] | 742 | "sk_FragColor.r += 1;" |
| 743 | "sk_FragColor.r += 0;" |
| 744 | "sk_FragColor.r -= 1;" |
| 745 | "sk_FragColor.r -= 0;" |
| 746 | "sk_FragColor.r *= 1;" |
| 747 | "sk_FragColor.r *= 2;" |
| 748 | "sk_FragColor.r /= 1;" |
| 749 | "sk_FragColor.r /= 2;" |
Ethan Nicholas | c81d22f | 2017-04-26 11:25:18 -0400 | [diff] [blame] | 750 | "}", |
| 751 | *SkSL::ShaderCapsFactory::Default(), |
| 752 | "#version 400\n" |
| 753 | "out vec4 sk_FragColor;\n" |
| 754 | "void main() {\n" |
| 755 | " sk_FragColor.x = 34.0;\n" |
| 756 | " sk_FragColor.x = 30.0;\n" |
| 757 | " sk_FragColor.x = 64.0;\n" |
| 758 | " sk_FragColor.x = 16.0;\n" |
| 759 | " sk_FragColor.x = 19.0;\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 760 | " sk_FragColor.x = 1.0;\n" |
Ethan Nicholas | c81d22f | 2017-04-26 11:25:18 -0400 | [diff] [blame] | 761 | " sk_FragColor.x = -2.0;\n" |
| 762 | " sk_FragColor.x = 3.0;\n" |
| 763 | " sk_FragColor.x = -4.0;\n" |
| 764 | " sk_FragColor.x = 5.0;\n" |
| 765 | " sk_FragColor.x = -6.0;\n" |
| 766 | " sk_FragColor.x = 7.0;\n" |
| 767 | " sk_FragColor.x = -8.0;\n" |
| 768 | " sk_FragColor.x = 9.0;\n" |
| 769 | " sk_FragColor.x = -10.0;\n" |
| 770 | " sk_FragColor.x = 11.0;\n" |
| 771 | " sk_FragColor.x = -12.0;\n" |
Ethan Nicholas | fe53e58 | 2017-04-27 16:24:51 -0400 | [diff] [blame] | 772 | " sk_FragColor.x = sqrt(1.0);\n" |
| 773 | " sk_FragColor.x = sqrt(2.0);\n" |
| 774 | " sk_FragColor.x = sqrt(3.0);\n" |
| 775 | " sk_FragColor.x = 0.0;\n" |
| 776 | " sk_FragColor.x = sqrt(5.0);\n" |
| 777 | " sk_FragColor.x = sqrt(6.0);\n" |
| 778 | " sk_FragColor.x = 0.0;\n" |
| 779 | " sk_FragColor.x = sqrt(8.0);\n" |
| 780 | " sk_FragColor.x = 0.0;\n" |
| 781 | " sk_FragColor.x += 1.0;\n" |
| 782 | " sk_FragColor.x -= 1.0;\n" |
| 783 | " sk_FragColor.x *= 2.0;\n" |
| 784 | " sk_FragColor.x /= 2.0;\n" |
Ethan Nicholas | c81d22f | 2017-04-26 11:25:18 -0400 | [diff] [blame] | 785 | "}\n"); |
| 786 | } |
| 787 | |
| 788 | DEF_TEST(SkSLBoolFolding, r) { |
| 789 | test(r, |
| 790 | "void main() {" |
| 791 | "sk_FragColor.r = 1 == 1 || 2 == 8 ? 1 : -1;" |
| 792 | "sk_FragColor.r = 1 > 1 || 2 == 8 ? 2 : -2;" |
| 793 | "sk_FragColor.r = 1 == 1 && 2 <= 8 ? 3 : -3;" |
| 794 | "sk_FragColor.r = 1 == 2 && 2 == 8 ? 4 : -4;" |
| 795 | "sk_FragColor.r = 1 == 1 ^^ 1 != 1 ? 5 : -5;" |
| 796 | "sk_FragColor.r = 1 == 1 ^^ 1 == 1 ? 6 : -6;" |
| 797 | "}", |
| 798 | *SkSL::ShaderCapsFactory::Default(), |
| 799 | "#version 400\n" |
| 800 | "out vec4 sk_FragColor;\n" |
| 801 | "void main() {\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 802 | " sk_FragColor.x = 1.0;\n" |
Ethan Nicholas | c81d22f | 2017-04-26 11:25:18 -0400 | [diff] [blame] | 803 | " sk_FragColor.x = -2.0;\n" |
| 804 | " sk_FragColor.x = 3.0;\n" |
| 805 | " sk_FragColor.x = -4.0;\n" |
| 806 | " sk_FragColor.x = 5.0;\n" |
| 807 | " sk_FragColor.x = -6.0;\n" |
| 808 | "}\n"); |
| 809 | } |
| 810 | |
Michael Ludwig | 7b429ae | 2018-09-06 17:01:38 -0400 | [diff] [blame] | 811 | DEF_TEST(SkSLShortCircuitBoolFolding, r) { |
| 812 | test(r, |
| 813 | "void main() {" |
| 814 | "bool expr1 = sk_FragCoord.x > 0;" |
| 815 | "bool expr2 = sk_FragCoord.y > 0;" |
| 816 | " if (true && expr1) {" // -> if (expr1) |
| 817 | " sk_FragColor.r = 1;" |
| 818 | " } else if (false && expr1) {" // -> if (false) -> block removed |
| 819 | " sk_FragColor.r = -2;" |
| 820 | " } else if (false || expr2) {" // -> if (expr2) |
| 821 | " sk_FragColor.r = 3;" |
| 822 | " } else if (true || expr2) {" // -> if (true) -> replaces unreachable else |
| 823 | " sk_FragColor.r = 4;" |
| 824 | " } else {" // removed |
| 825 | " sk_FragColor.r = -5;" |
| 826 | " }" |
| 827 | // Test short-circuiting of right hand side boolean literals |
| 828 | " if (expr1 && true) {" // -> if (expr1) |
| 829 | " sk_FragColor.r = 1;" |
| 830 | " } else if (expr1 && false) {" // -> if (false) -> block removed |
| 831 | " sk_FragColor.r = -2;" |
| 832 | " } else if (expr2 || false) {" // -> if (expr2) |
| 833 | " sk_FragColor.r = 3;" |
| 834 | " } else if (expr2 || true) {" // -> if (true) -> replaces unreachable else |
| 835 | " sk_FragColor.r = 4;" |
| 836 | " } else {" // removed |
| 837 | " sk_FragColor.r = -5;" |
| 838 | " }" |
| 839 | "}", |
| 840 | *SkSL::ShaderCapsFactory::Default(), |
| 841 | "#version 400\n" |
| 842 | "out vec4 sk_FragColor;\n" |
| 843 | "void main() {\n" |
| 844 | " bool expr1 = gl_FragCoord.x > 0.0;\n" |
| 845 | " bool expr2 = gl_FragCoord.y > 0.0;\n" |
| 846 | " if (expr1) {\n" |
| 847 | " sk_FragColor.x = 1.0;\n" |
| 848 | " } else if (expr2) {\n" |
| 849 | " sk_FragColor.x = 3.0;\n" |
| 850 | " } else {\n" |
| 851 | " sk_FragColor.x = 4.0;\n" |
| 852 | " }\n" |
| 853 | " if (expr1) {\n" |
| 854 | " sk_FragColor.x = 1.0;\n" |
| 855 | " } else if (expr2) {\n" |
| 856 | " sk_FragColor.x = 3.0;\n" |
| 857 | " } else {\n" |
| 858 | " sk_FragColor.x = 4.0;\n" |
| 859 | " }\n" |
| 860 | "}\n"); |
| 861 | } |
| 862 | |
Ethan Nicholas | c81d22f | 2017-04-26 11:25:18 -0400 | [diff] [blame] | 863 | DEF_TEST(SkSLVecFolding, r) { |
| 864 | test(r, |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 865 | "void main() {\n" |
| 866 | "sk_FragColor.r = half4(0.5, 1, 1, 1).x;\n" |
| 867 | "sk_FragColor = half4(half2(1), half2(2, 3)) + half4(5, 6, 7, 8);\n" |
| 868 | "sk_FragColor = half4(8, half3(10)) - half4(1);\n" |
| 869 | "sk_FragColor = half4(2) * half4(1, 2, 3, 4);\n" |
| 870 | "sk_FragColor = half4(12) / half4(1, 2, 3, 4);\n" |
| 871 | "sk_FragColor.r = (half4(12) / half4(1, 2, 3, 4)).y;\n" |
| 872 | "sk_FragColor.x = half4(1) == half4(1) ? 1.0 : -1.0;\n" |
| 873 | "sk_FragColor.x = half4(1) == half4(2) ? 2.0 : -2.0;\n" |
| 874 | "sk_FragColor.x = half2(1) == half2(1, 1) ? 3.0 : -3.0;\n" |
| 875 | "sk_FragColor.x = half2(1, 1) == half2(1, 1) ? 4.0 : -4.0;\n" |
| 876 | "sk_FragColor.x = half2(1) == half2(1, 0) ? 5.0 : -5.0;\n" |
| 877 | "sk_FragColor.x = half4(1) == half4(half2(1), half2(1)) ? 6.0 : -6.0;\n" |
| 878 | "sk_FragColor.x = half4(half3(1), 1) == half4(half2(1), half2(1)) ? 7.0 : -7.0;\n" |
| 879 | "sk_FragColor.x = half4(half3(1), 1) == half4(half2(1), 1, 0) ? 8.0 : -8.0;\n" |
| 880 | "sk_FragColor.x = half2(1) != half2(1, 0) ? 9.0 : -9.0;\n" |
| 881 | "sk_FragColor.x = half4(1) != half4(half2(1), half2(1)) ? 10.0 : -10.0;\n" |
| 882 | "sk_FragColor = half4(half(sqrt(1))) * half4(1);\n" |
| 883 | "sk_FragColor = half4(1) * half4(half(sqrt(2)));\n" |
| 884 | "sk_FragColor = half4(0) * half4(half(sqrt(3)));\n" |
| 885 | "sk_FragColor = half4(half(sqrt(4))) * half4(0);\n" |
| 886 | "sk_FragColor = half4(0) / half4(half(sqrt(5)));\n" |
| 887 | "sk_FragColor = half4(0) + half4(half(sqrt(6)));\n" |
| 888 | "sk_FragColor = half4(half(sqrt(7))) + half4(0);\n" |
| 889 | "sk_FragColor = half4(half(sqrt(8))) - half4(0);\n" |
| 890 | "sk_FragColor = half4(0) + half(half(sqrt(9)));\n" |
| 891 | "sk_FragColor = half4(0) * half(sqrt(10));\n" |
| 892 | "sk_FragColor = half4(0) / half(sqrt(11));\n" |
| 893 | "sk_FragColor = half4(1) * half(sqrt(12));\n" |
| 894 | "sk_FragColor = 0 + half4(half(sqrt(13)));\n" |
| 895 | "sk_FragColor = 0 * half4(half(sqrt(14)));\n" |
| 896 | "sk_FragColor = 0 / half4(half(sqrt(15)));\n" |
| 897 | "sk_FragColor = 1 * half4(half(sqrt(16)));\n" |
| 898 | "sk_FragColor = half4(half(sqrt(17))) + 0;\n" |
| 899 | "sk_FragColor = half4(half(sqrt(18))) * 0;\n" |
| 900 | "sk_FragColor = half4(half(sqrt(19))) * 1;\n" |
| 901 | "sk_FragColor = half4(half(sqrt(19.5))) - 0;\n" |
| 902 | "sk_FragColor = half(half(sqrt(20))) * half4(1);\n" |
| 903 | "sk_FragColor = half(half(sqrt(21))) + half4(0);\n" |
| 904 | "sk_FragColor = half(half(sqrt(22))) - half4(0);\n" |
| 905 | "sk_FragColor = half(half(sqrt(23))) / half4(1);\n" |
| 906 | "sk_FragColor = half4(half(sqrt(24))) / 1;\n" |
| 907 | "sk_FragColor += half4(1);\n" |
| 908 | "sk_FragColor += half4(0);\n" |
| 909 | "sk_FragColor -= half4(1);\n" |
| 910 | "sk_FragColor -= half4(0);\n" |
| 911 | "sk_FragColor *= half4(1);\n" |
| 912 | "sk_FragColor *= half4(2);\n" |
| 913 | "sk_FragColor /= half4(1);\n" |
| 914 | "sk_FragColor /= half4(2);\n" |
Ethan Nicholas | c81d22f | 2017-04-26 11:25:18 -0400 | [diff] [blame] | 915 | "}", |
| 916 | *SkSL::ShaderCapsFactory::Default(), |
| 917 | "#version 400\n" |
| 918 | "out vec4 sk_FragColor;\n" |
| 919 | "void main() {\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 920 | " sk_FragColor.x = 0.5;\n" |
| 921 | " sk_FragColor = vec4(6.0, 7.0, 9.0, 11.0);\n" |
| 922 | " sk_FragColor = vec4(7.0, 9.0, 9.0, 9.0);\n" |
| 923 | " sk_FragColor = vec4(2.0, 4.0, 6.0, 8.0);\n" |
| 924 | " sk_FragColor = vec4(12.0, 6.0, 4.0, 3.0);\n" |
| 925 | " sk_FragColor.x = 6.0;\n" |
Ethan Nicholas | 3deaeb2 | 2017-04-25 14:42:11 -0400 | [diff] [blame] | 926 | " sk_FragColor.x = 1.0;\n" |
Ethan Nicholas | c81d22f | 2017-04-26 11:25:18 -0400 | [diff] [blame] | 927 | " sk_FragColor.x = -2.0;\n" |
| 928 | " sk_FragColor.x = 3.0;\n" |
| 929 | " sk_FragColor.x = 4.0;\n" |
| 930 | " sk_FragColor.x = -5.0;\n" |
| 931 | " sk_FragColor.x = 6.0;\n" |
| 932 | " sk_FragColor.x = 7.0;\n" |
| 933 | " sk_FragColor.x = -8.0;\n" |
| 934 | " sk_FragColor.x = 9.0;\n" |
| 935 | " sk_FragColor.x = -10.0;\n" |
Ethan Nicholas | fe53e58 | 2017-04-27 16:24:51 -0400 | [diff] [blame] | 936 | " sk_FragColor = vec4(sqrt(1.0));\n" |
| 937 | " sk_FragColor = vec4(sqrt(2.0));\n" |
| 938 | " sk_FragColor = vec4(0.0);\n" |
| 939 | " sk_FragColor = vec4(0.0);\n" |
| 940 | " sk_FragColor = vec4(0.0);\n" |
| 941 | " sk_FragColor = vec4(sqrt(6.0));\n" |
| 942 | " sk_FragColor = vec4(sqrt(7.0));\n" |
| 943 | " sk_FragColor = vec4(sqrt(8.0));\n" |
| 944 | " sk_FragColor = vec4(sqrt(9.0));\n" |
| 945 | " sk_FragColor = vec4(0.0);\n" |
| 946 | " sk_FragColor = vec4(0.0);\n" |
| 947 | " sk_FragColor = vec4(sqrt(12.0));\n" |
| 948 | " sk_FragColor = vec4(sqrt(13.0));\n" |
| 949 | " sk_FragColor = vec4(0.0);\n" |
| 950 | " sk_FragColor = vec4(0.0);\n" |
| 951 | " sk_FragColor = vec4(sqrt(16.0));\n" |
| 952 | " sk_FragColor = vec4(sqrt(17.0));\n" |
| 953 | " sk_FragColor = vec4(0.0);\n" |
| 954 | " sk_FragColor = vec4(sqrt(19.0));\n" |
| 955 | " sk_FragColor = vec4(sqrt(19.5));\n" |
| 956 | " sk_FragColor = vec4(sqrt(20.0));\n" |
| 957 | " sk_FragColor = vec4(sqrt(21.0));\n" |
| 958 | " sk_FragColor = vec4(sqrt(22.0));\n" |
| 959 | " sk_FragColor = vec4(sqrt(23.0));\n" |
| 960 | " sk_FragColor = vec4(sqrt(24.0));\n" |
| 961 | " sk_FragColor += vec4(1.0);\n" |
| 962 | " sk_FragColor -= vec4(1.0);\n" |
| 963 | " sk_FragColor *= vec4(2.0);\n" |
| 964 | " sk_FragColor /= vec4(2.0);\n" |
Ethan Nicholas | c81d22f | 2017-04-26 11:25:18 -0400 | [diff] [blame] | 965 | "}\n"); |
| 966 | } |
| 967 | |
| 968 | DEF_TEST(SkSLMatFolding, r) { |
| 969 | test(r, |
| 970 | "void main() {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 971 | "sk_FragColor.x = float2x2(float2(1.0, 0.0), float2(0.0, 1.0)) == " |
| 972 | "float2x2(float2(1.0, 0.0), float2(0.0, 1.0)) ? 1 : -1;" |
| 973 | "sk_FragColor.x = float2x2(float2(1.0, 0.0), float2(1.0, 1.0)) == " |
| 974 | "float2x2(float2(1.0, 0.0), float2(0.0, 1.0)) ? 2 : -2;" |
| 975 | "sk_FragColor.x = float2x2(1) == float2x2(1) ? 3 : -3;" |
| 976 | "sk_FragColor.x = float2x2(1) == float2x2(0) ? 4 : -4;" |
| 977 | "sk_FragColor.x = float2x2(1) == float2x2(float2(1.0, 0.0), float2(0.0, 1.0)) ? 5 : -5;" |
| 978 | "sk_FragColor.x = float2x2(2) == float2x2(float2(1.0, 0.0), float2(0.0, 1.0)) ? 6 : -6;" |
| 979 | "sk_FragColor.x = float3x2(2) == float3x2(float2(2.0, 0.0), float2(0.0, 2.0), float2(0.0))" |
Ethan Nicholas | 5af9ea3 | 2017-07-28 15:19:46 -0400 | [diff] [blame] | 980 | "? 7 : -7;" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 981 | "sk_FragColor.x = float2x2(1) != float2x2(1) ? 8 : -8;" |
| 982 | "sk_FragColor.x = float2x2(1) != float2x2(0) ? 9 : -9;" |
| 983 | "sk_FragColor.x = float3x3(float3(1.0, 0.0, 0.0), float3(0.0, 1.0, 0.0), " |
| 984 | "float3(0.0, 0.0, 0.0)) == float3x3(float2x2(1.0)) ? 10 : -10;" |
| 985 | "sk_FragColor.x = float2x2(float3x3(1.0)) == float2x2(1.0) ? 11 : -11;" |
| 986 | "sk_FragColor.x = float2x2(float4(1.0, 0.0, 0.0, 1.0)) == float2x2(1.0) ? 12 : -12;" |
| 987 | "sk_FragColor.x = float2x2(1.0, 0.0, float2(0.0, 1.0)) == float2x2(1.0) ? 13 : -13;" |
| 988 | "sk_FragColor.x = float2x2(float2(1.0, 0.0), 0.0, 1.0) == float2x2(1.0) ? 14 : -14;" |
Ethan Nicholas | c81d22f | 2017-04-26 11:25:18 -0400 | [diff] [blame] | 989 | "}", |
| 990 | *SkSL::ShaderCapsFactory::Default(), |
| 991 | "#version 400\n" |
| 992 | "out vec4 sk_FragColor;\n" |
| 993 | "void main() {\n" |
Ethan Nicholas | 3deaeb2 | 2017-04-25 14:42:11 -0400 | [diff] [blame] | 994 | " sk_FragColor.x = 1.0;\n" |
Ethan Nicholas | c81d22f | 2017-04-26 11:25:18 -0400 | [diff] [blame] | 995 | " sk_FragColor.x = -2.0;\n" |
| 996 | " sk_FragColor.x = 3.0;\n" |
| 997 | " sk_FragColor.x = -4.0;\n" |
| 998 | " sk_FragColor.x = 5.0;\n" |
| 999 | " sk_FragColor.x = -6.0;\n" |
| 1000 | " sk_FragColor.x = 7.0;\n" |
| 1001 | " sk_FragColor.x = -8.0;\n" |
| 1002 | " sk_FragColor.x = 9.0;\n" |
| 1003 | " sk_FragColor.x = 10.0;\n" |
| 1004 | " sk_FragColor.x = 11.0;\n" |
| 1005 | " sk_FragColor.x = 12.0;\n" |
| 1006 | " sk_FragColor.x = 13.0;\n" |
| 1007 | " sk_FragColor.x = 14.0;\n" |
ethannicholas | 08a9211 | 2016-11-09 13:26:45 -0800 | [diff] [blame] | 1008 | "}\n"); |
| 1009 | } |
| 1010 | |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1011 | DEF_TEST(SkSLConstantIf, r) { |
ethannicholas | 08a9211 | 2016-11-09 13:26:45 -0800 | [diff] [blame] | 1012 | test(r, |
| 1013 | "void main() {" |
| 1014 | "int x;" |
| 1015 | "if (true) x = 1;" |
| 1016 | "if (2 > 1) x = 2; else x = 3;" |
| 1017 | "if (1 > 2) x = 4; else x = 5;" |
| 1018 | "if (false) x = 6;" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 1019 | "sk_FragColor.r = x;" |
ethannicholas | 08a9211 | 2016-11-09 13:26:45 -0800 | [diff] [blame] | 1020 | "}", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 1021 | *SkSL::ShaderCapsFactory::Default(), |
ethannicholas | 08a9211 | 2016-11-09 13:26:45 -0800 | [diff] [blame] | 1022 | "#version 400\n" |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 1023 | "out vec4 sk_FragColor;\n" |
ethannicholas | 08a9211 | 2016-11-09 13:26:45 -0800 | [diff] [blame] | 1024 | "void main() {\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 1025 | " sk_FragColor.x = 5.0;\n" |
ethannicholas | 08a9211 | 2016-11-09 13:26:45 -0800 | [diff] [blame] | 1026 | "}\n"); |
| 1027 | } |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 1028 | |
Ethan Nicholas | 3605ace | 2016-11-21 15:59:48 -0500 | [diff] [blame] | 1029 | DEF_TEST(SkSLCaps, r) { |
| 1030 | test(r, |
| 1031 | "void main() {" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 1032 | "int x = 0;" |
| 1033 | "int y = 0;" |
| 1034 | "int z = 0;" |
Ethan Nicholas | 3605ace | 2016-11-21 15:59:48 -0500 | [diff] [blame] | 1035 | "if (sk_Caps.externalTextureSupport) x = 1;" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 1036 | "if (sk_Caps.fbFetchSupport) y = 1;" |
Brian Osman | 6386efa | 2019-06-05 10:59:00 -0400 | [diff] [blame] | 1037 | "if (sk_Caps.canUseAnyFunctionInShader) z = 1;" |
| 1038 | "sk_FragColor = half4(x, y, z, 0.0);" |
Ethan Nicholas | 3605ace | 2016-11-21 15:59:48 -0500 | [diff] [blame] | 1039 | "}", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 1040 | *SkSL::ShaderCapsFactory::VariousCaps(), |
Ethan Nicholas | 3605ace | 2016-11-21 15:59:48 -0500 | [diff] [blame] | 1041 | "#version 400\n" |
| 1042 | "out vec4 sk_FragColor;\n" |
| 1043 | "void main() {\n" |
Brian Osman | 6386efa | 2019-06-05 10:59:00 -0400 | [diff] [blame] | 1044 | " sk_FragColor = vec4(1.0, 0.0, 0.0, 0.0);\n" |
Ethan Nicholas | 3605ace | 2016-11-21 15:59:48 -0500 | [diff] [blame] | 1045 | "}\n"); |
| 1046 | } |
| 1047 | |
Ethan Nicholas | 2b3dab6 | 2016-11-28 12:03:26 -0500 | [diff] [blame] | 1048 | DEF_TEST(SkSLTexture, r) { |
| 1049 | test(r, |
| 1050 | "uniform sampler1D one;" |
| 1051 | "uniform sampler2D two;" |
| 1052 | "void main() {" |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 1053 | "float4 a = sample(one, 0);" |
| 1054 | "float4 b = sample(two, float2(0));" |
| 1055 | "float4 c = sample(one, float2(0));" |
| 1056 | "float4 d = sample(two, float3(0));" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1057 | "sk_FragColor = half4(half(a.x), half(b.x), half(c.x), half(d.x));" |
Ethan Nicholas | 2b3dab6 | 2016-11-28 12:03:26 -0500 | [diff] [blame] | 1058 | "}", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 1059 | *SkSL::ShaderCapsFactory::Default(), |
Ethan Nicholas | 2b3dab6 | 2016-11-28 12:03:26 -0500 | [diff] [blame] | 1060 | "#version 400\n" |
| 1061 | "out vec4 sk_FragColor;\n" |
| 1062 | "uniform sampler1D one;\n" |
| 1063 | "uniform sampler2D two;\n" |
| 1064 | "void main() {\n" |
| 1065 | " vec4 a = texture(one, 0.0);\n" |
| 1066 | " vec4 b = texture(two, vec2(0.0));\n" |
| 1067 | " vec4 c = textureProj(one, vec2(0.0));\n" |
| 1068 | " vec4 d = textureProj(two, vec3(0.0));\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 1069 | " sk_FragColor = vec4(a.x, b.x, c.x, d.x);\n" |
Ethan Nicholas | 2b3dab6 | 2016-11-28 12:03:26 -0500 | [diff] [blame] | 1070 | "}\n"); |
| 1071 | test(r, |
| 1072 | "uniform sampler1D one;" |
| 1073 | "uniform sampler2D two;" |
| 1074 | "void main() {" |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 1075 | "float4 a = sample(one, 0);" |
| 1076 | "float4 b = sample(two, float2(0));" |
| 1077 | "float4 c = sample(one, float2(0));" |
| 1078 | "float4 d = sample(two, float3(0));" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1079 | "sk_FragColor = half4(half(a.x), half(b.x), half(c.x), half(d.x));" |
Ethan Nicholas | 2b3dab6 | 2016-11-28 12:03:26 -0500 | [diff] [blame] | 1080 | "}", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 1081 | *SkSL::ShaderCapsFactory::Version110(), |
Ethan Nicholas | 2b3dab6 | 2016-11-28 12:03:26 -0500 | [diff] [blame] | 1082 | "#version 110\n" |
| 1083 | "uniform sampler1D one;\n" |
| 1084 | "uniform sampler2D two;\n" |
| 1085 | "void main() {\n" |
| 1086 | " vec4 a = texture1D(one, 0.0);\n" |
| 1087 | " vec4 b = texture2D(two, vec2(0.0));\n" |
| 1088 | " vec4 c = texture1DProj(one, vec2(0.0));\n" |
| 1089 | " vec4 d = texture2DProj(two, vec3(0.0));\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 1090 | " gl_FragColor = vec4(a.x, b.x, c.x, d.x);\n" |
Ethan Nicholas | 2b3dab6 | 2016-11-28 12:03:26 -0500 | [diff] [blame] | 1091 | "}\n"); |
| 1092 | } |
| 1093 | |
Brian Osman | 8a83ca4 | 2018-02-12 14:32:17 -0500 | [diff] [blame] | 1094 | DEF_TEST(SkSLSharpen, r) { |
| 1095 | SkSL::Program::Settings settings; |
| 1096 | settings.fSharpenTextures = true; |
| 1097 | sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default(); |
| 1098 | settings.fCaps = caps.get(); |
| 1099 | SkSL::Program::Inputs inputs; |
| 1100 | test(r, |
| 1101 | "uniform sampler1D one;" |
| 1102 | "uniform sampler2D two;" |
| 1103 | "void main() {" |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 1104 | "float4 a = sample(one, 0);" |
| 1105 | "float4 b = sample(two, float2(0));" |
| 1106 | "float4 c = sample(one, float2(0));" |
| 1107 | "float4 d = sample(two, float3(0));" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1108 | "sk_FragColor = half4(half(a.x), half(b.x), half(c.x), half(d.x));" |
Brian Osman | 8a83ca4 | 2018-02-12 14:32:17 -0500 | [diff] [blame] | 1109 | "}", |
| 1110 | settings, |
| 1111 | "#version 400\n" |
| 1112 | "out vec4 sk_FragColor;\n" |
| 1113 | "uniform sampler1D one;\n" |
| 1114 | "uniform sampler2D two;\n" |
| 1115 | "void main() {\n" |
| 1116 | " vec4 a = texture(one, 0.0, -0.5);\n" |
| 1117 | " vec4 b = texture(two, vec2(0.0), -0.5);\n" |
| 1118 | " vec4 c = textureProj(one, vec2(0.0), -0.5);\n" |
| 1119 | " vec4 d = textureProj(two, vec3(0.0), -0.5);\n" |
| 1120 | " sk_FragColor = vec4(a.x, b.x, c.x, d.x);\n" |
| 1121 | "}\n", |
| 1122 | &inputs); |
| 1123 | |
| 1124 | caps = SkSL::ShaderCapsFactory::Version110(); |
| 1125 | settings.fCaps = caps.get(); |
| 1126 | test(r, |
| 1127 | "uniform sampler1D one;" |
| 1128 | "uniform sampler2D two;" |
| 1129 | "void main() {" |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 1130 | "float4 a = sample(one, 0);" |
| 1131 | "float4 b = sample(two, float2(0));" |
| 1132 | "float4 c = sample(one, float2(0));" |
| 1133 | "float4 d = sample(two, float3(0));" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1134 | "sk_FragColor = half4(half(a.x), half(b.x), half(c.x), half(d.x));" |
Brian Osman | 8a83ca4 | 2018-02-12 14:32:17 -0500 | [diff] [blame] | 1135 | "}", |
| 1136 | settings, |
| 1137 | "#version 110\n" |
| 1138 | "uniform sampler1D one;\n" |
| 1139 | "uniform sampler2D two;\n" |
| 1140 | "void main() {\n" |
| 1141 | " vec4 a = texture1D(one, 0.0, -0.5);\n" |
| 1142 | " vec4 b = texture2D(two, vec2(0.0), -0.5);\n" |
| 1143 | " vec4 c = texture1DProj(one, vec2(0.0), -0.5);\n" |
| 1144 | " vec4 d = texture2DProj(two, vec3(0.0), -0.5);\n" |
| 1145 | " gl_FragColor = vec4(a.x, b.x, c.x, d.x);\n" |
| 1146 | "}\n", |
| 1147 | &inputs); |
| 1148 | } |
| 1149 | |
Ethan Nicholas | 1967177 | 2016-11-28 16:30:17 -0500 | [diff] [blame] | 1150 | DEF_TEST(SkSLOffset, r) { |
| 1151 | test(r, |
| 1152 | "struct Test {" |
| 1153 | "layout(offset = 0) int x;" |
| 1154 | "layout(offset = 4) int y;" |
| 1155 | "int z;" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 1156 | "} test;" |
| 1157 | "void main() {" |
| 1158 | "Test t;" |
| 1159 | "t.x = 0;" |
| 1160 | "sk_FragColor.r = half(t.x);" |
| 1161 | "}", |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 1162 | *SkSL::ShaderCapsFactory::Default(), |
Ethan Nicholas | 1967177 | 2016-11-28 16:30:17 -0500 | [diff] [blame] | 1163 | "#version 400\n" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 1164 | "out vec4 sk_FragColor;\n" |
| 1165 | "void main() {\n" |
| 1166 | " struct Test {\n" |
| 1167 | " layout (offset = 0) int x;\n" |
| 1168 | " layout (offset = 4) int y;\n" |
| 1169 | " int z;\n" |
| 1170 | " } t;\n" |
| 1171 | " t.x = 0;\n" |
| 1172 | " sk_FragColor.x = float(t.x);\n" |
| 1173 | "}\n"); |
Ethan Nicholas | 1967177 | 2016-11-28 16:30:17 -0500 | [diff] [blame] | 1174 | } |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 1175 | |
| 1176 | DEF_TEST(SkSLFragCoord, r) { |
| 1177 | SkSL::Program::Settings settings; |
| 1178 | settings.fFlipY = true; |
| 1179 | sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::FragCoordsOld(); |
| 1180 | settings.fCaps = caps.get(); |
| 1181 | SkSL::Program::Inputs inputs; |
| 1182 | test(r, |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1183 | "void main() { sk_FragColor.xy = half2(sk_FragCoord.xy); }", |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 1184 | settings, |
| 1185 | "#version 110\n" |
| 1186 | "#extension GL_ARB_fragment_coord_conventions : require\n" |
| 1187 | "layout(origin_upper_left) in vec4 gl_FragCoord;\n" |
| 1188 | "void main() {\n" |
| 1189 | " gl_FragColor.xy = gl_FragCoord.xy;\n" |
| 1190 | "}\n", |
| 1191 | &inputs); |
Greg Daniel | e6ab998 | 2018-08-22 13:56:32 +0000 | [diff] [blame] | 1192 | REPORTER_ASSERT(r, !inputs.fRTHeight); |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 1193 | |
| 1194 | caps = SkSL::ShaderCapsFactory::FragCoordsNew(); |
| 1195 | settings.fCaps = caps.get(); |
| 1196 | test(r, |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1197 | "void main() { sk_FragColor.xy = half2(sk_FragCoord.xy); }", |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 1198 | settings, |
| 1199 | "#version 400\n" |
| 1200 | "layout(origin_upper_left) in vec4 gl_FragCoord;\n" |
| 1201 | "out vec4 sk_FragColor;\n" |
| 1202 | "void main() {\n" |
| 1203 | " sk_FragColor.xy = gl_FragCoord.xy;\n" |
| 1204 | "}\n", |
| 1205 | &inputs); |
Greg Daniel | e6ab998 | 2018-08-22 13:56:32 +0000 | [diff] [blame] | 1206 | REPORTER_ASSERT(r, !inputs.fRTHeight); |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 1207 | |
| 1208 | caps = SkSL::ShaderCapsFactory::Default(); |
| 1209 | settings.fCaps = caps.get(); |
| 1210 | test(r, |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1211 | "void main() { sk_FragColor.xy = half2(sk_FragCoord.xy); }", |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 1212 | settings, |
| 1213 | "#version 400\n" |
Greg Daniel | e6ab998 | 2018-08-22 13:56:32 +0000 | [diff] [blame] | 1214 | "uniform float u_skRTHeight;\n" |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 1215 | "out vec4 sk_FragColor;\n" |
| 1216 | "void main() {\n" |
Michael Ludwig | f0b6044 | 2018-12-10 14:43:38 +0000 | [diff] [blame] | 1217 | " vec4 sk_FragCoord = vec4(gl_FragCoord.x, u_skRTHeight - gl_FragCoord.y, " |
| 1218 | "gl_FragCoord.z, gl_FragCoord.w);\n" |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 1219 | " sk_FragColor.xy = sk_FragCoord.xy;\n" |
| 1220 | "}\n", |
| 1221 | &inputs); |
Greg Daniel | e6ab998 | 2018-08-22 13:56:32 +0000 | [diff] [blame] | 1222 | REPORTER_ASSERT(r, inputs.fRTHeight); |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 1223 | |
| 1224 | settings.fFlipY = false; |
| 1225 | test(r, |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1226 | "void main() { sk_FragColor.xy = half2(sk_FragCoord.xy); }", |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 1227 | settings, |
| 1228 | "#version 400\n" |
| 1229 | "out vec4 sk_FragColor;\n" |
| 1230 | "void main() {\n" |
| 1231 | " sk_FragColor.xy = gl_FragCoord.xy;\n" |
| 1232 | "}\n", |
| 1233 | &inputs); |
Greg Daniel | e6ab998 | 2018-08-22 13:56:32 +0000 | [diff] [blame] | 1234 | REPORTER_ASSERT(r, !inputs.fRTHeight); |
Brian Osman | cd3261a | 2018-01-16 13:52:29 +0000 | [diff] [blame] | 1235 | |
| 1236 | test(r, |
| 1237 | "in float4 pos; void main() { sk_Position = pos; }", |
| 1238 | *SkSL::ShaderCapsFactory::CannotUseFragCoord(), |
| 1239 | "#version 400\n" |
| 1240 | "out vec4 sk_FragCoord_Workaround;\n" |
| 1241 | "in vec4 pos;\n" |
| 1242 | "void main() {\n" |
| 1243 | " sk_FragCoord_Workaround = (gl_Position = pos);\n" |
| 1244 | "}\n", |
| 1245 | SkSL::Program::kVertex_Kind); |
| 1246 | |
| 1247 | test(r, |
Robert Phillips | fe8da17 | 2018-01-24 14:52:02 +0000 | [diff] [blame] | 1248 | "in uniform float4 sk_RTAdjust; in float4 pos; void main() { sk_Position = pos; }", |
| 1249 | *SkSL::ShaderCapsFactory::CannotUseFragCoord(), |
| 1250 | "#version 400\n" |
| 1251 | "out vec4 sk_FragCoord_Workaround;\n" |
| 1252 | "in uniform vec4 sk_RTAdjust;\n" |
| 1253 | "in vec4 pos;\n" |
| 1254 | "void main() {\n" |
| 1255 | " sk_FragCoord_Workaround = (gl_Position = pos);\n" |
Ethan Nicholas | b809efb | 2018-04-12 14:39:21 -0400 | [diff] [blame] | 1256 | " gl_Position = vec4(gl_Position.xy * sk_RTAdjust.xz + gl_Position.ww * sk_RTAdjust.yw," |
| 1257 | " 0.0, gl_Position.w);\n" |
Robert Phillips | fe8da17 | 2018-01-24 14:52:02 +0000 | [diff] [blame] | 1258 | "}\n", |
| 1259 | SkSL::Program::kVertex_Kind); |
| 1260 | |
| 1261 | test(r, |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1262 | "void main() { sk_FragColor.xy = half2(sk_FragCoord.xy); }", |
Brian Osman | cd3261a | 2018-01-16 13:52:29 +0000 | [diff] [blame] | 1263 | *SkSL::ShaderCapsFactory::CannotUseFragCoord(), |
| 1264 | "#version 400\n" |
| 1265 | "in vec4 sk_FragCoord_Workaround;\n" |
| 1266 | "out vec4 sk_FragColor;\n" |
| 1267 | "void main() {\n" |
Brian Salomon | dba65f9 | 2018-01-22 08:43:38 -0500 | [diff] [blame] | 1268 | " float sk_FragCoord_InvW = 1. / sk_FragCoord_Workaround.w;\n" |
| 1269 | " vec4 sk_FragCoord_Resolved = vec4(sk_FragCoord_Workaround.xyz * " |
| 1270 | "sk_FragCoord_InvW, sk_FragCoord_InvW);\n" |
| 1271 | " sk_FragCoord_Resolved.xy = floor(sk_FragCoord_Resolved.xy) + vec2(.5);\n" |
| 1272 | " sk_FragColor.xy = sk_FragCoord_Resolved.xy;\n" |
Brian Osman | cd3261a | 2018-01-16 13:52:29 +0000 | [diff] [blame] | 1273 | "}\n"); |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 1274 | } |
| 1275 | |
Ethan Nicholas | cd700e9 | 2018-08-24 16:43:57 -0400 | [diff] [blame] | 1276 | DEF_TEST(SkSLWidthAndHeight, r) { |
| 1277 | SkSL::Program::Settings settings; |
| 1278 | sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default(); |
| 1279 | settings.fCaps = caps.get(); |
| 1280 | SkSL::Program::Inputs inputs; |
| 1281 | test(r, |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1282 | "void main() { sk_FragColor.r = half(sk_FragCoord.x / sk_Width); }", |
Ethan Nicholas | cd700e9 | 2018-08-24 16:43:57 -0400 | [diff] [blame] | 1283 | settings, |
| 1284 | "#version 400\n" |
| 1285 | "uniform float u_skRTWidth;\n" |
| 1286 | "out vec4 sk_FragColor;\n" |
| 1287 | "void main() {\n" |
| 1288 | " sk_FragColor.x = gl_FragCoord.x / u_skRTWidth;\n" |
| 1289 | "}\n", |
| 1290 | &inputs); |
| 1291 | REPORTER_ASSERT(r, inputs.fRTWidth); |
| 1292 | REPORTER_ASSERT(r, !inputs.fRTHeight); |
| 1293 | |
| 1294 | test(r, |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1295 | "void main() { sk_FragColor.r = half(sk_FragCoord.y / sk_Height); }", |
Ethan Nicholas | cd700e9 | 2018-08-24 16:43:57 -0400 | [diff] [blame] | 1296 | settings, |
| 1297 | "#version 400\n" |
| 1298 | "uniform float u_skRTHeight;\n" |
| 1299 | "out vec4 sk_FragColor;\n" |
| 1300 | "void main() {\n" |
| 1301 | " sk_FragColor.x = gl_FragCoord.y / u_skRTHeight;\n" |
| 1302 | "}\n", |
| 1303 | &inputs); |
| 1304 | REPORTER_ASSERT(r, !inputs.fRTWidth); |
| 1305 | REPORTER_ASSERT(r, inputs.fRTHeight); |
| 1306 | } |
| 1307 | |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 1308 | DEF_TEST(SkSLClockwise, r) { |
| 1309 | test(r, |
| 1310 | "void main() { sk_FragColor = half4(sk_Clockwise ? +1 : -1); }", |
| 1311 | *SkSL::ShaderCapsFactory::Default(), |
| 1312 | "#version 400\n" |
| 1313 | "out vec4 sk_FragColor;\n" |
| 1314 | "void main() {\n" |
| 1315 | " sk_FragColor = vec4(float(gl_FrontFacing ? 1 : -1));\n" |
| 1316 | "}\n"); |
| 1317 | } |
| 1318 | |
Chris Dalton | b0fd4b1 | 2019-10-29 13:41:22 -0600 | [diff] [blame] | 1319 | DEF_TEST(SkSLSampleMask, r) { |
| 1320 | test(r, |
| 1321 | "void main() { sk_SampleMask[0] |= 8; }", |
| 1322 | *SkSL::ShaderCapsFactory::SampleMaskSupport(), |
| 1323 | "#version 400\n" |
| 1324 | "void main() {\n" |
| 1325 | " gl_SampleMask[0] |= 8;\n" |
| 1326 | "}\n"); |
| 1327 | } |
| 1328 | |
Ethan Nicholas | a51740c | 2017-02-07 14:53:32 -0500 | [diff] [blame] | 1329 | DEF_TEST(SkSLVertexID, r) { |
| 1330 | test(r, |
| 1331 | "out int id; void main() { id = sk_VertexID; }", |
| 1332 | *SkSL::ShaderCapsFactory::Default(), |
| 1333 | "#version 400\n" |
| 1334 | "out int id;\n" |
| 1335 | "void main() {\n" |
| 1336 | " id = gl_VertexID;\n" |
| 1337 | "}\n", |
| 1338 | SkSL::Program::kVertex_Kind); |
| 1339 | } |
| 1340 | |
Chris Dalton | 8580d51 | 2017-10-14 22:12:33 -0600 | [diff] [blame] | 1341 | DEF_TEST(SkSLInstanceID, r) { |
| 1342 | test(r, |
| 1343 | "out int id; void main() { id = sk_InstanceID; }", |
| 1344 | *SkSL::ShaderCapsFactory::Default(), |
| 1345 | "#version 400\n" |
| 1346 | "out int id;\n" |
| 1347 | "void main() {\n" |
| 1348 | " id = gl_InstanceID;\n" |
| 1349 | "}\n", |
| 1350 | SkSL::Program::kVertex_Kind); |
| 1351 | } |
| 1352 | |
Ethan Nicholas | 67d6460 | 2017-02-09 10:15:25 -0500 | [diff] [blame] | 1353 | DEF_TEST(SkSLClipDistance, r) { |
| 1354 | test(r, |
| 1355 | "void main() { sk_ClipDistance[0] = 0; }", |
| 1356 | *SkSL::ShaderCapsFactory::Default(), |
| 1357 | "#version 400\n" |
| 1358 | "void main() {\n" |
| 1359 | " gl_ClipDistance[0] = 0.0;\n" |
| 1360 | "}\n", |
| 1361 | SkSL::Program::kVertex_Kind); |
| 1362 | test(r, |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1363 | "void main() { sk_FragColor = half4(half(sk_ClipDistance[0])); }", |
Ethan Nicholas | 67d6460 | 2017-02-09 10:15:25 -0500 | [diff] [blame] | 1364 | *SkSL::ShaderCapsFactory::Default(), |
| 1365 | "#version 400\n" |
| 1366 | "out vec4 sk_FragColor;\n" |
| 1367 | "void main() {\n" |
| 1368 | " sk_FragColor = vec4(gl_ClipDistance[0]);\n" |
| 1369 | "}\n"); |
| 1370 | } |
Ethan Nicholas | 50afc17 | 2017-02-16 14:49:57 -0500 | [diff] [blame] | 1371 | |
| 1372 | DEF_TEST(SkSLArrayTypes, r) { |
| 1373 | test(r, |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1374 | "void main() { float2 x[2] = float2[2](float2(1), float2(2));" |
| 1375 | "float2[2] y = float2[2](float2(3), float2(4));" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1376 | "sk_FragColor = half4(half2(x[0]), half2(y[1])); }", |
Ethan Nicholas | 50afc17 | 2017-02-16 14:49:57 -0500 | [diff] [blame] | 1377 | *SkSL::ShaderCapsFactory::Default(), |
| 1378 | "#version 400\n" |
| 1379 | "out vec4 sk_FragColor;\n" |
| 1380 | "void main() {\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 1381 | " sk_FragColor = vec4(vec2[2](vec2(1.0), vec2(2.0))[0], " |
| 1382 | "vec2[2](vec2(3.0), vec2(4.0))[1]);\n" |
Ethan Nicholas | 50afc17 | 2017-02-16 14:49:57 -0500 | [diff] [blame] | 1383 | "}\n"); |
| 1384 | } |
| 1385 | |
Ethan Nicholas | 58d5648 | 2017-12-19 09:29:22 -0500 | [diff] [blame] | 1386 | DEF_TEST(SkSLArrayIndexTypes, r) { |
| 1387 | test(r, |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1388 | "void main() { float array[4] = float[4](1, 2, 3, 4);\n" |
| 1389 | "short x = 0;\n ushort y = 1;\n int z = 2;\n uint w = 3;\n" |
| 1390 | "sk_FragColor = half4(half(array[x]), half(array[y]), half(array[z]), half(array[w])); }", |
Ethan Nicholas | 58d5648 | 2017-12-19 09:29:22 -0500 | [diff] [blame] | 1391 | *SkSL::ShaderCapsFactory::Default(), |
| 1392 | "#version 400\n" |
| 1393 | "out vec4 sk_FragColor;\n" |
| 1394 | "void main() {\n" |
| 1395 | " sk_FragColor = vec4(float[4](1.0, 2.0, 3.0, 4.0)[0], " |
| 1396 | "float[4](1.0, 2.0, 3.0, 4.0)[1], " |
| 1397 | "float[4](1.0, 2.0, 3.0, 4.0)[2], " |
| 1398 | "float[4](1.0, 2.0, 3.0, 4.0)[3]);\n" |
| 1399 | "}\n"); |
| 1400 | } |
| 1401 | |
Ethan Nicholas | 52cad15 | 2017-02-16 16:37:32 -0500 | [diff] [blame] | 1402 | DEF_TEST(SkSLGeometry, r) { |
| 1403 | test(r, |
| 1404 | "layout(points) in;" |
| 1405 | "layout(invocations = 2) in;" |
| 1406 | "layout(line_strip, max_vertices = 2) out;" |
| 1407 | "void main() {" |
Ethan Nicholas | bed683a | 2017-09-26 14:23:59 -0400 | [diff] [blame] | 1408 | "sk_Position = sk_in[0].sk_Position + float4(-0.5, 0, 0, sk_InvocationID);" |
Ethan Nicholas | 52cad15 | 2017-02-16 16:37:32 -0500 | [diff] [blame] | 1409 | "EmitVertex();" |
Ethan Nicholas | bed683a | 2017-09-26 14:23:59 -0400 | [diff] [blame] | 1410 | "sk_Position = sk_in[0].sk_Position + float4(0.5, 0, 0, sk_InvocationID);" |
Ethan Nicholas | 52cad15 | 2017-02-16 16:37:32 -0500 | [diff] [blame] | 1411 | "EmitVertex();" |
| 1412 | "EndPrimitive();" |
| 1413 | "}", |
Chris Dalton | 8fd7955 | 2018-01-11 00:46:14 -0500 | [diff] [blame] | 1414 | *SkSL::ShaderCapsFactory::GeometryShaderSupport(), |
Ethan Nicholas | 52cad15 | 2017-02-16 16:37:32 -0500 | [diff] [blame] | 1415 | "#version 400\n" |
| 1416 | "layout (points) in ;\n" |
| 1417 | "layout (invocations = 2) in ;\n" |
| 1418 | "layout (line_strip, max_vertices = 2) out ;\n" |
| 1419 | "void main() {\n" |
| 1420 | " gl_Position = gl_in[0].gl_Position + vec4(-0.5, 0.0, 0.0, float(gl_InvocationID));\n" |
| 1421 | " EmitVertex();\n" |
| 1422 | " gl_Position = gl_in[0].gl_Position + vec4(0.5, 0.0, 0.0, float(gl_InvocationID));\n" |
| 1423 | " EmitVertex();\n" |
| 1424 | " EndPrimitive();\n" |
| 1425 | "}\n", |
| 1426 | SkSL::Program::kGeometry_Kind); |
| 1427 | } |
| 1428 | |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 1429 | DEF_TEST(SkSLSwitch, r) { |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1430 | // basic "does a switch even work" test |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 1431 | test(r, |
| 1432 | "void main() {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1433 | " float x;" |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1434 | " switch (int(sqrt(1))) {" |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 1435 | " case 0:" |
| 1436 | " x = 0.0;" |
| 1437 | " break;" |
| 1438 | " case 1:" |
| 1439 | " x = 1.0;" |
| 1440 | " break;" |
| 1441 | " default:" |
| 1442 | " x = 2.0;" |
| 1443 | " }" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1444 | " sk_FragColor = half4(half(x));" |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 1445 | "}", |
| 1446 | *SkSL::ShaderCapsFactory::Default(), |
| 1447 | "#version 400\n" |
| 1448 | "out vec4 sk_FragColor;\n" |
| 1449 | "void main() {\n" |
| 1450 | " float x;\n" |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1451 | " switch (int(sqrt(1.0))) {\n" |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 1452 | " case 0:\n" |
| 1453 | " x = 0.0;\n" |
| 1454 | " break;\n" |
| 1455 | " case 1:\n" |
| 1456 | " x = 1.0;\n" |
| 1457 | " break;\n" |
| 1458 | " default:\n" |
| 1459 | " x = 2.0;\n" |
| 1460 | " }\n" |
| 1461 | " sk_FragColor = vec4(x);\n" |
| 1462 | "}\n"); |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1463 | // dead code inside of switch |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 1464 | test(r, |
| 1465 | "void main() {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1466 | " float x;" |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1467 | " switch (int(sqrt(2))) {" |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 1468 | " case 0:" |
| 1469 | " x = 0.0;" |
| 1470 | " case 1:" |
| 1471 | " x = 1.0;" |
| 1472 | " default:" |
| 1473 | " x = 2.0;" |
| 1474 | " }" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1475 | " sk_FragColor = half4(half(x));" |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 1476 | "}", |
| 1477 | *SkSL::ShaderCapsFactory::Default(), |
| 1478 | "#version 400\n" |
| 1479 | "out vec4 sk_FragColor;\n" |
| 1480 | "void main() {\n" |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1481 | " switch (int(sqrt(2.0))) {\n" |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 1482 | " case 0:\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 1483 | " ;\n" |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 1484 | " case 1:\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 1485 | " ;\n" |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 1486 | " default:\n" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 1487 | " ;\n" |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 1488 | " }\n" |
| 1489 | " sk_FragColor = vec4(2.0);\n" |
| 1490 | "}\n"); |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1491 | // non-static test w/ fallthrough |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 1492 | test(r, |
| 1493 | "void main() {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1494 | " float x = 0.0;" |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1495 | " switch (int(sqrt(3))) {" |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 1496 | " case 0:" |
| 1497 | " x = 0.0;" |
| 1498 | " case 1:" |
| 1499 | " x = 1.0;" |
| 1500 | " }" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1501 | " sk_FragColor = half4(half(x));" |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 1502 | "}", |
| 1503 | *SkSL::ShaderCapsFactory::Default(), |
| 1504 | "#version 400\n" |
| 1505 | "out vec4 sk_FragColor;\n" |
| 1506 | "void main() {\n" |
| 1507 | " float x = 0.0;\n" |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1508 | " switch (int(sqrt(3.0))) {\n" |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 1509 | " case 0:\n" |
| 1510 | " x = 0.0;\n" |
| 1511 | " case 1:\n" |
| 1512 | " x = 1.0;\n" |
| 1513 | " }\n" |
| 1514 | " sk_FragColor = vec4(x);\n" |
| 1515 | "}\n"); |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1516 | // static test w/ fallthrough |
| 1517 | test(r, |
| 1518 | "void main() {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1519 | " float x = 0.0;" |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1520 | " switch (0) {" |
| 1521 | " case 0:" |
| 1522 | " x = 0.0;" |
| 1523 | " case 1:" |
| 1524 | " x = 1.0;" |
| 1525 | " }" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1526 | " sk_FragColor = half4(half(x));" |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1527 | "}", |
| 1528 | *SkSL::ShaderCapsFactory::Default(), |
| 1529 | "#version 400\n" |
| 1530 | "out vec4 sk_FragColor;\n" |
| 1531 | "void main() {\n" |
| 1532 | " sk_FragColor = vec4(1.0);\n" |
| 1533 | "}\n"); |
| 1534 | // static test w/ fallthrough, different entry point |
| 1535 | test(r, |
| 1536 | "void main() {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1537 | " float x = 0.0;" |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1538 | " switch (1) {" |
| 1539 | " case 0:" |
| 1540 | " x = 0.0;" |
| 1541 | " case 1:" |
| 1542 | " x = 1.0;" |
| 1543 | " }" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1544 | " sk_FragColor = half4(half(x));" |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1545 | "}", |
| 1546 | *SkSL::ShaderCapsFactory::Default(), |
| 1547 | "#version 400\n" |
| 1548 | "out vec4 sk_FragColor;\n" |
| 1549 | "void main() {\n" |
| 1550 | " sk_FragColor = vec4(1.0);\n" |
| 1551 | "}\n"); |
| 1552 | // static test w/ break |
| 1553 | test(r, |
| 1554 | "void main() {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1555 | " float x = 0.0;" |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1556 | " switch (0) {" |
| 1557 | " case 0:" |
| 1558 | " x = 0.0;" |
| 1559 | " break;" |
| 1560 | " case 1:" |
| 1561 | " x = 1.0;" |
| 1562 | " }" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1563 | " sk_FragColor = half4(half(x));" |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1564 | "}", |
| 1565 | *SkSL::ShaderCapsFactory::Default(), |
| 1566 | "#version 400\n" |
| 1567 | "out vec4 sk_FragColor;\n" |
| 1568 | "void main() {\n" |
| 1569 | " sk_FragColor = vec4(0.0);\n" |
| 1570 | "}\n"); |
| 1571 | // static test w/ static conditional break |
| 1572 | test(r, |
| 1573 | "void main() {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1574 | " float x = 0.0;" |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1575 | " switch (0) {" |
| 1576 | " case 0:" |
| 1577 | " x = 0.0;" |
| 1578 | " if (x < 1) break;" |
| 1579 | " case 1:" |
| 1580 | " x = 1.0;" |
| 1581 | " }" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1582 | " sk_FragColor = half4(half(x));" |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1583 | "}", |
| 1584 | *SkSL::ShaderCapsFactory::Default(), |
| 1585 | "#version 400\n" |
| 1586 | "out vec4 sk_FragColor;\n" |
| 1587 | "void main() {\n" |
| 1588 | " sk_FragColor = vec4(0.0);\n" |
| 1589 | "}\n"); |
| 1590 | // static test w/ non-static conditional break |
| 1591 | test(r, |
| 1592 | "void main() {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1593 | " float x = 0.0;" |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1594 | " switch (0) {" |
| 1595 | " case 0:" |
| 1596 | " x = 0.0;" |
| 1597 | " if (x < sqrt(1)) break;" |
| 1598 | " case 1:" |
| 1599 | " x = 1.0;" |
| 1600 | " }" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1601 | " sk_FragColor = half4(half(x));" |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1602 | "}", |
| 1603 | *SkSL::ShaderCapsFactory::Default(), |
| 1604 | "#version 400\n" |
| 1605 | "out vec4 sk_FragColor;\n" |
| 1606 | "void main() {\n" |
| 1607 | " float x = 0.0;\n" |
| 1608 | " switch (0) {\n" |
| 1609 | " case 0:\n" |
| 1610 | " x = 0.0;\n" |
| 1611 | " if (0.0 < sqrt(1.0)) break;\n" |
| 1612 | " case 1:\n" |
| 1613 | " x = 1.0;\n" |
| 1614 | " }\n" |
| 1615 | " sk_FragColor = vec4(x);\n" |
| 1616 | "}\n"); |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 1617 | } |
| 1618 | |
Ethan Nicholas | 5338f99 | 2017-04-19 15:54:07 -0400 | [diff] [blame] | 1619 | DEF_TEST(SkSLRectangleTexture, r) { |
| 1620 | test(r, |
| 1621 | "uniform sampler2D test;" |
| 1622 | "void main() {" |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 1623 | " sk_FragColor = sample(test, float2(0.5));" |
Ethan Nicholas | 5338f99 | 2017-04-19 15:54:07 -0400 | [diff] [blame] | 1624 | "}", |
| 1625 | *SkSL::ShaderCapsFactory::Default(), |
| 1626 | "#version 400\n" |
| 1627 | "out vec4 sk_FragColor;\n" |
| 1628 | "uniform sampler2D test;\n" |
| 1629 | "void main() {\n" |
Ethan Nicholas | fe53e58 | 2017-04-27 16:24:51 -0400 | [diff] [blame] | 1630 | " sk_FragColor = texture(test, vec2(0.5));\n" |
Ethan Nicholas | 5338f99 | 2017-04-19 15:54:07 -0400 | [diff] [blame] | 1631 | "}\n"); |
| 1632 | test(r, |
| 1633 | "uniform sampler2DRect test;" |
| 1634 | "void main() {" |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 1635 | " sk_FragColor = sample(test, float2(0.5));" |
Ethan Nicholas | 5338f99 | 2017-04-19 15:54:07 -0400 | [diff] [blame] | 1636 | "}", |
| 1637 | *SkSL::ShaderCapsFactory::Default(), |
| 1638 | "#version 400\n" |
| 1639 | "out vec4 sk_FragColor;\n" |
| 1640 | "uniform sampler2DRect test;\n" |
| 1641 | "void main() {\n" |
Brian Salomon | 246bc3d | 2018-12-06 15:33:02 -0500 | [diff] [blame] | 1642 | " sk_FragColor = texture(test, vec2(0.5));\n" |
Ethan Nicholas | 5338f99 | 2017-04-19 15:54:07 -0400 | [diff] [blame] | 1643 | "}\n"); |
| 1644 | test(r, |
| 1645 | "uniform sampler2DRect test;" |
| 1646 | "void main() {" |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 1647 | " sk_FragColor = sample(test, float3(0.5));" |
Ethan Nicholas | 5338f99 | 2017-04-19 15:54:07 -0400 | [diff] [blame] | 1648 | "}", |
| 1649 | *SkSL::ShaderCapsFactory::Default(), |
| 1650 | "#version 400\n" |
| 1651 | "out vec4 sk_FragColor;\n" |
| 1652 | "uniform sampler2DRect test;\n" |
| 1653 | "void main() {\n" |
Brian Salomon | 246bc3d | 2018-12-06 15:33:02 -0500 | [diff] [blame] | 1654 | " sk_FragColor = texture(test, vec3(0.5));\n" |
Ethan Nicholas | 5338f99 | 2017-04-19 15:54:07 -0400 | [diff] [blame] | 1655 | "}\n"); |
| 1656 | } |
| 1657 | |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 1658 | DEF_TEST(SkSLUnusedVars, r) { |
| 1659 | test(r, |
| 1660 | "void main() {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1661 | "float a = 1, b = 2, c = 3;" |
| 1662 | "float d = c;" |
| 1663 | "float e = d;" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 1664 | "b++;" |
| 1665 | "d++;" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1666 | "sk_FragColor = half4(half(b), half(b), half(d), half(d));" |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 1667 | "}", |
| 1668 | *SkSL::ShaderCapsFactory::Default(), |
| 1669 | "#version 400\n" |
| 1670 | "out vec4 sk_FragColor;\n" |
| 1671 | "void main() {\n" |
| 1672 | " float b = 2.0;\n" |
| 1673 | " float d = 3.0;\n" |
| 1674 | " b++;\n" |
| 1675 | " d++;\n" |
| 1676 | " sk_FragColor = vec4(b, b, d, d);\n" |
| 1677 | "}\n"); |
| 1678 | } |
| 1679 | |
Ethan Nicholas | c2371a4 | 2017-05-05 10:04:06 -0400 | [diff] [blame] | 1680 | DEF_TEST(SkSLMultipleAssignments, r) { |
| 1681 | test(r, |
| 1682 | "void main() {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1683 | "float x;" |
| 1684 | "float y;" |
Ethan Nicholas | c2371a4 | 2017-05-05 10:04:06 -0400 | [diff] [blame] | 1685 | "int z;" |
| 1686 | "x = y = z = 1;" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1687 | "sk_FragColor = half4(z);" |
Ethan Nicholas | c2371a4 | 2017-05-05 10:04:06 -0400 | [diff] [blame] | 1688 | "}", |
| 1689 | *SkSL::ShaderCapsFactory::Default(), |
| 1690 | "#version 400\n" |
| 1691 | "out vec4 sk_FragColor;\n" |
| 1692 | "void main() {\n" |
| 1693 | " sk_FragColor = vec4(1.0);\n" |
| 1694 | "}\n"); |
| 1695 | } |
| 1696 | |
Ethan Nicholas | 4b330df | 2017-05-17 10:52:55 -0400 | [diff] [blame] | 1697 | DEF_TEST(SkSLComplexDelete, r) { |
| 1698 | test(r, |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1699 | "uniform float4x4 colorXform;" |
Ethan Nicholas | b4dc419 | 2017-06-02 10:16:28 -0400 | [diff] [blame] | 1700 | "uniform sampler2D sampler;" |
| 1701 | "void main() {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1702 | "float4 tmpColor;" |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 1703 | "sk_FragColor = half4(1.0) * (tmpColor = sample(sampler, float2(1)) , " |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1704 | "half4(colorXform != float4x4(1.0) ? float4(clamp((float4x4(colorXform) * " |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1705 | "float4(tmpColor.xyz, 1.0)).xyz, " |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1706 | "0.0, tmpColor.w), tmpColor.w) : tmpColor));" |
Ethan Nicholas | b4dc419 | 2017-06-02 10:16:28 -0400 | [diff] [blame] | 1707 | "}", |
| 1708 | *SkSL::ShaderCapsFactory::Default(), |
| 1709 | "#version 400\n" |
| 1710 | "out vec4 sk_FragColor;\n" |
| 1711 | "uniform mat4 colorXform;\n" |
| 1712 | "uniform sampler2D sampler;\n" |
| 1713 | "void main() {\n" |
| 1714 | " vec4 tmpColor;\n" |
| 1715 | " sk_FragColor = (tmpColor = texture(sampler, vec2(1.0)) , colorXform != mat4(1.0) ? " |
| 1716 | "vec4(clamp((colorXform * vec4(tmpColor.xyz, 1.0)).xyz, 0.0, tmpColor.w), tmpColor.w) : " |
| 1717 | "tmpColor);\n" |
| 1718 | "}\n"); |
Ethan Nicholas | 4b330df | 2017-05-17 10:52:55 -0400 | [diff] [blame] | 1719 | } |
Ethan Nicholas | b4dc419 | 2017-06-02 10:16:28 -0400 | [diff] [blame] | 1720 | |
| 1721 | DEF_TEST(SkSLDependentInitializers, r) { |
| 1722 | test(r, |
| 1723 | "void main() {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1724 | "float x = 0.5, y = x * 2;" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1725 | "sk_FragColor = half4(half(y));" |
Ethan Nicholas | b4dc419 | 2017-06-02 10:16:28 -0400 | [diff] [blame] | 1726 | "}", |
| 1727 | *SkSL::ShaderCapsFactory::Default(), |
| 1728 | "#version 400\n" |
| 1729 | "out vec4 sk_FragColor;\n" |
| 1730 | "void main() {\n" |
| 1731 | " sk_FragColor = vec4(1.0);\n" |
| 1732 | "}\n"); |
| 1733 | } |
| 1734 | |
Ethan Nicholas | b310fd5 | 2017-06-09 13:46:34 -0400 | [diff] [blame] | 1735 | DEF_TEST(SkSLDeadLoopVar, r) { |
| 1736 | test(r, |
| 1737 | "void main() {" |
| 1738 | "for (int x = 0; x < 4; ) {" |
| 1739 | "break;" |
| 1740 | "}" |
| 1741 | "}", |
| 1742 | *SkSL::ShaderCapsFactory::Default(), |
| 1743 | "#version 400\n" |
Ethan Nicholas | b310fd5 | 2017-06-09 13:46:34 -0400 | [diff] [blame] | 1744 | "void main() {\n" |
| 1745 | " for (; true; ) {\n" |
| 1746 | " break;\n" |
| 1747 | " }\n" |
| 1748 | "}\n" |
| 1749 | ); |
| 1750 | } |
| 1751 | |
Chris Dalton | 8fd7955 | 2018-01-11 00:46:14 -0500 | [diff] [blame] | 1752 | DEF_TEST(SkSLGeometryShaders, r) { |
Ethan Nicholas | 7da6dfa | 2017-06-21 11:25:18 -0400 | [diff] [blame] | 1753 | test(r, |
| 1754 | "layout(points) in;" |
| 1755 | "layout(invocations = 2) in;" |
| 1756 | "layout(line_strip, max_vertices = 2) out;" |
| 1757 | "void test() {" |
Ethan Nicholas | bed683a | 2017-09-26 14:23:59 -0400 | [diff] [blame] | 1758 | "sk_Position = sk_in[0].sk_Position + float4(0.5, 0, 0, sk_InvocationID);" |
Ethan Nicholas | 7da6dfa | 2017-06-21 11:25:18 -0400 | [diff] [blame] | 1759 | "EmitVertex();" |
| 1760 | "}" |
| 1761 | "void main() {" |
Ethan Nicholas | bed683a | 2017-09-26 14:23:59 -0400 | [diff] [blame] | 1762 | "sk_Position = sk_in[0].sk_Position + float4(-0.5, 0, 0, sk_InvocationID);" |
Ethan Nicholas | 7da6dfa | 2017-06-21 11:25:18 -0400 | [diff] [blame] | 1763 | "EmitVertex();" |
| 1764 | "}", |
Chris Dalton | f1b47bb | 2017-10-06 11:57:51 -0600 | [diff] [blame] | 1765 | *SkSL::ShaderCapsFactory::NoGSInvocationsSupport(), |
Ethan Nicholas | 7da6dfa | 2017-06-21 11:25:18 -0400 | [diff] [blame] | 1766 | "#version 400\n" |
| 1767 | "int sk_InvocationID;\n" |
| 1768 | "layout (points) in ;\n" |
| 1769 | "layout (line_strip, max_vertices = 4) out ;\n" |
| 1770 | "void test() {\n" |
| 1771 | " gl_Position = gl_in[0].gl_Position + vec4(0.5, 0.0, 0.0, float(sk_InvocationID));\n" |
| 1772 | " EmitVertex();\n" |
| 1773 | "}\n" |
| 1774 | "void _invoke() {\n" |
| 1775 | " gl_Position = gl_in[0].gl_Position + vec4(-0.5, 0.0, 0.0, float(sk_InvocationID));\n" |
| 1776 | " EmitVertex();\n" |
| 1777 | "}\n" |
| 1778 | "void main() {\n" |
| 1779 | " for (sk_InvocationID = 0;sk_InvocationID < 2; sk_InvocationID++) {\n" |
| 1780 | " _invoke();\n" |
| 1781 | " EndPrimitive();\n" |
| 1782 | " }\n" |
| 1783 | "}\n", |
| 1784 | SkSL::Program::kGeometry_Kind); |
Chris Dalton | f1b47bb | 2017-10-06 11:57:51 -0600 | [diff] [blame] | 1785 | test(r, |
| 1786 | "layout(points, invocations = 2) in;" |
| 1787 | "layout(invocations = 3) in;" |
| 1788 | "layout(line_strip, max_vertices = 2) out;" |
| 1789 | "void main() {" |
| 1790 | "sk_Position = sk_in[0].sk_Position + float4(-0.5, 0, 0, sk_InvocationID);" |
| 1791 | "EmitVertex();" |
| 1792 | "EndPrimitive();" |
| 1793 | "}", |
| 1794 | *SkSL::ShaderCapsFactory::GSInvocationsExtensionString(), |
| 1795 | "#version 400\n" |
| 1796 | "#extension GL_ARB_gpu_shader5 : require\n" |
| 1797 | "layout (points, invocations = 2) in ;\n" |
| 1798 | "layout (invocations = 3) in ;\n" |
| 1799 | "layout (line_strip, max_vertices = 2) out ;\n" |
| 1800 | "void main() {\n" |
| 1801 | " gl_Position = gl_in[0].gl_Position + vec4(-0.5, 0.0, 0.0, float(gl_InvocationID));\n" |
| 1802 | " EmitVertex();\n" |
| 1803 | " EndPrimitive();\n" |
| 1804 | "}\n", |
| 1805 | SkSL::Program::kGeometry_Kind); |
Chris Dalton | 8fd7955 | 2018-01-11 00:46:14 -0500 | [diff] [blame] | 1806 | test(r, |
| 1807 | "layout(points, invocations = 2) in;" |
| 1808 | "layout(invocations = 3) in;" |
| 1809 | "layout(line_strip, max_vertices = 2) out;" |
| 1810 | "void main() {" |
| 1811 | "sk_Position = sk_in[0].sk_Position + float4(-0.5, 0, 0, sk_InvocationID);" |
| 1812 | "EmitVertex();" |
| 1813 | "EndPrimitive();" |
| 1814 | "}", |
| 1815 | *SkSL::ShaderCapsFactory::GeometryShaderExtensionString(), |
| 1816 | "#version 310es\n" |
| 1817 | "#extension GL_EXT_geometry_shader : require\n" |
| 1818 | "layout (points, invocations = 2) in ;\n" |
| 1819 | "layout (invocations = 3) in ;\n" |
| 1820 | "layout (line_strip, max_vertices = 2) out ;\n" |
| 1821 | "void main() {\n" |
| 1822 | " gl_Position = gl_in[0].gl_Position + vec4(-0.5, 0.0, 0.0, float(gl_InvocationID));\n" |
| 1823 | " EmitVertex();\n" |
| 1824 | " EndPrimitive();\n" |
| 1825 | "}\n", |
| 1826 | SkSL::Program::kGeometry_Kind); |
Ethan Nicholas | 7da6dfa | 2017-06-21 11:25:18 -0400 | [diff] [blame] | 1827 | } |
| 1828 | |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1829 | DEF_TEST(SkSLTypePrecision, r) { |
| 1830 | test(r, |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1831 | "float f = 1;" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1832 | "half h = 2;" |
| 1833 | "double d = 3;" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1834 | "float2 f2 = float2(1, 2);" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1835 | "half3 h3 = half3(1, 2, 3);" |
| 1836 | "double4 d4 = double4(1, 2, 3, 4);" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1837 | "float2x2 f22 = float2x2(1, 2, 3, 4);" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1838 | "half2x4 h24 = half2x4(1, 2, 3, 4, 5, 6, 7, 8);" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 1839 | "double4x2 d42 = double4x2(1, 2, 3, 4, 5, 6, 7, 8);" |
| 1840 | "void main() {" |
| 1841 | "sk_FragColor.r = half(f + h + d + f2.x + h3.x + d4.x + f22[0][0] + h24[0][0] + " |
| 1842 | "d42[0][0]);" |
| 1843 | "}", |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1844 | *SkSL::ShaderCapsFactory::Default(), |
| 1845 | "#version 400\n" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 1846 | "out vec4 sk_FragColor;\n" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1847 | "float f = 1.0;\n" |
| 1848 | "float h = 2.0;\n" |
| 1849 | "double d = 3.0;\n" |
| 1850 | "vec2 f2 = vec2(1.0, 2.0);\n" |
| 1851 | "vec3 h3 = vec3(1.0, 2.0, 3.0);\n" |
| 1852 | "dvec4 d4 = dvec4(1.0, 2.0, 3.0, 4.0);\n" |
| 1853 | "mat2 f22 = mat2(1.0, 2.0, 3.0, 4.0);\n" |
| 1854 | "mat2x4 h24 = mat2x4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);\n" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 1855 | "dmat4x2 d42 = dmat4x2(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);\n" |
| 1856 | "void main() {\n" |
| 1857 | " sk_FragColor.x = float(((((((double(f + h) + d) + double(f2.x)) + double(h3.x)) + " |
| 1858 | "d4.x) + double(f22[0][0])) + double(h24[0][0])) + d42[0][0]);\n" |
| 1859 | "}\n"); |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1860 | test(r, |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1861 | "float f = 1;" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1862 | "half h = 2;" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1863 | "float2 f2 = float2(1, 2);" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1864 | "half3 h3 = half3(1, 2, 3);" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1865 | "float2x2 f22 = float2x2(1, 2, 3, 4);" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 1866 | "half2x4 h24 = half2x4(1, 2, 3, 4, 5, 6, 7, 8);" |
| 1867 | "void main() {" |
| 1868 | "sk_FragColor.r = half(f + h + f2.x + h3.x + f22[0][0] + h24[0][0]);" |
| 1869 | "}", |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1870 | *SkSL::ShaderCapsFactory::UsesPrecisionModifiers(), |
| 1871 | "#version 400\n" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 1872 | "precision mediump float;\n" |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 1873 | "precision mediump sampler2D;\n" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 1874 | "out mediump vec4 sk_FragColor;\n" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 1875 | "highp float f = 1.0;\n" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1876 | "mediump float h = 2.0;\n" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 1877 | "highp vec2 f2 = vec2(1.0, 2.0);\n" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1878 | "mediump vec3 h3 = vec3(1.0, 2.0, 3.0);\n" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 1879 | "highp mat2 f22 = mat2(1.0, 2.0, 3.0, 4.0);\n" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 1880 | "mediump mat2x4 h24 = mat2x4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);\n" |
| 1881 | "void main() {\n" |
| 1882 | " sk_FragColor.x = ((((f + h) + f2.x) + h3.x) + f22[0][0]) + h24[0][0];\n" |
| 1883 | "}\n"); |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | DEF_TEST(SkSLNumberConversions, r) { |
| 1887 | test(r, |
| 1888 | "short s = short(sqrt(1));" |
| 1889 | "int i = int(sqrt(1));" |
| 1890 | "ushort us = ushort(sqrt(1));" |
| 1891 | "uint ui = uint(sqrt(1));" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1892 | "half h = half(sqrt(1));" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1893 | "float f = sqrt(1);" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1894 | "short s2s = s;" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1895 | "short i2s = short(i);" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1896 | "short us2s = short(us);" |
| 1897 | "short ui2s = short(ui);" |
| 1898 | "short h2s = short(h);" |
| 1899 | "short f2s = short(f);" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1900 | "int s2i = s;" |
| 1901 | "int i2i = i;" |
| 1902 | "int us2i = int(us);" |
| 1903 | "int ui2i = int(ui);" |
| 1904 | "int h2i = int(h);" |
| 1905 | "int f2i = int(f);" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1906 | "ushort s2us = ushort(s);" |
| 1907 | "ushort i2us = ushort(i);" |
| 1908 | "ushort us2us = us;" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1909 | "ushort ui2us = ushort(ui);" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1910 | "ushort h2us = ushort(h);" |
| 1911 | "ushort f2us = ushort(f);" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1912 | "uint s2ui = uint(s);" |
| 1913 | "uint i2ui = uint(i);" |
| 1914 | "uint us2ui = us;" |
| 1915 | "uint ui2ui = ui;" |
| 1916 | "uint h2ui = uint(h);" |
| 1917 | "uint f2ui = uint(f);" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 1918 | "float s2f = s;" |
| 1919 | "float i2f = i;" |
| 1920 | "float us2f = us;" |
| 1921 | "float ui2f = ui;" |
| 1922 | "float h2f = h;" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 1923 | "float f2f = f;" |
| 1924 | "void main() {" |
| 1925 | "sk_FragColor.r = half(s + i + us + half(ui) + h + f + s2s + i2s + us2s + ui2s + h2s + " |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 1926 | "f2s + s2i + i2i + us2i + ui2i + h2i + f2i + s2us + i2us + us2us);" |
| 1927 | "sk_FragColor.r += half(ui2us + h2us + f2us + half(s2ui) + half(i2ui) + half(us2ui) + " |
| 1928 | "half(ui2ui) + half(h2ui) + half(f2ui) + s2f + i2f + us2f + ui2f + " |
| 1929 | "h2f + f2f);" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 1930 | "}", |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1931 | *SkSL::ShaderCapsFactory::Default(), |
| 1932 | "#version 400\n" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 1933 | "out vec4 sk_FragColor;\n" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1934 | "int s = int(sqrt(1.0));\n" |
| 1935 | "int i = int(sqrt(1.0));\n" |
| 1936 | "uint us = uint(sqrt(1.0));\n" |
| 1937 | "uint ui = uint(sqrt(1.0));\n" |
| 1938 | "float h = sqrt(1.0);\n" |
| 1939 | "float f = sqrt(1.0);\n" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1940 | "int s2s = s;\n" |
| 1941 | "int i2s = i;\n" |
| 1942 | "int us2s = int(us);\n" |
| 1943 | "int ui2s = int(ui);\n" |
| 1944 | "int h2s = int(h);\n" |
| 1945 | "int f2s = int(f);\n" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1946 | "int s2i = s;\n" |
| 1947 | "int i2i = i;\n" |
| 1948 | "int us2i = int(us);\n" |
| 1949 | "int ui2i = int(ui);\n" |
| 1950 | "int h2i = int(h);\n" |
| 1951 | "int f2i = int(f);\n" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1952 | "uint s2us = uint(s);\n" |
| 1953 | "uint i2us = uint(i);\n" |
| 1954 | "uint us2us = us;\n" |
| 1955 | "uint ui2us = ui;\n" |
| 1956 | "uint h2us = uint(h);\n" |
| 1957 | "uint f2us = uint(f);\n" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1958 | "uint s2ui = uint(s);\n" |
| 1959 | "uint i2ui = uint(i);\n" |
| 1960 | "uint us2ui = us;\n" |
| 1961 | "uint ui2ui = ui;\n" |
| 1962 | "uint h2ui = uint(h);\n" |
| 1963 | "uint f2ui = uint(f);\n" |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 1964 | "float s2f = float(s);\n" |
| 1965 | "float i2f = float(i);\n" |
| 1966 | "float us2f = float(us);\n" |
| 1967 | "float ui2f = float(ui);\n" |
| 1968 | "float h2f = h;\n" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 1969 | "float f2f = f;\n" |
| 1970 | "void main() {\n" |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 1971 | " sk_FragColor.x = (((((((((((((((((float((s + i) + int(us)) + float(ui)) + h) + f) + " |
| 1972 | "float(s2s)) + float(i2s)) + float(us2s)) + float(ui2s)) + float(h2s)) + float(f2s)) + " |
| 1973 | "float(s2i)) + float(i2i)) + float(us2i)) + float(ui2i)) + float(h2i)) + float(f2i)) + " |
| 1974 | "float(s2us)) + float(i2us)) + float(us2us);\n" |
| 1975 | " sk_FragColor.x += (((((((((((float((ui2us + h2us) + f2us) + float(s2ui)) + " |
| 1976 | "float(i2ui)) + float(us2ui)) + float(ui2ui)) + float(h2ui)) + float(f2ui)) + s2f) + " |
| 1977 | "i2f) + us2f) + ui2f) + h2f) + f2f;\n" |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 1978 | "}\n"); |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 1979 | } |
| 1980 | |
| 1981 | DEF_TEST(SkSLForceHighPrecision, r) { |
| 1982 | test(r, |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 1983 | "void main() {\n half x = half(sqrt(1));\n half4 y = half4(x);\n sk_FragColor = y;\n }", |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 1984 | *SkSL::ShaderCapsFactory::UsesPrecisionModifiers(), |
| 1985 | "#version 400\n" |
| 1986 | "precision mediump float;\n" |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 1987 | "precision mediump sampler2D;\n" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 1988 | "out mediump vec4 sk_FragColor;\n" |
| 1989 | "void main() {\n" |
| 1990 | " mediump float x = sqrt(1.0);\n" |
| 1991 | " mediump vec4 y = vec4(x);\n" |
| 1992 | " sk_FragColor = y;\n" |
| 1993 | "}\n"); |
| 1994 | SkSL::Program::Settings settings; |
| 1995 | settings.fForceHighPrecision = true; |
| 1996 | sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::UsesPrecisionModifiers(); |
| 1997 | settings.fCaps = caps.get(); |
| 1998 | SkSL::Program::Inputs inputs; |
| 1999 | test(r, |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 2000 | "void main() { half x = half(sqrt(1)); half4 y = half4(x); sk_FragColor = y; }", |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 2001 | settings, |
| 2002 | "#version 400\n" |
| 2003 | "precision mediump float;\n" |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 2004 | "precision mediump sampler2D;\n" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 2005 | "out mediump vec4 sk_FragColor;\n" |
| 2006 | "void main() {\n" |
| 2007 | " highp float x = sqrt(1.0);\n" |
| 2008 | " highp vec4 y = vec4(x);\n" |
| 2009 | " sk_FragColor = y;\n" |
| 2010 | "}\n", |
| 2011 | &inputs); |
Ethan Nicholas | dcba08e | 2017-08-02 10:52:54 -0400 | [diff] [blame] | 2012 | } |
| 2013 | |
Robert Phillips | fe8da17 | 2018-01-24 14:52:02 +0000 | [diff] [blame] | 2014 | DEF_TEST(SkSLNormalization, r) { |
| 2015 | test(r, |
| 2016 | "uniform float4 sk_RTAdjust; void main() { sk_Position = half4(1); }", |
| 2017 | *SkSL::ShaderCapsFactory::Default(), |
| 2018 | "#version 400\n" |
| 2019 | "uniform vec4 sk_RTAdjust;\n" |
| 2020 | "void main() {\n" |
| 2021 | " gl_Position = vec4(1.0);\n" |
Ethan Nicholas | b809efb | 2018-04-12 14:39:21 -0400 | [diff] [blame] | 2022 | " gl_Position = vec4(gl_Position.xy * sk_RTAdjust.xz + gl_Position.ww * " |
| 2023 | "sk_RTAdjust.yw, 0.0, gl_Position.w);\n" |
Robert Phillips | fe8da17 | 2018-01-24 14:52:02 +0000 | [diff] [blame] | 2024 | "}\n", |
| 2025 | SkSL::Program::kVertex_Kind); |
| 2026 | test(r, |
| 2027 | "uniform float4 sk_RTAdjust;" |
| 2028 | "layout(points) in;" |
| 2029 | "layout(invocations = 2) in;" |
| 2030 | "layout(line_strip, max_vertices = 2) out;" |
| 2031 | "void main() {" |
| 2032 | "sk_Position = sk_in[0].sk_Position + float4(-0.5, 0, 0, sk_InvocationID);" |
| 2033 | "EmitVertex();" |
| 2034 | "sk_Position = sk_in[0].sk_Position + float4(0.5, 0, 0, sk_InvocationID);" |
| 2035 | "EmitVertex();" |
| 2036 | "EndPrimitive();" |
| 2037 | "}", |
| 2038 | *SkSL::ShaderCapsFactory::GeometryShaderSupport(), |
| 2039 | "#version 400\n" |
| 2040 | "uniform vec4 sk_RTAdjust;\n" |
| 2041 | "layout (points) in ;\n" |
| 2042 | "layout (invocations = 2) in ;\n" |
| 2043 | "layout (line_strip, max_vertices = 2) out ;\n" |
| 2044 | "void main() {\n" |
| 2045 | " gl_Position = gl_in[0].gl_Position + vec4(-0.5, 0.0, 0.0, float(gl_InvocationID));\n" |
| 2046 | " {\n" |
Ethan Nicholas | b809efb | 2018-04-12 14:39:21 -0400 | [diff] [blame] | 2047 | " gl_Position = vec4(gl_Position.xy * sk_RTAdjust.xz + gl_Position.ww * " |
| 2048 | "sk_RTAdjust.yw, 0.0, gl_Position.w);\n" |
Robert Phillips | fe8da17 | 2018-01-24 14:52:02 +0000 | [diff] [blame] | 2049 | " EmitVertex();\n" |
| 2050 | " }\n" |
| 2051 | " gl_Position = gl_in[0].gl_Position + vec4(0.5, 0.0, 0.0, float(gl_InvocationID));\n" |
| 2052 | " {\n" |
Ethan Nicholas | b809efb | 2018-04-12 14:39:21 -0400 | [diff] [blame] | 2053 | " gl_Position = vec4(gl_Position.xy * sk_RTAdjust.xz + gl_Position.ww * " |
| 2054 | "sk_RTAdjust.yw, 0.0, gl_Position.w);\n" |
Robert Phillips | fe8da17 | 2018-01-24 14:52:02 +0000 | [diff] [blame] | 2055 | " EmitVertex();\n" |
| 2056 | " }\n" |
| 2057 | " EndPrimitive();\n" |
| 2058 | "}\n", |
| 2059 | SkSL::Program::kGeometry_Kind); |
| 2060 | } |
| 2061 | |
Ethan Nicholas | a583b81 | 2018-01-18 13:32:11 -0500 | [diff] [blame] | 2062 | DEF_TEST(SkSLTernaryLValue, r) { |
| 2063 | test(r, |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 2064 | "void main() { int r, g; (true ? r : g) = 1; (false ? r : g) = 0; " |
Ethan Nicholas | a583b81 | 2018-01-18 13:32:11 -0500 | [diff] [blame] | 2065 | "sk_FragColor = half4(r, g, 1, 1); }", |
| 2066 | *SkSL::ShaderCapsFactory::Default(), |
| 2067 | "#version 400\n" |
| 2068 | "out vec4 sk_FragColor;\n" |
| 2069 | "void main() {\n" |
| 2070 | " sk_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n" |
| 2071 | "}\n"); |
| 2072 | test(r, |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 2073 | "void main() { half r, g; (true ? r : g) = half(sqrt(1)); (false ? r : g) = half(sqrt(0));" |
Ethan Nicholas | a583b81 | 2018-01-18 13:32:11 -0500 | [diff] [blame] | 2074 | "sk_FragColor = half4(r, g, 1, 1); }", |
| 2075 | *SkSL::ShaderCapsFactory::Default(), |
| 2076 | "#version 400\n" |
| 2077 | "out vec4 sk_FragColor;\n" |
| 2078 | "void main() {\n" |
| 2079 | " float r, g;\n" |
| 2080 | " r = sqrt(1.0);\n" |
| 2081 | " g = sqrt(0.0);\n" |
| 2082 | " sk_FragColor = vec4(r, g, 1.0, 1.0);\n" |
| 2083 | "}\n"); |
| 2084 | test(r, |
| 2085 | "void main() {" |
| 2086 | "half r, g;" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 2087 | "(sqrt(1) > 0 ? r : g) = half(sqrt(1));" |
| 2088 | "(sqrt(0) > 0 ? r : g) = half(sqrt(0));" |
Ethan Nicholas | a583b81 | 2018-01-18 13:32:11 -0500 | [diff] [blame] | 2089 | "sk_FragColor = half4(r, g, 1, 1);" |
| 2090 | "}", |
| 2091 | *SkSL::ShaderCapsFactory::Default(), |
| 2092 | "#version 400\n" |
| 2093 | "out vec4 sk_FragColor;\n" |
| 2094 | "void main() {\n" |
| 2095 | " float r, g;\n" |
| 2096 | " sqrt(1.0) > 0.0 ? r : g = sqrt(1.0);\n" |
| 2097 | " sqrt(0.0) > 0.0 ? r : g = sqrt(0.0);\n" |
| 2098 | " sk_FragColor = vec4(r, g, 1.0, 1.0);\n" |
| 2099 | "}\n"); |
| 2100 | } |
| 2101 | |
Chris Dalton | c2d0dd6 | 2018-03-07 07:46:10 -0700 | [diff] [blame] | 2102 | DEF_TEST(SkSLIncompleteShortIntPrecision, r) { |
| 2103 | test(r, |
| 2104 | "uniform sampler2D tex;" |
| 2105 | "in float2 texcoord;" |
| 2106 | "in short2 offset;" |
| 2107 | "void main() {" |
| 2108 | " short scalar = offset.y;" |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 2109 | " sk_FragColor = sample(tex, texcoord + float2(offset * scalar));" |
Chris Dalton | c2d0dd6 | 2018-03-07 07:46:10 -0700 | [diff] [blame] | 2110 | "}", |
| 2111 | *SkSL::ShaderCapsFactory::UsesPrecisionModifiers(), |
| 2112 | "#version 400\n" |
| 2113 | "precision mediump float;\n" |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 2114 | "precision mediump sampler2D;\n" |
Chris Dalton | c2d0dd6 | 2018-03-07 07:46:10 -0700 | [diff] [blame] | 2115 | "out mediump vec4 sk_FragColor;\n" |
| 2116 | "uniform sampler2D tex;\n" |
| 2117 | "in highp vec2 texcoord;\n" |
| 2118 | "in mediump ivec2 offset;\n" |
| 2119 | "void main() {\n" |
| 2120 | " mediump int scalar = offset.y;\n" |
| 2121 | " sk_FragColor = texture(tex, texcoord + vec2(offset * scalar));\n" |
| 2122 | "}\n", |
| 2123 | SkSL::Program::kFragment_Kind); |
| 2124 | test(r, |
| 2125 | "uniform sampler2D tex;" |
| 2126 | "in float2 texcoord;" |
| 2127 | "in short2 offset;" |
| 2128 | "void main() {" |
| 2129 | " short scalar = offset.y;" |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 2130 | " sk_FragColor = sample(tex, texcoord + float2(offset * scalar));" |
Chris Dalton | c2d0dd6 | 2018-03-07 07:46:10 -0700 | [diff] [blame] | 2131 | "}", |
| 2132 | *SkSL::ShaderCapsFactory::IncompleteShortIntPrecision(), |
| 2133 | "#version 310es\n" |
| 2134 | "precision mediump float;\n" |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 2135 | "precision mediump sampler2D;\n" |
Chris Dalton | c2d0dd6 | 2018-03-07 07:46:10 -0700 | [diff] [blame] | 2136 | "out mediump vec4 sk_FragColor;\n" |
| 2137 | "uniform sampler2D tex;\n" |
| 2138 | "in highp vec2 texcoord;\n" |
| 2139 | "in highp ivec2 offset;\n" |
| 2140 | "void main() {\n" |
| 2141 | " highp int scalar = offset.y;\n" |
| 2142 | " sk_FragColor = texture(tex, texcoord + vec2(offset * scalar));\n" |
| 2143 | "}\n", |
| 2144 | SkSL::Program::kFragment_Kind); |
| 2145 | } |
| 2146 | |
Ethan Nicholas | c6a19f1 | 2018-03-29 16:46:56 -0400 | [diff] [blame] | 2147 | DEF_TEST(SkSLFrExp, r) { |
| 2148 | test(r, |
| 2149 | "void main() {" |
| 2150 | " int exp;" |
| 2151 | " float foo = frexp(0.5, exp);" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 2152 | " sk_FragColor = half4(exp);" |
Ethan Nicholas | c6a19f1 | 2018-03-29 16:46:56 -0400 | [diff] [blame] | 2153 | "}", |
| 2154 | *SkSL::ShaderCapsFactory::Default(), |
| 2155 | "#version 400\n" |
| 2156 | "out vec4 sk_FragColor;\n" |
| 2157 | "void main() {\n" |
| 2158 | " int exp;\n" |
| 2159 | " float foo = frexp(0.5, exp);\n" |
| 2160 | " sk_FragColor = vec4(float(exp));\n" |
| 2161 | "}\n"); |
| 2162 | } |
Adrienne Walker | ee8295c | 2018-08-21 10:56:30 -0700 | [diff] [blame] | 2163 | |
| 2164 | DEF_TEST(SkSLWorkaroundAddAndTrueToLoopCondition, r) { |
| 2165 | test(r, |
| 2166 | "void main() {" |
| 2167 | " int c = 0;" |
| 2168 | " for (int i = 0; i < 4 || c < 10; ++i) {" |
| 2169 | " c += 1;" |
| 2170 | " }" |
| 2171 | "}", |
| 2172 | *SkSL::ShaderCapsFactory::AddAndTrueToLoopCondition(), |
| 2173 | "#version 400\n" |
Adrienne Walker | ee8295c | 2018-08-21 10:56:30 -0700 | [diff] [blame] | 2174 | "void main() {\n" |
| 2175 | " int c = 0;\n" |
| 2176 | " for (int i = 0;(i < 4 || c < 10) && true; ++i) {\n" |
| 2177 | " c += 1;\n" |
| 2178 | " }\n" |
| 2179 | "}\n", |
| 2180 | SkSL::Program::kFragment_Kind |
| 2181 | ); |
| 2182 | } |
Adrienne Walker | c02165f | 2018-08-21 11:08:11 -0700 | [diff] [blame] | 2183 | |
| 2184 | DEF_TEST(SkSLWorkaroundUnfoldShortCircuitAsTernary, r) { |
| 2185 | test(r, |
| 2186 | "uniform bool x;" |
| 2187 | "uniform bool y;" |
| 2188 | "uniform int i;" |
| 2189 | "uniform int j;" |
| 2190 | "void main() {" |
| 2191 | " bool andXY = x && y;" |
| 2192 | " bool orXY = x || y;" |
| 2193 | " bool combo = (x && y) || (x || y);" |
| 2194 | " bool prec = (i + j == 3) && y;" |
| 2195 | " while (andXY && orXY && combo && prec) {" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 2196 | " sk_FragColor = half4(0);" |
Adrienne Walker | c02165f | 2018-08-21 11:08:11 -0700 | [diff] [blame] | 2197 | " break;" |
| 2198 | " }" |
| 2199 | "}", |
| 2200 | *SkSL::ShaderCapsFactory::UnfoldShortCircuitAsTernary(), |
| 2201 | "#version 400\n" |
| 2202 | "out vec4 sk_FragColor;\n" |
| 2203 | "uniform bool x;\n" |
| 2204 | "uniform bool y;\n" |
| 2205 | "uniform int i;\n" |
| 2206 | "uniform int j;\n" |
| 2207 | "void main() {\n" |
| 2208 | " bool andXY = x ? y : false;\n" |
| 2209 | " bool orXY = x ? true : y;\n" |
| 2210 | " bool combo = (x ? y : false) ? true : (x ? true : y);\n" |
| 2211 | " bool prec = i + j == 3 ? y : false;\n" |
| 2212 | " while (((andXY ? orXY : false) ? combo : false) ? prec : false) {\n" |
| 2213 | " sk_FragColor = vec4(0.0);\n" |
| 2214 | " break;\n" |
| 2215 | " }\n" |
| 2216 | "}\n", |
| 2217 | SkSL::Program::kFragment_Kind |
| 2218 | ); |
| 2219 | } |
Adrienne Walker | 92b161f | 2018-08-22 10:41:52 -0700 | [diff] [blame] | 2220 | |
| 2221 | DEF_TEST(SkSLWorkaroundEmulateAbsIntFunction, r) { |
| 2222 | test(r, |
| 2223 | "uniform int i;" |
| 2224 | "uniform float f;" |
| 2225 | "void main() {" |
| 2226 | " float output = abs(f) + abs(i);" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 2227 | " sk_FragColor = half4(half(output));" |
Adrienne Walker | 92b161f | 2018-08-22 10:41:52 -0700 | [diff] [blame] | 2228 | "}", |
| 2229 | *SkSL::ShaderCapsFactory::EmulateAbsIntFunction(), |
| 2230 | "#version 400\n" |
| 2231 | "int _absemulation(int x) {\n" |
| 2232 | " return x * sign(x);\n" |
| 2233 | "}\n" |
| 2234 | "out vec4 sk_FragColor;\n" |
| 2235 | "uniform int i;\n" |
| 2236 | "uniform float f;\n" |
| 2237 | "void main() {\n" |
| 2238 | " float output = abs(f) + float(_absemulation(i));\n" |
| 2239 | " sk_FragColor = vec4(output);\n" |
| 2240 | "}\n", |
| 2241 | SkSL::Program::kFragment_Kind |
| 2242 | ); |
| 2243 | } |
Adrienne Walker | 8b23ca6 | 2018-08-22 10:45:41 -0700 | [diff] [blame] | 2244 | |
| 2245 | DEF_TEST(SkSLWorkaroundRewriteDoWhileLoops, r) { |
| 2246 | test(r, |
| 2247 | "void main() {" |
| 2248 | " int i = 0;" |
| 2249 | " do {" |
| 2250 | " ++i;" |
| 2251 | " do {" |
| 2252 | " i++;" |
| 2253 | " } while (true);" |
| 2254 | " } while (i < 10);" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 2255 | " sk_FragColor = half4(i);" |
Adrienne Walker | 8b23ca6 | 2018-08-22 10:45:41 -0700 | [diff] [blame] | 2256 | "}", |
| 2257 | *SkSL::ShaderCapsFactory::RewriteDoWhileLoops(), |
| 2258 | "#version 400\n" |
| 2259 | "out vec4 sk_FragColor;\n" |
| 2260 | "void main() {\n" |
| 2261 | " int i = 0;\n" |
| 2262 | " bool _tmpLoopSeenOnce0 = false;\n" |
| 2263 | " while (true) {\n" |
| 2264 | " if (_tmpLoopSeenOnce0) {\n" |
| 2265 | " if (!(i < 10)) {\n" |
| 2266 | " break;\n" |
| 2267 | " }\n" |
| 2268 | " }\n" |
| 2269 | " _tmpLoopSeenOnce0 = true;\n" |
| 2270 | " {\n" |
| 2271 | " ++i;\n" |
| 2272 | " bool _tmpLoopSeenOnce1 = false;\n" |
| 2273 | " while (true) {\n" |
| 2274 | " if (_tmpLoopSeenOnce1) {\n" |
| 2275 | " if (!true) {\n" |
| 2276 | " break;\n" |
| 2277 | " }\n" |
| 2278 | " }\n" |
| 2279 | " _tmpLoopSeenOnce1 = true;\n" |
| 2280 | " {\n" |
| 2281 | " i++;\n" |
| 2282 | " }\n" |
| 2283 | " }\n" |
| 2284 | " }\n" |
| 2285 | " }\n" |
| 2286 | " sk_FragColor = vec4(float(i));\n" |
| 2287 | "}\n", |
| 2288 | SkSL::Program::kFragment_Kind |
| 2289 | ); |
| 2290 | } |
Adrienne Walker | 2f4c09b | 2018-08-22 16:04:57 -0700 | [diff] [blame] | 2291 | |
| 2292 | DEF_TEST(SkSLWorkaroundRemovePowWithConstantExponent, r) { |
| 2293 | test(r, |
| 2294 | "uniform float x;" |
| 2295 | "uniform float y;" |
| 2296 | "void main() {" |
| 2297 | " float z = pow(x + 1.0, y + 2.0);" |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 2298 | " sk_FragColor = half4(half(z));" |
Adrienne Walker | 2f4c09b | 2018-08-22 16:04:57 -0700 | [diff] [blame] | 2299 | "}", |
| 2300 | *SkSL::ShaderCapsFactory::RemovePowWithConstantExponent(), |
| 2301 | "#version 400\n" |
| 2302 | "out vec4 sk_FragColor;\n" |
| 2303 | "uniform float x;\n" |
| 2304 | "uniform float y;\n" |
| 2305 | "void main() {\n" |
| 2306 | " float z = exp2((y + 2.0) * log2(x + 1.0));\n" |
| 2307 | " sk_FragColor = vec4(z);\n" |
| 2308 | "}\n", |
| 2309 | SkSL::Program::kFragment_Kind |
| 2310 | ); |
| 2311 | } |
Ethan Nicholas | ac285b1 | 2019-02-12 16:05:18 -0500 | [diff] [blame] | 2312 | |
Ethan Nicholas | e455f65 | 2019-09-13 12:52:55 -0400 | [diff] [blame] | 2313 | DEF_TEST(SkSLSwizzleLTRB, r) { |
| 2314 | test(r, |
| 2315 | "void main() {" |
| 2316 | " sk_FragColor = sk_FragColor.BRTL;" |
| 2317 | "}", |
| 2318 | *SkSL::ShaderCapsFactory::RemovePowWithConstantExponent(), |
| 2319 | "#version 400\n" |
| 2320 | "out vec4 sk_FragColor;\n" |
| 2321 | "void main() {\n" |
| 2322 | " sk_FragColor = sk_FragColor.wzyx;\n" |
| 2323 | "}\n", |
| 2324 | SkSL::Program::kFragment_Kind |
| 2325 | ); |
| 2326 | } |
| 2327 | |
Ethan Nicholas | ac285b1 | 2019-02-12 16:05:18 -0500 | [diff] [blame] | 2328 | DEF_TEST(SkSLSwizzleConstants, r) { |
| 2329 | test(r, |
| 2330 | "void main() {" |
| 2331 | " half4 v = half4(half(sqrt(1)));" |
Ethan Nicholas | e455f65 | 2019-09-13 12:52:55 -0400 | [diff] [blame] | 2332 | " sk_FragColor = half4(v.x, 1, 1, 1);" |
| 2333 | " sk_FragColor = half4(v.1, 1, 1, 1);" |
| 2334 | " sk_FragColor = half4(v.xy, 1, 1);" |
| 2335 | " sk_FragColor = half4(v.x1, 1, 1);" |
| 2336 | " sk_FragColor = half4(v.0y, 1, 1);" |
| 2337 | " sk_FragColor = half4(v.10, 1, 1);" |
| 2338 | " sk_FragColor = half4(v.xyz, 1);" |
| 2339 | " sk_FragColor = half4(v.xy1, 1);" |
| 2340 | " sk_FragColor = half4(v.x0z, 1);" |
| 2341 | " sk_FragColor = half4(v.x10, 1);" |
| 2342 | " sk_FragColor = half4(v.1yz, 1);" |
| 2343 | " sk_FragColor = half4(v.0y1, 1);" |
| 2344 | " sk_FragColor = half4(v.11z, 1);" |
| 2345 | " sk_FragColor = half4(v.101, 1);" |
| 2346 | " sk_FragColor = v.xyzw;" |
| 2347 | " sk_FragColor = v.xyz1;" |
| 2348 | " sk_FragColor = v.xy0w;" |
| 2349 | " sk_FragColor = v.xy10;" |
| 2350 | " sk_FragColor = v.x1zw;" |
| 2351 | " sk_FragColor = v.x0z1;" |
| 2352 | " sk_FragColor = v.x11w;" |
| 2353 | " sk_FragColor = v.x101;" |
| 2354 | " sk_FragColor = v.1yzw;" |
| 2355 | " sk_FragColor = v.0yz1;" |
| 2356 | " sk_FragColor = v.0y1w;" |
| 2357 | " sk_FragColor = v.1y11;" |
| 2358 | " sk_FragColor = v.00zw;" |
| 2359 | " sk_FragColor = v.00z1;" |
| 2360 | " sk_FragColor = v.011w;" |
| 2361 | " sk_FragColor = v.1101;" |
Ethan Nicholas | ac285b1 | 2019-02-12 16:05:18 -0500 | [diff] [blame] | 2362 | "}", |
| 2363 | *SkSL::ShaderCapsFactory::RemovePowWithConstantExponent(), |
| 2364 | "#version 400\n" |
| 2365 | "out vec4 sk_FragColor;\n" |
| 2366 | "void main() {\n" |
| 2367 | " vec4 v = vec4(sqrt(1.0));\n" |
Ethan Nicholas | e455f65 | 2019-09-13 12:52:55 -0400 | [diff] [blame] | 2368 | " sk_FragColor = vec4(v.x, 1.0, 1.0, 1.0);\n" |
| 2369 | " sk_FragColor = vec4(1, 1.0, 1.0, 1.0);\n" |
| 2370 | " sk_FragColor = vec4(v.xy, 1.0, 1.0);\n" |
| 2371 | " sk_FragColor = vec4(vec2(v.x, 1), 1.0, 1.0);\n" |
| 2372 | " sk_FragColor = vec4(vec2(0, v.y), 1.0, 1.0);\n" |
| 2373 | " sk_FragColor = vec4(vec2(1, 0), 1.0, 1.0);\n" |
| 2374 | " sk_FragColor = vec4(v.xyz, 1.0);\n" |
| 2375 | " sk_FragColor = vec4(vec3(v.xy, 1), 1.0);\n" |
| 2376 | " sk_FragColor = vec4(vec3(v.xz, 0).xzy, 1.0);\n" |
| 2377 | " sk_FragColor = vec4(vec3(v.x, 1, 0), 1.0);\n" |
| 2378 | " sk_FragColor = vec4(vec3(1, v.yz), 1.0);\n" |
| 2379 | " sk_FragColor = vec4(vec3(v.y, 0, 1).yxz, 1.0);\n" |
| 2380 | " sk_FragColor = vec4(vec3(1, 1, v.z), 1.0);\n" |
| 2381 | " sk_FragColor = vec4(vec3(1, 0, 1), 1.0);\n" |
Ethan Nicholas | 409f6f0 | 2019-09-17 12:34:39 -0400 | [diff] [blame] | 2382 | " sk_FragColor = v;\n" |
Ethan Nicholas | ac285b1 | 2019-02-12 16:05:18 -0500 | [diff] [blame] | 2383 | " sk_FragColor = vec4(v.xyz, 1);\n" |
Ethan Nicholas | e455f65 | 2019-09-13 12:52:55 -0400 | [diff] [blame] | 2384 | " sk_FragColor = vec4(v.xyw, 0).xywz;\n" |
| 2385 | " sk_FragColor = vec4(v.xy, 1, 0);\n" |
| 2386 | " sk_FragColor = vec4(v.xzw, 1).xwyz;\n" |
| 2387 | " sk_FragColor = vec4(v.xz, 0, 1).xzyw;\n" |
| 2388 | " sk_FragColor = vec4(v.xw, 1, 1).xzwy;\n" |
| 2389 | " sk_FragColor = vec4(v.x, 1, 0, 1);\n" |
| 2390 | " sk_FragColor = vec4(1, v.yzw);\n" |
| 2391 | " sk_FragColor = vec4(v.yz, 0, 1).zxyw;\n" |
| 2392 | " sk_FragColor = vec4(v.yw, 0, 1).zxwy;\n" |
| 2393 | " sk_FragColor = vec4(v.y, 1, 1, 1).yxzw;\n" |
| 2394 | " sk_FragColor = vec4(0, 0, v.zw);\n" |
| 2395 | " sk_FragColor = vec4(v.z, 0, 0, 1).yzxw;\n" |
| 2396 | " sk_FragColor = vec4(0, 1, 1, v.w);\n" |
| 2397 | " sk_FragColor = vec4(1, 1, 0, 1);\n" |
Ethan Nicholas | ac285b1 | 2019-02-12 16:05:18 -0500 | [diff] [blame] | 2398 | "}\n", |
| 2399 | SkSL::Program::kFragment_Kind |
| 2400 | ); |
| 2401 | } |
Ethan Nicholas | d188c18 | 2019-06-10 15:55:38 -0400 | [diff] [blame] | 2402 | |
Ethan Nicholas | 409f6f0 | 2019-09-17 12:34:39 -0400 | [diff] [blame] | 2403 | DEF_TEST(SkSLSwizzleOpt, r) { |
| 2404 | test(r, |
| 2405 | "void main() {" |
| 2406 | " half v = half(sqrt(1));" |
| 2407 | " sk_FragColor = half4(v).rgba;" |
| 2408 | " sk_FragColor = half4(v).rgb0.abgr;" |
| 2409 | " sk_FragColor = half4(v).rgba.00ra;" |
| 2410 | " sk_FragColor = half4(v).rgba.rrra.00ra.11ab;" |
| 2411 | " sk_FragColor = half4(v).abga.gb11;" |
| 2412 | " sk_FragColor = half4(half3(v).rrr.000, 1);" |
| 2413 | " sk_FragColor = half4(half3(v).000.rrr, 1);" |
| 2414 | " sk_FragColor = half4(v).abgr.abgr;" |
| 2415 | " sk_FragColor = half4(half4(v).rrrr.bb, 1, 1);" |
| 2416 | " sk_FragColor = half4(half4(v).ba.grgr);" |
| 2417 | "}", |
| 2418 | *SkSL::ShaderCapsFactory::Default(), |
| 2419 | "#version 400\n" |
| 2420 | "out vec4 sk_FragColor;\n" |
| 2421 | "void main() {\n" |
| 2422 | " float v = sqrt(1.0);\n" |
| 2423 | " sk_FragColor = vec4(v);\n" |
| 2424 | " sk_FragColor = vec4(0, vec4(v).zyx);\n" |
| 2425 | " sk_FragColor = vec4(0, 0, vec4(v).xw);\n" |
| 2426 | " sk_FragColor = vec4(1, 1, vec4(v).wx);\n" |
| 2427 | " sk_FragColor = vec4(vec4(v).zy, 1, 1);\n" |
| 2428 | " sk_FragColor = vec4(vec3(0, 0, 0), 1.0);\n" |
| 2429 | " sk_FragColor = vec4(vec3(0, 0, 0), 1.0);\n" |
| 2430 | " sk_FragColor = vec4(v);\n" |
| 2431 | " sk_FragColor = vec4(vec4(v).xx, 1.0, 1.0);\n" |
| 2432 | " sk_FragColor = vec4(v).wzwz;\n" |
| 2433 | "}\n", |
| 2434 | SkSL::Program::kFragment_Kind |
| 2435 | ); |
| 2436 | } |
| 2437 | |
Ethan Nicholas | d188c18 | 2019-06-10 15:55:38 -0400 | [diff] [blame] | 2438 | DEF_TEST(SkSLNegatedVectorLiteral, r) { |
| 2439 | test(r, |
| 2440 | "void main() {" |
| 2441 | " if (half4(1) == half4(-half2(-1), half2(1)))" |
| 2442 | " sk_FragColor = half4(0, 1, 0, 1);" |
| 2443 | " else" |
| 2444 | " sk_FragColor = half4(1, 0, 0, 1);" |
| 2445 | "}", |
| 2446 | *SkSL::ShaderCapsFactory::Default(), |
| 2447 | "#version 400\n" |
| 2448 | "out vec4 sk_FragColor;\n" |
| 2449 | "void main() {\n" |
| 2450 | " sk_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 2451 | "}\n"); |
| 2452 | } |