Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [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_METALCODEGENERATOR |
| 9 | #define SKSL_METALCODEGENERATOR |
| 10 | |
Brian Osman | 0018501 | 2021-02-04 16:07:11 -0500 | [diff] [blame] | 11 | #include <set> |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 12 | #include <stack> |
| 13 | #include <tuple> |
| 14 | #include <unordered_map> |
John Stiles | 1bdafbf | 2020-05-28 12:17:20 -0400 | [diff] [blame] | 15 | #include <unordered_set> |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 16 | |
Ethan Nicholas | 24c1772 | 2021-03-09 13:10:59 -0500 | [diff] [blame] | 17 | #include "include/private/SkSLProgramElement.h" |
| 18 | #include "include/private/SkSLStatement.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/sksl/SkSLCodeGenerator.h" |
Brian Osman | 0018501 | 2021-02-04 16:07:11 -0500 | [diff] [blame] | 20 | #include "src/sksl/SkSLOperators.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/sksl/SkSLStringStream.h" |
| 22 | #include "src/sksl/ir/SkSLBinaryExpression.h" |
| 23 | #include "src/sksl/ir/SkSLBoolLiteral.h" |
| 24 | #include "src/sksl/ir/SkSLConstructor.h" |
| 25 | #include "src/sksl/ir/SkSLDoStatement.h" |
| 26 | #include "src/sksl/ir/SkSLExtension.h" |
| 27 | #include "src/sksl/ir/SkSLFieldAccess.h" |
| 28 | #include "src/sksl/ir/SkSLFloatLiteral.h" |
| 29 | #include "src/sksl/ir/SkSLForStatement.h" |
| 30 | #include "src/sksl/ir/SkSLFunctionCall.h" |
| 31 | #include "src/sksl/ir/SkSLFunctionDeclaration.h" |
| 32 | #include "src/sksl/ir/SkSLFunctionDefinition.h" |
John Stiles | 569249b | 2020-11-03 12:18:22 -0500 | [diff] [blame] | 33 | #include "src/sksl/ir/SkSLFunctionPrototype.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 34 | #include "src/sksl/ir/SkSLIfStatement.h" |
| 35 | #include "src/sksl/ir/SkSLIndexExpression.h" |
John Stiles | 98c1f82 | 2020-09-09 14:18:53 -0400 | [diff] [blame] | 36 | #include "src/sksl/ir/SkSLInlineMarker.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 37 | #include "src/sksl/ir/SkSLIntLiteral.h" |
| 38 | #include "src/sksl/ir/SkSLInterfaceBlock.h" |
| 39 | #include "src/sksl/ir/SkSLPostfixExpression.h" |
| 40 | #include "src/sksl/ir/SkSLPrefixExpression.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 41 | #include "src/sksl/ir/SkSLReturnStatement.h" |
| 42 | #include "src/sksl/ir/SkSLSetting.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 43 | #include "src/sksl/ir/SkSLSwitchStatement.h" |
| 44 | #include "src/sksl/ir/SkSLSwizzle.h" |
| 45 | #include "src/sksl/ir/SkSLTernaryExpression.h" |
| 46 | #include "src/sksl/ir/SkSLVarDeclarations.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 47 | #include "src/sksl/ir/SkSLVariableReference.h" |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 48 | |
| 49 | namespace SkSL { |
| 50 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 51 | /** |
| 52 | * Converts a Program into Metal code. |
| 53 | */ |
| 54 | class MetalCodeGenerator : public CodeGenerator { |
| 55 | public: |
Timothy Liang | a06f215 | 2018-05-24 15:33:31 -0400 | [diff] [blame] | 56 | static constexpr const char* SAMPLER_SUFFIX = "Smplr"; |
Timothy Liang | 7d63778 | 2018-06-05 09:58:07 -0400 | [diff] [blame] | 57 | static constexpr const char* PACKED_PREFIX = "packed_"; |
Timothy Liang | a06f215 | 2018-05-24 15:33:31 -0400 | [diff] [blame] | 58 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 59 | MetalCodeGenerator(const Context* context, const Program* program, ErrorReporter* errors, |
Ethan Nicholas | 5a9a9b8 | 2019-09-20 12:59:22 -0400 | [diff] [blame] | 60 | OutputStream* out) |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 61 | : INHERITED(program, errors, out) |
John Stiles | 2345653 | 2020-12-30 18:12:48 -0500 | [diff] [blame] | 62 | , fReservedWords({"atan2", "rsqrt", "rint", "dfdx", "dfdy", "vertex", "fragment"}) |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 63 | , fLineEnding("\n") |
Timothy Liang | 6403b0e | 2018-05-17 10:40:04 -0400 | [diff] [blame] | 64 | , fContext(*context) { |
| 65 | this->setupIntrinsics(); |
| 66 | } |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 67 | |
| 68 | bool generateCode() override; |
| 69 | |
| 70 | protected: |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 71 | using Precedence = Operator::Precedence; |
Brian Osman | 0018501 | 2021-02-04 16:07:11 -0500 | [diff] [blame] | 72 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 73 | typedef int Requirements; |
Ethan Nicholas | c6dce5a | 2019-07-24 16:51:36 -0400 | [diff] [blame] | 74 | static constexpr Requirements kNo_Requirements = 0; |
| 75 | static constexpr Requirements kInputs_Requirement = 1 << 0; |
| 76 | static constexpr Requirements kOutputs_Requirement = 1 << 1; |
| 77 | static constexpr Requirements kUniforms_Requirement = 1 << 2; |
| 78 | static constexpr Requirements kGlobals_Requirement = 1 << 3; |
| 79 | static constexpr Requirements kFragCoord_Requirement = 1 << 4; |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 80 | |
Timothy Liang | 6403b0e | 2018-05-17 10:40:04 -0400 | [diff] [blame] | 81 | enum IntrinsicKind { |
John Stiles | d7199b2 | 2020-12-30 16:22:58 -0500 | [diff] [blame] | 82 | kAtan_IntrinsicKind, |
| 83 | kBitcast_IntrinsicKind, |
| 84 | kBitCount_IntrinsicKind, |
| 85 | kCompareEqual_IntrinsicKind, |
| 86 | kCompareGreaterThan_IntrinsicKind, |
| 87 | kCompareGreaterThanEqual_IntrinsicKind, |
| 88 | kCompareLessThan_IntrinsicKind, |
| 89 | kCompareLessThanEqual_IntrinsicKind, |
| 90 | kCompareNotEqual_IntrinsicKind, |
| 91 | kDegrees_IntrinsicKind, |
| 92 | kDFdx_IntrinsicKind, |
| 93 | kDFdy_IntrinsicKind, |
| 94 | kDistance_IntrinsicKind, |
| 95 | kDot_IntrinsicKind, |
| 96 | kFaceforward_IntrinsicKind, |
| 97 | kFindLSB_IntrinsicKind, |
| 98 | kFindMSB_IntrinsicKind, |
| 99 | kInverse_IntrinsicKind, |
| 100 | kInversesqrt_IntrinsicKind, |
| 101 | kLength_IntrinsicKind, |
| 102 | kMatrixCompMult_IntrinsicKind, |
| 103 | kMod_IntrinsicKind, |
| 104 | kNormalize_IntrinsicKind, |
| 105 | kRadians_IntrinsicKind, |
| 106 | kReflect_IntrinsicKind, |
| 107 | kRefract_IntrinsicKind, |
John Stiles | 2345653 | 2020-12-30 18:12:48 -0500 | [diff] [blame] | 108 | kRoundEven_IntrinsicKind, |
John Stiles | d7199b2 | 2020-12-30 16:22:58 -0500 | [diff] [blame] | 109 | kTexture_IntrinsicKind, |
Timothy Liang | a06f215 | 2018-05-24 15:33:31 -0400 | [diff] [blame] | 110 | }; |
Timothy Liang | 6403b0e | 2018-05-17 10:40:04 -0400 | [diff] [blame] | 111 | |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 112 | static const char* OperatorName(Operator op); |
John Stiles | d6449e9 | 2020-11-30 09:13:23 -0500 | [diff] [blame] | 113 | |
John Stiles | cdcdb04 | 2020-07-06 09:03:51 -0400 | [diff] [blame] | 114 | class GlobalStructVisitor; |
| 115 | void visitGlobalStruct(GlobalStructVisitor* visitor); |
| 116 | |
Timothy Liang | a06f215 | 2018-05-24 15:33:31 -0400 | [diff] [blame] | 117 | void setupIntrinsics(); |
Timothy Liang | ee84fe1 | 2018-05-18 14:38:19 -0400 | [diff] [blame] | 118 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 119 | void write(const char* s); |
| 120 | |
| 121 | void writeLine(); |
| 122 | |
| 123 | void writeLine(const char* s); |
| 124 | |
| 125 | void write(const String& s); |
| 126 | |
| 127 | void writeLine(const String& s); |
| 128 | |
John Stiles | e8b5a73 | 2021-03-12 13:25:52 -0500 | [diff] [blame] | 129 | void finishLine(); |
| 130 | |
Michael Ludwig | bf58add | 2021-03-16 10:40:11 -0400 | [diff] [blame^] | 131 | void writeHeader(); |
| 132 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 133 | void writeUniformStruct(); |
| 134 | |
| 135 | void writeInputStruct(); |
| 136 | |
| 137 | void writeOutputStruct(); |
| 138 | |
Timothy Liang | 7d63778 | 2018-06-05 09:58:07 -0400 | [diff] [blame] | 139 | void writeInterfaceBlocks(); |
| 140 | |
John Stiles | dc75a97 | 2020-11-25 16:24:55 -0500 | [diff] [blame] | 141 | void writeStructDefinitions(); |
| 142 | |
Timothy Liang | dc89f19 | 2018-06-13 09:20:31 -0400 | [diff] [blame] | 143 | void writeFields(const std::vector<Type::Field>& fields, int parentOffset, |
| 144 | const InterfaceBlock* parentIntf = nullptr); |
| 145 | |
Timothy Liang | 7d63778 | 2018-06-05 09:58:07 -0400 | [diff] [blame] | 146 | int size(const Type* type, bool isPacked) const; |
| 147 | |
| 148 | int alignment(const Type* type, bool isPacked) const; |
| 149 | |
Timothy Liang | ee84fe1 | 2018-05-18 14:38:19 -0400 | [diff] [blame] | 150 | void writeGlobalStruct(); |
John Stiles | d7199b2 | 2020-12-30 16:22:58 -0500 | [diff] [blame] | 151 | |
John Stiles | cdcdb04 | 2020-07-06 09:03:51 -0400 | [diff] [blame] | 152 | void writeGlobalInit(); |
Timothy Liang | ee84fe1 | 2018-05-18 14:38:19 -0400 | [diff] [blame] | 153 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 154 | void writePrecisionModifier(); |
| 155 | |
Ethan Nicholas | 45fa810 | 2020-01-13 10:58:49 -0500 | [diff] [blame] | 156 | String typeName(const Type& type); |
| 157 | |
Brian Osman | 02bc522 | 2021-01-28 11:00:20 -0500 | [diff] [blame] | 158 | void writeStructDefinition(const StructDefinition& s); |
John Stiles | dc75a97 | 2020-11-25 16:24:55 -0500 | [diff] [blame] | 159 | |
John Stiles | b441850 | 2021-02-04 10:57:08 -0500 | [diff] [blame] | 160 | void writeType(const Type& type); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 161 | |
| 162 | void writeExtension(const Extension& ext); |
| 163 | |
| 164 | void writeInterfaceBlock(const InterfaceBlock& intf); |
| 165 | |
| 166 | void writeFunctionStart(const FunctionDeclaration& f); |
| 167 | |
John Stiles | 06b84ef | 2020-12-09 12:35:48 -0500 | [diff] [blame] | 168 | void writeFunctionRequirementParams(const FunctionDeclaration& f, |
| 169 | const char*& separator); |
| 170 | |
| 171 | void writeFunctionRequirementArgs(const FunctionDeclaration& f, const char*& separator); |
| 172 | |
John Stiles | 569249b | 2020-11-03 12:18:22 -0500 | [diff] [blame] | 173 | bool writeFunctionDeclaration(const FunctionDeclaration& f); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 174 | |
| 175 | void writeFunction(const FunctionDefinition& f); |
| 176 | |
John Stiles | 569249b | 2020-11-03 12:18:22 -0500 | [diff] [blame] | 177 | void writeFunctionPrototype(const FunctionPrototype& f); |
| 178 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 179 | void writeLayout(const Layout& layout); |
| 180 | |
| 181 | void writeModifiers(const Modifiers& modifiers, bool globalContext); |
| 182 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 183 | void writeVarInitializer(const Variable& var, const Expression& value); |
| 184 | |
Timothy Liang | 651286f | 2018-06-07 09:55:33 -0400 | [diff] [blame] | 185 | void writeName(const String& name); |
| 186 | |
Brian Osman | c021360 | 2020-10-06 14:43:32 -0400 | [diff] [blame] | 187 | void writeVarDeclaration(const VarDeclaration& decl, bool global); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 188 | |
| 189 | void writeFragCoord(); |
| 190 | |
| 191 | void writeVariableReference(const VariableReference& ref); |
| 192 | |
| 193 | void writeExpression(const Expression& expr, Precedence parentPrecedence); |
| 194 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 195 | void writeMinAbsHack(Expression& absExpr, Expression& otherExpr); |
| 196 | |
John Stiles | 06b84ef | 2020-12-09 12:35:48 -0500 | [diff] [blame] | 197 | String getOutParamHelper(const FunctionCall& c, |
| 198 | const ExpressionArray& arguments, |
| 199 | const SkTArray<VariableReference*>& outVars); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 200 | |
John Stiles | d7199b2 | 2020-12-30 16:22:58 -0500 | [diff] [blame] | 201 | String getInversePolyfill(const ExpressionArray& arguments); |
John Stiles | b21fac2 | 2020-12-04 15:36:49 -0500 | [diff] [blame] | 202 | |
John Stiles | f64e407 | 2020-12-10 10:34:27 -0500 | [diff] [blame] | 203 | String getBitcastIntrinsic(const Type& outType); |
| 204 | |
John Stiles | 86424eb | 2020-12-11 11:17:14 -0500 | [diff] [blame] | 205 | String getTempVariable(const Type& varType); |
| 206 | |
John Stiles | b21fac2 | 2020-12-04 15:36:49 -0500 | [diff] [blame] | 207 | void writeFunctionCall(const FunctionCall& c); |
Chris Dalton | dba7aab | 2018-11-15 10:57:49 -0500 | [diff] [blame] | 208 | |
John Stiles | 1bdafbf | 2020-05-28 12:17:20 -0400 | [diff] [blame] | 209 | bool matrixConstructHelperIsNeeded(const Constructor& c); |
| 210 | String getMatrixConstructHelper(const Constructor& c); |
John Stiles | fcf8cb2 | 2020-08-06 14:29:22 -0400 | [diff] [blame] | 211 | void assembleMatrixFromMatrix(const Type& sourceMatrix, int rows, int columns); |
John Stiles | 8e3b6be | 2020-10-13 11:14:08 -0400 | [diff] [blame] | 212 | void assembleMatrixFromExpressions(const ExpressionArray& args, int rows, int columns); |
Ethan Nicholas | 842d31b | 2019-01-22 10:59:11 -0500 | [diff] [blame] | 213 | |
Brian Osman | 93aed9a | 2020-12-28 15:18:46 -0500 | [diff] [blame] | 214 | void writeMatrixCompMult(); |
John Stiles | 01cdf01 | 2021-02-10 09:53:41 -0500 | [diff] [blame] | 215 | |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 216 | void writeMatrixTimesEqualHelper(const Type& left, const Type& right, const Type& result); |
| 217 | |
John Stiles | 01cdf01 | 2021-02-10 09:53:41 -0500 | [diff] [blame] | 218 | void writeMatrixEqualityHelper(const Type& left, const Type& right); |
| 219 | |
| 220 | void writeMatrixInequalityHelper(const Type& left, const Type& right); |
| 221 | |
John Stiles | d7199b2 | 2020-12-30 16:22:58 -0500 | [diff] [blame] | 222 | void writeArgumentList(const ExpressionArray& arguments); |
| 223 | |
John Stiles | 791c27d | 2020-12-30 14:56:57 -0500 | [diff] [blame] | 224 | void writeSimpleIntrinsic(const FunctionCall& c); |
| 225 | |
John Stiles | d7199b2 | 2020-12-30 16:22:58 -0500 | [diff] [blame] | 226 | void writeIntrinsicCall(const FunctionCall& c, IntrinsicKind kind); |
Timothy Liang | 6403b0e | 2018-05-17 10:40:04 -0400 | [diff] [blame] | 227 | |
Ethan Nicholas | 842d31b | 2019-01-22 10:59:11 -0500 | [diff] [blame] | 228 | bool canCoerce(const Type& t1, const Type& t2); |
| 229 | |
| 230 | void writeConstructor(const Constructor& c, Precedence parentPrecedence); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 231 | |
| 232 | void writeFieldAccess(const FieldAccess& f); |
| 233 | |
| 234 | void writeSwizzle(const Swizzle& swizzle); |
| 235 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 236 | void writeBinaryExpression(const BinaryExpression& b, Precedence parentPrecedence); |
| 237 | |
| 238 | void writeTernaryExpression(const TernaryExpression& t, Precedence parentPrecedence); |
| 239 | |
| 240 | void writeIndexExpression(const IndexExpression& expr); |
| 241 | |
| 242 | void writePrefixExpression(const PrefixExpression& p, Precedence parentPrecedence); |
| 243 | |
| 244 | void writePostfixExpression(const PostfixExpression& p, Precedence parentPrecedence); |
| 245 | |
| 246 | void writeBoolLiteral(const BoolLiteral& b); |
| 247 | |
| 248 | void writeIntLiteral(const IntLiteral& i); |
| 249 | |
| 250 | void writeFloatLiteral(const FloatLiteral& f); |
| 251 | |
| 252 | void writeSetting(const Setting& s); |
| 253 | |
| 254 | void writeStatement(const Statement& s); |
| 255 | |
John Stiles | 8f2a0cf | 2020-10-13 12:48:21 -0400 | [diff] [blame] | 256 | void writeStatements(const StatementArray& statements); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 257 | |
| 258 | void writeBlock(const Block& b); |
| 259 | |
| 260 | void writeIfStatement(const IfStatement& stmt); |
| 261 | |
| 262 | void writeForStatement(const ForStatement& f); |
| 263 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 264 | void writeDoStatement(const DoStatement& d); |
| 265 | |
| 266 | void writeSwitchStatement(const SwitchStatement& s); |
| 267 | |
John Stiles | 986c7fb | 2020-12-01 14:44:56 -0500 | [diff] [blame] | 268 | void writeReturnStatementFromMain(); |
| 269 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 270 | void writeReturnStatement(const ReturnStatement& r); |
| 271 | |
| 272 | void writeProgramElement(const ProgramElement& e); |
| 273 | |
| 274 | Requirements requirements(const FunctionDeclaration& f); |
| 275 | |
Ethan Nicholas | ff350cb | 2020-05-14 14:05:13 -0400 | [diff] [blame] | 276 | Requirements requirements(const Expression* e); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 277 | |
Ethan Nicholas | ff350cb | 2020-05-14 14:05:13 -0400 | [diff] [blame] | 278 | Requirements requirements(const Statement* s); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 279 | |
John Stiles | da5cdf6 | 2021-01-28 11:47:29 -0500 | [diff] [blame] | 280 | int getUniformBinding(const Modifiers& m); |
| 281 | |
| 282 | int getUniformSet(const Modifiers& m); |
| 283 | |
John Stiles | d7199b2 | 2020-12-30 16:22:58 -0500 | [diff] [blame] | 284 | std::unordered_map<String, IntrinsicKind> fIntrinsicMap; |
Timothy Liang | 651286f | 2018-06-07 09:55:33 -0400 | [diff] [blame] | 285 | std::unordered_set<String> fReservedWords; |
Timothy Liang | a06f215 | 2018-05-24 15:33:31 -0400 | [diff] [blame] | 286 | std::unordered_map<const Type::Field*, const InterfaceBlock*> fInterfaceBlockMap; |
| 287 | std::unordered_map<const InterfaceBlock*, String> fInterfaceBlockNameMap; |
| 288 | int fAnonInterfaceCount = 0; |
Timothy Liang | 7d63778 | 2018-06-05 09:58:07 -0400 | [diff] [blame] | 289 | int fPaddingCount = 0; |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 290 | const char* fLineEnding; |
| 291 | const Context& fContext; |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 292 | String fFunctionHeader; |
Chris Dalton | dba7aab | 2018-11-15 10:57:49 -0500 | [diff] [blame] | 293 | StringStream fExtraFunctions; |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 294 | int fVarCount = 0; |
| 295 | int fIndentation = 0; |
| 296 | bool fAtLineStart = false; |
Chris Dalton | dba7aab | 2018-11-15 10:57:49 -0500 | [diff] [blame] | 297 | std::set<String> fWrittenIntrinsics; |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 298 | // true if we have run into usages of dFdx / dFdy |
| 299 | bool fFoundDerivatives = false; |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 300 | std::unordered_map<const FunctionDeclaration*, Requirements> fRequirements; |
| 301 | bool fSetupFragPositionGlobal = false; |
| 302 | bool fSetupFragPositionLocal = false; |
John Stiles | 1bdafbf | 2020-05-28 12:17:20 -0400 | [diff] [blame] | 303 | std::unordered_set<String> fHelpers; |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 304 | int fUniformBuffer = -1; |
Ethan Nicholas | f931e40 | 2019-07-26 15:40:33 -0400 | [diff] [blame] | 305 | String fRTHeightName; |
John Stiles | 986c7fb | 2020-12-01 14:44:56 -0500 | [diff] [blame] | 306 | const FunctionDeclaration* fCurrentFunction = nullptr; |
John Stiles | 06b84ef | 2020-12-09 12:35:48 -0500 | [diff] [blame] | 307 | int fSwizzleHelperCount = 0; |
| 308 | bool fIgnoreVariableReferenceModifiers = false; |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 309 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 310 | using INHERITED = CodeGenerator; |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 311 | }; |
| 312 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 313 | } // namespace SkSL |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 314 | |
| 315 | #endif |