aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLCPPCodeGenerator.cpp
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2017-10-16 12:35:44 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-10-16 16:58:41 +0000
commit823994624aa5e805e16833ecd3d748fc769a164d (patch)
tree5066101c7fd3f697bf3d95b3166ad0168dc404d3 /src/sksl/SkSLCPPCodeGenerator.cpp
parentd982d0579e7681ec512c0ab612f9664b7a235e79 (diff)
converted GrRectBlurEffect to SkSL
Bug: skia: Change-Id: I3a8e16fd2792e6fb5711815d8aad46ae30c2872e Reviewed-on: https://skia-review.googlesource.com/59163 Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/sksl/SkSLCPPCodeGenerator.cpp')
-rw-r--r--src/sksl/SkSLCPPCodeGenerator.cpp59
1 files changed, 53 insertions, 6 deletions
diff --git a/src/sksl/SkSLCPPCodeGenerator.cpp b/src/sksl/SkSLCPPCodeGenerator.cpp
index a7008400ce..0b2ef78016 100644
--- a/src/sksl/SkSLCPPCodeGenerator.cpp
+++ b/src/sksl/SkSLCPPCodeGenerator.cpp
@@ -148,10 +148,15 @@ void CPPCodeGenerator::writeRuntimeValue(const Type& type, const String& cppCode
this->write(type.name() + "(%f, %f)");
fFormatArgs.push_back(cppCode + ".fX");
fFormatArgs.push_back(cppCode + ".fY");
+ } else if (type == *fContext.fFloat4_Type || type == *fContext.fHalf4_Type) {
+ this->write(type.name() + "(%f, %f, %f, %f)");
+ fFormatArgs.push_back(cppCode + ".left()");
+ fFormatArgs.push_back(cppCode + ".top()");
+ fFormatArgs.push_back(cppCode + ".right()");
+ fFormatArgs.push_back(cppCode + ".bottom()");
} else {
- this->write(type.name());
- this->write("\n");
- ABORT("unsupported runtime value type\n");
+ printf("unsupported runtime value type '%s'\n", String(type.fName).c_str());
+ ASSERT(false);
}
}
@@ -180,7 +185,26 @@ void CPPCodeGenerator::writeIntLiteral(const IntLiteral& i) {
this->write(to_string((int32_t) i.fValue));
}
+void CPPCodeGenerator::writeSwizzle(const Swizzle& swizzle) {
+ if (fCPPMode) {
+ ASSERT(swizzle.fComponents.size() == 1); // no support for multiple swizzle components yet
+ this->writeExpression(*swizzle.fBase, kPostfix_Precedence);
+ switch (swizzle.fComponents[0]) {
+ case 0: this->write(".left()"); break;
+ case 1: this->write(".top()"); break;
+ case 2: this->write(".right()"); break;
+ case 3: this->write(".bottom()"); break;
+ }
+ } else {
+ INHERITED::writeSwizzle(swizzle);
+ }
+}
+
void CPPCodeGenerator::writeVariableReference(const VariableReference& ref) {
+ if (fCPPMode) {
+ this->write(ref.fVariable.fName);
+ return;
+ }
switch (ref.fVariable.fModifiers.fLayout.fBuiltin) {
case SK_INCOLOR_BUILTIN:
this->write("%s");
@@ -434,15 +458,22 @@ void CPPCodeGenerator::writePrivateVarValues() {
for (const auto& raw : decls->fVars) {
VarDeclaration& decl = (VarDeclaration&) *raw;
if (is_private(*decl.fVar) && decl.fValue) {
- this->writef("%s = %s;\n",
- String(decl.fVar->fName).c_str(),
- decl.fValue->description().c_str());
+ this->writef("%s = ", String(decl.fVar->fName).c_str());
+ fCPPMode = true;
+ this->writeExpression(*decl.fValue, kAssignment_Precedence);
+ fCPPMode = false;
+ this->write(";\n");
}
}
}
}
}
+static bool is_accessible(const Variable& var) {
+ return Type::kSampler_Kind != var.fType.kind() &&
+ Type::kOther_Kind != var.fType.kind();
+}
+
void CPPCodeGenerator::writeCodeAppend(const String& code) {
// codeAppendf can only handle appending 1024 bytes at a time, so we need to break the string
// into chunks. Unfortunately we can't tell exactly how long the string is going to end up,
@@ -484,6 +515,22 @@ bool CPPCodeGenerator::writeEmitCode(std::vector<const Variable*>& uniforms) {
this->writef(" const %s& _outer = args.fFp.cast<%s>();\n"
" (void) _outer;\n",
fFullName.c_str(), fFullName.c_str());
+ for (const auto& p : fProgram.fElements) {
+ if (ProgramElement::kVar_Kind == p->fKind) {
+ const VarDeclarations* decls = (const VarDeclarations*) p.get();
+ for (const auto& raw : decls->fVars) {
+ VarDeclaration& decl = (VarDeclaration&) *raw;
+ String nameString(decl.fVar->fName);
+ const char* name = nameString.c_str();
+ if (SectionAndParameterHelper::IsParameter(*decl.fVar) &&
+ is_accessible(*decl.fVar)) {
+ this->writef(" auto %s = _outer.%s();\n"
+ " (void) %s;\n",
+ name, name, name);
+ }
+ }
+ }
+ }
this->writePrivateVarValues();
for (const auto u : uniforms) {
this->addUniform(*u);