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 | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 7 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 8 | #ifndef SKSL_SPIRVCODEGENERATOR |
| 9 | #define SKSL_SPIRVCODEGENERATOR |
| 10 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 11 | #include <stack> |
| 12 | #include <tuple> |
| 13 | #include <unordered_map> |
| 14 | |
Ethan Nicholas | daed259 | 2021-03-04 14:30:25 -0500 | [diff] [blame] | 15 | #include "include/private/SkSLModifiers.h" |
Ethan Nicholas | 24c1772 | 2021-03-09 13:10:59 -0500 | [diff] [blame] | 16 | #include "include/private/SkSLProgramElement.h" |
| 17 | #include "include/private/SkSLStatement.h" |
John Stiles | cd80689 | 2021-01-06 13:33:31 -0500 | [diff] [blame] | 18 | #include "src/core/SkOpts.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/sksl/SkSLMemoryLayout.h" |
Mike Klein | 4b432fa | 2019-06-06 11:44:05 -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 | 7384b37 | 2021-04-01 13:48:15 -0400 | [diff] [blame] | 25 | #include "src/sksl/ir/SkSLConstructorArray.h" |
John Stiles | 8cad637 | 2021-04-07 12:31:13 -0400 | [diff] [blame] | 26 | #include "src/sksl/ir/SkSLConstructorCompound.h" |
| 27 | #include "src/sksl/ir/SkSLConstructorCompoundCast.h" |
John Stiles | e118278 | 2021-03-30 22:09:37 -0400 | [diff] [blame] | 28 | #include "src/sksl/ir/SkSLConstructorDiagonalMatrix.h" |
John Stiles | 5abb9e1 | 2021-04-06 13:47:19 -0400 | [diff] [blame] | 29 | #include "src/sksl/ir/SkSLConstructorMatrixResize.h" |
John Stiles | fd7252f | 2021-04-04 22:24:40 -0400 | [diff] [blame] | 30 | #include "src/sksl/ir/SkSLConstructorScalarCast.h" |
John Stiles | 2938eea | 2021-04-01 18:58:25 -0400 | [diff] [blame] | 31 | #include "src/sksl/ir/SkSLConstructorSplat.h" |
John Stiles | d47330f | 2021-04-08 23:25:52 -0400 | [diff] [blame] | 32 | #include "src/sksl/ir/SkSLConstructorStruct.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 33 | #include "src/sksl/ir/SkSLDoStatement.h" |
| 34 | #include "src/sksl/ir/SkSLFieldAccess.h" |
| 35 | #include "src/sksl/ir/SkSLFloatLiteral.h" |
| 36 | #include "src/sksl/ir/SkSLForStatement.h" |
| 37 | #include "src/sksl/ir/SkSLFunctionCall.h" |
| 38 | #include "src/sksl/ir/SkSLFunctionDeclaration.h" |
| 39 | #include "src/sksl/ir/SkSLFunctionDefinition.h" |
| 40 | #include "src/sksl/ir/SkSLIfStatement.h" |
| 41 | #include "src/sksl/ir/SkSLIndexExpression.h" |
| 42 | #include "src/sksl/ir/SkSLIntLiteral.h" |
| 43 | #include "src/sksl/ir/SkSLInterfaceBlock.h" |
| 44 | #include "src/sksl/ir/SkSLPostfixExpression.h" |
| 45 | #include "src/sksl/ir/SkSLPrefixExpression.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 46 | #include "src/sksl/ir/SkSLReturnStatement.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 47 | #include "src/sksl/ir/SkSLSwitchStatement.h" |
| 48 | #include "src/sksl/ir/SkSLSwizzle.h" |
| 49 | #include "src/sksl/ir/SkSLTernaryExpression.h" |
| 50 | #include "src/sksl/ir/SkSLVarDeclarations.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 51 | #include "src/sksl/ir/SkSLVariableReference.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 52 | #include "src/sksl/spirv.h" |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 53 | |
John Stiles | cd80689 | 2021-01-06 13:33:31 -0500 | [diff] [blame] | 54 | namespace SkSL { |
| 55 | |
John Stiles | bdc3d3c | 2021-01-06 18:41:40 -0500 | [diff] [blame] | 56 | struct SPIRVNumberConstant { |
| 57 | bool operator==(const SPIRVNumberConstant& that) const { |
| 58 | return fValueBits == that.fValueBits && |
| 59 | fKind == that.fKind; |
Ethan Nicholas | a3f22f1 | 2020-10-01 12:13:17 -0400 | [diff] [blame] | 60 | } |
John Stiles | bdc3d3c | 2021-01-06 18:41:40 -0500 | [diff] [blame] | 61 | int64_t fValueBits; // contains either an SKSL_INT or zero-padded bits from an SKSL_FLOAT |
| 62 | SkSL::Type::NumberKind fKind; |
Ethan Nicholas | cc5d3e0 | 2019-04-19 09:50:56 -0400 | [diff] [blame] | 63 | }; |
| 64 | |
John Stiles | cd80689 | 2021-01-06 13:33:31 -0500 | [diff] [blame] | 65 | struct SPIRVVectorConstant { |
| 66 | bool operator==(const SPIRVVectorConstant& that) const { |
| 67 | return fTypeId == that.fTypeId && |
| 68 | fValueId[0] == that.fValueId[0] && |
| 69 | fValueId[1] == that.fValueId[1] && |
| 70 | fValueId[2] == that.fValueId[2] && |
| 71 | fValueId[3] == that.fValueId[3]; |
| 72 | } |
| 73 | SpvId fTypeId; |
| 74 | SpvId fValueId[4]; |
| 75 | }; |
| 76 | |
| 77 | } // namespace SkSL |
| 78 | |
Ethan Nicholas | cc5d3e0 | 2019-04-19 09:50:56 -0400 | [diff] [blame] | 79 | namespace std { |
| 80 | |
| 81 | template <> |
John Stiles | bdc3d3c | 2021-01-06 18:41:40 -0500 | [diff] [blame] | 82 | struct hash<SkSL::SPIRVNumberConstant> { |
| 83 | size_t operator()(const SkSL::SPIRVNumberConstant& key) const { |
| 84 | return key.fValueBits ^ (int)key.fKind; |
Ethan Nicholas | cc5d3e0 | 2019-04-19 09:50:56 -0400 | [diff] [blame] | 85 | } |
| 86 | }; |
| 87 | |
John Stiles | cd80689 | 2021-01-06 13:33:31 -0500 | [diff] [blame] | 88 | template <> |
| 89 | struct hash<SkSL::SPIRVVectorConstant> { |
| 90 | size_t operator()(const SkSL::SPIRVVectorConstant& key) const { |
| 91 | return SkOpts::hash(&key, sizeof(key)); |
| 92 | } |
| 93 | }; |
| 94 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 95 | } // namespace std |
Ethan Nicholas | cc5d3e0 | 2019-04-19 09:50:56 -0400 | [diff] [blame] | 96 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 97 | namespace SkSL { |
| 98 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 99 | /** |
| 100 | * Converts a Program into a SPIR-V binary. |
| 101 | */ |
| 102 | class SPIRVCodeGenerator : public CodeGenerator { |
| 103 | public: |
| 104 | class LValue { |
| 105 | public: |
| 106 | virtual ~LValue() {} |
Greg Daniel | 64773e6 | 2016-11-22 09:44:03 -0500 | [diff] [blame] | 107 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 108 | // returns a pointer to the lvalue, if possible. If the lvalue cannot be directly referenced |
John Stiles | 3f14d28 | 2021-02-05 09:31:04 -0500 | [diff] [blame] | 109 | // by a pointer (e.g. vector swizzles), returns -1. |
| 110 | virtual SpvId getPointer() { return -1; } |
| 111 | |
Ethan Nicholas | e0707b7 | 2021-03-17 11:16:41 -0400 | [diff] [blame] | 112 | // Returns true if a valid pointer returned by getPointer represents a memory object |
| 113 | // (see https://github.com/KhronosGroup/SPIRV-Tools/issues/2892). Has no meaning if |
| 114 | // getPointer() returns -1. |
| 115 | virtual bool isMemoryObjectPointer() const { return true; } |
| 116 | |
John Stiles | 3f14d28 | 2021-02-05 09:31:04 -0500 | [diff] [blame] | 117 | // Applies a swizzle to the components of the LValue, if possible. This is used to create |
| 118 | // LValues that are swizzes-of-swizzles. Non-swizzle LValues can just return false. |
| 119 | virtual bool applySwizzle(const ComponentArray& components, const Type& newType) { |
| 120 | return false; |
| 121 | } |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 122 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 123 | virtual SpvId load(OutputStream& out) = 0; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 124 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 125 | virtual void store(SpvId value, OutputStream& out) = 0; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 126 | }; |
| 127 | |
Brian Osman | 8b43dad | 2020-10-09 13:31:42 -0400 | [diff] [blame] | 128 | SPIRVCodeGenerator(const Context* context, |
| 129 | const Program* program, |
| 130 | ErrorReporter* errors, |
| 131 | OutputStream* out) |
| 132 | : INHERITED(program, errors, out) |
| 133 | , fContext(*context) |
| 134 | , fDefaultLayout(MemoryLayout::k140_Standard) |
| 135 | , fCapabilities(0) |
| 136 | , fIdCount(1) |
| 137 | , fBoolTrue(0) |
| 138 | , fBoolFalse(0) |
| 139 | , fSetupFragPosition(false) |
| 140 | , fCurrentBlock(0) |
John Stiles | 7c3515b | 2020-10-16 18:38:39 -0400 | [diff] [blame] | 141 | , fSynthetics(errors, /*builtin=*/true) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 142 | this->setupIntrinsics(); |
| 143 | } |
| 144 | |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 145 | bool generateCode() override; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 146 | |
| 147 | private: |
John Stiles | aaac4e4 | 2021-05-06 14:08:28 -0400 | [diff] [blame] | 148 | enum IntrinsicOpcodeKind { |
| 149 | kGLSL_STD_450_IntrinsicOpcodeKind, |
| 150 | kSPIRV_IntrinsicOpcodeKind, |
| 151 | kSpecial_IntrinsicOpcodeKind |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | enum SpecialIntrinsic { |
| 155 | kAtan_SpecialIntrinsic, |
Ethan Nicholas | 0fc07f9 | 2018-02-27 15:25:47 -0500 | [diff] [blame] | 156 | kClamp_SpecialIntrinsic, |
Brian Osman | d1b593f | 2020-12-28 13:00:46 -0500 | [diff] [blame] | 157 | kMatrixCompMult_SpecialIntrinsic, |
Ethan Nicholas | 0fc07f9 | 2018-02-27 15:25:47 -0500 | [diff] [blame] | 158 | kMax_SpecialIntrinsic, |
| 159 | kMin_SpecialIntrinsic, |
| 160 | kMix_SpecialIntrinsic, |
Ethan Nicholas | 70a44b2 | 2017-11-30 09:09:16 -0500 | [diff] [blame] | 161 | kMod_SpecialIntrinsic, |
Chris Dalton | b8af5ad | 2019-02-25 14:54:21 -0700 | [diff] [blame] | 162 | kDFdy_SpecialIntrinsic, |
Ethan Nicholas | 12fb9cf | 2018-08-03 16:16:57 -0400 | [diff] [blame] | 163 | kSaturate_SpecialIntrinsic, |
Stephen White | ff5d7a2 | 2019-07-26 17:42:06 -0400 | [diff] [blame] | 164 | kSampledImage_SpecialIntrinsic, |
Brian Osman | 6ba3be1 | 2020-11-13 16:32:52 -0500 | [diff] [blame] | 165 | kSmoothStep_SpecialIntrinsic, |
| 166 | kStep_SpecialIntrinsic, |
Greg Daniel | 64773e6 | 2016-11-22 09:44:03 -0500 | [diff] [blame] | 167 | kSubpassLoad_SpecialIntrinsic, |
Ethan Nicholas | 0187ae6 | 2017-05-03 11:03:44 -0400 | [diff] [blame] | 168 | kTexture_SpecialIntrinsic, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 169 | }; |
| 170 | |
Ethan Nicholas | 10e93b6 | 2019-03-20 10:46:14 -0400 | [diff] [blame] | 171 | enum class Precision { |
Ethan Nicholas | 8f352ce | 2021-03-17 14:12:20 -0400 | [diff] [blame] | 172 | kDefault, |
| 173 | kRelaxed, |
Ethan Nicholas | 10e93b6 | 2019-03-20 10:46:14 -0400 | [diff] [blame] | 174 | }; |
| 175 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 176 | void setupIntrinsics(); |
| 177 | |
Ethan Nicholas | 8f352ce | 2021-03-17 14:12:20 -0400 | [diff] [blame] | 178 | /** |
| 179 | * Pass in the type to automatically add a RelaxedPrecision decoration for the id when |
| 180 | * appropriate, or null to never add one. |
| 181 | */ |
| 182 | SpvId nextId(const Type* type); |
| 183 | |
| 184 | SpvId nextId(Precision precision); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 185 | |
Ethan Nicholas | e2c4999 | 2020-10-05 11:49:11 -0400 | [diff] [blame] | 186 | const Type& getActualType(const Type& type); |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 187 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 188 | SpvId getType(const Type& type); |
| 189 | |
ethannicholas | 8ac838d | 2016-11-22 08:39:36 -0800 | [diff] [blame] | 190 | SpvId getType(const Type& type, const MemoryLayout& layout); |
| 191 | |
Ethan Nicholas | 0187ae6 | 2017-05-03 11:03:44 -0400 | [diff] [blame] | 192 | SpvId getImageType(const Type& type); |
| 193 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 194 | SpvId getFunctionType(const FunctionDeclaration& function); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 195 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 196 | SpvId getPointerType(const Type& type, SpvStorageClass_ storageClass); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 197 | |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 198 | SpvId getPointerType(const Type& type, const MemoryLayout& layout, |
ethannicholas | 8ac838d | 2016-11-22 08:39:36 -0800 | [diff] [blame] | 199 | SpvStorageClass_ storageClass); |
| 200 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 201 | std::vector<SpvId> getAccessChain(const Expression& expr, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 202 | |
| 203 | void writeLayout(const Layout& layout, SpvId target); |
| 204 | |
| 205 | void writeLayout(const Layout& layout, SpvId target, int member); |
| 206 | |
ethannicholas | 8ac838d | 2016-11-22 08:39:36 -0800 | [diff] [blame] | 207 | void writeStruct(const Type& type, const MemoryLayout& layout, SpvId resultId); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 208 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 209 | void writeProgramElement(const ProgramElement& pe, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 210 | |
Stephen White | 8857497 | 2020-06-23 19:09:29 -0400 | [diff] [blame] | 211 | SpvId writeInterfaceBlock(const InterfaceBlock& intf, bool appendRTHeight = true); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 212 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 213 | SpvId writeFunctionStart(const FunctionDeclaration& f, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 214 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 215 | SpvId writeFunctionDeclaration(const FunctionDeclaration& f, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 216 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 217 | SpvId writeFunction(const FunctionDefinition& f, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 218 | |
John Stiles | dbd4e6f | 2021-02-16 13:29:15 -0500 | [diff] [blame] | 219 | void writeGlobalVar(ProgramKind kind, const VarDeclaration& v); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 220 | |
Brian Osman | c021360 | 2020-10-06 14:43:32 -0400 | [diff] [blame] | 221 | void writeVarDeclaration(const VarDeclaration& var, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 222 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 223 | SpvId writeVariableReference(const VariableReference& ref, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 224 | |
John Stiles | e40d166 | 2021-01-29 10:08:50 -0500 | [diff] [blame] | 225 | int findUniformFieldIndex(const Variable& var) const; |
| 226 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 227 | std::unique_ptr<LValue> getLValue(const Expression& value, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 228 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 229 | SpvId writeExpression(const Expression& expr, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 230 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 231 | SpvId writeIntrinsicCall(const FunctionCall& c, OutputStream& out); |
| 232 | |
| 233 | SpvId writeFunctionCall(const FunctionCall& c, OutputStream& out); |
| 234 | |
Ethan Nicholas | 0fc07f9 | 2018-02-27 15:25:47 -0500 | [diff] [blame] | 235 | |
| 236 | void writeGLSLExtendedInstruction(const Type& type, SpvId id, SpvId floatInst, |
| 237 | SpvId signedInst, SpvId unsignedInst, |
| 238 | const std::vector<SpvId>& args, OutputStream& out); |
| 239 | |
| 240 | /** |
| 241 | * Given a list of potentially mixed scalars and vectors, promotes the scalars to match the |
| 242 | * size of the vectors and returns the ids of the written expressions. e.g. given (float, vec2), |
| 243 | * returns (vec2(float), vec2). It is an error to use mismatched vector sizes, e.g. (float, |
| 244 | * vec2, vec3). |
| 245 | */ |
John Stiles | 8e3b6be | 2020-10-13 11:14:08 -0400 | [diff] [blame] | 246 | std::vector<SpvId> vectorize(const ExpressionArray& args, OutputStream& out); |
Ethan Nicholas | 0fc07f9 | 2018-02-27 15:25:47 -0500 | [diff] [blame] | 247 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 248 | SpvId writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 249 | |
John Stiles | 2938eea | 2021-04-01 18:58:25 -0400 | [diff] [blame] | 250 | SpvId writeConstantVector(const AnyConstructor& c); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 251 | |
John Stiles | a91bf05 | 2021-05-17 09:34:03 -0400 | [diff] [blame] | 252 | SpvId writeScalarToMatrixSplat(const Type& matrixType, SpvId scalarId, OutputStream& out); |
| 253 | |
John Stiles | fd7252f | 2021-04-04 22:24:40 -0400 | [diff] [blame] | 254 | SpvId writeFloatConstructor(const AnyConstructor& c, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 255 | |
John Stiles | d9d5271 | 2021-01-13 17:15:02 -0500 | [diff] [blame] | 256 | SpvId castScalarToFloat(SpvId inputId, const Type& inputType, const Type& outputType, |
| 257 | OutputStream& out); |
| 258 | |
John Stiles | fd7252f | 2021-04-04 22:24:40 -0400 | [diff] [blame] | 259 | SpvId writeIntConstructor(const AnyConstructor& c, OutputStream& out); |
Ethan Nicholas | 84645e3 | 2017-02-09 13:57:14 -0500 | [diff] [blame] | 260 | |
John Stiles | d9d5271 | 2021-01-13 17:15:02 -0500 | [diff] [blame] | 261 | SpvId castScalarToSignedInt(SpvId inputId, const Type& inputType, const Type& outputType, |
| 262 | OutputStream& out); |
| 263 | |
John Stiles | fd7252f | 2021-04-04 22:24:40 -0400 | [diff] [blame] | 264 | SpvId writeUIntConstructor(const AnyConstructor& c, OutputStream& out); |
Ethan Nicholas | 925f52d | 2017-07-19 10:42:50 -0400 | [diff] [blame] | 265 | |
John Stiles | d9d5271 | 2021-01-13 17:15:02 -0500 | [diff] [blame] | 266 | SpvId castScalarToUnsignedInt(SpvId inputId, const Type& inputType, const Type& outputType, |
| 267 | OutputStream& out); |
| 268 | |
John Stiles | fd7252f | 2021-04-04 22:24:40 -0400 | [diff] [blame] | 269 | SpvId writeBooleanConstructor(const AnyConstructor& c, OutputStream& out); |
John Stiles | a60fb17 | 2021-01-14 11:06:20 -0500 | [diff] [blame] | 270 | |
John Stiles | 48c2884 | 2021-01-14 11:05:03 -0500 | [diff] [blame] | 271 | SpvId castScalarToBoolean(SpvId inputId, const Type& inputType, const Type& outputType, |
| 272 | OutputStream& out); |
| 273 | |
John Stiles | b14a819 | 2021-04-05 11:40:46 -0400 | [diff] [blame] | 274 | SpvId castScalarToType(SpvId inputExprId, const Type& inputType, const Type& outputType, |
| 275 | OutputStream& out); |
| 276 | |
Ethan Nicholas | 84645e3 | 2017-02-09 13:57:14 -0500 | [diff] [blame] | 277 | /** |
| 278 | * Writes a matrix with the diagonal entries all equal to the provided expression, and all other |
| 279 | * entries equal to zero. |
| 280 | */ |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 281 | void writeUniformScaleMatrix(SpvId id, SpvId diagonal, const Type& type, OutputStream& out); |
Ethan Nicholas | 84645e3 | 2017-02-09 13:57:14 -0500 | [diff] [blame] | 282 | |
| 283 | /** |
| 284 | * Writes a potentially-different-sized copy of a matrix. Entries which do not exist in the |
| 285 | * source matrix are filled with zero; entries which do not exist in the destination matrix are |
| 286 | * ignored. |
| 287 | */ |
John Stiles | 268a73f | 2021-04-07 12:30:22 -0400 | [diff] [blame] | 288 | SpvId writeMatrixCopy(SpvId src, const Type& srcType, const Type& dstType, OutputStream& out); |
Ethan Nicholas | 84645e3 | 2017-02-09 13:57:14 -0500 | [diff] [blame] | 289 | |
Ethan Nicholas | cc5d3e0 | 2019-04-19 09:50:56 -0400 | [diff] [blame] | 290 | void addColumnEntry(SpvId columnType, Precision precision, std::vector<SpvId>* currentColumn, |
Ethan Nicholas | 5c46b72 | 2019-03-22 14:32:37 -0400 | [diff] [blame] | 291 | std::vector<SpvId>* columnIds, int* currentCount, int rows, SpvId entry, |
| 292 | OutputStream& out); |
| 293 | |
John Stiles | 8cad637 | 2021-04-07 12:31:13 -0400 | [diff] [blame] | 294 | SpvId writeConstructorCompound(const ConstructorCompound& c, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 295 | |
John Stiles | 8cad637 | 2021-04-07 12:31:13 -0400 | [diff] [blame] | 296 | SpvId writeMatrixConstructor(const ConstructorCompound& c, OutputStream& out); |
John Stiles | 2bec8ab | 2021-04-06 18:40:04 -0400 | [diff] [blame] | 297 | |
John Stiles | 8cad637 | 2021-04-07 12:31:13 -0400 | [diff] [blame] | 298 | SpvId writeVectorConstructor(const ConstructorCompound& c, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 299 | |
John Stiles | d47330f | 2021-04-08 23:25:52 -0400 | [diff] [blame] | 300 | SpvId writeCompositeConstructor(const AnyConstructor& c, OutputStream& out); |
Ethan Nicholas | bd55322 | 2017-07-18 15:54:59 -0400 | [diff] [blame] | 301 | |
John Stiles | e118278 | 2021-03-30 22:09:37 -0400 | [diff] [blame] | 302 | SpvId writeConstructorDiagonalMatrix(const ConstructorDiagonalMatrix& c, OutputStream& out); |
| 303 | |
John Stiles | 5abb9e1 | 2021-04-06 13:47:19 -0400 | [diff] [blame] | 304 | SpvId writeConstructorMatrixResize(const ConstructorMatrixResize& c, OutputStream& out); |
| 305 | |
John Stiles | fd7252f | 2021-04-04 22:24:40 -0400 | [diff] [blame] | 306 | SpvId writeConstructorScalarCast(const ConstructorScalarCast& c, OutputStream& out); |
| 307 | |
John Stiles | 2938eea | 2021-04-01 18:58:25 -0400 | [diff] [blame] | 308 | SpvId writeConstructorSplat(const ConstructorSplat& c, OutputStream& out); |
| 309 | |
John Stiles | 8cad637 | 2021-04-07 12:31:13 -0400 | [diff] [blame] | 310 | SpvId writeConstructorCompoundCast(const ConstructorCompoundCast& c, OutputStream& out); |
John Stiles | b14a819 | 2021-04-05 11:40:46 -0400 | [diff] [blame] | 311 | |
| 312 | SpvId writeComposite(const std::vector<SpvId>& arguments, const Type& type, OutputStream& out); |
| 313 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 314 | SpvId writeFieldAccess(const FieldAccess& f, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 315 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 316 | SpvId writeSwizzle(const Swizzle& swizzle, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 317 | |
Ethan Nicholas | ef653b8 | 2017-02-21 13:50:00 -0500 | [diff] [blame] | 318 | /** |
| 319 | * Folds the potentially-vector result of a logical operation down to a single bool. If |
| 320 | * operandType is a vector type, assumes that the intermediate result in id is a bvec of the |
| 321 | * same dimensions, and applys all() to it to fold it down to a single bool value. Otherwise, |
| 322 | * returns the original id value. |
| 323 | */ |
Ethan Nicholas | 48e2405 | 2018-03-14 13:51:39 -0400 | [diff] [blame] | 324 | SpvId foldToBool(SpvId id, const Type& operandType, SpvOp op, OutputStream& out); |
Ethan Nicholas | ef653b8 | 2017-02-21 13:50:00 -0500 | [diff] [blame] | 325 | |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 326 | SpvId writeMatrixComparison(const Type& operandType, SpvId lhs, SpvId rhs, SpvOp_ floatOperator, |
Ethan Nicholas | 0df2113 | 2018-07-10 09:37:51 -0400 | [diff] [blame] | 327 | SpvOp_ intOperator, SpvOp_ vectorMergeOperator, |
| 328 | SpvOp_ mergeOperator, OutputStream& out); |
| 329 | |
John Stiles | bc5c2a0 | 2021-04-08 11:44:53 -0400 | [diff] [blame] | 330 | SpvId writeStructComparison(const Type& structType, SpvId lhs, Operator op, SpvId rhs, |
| 331 | OutputStream& out); |
| 332 | |
John Stiles | 3509210 | 2021-04-08 23:30:51 -0400 | [diff] [blame] | 333 | SpvId writeArrayComparison(const Type& structType, SpvId lhs, Operator op, SpvId rhs, |
| 334 | OutputStream& out); |
| 335 | |
| 336 | // Used by writeStructComparison and writeArrayComparison to logically combine field-by-field |
| 337 | // comparisons into an overall comparison result. |
| 338 | // - `a.x == b.x` merged with `a.y == b.y` generates `(a.x == b.x) && (a.y == b.y)` |
| 339 | // - `a.x != b.x` merged with `a.y != b.y` generates `(a.x != b.x) || (a.y != b.y)` |
| 340 | SpvId mergeComparisons(SpvId comparison, SpvId allComparisons, Operator op, OutputStream& out); |
| 341 | |
Ethan Nicholas | 0df2113 | 2018-07-10 09:37:51 -0400 | [diff] [blame] | 342 | SpvId writeComponentwiseMatrixBinary(const Type& operandType, SpvId lhs, SpvId rhs, |
John Stiles | 43b593c | 2021-05-13 22:03:27 -0400 | [diff] [blame] | 343 | SpvOp_ op, OutputStream& out); |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 344 | |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 345 | SpvId writeBinaryOperation(const Type& resultType, const Type& operandType, SpvId lhs, |
| 346 | SpvId rhs, SpvOp_ ifFloat, SpvOp_ ifInt, SpvOp_ ifUInt, |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 347 | SpvOp_ ifBool, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 348 | |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 349 | SpvId writeBinaryOperation(const BinaryExpression& expr, SpvOp_ ifFloat, SpvOp_ ifInt, |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 350 | SpvOp_ ifUInt, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 351 | |
John Stiles | d94bfdd | 2021-03-25 11:44:08 -0400 | [diff] [blame] | 352 | SpvId writeReciprocal(const Type& type, SpvId value, OutputStream& out); |
| 353 | |
John Stiles | 4599050 | 2021-02-16 10:55:27 -0500 | [diff] [blame] | 354 | SpvId writeBinaryExpression(const Type& leftType, SpvId lhs, Operator op, |
Ethan Nicholas | 49465b4 | 2019-04-17 12:22:21 -0400 | [diff] [blame] | 355 | const Type& rightType, SpvId rhs, const Type& resultType, |
| 356 | OutputStream& out); |
| 357 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 358 | SpvId writeBinaryExpression(const BinaryExpression& b, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 359 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 360 | SpvId writeTernaryExpression(const TernaryExpression& t, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 361 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 362 | SpvId writeIndexExpression(const IndexExpression& expr, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 363 | |
John Stiles | bc5c2a0 | 2021-04-08 11:44:53 -0400 | [diff] [blame] | 364 | SpvId writeLogicalAnd(const Expression& left, const Expression& right, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 365 | |
John Stiles | bc5c2a0 | 2021-04-08 11:44:53 -0400 | [diff] [blame] | 366 | SpvId writeLogicalOr(const Expression& left, const Expression& right, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 367 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 368 | SpvId writePrefixExpression(const PrefixExpression& p, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 369 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 370 | SpvId writePostfixExpression(const PostfixExpression& p, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 371 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 372 | SpvId writeBoolLiteral(const BoolLiteral& b); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 373 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 374 | SpvId writeIntLiteral(const IntLiteral& i); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 375 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 376 | SpvId writeFloatLiteral(const FloatLiteral& f); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 377 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 378 | void writeStatement(const Statement& s, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 379 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 380 | void writeBlock(const Block& b, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 381 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 382 | void writeIfStatement(const IfStatement& stmt, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 383 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 384 | void writeForStatement(const ForStatement& f, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 385 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 386 | void writeDoStatement(const DoStatement& d, OutputStream& out); |
Ethan Nicholas | fd146aa | 2017-01-13 16:40:35 -0500 | [diff] [blame] | 387 | |
Ethan Nicholas | e92b1b1 | 2017-11-13 16:13:21 -0500 | [diff] [blame] | 388 | void writeSwitchStatement(const SwitchStatement& s, OutputStream& out); |
| 389 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 390 | void writeReturnStatement(const ReturnStatement& r, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 391 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 392 | void writeCapabilities(OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 393 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 394 | void writeInstructions(const Program& program, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 395 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 396 | void writeOpCode(SpvOp_ opCode, int length, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 397 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 398 | void writeWord(int32_t word, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 399 | |
Ethan Nicholas | 962dec4 | 2021-06-10 13:06:39 -0400 | [diff] [blame^] | 400 | void writeString(skstd::string_view s, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 401 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 402 | void writeLabel(SpvId id, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 403 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 404 | void writeInstruction(SpvOp_ opCode, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 405 | |
Ethan Nicholas | 962dec4 | 2021-06-10 13:06:39 -0400 | [diff] [blame^] | 406 | void writeInstruction(SpvOp_ opCode, skstd::string_view string, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 407 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 408 | void writeInstruction(SpvOp_ opCode, int32_t word1, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 409 | |
Ethan Nicholas | 962dec4 | 2021-06-10 13:06:39 -0400 | [diff] [blame^] | 410 | void writeInstruction(SpvOp_ opCode, int32_t word1, skstd::string_view string, |
| 411 | OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 412 | |
Ethan Nicholas | 962dec4 | 2021-06-10 13:06:39 -0400 | [diff] [blame^] | 413 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, skstd::string_view string, |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 414 | OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 415 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 416 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 417 | |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 418 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 419 | OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 420 | |
| 421 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 422 | OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 423 | |
| 424 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 425 | int32_t word5, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 426 | |
| 427 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 428 | int32_t word5, int32_t word6, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 429 | |
| 430 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 431 | int32_t word5, int32_t word6, int32_t word7, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 432 | |
| 433 | void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 434 | int32_t word5, int32_t word6, int32_t word7, int32_t word8, |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 435 | OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 436 | |
Ethan Nicholas | bb155e2 | 2017-07-24 10:05:09 -0400 | [diff] [blame] | 437 | void writeGeometryShaderExecutionMode(SpvId entryPoint, OutputStream& out); |
| 438 | |
Brian Osman | 2a4c0fb | 2021-01-22 13:41:40 -0500 | [diff] [blame] | 439 | MemoryLayout memoryLayoutForVariable(const Variable&) const; |
| 440 | |
John Stiles | 4d6310a | 2021-01-26 19:58:22 -0500 | [diff] [blame] | 441 | struct EntrypointAdapter { |
| 442 | std::unique_ptr<FunctionDefinition> entrypointDef; |
| 443 | std::unique_ptr<FunctionDeclaration> entrypointDecl; |
| 444 | Layout fLayout; |
| 445 | Modifiers fModifiers; |
| 446 | }; |
| 447 | |
| 448 | EntrypointAdapter writeEntrypointAdapter(const FunctionDeclaration& main); |
| 449 | |
John Stiles | e40d166 | 2021-01-29 10:08:50 -0500 | [diff] [blame] | 450 | struct UniformBuffer { |
| 451 | std::unique_ptr<InterfaceBlock> fInterfaceBlock; |
| 452 | std::unique_ptr<Variable> fInnerVariable; |
| 453 | std::unique_ptr<Type> fStruct; |
| 454 | }; |
| 455 | |
| 456 | void writeUniformBuffer(std::shared_ptr<SymbolTable> topLevelSymbolTable); |
| 457 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 458 | const Context& fContext; |
ethannicholas | 8ac838d | 2016-11-22 08:39:36 -0800 | [diff] [blame] | 459 | const MemoryLayout fDefaultLayout; |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 460 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 461 | uint64_t fCapabilities; |
| 462 | SpvId fIdCount; |
| 463 | SpvId fGLSLExtendedInstructions; |
John Stiles | aaac4e4 | 2021-05-06 14:08:28 -0400 | [diff] [blame] | 464 | typedef std::tuple<IntrinsicOpcodeKind, int32_t, int32_t, int32_t, int32_t> Intrinsic; |
| 465 | std::unordered_map<IntrinsicKind, Intrinsic> fIntrinsicMap; |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 466 | std::unordered_map<const FunctionDeclaration*, SpvId> fFunctionMap; |
| 467 | std::unordered_map<const Variable*, SpvId> fVariableMap; |
| 468 | std::unordered_map<const Variable*, int32_t> fInterfaceBlockMap; |
Ethan Nicholas | 0187ae6 | 2017-05-03 11:03:44 -0400 | [diff] [blame] | 469 | std::unordered_map<String, SpvId> fImageTypeMap; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 470 | std::unordered_map<String, SpvId> fTypeMap; |
| 471 | StringStream fCapabilitiesBuffer; |
| 472 | StringStream fGlobalInitializersBuffer; |
| 473 | StringStream fConstantBuffer; |
| 474 | StringStream fExtraGlobalsBuffer; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 475 | StringStream fVariableBuffer; |
| 476 | StringStream fNameBuffer; |
| 477 | StringStream fDecorationBuffer; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 478 | |
| 479 | SpvId fBoolTrue; |
| 480 | SpvId fBoolFalse; |
John Stiles | bdc3d3c | 2021-01-06 18:41:40 -0500 | [diff] [blame] | 481 | std::unordered_map<SPIRVNumberConstant, SpvId> fNumberConstants; |
John Stiles | cd80689 | 2021-01-06 13:33:31 -0500 | [diff] [blame] | 482 | std::unordered_map<SPIRVVectorConstant, SpvId> fVectorConstants; |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 483 | bool fSetupFragPosition; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 484 | // label of the current block, or 0 if we are not in a block |
| 485 | SpvId fCurrentBlock; |
| 486 | std::stack<SpvId> fBreakTarget; |
| 487 | std::stack<SpvId> fContinueTarget; |
Greg Daniel | e6ab998 | 2018-08-22 13:56:32 +0000 | [diff] [blame] | 488 | SpvId fRTHeightStructId = (SpvId) -1; |
| 489 | SpvId fRTHeightFieldIndex = (SpvId) -1; |
Jim Van Verth | f3ec983 | 2020-10-21 16:09:57 -0400 | [diff] [blame] | 490 | SpvStorageClass_ fRTHeightStorageClass; |
Ethan Nicholas | 8feeff9 | 2017-03-30 14:11:58 -0400 | [diff] [blame] | 491 | // holds variables synthesized during output, for lifetime purposes |
| 492 | SymbolTable fSynthetics; |
Ethan Nicholas | 5226b77 | 2018-05-03 16:20:41 -0400 | [diff] [blame] | 493 | int fSkInCount = 1; |
John Stiles | e40d166 | 2021-01-29 10:08:50 -0500 | [diff] [blame] | 494 | // Holds a list of uniforms that were declared as globals at the top-level instead of in an |
| 495 | // interface block. |
| 496 | UniformBuffer fUniformBuffer; |
| 497 | std::vector<const VarDeclaration*> fTopLevelUniforms; |
| 498 | std::unordered_map<const Variable*, int> fTopLevelUniformMap; //<var, UniformBuffer field index> |
| 499 | SpvId fUniformBufferId = -1; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 500 | |
| 501 | friend class PointerLValue; |
| 502 | friend class SwizzleLValue; |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 503 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 504 | using INHERITED = CodeGenerator; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 505 | }; |
| 506 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 507 | } // namespace SkSL |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 508 | |
| 509 | #endif |