diff options
Diffstat (limited to 'src/sksl/SkSLSPIRVCodeGenerator.h')
-rw-r--r-- | src/sksl/SkSLSPIRVCodeGenerator.h | 147 |
1 files changed, 74 insertions, 73 deletions
diff --git a/src/sksl/SkSLSPIRVCodeGenerator.h b/src/sksl/SkSLSPIRVCodeGenerator.h index 656fb99e40..1cdc653c85 100644 --- a/src/sksl/SkSLSPIRVCodeGenerator.h +++ b/src/sksl/SkSLSPIRVCodeGenerator.h @@ -4,7 +4,7 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ - + #ifndef SKSL_SPIRVCODEGENERATOR #define SKSL_SPIRVCODEGENERATOR @@ -12,6 +12,7 @@ #include <tuple> #include <unordered_map> +#include "SkStream.h" #include "SkSLCodeGenerator.h" #include "SkSLMemoryLayout.h" #include "ir/SkSLBinaryExpression.h" @@ -58,13 +59,13 @@ public: // by a pointer (e.g. vector swizzles), returns 0. virtual SpvId getPointer() = 0; - virtual SpvId load(OutputStream& out) = 0; + virtual SpvId load(SkWStream& out) = 0; - virtual void store(SpvId value, OutputStream& out) = 0; + virtual void store(SpvId value, SkWStream& out) = 0; }; SPIRVCodeGenerator(const Context* context, const Program* program, ErrorReporter* errors, - OutputStream* out) + SkWStream* out) : INHERITED(program, errors, out) , fContext(*context) , fDefaultLayout(MemoryLayout::k140_Standard) @@ -107,7 +108,7 @@ private: SpvId getPointerType(const Type& type, const MemoryLayout& layout, SpvStorageClass_ storageClass); - std::vector<SpvId> getAccessChain(const Expression& expr, OutputStream& out); + std::vector<SpvId> getAccessChain(const Expression& expr, SkWStream& out); void writeLayout(const Layout& layout, SpvId target); @@ -115,43 +116,43 @@ private: void writeStruct(const Type& type, const MemoryLayout& layout, SpvId resultId); - void writeProgramElement(const ProgramElement& pe, OutputStream& out); + void writeProgramElement(const ProgramElement& pe, SkWStream& out); SpvId writeInterfaceBlock(const InterfaceBlock& intf); - SpvId writeFunctionStart(const FunctionDeclaration& f, OutputStream& out); - - SpvId writeFunctionDeclaration(const FunctionDeclaration& f, OutputStream& out); - - SpvId writeFunction(const FunctionDefinition& f, OutputStream& out); + SpvId writeFunctionStart(const FunctionDeclaration& f, SkWStream& out); + + SpvId writeFunctionDeclaration(const FunctionDeclaration& f, SkWStream& out); - void writeGlobalVars(Program::Kind kind, const VarDeclarations& v, OutputStream& out); + SpvId writeFunction(const FunctionDefinition& f, SkWStream& out); - void writeVarDeclarations(const VarDeclarations& decl, OutputStream& out); + void writeGlobalVars(Program::Kind kind, const VarDeclarations& v, SkWStream& out); - SpvId writeVariableReference(const VariableReference& ref, OutputStream& out); + void writeVarDeclarations(const VarDeclarations& decl, SkWStream& out); - std::unique_ptr<LValue> getLValue(const Expression& value, OutputStream& out); + SpvId writeVariableReference(const VariableReference& ref, SkWStream& out); - SpvId writeExpression(const Expression& expr, OutputStream& out); + std::unique_ptr<LValue> getLValue(const Expression& value, SkWStream& out); - SpvId writeIntrinsicCall(const FunctionCall& c, OutputStream& out); + SpvId writeExpression(const Expression& expr, SkWStream& out); + + SpvId writeIntrinsicCall(const FunctionCall& c, SkWStream& out); - SpvId writeFunctionCall(const FunctionCall& c, OutputStream& out); + SpvId writeFunctionCall(const FunctionCall& c, SkWStream& out); - SpvId writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind, OutputStream& out); + SpvId writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind, SkWStream& out); SpvId writeConstantVector(const Constructor& c); - SpvId writeFloatConstructor(const Constructor& c, OutputStream& out); + SpvId writeFloatConstructor(const Constructor& c, SkWStream& out); - SpvId writeIntConstructor(const Constructor& c, OutputStream& out); + SpvId writeIntConstructor(const Constructor& c, SkWStream& out); /** * Writes a matrix with the diagonal entries all equal to the provided expression, and all other * entries equal to zero. */ - void writeUniformScaleMatrix(SpvId id, SpvId diagonal, const Type& type, OutputStream& out); + void writeUniformScaleMatrix(SpvId id, SpvId diagonal, const Type& type, SkWStream& out); /** * Writes a potentially-different-sized copy of a matrix. Entries which do not exist in the @@ -159,17 +160,17 @@ private: * ignored. */ void writeMatrixCopy(SpvId id, SpvId src, const Type& srcType, const Type& dstType, - OutputStream& out); + SkWStream& out); - SpvId writeMatrixConstructor(const Constructor& c, OutputStream& out); + SpvId writeMatrixConstructor(const Constructor& c, SkWStream& out); - SpvId writeVectorConstructor(const Constructor& c, OutputStream& out); + SpvId writeVectorConstructor(const Constructor& c, SkWStream& out); - SpvId writeConstructor(const Constructor& c, OutputStream& out); + SpvId writeConstructor(const Constructor& c, SkWStream& out); - SpvId writeFieldAccess(const FieldAccess& f, OutputStream& out); + SpvId writeFieldAccess(const FieldAccess& f, SkWStream& out); - SpvId writeSwizzle(const Swizzle& swizzle, OutputStream& out); + SpvId writeSwizzle(const Swizzle& swizzle, SkWStream& out); /** * Folds the potentially-vector result of a logical operation down to a single bool. If @@ -177,28 +178,28 @@ private: * same dimensions, and applys all() to it to fold it down to a single bool value. Otherwise, * returns the original id value. */ - SpvId foldToBool(SpvId id, const Type& operandType, OutputStream& out); + SpvId foldToBool(SpvId id, const Type& operandType, SkWStream& out); SpvId writeBinaryOperation(const Type& resultType, const Type& operandType, SpvId lhs, SpvId rhs, SpvOp_ ifFloat, SpvOp_ ifInt, SpvOp_ ifUInt, - SpvOp_ ifBool, OutputStream& out); + SpvOp_ ifBool, SkWStream& out); SpvId writeBinaryOperation(const BinaryExpression& expr, SpvOp_ ifFloat, SpvOp_ ifInt, - SpvOp_ ifUInt, OutputStream& out); + SpvOp_ ifUInt, SkWStream& out); - SpvId writeBinaryExpression(const BinaryExpression& b, OutputStream& out); + SpvId writeBinaryExpression(const BinaryExpression& b, SkWStream& out); - SpvId writeTernaryExpression(const TernaryExpression& t, OutputStream& out); + SpvId writeTernaryExpression(const TernaryExpression& t, SkWStream& out); - SpvId writeIndexExpression(const IndexExpression& expr, OutputStream& out); + SpvId writeIndexExpression(const IndexExpression& expr, SkWStream& out); - SpvId writeLogicalAnd(const BinaryExpression& b, OutputStream& out); + SpvId writeLogicalAnd(const BinaryExpression& b, SkWStream& out); - SpvId writeLogicalOr(const BinaryExpression& o, OutputStream& out); + SpvId writeLogicalOr(const BinaryExpression& o, SkWStream& out); - SpvId writePrefixExpression(const PrefixExpression& p, OutputStream& out); + SpvId writePrefixExpression(const PrefixExpression& p, SkWStream& out); - SpvId writePostfixExpression(const PostfixExpression& p, OutputStream& out); + SpvId writePostfixExpression(const PostfixExpression& p, SkWStream& out); SpvId writeBoolLiteral(const BoolLiteral& b); @@ -206,63 +207,63 @@ private: SpvId writeFloatLiteral(const FloatLiteral& f); - void writeStatement(const Statement& s, OutputStream& out); + void writeStatement(const Statement& s, SkWStream& out); - void writeBlock(const Block& b, OutputStream& out); + void writeBlock(const Block& b, SkWStream& out); - void writeIfStatement(const IfStatement& stmt, OutputStream& out); + void writeIfStatement(const IfStatement& stmt, SkWStream& out); - void writeForStatement(const ForStatement& f, OutputStream& out); + void writeForStatement(const ForStatement& f, SkWStream& out); - void writeWhileStatement(const WhileStatement& w, OutputStream& out); + void writeWhileStatement(const WhileStatement& w, SkWStream& out); - void writeDoStatement(const DoStatement& d, OutputStream& out); + void writeDoStatement(const DoStatement& d, SkWStream& out); - void writeReturnStatement(const ReturnStatement& r, OutputStream& out); + void writeReturnStatement(const ReturnStatement& r, SkWStream& out); - void writeCapabilities(OutputStream& out); + void writeCapabilities(SkWStream& out); - void writeInstructions(const Program& program, OutputStream& out); + void writeInstructions(const Program& program, SkWStream& out); - void writeOpCode(SpvOp_ opCode, int length, OutputStream& out); + void writeOpCode(SpvOp_ opCode, int length, SkWStream& out); - void writeWord(int32_t word, OutputStream& out); + void writeWord(int32_t word, SkWStream& out); - void writeString(const char* string, OutputStream& out); + void writeString(const char* string, SkWStream& out); - void writeLabel(SpvId id, OutputStream& out); + void writeLabel(SpvId id, SkWStream& out); - void writeInstruction(SpvOp_ opCode, OutputStream& out); + void writeInstruction(SpvOp_ opCode, SkWStream& out); - void writeInstruction(SpvOp_ opCode, const char* string, OutputStream& out); + void writeInstruction(SpvOp_ opCode, const char* string, SkWStream& out); - void writeInstruction(SpvOp_ opCode, int32_t word1, OutputStream& out); + void writeInstruction(SpvOp_ opCode, int32_t word1, SkWStream& out); - void writeInstruction(SpvOp_ opCode, int32_t word1, const char* string, OutputStream& 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, - OutputStream& out); + SkWStream& out); - void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, OutputStream& 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, - OutputStream& out); + SkWStream& out); void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, - OutputStream& out); + SkWStream& out); void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, - int32_t word5, OutputStream& 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, OutputStream& 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, OutputStream& 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, - OutputStream& out); + SkWStream& out); const Context& fContext; const MemoryLayout fDefaultLayout; @@ -271,19 +272,19 @@ private: SpvId fIdCount; SpvId fGLSLExtendedInstructions; typedef std::tuple<IntrinsicKind, int32_t, int32_t, int32_t, int32_t> Intrinsic; - std::unordered_map<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<String, SpvId> fTypeMap; - StringStream fCapabilitiesBuffer; - StringStream fGlobalInitializersBuffer; - StringStream fConstantBuffer; - StringStream fExtraGlobalsBuffer; - StringStream fExternalFunctionsBuffer; - StringStream fVariableBuffer; - StringStream fNameBuffer; - StringStream fDecorationBuffer; + std::unordered_map<SkString, SpvId> fTypeMap; + SkDynamicMemoryWStream fCapabilitiesBuffer; + SkDynamicMemoryWStream fGlobalInitializersBuffer; + SkDynamicMemoryWStream fConstantBuffer; + SkDynamicMemoryWStream fExtraGlobalsBuffer; + SkDynamicMemoryWStream fExternalFunctionsBuffer; + SkDynamicMemoryWStream fVariableBuffer; + SkDynamicMemoryWStream fNameBuffer; + SkDynamicMemoryWStream fDecorationBuffer; SpvId fBoolTrue; SpvId fBoolFalse; |