#include "gl/builders/GrGLShaderStringBuilder.h"
#include "SkSLCompiler.h"
#include <stdio.h>
-#include <string>
const GrGLContext* GLBench::getGLContext(SkCanvas* canvas) {
// This bench exclusively tests GL calls directly
GrGLuint GLBench::CompileShader(const GrGLContext* context, const char* sksl, GrGLenum type) {
const GrGLInterface* gl = context->interface();
- std::string glsl;
+ SkString glsl;
bool result = context->compiler()->toGLSL(type == GR_GL_VERTEX_SHADER
? SkSL::Program::kVertex_Kind
: SkSL::Program::kFragment_Kind,
- std::string(sksl),
+ SkString(sksl),
*context->caps()->glslCaps(),
&glsl);
if (!result) {
#if SK_SUPPORT_GPU
int fuzz_sksl2glsl(sk_sp<SkData> bytes) {
SkSL::Compiler compiler;
- std::string output;
+ SkString output;
bool result = compiler.toGLSL(SkSL::Program::kFragment_Kind,
- (const char*)bytes->data(), *SkSL::GLSLCapsFactory::Default(), &output);
+ SkString((const char*)bytes->data()), *SkSL::GLSLCapsFactory::Default(), &output);
if (!result) {
SkDebugf("[terminated] Couldn't compile input.\n");
static void print_shader_source(const char** strings, int* lengths, int count);
-static void dump_string(std::string s) {
+static void dump_string(SkString s) {
// on Android, SkDebugf only displays the first 1K characters of output, which results in
// incomplete shader source code. Print each line individually to avoid this problem.
- size_t index = 0;
+ const char* chars = s.c_str();
for (;;) {
- size_t next = s.find("\n", index);
- if (next == std::string::npos) {
- SkDebugf("%s", s.substr(index).c_str());
- break;
+ const char* next = strchr(chars, '\n');
+ if (next) {
+ next++;
+ SkDebugf("%s", SkString(chars, next - chars).c_str());
+ chars = next;
} else {
- SkDebugf("%s", s.substr(index, next - index + 1).c_str());
- index = next + 1;
+ SkDebugf("%s", chars);
+ break;
}
}
}
return 0;
}
- std::string sksl;
+ SkString sksl;
#ifdef SK_DEBUG
- SkString prettySource = GrGLSLPrettyPrint::PrettyPrintGLSL(strings, lengths, count, false);
- sksl = std::string(prettySource.c_str());
+ sksl = GrGLSLPrettyPrint::PrettyPrintGLSL(strings, lengths, count, false);
#else
for (int i = 0; i < count; i++) {
sksl.append(strings[i], lengths[i]);
}
#endif
- std::string glsl;
+ SkString glsl;
SkSL::Compiler& compiler = *glCtx.compiler();
SkASSERT(type == GR_GL_VERTEX_SHADER || type == GR_GL_FRAGMENT_SHADER);
SkDEBUGCODE(bool result = )compiler.toGLSL(type == GR_GL_VERTEX_SHADER
? SkSL::Program::kVertex_Kind
: SkSL::Program::kFragment_Kind,
- std::string(sksl.c_str()),
+ sksl,
*glCtx.caps()->glslCaps(),
&glsl);
#ifdef SK_DEBUG
#endif
const char* glslChars = glsl.c_str();
- GrGLint glslLength = (GrGLint) glsl.length();
+ GrGLint glslLength = (GrGLint) glsl.size();
GR_GL_CALL(gli, ShaderSource(shaderId, 1, &glslChars, &glslLength));
// If tracing is enabled in chrome then we pretty print
moduleCreateInfo.flags = 0;
#if USE_SKSL
- std::string code;
+ SkString code;
#else
shaderc_compilation_result_t result = nullptr;
#endif
#if USE_SKSL
bool result = gpu->shaderCompiler()->toSPIRV(vk_shader_stage_to_skiasl_kind(stage),
- std::string(shaderString),
+ SkString(shaderString),
&code);
if (!result) {
SkDebugf("%s\n", gpu->shaderCompiler()->errorText().c_str());
#define SKSL_CODEGENERATOR
#include "ir/SkSLProgram.h"
-#include <vector>
-#include <ostream>
namespace SkSL {
public:
virtual ~CodeGenerator() {}
- virtual void generateCode(const Program& program, std::ostream& out) = 0;
+ virtual void generateCode(const Program& program, SkWStream& out) = 0;
};
} // namespace
#include "SkSLCompiler.h"
-#include <fstream>
-#include <streambuf>
-
#include "ast/SkSLASTPrecision.h"
#include "SkSLCFGGenerator.h"
#include "SkSLIRGenerator.h"
ADD_TYPE(BVec3);
ADD_TYPE(BVec4);
ADD_TYPE(Mat2x2);
- types->addWithoutOwnership("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("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("mat4x4", fContext.fMat4x4_Type.get());
+ types->addWithoutOwnership(SkString("mat4x4"), fContext.fMat4x4_Type.get());
ADD_TYPE(GenType);
ADD_TYPE(GenDType);
ADD_TYPE(GenIType);
Modifiers::Flag ignored1;
std::vector<std::unique_ptr<ProgramElement>> ignored2;
- this->internalConvertProgram(SKSL_INCLUDE, &ignored1, &ignored2);
+ this->internalConvertProgram(SkString(SKSL_INCLUDE), &ignored1, &ignored2);
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
ASSERT(!fErrorCount);
}
for (size_t i = 0; i < cfg.fBlocks.size(); i++) {
if (i != cfg.fStart && !cfg.fBlocks[i].fEntrances.size() &&
cfg.fBlocks[i].fNodes.size()) {
- this->error(cfg.fBlocks[i].fNodes[0].fNode->fPosition, "unreachable");
+ this->error(cfg.fBlocks[i].fNodes[0].fNode->fPosition, SkString("unreachable"));
}
}
if (fErrorCount) {
// check for missing return
if (f.fDeclaration.fReturnType != *fContext.fVoid_Type) {
if (cfg.fBlocks[cfg.fExit].fEntrances.size()) {
- this->error(f.fPosition, "function can exit without returning a value");
+ this->error(f.fPosition, SkString("function can exit without returning a value"));
}
}
}
-void Compiler::internalConvertProgram(std::string text,
+void Compiler::internalConvertProgram(SkString text,
Modifiers::Flag* defaultPrecision,
std::vector<std::unique_ptr<ProgramElement>>* result) {
Parser parser(text, *fTypes, *this);
}
}
-std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, std::string text) {
+std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, SkString text) {
fErrorText = "";
fErrorCount = 0;
fIRGenerator->pushSymbolTable();
Modifiers::Flag ignored;
switch (kind) {
case Program::kVertex_Kind:
- this->internalConvertProgram(SKSL_VERT_INCLUDE, &ignored, &elements);
+ this->internalConvertProgram(SkString(SKSL_VERT_INCLUDE), &ignored, &elements);
break;
case Program::kFragment_Kind:
- this->internalConvertProgram(SKSL_FRAG_INCLUDE, &ignored, &elements);
+ this->internalConvertProgram(SkString(SKSL_FRAG_INCLUDE), &ignored, &elements);
break;
}
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
return result;
}
-void Compiler::error(Position position, std::string msg) {
+void Compiler::error(Position position, SkString msg) {
fErrorCount++;
fErrorText += "error: " + position.description() + ": " + msg.c_str() + "\n";
}
-std::string Compiler::errorText() {
- std::string result = fErrorText;
+SkString Compiler::errorText() {
+ SkString result = fErrorText;
return result;
}
}
}
-bool Compiler::toSPIRV(Program::Kind kind, const std::string& text, std::ostream& out) {
+bool Compiler::toSPIRV(Program::Kind kind, const SkString& text, SkWStream& out) {
auto program = this->convertProgram(kind, text);
if (fErrorCount == 0) {
SkSL::SPIRVCodeGenerator cg(&fContext);
cg.generateCode(*program.get(), out);
- ASSERT(!out.rdstate());
}
return fErrorCount == 0;
}
-bool Compiler::toSPIRV(Program::Kind kind, const std::string& text, std::string* out) {
- std::stringstream buffer;
+bool Compiler::toSPIRV(Program::Kind kind, const SkString& text, SkString* out) {
+ SkDynamicMemoryWStream buffer;
bool result = this->toSPIRV(kind, text, buffer);
if (result) {
- *out = buffer.str();
+ sk_sp<SkData> data(buffer.detachAsData());
+ *out = SkString((const char*) data->data(), data->size());
}
return result;
}
-bool Compiler::toGLSL(Program::Kind kind, const std::string& text, const GrGLSLCaps& caps,
- std::ostream& out) {
+bool Compiler::toGLSL(Program::Kind kind, const SkString& text, const GrGLSLCaps& caps,
+ SkWStream& out) {
auto program = this->convertProgram(kind, text);
if (fErrorCount == 0) {
SkSL::GLSLCodeGenerator cg(&fContext, &caps);
cg.generateCode(*program.get(), out);
- ASSERT(!out.rdstate());
}
return fErrorCount == 0;
}
-bool Compiler::toGLSL(Program::Kind kind, const std::string& text, const GrGLSLCaps& caps,
- std::string* out) {
- std::stringstream buffer;
+bool Compiler::toGLSL(Program::Kind kind, const SkString& text, const GrGLSLCaps& caps,
+ SkString* out) {
+ SkDynamicMemoryWStream buffer;
bool result = this->toGLSL(kind, text, caps, buffer);
if (result) {
- *out = buffer.str();
+ sk_sp<SkData> data(buffer.detachAsData());
+ *out = SkString((const char*) data->data(), data->size());
}
return result;
}
~Compiler();
- std::unique_ptr<Program> convertProgram(Program::Kind kind, std::string text);
+ std::unique_ptr<Program> convertProgram(Program::Kind kind, SkString text);
- bool toSPIRV(Program::Kind kind, const std::string& text, std::ostream& out);
+ bool toSPIRV(Program::Kind kind, const SkString& text, SkWStream& out);
- bool toSPIRV(Program::Kind kind, const std::string& text, std::string* out);
+ bool toSPIRV(Program::Kind kind, const SkString& text, SkString* out);
- bool toGLSL(Program::Kind kind, const std::string& text, const GrGLSLCaps& caps,
- std::ostream& out);
+ bool toGLSL(Program::Kind kind, const SkString& text, const GrGLSLCaps& caps,
+ SkWStream& out);
- bool toGLSL(Program::Kind kind, const std::string& text, const GrGLSLCaps& caps,
- std::string* out);
+ bool toGLSL(Program::Kind kind, const SkString& text, const GrGLSLCaps& caps,
+ SkString* out);
- void error(Position position, std::string msg) override;
+ void error(Position position, SkString msg) override;
- std::string errorText();
+ SkString errorText();
void writeErrorCount();
void scanCFG(const FunctionDefinition& f);
- void internalConvertProgram(std::string text,
+ void internalConvertProgram(SkString text,
Modifiers::Flag* defaultPrecision,
std::vector<std::unique_ptr<ProgramElement>>* result);
std::shared_ptr<SymbolTable> fTypes;
IRGenerator* fIRGenerator;
- std::string fSkiaVertText; // FIXME store parsed version instead
+ SkString fSkiaVertText; // FIXME store parsed version instead
Context fContext;
int fErrorCount;
- std::string fErrorText;
+ SkString fErrorText;
};
} // namespace
class Context {
public:
Context()
- : fInvalid_Type(new Type("<INVALID>"))
- , fVoid_Type(new Type("void"))
- , fDouble_Type(new Type("double", true))
- , fDVec2_Type(new Type("dvec2", *fDouble_Type, 2))
- , fDVec3_Type(new Type("dvec3", *fDouble_Type, 3))
- , fDVec4_Type(new Type("dvec4", *fDouble_Type, 4))
- , fFloat_Type(new Type("float", true, { fDouble_Type.get() }))
- , fVec2_Type(new Type("vec2", *fFloat_Type, 2))
- , fVec3_Type(new Type("vec3", *fFloat_Type, 3))
- , fVec4_Type(new Type("vec4", *fFloat_Type, 4))
- , fUInt_Type(new Type("uint", true, { fFloat_Type.get(), fDouble_Type.get() }))
- , fUVec2_Type(new Type("uvec2", *fUInt_Type, 2))
- , fUVec3_Type(new Type("uvec3", *fUInt_Type, 3))
- , fUVec4_Type(new Type("uvec4", *fUInt_Type, 4))
- , fInt_Type(new Type("int", true, { fUInt_Type.get(), fFloat_Type.get(), fDouble_Type.get() }))
- , fIVec2_Type(new Type("ivec2", *fInt_Type, 2))
- , fIVec3_Type(new Type("ivec3", *fInt_Type, 3))
- , fIVec4_Type(new Type("ivec4", *fInt_Type, 4))
- , fBool_Type(new Type("bool", false))
- , fBVec2_Type(new Type("bvec2", *fBool_Type, 2))
- , fBVec3_Type(new Type("bvec3", *fBool_Type, 3))
- , fBVec4_Type(new Type("bvec4", *fBool_Type, 4))
- , fMat2x2_Type(new Type("mat2", *fFloat_Type, 2, 2))
- , fMat2x3_Type(new Type("mat2x3", *fFloat_Type, 2, 3))
- , fMat2x4_Type(new Type("mat2x4", *fFloat_Type, 2, 4))
- , fMat3x2_Type(new Type("mat3x2", *fFloat_Type, 3, 2))
- , fMat3x3_Type(new Type("mat3", *fFloat_Type, 3, 3))
- , fMat3x4_Type(new Type("mat3x4", *fFloat_Type, 3, 4))
- , fMat4x2_Type(new Type("mat4x2", *fFloat_Type, 4, 2))
- , fMat4x3_Type(new Type("mat4x3", *fFloat_Type, 4, 3))
- , fMat4x4_Type(new Type("mat4", *fFloat_Type, 4, 4))
- , fDMat2x2_Type(new Type("dmat2", *fFloat_Type, 2, 2))
- , fDMat2x3_Type(new Type("dmat2x3", *fFloat_Type, 2, 3))
- , fDMat2x4_Type(new Type("dmat2x4", *fFloat_Type, 2, 4))
- , fDMat3x2_Type(new Type("dmat3x2", *fFloat_Type, 3, 2))
- , fDMat3x3_Type(new Type("dmat3", *fFloat_Type, 3, 3))
- , fDMat3x4_Type(new Type("dmat3x4", *fFloat_Type, 3, 4))
- , fDMat4x2_Type(new Type("dmat4x2", *fFloat_Type, 4, 2))
- , fDMat4x3_Type(new Type("dmat4x3", *fFloat_Type, 4, 3))
- , fDMat4x4_Type(new Type("dmat4", *fFloat_Type, 4, 4))
- , fSampler1D_Type(new Type("sampler1D", SpvDim1D, false, false, false, true))
- , fSampler2D_Type(new Type("sampler2D", SpvDim2D, false, false, false, true))
- , fSampler3D_Type(new Type("sampler3D", SpvDim3D, false, false, false, true))
- , fSamplerExternalOES_Type(new Type("samplerExternalOES", SpvDim2D, false, false, false, true))
- , fSamplerCube_Type(new Type("samplerCube"))
- , fSampler2DRect_Type(new Type("sampler2DRect"))
- , fSampler1DArray_Type(new Type("sampler1DArray"))
- , fSampler2DArray_Type(new Type("sampler2DArray"))
- , fSamplerCubeArray_Type(new Type("samplerCubeArray"))
- , fSamplerBuffer_Type(new Type("samplerBuffer"))
- , fSampler2DMS_Type(new Type("sampler2DMS"))
- , fSampler2DMSArray_Type(new Type("sampler2DMSArray"))
- , fSampler1DShadow_Type(new Type("sampler1DShadow"))
- , fSampler2DShadow_Type(new Type("sampler2DShadow"))
- , fSamplerCubeShadow_Type(new Type("samplerCubeShadow"))
- , fSampler2DRectShadow_Type(new Type("sampler2DRectShadow"))
- , fSampler1DArrayShadow_Type(new Type("sampler1DArrayShadow"))
- , fSampler2DArrayShadow_Type(new Type("sampler2DArrayShadow"))
- , fSamplerCubeArrayShadow_Type(new Type("samplerCubeArrayShadow"))
+ : fInvalid_Type(new Type(SkString("<INVALID>")))
+ , fVoid_Type(new Type(SkString("void")))
+ , fDouble_Type(new Type(SkString("double"), true))
+ , fDVec2_Type(new Type(SkString("dvec2"), *fDouble_Type, 2))
+ , fDVec3_Type(new Type(SkString("dvec3"), *fDouble_Type, 3))
+ , fDVec4_Type(new Type(SkString("dvec4"), *fDouble_Type, 4))
+ , fFloat_Type(new Type(SkString("float"), true, { fDouble_Type.get() }))
+ , fVec2_Type(new Type(SkString("vec2"), *fFloat_Type, 2))
+ , fVec3_Type(new Type(SkString("vec3"), *fFloat_Type, 3))
+ , fVec4_Type(new Type(SkString("vec4"), *fFloat_Type, 4))
+ , fUInt_Type(new Type(SkString("uint"), true, { fFloat_Type.get(), fDouble_Type.get() }))
+ , fUVec2_Type(new Type(SkString("uvec2"), *fUInt_Type, 2))
+ , fUVec3_Type(new Type(SkString("uvec3"), *fUInt_Type, 3))
+ , fUVec4_Type(new Type(SkString("uvec4"), *fUInt_Type, 4))
+ , fInt_Type(new Type(SkString("int"), true, { fUInt_Type.get(), fFloat_Type.get(),
+ fDouble_Type.get() }))
+ , fIVec2_Type(new Type(SkString("ivec2"), *fInt_Type, 2))
+ , fIVec3_Type(new Type(SkString("ivec3"), *fInt_Type, 3))
+ , fIVec4_Type(new Type(SkString("ivec4"), *fInt_Type, 4))
+ , fBool_Type(new Type(SkString("bool"), false))
+ , fBVec2_Type(new Type(SkString("bvec2"), *fBool_Type, 2))
+ , fBVec3_Type(new Type(SkString("bvec3"), *fBool_Type, 3))
+ , fBVec4_Type(new Type(SkString("bvec4"), *fBool_Type, 4))
+ , fMat2x2_Type(new Type(SkString("mat2"), *fFloat_Type, 2, 2))
+ , fMat2x3_Type(new Type(SkString("mat2x3"), *fFloat_Type, 2, 3))
+ , fMat2x4_Type(new Type(SkString("mat2x4"), *fFloat_Type, 2, 4))
+ , fMat3x2_Type(new Type(SkString("mat3x2"), *fFloat_Type, 3, 2))
+ , fMat3x3_Type(new Type(SkString("mat3"), *fFloat_Type, 3, 3))
+ , fMat3x4_Type(new Type(SkString("mat3x4"), *fFloat_Type, 3, 4))
+ , fMat4x2_Type(new Type(SkString("mat4x2"), *fFloat_Type, 4, 2))
+ , fMat4x3_Type(new Type(SkString("mat4x3"), *fFloat_Type, 4, 3))
+ , fMat4x4_Type(new Type(SkString("mat4"), *fFloat_Type, 4, 4))
+ , fDMat2x2_Type(new Type(SkString("dmat2"), *fFloat_Type, 2, 2))
+ , fDMat2x3_Type(new Type(SkString("dmat2x3"), *fFloat_Type, 2, 3))
+ , fDMat2x4_Type(new Type(SkString("dmat2x4"), *fFloat_Type, 2, 4))
+ , fDMat3x2_Type(new Type(SkString("dmat3x2"), *fFloat_Type, 3, 2))
+ , fDMat3x3_Type(new Type(SkString("dmat3"), *fFloat_Type, 3, 3))
+ , fDMat3x4_Type(new Type(SkString("dmat3x4"), *fFloat_Type, 3, 4))
+ , fDMat4x2_Type(new Type(SkString("dmat4x2"), *fFloat_Type, 4, 2))
+ , fDMat4x3_Type(new Type(SkString("dmat4x3"), *fFloat_Type, 4, 3))
+ , fDMat4x4_Type(new Type(SkString("dmat4"), *fFloat_Type, 4, 4))
+ , fSampler1D_Type(new Type(SkString("sampler1D"), SpvDim1D, false, false, false, true))
+ , fSampler2D_Type(new Type(SkString("sampler2D"), SpvDim2D, false, false, false, true))
+ , fSampler3D_Type(new Type(SkString("sampler3D"), SpvDim3D, false, false, false, true))
+ , fSamplerExternalOES_Type(new Type(SkString("samplerExternalOES"), SpvDim2D, false, false,
+ false, true))
+ , fSamplerCube_Type(new Type(SkString("samplerCube")))
+ , fSampler2DRect_Type(new Type(SkString("sampler2DRect")))
+ , fSampler1DArray_Type(new Type(SkString("sampler1DArray")))
+ , fSampler2DArray_Type(new Type(SkString("sampler2DArray")))
+ , fSamplerCubeArray_Type(new Type(SkString("samplerCubeArray")))
+ , fSamplerBuffer_Type(new Type(SkString("samplerBuffer")))
+ , fSampler2DMS_Type(new Type(SkString("sampler2DMS")))
+ , fSampler2DMSArray_Type(new Type(SkString("sampler2DMSArray")))
+ , fSampler1DShadow_Type(new Type(SkString("sampler1DShadow")))
+ , fSampler2DShadow_Type(new Type(SkString("sampler2DShadow")))
+ , fSamplerCubeShadow_Type(new Type(SkString("samplerCubeShadow")))
+ , fSampler2DRectShadow_Type(new Type(SkString("sampler2DRectShadow")))
+ , fSampler1DArrayShadow_Type(new Type(SkString("sampler1DArrayShadow")))
+ , fSampler2DArrayShadow_Type(new Type(SkString("sampler2DArrayShadow")))
+ , fSamplerCubeArrayShadow_Type(new Type(SkString("samplerCubeArrayShadow")))
// Related to below FIXME, gsampler*s don't currently expand to cover integer case.
- , fISampler2D_Type(new Type("isampler2D", SpvDim2D, false, false, false, true))
+ , fISampler2D_Type(new Type(SkString("isampler2D"), SpvDim2D, false, false, false, true))
// FIXME express these as "gimage2D" that expand to image2D, iimage2D, and uimage2D.
- , fImage2D_Type(new Type("image2D", SpvDim2D, false, false, false, true))
- , fIImage2D_Type(new Type("iimage2D", SpvDim2D, false, false, false, true))
+ , fImage2D_Type(new Type(SkString("image2D"), SpvDim2D, false, false, false, true))
+ , fIImage2D_Type(new Type(SkString("iimage2D"), SpvDim2D, false, false, false, true))
// FIXME figure out what we're supposed to do with the gsampler et al. types)
- , fGSampler1D_Type(new Type("$gsampler1D", static_type(*fSampler1D_Type)))
- , fGSampler2D_Type(new Type("$gsampler2D", static_type(*fSampler2D_Type)))
- , fGSampler3D_Type(new Type("$gsampler3D", static_type(*fSampler3D_Type)))
- , fGSamplerCube_Type(new Type("$gsamplerCube", static_type(*fSamplerCube_Type)))
- , fGSampler2DRect_Type(new Type("$gsampler2DRect", static_type(*fSampler2DRect_Type)))
- , fGSampler1DArray_Type(new Type("$gsampler1DArray", static_type(*fSampler1DArray_Type)))
- , fGSampler2DArray_Type(new Type("$gsampler2DArray", static_type(*fSampler2DArray_Type)))
- , fGSamplerCubeArray_Type(new Type("$gsamplerCubeArray", static_type(*fSamplerCubeArray_Type)))
- , fGSamplerBuffer_Type(new Type("$gsamplerBuffer", static_type(*fSamplerBuffer_Type)))
- , fGSampler2DMS_Type(new Type("$gsampler2DMS", static_type(*fSampler2DMS_Type)))
- , fGSampler2DMSArray_Type(new Type("$gsampler2DMSArray", static_type(*fSampler2DMSArray_Type)))
- , fGSampler2DArrayShadow_Type(new Type("$gsampler2DArrayShadow",
+ , fGSampler1D_Type(new Type(SkString("$gsampler1D"), static_type(*fSampler1D_Type)))
+ , fGSampler2D_Type(new Type(SkString("$gsampler2D"), static_type(*fSampler2D_Type)))
+ , fGSampler3D_Type(new Type(SkString("$gsampler3D"), static_type(*fSampler3D_Type)))
+ , fGSamplerCube_Type(new Type(SkString("$gsamplerCube"), static_type(*fSamplerCube_Type)))
+ , fGSampler2DRect_Type(new Type(SkString("$gsampler2DRect"), static_type(*fSampler2DRect_Type)))
+ , fGSampler1DArray_Type(new Type(SkString("$gsampler1DArray"),
+ static_type(*fSampler1DArray_Type)))
+ , fGSampler2DArray_Type(new Type(SkString("$gsampler2DArray"),
+ static_type(*fSampler2DArray_Type)))
+ , fGSamplerCubeArray_Type(new Type(SkString("$gsamplerCubeArray"),
+ static_type(*fSamplerCubeArray_Type)))
+ , fGSamplerBuffer_Type(new Type(SkString("$gsamplerBuffer"), static_type(*fSamplerBuffer_Type)))
+ , fGSampler2DMS_Type(new Type(SkString("$gsampler2DMS"), static_type(*fSampler2DMS_Type)))
+ , fGSampler2DMSArray_Type(new Type(SkString("$gsampler2DMSArray"),
+ static_type(*fSampler2DMSArray_Type)))
+ , fGSampler2DArrayShadow_Type(new Type(SkString("$gsampler2DArrayShadow"),
static_type(*fSampler2DArrayShadow_Type)))
- , fGSamplerCubeArrayShadow_Type(new Type("$gsamplerCubeArrayShadow",
+ , fGSamplerCubeArrayShadow_Type(new Type(SkString("$gsamplerCubeArrayShadow"),
static_type(*fSamplerCubeArrayShadow_Type)))
- , fGenType_Type(new Type("$genType", { fFloat_Type.get(), fVec2_Type.get(), fVec3_Type.get(),
- fVec4_Type.get() }))
- , fGenDType_Type(new Type("$genDType", { fDouble_Type.get(), fDVec2_Type.get(),
- fDVec3_Type.get(), fDVec4_Type.get() }))
- , fGenIType_Type(new Type("$genIType", { fInt_Type.get(), fIVec2_Type.get(), fIVec3_Type.get(),
- fIVec4_Type.get() }))
- , fGenUType_Type(new Type("$genUType", { fUInt_Type.get(), fUVec2_Type.get(), fUVec3_Type.get(),
- fUVec4_Type.get() }))
- , fGenBType_Type(new Type("$genBType", { fBool_Type.get(), fBVec2_Type.get(), fBVec3_Type.get(),
- fBVec4_Type.get() }))
- , fMat_Type(new Type("$mat"))
- , fVec_Type(new Type("$vec", { fInvalid_Type.get(), fVec2_Type.get(), fVec3_Type.get(),
- fVec4_Type.get() }))
- , fGVec_Type(new Type("$gvec"))
- , fGVec2_Type(new Type("$gvec2"))
- , fGVec3_Type(new Type("$gvec3"))
- , fGVec4_Type(new Type("$gvec4", static_type(*fVec4_Type)))
- , fDVec_Type(new Type("$dvec", { fInvalid_Type.get(), fDVec2_Type.get(), fDVec3_Type.get(),
- fDVec4_Type.get() }))
- , fIVec_Type(new Type("$ivec", { fInvalid_Type.get(), fIVec2_Type.get(), fIVec3_Type.get(),
- fIVec4_Type.get() }))
- , fUVec_Type(new Type("$uvec", { fInvalid_Type.get(), fUVec2_Type.get(), fUVec3_Type.get(),
- fUVec4_Type.get() }))
- , fBVec_Type(new Type("$bvec", { fInvalid_Type.get(), fBVec2_Type.get(), fBVec3_Type.get(),
- fBVec4_Type.get() }))
+ , fGenType_Type(new Type(SkString("$genType"), { fFloat_Type.get(), fVec2_Type.get(),
+ fVec3_Type.get(), fVec4_Type.get() }))
+ , fGenDType_Type(new Type(SkString("$genDType"), { fDouble_Type.get(), fDVec2_Type.get(),
+ fDVec3_Type.get(), fDVec4_Type.get() }))
+ , fGenIType_Type(new Type(SkString("$genIType"), { fInt_Type.get(), fIVec2_Type.get(),
+ fIVec3_Type.get(), fIVec4_Type.get() }))
+ , fGenUType_Type(new Type(SkString("$genUType"), { fUInt_Type.get(), fUVec2_Type.get(),
+ fUVec3_Type.get(), fUVec4_Type.get() }))
+ , fGenBType_Type(new Type(SkString("$genBType"), { fBool_Type.get(), fBVec2_Type.get(),
+ fBVec3_Type.get(), fBVec4_Type.get() }))
+ , fMat_Type(new Type(SkString("$mat")))
+ , fVec_Type(new Type(SkString("$vec"), { fInvalid_Type.get(), fVec2_Type.get(),
+ fVec3_Type.get(), fVec4_Type.get() }))
+ , fGVec_Type(new Type(SkString("$gvec")))
+ , fGVec2_Type(new Type(SkString("$gvec2")))
+ , fGVec3_Type(new Type(SkString("$gvec3")))
+ , fGVec4_Type(new Type(SkString("$gvec4"), static_type(*fVec4_Type)))
+ , fDVec_Type(new Type(SkString("$dvec"), { fInvalid_Type.get(), fDVec2_Type.get(),
+ fDVec3_Type.get(), fDVec4_Type.get() }))
+ , fIVec_Type(new Type(SkString("$ivec"), { fInvalid_Type.get(), fIVec2_Type.get(),
+ fIVec3_Type.get(), fIVec4_Type.get() }))
+ , fUVec_Type(new Type(SkString("$uvec"), { fInvalid_Type.get(), fUVec2_Type.get(),
+ fUVec3_Type.get(), fUVec4_Type.get() }))
+ , fBVec_Type(new Type(SkString("$bvec"), { fInvalid_Type.get(), fBVec2_Type.get(),
+ fBVec3_Type.get(), fBVec4_Type.get() }))
, fDefined_Expression(new Defined(*fInvalid_Type)) {}
static std::vector<const Type*> static_type(const Type& t) {
Defined(const Type& type)
: INHERITED(Position(), kDefined_Kind, type) {}
- virtual std::string description() const override {
- return "<defined>";
+ virtual SkString description() const override {
+ return SkString("<defined>");
}
typedef Expression INHERITED;
public:
virtual ~ErrorReporter() {}
- virtual void error(Position position, std::string msg) = 0;
+ void error(Position position, const char* msg) {
+ this->error(position, SkString(msg));
+ }
+
+ virtual void error(Position position, SkString msg) = 0;
};
} // namespace
}
if (fAtLineStart) {
for (int i = 0; i < fIndentation; i++) {
- *fOut << " ";
+ fOut->writeText(" ");
}
}
- *fOut << s;
+ fOut->writeText(s);
fAtLineStart = false;
}
void GLSLCodeGenerator::writeLine(const char* s) {
this->write(s);
- *fOut << "\n";
+ fOut->writeText("\n");
fAtLineStart = true;
}
-void GLSLCodeGenerator::write(const std::string& s) {
+void GLSLCodeGenerator::write(const SkString& s) {
this->write(s.c_str());
}
-void GLSLCodeGenerator::writeLine(const std::string& s) {
+void GLSLCodeGenerator::writeLine(const SkString& s) {
this->writeLine(s.c_str());
}
// Tegra3 compiler bug.
void GLSLCodeGenerator::writeMinAbsHack(Expression& absExpr, Expression& otherExpr) {
ASSERT(!fCaps.canUseMinAndAbsTogether());
- std::string tmpVar1 = "minAbsHackVar" + to_string(fVarCount++);
- std::string tmpVar2 = "minAbsHackVar" + to_string(fVarCount++);
+ SkString tmpVar1 = "minAbsHackVar" + to_string(fVarCount++);
+ SkString tmpVar2 = "minAbsHackVar" + to_string(fVarCount++);
this->fFunctionHeader += " " + absExpr.fType.name() + " " + tmpVar1 + ";\n";
this->fFunctionHeader += " " + otherExpr.fType.name() + " " + tmpVar2 + ";\n";
this->write("((" + tmpVar1 + " = ");
if (!fFoundDerivatives && (c.fFunction.fName == "dFdx" || c.fFunction.fName == "dFdy") &&
c.fFunction.fBuiltin && fCaps.shaderDerivativeExtensionString()) {
ASSERT(fCaps.shaderDerivativeSupport());
- fHeader << "#extension " << fCaps.shaderDerivativeExtensionString() << " : require\n";
+ fHeader.writeText("#extension ");
+ fHeader.writeText(fCaps.shaderDerivativeExtensionString());
+ fHeader.writeText(" : require\n");
fFoundDerivatives = true;
}
this->write(c.fFunction.fName + "(");
this->writeLine(") {");
fFunctionHeader = "";
- std::ostream* oldOut = fOut;
- std::stringstream buffer;
+ SkWStream* oldOut = fOut;
+ SkDynamicMemoryWStream buffer;
fOut = &buffer;
fIndentation++;
for (const auto& s : f.fBody->fStatements) {
fOut = oldOut;
this->write(fFunctionHeader);
- this->write(buffer.str());
+ sk_sp<SkData> data(buffer.detachAsData());
+ this->write(SkString((const char*) data->data(), data->size()));
}
void GLSLCodeGenerator::writeModifiers(const Modifiers& modifiers,
if (modifiers.fFlags & Modifiers::kFlat_Flag) {
this->write("flat ");
}
- std::string layout = modifiers.fLayout.description();
- if (layout.length()) {
+ SkString layout = modifiers.fLayout.description();
+ if (layout.size()) {
this->write(layout + " ");
}
if ((modifiers.fFlags & Modifiers::kIn_Flag) &&
ASSERT(decl.fVars.size() > 0);
this->writeModifiers(decl.fVars[0].fVar->fModifiers, global);
this->writeType(decl.fBaseType);
- std::string separator = " ";
+ SkString separator(" ");
for (const auto& var : decl.fVars) {
ASSERT(var.fVar->fModifiers == decl.fVars[0].fVar->fModifiers);
this->write(separator);
- separator = ", ";
+ separator = SkString(", ");
this->write(var.fVar->fName);
for (const auto& size : var.fSizes) {
this->write("[");
}
if (!fFoundImageDecl && var.fVar->fType == *fContext.fImage2D_Type) {
if (fCaps.imageLoadStoreExtensionString()) {
- fHeader << "#extension " << fCaps.imageLoadStoreExtensionString() << " : require\n";
+ fHeader.writeText("#extension ");
+ fHeader.writeText(fCaps.imageLoadStoreExtensionString());
+ fHeader.writeText(" : require\n");
}
fFoundImageDecl = true;
}
this->write(";");
}
-void GLSLCodeGenerator::generateCode(const Program& program, std::ostream& out) {
+void GLSLCodeGenerator::generateCode(const Program& program, SkWStream& out) {
ASSERT(fOut == nullptr);
fOut = &fHeader;
fProgramKind = program.fKind;
this->writeExtension((Extension&) *e);
}
}
- std::stringstream body;
+ SkDynamicMemoryWStream body;
fOut = &body;
if (fCaps.usesPrecisionModifiers()) {
this->write("precision ");
}
fOut = nullptr;
- out << fHeader.str();
- out << body.str();
+ write_data(*fHeader.detachAsData(), out);
+ write_data(*body.detachAsData(), out);
}
}
#include <tuple>
#include <unordered_map>
+#include "SkStream.h"
#include "glsl/GrGLSLCaps.h"
#include "SkSLCodeGenerator.h"
#include "ir/SkSLBinaryExpression.h"
: fContext(*context)
, fCaps(*caps) {}
- void generateCode(const Program& program, std::ostream& out) override;
+ void generateCode(const Program& program, SkWStream& out) override;
private:
void write(const char* s);
void writeLine(const char* s);
- void write(const std::string& s);
+ void write(const SkString& s);
- void writeLine(const std::string& s);
+ void writeLine(const SkString& s);
void writeType(const Type& type);
const Context& fContext;
const GrGLSLCaps& fCaps;
- std::ostream* fOut = nullptr;
- std::stringstream fHeader;
- std::string fFunctionHeader;
+ SkWStream* fOut = nullptr;
+ SkDynamicMemoryWStream fHeader;
+ SkString fFunctionHeader;
Program::Kind fProgramKind;
int fVarCount = 0;
int fIndentation = 0;
if (!size) {
return nullptr;
}
- std::string name = type->fName;
+ SkString name = type->fName;
uint64_t count;
if (size->fKind == Expression::kIntLiteral_Kind) {
count = ((IntLiteral&) *size).fValue;
}
value = this->coerce(std::move(value), *type);
}
- if (storage == Variable::kGlobal_Storage && "sk_FragColor" == varDecl.fName &&
+ if (storage == Variable::kGlobal_Storage && varDecl.fName == SkString("sk_FragColor") &&
(*fSymbolTable)[varDecl.fName]) {
// already defined, ignore
} else if (storage == Variable::kGlobal_Storage && (*fSymbolTable)[varDecl.fName] &&
}
for (int j = (int) param->fSizes.size() - 1; j >= 0; j--) {
int size = param->fSizes[j];
- std::string name = type->name() + "[" + to_string(size) + "]";
+ SkString name = type->name() + "[" + to_string(size) + "]";
Type* newType = new Type(std::move(name), Type::kArray_Kind, *type, size);
fSymbolTable->takeOwnership(newType);
type = newType;
}
- std::string name = param->fName;
+ SkString name = param->fName;
Modifiers modifiers = this->convertModifiers(param->fModifiers);
Position pos = param->fPosition;
Variable* var = new Variable(pos, modifiers, std::move(name), *type,
}
Type* type = new Type(intf.fInterfaceName, fields);
fSymbolTable->takeOwnership(type);
- std::string name = intf.fValueName.length() > 0 ? intf.fValueName : intf.fInterfaceName;
+ SkString name = intf.fValueName.size() > 0 ? intf.fValueName : intf.fInterfaceName;
Variable* var = new Variable(intf.fPosition, mods, name, *type, Variable::kGlobal_Storage);
fSymbolTable->takeOwnership(var);
- if (intf.fValueName.length()) {
+ if (intf.fValueName.size()) {
old->addWithoutOwnership(intf.fValueName, var);
} else {
for (size_t i = 0; i < fields.size(); i++) {
const FunctionDeclaration& function,
std::vector<std::unique_ptr<Expression>> arguments) {
if (function.fParameters.size() != arguments.size()) {
- std::string msg = "call to '" + function.fName + "' expected " +
+ SkString msg = "call to '" + function.fName + "' expected " +
to_string((uint64_t) function.fParameters.size()) +
" argument";
if (function.fParameters.size() != 1) {
std::vector<const Type*> types;
const Type* returnType;
if (!function.determineFinalTypes(arguments, &types, &returnType)) {
- std::string msg = "no match for " + function.fName + "(";
- std::string separator = "";
+ SkString msg = "no match for " + function.fName + "(";
+ SkString separator;
for (size_t i = 0; i < arguments.size(); i++) {
msg += separator;
separator = ", ";
if (best) {
return this->call(position, *best, std::move(arguments));
}
- std::string msg = "no match for " + ref->fFunctions[0]->fName + "(";
- std::string separator = "";
+ SkString msg = "no match for " + ref->fFunctions[0]->fName + "(";
+ SkString separator;
for (size_t i = 0; i < arguments.size(); i++) {
msg += separator;
separator = ", ";
}
std::unique_ptr<Expression> IRGenerator::convertField(std::unique_ptr<Expression> base,
- const std::string& field) {
+ const SkString& field) {
auto fields = base->fType.fields();
for (size_t i = 0; i < fields.size(); i++) {
if (fields[i].fName == field) {
}
std::unique_ptr<Expression> IRGenerator::convertSwizzle(std::unique_ptr<Expression> base,
- const std::string& fields) {
+ const SkString& fields) {
if (base->fType.kind() != Type::kVector_Kind) {
fErrors.error(base->fPosition, "cannot swizzle type '" + base->fType.description() + "'");
return nullptr;
}
std::vector<int> swizzleComponents;
- for (char c : fields) {
- switch (c) {
+ for (size_t i = 0; i < fields.size(); i++) {
+ switch (fields[i]) {
case 'x': // fall through
case 'r': // fall through
case 's':
}
// fall through
default:
- fErrors.error(base->fPosition, "invalid swizzle component '" + std::string(1, c) +
- "'");
+ fErrors.error(base->fPosition, SkStringPrintf("invalid swizzle component '%c'",
+ fields[i]));
return nullptr;
}
}
std::unique_ptr<Statement> convertReturn(const ASTReturnStatement& r);
std::unique_ptr<Expression> convertSuffixExpression(const ASTSuffixExpression& expression);
std::unique_ptr<Expression> convertField(std::unique_ptr<Expression> base,
- const std::string& field);
+ const SkString& field);
std::unique_ptr<Expression> convertSwizzle(std::unique_ptr<Expression> base,
- const std::string& fields);
+ const SkString& fields);
std::unique_ptr<Expression> convertTernaryExpression(const ASTTernaryExpression& expression);
std::unique_ptr<Statement> convertVarDeclarationStatement(const ASTVarDeclarationStatement& s);
std::unique_ptr<Statement> convertWhile(const ASTWhileStatement& w);
#include "SkSLCompiler.h"
#include "GrContextOptions.h"
-bool endsWith(const std::string& s, const std::string& ending) {
- if (s.length() >= ending.length()) {
- return (0 == s.compare(s.length() - ending.length(), ending.length(), ending));
- }
- return false;
-}
-
/**
* Very simple standalone executable to facilitate testing.
*/
}
std::ifstream in(argv[1]);
- std::string text((std::istreambuf_iterator<char>(in)),
- std::istreambuf_iterator<char>());
+ std::string stdText((std::istreambuf_iterator<char>(in)),
+ std::istreambuf_iterator<char>());
+ SkString text(stdText.c_str());
if (in.rdstate()) {
printf("error reading '%s'\n", argv[1]);
exit(2);
}
- std::string name(argv[2]);
- if (endsWith(name, ".spirv")) {
- std::ofstream out(argv[2], std::ofstream::binary);
+ SkString name(argv[2]);
+ if (name.endsWith(".spirv")) {
+ SkFILEWStream out(argv[2]);
SkSL::Compiler compiler;
+ if (!out.isValid()) {
+ printf("error writing '%s'\n", argv[2]);
+ exit(4);
+ }
if (!compiler.toSPIRV(kind, text, out)) {
printf("%s", compiler.errorText().c_str());
exit(3);
}
- if (out.rdstate()) {
+ } else if (name.endsWith(".glsl")) {
+ SkFILEWStream out(argv[2]);
+ SkSL::Compiler compiler;
+ if (!out.isValid()) {
printf("error writing '%s'\n", argv[2]);
exit(4);
}
- } else if (endsWith(name, ".glsl")) {
- std::ofstream out(argv[2], std::ofstream::binary);
- SkSL::Compiler compiler;
if (!compiler.toGLSL(kind, text, *SkSL::GLSLCapsFactory::Default(), out)) {
printf("%s", compiler.errorText().c_str());
exit(3);
}
- if (out.rdstate()) {
- printf("error writing '%s'\n", argv[2]);
- exit(4);
- }
} else {
printf("expected output filename to end with '.spirv' or '.glsl'");
}
bool checkValid() {
if (fParser->fDepth > MAX_PARSE_DEPTH) {
- fParser->error(fParser->peek().fPosition, "exceeded max parse depth");
+ fParser->error(fParser->peek().fPosition, SkString("exceeded max parse depth"));
return false;
}
return true;
Parser* fParser;
};
-Parser::Parser(std::string text, SymbolTable& types, ErrorReporter& errors)
-: fPushback(Position(-1, -1), Token::INVALID_TOKEN, "")
+Parser::Parser(SkString text, SymbolTable& types, ErrorReporter& errors)
+: fPushback(Position(-1, -1), Token::INVALID_TOKEN, SkString())
, fTypes(types)
, fErrors(errors) {
sksllex_init(&fScanner);
return result;
}
int token = sksllex(fScanner);
- std::string text;
+ SkString text;
switch ((Token::Kind) token) {
case Token::IDENTIFIER: // fall through
case Token::INT_LITERAL: // fall through
case Token::FLOAT_LITERAL: // fall through
case Token::DIRECTIVE:
- text = std::string(skslget_text(fScanner));
+ text = SkString(skslget_text(fScanner));
break;
default:
break;
return fPushback;
}
-bool Parser::expect(Token::Kind kind, std::string expected, Token* result) {
+
+bool Parser::expect(Token::Kind kind, const char* expected, Token* result) {
+ return this->expect(kind, SkString(expected), result);
+}
+
+bool Parser::expect(Token::Kind kind, SkString expected, Token* result) {
Token next = this->nextToken();
if (next.fKind == kind) {
if (result) {
}
}
-void Parser::error(Position p, std::string msg) {
+void Parser::error(Position p, const char* msg) {
+ this->error(p, SkString(msg));
+}
+
+void Parser::error(Position p, SkString msg) {
fErrors.error(p, msg);
}
-bool Parser::isType(std::string name) {
+bool Parser::isType(SkString name) {
return nullptr != fTypes[name];
}
return nullptr;
}
uint64_t columns = ((ASTIntLiteral&) *var.fSizes[i]).fValue;
- std::string name = type->name() + "[" + to_string(columns) + "]";
+ SkString name = type->name() + "[" + to_string(columns) + "]";
type = new Type(name, Type::kArray_Kind, *type, (int) columns);
fTypes.takeOwnership((Type*) type);
}
(LBRACKET expression? RBRACKET)* (EQ expression)?)* SEMICOLON */
std::unique_ptr<ASTVarDeclarations> Parser::varDeclarationEnd(ASTModifiers mods,
std::unique_ptr<ASTType> type,
- std::string name) {
+ SkString name) {
std::vector<ASTVarDeclaration> vars;
std::vector<std::unique_ptr<ASTExpression>> currentVarSizes;
while (this->peek().fKind == Token::LBRACKET) {
decls.push_back(std::move(decl));
}
this->nextToken();
- std::string valueName;
+ SkString valueName;
if (this->peek().fKind == Token::IDENTIFIER) {
valueName = this->nextToken().fText;
}
}
case Token::DOT: {
Position pos = this->peek().fPosition;
- std::string text;
+ SkString text;
if (this->identifier(&text)) {
return std::unique_ptr<ASTSuffix>(new ASTFieldSuffix(pos, std::move(text)));
}
Token t = this->peek();
switch (t.fKind) {
case Token::IDENTIFIER: {
- std::string text;
+ SkString text;
if (this->identifier(&text)) {
result.reset(new ASTIdentifier(t.fPosition, std::move(text)));
}
}
/* IDENTIFIER */
-bool Parser::identifier(std::string* dest) {
+bool Parser::identifier(SkString* dest) {
Token t;
if (this->expect(Token::IDENTIFIER, "identifier", &t)) {
*dest = t.fText;
#ifndef SKSL_PARSER
#define SKSL_PARSER
-#include <string>
#include <vector>
#include <memory>
#include <unordered_set>
*/
class Parser {
public:
- Parser(std::string text, SymbolTable& types, ErrorReporter& errors);
+ Parser(SkString text, SymbolTable& types, ErrorReporter& errors);
~Parser();
* If 'result' is non-null, it is set to point to the token that was read.
* Returns true if the read token was as expected, false otherwise.
*/
- bool expect(Token::Kind kind, std::string expected, Token* result = nullptr);
+ bool expect(Token::Kind kind, const char* expected, Token* result = nullptr);
+ bool expect(Token::Kind kind, SkString expected, Token* result = nullptr);
- void error(Position p, std::string msg);
+ void error(Position p, const char* msg);
+ void error(Position p, SkString msg);
/**
* Returns true if the 'name' identifier refers to a type name. For instance, isType("int") will
* always return true.
*/
- bool isType(std::string name);
+ bool isType(SkString name);
// these functions parse individual grammar rules from the current parse position; you probably
// don't need to call any of these outside of the parser. The function declarations in the .cpp
std::unique_ptr<ASTVarDeclarations> varDeclarationEnd(ASTModifiers modifiers,
std::unique_ptr<ASTType> type,
- std::string name);
+ SkString name);
std::unique_ptr<ASTParameter> parameter();
bool boolLiteral(bool* dest);
- bool identifier(std::string* dest);
+ bool identifier(SkString* dest);
void* fScanner;
YY_BUFFER_STATE fBuffer;
: fLine(line)
, fColumn(column) {}
- std::string description() const {
+ SkString description() const {
return to_string(fLine);
}
#define SPECIAL(x) std::make_tuple(kSpecial_IntrinsicKind, k ## x ## _SpecialIntrinsic, \
k ## x ## _SpecialIntrinsic, k ## x ## _SpecialIntrinsic, \
k ## x ## _SpecialIntrinsic)
- fIntrinsicMap["round"] = ALL_GLSL(Round);
- fIntrinsicMap["roundEven"] = ALL_GLSL(RoundEven);
- fIntrinsicMap["trunc"] = ALL_GLSL(Trunc);
- fIntrinsicMap["abs"] = BY_TYPE_GLSL(FAbs, SAbs, SAbs);
- fIntrinsicMap["sign"] = BY_TYPE_GLSL(FSign, SSign, SSign);
- fIntrinsicMap["floor"] = ALL_GLSL(Floor);
- fIntrinsicMap["ceil"] = ALL_GLSL(Ceil);
- fIntrinsicMap["fract"] = ALL_GLSL(Fract);
- fIntrinsicMap["radians"] = ALL_GLSL(Radians);
- fIntrinsicMap["degrees"] = ALL_GLSL(Degrees);
- fIntrinsicMap["sin"] = ALL_GLSL(Sin);
- fIntrinsicMap["cos"] = ALL_GLSL(Cos);
- fIntrinsicMap["tan"] = ALL_GLSL(Tan);
- fIntrinsicMap["asin"] = ALL_GLSL(Asin);
- fIntrinsicMap["acos"] = ALL_GLSL(Acos);
- fIntrinsicMap["atan"] = SPECIAL(Atan);
- fIntrinsicMap["sinh"] = ALL_GLSL(Sinh);
- fIntrinsicMap["cosh"] = ALL_GLSL(Cosh);
- fIntrinsicMap["tanh"] = ALL_GLSL(Tanh);
- fIntrinsicMap["asinh"] = ALL_GLSL(Asinh);
- fIntrinsicMap["acosh"] = ALL_GLSL(Acosh);
- fIntrinsicMap["atanh"] = ALL_GLSL(Atanh);
- fIntrinsicMap["pow"] = ALL_GLSL(Pow);
- fIntrinsicMap["exp"] = ALL_GLSL(Exp);
- fIntrinsicMap["log"] = ALL_GLSL(Log);
- fIntrinsicMap["exp2"] = ALL_GLSL(Exp2);
- fIntrinsicMap["log2"] = ALL_GLSL(Log2);
- fIntrinsicMap["sqrt"] = ALL_GLSL(Sqrt);
- fIntrinsicMap["inversesqrt"] = ALL_GLSL(InverseSqrt);
- fIntrinsicMap["determinant"] = ALL_GLSL(Determinant);
- fIntrinsicMap["matrixInverse"] = ALL_GLSL(MatrixInverse);
- fIntrinsicMap["mod"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpFMod, SpvOpSMod,
- SpvOpUMod, SpvOpUndef);
- fIntrinsicMap["min"] = BY_TYPE_GLSL(FMin, SMin, UMin);
- fIntrinsicMap["max"] = BY_TYPE_GLSL(FMax, SMax, UMax);
- fIntrinsicMap["clamp"] = BY_TYPE_GLSL(FClamp, SClamp, UClamp);
- fIntrinsicMap["dot"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDot, SpvOpUndef,
- SpvOpUndef, SpvOpUndef);
- fIntrinsicMap["mix"] = ALL_GLSL(FMix);
- fIntrinsicMap["step"] = ALL_GLSL(Step);
- fIntrinsicMap["smoothstep"] = ALL_GLSL(SmoothStep);
- fIntrinsicMap["fma"] = ALL_GLSL(Fma);
- fIntrinsicMap["frexp"] = ALL_GLSL(Frexp);
- fIntrinsicMap["ldexp"] = ALL_GLSL(Ldexp);
-
-#define PACK(type) fIntrinsicMap["pack" #type] = ALL_GLSL(Pack ## type); \
- fIntrinsicMap["unpack" #type] = ALL_GLSL(Unpack ## type)
+ fIntrinsicMap[SkString("round")] = ALL_GLSL(Round);
+ fIntrinsicMap[SkString("roundEven")] = ALL_GLSL(RoundEven);
+ fIntrinsicMap[SkString("trunc")] = ALL_GLSL(Trunc);
+ fIntrinsicMap[SkString("abs")] = BY_TYPE_GLSL(FAbs, SAbs, SAbs);
+ fIntrinsicMap[SkString("sign")] = BY_TYPE_GLSL(FSign, SSign, SSign);
+ fIntrinsicMap[SkString("floor")] = ALL_GLSL(Floor);
+ fIntrinsicMap[SkString("ceil")] = ALL_GLSL(Ceil);
+ fIntrinsicMap[SkString("fract")] = ALL_GLSL(Fract);
+ fIntrinsicMap[SkString("radians")] = ALL_GLSL(Radians);
+ fIntrinsicMap[SkString("degrees")] = ALL_GLSL(Degrees);
+ fIntrinsicMap[SkString("sin")] = ALL_GLSL(Sin);
+ fIntrinsicMap[SkString("cos")] = ALL_GLSL(Cos);
+ fIntrinsicMap[SkString("tan")] = ALL_GLSL(Tan);
+ fIntrinsicMap[SkString("asin")] = ALL_GLSL(Asin);
+ fIntrinsicMap[SkString("acos")] = ALL_GLSL(Acos);
+ fIntrinsicMap[SkString("atan")] = SPECIAL(Atan);
+ fIntrinsicMap[SkString("sinh")] = ALL_GLSL(Sinh);
+ fIntrinsicMap[SkString("cosh")] = ALL_GLSL(Cosh);
+ fIntrinsicMap[SkString("tanh")] = ALL_GLSL(Tanh);
+ fIntrinsicMap[SkString("asinh")] = ALL_GLSL(Asinh);
+ fIntrinsicMap[SkString("acosh")] = ALL_GLSL(Acosh);
+ fIntrinsicMap[SkString("atanh")] = ALL_GLSL(Atanh);
+ fIntrinsicMap[SkString("pow")] = ALL_GLSL(Pow);
+ fIntrinsicMap[SkString("exp")] = ALL_GLSL(Exp);
+ fIntrinsicMap[SkString("log")] = ALL_GLSL(Log);
+ fIntrinsicMap[SkString("exp2")] = ALL_GLSL(Exp2);
+ fIntrinsicMap[SkString("log2")] = ALL_GLSL(Log2);
+ fIntrinsicMap[SkString("sqrt")] = ALL_GLSL(Sqrt);
+ fIntrinsicMap[SkString("inversesqrt")] = ALL_GLSL(InverseSqrt);
+ fIntrinsicMap[SkString("determinant")] = ALL_GLSL(Determinant);
+ fIntrinsicMap[SkString("matrixInverse")] = ALL_GLSL(MatrixInverse);
+ fIntrinsicMap[SkString("mod")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpFMod,
+ SpvOpSMod, SpvOpUMod, SpvOpUndef);
+ fIntrinsicMap[SkString("min")] = BY_TYPE_GLSL(FMin, SMin, UMin);
+ fIntrinsicMap[SkString("max")] = BY_TYPE_GLSL(FMax, SMax, UMax);
+ fIntrinsicMap[SkString("clamp")] = BY_TYPE_GLSL(FClamp, SClamp, UClamp);
+ fIntrinsicMap[SkString("dot")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDot,
+ SpvOpUndef, SpvOpUndef, SpvOpUndef);
+ fIntrinsicMap[SkString("mix")] = ALL_GLSL(FMix);
+ fIntrinsicMap[SkString("step")] = ALL_GLSL(Step);
+ fIntrinsicMap[SkString("smoothstep")] = ALL_GLSL(SmoothStep);
+ fIntrinsicMap[SkString("fma")] = ALL_GLSL(Fma);
+ fIntrinsicMap[SkString("frexp")] = ALL_GLSL(Frexp);
+ fIntrinsicMap[SkString("ldexp")] = ALL_GLSL(Ldexp);
+
+#define PACK(type) fIntrinsicMap[SkString("pack" #type)] = ALL_GLSL(Pack ## type); \
+ fIntrinsicMap[SkString("unpack" #type)] = ALL_GLSL(Unpack ## type)
PACK(Snorm4x8);
PACK(Unorm4x8);
PACK(Snorm2x16);
PACK(Unorm2x16);
PACK(Half2x16);
PACK(Double2x32);
- fIntrinsicMap["length"] = ALL_GLSL(Length);
- fIntrinsicMap["distance"] = ALL_GLSL(Distance);
- fIntrinsicMap["cross"] = ALL_GLSL(Cross);
- fIntrinsicMap["normalize"] = ALL_GLSL(Normalize);
- fIntrinsicMap["faceForward"] = ALL_GLSL(FaceForward);
- fIntrinsicMap["reflect"] = ALL_GLSL(Reflect);
- fIntrinsicMap["refract"] = ALL_GLSL(Refract);
- fIntrinsicMap["findLSB"] = ALL_GLSL(FindILsb);
- fIntrinsicMap["findMSB"] = BY_TYPE_GLSL(FindSMsb, FindSMsb, FindUMsb);
- fIntrinsicMap["dFdx"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdx, SpvOpUndef,
- SpvOpUndef, SpvOpUndef);
- fIntrinsicMap["dFdy"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdy, SpvOpUndef,
- SpvOpUndef, SpvOpUndef);
- fIntrinsicMap["dFdy"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdy, SpvOpUndef,
- SpvOpUndef, SpvOpUndef);
- fIntrinsicMap["texture"] = SPECIAL(Texture);
- fIntrinsicMap["texture2D"] = SPECIAL(Texture2D);
- fIntrinsicMap["textureProj"] = SPECIAL(TextureProj);
-
- fIntrinsicMap["any"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpUndef,
- SpvOpUndef, SpvOpUndef, SpvOpAny);
- fIntrinsicMap["all"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpUndef,
- SpvOpUndef, SpvOpUndef, SpvOpAll);
- fIntrinsicMap["equal"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpFOrdEqual,
- SpvOpIEqual, SpvOpIEqual,
- SpvOpLogicalEqual);
- fIntrinsicMap["notEqual"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpFOrdNotEqual,
- SpvOpINotEqual, SpvOpINotEqual,
- SpvOpLogicalNotEqual);
- fIntrinsicMap["lessThan"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpSLessThan,
- SpvOpULessThan, SpvOpFOrdLessThan,
- SpvOpUndef);
- fIntrinsicMap["lessThanEqual"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpSLessThanEqual,
- SpvOpULessThanEqual, SpvOpFOrdLessThanEqual,
- SpvOpUndef);
- fIntrinsicMap["greaterThan"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpSGreaterThan,
- SpvOpUGreaterThan, SpvOpFOrdGreaterThan,
- SpvOpUndef);
- fIntrinsicMap["greaterThanEqual"] = std::make_tuple(kSPIRV_IntrinsicKind,
- SpvOpSGreaterThanEqual,
- SpvOpUGreaterThanEqual,
- SpvOpFOrdGreaterThanEqual,
- SpvOpUndef);
+ fIntrinsicMap[SkString("length")] = ALL_GLSL(Length);
+ fIntrinsicMap[SkString("distance")] = ALL_GLSL(Distance);
+ fIntrinsicMap[SkString("cross")] = ALL_GLSL(Cross);
+ fIntrinsicMap[SkString("normalize")] = ALL_GLSL(Normalize);
+ fIntrinsicMap[SkString("faceForward")] = ALL_GLSL(FaceForward);
+ fIntrinsicMap[SkString("reflect")] = ALL_GLSL(Reflect);
+ fIntrinsicMap[SkString("refract")] = ALL_GLSL(Refract);
+ fIntrinsicMap[SkString("findLSB")] = ALL_GLSL(FindILsb);
+ fIntrinsicMap[SkString("findMSB")] = BY_TYPE_GLSL(FindSMsb, FindSMsb, FindUMsb);
+ fIntrinsicMap[SkString("dFdx")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdx,
+ SpvOpUndef, SpvOpUndef, SpvOpUndef);
+ fIntrinsicMap[SkString("dFdy")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdy,
+ SpvOpUndef, SpvOpUndef, SpvOpUndef);
+ fIntrinsicMap[SkString("dFdy")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdy,
+ SpvOpUndef, SpvOpUndef, SpvOpUndef);
+ fIntrinsicMap[SkString("texture")] = SPECIAL(Texture);
+ fIntrinsicMap[SkString("texture2D")] = SPECIAL(Texture2D);
+ fIntrinsicMap[SkString("textureProj")] = SPECIAL(TextureProj);
+
+ fIntrinsicMap[SkString("any")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpUndef,
+ SpvOpUndef, SpvOpUndef, SpvOpAny);
+ fIntrinsicMap[SkString("all")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpUndef,
+ SpvOpUndef, SpvOpUndef, SpvOpAll);
+ fIntrinsicMap[SkString("equal")] = std::make_tuple(kSPIRV_IntrinsicKind,
+ SpvOpFOrdEqual, SpvOpIEqual,
+ SpvOpIEqual, SpvOpLogicalEqual);
+ fIntrinsicMap[SkString("notEqual")] = std::make_tuple(kSPIRV_IntrinsicKind,
+ SpvOpFOrdNotEqual, SpvOpINotEqual,
+ SpvOpINotEqual,
+ SpvOpLogicalNotEqual);
+ fIntrinsicMap[SkString("lessThan")] = std::make_tuple(kSPIRV_IntrinsicKind,
+ SpvOpSLessThan, SpvOpULessThan,
+ SpvOpFOrdLessThan, SpvOpUndef);
+ fIntrinsicMap[SkString("lessThanEqual")] = std::make_tuple(kSPIRV_IntrinsicKind,
+ SpvOpSLessThanEqual,
+ SpvOpULessThanEqual,
+ SpvOpFOrdLessThanEqual,
+ SpvOpUndef);
+ fIntrinsicMap[SkString("greaterThan")] = std::make_tuple(kSPIRV_IntrinsicKind,
+ SpvOpSGreaterThan,
+ SpvOpUGreaterThan,
+ SpvOpFOrdGreaterThan,
+ SpvOpUndef);
+ fIntrinsicMap[SkString("greaterThanEqual")] = std::make_tuple(kSPIRV_IntrinsicKind,
+ SpvOpSGreaterThanEqual,
+ SpvOpUGreaterThanEqual,
+ SpvOpFOrdGreaterThanEqual,
+ SpvOpUndef);
// interpolateAt* not yet supported...
}
-void SPIRVCodeGenerator::writeWord(int32_t word, std::ostream& out) {
+void SPIRVCodeGenerator::writeWord(int32_t word, SkWStream& out) {
#if SPIRV_DEBUG
out << "(" << word << ") ";
#else
}
#if SPIRV_DEBUG
-static std::string opcode_text(SpvOp_ opCode) {
+static SkString opcode_text(SpvOp_ opCode) {
switch (opCode) {
case SpvOpNop:
- return "Nop";
+ return SkString("Nop");
case SpvOpUndef:
- return "Undef";
+ return SkString("Undef");
case SpvOpSourceContinued:
- return "SourceContinued";
+ return SkString("SourceContinued");
case SpvOpSource:
- return "Source";
+ return SkString("Source");
case SpvOpSourceExtension:
- return "SourceExtension";
+ return SkString("SourceExtension");
case SpvOpName:
- return "Name";
+ return SkString("Name");
case SpvOpMemberName:
- return "MemberName";
+ return SkString("MemberName");
case SpvOpString:
- return "String";
+ return SkString("String");
case SpvOpLine:
- return "Line";
+ return SkString("Line");
case SpvOpExtension:
- return "Extension";
+ return SkString("Extension");
case SpvOpExtInstImport:
- return "ExtInstImport";
+ return SkString("ExtInstImport");
case SpvOpExtInst:
- return "ExtInst";
+ return SkString("ExtInst");
case SpvOpMemoryModel:
- return "MemoryModel";
+ return SkString("MemoryModel");
case SpvOpEntryPoint:
- return "EntryPoint";
+ return SkString("EntryPoint");
case SpvOpExecutionMode:
- return "ExecutionMode";
+ return SkString("ExecutionMode");
case SpvOpCapability:
- return "Capability";
+ return SkString("Capability");
case SpvOpTypeVoid:
- return "TypeVoid";
+ return SkString("TypeVoid");
case SpvOpTypeBool:
- return "TypeBool";
+ return SkString("TypeBool");
case SpvOpTypeInt:
- return "TypeInt";
+ return SkString("TypeInt");
case SpvOpTypeFloat:
- return "TypeFloat";
+ return SkString("TypeFloat");
case SpvOpTypeVector:
- return "TypeVector";
+ return SkString("TypeVector");
case SpvOpTypeMatrix:
- return "TypeMatrix";
+ return SkString("TypeMatrix");
case SpvOpTypeImage:
- return "TypeImage";
+ return SkString("TypeImage");
case SpvOpTypeSampler:
- return "TypeSampler";
+ return SkString("TypeSampler");
case SpvOpTypeSampledImage:
- return "TypeSampledImage";
+ return SkString("TypeSampledImage");
case SpvOpTypeArray:
- return "TypeArray";
+ return SkString("TypeArray");
case SpvOpTypeRuntimeArray:
- return "TypeRuntimeArray";
+ return SkString("TypeRuntimeArray");
case SpvOpTypeStruct:
- return "TypeStruct";
+ return SkString("TypeStruct");
case SpvOpTypeOpaque:
- return "TypeOpaque";
+ return SkString("TypeOpaque");
case SpvOpTypePointer:
- return "TypePointer";
+ return SkString("TypePointer");
case SpvOpTypeFunction:
- return "TypeFunction";
+ return SkString("TypeFunction");
case SpvOpTypeEvent:
- return "TypeEvent";
+ return SkString("TypeEvent");
case SpvOpTypeDeviceEvent:
- return "TypeDeviceEvent";
+ return SkString("TypeDeviceEvent");
case SpvOpTypeReserveId:
- return "TypeReserveId";
+ return SkString("TypeReserveId");
case SpvOpTypeQueue:
- return "TypeQueue";
+ return SkString("TypeQueue");
case SpvOpTypePipe:
- return "TypePipe";
+ return SkString("TypePipe");
case SpvOpTypeForwardPointer:
- return "TypeForwardPointer";
+ return SkString("TypeForwardPointer");
case SpvOpConstantTrue:
- return "ConstantTrue";
+ return SkString("ConstantTrue");
case SpvOpConstantFalse:
- return "ConstantFalse";
+ return SkString("ConstantFalse");
case SpvOpConstant:
- return "Constant";
+ return SkString("Constant");
case SpvOpConstantComposite:
- return "ConstantComposite";
+ return SkString("ConstantComposite");
case SpvOpConstantSampler:
- return "ConstantSampler";
+ return SkString("ConstantSampler");
case SpvOpConstantNull:
- return "ConstantNull";
+ return SkString("ConstantNull");
case SpvOpSpecConstantTrue:
- return "SpecConstantTrue";
+ return SkString("SpecConstantTrue");
case SpvOpSpecConstantFalse:
- return "SpecConstantFalse";
+ return SkString("SpecConstantFalse");
case SpvOpSpecConstant:
- return "SpecConstant";
+ return SkString("SpecConstant");
case SpvOpSpecConstantComposite:
- return "SpecConstantComposite";
+ return SkString("SpecConstantComposite");
case SpvOpSpecConstantOp:
- return "SpecConstantOp";
+ return SkString("SpecConstantOp");
case SpvOpFunction:
- return "Function";
+ return SkString("Function");
case SpvOpFunctionParameter:
- return "FunctionParameter";
+ return SkString("FunctionParameter");
case SpvOpFunctionEnd:
- return "FunctionEnd";
+ return SkString("FunctionEnd");
case SpvOpFunctionCall:
- return "FunctionCall";
+ return SkString("FunctionCall");
case SpvOpVariable:
- return "Variable";
+ return SkString("Variable");
case SpvOpImageTexelPointer:
- return "ImageTexelPointer";
+ return SkString("ImageTexelPointer");
case SpvOpLoad:
- return "Load";
+ return SkString("Load");
case SpvOpStore:
- return "Store";
+ return SkString("Store");
case SpvOpCopyMemory:
- return "CopyMemory";
+ return SkString("CopyMemory");
case SpvOpCopyMemorySized:
- return "CopyMemorySized";
+ return SkString("CopyMemorySized");
case SpvOpAccessChain:
- return "AccessChain";
+ return SkString("AccessChain");
case SpvOpInBoundsAccessChain:
- return "InBoundsAccessChain";
+ return SkString("InBoundsAccessChain");
case SpvOpPtrAccessChain:
- return "PtrAccessChain";
+ return SkString("PtrAccessChain");
case SpvOpArrayLength:
- return "ArrayLength";
+ return SkString("ArrayLength");
case SpvOpGenericPtrMemSemantics:
- return "GenericPtrMemSemantics";
+ return SkString("GenericPtrMemSemantics");
case SpvOpInBoundsPtrAccessChain:
- return "InBoundsPtrAccessChain";
+ return SkString("InBoundsPtrAccessChain");
case SpvOpDecorate:
- return "Decorate";
+ return SkString("Decorate");
case SpvOpMemberDecorate:
- return "MemberDecorate";
+ return SkString("MemberDecorate");
case SpvOpDecorationGroup:
- return "DecorationGroup";
+ return SkString("DecorationGroup");
case SpvOpGroupDecorate:
- return "GroupDecorate";
+ return SkString("GroupDecorate");
case SpvOpGroupMemberDecorate:
- return "GroupMemberDecorate";
+ return SkString("GroupMemberDecorate");
case SpvOpVectorExtractDynamic:
- return "VectorExtractDynamic";
+ return SkString("VectorExtractDynamic");
case SpvOpVectorInsertDynamic:
- return "VectorInsertDynamic";
+ return SkString("VectorInsertDynamic");
case SpvOpVectorShuffle:
- return "VectorShuffle";
+ return SkString("VectorShuffle");
case SpvOpCompositeConstruct:
- return "CompositeConstruct";
+ return SkString("CompositeConstruct");
case SpvOpCompositeExtract:
- return "CompositeExtract";
+ return SkString("CompositeExtract");
case SpvOpCompositeInsert:
- return "CompositeInsert";
+ return SkString("CompositeInsert");
case SpvOpCopyObject:
- return "CopyObject";
+ return SkString("CopyObject");
case SpvOpTranspose:
- return "Transpose";
+ return SkString("Transpose");
case SpvOpSampledImage:
- return "SampledImage";
+ return SkString("SampledImage");
case SpvOpImageSampleImplicitLod:
- return "ImageSampleImplicitLod";
+ return SkString("ImageSampleImplicitLod");
case SpvOpImageSampleExplicitLod:
- return "ImageSampleExplicitLod";
+ return SkString("ImageSampleExplicitLod");
case SpvOpImageSampleDrefImplicitLod:
- return "ImageSampleDrefImplicitLod";
+ return SkString("ImageSampleDrefImplicitLod");
case SpvOpImageSampleDrefExplicitLod:
- return "ImageSampleDrefExplicitLod";
+ return SkString("ImageSampleDrefExplicitLod");
case SpvOpImageSampleProjImplicitLod:
- return "ImageSampleProjImplicitLod";
+ return SkString("ImageSampleProjImplicitLod");
case SpvOpImageSampleProjExplicitLod:
- return "ImageSampleProjExplicitLod";
+ return SkString("ImageSampleProjExplicitLod");
case SpvOpImageSampleProjDrefImplicitLod:
- return "ImageSampleProjDrefImplicitLod";
+ return SkString("ImageSampleProjDrefImplicitLod");
case SpvOpImageSampleProjDrefExplicitLod:
- return "ImageSampleProjDrefExplicitLod";
+ return SkString("ImageSampleProjDrefExplicitLod");
case SpvOpImageFetch:
- return "ImageFetch";
+ return SkString("ImageFetch");
case SpvOpImageGather:
- return "ImageGather";
+ return SkString("ImageGather");
case SpvOpImageDrefGather:
- return "ImageDrefGather";
+ return SkString("ImageDrefGather");
case SpvOpImageRead:
- return "ImageRead";
+ return SkString("ImageRead");
case SpvOpImageWrite:
- return "ImageWrite";
+ return SkString("ImageWrite");
case SpvOpImage:
- return "Image";
+ return SkString("Image");
case SpvOpImageQueryFormat:
- return "ImageQueryFormat";
+ return SkString("ImageQueryFormat");
case SpvOpImageQueryOrder:
- return "ImageQueryOrder";
+ return SkString("ImageQueryOrder");
case SpvOpImageQuerySizeLod:
- return "ImageQuerySizeLod";
+ return SkString("ImageQuerySizeLod");
case SpvOpImageQuerySize:
- return "ImageQuerySize";
+ return SkString("ImageQuerySize");
case SpvOpImageQueryLod:
- return "ImageQueryLod";
+ return SkString("ImageQueryLod");
case SpvOpImageQueryLevels:
- return "ImageQueryLevels";
+ return SkString("ImageQueryLevels");
case SpvOpImageQuerySamples:
- return "ImageQuerySamples";
+ return SkString("ImageQuerySamples");
case SpvOpConvertFToU:
- return "ConvertFToU";
+ return SkString("ConvertFToU");
case SpvOpConvertFToS:
- return "ConvertFToS";
+ return SkString("ConvertFToS");
case SpvOpConvertSToF:
- return "ConvertSToF";
+ return SkString("ConvertSToF");
case SpvOpConvertUToF:
- return "ConvertUToF";
+ return SkString("ConvertUToF");
case SpvOpUConvert:
- return "UConvert";
+ return SkString("UConvert");
case SpvOpSConvert:
- return "SConvert";
+ return SkString("SConvert");
case SpvOpFConvert:
- return "FConvert";
+ return SkString("FConvert");
case SpvOpQuantizeToF16:
- return "QuantizeToF16";
+ return SkString("QuantizeToF16");
case SpvOpConvertPtrToU:
- return "ConvertPtrToU";
+ return SkString("ConvertPtrToU");
case SpvOpSatConvertSToU:
- return "SatConvertSToU";
+ return SkString("SatConvertSToU");
case SpvOpSatConvertUToS:
- return "SatConvertUToS";
+ return SkString("SatConvertUToS");
case SpvOpConvertUToPtr:
- return "ConvertUToPtr";
+ return SkString("ConvertUToPtr");
case SpvOpPtrCastToGeneric:
- return "PtrCastToGeneric";
+ return SkString("PtrCastToGeneric");
case SpvOpGenericCastToPtr:
- return "GenericCastToPtr";
+ return SkString("GenericCastToPtr");
case SpvOpGenericCastToPtrExplicit:
- return "GenericCastToPtrExplicit";
+ return SkString("GenericCastToPtrExplicit");
case SpvOpBitcast:
- return "Bitcast";
+ return SkString("Bitcast");
case SpvOpSNegate:
- return "SNegate";
+ return SkString("SNegate");
case SpvOpFNegate:
- return "FNegate";
+ return SkString("FNegate");
case SpvOpIAdd:
- return "IAdd";
+ return SkString("IAdd");
case SpvOpFAdd:
- return "FAdd";
+ return SkString("FAdd");
case SpvOpISub:
- return "ISub";
+ return SkString("ISub");
case SpvOpFSub:
- return "FSub";
+ return SkString("FSub");
case SpvOpIMul:
- return "IMul";
+ return SkString("IMul");
case SpvOpFMul:
- return "FMul";
+ return SkString("FMul");
case SpvOpUDiv:
- return "UDiv";
+ return SkString("UDiv");
case SpvOpSDiv:
- return "SDiv";
+ return SkString("SDiv");
case SpvOpFDiv:
- return "FDiv";
+ return SkString("FDiv");
case SpvOpUMod:
- return "UMod";
+ return SkString("UMod");
case SpvOpSRem:
- return "SRem";
+ return SkString("SRem");
case SpvOpSMod:
- return "SMod";
+ return SkString("SMod");
case SpvOpFRem:
- return "FRem";
+ return SkString("FRem");
case SpvOpFMod:
- return "FMod";
+ return SkString("FMod");
case SpvOpVectorTimesScalar:
- return "VectorTimesScalar";
+ return SkString("VectorTimesScalar");
case SpvOpMatrixTimesScalar:
- return "MatrixTimesScalar";
+ return SkString("MatrixTimesScalar");
case SpvOpVectorTimesMatrix:
- return "VectorTimesMatrix";
+ return SkString("VectorTimesMatrix");
case SpvOpMatrixTimesVector:
- return "MatrixTimesVector";
+ return SkString("MatrixTimesVector");
case SpvOpMatrixTimesMatrix:
- return "MatrixTimesMatrix";
+ return SkString("MatrixTimesMatrix");
case SpvOpOuterProduct:
- return "OuterProduct";
+ return SkString("OuterProduct");
case SpvOpDot:
- return "Dot";
+ return SkString("Dot");
case SpvOpIAddCarry:
- return "IAddCarry";
+ return SkString("IAddCarry");
case SpvOpISubBorrow:
- return "ISubBorrow";
+ return SkString("ISubBorrow");
case SpvOpUMulExtended:
- return "UMulExtended";
+ return SkString("UMulExtended");
case SpvOpSMulExtended:
- return "SMulExtended";
+ return SkString("SMulExtended");
case SpvOpAny:
- return "Any";
+ return SkString("Any");
case SpvOpAll:
- return "All";
+ return SkString("All");
case SpvOpIsNan:
- return "IsNan";
+ return SkString("IsNan");
case SpvOpIsInf:
- return "IsInf";
+ return SkString("IsInf");
case SpvOpIsFinite:
- return "IsFinite";
+ return SkString("IsFinite");
case SpvOpIsNormal:
- return "IsNormal";
+ return SkString("IsNormal");
case SpvOpSignBitSet:
- return "SignBitSet";
+ return SkString("SignBitSet");
case SpvOpLessOrGreater:
- return "LessOrGreater";
+ return SkString("LessOrGreater");
case SpvOpOrdered:
- return "Ordered";
+ return SkString("Ordered");
case SpvOpUnordered:
- return "Unordered";
+ return SkString("Unordered");
case SpvOpLogicalEqual:
- return "LogicalEqual";
+ return SkString("LogicalEqual");
case SpvOpLogicalNotEqual:
- return "LogicalNotEqual";
+ return SkString("LogicalNotEqual");
case SpvOpLogicalOr:
- return "LogicalOr";
+ return SkString("LogicalOr");
case SpvOpLogicalAnd:
- return "LogicalAnd";
+ return SkString("LogicalAnd");
case SpvOpLogicalNot:
- return "LogicalNot";
+ return SkString("LogicalNot");
case SpvOpSelect:
- return "Select";
+ return SkString("Select");
case SpvOpIEqual:
- return "IEqual";
+ return SkString("IEqual");
case SpvOpINotEqual:
- return "INotEqual";
+ return SkString("INotEqual");
case SpvOpUGreaterThan:
- return "UGreaterThan";
+ return SkString("UGreaterThan");
case SpvOpSGreaterThan:
- return "SGreaterThan";
+ return SkString("SGreaterThan");
case SpvOpUGreaterThanEqual:
- return "UGreaterThanEqual";
+ return SkString("UGreaterThanEqual");
case SpvOpSGreaterThanEqual:
- return "SGreaterThanEqual";
+ return SkString("SGreaterThanEqual");
case SpvOpULessThan:
- return "ULessThan";
+ return SkString("ULessThan");
case SpvOpSLessThan:
- return "SLessThan";
+ return SkString("SLessThan");
case SpvOpULessThanEqual:
- return "ULessThanEqual";
+ return SkString("ULessThanEqual");
case SpvOpSLessThanEqual:
- return "SLessThanEqual";
+ return SkString("SLessThanEqual");
case SpvOpFOrdEqual:
- return "FOrdEqual";
+ return SkString("FOrdEqual");
case SpvOpFUnordEqual:
- return "FUnordEqual";
+ return SkString("FUnordEqual");
case SpvOpFOrdNotEqual:
- return "FOrdNotEqual";
+ return SkString("FOrdNotEqual");
case SpvOpFUnordNotEqual:
- return "FUnordNotEqual";
+ return SkString("FUnordNotEqual");
case SpvOpFOrdLessThan:
- return "FOrdLessThan";
+ return SkString("FOrdLessThan");
case SpvOpFUnordLessThan:
- return "FUnordLessThan";
+ return SkString("FUnordLessThan");
case SpvOpFOrdGreaterThan:
- return "FOrdGreaterThan";
+ return SkString("FOrdGreaterThan");
case SpvOpFUnordGreaterThan:
- return "FUnordGreaterThan";
+ return SkString("FUnordGreaterThan");
case SpvOpFOrdLessThanEqual:
- return "FOrdLessThanEqual";
+ return SkString("FOrdLessThanEqual");
case SpvOpFUnordLessThanEqual:
- return "FUnordLessThanEqual";
+ return SkString("FUnordLessThanEqual");
case SpvOpFOrdGreaterThanEqual:
- return "FOrdGreaterThanEqual";
+ return SkString("FOrdGreaterThanEqual");
case SpvOpFUnordGreaterThanEqual:
- return "FUnordGreaterThanEqual";
+ return SkString("FUnordGreaterThanEqual");
case SpvOpShiftRightLogical:
- return "ShiftRightLogical";
+ return SkString("ShiftRightLogical");
case SpvOpShiftRightArithmetic:
- return "ShiftRightArithmetic";
+ return SkString("ShiftRightArithmetic");
case SpvOpShiftLeftLogical:
- return "ShiftLeftLogical";
+ return SkString("ShiftLeftLogical");
case SpvOpBitwiseOr:
- return "BitwiseOr";
+ return SkString("BitwiseOr");
case SpvOpBitwiseXor:
- return "BitwiseXor";
+ return SkString("BitwiseXor");
case SpvOpBitwiseAnd:
- return "BitwiseAnd";
+ return SkString("BitwiseAnd");
case SpvOpNot:
- return "Not";
+ return SkString("Not");
case SpvOpBitFieldInsert:
- return "BitFieldInsert";
+ return SkString("BitFieldInsert");
case SpvOpBitFieldSExtract:
- return "BitFieldSExtract";
+ return SkString("BitFieldSExtract");
case SpvOpBitFieldUExtract:
- return "BitFieldUExtract";
+ return SkString("BitFieldUExtract");
case SpvOpBitReverse:
- return "BitReverse";
+ return SkString("BitReverse");
case SpvOpBitCount:
- return "BitCount";
+ return SkString("BitCount");
case SpvOpDPdx:
- return "DPdx";
+ return SkString("DPdx");
case SpvOpDPdy:
- return "DPdy";
+ return SkString("DPdy");
case SpvOpFwidth:
- return "Fwidth";
+ return SkString("Fwidth");
case SpvOpDPdxFine:
- return "DPdxFine";
+ return SkString("DPdxFine");
case SpvOpDPdyFine:
- return "DPdyFine";
+ return SkString("DPdyFine");
case SpvOpFwidthFine:
- return "FwidthFine";
+ return SkString("FwidthFine");
case SpvOpDPdxCoarse:
- return "DPdxCoarse";
+ return SkString("DPdxCoarse");
case SpvOpDPdyCoarse:
- return "DPdyCoarse";
+ return SkString("DPdyCoarse");
case SpvOpFwidthCoarse:
- return "FwidthCoarse";
+ return SkString("FwidthCoarse");
case SpvOpEmitVertex:
- return "EmitVertex";
+ return SkString("EmitVertex");
case SpvOpEndPrimitive:
- return "EndPrimitive";
+ return SkString("EndPrimitive");
case SpvOpEmitStreamVertex:
- return "EmitStreamVertex";
+ return SkString("EmitStreamVertex");
case SpvOpEndStreamPrimitive:
- return "EndStreamPrimitive";
+ return SkString("EndStreamPrimitive");
case SpvOpControlBarrier:
- return "ControlBarrier";
+ return SkString("ControlBarrier");
case SpvOpMemoryBarrier:
- return "MemoryBarrier";
+ return SkString("MemoryBarrier");
case SpvOpAtomicLoad:
- return "AtomicLoad";
+ return SkString("AtomicLoad");
case SpvOpAtomicStore:
- return "AtomicStore";
+ return SkString("AtomicStore");
case SpvOpAtomicExchange:
- return "AtomicExchange";
+ return SkString("AtomicExchange");
case SpvOpAtomicCompareExchange:
- return "AtomicCompareExchange";
+ return SkString("AtomicCompareExchange");
case SpvOpAtomicCompareExchangeWeak:
- return "AtomicCompareExchangeWeak";
+ return SkString("AtomicCompareExchangeWeak");
case SpvOpAtomicIIncrement:
- return "AtomicIIncrement";
+ return SkString("AtomicIIncrement");
case SpvOpAtomicIDecrement:
- return "AtomicIDecrement";
+ return SkString("AtomicIDecrement");
case SpvOpAtomicIAdd:
- return "AtomicIAdd";
+ return SkString("AtomicIAdd");
case SpvOpAtomicISub:
- return "AtomicISub";
+ return SkString("AtomicISub");
case SpvOpAtomicSMin:
- return "AtomicSMin";
+ return SkString("AtomicSMin");
case SpvOpAtomicUMin:
- return "AtomicUMin";
+ return SkString("AtomicUMin");
case SpvOpAtomicSMax:
- return "AtomicSMax";
+ return SkString("AtomicSMax");
case SpvOpAtomicUMax:
- return "AtomicUMax";
+ return SkString("AtomicUMax");
case SpvOpAtomicAnd:
- return "AtomicAnd";
+ return SkString("AtomicAnd");
case SpvOpAtomicOr:
- return "AtomicOr";
+ return SkString("AtomicOr");
case SpvOpAtomicXor:
- return "AtomicXor";
+ return SkString("AtomicXor");
case SpvOpPhi:
- return "Phi";
+ return SkString("Phi");
case SpvOpLoopMerge:
- return "LoopMerge";
+ return SkString("LoopMerge");
case SpvOpSelectionMerge:
- return "SelectionMerge";
+ return SkString("SelectionMerge");
case SpvOpLabel:
- return "Label";
+ return SkString("Label");
case SpvOpBranch:
- return "Branch";
+ return SkString("Branch");
case SpvOpBranchConditional:
- return "BranchConditional";
+ return SkString("BranchConditional");
case SpvOpSwitch:
- return "Switch";
+ return SkString("Switch");
case SpvOpKill:
- return "Kill";
+ return SkString("Kill");
case SpvOpReturn:
- return "Return";
+ return SkString("Return");
case SpvOpReturnValue:
- return "ReturnValue";
+ return SkString("ReturnValue");
case SpvOpUnreachable:
- return "Unreachable";
+ return SkString("Unreachable");
case SpvOpLifetimeStart:
- return "LifetimeStart";
+ return SkString("LifetimeStart");
case SpvOpLifetimeStop:
- return "LifetimeStop";
+ return SkString("LifetimeStop");
case SpvOpGroupAsyncCopy:
- return "GroupAsyncCopy";
+ return SkString("GroupAsyncCopy");
case SpvOpGroupWaitEvents:
- return "GroupWaitEvents";
+ return SkString("GroupWaitEvents");
case SpvOpGroupAll:
- return "GroupAll";
+ return SkString("GroupAll");
case SpvOpGroupAny:
- return "GroupAny";
+ return SkString("GroupAny");
case SpvOpGroupBroadcast:
- return "GroupBroadcast";
+ return SkString("GroupBroadcast");
case SpvOpGroupIAdd:
- return "GroupIAdd";
+ return SkString("GroupIAdd");
case SpvOpGroupFAdd:
- return "GroupFAdd";
+ return SkString("GroupFAdd");
case SpvOpGroupFMin:
- return "GroupFMin";
+ return SkString("GroupFMin");
case SpvOpGroupUMin:
- return "GroupUMin";
+ return SkString("GroupUMin");
case SpvOpGroupSMin:
- return "GroupSMin";
+ return SkString("GroupSMin");
case SpvOpGroupFMax:
- return "GroupFMax";
+ return SkString("GroupFMax");
case SpvOpGroupUMax:
- return "GroupUMax";
+ return SkString("GroupUMax");
case SpvOpGroupSMax:
- return "GroupSMax";
+ return SkString("GroupSMax");
case SpvOpReadPipe:
- return "ReadPipe";
+ return SkString("ReadPipe");
case SpvOpWritePipe:
- return "WritePipe";
+ return SkString("WritePipe");
case SpvOpReservedReadPipe:
- return "ReservedReadPipe";
+ return SkString("ReservedReadPipe");
case SpvOpReservedWritePipe:
- return "ReservedWritePipe";
+ return SkString("ReservedWritePipe");
case SpvOpReserveReadPipePackets:
- return "ReserveReadPipePackets";
+ return SkString("ReserveReadPipePackets");
case SpvOpReserveWritePipePackets:
- return "ReserveWritePipePackets";
+ return SkString("ReserveWritePipePackets");
case SpvOpCommitReadPipe:
- return "CommitReadPipe";
+ return SkString("CommitReadPipe");
case SpvOpCommitWritePipe:
- return "CommitWritePipe";
+ return SkString("CommitWritePipe");
case SpvOpIsValidReserveId:
- return "IsValidReserveId";
+ return SkString("IsValidReserveId");
case SpvOpGetNumPipePackets:
- return "GetNumPipePackets";
+ return SkString("GetNumPipePackets");
case SpvOpGetMaxPipePackets:
- return "GetMaxPipePackets";
+ return SkString("GetMaxPipePackets");
case SpvOpGroupReserveReadPipePackets:
- return "GroupReserveReadPipePackets";
+ return SkString("GroupReserveReadPipePackets");
case SpvOpGroupReserveWritePipePackets:
- return "GroupReserveWritePipePackets";
+ return SkString("GroupReserveWritePipePackets");
case SpvOpGroupCommitReadPipe:
- return "GroupCommitReadPipe";
+ return SkString("GroupCommitReadPipe");
case SpvOpGroupCommitWritePipe:
- return "GroupCommitWritePipe";
+ return SkString("GroupCommitWritePipe");
case SpvOpEnqueueMarker:
- return "EnqueueMarker";
+ return SkString("EnqueueMarker");
case SpvOpEnqueueKernel:
- return "EnqueueKernel";
+ return SkString("EnqueueKernel");
case SpvOpGetKernelNDrangeSubGroupCount:
- return "GetKernelNDrangeSubGroupCount";
+ return SkString("GetKernelNDrangeSubGroupCount");
case SpvOpGetKernelNDrangeMaxSubGroupSize:
- return "GetKernelNDrangeMaxSubGroupSize";
+ return SkString("GetKernelNDrangeMaxSubGroupSize");
case SpvOpGetKernelWorkGroupSize:
- return "GetKernelWorkGroupSize";
+ return SkString("GetKernelWorkGroupSize");
case SpvOpGetKernelPreferredWorkGroupSizeMultiple:
- return "GetKernelPreferredWorkGroupSizeMultiple";
+ return SkString("GetKernelPreferredWorkGroupSizeMultiple");
case SpvOpRetainEvent:
- return "RetainEvent";
+ return SkString("RetainEvent");
case SpvOpReleaseEvent:
- return "ReleaseEvent";
+ return SkString("ReleaseEvent");
case SpvOpCreateUserEvent:
- return "CreateUserEvent";
+ return SkString("CreateUserEvent");
case SpvOpIsValidEvent:
- return "IsValidEvent";
+ return SkString("IsValidEvent");
case SpvOpSetUserEventStatus:
- return "SetUserEventStatus";
+ return SkString("SetUserEventStatus");
case SpvOpCaptureEventProfilingInfo:
- return "CaptureEventProfilingInfo";
+ return SkString("CaptureEventProfilingInfo");
case SpvOpGetDefaultQueue:
- return "GetDefaultQueue";
+ return SkString("GetDefaultQueue");
case SpvOpBuildNDRange:
- return "BuildNDRange";
+ return SkString("BuildNDRange");
case SpvOpImageSparseSampleImplicitLod:
- return "ImageSparseSampleImplicitLod";
+ return SkString("ImageSparseSampleImplicitLod");
case SpvOpImageSparseSampleExplicitLod:
- return "ImageSparseSampleExplicitLod";
+ return SkString("ImageSparseSampleExplicitLod");
case SpvOpImageSparseSampleDrefImplicitLod:
- return "ImageSparseSampleDrefImplicitLod";
+ return SkString("ImageSparseSampleDrefImplicitLod");
case SpvOpImageSparseSampleDrefExplicitLod:
- return "ImageSparseSampleDrefExplicitLod";
+ return SkString("ImageSparseSampleDrefExplicitLod");
case SpvOpImageSparseSampleProjImplicitLod:
- return "ImageSparseSampleProjImplicitLod";
+ return SkString("ImageSparseSampleProjImplicitLod");
case SpvOpImageSparseSampleProjExplicitLod:
- return "ImageSparseSampleProjExplicitLod";
+ return SkString("ImageSparseSampleProjExplicitLod");
case SpvOpImageSparseSampleProjDrefImplicitLod:
- return "ImageSparseSampleProjDrefImplicitLod";
+ return SkString("ImageSparseSampleProjDrefImplicitLod");
case SpvOpImageSparseSampleProjDrefExplicitLod:
- return "ImageSparseSampleProjDrefExplicitLod";
+ return SkString("ImageSparseSampleProjDrefExplicitLod");
case SpvOpImageSparseFetch:
- return "ImageSparseFetch";
+ return SkString("ImageSparseFetch");
case SpvOpImageSparseGather:
- return "ImageSparseGather";
+ return SkString("ImageSparseGather");
case SpvOpImageSparseDrefGather:
- return "ImageSparseDrefGather";
+ return SkString("ImageSparseDrefGather");
case SpvOpImageSparseTexelsResident:
- return "ImageSparseTexelsResident";
+ return SkString("ImageSparseTexelsResident");
case SpvOpNoLine:
- return "NoLine";
+ return SkString("NoLine");
case SpvOpAtomicFlagTestAndSet:
- return "AtomicFlagTestAndSet";
+ return SkString("AtomicFlagTestAndSet");
case SpvOpAtomicFlagClear:
- return "AtomicFlagClear";
+ return SkString("AtomicFlagClear");
case SpvOpImageSparseRead:
- return "ImageSparseRead";
+ return SkString("ImageSparseRead");
default:
ABORT("unsupported SPIR-V op");
}
}
#endif
-void SPIRVCodeGenerator::writeOpCode(SpvOp_ opCode, int length, std::ostream& out) {
+void SPIRVCodeGenerator::writeOpCode(SpvOp_ opCode, int length, SkWStream& out) {
ASSERT(opCode != SpvOpUndef);
switch (opCode) {
case SpvOpReturn: // fall through
#endif
}
-void SPIRVCodeGenerator::writeLabel(SpvId label, std::ostream& out) {
+void SPIRVCodeGenerator::writeLabel(SpvId label, SkWStream& out) {
fCurrentBlock = label;
this->writeInstruction(SpvOpLabel, label, out);
}
-void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, std::ostream& out) {
+void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, SkWStream& out) {
this->writeOpCode(opCode, 1, out);
}
-void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, std::ostream& out) {
+void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, SkWStream& out) {
this->writeOpCode(opCode, 2, out);
this->writeWord(word1, out);
}
-void SPIRVCodeGenerator::writeString(const char* string, std::ostream& out) {
+void SPIRVCodeGenerator::writeString(const char* string, SkWStream& out) {
size_t length = strlen(string);
- out << string;
+ out.writeText(string);
switch (length % 4) {
case 1:
- out << (char) 0;
+ out.write8(0);
// fall through
case 2:
- out << (char) 0;
+ out.write8(0);
// fall through
case 3:
- out << (char) 0;
+ out.write8(0);
break;
default:
this->writeWord(0, out);
}
}
-void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, const char* string, std::ostream& out) {
+void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, const char* string, SkWStream& out) {
int32_t length = (int32_t) strlen(string);
this->writeOpCode(opCode, 1 + (length + 4) / 4, out);
this->writeString(string, out);
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, const char* string,
- std::ostream& out) {
+ SkWStream& out) {
int32_t length = (int32_t) strlen(string);
this->writeOpCode(opCode, 2 + (length + 4) / 4, out);
this->writeWord(word1, out);
}
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2,
- const char* string, std::ostream& out) {
+ const char* string, SkWStream& out) {
int32_t length = (int32_t) strlen(string);
this->writeOpCode(opCode, 3 + (length + 4) / 4, out);
this->writeWord(word1, out);
}
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2,
- std::ostream& out) {
+ SkWStream& out) {
this->writeOpCode(opCode, 3, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
}
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2,
- int32_t word3, std::ostream& out) {
+ int32_t word3, SkWStream& out) {
this->writeOpCode(opCode, 4, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
}
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2,
- int32_t word3, int32_t word4, std::ostream& out) {
+ int32_t word3, int32_t word4, SkWStream& out) {
this->writeOpCode(opCode, 5, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2,
int32_t word3, int32_t word4, int32_t word5,
- std::ostream& out) {
+ SkWStream& out) {
this->writeOpCode(opCode, 6, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2,
int32_t word3, int32_t word4, int32_t word5,
- int32_t word6, std::ostream& out) {
+ int32_t word6, SkWStream& out) {
this->writeOpCode(opCode, 7, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2,
int32_t word3, int32_t word4, int32_t word5,
- int32_t word6, int32_t word7, std::ostream& out) {
+ int32_t word6, int32_t word7, SkWStream& out) {
this->writeOpCode(opCode, 8, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2,
int32_t word3, int32_t word4, int32_t word5,
int32_t word6, int32_t word7, int32_t word8,
- std::ostream& out) {
+ SkWStream& out) {
this->writeOpCode(opCode, 9, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
this->writeWord(word8, out);
}
-void SPIRVCodeGenerator::writeCapabilities(std::ostream& out) {
+void SPIRVCodeGenerator::writeCapabilities(SkWStream& out) {
for (uint64_t i = 0, bit = 1; i <= kLast_Capability; i++, bit <<= 1) {
if (fCapabilities & bit) {
this->writeInstruction(SpvOpCapability, (SpvId) i, out);
if ((kind == Type::kArray_Kind || kind == Type::kStruct_Kind) && offset % alignment != 0) {
offset += alignment - offset % alignment;
}
- ASSERT(offset % alignment == 0);
}
}
}
SpvId SPIRVCodeGenerator::getFunctionType(const FunctionDeclaration& function) {
- std::string key = function.fReturnType.description() + "(";
- std::string separator = "";
+ SkString key = function.fReturnType.description() + "(";
+ SkString separator;
for (size_t i = 0; i < function.fParameters.size(); i++) {
key += separator;
separator = ", ";
SpvId SPIRVCodeGenerator::getPointerType(const Type& type,
SpvStorageClass_ storageClass) {
- std::string key = type.description() + "*" + to_string(storageClass);
+ SkString key = type.description() + "*" + to_string(storageClass);
auto entry = fTypeMap.find(key);
if (entry == fTypeMap.end()) {
SpvId result = this->nextId();
return entry->second;
}
-SpvId SPIRVCodeGenerator::writeExpression(const Expression& expr, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writeExpression(const Expression& expr, SkWStream& out) {
switch (expr.fKind) {
case Expression::kBinary_Kind:
return this->writeBinaryExpression((BinaryExpression&) expr, out);
return -1;
}
-SpvId SPIRVCodeGenerator::writeIntrinsicCall(const FunctionCall& c, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writeIntrinsicCall(const FunctionCall& c, SkWStream& out) {
auto intrinsic = fIntrinsicMap.find(c.fFunction.fName);
ASSERT(intrinsic != fIntrinsicMap.end());
const Type& type = c.fArguments[0]->fType;
}
SpvId SPIRVCodeGenerator::writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind,
- std::ostream& out) {
+ SkWStream& out) {
SpvId result = this->nextId();
switch (kind) {
case kAtan_SpecialIntrinsic: {
return result;
}
-SpvId SPIRVCodeGenerator::writeFunctionCall(const FunctionCall& c, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writeFunctionCall(const FunctionCall& c, SkWStream& out) {
const auto& entry = fFunctionMap.find(&c.fFunction);
if (entry == fFunctionMap.end()) {
return this->writeIntrinsicCall(c, out);
return result;
}
-SpvId SPIRVCodeGenerator::writeFloatConstructor(const Constructor& c, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writeFloatConstructor(const Constructor& c, SkWStream& out) {
ASSERT(c.fType == *fContext.fFloat_Type);
ASSERT(c.fArguments.size() == 1);
ASSERT(c.fArguments[0]->fType.isNumber());
return result;
}
-SpvId SPIRVCodeGenerator::writeIntConstructor(const Constructor& c, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writeIntConstructor(const Constructor& c, SkWStream& out) {
ASSERT(c.fType == *fContext.fInt_Type);
ASSERT(c.fArguments.size() == 1);
ASSERT(c.fArguments[0]->fType.isNumber());
return result;
}
-SpvId SPIRVCodeGenerator::writeMatrixConstructor(const Constructor& c, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writeMatrixConstructor(const Constructor& c, SkWStream& out) {
ASSERT(c.fType.kind() == Type::kMatrix_Kind);
// go ahead and write the arguments so we don't try to write new instructions in the middle of
// an instruction
return result;
}
-SpvId SPIRVCodeGenerator::writeVectorConstructor(const Constructor& c, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writeVectorConstructor(const Constructor& c, SkWStream& out) {
ASSERT(c.fType.kind() == Type::kVector_Kind);
if (c.isConstant()) {
return this->writeConstantVector(c);
return result;
}
-SpvId SPIRVCodeGenerator::writeConstructor(const Constructor& c, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writeConstructor(const Constructor& c, SkWStream& out) {
if (c.fType == *fContext.fFloat_Type) {
return this->writeFloatConstructor(c, out);
} else if (c.fType == *fContext.fInt_Type) {
}
}
-std::vector<SpvId> SPIRVCodeGenerator::getAccessChain(const Expression& expr, std::ostream& out) {
+std::vector<SpvId> SPIRVCodeGenerator::getAccessChain(const Expression& expr, SkWStream& out) {
std::vector<SpvId> chain;
switch (expr.fKind) {
case Expression::kIndex_Kind: {
return fPointer;
}
- virtual SpvId load(std::ostream& out) override {
+ virtual SpvId load(SkWStream& out) override {
SpvId result = fGen.nextId();
fGen.writeInstruction(SpvOpLoad, fType, result, fPointer, out);
return result;
}
- virtual void store(SpvId value, std::ostream& out) override {
+ virtual void store(SpvId value, SkWStream& out) override {
fGen.writeInstruction(SpvOpStore, fPointer, value, out);
}
return 0;
}
- virtual SpvId load(std::ostream& out) override {
+ virtual SpvId load(SkWStream& out) override {
SpvId base = fGen.nextId();
fGen.writeInstruction(SpvOpLoad, fGen.getType(fBaseType), base, fVecPointer, out);
SpvId result = fGen.nextId();
return result;
}
- virtual void store(SpvId value, std::ostream& out) override {
+ virtual void store(SpvId value, SkWStream& out) override {
// use OpVectorShuffle to mix and match the vector components. We effectively create
// a virtual vector out of the concatenation of the left and right vectors, and then
// select components from this virtual vector to make the result vector. For
};
std::unique_ptr<SPIRVCodeGenerator::LValue> SPIRVCodeGenerator::getLValue(const Expression& expr,
- std::ostream& out) {
+ SkWStream& out) {
switch (expr.fKind) {
case Expression::kVariableReference_Kind: {
const Variable& var = ((VariableReference&) expr).fVariable;
}
}
-SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, SkWStream& out) {
auto entry = fVariableMap.find(&ref.fVariable);
ASSERT(entry != fVariableMap.end());
SpvId var = entry->second;
return result;
}
-SpvId SPIRVCodeGenerator::writeIndexExpression(const IndexExpression& expr, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writeIndexExpression(const IndexExpression& expr, SkWStream& out) {
return getLValue(expr, out)->load(out);
}
-SpvId SPIRVCodeGenerator::writeFieldAccess(const FieldAccess& f, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writeFieldAccess(const FieldAccess& f, SkWStream& out) {
return getLValue(f, out)->load(out);
}
-SpvId SPIRVCodeGenerator::writeSwizzle(const Swizzle& swizzle, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writeSwizzle(const Swizzle& swizzle, SkWStream& out) {
SpvId base = this->writeExpression(*swizzle.fBase, out);
SpvId result = this->nextId();
size_t count = swizzle.fComponents.size();
SpvId SPIRVCodeGenerator::writeBinaryOperation(const Type& resultType,
const Type& operandType, SpvId lhs,
SpvId rhs, SpvOp_ ifFloat, SpvOp_ ifInt,
- SpvOp_ ifUInt, SpvOp_ ifBool, std::ostream& out) {
+ SpvOp_ ifUInt, SpvOp_ ifBool, SkWStream& out) {
SpvId result = this->nextId();
if (is_float(fContext, operandType)) {
this->writeInstruction(ifFloat, this->getType(resultType), result, lhs, rhs, out);
}
}
-SpvId SPIRVCodeGenerator::writeBinaryExpression(const BinaryExpression& b, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writeBinaryExpression(const BinaryExpression& b, SkWStream& out) {
// handle cases where we don't necessarily evaluate both LHS and RHS
switch (b.fOperator) {
case Token::EQ: {
}
}
-SpvId SPIRVCodeGenerator::writeLogicalAnd(const BinaryExpression& a, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writeLogicalAnd(const BinaryExpression& a, SkWStream& out) {
ASSERT(a.fOperator == Token::LOGICALAND);
BoolLiteral falseLiteral(fContext, Position(), false);
SpvId falseConstant = this->writeBoolLiteral(falseLiteral);
return result;
}
-SpvId SPIRVCodeGenerator::writeLogicalOr(const BinaryExpression& o, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writeLogicalOr(const BinaryExpression& o, SkWStream& out) {
ASSERT(o.fOperator == Token::LOGICALOR);
BoolLiteral trueLiteral(fContext, Position(), true);
SpvId trueConstant = this->writeBoolLiteral(trueLiteral);
return result;
}
-SpvId SPIRVCodeGenerator::writeTernaryExpression(const TernaryExpression& t, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writeTernaryExpression(const TernaryExpression& t, SkWStream& out) {
SpvId test = this->writeExpression(*t.fTest, out);
if (t.fIfTrue->isConstant() && t.fIfFalse->isConstant()) {
// both true and false are constants, can just use OpSelect
}
}
-SpvId SPIRVCodeGenerator::writePrefixExpression(const PrefixExpression& p, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writePrefixExpression(const PrefixExpression& p, SkWStream& out) {
if (p.fOperator == Token::MINUS) {
SpvId result = this->nextId();
SpvId typeId = this->getType(p.fType);
}
}
-SpvId SPIRVCodeGenerator::writePostfixExpression(const PostfixExpression& p, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writePostfixExpression(const PostfixExpression& p, SkWStream& out) {
std::unique_ptr<LValue> lv = this->getLValue(*p.fOperand, out);
SpvId result = lv->load(out);
SpvId one = this->writeExpression(*create_literal_1(fContext, p.fType), out);
}
}
-SpvId SPIRVCodeGenerator::writeFunctionStart(const FunctionDeclaration& f, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writeFunctionStart(const FunctionDeclaration& f, SkWStream& out) {
SpvId result = fFunctionMap[&f];
this->writeInstruction(SpvOpFunction, this->getType(f.fReturnType), result,
SpvFunctionControlMaskNone, this->getFunctionType(f), out);
return result;
}
-SpvId SPIRVCodeGenerator::writeFunction(const FunctionDefinition& f, std::ostream& out) {
+SpvId SPIRVCodeGenerator::writeFunction(const FunctionDefinition& f, SkWStream& out) {
SpvId result = this->writeFunctionStart(f.fDeclaration, out);
this->writeLabel(this->nextId(), out);
if (f.fDeclaration.fName == "main") {
- out << fGlobalInitializersBuffer.str();
+ write_data(*fGlobalInitializersBuffer.detachAsData(), out);
}
- std::stringstream bodyBuffer;
+ SkDynamicMemoryWStream bodyBuffer;
this->writeBlock(*f.fBody, bodyBuffer);
- out << fVariableBuffer.str();
- fVariableBuffer.str("");
- out << bodyBuffer.str();
+ write_data(*fVariableBuffer.detachAsData(), out);
+ write_data(*bodyBuffer.detachAsData(), out);
if (fCurrentBlock) {
this->writeInstruction(SpvOpReturn, out);
}
#define BUILTIN_IGNORE 9999
void SPIRVCodeGenerator::writeGlobalVars(Program::Kind kind, const VarDeclarations& decl,
- std::ostream& out) {
+ SkWStream& out) {
for (size_t i = 0; i < decl.fVars.size(); i++) {
const VarDeclaration& varDecl = decl.fVars[i];
const Variable* var = varDecl.fVar;
}
}
-void SPIRVCodeGenerator::writeVarDeclarations(const VarDeclarations& decl, std::ostream& out) {
+void SPIRVCodeGenerator::writeVarDeclarations(const VarDeclarations& decl, SkWStream& out) {
for (const auto& varDecl : decl.fVars) {
const Variable* var = varDecl.fVar;
SpvId id = this->nextId();
}
}
-void SPIRVCodeGenerator::writeStatement(const Statement& s, std::ostream& out) {
+void SPIRVCodeGenerator::writeStatement(const Statement& s, SkWStream& out) {
switch (s.fKind) {
case Statement::kBlock_Kind:
this->writeBlock((Block&) s, out);
}
}
-void SPIRVCodeGenerator::writeBlock(const Block& b, std::ostream& out) {
+void SPIRVCodeGenerator::writeBlock(const Block& b, SkWStream& out) {
for (size_t i = 0; i < b.fStatements.size(); i++) {
this->writeStatement(*b.fStatements[i], out);
}
}
-void SPIRVCodeGenerator::writeIfStatement(const IfStatement& stmt, std::ostream& out) {
+void SPIRVCodeGenerator::writeIfStatement(const IfStatement& stmt, SkWStream& out) {
SpvId test = this->writeExpression(*stmt.fTest, out);
SpvId ifTrue = this->nextId();
SpvId ifFalse = this->nextId();
}
}
-void SPIRVCodeGenerator::writeForStatement(const ForStatement& f, std::ostream& out) {
+void SPIRVCodeGenerator::writeForStatement(const ForStatement& f, SkWStream& out) {
if (f.fInitializer) {
this->writeStatement(*f.fInitializer, out);
}
fContinueTarget.pop();
}
-void SPIRVCodeGenerator::writeReturnStatement(const ReturnStatement& r, std::ostream& out) {
+void SPIRVCodeGenerator::writeReturnStatement(const ReturnStatement& r, SkWStream& out) {
if (r.fExpression) {
this->writeInstruction(SpvOpReturnValue, this->writeExpression(*r.fExpression, out),
out);
}
}
-void SPIRVCodeGenerator::writeInstructions(const Program& program, std::ostream& out) {
+void SPIRVCodeGenerator::writeInstructions(const Program& program, SkWStream& out) {
fGLSLExtendedInstructions = this->nextId();
- std::stringstream body;
+ SkDynamicMemoryWStream body;
std::vector<SpvId> interfaceVars;
// assign IDs to functions
for (size_t i = 0; i < program.fElements.size(); i++) {
}
}
- out << fNameBuffer.str();
- out << fDecorationBuffer.str();
- out << fConstantBuffer.str();
- out << fExternalFunctionsBuffer.str();
- out << body.str();
+ write_data(*fNameBuffer.detachAsData(), out);
+ write_data(*fDecorationBuffer.detachAsData(), out);
+ write_data(*fConstantBuffer.detachAsData(), out);
+ write_data(*fExternalFunctionsBuffer.detachAsData(), out);
+ write_data(*body.detachAsData(), out);
}
-void SPIRVCodeGenerator::generateCode(const Program& program, std::ostream& out) {
+void SPIRVCodeGenerator::generateCode(const Program& program, SkWStream& out) {
this->writeWord(SpvMagicNumber, out);
this->writeWord(SpvVersion, out);
this->writeWord(SKSL_MAGIC, out);
- std::stringstream buffer;
+ SkDynamicMemoryWStream buffer;
this->writeInstructions(program, buffer);
this->writeWord(fIdCount, out);
this->writeWord(0, out); // reserved, always zero
- out << buffer.str();
+ write_data(*buffer.detachAsData(), out);
}
}
#ifndef SKSL_SPIRVCODEGENERATOR
#define SKSL_SPIRVCODEGENERATOR
-#include <sstream>
#include <stack>
#include <tuple>
#include <unordered_map>
+#include "SkStream.h"
#include "SkSLCodeGenerator.h"
#include "ir/SkSLBinaryExpression.h"
#include "ir/SkSLBoolLiteral.h"
// by a pointer (e.g. vector swizzles), returns 0.
virtual SpvId getPointer() = 0;
- virtual SpvId load(std::ostream& out) = 0;
+ virtual SpvId load(SkWStream& out) = 0;
- virtual void store(SpvId value, std::ostream& out) = 0;
+ virtual void store(SpvId value, SkWStream& out) = 0;
};
SPIRVCodeGenerator(const Context* context)
this->setupIntrinsics();
}
- void generateCode(const Program& program, std::ostream& out) override;
+ void generateCode(const Program& program, SkWStream& out) override;
private:
enum IntrinsicKind {
SpvId getPointerType(const Type& type, SpvStorageClass_ storageClass);
- std::vector<SpvId> getAccessChain(const Expression& expr, std::ostream& out);
+ std::vector<SpvId> getAccessChain(const Expression& expr, SkWStream& out);
void writeLayout(const Layout& layout, SpvId target);
void writeStruct(const Type& type, SpvId resultId);
- void writeProgramElement(const ProgramElement& pe, std::ostream& out);
+ void writeProgramElement(const ProgramElement& pe, SkWStream& out);
SpvId writeInterfaceBlock(const InterfaceBlock& intf);
- SpvId writeFunctionStart(const FunctionDeclaration& f, std::ostream& out);
+ SpvId writeFunctionStart(const FunctionDeclaration& f, SkWStream& out);
- SpvId writeFunctionDeclaration(const FunctionDeclaration& f, std::ostream& out);
+ SpvId writeFunctionDeclaration(const FunctionDeclaration& f, SkWStream& out);
- SpvId writeFunction(const FunctionDefinition& f, std::ostream& out);
+ SpvId writeFunction(const FunctionDefinition& f, SkWStream& out);
- void writeGlobalVars(Program::Kind kind, const VarDeclarations& v, std::ostream& out);
+ void writeGlobalVars(Program::Kind kind, const VarDeclarations& v, SkWStream& out);
- void writeVarDeclarations(const VarDeclarations& decl, std::ostream& out);
+ void writeVarDeclarations(const VarDeclarations& decl, SkWStream& out);
- SpvId writeVariableReference(const VariableReference& ref, std::ostream& out);
+ SpvId writeVariableReference(const VariableReference& ref, SkWStream& out);
- std::unique_ptr<LValue> getLValue(const Expression& value, std::ostream& out);
+ std::unique_ptr<LValue> getLValue(const Expression& value, SkWStream& out);
- SpvId writeExpression(const Expression& expr, std::ostream& out);
+ SpvId writeExpression(const Expression& expr, SkWStream& out);
- SpvId writeIntrinsicCall(const FunctionCall& c, std::ostream& out);
+ SpvId writeIntrinsicCall(const FunctionCall& c, SkWStream& out);
- SpvId writeFunctionCall(const FunctionCall& c, std::ostream& out);
+ SpvId writeFunctionCall(const FunctionCall& c, SkWStream& out);
- SpvId writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind, std::ostream& out);
+ SpvId writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind, SkWStream& out);
SpvId writeConstantVector(const Constructor& c);
- SpvId writeFloatConstructor(const Constructor& c, std::ostream& out);
+ SpvId writeFloatConstructor(const Constructor& c, SkWStream& out);
- SpvId writeIntConstructor(const Constructor& c, std::ostream& out);
+ SpvId writeIntConstructor(const Constructor& c, SkWStream& out);
- SpvId writeMatrixConstructor(const Constructor& c, std::ostream& out);
+ SpvId writeMatrixConstructor(const Constructor& c, SkWStream& out);
- SpvId writeVectorConstructor(const Constructor& c, std::ostream& out);
+ SpvId writeVectorConstructor(const Constructor& c, SkWStream& out);
- SpvId writeConstructor(const Constructor& c, std::ostream& out);
+ SpvId writeConstructor(const Constructor& c, SkWStream& out);
- SpvId writeFieldAccess(const FieldAccess& f, std::ostream& out);
+ SpvId writeFieldAccess(const FieldAccess& f, SkWStream& out);
- SpvId writeSwizzle(const Swizzle& swizzle, std::ostream& out);
+ SpvId writeSwizzle(const Swizzle& swizzle, SkWStream& out);
SpvId writeBinaryOperation(const Type& resultType, const Type& operandType, SpvId lhs,
SpvId rhs, SpvOp_ ifFloat, SpvOp_ ifInt, SpvOp_ ifUInt,
- SpvOp_ ifBool, std::ostream& out);
+ SpvOp_ ifBool, SkWStream& out);
SpvId writeBinaryOperation(const BinaryExpression& expr, SpvOp_ ifFloat, SpvOp_ ifInt,
- SpvOp_ ifUInt, std::ostream& out);
+ SpvOp_ ifUInt, SkWStream& out);
- SpvId writeBinaryExpression(const BinaryExpression& b, std::ostream& out);
+ SpvId writeBinaryExpression(const BinaryExpression& b, SkWStream& out);
- SpvId writeTernaryExpression(const TernaryExpression& t, std::ostream& out);
+ SpvId writeTernaryExpression(const TernaryExpression& t, SkWStream& out);
- SpvId writeIndexExpression(const IndexExpression& expr, std::ostream& out);
+ SpvId writeIndexExpression(const IndexExpression& expr, SkWStream& out);
- SpvId writeLogicalAnd(const BinaryExpression& b, std::ostream& out);
+ SpvId writeLogicalAnd(const BinaryExpression& b, SkWStream& out);
- SpvId writeLogicalOr(const BinaryExpression& o, std::ostream& out);
+ SpvId writeLogicalOr(const BinaryExpression& o, SkWStream& out);
- SpvId writePrefixExpression(const PrefixExpression& p, std::ostream& out);
+ SpvId writePrefixExpression(const PrefixExpression& p, SkWStream& out);
- SpvId writePostfixExpression(const PostfixExpression& p, std::ostream& out);
+ SpvId writePostfixExpression(const PostfixExpression& p, SkWStream& out);
SpvId writeBoolLiteral(const BoolLiteral& b);
SpvId writeFloatLiteral(const FloatLiteral& f);
- void writeStatement(const Statement& s, std::ostream& out);
+ void writeStatement(const Statement& s, SkWStream& out);
- void writeBlock(const Block& b, std::ostream& out);
+ void writeBlock(const Block& b, SkWStream& out);
- void writeIfStatement(const IfStatement& stmt, std::ostream& out);
+ void writeIfStatement(const IfStatement& stmt, SkWStream& out);
- void writeForStatement(const ForStatement& f, std::ostream& out);
+ void writeForStatement(const ForStatement& f, SkWStream& out);
- void writeReturnStatement(const ReturnStatement& r, std::ostream& out);
+ void writeReturnStatement(const ReturnStatement& r, SkWStream& out);
- void writeCapabilities(std::ostream& out);
+ void writeCapabilities(SkWStream& out);
- void writeInstructions(const Program& program, std::ostream& out);
+ void writeInstructions(const Program& program, SkWStream& out);
- void writeOpCode(SpvOp_ opCode, int length, std::ostream& out);
+ void writeOpCode(SpvOp_ opCode, int length, SkWStream& out);
- void writeWord(int32_t word, std::ostream& out);
+ void writeWord(int32_t word, SkWStream& out);
- void writeString(const char* string, std::ostream& out);
+ void writeString(const char* string, SkWStream& out);
- void writeLabel(SpvId id, std::ostream& out);
+ void writeLabel(SpvId id, SkWStream& out);
- void writeInstruction(SpvOp_ opCode, std::ostream& out);
+ void writeInstruction(SpvOp_ opCode, SkWStream& out);
- void writeInstruction(SpvOp_ opCode, const char* string, std::ostream& out);
+ void writeInstruction(SpvOp_ opCode, const char* string, SkWStream& out);
- void writeInstruction(SpvOp_ opCode, int32_t word1, std::ostream& out);
+ void writeInstruction(SpvOp_ opCode, int32_t word1, SkWStream& out);
- void writeInstruction(SpvOp_ opCode, int32_t word1, const char* string, std::ostream& out);
+ void writeInstruction(SpvOp_ opCode, int32_t word1, const char* string, SkWStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, const char* string,
- std::ostream& out);
+ SkWStream& out);
- void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, std::ostream& out);
+ void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, SkWStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3,
- std::ostream& out);
+ SkWStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4,
- std::ostream& out);
+ SkWStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4,
- int32_t word5, std::ostream& out);
+ int32_t word5, SkWStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4,
- int32_t word5, int32_t word6, std::ostream& out);
+ int32_t word5, int32_t word6, SkWStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4,
- int32_t word5, int32_t word6, int32_t word7, std::ostream& out);
+ int32_t word5, int32_t word6, int32_t word7, SkWStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4,
int32_t word5, int32_t word6, int32_t word7, int32_t word8,
- std::ostream& out);
+ SkWStream& out);
const Context& fContext;
SpvId fIdCount;
SpvId fGLSLExtendedInstructions;
typedef std::tuple<IntrinsicKind, int32_t, int32_t, int32_t, int32_t> Intrinsic;
- std::unordered_map<std::string, Intrinsic> fIntrinsicMap;
+ std::unordered_map<SkString, Intrinsic> fIntrinsicMap;
std::unordered_map<const FunctionDeclaration*, SpvId> fFunctionMap;
std::unordered_map<const Variable*, SpvId> fVariableMap;
std::unordered_map<const Variable*, int32_t> fInterfaceBlockMap;
- std::unordered_map<std::string, SpvId> fTypeMap;
- std::stringstream fCapabilitiesBuffer;
- std::stringstream fGlobalInitializersBuffer;
- std::stringstream fConstantBuffer;
- std::stringstream fExternalFunctionsBuffer;
- std::stringstream fVariableBuffer;
- std::stringstream fNameBuffer;
- std::stringstream fDecorationBuffer;
+ std::unordered_map<SkString, SpvId> fTypeMap;
+ SkDynamicMemoryWStream fCapabilitiesBuffer;
+ SkDynamicMemoryWStream fGlobalInitializersBuffer;
+ SkDynamicMemoryWStream fConstantBuffer;
+ SkDynamicMemoryWStream fExternalFunctionsBuffer;
+ SkDynamicMemoryWStream fVariableBuffer;
+ SkDynamicMemoryWStream fNameBuffer;
+ SkDynamicMemoryWStream fDecorationBuffer;
SpvId fBoolTrue;
SpvId fBoolFalse;
INVALID_TOKEN
};
- static std::string OperatorName(Kind kind) {
+ static SkString OperatorName(Kind kind) {
switch (kind) {
- case Token::PLUS: return "+";
- case Token::MINUS: return "-";
- case Token::STAR: return "*";
- case Token::SLASH: return "/";
- case Token::PERCENT: return "%";
- case Token::SHL: return "<<";
- case Token::SHR: return ">>";
- case Token::LOGICALNOT: return "!";
- case Token::LOGICALAND: return "&&";
- case Token::LOGICALOR: return "||";
- case Token::LOGICALXOR: return "^^";
- case Token::BITWISENOT: return "~";
- case Token::BITWISEAND: return "&";
- case Token::BITWISEOR: return "|";
- case Token::BITWISEXOR: return "^";
- case Token::EQ: return "=";
- case Token::EQEQ: return "==";
- case Token::NEQ: return "!=";
- case Token::LT: return "<";
- case Token::GT: return ">";
- case Token::LTEQ: return "<=";
- case Token::GTEQ: return ">=";
- case Token::PLUSEQ: return "+=";
- case Token::MINUSEQ: return "-=";
- case Token::STAREQ: return "*=";
- case Token::SLASHEQ: return "/=";
- case Token::PERCENTEQ: return "%=";
- case Token::SHLEQ: return "<<=";
- case Token::SHREQ: return ">>=";
- case Token::LOGICALANDEQ: return "&&=";
- case Token::LOGICALOREQ: return "||=";
- case Token::LOGICALXOREQ: return "^^=";
- case Token::BITWISEANDEQ: return "&=";
- case Token::BITWISEOREQ: return "|=";
- case Token::BITWISEXOREQ: return "^=";
- case Token::PLUSPLUS: return "++";
- case Token::MINUSMINUS: return "--";
+ case Token::PLUS: return SkString("+");
+ case Token::MINUS: return SkString("-");
+ case Token::STAR: return SkString("*");
+ case Token::SLASH: return SkString("/");
+ case Token::PERCENT: return SkString("%");
+ case Token::SHL: return SkString("<<");
+ case Token::SHR: return SkString(">>");
+ case Token::LOGICALNOT: return SkString("!");
+ case Token::LOGICALAND: return SkString("&&");
+ case Token::LOGICALOR: return SkString("||");
+ case Token::LOGICALXOR: return SkString("^^");
+ case Token::BITWISENOT: return SkString("~");
+ case Token::BITWISEAND: return SkString("&");
+ case Token::BITWISEOR: return SkString("|");
+ case Token::BITWISEXOR: return SkString("^");
+ case Token::EQ: return SkString("=");
+ case Token::EQEQ: return SkString("==");
+ case Token::NEQ: return SkString("!=");
+ case Token::LT: return SkString("<");
+ case Token::GT: return SkString(">");
+ case Token::LTEQ: return SkString("<=");
+ case Token::GTEQ: return SkString(">=");
+ case Token::PLUSEQ: return SkString("+=");
+ case Token::MINUSEQ: return SkString("-=");
+ case Token::STAREQ: return SkString("*=");
+ case Token::SLASHEQ: return SkString("/=");
+ case Token::PERCENTEQ: return SkString("%=");
+ case Token::SHLEQ: return SkString("<<=");
+ case Token::SHREQ: return SkString(">>=");
+ case Token::LOGICALANDEQ: return SkString("&&=");
+ case Token::LOGICALOREQ: return SkString("||=");
+ case Token::LOGICALXOREQ: return SkString("^^=");
+ case Token::BITWISEANDEQ: return SkString("&=");
+ case Token::BITWISEOREQ: return SkString("|=");
+ case Token::BITWISEXOREQ: return SkString("^=");
+ case Token::PLUSPLUS: return SkString("++");
+ case Token::MINUSMINUS: return SkString("--");
default:
ABORT("unsupported operator: %d\n", kind);
}
Token() {
}
- Token(Position position, Kind kind, std::string text)
+ Token(Position position, Kind kind, SkString text)
: fPosition(position)
, fKind(kind)
, fText(std::move(text)) {}
Kind fKind;
// will be the empty string unless the token has variable text content (identifiers, numeric
// literals, and directives)
- std::string fText;
+ SkString fText;
};
} // namespace
#include "SkSLUtil.h"
+#include <cinttypes>
+
namespace SkSL {
-std::string to_string(double value) {
- std::stringstream buffer;
- buffer << std::setprecision(std::numeric_limits<double>::digits10) << value;
- std::string result = buffer.str();
- if (result.find_last_of(".") == std::string::npos &&
- result.find_last_of("e") == std::string::npos) {
+SkString to_string(double value) {
+#ifdef SK_BUILD_FOR_WIN
+ #define SNPRINTF _snprintf
+#else
+ #define SNPRINTF snprintf
+#endif
+#define MAX_DOUBLE_CHARS 25
+ char buffer[MAX_DOUBLE_CHARS];
+ SkDEBUGCODE(int len = )SNPRINTF(buffer, sizeof(buffer), "%.17g", value);
+ ASSERT(len < MAX_DOUBLE_CHARS);
+ SkString result(buffer);
+ if (!strchr(buffer, '.') && !strchr(buffer, 'e')) {
result += ".0";
}
return result;
+#undef SNPRINTF
+#undef MAX_DOUBLE_CHARS
}
-std::string to_string(int32_t value) {
- std::stringstream buffer;
- buffer << value;
- return buffer.str();
+SkString to_string(int32_t value) {
+ return SkStringPrintf("%d", value);
}
-std::string to_string(uint32_t value) {
- std::stringstream buffer;
- buffer << value;
- return buffer.str();
+SkString to_string(uint32_t value) {
+ return SkStringPrintf("%u", value);
}
-std::string to_string(int64_t value) {
- std::stringstream buffer;
- buffer << value;
- return buffer.str();
+SkString to_string(int64_t value) {
+ return SkStringPrintf("%" PRId64, value);
}
-std::string to_string(uint64_t value) {
- std::stringstream buffer;
- buffer << value;
- return buffer.str();
+SkString to_string(uint64_t value) {
+ return SkStringPrintf("%" PRIu64, value);
}
-int stoi(std::string s) {
+int stoi(SkString s) {
if (s.size() > 2 && s[0] == '0' && s[1] == 'x') {
char* p;
- int result = strtoul(s.substr(2).c_str(), &p, 16);
+ int result = strtoul(s.c_str() + 2, &p, 16);
ASSERT(*p == 0);
return result;
}
return atoi(s.c_str());
}
-double stod(std::string s) {
+double stod(SkString s) {
return atof(s.c_str());
}
-long stol(std::string s) {
+long stol(SkString s) {
if (s.size() > 2 && s[0] == '0' && s[1] == 'x') {
char* p;
- long result = strtoul(s.substr(2).c_str(), &p, 16);
+ long result = strtoul(s.c_str() + 2, &p, 16);
ASSERT(*p == 0);
return result;
}
#endif
}
+void write_data(const SkData& data, SkWStream& out) {
+ out.write(data.data(), data.size());
+}
+
+SkString operator+(const SkString& s, const char* c) {
+ SkString result(s);
+ result += c;
+ return result;
+}
+
+SkString operator+(const char* c, const SkString& s) {
+ SkString result(c);
+ result += s;
+ return result;
+}
+
+SkString operator+(const SkString& s1, const SkString& s2) {
+ SkString result(s1);
+ result += s2;
+ return result;
+}
+
+bool operator==(const SkString& s1, const char* s2) {
+ return !strcmp(s1.c_str(), s2);
+}
+
+bool operator!=(const SkString& s1, const char* s2) {
+ return strcmp(s1.c_str(), s2);
+}
+
+bool operator!=(const char* s1, const SkString& s2) {
+ return strcmp(s1, s2.c_str());
+}
} // namespace
#ifndef SKSL_UTIL
#define SKSL_UTIL
-#include <iomanip>
-#include <string>
-#include <sstream>
#include "stdlib.h"
#include "assert.h"
+#include "SkOpts.h"
#include "SkRefCnt.h"
+#include "SkStream.h"
+#include "SkString.h"
#include "SkTypes.h"
#include "glsl/GrGLSLCaps.h"
#include "GrContextOptions.h"
}
};
-// our own definitions of certain std:: functions, because they are not always present on Android
+void write_data(const SkData& d, SkWStream& out);
-std::string to_string(double value);
+SkString operator+(const SkString& s, const char* c);
-std::string to_string(int32_t value);
+SkString operator+(const char* c, const SkString& s);
-std::string to_string(uint32_t value);
+SkString operator+(const SkString& s1, const SkString& s2);
-std::string to_string(int64_t value);
+bool operator==(const SkString& s1, const char* s2);
-std::string to_string(uint64_t value);
+bool operator!=(const SkString& s1, const char* s2);
+
+bool operator!=(const char* s1, const SkString& s2);
+
+SkString to_string(double value);
+
+SkString to_string(int32_t value);
+
+SkString to_string(uint32_t value);
+
+SkString to_string(int64_t value);
+
+SkString to_string(uint64_t value);
#if _MSC_VER
#define NORETURN __declspec(noreturn)
#else
#define NORETURN __attribute__((__noreturn__))
#endif
-int stoi(std::string s);
+int stoi(SkString s);
-double stod(std::string s);
+double stod(SkString s);
-long stol(std::string s);
+long stol(SkString s);
NORETURN void sksl_abort();
} // namespace
-#ifdef DEBUG
-#define ASSERT(x) assert(x)
-#define ASSERT_RESULT(x) ASSERT(x);
-#else
-#define ASSERT(x)
-#define ASSERT_RESULT(x) x
-#endif
+#define ASSERT(x) SkASSERT(x)
+#define ASSERT_RESULT(x) SkAssertResult(x);
#ifdef SKIA
#define ABORT(...) { SkDebugf(__VA_ARGS__); sksl_abort(); }
#define ABORT(...) { sksl_abort(); }
#endif
+namespace std {
+ template<> struct hash<SkString> {
+ size_t operator()(const SkString& s) const {
+ return SkOpts::hash_fn(s.c_str(), s.size(), 0);
+ }
+ };
+}
#endif
#include "SkSLASTExpression.h"
#include "../SkSLToken.h"
-#include <sstream>
namespace SkSL {
, fOperator(op.fKind)
, fRight(std::move(right)) {}
- std::string description() const override {
+ SkString description() const override {
return "(" + fLeft->description() + " " + Token::OperatorName(fOperator) + " " +
fRight->description() + ")";
}
: INHERITED(position, kBlock_Kind)
, fStatements(std::move(statements)) {}
- std::string description() const override {
- std::string result("{");
+ SkString description() const override {
+ SkString result("{");
for (size_t i = 0; i < fStatements.size(); i++) {
result += "\n";
result += fStatements[i]->description();
: INHERITED(position, kBool_Kind)
, fValue(value) {}
- std::string description() const override {
- return fValue ? "true" : "false";
+ SkString description() const override {
+ return SkString(fValue ? "true" : "false");
}
const bool fValue;
ASTBreakStatement(Position position)
: INHERITED(position, kBreak_Kind) {}
- std::string description() const override {
- return "break;";
+ SkString description() const override {
+ return SkString("break;");
}
typedef ASTStatement INHERITED;
#ifndef SKSL_ASTCALLSUFFIX
#define SKSL_ASTCALLSUFFIX
-#include <sstream>
#include <vector>
#include "SkSLASTSuffix.h"
: INHERITED(position, ASTSuffix::kCall_Kind)
, fArguments(std::move(arguments)) {}
- std::string description() const override {
- std::string result("(");
- std::string separator = "";
+ SkString description() const override {
+ SkString result("(");
+ SkString separator;
for (size_t i = 0; i < fArguments.size(); ++i) {
result += separator;
separator = ", ";
ASTContinueStatement(Position position)
: INHERITED(position, kContinue_Kind) {}
- std::string description() const override {
- return "continue;";
+ SkString description() const override {
+ return SkString("continue;");
}
typedef ASTStatement INHERITED;
ASTDiscardStatement(Position position)
: INHERITED(position, kDiscard_Kind) {}
- std::string description() const override {
- return "discard;";
+ SkString description() const override {
+ return SkString("discard;");
}
typedef ASTStatement INHERITED;
, fStatement(std::move(statement))
, fTest(std::move(test)) {}
- std::string description() const override {
+ SkString description() const override {
return "do " + fStatement->description() + " while (" + fTest->description() + ");";
}
: INHERITED(expression->fPosition, kExpression_Kind)
, fExpression(std::move(expression)) {}
- std::string description() const override {
+ SkString description() const override {
return fExpression->description() + ";";
}
* An extension declaration.
*/
struct ASTExtension : public ASTDeclaration {
- ASTExtension(Position position, std::string name)
+ ASTExtension(Position position, SkString name)
: INHERITED(position, kExtension_Kind)
, fName(std::move(name)) {}
- std::string description() const override {
+ SkString description() const override {
return "#extension " + fName + " : enable";
}
- const std::string fName;
+ const SkString fName;
typedef ASTDeclaration INHERITED;
};
* actually vector swizzle (which looks the same to the parser).
*/
struct ASTFieldSuffix : public ASTSuffix {
- ASTFieldSuffix(Position position, std::string field)
+ ASTFieldSuffix(Position position, SkString field)
: INHERITED(position, ASTSuffix::kField_Kind)
, fField(std::move(field)) {}
- std::string description() const override {
+ SkString description() const override {
return "." + fField;
}
- std::string fField;
+ SkString fField;
typedef ASTSuffix INHERITED;
};
: INHERITED(position, kFloat_Kind)
, fValue(value) {}
- std::string description() const override {
+ SkString description() const override {
return to_string(fValue);
}
, fNext(std::move(next))
, fStatement(std::move(statement)) {}
- std::string description() const override {
- std::string result = "for (";
+ SkString description() const override {
+ SkString result("for (");
if (fInitializer) {
result.append(fInitializer->description());
}
* A function declaration or definition. The fBody field will be null for declarations.
*/
struct ASTFunction : public ASTDeclaration {
- ASTFunction(Position position, std::unique_ptr<ASTType> returnType, std::string name,
+ ASTFunction(Position position, std::unique_ptr<ASTType> returnType, SkString name,
std::vector<std::unique_ptr<ASTParameter>> parameters,
std::unique_ptr<ASTBlock> body)
: INHERITED(position, kFunction_Kind)
, fParameters(std::move(parameters))
, fBody(std::move(body)) {}
- std::string description() const override {
- std::string result = fReturnType->description() + " " + fName + "(";
+ SkString description() const override {
+ SkString result = fReturnType->description() + " " + fName + "(";
for (size_t i = 0; i < fParameters.size(); i++) {
if (i > 0) {
result += ", ";
}
const std::unique_ptr<ASTType> fReturnType;
- const std::string fName;
+ const SkString fName;
const std::vector<std::unique_ptr<ASTParameter>> fParameters;
const std::unique_ptr<ASTBlock> fBody;
* An identifier in an expression context.
*/
struct ASTIdentifier : public ASTExpression {
- ASTIdentifier(Position position, std::string text)
+ ASTIdentifier(Position position, SkString text)
: INHERITED(position, kIdentifier_Kind)
, fText(std::move(text)) {}
- std::string description() const override {
+ SkString description() const override {
return fText;
}
- const std::string fText;
+ const SkString fText;
typedef ASTExpression INHERITED;
};
, fIfTrue(std::move(ifTrue))
, fIfFalse(std::move(ifFalse)) {}
- std::string description() const override {
- std::string result("if (");
+ SkString description() const override {
+ SkString result("if (");
result += fTest->description();
result += ") ";
result += fIfTrue->description();
: INHERITED(expression ? expression->fPosition : Position(), ASTSuffix::kIndex_Kind)
, fExpression(std::move(expression)) {}
- std::string description() const override {
+ SkString description() const override {
if (fExpression) {
return "[" + fExpression->description() + "]";
} else {
- return "[]";
+ return SkString("[]");
}
}
: INHERITED(position, kInt_Kind)
, fValue(value) {}
- std::string description() const override {
+ SkString description() const override {
return to_string(fValue);
}
// valueName is empty when it was not present in the source
ASTInterfaceBlock(Position position,
ASTModifiers modifiers,
- std::string interfaceName,
- std::string valueName,
+ SkString interfaceName,
+ SkString valueName,
std::vector<std::unique_ptr<ASTVarDeclarations>> declarations)
: INHERITED(position, kInterfaceBlock_Kind)
, fModifiers(modifiers)
, fValueName(std::move(valueName))
, fDeclarations(std::move(declarations)) {}
- std::string description() const override {
- std::string result = fModifiers.description() + fInterfaceName + " {\n";
+ SkString description() const override {
+ SkString result = fModifiers.description() + fInterfaceName + " {\n";
for (size_t i = 0; i < fDeclarations.size(); i++) {
result += fDeclarations[i]->description() + "\n";
}
result += "}";
- if (fValueName.length()) {
+ if (fValueName.size()) {
result += " " + fValueName;
}
return result + ";";
}
const ASTModifiers fModifiers;
- const std::string fInterfaceName;
- const std::string fValueName;
+ const SkString fInterfaceName;
+ const SkString fValueName;
const std::vector<std::unique_ptr<ASTVarDeclarations>> fDeclarations;
typedef ASTDeclaration INHERITED;
return "";
}
- static bool ReadFormat(std::string str, Format* format) {
+ static bool ReadFormat(SkString str, Format* format) {
if (str == "rgba32f") {
*format = Format::kRGBA32F;
return true;
, fBlendSupportAllEquations(blendSupportAllEquations)
, fFormat(format) {}
- std::string description() const {
- std::string result;
- std::string separator;
+ SkString description() const {
+ SkString result;
+ SkString separator;
if (fLocation >= 0) {
result += separator + "location = " + to_string(fLocation);
separator = ", ";
result += separator + FormatToStr(fFormat);
separator = ", ";
}
- if (result.length() > 0) {
+ if (result.size() > 0) {
result = "layout (" + result + ")";
}
return result;
: fLayout(layout)
, fFlags(flags) {}
- std::string description() const override {
- std::string result = fLayout.description();
+ SkString description() const override {
+ SkString result = fLayout.description();
if (fFlags & kUniform_Flag) {
result += "uniform ";
}
: INHERITED(Position(), kModifiers_Kind)
, fModifiers(modifiers) {}
- std::string description() const {
+ SkString description() const {
return fModifiers.description() + ";";
}
#ifndef SKSL_ASTNODE
#define SKSL_ASTNODE
-#include <memory>
-#include <string>
+#include "SkString.h"
namespace SkSL {
struct ASTNode {
virtual ~ASTNode() {}
- virtual std::string description() const = 0;
+ virtual SkString description() const = 0;
};
} // namespace
// 'sizes' is a list of the array sizes appearing on a parameter, in source order.
// e.g. int x[3][1] would have sizes [3, 1].
ASTParameter(Position position, ASTModifiers modifiers, std::unique_ptr<ASTType> type,
- std::string name, std::vector<int> sizes)
+ SkString name, std::vector<int> sizes)
: INHERITED(position)
, fModifiers(modifiers)
, fType(std::move(type))
, fName(std::move(name))
, fSizes(std::move(sizes)) {}
- std::string description() const override {
- std::string result = fModifiers.description() + fType->description() + " " + fName;
+ SkString description() const override {
+ SkString result = fModifiers.description() + fType->description() + " " + fName;
for (int size : fSizes) {
result += "[" + to_string(size) + "]";
}
const ASTModifiers fModifiers;
const std::unique_ptr<ASTType> fType;
- const std::string fName;
+ const SkString fName;
const std::vector<int> fSizes;
typedef ASTPositionNode INHERITED;
: INHERITED(position, kPrecision_Kind)
, fPrecision(precision) {}
- std::string description() const {
+ SkString description() const {
switch (fPrecision) {
- case Modifiers::kLowp_Flag: return "precision lowp float;";
- case Modifiers::kMediump_Flag: return "precision mediump float;";
- case Modifiers::kHighp_Flag: return "precision highp float;";
+ case Modifiers::kLowp_Flag: return SkString("precision lowp float;");
+ case Modifiers::kMediump_Flag: return SkString("precision mediump float;");
+ case Modifiers::kHighp_Flag: return SkString("precision highp float;");
default:
ASSERT(false);
- return "<error>";
+ return SkString("<error>");
}
ASSERT(false);
- return "<error>";
+ return SkString("<error>");
}
const Modifiers::Flag fPrecision;
, fOperator(op.fKind)
, fOperand(std::move(operand)) {}
- std::string description() const override {
+ SkString description() const override {
return Token::OperatorName(fOperator) + fOperand->description();
}
: INHERITED(position, kReturn_Kind)
, fExpression(std::move(expression)) {}
- std::string description() const override {
- std::string result("return");
+ SkString description() const override {
+ SkString result("return");
if (fExpression) {
result += " " + fExpression->description();
}
: INHERITED(position)
, fKind(kind) {}
- std::string description() const override {
+ SkString description() const override {
switch (fKind) {
case kPostIncrement_Kind:
- return "++";
+ return SkString("++");
case kPostDecrement_Kind:
- return "--";
+ return SkString("--");
default:
ABORT("unsupported suffix operator");
}
, fBase(std::move(base))
, fSuffix(std::move(suffix)) {}
- std::string description() const override {
+ SkString description() const override {
return fBase->description() + fSuffix->description();
}
, fIfTrue(std::move(ifTrue))
, fIfFalse(std::move(ifFalse)) {}
- std::string description() const override {
+ SkString description() const override {
return "(" + fTest->description() + " ? " + fIfTrue->description() + " : " +
fIfFalse->description() + ")";
}
kStruct_Kind
};
- ASTType(Position position, std::string name, Kind kind)
+ ASTType(Position position, SkString name, Kind kind)
: INHERITED(position)
, fName(std::move(name))
, fKind(kind) {}
- std::string description() const override {
+ SkString description() const override {
return fName;
}
- const std::string fName;
+ const SkString fName;
const Kind fKind;
* instances.
*/
struct ASTVarDeclaration {
- ASTVarDeclaration(const std::string name,
+ ASTVarDeclaration(const SkString name,
std::vector<std::unique_ptr<ASTExpression>> sizes,
std::unique_ptr<ASTExpression> value)
: fName(name)
, fSizes(std::move(sizes))
, fValue(std::move(value)) {}
- std::string description() const {
- std::string result = fName;
+ SkString description() const {
+ SkString result = fName;
for (const auto& size : fSizes) {
if (size) {
result += "[" + size->description() + "]";
return result;
}
- std::string fName;
+ SkString fName;
// array sizes, if any. e.g. 'foo[3][]' has sizes [3, null]
std::vector<std::unique_ptr<ASTExpression>> fSizes;
, fType(std::move(type))
, fVars(std::move(vars)) {}
- std::string description() const override {
- std::string result = fModifiers.description() + fType->description() + " ";
- std::string separator = "";
+ SkString description() const override {
+ SkString result = fModifiers.description() + fType->description() + " ";
+ SkString separator;
for (const auto& var : fVars) {
result += separator;
separator = ", ";
: INHERITED(decl->fPosition, kVarDeclaration_Kind)
, fDeclarations(std::move(decl)) {}
- std::string description() const override {
+ SkString description() const override {
return fDeclarations->description() + ";";
}
, fTest(std::move(test))
, fStatement(std::move(statement)) {}
- std::string description() const override {
+ SkString description() const override {
return "while (" + fTest->description() + ") " + fStatement->description();
}
, fOperator(op)
, fRight(std::move(right)) {}
- virtual std::string description() const override {
+ virtual SkString description() const override {
return "(" + fLeft->description() + " " + Token::OperatorName(fOperator) + " " +
fRight->description() + ")";
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_BLOCK
#define SKSL_BLOCK
, fStatements(std::move(statements))
, fSymbols(std::move(symbols)) {}
- std::string description() const override {
- std::string result = "{";
+ SkString description() const override {
+ SkString result("{");
for (size_t i = 0; i < fStatements.size(); i++) {
result += "\n";
result += fStatements[i]->description();
}
result += "\n}\n";
- return result;
+ return result;
}
const std::vector<std::unique_ptr<Statement>> fStatements;
: INHERITED(position, kBoolLiteral_Kind, *context.fBool_Type)
, fValue(value) {}
- std::string description() const override {
- return fValue ? "true" : "false";
+ SkString description() const override {
+ return SkString(fValue ? "true" : "false");
}
bool isConstant() const override {
BreakStatement(Position position)
: INHERITED(position, kBreak_Kind) {}
- std::string description() const override {
- return "break;";
+ SkString description() const override {
+ return SkString("break;");
}
typedef Statement INHERITED;
: INHERITED(position, kConstructor_Kind, type)
, fArguments(std::move(arguments)) {}
- std::string description() const override {
- std::string result = fType.description() + "(";
- std::string separator = "";
+ SkString description() const override {
+ SkString result = fType.description() + "(";
+ SkString separator;
for (size_t i = 0; i < fArguments.size(); i++) {
result += separator;
result += fArguments[i]->description();
ContinueStatement(Position position)
: INHERITED(position, kContinue_Kind) {}
- std::string description() const override {
- return "continue;";
+ SkString description() const override {
+ return SkString("continue;");
}
typedef Statement INHERITED;
DiscardStatement(Position position)
: INHERITED(position, kDiscard_Kind) {}
- std::string description() const override {
- return "discard;";
+ SkString description() const override {
+ return SkString("discard;");
}
typedef Statement INHERITED;
, fStatement(std::move(statement))
, fTest(std::move(test)) {}
- std::string description() const override {
+ SkString description() const override {
return "do " + fStatement->description() + " while (" + fTest->description() + ");";
}
: INHERITED(expression->fPosition, kExpression_Kind)
, fExpression(std::move(expression)) {}
- std::string description() const override {
+ SkString description() const override {
return fExpression->description() + ";";
}
* An extension declaration.
*/
struct Extension : public ProgramElement {
- Extension(Position position, std::string name)
+ Extension(Position position, SkString name)
: INHERITED(position, kExtension_Kind)
, fName(std::move(name)) {}
- std::string description() const override {
+ SkString description() const override {
return "#extension " + fName + " : enable";
}
- const std::string fName;
+ const SkString fName;
typedef ProgramElement INHERITED;
};
, fOwner(owner)
, fFieldIndex(fieldIndex) {}
- virtual std::string description() const override {
+ virtual SkString description() const override {
return fOwner.description() + "." + fOwner.fType.fields()[fFieldIndex].fName;
}
, fFieldIndex(fieldIndex)
, fOwnerKind(ownerKind) {}
- virtual std::string description() const override {
+ virtual SkString description() const override {
return fBase->description() + "." + fBase->fType.fields()[fFieldIndex].fName;
}
: INHERITED(position, kFloatLiteral_Kind, *context.fFloat_Type)
, fValue(value) {}
- virtual std::string description() const override {
+ virtual SkString description() const override {
return to_string(fValue);
}
, fStatement(std::move(statement))
, fSymbols(symbols) {}
- std::string description() const override {
- std::string result = "for (";
+ SkString description() const override {
+ SkString result("for (");
if (fInitializer) {
result += fInitializer->description();
}
, fFunction(std::move(function))
, fArguments(std::move(arguments)) {}
- std::string description() const override {
- std::string result = fFunction.fName + "(";
- std::string separator = "";
+ SkString description() const override {
+ SkString result = fFunction.fName + "(";
+ SkString separator;
for (size_t i = 0; i < fArguments.size(); i++) {
result += separator;
result += fArguments[i]->description();
* A function declaration (not a definition -- does not contain a body).
*/
struct FunctionDeclaration : public Symbol {
- FunctionDeclaration(Position position, std::string name,
+ FunctionDeclaration(Position position, SkString name,
std::vector<const Variable*> parameters, const Type& returnType)
: INHERITED(position, kFunctionDeclaration_Kind, std::move(name))
, fDefined(false)
, fParameters(std::move(parameters))
, fReturnType(returnType) {}
- std::string description() const override {
- std::string result = fReturnType.description() + " " + fName + "(";
- std::string separator = "";
+ SkString description() const override {
+ SkString result = fReturnType.description() + " " + fName + "(";
+ SkString separator;
for (auto p : fParameters) {
result += separator;
separator = ", ";
, fDeclaration(declaration)
, fBody(std::move(body)) {}
- std::string description() const override {
+ SkString description() const override {
return fDeclaration.description() + " " + fBody->description();
}
: INHERITED(position, kFunctionReference_Kind, *context.fInvalid_Type)
, fFunctions(function) {}
- virtual std::string description() const override {
+ virtual SkString description() const override {
ASSERT(false);
- return "<function>";
+ return SkString("<function>");
}
const std::vector<const FunctionDeclaration*> fFunctions;
virtual ~IRNode() {}
- virtual std::string description() const = 0;
+ virtual SkString description() const = 0;
const Position fPosition;
};
, fIfTrue(std::move(ifTrue))
, fIfFalse(std::move(ifFalse)) {}
- std::string description() const override {
- std::string result = "if (" + fTest->description() + ") " + fIfTrue->description();
+ SkString description() const override {
+ SkString result = "if (" + fTest->description() + ") " + fIfTrue->description();
if (fIfFalse) {
result += " else " + fIfFalse->description();
}
ASSERT(fIndex->fType == *context.fInt_Type || fIndex->fType == *context.fUInt_Type);
}
- std::string description() const override {
+ SkString description() const override {
return fBase->description() + "[" + fIndex->description() + "]";
}
: INHERITED(position, kIntLiteral_Kind, type ? *type : *context.fInt_Type)
, fValue(value) {}
- virtual std::string description() const override {
+ virtual SkString description() const override {
return to_string(fValue);
}
ASSERT(fVariable.fType.kind() == Type::kStruct_Kind);
}
- std::string description() const override {
- std::string result = fVariable.fModifiers.description() + fVariable.fName + " {\n";
+ SkString description() const override {
+ SkString result = fVariable.fModifiers.description() + fVariable.fName + " {\n";
for (size_t i = 0; i < fVariable.fType.fields().size(); i++) {
result += fVariable.fType.fields()[i].description() + "\n";
}
, fBlendSupportAllEquations(false)
, fFormat(ASTLayout::Format::kUnspecified) {}
- std::string description() const {
- std::string result;
- std::string separator;
+ SkString description() const {
+ SkString result;
+ SkString separator;
if (fLocation >= 0) {
result += separator + "location = " + to_string(fLocation);
separator = ", ";
result += separator + ASTLayout::FormatToStr(fFormat);
separator = ", ";
}
- if (result.length() > 0) {
+ if (result.size() > 0) {
result = "layout (" + result + ")";
}
return result;
: fLayout(layout)
, fFlags(flags) {}
- std::string description() const {
- std::string result = fLayout.description();
+ SkString description() const {
+ SkString result = fLayout.description();
if (fFlags & kUniform_Flag) {
result += "uniform ";
}
: INHERITED(Position(), kModifiers_Kind)
, fModifiers(modifiers) {}
- std::string description() const {
+ SkString description() const {
return fModifiers.description() + ";";
}
, fOperand(std::move(operand))
, fOperator(op) {}
- virtual std::string description() const override {
+ virtual SkString description() const override {
return fOperand->description() + Token::OperatorName(fOperator);
}
, fOperand(std::move(operand))
, fOperator(op) {}
- virtual std::string description() const override {
+ virtual SkString description() const override {
return Token::OperatorName(fOperator) + fOperand->description();
}
: INHERITED(expression->fPosition, kReturn_Kind)
, fExpression(std::move(expression)) {}
- std::string description() const override {
+ SkString description() const override {
if (fExpression) {
return "return " + fExpression->description() + ";";
} else {
- return "return;";
+ return SkString("return;");
}
}
ASSERT(fComponents.size() >= 1 && fComponents.size() <= 4);
}
- std::string description() const override {
- std::string result = fBase->description() + ".";
+ SkString description() const override {
+ SkString result = fBase->description() + ".";
for (int x : fComponents) {
result += "xyzw"[x];
}
kField_Kind
};
- Symbol(Position position, Kind kind, std::string name)
+ Symbol(Position position, Kind kind, SkString name)
: INHERITED(position)
, fKind(kind)
, fName(std::move(name)) {}
const Kind fKind;
- const std::string fName;
+ const SkString fName;
typedef IRNode INHERITED;
};
}
}
-const Symbol* SymbolTable::operator[](const std::string& name) {
+const Symbol* SymbolTable::operator[](const SkString& name) {
const auto& entry = fSymbols.find(name);
if (entry == fSymbols.end()) {
if (fParent) {
return s;
}
-void SymbolTable::add(const std::string& name, std::unique_ptr<Symbol> symbol) {
+void SymbolTable::add(const SkString& name, std::unique_ptr<Symbol> symbol) {
this->addWithoutOwnership(name, symbol.get());
fOwnedPointers.push_back(std::move(symbol));
}
-void SymbolTable::addWithoutOwnership(const std::string& name, const Symbol* symbol) {
+void SymbolTable::addWithoutOwnership(const SkString& name, const Symbol* symbol) {
const auto& existing = fSymbols.find(name);
if (existing == fSymbols.end()) {
fSymbols[name] = symbol;
: fParent(parent)
, fErrorReporter(errorReporter) {}
- const Symbol* operator[](const std::string& name);
+ const Symbol* operator[](const SkString& name);
- void add(const std::string& name, std::unique_ptr<Symbol> symbol);
+ void add(const SkString& name, std::unique_ptr<Symbol> symbol);
- void addWithoutOwnership(const std::string& name, const Symbol* symbol);
+ void addWithoutOwnership(const SkString& name, const Symbol* symbol);
Symbol* takeOwnership(Symbol* s);
std::vector<std::unique_ptr<Symbol>> fOwnedPointers;
- std::unordered_map<std::string, const Symbol*> fSymbols;
+ std::unordered_map<SkString, const Symbol*> fSymbols;
ErrorReporter& fErrorReporter;
};
ASSERT(fIfTrue->fType == fIfFalse->fType);
}
- std::string description() const override {
+ SkString description() const override {
return "(" + fTest->description() + " ? " + fIfTrue->description() + " : " +
fIfFalse->description() + ")";
}
class Type : public Symbol {
public:
struct Field {
- Field(Modifiers modifiers, std::string name, const Type* type)
+ Field(Modifiers modifiers, SkString name, const Type* type)
: fModifiers(modifiers)
, fName(std::move(name))
, fType(std::move(type)) {}
- const std::string description() const {
+ const SkString description() const {
return fType->description() + " " + fName + ";";
}
Modifiers fModifiers;
- std::string fName;
+ SkString fName;
const Type* fType;
};
// Create an "other" (special) type with the given name. These types cannot be directly
// referenced from user code.
- Type(std::string name)
+ Type(SkString name)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kOther_Kind) {}
// Create a generic type which maps to the listed types. As currently implemented, there are
// always exactly four coercion targets, mapping to the scalar, vec2, vec3, and vec4 versions of
// a type.
- Type(std::string name, std::vector<const Type*> types)
+ Type(SkString name, std::vector<const Type*> types)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kGeneric_Kind)
, fCoercibleTypes(std::move(types)) {
}
// Create a struct type with the given fields.
- Type(std::string name, std::vector<Field> fields)
+ Type(SkString name, std::vector<Field> fields)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kStruct_Kind)
, fFields(std::move(fields)) {}
// Create a scalar type.
- Type(std::string name, bool isNumber)
+ Type(SkString name, bool isNumber)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kScalar_Kind)
, fIsNumber(isNumber)
, fRows(1) {}
// Create a scalar type which can be coerced to the listed types.
- Type(std::string name, bool isNumber, std::vector<const Type*> coercibleTypes)
+ Type(SkString name, bool isNumber, std::vector<const Type*> coercibleTypes)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kScalar_Kind)
, fIsNumber(isNumber)
, fRows(1) {}
// Create a vector type.
- Type(std::string name, const Type& componentType, int columns)
+ Type(SkString name, const Type& componentType, int columns)
: Type(name, kVector_Kind, componentType, columns) {}
// Create a vector or array type.
- Type(std::string name, Kind kind, const Type& componentType, int columns)
+ Type(SkString name, Kind kind, const Type& componentType, int columns)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kind)
, fComponentType(&componentType)
, fDimensions(SpvDim1D) {}
// Create a matrix type.
- Type(std::string name, const Type& componentType, int columns, int rows)
+ Type(SkString name, const Type& componentType, int columns, int rows)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kMatrix_Kind)
, fComponentType(&componentType)
, fDimensions(SpvDim1D) {}
// Create a sampler type.
- Type(std::string name, SpvDim_ dimensions, bool isDepth, bool isArrayed, bool isMultisampled,
+ Type(SkString name, SpvDim_ dimensions, bool isDepth, bool isArrayed, bool isMultisampled,
bool isSampled)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kSampler_Kind)
, fIsMultisampled(isMultisampled)
, fIsSampled(isSampled) {}
- std::string name() const {
+ SkString name() const {
return fName;
}
- std::string description() const override {
+ SkString description() const override {
return fName;
}
: INHERITED(position, kTypeReference_Kind, *context.fInvalid_Type)
, fValue(type) {}
- std::string description() const override {
+ SkString description() const override {
return fValue.name();
}
#endif
}
- virtual std::string description() const override {
+ virtual SkString description() const override {
return fName;
}
, fSizes(std::move(sizes))
, fValue(std::move(value)) {}
- std::string description() const {
- std::string result = fVar->fName;
+ SkString description() const {
+ SkString result = fVar->fName;
for (const auto& size : fSizes) {
if (size) {
result += "[" + size->description() + "]";
, fBaseType(*baseType)
, fVars(std::move(vars)) {}
- std::string description() const override {
+ SkString description() const override {
if (!fVars.size()) {
- return "";
+ return SkString();
}
- std::string result = fVars[0].fVar->fModifiers.description() + fBaseType.description() +
- " ";
- std::string separator = "";
+ SkString result = fVars[0].fVar->fModifiers.description() + fBaseType.description() + " ";
+ SkString separator;
for (const auto& var : fVars) {
result += separator;
separator = ", ";
: INHERITED(decl->fPosition, kVarDeclarations_Kind)
, fDeclaration(std::move(decl)) {}
- std::string description() const override {
+ SkString description() const override {
return fDeclaration->description();
}
kParameter_Storage
};
- Variable(Position position, Modifiers modifiers, std::string name, const Type& type,
+ Variable(Position position, Modifiers modifiers, SkString name, const Type& type,
Storage storage)
: INHERITED(position, kVariable_Kind, std::move(name))
, fModifiers(modifiers)
, fIsReadFrom(false)
, fIsWrittenTo(false) {}
- virtual std::string description() const override {
+ virtual SkString description() const override {
return fModifiers.description() + fType.fName + " " + fName;
}
: INHERITED(position, kVariableReference_Kind, variable.fType)
, fVariable(variable) {}
- std::string description() const override {
+ SkString description() const override {
return fVariable.fName;
}
, fTest(std::move(test))
, fStatement(std::move(statement)) {}
- std::string description() const override {
+ SkString description() const override {
return "while (" + fTest->description() + ") " + fStatement->description();
}
#include "Test.h"
-#if SKIA_SUPPORT_GPU
+#if SK_SUPPORT_GPU
static void test_failure(skiatest::Reporter* r, const char* src, const char* error) {
SkSL::Compiler compiler;
- std::stringstream out;
- bool result = compiler.toSPIRV(SkSL::Program::kFragment_Kind, src, out);
- if (compiler.errorText() != error) {
+ SkDynamicMemoryWStream out;
+ bool result = compiler.toSPIRV(SkSL::Program::kFragment_Kind, SkString(src), out);
+ SkString 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, !result);
- REPORTER_ASSERT(r, compiler.errorText() == error);
+ REPORTER_ASSERT(r, compiler.errorText() == skError);
}
static void test_success(skiatest::Reporter* r, const char* src) {
SkSL::Compiler compiler;
- std::stringstream out;
- bool result = compiler.toSPIRV(SkSL::Program::kFragment_Kind, src, out);
+ SkDynamicMemoryWStream out;
+ bool result = compiler.toSPIRV(SkSL::Program::kFragment_Kind, SkString(src), out);
REPORTER_ASSERT(r, result);
}
#include "Test.h"
-#if SKIA_SUPPORT_GPU
+#if SK_SUPPORT_GPU
static void test(skiatest::Reporter* r, const char* src, const GrGLSLCaps& caps,
const char* expected) {
SkSL::Compiler compiler;
- std::string output;
- bool result = compiler.toGLSL(SkSL::Program::kFragment_Kind, src, caps, &output);
+ SkString output;
+ bool result = compiler.toGLSL(SkSL::Program::kFragment_Kind, SkString(src), caps, &output);
if (!result) {
SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().c_str());
}
REPORTER_ASSERT(r, result);
if (result) {
- if (output != expected) {
+ SkString skExpected(expected);
+ if (output != skExpected) {
SkDebugf("GLSL MISMATCH:\nsource:\n%s\n\nexpected:\n'%s'\n\nreceived:\n'%s'", src,
expected, output.c_str());
}
- REPORTER_ASSERT(r, output == expected);
+ REPORTER_ASSERT(r, output == skExpected);
}
}
"if (sqrt(2) > 5) { sk_FragColor = vec4(0.75); } else { discard; }"
"int i = 0;"
"while (i < 10) sk_FragColor *= 0.5;"
- "do { sk_FragColor += 0.01; } while (sk_FragColor.x < 0.7);"
+ "do { sk_FragColor += 0.01; } while (sk_FragColor.x < 0.75);"
"for (int i = 0; i < 10; i++) {"
"if (i % 0 == 1) break; else continue;"
"}"
" while (i < 10) sk_FragColor *= 0.5;\n"
" do {\n"
" sk_FragColor += 0.01;\n"
- " } while (sk_FragColor.x < 0.7);\n"
+ " } while (sk_FragColor.x < 0.75);\n"
" for (int i = 0;i < 10; i++) {\n"
" if (i % 0 == 1) break; else continue;\n"
" }\n"