| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SKSL_SPIRVCODEGENERATOR | 8 #ifndef SKSL_SPIRVCODEGENERATOR |
| 9 #define SKSL_SPIRVCODEGENERATOR | 9 #define SKSL_SPIRVCODEGENERATOR |
| 10 | 10 |
| 11 #include <sstream> | 11 #include <sstream> |
| 12 #include <stack> | 12 #include <stack> |
| 13 #include <tuple> | 13 #include <tuple> |
| 14 #include <unordered_map> | 14 #include <unordered_map> |
| 15 | 15 |
| 16 #include "SkSLCodeGenerator.h" | 16 #include "SkSLCodeGenerator.h" |
| 17 #include "SkSLMemoryLayout.h" |
| 17 #include "ir/SkSLBinaryExpression.h" | 18 #include "ir/SkSLBinaryExpression.h" |
| 18 #include "ir/SkSLBoolLiteral.h" | 19 #include "ir/SkSLBoolLiteral.h" |
| 19 #include "ir/SkSLConstructor.h" | 20 #include "ir/SkSLConstructor.h" |
| 20 #include "ir/SkSLFloatLiteral.h" | 21 #include "ir/SkSLFloatLiteral.h" |
| 21 #include "ir/SkSLIfStatement.h" | 22 #include "ir/SkSLIfStatement.h" |
| 22 #include "ir/SkSLIndexExpression.h" | 23 #include "ir/SkSLIndexExpression.h" |
| 23 #include "ir/SkSLInterfaceBlock.h" | 24 #include "ir/SkSLInterfaceBlock.h" |
| 24 #include "ir/SkSLIntLiteral.h" | 25 #include "ir/SkSLIntLiteral.h" |
| 25 #include "ir/SkSLFieldAccess.h" | 26 #include "ir/SkSLFieldAccess.h" |
| 26 #include "ir/SkSLForStatement.h" | 27 #include "ir/SkSLForStatement.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 56 // by a pointer (e.g. vector swizzles), returns 0. | 57 // by a pointer (e.g. vector swizzles), returns 0. |
| 57 virtual SpvId getPointer() = 0; | 58 virtual SpvId getPointer() = 0; |
| 58 | 59 |
| 59 virtual SpvId load(std::ostream& out) = 0; | 60 virtual SpvId load(std::ostream& out) = 0; |
| 60 | 61 |
| 61 virtual void store(SpvId value, std::ostream& out) = 0; | 62 virtual void store(SpvId value, std::ostream& out) = 0; |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 SPIRVCodeGenerator(const Context* context) | 65 SPIRVCodeGenerator(const Context* context) |
| 65 : fContext(*context) | 66 : fContext(*context) |
| 67 , fDefaultLayout(MemoryLayout::k140_Standard) |
| 66 , fCapabilities(1 << SpvCapabilityShader) | 68 , fCapabilities(1 << SpvCapabilityShader) |
| 67 , fIdCount(1) | 69 , fIdCount(1) |
| 68 , fBoolTrue(0) | 70 , fBoolTrue(0) |
| 69 , fBoolFalse(0) | 71 , fBoolFalse(0) |
| 70 , fCurrentBlock(0) { | 72 , fCurrentBlock(0) { |
| 71 this->setupIntrinsics(); | 73 this->setupIntrinsics(); |
| 72 } | 74 } |
| 73 | 75 |
| 74 void generateCode(const Program& program, std::ostream& out) override; | 76 void generateCode(const Program& program, std::ostream& out) override; |
| 75 | 77 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 86 kTexture2D_SpecialIntrinsic, | 88 kTexture2D_SpecialIntrinsic, |
| 87 kTextureProj_SpecialIntrinsic | 89 kTextureProj_SpecialIntrinsic |
| 88 }; | 90 }; |
| 89 | 91 |
| 90 void setupIntrinsics(); | 92 void setupIntrinsics(); |
| 91 | 93 |
| 92 SpvId nextId(); | 94 SpvId nextId(); |
| 93 | 95 |
| 94 SpvId getType(const Type& type); | 96 SpvId getType(const Type& type); |
| 95 | 97 |
| 98 SpvId getType(const Type& type, const MemoryLayout& layout); |
| 99 |
| 96 SpvId getFunctionType(const FunctionDeclaration& function); | 100 SpvId getFunctionType(const FunctionDeclaration& function); |
| 97 | 101 |
| 98 SpvId getPointerType(const Type& type, SpvStorageClass_ storageClass); | 102 SpvId getPointerType(const Type& type, SpvStorageClass_ storageClass); |
| 99 | 103 |
| 104 SpvId getPointerType(const Type& type, const MemoryLayout& layout, |
| 105 SpvStorageClass_ storageClass); |
| 106 |
| 100 std::vector<SpvId> getAccessChain(const Expression& expr, std::ostream& out)
; | 107 std::vector<SpvId> getAccessChain(const Expression& expr, std::ostream& out)
; |
| 101 | 108 |
| 102 void writeLayout(const Layout& layout, SpvId target); | 109 void writeLayout(const Layout& layout, SpvId target); |
| 103 | 110 |
| 104 void writeLayout(const Layout& layout, SpvId target, int member); | 111 void writeLayout(const Layout& layout, SpvId target, int member); |
| 105 | 112 |
| 106 void writeStruct(const Type& type, SpvId resultId); | 113 void writeStruct(const Type& type, const MemoryLayout& layout, SpvId resultI
d); |
| 107 | 114 |
| 108 void writeProgramElement(const ProgramElement& pe, std::ostream& out); | 115 void writeProgramElement(const ProgramElement& pe, std::ostream& out); |
| 109 | 116 |
| 110 SpvId writeInterfaceBlock(const InterfaceBlock& intf); | 117 SpvId writeInterfaceBlock(const InterfaceBlock& intf); |
| 111 | 118 |
| 112 SpvId writeFunctionStart(const FunctionDeclaration& f, std::ostream& out); | 119 SpvId writeFunctionStart(const FunctionDeclaration& f, std::ostream& out); |
| 113 | 120 |
| 114 SpvId writeFunctionDeclaration(const FunctionDeclaration& f, std::ostream& o
ut); | 121 SpvId writeFunctionDeclaration(const FunctionDeclaration& f, std::ostream& o
ut); |
| 115 | 122 |
| 116 SpvId writeFunction(const FunctionDefinition& f, std::ostream& out); | 123 SpvId writeFunction(const FunctionDefinition& f, std::ostream& out); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 int32_t word5, int32_t word6, std::ostream& out); | 229 int32_t word5, int32_t word6, std::ostream& out); |
| 223 | 230 |
| 224 void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t w
ord3, int32_t word4, | 231 void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t w
ord3, int32_t word4, |
| 225 int32_t word5, int32_t word6, int32_t word7, std::ostr
eam& out); | 232 int32_t word5, int32_t word6, int32_t word7, std::ostr
eam& out); |
| 226 | 233 |
| 227 void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t w
ord3, int32_t word4, | 234 void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t w
ord3, int32_t word4, |
| 228 int32_t word5, int32_t word6, int32_t word7, int32_t w
ord8, | 235 int32_t word5, int32_t word6, int32_t word7, int32_t w
ord8, |
| 229 std::ostream& out); | 236 std::ostream& out); |
| 230 | 237 |
| 231 const Context& fContext; | 238 const Context& fContext; |
| 239 const MemoryLayout fDefaultLayout; |
| 232 | 240 |
| 233 uint64_t fCapabilities; | 241 uint64_t fCapabilities; |
| 234 SpvId fIdCount; | 242 SpvId fIdCount; |
| 235 SpvId fGLSLExtendedInstructions; | 243 SpvId fGLSLExtendedInstructions; |
| 236 typedef std::tuple<IntrinsicKind, int32_t, int32_t, int32_t, int32_t> Intrin
sic; | 244 typedef std::tuple<IntrinsicKind, int32_t, int32_t, int32_t, int32_t> Intrin
sic; |
| 237 std::unordered_map<std::string, Intrinsic> fIntrinsicMap; | 245 std::unordered_map<std::string, Intrinsic> fIntrinsicMap; |
| 238 std::unordered_map<const FunctionDeclaration*, SpvId> fFunctionMap; | 246 std::unordered_map<const FunctionDeclaration*, SpvId> fFunctionMap; |
| 239 std::unordered_map<const Variable*, SpvId> fVariableMap; | 247 std::unordered_map<const Variable*, SpvId> fVariableMap; |
| 240 std::unordered_map<const Variable*, int32_t> fInterfaceBlockMap; | 248 std::unordered_map<const Variable*, int32_t> fInterfaceBlockMap; |
| 241 std::unordered_map<std::string, SpvId> fTypeMap; | 249 std::unordered_map<std::string, SpvId> fTypeMap; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 258 std::stack<SpvId> fBreakTarget; | 266 std::stack<SpvId> fBreakTarget; |
| 259 std::stack<SpvId> fContinueTarget; | 267 std::stack<SpvId> fContinueTarget; |
| 260 | 268 |
| 261 friend class PointerLValue; | 269 friend class PointerLValue; |
| 262 friend class SwizzleLValue; | 270 friend class SwizzleLValue; |
| 263 }; | 271 }; |
| 264 | 272 |
| 265 } | 273 } |
| 266 | 274 |
| 267 #endif | 275 #endif |
| OLD | NEW |