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 | */ |
Ethan Nicholas | 11d5397 | 2016-11-28 11:23:23 -0500 | [diff] [blame] | 7 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 8 | #ifndef SKSL_IRGENERATOR |
| 9 | #define SKSL_IRGENERATOR |
| 10 | |
John Stiles | ddefaee | 2020-08-11 15:13:26 -0400 | [diff] [blame] | 11 | #include <unordered_map> |
John Stiles | b8e010c | 2020-08-11 18:05:39 -0400 | [diff] [blame] | 12 | #include <unordered_set> |
Ethan Nicholas | db80f69 | 2019-11-22 14:06:12 -0500 | [diff] [blame] | 13 | |
Ethan Nicholas | daed259 | 2021-03-04 14:30:25 -0500 | [diff] [blame] | 14 | #include "include/private/SkSLModifiers.h" |
Ethan Nicholas | 24c1772 | 2021-03-09 13:10:59 -0500 | [diff] [blame] | 15 | #include "include/private/SkSLStatement.h" |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 16 | #include "src/sksl/SkSLASTFile.h" |
| 17 | #include "src/sksl/SkSLASTNode.h" |
Mike Klein | 4b432fa | 2019-06-06 11:44:05 -0500 | [diff] [blame] | 18 | #include "src/sksl/SkSLErrorReporter.h" |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 19 | #include "src/sksl/SkSLOperators.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "src/sksl/ir/SkSLBlock.h" |
| 21 | #include "src/sksl/ir/SkSLExpression.h" |
| 22 | #include "src/sksl/ir/SkSLExtension.h" |
| 23 | #include "src/sksl/ir/SkSLFunctionDefinition.h" |
| 24 | #include "src/sksl/ir/SkSLInterfaceBlock.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/sksl/ir/SkSLModifiersDeclaration.h" |
| 26 | #include "src/sksl/ir/SkSLProgram.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 27 | #include "src/sksl/ir/SkSLSymbolTable.h" |
| 28 | #include "src/sksl/ir/SkSLType.h" |
| 29 | #include "src/sksl/ir/SkSLTypeReference.h" |
| 30 | #include "src/sksl/ir/SkSLVarDeclarations.h" |
| 31 | #include "src/sksl/ir/SkSLVariableReference.h" |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 32 | |
| 33 | namespace SkSL { |
| 34 | |
Ethan Nicholas | 9504614 | 2021-01-07 10:57:27 -0500 | [diff] [blame] | 35 | namespace dsl { |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 36 | class DSLCore; |
Ethan Nicholas | 1ff7609 | 2021-01-28 10:02:43 -0500 | [diff] [blame] | 37 | class DSLFunction; |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 38 | class DSLVar; |
Ethan Nicholas | 9504614 | 2021-01-07 10:57:27 -0500 | [diff] [blame] | 39 | class DSLWriter; |
| 40 | } |
| 41 | |
Brian Osman | be0b3b7 | 2021-01-06 14:27:35 -0500 | [diff] [blame] | 42 | class ExternalFunction; |
Ethan Nicholas | 1e9f7f3 | 2020-10-08 05:28:32 -0400 | [diff] [blame] | 43 | class FunctionCall; |
John Stiles | dc75a97 | 2020-11-25 16:24:55 -0500 | [diff] [blame] | 44 | class StructDefinition; |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 45 | struct ParsedModule; |
Ethan Nicholas | cb0f409 | 2019-04-19 11:26:50 -0400 | [diff] [blame] | 46 | struct Swizzle; |
| 47 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 48 | /** |
John Stiles | 810c8cf | 2020-08-26 19:46:27 -0400 | [diff] [blame] | 49 | * Intrinsics are passed between the Compiler and the IRGenerator using IRIntrinsicMaps. |
| 50 | */ |
Brian Osman | 2b469eb | 2020-09-21 11:32:10 -0400 | [diff] [blame] | 51 | class IRIntrinsicMap { |
| 52 | public: |
| 53 | IRIntrinsicMap(IRIntrinsicMap* parent) : fParent(parent) {} |
| 54 | |
| 55 | void insertOrDie(String key, std::unique_ptr<ProgramElement> element) { |
| 56 | SkASSERT(fIntrinsics.find(key) == fIntrinsics.end()); |
| 57 | fIntrinsics[key] = Intrinsic{std::move(element), false}; |
| 58 | } |
| 59 | |
Brian Osman | afa18ee | 2020-10-07 17:47:45 -0400 | [diff] [blame] | 60 | const ProgramElement* find(const String& key) { |
| 61 | auto iter = fIntrinsics.find(key); |
| 62 | if (iter == fIntrinsics.end()) { |
| 63 | return fParent ? fParent->find(key) : nullptr; |
| 64 | } |
| 65 | return iter->second.fIntrinsic.get(); |
| 66 | } |
| 67 | |
Brian Osman | 2b469eb | 2020-09-21 11:32:10 -0400 | [diff] [blame] | 68 | // Only returns an intrinsic that isn't already marked as included, and then marks it. |
Brian Osman | 00a8b5b | 2020-10-02 09:06:04 -0400 | [diff] [blame] | 69 | const ProgramElement* findAndInclude(const String& key) { |
Brian Osman | 2b469eb | 2020-09-21 11:32:10 -0400 | [diff] [blame] | 70 | auto iter = fIntrinsics.find(key); |
| 71 | if (iter == fIntrinsics.end()) { |
| 72 | return fParent ? fParent->findAndInclude(key) : nullptr; |
| 73 | } |
| 74 | if (iter->second.fAlreadyIncluded) { |
| 75 | return nullptr; |
| 76 | } |
| 77 | iter->second.fAlreadyIncluded = true; |
| 78 | return iter->second.fIntrinsic.get(); |
| 79 | } |
| 80 | |
| 81 | void resetAlreadyIncluded() { |
| 82 | for (auto& pair : fIntrinsics) { |
| 83 | pair.second.fAlreadyIncluded = false; |
| 84 | } |
| 85 | if (fParent) { |
| 86 | fParent->resetAlreadyIncluded(); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | private: |
| 91 | struct Intrinsic { |
| 92 | std::unique_ptr<ProgramElement> fIntrinsic; |
| 93 | bool fAlreadyIncluded = false; |
| 94 | }; |
| 95 | |
| 96 | std::unordered_map<String, Intrinsic> fIntrinsics; |
| 97 | IRIntrinsicMap* fParent = nullptr; |
John Stiles | 810c8cf | 2020-08-26 19:46:27 -0400 | [diff] [blame] | 98 | }; |
John Stiles | 810c8cf | 2020-08-26 19:46:27 -0400 | [diff] [blame] | 99 | |
| 100 | /** |
Ethan Nicholas | 11d5397 | 2016-11-28 11:23:23 -0500 | [diff] [blame] | 101 | * Performs semantic analysis on an abstract syntax tree (AST) and produces the corresponding |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 102 | * (unoptimized) intermediate representation (IR). |
| 103 | */ |
| 104 | class IRGenerator { |
| 105 | public: |
John Stiles | c1a98b8 | 2021-02-24 13:35:02 -0500 | [diff] [blame] | 106 | IRGenerator(const Context* context); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 107 | |
Brian Osman | 88cda17 | 2020-10-09 12:05:16 -0400 | [diff] [blame] | 108 | struct IRBundle { |
| 109 | std::vector<std::unique_ptr<ProgramElement>> fElements; |
Brian Osman | 133724c | 2020-10-28 14:14:39 -0400 | [diff] [blame] | 110 | std::vector<const ProgramElement*> fSharedElements; |
Brian Osman | 88cda17 | 2020-10-09 12:05:16 -0400 | [diff] [blame] | 111 | std::shared_ptr<SymbolTable> fSymbolTable; |
| 112 | Program::Inputs fInputs; |
| 113 | }; |
| 114 | |
| 115 | /** |
John Stiles | aecf8d5 | 2021-05-14 12:15:01 -0400 | [diff] [blame] | 116 | * If externalFunctions is supplied, those values are registered in the symbol table of the |
Brian Osman | 88cda17 | 2020-10-09 12:05:16 -0400 | [diff] [blame] | 117 | * Program, but ownership is *not* transferred. It is up to the caller to keep them alive. |
| 118 | */ |
Brian Osman | be0b3b7 | 2021-01-06 14:27:35 -0500 | [diff] [blame] | 119 | IRBundle convertProgram( |
Brian Osman | be0b3b7 | 2021-01-06 14:27:35 -0500 | [diff] [blame] | 120 | const ParsedModule& base, |
| 121 | bool isBuiltinCode, |
Ethan Nicholas | 6823b50 | 2021-06-15 11:42:07 -0400 | [diff] [blame] | 122 | skstd::string_view text); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 123 | |
John Stiles | d120464 | 2021-02-17 16:30:02 -0500 | [diff] [blame] | 124 | const Program::Settings& settings() const { return fContext.fConfig->fSettings; } |
| 125 | ProgramKind programKind() const { return fContext.fConfig->fKind; } |
Brian Osman | 88cda17 | 2020-10-09 12:05:16 -0400 | [diff] [blame] | 126 | |
John Stiles | b30151e | 2021-01-11 16:13:08 -0500 | [diff] [blame] | 127 | ErrorReporter& errorReporter() const { return fContext.fErrors; } |
John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame] | 128 | |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 129 | std::shared_ptr<SymbolTable>& symbolTable() { |
| 130 | return fSymbolTable; |
| 131 | } |
| 132 | |
| 133 | void setSymbolTable(std::shared_ptr<SymbolTable>& symbolTable) { |
| 134 | fSymbolTable = symbolTable; |
| 135 | } |
| 136 | |
| 137 | void pushSymbolTable(); |
| 138 | void popSymbolTable(); |
| 139 | |
Ethan Nicholas | 371f6e1 | 2021-05-04 14:30:02 -0400 | [diff] [blame] | 140 | static void CheckModifiers(const Context& context, |
| 141 | int offset, |
| 142 | const Modifiers& modifiers, |
| 143 | int permittedModifierFlags, |
| 144 | int permittedLayoutFlags); |
| 145 | |
Ethan Nicholas | 962dec4 | 2021-06-10 13:06:39 -0400 | [diff] [blame] | 146 | std::unique_ptr<Expression> convertIdentifier(int offset, skstd::string_view identifier); |
Ethan Nicholas | 722cb67 | 2021-05-06 10:47:06 -0400 | [diff] [blame] | 147 | |
Ethan Nicholas | 86a4340 | 2017-01-19 13:32:00 -0500 | [diff] [blame] | 148 | const Context& fContext; |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 149 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 150 | private: |
Ethan Nicholas | 8b3dd34 | 2021-03-23 12:32:56 -0400 | [diff] [blame] | 151 | void start(const ParsedModule& base, |
| 152 | bool isBuiltinCode, |
Ethan Nicholas | 8b3dd34 | 2021-03-23 12:32:56 -0400 | [diff] [blame] | 153 | std::vector<std::unique_ptr<ProgramElement>>* elements, |
| 154 | std::vector<const ProgramElement*>* sharedElements); |
| 155 | |
| 156 | IRGenerator::IRBundle finish(); |
| 157 | |
Brian Osman | a654faa | 2021-02-26 11:52:59 -0500 | [diff] [blame] | 158 | void checkVarDeclaration(int offset, |
| 159 | const Modifiers& modifiers, |
| 160 | const Type* baseType, |
Ethan Nicholas | 489e552 | 2021-01-20 10:53:11 -0500 | [diff] [blame] | 161 | Variable::Storage storage); |
Ethan Nicholas | bd97400 | 2021-02-22 16:20:06 -0500 | [diff] [blame] | 162 | std::unique_ptr<Variable> convertVar(int offset, const Modifiers& modifiers, |
Ethan Nicholas | 962dec4 | 2021-06-10 13:06:39 -0400 | [diff] [blame] | 163 | const Type* baseType, skstd::string_view name, |
| 164 | bool isArray, std::unique_ptr<Expression> arraySize, |
Ethan Nicholas | bd97400 | 2021-02-22 16:20:06 -0500 | [diff] [blame] | 165 | Variable::Storage storage); |
| 166 | std::unique_ptr<Statement> convertVarDeclaration(std::unique_ptr<Variable> var, |
Ethan Nicholas | dd2fdea | 2021-07-20 15:23:04 -0400 | [diff] [blame] | 167 | std::unique_ptr<Expression> value, |
| 168 | bool addToSymbolTable = true); |
Ethan Nicholas | 489e552 | 2021-01-20 10:53:11 -0500 | [diff] [blame] | 169 | std::unique_ptr<Statement> convertVarDeclaration(int offset, const Modifiers& modifiers, |
Ethan Nicholas | 962dec4 | 2021-06-10 13:06:39 -0400 | [diff] [blame] | 170 | const Type* baseType, skstd::string_view name, |
Ethan Nicholas | 489e552 | 2021-01-20 10:53:11 -0500 | [diff] [blame] | 171 | bool isArray, |
| 172 | std::unique_ptr<Expression> arraySize, |
| 173 | std::unique_ptr<Expression> value, |
| 174 | Variable::Storage storage); |
John Stiles | 8f2a0cf | 2020-10-13 12:48:21 -0400 | [diff] [blame] | 175 | StatementArray convertVarDeclarations(const ASTNode& decl, Variable::Storage storage); |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 176 | void convertFunction(const ASTNode& f); |
| 177 | std::unique_ptr<Statement> convertStatement(const ASTNode& statement); |
| 178 | std::unique_ptr<Expression> convertExpression(const ASTNode& expression); |
| 179 | std::unique_ptr<ModifiersDeclaration> convertModifiersDeclaration(const ASTNode& m); |
Ethan Nicholas | 7da6dfa | 2017-06-21 11:25:18 -0400 | [diff] [blame] | 180 | |
Brian Osman | d807039 | 2020-09-09 15:50:02 -0400 | [diff] [blame] | 181 | const Type* convertType(const ASTNode& type, bool allowVoid = false); |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 182 | std::unique_ptr<Expression> call(int offset, |
Ethan Nicholas | 9ead3df | 2021-01-06 12:10:48 -0500 | [diff] [blame] | 183 | std::unique_ptr<Expression> function, |
| 184 | ExpressionArray arguments); |
| 185 | std::unique_ptr<Expression> call(int offset, |
Ethan Nicholas | 11d5397 | 2016-11-28 11:23:23 -0500 | [diff] [blame] | 186 | const FunctionDeclaration& function, |
John Stiles | 8e3b6be | 2020-10-13 11:14:08 -0400 | [diff] [blame] | 187 | ExpressionArray arguments); |
Brian Osman | 0acb5b5 | 2020-09-02 13:45:47 -0400 | [diff] [blame] | 188 | CoercionCost callCost(const FunctionDeclaration& function, |
John Stiles | 8e3b6be | 2020-10-13 11:14:08 -0400 | [diff] [blame] | 189 | const ExpressionArray& arguments); |
Ethan Nicholas | dcd2f86 | 2020-12-17 23:24:25 +0000 | [diff] [blame] | 190 | std::unique_ptr<Expression> coerce(std::unique_ptr<Expression> expr, const Type& type); |
Ethan Nicholas | 9ead3df | 2021-01-06 12:10:48 -0500 | [diff] [blame] | 191 | CoercionCost coercionCost(const Expression& expr, const Type& type); |
John Stiles | 80b02af | 2021-02-12 17:07:51 -0500 | [diff] [blame] | 192 | int convertArraySize(const Type& type, int offset, const ASTNode& s); |
| 193 | int convertArraySize(const Type& type, std::unique_ptr<Expression> s); |
Ethan Nicholas | c0f9815 | 2021-02-05 16:21:10 -0500 | [diff] [blame] | 194 | bool containsConstantZero(Expression& expr); |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 195 | bool dividesByZero(Operator op, Expression& right); |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 196 | std::unique_ptr<Block> convertBlock(const ASTNode& block); |
| 197 | std::unique_ptr<Statement> convertBreak(const ASTNode& b); |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 198 | std::unique_ptr<Statement> convertContinue(const ASTNode& c); |
| 199 | std::unique_ptr<Statement> convertDiscard(const ASTNode& d); |
| 200 | std::unique_ptr<Statement> convertDo(const ASTNode& d); |
| 201 | std::unique_ptr<Statement> convertSwitch(const ASTNode& s); |
| 202 | std::unique_ptr<Expression> convertBinaryExpression(const ASTNode& expression); |
Ethan Nicholas | 962dec4 | 2021-06-10 13:06:39 -0400 | [diff] [blame] | 203 | std::unique_ptr<Extension> convertExtension(int offset, skstd::string_view name); |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 204 | std::unique_ptr<Statement> convertExpressionStatement(const ASTNode& s); |
Ethan Nicholas | 9ead3df | 2021-01-06 12:10:48 -0500 | [diff] [blame] | 205 | std::unique_ptr<Expression> convertField(std::unique_ptr<Expression> base, |
Ethan Nicholas | 962dec4 | 2021-06-10 13:06:39 -0400 | [diff] [blame] | 206 | skstd::string_view field); |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 207 | std::unique_ptr<Statement> convertFor(const ASTNode& f); |
| 208 | std::unique_ptr<Expression> convertIdentifier(const ASTNode& identifier); |
| 209 | std::unique_ptr<Statement> convertIf(const ASTNode& s); |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 210 | std::unique_ptr<InterfaceBlock> convertInterfaceBlock(const ASTNode& s); |
Ethan Nicholas | 11d5397 | 2016-11-28 11:23:23 -0500 | [diff] [blame] | 211 | Modifiers convertModifiers(const Modifiers& m); |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 212 | std::unique_ptr<Expression> convertPrefixExpression(const ASTNode& expression); |
Ethan Nicholas | 1ff7609 | 2021-01-28 10:02:43 -0500 | [diff] [blame] | 213 | std::unique_ptr<Statement> convertReturn(int offset, std::unique_ptr<Expression> result); |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 214 | std::unique_ptr<Statement> convertReturn(const ASTNode& r); |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 215 | std::unique_ptr<Expression> convertCallExpression(const ASTNode& expression); |
| 216 | std::unique_ptr<Expression> convertFieldExpression(const ASTNode& expression); |
| 217 | std::unique_ptr<Expression> convertIndexExpression(const ASTNode& expression); |
| 218 | std::unique_ptr<Expression> convertPostfixExpression(const ASTNode& expression); |
John Stiles | dc75a97 | 2020-11-25 16:24:55 -0500 | [diff] [blame] | 219 | std::unique_ptr<StructDefinition> convertStructDefinition(const ASTNode& expression); |
Ethan Nicholas | d2e0960 | 2021-06-10 11:21:59 -0400 | [diff] [blame] | 220 | std::unique_ptr<Expression> convertSwizzle(std::unique_ptr<Expression> base, |
Ethan Nicholas | 962dec4 | 2021-06-10 13:06:39 -0400 | [diff] [blame] | 221 | skstd::string_view fields); |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 222 | std::unique_ptr<Expression> convertTernaryExpression(const ASTNode& expression); |
| 223 | std::unique_ptr<Statement> convertVarDeclarationStatement(const ASTNode& s); |
| 224 | std::unique_ptr<Statement> convertWhile(const ASTNode& w); |
John Stiles | 7bd7033 | 2020-11-30 17:04:09 -0500 | [diff] [blame] | 225 | void convertGlobalVarDeclarations(const ASTNode& decl); |
Ethan Nicholas | aae47c8 | 2017-11-10 15:34:03 -0500 | [diff] [blame] | 226 | std::unique_ptr<Block> applyInvocationIDWorkaround(std::unique_ptr<Block> main); |
Robert Phillips | fe8da17 | 2018-01-24 14:52:02 +0000 | [diff] [blame] | 227 | // returns a statement which converts sk_Position from device to normalized coordinates |
| 228 | std::unique_ptr<Statement> getNormalizeSkPositionCode(); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 229 | |
| 230 | void checkValid(const Expression& expr); |
John Stiles | b4b627e | 2020-11-13 15:55:27 -0500 | [diff] [blame] | 231 | bool typeContainsPrivateFields(const Type& type); |
John Stiles | 403a363 | 2020-08-20 12:11:48 -0400 | [diff] [blame] | 232 | bool setRefKind(Expression& expr, VariableReference::RefKind kind); |
Ethan Nicholas | c18bb51 | 2020-07-28 14:46:53 -0400 | [diff] [blame] | 233 | void copyIntrinsicIfNeeded(const FunctionDeclaration& function); |
Brian Osman | 9496fe5 | 2020-11-18 14:48:19 -0500 | [diff] [blame] | 234 | void findAndDeclareBuiltinVariables(); |
John Stiles | e3a91cf | 2021-01-26 10:13:58 -0500 | [diff] [blame] | 235 | bool detectVarDeclarationWithoutScope(const Statement& stmt); |
Ethan Nicholas | ebc9fad | 2021-07-09 15:35:23 -0400 | [diff] [blame] | 236 | // Coerces returns to correct type, detects invalid break / continue placement, and otherwise |
| 237 | // massages the function into its final form |
| 238 | std::unique_ptr<Block> finalizeFunction(const FunctionDeclaration& funcDecl, |
| 239 | std::unique_ptr<Block> body); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 240 | |
Brian Osman | 818fd6d | 2020-12-30 15:06:22 -0500 | [diff] [blame] | 241 | // Runtime effects (and the interpreter, which uses the same CPU runtime) require adherence to |
| 242 | // the strict rules from The OpenGL ES Shading Language Version 1.00. (Including Appendix A). |
| 243 | bool strictES2Mode() const { |
John Stiles | ca107c9 | 2021-02-19 09:54:44 -0500 | [diff] [blame] | 244 | return fContext.fConfig->strictES2Mode(); |
Brian Osman | 818fd6d | 2020-12-30 15:06:22 -0500 | [diff] [blame] | 245 | } |
| 246 | |
John Stiles | bb2ef92 | 2021-07-26 08:32:07 -0400 | [diff] [blame] | 247 | bool isRuntimeEffect() const { |
John Stiles | addccaf | 2021-08-02 19:03:30 -0400 | [diff] [blame^] | 248 | return ProgramConfig::IsRuntimeEffect(fContext.fConfig->fKind); |
John Stiles | bb2ef92 | 2021-07-26 08:32:07 -0400 | [diff] [blame] | 249 | } |
| 250 | |
John Stiles | c1a98b8 | 2021-02-24 13:35:02 -0500 | [diff] [blame] | 251 | const ShaderCapsClass& caps() const { |
| 252 | return fContext.fCaps; |
| 253 | } |
| 254 | |
John Stiles | f2872e6 | 2021-05-04 11:38:43 -0400 | [diff] [blame] | 255 | ModifiersPool& modifiersPool() const { |
John Stiles | 10d39d9 | 2021-05-04 16:13:14 -0400 | [diff] [blame] | 256 | return *fContext.fModifiersPool; |
John Stiles | f2872e6 | 2021-05-04 11:38:43 -0400 | [diff] [blame] | 257 | } |
| 258 | |
Brian Osman | 88cda17 | 2020-10-09 12:05:16 -0400 | [diff] [blame] | 259 | Program::Inputs fInputs; |
Brian Osman | 88cda17 | 2020-10-09 12:05:16 -0400 | [diff] [blame] | 260 | |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 261 | std::unique_ptr<ASTFile> fFile; |
John Stiles | dbd4e6f | 2021-02-16 13:29:15 -0500 | [diff] [blame] | 262 | |
Brian Osman | 88cda17 | 2020-10-09 12:05:16 -0400 | [diff] [blame] | 263 | std::shared_ptr<SymbolTable> fSymbolTable = nullptr; |
John Stiles | 810c8cf | 2020-08-26 19:46:27 -0400 | [diff] [blame] | 264 | // Symbols which have definitions in the include files. |
| 265 | IRIntrinsicMap* fIntrinsics = nullptr; |
John Stiles | b8e010c | 2020-08-11 18:05:39 -0400 | [diff] [blame] | 266 | std::unordered_set<const FunctionDeclaration*> fReferencedIntrinsics; |
Ethan Nicholas | 7da6dfa | 2017-06-21 11:25:18 -0400 | [diff] [blame] | 267 | int fInvocations; |
Brian Osman | 02bc522 | 2021-01-28 11:00:20 -0500 | [diff] [blame] | 268 | std::unordered_set<const Type*> fDefinedStructs; |
Brian Osman | 88cda17 | 2020-10-09 12:05:16 -0400 | [diff] [blame] | 269 | std::vector<std::unique_ptr<ProgramElement>>* fProgramElements = nullptr; |
Brian Osman | 133724c | 2020-10-28 14:14:39 -0400 | [diff] [blame] | 270 | std::vector<const ProgramElement*>* fSharedElements = nullptr; |
Brian Osman | 88cda17 | 2020-10-09 12:05:16 -0400 | [diff] [blame] | 271 | const Variable* fRTAdjust = nullptr; |
| 272 | const Variable* fRTAdjustInterfaceBlock = nullptr; |
Robert Phillips | fe8da17 | 2018-01-24 14:52:02 +0000 | [diff] [blame] | 273 | int fRTAdjustFieldIndex; |
Ethan Nicholas | c18bb51 | 2020-07-28 14:46:53 -0400 | [diff] [blame] | 274 | // true if we are currently processing one of the built-in SkSL include files |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 275 | bool fIsBuiltinCode = false; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 276 | |
| 277 | friend class AutoSymbolTable; |
ethannicholas | 22f939e | 2016-10-13 13:25:34 -0700 | [diff] [blame] | 278 | friend class AutoLoopLevel; |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 279 | friend class AutoSwitchLevel; |
John Stiles | d1c4dac | 2020-08-11 18:50:50 -0400 | [diff] [blame] | 280 | friend class AutoDisableInline; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 281 | friend class Compiler; |
Ethan Nicholas | dd2fdea | 2021-07-20 15:23:04 -0400 | [diff] [blame] | 282 | friend class DSLParser; |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 283 | friend class dsl::DSLCore; |
Ethan Nicholas | 1ff7609 | 2021-01-28 10:02:43 -0500 | [diff] [blame] | 284 | friend class dsl::DSLFunction; |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 285 | friend class dsl::DSLVar; |
Ethan Nicholas | 9504614 | 2021-01-07 10:57:27 -0500 | [diff] [blame] | 286 | friend class dsl::DSLWriter; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 287 | }; |
| 288 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 289 | } // namespace SkSL |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 290 | |
| 291 | #endif |