aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLCompiler.cpp
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2017-06-27 11:20:22 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-06-27 18:27:57 +0000
commitc070939fd1a954b7a492bc30f0cf64a664b90181 (patch)
tree6b1167726bc9ac4d2073f893c699b40c70f63ba1 /src/sksl/SkSLCompiler.cpp
parent26249e0e1d1b18a1e67195a2998b49958426f8ba (diff)
Re-land sksl fragment processor support
This reverts commit ed50200682e0de72c3abecaa4d5324ebcd1ed9f9. Bug: skia: Change-Id: I9caa7454b391450620d6989dc472abb3cf7a2cab Reviewed-on: https://skia-review.googlesource.com/20965 Reviewed-by: Ben Wagner <benjaminwagner@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl/SkSLCompiler.cpp')
-rw-r--r--src/sksl/SkSLCompiler.cpp41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp
index 39ac31532e..593397bd2a 100644
--- a/src/sksl/SkSLCompiler.cpp
+++ b/src/sksl/SkSLCompiler.cpp
@@ -8,7 +8,9 @@
#include "SkSLCompiler.h"
#include "SkSLCFGGenerator.h"
+#include "SkSLCPPCodeGenerator.h"
#include "SkSLGLSLCodeGenerator.h"
+#include "SkSLHCodeGenerator.h"
#include "SkSLIRGenerator.h"
#include "SkSLSPIRVCodeGenerator.h"
#include "ir/SkSLExpression.h"
@@ -45,6 +47,11 @@ static const char* SKSL_GEOM_INCLUDE =
#include "sksl_geom.include"
;
+static const char* SKSL_FP_INCLUDE =
+#include "sksl_fp.include"
+;
+
+
namespace SkSL {
Compiler::Compiler()
@@ -146,12 +153,18 @@ Compiler::Compiler()
ADD_TYPE(SamplerCubeArrayShadow);
ADD_TYPE(GSampler2DArrayShadow);
ADD_TYPE(GSamplerCubeArrayShadow);
+ ADD_TYPE(ColorSpaceXform);
String skCapsName("sk_Caps");
Variable* skCaps = new Variable(Position(), Modifiers(), skCapsName,
*fContext.fSkCaps_Type, Variable::kGlobal_Storage);
fIRGenerator->fSymbolTable->add(skCapsName, std::unique_ptr<Symbol>(skCaps));
+ String skArgsName("sk_Args");
+ Variable* skArgs = new Variable(Position(), Modifiers(), skArgsName,
+ *fContext.fSkArgs_Type, Variable::kGlobal_Storage);
+ fIRGenerator->fSymbolTable->add(skArgsName, std::unique_ptr<Symbol>(skArgs));
+
Modifiers::Flag ignored1;
std::vector<std::unique_ptr<ProgramElement>> ignored2;
fIRGenerator->convertProgram(String(SKSL_INCLUDE), *fTypes, &ignored1, &ignored2);
@@ -778,7 +791,6 @@ void Compiler::simplifyExpression(DefinitionMap& definitions,
}
}
-
// returns true if this statement could potentially execute a break at the current level (we ignore
// nested loops and switches, since any breaks inside of them will merely break the loop / switch)
static bool contains_break(Statement& s) {
@@ -1097,6 +1109,9 @@ std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, String tex
case Program::kGeometry_Kind:
fIRGenerator->convertProgram(String(SKSL_GEOM_INCLUDE), *fTypes, &ignored, &elements);
break;
+ case Program::kFragmentProcessor_Kind:
+ fIRGenerator->convertProgram(String(SKSL_FP_INCLUDE), *fTypes, &ignored, &elements);
+ break;
}
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
Modifiers::Flag defaultPrecision;
@@ -1127,15 +1142,16 @@ bool Compiler::toSPIRV(const Program& program, OutputStream& out) {
bool result = cg.generateCode();
if (result) {
spvtools::SpirvTools tools(SPV_ENV_VULKAN_1_0);
- ASSERT(0 == buffer.size() % 4);
+ const String& data = buffer.str();
+ ASSERT(0 == data.size() % 4);
auto dumpmsg = [](spv_message_level_t, const char*, const spv_position_t&, const char* m) {
SkDebugf("SPIR-V validation error: %s\n", m);
};
tools.SetMessageConsumer(dumpmsg);
// Verify that the SPIR-V we produced is valid. If this assert fails, check the logs prior
// to the failure to see the validation errors.
- ASSERT_RESULT(tools.Validate((const uint32_t*) buffer.data(), buffer.size() / 4));
- out.write(buffer.data(), buffer.size());
+ ASSERT_RESULT(tools.Validate((const uint32_t*) data.c_str(), data.size() / 4));
+ out.write(data.c_str(), data.size());
}
#else
SPIRVCodeGenerator cg(&fContext, &program, this, &out);
@@ -1149,7 +1165,7 @@ bool Compiler::toSPIRV(const Program& program, String* out) {
StringStream buffer;
bool result = this->toSPIRV(program, buffer);
if (result) {
- *out = String(buffer.data(), buffer.size());
+ *out = buffer.str();
}
return result;
}
@@ -1165,11 +1181,24 @@ bool Compiler::toGLSL(const Program& program, String* out) {
StringStream buffer;
bool result = this->toGLSL(program, buffer);
if (result) {
- *out = String(buffer.data(), buffer.size());
+ *out = buffer.str();
}
return result;
}
+bool Compiler::toCPP(const Program& program, String name, OutputStream& out) {
+ CPPCodeGenerator cg(&fContext, &program, this, name, &out);
+ bool result = cg.generateCode();
+ this->writeErrorCount();
+ return result;
+}
+
+bool Compiler::toH(const Program& program, String name, OutputStream& out) {
+ HCodeGenerator cg(&program, this, name, &out);
+ bool result = cg.generateCode();
+ this->writeErrorCount();
+ return result;
+}
void Compiler::error(Position position, String msg) {
fErrorCount++;