| 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 <stack> | 11 #include <stack> |
| 12 #include <tuple> | 12 #include <tuple> |
| 13 #include <unordered_map> | 13 #include <unordered_map> |
| 14 | 14 |
| 15 #include "SkStream.h" | 15 #include "SkStream.h" |
| 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(SkWStream& out) = 0; | 60 virtual SpvId load(SkWStream& out) = 0; |
| 60 | 61 |
| 61 virtual void store(SpvId value, SkWStream& out) = 0; | 62 virtual void store(SpvId value, SkWStream& 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, SkWStream& out) override; | 76 void generateCode(const Program& program, SkWStream& out) override; |
| 75 | 77 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 87 kTextureProj_SpecialIntrinsic, | 89 kTextureProj_SpecialIntrinsic, |
| 88 kSubpassLoad_SpecialIntrinsic, | 90 kSubpassLoad_SpecialIntrinsic, |
| 89 }; | 91 }; |
| 90 | 92 |
| 91 void setupIntrinsics(); | 93 void setupIntrinsics(); |
| 92 | 94 |
| 93 SpvId nextId(); | 95 SpvId nextId(); |
| 94 | 96 |
| 95 SpvId getType(const Type& type); | 97 SpvId getType(const Type& type); |
| 96 | 98 |
| 99 SpvId getType(const Type& type, const MemoryLayout& layout); |
| 100 |
| 97 SpvId getFunctionType(const FunctionDeclaration& function); | 101 SpvId getFunctionType(const FunctionDeclaration& function); |
| 98 | 102 |
| 99 SpvId getPointerType(const Type& type, SpvStorageClass_ storageClass); | 103 SpvId getPointerType(const Type& type, SpvStorageClass_ storageClass); |
| 100 | 104 |
| 105 SpvId getPointerType(const Type& type, const MemoryLayout& layout, |
| 106 SpvStorageClass_ storageClass); |
| 107 |
| 101 std::vector<SpvId> getAccessChain(const Expression& expr, SkWStream& out); | 108 std::vector<SpvId> getAccessChain(const Expression& expr, SkWStream& out); |
| 102 | 109 |
| 103 void writeLayout(const Layout& layout, SpvId target); | 110 void writeLayout(const Layout& layout, SpvId target); |
| 104 | 111 |
| 105 void writeLayout(const Layout& layout, SpvId target, int member); | 112 void writeLayout(const Layout& layout, SpvId target, int member); |
| 106 | 113 |
| 107 void writeStruct(const Type& type, SpvId resultId); | 114 void writeStruct(const Type& type, const MemoryLayout& layout, SpvId resultI
d); |
| 108 | 115 |
| 109 void writeProgramElement(const ProgramElement& pe, SkWStream& out); | 116 void writeProgramElement(const ProgramElement& pe, SkWStream& out); |
| 110 | 117 |
| 111 SpvId writeInterfaceBlock(const InterfaceBlock& intf); | 118 SpvId writeInterfaceBlock(const InterfaceBlock& intf); |
| 112 | 119 |
| 113 SpvId writeFunctionStart(const FunctionDeclaration& f, SkWStream& out); | 120 SpvId writeFunctionStart(const FunctionDeclaration& f, SkWStream& out); |
| 114 | 121 |
| 115 SpvId writeFunctionDeclaration(const FunctionDeclaration& f, SkWStream& out)
; | 122 SpvId writeFunctionDeclaration(const FunctionDeclaration& f, SkWStream& out)
; |
| 116 | 123 |
| 117 SpvId writeFunction(const FunctionDefinition& f, SkWStream& out); | 124 SpvId writeFunction(const FunctionDefinition& f, SkWStream& out); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 int32_t word5, int32_t word6, SkWStream& out); | 230 int32_t word5, int32_t word6, SkWStream& out); |
| 224 | 231 |
| 225 void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t w
ord3, int32_t word4, | 232 void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t w
ord3, int32_t word4, |
| 226 int32_t word5, int32_t word6, int32_t word7, SkWStream
& out); | 233 int32_t word5, int32_t word6, int32_t word7, SkWStream
& out); |
| 227 | 234 |
| 228 void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t w
ord3, int32_t word4, | 235 void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t w
ord3, int32_t word4, |
| 229 int32_t word5, int32_t word6, int32_t word7, int32_t w
ord8, | 236 int32_t word5, int32_t word6, int32_t word7, int32_t w
ord8, |
| 230 SkWStream& out); | 237 SkWStream& out); |
| 231 | 238 |
| 232 const Context& fContext; | 239 const Context& fContext; |
| 240 const MemoryLayout fDefaultLayout; |
| 233 | 241 |
| 234 uint64_t fCapabilities; | 242 uint64_t fCapabilities; |
| 235 SpvId fIdCount; | 243 SpvId fIdCount; |
| 236 SpvId fGLSLExtendedInstructions; | 244 SpvId fGLSLExtendedInstructions; |
| 237 typedef std::tuple<IntrinsicKind, int32_t, int32_t, int32_t, int32_t> Intrin
sic; | 245 typedef std::tuple<IntrinsicKind, int32_t, int32_t, int32_t, int32_t> Intrin
sic; |
| 238 std::unordered_map<SkString, Intrinsic> fIntrinsicMap; | 246 std::unordered_map<SkString, Intrinsic> fIntrinsicMap; |
| 239 std::unordered_map<const FunctionDeclaration*, SpvId> fFunctionMap; | 247 std::unordered_map<const FunctionDeclaration*, SpvId> fFunctionMap; |
| 240 std::unordered_map<const Variable*, SpvId> fVariableMap; | 248 std::unordered_map<const Variable*, SpvId> fVariableMap; |
| 241 std::unordered_map<const Variable*, int32_t> fInterfaceBlockMap; | 249 std::unordered_map<const Variable*, int32_t> fInterfaceBlockMap; |
| 242 std::unordered_map<SkString, SpvId> fTypeMap; | 250 std::unordered_map<SkString, SpvId> fTypeMap; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 259 std::stack<SpvId> fBreakTarget; | 267 std::stack<SpvId> fBreakTarget; |
| 260 std::stack<SpvId> fContinueTarget; | 268 std::stack<SpvId> fContinueTarget; |
| 261 | 269 |
| 262 friend class PointerLValue; | 270 friend class PointerLValue; |
| 263 friend class SwizzleLValue; | 271 friend class SwizzleLValue; |
| 264 }; | 272 }; |
| 265 | 273 |
| 266 } | 274 } |
| 267 | 275 |
| 268 #endif | 276 #endif |
| OLD | NEW |