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 
test(skiatest::Reporter * r,const GrShaderCaps & caps,const char * src,SkSL::ProgramKind kind=SkSL::ProgramKind::kFragment)12 static void test(skiatest::Reporter* r,
13                  const GrShaderCaps& caps,
14                  const char* src,
15                  SkSL::ProgramKind kind = SkSL::ProgramKind::kFragment) {
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.toSPIRV(*program, &output));
26     }
27 }
28 
DEF_TEST(SkSLSPIRVTestbed,r)29 DEF_TEST(SkSLSPIRVTestbed, r) {
30     // Add in your SkSL here.
31     test(r,
32          *SkSL::ShaderCapsFactory::Default(),
33          R"__SkSL__(
34              void main() {
35                  sk_FragColor = half4(0);
36              }
37          )__SkSL__");
38 }
39