skia2/tests/SkSLFPTestbed.cpp
Brian Osman d7e7659cad Move GrShaderCaps from Program::Settings to Compiler
This ties the caps to the compiler instance, paving the way for
pre-optimizing the shared code. Most of the time, the compiler is
created and owned the GPU instance, so this is fine. For runtime
effects, we now use the shared (device-agnostic) compiler instance
for the first compile, even on GPU. It's configured with caps that
apply no workarounds. We pass the user's SkSL to the backend as
cleanly as possible, and then apply any workarounds once it's part
of the full program.

Bug: skia:10905
Bug: skia:10868
Change-Id: Ifcf8d7ebda5d43ad8e180f06700a261811da83de
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/331493
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2020-11-04 19:38:33 +00:00

51 lines
1.7 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 "src/sksl/SkSLStringStream.h"
#include "tests/Test.h"
static void test(skiatest::Reporter* r, const GrShaderCaps& caps, const char* src) {
SkSL::Program::Settings settings;
settings.fRemoveDeadFunctions = false;
SkSL::Compiler compiler(&caps);
SkSL::StringStream output;
std::unique_ptr<SkSL::Program> program = compiler.convertProgram(
SkSL::Program::kFragmentProcessor_Kind,
SkSL::String(src),
settings);
if (!program) {
SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().c_str());
return;
}
REPORTER_ASSERT(r, program);
bool success = compiler.toH(*program, "Test", output);
if (!success) {
SkDebugf("Unexpected error generating .h file for %s\n%s",
src, compiler.errorText().c_str());
}
REPORTER_ASSERT(r, success);
output.reset();
success = compiler.toCPP(*program, "Test", output);
if (!success) {
SkDebugf("Unexpected error generating .cpp file for %s\n%s",
src, compiler.errorText().c_str());
}
REPORTER_ASSERT(r, success);
}
DEF_TEST(SkSLFPTestbed, r) {
test(r,
*SkSL::ShaderCapsFactory::Default(),
R"__SkSL__(
void main(float2 coord) {
sk_OutColor = half4(0);
}
)__SkSL__");
}