aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLCompiler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sksl/SkSLCompiler.cpp')
-rw-r--r--src/sksl/SkSLCompiler.cpp60
1 files changed, 32 insertions, 28 deletions
diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp
index a20369b32b..1cbc4410b5 100644
--- a/src/sksl/SkSLCompiler.cpp
+++ b/src/sksl/SkSLCompiler.cpp
@@ -19,6 +19,7 @@
#include "ir/SkSLSymbolTable.h"
#include "ir/SkSLUnresolvedFunction.h"
#include "ir/SkSLVarDeclarations.h"
+#include "SkMutex.h"
#ifdef SK_ENABLE_SPIRV_VALIDATION
#include "spirv-tools/libspirv.hpp"
@@ -76,17 +77,17 @@ Compiler::Compiler()
ADD_TYPE(BVec3);
ADD_TYPE(BVec4);
ADD_TYPE(Mat2x2);
- types->addWithoutOwnership(String("mat2x2"), fContext.fMat2x2_Type.get());
+ types->addWithoutOwnership(SkString("mat2x2"), fContext.fMat2x2_Type.get());
ADD_TYPE(Mat2x3);
ADD_TYPE(Mat2x4);
ADD_TYPE(Mat3x2);
ADD_TYPE(Mat3x3);
- types->addWithoutOwnership(String("mat3x3"), fContext.fMat3x3_Type.get());
+ types->addWithoutOwnership(SkString("mat3x3"), fContext.fMat3x3_Type.get());
ADD_TYPE(Mat3x4);
ADD_TYPE(Mat4x2);
ADD_TYPE(Mat4x3);
ADD_TYPE(Mat4x4);
- types->addWithoutOwnership(String("mat4x4"), fContext.fMat4x4_Type.get());
+ types->addWithoutOwnership(SkString("mat4x4"), fContext.fMat4x4_Type.get());
ADD_TYPE(GenType);
ADD_TYPE(GenDType);
ADD_TYPE(GenIType);
@@ -146,14 +147,14 @@ Compiler::Compiler()
ADD_TYPE(GSampler2DArrayShadow);
ADD_TYPE(GSamplerCubeArrayShadow);
- String skCapsName("sk_Caps");
- Variable* skCaps = new Variable(Position(), Modifiers(), skCapsName,
+ SkString 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));
Modifiers::Flag ignored1;
std::vector<std::unique_ptr<ProgramElement>> ignored2;
- this->internalConvertProgram(String(SKSL_INCLUDE), &ignored1, &ignored2);
+ this->internalConvertProgram(SkString(SKSL_INCLUDE), &ignored1, &ignored2);
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
ASSERT(!fErrorCount);
}
@@ -350,7 +351,7 @@ void Compiler::scanCFG(const FunctionDefinition& f) {
p = (*cfg.fBlocks[i].fNodes[0].fExpression)->fPosition;
break;
}
- this->error(p, String("unreachable"));
+ this->error(p, SkString("unreachable"));
}
}
if (fErrorCount) {
@@ -388,12 +389,12 @@ void Compiler::scanCFG(const FunctionDefinition& f) {
// check for missing return
if (f.fDeclaration.fReturnType != *fContext.fVoid_Type) {
if (cfg.fBlocks[cfg.fExit].fEntrances.size()) {
- this->error(f.fPosition, String("function can exit without returning a value"));
+ this->error(f.fPosition, SkString("function can exit without returning a value"));
}
}
}
-void Compiler::internalConvertProgram(String text,
+void Compiler::internalConvertProgram(SkString text,
Modifiers::Flag* defaultPrecision,
std::vector<std::unique_ptr<ProgramElement>>* result) {
Parser parser(text, *fTypes, *this);
@@ -456,7 +457,7 @@ void Compiler::internalConvertProgram(String text,
}
}
-std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, String text,
+std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, SkString text,
const Program::Settings& settings) {
fErrorText = "";
fErrorCount = 0;
@@ -465,13 +466,13 @@ std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, String tex
Modifiers::Flag ignored;
switch (kind) {
case Program::kVertex_Kind:
- this->internalConvertProgram(String(SKSL_VERT_INCLUDE), &ignored, &elements);
+ this->internalConvertProgram(SkString(SKSL_VERT_INCLUDE), &ignored, &elements);
break;
case Program::kFragment_Kind:
- this->internalConvertProgram(String(SKSL_FRAG_INCLUDE), &ignored, &elements);
+ this->internalConvertProgram(SkString(SKSL_FRAG_INCLUDE), &ignored, &elements);
break;
case Program::kGeometry_Kind:
- this->internalConvertProgram(String(SKSL_GEOM_INCLUDE), &ignored, &elements);
+ this->internalConvertProgram(SkString(SKSL_GEOM_INCLUDE), &ignored, &elements);
break;
}
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
@@ -489,22 +490,23 @@ std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, String tex
return result;
}
-bool Compiler::toSPIRV(const Program& program, OutputStream& out) {
+bool Compiler::toSPIRV(const Program& program, SkWStream& out) {
#ifdef SK_ENABLE_SPIRV_VALIDATION
- StringStream buffer;
+ SkDynamicMemoryWStream buffer;
SPIRVCodeGenerator cg(&fContext, &program, this, &buffer);
bool result = cg.generateCode();
if (result) {
+ sk_sp<SkData> data(buffer.detachAsData());
spvtools::SpirvTools tools(SPV_ENV_VULKAN_1_0);
- ASSERT(0 == buffer.size() % 4);
+ SkASSERT(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());
+ SkAssertResult(tools.Validate((const uint32_t*) data->data(), data->size() / 4));
+ out.write(data->data(), data->size());
}
#else
SPIRVCodeGenerator cg(&fContext, &program, this, &out);
@@ -514,39 +516,41 @@ bool Compiler::toSPIRV(const Program& program, OutputStream& out) {
return result;
}
-bool Compiler::toSPIRV(const Program& program, String* out) {
- StringStream buffer;
+bool Compiler::toSPIRV(const Program& program, SkString* out) {
+ SkDynamicMemoryWStream buffer;
bool result = this->toSPIRV(program, buffer);
if (result) {
- *out = String(buffer.data(), buffer.size());
+ sk_sp<SkData> data(buffer.detachAsData());
+ *out = SkString((const char*) data->data(), data->size());
}
return result;
}
-bool Compiler::toGLSL(const Program& program, OutputStream& out) {
+bool Compiler::toGLSL(const Program& program, SkWStream& out) {
GLSLCodeGenerator cg(&fContext, &program, this, &out);
bool result = cg.generateCode();
this->writeErrorCount();
return result;
}
-bool Compiler::toGLSL(const Program& program, String* out) {
- StringStream buffer;
+bool Compiler::toGLSL(const Program& program, SkString* out) {
+ SkDynamicMemoryWStream buffer;
bool result = this->toGLSL(program, buffer);
if (result) {
- *out = String(buffer.data(), buffer.size());
+ sk_sp<SkData> data(buffer.detachAsData());
+ *out = SkString((const char*) data->data(), data->size());
}
return result;
}
-void Compiler::error(Position position, String msg) {
+void Compiler::error(Position position, SkString msg) {
fErrorCount++;
fErrorText += "error: " + position.description() + ": " + msg.c_str() + "\n";
}
-String Compiler::errorText() {
- String result = fErrorText;
+SkString Compiler::errorText() {
+ SkString result = fErrorText;
return result;
}