ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SKSL_SPIRVCODEGENERATOR |
| 9 | #define SKSL_SPIRVCODEGENERATOR |
| 10 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 11 | #include <stack> |
| 12 | #include <tuple> |
| 13 | #include <unordered_map> |
| 14 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 15 | #include "SkStream.h" |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 16 | #include "SkSLCodeGenerator.h" |
| 17 | #include "ir/SkSLBinaryExpression.h" |
| 18 | #include "ir/SkSLBoolLiteral.h" |
| 19 | #include "ir/SkSLConstructor.h" |
| 20 | #include "ir/SkSLFloatLiteral.h" |
| 21 | #include "ir/SkSLIfStatement.h" |
| 22 | #include "ir/SkSLIndexExpression.h" |
| 23 | #include "ir/SkSLInterfaceBlock.h" |
| 24 | #include "ir/SkSLIntLiteral.h" |
| 25 | #include "ir/SkSLFieldAccess.h" |
| 26 | #include "ir/SkSLForStatement.h" |
| 27 | #include "ir/SkSLFunctionCall.h" |
| 28 | #include "ir/SkSLFunctionDeclaration.h" |
| 29 | #include "ir/SkSLFunctionDefinition.h" |
| 30 | #include "ir/SkSLPrefixExpression.h" |
| 31 | #include "ir/SkSLPostfixExpression.h" |
| 32 | #include "ir/SkSLProgramElement.h" |
| 33 | #include "ir/SkSLReturnStatement.h" |
| 34 | #include "ir/SkSLStatement.h" |
| 35 | #include "ir/SkSLSwizzle.h" |
| 36 | #include "ir/SkSLTernaryExpression.h" |
ethannicholas | 22f939e | 2016-10-13 13:25:34 -0700 | [diff] [blame] | 37 | #include "ir/SkSLVarDeclarations.h" |
| 38 | #include "ir/SkSLVarDeclarationsStatement.h" |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 39 | #include "ir/SkSLVariableReference.h" |
| 40 | #include "spirv.h" |
| 41 | |
| 42 | namespace SkSL { |
| 43 | |
| 44 | #define kLast_Capability SpvCapabilityMultiViewport |
| 45 | |
| 46 | /** |
| 47 | * Converts a Program into a SPIR-V binary. |
| 48 | */ |
| 49 | class SPIRVCodeGenerator : public CodeGenerator { |
| 50 | public: |
| 51 | class LValue { |
| 52 | public: |
| 53 | virtual ~LValue() {} |
Greg Daniel | 64773e6 | 2016-11-22 09:44:03 -0500 | [diff] [blame^] | 54 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 55 | // returns a pointer to the lvalue, if possible. If the lvalue cannot be directly referenced |
| 56 | // by a pointer (e.g. vector swizzles), returns 0. |
| 57 | virtual SpvId getPointer() = 0; |
| 58 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 59 | virtual SpvId load(SkWStream& out) = 0; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 60 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 61 | virtual void store(SpvId value, SkWStream& out) = 0; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 64 | SPIRVCodeGenerator(const Context* context) |
| 65 | : fContext(*context) |
| 66 | , fCapabilities(1 << SpvCapabilityShader) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 67 | , fIdCount(1) |
| 68 | , fBoolTrue(0) |
| 69 | , fBoolFalse(0) |
| 70 | , fCurrentBlock(0) { |
| 71 | this->setupIntrinsics(); |
| 72 | } |
| 73 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 74 | void generateCode(const Program& program, SkWStream& out) override; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 75 | |
| 76 | private: |
| 77 | enum IntrinsicKind { |
| 78 | kGLSL_STD_450_IntrinsicKind, |
| 79 | kSPIRV_IntrinsicKind, |
| 80 | kSpecial_IntrinsicKind |
| 81 | }; |
| 82 | |
| 83 | enum SpecialIntrinsic { |
| 84 | kAtan_SpecialIntrinsic, |
| 85 | kTexture_SpecialIntrinsic, |
| 86 | kTexture2D_SpecialIntrinsic, |
Greg Daniel | 64773e6 | 2016-11-22 09:44:03 -0500 | [diff] [blame^] | 87 | kTextureProj_SpecialIntrinsic, |
| 88 | kSubpassLoad_SpecialIntrinsic, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | void setupIntrinsics(); |
| 92 | |
| 93 | SpvId nextId(); |
| 94 | |
| 95 | SpvId getType(const Type& type); |
| 96 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 97 | SpvId getFunctionType(const FunctionDeclaration& function); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 98 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 99 | SpvId getPointerType(const Type& type, SpvStorageClass_ storageClass); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 100 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 101 | std::vector<SpvId> getAccessChain(const Expression& expr, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 102 | |
| 103 | void writeLayout(const Layout& layout, SpvId target); |
| 104 | |
| 105 | void writeLayout(const Layout& layout, SpvId target, int member); |
| 106 | |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 107 | void writeStruct(const Type& type, SpvId resultId); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 108 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 109 | void writeProgramElement(const ProgramElement& pe, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 110 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 111 | SpvId writeInterfaceBlock(const InterfaceBlock& intf); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 112 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 113 | SpvId writeFunctionStart(const FunctionDeclaration& f, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 114 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 115 | SpvId writeFunctionDeclaration(const FunctionDeclaration& f, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 116 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 117 | SpvId writeFunction(const FunctionDefinition& f, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 118 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 119 | void writeGlobalVars(Program::Kind kind, const VarDeclarations& v, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 120 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 121 | void writeVarDeclarations(const VarDeclarations& decl, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 122 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 123 | SpvId writeVariableReference(const VariableReference& ref, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 124 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 125 | std::unique_ptr<LValue> getLValue(const Expression& value, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 126 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 127 | SpvId writeExpression(const Expression& expr, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 128 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 129 | SpvId writeIntrinsicCall(const FunctionCall& c, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 130 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 131 | SpvId writeFunctionCall(const FunctionCall& c, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 132 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 133 | SpvId writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 134 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 135 | SpvId writeConstantVector(const Constructor& c); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 136 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 137 | SpvId writeFloatConstructor(const Constructor& c, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 138 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 139 | SpvId writeIntConstructor(const Constructor& c, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 140 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 141 | SpvId writeMatrixConstructor(const Constructor& c, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 142 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 143 | SpvId writeVectorConstructor(const Constructor& c, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 144 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 145 | SpvId writeConstructor(const Constructor& c, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 146 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 147 | SpvId writeFieldAccess(const FieldAccess& f, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 148 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 149 | SpvId writeSwizzle(const Swizzle& swizzle, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 150 | |
| 151 | SpvId writeBinaryOperation(const Type& resultType, const Type& operandType, SpvId lhs, |
| 152 | SpvId rhs, SpvOp_ ifFloat, SpvOp_ ifInt, SpvOp_ ifUInt, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 153 | SpvOp_ ifBool, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 154 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 155 | SpvId writeBinaryOperation(const BinaryExpression& expr, SpvOp_ ifFloat, SpvOp_ ifInt, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 156 | SpvOp_ ifUInt, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 157 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 158 | SpvId writeBinaryExpression(const BinaryExpression& b, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 159 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 160 | SpvId writeTernaryExpression(const TernaryExpression& t, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 161 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 162 | SpvId writeIndexExpression(const IndexExpression& expr, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 163 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 164 | SpvId writeLogicalAnd(const BinaryExpression& b, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 165 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 166 | SpvId writeLogicalOr(const BinaryExpression& o, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 167 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 168 | SpvId writePrefixExpression(const PrefixExpression& p, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 169 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 170 | SpvId writePostfixExpression(const PostfixExpression& p, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 171 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 172 | SpvId writeBoolLiteral(const BoolLiteral& b); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 173 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 174 | SpvId writeIntLiteral(const IntLiteral& i); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 175 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 176 | SpvId writeFloatLiteral(const FloatLiteral& f); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 177 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 178 | void writeStatement(const Statement& s, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 179 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 180 | void writeBlock(const Block& b, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 181 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 182 | void writeIfStatement(const IfStatement& stmt, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 183 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 184 | void writeForStatement(const ForStatement& f, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 185 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 186 | void writeReturnStatement(const ReturnStatement& r, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 187 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 188 | void writeCapabilities(SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 189 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 190 | void writeInstructions(const Program& program, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 191 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 192 | void writeOpCode(SpvOp_ opCode, int length, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 193 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 194 | void writeWord(int32_t word, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 195 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 196 | void writeString(const char* string, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 197 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 198 | void writeLabel(SpvId id, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 199 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 200 | void writeInstruction(SpvOp_ opCode, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 201 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 202 | void writeInstruction(SpvOp_ opCode, const char* string, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 203 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 204 | void writeInstruction(SpvOp_ opCode, int32_t word1, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 205 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 206 | void writeInstruction(SpvOp_ opCode, int32_t word1, const char* string, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 207 | |
| 208 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, const char* string, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 209 | SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 210 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 211 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 212 | |
| 213 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 214 | SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 215 | |
| 216 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 217 | SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 218 | |
| 219 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 220 | int32_t word5, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 221 | |
| 222 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 223 | int32_t word5, int32_t word6, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 224 | |
| 225 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 226 | int32_t word5, int32_t word6, int32_t word7, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 227 | |
| 228 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, |
| 229 | int32_t word5, int32_t word6, int32_t word7, int32_t word8, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 230 | SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 231 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 232 | const Context& fContext; |
| 233 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 234 | uint64_t fCapabilities; |
| 235 | SpvId fIdCount; |
| 236 | SpvId fGLSLExtendedInstructions; |
| 237 | typedef std::tuple<IntrinsicKind, int32_t, int32_t, int32_t, int32_t> Intrinsic; |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 238 | std::unordered_map<SkString, Intrinsic> fIntrinsicMap; |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 239 | std::unordered_map<const FunctionDeclaration*, SpvId> fFunctionMap; |
| 240 | std::unordered_map<const Variable*, SpvId> fVariableMap; |
| 241 | std::unordered_map<const Variable*, int32_t> fInterfaceBlockMap; |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 242 | std::unordered_map<SkString, SpvId> fTypeMap; |
| 243 | SkDynamicMemoryWStream fCapabilitiesBuffer; |
| 244 | SkDynamicMemoryWStream fGlobalInitializersBuffer; |
| 245 | SkDynamicMemoryWStream fConstantBuffer; |
| 246 | SkDynamicMemoryWStream fExternalFunctionsBuffer; |
| 247 | SkDynamicMemoryWStream fVariableBuffer; |
| 248 | SkDynamicMemoryWStream fNameBuffer; |
| 249 | SkDynamicMemoryWStream fDecorationBuffer; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 250 | |
| 251 | SpvId fBoolTrue; |
| 252 | SpvId fBoolFalse; |
| 253 | std::unordered_map<int64_t, SpvId> fIntConstants; |
| 254 | std::unordered_map<uint64_t, SpvId> fUIntConstants; |
| 255 | std::unordered_map<float, SpvId> fFloatConstants; |
| 256 | std::unordered_map<double, SpvId> fDoubleConstants; |
| 257 | // label of the current block, or 0 if we are not in a block |
| 258 | SpvId fCurrentBlock; |
| 259 | std::stack<SpvId> fBreakTarget; |
| 260 | std::stack<SpvId> fContinueTarget; |
| 261 | |
| 262 | friend class PointerLValue; |
| 263 | friend class SwizzleLValue; |
| 264 | }; |
| 265 | |
| 266 | } |
| 267 | |
| 268 | #endif |