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 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 11 | #include <sstream> |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 12 | #include <stack> |
| 13 | #include <tuple> |
| 14 | #include <unordered_map> |
| 15 | |
| 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 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 59 | virtual SpvId load(std::ostream& out) = 0; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 60 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 61 | virtual void store(SpvId value, std::ostream& 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 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 74 | void generateCode(const Program& program, std::ostream& 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 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 100 | std::vector<SpvId> getAccessChain(const Expression& expr, std::ostream& 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 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 108 | void writeProgramElement(const ProgramElement& pe, std::ostream& 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 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 112 | SpvId writeFunctionStart(const FunctionDeclaration& f, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 113 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 114 | SpvId writeFunctionDeclaration(const FunctionDeclaration& f, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 115 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 116 | SpvId writeFunction(const FunctionDefinition& f, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 117 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 118 | void writeGlobalVars(Program::Kind kind, const VarDeclarations& v, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 119 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 120 | void writeVarDeclarations(const VarDeclarations& decl, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 121 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 122 | SpvId writeVariableReference(const VariableReference& ref, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 123 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 124 | std::unique_ptr<LValue> getLValue(const Expression& value, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 125 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 126 | SpvId writeExpression(const Expression& expr, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 127 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 128 | SpvId writeIntrinsicCall(const FunctionCall& c, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 129 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 130 | SpvId writeFunctionCall(const FunctionCall& c, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 131 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 132 | SpvId writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind, std::ostream& 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 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 136 | SpvId writeFloatConstructor(const Constructor& c, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 137 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 138 | SpvId writeIntConstructor(const Constructor& c, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 139 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 140 | SpvId writeMatrixConstructor(const Constructor& c, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 141 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 142 | SpvId writeVectorConstructor(const Constructor& c, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 143 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 144 | SpvId writeConstructor(const Constructor& c, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 145 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 146 | SpvId writeFieldAccess(const FieldAccess& f, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 147 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 148 | SpvId writeSwizzle(const Swizzle& swizzle, std::ostream& 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, |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 152 | SpvOp_ ifBool, std::ostream& 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, |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 155 | SpvOp_ ifUInt, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 156 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 157 | SpvId writeBinaryExpression(const BinaryExpression& b, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 158 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 159 | SpvId writeTernaryExpression(const TernaryExpression& t, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 160 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 161 | SpvId writeIndexExpression(const IndexExpression& expr, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 162 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 163 | SpvId writeLogicalAnd(const BinaryExpression& b, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 164 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 165 | SpvId writeLogicalOr(const BinaryExpression& o, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 166 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 167 | SpvId writePrefixExpression(const PrefixExpression& p, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 168 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 169 | SpvId writePostfixExpression(const PostfixExpression& p, std::ostream& 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 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 177 | void writeStatement(const Statement& s, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 178 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 179 | void writeBlock(const Block& b, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 180 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 181 | void writeIfStatement(const IfStatement& stmt, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 182 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 183 | void writeForStatement(const ForStatement& f, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 184 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 185 | void writeReturnStatement(const ReturnStatement& r, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 186 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 187 | void writeCapabilities(std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 188 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 189 | void writeInstructions(const Program& program, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 190 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 191 | void writeOpCode(SpvOp_ opCode, int length, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 192 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 193 | void writeWord(int32_t word, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 194 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 195 | void writeString(const char* string, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 196 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 197 | void writeLabel(SpvId id, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 198 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 199 | void writeInstruction(SpvOp_ opCode, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 200 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 201 | void writeInstruction(SpvOp_ opCode, const char* string, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 202 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 203 | void writeInstruction(SpvOp_ opCode, int32_t word1, std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 204 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 205 | void writeInstruction(SpvOp_ opCode, int32_t word1, const char* string, std::ostream& 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, |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 208 | std::ostream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 209 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 210 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, std::ostream& 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, |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 213 | std::ostream& 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, |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 216 | std::ostream& 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, |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 219 | int32_t word5, std::ostream& 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, |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 222 | int32_t word5, int32_t word6, std::ostream& 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, |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 225 | int32_t word5, int32_t word6, int32_t word7, std::ostream& 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, |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 229 | std::ostream& 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; |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 237 | std::unordered_map<std::string, 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; |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 241 | std::unordered_map<std::string, SpvId> fTypeMap; |
| 242 | std::stringstream fCapabilitiesBuffer; |
| 243 | std::stringstream fGlobalInitializersBuffer; |
| 244 | std::stringstream fConstantBuffer; |
| 245 | std::stringstream fExternalFunctionsBuffer; |
| 246 | std::stringstream fVariableBuffer; |
| 247 | std::stringstream fNameBuffer; |
| 248 | std::stringstream 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 |