skia2/tests/SkSLSPIRVTestbed.cpp
Jim Van Verth 3b0eacc6ea Add SkSL::ShaderCaps and use as base class for GrShaderCaps
Bug: skia:12559
Change-Id: I76b225c9ca81264a15869324007d774d210053b5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/473416
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-11-19 16:35:39 +00:00

39 lines
1.1 KiB
C++

/*
* Copyright 2020 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/sksl/SkSLCompiler.h"
#include "tests/Test.h"
static void test(skiatest::Reporter* r,
const SkSL::ShaderCaps& caps,
const char* src,
SkSL::ProgramKind kind = SkSL::ProgramKind::kFragment) {
SkSL::Compiler compiler(&caps);
SkSL::Program::Settings settings;
SkSL::String output;
std::unique_ptr<SkSL::Program> program = compiler.convertProgram(kind, SkSL::String(src),
settings);
if (!program) {
SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().c_str());
REPORTER_ASSERT(r, program);
} else {
REPORTER_ASSERT(r, compiler.toSPIRV(*program, &output));
}
}
DEF_TEST(SkSLSPIRVTestbed, r) {
// Add in your SkSL here.
test(r,
*SkSL::ShaderCapsFactory::Default(),
R"__SkSL__(
void main() {
sk_FragColor = half4(0);
}
)__SkSL__");
}