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 | d8df21a | 2016-11-17 16:13:37 -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() {} |
| 54 | |
| 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 | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 59 | virtual SpvId load(SkWStream& out) = 0; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 60 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -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 | d8df21a | 2016-11-17 16:13:37 -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, |
| 87 | kTextureProj_SpecialIntrinsic |
| 88 | }; |
| 89 | |
| 90 | void setupIntrinsics(); |
| 91 | |
| 92 | SpvId nextId(); |
| 93 | |
| 94 | SpvId getType(const Type& type); |
| 95 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 96 | SpvId getFunctionType(const FunctionDeclaration& function); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 97 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 98 | SpvId getPointerType(const Type& type, SpvStorageClass_ storageClass); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 99 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 100 | std::vector<SpvId> getAccessChain(const Expression& expr, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 101 | |
| 102 | void writeLayout(const Layout& layout, SpvId target); |
| 103 | |
| 104 | void writeLayout(const Layout& layout, SpvId target, int member); |
| 105 | |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 106 | void writeStruct(const Type& type, SpvId resultId); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 107 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 108 | void writeProgramElement(const ProgramElement& pe, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 109 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 110 | SpvId writeInterfaceBlock(const InterfaceBlock& intf); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 111 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 112 | SpvId writeFunctionStart(const FunctionDeclaration& f, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 113 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 114 | SpvId writeFunctionDeclaration(const FunctionDeclaration& f, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 115 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 116 | SpvId writeFunction(const FunctionDefinition& f, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 117 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 118 | void writeGlobalVars(Program::Kind kind, const VarDeclarations& v, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 119 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 120 | void writeVarDeclarations(const VarDeclarations& decl, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 121 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 122 | SpvId writeVariableReference(const VariableReference& ref, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 123 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 124 | std::unique_ptr<LValue> getLValue(const Expression& value, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 125 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 126 | SpvId writeExpression(const Expression& expr, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 127 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 128 | SpvId writeIntrinsicCall(const FunctionCall& c, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 129 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 130 | SpvId writeFunctionCall(const FunctionCall& c, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 131 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 132 | SpvId writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 133 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 134 | SpvId writeConstantVector(const Constructor& c); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 135 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 136 | SpvId writeFloatConstructor(const Constructor& c, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 137 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 138 | SpvId writeIntConstructor(const Constructor& c, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 139 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 140 | SpvId writeMatrixConstructor(const Constructor& c, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 141 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 142 | SpvId writeVectorConstructor(const Constructor& c, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 143 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 144 | SpvId writeConstructor(const Constructor& c, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 145 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 146 | SpvId writeFieldAccess(const FieldAccess& f, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 147 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 148 | SpvId writeSwizzle(const Swizzle& swizzle, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 149 | |
| 150 | SpvId writeBinaryOperation(const Type& resultType, const Type& operandType, SpvId lhs, |
| 151 | SpvId rhs, SpvOp_ ifFloat, SpvOp_ ifInt, SpvOp_ ifUInt, |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 152 | SpvOp_ ifBool, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 153 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 154 | SpvId writeBinaryOperation(const BinaryExpression& expr, SpvOp_ ifFloat, SpvOp_ ifInt, |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 155 | SpvOp_ ifUInt, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 156 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 157 | SpvId writeBinaryExpression(const BinaryExpression& b, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 158 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 159 | SpvId writeTernaryExpression(const TernaryExpression& t, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 160 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 161 | SpvId writeIndexExpression(const IndexExpression& expr, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 162 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 163 | SpvId writeLogicalAnd(const BinaryExpression& b, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 164 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 165 | SpvId writeLogicalOr(const BinaryExpression& o, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 166 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 167 | SpvId writePrefixExpression(const PrefixExpression& p, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 168 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 169 | SpvId writePostfixExpression(const PostfixExpression& p, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 170 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 171 | SpvId writeBoolLiteral(const BoolLiteral& b); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 172 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 173 | SpvId writeIntLiteral(const IntLiteral& i); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 174 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 175 | SpvId writeFloatLiteral(const FloatLiteral& f); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 176 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 177 | void writeStatement(const Statement& s, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 178 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 179 | void writeBlock(const Block& b, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 180 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 181 | void writeIfStatement(const IfStatement& stmt, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 182 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 183 | void writeForStatement(const ForStatement& f, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 184 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 185 | void writeReturnStatement(const ReturnStatement& r, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 186 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 187 | void writeCapabilities(SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 188 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 189 | void writeInstructions(const Program& program, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 190 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 191 | void writeOpCode(SpvOp_ opCode, int length, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 192 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 193 | void writeWord(int32_t word, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 194 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 195 | void writeString(const char* string, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 196 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 197 | void writeLabel(SpvId id, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 198 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 199 | void writeInstruction(SpvOp_ opCode, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 200 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 201 | void writeInstruction(SpvOp_ opCode, const char* string, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 202 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 203 | void writeInstruction(SpvOp_ opCode, int32_t word1, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 204 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 205 | void writeInstruction(SpvOp_ opCode, int32_t word1, const char* string, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 206 | |
| 207 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, const char* string, |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 208 | SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 209 | |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 210 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 211 | |
| 212 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 213 | SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 214 | |
| 215 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 216 | SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 217 | |
| 218 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 219 | int32_t word5, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 220 | |
| 221 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 222 | int32_t word5, int32_t word6, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 223 | |
| 224 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 225 | int32_t word5, int32_t word6, int32_t word7, SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 226 | |
| 227 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, |
| 228 | int32_t word5, int32_t word6, int32_t word7, int32_t word8, |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 229 | SkWStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 230 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 231 | const Context& fContext; |
| 232 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 233 | uint64_t fCapabilities; |
| 234 | SpvId fIdCount; |
| 235 | SpvId fGLSLExtendedInstructions; |
| 236 | typedef std::tuple<IntrinsicKind, int32_t, int32_t, int32_t, int32_t> Intrinsic; |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 237 | std::unordered_map<SkString, Intrinsic> fIntrinsicMap; |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 238 | std::unordered_map<const FunctionDeclaration*, SpvId> fFunctionMap; |
| 239 | std::unordered_map<const Variable*, SpvId> fVariableMap; |
| 240 | std::unordered_map<const Variable*, int32_t> fInterfaceBlockMap; |
Ethan Nicholas | d8df21a | 2016-11-17 16:13:37 -0500 | [diff] [blame^] | 241 | std::unordered_map<SkString, SpvId> fTypeMap; |
| 242 | SkDynamicMemoryWStream fCapabilitiesBuffer; |
| 243 | SkDynamicMemoryWStream fGlobalInitializersBuffer; |
| 244 | SkDynamicMemoryWStream fConstantBuffer; |
| 245 | SkDynamicMemoryWStream fExternalFunctionsBuffer; |
| 246 | SkDynamicMemoryWStream fVariableBuffer; |
| 247 | SkDynamicMemoryWStream fNameBuffer; |
| 248 | SkDynamicMemoryWStream fDecorationBuffer; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 249 | |
| 250 | SpvId fBoolTrue; |
| 251 | SpvId fBoolFalse; |
| 252 | std::unordered_map<int64_t, SpvId> fIntConstants; |
| 253 | std::unordered_map<uint64_t, SpvId> fUIntConstants; |
| 254 | std::unordered_map<float, SpvId> fFloatConstants; |
| 255 | std::unordered_map<double, SpvId> fDoubleConstants; |
| 256 | // label of the current block, or 0 if we are not in a block |
| 257 | SpvId fCurrentBlock; |
| 258 | std::stack<SpvId> fBreakTarget; |
| 259 | std::stack<SpvId> fContinueTarget; |
| 260 | |
| 261 | friend class PointerLValue; |
| 262 | friend class SwizzleLValue; |
| 263 | }; |
| 264 | |
| 265 | } |
| 266 | |
| 267 | #endif |