2017-06-29 14:03:38 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/sksl/SkSLCompiler.h"
|
2019-06-06 14:04:27 +00:00
|
|
|
#include "src/sksl/SkSLStringStream.h"
|
2017-06-29 14:03:38 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
2017-06-29 14:03:38 +00:00
|
|
|
|
|
|
|
static void test(skiatest::Reporter* r, const char* src, const GrShaderCaps& caps,
|
|
|
|
std::vector<const char*> expectedH, std::vector<const char*> expectedCPP) {
|
|
|
|
SkSL::Program::Settings settings;
|
|
|
|
settings.fCaps = ∩︀
|
|
|
|
SkSL::Compiler compiler;
|
|
|
|
SkSL::StringStream output;
|
|
|
|
std::unique_ptr<SkSL::Program> program = compiler.convertProgram(
|
|
|
|
SkSL::Program::kFragmentProcessor_Kind,
|
2017-08-14 18:48:10 +00:00
|
|
|
SkSL::String(src),
|
2017-06-29 14:03:38 +00:00
|
|
|
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 compiling %s\n%s", src, compiler.errorText().c_str());
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(r, success);
|
|
|
|
if (success) {
|
|
|
|
for (const char* expected : expectedH) {
|
|
|
|
bool found = strstr(output.str().c_str(), expected);
|
|
|
|
if (!found) {
|
|
|
|
SkDebugf("HEADER MISMATCH:\nsource:\n%s\n\nexpected:\n'%s'\n\nreceived:\n'%s'", src,
|
|
|
|
expected, output.str().c_str());
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(r, found);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
output.reset();
|
|
|
|
success = compiler.toCPP(*program, "Test", output);
|
|
|
|
if (!success) {
|
|
|
|
SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().c_str());
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(r, success);
|
|
|
|
if (success) {
|
|
|
|
for (const char* expected : expectedCPP) {
|
|
|
|
bool found = strstr(output.str().c_str(), expected);
|
|
|
|
if (!found) {
|
|
|
|
SkDebugf("CPP MISMATCH:\nsource:\n%s\n\nexpected:\n'%s'\n\nreceived:\n'%s'", src,
|
|
|
|
expected, output.str().c_str());
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(r, found);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-13 14:21:38 +00:00
|
|
|
static void test_failure(skiatest::Reporter* r, const char* src, const char* error) {
|
|
|
|
SkSL::Compiler compiler;
|
|
|
|
SkSL::Program::Settings settings;
|
|
|
|
sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
|
|
|
|
settings.fCaps = caps.get();
|
|
|
|
std::unique_ptr<SkSL::Program> program = compiler.convertProgram(
|
|
|
|
SkSL::Program::kFragmentProcessor_Kind,
|
|
|
|
SkSL::String(src),
|
|
|
|
settings);
|
|
|
|
if (!compiler.errorCount()) {
|
|
|
|
compiler.optimize(*program);
|
|
|
|
}
|
|
|
|
SkSL::String skError(error);
|
|
|
|
if (compiler.errorText() != skError) {
|
|
|
|
SkDebugf("SKSL ERROR:\n source: %s\n expected: %s received: %s", src, error,
|
|
|
|
compiler.errorText().c_str());
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(r, compiler.errorText() == skError);
|
|
|
|
}
|
|
|
|
|
2017-06-29 14:03:38 +00:00
|
|
|
DEF_TEST(SkSLFPHelloWorld, r) {
|
|
|
|
test(r,
|
2018-02-01 17:14:34 +00:00
|
|
|
"/* HEADER */"
|
2017-06-29 14:03:38 +00:00
|
|
|
"void main() {"
|
2017-09-18 18:10:39 +00:00
|
|
|
"sk_OutColor = half4(1);"
|
2017-06-29 14:03:38 +00:00
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
2018-02-01 17:14:34 +00:00
|
|
|
"/* HEADER */\n"
|
2017-06-29 14:03:38 +00:00
|
|
|
"\n"
|
2018-02-01 17:14:34 +00:00
|
|
|
"/**************************************************************************************************\n"
|
|
|
|
" *** This file was autogenerated from GrTest.fp; do not modify.\n"
|
|
|
|
" **************************************************************************************************/\n"
|
2017-06-29 14:03:38 +00:00
|
|
|
"#ifndef GrTest_DEFINED\n"
|
|
|
|
"#define GrTest_DEFINED\n"
|
2019-04-23 17:05:21 +00:00
|
|
|
"#include \"include/core/SkTypes.h\"\n\n"
|
|
|
|
"#include \"src/gpu/GrCoordTransform.h\"\n"
|
|
|
|
"#include \"src/gpu/GrFragmentProcessor.h\"\n"
|
2017-06-29 14:03:38 +00:00
|
|
|
"class GrTest : public GrFragmentProcessor {\n"
|
|
|
|
"public:\n"
|
2017-08-11 13:40:37 +00:00
|
|
|
" static std::unique_ptr<GrFragmentProcessor> Make() {\n"
|
|
|
|
" return std::unique_ptr<GrFragmentProcessor>(new GrTest());\n"
|
2017-06-29 14:03:38 +00:00
|
|
|
" }\n"
|
2017-07-31 15:18:22 +00:00
|
|
|
" GrTest(const GrTest& src);\n"
|
2017-08-11 13:40:37 +00:00
|
|
|
" std::unique_ptr<GrFragmentProcessor> clone() const override;\n"
|
2017-06-29 14:03:38 +00:00
|
|
|
" const char* name() const override { return \"Test\"; }\n"
|
|
|
|
"private:\n"
|
|
|
|
" GrTest()\n"
|
2017-10-09 14:54:08 +00:00
|
|
|
" : INHERITED(kGrTest_ClassID, kNone_OptimizationFlags) {\n"
|
2017-06-29 14:03:38 +00:00
|
|
|
" }\n"
|
|
|
|
" GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;\n"
|
2019-04-09 14:40:41 +00:00
|
|
|
" void onGetGLSLProcessorKey(const GrShaderCaps&,GrProcessorKeyBuilder*) const "
|
|
|
|
"override;\n"
|
2017-06-29 14:03:38 +00:00
|
|
|
" bool onIsEqual(const GrFragmentProcessor&) const override;\n"
|
2017-07-06 14:09:38 +00:00
|
|
|
" GR_DECLARE_FRAGMENT_PROCESSOR_TEST\n"
|
2017-06-29 14:03:38 +00:00
|
|
|
" typedef GrFragmentProcessor INHERITED;\n"
|
|
|
|
"};\n"
|
|
|
|
"#endif\n"
|
|
|
|
},
|
|
|
|
{
|
2018-02-01 17:14:34 +00:00
|
|
|
"/**************************************************************************************************\n"
|
|
|
|
" *** This file was autogenerated from GrTest.fp; do not modify.\n"
|
|
|
|
" **************************************************************************************************/\n"
|
2019-04-23 17:05:21 +00:00
|
|
|
"#include \"GrTest.h\"\n\n"
|
|
|
|
"#include \"include/gpu/GrTexture.h\"\n"
|
|
|
|
"#include \"src/gpu/glsl/GrGLSLFragmentProcessor.h\"\n"
|
|
|
|
"#include \"src/gpu/glsl/GrGLSLFragmentShaderBuilder.h\"\n"
|
|
|
|
"#include \"src/gpu/glsl/GrGLSLProgramBuilder.h\"\n"
|
|
|
|
"#include \"src/sksl/SkSLCPP.h\"\n"
|
|
|
|
"#include \"src/sksl/SkSLUtil.h\"\n"
|
2017-06-29 14:03:38 +00:00
|
|
|
"class GrGLSLTest : public GrGLSLFragmentProcessor {\n"
|
|
|
|
"public:\n"
|
|
|
|
" GrGLSLTest() {}\n"
|
|
|
|
" void emitCode(EmitArgs& args) override {\n"
|
|
|
|
" GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;\n"
|
|
|
|
" const GrTest& _outer = args.fFp.cast<GrTest>();\n"
|
|
|
|
" (void) _outer;\n"
|
2017-09-18 18:10:39 +00:00
|
|
|
" fragBuilder->codeAppendf(\"%s = half4(1.0);\\n\", args.fOutputColor);\n"
|
2017-06-29 14:03:38 +00:00
|
|
|
" }\n"
|
|
|
|
"private:\n"
|
|
|
|
" void onSetData(const GrGLSLProgramDataManager& pdman, "
|
|
|
|
"const GrFragmentProcessor& _proc) override {\n"
|
|
|
|
" }\n"
|
|
|
|
"};\n"
|
|
|
|
"GrGLSLFragmentProcessor* GrTest::onCreateGLSLInstance() const {\n"
|
|
|
|
" return new GrGLSLTest();\n"
|
|
|
|
"}\n"
|
|
|
|
"void GrTest::onGetGLSLProcessorKey(const GrShaderCaps& caps, "
|
|
|
|
"GrProcessorKeyBuilder* b) const {\n"
|
|
|
|
"}\n"
|
|
|
|
"bool GrTest::onIsEqual(const GrFragmentProcessor& other) const {\n"
|
|
|
|
" const GrTest& that = other.cast<GrTest>();\n"
|
|
|
|
" (void) that;\n"
|
|
|
|
" return true;\n"
|
|
|
|
"}\n"
|
2017-07-31 15:18:22 +00:00
|
|
|
"GrTest::GrTest(const GrTest& src)\n"
|
2017-10-09 14:54:08 +00:00
|
|
|
": INHERITED(kGrTest_ClassID, src.optimizationFlags()) {\n"
|
2017-07-31 15:18:22 +00:00
|
|
|
"}\n"
|
2017-08-11 13:40:37 +00:00
|
|
|
"std::unique_ptr<GrFragmentProcessor> GrTest::clone() const {\n"
|
|
|
|
" return std::unique_ptr<GrFragmentProcessor>(new GrTest(*this));\n"
|
2017-07-31 15:18:22 +00:00
|
|
|
"}\n"
|
2017-06-29 14:03:38 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(SkSLFPInput, r) {
|
|
|
|
test(r,
|
2019-08-13 14:21:38 +00:00
|
|
|
"layout(key) in half2 point;"
|
2017-06-29 14:03:38 +00:00
|
|
|
"void main() {"
|
2017-09-18 18:10:39 +00:00
|
|
|
"sk_OutColor = half4(point, point);"
|
2017-06-29 14:03:38 +00:00
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
2017-08-11 13:40:37 +00:00
|
|
|
"static std::unique_ptr<GrFragmentProcessor> Make(SkPoint point) {",
|
|
|
|
"return std::unique_ptr<GrFragmentProcessor>(new GrTest(point));",
|
2017-06-29 14:03:38 +00:00
|
|
|
"GrTest(SkPoint point)",
|
2019-04-09 14:40:41 +00:00
|
|
|
", point(point)"
|
2017-06-29 14:03:38 +00:00
|
|
|
},
|
|
|
|
{
|
2017-09-18 18:10:39 +00:00
|
|
|
"fragBuilder->codeAppendf(\"%s = half4(half2(%f, %f), half2(%f, %f));\\n\", "
|
2019-04-09 14:40:41 +00:00
|
|
|
"args.fOutputColor, _outer.point.fX, _outer.point.fY, "
|
|
|
|
"_outer.point.fX, _outer.point.fY);",
|
|
|
|
"if (point != that.point) return false;"
|
2017-06-29 14:03:38 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(SkSLFPUniform, r) {
|
|
|
|
test(r,
|
2017-09-18 18:10:39 +00:00
|
|
|
"uniform half4 color;"
|
2017-06-29 14:03:38 +00:00
|
|
|
"void main() {"
|
|
|
|
"sk_OutColor = color;"
|
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
2017-08-11 13:40:37 +00:00
|
|
|
"static std::unique_ptr<GrFragmentProcessor> Make()"
|
2017-06-29 14:03:38 +00:00
|
|
|
},
|
|
|
|
{
|
2019-04-09 14:40:41 +00:00
|
|
|
"colorVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, "
|
|
|
|
"\"color\");",
|
2017-06-29 14:03:38 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-31 14:52:47 +00:00
|
|
|
// SkSLFPInUniform tests the simplest plumbing case, default type, no tracking
|
|
|
|
// with a setUniform template that supports inlining the value call with no
|
|
|
|
// local variable.
|
2017-06-29 14:03:38 +00:00
|
|
|
DEF_TEST(SkSLFPInUniform, r) {
|
|
|
|
test(r,
|
2017-09-18 18:10:39 +00:00
|
|
|
"in uniform half4 color;"
|
2017-06-29 14:03:38 +00:00
|
|
|
"void main() {"
|
|
|
|
"sk_OutColor = color;"
|
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
2017-08-11 13:40:37 +00:00
|
|
|
"static std::unique_ptr<GrFragmentProcessor> Make(SkRect color) {",
|
2017-06-29 14:03:38 +00:00
|
|
|
},
|
|
|
|
{
|
2019-04-09 14:40:41 +00:00
|
|
|
"colorVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, "
|
|
|
|
"\"color\");",
|
|
|
|
"pdman.set4fv(colorVar, 1, reinterpret_cast<const float*>(&(_outer.color)));"
|
2018-08-31 14:52:47 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// As above, but tests in uniform's ability to override the default ctype.
|
|
|
|
DEF_TEST(SkSLFPInUniformCType, r) {
|
|
|
|
test(r,
|
2018-10-16 19:45:55 +00:00
|
|
|
"layout(ctype=SkPMColor4f) in uniform half4 color;"
|
2018-08-31 14:52:47 +00:00
|
|
|
"void main() {"
|
|
|
|
"sk_OutColor = color;"
|
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
2018-10-16 19:45:55 +00:00
|
|
|
"static std::unique_ptr<GrFragmentProcessor> Make(SkPMColor4f color) {",
|
2018-08-31 14:52:47 +00:00
|
|
|
},
|
|
|
|
{
|
2019-04-09 14:40:41 +00:00
|
|
|
"colorVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, "
|
|
|
|
"\"color\");",
|
|
|
|
"pdman.set4fv(colorVar, 1, (_outer.color).vec());"
|
2018-08-31 14:52:47 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add state tracking to the default typed SkRect <-> half4 uniform. But since
|
|
|
|
// it now has to track state, the value inlining previously done for the
|
|
|
|
// setUniform call is removed in favor of a local variable.
|
|
|
|
DEF_TEST(SkSLFPTrackedInUniform, r) {
|
|
|
|
test(r,
|
|
|
|
"layout(tracked) in uniform half4 color;"
|
|
|
|
"void main() {"
|
|
|
|
"sk_OutColor = color;"
|
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
|
|
|
"static std::unique_ptr<GrFragmentProcessor> Make(SkRect color) {",
|
|
|
|
},
|
|
|
|
{
|
2019-04-09 14:40:41 +00:00
|
|
|
"SkRect colorPrev = SkRect::MakeEmpty();",
|
|
|
|
"colorVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, "
|
|
|
|
"\"color\");",
|
|
|
|
"const SkRect& colorValue = _outer.color;",
|
|
|
|
"if (colorPrev.isEmpty() || colorPrev != colorValue) {",
|
|
|
|
"colorPrev = colorValue;",
|
|
|
|
"pdman.set4fv(colorVar, 1, reinterpret_cast<const float*>(&colorValue));"
|
2018-08-31 14:52:47 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test the case where the template does not support variable inlining in
|
|
|
|
// setUniform (i.e. it references the value multiple times).
|
|
|
|
DEF_TEST(SkSLFPNonInlinedInUniform, r) {
|
|
|
|
test(r,
|
|
|
|
"in uniform half2 point;"
|
|
|
|
"void main() {"
|
|
|
|
"sk_OutColor = half4(point, point);"
|
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
|
|
|
"static std::unique_ptr<GrFragmentProcessor> Make(SkPoint point) {",
|
|
|
|
},
|
|
|
|
{
|
2019-04-09 14:40:41 +00:00
|
|
|
"pointVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, "
|
|
|
|
"\"point\");",
|
|
|
|
"const SkPoint& pointValue = _outer.point;",
|
|
|
|
"pdman.set2f(pointVar, pointValue.fX, pointValue.fY);"
|
2018-08-31 14:52:47 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test handling conditional uniforms (that use when= in layout), combined with
|
|
|
|
// state tracking and custom ctypes to really put the code generation through its paces.
|
|
|
|
DEF_TEST(SkSLFPConditionalInUniform, r) {
|
|
|
|
test(r,
|
2019-08-13 14:21:38 +00:00
|
|
|
"layout(key) in bool test;"
|
2018-10-16 19:45:55 +00:00
|
|
|
"layout(ctype=SkPMColor4f, tracked, when=test) in uniform half4 color;"
|
2018-08-31 14:52:47 +00:00
|
|
|
"void main() {"
|
|
|
|
" if (test) {"
|
|
|
|
" sk_OutColor = color;"
|
|
|
|
" } else {"
|
|
|
|
" sk_OutColor = half4(1);"
|
|
|
|
" }"
|
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
2018-10-16 19:45:55 +00:00
|
|
|
"static std::unique_ptr<GrFragmentProcessor> Make(bool test, SkPMColor4f color) {",
|
2018-08-31 14:52:47 +00:00
|
|
|
},
|
|
|
|
{
|
2019-04-09 14:40:41 +00:00
|
|
|
"SkPMColor4f colorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN}",
|
|
|
|
"auto test = _outer.test;",
|
2018-08-31 14:52:47 +00:00
|
|
|
"if (test) {",
|
2019-04-09 14:40:41 +00:00
|
|
|
"colorVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, "
|
|
|
|
"\"color\");",
|
|
|
|
"if (colorVar.isValid()) {",
|
|
|
|
"const SkPMColor4f& colorValue = _outer.color;",
|
|
|
|
"if (colorPrev != colorValue) {",
|
|
|
|
"colorPrev = colorValue;",
|
|
|
|
"pdman.set4fv(colorVar, 1, colorValue.vec());"
|
2017-06-29 14:03:38 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(SkSLFPSections, r) {
|
|
|
|
test(r,
|
|
|
|
"@header { header section }"
|
|
|
|
"void main() {"
|
2017-09-18 18:10:39 +00:00
|
|
|
"sk_OutColor = half4(1);"
|
2017-06-29 14:03:38 +00:00
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
2018-04-06 14:37:55 +00:00
|
|
|
"header section"
|
2017-06-29 14:03:38 +00:00
|
|
|
},
|
|
|
|
{});
|
|
|
|
test(r,
|
|
|
|
"@class { class section }"
|
|
|
|
"void main() {"
|
2017-09-18 18:10:39 +00:00
|
|
|
"sk_OutColor = half4(1);"
|
2017-06-29 14:03:38 +00:00
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
|
|
|
"class GrTest : public GrFragmentProcessor {\n"
|
|
|
|
"public:\n"
|
|
|
|
" class section"
|
|
|
|
},
|
|
|
|
{});
|
|
|
|
test(r,
|
|
|
|
"@cpp { cpp section }"
|
|
|
|
"void main() {"
|
2017-09-18 18:10:39 +00:00
|
|
|
"sk_OutColor = half4(1);"
|
2017-06-29 14:03:38 +00:00
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{},
|
|
|
|
{"cpp section"});
|
|
|
|
test(r,
|
|
|
|
"@constructorParams { int x, float y, std::vector<float> z }"
|
2017-09-20 15:24:15 +00:00
|
|
|
"in float w;"
|
2017-06-29 14:03:38 +00:00
|
|
|
"void main() {"
|
2019-02-05 22:17:40 +00:00
|
|
|
"sk_OutColor = half4(1);"
|
2017-06-29 14:03:38 +00:00
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
|
|
|
"Make(float w, int x, float y, std::vector<float> z )",
|
2017-08-11 13:40:37 +00:00
|
|
|
"return std::unique_ptr<GrFragmentProcessor>(new GrTest(w, x, y, z));",
|
2017-06-29 14:03:38 +00:00
|
|
|
"GrTest(float w, int x, float y, std::vector<float> z )",
|
2019-04-09 14:40:41 +00:00
|
|
|
", w(w) {"
|
2017-06-29 14:03:38 +00:00
|
|
|
},
|
|
|
|
{});
|
|
|
|
test(r,
|
|
|
|
"@constructor { constructor section }"
|
|
|
|
"void main() {"
|
2017-09-18 18:10:39 +00:00
|
|
|
"sk_OutColor = half4(1);"
|
2017-06-29 14:03:38 +00:00
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
|
|
|
"private:\n constructor section"
|
|
|
|
},
|
|
|
|
{});
|
|
|
|
test(r,
|
|
|
|
"@initializers { initializers section }"
|
|
|
|
"void main() {"
|
2017-09-18 18:10:39 +00:00
|
|
|
"sk_OutColor = half4(1);"
|
2017-06-29 14:03:38 +00:00
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
2017-10-09 14:54:08 +00:00
|
|
|
": INHERITED(kGrTest_ClassID, kNone_OptimizationFlags)\n , initializers section"
|
2017-06-29 14:03:38 +00:00
|
|
|
},
|
|
|
|
{});
|
|
|
|
test(r,
|
2017-09-18 18:10:39 +00:00
|
|
|
"half x = 10;"
|
|
|
|
"@emitCode { fragBuilder->codeAppendf(\"half y = %d\\n\", x * 2); }"
|
2017-06-29 14:03:38 +00:00
|
|
|
"void main() {"
|
2017-09-18 18:10:39 +00:00
|
|
|
"sk_OutColor = half4(1);"
|
2017-06-29 14:03:38 +00:00
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
"x = 10.0;\n"
|
2017-09-18 18:10:39 +00:00
|
|
|
" fragBuilder->codeAppendf(\"half y = %d\\n\", x * 2);"
|
2017-06-29 14:03:38 +00:00
|
|
|
});
|
|
|
|
test(r,
|
|
|
|
"@fields { fields section }"
|
2017-07-31 15:18:22 +00:00
|
|
|
"@clone { }"
|
2017-06-29 14:03:38 +00:00
|
|
|
"void main() {"
|
2017-09-18 18:10:39 +00:00
|
|
|
"sk_OutColor = half4(1);"
|
2017-06-29 14:03:38 +00:00
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
2019-04-09 14:40:41 +00:00
|
|
|
"const char* name() const override { return \"Test\"; }\n"
|
|
|
|
" fields section private:"
|
2017-06-29 14:03:38 +00:00
|
|
|
},
|
|
|
|
{});
|
|
|
|
test(r,
|
|
|
|
"@make { make section }"
|
|
|
|
"void main() {"
|
2017-09-18 18:10:39 +00:00
|
|
|
"sk_OutColor = half4(1);"
|
2017-06-29 14:03:38 +00:00
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
|
|
|
"public:\n"
|
|
|
|
" make section"
|
|
|
|
},
|
|
|
|
{});
|
|
|
|
test(r,
|
2017-09-18 18:10:39 +00:00
|
|
|
"uniform half calculated;"
|
2019-08-13 14:21:38 +00:00
|
|
|
"layout(key) in half provided;"
|
2017-06-29 14:03:38 +00:00
|
|
|
"@setData(varName) { varName.set1f(calculated, provided * 2); }"
|
|
|
|
"void main() {"
|
2017-09-18 18:10:39 +00:00
|
|
|
"sk_OutColor = half4(1);"
|
2017-06-29 14:03:38 +00:00
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
"void onSetData(const GrGLSLProgramDataManager& varName, "
|
|
|
|
"const GrFragmentProcessor& _proc) override {\n",
|
2019-04-09 14:40:41 +00:00
|
|
|
"UniformHandle& calculated = calculatedVar;",
|
|
|
|
"auto provided = _outer.provided;",
|
2017-06-29 14:03:38 +00:00
|
|
|
"varName.set1f(calculated, provided * 2);"
|
|
|
|
});
|
|
|
|
test(r,
|
|
|
|
"@test(testDataName) { testDataName section }"
|
|
|
|
"void main() {"
|
2017-09-18 18:10:39 +00:00
|
|
|
"sk_OutColor = half4(1);"
|
2017-06-29 14:03:38 +00:00
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
"#if GR_TEST_UTILS\n"
|
2017-08-11 13:40:37 +00:00
|
|
|
"std::unique_ptr<GrFragmentProcessor> GrTest::TestCreate(GrProcessorTestData* testDataName) {\n"
|
2017-06-29 14:03:38 +00:00
|
|
|
" testDataName section }\n"
|
|
|
|
"#endif"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(SkSLFPTransformedCoords, r) {
|
|
|
|
test(r,
|
|
|
|
"void main() {"
|
2017-09-18 18:10:39 +00:00
|
|
|
"sk_OutColor = half4(sk_TransformedCoords2D[0], sk_TransformedCoords2D[0]);"
|
2017-06-29 14:03:38 +00:00
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{},
|
|
|
|
{
|
2017-08-15 13:19:53 +00:00
|
|
|
"SkString sk_TransformedCoords2D_0 = "
|
2017-06-29 14:03:38 +00:00
|
|
|
"fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);",
|
2017-09-18 18:10:39 +00:00
|
|
|
"fragBuilder->codeAppendf(\"%s = half4(%s, %s);\\n\", args.fOutputColor, "
|
2017-06-29 14:03:38 +00:00
|
|
|
"sk_TransformedCoords2D_0.c_str(), sk_TransformedCoords2D_0.c_str());"
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(SkSLFPLayoutWhen, r) {
|
|
|
|
test(r,
|
2017-09-18 18:10:39 +00:00
|
|
|
"layout(when=someExpression(someOtherExpression())) uniform half sometimes;"
|
2017-06-29 14:03:38 +00:00
|
|
|
"void main() {"
|
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
"if (someExpression(someOtherExpression())) {\n"
|
2019-04-09 14:40:41 +00:00
|
|
|
" sometimesVar = args.fUniformHandler->addUniform"
|
2017-06-29 14:03:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-10-10 20:30:21 +00:00
|
|
|
DEF_TEST(SkSLFPChildProcessors, r) {
|
|
|
|
test(r,
|
|
|
|
"in fragmentProcessor child1;"
|
|
|
|
"in fragmentProcessor child2;"
|
|
|
|
"void main() {"
|
2019-07-29 17:05:15 +00:00
|
|
|
" sk_OutColor = sample(child1) * sample(child2);"
|
2017-10-10 20:30:21 +00:00
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
|
|
|
"this->registerChildProcessor(std::move(child1));",
|
|
|
|
"this->registerChildProcessor(std::move(child2));"
|
|
|
|
},
|
|
|
|
{
|
2019-07-29 17:05:15 +00:00
|
|
|
"SkString _sample93(\"_sample93\");\n",
|
|
|
|
"this->invokeChild(_outer.child1_index, &_sample93, args);\n",
|
|
|
|
"SkString _sample110(\"_sample110\");\n",
|
|
|
|
"this->invokeChild(_outer.child2_index, &_sample110, args);\n",
|
|
|
|
"fragBuilder->codeAppendf(\"%s = %s * %s;\\n\", args.fOutputColor, _sample93.c_str(), "
|
|
|
|
"_sample110.c_str());\n",
|
2019-04-09 14:40:41 +00:00
|
|
|
"this->registerChildProcessor(src.childProcessor(child1_index).clone());",
|
|
|
|
"this->registerChildProcessor(src.childProcessor(child2_index).clone());"
|
2017-10-10 20:30:21 +00:00
|
|
|
});
|
|
|
|
}
|
2018-08-30 20:08:18 +00:00
|
|
|
|
|
|
|
DEF_TEST(SkSLFPChildProcessorsWithInput, r) {
|
|
|
|
test(r,
|
|
|
|
"in fragmentProcessor child1;"
|
|
|
|
"in fragmentProcessor child2;"
|
|
|
|
"void main() {"
|
|
|
|
" half4 childIn = sk_InColor;"
|
2019-07-29 17:05:15 +00:00
|
|
|
" half4 childOut1 = sample(child1, childIn);"
|
|
|
|
" half4 childOut2 = sample(child2, childOut1);"
|
2018-08-30 20:08:18 +00:00
|
|
|
" sk_OutColor = childOut2;"
|
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
|
|
|
"this->registerChildProcessor(std::move(child1));",
|
|
|
|
"this->registerChildProcessor(std::move(child2));"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"SkString _input0(\"childIn\");",
|
2019-07-29 17:05:15 +00:00
|
|
|
"SkString _sample128(\"_sample128\");",
|
|
|
|
"this->invokeChild(_outer.child1_index, _input0.c_str(), &_sample128, args);",
|
|
|
|
"fragBuilder->codeAppendf(\"\\nhalf4 childOut1 = %s;\", _sample128.c_str());",
|
2018-08-30 20:08:18 +00:00
|
|
|
"SkString _input1(\"childOut1\");",
|
2019-07-29 17:05:15 +00:00
|
|
|
"SkString _sample174(\"_sample174\");",
|
|
|
|
"this->invokeChild(_outer.child2_index, _input1.c_str(), &_sample174, args);",
|
2019-04-09 14:40:41 +00:00
|
|
|
"this->registerChildProcessor(src.childProcessor(child1_index).clone());",
|
|
|
|
"this->registerChildProcessor(src.childProcessor(child2_index).clone());"
|
2018-08-30 20:08:18 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(SkSLFPChildProcessorWithInputExpression, r) {
|
|
|
|
test(r,
|
|
|
|
"in fragmentProcessor child;"
|
|
|
|
"void main() {"
|
2019-07-29 17:05:15 +00:00
|
|
|
" sk_OutColor = sample(child, sk_InColor * half4(0.5));"
|
2018-08-30 20:08:18 +00:00
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
|
|
|
"this->registerChildProcessor(std::move(child));",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"SkString _input0 = SkStringPrintf(\"%s * half4(0.5)\", args.fInputColor);",
|
2019-07-29 17:05:15 +00:00
|
|
|
"SkString _sample64(\"_sample64\");",
|
|
|
|
"this->invokeChild(_outer.child_index, _input0.c_str(), &_sample64, args);",
|
|
|
|
"fragBuilder->codeAppendf(\"%s = %s;\\n\", args.fOutputColor, _sample64.c_str());",
|
2019-04-09 14:40:41 +00:00
|
|
|
"this->registerChildProcessor(src.childProcessor(child_index).clone());",
|
2018-08-30 20:08:18 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(SkSLFPNestedChildProcessors, r) {
|
|
|
|
test(r,
|
|
|
|
"in fragmentProcessor child1;"
|
|
|
|
"in fragmentProcessor child2;"
|
|
|
|
"void main() {"
|
2019-07-29 17:05:15 +00:00
|
|
|
" sk_OutColor = sample(child2, sk_InColor * sample(child1, sk_InColor * half4(0.5)));"
|
2018-08-30 20:08:18 +00:00
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
|
|
|
"this->registerChildProcessor(std::move(child1));",
|
|
|
|
"this->registerChildProcessor(std::move(child2));"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"SkString _input0 = SkStringPrintf(\"%s * half4(0.5)\", args.fInputColor);",
|
2019-07-29 17:05:15 +00:00
|
|
|
"SkString _sample121(\"_sample121\");",
|
|
|
|
"this->invokeChild(_outer.child1_index, _input0.c_str(), &_sample121, args);",
|
|
|
|
"SkString _input1 = SkStringPrintf(\"%s * %s\", args.fInputColor, _sample121.c_str());",
|
|
|
|
"SkString _sample93(\"_sample93\");",
|
|
|
|
"this->invokeChild(_outer.child2_index, _input1.c_str(), &_sample93, args);",
|
|
|
|
"fragBuilder->codeAppendf(\"%s = %s;\\n\", args.fOutputColor, _sample93.c_str());",
|
2019-04-09 14:40:41 +00:00
|
|
|
"this->registerChildProcessor(src.childProcessor(child1_index).clone());",
|
|
|
|
"this->registerChildProcessor(src.childProcessor(child2_index).clone());"
|
2018-08-30 20:08:18 +00:00
|
|
|
});
|
|
|
|
}
|
Reland "Redo how extra emit code flushing operates" with type fix.
This reverts commit d0440195d5cc049062238d02b8a962ae49c7f4ff.
Reason for revert: Fixes size_t -> int that was triggering ASAN failures.
Original change's description:
> Revert "Redo how extra emit code flushing operates"
>
> This reverts commit 9b8181b05a84e7dd24234c46c87d0bb2c73a7c08.
>
> Reason for revert: <INSERT REASONING HERE>
>
> Original change's description:
> > Redo how extra emit code flushing operates
> >
> > The previous implementation of flushEmittedCode(), that flushed on
> > demand when a process() was encountered, was brittle and susceptible to
> > mangling the expected sksl when fOut was modified outside of its
> > control. Given that writeFunction() and generateCode() in the parent
> > class all do this, it's possible to generate a simple SkSL snippet that
> > would generate a CPP file that builds invalid final SkSL:
> >
> > ```
> > in fragmentProcessor child;
> > bool someGlobalVar = ...;
> > void main() {
> > if (someGlobalVar) {
> > sk_OutColor = process(child, sk_InColor);
> > } else {
> > sk_OutColor = half4(1);
> > }
> > }
> > ```
> >
> > The CPP generated code *should* insert 'bool someGlobalVar' at the start
> > but because of the early flush from the child process and because of
> > how fOut was overwritten, someGlobalVar's declaration is put into a
> > stream that is not visible to the flush and ends up being inserted into
> > the output sksl in an incorrect location (namely after the if condition
> > that depends on it).
> >
> > This CL updates the extra emitted code logic to support multiple blocks
> > of extra CPP code. When a flush point occurs in SkSL writing, a special
> > token is inserted into the SkSL and a new CPP code buffer is associated
> > with that token. Then once all of the SkSL is accumulated into the root
> > output stream, it is processed into sections for each extra CPP block.
> > Special logic is done so that the SkSL that is emitted before the next
> > CPP block terminates at the end of the last valid statement before the
> > special token.
> >
> > A unit test demonstrating this failure condition is added to SkSLFPTest
> > and the CL properly passes. Since this bug did not trigger on existing
> > .fp files, the updated generator does not modify the generated FPs.
> >
> > Bug: skia:
> > Change-Id: Ib74911942080f1b964159807a06805bc52898789
> > Reviewed-on: https://skia-review.googlesource.com/152321
> > Commit-Queue: Michael Ludwig <michaelludwig@google.com>
> > Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
>
> TBR=ethannicholas@google.com,michaelludwig@google.com
>
> Change-Id: Id0f908453b596873f43b86a1c14eed48b2474a76
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:
> Reviewed-on: https://skia-review.googlesource.com/152660
> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
TBR=ethannicholas@google.com,michaelludwig@google.com
Change-Id: I3ccf2fee6ef96c6102dbe1c2c2ef6c14a701b8fd
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/152663
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
2018-09-07 17:13:06 +00:00
|
|
|
|
|
|
|
DEF_TEST(SkSLFPChildFPAndGlobal, r) {
|
|
|
|
test(r,
|
|
|
|
"in fragmentProcessor child;"
|
|
|
|
"bool hasCap = sk_Caps.externalTextureSupport;"
|
|
|
|
"void main() {"
|
|
|
|
" if (hasCap) {"
|
2019-07-29 17:05:15 +00:00
|
|
|
" sk_OutColor = sample(child, sk_InColor);"
|
Reland "Redo how extra emit code flushing operates" with type fix.
This reverts commit d0440195d5cc049062238d02b8a962ae49c7f4ff.
Reason for revert: Fixes size_t -> int that was triggering ASAN failures.
Original change's description:
> Revert "Redo how extra emit code flushing operates"
>
> This reverts commit 9b8181b05a84e7dd24234c46c87d0bb2c73a7c08.
>
> Reason for revert: <INSERT REASONING HERE>
>
> Original change's description:
> > Redo how extra emit code flushing operates
> >
> > The previous implementation of flushEmittedCode(), that flushed on
> > demand when a process() was encountered, was brittle and susceptible to
> > mangling the expected sksl when fOut was modified outside of its
> > control. Given that writeFunction() and generateCode() in the parent
> > class all do this, it's possible to generate a simple SkSL snippet that
> > would generate a CPP file that builds invalid final SkSL:
> >
> > ```
> > in fragmentProcessor child;
> > bool someGlobalVar = ...;
> > void main() {
> > if (someGlobalVar) {
> > sk_OutColor = process(child, sk_InColor);
> > } else {
> > sk_OutColor = half4(1);
> > }
> > }
> > ```
> >
> > The CPP generated code *should* insert 'bool someGlobalVar' at the start
> > but because of the early flush from the child process and because of
> > how fOut was overwritten, someGlobalVar's declaration is put into a
> > stream that is not visible to the flush and ends up being inserted into
> > the output sksl in an incorrect location (namely after the if condition
> > that depends on it).
> >
> > This CL updates the extra emitted code logic to support multiple blocks
> > of extra CPP code. When a flush point occurs in SkSL writing, a special
> > token is inserted into the SkSL and a new CPP code buffer is associated
> > with that token. Then once all of the SkSL is accumulated into the root
> > output stream, it is processed into sections for each extra CPP block.
> > Special logic is done so that the SkSL that is emitted before the next
> > CPP block terminates at the end of the last valid statement before the
> > special token.
> >
> > A unit test demonstrating this failure condition is added to SkSLFPTest
> > and the CL properly passes. Since this bug did not trigger on existing
> > .fp files, the updated generator does not modify the generated FPs.
> >
> > Bug: skia:
> > Change-Id: Ib74911942080f1b964159807a06805bc52898789
> > Reviewed-on: https://skia-review.googlesource.com/152321
> > Commit-Queue: Michael Ludwig <michaelludwig@google.com>
> > Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
>
> TBR=ethannicholas@google.com,michaelludwig@google.com
>
> Change-Id: Id0f908453b596873f43b86a1c14eed48b2474a76
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:
> Reviewed-on: https://skia-review.googlesource.com/152660
> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
TBR=ethannicholas@google.com,michaelludwig@google.com
Change-Id: I3ccf2fee6ef96c6102dbe1c2c2ef6c14a701b8fd
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/152663
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
2018-09-07 17:13:06 +00:00
|
|
|
" } else {"
|
|
|
|
" sk_OutColor = half4(1);"
|
|
|
|
" }"
|
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
|
|
|
"this->registerChildProcessor(std::move(child));"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"hasCap = sk_Caps.externalTextureSupport;",
|
2019-07-29 17:05:15 +00:00
|
|
|
"fragBuilder->codeAppendf(\"bool hasCap = %s;\\nif (hasCap) {\", (hasCap ? \"true\" : "
|
|
|
|
"\"false\"));",
|
Reland "Redo how extra emit code flushing operates" with type fix.
This reverts commit d0440195d5cc049062238d02b8a962ae49c7f4ff.
Reason for revert: Fixes size_t -> int that was triggering ASAN failures.
Original change's description:
> Revert "Redo how extra emit code flushing operates"
>
> This reverts commit 9b8181b05a84e7dd24234c46c87d0bb2c73a7c08.
>
> Reason for revert: <INSERT REASONING HERE>
>
> Original change's description:
> > Redo how extra emit code flushing operates
> >
> > The previous implementation of flushEmittedCode(), that flushed on
> > demand when a process() was encountered, was brittle and susceptible to
> > mangling the expected sksl when fOut was modified outside of its
> > control. Given that writeFunction() and generateCode() in the parent
> > class all do this, it's possible to generate a simple SkSL snippet that
> > would generate a CPP file that builds invalid final SkSL:
> >
> > ```
> > in fragmentProcessor child;
> > bool someGlobalVar = ...;
> > void main() {
> > if (someGlobalVar) {
> > sk_OutColor = process(child, sk_InColor);
> > } else {
> > sk_OutColor = half4(1);
> > }
> > }
> > ```
> >
> > The CPP generated code *should* insert 'bool someGlobalVar' at the start
> > but because of the early flush from the child process and because of
> > how fOut was overwritten, someGlobalVar's declaration is put into a
> > stream that is not visible to the flush and ends up being inserted into
> > the output sksl in an incorrect location (namely after the if condition
> > that depends on it).
> >
> > This CL updates the extra emitted code logic to support multiple blocks
> > of extra CPP code. When a flush point occurs in SkSL writing, a special
> > token is inserted into the SkSL and a new CPP code buffer is associated
> > with that token. Then once all of the SkSL is accumulated into the root
> > output stream, it is processed into sections for each extra CPP block.
> > Special logic is done so that the SkSL that is emitted before the next
> > CPP block terminates at the end of the last valid statement before the
> > special token.
> >
> > A unit test demonstrating this failure condition is added to SkSLFPTest
> > and the CL properly passes. Since this bug did not trigger on existing
> > .fp files, the updated generator does not modify the generated FPs.
> >
> > Bug: skia:
> > Change-Id: Ib74911942080f1b964159807a06805bc52898789
> > Reviewed-on: https://skia-review.googlesource.com/152321
> > Commit-Queue: Michael Ludwig <michaelludwig@google.com>
> > Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
>
> TBR=ethannicholas@google.com,michaelludwig@google.com
>
> Change-Id: Id0f908453b596873f43b86a1c14eed48b2474a76
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:
> Reviewed-on: https://skia-review.googlesource.com/152660
> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
TBR=ethannicholas@google.com,michaelludwig@google.com
Change-Id: I3ccf2fee6ef96c6102dbe1c2c2ef6c14a701b8fd
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/152663
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
2018-09-07 17:13:06 +00:00
|
|
|
"SkString _input0 = SkStringPrintf(\"%s\", args.fInputColor);",
|
2019-07-29 17:05:15 +00:00
|
|
|
"SkString _sample130(\"_sample130\");",
|
|
|
|
"this->invokeChild(_outer.child_index, _input0.c_str(), &_sample130, args);",
|
|
|
|
"fragBuilder->codeAppendf(\"\\n %s = %s;\\n} else {\\n %s = half4(1.0);\\n}\\n\","
|
|
|
|
" args.fOutputColor, _sample130.c_str(), args.fOutputColor);",
|
|
|
|
|
2019-04-09 14:40:41 +00:00
|
|
|
"this->registerChildProcessor(src.childProcessor(child_index).clone());"
|
Reland "Redo how extra emit code flushing operates" with type fix.
This reverts commit d0440195d5cc049062238d02b8a962ae49c7f4ff.
Reason for revert: Fixes size_t -> int that was triggering ASAN failures.
Original change's description:
> Revert "Redo how extra emit code flushing operates"
>
> This reverts commit 9b8181b05a84e7dd24234c46c87d0bb2c73a7c08.
>
> Reason for revert: <INSERT REASONING HERE>
>
> Original change's description:
> > Redo how extra emit code flushing operates
> >
> > The previous implementation of flushEmittedCode(), that flushed on
> > demand when a process() was encountered, was brittle and susceptible to
> > mangling the expected sksl when fOut was modified outside of its
> > control. Given that writeFunction() and generateCode() in the parent
> > class all do this, it's possible to generate a simple SkSL snippet that
> > would generate a CPP file that builds invalid final SkSL:
> >
> > ```
> > in fragmentProcessor child;
> > bool someGlobalVar = ...;
> > void main() {
> > if (someGlobalVar) {
> > sk_OutColor = process(child, sk_InColor);
> > } else {
> > sk_OutColor = half4(1);
> > }
> > }
> > ```
> >
> > The CPP generated code *should* insert 'bool someGlobalVar' at the start
> > but because of the early flush from the child process and because of
> > how fOut was overwritten, someGlobalVar's declaration is put into a
> > stream that is not visible to the flush and ends up being inserted into
> > the output sksl in an incorrect location (namely after the if condition
> > that depends on it).
> >
> > This CL updates the extra emitted code logic to support multiple blocks
> > of extra CPP code. When a flush point occurs in SkSL writing, a special
> > token is inserted into the SkSL and a new CPP code buffer is associated
> > with that token. Then once all of the SkSL is accumulated into the root
> > output stream, it is processed into sections for each extra CPP block.
> > Special logic is done so that the SkSL that is emitted before the next
> > CPP block terminates at the end of the last valid statement before the
> > special token.
> >
> > A unit test demonstrating this failure condition is added to SkSLFPTest
> > and the CL properly passes. Since this bug did not trigger on existing
> > .fp files, the updated generator does not modify the generated FPs.
> >
> > Bug: skia:
> > Change-Id: Ib74911942080f1b964159807a06805bc52898789
> > Reviewed-on: https://skia-review.googlesource.com/152321
> > Commit-Queue: Michael Ludwig <michaelludwig@google.com>
> > Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
>
> TBR=ethannicholas@google.com,michaelludwig@google.com
>
> Change-Id: Id0f908453b596873f43b86a1c14eed48b2474a76
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:
> Reviewed-on: https://skia-review.googlesource.com/152660
> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
TBR=ethannicholas@google.com,michaelludwig@google.com
Change-Id: I3ccf2fee6ef96c6102dbe1c2c2ef6c14a701b8fd
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/152663
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
2018-09-07 17:13:06 +00:00
|
|
|
});
|
|
|
|
}
|
2018-09-07 17:44:21 +00:00
|
|
|
|
|
|
|
DEF_TEST(SkSLFPChildProcessorInlineFieldAccess, r) {
|
|
|
|
test(r,
|
|
|
|
"in fragmentProcessor child;"
|
|
|
|
"void main() {"
|
|
|
|
" if (child.preservesOpaqueInput) {"
|
2019-07-29 17:05:15 +00:00
|
|
|
" sk_OutColor = sample(child, sk_InColor);"
|
2018-09-07 17:44:21 +00:00
|
|
|
" } else {"
|
|
|
|
" sk_OutColor = half4(1);"
|
|
|
|
" }"
|
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
|
|
|
"this->registerChildProcessor(std::move(child));"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fragBuilder->codeAppendf(\"if (%s) {\", "
|
2019-07-29 17:05:15 +00:00
|
|
|
"(_outer.childProcessor(_outer.child_index).preservesOpaqueInput() ? ",
|
2018-09-07 17:44:21 +00:00
|
|
|
"SkString _input0 = SkStringPrintf(\"%s\", args.fInputColor);",
|
2019-07-29 17:05:15 +00:00
|
|
|
"SkString _sample105(\"_sample105\");",
|
|
|
|
"this->invokeChild(_outer.child_index, _input0.c_str(), &_sample105, args);",
|
|
|
|
"fragBuilder->codeAppendf(\"\\n %s = %s;\\n} else {\\n %s = half4(1.0);\\n}\\n\","
|
|
|
|
" args.fOutputColor, _sample105.c_str(), args.fOutputColor);",
|
2019-04-09 14:40:41 +00:00
|
|
|
"this->registerChildProcessor(src.childProcessor(child_index).clone());"
|
2018-09-07 17:44:21 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(SkSLFPChildProcessorFieldAccess, r) {
|
|
|
|
test(r,
|
|
|
|
"in fragmentProcessor child;"
|
|
|
|
"bool opaque = child.preservesOpaqueInput;"
|
|
|
|
"void main() {"
|
|
|
|
" if (opaque) {"
|
2019-07-29 17:05:15 +00:00
|
|
|
" sk_OutColor = sample(child);"
|
2018-09-07 17:44:21 +00:00
|
|
|
" } else {"
|
|
|
|
" sk_OutColor = half4(0.5);"
|
|
|
|
" }"
|
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{
|
|
|
|
"this->registerChildProcessor(std::move(child));"
|
|
|
|
},
|
|
|
|
{
|
2019-04-09 14:40:41 +00:00
|
|
|
"opaque = _outer.childProcessor(_outer.child_index).preservesOpaqueInput();",
|
2019-07-29 17:05:15 +00:00
|
|
|
"fragBuilder->codeAppendf(\"bool opaque = %s;\\nif (opaque) {\", (opaque ? \"true\" : "
|
|
|
|
"\"false\"));",
|
|
|
|
"SkString _sample126(\"_sample126\");",
|
|
|
|
"this->invokeChild(_outer.child_index, &_sample126, args);",
|
|
|
|
"fragBuilder->codeAppendf(\"\\n %s = %s;\\n} else {\\n %s = half4(0.5);\\n}\\n\","
|
|
|
|
" args.fOutputColor, _sample126.c_str(), args.fOutputColor);",
|
2019-04-09 14:40:41 +00:00
|
|
|
"this->registerChildProcessor(src.childProcessor(child_index).clone());"
|
2018-09-07 17:44:21 +00:00
|
|
|
});
|
|
|
|
}
|
2019-03-04 17:25:57 +00:00
|
|
|
|
|
|
|
DEF_TEST(SkSLFPNullableChildProcessor, r) {
|
|
|
|
test(r,
|
|
|
|
"in fragmentProcessor? child;"
|
|
|
|
"void main() {"
|
|
|
|
" if (child != null) {"
|
2019-07-29 17:05:15 +00:00
|
|
|
" sk_OutColor = sample(child);"
|
2019-03-04 17:25:57 +00:00
|
|
|
" } else {"
|
|
|
|
" sk_OutColor = half4(0.5);"
|
|
|
|
" }"
|
|
|
|
"}",
|
|
|
|
*SkSL::ShaderCapsFactory::Default(),
|
|
|
|
{},
|
|
|
|
{
|
2019-07-29 17:05:15 +00:00
|
|
|
"fragBuilder->codeAppendf(\"if (%s) {\", _outer.child_index >= 0 ? \"true\" : "
|
|
|
|
"\"false\");",
|
|
|
|
"SkString _sample93(\"_sample93\");",
|
2019-04-09 14:40:41 +00:00
|
|
|
"if (_outer.child_index >= 0) {",
|
2019-07-29 17:05:15 +00:00
|
|
|
"this->invokeChild(_outer.child_index, &_sample93, args);",
|
2019-03-04 17:25:57 +00:00
|
|
|
"}",
|
2019-07-29 17:05:15 +00:00
|
|
|
"fragBuilder->codeAppendf(\"\\n %s = %s;\\n} else {\\n %s = half4(0.5);\\n}\\n\","
|
|
|
|
" args.fOutputColor, _sample93.c_str(), args.fOutputColor);"
|
|
|
|
|
2019-03-04 17:25:57 +00:00
|
|
|
});
|
|
|
|
}
|
2019-08-13 14:21:38 +00:00
|
|
|
|
|
|
|
DEF_TEST(SkSLFPBadIn, r) {
|
|
|
|
test_failure(r,
|
|
|
|
"in half4 c;"
|
|
|
|
"void main() {"
|
|
|
|
" sk_OutColor = c;"
|
|
|
|
"}",
|
|
|
|
"error: 1: 'in' variable must be either 'uniform' or 'layout(key)', or there must be a "
|
|
|
|
"custom @setData function\n1 error\n");
|
|
|
|
}
|