Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | |
| 12 | #if SK_SUPPORT_GPU |
| 13 | |
| 14 | static void test(skiatest::Reporter* r, const char* src, const GrShaderCaps& caps, |
| 15 | std::vector<const char*> expectedH, std::vector<const char*> expectedCPP) { |
| 16 | SkSL::Program::Settings settings; |
| 17 | settings.fCaps = ∩︀ |
| 18 | SkSL::Compiler compiler; |
| 19 | SkSL::StringStream output; |
| 20 | std::unique_ptr<SkSL::Program> program = compiler.convertProgram( |
| 21 | SkSL::Program::kFragmentProcessor_Kind, |
Brian Osman | 93ba0a4 | 2017-08-14 14:48:10 -0400 | [diff] [blame] | 22 | SkSL::String(src), |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 23 | settings); |
| 24 | if (!program) { |
| 25 | SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().c_str()); |
| 26 | return; |
| 27 | } |
| 28 | REPORTER_ASSERT(r, program); |
| 29 | bool success = compiler.toH(*program, "Test", output); |
| 30 | if (!success) { |
| 31 | SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().c_str()); |
| 32 | } |
| 33 | REPORTER_ASSERT(r, success); |
| 34 | if (success) { |
| 35 | for (const char* expected : expectedH) { |
| 36 | bool found = strstr(output.str().c_str(), expected); |
| 37 | if (!found) { |
| 38 | SkDebugf("HEADER MISMATCH:\nsource:\n%s\n\nexpected:\n'%s'\n\nreceived:\n'%s'", src, |
| 39 | expected, output.str().c_str()); |
| 40 | } |
| 41 | REPORTER_ASSERT(r, found); |
| 42 | } |
| 43 | } |
| 44 | output.reset(); |
| 45 | success = compiler.toCPP(*program, "Test", output); |
| 46 | if (!success) { |
| 47 | SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().c_str()); |
| 48 | } |
| 49 | REPORTER_ASSERT(r, success); |
| 50 | if (success) { |
| 51 | for (const char* expected : expectedCPP) { |
| 52 | bool found = strstr(output.str().c_str(), expected); |
| 53 | if (!found) { |
| 54 | SkDebugf("CPP MISMATCH:\nsource:\n%s\n\nexpected:\n'%s'\n\nreceived:\n'%s'", src, |
| 55 | expected, output.str().c_str()); |
| 56 | } |
| 57 | REPORTER_ASSERT(r, found); |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | DEF_TEST(SkSLFPHelloWorld, r) { |
| 63 | test(r, |
| 64 | "void main() {" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 65 | "sk_OutColor = half4(1);" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 66 | "}", |
| 67 | *SkSL::ShaderCapsFactory::Default(), |
| 68 | { |
| 69 | "/*\n" |
| 70 | " * Copyright 2017 Google Inc.\n" |
| 71 | " *\n" |
| 72 | " * Use of this source code is governed by a BSD-style license that can be\n" |
| 73 | " * found in the LICENSE file.\n" |
| 74 | " */\n" |
| 75 | "\n" |
| 76 | "/*\n" |
| 77 | " * This file was autogenerated from GrTest.fp; do not modify.\n" |
| 78 | " */\n" |
| 79 | "#ifndef GrTest_DEFINED\n" |
| 80 | "#define GrTest_DEFINED\n" |
Ethan Nicholas | ceb4d48 | 2017-07-10 15:40:20 -0400 | [diff] [blame] | 81 | "#include \"SkTypes.h\"\n" |
| 82 | "#if SK_SUPPORT_GPU\n" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 83 | "#include \"GrFragmentProcessor.h\"\n" |
| 84 | "#include \"GrCoordTransform.h\"\n" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 85 | "class GrTest : public GrFragmentProcessor {\n" |
| 86 | "public:\n" |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 87 | " static std::unique_ptr<GrFragmentProcessor> Make() {\n" |
| 88 | " return std::unique_ptr<GrFragmentProcessor>(new GrTest());\n" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 89 | " }\n" |
Ethan Nicholas | f57c0d6 | 2017-07-31 11:18:22 -0400 | [diff] [blame] | 90 | " GrTest(const GrTest& src);\n" |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 91 | " std::unique_ptr<GrFragmentProcessor> clone() const override;\n" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 92 | " const char* name() const override { return \"Test\"; }\n" |
| 93 | "private:\n" |
| 94 | " GrTest()\n" |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 95 | " : INHERITED(kGrTest_ClassID, kNone_OptimizationFlags) {\n" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 96 | " }\n" |
| 97 | " GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;\n" |
| 98 | " void onGetGLSLProcessorKey(const GrShaderCaps&,GrProcessorKeyBuilder*) " |
| 99 | "const override;\n" |
| 100 | " bool onIsEqual(const GrFragmentProcessor&) const override;\n" |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 101 | " GR_DECLARE_FRAGMENT_PROCESSOR_TEST\n" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 102 | " typedef GrFragmentProcessor INHERITED;\n" |
| 103 | "};\n" |
| 104 | "#endif\n" |
Ethan Nicholas | ceb4d48 | 2017-07-10 15:40:20 -0400 | [diff] [blame] | 105 | "#endif\n" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 106 | }, |
| 107 | { |
| 108 | "/*\n" |
| 109 | " * Copyright 2017 Google Inc.\n" |
| 110 | " *\n" |
| 111 | " * Use of this source code is governed by a BSD-style license that can be\n" |
| 112 | " * found in the LICENSE file.\n" |
| 113 | " */\n" |
| 114 | "\n" |
| 115 | "/*\n" |
| 116 | " * This file was autogenerated from GrTest.fp; do not modify.\n" |
| 117 | " */\n" |
| 118 | "#include \"GrTest.h\"\n" |
Ethan Nicholas | ceb4d48 | 2017-07-10 15:40:20 -0400 | [diff] [blame] | 119 | "#if SK_SUPPORT_GPU\n" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 120 | "#include \"glsl/GrGLSLFragmentProcessor.h\"\n" |
| 121 | "#include \"glsl/GrGLSLFragmentShaderBuilder.h\"\n" |
| 122 | "#include \"glsl/GrGLSLProgramBuilder.h\"\n" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 123 | "#include \"SkSLCPP.h\"\n" |
| 124 | "#include \"SkSLUtil.h\"\n" |
| 125 | "class GrGLSLTest : public GrGLSLFragmentProcessor {\n" |
| 126 | "public:\n" |
| 127 | " GrGLSLTest() {}\n" |
| 128 | " void emitCode(EmitArgs& args) override {\n" |
| 129 | " GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;\n" |
| 130 | " const GrTest& _outer = args.fFp.cast<GrTest>();\n" |
| 131 | " (void) _outer;\n" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 132 | " fragBuilder->codeAppendf(\"%s = half4(1.0);\\n\", args.fOutputColor);\n" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 133 | " }\n" |
| 134 | "private:\n" |
| 135 | " void onSetData(const GrGLSLProgramDataManager& pdman, " |
| 136 | "const GrFragmentProcessor& _proc) override {\n" |
| 137 | " }\n" |
| 138 | "};\n" |
| 139 | "GrGLSLFragmentProcessor* GrTest::onCreateGLSLInstance() const {\n" |
| 140 | " return new GrGLSLTest();\n" |
| 141 | "}\n" |
| 142 | "void GrTest::onGetGLSLProcessorKey(const GrShaderCaps& caps, " |
| 143 | "GrProcessorKeyBuilder* b) const {\n" |
| 144 | "}\n" |
| 145 | "bool GrTest::onIsEqual(const GrFragmentProcessor& other) const {\n" |
| 146 | " const GrTest& that = other.cast<GrTest>();\n" |
| 147 | " (void) that;\n" |
| 148 | " return true;\n" |
| 149 | "}\n" |
Ethan Nicholas | f57c0d6 | 2017-07-31 11:18:22 -0400 | [diff] [blame] | 150 | "GrTest::GrTest(const GrTest& src)\n" |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 151 | ": INHERITED(kGrTest_ClassID, src.optimizationFlags()) {\n" |
Ethan Nicholas | f57c0d6 | 2017-07-31 11:18:22 -0400 | [diff] [blame] | 152 | "}\n" |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 153 | "std::unique_ptr<GrFragmentProcessor> GrTest::clone() const {\n" |
| 154 | " return std::unique_ptr<GrFragmentProcessor>(new GrTest(*this));\n" |
Ethan Nicholas | f57c0d6 | 2017-07-31 11:18:22 -0400 | [diff] [blame] | 155 | "}\n" |
Ethan Nicholas | ceb4d48 | 2017-07-10 15:40:20 -0400 | [diff] [blame] | 156 | "#endif\n" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 157 | }); |
| 158 | } |
| 159 | |
| 160 | DEF_TEST(SkSLFPInput, r) { |
| 161 | test(r, |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 162 | "in half2 point;" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 163 | "void main() {" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 164 | "sk_OutColor = half4(point, point);" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 165 | "}", |
| 166 | *SkSL::ShaderCapsFactory::Default(), |
| 167 | { |
| 168 | "SkPoint point() const { return fPoint; }", |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 169 | "static std::unique_ptr<GrFragmentProcessor> Make(SkPoint point) {", |
| 170 | "return std::unique_ptr<GrFragmentProcessor>(new GrTest(point));", |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 171 | "GrTest(SkPoint point)", |
| 172 | ", fPoint(point)" |
| 173 | }, |
| 174 | { |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 175 | "fragBuilder->codeAppendf(\"%s = half4(half2(%f, %f), half2(%f, %f));\\n\", " |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 176 | "args.fOutputColor, _outer.point().fX, _outer.point().fY, " |
| 177 | "_outer.point().fX, _outer.point().fY);", |
| 178 | "if (fPoint != that.fPoint) return false;" |
| 179 | }); |
| 180 | } |
| 181 | |
| 182 | DEF_TEST(SkSLFPUniform, r) { |
| 183 | test(r, |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 184 | "uniform half4 color;" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 185 | "void main() {" |
| 186 | "sk_OutColor = color;" |
| 187 | "}", |
| 188 | *SkSL::ShaderCapsFactory::Default(), |
| 189 | { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 190 | "static std::unique_ptr<GrFragmentProcessor> Make()" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 191 | }, |
| 192 | { |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 193 | "fColorVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, " |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 194 | "kDefault_GrSLPrecision, \"color\");", |
| 195 | }); |
| 196 | } |
| 197 | |
| 198 | DEF_TEST(SkSLFPInUniform, r) { |
| 199 | test(r, |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 200 | "in uniform half4 color;" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 201 | "void main() {" |
| 202 | "sk_OutColor = color;" |
| 203 | "}", |
| 204 | *SkSL::ShaderCapsFactory::Default(), |
| 205 | { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 206 | "static std::unique_ptr<GrFragmentProcessor> Make(SkRect color) {", |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 207 | }, |
| 208 | { |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 209 | "fColorVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, " |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 210 | "kDefault_GrSLPrecision, \"color\");", |
| 211 | "const SkRect colorValue = _outer.color();", |
Ethan Nicholas | ee33873 | 2017-07-17 15:13:45 -0400 | [diff] [blame] | 212 | "pdman.set4fv(fColorVar, 1, (float*) &colorValue);" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 213 | }); |
| 214 | } |
| 215 | |
| 216 | DEF_TEST(SkSLFPSections, r) { |
| 217 | test(r, |
| 218 | "@header { header section }" |
| 219 | "void main() {" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 220 | "sk_OutColor = half4(1);" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 221 | "}", |
| 222 | *SkSL::ShaderCapsFactory::Default(), |
| 223 | { |
Ethan Nicholas | ceb4d48 | 2017-07-10 15:40:20 -0400 | [diff] [blame] | 224 | "#if SK_SUPPORT_GPU\n header section" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 225 | }, |
| 226 | {}); |
| 227 | test(r, |
| 228 | "@class { class section }" |
| 229 | "void main() {" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 230 | "sk_OutColor = half4(1);" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 231 | "}", |
| 232 | *SkSL::ShaderCapsFactory::Default(), |
| 233 | { |
| 234 | "class GrTest : public GrFragmentProcessor {\n" |
| 235 | "public:\n" |
| 236 | " class section" |
| 237 | }, |
| 238 | {}); |
| 239 | test(r, |
| 240 | "@cpp { cpp section }" |
| 241 | "void main() {" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 242 | "sk_OutColor = half4(1);" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 243 | "}", |
| 244 | *SkSL::ShaderCapsFactory::Default(), |
| 245 | {}, |
| 246 | {"cpp section"}); |
| 247 | test(r, |
| 248 | "@constructorParams { int x, float y, std::vector<float> z }" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 249 | "in float w;" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 250 | "void main() {" |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 251 | "sk_OutColor = float4(1);" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 252 | "}", |
| 253 | *SkSL::ShaderCapsFactory::Default(), |
| 254 | { |
| 255 | "Make(float w, int x, float y, std::vector<float> z )", |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 256 | "return std::unique_ptr<GrFragmentProcessor>(new GrTest(w, x, y, z));", |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 257 | "GrTest(float w, int x, float y, std::vector<float> z )", |
| 258 | ", fW(w) {" |
| 259 | }, |
| 260 | {}); |
| 261 | test(r, |
| 262 | "@constructor { constructor section }" |
| 263 | "void main() {" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 264 | "sk_OutColor = half4(1);" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 265 | "}", |
| 266 | *SkSL::ShaderCapsFactory::Default(), |
| 267 | { |
| 268 | "private:\n constructor section" |
| 269 | }, |
| 270 | {}); |
| 271 | test(r, |
| 272 | "@initializers { initializers section }" |
| 273 | "void main() {" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 274 | "sk_OutColor = half4(1);" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 275 | "}", |
| 276 | *SkSL::ShaderCapsFactory::Default(), |
| 277 | { |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 278 | ": INHERITED(kGrTest_ClassID, kNone_OptimizationFlags)\n , initializers section" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 279 | }, |
| 280 | {}); |
| 281 | test(r, |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 282 | "half x = 10;" |
| 283 | "@emitCode { fragBuilder->codeAppendf(\"half y = %d\\n\", x * 2); }" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 284 | "void main() {" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 285 | "sk_OutColor = half4(1);" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 286 | "}", |
| 287 | *SkSL::ShaderCapsFactory::Default(), |
| 288 | {}, |
| 289 | { |
| 290 | "x = 10.0;\n" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 291 | " fragBuilder->codeAppendf(\"half y = %d\\n\", x * 2);" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 292 | }); |
| 293 | test(r, |
| 294 | "@fields { fields section }" |
Ethan Nicholas | f57c0d6 | 2017-07-31 11:18:22 -0400 | [diff] [blame] | 295 | "@clone { }" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 296 | "void main() {" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 297 | "sk_OutColor = half4(1);" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 298 | "}", |
| 299 | *SkSL::ShaderCapsFactory::Default(), |
| 300 | { |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 301 | "GR_DECLARE_FRAGMENT_PROCESSOR_TEST\n" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 302 | " fields section typedef GrFragmentProcessor INHERITED;" |
| 303 | }, |
| 304 | {}); |
| 305 | test(r, |
| 306 | "@make { make section }" |
| 307 | "void main() {" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 308 | "sk_OutColor = half4(1);" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 309 | "}", |
| 310 | *SkSL::ShaderCapsFactory::Default(), |
| 311 | { |
| 312 | "public:\n" |
| 313 | " make section" |
| 314 | }, |
| 315 | {}); |
| 316 | test(r, |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 317 | "uniform half calculated;" |
| 318 | "in half provided;" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 319 | "@setData(varName) { varName.set1f(calculated, provided * 2); }" |
| 320 | "void main() {" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 321 | "sk_OutColor = half4(1);" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 322 | "}", |
| 323 | *SkSL::ShaderCapsFactory::Default(), |
| 324 | {}, |
| 325 | { |
| 326 | "void onSetData(const GrGLSLProgramDataManager& varName, " |
| 327 | "const GrFragmentProcessor& _proc) override {\n", |
| 328 | "UniformHandle& calculated = fCalculatedVar;", |
| 329 | "auto provided = _outer.provided();", |
| 330 | "varName.set1f(calculated, provided * 2);" |
| 331 | }); |
| 332 | test(r, |
| 333 | "@test(testDataName) { testDataName section }" |
| 334 | "void main() {" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 335 | "sk_OutColor = half4(1);" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 336 | "}", |
| 337 | *SkSL::ShaderCapsFactory::Default(), |
| 338 | {}, |
| 339 | { |
| 340 | "#if GR_TEST_UTILS\n" |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 341 | "std::unique_ptr<GrFragmentProcessor> GrTest::TestCreate(GrProcessorTestData* testDataName) {\n" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 342 | " testDataName section }\n" |
| 343 | "#endif" |
| 344 | }); |
| 345 | } |
| 346 | |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 347 | DEF_TEST(SkSLFPTransformedCoords, r) { |
| 348 | test(r, |
| 349 | "void main() {" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 350 | "sk_OutColor = half4(sk_TransformedCoords2D[0], sk_TransformedCoords2D[0]);" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 351 | "}", |
| 352 | *SkSL::ShaderCapsFactory::Default(), |
| 353 | {}, |
| 354 | { |
Brian Osman | 72a37be | 2017-08-15 09:19:53 -0400 | [diff] [blame] | 355 | "SkString sk_TransformedCoords2D_0 = " |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 356 | "fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);", |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 357 | "fragBuilder->codeAppendf(\"%s = half4(%s, %s);\\n\", args.fOutputColor, " |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 358 | "sk_TransformedCoords2D_0.c_str(), sk_TransformedCoords2D_0.c_str());" |
| 359 | }); |
| 360 | |
| 361 | } |
| 362 | |
| 363 | DEF_TEST(SkSLFPLayoutWhen, r) { |
| 364 | test(r, |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 365 | "layout(when=someExpression(someOtherExpression())) uniform half sometimes;" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 366 | "void main() {" |
| 367 | "}", |
| 368 | *SkSL::ShaderCapsFactory::Default(), |
| 369 | {}, |
| 370 | { |
| 371 | "if (someExpression(someOtherExpression())) {\n" |
| 372 | " fSometimesVar = args.fUniformHandler->addUniform" |
| 373 | }); |
| 374 | |
| 375 | } |
| 376 | |
Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 377 | DEF_TEST(SkSLFPChildProcessors, r) { |
| 378 | test(r, |
| 379 | "in fragmentProcessor child1;" |
| 380 | "in fragmentProcessor child2;" |
| 381 | "void main() {" |
| 382 | " sk_OutColor = process(child1) * process(child2);" |
| 383 | "}", |
| 384 | *SkSL::ShaderCapsFactory::Default(), |
| 385 | { |
| 386 | "this->registerChildProcessor(std::move(child1));", |
| 387 | "this->registerChildProcessor(std::move(child2));" |
| 388 | }, |
| 389 | { |
| 390 | "SkString _child0(\"_child0\");", |
| 391 | "this->emitChild(0, &_child0, args);", |
| 392 | "SkString _child1(\"_child1\");", |
| 393 | "this->emitChild(1, &_child1, args);", |
| 394 | "this->registerChildProcessor(src.childProcessor(0).clone());", |
| 395 | "this->registerChildProcessor(src.childProcessor(1).clone());" |
| 396 | }); |
| 397 | } |
| 398 | |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 399 | #endif |