blob: c1bf2bbbce4f68c35833781616f06a6e6b364abd [file] [log] [blame]
ethannicholasf789b382016-08-03 12:43:36 -07001/*
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
8#include "SkSLCompiler.h"
9
10#include "Test.h"
11
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050012#if SK_SUPPORT_GPU
Ethan Nicholas7ef4b742016-11-11 15:16:46 -050013
Ethan Nicholascb670962017-04-20 19:31:52 -040014// Note that the optimizer will aggressively kill dead code and substitute constants in place of
15// variables, so we have to jump through a few hoops to ensure that the code in these tests has the
16// necessary side-effects to remain live. In some cases we rely on the optimizer not (yet) being
17// smart enough to optimize around certain constructs; as the optimizer gets smarter it will
18// undoubtedly end up breaking some of these tests. That is a good thing, as long as the new code is
19// equivalent!
20
Ethan Nicholas941e7e22016-12-12 15:33:30 -050021static void test(skiatest::Reporter* r, const char* src, const SkSL::Program::Settings& settings,
Ethan Nicholasa51740c2017-02-07 14:53:32 -050022 const char* expected, SkSL::Program::Inputs* inputs,
23 SkSL::Program::Kind kind = SkSL::Program::kFragment_Kind) {
ethannicholasf789b382016-08-03 12:43:36 -070024 SkSL::Compiler compiler;
Ethan Nicholas0df1b042017-03-31 13:56:23 -040025 SkSL::String output;
Ethan Nicholasa51740c2017-02-07 14:53:32 -050026 std::unique_ptr<SkSL::Program> program = compiler.convertProgram(kind, SkString(src), settings);
Ethan Nicholas941e7e22016-12-12 15:33:30 -050027 if (!program) {
ethannicholasf789b382016-08-03 12:43:36 -070028 SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().c_str());
29 }
Ethan Nicholas941e7e22016-12-12 15:33:30 -050030 REPORTER_ASSERT(r, program);
31 *inputs = program->fInputs;
32 REPORTER_ASSERT(r, compiler.toGLSL(*program, &output));
33 if (program) {
Ethan Nicholas0df1b042017-03-31 13:56:23 -040034 SkSL::String skExpected(expected);
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050035 if (output != skExpected) {
Ethan Nicholas941e7e22016-12-12 15:33:30 -050036 SkDebugf("GLSL MISMATCH:\nsource:\n%s\n\nexpected:\n'%s'\n\nreceived:\n'%s'", src,
ethannicholasf789b382016-08-03 12:43:36 -070037 expected, output.c_str());
38 }
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050039 REPORTER_ASSERT(r, output == skExpected);
ethannicholasf789b382016-08-03 12:43:36 -070040 }
41}
42
Ethan Nicholas941e7e22016-12-12 15:33:30 -050043static void test(skiatest::Reporter* r, const char* src, const GrShaderCaps& caps,
Ethan Nicholasa51740c2017-02-07 14:53:32 -050044 const char* expected, SkSL::Program::Kind kind = SkSL::Program::kFragment_Kind) {
Ethan Nicholas941e7e22016-12-12 15:33:30 -050045 SkSL::Program::Settings settings;
46 settings.fCaps = &caps;
47 SkSL::Program::Inputs inputs;
Ethan Nicholasa51740c2017-02-07 14:53:32 -050048 test(r, src, settings, expected, &inputs, kind);
Ethan Nicholas941e7e22016-12-12 15:33:30 -050049}
50
ethannicholasf789b382016-08-03 12:43:36 -070051DEF_TEST(SkSLHelloWorld, r) {
ethannicholasf789b382016-08-03 12:43:36 -070052 test(r,
Ethan Nicholas5af9ea32017-07-28 15:19:46 -040053 "void main() { sk_FragColor = float4(0.75); }",
Brian Salomonf1dd6772016-11-29 15:27:52 -050054 *SkSL::ShaderCapsFactory::Default(),
ethannicholasf789b382016-08-03 12:43:36 -070055 "#version 400\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -050056 "out vec4 sk_FragColor;\n"
ethannicholasf789b382016-08-03 12:43:36 -070057 "void main() {\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -050058 " sk_FragColor = vec4(0.75);\n"
ethannicholasf789b382016-08-03 12:43:36 -070059 "}\n");
60}
61
62DEF_TEST(SkSLControl, r) {
ethannicholasf789b382016-08-03 12:43:36 -070063 test(r,
ethannicholasf789b382016-08-03 12:43:36 -070064 "void main() {"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -040065 "if (sqrt(2) > 5) { sk_FragColor = float4(0.75); } else { discard; }"
ethannicholasf789b382016-08-03 12:43:36 -070066 "int i = 0;"
Ethan Nicholascb670962017-04-20 19:31:52 -040067 "while (i < 10) { sk_FragColor *= 0.5; i++; }"
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050068 "do { sk_FragColor += 0.01; } while (sk_FragColor.x < 0.75);"
ethannicholasf789b382016-08-03 12:43:36 -070069 "for (int i = 0; i < 10; i++) {"
Ethan Nicholas86a43402017-01-19 13:32:00 -050070 "if (i % 2 == 1) break; else continue;"
ethannicholasf789b382016-08-03 12:43:36 -070071 "}"
72 "return;"
73 "}",
Brian Salomonf1dd6772016-11-29 15:27:52 -050074 *SkSL::ShaderCapsFactory::Default(),
ethannicholasf789b382016-08-03 12:43:36 -070075 "#version 400\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -050076 "out vec4 sk_FragColor;\n"
ethannicholasf789b382016-08-03 12:43:36 -070077 "void main() {\n"
ethannicholas08a92112016-11-09 13:26:45 -080078 " if (sqrt(2.0) > 5.0) {\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -050079 " sk_FragColor = vec4(0.75);\n"
ethannicholasf789b382016-08-03 12:43:36 -070080 " } else {\n"
81 " discard;\n"
82 " }\n"
83 " int i = 0;\n"
Ethan Nicholascb670962017-04-20 19:31:52 -040084 " while (i < 10) {\n"
85 " sk_FragColor *= 0.5;\n"
86 " i++;\n"
87 " }\n"
ethannicholasf789b382016-08-03 12:43:36 -070088 " do {\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -050089 " sk_FragColor += 0.01;\n"
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050090 " } while (sk_FragColor.x < 0.75);\n"
ethannicholasf789b382016-08-03 12:43:36 -070091 " for (int i = 0;i < 10; i++) {\n"
Ethan Nicholas86a43402017-01-19 13:32:00 -050092 " if (i % 2 == 1) break; else continue;\n"
ethannicholasf789b382016-08-03 12:43:36 -070093 " }\n"
94 " return;\n"
95 "}\n");
96}
97
98DEF_TEST(SkSLFunctions, r) {
ethannicholasf789b382016-08-03 12:43:36 -070099 test(r,
ethannicholasf789b382016-08-03 12:43:36 -0700100 "float foo(float v[2]) { return v[0] * v[1]; }"
101 "void bar(inout float x) { float y[2], z; y[0] = x; y[1] = x * 2; z = foo(y); x = z; }"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400102 "void main() { float x = 10; bar(x); sk_FragColor = float4(x); }",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500103 *SkSL::ShaderCapsFactory::Default(),
ethannicholasf789b382016-08-03 12:43:36 -0700104 "#version 400\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500105 "out vec4 sk_FragColor;\n"
Ethan Nicholasc6f5e102017-03-31 14:53:17 -0400106 "float foo(float v[2]) {\n"
ethannicholasf789b382016-08-03 12:43:36 -0700107 " return v[0] * v[1];\n"
108 "}\n"
109 "void bar(inout float x) {\n"
110 " float y[2], z;\n"
111 " y[0] = x;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700112 " y[1] = x * 2.0;\n"
ethannicholasf789b382016-08-03 12:43:36 -0700113 " z = foo(y);\n"
114 " x = z;\n"
115 "}\n"
116 "void main() {\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700117 " float x = 10.0;\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400118 " bar(x);\n"
119 " sk_FragColor = vec4(x);\n"
ethannicholasf789b382016-08-03 12:43:36 -0700120 "}\n");
121}
122
123DEF_TEST(SkSLOperators, r) {
ethannicholasf789b382016-08-03 12:43:36 -0700124 test(r,
125 "void main() {"
126 "float x = 1, y = 2;"
127 "int z = 3;"
Ethan Nicholas86a43402017-01-19 13:32:00 -0500128 "x = x - x + y * z * x * (y - z);"
ethannicholasf789b382016-08-03 12:43:36 -0700129 "y = x / y / z;"
130 "z = (z / 2 % 3 << 4) >> 2 << 1;"
ethannicholas08a92112016-11-09 13:26:45 -0800131 "bool b = (x > 4) == x < 2 || 2 >= sqrt(2) && y <= z;"
ethannicholasf789b382016-08-03 12:43:36 -0700132 "x += 12;"
133 "x -= 12;"
134 "x *= y /= z = 10;"
135 "b ||= false;"
136 "b &&= true;"
137 "b ^^= false;"
138 "z |= 0;"
139 "z &= -1;"
140 "z ^= 0;"
141 "z >>= 2;"
142 "z <<= 4;"
143 "z %= 5;"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400144 "x = (float2(sqrt(1)) , 6);"
145 "z = (float2(sqrt(1)) , 6);"
ethannicholasf789b382016-08-03 12:43:36 -0700146 "}",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500147 *SkSL::ShaderCapsFactory::Default(),
ethannicholasf789b382016-08-03 12:43:36 -0700148 "#version 400\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500149 "out vec4 sk_FragColor;\n"
ethannicholasf789b382016-08-03 12:43:36 -0700150 "void main() {\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700151 " float x = 1.0, y = 2.0;\n"
ethannicholasf789b382016-08-03 12:43:36 -0700152 " int z = 3;\n"
Ethan Nicholas86a43402017-01-19 13:32:00 -0500153 " x = -6.0;\n"
154 " y = -1.0;\n"
155 " z = 8;\n"
156 " bool b = false == true || 2.0 >= sqrt(2.0) && true;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700157 " x += 12.0;\n"
158 " x -= 12.0;\n"
ethannicholasf789b382016-08-03 12:43:36 -0700159 " 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 Nicholas4b330df2017-05-17 10:52:55 -0400169 " x = float((vec2(sqrt(1.0)) , 6));\n"
170 " z = (vec2(sqrt(1.0)) , 6);\n"
ethannicholasf789b382016-08-03 12:43:36 -0700171 "}\n");
172}
173
174DEF_TEST(SkSLMatrices, r) {
ethannicholasf789b382016-08-03 12:43:36 -0700175 test(r,
176 "void main() {"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400177 "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);"
182 "sk_FragColor = float4(z[0].x, v1 + v2);"
ethannicholasf789b382016-08-03 12:43:36 -0700183 "}",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500184 *SkSL::ShaderCapsFactory::Default(),
ethannicholasf789b382016-08-03 12:43:36 -0700185 "#version 400\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500186 "out vec4 sk_FragColor;\n"
ethannicholasf789b382016-08-03 12:43:36 -0700187 "void main() {\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400188 " mat3x4 z = mat2x4(1.0) * mat3x2(1.0, 0.0, 0.0, 1.0, vec2(2.0, 2.0));\n"
Ethan Nicholasfe53e582017-04-27 16:24:51 -0400189 " vec3 v1 = mat3(1.0) * vec3(2.0);\n"
190 " vec3 v2 = vec3(2.0) * mat3(1.0);\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400191 " sk_FragColor = vec4(z[0].x, v1 + v2);\n"
ethannicholasf789b382016-08-03 12:43:36 -0700192 "}\n");
193}
194
195DEF_TEST(SkSLInterfaceBlock, r) {
ethannicholasf789b382016-08-03 12:43:36 -0700196 test(r,
197 "uniform testBlock {"
198 "float x;"
199 "float y[2];"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400200 "layout(binding=12) float3x2 z;"
ethannicholasf789b382016-08-03 12:43:36 -0700201 "bool w;"
202 "};"
203 "void main() {"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400204 " sk_FragColor = float4(x, y[0], y[1], 0);"
ethannicholasf789b382016-08-03 12:43:36 -0700205 "}",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500206 *SkSL::ShaderCapsFactory::Default(),
ethannicholasf789b382016-08-03 12:43:36 -0700207 "#version 400\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500208 "out vec4 sk_FragColor;\n"
ethannicholasf789b382016-08-03 12:43:36 -0700209 "uniform testBlock {\n"
210 " float x;\n"
211 " float[2] y;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700212 " layout (binding = 12) mat3x2 z;\n"
ethannicholasf789b382016-08-03 12:43:36 -0700213 " bool w;\n"
214 "};\n"
215 "void main() {\n"
Ethan Nicholas50afc172017-02-16 14:49:57 -0500216 " sk_FragColor = vec4(x, y[0], y[1], 0.0);\n"
217 "}\n");
218 test(r,
219 "uniform testBlock {"
220 "float x;"
221 "} test;"
222 "void main() {"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400223 " sk_FragColor = float4(test.x);"
Ethan Nicholas50afc172017-02-16 14:49:57 -0500224 "}",
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 {"
236 "float x;"
237 "} test[2];"
238 "void main() {"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400239 " sk_FragColor = float4(test[1].x);"
Ethan Nicholas50afc172017-02-16 14:49:57 -0500240 "}",
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"
ethannicholasf789b382016-08-03 12:43:36 -0700249 "}\n");
250}
251
252DEF_TEST(SkSLStructs, r) {
ethannicholasf789b382016-08-03 12:43:36 -0700253 test(r,
254 "struct A {"
255 "int x;"
256 "int y;"
257 "} a1, a2;"
258 "A a3;"
259 "struct B {"
260 "float x;"
261 "float y[2];"
262 "layout(binding=1) A z;"
263 "};"
264 "B b1, b2, b3;"
265 "void main() {"
266 "}",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500267 *SkSL::ShaderCapsFactory::Default(),
ethannicholasf789b382016-08-03 12:43:36 -0700268 "#version 400\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500269 "out vec4 sk_FragColor;\n"
ethannicholasf789b382016-08-03 12:43:36 -0700270 "struct A {\n"
271 " int x;\n"
272 " int y;\n"
Ethan Nicholas19671772016-11-28 16:30:17 -0500273 "} a1, a2;\n"
ethannicholasf789b382016-08-03 12:43:36 -0700274 "A a3;\n"
275 "struct B {\n"
276 " float x;\n"
277 " float[2] y;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700278 " layout (binding = 1) A z;\n"
Ethan Nicholas19671772016-11-28 16:30:17 -0500279 "} b1, b2, b3;\n"
ethannicholasf789b382016-08-03 12:43:36 -0700280 "void main() {\n"
281 "}\n");
ethannicholas5961bc92016-10-12 06:39:56 -0700282}
ethannicholasf789b382016-08-03 12:43:36 -0700283
ethannicholas5961bc92016-10-12 06:39:56 -0700284DEF_TEST(SkSLVersion, r) {
ethannicholas5961bc92016-10-12 06:39:56 -0700285 test(r,
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400286 "in float test; void main() { sk_FragColor = float4(0.75); }",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500287 *SkSL::ShaderCapsFactory::Version450Core(),
ethannicholas5961bc92016-10-12 06:39:56 -0700288 "#version 450 core\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500289 "out vec4 sk_FragColor;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700290 "in float test;\n"
291 "void main() {\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500292 " sk_FragColor = vec4(0.75);\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700293 "}\n");
ethannicholas5961bc92016-10-12 06:39:56 -0700294 test(r,
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400295 "in float test; void main() { sk_FragColor = float4(0.75); }",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500296 *SkSL::ShaderCapsFactory::Version110(),
ethannicholas5961bc92016-10-12 06:39:56 -0700297 "#version 110\n"
298 "varying float test;\n"
299 "void main() {\n"
300 " gl_FragColor = vec4(0.75);\n"
301 "}\n");
302}
303
Leon Scroggins857cb972016-11-11 18:44:37 +0000304DEF_TEST(SkSLUsesPrecisionModifiers, r) {
Leon Scroggins857cb972016-11-11 18:44:37 +0000305 test(r,
Ethan Nicholascb670962017-04-20 19:31:52 -0400306 "void main() { float x = 0.75; highp float y = 1; x++; y++;"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400307 "sk_FragColor.rg = float2(x, y); }",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500308 *SkSL::ShaderCapsFactory::Default(),
Leon Scroggins857cb972016-11-11 18:44:37 +0000309 "#version 400\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500310 "out vec4 sk_FragColor;\n"
Leon Scroggins857cb972016-11-11 18:44:37 +0000311 "void main() {\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700312 " float x = 0.75;\n"
313 " float y = 1.0;\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400314 " x++;\n"
315 " y++;\n"
316 " sk_FragColor.xy = vec2(x, y);\n"
317 "}\n");
ethannicholas5961bc92016-10-12 06:39:56 -0700318 test(r,
Ethan Nicholasdcba08e2017-08-02 10:52:54 -0400319 "void main() { float x = 0.75; half y = 1; x++; y++;"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400320 "sk_FragColor.rg = float2(x, y); }",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500321 *SkSL::ShaderCapsFactory::UsesPrecisionModifiers(),
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500322 "#version 400\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700323 "precision highp float;\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500324 "out mediump vec4 sk_FragColor;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700325 "void main() {\n"
326 " float x = 0.75;\n"
Ethan Nicholasdcba08e2017-08-02 10:52:54 -0400327 " mediump float y = 1.0;\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400328 " x++;\n"
329 " y++;\n"
330 " sk_FragColor.xy = vec2(x, y);\n"
331 "}\n");
ethannicholas5961bc92016-10-12 06:39:56 -0700332}
333
334DEF_TEST(SkSLMinAbs, r) {
335 test(r,
336 "void main() {"
337 "float x = -5;"
Ethan Nicholascb670962017-04-20 19:31:52 -0400338 "sk_FragColor.r = min(abs(x), 6);"
ethannicholas5961bc92016-10-12 06:39:56 -0700339 "}",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500340 *SkSL::ShaderCapsFactory::Default(),
ethannicholas5961bc92016-10-12 06:39:56 -0700341 "#version 400\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500342 "out vec4 sk_FragColor;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700343 "void main() {\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400344 " sk_FragColor.x = min(abs(-5.0), 6.0);\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700345 "}\n");
346
ethannicholas5961bc92016-10-12 06:39:56 -0700347 test(r,
348 "void main() {"
349 "float x = -5.0;"
Ethan Nicholascb670962017-04-20 19:31:52 -0400350 "sk_FragColor.r = min(abs(x), 6.0);"
ethannicholas5961bc92016-10-12 06:39:56 -0700351 "}",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500352 *SkSL::ShaderCapsFactory::CannotUseMinAndAbsTogether(),
ethannicholas5961bc92016-10-12 06:39:56 -0700353 "#version 400\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500354 "out vec4 sk_FragColor;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700355 "void main() {\n"
356 " float minAbsHackVar0;\n"
357 " float minAbsHackVar1;\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400358 " sk_FragColor.x = ((minAbsHackVar0 = abs(-5.0)) < (minAbsHackVar1 = 6.0) ? "
359 "minAbsHackVar0 : minAbsHackVar1);\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700360 "}\n");
361}
362
Florin Malita3b30c4f2017-08-08 15:47:35 -0400363DEF_TEST(SkSLFractNegative, r) {
364 static constexpr char input[] =
365 "void main() {"
366 "float x = -42.0;"
367 "sk_FragColor.r = fract(x);"
368 "}";
369 static constexpr char output_default[] =
370 "#version 400\n"
371 "out vec4 sk_FragColor;\n"
372 "void main() {\n"
373 " sk_FragColor.x = fract(-42.0);\n"
374 "}\n";
375 static constexpr char output_workaround[] =
376 "#version 400\n"
377 "out vec4 sk_FragColor;\n"
378 "void main() {\n"
379 " sk_FragColor.x = (0.5 - sign(-42.0) * (0.5 - fract(abs(-42.0))));\n"
380 "}\n";
381
382 test(r, input, *SkSL::ShaderCapsFactory::Default(), output_default);
383 test(r, input, *SkSL::ShaderCapsFactory::CannotUseFractForNegativeValues(), output_workaround);
384}
385
ethannicholasad146f62016-10-14 06:40:02 -0700386DEF_TEST(SkSLNegatedAtan, r) {
387 test(r,
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400388 "void main() { float2 x = float2(sqrt(2)); sk_FragColor.r = atan(x.x, -x.y); }",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500389 *SkSL::ShaderCapsFactory::Default(),
ethannicholasad146f62016-10-14 06:40:02 -0700390 "#version 400\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500391 "out vec4 sk_FragColor;\n"
ethannicholasad146f62016-10-14 06:40:02 -0700392 "void main() {\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400393 " vec2 x = vec2(sqrt(2.0));\n"
394 " sk_FragColor.x = atan(x.x, -x.y);\n"
ethannicholasad146f62016-10-14 06:40:02 -0700395 "}\n");
ethannicholasad146f62016-10-14 06:40:02 -0700396 test(r,
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400397 "void main() { float2 x = float2(sqrt(2)); sk_FragColor.r = atan(x.x, -x.y); }",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500398 *SkSL::ShaderCapsFactory::MustForceNegatedAtanParamToFloat(),
ethannicholasad146f62016-10-14 06:40:02 -0700399 "#version 400\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500400 "out vec4 sk_FragColor;\n"
ethannicholasad146f62016-10-14 06:40:02 -0700401 "void main() {\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400402 " vec2 x = vec2(sqrt(2.0));\n"
403 " sk_FragColor.x = atan(x.x, -1.0 * x.y);\n"
ethannicholasad146f62016-10-14 06:40:02 -0700404 "}\n");
405}
406
ethannicholas5961bc92016-10-12 06:39:56 -0700407DEF_TEST(SkSLModifiersDeclaration, r) {
408 test(r,
409 "layout(blend_support_all_equations) out;"
410 "void main() { }",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500411 *SkSL::ShaderCapsFactory::Default(),
ethannicholas5961bc92016-10-12 06:39:56 -0700412 "#version 400\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500413 "out vec4 sk_FragColor;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700414 "layout (blend_support_all_equations) out ;\n"
415 "void main() {\n"
416 "}\n");
417}
418
419DEF_TEST(SkSLHex, r) {
420 test(r,
421 "void main() {"
422 "int i1 = 0x0;"
Ethan Nicholascb670962017-04-20 19:31:52 -0400423 "i1++;"
ethannicholas5961bc92016-10-12 06:39:56 -0700424 "int i2 = 0x1234abcd;"
Ethan Nicholascb670962017-04-20 19:31:52 -0400425 "i2++;"
ethannicholas5961bc92016-10-12 06:39:56 -0700426 "int i3 = 0x7fffffff;"
Ethan Nicholascb670962017-04-20 19:31:52 -0400427 "i3++;"
ethannicholas5961bc92016-10-12 06:39:56 -0700428 "int i4 = 0xffffffff;"
Ethan Nicholascb670962017-04-20 19:31:52 -0400429 "i4++;"
ethannicholas5961bc92016-10-12 06:39:56 -0700430 "int i5 = -0xbeef;"
Ethan Nicholascb670962017-04-20 19:31:52 -0400431 "i5++;"
ethannicholas5961bc92016-10-12 06:39:56 -0700432 "uint u1 = 0x0;"
Ethan Nicholascb670962017-04-20 19:31:52 -0400433 "u1++;"
ethannicholas5961bc92016-10-12 06:39:56 -0700434 "uint u2 = 0x1234abcd;"
Ethan Nicholascb670962017-04-20 19:31:52 -0400435 "u2++;"
ethannicholas5961bc92016-10-12 06:39:56 -0700436 "uint u3 = 0x7fffffff;"
Ethan Nicholascb670962017-04-20 19:31:52 -0400437 "u3++;"
ethannicholas5961bc92016-10-12 06:39:56 -0700438 "uint u4 = 0xffffffff;"
Ethan Nicholascb670962017-04-20 19:31:52 -0400439 "u4++;"
ethannicholas5961bc92016-10-12 06:39:56 -0700440 "}",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500441 *SkSL::ShaderCapsFactory::Default(),
ethannicholas5961bc92016-10-12 06:39:56 -0700442 "#version 400\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500443 "out vec4 sk_FragColor;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700444 "void main() {\n"
445 " int i1 = 0;\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400446 " i1++;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700447 " int i2 = 305441741;\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400448 " i2++;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700449 " int i3 = 2147483647;\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400450 " i3++;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700451 " int i4 = -1;\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400452 " i4++;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700453 " int i5 = -48879;\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400454 " i5++;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700455 " uint u1 = 0u;\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400456 " u1++;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700457 " uint u2 = 305441741u;\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400458 " u2++;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700459 " uint u3 = 2147483647u;\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400460 " u3++;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700461 " uint u4 = 4294967295u;\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400462 " u4++;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700463 "}\n");
464}
465
Ethan Nicholas4578a8e2016-11-01 11:57:42 -0400466DEF_TEST(SkSLVectorConstructors, r) {
467 test(r,
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400468 "float2 v1 = float2(1);"
469 "float2 v2 = float2(1, 2);"
470 "float2 v3 = float2(float2(1));"
471 "float3 v4 = float3(float2(1), 1.0);"
472 "int2 v5 = int2(1);"
473 "int2 v6 = int2(float2(1, 2));"
474 "float2 v7 = float2(int2(1, 2));",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500475 *SkSL::ShaderCapsFactory::Default(),
Ethan Nicholas4578a8e2016-11-01 11:57:42 -0400476 "#version 400\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500477 "out vec4 sk_FragColor;\n"
Ethan Nicholas4578a8e2016-11-01 11:57:42 -0400478 "vec2 v1 = vec2(1.0);\n"
479 "vec2 v2 = vec2(1.0, 2.0);\n"
480 "vec2 v3 = vec2(1.0);\n"
Ethan Nicholas84645e32017-02-09 13:57:14 -0500481 "vec3 v4 = vec3(vec2(1.0), 1.0);\n"
482 "ivec2 v5 = ivec2(1);\n"
483 "ivec2 v6 = ivec2(vec2(1.0, 2.0));\n"
484 "vec2 v7 = vec2(ivec2(1, 2));\n");
Ethan Nicholas4578a8e2016-11-01 11:57:42 -0400485}
486
ethannicholas5961bc92016-10-12 06:39:56 -0700487DEF_TEST(SkSLArrayConstructors, r) {
488 test(r,
489 "float test1[] = float[](1, 2, 3, 4);"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400490 "float2 test2[] = float2[](float2(1, 2), float2(3, 4));"
491 "float4x4 test3[] = float4x4[]();",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500492 *SkSL::ShaderCapsFactory::Default(),
ethannicholas5961bc92016-10-12 06:39:56 -0700493 "#version 400\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500494 "out vec4 sk_FragColor;\n"
ethannicholas5961bc92016-10-12 06:39:56 -0700495 "float test1[] = float[](1.0, 2.0, 3.0, 4.0);\n"
496 "vec2 test2[] = vec2[](vec2(1.0, 2.0), vec2(3.0, 4.0));\n"
497 "mat4 test3[] = mat4[]();\n");
ethannicholasf789b382016-08-03 12:43:36 -0700498}
ethannicholasddb37d62016-10-20 09:54:00 -0700499
500DEF_TEST(SkSLDerivatives, r) {
501 test(r,
Ethan Nicholascb670962017-04-20 19:31:52 -0400502 "void main() { sk_FragColor.r = dFdx(1); }",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500503 *SkSL::ShaderCapsFactory::Default(),
ethannicholasddb37d62016-10-20 09:54:00 -0700504 "#version 400\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500505 "out vec4 sk_FragColor;\n"
ethannicholasddb37d62016-10-20 09:54:00 -0700506 "void main() {\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400507 " sk_FragColor.x = dFdx(1.0);\n"
ethannicholasddb37d62016-10-20 09:54:00 -0700508 "}\n");
ethannicholasddb37d62016-10-20 09:54:00 -0700509 test(r,
Ethan Nicholascb670962017-04-20 19:31:52 -0400510 "void main() { sk_FragColor.r = 1; }",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500511 *SkSL::ShaderCapsFactory::ShaderDerivativeExtensionString(),
ethannicholasddb37d62016-10-20 09:54:00 -0700512 "#version 400\n"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400513 "precision highp float;\n"
514 "out mediump vec4 sk_FragColor;\n"
ethannicholasddb37d62016-10-20 09:54:00 -0700515 "void main() {\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400516 " sk_FragColor.x = 1.0;\n"
ethannicholasddb37d62016-10-20 09:54:00 -0700517 "}\n");
518 test(r,
Ethan Nicholascb670962017-04-20 19:31:52 -0400519 "void main() { sk_FragColor.r = dFdx(1); }",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500520 *SkSL::ShaderCapsFactory::ShaderDerivativeExtensionString(),
ethannicholasddb37d62016-10-20 09:54:00 -0700521 "#version 400\n"
522 "#extension GL_OES_standard_derivatives : require\n"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400523 "precision highp float;\n"
524 "out mediump vec4 sk_FragColor;\n"
ethannicholasddb37d62016-10-20 09:54:00 -0700525 "void main() {\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400526 " sk_FragColor.x = dFdx(1.0);\n"
ethannicholasddb37d62016-10-20 09:54:00 -0700527 "}\n");
528}
ethannicholas08a92112016-11-09 13:26:45 -0800529
Ethan Nicholasc81d22f2017-04-26 11:25:18 -0400530
531DEF_TEST(SkSLIntFolding, r) {
ethannicholas08a92112016-11-09 13:26:45 -0800532 test(r,
533 "void main() {"
Ethan Nicholasc81d22f2017-04-26 11:25:18 -0400534 "sk_FragColor.r = 32 + 2;"
535 "sk_FragColor.r = 32 - 2;"
536 "sk_FragColor.r = 32 * 2;"
537 "sk_FragColor.r = 32 / 2;"
538 "sk_FragColor.r = 12 | 6;"
539 "sk_FragColor.r = 254 & 7;"
540 "sk_FragColor.r = 2 ^ 7;"
541 "sk_FragColor.r = 1 << 4;"
542 "sk_FragColor.r = 128 >> 2;"
543 "sk_FragColor.r = -1 == -1 ? 1 : -1;"
544 "sk_FragColor.r = -1 == -2 ? 2 : -2;"
545 "sk_FragColor.r = 0 != 1 ? 3 : -3;"
546 "sk_FragColor.r = 0 != 0 ? 4 : -4;"
547 "sk_FragColor.r = 6 > 5 ? 5 : -5;"
548 "sk_FragColor.r = 6 > 6 ? 6 : -6;"
549 "sk_FragColor.r = -1 < 0 ? 7 : -7;"
550 "sk_FragColor.r = 1 < 0 ? 8 : -8;"
551 "sk_FragColor.r = 6 >= 6 ? 9 : -9;"
552 "sk_FragColor.r = 6 >= 7 ? 10 : -10;"
553 "sk_FragColor.r = 6 <= 6 ? 11 : -11;"
554 "sk_FragColor.r = 6 <= 5 ? 12 : -12;"
Ethan Nicholasfe53e582017-04-27 16:24:51 -0400555 "sk_FragColor.r = int(sqrt(1)) + 0;"
556 "sk_FragColor.r = 0 + int(sqrt(2));"
557 "sk_FragColor.r = int(sqrt(3)) - 0;"
558 "sk_FragColor.r = int(sqrt(4)) * 0;"
559 "sk_FragColor.r = int(sqrt(5)) * 1;"
560 "sk_FragColor.r = 1 * int(sqrt(6));"
561 "sk_FragColor.r = 0 * int(sqrt(7));"
562 "sk_FragColor.r = int(sqrt(8)) / 1;"
563 "sk_FragColor.r = 0 / int(sqrt(9));"
564 "int x = int(sqrt(2));"
565 "x += 1;"
566 "x += 0;"
567 "x -= 1;"
568 "x -= 0;"
569 "x *= 1;"
570 "x *= 2;"
571 "x /= 1;"
572 "x /= 2;"
573 "sk_FragColor.r = x;"
ethannicholas08a92112016-11-09 13:26:45 -0800574 "}",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500575 *SkSL::ShaderCapsFactory::Default(),
ethannicholas08a92112016-11-09 13:26:45 -0800576 "#version 400\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500577 "out vec4 sk_FragColor;\n"
ethannicholas08a92112016-11-09 13:26:45 -0800578 "void main() {\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400579 " sk_FragColor.x = 34.0;\n"
580 " sk_FragColor.x = 30.0;\n"
581 " sk_FragColor.x = 64.0;\n"
582 " sk_FragColor.x = 16.0;\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400583 " sk_FragColor.x = 14.0;\n"
584 " sk_FragColor.x = 6.0;\n"
585 " sk_FragColor.x = 5.0;\n"
586 " sk_FragColor.x = 16.0;\n"
587 " sk_FragColor.x = 32.0;\n"
588 " sk_FragColor.x = 1.0;\n"
Ethan Nicholasc81d22f2017-04-26 11:25:18 -0400589 " sk_FragColor.x = -2.0;\n"
590 " sk_FragColor.x = 3.0;\n"
591 " sk_FragColor.x = -4.0;\n"
592 " sk_FragColor.x = 5.0;\n"
593 " sk_FragColor.x = -6.0;\n"
594 " sk_FragColor.x = 7.0;\n"
595 " sk_FragColor.x = -8.0;\n"
596 " sk_FragColor.x = 9.0;\n"
597 " sk_FragColor.x = -10.0;\n"
598 " sk_FragColor.x = 11.0;\n"
599 " sk_FragColor.x = -12.0;\n"
Ethan Nicholasfe53e582017-04-27 16:24:51 -0400600 " sk_FragColor.x = float(int(sqrt(1.0)));\n"
601 " sk_FragColor.x = float(int(sqrt(2.0)));\n"
602 " sk_FragColor.x = float(int(sqrt(3.0)));\n"
603 " sk_FragColor.x = 0.0;\n"
604 " sk_FragColor.x = float(int(sqrt(5.0)));\n"
605 " sk_FragColor.x = float(int(sqrt(6.0)));\n"
606 " sk_FragColor.x = 0.0;\n"
607 " sk_FragColor.x = float(int(sqrt(8.0)));\n"
608 " sk_FragColor.x = 0.0;\n"
609 " int x = int(sqrt(2.0));\n"
610 " x += 1;\n"
611 " x -= 1;\n"
612 " x *= 2;\n"
613 " x /= 2;\n"
614 " sk_FragColor.x = float(x);\n"
Ethan Nicholasc81d22f2017-04-26 11:25:18 -0400615 "}\n");
616}
617
618DEF_TEST(SkSLFloatFolding, r) {
619 test(r,
620 "void main() {"
621 "sk_FragColor.r = 32.0 + 2.0;"
622 "sk_FragColor.r = 32.0 - 2.0;"
623 "sk_FragColor.r = 32.0 * 2.0;"
624 "sk_FragColor.r = 32.0 / 2.0;"
625 "sk_FragColor.r = (12 > 2.0) ? (10 * 2 / 5 + 18 - 3) : 0;"
626 "sk_FragColor.r = 0.0 == 0.0 ? 1 : -1;"
627 "sk_FragColor.r = 0.0 == 1.0 ? 2 : -2;"
628 "sk_FragColor.r = 0.0 != 1.0 ? 3 : -3;"
629 "sk_FragColor.r = 0.0 != 0.0 ? 4 : -4;"
630 "sk_FragColor.r = 6.0 > 5.0 ? 5 : -5;"
631 "sk_FragColor.r = 6.0 > 6.0 ? 6 : -6;"
632 "sk_FragColor.r = 6.0 >= 6.0 ? 7 : -7;"
633 "sk_FragColor.r = 6.0 >= 7.0 ? 8 : -8;"
634 "sk_FragColor.r = 5.0 < 6.0 ? 9 : -9;"
635 "sk_FragColor.r = 6.0 < 6.0 ? 10 : -10;"
636 "sk_FragColor.r = 6.0 <= 6.0 ? 11 : -11;"
637 "sk_FragColor.r = 6.0 <= 5.0 ? 12 : -12;"
Ethan Nicholasfe53e582017-04-27 16:24:51 -0400638 "sk_FragColor.r = sqrt(1) + 0;"
639 "sk_FragColor.r = 0 + sqrt(2);"
640 "sk_FragColor.r = sqrt(3) - 0;"
641 "sk_FragColor.r = sqrt(4) * 0;"
642 "sk_FragColor.r = sqrt(5) * 1;"
643 "sk_FragColor.r = 1 * sqrt(6);"
644 "sk_FragColor.r = 0 * sqrt(7);"
645 "sk_FragColor.r = sqrt(8) / 1;"
646 "sk_FragColor.r = 0 / sqrt(9);"
647 "sk_FragColor.r += 1;"
648 "sk_FragColor.r += 0;"
649 "sk_FragColor.r -= 1;"
650 "sk_FragColor.r -= 0;"
651 "sk_FragColor.r *= 1;"
652 "sk_FragColor.r *= 2;"
653 "sk_FragColor.r /= 1;"
654 "sk_FragColor.r /= 2;"
Ethan Nicholasc81d22f2017-04-26 11:25:18 -0400655 "}",
656 *SkSL::ShaderCapsFactory::Default(),
657 "#version 400\n"
658 "out vec4 sk_FragColor;\n"
659 "void main() {\n"
660 " sk_FragColor.x = 34.0;\n"
661 " sk_FragColor.x = 30.0;\n"
662 " sk_FragColor.x = 64.0;\n"
663 " sk_FragColor.x = 16.0;\n"
664 " sk_FragColor.x = 19.0;\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400665 " sk_FragColor.x = 1.0;\n"
Ethan Nicholasc81d22f2017-04-26 11:25:18 -0400666 " sk_FragColor.x = -2.0;\n"
667 " sk_FragColor.x = 3.0;\n"
668 " sk_FragColor.x = -4.0;\n"
669 " sk_FragColor.x = 5.0;\n"
670 " sk_FragColor.x = -6.0;\n"
671 " sk_FragColor.x = 7.0;\n"
672 " sk_FragColor.x = -8.0;\n"
673 " sk_FragColor.x = 9.0;\n"
674 " sk_FragColor.x = -10.0;\n"
675 " sk_FragColor.x = 11.0;\n"
676 " sk_FragColor.x = -12.0;\n"
Ethan Nicholasfe53e582017-04-27 16:24:51 -0400677 " sk_FragColor.x = sqrt(1.0);\n"
678 " sk_FragColor.x = sqrt(2.0);\n"
679 " sk_FragColor.x = sqrt(3.0);\n"
680 " sk_FragColor.x = 0.0;\n"
681 " sk_FragColor.x = sqrt(5.0);\n"
682 " sk_FragColor.x = sqrt(6.0);\n"
683 " sk_FragColor.x = 0.0;\n"
684 " sk_FragColor.x = sqrt(8.0);\n"
685 " sk_FragColor.x = 0.0;\n"
686 " sk_FragColor.x += 1.0;\n"
687 " sk_FragColor.x -= 1.0;\n"
688 " sk_FragColor.x *= 2.0;\n"
689 " sk_FragColor.x /= 2.0;\n"
Ethan Nicholasc81d22f2017-04-26 11:25:18 -0400690 "}\n");
691}
692
693DEF_TEST(SkSLBoolFolding, r) {
694 test(r,
695 "void main() {"
696 "sk_FragColor.r = 1 == 1 || 2 == 8 ? 1 : -1;"
697 "sk_FragColor.r = 1 > 1 || 2 == 8 ? 2 : -2;"
698 "sk_FragColor.r = 1 == 1 && 2 <= 8 ? 3 : -3;"
699 "sk_FragColor.r = 1 == 2 && 2 == 8 ? 4 : -4;"
700 "sk_FragColor.r = 1 == 1 ^^ 1 != 1 ? 5 : -5;"
701 "sk_FragColor.r = 1 == 1 ^^ 1 == 1 ? 6 : -6;"
702 "}",
703 *SkSL::ShaderCapsFactory::Default(),
704 "#version 400\n"
705 "out vec4 sk_FragColor;\n"
706 "void main() {\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400707 " sk_FragColor.x = 1.0;\n"
Ethan Nicholasc81d22f2017-04-26 11:25:18 -0400708 " sk_FragColor.x = -2.0;\n"
709 " sk_FragColor.x = 3.0;\n"
710 " sk_FragColor.x = -4.0;\n"
711 " sk_FragColor.x = 5.0;\n"
712 " sk_FragColor.x = -6.0;\n"
713 "}\n");
714}
715
716DEF_TEST(SkSLVecFolding, r) {
717 test(r,
718 "void main() {"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400719 "sk_FragColor.r = float4(0.5, 1, 1, 1).x;"
720 "sk_FragColor = float4(float2(1), float2(2, 3)) + float4(5, 6, 7, 8);"
721 "sk_FragColor = float4(8, float3(10)) - float4(1);"
722 "sk_FragColor = float4(2) * float4(1, 2, 3, 4);"
723 "sk_FragColor = float4(12) / float4(1, 2, 3, 4);"
724 "sk_FragColor.r = (float4(12) / float4(1, 2, 3, 4)).y;"
725 "sk_FragColor.x = float4(1) == float4(1) ? 1.0 : -1.0;"
726 "sk_FragColor.x = float4(1) == float4(2) ? 2.0 : -2.0;"
727 "sk_FragColor.x = float2(1) == float2(1, 1) ? 3.0 : -3.0;"
728 "sk_FragColor.x = float2(1, 1) == float2(1, 1) ? 4.0 : -4.0;"
729 "sk_FragColor.x = float2(1) == float2(1, 0) ? 5.0 : -5.0;"
730 "sk_FragColor.x = float4(1) == float4(float2(1), float2(1)) ? 6.0 : -6.0;"
731 "sk_FragColor.x = float4(float3(1), 1) == float4(float2(1), float2(1)) ? 7.0 : -7.0;"
732 "sk_FragColor.x = float4(float3(1), 1) == float4(float2(1), 1, 0) ? 8.0 : -8.0;"
733 "sk_FragColor.x = float2(1) != float2(1, 0) ? 9.0 : -9.0;"
734 "sk_FragColor.x = float4(1) != float4(float2(1), float2(1)) ? 10.0 : -10.0;"
735 "sk_FragColor = float4(sqrt(1)) * float4(1);"
736 "sk_FragColor = float4(1) * float4(sqrt(2));"
737 "sk_FragColor = float4(0) * float4(sqrt(3));"
738 "sk_FragColor = float4(sqrt(4)) * float4(0);"
739 "sk_FragColor = float4(0) / float4(sqrt(5));"
740 "sk_FragColor = float4(0) + float4(sqrt(6));"
741 "sk_FragColor = float4(sqrt(7)) + float4(0);"
742 "sk_FragColor = float4(sqrt(8)) - float4(0);"
743 "sk_FragColor = float4(0) + sqrt(9);"
744 "sk_FragColor = float4(0) * sqrt(10);"
745 "sk_FragColor = float4(0) / sqrt(11);"
746 "sk_FragColor = float4(1) * sqrt(12);"
747 "sk_FragColor = 0 + float4(sqrt(13));"
748 "sk_FragColor = 0 * float4(sqrt(14));"
749 "sk_FragColor = 0 / float4(sqrt(15));"
750 "sk_FragColor = 1 * float4(sqrt(16));"
751 "sk_FragColor = float4(sqrt(17)) + 0;"
752 "sk_FragColor = float4(sqrt(18)) * 0;"
753 "sk_FragColor = float4(sqrt(19)) * 1;"
754 "sk_FragColor = float4(sqrt(19.5)) - 0;"
755 "sk_FragColor = sqrt(20) * float4(1);"
756 "sk_FragColor = sqrt(21) + float4(0);"
757 "sk_FragColor = sqrt(22) - float4(0);"
758 "sk_FragColor = sqrt(23) / float4(1);"
759 "sk_FragColor = float4(sqrt(24)) / 1;"
760 "sk_FragColor += float4(1);"
761 "sk_FragColor += float4(0);"
762 "sk_FragColor -= float4(1);"
763 "sk_FragColor -= float4(0);"
764 "sk_FragColor *= float4(1);"
765 "sk_FragColor *= float4(2);"
766 "sk_FragColor /= float4(1);"
767 "sk_FragColor /= float4(2);"
Ethan Nicholasc81d22f2017-04-26 11:25:18 -0400768 "}",
769 *SkSL::ShaderCapsFactory::Default(),
770 "#version 400\n"
771 "out vec4 sk_FragColor;\n"
772 "void main() {\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400773 " sk_FragColor.x = 0.5;\n"
774 " sk_FragColor = vec4(6.0, 7.0, 9.0, 11.0);\n"
775 " sk_FragColor = vec4(7.0, 9.0, 9.0, 9.0);\n"
776 " sk_FragColor = vec4(2.0, 4.0, 6.0, 8.0);\n"
777 " sk_FragColor = vec4(12.0, 6.0, 4.0, 3.0);\n"
778 " sk_FragColor.x = 6.0;\n"
Ethan Nicholas3deaeb22017-04-25 14:42:11 -0400779 " sk_FragColor.x = 1.0;\n"
Ethan Nicholasc81d22f2017-04-26 11:25:18 -0400780 " sk_FragColor.x = -2.0;\n"
781 " sk_FragColor.x = 3.0;\n"
782 " sk_FragColor.x = 4.0;\n"
783 " sk_FragColor.x = -5.0;\n"
784 " sk_FragColor.x = 6.0;\n"
785 " sk_FragColor.x = 7.0;\n"
786 " sk_FragColor.x = -8.0;\n"
787 " sk_FragColor.x = 9.0;\n"
788 " sk_FragColor.x = -10.0;\n"
Ethan Nicholasfe53e582017-04-27 16:24:51 -0400789 " sk_FragColor = vec4(sqrt(1.0));\n"
790 " sk_FragColor = vec4(sqrt(2.0));\n"
791 " sk_FragColor = vec4(0.0);\n"
792 " sk_FragColor = vec4(0.0);\n"
793 " sk_FragColor = vec4(0.0);\n"
794 " sk_FragColor = vec4(sqrt(6.0));\n"
795 " sk_FragColor = vec4(sqrt(7.0));\n"
796 " sk_FragColor = vec4(sqrt(8.0));\n"
797 " sk_FragColor = vec4(sqrt(9.0));\n"
798 " sk_FragColor = vec4(0.0);\n"
799 " sk_FragColor = vec4(0.0);\n"
800 " sk_FragColor = vec4(sqrt(12.0));\n"
801 " sk_FragColor = vec4(sqrt(13.0));\n"
802 " sk_FragColor = vec4(0.0);\n"
803 " sk_FragColor = vec4(0.0);\n"
804 " sk_FragColor = vec4(sqrt(16.0));\n"
805 " sk_FragColor = vec4(sqrt(17.0));\n"
806 " sk_FragColor = vec4(0.0);\n"
807 " sk_FragColor = vec4(sqrt(19.0));\n"
808 " sk_FragColor = vec4(sqrt(19.5));\n"
809 " sk_FragColor = vec4(sqrt(20.0));\n"
810 " sk_FragColor = vec4(sqrt(21.0));\n"
811 " sk_FragColor = vec4(sqrt(22.0));\n"
812 " sk_FragColor = vec4(sqrt(23.0));\n"
813 " sk_FragColor = vec4(sqrt(24.0));\n"
814 " sk_FragColor += vec4(1.0);\n"
815 " sk_FragColor -= vec4(1.0);\n"
816 " sk_FragColor *= vec4(2.0);\n"
817 " sk_FragColor /= vec4(2.0);\n"
Ethan Nicholasc81d22f2017-04-26 11:25:18 -0400818 "}\n");
819}
820
821DEF_TEST(SkSLMatFolding, r) {
822 test(r,
823 "void main() {"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400824 "sk_FragColor.x = float2x2(float2(1.0, 0.0), float2(0.0, 1.0)) == "
825 "float2x2(float2(1.0, 0.0), float2(0.0, 1.0)) ? 1 : -1;"
826 "sk_FragColor.x = float2x2(float2(1.0, 0.0), float2(1.0, 1.0)) == "
827 "float2x2(float2(1.0, 0.0), float2(0.0, 1.0)) ? 2 : -2;"
828 "sk_FragColor.x = float2x2(1) == float2x2(1) ? 3 : -3;"
829 "sk_FragColor.x = float2x2(1) == float2x2(0) ? 4 : -4;"
830 "sk_FragColor.x = float2x2(1) == float2x2(float2(1.0, 0.0), float2(0.0, 1.0)) ? 5 : -5;"
831 "sk_FragColor.x = float2x2(2) == float2x2(float2(1.0, 0.0), float2(0.0, 1.0)) ? 6 : -6;"
832 "sk_FragColor.x = float3x2(2) == float3x2(float2(2.0, 0.0), float2(0.0, 2.0), float2(0.0))"
833 "? 7 : -7;"
834 "sk_FragColor.x = float2x2(1) != float2x2(1) ? 8 : -8;"
835 "sk_FragColor.x = float2x2(1) != float2x2(0) ? 9 : -9;"
836 "sk_FragColor.x = float3x3(float3(1.0, 0.0, 0.0), float3(0.0, 1.0, 0.0), "
837 "float3(0.0, 0.0, 0.0)) == float3x3(float2x2(1.0)) ? 10 : -10;"
838 "sk_FragColor.x = float2x2(float3x3(1.0)) == float2x2(1.0) ? 11 : -11;"
839 "sk_FragColor.x = float2x2(float4(1.0, 0.0, 0.0, 1.0)) == float2x2(1.0) ? 12 : -12;"
840 "sk_FragColor.x = float2x2(1.0, 0.0, float2(0.0, 1.0)) == float2x2(1.0) ? 13 : -13;"
841 "sk_FragColor.x = float2x2(float2(1.0, 0.0), 0.0, 1.0) == float2x2(1.0) ? 14 : -14;"
Ethan Nicholasc81d22f2017-04-26 11:25:18 -0400842 "}",
843 *SkSL::ShaderCapsFactory::Default(),
844 "#version 400\n"
845 "out vec4 sk_FragColor;\n"
846 "void main() {\n"
Ethan Nicholas3deaeb22017-04-25 14:42:11 -0400847 " sk_FragColor.x = 1.0;\n"
Ethan Nicholasc81d22f2017-04-26 11:25:18 -0400848 " sk_FragColor.x = -2.0;\n"
849 " sk_FragColor.x = 3.0;\n"
850 " sk_FragColor.x = -4.0;\n"
851 " sk_FragColor.x = 5.0;\n"
852 " sk_FragColor.x = -6.0;\n"
853 " sk_FragColor.x = 7.0;\n"
854 " sk_FragColor.x = -8.0;\n"
855 " sk_FragColor.x = 9.0;\n"
856 " sk_FragColor.x = 10.0;\n"
857 " sk_FragColor.x = 11.0;\n"
858 " sk_FragColor.x = 12.0;\n"
859 " sk_FragColor.x = 13.0;\n"
860 " sk_FragColor.x = 14.0;\n"
ethannicholas08a92112016-11-09 13:26:45 -0800861 "}\n");
862}
863
Ethan Nicholas5ac13c22017-05-10 15:06:17 -0400864DEF_TEST(SkSLConstantIf, r) {
ethannicholas08a92112016-11-09 13:26:45 -0800865 test(r,
866 "void main() {"
867 "int x;"
868 "if (true) x = 1;"
869 "if (2 > 1) x = 2; else x = 3;"
870 "if (1 > 2) x = 4; else x = 5;"
871 "if (false) x = 6;"
Ethan Nicholascb670962017-04-20 19:31:52 -0400872 "sk_FragColor.r = x;"
ethannicholas08a92112016-11-09 13:26:45 -0800873 "}",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500874 *SkSL::ShaderCapsFactory::Default(),
ethannicholas08a92112016-11-09 13:26:45 -0800875 "#version 400\n"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500876 "out vec4 sk_FragColor;\n"
ethannicholas08a92112016-11-09 13:26:45 -0800877 "void main() {\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400878 " sk_FragColor.x = 5.0;\n"
ethannicholas08a92112016-11-09 13:26:45 -0800879 "}\n");
880}
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500881
Ethan Nicholas3605ace2016-11-21 15:59:48 -0500882DEF_TEST(SkSLCaps, r) {
883 test(r,
884 "void main() {"
Ethan Nicholascb670962017-04-20 19:31:52 -0400885 "int x = 0;"
886 "int y = 0;"
887 "int z = 0;"
888 "int w = 0;"
Ethan Nicholas3605ace2016-11-21 15:59:48 -0500889 "if (sk_Caps.externalTextureSupport) x = 1;"
Ethan Nicholascb670962017-04-20 19:31:52 -0400890 "if (sk_Caps.fbFetchSupport) y = 1;"
891 "if (sk_Caps.dropsTileOnZeroDivide && sk_Caps.texelFetchSupport) z = 1;"
892 "if (sk_Caps.dropsTileOnZeroDivide && sk_Caps.canUseAnyFunctionInShader) w = 1;"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400893 "sk_FragColor = float4(x, y, z, w);"
Ethan Nicholas3605ace2016-11-21 15:59:48 -0500894 "}",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500895 *SkSL::ShaderCapsFactory::VariousCaps(),
Ethan Nicholas3605ace2016-11-21 15:59:48 -0500896 "#version 400\n"
897 "out vec4 sk_FragColor;\n"
898 "void main() {\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400899 " sk_FragColor = vec4(1.0, 0.0, 1.0, 0.0);\n"
Ethan Nicholas3605ace2016-11-21 15:59:48 -0500900 "}\n");
901}
902
Ethan Nicholas2b3dab62016-11-28 12:03:26 -0500903DEF_TEST(SkSLTexture, r) {
904 test(r,
905 "uniform sampler1D one;"
906 "uniform sampler2D two;"
907 "void main() {"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400908 "float4 a = texture(one, 0);"
909 "float4 b = texture(two, float2(0));"
910 "float4 c = texture(one, float2(0));"
911 "float4 d = texture(two, float3(0));"
912 "sk_FragColor = float4(a.x, b.x, c.x, d.x);"
Ethan Nicholas2b3dab62016-11-28 12:03:26 -0500913 "}",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500914 *SkSL::ShaderCapsFactory::Default(),
Ethan Nicholas2b3dab62016-11-28 12:03:26 -0500915 "#version 400\n"
916 "out vec4 sk_FragColor;\n"
917 "uniform sampler1D one;\n"
918 "uniform sampler2D two;\n"
919 "void main() {\n"
920 " vec4 a = texture(one, 0.0);\n"
921 " vec4 b = texture(two, vec2(0.0));\n"
922 " vec4 c = textureProj(one, vec2(0.0));\n"
923 " vec4 d = textureProj(two, vec3(0.0));\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400924 " sk_FragColor = vec4(a.x, b.x, c.x, d.x);\n"
Ethan Nicholas2b3dab62016-11-28 12:03:26 -0500925 "}\n");
926 test(r,
927 "uniform sampler1D one;"
928 "uniform sampler2D two;"
929 "void main() {"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400930 "float4 a = texture(one, 0);"
931 "float4 b = texture(two, float2(0));"
932 "float4 c = texture(one, float2(0));"
933 "float4 d = texture(two, float3(0));"
934 "sk_FragColor = float4(a.x, b.x, c.x, d.x);"
Ethan Nicholas2b3dab62016-11-28 12:03:26 -0500935 "}",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500936 *SkSL::ShaderCapsFactory::Version110(),
Ethan Nicholas2b3dab62016-11-28 12:03:26 -0500937 "#version 110\n"
938 "uniform sampler1D one;\n"
939 "uniform sampler2D two;\n"
940 "void main() {\n"
941 " vec4 a = texture1D(one, 0.0);\n"
942 " vec4 b = texture2D(two, vec2(0.0));\n"
943 " vec4 c = texture1DProj(one, vec2(0.0));\n"
944 " vec4 d = texture2DProj(two, vec3(0.0));\n"
Ethan Nicholascb670962017-04-20 19:31:52 -0400945 " gl_FragColor = vec4(a.x, b.x, c.x, d.x);\n"
Ethan Nicholas2b3dab62016-11-28 12:03:26 -0500946 "}\n");
947}
948
Ethan Nicholas19671772016-11-28 16:30:17 -0500949DEF_TEST(SkSLOffset, r) {
950 test(r,
951 "struct Test {"
952 "layout(offset = 0) int x;"
953 "layout(offset = 4) int y;"
954 "int z;"
955 "} test;",
Brian Salomonf1dd6772016-11-29 15:27:52 -0500956 *SkSL::ShaderCapsFactory::Default(),
Ethan Nicholas19671772016-11-28 16:30:17 -0500957 "#version 400\n"
958 "out vec4 sk_FragColor;\n"
959 "struct Test {\n"
960 " layout (offset = 0) int x;\n"
961 " layout (offset = 4) int y;\n"
962 " int z;\n"
963 "} test;\n");
964}
Ethan Nicholas941e7e22016-12-12 15:33:30 -0500965
966DEF_TEST(SkSLFragCoord, r) {
967 SkSL::Program::Settings settings;
968 settings.fFlipY = true;
969 sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::FragCoordsOld();
970 settings.fCaps = caps.get();
971 SkSL::Program::Inputs inputs;
972 test(r,
973 "void main() { sk_FragColor.xy = sk_FragCoord.xy; }",
974 settings,
975 "#version 110\n"
976 "#extension GL_ARB_fragment_coord_conventions : require\n"
977 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
978 "void main() {\n"
979 " gl_FragColor.xy = gl_FragCoord.xy;\n"
980 "}\n",
981 &inputs);
982 REPORTER_ASSERT(r, !inputs.fRTHeight);
983
984 caps = SkSL::ShaderCapsFactory::FragCoordsNew();
985 settings.fCaps = caps.get();
986 test(r,
987 "void main() { sk_FragColor.xy = sk_FragCoord.xy; }",
988 settings,
989 "#version 400\n"
990 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
991 "out vec4 sk_FragColor;\n"
992 "void main() {\n"
993 " sk_FragColor.xy = gl_FragCoord.xy;\n"
994 "}\n",
995 &inputs);
996 REPORTER_ASSERT(r, !inputs.fRTHeight);
997
998 caps = SkSL::ShaderCapsFactory::Default();
999 settings.fCaps = caps.get();
1000 test(r,
1001 "void main() { sk_FragColor.xy = sk_FragCoord.xy; }",
1002 settings,
1003 "#version 400\n"
1004 "uniform float u_skRTHeight;\n"
1005 "out vec4 sk_FragColor;\n"
1006 "void main() {\n"
1007 " vec2 _sktmpCoord = gl_FragCoord.xy;\n"
1008 " vec4 sk_FragCoord = vec4(_sktmpCoord.x, u_skRTHeight - _sktmpCoord.y, 1.0, 1.0);\n"
1009 " sk_FragColor.xy = sk_FragCoord.xy;\n"
1010 "}\n",
1011 &inputs);
1012 REPORTER_ASSERT(r, inputs.fRTHeight);
1013
1014 settings.fFlipY = false;
1015 test(r,
1016 "void main() { sk_FragColor.xy = sk_FragCoord.xy; }",
1017 settings,
1018 "#version 400\n"
1019 "out vec4 sk_FragColor;\n"
1020 "void main() {\n"
1021 " sk_FragColor.xy = gl_FragCoord.xy;\n"
1022 "}\n",
1023 &inputs);
1024 REPORTER_ASSERT(r, !inputs.fRTHeight);
1025}
1026
Ethan Nicholasa51740c2017-02-07 14:53:32 -05001027DEF_TEST(SkSLVertexID, r) {
1028 test(r,
1029 "out int id; void main() { id = sk_VertexID; }",
1030 *SkSL::ShaderCapsFactory::Default(),
1031 "#version 400\n"
1032 "out int id;\n"
1033 "void main() {\n"
1034 " id = gl_VertexID;\n"
1035 "}\n",
1036 SkSL::Program::kVertex_Kind);
1037}
1038
Ethan Nicholas67d64602017-02-09 10:15:25 -05001039DEF_TEST(SkSLClipDistance, r) {
1040 test(r,
1041 "void main() { sk_ClipDistance[0] = 0; }",
1042 *SkSL::ShaderCapsFactory::Default(),
1043 "#version 400\n"
1044 "void main() {\n"
1045 " gl_ClipDistance[0] = 0.0;\n"
1046 "}\n",
1047 SkSL::Program::kVertex_Kind);
1048 test(r,
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001049 "void main() { sk_FragColor = float4(sk_ClipDistance[0]); }",
Ethan Nicholas67d64602017-02-09 10:15:25 -05001050 *SkSL::ShaderCapsFactory::Default(),
1051 "#version 400\n"
1052 "out vec4 sk_FragColor;\n"
1053 "void main() {\n"
1054 " sk_FragColor = vec4(gl_ClipDistance[0]);\n"
1055 "}\n");
1056}
Ethan Nicholas50afc172017-02-16 14:49:57 -05001057
1058DEF_TEST(SkSLArrayTypes, r) {
1059 test(r,
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001060 "void main() { float2 x[2] = float2[2](float2(1), float2(2));"
1061 "float2[2] y = float2[2](float2(3), float2(4));"
1062 "sk_FragColor = float4(x[0], y[1]); }",
Ethan Nicholas50afc172017-02-16 14:49:57 -05001063 *SkSL::ShaderCapsFactory::Default(),
1064 "#version 400\n"
1065 "out vec4 sk_FragColor;\n"
1066 "void main() {\n"
Ethan Nicholascb670962017-04-20 19:31:52 -04001067 " sk_FragColor = vec4(vec2[2](vec2(1.0), vec2(2.0))[0], "
1068 "vec2[2](vec2(3.0), vec2(4.0))[1]);\n"
Ethan Nicholas50afc172017-02-16 14:49:57 -05001069 "}\n");
1070}
1071
Ethan Nicholas52cad152017-02-16 16:37:32 -05001072DEF_TEST(SkSLGeometry, r) {
1073 test(r,
1074 "layout(points) in;"
1075 "layout(invocations = 2) in;"
1076 "layout(line_strip, max_vertices = 2) out;"
1077 "void main() {"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001078 "gl_Position = sk_in[0].gl_Position + float4(-0.5, 0, 0, sk_InvocationID);"
Ethan Nicholas52cad152017-02-16 16:37:32 -05001079 "EmitVertex();"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001080 "gl_Position = sk_in[0].gl_Position + float4(0.5, 0, 0, sk_InvocationID);"
Ethan Nicholas52cad152017-02-16 16:37:32 -05001081 "EmitVertex();"
1082 "EndPrimitive();"
1083 "}",
1084 *SkSL::ShaderCapsFactory::Default(),
1085 "#version 400\n"
1086 "layout (points) in ;\n"
1087 "layout (invocations = 2) in ;\n"
1088 "layout (line_strip, max_vertices = 2) out ;\n"
1089 "void main() {\n"
1090 " gl_Position = gl_in[0].gl_Position + vec4(-0.5, 0.0, 0.0, float(gl_InvocationID));\n"
1091 " EmitVertex();\n"
1092 " gl_Position = gl_in[0].gl_Position + vec4(0.5, 0.0, 0.0, float(gl_InvocationID));\n"
1093 " EmitVertex();\n"
1094 " EndPrimitive();\n"
1095 "}\n",
1096 SkSL::Program::kGeometry_Kind);
1097}
1098
Ethan Nicholasaf197692017-02-27 13:26:45 -05001099DEF_TEST(SkSLSwitch, r) {
Ethan Nicholas5ac13c22017-05-10 15:06:17 -04001100 // basic "does a switch even work" test
Ethan Nicholasaf197692017-02-27 13:26:45 -05001101 test(r,
1102 "void main() {"
1103 " float x;"
Ethan Nicholas5ac13c22017-05-10 15:06:17 -04001104 " switch (int(sqrt(1))) {"
Ethan Nicholasaf197692017-02-27 13:26:45 -05001105 " case 0:"
1106 " x = 0.0;"
1107 " break;"
1108 " case 1:"
1109 " x = 1.0;"
1110 " break;"
1111 " default:"
1112 " x = 2.0;"
1113 " }"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001114 " sk_FragColor = float4(x);"
Ethan Nicholasaf197692017-02-27 13:26:45 -05001115 "}",
1116 *SkSL::ShaderCapsFactory::Default(),
1117 "#version 400\n"
1118 "out vec4 sk_FragColor;\n"
1119 "void main() {\n"
1120 " float x;\n"
Ethan Nicholas5ac13c22017-05-10 15:06:17 -04001121 " switch (int(sqrt(1.0))) {\n"
Ethan Nicholasaf197692017-02-27 13:26:45 -05001122 " case 0:\n"
1123 " x = 0.0;\n"
1124 " break;\n"
1125 " case 1:\n"
1126 " x = 1.0;\n"
1127 " break;\n"
1128 " default:\n"
1129 " x = 2.0;\n"
1130 " }\n"
1131 " sk_FragColor = vec4(x);\n"
1132 "}\n");
Ethan Nicholas5ac13c22017-05-10 15:06:17 -04001133 // dead code inside of switch
Ethan Nicholasaf197692017-02-27 13:26:45 -05001134 test(r,
1135 "void main() {"
1136 " float x;"
Ethan Nicholas5ac13c22017-05-10 15:06:17 -04001137 " switch (int(sqrt(2))) {"
Ethan Nicholasaf197692017-02-27 13:26:45 -05001138 " case 0:"
1139 " x = 0.0;"
1140 " case 1:"
1141 " x = 1.0;"
1142 " default:"
1143 " x = 2.0;"
1144 " }"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001145 " sk_FragColor = float4(x);"
Ethan Nicholasaf197692017-02-27 13:26:45 -05001146 "}",
1147 *SkSL::ShaderCapsFactory::Default(),
1148 "#version 400\n"
1149 "out vec4 sk_FragColor;\n"
1150 "void main() {\n"
Ethan Nicholas5ac13c22017-05-10 15:06:17 -04001151 " switch (int(sqrt(2.0))) {\n"
Ethan Nicholasaf197692017-02-27 13:26:45 -05001152 " case 0:\n"
Ethan Nicholascb670962017-04-20 19:31:52 -04001153 " ;\n"
Ethan Nicholasaf197692017-02-27 13:26:45 -05001154 " case 1:\n"
Ethan Nicholascb670962017-04-20 19:31:52 -04001155 " ;\n"
Ethan Nicholasaf197692017-02-27 13:26:45 -05001156 " default:\n"
Ethan Nicholascb670962017-04-20 19:31:52 -04001157 " ;\n"
Ethan Nicholasaf197692017-02-27 13:26:45 -05001158 " }\n"
1159 " sk_FragColor = vec4(2.0);\n"
1160 "}\n");
Ethan Nicholas5ac13c22017-05-10 15:06:17 -04001161 // non-static test w/ fallthrough
Ethan Nicholasaf197692017-02-27 13:26:45 -05001162 test(r,
1163 "void main() {"
1164 " float x = 0.0;"
Ethan Nicholas5ac13c22017-05-10 15:06:17 -04001165 " switch (int(sqrt(3))) {"
Ethan Nicholasaf197692017-02-27 13:26:45 -05001166 " case 0:"
1167 " x = 0.0;"
1168 " case 1:"
1169 " x = 1.0;"
1170 " }"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001171 " sk_FragColor = float4(x);"
Ethan Nicholasaf197692017-02-27 13:26:45 -05001172 "}",
1173 *SkSL::ShaderCapsFactory::Default(),
1174 "#version 400\n"
1175 "out vec4 sk_FragColor;\n"
1176 "void main() {\n"
1177 " float x = 0.0;\n"
Ethan Nicholas5ac13c22017-05-10 15:06:17 -04001178 " switch (int(sqrt(3.0))) {\n"
Ethan Nicholasaf197692017-02-27 13:26:45 -05001179 " case 0:\n"
1180 " x = 0.0;\n"
1181 " case 1:\n"
1182 " x = 1.0;\n"
1183 " }\n"
1184 " sk_FragColor = vec4(x);\n"
1185 "}\n");
Ethan Nicholas5ac13c22017-05-10 15:06:17 -04001186 // static test w/ fallthrough
1187 test(r,
1188 "void main() {"
1189 " float x = 0.0;"
1190 " switch (0) {"
1191 " case 0:"
1192 " x = 0.0;"
1193 " case 1:"
1194 " x = 1.0;"
1195 " }"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001196 " sk_FragColor = float4(x);"
Ethan Nicholas5ac13c22017-05-10 15:06:17 -04001197 "}",
1198 *SkSL::ShaderCapsFactory::Default(),
1199 "#version 400\n"
1200 "out vec4 sk_FragColor;\n"
1201 "void main() {\n"
1202 " sk_FragColor = vec4(1.0);\n"
1203 "}\n");
1204 // static test w/ fallthrough, different entry point
1205 test(r,
1206 "void main() {"
1207 " float x = 0.0;"
1208 " switch (1) {"
1209 " case 0:"
1210 " x = 0.0;"
1211 " case 1:"
1212 " x = 1.0;"
1213 " }"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001214 " sk_FragColor = float4(x);"
Ethan Nicholas5ac13c22017-05-10 15:06:17 -04001215 "}",
1216 *SkSL::ShaderCapsFactory::Default(),
1217 "#version 400\n"
1218 "out vec4 sk_FragColor;\n"
1219 "void main() {\n"
1220 " sk_FragColor = vec4(1.0);\n"
1221 "}\n");
1222 // static test w/ break
1223 test(r,
1224 "void main() {"
1225 " float x = 0.0;"
1226 " switch (0) {"
1227 " case 0:"
1228 " x = 0.0;"
1229 " break;"
1230 " case 1:"
1231 " x = 1.0;"
1232 " }"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001233 " sk_FragColor = float4(x);"
Ethan Nicholas5ac13c22017-05-10 15:06:17 -04001234 "}",
1235 *SkSL::ShaderCapsFactory::Default(),
1236 "#version 400\n"
1237 "out vec4 sk_FragColor;\n"
1238 "void main() {\n"
1239 " sk_FragColor = vec4(0.0);\n"
1240 "}\n");
1241 // static test w/ static conditional break
1242 test(r,
1243 "void main() {"
1244 " float x = 0.0;"
1245 " switch (0) {"
1246 " case 0:"
1247 " x = 0.0;"
1248 " if (x < 1) break;"
1249 " case 1:"
1250 " x = 1.0;"
1251 " }"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001252 " sk_FragColor = float4(x);"
Ethan Nicholas5ac13c22017-05-10 15:06:17 -04001253 "}",
1254 *SkSL::ShaderCapsFactory::Default(),
1255 "#version 400\n"
1256 "out vec4 sk_FragColor;\n"
1257 "void main() {\n"
1258 " sk_FragColor = vec4(0.0);\n"
1259 "}\n");
1260 // static test w/ non-static conditional break
1261 test(r,
1262 "void main() {"
1263 " float x = 0.0;"
1264 " switch (0) {"
1265 " case 0:"
1266 " x = 0.0;"
1267 " if (x < sqrt(1)) break;"
1268 " case 1:"
1269 " x = 1.0;"
1270 " }"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001271 " sk_FragColor = float4(x);"
Ethan Nicholas5ac13c22017-05-10 15:06:17 -04001272 "}",
1273 *SkSL::ShaderCapsFactory::Default(),
1274 "#version 400\n"
1275 "out vec4 sk_FragColor;\n"
1276 "void main() {\n"
1277 " float x = 0.0;\n"
1278 " switch (0) {\n"
1279 " case 0:\n"
1280 " x = 0.0;\n"
1281 " if (0.0 < sqrt(1.0)) break;\n"
1282 " case 1:\n"
1283 " x = 1.0;\n"
1284 " }\n"
1285 " sk_FragColor = vec4(x);\n"
1286 "}\n");
Ethan Nicholasaf197692017-02-27 13:26:45 -05001287}
1288
Ethan Nicholas5338f992017-04-19 15:54:07 -04001289DEF_TEST(SkSLRectangleTexture, r) {
1290 test(r,
1291 "uniform sampler2D test;"
1292 "void main() {"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001293 " sk_FragColor = texture(test, float2(0.5));"
Ethan Nicholas5338f992017-04-19 15:54:07 -04001294 "}",
1295 *SkSL::ShaderCapsFactory::Default(),
1296 "#version 400\n"
1297 "out vec4 sk_FragColor;\n"
1298 "uniform sampler2D test;\n"
1299 "void main() {\n"
Ethan Nicholasfe53e582017-04-27 16:24:51 -04001300 " sk_FragColor = texture(test, vec2(0.5));\n"
Ethan Nicholas5338f992017-04-19 15:54:07 -04001301 "}\n");
1302 test(r,
1303 "uniform sampler2DRect test;"
1304 "void main() {"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001305 " sk_FragColor = texture(test, float2(0.5));"
Ethan Nicholas5338f992017-04-19 15:54:07 -04001306 "}",
1307 *SkSL::ShaderCapsFactory::Default(),
1308 "#version 400\n"
1309 "out vec4 sk_FragColor;\n"
1310 "uniform sampler2DRect test;\n"
1311 "void main() {\n"
Ethan Nicholasfe53e582017-04-27 16:24:51 -04001312 " sk_FragColor = texture(test, textureSize(test) * vec2(0.5));\n"
Ethan Nicholas5338f992017-04-19 15:54:07 -04001313 "}\n");
1314 test(r,
1315 "uniform sampler2DRect test;"
1316 "void main() {"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001317 " sk_FragColor = texture(test, float3(0.5));"
Ethan Nicholas5338f992017-04-19 15:54:07 -04001318 "}",
1319 *SkSL::ShaderCapsFactory::Default(),
1320 "#version 400\n"
1321 "out vec4 sk_FragColor;\n"
1322 "uniform sampler2DRect test;\n"
1323 "void main() {\n"
Ethan Nicholasfe53e582017-04-27 16:24:51 -04001324 " sk_FragColor = texture(test, vec3(textureSize(test), 1.0) * vec3(0.5));\n"
Ethan Nicholas5338f992017-04-19 15:54:07 -04001325 "}\n");
1326}
1327
Ethan Nicholascb670962017-04-20 19:31:52 -04001328DEF_TEST(SkSLUnusedVars, r) {
1329 test(r,
1330 "void main() {"
1331 "float a = 1, b = 2, c = 3;"
1332 "float d = c;"
1333 "float e = d;"
1334 "b++;"
1335 "d++;"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001336 "sk_FragColor = float4(b, b, d, d);"
Ethan Nicholascb670962017-04-20 19:31:52 -04001337 "}",
1338 *SkSL::ShaderCapsFactory::Default(),
1339 "#version 400\n"
1340 "out vec4 sk_FragColor;\n"
1341 "void main() {\n"
1342 " float b = 2.0;\n"
1343 " float d = 3.0;\n"
1344 " b++;\n"
1345 " d++;\n"
1346 " sk_FragColor = vec4(b, b, d, d);\n"
1347 "}\n");
1348}
1349
Ethan Nicholasc2371a42017-05-05 10:04:06 -04001350DEF_TEST(SkSLMultipleAssignments, r) {
1351 test(r,
1352 "void main() {"
1353 "float x;"
1354 "float y;"
1355 "int z;"
1356 "x = y = z = 1;"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001357 "sk_FragColor = float4(z);"
Ethan Nicholasc2371a42017-05-05 10:04:06 -04001358 "}",
1359 *SkSL::ShaderCapsFactory::Default(),
1360 "#version 400\n"
1361 "out vec4 sk_FragColor;\n"
1362 "void main() {\n"
1363 " sk_FragColor = vec4(1.0);\n"
1364 "}\n");
1365}
1366
Ethan Nicholas4b330df2017-05-17 10:52:55 -04001367DEF_TEST(SkSLComplexDelete, r) {
1368 test(r,
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001369 "uniform float4x4 colorXform;"
Ethan Nicholasb4dc4192017-06-02 10:16:28 -04001370 "uniform sampler2D sampler;"
1371 "void main() {"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001372 "float4 tmpColor;"
1373 "sk_FragColor = float4(1.0) * (tmpColor = texture(sampler, float2(1)) , "
1374 "colorXform != float4x4(1.0) ? float4(clamp((float4x4(colorXform) * "
1375 "float4(tmpColor.xyz, 1.0)).xyz, "
1376 "0.0, tmpColor.w), tmpColor.w) : tmpColor);"
Ethan Nicholasb4dc4192017-06-02 10:16:28 -04001377 "}",
1378 *SkSL::ShaderCapsFactory::Default(),
1379 "#version 400\n"
1380 "out vec4 sk_FragColor;\n"
1381 "uniform mat4 colorXform;\n"
1382 "uniform sampler2D sampler;\n"
1383 "void main() {\n"
1384 " vec4 tmpColor;\n"
1385 " sk_FragColor = (tmpColor = texture(sampler, vec2(1.0)) , colorXform != mat4(1.0) ? "
1386 "vec4(clamp((colorXform * vec4(tmpColor.xyz, 1.0)).xyz, 0.0, tmpColor.w), tmpColor.w) : "
1387 "tmpColor);\n"
1388 "}\n");
Ethan Nicholas4b330df2017-05-17 10:52:55 -04001389}
Ethan Nicholasb4dc4192017-06-02 10:16:28 -04001390
1391DEF_TEST(SkSLDependentInitializers, r) {
1392 test(r,
1393 "void main() {"
1394 "float x = 0.5, y = x * 2;"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001395 "sk_FragColor = float4(y);"
Ethan Nicholasb4dc4192017-06-02 10:16:28 -04001396 "}",
1397 *SkSL::ShaderCapsFactory::Default(),
1398 "#version 400\n"
1399 "out vec4 sk_FragColor;\n"
1400 "void main() {\n"
1401 " sk_FragColor = vec4(1.0);\n"
1402 "}\n");
1403}
1404
Ethan Nicholasb310fd52017-06-09 13:46:34 -04001405DEF_TEST(SkSLDeadLoopVar, r) {
1406 test(r,
1407 "void main() {"
1408 "for (int x = 0; x < 4; ) {"
1409 "break;"
1410 "}"
1411 "}",
1412 *SkSL::ShaderCapsFactory::Default(),
1413 "#version 400\n"
1414 "out vec4 sk_FragColor;\n"
1415 "void main() {\n"
1416 " for (; true; ) {\n"
1417 " break;\n"
1418 " }\n"
1419 "}\n"
1420 );
1421}
1422
Ethan Nicholas7da6dfa2017-06-21 11:25:18 -04001423DEF_TEST(SkSLInvocations, r) {
1424 test(r,
1425 "layout(points) in;"
1426 "layout(invocations = 2) in;"
1427 "layout(line_strip, max_vertices = 2) out;"
1428 "void test() {"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001429 "gl_Position = sk_in[0].gl_Position + float4(0.5, 0, 0, sk_InvocationID);"
Ethan Nicholas7da6dfa2017-06-21 11:25:18 -04001430 "EmitVertex();"
1431 "}"
1432 "void main() {"
Ethan Nicholas5af9ea32017-07-28 15:19:46 -04001433 "gl_Position = sk_in[0].gl_Position + float4(-0.5, 0, 0, sk_InvocationID);"
Ethan Nicholas7da6dfa2017-06-21 11:25:18 -04001434 "EmitVertex();"
1435 "}",
1436 *SkSL::ShaderCapsFactory::MustImplementGSInvocationsWithLoop(),
1437 "#version 400\n"
1438 "int sk_InvocationID;\n"
1439 "layout (points) in ;\n"
1440 "layout (line_strip, max_vertices = 4) out ;\n"
1441 "void test() {\n"
1442 " gl_Position = gl_in[0].gl_Position + vec4(0.5, 0.0, 0.0, float(sk_InvocationID));\n"
1443 " EmitVertex();\n"
1444 "}\n"
1445 "void _invoke() {\n"
1446 " gl_Position = gl_in[0].gl_Position + vec4(-0.5, 0.0, 0.0, float(sk_InvocationID));\n"
1447 " EmitVertex();\n"
1448 "}\n"
1449 "void main() {\n"
1450 " for (sk_InvocationID = 0;sk_InvocationID < 2; sk_InvocationID++) {\n"
1451 " _invoke();\n"
1452 " EndPrimitive();\n"
1453 " }\n"
1454 "}\n",
1455 SkSL::Program::kGeometry_Kind);
1456}
1457
Ethan Nicholasdcba08e2017-08-02 10:52:54 -04001458DEF_TEST(SkSLTypePrecision, r) {
1459 test(r,
1460 "float f = 1;"
1461 "half h = 2;"
1462 "double d = 3;"
1463 "float2 f2 = float2(1, 2);"
1464 "half3 h3 = half3(1, 2, 3);"
1465 "double4 d4 = double4(1, 2, 3, 4);"
1466 "float2x2 f22 = float2x2(1, 2, 3, 4);"
1467 "half2x4 h24 = half2x4(1, 2, 3, 4, 5, 6, 7, 8);"
1468 "double4x2 d42 = double4x2(1, 2, 3, 4, 5, 6, 7, 8);",
1469 *SkSL::ShaderCapsFactory::Default(),
1470 "#version 400\n"
1471 "out vec4 sk_FragColor;\n"
1472 "float f = 1.0;\n"
1473 "float h = 2.0;\n"
1474 "double d = 3.0;\n"
1475 "vec2 f2 = vec2(1.0, 2.0);\n"
1476 "vec3 h3 = vec3(1.0, 2.0, 3.0);\n"
1477 "dvec4 d4 = dvec4(1.0, 2.0, 3.0, 4.0);\n"
1478 "mat2 f22 = mat2(1.0, 2.0, 3.0, 4.0);\n"
1479 "mat2x4 h24 = mat2x4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);\n"
1480 "dmat4x2 d42 = dmat4x2(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);\n");
1481 test(r,
1482 "float f = 1;"
1483 "half h = 2;"
1484 "float2 f2 = float2(1, 2);"
1485 "half3 h3 = half3(1, 2, 3);"
1486 "float2x2 f22 = float2x2(1, 2, 3, 4);"
1487 "half2x4 h24 = half2x4(1, 2, 3, 4, 5, 6, 7, 8);",
1488 *SkSL::ShaderCapsFactory::UsesPrecisionModifiers(),
1489 "#version 400\n"
1490 "precision highp float;\n"
1491 "out mediump vec4 sk_FragColor;\n"
1492 "float f = 1.0;\n"
1493 "mediump float h = 2.0;\n"
1494 "vec2 f2 = vec2(1.0, 2.0);\n"
1495 "mediump vec3 h3 = vec3(1.0, 2.0, 3.0);\n"
1496 "mat2 f22 = mat2(1.0, 2.0, 3.0, 4.0);\n"
1497 "mediump mat2x4 h24 = mat2x4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);\n");
1498}
1499
1500DEF_TEST(SkSLNumberConversions, r) {
1501 test(r,
1502 "short s = short(sqrt(1));"
1503 "int i = int(sqrt(1));"
1504 "ushort us = ushort(sqrt(1));"
1505 "uint ui = uint(sqrt(1));"
1506 "half h = sqrt(1);"
1507 "float f = sqrt(1);"
1508 "double d = sqrt(1);"
1509 "short s2s = s;"
1510 "short i2s = i;"
1511 "short us2s = short(us);"
1512 "short ui2s = short(ui);"
1513 "short h2s = short(h);"
1514 "short f2s = short(f);"
1515 "short d2fs = short(d);"
1516 "int s2i = s;"
1517 "int i2i = i;"
1518 "int us2i = int(us);"
1519 "int ui2i = int(ui);"
1520 "int h2i = int(h);"
1521 "int f2i = int(f);"
1522 "int d2fi = int(d);"
1523 "ushort s2us = ushort(s);"
1524 "ushort i2us = ushort(i);"
1525 "ushort us2us = us;"
1526 "ushort ui2us = ui;"
1527 "ushort h2us = ushort(h);"
1528 "ushort f2us = ushort(f);"
1529 "ushort d2fus = ushort(d);"
1530 "uint s2ui = uint(s);"
1531 "uint i2ui = uint(i);"
1532 "uint us2ui = us;"
1533 "uint ui2ui = ui;"
1534 "uint h2ui = uint(h);"
1535 "uint f2ui = uint(f);"
1536 "uint d2fui = uint(d);"
1537 "float s2f = s;"
1538 "float i2f = i;"
1539 "float us2f = us;"
1540 "float ui2f = ui;"
1541 "float h2f = h;"
1542 "float f2f = f;"
1543 "float d2f = d;"
1544 "double s2d = s;"
1545 "double i2d = i;"
1546 "double us2d = us;"
1547 "double ui2d = ui;"
1548 "double h2d = h;"
1549 "double f2d = f;"
1550 "double d2d = d;",
1551 *SkSL::ShaderCapsFactory::Default(),
1552 "#version 400\n"
1553 "out vec4 sk_FragColor;\n"
1554 "int s = int(sqrt(1.0));\n"
1555 "int i = int(sqrt(1.0));\n"
1556 "uint us = uint(sqrt(1.0));\n"
1557 "uint ui = uint(sqrt(1.0));\n"
1558 "float h = sqrt(1.0);\n"
1559 "float f = sqrt(1.0);\n"
1560 "double d = sqrt(1.0);\n"
1561 "int s2s = s;\n"
1562 "int i2s = i;\n"
1563 "int us2s = int(us);\n"
1564 "int ui2s = int(ui);\n"
1565 "int h2s = int(h);\n"
1566 "int f2s = int(f);\n"
1567 "int d2fs = int(d);\n"
1568 "int s2i = s;\n"
1569 "int i2i = i;\n"
1570 "int us2i = int(us);\n"
1571 "int ui2i = int(ui);\n"
1572 "int h2i = int(h);\n"
1573 "int f2i = int(f);\n"
1574 "int d2fi = int(d);\n"
1575 "uint s2us = uint(s);\n"
1576 "uint i2us = uint(i);\n"
1577 "uint us2us = us;\n"
1578 "uint ui2us = ui;\n"
1579 "uint h2us = uint(h);\n"
1580 "uint f2us = uint(f);\n"
1581 "uint d2fus = uint(d);\n"
1582 "uint s2ui = uint(s);\n"
1583 "uint i2ui = uint(i);\n"
1584 "uint us2ui = us;\n"
1585 "uint ui2ui = ui;\n"
1586 "uint h2ui = uint(h);\n"
1587 "uint f2ui = uint(f);\n"
1588 "uint d2fui = uint(d);\n"
1589 "float s2f = float(s);\n"
1590 "float i2f = float(i);\n"
1591 "float us2f = float(us);\n"
1592 "float ui2f = float(ui);\n"
1593 "float h2f = h;\n"
1594 "float f2f = f;\n"
1595 "float d2f = d;\n"
1596 "double s2d = double(s);\n"
1597 "double i2d = double(i);\n"
1598 "double us2d = double(us);\n"
1599 "double ui2d = double(ui);\n"
1600 "double h2d = h;\n"
1601 "double f2d = f;\n"
1602 "double d2d = d;\n");
1603}
1604
Ethan Nicholas7ef4b742016-11-11 15:16:46 -05001605#endif