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