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" |
Brian Osman | 0018501 | 2021-02-04 16:07:11 -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/SkSLStringStream.h" |
John Stiles | 3738ef5 | 2021-04-13 10:41:57 -0400 | [diff] [blame] | 21 | #include "src/sksl/codegen/SkSLCodeGenerator.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 22 | #include "src/sksl/ir/SkSLBinaryExpression.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "src/sksl/ir/SkSLConstructor.h" |
John Stiles | 8cad637 | 2021-04-07 12:31:13 -0400 | [diff] [blame] | 24 | #include "src/sksl/ir/SkSLConstructorCompound.h" |
John Stiles | 5abb9e1 | 2021-04-06 13:47:19 -0400 | [diff] [blame] | 25 | #include "src/sksl/ir/SkSLConstructorMatrixResize.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 26 | #include "src/sksl/ir/SkSLDoStatement.h" |
| 27 | #include "src/sksl/ir/SkSLExtension.h" |
| 28 | #include "src/sksl/ir/SkSLFieldAccess.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 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/SkSLInterfaceBlock.h" |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame] | 38 | #include "src/sksl/ir/SkSLLiteral.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 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 | 3abc6c6 | 2021-08-13 11:20:09 -0400 | [diff] [blame] | 59 | MetalCodeGenerator(const Context* context, const Program* program, OutputStream* out) |
| 60 | : INHERITED(context, program, out) |
John Stiles | 2345653 | 2020-12-30 18:12:48 -0500 | [diff] [blame] | 61 | , fReservedWords({"atan2", "rsqrt", "rint", "dfdx", "dfdy", "vertex", "fragment"}) |
Ethan Nicholas | 3abc6c6 | 2021-08-13 11:20:09 -0400 | [diff] [blame] | 62 | , fLineEnding("\n") {} |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 63 | |
| 64 | bool generateCode() override; |
| 65 | |
| 66 | protected: |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 67 | using Precedence = Operator::Precedence; |
Brian Osman | 0018501 | 2021-02-04 16:07:11 -0500 | [diff] [blame] | 68 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 69 | typedef int Requirements; |
Ethan Nicholas | c6dce5a | 2019-07-24 16:51:36 -0400 | [diff] [blame] | 70 | static constexpr Requirements kNo_Requirements = 0; |
| 71 | static constexpr Requirements kInputs_Requirement = 1 << 0; |
| 72 | static constexpr Requirements kOutputs_Requirement = 1 << 1; |
| 73 | static constexpr Requirements kUniforms_Requirement = 1 << 2; |
| 74 | static constexpr Requirements kGlobals_Requirement = 1 << 3; |
| 75 | static constexpr Requirements kFragCoord_Requirement = 1 << 4; |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 76 | |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 77 | static const char* OperatorName(Operator op); |
John Stiles | d6449e9 | 2020-11-30 09:13:23 -0500 | [diff] [blame] | 78 | |
John Stiles | cdcdb04 | 2020-07-06 09:03:51 -0400 | [diff] [blame] | 79 | class GlobalStructVisitor; |
| 80 | void visitGlobalStruct(GlobalStructVisitor* visitor); |
| 81 | |
Ethan Nicholas | 962dec4 | 2021-06-10 13:06:39 -0400 | [diff] [blame] | 82 | void write(skstd::string_view s); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 83 | |
Ethan Nicholas | 962dec4 | 2021-06-10 13:06:39 -0400 | [diff] [blame] | 84 | void writeLine(skstd::string_view s = skstd::string_view()); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 85 | |
John Stiles | e8b5a73 | 2021-03-12 13:25:52 -0500 | [diff] [blame] | 86 | void finishLine(); |
| 87 | |
Michael Ludwig | bf58add | 2021-03-16 10:40:11 -0400 | [diff] [blame] | 88 | void writeHeader(); |
| 89 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 90 | void writeUniformStruct(); |
| 91 | |
| 92 | void writeInputStruct(); |
| 93 | |
| 94 | void writeOutputStruct(); |
| 95 | |
Timothy Liang | 7d63778 | 2018-06-05 09:58:07 -0400 | [diff] [blame] | 96 | void writeInterfaceBlocks(); |
| 97 | |
John Stiles | dc75a97 | 2020-11-25 16:24:55 -0500 | [diff] [blame] | 98 | void writeStructDefinitions(); |
| 99 | |
Ethan Nicholas | 89cfde1 | 2021-09-27 11:20:34 -0400 | [diff] [blame] | 100 | void writeFields(const std::vector<Type::Field>& fields, int parentLine, |
Timothy Liang | dc89f19 | 2018-06-13 09:20:31 -0400 | [diff] [blame] | 101 | const InterfaceBlock* parentIntf = nullptr); |
| 102 | |
Timothy Liang | 7d63778 | 2018-06-05 09:58:07 -0400 | [diff] [blame] | 103 | int size(const Type* type, bool isPacked) const; |
| 104 | |
| 105 | int alignment(const Type* type, bool isPacked) const; |
| 106 | |
Timothy Liang | ee84fe1 | 2018-05-18 14:38:19 -0400 | [diff] [blame] | 107 | void writeGlobalStruct(); |
John Stiles | d7199b2 | 2020-12-30 16:22:58 -0500 | [diff] [blame] | 108 | |
John Stiles | cdcdb04 | 2020-07-06 09:03:51 -0400 | [diff] [blame] | 109 | void writeGlobalInit(); |
Timothy Liang | ee84fe1 | 2018-05-18 14:38:19 -0400 | [diff] [blame] | 110 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 111 | void writePrecisionModifier(); |
| 112 | |
Ethan Nicholas | 45fa810 | 2020-01-13 10:58:49 -0500 | [diff] [blame] | 113 | String typeName(const Type& type); |
| 114 | |
Brian Osman | 02bc522 | 2021-01-28 11:00:20 -0500 | [diff] [blame] | 115 | void writeStructDefinition(const StructDefinition& s); |
John Stiles | dc75a97 | 2020-11-25 16:24:55 -0500 | [diff] [blame] | 116 | |
John Stiles | b441850 | 2021-02-04 10:57:08 -0500 | [diff] [blame] | 117 | void writeType(const Type& type); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 118 | |
| 119 | void writeExtension(const Extension& ext); |
| 120 | |
| 121 | void writeInterfaceBlock(const InterfaceBlock& intf); |
| 122 | |
| 123 | void writeFunctionStart(const FunctionDeclaration& f); |
| 124 | |
John Stiles | 06b84ef | 2020-12-09 12:35:48 -0500 | [diff] [blame] | 125 | void writeFunctionRequirementParams(const FunctionDeclaration& f, |
| 126 | const char*& separator); |
| 127 | |
| 128 | void writeFunctionRequirementArgs(const FunctionDeclaration& f, const char*& separator); |
| 129 | |
John Stiles | 569249b | 2020-11-03 12:18:22 -0500 | [diff] [blame] | 130 | bool writeFunctionDeclaration(const FunctionDeclaration& f); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 131 | |
| 132 | void writeFunction(const FunctionDefinition& f); |
| 133 | |
John Stiles | 569249b | 2020-11-03 12:18:22 -0500 | [diff] [blame] | 134 | void writeFunctionPrototype(const FunctionPrototype& f); |
| 135 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 136 | void writeLayout(const Layout& layout); |
| 137 | |
Brian Osman | 58134e1 | 2021-05-13 14:51:07 -0400 | [diff] [blame] | 138 | void writeModifiers(const Modifiers& modifiers); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 139 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 140 | void writeVarInitializer(const Variable& var, const Expression& value); |
| 141 | |
Ethan Nicholas | 962dec4 | 2021-06-10 13:06:39 -0400 | [diff] [blame] | 142 | void writeName(skstd::string_view name); |
Timothy Liang | 651286f | 2018-06-07 09:55:33 -0400 | [diff] [blame] | 143 | |
Brian Osman | 58134e1 | 2021-05-13 14:51:07 -0400 | [diff] [blame] | 144 | void writeVarDeclaration(const VarDeclaration& decl); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 145 | |
| 146 | void writeFragCoord(); |
| 147 | |
| 148 | void writeVariableReference(const VariableReference& ref); |
| 149 | |
| 150 | void writeExpression(const Expression& expr, Precedence parentPrecedence); |
| 151 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 152 | void writeMinAbsHack(Expression& absExpr, Expression& otherExpr); |
| 153 | |
John Stiles | 06b84ef | 2020-12-09 12:35:48 -0500 | [diff] [blame] | 154 | String getOutParamHelper(const FunctionCall& c, |
| 155 | const ExpressionArray& arguments, |
| 156 | const SkTArray<VariableReference*>& outVars); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 157 | |
John Stiles | d7199b2 | 2020-12-30 16:22:58 -0500 | [diff] [blame] | 158 | String getInversePolyfill(const ExpressionArray& arguments); |
John Stiles | b21fac2 | 2020-12-04 15:36:49 -0500 | [diff] [blame] | 159 | |
John Stiles | f64e407 | 2020-12-10 10:34:27 -0500 | [diff] [blame] | 160 | String getBitcastIntrinsic(const Type& outType); |
| 161 | |
John Stiles | 86424eb | 2020-12-11 11:17:14 -0500 | [diff] [blame] | 162 | String getTempVariable(const Type& varType); |
| 163 | |
John Stiles | b21fac2 | 2020-12-04 15:36:49 -0500 | [diff] [blame] | 164 | void writeFunctionCall(const FunctionCall& c); |
Chris Dalton | dba7aab | 2018-11-15 10:57:49 -0500 | [diff] [blame] | 165 | |
John Stiles | 8cad637 | 2021-04-07 12:31:13 -0400 | [diff] [blame] | 166 | bool matrixConstructHelperIsNeeded(const ConstructorCompound& c); |
John Stiles | 5abb9e1 | 2021-04-06 13:47:19 -0400 | [diff] [blame] | 167 | String getMatrixConstructHelper(const AnyConstructor& c); |
John Stiles | fcf8cb2 | 2020-08-06 14:29:22 -0400 | [diff] [blame] | 168 | void assembleMatrixFromMatrix(const Type& sourceMatrix, int rows, int columns); |
John Stiles | 5abb9e1 | 2021-04-06 13:47:19 -0400 | [diff] [blame] | 169 | void assembleMatrixFromExpressions(const AnyConstructor& ctor, int rows, int columns); |
Ethan Nicholas | 842d31b | 2019-01-22 10:59:11 -0500 | [diff] [blame] | 170 | |
Brian Osman | 93aed9a | 2020-12-28 15:18:46 -0500 | [diff] [blame] | 171 | void writeMatrixCompMult(); |
John Stiles | 01cdf01 | 2021-02-10 09:53:41 -0500 | [diff] [blame] | 172 | |
John Stiles | feb1e12 | 2021-09-09 14:27:28 -0400 | [diff] [blame] | 173 | void writeOuterProduct(); |
| 174 | |
Ethan Nicholas | 0dc8087 | 2019-02-08 15:46:24 -0500 | [diff] [blame] | 175 | void writeMatrixTimesEqualHelper(const Type& left, const Type& right, const Type& result); |
| 176 | |
John Stiles | c985e14 | 2021-05-13 14:01:48 -0400 | [diff] [blame] | 177 | void writeMatrixDivisionHelpers(const Type& type); |
| 178 | |
John Stiles | 3934647 | 2021-04-29 14:39:35 -0400 | [diff] [blame] | 179 | void writeMatrixEqualityHelpers(const Type& left, const Type& right); |
John Stiles | 01cdf01 | 2021-02-10 09:53:41 -0500 | [diff] [blame] | 180 | |
John Stiles | c18ee4e | 2021-08-13 17:53:49 -0400 | [diff] [blame] | 181 | String getVectorFromMat2x2ConstructorHelper(const Type& matrixType); |
John Stiles | 6de2e1d | 2021-07-09 12:41:55 -0400 | [diff] [blame] | 182 | |
John Stiles | 3934647 | 2021-04-29 14:39:35 -0400 | [diff] [blame] | 183 | void writeArrayEqualityHelpers(const Type& type); |
| 184 | |
| 185 | void writeStructEqualityHelpers(const Type& type); |
| 186 | |
| 187 | void writeEqualityHelpers(const Type& leftType, const Type& rightType); |
John Stiles | 01cdf01 | 2021-02-10 09:53:41 -0500 | [diff] [blame] | 188 | |
John Stiles | d7199b2 | 2020-12-30 16:22:58 -0500 | [diff] [blame] | 189 | void writeArgumentList(const ExpressionArray& arguments); |
| 190 | |
John Stiles | 791c27d | 2020-12-30 14:56:57 -0500 | [diff] [blame] | 191 | void writeSimpleIntrinsic(const FunctionCall& c); |
| 192 | |
John Stiles | 496b7d1 | 2021-05-06 10:26:45 -0400 | [diff] [blame] | 193 | bool writeIntrinsicCall(const FunctionCall& c, IntrinsicKind kind); |
Timothy Liang | 6403b0e | 2018-05-17 10:40:04 -0400 | [diff] [blame] | 194 | |
Ethan Nicholas | 842d31b | 2019-01-22 10:59:11 -0500 | [diff] [blame] | 195 | bool canCoerce(const Type& t1, const Type& t2); |
| 196 | |
John Stiles | 8cad637 | 2021-04-07 12:31:13 -0400 | [diff] [blame] | 197 | void writeConstructorCompound(const ConstructorCompound& c, Precedence parentPrecedence); |
John Stiles | 2bec8ab | 2021-04-06 18:40:04 -0400 | [diff] [blame] | 198 | |
John Stiles | 6de2e1d | 2021-07-09 12:41:55 -0400 | [diff] [blame] | 199 | void writeConstructorCompoundVector(const ConstructorCompound& c, Precedence parentPrecedence); |
| 200 | |
John Stiles | 8cad637 | 2021-04-07 12:31:13 -0400 | [diff] [blame] | 201 | void writeConstructorCompoundMatrix(const ConstructorCompound& c, Precedence parentPrecedence); |
John Stiles | 2bec8ab | 2021-04-06 18:40:04 -0400 | [diff] [blame] | 202 | |
John Stiles | 5abb9e1 | 2021-04-06 13:47:19 -0400 | [diff] [blame] | 203 | void writeConstructorMatrixResize(const ConstructorMatrixResize& c, |
| 204 | Precedence parentPrecedence); |
| 205 | |
John Stiles | b14a819 | 2021-04-05 11:40:46 -0400 | [diff] [blame] | 206 | void writeAnyConstructor(const AnyConstructor& c, |
| 207 | const char* leftBracket, |
| 208 | const char* rightBracket, |
| 209 | Precedence parentPrecedence); |
John Stiles | 7384b37 | 2021-04-01 13:48:15 -0400 | [diff] [blame] | 210 | |
John Stiles | b14a819 | 2021-04-05 11:40:46 -0400 | [diff] [blame] | 211 | void writeCastConstructor(const AnyConstructor& c, |
| 212 | const char* leftBracket, |
| 213 | const char* rightBracket, |
| 214 | Precedence parentPrecedence); |
John Stiles | e118278 | 2021-03-30 22:09:37 -0400 | [diff] [blame] | 215 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 216 | void writeFieldAccess(const FieldAccess& f); |
| 217 | |
| 218 | void writeSwizzle(const Swizzle& swizzle); |
| 219 | |
John Stiles | 6b13129 | 2021-05-12 17:12:21 -0400 | [diff] [blame] | 220 | // Splats a scalar expression across a matrix of arbitrary size. |
| 221 | void writeNumberAsMatrix(const Expression& expr, const Type& matrixType); |
| 222 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 223 | void writeBinaryExpression(const BinaryExpression& b, Precedence parentPrecedence); |
| 224 | |
| 225 | void writeTernaryExpression(const TernaryExpression& t, Precedence parentPrecedence); |
| 226 | |
| 227 | void writeIndexExpression(const IndexExpression& expr); |
| 228 | |
| 229 | void writePrefixExpression(const PrefixExpression& p, Precedence parentPrecedence); |
| 230 | |
| 231 | void writePostfixExpression(const PostfixExpression& p, Precedence parentPrecedence); |
| 232 | |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame] | 233 | void writeLiteral(const Literal& f); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 234 | |
| 235 | void writeSetting(const Setting& s); |
| 236 | |
| 237 | void writeStatement(const Statement& s); |
| 238 | |
John Stiles | 8f2a0cf | 2020-10-13 12:48:21 -0400 | [diff] [blame] | 239 | void writeStatements(const StatementArray& statements); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 240 | |
| 241 | void writeBlock(const Block& b); |
| 242 | |
| 243 | void writeIfStatement(const IfStatement& stmt); |
| 244 | |
| 245 | void writeForStatement(const ForStatement& f); |
| 246 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 247 | void writeDoStatement(const DoStatement& d); |
| 248 | |
| 249 | void writeSwitchStatement(const SwitchStatement& s); |
| 250 | |
John Stiles | 986c7fb | 2020-12-01 14:44:56 -0500 | [diff] [blame] | 251 | void writeReturnStatementFromMain(); |
| 252 | |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 253 | void writeReturnStatement(const ReturnStatement& r); |
| 254 | |
| 255 | void writeProgramElement(const ProgramElement& e); |
| 256 | |
| 257 | Requirements requirements(const FunctionDeclaration& f); |
| 258 | |
Ethan Nicholas | ff350cb | 2020-05-14 14:05:13 -0400 | [diff] [blame] | 259 | Requirements requirements(const Expression* e); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 260 | |
Ethan Nicholas | ff350cb | 2020-05-14 14:05:13 -0400 | [diff] [blame] | 261 | Requirements requirements(const Statement* s); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 262 | |
John Stiles | da5cdf6 | 2021-01-28 11:47:29 -0500 | [diff] [blame] | 263 | int getUniformBinding(const Modifiers& m); |
| 264 | |
| 265 | int getUniformSet(const Modifiers& m); |
| 266 | |
Ethan Nicholas | 962dec4 | 2021-06-10 13:06:39 -0400 | [diff] [blame] | 267 | std::unordered_set<skstd::string_view> fReservedWords; |
Timothy Liang | a06f215 | 2018-05-24 15:33:31 -0400 | [diff] [blame] | 268 | std::unordered_map<const Type::Field*, const InterfaceBlock*> fInterfaceBlockMap; |
Ethan Nicholas | 3533ff1 | 2021-08-02 12:53:29 -0400 | [diff] [blame] | 269 | std::unordered_map<const InterfaceBlock*, skstd::string_view> fInterfaceBlockNameMap; |
Timothy Liang | a06f215 | 2018-05-24 15:33:31 -0400 | [diff] [blame] | 270 | int fAnonInterfaceCount = 0; |
Timothy Liang | 7d63778 | 2018-06-05 09:58:07 -0400 | [diff] [blame] | 271 | int fPaddingCount = 0; |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 272 | const char* fLineEnding; |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 273 | String fFunctionHeader; |
Chris Dalton | dba7aab | 2018-11-15 10:57:49 -0500 | [diff] [blame] | 274 | StringStream fExtraFunctions; |
John Stiles | 82d4c12 | 2021-08-10 16:03:23 -0400 | [diff] [blame] | 275 | StringStream fExtraFunctionPrototypes; |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 276 | int fVarCount = 0; |
| 277 | int fIndentation = 0; |
| 278 | bool fAtLineStart = false; |
Chris Dalton | dba7aab | 2018-11-15 10:57:49 -0500 | [diff] [blame] | 279 | std::set<String> fWrittenIntrinsics; |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 280 | // true if we have run into usages of dFdx / dFdy |
| 281 | bool fFoundDerivatives = false; |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 282 | std::unordered_map<const FunctionDeclaration*, Requirements> fRequirements; |
| 283 | bool fSetupFragPositionGlobal = false; |
| 284 | bool fSetupFragPositionLocal = false; |
John Stiles | 1bdafbf | 2020-05-28 12:17:20 -0400 | [diff] [blame] | 285 | std::unordered_set<String> fHelpers; |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 286 | int fUniformBuffer = -1; |
Brian Salomon | d8d85b9 | 2021-07-07 09:41:17 -0400 | [diff] [blame] | 287 | String fRTFlipName; |
John Stiles | 986c7fb | 2020-12-01 14:44:56 -0500 | [diff] [blame] | 288 | const FunctionDeclaration* fCurrentFunction = nullptr; |
John Stiles | 06b84ef | 2020-12-09 12:35:48 -0500 | [diff] [blame] | 289 | int fSwizzleHelperCount = 0; |
| 290 | bool fIgnoreVariableReferenceModifiers = false; |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 291 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 292 | using INHERITED = CodeGenerator; |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 293 | }; |
| 294 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 295 | } // namespace SkSL |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 296 | |
| 297 | #endif |