John Stiles | 34de5cb | 2020-11-13 18:14:11 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 Google LLC |
| 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 "src/sksl/SkSLCompiler.h" |
| 9 | |
| 10 | #include "tests/Test.h" |
| 11 | |
| 12 | static void test(skiatest::Reporter* r, |
| 13 | const GrShaderCaps& caps, |
| 14 | const char* src, |
John Stiles | dbd4e6f | 2021-02-16 13:29:15 -0500 | [diff] [blame] | 15 | SkSL::ProgramKind kind = SkSL::ProgramKind::kFragment) { |
John Stiles | 34de5cb | 2020-11-13 18:14:11 -0500 | [diff] [blame] | 16 | SkSL::Compiler compiler(&caps); |
| 17 | SkSL::Program::Settings settings; |
| 18 | SkSL::String output; |
| 19 | std::unique_ptr<SkSL::Program> program = compiler.convertProgram(kind, SkSL::String(src), |
| 20 | settings); |
| 21 | if (!program) { |
| 22 | SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().c_str()); |
| 23 | REPORTER_ASSERT(r, program); |
| 24 | } else { |
| 25 | REPORTER_ASSERT(r, compiler.toMetal(*program, &output)); |
| 26 | REPORTER_ASSERT(r, output != ""); |
| 27 | //SkDebugf("Metal output:\n\n%s", output.c_str()); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | DEF_TEST(SkSLMetalTestbed, r) { |
| 32 | // Add in your SkSL here. |
| 33 | test(r, |
| 34 | *SkSL::ShaderCapsFactory::Default(), |
| 35 | R"__SkSL__( |
| 36 | void main() { |
| 37 | sk_FragColor = half4(0); |
| 38 | } |
| 39 | )__SkSL__"); |
| 40 | } |