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 | */ |
| 7 | |
| 8 | #include "SkSLSPIRVCodeGenerator.h" |
| 9 | |
| 10 | #include "string.h" |
| 11 | |
| 12 | #include "GLSL.std.450.h" |
| 13 | |
| 14 | #include "ir/SkSLExpressionStatement.h" |
| 15 | #include "ir/SkSLExtension.h" |
| 16 | #include "ir/SkSLIndexExpression.h" |
| 17 | #include "ir/SkSLVariableReference.h" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 18 | #include "SkSLCompiler.h" |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 19 | |
| 20 | namespace SkSL { |
| 21 | |
| 22 | #define SPIRV_DEBUG 0 |
| 23 | |
| 24 | static const int32_t SKSL_MAGIC = 0x0; // FIXME: we should probably register a magic number |
| 25 | |
| 26 | void SPIRVCodeGenerator::setupIntrinsics() { |
| 27 | #define ALL_GLSL(x) std::make_tuple(kGLSL_STD_450_IntrinsicKind, GLSLstd450 ## x, GLSLstd450 ## x, \ |
| 28 | GLSLstd450 ## x, GLSLstd450 ## x) |
| 29 | #define BY_TYPE_GLSL(ifFloat, ifInt, ifUInt) std::make_tuple(kGLSL_STD_450_IntrinsicKind, \ |
| 30 | GLSLstd450 ## ifFloat, \ |
| 31 | GLSLstd450 ## ifInt, \ |
| 32 | GLSLstd450 ## ifUInt, \ |
| 33 | SpvOpUndef) |
| 34 | #define SPECIAL(x) std::make_tuple(kSpecial_IntrinsicKind, k ## x ## _SpecialIntrinsic, \ |
| 35 | k ## x ## _SpecialIntrinsic, k ## x ## _SpecialIntrinsic, \ |
| 36 | k ## x ## _SpecialIntrinsic) |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 37 | fIntrinsicMap[SkString("round")] = ALL_GLSL(Round); |
| 38 | fIntrinsicMap[SkString("roundEven")] = ALL_GLSL(RoundEven); |
| 39 | fIntrinsicMap[SkString("trunc")] = ALL_GLSL(Trunc); |
| 40 | fIntrinsicMap[SkString("abs")] = BY_TYPE_GLSL(FAbs, SAbs, SAbs); |
| 41 | fIntrinsicMap[SkString("sign")] = BY_TYPE_GLSL(FSign, SSign, SSign); |
| 42 | fIntrinsicMap[SkString("floor")] = ALL_GLSL(Floor); |
| 43 | fIntrinsicMap[SkString("ceil")] = ALL_GLSL(Ceil); |
| 44 | fIntrinsicMap[SkString("fract")] = ALL_GLSL(Fract); |
| 45 | fIntrinsicMap[SkString("radians")] = ALL_GLSL(Radians); |
| 46 | fIntrinsicMap[SkString("degrees")] = ALL_GLSL(Degrees); |
| 47 | fIntrinsicMap[SkString("sin")] = ALL_GLSL(Sin); |
| 48 | fIntrinsicMap[SkString("cos")] = ALL_GLSL(Cos); |
| 49 | fIntrinsicMap[SkString("tan")] = ALL_GLSL(Tan); |
| 50 | fIntrinsicMap[SkString("asin")] = ALL_GLSL(Asin); |
| 51 | fIntrinsicMap[SkString("acos")] = ALL_GLSL(Acos); |
| 52 | fIntrinsicMap[SkString("atan")] = SPECIAL(Atan); |
| 53 | fIntrinsicMap[SkString("sinh")] = ALL_GLSL(Sinh); |
| 54 | fIntrinsicMap[SkString("cosh")] = ALL_GLSL(Cosh); |
| 55 | fIntrinsicMap[SkString("tanh")] = ALL_GLSL(Tanh); |
| 56 | fIntrinsicMap[SkString("asinh")] = ALL_GLSL(Asinh); |
| 57 | fIntrinsicMap[SkString("acosh")] = ALL_GLSL(Acosh); |
| 58 | fIntrinsicMap[SkString("atanh")] = ALL_GLSL(Atanh); |
| 59 | fIntrinsicMap[SkString("pow")] = ALL_GLSL(Pow); |
| 60 | fIntrinsicMap[SkString("exp")] = ALL_GLSL(Exp); |
| 61 | fIntrinsicMap[SkString("log")] = ALL_GLSL(Log); |
| 62 | fIntrinsicMap[SkString("exp2")] = ALL_GLSL(Exp2); |
| 63 | fIntrinsicMap[SkString("log2")] = ALL_GLSL(Log2); |
| 64 | fIntrinsicMap[SkString("sqrt")] = ALL_GLSL(Sqrt); |
| 65 | fIntrinsicMap[SkString("inversesqrt")] = ALL_GLSL(InverseSqrt); |
| 66 | fIntrinsicMap[SkString("determinant")] = ALL_GLSL(Determinant); |
| 67 | fIntrinsicMap[SkString("matrixInverse")] = ALL_GLSL(MatrixInverse); |
| 68 | fIntrinsicMap[SkString("mod")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpFMod, |
| 69 | SpvOpSMod, SpvOpUMod, SpvOpUndef); |
| 70 | fIntrinsicMap[SkString("min")] = BY_TYPE_GLSL(FMin, SMin, UMin); |
| 71 | fIntrinsicMap[SkString("max")] = BY_TYPE_GLSL(FMax, SMax, UMax); |
| 72 | fIntrinsicMap[SkString("clamp")] = BY_TYPE_GLSL(FClamp, SClamp, UClamp); |
| 73 | fIntrinsicMap[SkString("dot")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDot, |
| 74 | SpvOpUndef, SpvOpUndef, SpvOpUndef); |
| 75 | fIntrinsicMap[SkString("mix")] = ALL_GLSL(FMix); |
| 76 | fIntrinsicMap[SkString("step")] = ALL_GLSL(Step); |
| 77 | fIntrinsicMap[SkString("smoothstep")] = ALL_GLSL(SmoothStep); |
| 78 | fIntrinsicMap[SkString("fma")] = ALL_GLSL(Fma); |
| 79 | fIntrinsicMap[SkString("frexp")] = ALL_GLSL(Frexp); |
| 80 | fIntrinsicMap[SkString("ldexp")] = ALL_GLSL(Ldexp); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 81 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 82 | #define PACK(type) fIntrinsicMap[SkString("pack" #type)] = ALL_GLSL(Pack ## type); \ |
| 83 | fIntrinsicMap[SkString("unpack" #type)] = ALL_GLSL(Unpack ## type) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 84 | PACK(Snorm4x8); |
| 85 | PACK(Unorm4x8); |
| 86 | PACK(Snorm2x16); |
| 87 | PACK(Unorm2x16); |
| 88 | PACK(Half2x16); |
| 89 | PACK(Double2x32); |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 90 | fIntrinsicMap[SkString("length")] = ALL_GLSL(Length); |
| 91 | fIntrinsicMap[SkString("distance")] = ALL_GLSL(Distance); |
| 92 | fIntrinsicMap[SkString("cross")] = ALL_GLSL(Cross); |
| 93 | fIntrinsicMap[SkString("normalize")] = ALL_GLSL(Normalize); |
| 94 | fIntrinsicMap[SkString("faceForward")] = ALL_GLSL(FaceForward); |
| 95 | fIntrinsicMap[SkString("reflect")] = ALL_GLSL(Reflect); |
| 96 | fIntrinsicMap[SkString("refract")] = ALL_GLSL(Refract); |
| 97 | fIntrinsicMap[SkString("findLSB")] = ALL_GLSL(FindILsb); |
| 98 | fIntrinsicMap[SkString("findMSB")] = BY_TYPE_GLSL(FindSMsb, FindSMsb, FindUMsb); |
| 99 | fIntrinsicMap[SkString("dFdx")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdx, |
| 100 | SpvOpUndef, SpvOpUndef, SpvOpUndef); |
| 101 | fIntrinsicMap[SkString("dFdy")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdy, |
| 102 | SpvOpUndef, SpvOpUndef, SpvOpUndef); |
| 103 | fIntrinsicMap[SkString("dFdy")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdy, |
| 104 | SpvOpUndef, SpvOpUndef, SpvOpUndef); |
| 105 | fIntrinsicMap[SkString("texture")] = SPECIAL(Texture); |
| 106 | fIntrinsicMap[SkString("texture2D")] = SPECIAL(Texture2D); |
| 107 | fIntrinsicMap[SkString("textureProj")] = SPECIAL(TextureProj); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 108 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 109 | fIntrinsicMap[SkString("any")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpUndef, |
| 110 | SpvOpUndef, SpvOpUndef, SpvOpAny); |
| 111 | fIntrinsicMap[SkString("all")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpUndef, |
| 112 | SpvOpUndef, SpvOpUndef, SpvOpAll); |
| 113 | fIntrinsicMap[SkString("equal")] = std::make_tuple(kSPIRV_IntrinsicKind, |
| 114 | SpvOpFOrdEqual, SpvOpIEqual, |
| 115 | SpvOpIEqual, SpvOpLogicalEqual); |
| 116 | fIntrinsicMap[SkString("notEqual")] = std::make_tuple(kSPIRV_IntrinsicKind, |
| 117 | SpvOpFOrdNotEqual, SpvOpINotEqual, |
| 118 | SpvOpINotEqual, |
| 119 | SpvOpLogicalNotEqual); |
| 120 | fIntrinsicMap[SkString("lessThan")] = std::make_tuple(kSPIRV_IntrinsicKind, |
| 121 | SpvOpSLessThan, SpvOpULessThan, |
| 122 | SpvOpFOrdLessThan, SpvOpUndef); |
| 123 | fIntrinsicMap[SkString("lessThanEqual")] = std::make_tuple(kSPIRV_IntrinsicKind, |
| 124 | SpvOpSLessThanEqual, |
| 125 | SpvOpULessThanEqual, |
| 126 | SpvOpFOrdLessThanEqual, |
| 127 | SpvOpUndef); |
| 128 | fIntrinsicMap[SkString("greaterThan")] = std::make_tuple(kSPIRV_IntrinsicKind, |
| 129 | SpvOpSGreaterThan, |
| 130 | SpvOpUGreaterThan, |
| 131 | SpvOpFOrdGreaterThan, |
| 132 | SpvOpUndef); |
| 133 | fIntrinsicMap[SkString("greaterThanEqual")] = std::make_tuple(kSPIRV_IntrinsicKind, |
| 134 | SpvOpSGreaterThanEqual, |
| 135 | SpvOpUGreaterThanEqual, |
| 136 | SpvOpFOrdGreaterThanEqual, |
| 137 | SpvOpUndef); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 138 | |
| 139 | // interpolateAt* not yet supported... |
| 140 | } |
| 141 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 142 | void SPIRVCodeGenerator::writeWord(int32_t word, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 143 | #if SPIRV_DEBUG |
| 144 | out << "(" << word << ") "; |
| 145 | #else |
| 146 | out.write((const char*) &word, sizeof(word)); |
| 147 | #endif |
| 148 | } |
| 149 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 150 | static bool is_float(const Context& context, const Type& type) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 151 | if (type.kind() == Type::kVector_Kind) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 152 | return is_float(context, type.componentType()); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 153 | } |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 154 | return type == *context.fFloat_Type || type == *context.fDouble_Type; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 155 | } |
| 156 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 157 | static bool is_signed(const Context& context, const Type& type) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 158 | if (type.kind() == Type::kVector_Kind) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 159 | return is_signed(context, type.componentType()); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 160 | } |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 161 | return type == *context.fInt_Type; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 162 | } |
| 163 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 164 | static bool is_unsigned(const Context& context, const Type& type) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 165 | if (type.kind() == Type::kVector_Kind) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 166 | return is_unsigned(context, type.componentType()); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 167 | } |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 168 | return type == *context.fUInt_Type; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 169 | } |
| 170 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 171 | static bool is_bool(const Context& context, const Type& type) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 172 | if (type.kind() == Type::kVector_Kind) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 173 | return is_bool(context, type.componentType()); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 174 | } |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 175 | return type == *context.fBool_Type; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 176 | } |
| 177 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 178 | static bool is_out(const Variable& var) { |
| 179 | return (var.fModifiers.fFlags & Modifiers::kOut_Flag) != 0; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | #if SPIRV_DEBUG |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 183 | static SkString opcode_text(SpvOp_ opCode) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 184 | switch (opCode) { |
| 185 | case SpvOpNop: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 186 | return SkString("Nop"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 187 | case SpvOpUndef: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 188 | return SkString("Undef"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 189 | case SpvOpSourceContinued: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 190 | return SkString("SourceContinued"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 191 | case SpvOpSource: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 192 | return SkString("Source"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 193 | case SpvOpSourceExtension: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 194 | return SkString("SourceExtension"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 195 | case SpvOpName: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 196 | return SkString("Name"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 197 | case SpvOpMemberName: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 198 | return SkString("MemberName"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 199 | case SpvOpString: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 200 | return SkString("String"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 201 | case SpvOpLine: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 202 | return SkString("Line"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 203 | case SpvOpExtension: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 204 | return SkString("Extension"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 205 | case SpvOpExtInstImport: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 206 | return SkString("ExtInstImport"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 207 | case SpvOpExtInst: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 208 | return SkString("ExtInst"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 209 | case SpvOpMemoryModel: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 210 | return SkString("MemoryModel"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 211 | case SpvOpEntryPoint: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 212 | return SkString("EntryPoint"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 213 | case SpvOpExecutionMode: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 214 | return SkString("ExecutionMode"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 215 | case SpvOpCapability: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 216 | return SkString("Capability"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 217 | case SpvOpTypeVoid: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 218 | return SkString("TypeVoid"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 219 | case SpvOpTypeBool: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 220 | return SkString("TypeBool"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 221 | case SpvOpTypeInt: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 222 | return SkString("TypeInt"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 223 | case SpvOpTypeFloat: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 224 | return SkString("TypeFloat"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 225 | case SpvOpTypeVector: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 226 | return SkString("TypeVector"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 227 | case SpvOpTypeMatrix: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 228 | return SkString("TypeMatrix"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 229 | case SpvOpTypeImage: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 230 | return SkString("TypeImage"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 231 | case SpvOpTypeSampler: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 232 | return SkString("TypeSampler"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 233 | case SpvOpTypeSampledImage: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 234 | return SkString("TypeSampledImage"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 235 | case SpvOpTypeArray: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 236 | return SkString("TypeArray"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 237 | case SpvOpTypeRuntimeArray: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 238 | return SkString("TypeRuntimeArray"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 239 | case SpvOpTypeStruct: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 240 | return SkString("TypeStruct"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 241 | case SpvOpTypeOpaque: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 242 | return SkString("TypeOpaque"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 243 | case SpvOpTypePointer: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 244 | return SkString("TypePointer"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 245 | case SpvOpTypeFunction: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 246 | return SkString("TypeFunction"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 247 | case SpvOpTypeEvent: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 248 | return SkString("TypeEvent"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 249 | case SpvOpTypeDeviceEvent: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 250 | return SkString("TypeDeviceEvent"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 251 | case SpvOpTypeReserveId: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 252 | return SkString("TypeReserveId"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 253 | case SpvOpTypeQueue: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 254 | return SkString("TypeQueue"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 255 | case SpvOpTypePipe: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 256 | return SkString("TypePipe"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 257 | case SpvOpTypeForwardPointer: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 258 | return SkString("TypeForwardPointer"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 259 | case SpvOpConstantTrue: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 260 | return SkString("ConstantTrue"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 261 | case SpvOpConstantFalse: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 262 | return SkString("ConstantFalse"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 263 | case SpvOpConstant: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 264 | return SkString("Constant"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 265 | case SpvOpConstantComposite: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 266 | return SkString("ConstantComposite"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 267 | case SpvOpConstantSampler: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 268 | return SkString("ConstantSampler"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 269 | case SpvOpConstantNull: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 270 | return SkString("ConstantNull"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 271 | case SpvOpSpecConstantTrue: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 272 | return SkString("SpecConstantTrue"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 273 | case SpvOpSpecConstantFalse: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 274 | return SkString("SpecConstantFalse"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 275 | case SpvOpSpecConstant: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 276 | return SkString("SpecConstant"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 277 | case SpvOpSpecConstantComposite: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 278 | return SkString("SpecConstantComposite"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 279 | case SpvOpSpecConstantOp: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 280 | return SkString("SpecConstantOp"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 281 | case SpvOpFunction: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 282 | return SkString("Function"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 283 | case SpvOpFunctionParameter: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 284 | return SkString("FunctionParameter"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 285 | case SpvOpFunctionEnd: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 286 | return SkString("FunctionEnd"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 287 | case SpvOpFunctionCall: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 288 | return SkString("FunctionCall"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 289 | case SpvOpVariable: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 290 | return SkString("Variable"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 291 | case SpvOpImageTexelPointer: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 292 | return SkString("ImageTexelPointer"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 293 | case SpvOpLoad: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 294 | return SkString("Load"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 295 | case SpvOpStore: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 296 | return SkString("Store"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 297 | case SpvOpCopyMemory: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 298 | return SkString("CopyMemory"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 299 | case SpvOpCopyMemorySized: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 300 | return SkString("CopyMemorySized"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 301 | case SpvOpAccessChain: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 302 | return SkString("AccessChain"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 303 | case SpvOpInBoundsAccessChain: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 304 | return SkString("InBoundsAccessChain"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 305 | case SpvOpPtrAccessChain: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 306 | return SkString("PtrAccessChain"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 307 | case SpvOpArrayLength: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 308 | return SkString("ArrayLength"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 309 | case SpvOpGenericPtrMemSemantics: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 310 | return SkString("GenericPtrMemSemantics"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 311 | case SpvOpInBoundsPtrAccessChain: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 312 | return SkString("InBoundsPtrAccessChain"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 313 | case SpvOpDecorate: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 314 | return SkString("Decorate"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 315 | case SpvOpMemberDecorate: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 316 | return SkString("MemberDecorate"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 317 | case SpvOpDecorationGroup: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 318 | return SkString("DecorationGroup"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 319 | case SpvOpGroupDecorate: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 320 | return SkString("GroupDecorate"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 321 | case SpvOpGroupMemberDecorate: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 322 | return SkString("GroupMemberDecorate"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 323 | case SpvOpVectorExtractDynamic: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 324 | return SkString("VectorExtractDynamic"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 325 | case SpvOpVectorInsertDynamic: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 326 | return SkString("VectorInsertDynamic"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 327 | case SpvOpVectorShuffle: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 328 | return SkString("VectorShuffle"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 329 | case SpvOpCompositeConstruct: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 330 | return SkString("CompositeConstruct"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 331 | case SpvOpCompositeExtract: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 332 | return SkString("CompositeExtract"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 333 | case SpvOpCompositeInsert: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 334 | return SkString("CompositeInsert"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 335 | case SpvOpCopyObject: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 336 | return SkString("CopyObject"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 337 | case SpvOpTranspose: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 338 | return SkString("Transpose"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 339 | case SpvOpSampledImage: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 340 | return SkString("SampledImage"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 341 | case SpvOpImageSampleImplicitLod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 342 | return SkString("ImageSampleImplicitLod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 343 | case SpvOpImageSampleExplicitLod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 344 | return SkString("ImageSampleExplicitLod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 345 | case SpvOpImageSampleDrefImplicitLod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 346 | return SkString("ImageSampleDrefImplicitLod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 347 | case SpvOpImageSampleDrefExplicitLod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 348 | return SkString("ImageSampleDrefExplicitLod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 349 | case SpvOpImageSampleProjImplicitLod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 350 | return SkString("ImageSampleProjImplicitLod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 351 | case SpvOpImageSampleProjExplicitLod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 352 | return SkString("ImageSampleProjExplicitLod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 353 | case SpvOpImageSampleProjDrefImplicitLod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 354 | return SkString("ImageSampleProjDrefImplicitLod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 355 | case SpvOpImageSampleProjDrefExplicitLod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 356 | return SkString("ImageSampleProjDrefExplicitLod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 357 | case SpvOpImageFetch: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 358 | return SkString("ImageFetch"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 359 | case SpvOpImageGather: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 360 | return SkString("ImageGather"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 361 | case SpvOpImageDrefGather: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 362 | return SkString("ImageDrefGather"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 363 | case SpvOpImageRead: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 364 | return SkString("ImageRead"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 365 | case SpvOpImageWrite: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 366 | return SkString("ImageWrite"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 367 | case SpvOpImage: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 368 | return SkString("Image"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 369 | case SpvOpImageQueryFormat: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 370 | return SkString("ImageQueryFormat"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 371 | case SpvOpImageQueryOrder: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 372 | return SkString("ImageQueryOrder"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 373 | case SpvOpImageQuerySizeLod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 374 | return SkString("ImageQuerySizeLod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 375 | case SpvOpImageQuerySize: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 376 | return SkString("ImageQuerySize"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 377 | case SpvOpImageQueryLod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 378 | return SkString("ImageQueryLod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 379 | case SpvOpImageQueryLevels: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 380 | return SkString("ImageQueryLevels"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 381 | case SpvOpImageQuerySamples: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 382 | return SkString("ImageQuerySamples"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 383 | case SpvOpConvertFToU: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 384 | return SkString("ConvertFToU"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 385 | case SpvOpConvertFToS: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 386 | return SkString("ConvertFToS"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 387 | case SpvOpConvertSToF: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 388 | return SkString("ConvertSToF"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 389 | case SpvOpConvertUToF: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 390 | return SkString("ConvertUToF"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 391 | case SpvOpUConvert: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 392 | return SkString("UConvert"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 393 | case SpvOpSConvert: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 394 | return SkString("SConvert"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 395 | case SpvOpFConvert: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 396 | return SkString("FConvert"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 397 | case SpvOpQuantizeToF16: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 398 | return SkString("QuantizeToF16"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 399 | case SpvOpConvertPtrToU: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 400 | return SkString("ConvertPtrToU"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 401 | case SpvOpSatConvertSToU: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 402 | return SkString("SatConvertSToU"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 403 | case SpvOpSatConvertUToS: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 404 | return SkString("SatConvertUToS"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 405 | case SpvOpConvertUToPtr: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 406 | return SkString("ConvertUToPtr"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 407 | case SpvOpPtrCastToGeneric: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 408 | return SkString("PtrCastToGeneric"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 409 | case SpvOpGenericCastToPtr: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 410 | return SkString("GenericCastToPtr"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 411 | case SpvOpGenericCastToPtrExplicit: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 412 | return SkString("GenericCastToPtrExplicit"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 413 | case SpvOpBitcast: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 414 | return SkString("Bitcast"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 415 | case SpvOpSNegate: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 416 | return SkString("SNegate"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 417 | case SpvOpFNegate: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 418 | return SkString("FNegate"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 419 | case SpvOpIAdd: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 420 | return SkString("IAdd"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 421 | case SpvOpFAdd: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 422 | return SkString("FAdd"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 423 | case SpvOpISub: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 424 | return SkString("ISub"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 425 | case SpvOpFSub: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 426 | return SkString("FSub"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 427 | case SpvOpIMul: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 428 | return SkString("IMul"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 429 | case SpvOpFMul: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 430 | return SkString("FMul"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 431 | case SpvOpUDiv: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 432 | return SkString("UDiv"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 433 | case SpvOpSDiv: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 434 | return SkString("SDiv"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 435 | case SpvOpFDiv: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 436 | return SkString("FDiv"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 437 | case SpvOpUMod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 438 | return SkString("UMod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 439 | case SpvOpSRem: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 440 | return SkString("SRem"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 441 | case SpvOpSMod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 442 | return SkString("SMod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 443 | case SpvOpFRem: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 444 | return SkString("FRem"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 445 | case SpvOpFMod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 446 | return SkString("FMod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 447 | case SpvOpVectorTimesScalar: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 448 | return SkString("VectorTimesScalar"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 449 | case SpvOpMatrixTimesScalar: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 450 | return SkString("MatrixTimesScalar"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 451 | case SpvOpVectorTimesMatrix: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 452 | return SkString("VectorTimesMatrix"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 453 | case SpvOpMatrixTimesVector: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 454 | return SkString("MatrixTimesVector"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 455 | case SpvOpMatrixTimesMatrix: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 456 | return SkString("MatrixTimesMatrix"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 457 | case SpvOpOuterProduct: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 458 | return SkString("OuterProduct"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 459 | case SpvOpDot: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 460 | return SkString("Dot"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 461 | case SpvOpIAddCarry: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 462 | return SkString("IAddCarry"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 463 | case SpvOpISubBorrow: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 464 | return SkString("ISubBorrow"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 465 | case SpvOpUMulExtended: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 466 | return SkString("UMulExtended"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 467 | case SpvOpSMulExtended: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 468 | return SkString("SMulExtended"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 469 | case SpvOpAny: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 470 | return SkString("Any"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 471 | case SpvOpAll: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 472 | return SkString("All"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 473 | case SpvOpIsNan: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 474 | return SkString("IsNan"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 475 | case SpvOpIsInf: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 476 | return SkString("IsInf"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 477 | case SpvOpIsFinite: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 478 | return SkString("IsFinite"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 479 | case SpvOpIsNormal: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 480 | return SkString("IsNormal"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 481 | case SpvOpSignBitSet: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 482 | return SkString("SignBitSet"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 483 | case SpvOpLessOrGreater: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 484 | return SkString("LessOrGreater"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 485 | case SpvOpOrdered: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 486 | return SkString("Ordered"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 487 | case SpvOpUnordered: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 488 | return SkString("Unordered"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 489 | case SpvOpLogicalEqual: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 490 | return SkString("LogicalEqual"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 491 | case SpvOpLogicalNotEqual: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 492 | return SkString("LogicalNotEqual"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 493 | case SpvOpLogicalOr: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 494 | return SkString("LogicalOr"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 495 | case SpvOpLogicalAnd: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 496 | return SkString("LogicalAnd"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 497 | case SpvOpLogicalNot: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 498 | return SkString("LogicalNot"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 499 | case SpvOpSelect: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 500 | return SkString("Select"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 501 | case SpvOpIEqual: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 502 | return SkString("IEqual"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 503 | case SpvOpINotEqual: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 504 | return SkString("INotEqual"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 505 | case SpvOpUGreaterThan: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 506 | return SkString("UGreaterThan"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 507 | case SpvOpSGreaterThan: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 508 | return SkString("SGreaterThan"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 509 | case SpvOpUGreaterThanEqual: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 510 | return SkString("UGreaterThanEqual"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 511 | case SpvOpSGreaterThanEqual: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 512 | return SkString("SGreaterThanEqual"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 513 | case SpvOpULessThan: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 514 | return SkString("ULessThan"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 515 | case SpvOpSLessThan: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 516 | return SkString("SLessThan"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 517 | case SpvOpULessThanEqual: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 518 | return SkString("ULessThanEqual"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 519 | case SpvOpSLessThanEqual: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 520 | return SkString("SLessThanEqual"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 521 | case SpvOpFOrdEqual: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 522 | return SkString("FOrdEqual"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 523 | case SpvOpFUnordEqual: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 524 | return SkString("FUnordEqual"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 525 | case SpvOpFOrdNotEqual: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 526 | return SkString("FOrdNotEqual"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 527 | case SpvOpFUnordNotEqual: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 528 | return SkString("FUnordNotEqual"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 529 | case SpvOpFOrdLessThan: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 530 | return SkString("FOrdLessThan"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 531 | case SpvOpFUnordLessThan: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 532 | return SkString("FUnordLessThan"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 533 | case SpvOpFOrdGreaterThan: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 534 | return SkString("FOrdGreaterThan"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 535 | case SpvOpFUnordGreaterThan: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 536 | return SkString("FUnordGreaterThan"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 537 | case SpvOpFOrdLessThanEqual: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 538 | return SkString("FOrdLessThanEqual"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 539 | case SpvOpFUnordLessThanEqual: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 540 | return SkString("FUnordLessThanEqual"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 541 | case SpvOpFOrdGreaterThanEqual: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 542 | return SkString("FOrdGreaterThanEqual"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 543 | case SpvOpFUnordGreaterThanEqual: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 544 | return SkString("FUnordGreaterThanEqual"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 545 | case SpvOpShiftRightLogical: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 546 | return SkString("ShiftRightLogical"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 547 | case SpvOpShiftRightArithmetic: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 548 | return SkString("ShiftRightArithmetic"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 549 | case SpvOpShiftLeftLogical: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 550 | return SkString("ShiftLeftLogical"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 551 | case SpvOpBitwiseOr: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 552 | return SkString("BitwiseOr"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 553 | case SpvOpBitwiseXor: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 554 | return SkString("BitwiseXor"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 555 | case SpvOpBitwiseAnd: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 556 | return SkString("BitwiseAnd"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 557 | case SpvOpNot: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 558 | return SkString("Not"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 559 | case SpvOpBitFieldInsert: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 560 | return SkString("BitFieldInsert"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 561 | case SpvOpBitFieldSExtract: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 562 | return SkString("BitFieldSExtract"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 563 | case SpvOpBitFieldUExtract: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 564 | return SkString("BitFieldUExtract"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 565 | case SpvOpBitReverse: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 566 | return SkString("BitReverse"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 567 | case SpvOpBitCount: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 568 | return SkString("BitCount"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 569 | case SpvOpDPdx: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 570 | return SkString("DPdx"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 571 | case SpvOpDPdy: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 572 | return SkString("DPdy"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 573 | case SpvOpFwidth: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 574 | return SkString("Fwidth"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 575 | case SpvOpDPdxFine: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 576 | return SkString("DPdxFine"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 577 | case SpvOpDPdyFine: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 578 | return SkString("DPdyFine"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 579 | case SpvOpFwidthFine: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 580 | return SkString("FwidthFine"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 581 | case SpvOpDPdxCoarse: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 582 | return SkString("DPdxCoarse"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 583 | case SpvOpDPdyCoarse: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 584 | return SkString("DPdyCoarse"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 585 | case SpvOpFwidthCoarse: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 586 | return SkString("FwidthCoarse"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 587 | case SpvOpEmitVertex: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 588 | return SkString("EmitVertex"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 589 | case SpvOpEndPrimitive: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 590 | return SkString("EndPrimitive"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 591 | case SpvOpEmitStreamVertex: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 592 | return SkString("EmitStreamVertex"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 593 | case SpvOpEndStreamPrimitive: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 594 | return SkString("EndStreamPrimitive"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 595 | case SpvOpControlBarrier: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 596 | return SkString("ControlBarrier"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 597 | case SpvOpMemoryBarrier: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 598 | return SkString("MemoryBarrier"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 599 | case SpvOpAtomicLoad: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 600 | return SkString("AtomicLoad"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 601 | case SpvOpAtomicStore: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 602 | return SkString("AtomicStore"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 603 | case SpvOpAtomicExchange: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 604 | return SkString("AtomicExchange"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 605 | case SpvOpAtomicCompareExchange: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 606 | return SkString("AtomicCompareExchange"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 607 | case SpvOpAtomicCompareExchangeWeak: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 608 | return SkString("AtomicCompareExchangeWeak"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 609 | case SpvOpAtomicIIncrement: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 610 | return SkString("AtomicIIncrement"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 611 | case SpvOpAtomicIDecrement: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 612 | return SkString("AtomicIDecrement"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 613 | case SpvOpAtomicIAdd: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 614 | return SkString("AtomicIAdd"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 615 | case SpvOpAtomicISub: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 616 | return SkString("AtomicISub"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 617 | case SpvOpAtomicSMin: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 618 | return SkString("AtomicSMin"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 619 | case SpvOpAtomicUMin: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 620 | return SkString("AtomicUMin"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 621 | case SpvOpAtomicSMax: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 622 | return SkString("AtomicSMax"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 623 | case SpvOpAtomicUMax: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 624 | return SkString("AtomicUMax"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 625 | case SpvOpAtomicAnd: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 626 | return SkString("AtomicAnd"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 627 | case SpvOpAtomicOr: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 628 | return SkString("AtomicOr"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 629 | case SpvOpAtomicXor: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 630 | return SkString("AtomicXor"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 631 | case SpvOpPhi: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 632 | return SkString("Phi"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 633 | case SpvOpLoopMerge: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 634 | return SkString("LoopMerge"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 635 | case SpvOpSelectionMerge: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 636 | return SkString("SelectionMerge"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 637 | case SpvOpLabel: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 638 | return SkString("Label"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 639 | case SpvOpBranch: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 640 | return SkString("Branch"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 641 | case SpvOpBranchConditional: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 642 | return SkString("BranchConditional"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 643 | case SpvOpSwitch: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 644 | return SkString("Switch"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 645 | case SpvOpKill: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 646 | return SkString("Kill"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 647 | case SpvOpReturn: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 648 | return SkString("Return"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 649 | case SpvOpReturnValue: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 650 | return SkString("ReturnValue"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 651 | case SpvOpUnreachable: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 652 | return SkString("Unreachable"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 653 | case SpvOpLifetimeStart: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 654 | return SkString("LifetimeStart"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 655 | case SpvOpLifetimeStop: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 656 | return SkString("LifetimeStop"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 657 | case SpvOpGroupAsyncCopy: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 658 | return SkString("GroupAsyncCopy"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 659 | case SpvOpGroupWaitEvents: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 660 | return SkString("GroupWaitEvents"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 661 | case SpvOpGroupAll: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 662 | return SkString("GroupAll"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 663 | case SpvOpGroupAny: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 664 | return SkString("GroupAny"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 665 | case SpvOpGroupBroadcast: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 666 | return SkString("GroupBroadcast"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 667 | case SpvOpGroupIAdd: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 668 | return SkString("GroupIAdd"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 669 | case SpvOpGroupFAdd: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 670 | return SkString("GroupFAdd"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 671 | case SpvOpGroupFMin: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 672 | return SkString("GroupFMin"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 673 | case SpvOpGroupUMin: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 674 | return SkString("GroupUMin"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 675 | case SpvOpGroupSMin: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 676 | return SkString("GroupSMin"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 677 | case SpvOpGroupFMax: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 678 | return SkString("GroupFMax"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 679 | case SpvOpGroupUMax: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 680 | return SkString("GroupUMax"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 681 | case SpvOpGroupSMax: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 682 | return SkString("GroupSMax"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 683 | case SpvOpReadPipe: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 684 | return SkString("ReadPipe"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 685 | case SpvOpWritePipe: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 686 | return SkString("WritePipe"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 687 | case SpvOpReservedReadPipe: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 688 | return SkString("ReservedReadPipe"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 689 | case SpvOpReservedWritePipe: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 690 | return SkString("ReservedWritePipe"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 691 | case SpvOpReserveReadPipePackets: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 692 | return SkString("ReserveReadPipePackets"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 693 | case SpvOpReserveWritePipePackets: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 694 | return SkString("ReserveWritePipePackets"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 695 | case SpvOpCommitReadPipe: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 696 | return SkString("CommitReadPipe"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 697 | case SpvOpCommitWritePipe: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 698 | return SkString("CommitWritePipe"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 699 | case SpvOpIsValidReserveId: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 700 | return SkString("IsValidReserveId"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 701 | case SpvOpGetNumPipePackets: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 702 | return SkString("GetNumPipePackets"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 703 | case SpvOpGetMaxPipePackets: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 704 | return SkString("GetMaxPipePackets"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 705 | case SpvOpGroupReserveReadPipePackets: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 706 | return SkString("GroupReserveReadPipePackets"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 707 | case SpvOpGroupReserveWritePipePackets: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 708 | return SkString("GroupReserveWritePipePackets"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 709 | case SpvOpGroupCommitReadPipe: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 710 | return SkString("GroupCommitReadPipe"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 711 | case SpvOpGroupCommitWritePipe: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 712 | return SkString("GroupCommitWritePipe"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 713 | case SpvOpEnqueueMarker: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 714 | return SkString("EnqueueMarker"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 715 | case SpvOpEnqueueKernel: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 716 | return SkString("EnqueueKernel"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 717 | case SpvOpGetKernelNDrangeSubGroupCount: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 718 | return SkString("GetKernelNDrangeSubGroupCount"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 719 | case SpvOpGetKernelNDrangeMaxSubGroupSize: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 720 | return SkString("GetKernelNDrangeMaxSubGroupSize"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 721 | case SpvOpGetKernelWorkGroupSize: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 722 | return SkString("GetKernelWorkGroupSize"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 723 | case SpvOpGetKernelPreferredWorkGroupSizeMultiple: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 724 | return SkString("GetKernelPreferredWorkGroupSizeMultiple"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 725 | case SpvOpRetainEvent: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 726 | return SkString("RetainEvent"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 727 | case SpvOpReleaseEvent: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 728 | return SkString("ReleaseEvent"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 729 | case SpvOpCreateUserEvent: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 730 | return SkString("CreateUserEvent"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 731 | case SpvOpIsValidEvent: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 732 | return SkString("IsValidEvent"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 733 | case SpvOpSetUserEventStatus: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 734 | return SkString("SetUserEventStatus"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 735 | case SpvOpCaptureEventProfilingInfo: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 736 | return SkString("CaptureEventProfilingInfo"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 737 | case SpvOpGetDefaultQueue: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 738 | return SkString("GetDefaultQueue"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 739 | case SpvOpBuildNDRange: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 740 | return SkString("BuildNDRange"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 741 | case SpvOpImageSparseSampleImplicitLod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 742 | return SkString("ImageSparseSampleImplicitLod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 743 | case SpvOpImageSparseSampleExplicitLod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 744 | return SkString("ImageSparseSampleExplicitLod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 745 | case SpvOpImageSparseSampleDrefImplicitLod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 746 | return SkString("ImageSparseSampleDrefImplicitLod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 747 | case SpvOpImageSparseSampleDrefExplicitLod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 748 | return SkString("ImageSparseSampleDrefExplicitLod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 749 | case SpvOpImageSparseSampleProjImplicitLod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 750 | return SkString("ImageSparseSampleProjImplicitLod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 751 | case SpvOpImageSparseSampleProjExplicitLod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 752 | return SkString("ImageSparseSampleProjExplicitLod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 753 | case SpvOpImageSparseSampleProjDrefImplicitLod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 754 | return SkString("ImageSparseSampleProjDrefImplicitLod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 755 | case SpvOpImageSparseSampleProjDrefExplicitLod: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 756 | return SkString("ImageSparseSampleProjDrefExplicitLod"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 757 | case SpvOpImageSparseFetch: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 758 | return SkString("ImageSparseFetch"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 759 | case SpvOpImageSparseGather: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 760 | return SkString("ImageSparseGather"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 761 | case SpvOpImageSparseDrefGather: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 762 | return SkString("ImageSparseDrefGather"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 763 | case SpvOpImageSparseTexelsResident: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 764 | return SkString("ImageSparseTexelsResident"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 765 | case SpvOpNoLine: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 766 | return SkString("NoLine"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 767 | case SpvOpAtomicFlagTestAndSet: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 768 | return SkString("AtomicFlagTestAndSet"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 769 | case SpvOpAtomicFlagClear: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 770 | return SkString("AtomicFlagClear"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 771 | case SpvOpImageSparseRead: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 772 | return SkString("ImageSparseRead"); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 773 | default: |
| 774 | ABORT("unsupported SPIR-V op"); |
| 775 | } |
| 776 | } |
| 777 | #endif |
| 778 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 779 | void SPIRVCodeGenerator::writeOpCode(SpvOp_ opCode, int length, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 780 | ASSERT(opCode != SpvOpUndef); |
| 781 | switch (opCode) { |
| 782 | case SpvOpReturn: // fall through |
| 783 | case SpvOpReturnValue: // fall through |
ethannicholas | 552882f | 2016-07-07 06:30:48 -0700 | [diff] [blame] | 784 | case SpvOpKill: // fall through |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 785 | case SpvOpBranch: // fall through |
| 786 | case SpvOpBranchConditional: |
| 787 | ASSERT(fCurrentBlock); |
| 788 | fCurrentBlock = 0; |
| 789 | break; |
| 790 | case SpvOpConstant: // fall through |
| 791 | case SpvOpConstantTrue: // fall through |
| 792 | case SpvOpConstantFalse: // fall through |
| 793 | case SpvOpConstantComposite: // fall through |
| 794 | case SpvOpTypeVoid: // fall through |
| 795 | case SpvOpTypeInt: // fall through |
| 796 | case SpvOpTypeFloat: // fall through |
| 797 | case SpvOpTypeBool: // fall through |
| 798 | case SpvOpTypeVector: // fall through |
| 799 | case SpvOpTypeMatrix: // fall through |
| 800 | case SpvOpTypeArray: // fall through |
| 801 | case SpvOpTypePointer: // fall through |
| 802 | case SpvOpTypeFunction: // fall through |
| 803 | case SpvOpTypeRuntimeArray: // fall through |
| 804 | case SpvOpTypeStruct: // fall through |
| 805 | case SpvOpTypeImage: // fall through |
| 806 | case SpvOpTypeSampledImage: // fall through |
| 807 | case SpvOpVariable: // fall through |
| 808 | case SpvOpFunction: // fall through |
| 809 | case SpvOpFunctionParameter: // fall through |
| 810 | case SpvOpFunctionEnd: // fall through |
| 811 | case SpvOpExecutionMode: // fall through |
| 812 | case SpvOpMemoryModel: // fall through |
| 813 | case SpvOpCapability: // fall through |
| 814 | case SpvOpExtInstImport: // fall through |
| 815 | case SpvOpEntryPoint: // fall through |
| 816 | case SpvOpSource: // fall through |
| 817 | case SpvOpSourceExtension: // fall through |
| 818 | case SpvOpName: // fall through |
| 819 | case SpvOpMemberName: // fall through |
| 820 | case SpvOpDecorate: // fall through |
| 821 | case SpvOpMemberDecorate: |
| 822 | break; |
| 823 | default: |
| 824 | ASSERT(fCurrentBlock); |
| 825 | } |
| 826 | #if SPIRV_DEBUG |
| 827 | out << std::endl << opcode_text(opCode) << " "; |
| 828 | #else |
| 829 | this->writeWord((length << 16) | opCode, out); |
| 830 | #endif |
| 831 | } |
| 832 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 833 | void SPIRVCodeGenerator::writeLabel(SpvId label, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 834 | fCurrentBlock = label; |
| 835 | this->writeInstruction(SpvOpLabel, label, out); |
| 836 | } |
| 837 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 838 | void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 839 | this->writeOpCode(opCode, 1, out); |
| 840 | } |
| 841 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 842 | void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 843 | this->writeOpCode(opCode, 2, out); |
| 844 | this->writeWord(word1, out); |
| 845 | } |
| 846 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 847 | void SPIRVCodeGenerator::writeString(const char* string, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 848 | size_t length = strlen(string); |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 849 | out.writeText(string); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 850 | switch (length % 4) { |
| 851 | case 1: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 852 | out.write8(0); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 853 | // fall through |
| 854 | case 2: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 855 | out.write8(0); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 856 | // fall through |
| 857 | case 3: |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 858 | out.write8(0); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 859 | break; |
| 860 | default: |
| 861 | this->writeWord(0, out); |
| 862 | } |
| 863 | } |
| 864 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 865 | void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, const char* string, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 866 | int32_t length = (int32_t) strlen(string); |
| 867 | this->writeOpCode(opCode, 1 + (length + 4) / 4, out); |
| 868 | this->writeString(string, out); |
| 869 | } |
| 870 | |
| 871 | |
| 872 | void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, const char* string, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 873 | SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 874 | int32_t length = (int32_t) strlen(string); |
| 875 | this->writeOpCode(opCode, 2 + (length + 4) / 4, out); |
| 876 | this->writeWord(word1, out); |
| 877 | this->writeString(string, out); |
| 878 | } |
| 879 | |
| 880 | void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 881 | const char* string, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 882 | int32_t length = (int32_t) strlen(string); |
| 883 | this->writeOpCode(opCode, 3 + (length + 4) / 4, out); |
| 884 | this->writeWord(word1, out); |
| 885 | this->writeWord(word2, out); |
| 886 | this->writeString(string, out); |
| 887 | } |
| 888 | |
| 889 | void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 890 | SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 891 | this->writeOpCode(opCode, 3, out); |
| 892 | this->writeWord(word1, out); |
| 893 | this->writeWord(word2, out); |
| 894 | } |
| 895 | |
| 896 | void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 897 | int32_t word3, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 898 | this->writeOpCode(opCode, 4, out); |
| 899 | this->writeWord(word1, out); |
| 900 | this->writeWord(word2, out); |
| 901 | this->writeWord(word3, out); |
| 902 | } |
| 903 | |
| 904 | void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 905 | int32_t word3, int32_t word4, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 906 | this->writeOpCode(opCode, 5, out); |
| 907 | this->writeWord(word1, out); |
| 908 | this->writeWord(word2, out); |
| 909 | this->writeWord(word3, out); |
| 910 | this->writeWord(word4, out); |
| 911 | } |
| 912 | |
| 913 | void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, |
| 914 | int32_t word3, int32_t word4, int32_t word5, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 915 | SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 916 | this->writeOpCode(opCode, 6, out); |
| 917 | this->writeWord(word1, out); |
| 918 | this->writeWord(word2, out); |
| 919 | this->writeWord(word3, out); |
| 920 | this->writeWord(word4, out); |
| 921 | this->writeWord(word5, out); |
| 922 | } |
| 923 | |
| 924 | void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, |
| 925 | int32_t word3, int32_t word4, int32_t word5, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 926 | int32_t word6, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 927 | this->writeOpCode(opCode, 7, out); |
| 928 | this->writeWord(word1, out); |
| 929 | this->writeWord(word2, out); |
| 930 | this->writeWord(word3, out); |
| 931 | this->writeWord(word4, out); |
| 932 | this->writeWord(word5, out); |
| 933 | this->writeWord(word6, out); |
| 934 | } |
| 935 | |
| 936 | void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, |
| 937 | int32_t word3, int32_t word4, int32_t word5, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 938 | int32_t word6, int32_t word7, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 939 | this->writeOpCode(opCode, 8, out); |
| 940 | this->writeWord(word1, out); |
| 941 | this->writeWord(word2, out); |
| 942 | this->writeWord(word3, out); |
| 943 | this->writeWord(word4, out); |
| 944 | this->writeWord(word5, out); |
| 945 | this->writeWord(word6, out); |
| 946 | this->writeWord(word7, out); |
| 947 | } |
| 948 | |
| 949 | void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, |
| 950 | int32_t word3, int32_t word4, int32_t word5, |
| 951 | int32_t word6, int32_t word7, int32_t word8, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 952 | SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 953 | this->writeOpCode(opCode, 9, out); |
| 954 | this->writeWord(word1, out); |
| 955 | this->writeWord(word2, out); |
| 956 | this->writeWord(word3, out); |
| 957 | this->writeWord(word4, out); |
| 958 | this->writeWord(word5, out); |
| 959 | this->writeWord(word6, out); |
| 960 | this->writeWord(word7, out); |
| 961 | this->writeWord(word8, out); |
| 962 | } |
| 963 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 964 | void SPIRVCodeGenerator::writeCapabilities(SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 965 | for (uint64_t i = 0, bit = 1; i <= kLast_Capability; i++, bit <<= 1) { |
| 966 | if (fCapabilities & bit) { |
| 967 | this->writeInstruction(SpvOpCapability, (SpvId) i, out); |
| 968 | } |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | SpvId SPIRVCodeGenerator::nextId() { |
| 973 | return fIdCount++; |
| 974 | } |
| 975 | |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 976 | void SPIRVCodeGenerator::writeStruct(const Type& type, SpvId resultId) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 977 | this->writeInstruction(SpvOpName, resultId, type.name().c_str(), fNameBuffer); |
| 978 | // go ahead and write all of the field types, so we don't inadvertently write them while we're |
| 979 | // in the middle of writing the struct instruction |
| 980 | std::vector<SpvId> types; |
| 981 | for (const auto& f : type.fields()) { |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 982 | types.push_back(this->getType(*f.fType)); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 983 | } |
| 984 | this->writeOpCode(SpvOpTypeStruct, 2 + (int32_t) types.size(), fConstantBuffer); |
| 985 | this->writeWord(resultId, fConstantBuffer); |
| 986 | for (SpvId id : types) { |
| 987 | this->writeWord(id, fConstantBuffer); |
| 988 | } |
| 989 | size_t offset = 0; |
| 990 | for (int32_t i = 0; i < (int32_t) type.fields().size(); i++) { |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 991 | size_t size = type.fields()[i].fType->size(); |
| 992 | size_t alignment = type.fields()[i].fType->alignment(); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 993 | size_t mod = offset % alignment; |
| 994 | if (mod != 0) { |
| 995 | offset += alignment - mod; |
| 996 | } |
| 997 | this->writeInstruction(SpvOpMemberName, resultId, i, type.fields()[i].fName.c_str(), |
| 998 | fNameBuffer); |
| 999 | this->writeLayout(type.fields()[i].fModifiers.fLayout, resultId, i); |
| 1000 | if (type.fields()[i].fModifiers.fLayout.fBuiltin < 0) { |
| 1001 | this->writeInstruction(SpvOpMemberDecorate, resultId, (SpvId) i, SpvDecorationOffset, |
| 1002 | (SpvId) offset, fDecorationBuffer); |
| 1003 | } |
ethannicholas | 0730be7 | 2016-09-01 07:59:02 -0700 | [diff] [blame] | 1004 | if (type.fields()[i].fType->kind() == Type::kMatrix_Kind) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1005 | this->writeInstruction(SpvOpMemberDecorate, resultId, i, SpvDecorationColMajor, |
| 1006 | fDecorationBuffer); |
| 1007 | this->writeInstruction(SpvOpMemberDecorate, resultId, i, SpvDecorationMatrixStride, |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 1008 | (SpvId) type.fields()[i].fType->stride(), fDecorationBuffer); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1009 | } |
| 1010 | offset += size; |
ethannicholas | 0730be7 | 2016-09-01 07:59:02 -0700 | [diff] [blame] | 1011 | Type::Kind kind = type.fields()[i].fType->kind(); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1012 | if ((kind == Type::kArray_Kind || kind == Type::kStruct_Kind) && offset % alignment != 0) { |
| 1013 | offset += alignment - offset % alignment; |
| 1014 | } |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | SpvId SPIRVCodeGenerator::getType(const Type& type) { |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 1019 | auto entry = fTypeMap.find(type.name()); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1020 | if (entry == fTypeMap.end()) { |
| 1021 | SpvId result = this->nextId(); |
| 1022 | switch (type.kind()) { |
| 1023 | case Type::kScalar_Kind: |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1024 | if (type == *fContext.fBool_Type) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1025 | this->writeInstruction(SpvOpTypeBool, result, fConstantBuffer); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1026 | } else if (type == *fContext.fInt_Type) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1027 | this->writeInstruction(SpvOpTypeInt, result, 32, 1, fConstantBuffer); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1028 | } else if (type == *fContext.fUInt_Type) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1029 | this->writeInstruction(SpvOpTypeInt, result, 32, 0, fConstantBuffer); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1030 | } else if (type == *fContext.fFloat_Type) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1031 | this->writeInstruction(SpvOpTypeFloat, result, 32, fConstantBuffer); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1032 | } else if (type == *fContext.fDouble_Type) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1033 | this->writeInstruction(SpvOpTypeFloat, result, 64, fConstantBuffer); |
| 1034 | } else { |
| 1035 | ASSERT(false); |
| 1036 | } |
| 1037 | break; |
| 1038 | case Type::kVector_Kind: |
| 1039 | this->writeInstruction(SpvOpTypeVector, result, |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 1040 | this->getType(type.componentType()), |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1041 | type.columns(), fConstantBuffer); |
| 1042 | break; |
| 1043 | case Type::kMatrix_Kind: |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1044 | this->writeInstruction(SpvOpTypeMatrix, result, |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 1045 | this->getType(index_type(fContext, type)), |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1046 | type.columns(), fConstantBuffer); |
| 1047 | break; |
| 1048 | case Type::kStruct_Kind: |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 1049 | this->writeStruct(type, result); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1050 | break; |
| 1051 | case Type::kArray_Kind: { |
| 1052 | if (type.columns() > 0) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1053 | IntLiteral count(fContext, Position(), type.columns()); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1054 | this->writeInstruction(SpvOpTypeArray, result, |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 1055 | this->getType(type.componentType()), |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1056 | this->writeIntLiteral(count), fConstantBuffer); |
| 1057 | this->writeInstruction(SpvOpDecorate, result, SpvDecorationArrayStride, |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 1058 | (int32_t) type.stride(), fDecorationBuffer); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1059 | } else { |
| 1060 | ABORT("runtime-sized arrays are not yet supported"); |
| 1061 | this->writeInstruction(SpvOpTypeRuntimeArray, result, |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 1062 | this->getType(type.componentType()), fConstantBuffer); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1063 | } |
| 1064 | break; |
| 1065 | } |
| 1066 | case Type::kSampler_Kind: { |
| 1067 | SpvId image = this->nextId(); |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 1068 | this->writeInstruction(SpvOpTypeImage, image, this->getType(*fContext.fFloat_Type), |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1069 | type.dimensions(), type.isDepth(), type.isArrayed(), |
| 1070 | type.isMultisampled(), type.isSampled(), |
| 1071 | SpvImageFormatUnknown, fConstantBuffer); |
| 1072 | this->writeInstruction(SpvOpTypeSampledImage, result, image, fConstantBuffer); |
| 1073 | break; |
| 1074 | } |
| 1075 | default: |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1076 | if (type == *fContext.fVoid_Type) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1077 | this->writeInstruction(SpvOpTypeVoid, result, fConstantBuffer); |
| 1078 | } else { |
| 1079 | ABORT("invalid type: %s", type.description().c_str()); |
| 1080 | } |
| 1081 | } |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 1082 | fTypeMap[type.name()] = result; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1083 | return result; |
| 1084 | } |
| 1085 | return entry->second; |
| 1086 | } |
| 1087 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1088 | SpvId SPIRVCodeGenerator::getFunctionType(const FunctionDeclaration& function) { |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1089 | SkString key = function.fReturnType.description() + "("; |
| 1090 | SkString separator; |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1091 | for (size_t i = 0; i < function.fParameters.size(); i++) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1092 | key += separator; |
| 1093 | separator = ", "; |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1094 | key += function.fParameters[i]->fType.description(); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1095 | } |
| 1096 | key += ")"; |
| 1097 | auto entry = fTypeMap.find(key); |
| 1098 | if (entry == fTypeMap.end()) { |
| 1099 | SpvId result = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1100 | int32_t length = 3 + (int32_t) function.fParameters.size(); |
| 1101 | SpvId returnType = this->getType(function.fReturnType); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1102 | std::vector<SpvId> parameterTypes; |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1103 | for (size_t i = 0; i < function.fParameters.size(); i++) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1104 | // glslang seems to treat all function arguments as pointers whether they need to be or |
| 1105 | // not. I was initially puzzled by this until I ran bizarre failures with certain |
| 1106 | // patterns of function calls and control constructs, as exemplified by this minimal |
| 1107 | // failure case: |
| 1108 | // |
| 1109 | // void sphere(float x) { |
| 1110 | // } |
| 1111 | // |
| 1112 | // void map() { |
| 1113 | // sphere(1.0); |
| 1114 | // } |
| 1115 | // |
| 1116 | // void main() { |
| 1117 | // for (int i = 0; i < 1; i++) { |
| 1118 | // map(); |
| 1119 | // } |
| 1120 | // } |
| 1121 | // |
| 1122 | // As of this writing, compiling this in the "obvious" way (with sphere taking a float) |
| 1123 | // crashes. Making it take a float* and storing the argument in a temporary variable, |
| 1124 | // as glslang does, fixes it. It's entirely possible I simply missed whichever part of |
| 1125 | // the spec makes this make sense. |
| 1126 | // if (is_out(function->fParameters[i])) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1127 | parameterTypes.push_back(this->getPointerType(function.fParameters[i]->fType, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1128 | SpvStorageClassFunction)); |
| 1129 | // } else { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1130 | // parameterTypes.push_back(this->getType(function.fParameters[i]->fType)); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1131 | // } |
| 1132 | } |
| 1133 | this->writeOpCode(SpvOpTypeFunction, length, fConstantBuffer); |
| 1134 | this->writeWord(result, fConstantBuffer); |
| 1135 | this->writeWord(returnType, fConstantBuffer); |
| 1136 | for (SpvId id : parameterTypes) { |
| 1137 | this->writeWord(id, fConstantBuffer); |
| 1138 | } |
| 1139 | fTypeMap[key] = result; |
| 1140 | return result; |
| 1141 | } |
| 1142 | return entry->second; |
| 1143 | } |
| 1144 | |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 1145 | SpvId SPIRVCodeGenerator::getPointerType(const Type& type, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1146 | SpvStorageClass_ storageClass) { |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1147 | SkString key = type.description() + "*" + to_string(storageClass); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1148 | auto entry = fTypeMap.find(key); |
| 1149 | if (entry == fTypeMap.end()) { |
| 1150 | SpvId result = this->nextId(); |
| 1151 | this->writeInstruction(SpvOpTypePointer, result, storageClass, |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1152 | this->getType(type), fConstantBuffer); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1153 | fTypeMap[key] = result; |
| 1154 | return result; |
| 1155 | } |
| 1156 | return entry->second; |
| 1157 | } |
| 1158 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1159 | SpvId SPIRVCodeGenerator::writeExpression(const Expression& expr, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1160 | switch (expr.fKind) { |
| 1161 | case Expression::kBinary_Kind: |
| 1162 | return this->writeBinaryExpression((BinaryExpression&) expr, out); |
| 1163 | case Expression::kBoolLiteral_Kind: |
| 1164 | return this->writeBoolLiteral((BoolLiteral&) expr); |
| 1165 | case Expression::kConstructor_Kind: |
| 1166 | return this->writeConstructor((Constructor&) expr, out); |
| 1167 | case Expression::kIntLiteral_Kind: |
| 1168 | return this->writeIntLiteral((IntLiteral&) expr); |
| 1169 | case Expression::kFieldAccess_Kind: |
| 1170 | return this->writeFieldAccess(((FieldAccess&) expr), out); |
| 1171 | case Expression::kFloatLiteral_Kind: |
| 1172 | return this->writeFloatLiteral(((FloatLiteral&) expr)); |
| 1173 | case Expression::kFunctionCall_Kind: |
| 1174 | return this->writeFunctionCall((FunctionCall&) expr, out); |
| 1175 | case Expression::kPrefix_Kind: |
| 1176 | return this->writePrefixExpression((PrefixExpression&) expr, out); |
| 1177 | case Expression::kPostfix_Kind: |
| 1178 | return this->writePostfixExpression((PostfixExpression&) expr, out); |
| 1179 | case Expression::kSwizzle_Kind: |
| 1180 | return this->writeSwizzle((Swizzle&) expr, out); |
| 1181 | case Expression::kVariableReference_Kind: |
| 1182 | return this->writeVariableReference((VariableReference&) expr, out); |
| 1183 | case Expression::kTernary_Kind: |
| 1184 | return this->writeTernaryExpression((TernaryExpression&) expr, out); |
| 1185 | case Expression::kIndex_Kind: |
| 1186 | return this->writeIndexExpression((IndexExpression&) expr, out); |
| 1187 | default: |
| 1188 | ABORT("unsupported expression: %s", expr.description().c_str()); |
| 1189 | } |
| 1190 | return -1; |
| 1191 | } |
| 1192 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1193 | SpvId SPIRVCodeGenerator::writeIntrinsicCall(const FunctionCall& c, SkWStream& out) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1194 | auto intrinsic = fIntrinsicMap.find(c.fFunction.fName); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1195 | ASSERT(intrinsic != fIntrinsicMap.end()); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1196 | const Type& type = c.fArguments[0]->fType; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1197 | int32_t intrinsicId; |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1198 | if (std::get<0>(intrinsic->second) == kSpecial_IntrinsicKind || is_float(fContext, type)) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1199 | intrinsicId = std::get<1>(intrinsic->second); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1200 | } else if (is_signed(fContext, type)) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1201 | intrinsicId = std::get<2>(intrinsic->second); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1202 | } else if (is_unsigned(fContext, type)) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1203 | intrinsicId = std::get<3>(intrinsic->second); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1204 | } else if (is_bool(fContext, type)) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1205 | intrinsicId = std::get<4>(intrinsic->second); |
| 1206 | } else { |
| 1207 | ABORT("invalid call %s, cannot operate on '%s'", c.description().c_str(), |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1208 | type.description().c_str()); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1209 | } |
| 1210 | switch (std::get<0>(intrinsic->second)) { |
| 1211 | case kGLSL_STD_450_IntrinsicKind: { |
| 1212 | SpvId result = this->nextId(); |
| 1213 | std::vector<SpvId> arguments; |
| 1214 | for (size_t i = 0; i < c.fArguments.size(); i++) { |
| 1215 | arguments.push_back(this->writeExpression(*c.fArguments[i], out)); |
| 1216 | } |
| 1217 | this->writeOpCode(SpvOpExtInst, 5 + (int32_t) arguments.size(), out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1218 | this->writeWord(this->getType(c.fType), out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1219 | this->writeWord(result, out); |
| 1220 | this->writeWord(fGLSLExtendedInstructions, out); |
| 1221 | this->writeWord(intrinsicId, out); |
| 1222 | for (SpvId id : arguments) { |
| 1223 | this->writeWord(id, out); |
| 1224 | } |
| 1225 | return result; |
| 1226 | } |
| 1227 | case kSPIRV_IntrinsicKind: { |
| 1228 | SpvId result = this->nextId(); |
| 1229 | std::vector<SpvId> arguments; |
| 1230 | for (size_t i = 0; i < c.fArguments.size(); i++) { |
| 1231 | arguments.push_back(this->writeExpression(*c.fArguments[i], out)); |
| 1232 | } |
| 1233 | this->writeOpCode((SpvOp_) intrinsicId, 3 + (int32_t) arguments.size(), out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1234 | this->writeWord(this->getType(c.fType), out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1235 | this->writeWord(result, out); |
| 1236 | for (SpvId id : arguments) { |
| 1237 | this->writeWord(id, out); |
| 1238 | } |
| 1239 | return result; |
| 1240 | } |
| 1241 | case kSpecial_IntrinsicKind: |
| 1242 | return this->writeSpecialIntrinsic(c, (SpecialIntrinsic) intrinsicId, out); |
| 1243 | default: |
| 1244 | ABORT("unsupported intrinsic kind"); |
| 1245 | } |
| 1246 | } |
| 1247 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 1248 | SpvId SPIRVCodeGenerator::writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1249 | SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1250 | SpvId result = this->nextId(); |
| 1251 | switch (kind) { |
| 1252 | case kAtan_SpecialIntrinsic: { |
| 1253 | std::vector<SpvId> arguments; |
| 1254 | for (size_t i = 0; i < c.fArguments.size(); i++) { |
| 1255 | arguments.push_back(this->writeExpression(*c.fArguments[i], out)); |
| 1256 | } |
| 1257 | this->writeOpCode(SpvOpExtInst, 5 + (int32_t) arguments.size(), out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1258 | this->writeWord(this->getType(c.fType), out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1259 | this->writeWord(result, out); |
| 1260 | this->writeWord(fGLSLExtendedInstructions, out); |
| 1261 | this->writeWord(arguments.size() == 2 ? GLSLstd450Atan2 : GLSLstd450Atan, out); |
| 1262 | for (SpvId id : arguments) { |
| 1263 | this->writeWord(id, out); |
| 1264 | } |
| 1265 | return result; |
| 1266 | } |
| 1267 | case kTexture_SpecialIntrinsic: { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1268 | SpvId type = this->getType(c.fType); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1269 | SpvId sampler = this->writeExpression(*c.fArguments[0], out); |
| 1270 | SpvId uv = this->writeExpression(*c.fArguments[1], out); |
| 1271 | if (c.fArguments.size() == 3) { |
| 1272 | this->writeInstruction(SpvOpImageSampleImplicitLod, type, result, sampler, uv, |
| 1273 | SpvImageOperandsBiasMask, |
| 1274 | this->writeExpression(*c.fArguments[2], out), |
| 1275 | out); |
| 1276 | } else { |
| 1277 | ASSERT(c.fArguments.size() == 2); |
| 1278 | this->writeInstruction(SpvOpImageSampleImplicitLod, type, result, sampler, uv, out); |
| 1279 | } |
| 1280 | break; |
| 1281 | } |
| 1282 | case kTextureProj_SpecialIntrinsic: { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1283 | SpvId type = this->getType(c.fType); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1284 | SpvId sampler = this->writeExpression(*c.fArguments[0], out); |
| 1285 | SpvId uv = this->writeExpression(*c.fArguments[1], out); |
| 1286 | if (c.fArguments.size() == 3) { |
| 1287 | this->writeInstruction(SpvOpImageSampleProjImplicitLod, type, result, sampler, uv, |
| 1288 | SpvImageOperandsBiasMask, |
| 1289 | this->writeExpression(*c.fArguments[2], out), |
| 1290 | out); |
| 1291 | } else { |
| 1292 | ASSERT(c.fArguments.size() == 2); |
| 1293 | this->writeInstruction(SpvOpImageSampleProjImplicitLod, type, result, sampler, uv, |
| 1294 | out); |
| 1295 | } |
| 1296 | break; |
| 1297 | } |
| 1298 | case kTexture2D_SpecialIntrinsic: { |
| 1299 | SpvId img = this->writeExpression(*c.fArguments[0], out); |
| 1300 | SpvId coords = this->writeExpression(*c.fArguments[1], out); |
| 1301 | this->writeInstruction(SpvOpImageSampleImplicitLod, |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1302 | this->getType(c.fType), |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1303 | result, |
| 1304 | img, |
| 1305 | coords, |
| 1306 | out); |
| 1307 | break; |
| 1308 | } |
| 1309 | } |
| 1310 | return result; |
| 1311 | } |
| 1312 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1313 | SpvId SPIRVCodeGenerator::writeFunctionCall(const FunctionCall& c, SkWStream& out) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1314 | const auto& entry = fFunctionMap.find(&c.fFunction); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1315 | if (entry == fFunctionMap.end()) { |
| 1316 | return this->writeIntrinsicCall(c, out); |
| 1317 | } |
| 1318 | // stores (variable, type, lvalue) pairs to extract and save after the function call is complete |
| 1319 | std::vector<std::tuple<SpvId, SpvId, std::unique_ptr<LValue>>> lvalues; |
| 1320 | std::vector<SpvId> arguments; |
| 1321 | for (size_t i = 0; i < c.fArguments.size(); i++) { |
| 1322 | // id of temporary variable that we will use to hold this argument, or 0 if it is being |
| 1323 | // passed directly |
| 1324 | SpvId tmpVar; |
| 1325 | // if we need a temporary var to store this argument, this is the value to store in the var |
| 1326 | SpvId tmpValueId; |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1327 | if (is_out(*c.fFunction.fParameters[i])) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1328 | std::unique_ptr<LValue> lv = this->getLValue(*c.fArguments[i], out); |
| 1329 | SpvId ptr = lv->getPointer(); |
| 1330 | if (ptr) { |
| 1331 | arguments.push_back(ptr); |
| 1332 | continue; |
| 1333 | } else { |
| 1334 | // lvalue cannot simply be read and written via a pointer (e.g. a swizzle). Need to |
| 1335 | // copy it into a temp, call the function, read the value out of the temp, and then |
| 1336 | // update the lvalue. |
| 1337 | tmpValueId = lv->load(out); |
| 1338 | tmpVar = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1339 | lvalues.push_back(std::make_tuple(tmpVar, this->getType(c.fArguments[i]->fType), |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1340 | std::move(lv))); |
| 1341 | } |
| 1342 | } else { |
| 1343 | // see getFunctionType for an explanation of why we're always using pointer parameters |
| 1344 | tmpValueId = this->writeExpression(*c.fArguments[i], out); |
| 1345 | tmpVar = this->nextId(); |
| 1346 | } |
| 1347 | this->writeInstruction(SpvOpVariable, |
| 1348 | this->getPointerType(c.fArguments[i]->fType, |
| 1349 | SpvStorageClassFunction), |
| 1350 | tmpVar, |
| 1351 | SpvStorageClassFunction, |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1352 | fVariableBuffer); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1353 | this->writeInstruction(SpvOpStore, tmpVar, tmpValueId, out); |
| 1354 | arguments.push_back(tmpVar); |
| 1355 | } |
| 1356 | SpvId result = this->nextId(); |
| 1357 | this->writeOpCode(SpvOpFunctionCall, 4 + (int32_t) c.fArguments.size(), out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1358 | this->writeWord(this->getType(c.fType), out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1359 | this->writeWord(result, out); |
| 1360 | this->writeWord(entry->second, out); |
| 1361 | for (SpvId id : arguments) { |
| 1362 | this->writeWord(id, out); |
| 1363 | } |
| 1364 | // now that the call is complete, we may need to update some lvalues with the new values of out |
| 1365 | // arguments |
| 1366 | for (const auto& tuple : lvalues) { |
| 1367 | SpvId load = this->nextId(); |
| 1368 | this->writeInstruction(SpvOpLoad, std::get<1>(tuple), load, std::get<0>(tuple), out); |
| 1369 | std::get<2>(tuple)->store(load, out); |
| 1370 | } |
| 1371 | return result; |
| 1372 | } |
| 1373 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 1374 | SpvId SPIRVCodeGenerator::writeConstantVector(const Constructor& c) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1375 | ASSERT(c.fType.kind() == Type::kVector_Kind && c.isConstant()); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1376 | SpvId result = this->nextId(); |
| 1377 | std::vector<SpvId> arguments; |
| 1378 | for (size_t i = 0; i < c.fArguments.size(); i++) { |
| 1379 | arguments.push_back(this->writeExpression(*c.fArguments[i], fConstantBuffer)); |
| 1380 | } |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1381 | SpvId type = this->getType(c.fType); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1382 | if (c.fArguments.size() == 1) { |
| 1383 | // with a single argument, a vector will have all of its entries equal to the argument |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1384 | this->writeOpCode(SpvOpConstantComposite, 3 + c.fType.columns(), fConstantBuffer); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1385 | this->writeWord(type, fConstantBuffer); |
| 1386 | this->writeWord(result, fConstantBuffer); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1387 | for (int i = 0; i < c.fType.columns(); i++) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1388 | this->writeWord(arguments[0], fConstantBuffer); |
| 1389 | } |
| 1390 | } else { |
| 1391 | this->writeOpCode(SpvOpConstantComposite, 3 + (int32_t) c.fArguments.size(), |
| 1392 | fConstantBuffer); |
| 1393 | this->writeWord(type, fConstantBuffer); |
| 1394 | this->writeWord(result, fConstantBuffer); |
| 1395 | for (SpvId id : arguments) { |
| 1396 | this->writeWord(id, fConstantBuffer); |
| 1397 | } |
| 1398 | } |
| 1399 | return result; |
| 1400 | } |
| 1401 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1402 | SpvId SPIRVCodeGenerator::writeFloatConstructor(const Constructor& c, SkWStream& out) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1403 | ASSERT(c.fType == *fContext.fFloat_Type); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1404 | ASSERT(c.fArguments.size() == 1); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1405 | ASSERT(c.fArguments[0]->fType.isNumber()); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1406 | SpvId result = this->nextId(); |
| 1407 | SpvId parameter = this->writeExpression(*c.fArguments[0], out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1408 | if (c.fArguments[0]->fType == *fContext.fInt_Type) { |
| 1409 | this->writeInstruction(SpvOpConvertSToF, this->getType(c.fType), result, parameter, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1410 | out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1411 | } else if (c.fArguments[0]->fType == *fContext.fUInt_Type) { |
| 1412 | this->writeInstruction(SpvOpConvertUToF, this->getType(c.fType), result, parameter, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1413 | out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1414 | } else if (c.fArguments[0]->fType == *fContext.fFloat_Type) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1415 | return parameter; |
| 1416 | } |
| 1417 | return result; |
| 1418 | } |
| 1419 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1420 | SpvId SPIRVCodeGenerator::writeIntConstructor(const Constructor& c, SkWStream& out) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1421 | ASSERT(c.fType == *fContext.fInt_Type); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1422 | ASSERT(c.fArguments.size() == 1); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1423 | ASSERT(c.fArguments[0]->fType.isNumber()); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1424 | SpvId result = this->nextId(); |
| 1425 | SpvId parameter = this->writeExpression(*c.fArguments[0], out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1426 | if (c.fArguments[0]->fType == *fContext.fFloat_Type) { |
| 1427 | this->writeInstruction(SpvOpConvertFToS, this->getType(c.fType), result, parameter, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1428 | out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1429 | } else if (c.fArguments[0]->fType == *fContext.fUInt_Type) { |
| 1430 | this->writeInstruction(SpvOpSatConvertUToS, this->getType(c.fType), result, parameter, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1431 | out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1432 | } else if (c.fArguments[0]->fType == *fContext.fInt_Type) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1433 | return parameter; |
| 1434 | } |
| 1435 | return result; |
| 1436 | } |
| 1437 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1438 | SpvId SPIRVCodeGenerator::writeMatrixConstructor(const Constructor& c, SkWStream& out) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1439 | ASSERT(c.fType.kind() == Type::kMatrix_Kind); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1440 | // go ahead and write the arguments so we don't try to write new instructions in the middle of |
| 1441 | // an instruction |
| 1442 | std::vector<SpvId> arguments; |
| 1443 | for (size_t i = 0; i < c.fArguments.size(); i++) { |
| 1444 | arguments.push_back(this->writeExpression(*c.fArguments[i], out)); |
| 1445 | } |
| 1446 | SpvId result = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1447 | int rows = c.fType.rows(); |
| 1448 | int columns = c.fType.columns(); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1449 | // FIXME this won't work to create a matrix from another matrix |
| 1450 | if (arguments.size() == 1) { |
| 1451 | // with a single argument, a matrix will have all of its diagonal entries equal to the |
| 1452 | // argument and its other values equal to zero |
| 1453 | // FIXME this won't work for int matrices |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1454 | FloatLiteral zero(fContext, Position(), 0); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1455 | SpvId zeroId = this->writeFloatLiteral(zero); |
| 1456 | std::vector<SpvId> columnIds; |
| 1457 | for (int column = 0; column < columns; column++) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1458 | this->writeOpCode(SpvOpCompositeConstruct, 3 + c.fType.rows(), |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1459 | out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1460 | this->writeWord(this->getType(c.fType.componentType().toCompound(fContext, rows, 1)), |
| 1461 | out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1462 | SpvId columnId = this->nextId(); |
| 1463 | this->writeWord(columnId, out); |
| 1464 | columnIds.push_back(columnId); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1465 | for (int row = 0; row < c.fType.columns(); row++) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1466 | this->writeWord(row == column ? arguments[0] : zeroId, out); |
| 1467 | } |
| 1468 | } |
| 1469 | this->writeOpCode(SpvOpCompositeConstruct, 3 + columns, |
| 1470 | out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1471 | this->writeWord(this->getType(c.fType), out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1472 | this->writeWord(result, out); |
| 1473 | for (SpvId id : columnIds) { |
| 1474 | this->writeWord(id, out); |
| 1475 | } |
| 1476 | } else { |
| 1477 | std::vector<SpvId> columnIds; |
| 1478 | int currentCount = 0; |
| 1479 | for (size_t i = 0; i < arguments.size(); i++) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1480 | if (c.fArguments[i]->fType.kind() == Type::kVector_Kind) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1481 | ASSERT(currentCount == 0); |
| 1482 | columnIds.push_back(arguments[i]); |
| 1483 | currentCount = 0; |
| 1484 | } else { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1485 | ASSERT(c.fArguments[i]->fType.kind() == Type::kScalar_Kind); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1486 | if (currentCount == 0) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1487 | this->writeOpCode(SpvOpCompositeConstruct, 3 + c.fType.rows(), out); |
| 1488 | this->writeWord(this->getType(c.fType.componentType().toCompound(fContext, rows, |
| 1489 | 1)), |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1490 | out); |
| 1491 | SpvId id = this->nextId(); |
| 1492 | this->writeWord(id, out); |
| 1493 | columnIds.push_back(id); |
| 1494 | } |
| 1495 | this->writeWord(arguments[i], out); |
| 1496 | currentCount = (currentCount + 1) % rows; |
| 1497 | } |
| 1498 | } |
| 1499 | ASSERT(columnIds.size() == (size_t) columns); |
| 1500 | this->writeOpCode(SpvOpCompositeConstruct, 3 + columns, out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1501 | this->writeWord(this->getType(c.fType), out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1502 | this->writeWord(result, out); |
| 1503 | for (SpvId id : columnIds) { |
| 1504 | this->writeWord(id, out); |
| 1505 | } |
| 1506 | } |
| 1507 | return result; |
| 1508 | } |
| 1509 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1510 | SpvId SPIRVCodeGenerator::writeVectorConstructor(const Constructor& c, SkWStream& out) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1511 | ASSERT(c.fType.kind() == Type::kVector_Kind); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1512 | if (c.isConstant()) { |
| 1513 | return this->writeConstantVector(c); |
| 1514 | } |
| 1515 | // go ahead and write the arguments so we don't try to write new instructions in the middle of |
| 1516 | // an instruction |
| 1517 | std::vector<SpvId> arguments; |
| 1518 | for (size_t i = 0; i < c.fArguments.size(); i++) { |
| 1519 | arguments.push_back(this->writeExpression(*c.fArguments[i], out)); |
| 1520 | } |
| 1521 | SpvId result = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1522 | if (arguments.size() == 1 && c.fArguments[0]->fType.kind() == Type::kScalar_Kind) { |
| 1523 | this->writeOpCode(SpvOpCompositeConstruct, 3 + c.fType.columns(), out); |
| 1524 | this->writeWord(this->getType(c.fType), out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1525 | this->writeWord(result, out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1526 | for (int i = 0; i < c.fType.columns(); i++) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1527 | this->writeWord(arguments[0], out); |
| 1528 | } |
| 1529 | } else { |
| 1530 | this->writeOpCode(SpvOpCompositeConstruct, 3 + (int32_t) c.fArguments.size(), out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1531 | this->writeWord(this->getType(c.fType), out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1532 | this->writeWord(result, out); |
| 1533 | for (SpvId id : arguments) { |
| 1534 | this->writeWord(id, out); |
| 1535 | } |
| 1536 | } |
| 1537 | return result; |
| 1538 | } |
| 1539 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1540 | SpvId SPIRVCodeGenerator::writeConstructor(const Constructor& c, SkWStream& out) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1541 | if (c.fType == *fContext.fFloat_Type) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1542 | return this->writeFloatConstructor(c, out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1543 | } else if (c.fType == *fContext.fInt_Type) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1544 | return this->writeIntConstructor(c, out); |
| 1545 | } |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1546 | switch (c.fType.kind()) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1547 | case Type::kVector_Kind: |
| 1548 | return this->writeVectorConstructor(c, out); |
| 1549 | case Type::kMatrix_Kind: |
| 1550 | return this->writeMatrixConstructor(c, out); |
| 1551 | default: |
| 1552 | ABORT("unsupported constructor: %s", c.description().c_str()); |
| 1553 | } |
| 1554 | } |
| 1555 | |
| 1556 | SpvStorageClass_ get_storage_class(const Modifiers& modifiers) { |
| 1557 | if (modifiers.fFlags & Modifiers::kIn_Flag) { |
| 1558 | return SpvStorageClassInput; |
| 1559 | } else if (modifiers.fFlags & Modifiers::kOut_Flag) { |
| 1560 | return SpvStorageClassOutput; |
| 1561 | } else if (modifiers.fFlags & Modifiers::kUniform_Flag) { |
| 1562 | return SpvStorageClassUniform; |
| 1563 | } else { |
| 1564 | return SpvStorageClassFunction; |
| 1565 | } |
| 1566 | } |
| 1567 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 1568 | SpvStorageClass_ get_storage_class(const Expression& expr) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1569 | switch (expr.fKind) { |
| 1570 | case Expression::kVariableReference_Kind: |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1571 | return get_storage_class(((VariableReference&) expr).fVariable.fModifiers); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1572 | case Expression::kFieldAccess_Kind: |
| 1573 | return get_storage_class(*((FieldAccess&) expr).fBase); |
| 1574 | case Expression::kIndex_Kind: |
| 1575 | return get_storage_class(*((IndexExpression&) expr).fBase); |
| 1576 | default: |
| 1577 | return SpvStorageClassFunction; |
| 1578 | } |
| 1579 | } |
| 1580 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1581 | std::vector<SpvId> SPIRVCodeGenerator::getAccessChain(const Expression& expr, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1582 | std::vector<SpvId> chain; |
| 1583 | switch (expr.fKind) { |
| 1584 | case Expression::kIndex_Kind: { |
| 1585 | IndexExpression& indexExpr = (IndexExpression&) expr; |
| 1586 | chain = this->getAccessChain(*indexExpr.fBase, out); |
| 1587 | chain.push_back(this->writeExpression(*indexExpr.fIndex, out)); |
| 1588 | break; |
| 1589 | } |
| 1590 | case Expression::kFieldAccess_Kind: { |
| 1591 | FieldAccess& fieldExpr = (FieldAccess&) expr; |
| 1592 | chain = this->getAccessChain(*fieldExpr.fBase, out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1593 | IntLiteral index(fContext, Position(), fieldExpr.fFieldIndex); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1594 | chain.push_back(this->writeIntLiteral(index)); |
| 1595 | break; |
| 1596 | } |
| 1597 | default: |
| 1598 | chain.push_back(this->getLValue(expr, out)->getPointer()); |
| 1599 | } |
| 1600 | return chain; |
| 1601 | } |
| 1602 | |
| 1603 | class PointerLValue : public SPIRVCodeGenerator::LValue { |
| 1604 | public: |
| 1605 | PointerLValue(SPIRVCodeGenerator& gen, SpvId pointer, SpvId type) |
| 1606 | : fGen(gen) |
| 1607 | , fPointer(pointer) |
| 1608 | , fType(type) {} |
| 1609 | |
| 1610 | virtual SpvId getPointer() override { |
| 1611 | return fPointer; |
| 1612 | } |
| 1613 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1614 | virtual SpvId load(SkWStream& out) override { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1615 | SpvId result = fGen.nextId(); |
| 1616 | fGen.writeInstruction(SpvOpLoad, fType, result, fPointer, out); |
| 1617 | return result; |
| 1618 | } |
| 1619 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1620 | virtual void store(SpvId value, SkWStream& out) override { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1621 | fGen.writeInstruction(SpvOpStore, fPointer, value, out); |
| 1622 | } |
| 1623 | |
| 1624 | private: |
| 1625 | SPIRVCodeGenerator& fGen; |
| 1626 | const SpvId fPointer; |
| 1627 | const SpvId fType; |
| 1628 | }; |
| 1629 | |
| 1630 | class SwizzleLValue : public SPIRVCodeGenerator::LValue { |
| 1631 | public: |
| 1632 | SwizzleLValue(SPIRVCodeGenerator& gen, SpvId vecPointer, const std::vector<int>& components, |
| 1633 | const Type& baseType, const Type& swizzleType) |
| 1634 | : fGen(gen) |
| 1635 | , fVecPointer(vecPointer) |
| 1636 | , fComponents(components) |
| 1637 | , fBaseType(baseType) |
| 1638 | , fSwizzleType(swizzleType) {} |
| 1639 | |
| 1640 | virtual SpvId getPointer() override { |
| 1641 | return 0; |
| 1642 | } |
| 1643 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1644 | virtual SpvId load(SkWStream& out) override { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1645 | SpvId base = fGen.nextId(); |
| 1646 | fGen.writeInstruction(SpvOpLoad, fGen.getType(fBaseType), base, fVecPointer, out); |
| 1647 | SpvId result = fGen.nextId(); |
| 1648 | fGen.writeOpCode(SpvOpVectorShuffle, 5 + (int32_t) fComponents.size(), out); |
| 1649 | fGen.writeWord(fGen.getType(fSwizzleType), out); |
| 1650 | fGen.writeWord(result, out); |
| 1651 | fGen.writeWord(base, out); |
| 1652 | fGen.writeWord(base, out); |
| 1653 | for (int component : fComponents) { |
| 1654 | fGen.writeWord(component, out); |
| 1655 | } |
| 1656 | return result; |
| 1657 | } |
| 1658 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1659 | virtual void store(SpvId value, SkWStream& out) override { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1660 | // use OpVectorShuffle to mix and match the vector components. We effectively create |
| 1661 | // a virtual vector out of the concatenation of the left and right vectors, and then |
| 1662 | // select components from this virtual vector to make the result vector. For |
| 1663 | // instance, given: |
| 1664 | // vec3 L = ...; |
| 1665 | // vec3 R = ...; |
| 1666 | // L.xz = R.xy; |
| 1667 | // we end up with the virtual vector (L.x, L.y, L.z, R.x, R.y, R.z). Then we want |
| 1668 | // our result vector to look like (R.x, L.y, R.y), so we need to select indices |
| 1669 | // (3, 1, 4). |
| 1670 | SpvId base = fGen.nextId(); |
| 1671 | fGen.writeInstruction(SpvOpLoad, fGen.getType(fBaseType), base, fVecPointer, out); |
| 1672 | SpvId shuffle = fGen.nextId(); |
| 1673 | fGen.writeOpCode(SpvOpVectorShuffle, 5 + fBaseType.columns(), out); |
| 1674 | fGen.writeWord(fGen.getType(fBaseType), out); |
| 1675 | fGen.writeWord(shuffle, out); |
| 1676 | fGen.writeWord(base, out); |
| 1677 | fGen.writeWord(value, out); |
| 1678 | for (int i = 0; i < fBaseType.columns(); i++) { |
| 1679 | // current offset into the virtual vector, defaults to pulling the unmodified |
| 1680 | // value from the left side |
| 1681 | int offset = i; |
| 1682 | // check to see if we are writing this component |
| 1683 | for (size_t j = 0; j < fComponents.size(); j++) { |
| 1684 | if (fComponents[j] == i) { |
| 1685 | // we're writing to this component, so adjust the offset to pull from |
| 1686 | // the correct component of the right side instead of preserving the |
| 1687 | // value from the left |
| 1688 | offset = (int) (j + fBaseType.columns()); |
| 1689 | break; |
| 1690 | } |
| 1691 | } |
| 1692 | fGen.writeWord(offset, out); |
| 1693 | } |
| 1694 | fGen.writeInstruction(SpvOpStore, fVecPointer, shuffle, out); |
| 1695 | } |
| 1696 | |
| 1697 | private: |
| 1698 | SPIRVCodeGenerator& fGen; |
| 1699 | const SpvId fVecPointer; |
| 1700 | const std::vector<int>& fComponents; |
| 1701 | const Type& fBaseType; |
| 1702 | const Type& fSwizzleType; |
| 1703 | }; |
| 1704 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 1705 | std::unique_ptr<SPIRVCodeGenerator::LValue> SPIRVCodeGenerator::getLValue(const Expression& expr, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1706 | SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1707 | switch (expr.fKind) { |
| 1708 | case Expression::kVariableReference_Kind: { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1709 | const Variable& var = ((VariableReference&) expr).fVariable; |
| 1710 | auto entry = fVariableMap.find(&var); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1711 | ASSERT(entry != fVariableMap.end()); |
| 1712 | return std::unique_ptr<SPIRVCodeGenerator::LValue>(new PointerLValue( |
| 1713 | *this, |
| 1714 | entry->second, |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1715 | this->getType(expr.fType))); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1716 | } |
| 1717 | case Expression::kIndex_Kind: // fall through |
| 1718 | case Expression::kFieldAccess_Kind: { |
| 1719 | std::vector<SpvId> chain = this->getAccessChain(expr, out); |
| 1720 | SpvId member = this->nextId(); |
| 1721 | this->writeOpCode(SpvOpAccessChain, (SpvId) (3 + chain.size()), out); |
| 1722 | this->writeWord(this->getPointerType(expr.fType, get_storage_class(expr)), out); |
| 1723 | this->writeWord(member, out); |
| 1724 | for (SpvId idx : chain) { |
| 1725 | this->writeWord(idx, out); |
| 1726 | } |
| 1727 | return std::unique_ptr<SPIRVCodeGenerator::LValue>(new PointerLValue( |
| 1728 | *this, |
| 1729 | member, |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1730 | this->getType(expr.fType))); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | case Expression::kSwizzle_Kind: { |
| 1734 | Swizzle& swizzle = (Swizzle&) expr; |
| 1735 | size_t count = swizzle.fComponents.size(); |
| 1736 | SpvId base = this->getLValue(*swizzle.fBase, out)->getPointer(); |
| 1737 | ASSERT(base); |
| 1738 | if (count == 1) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1739 | IntLiteral index(fContext, Position(), swizzle.fComponents[0]); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1740 | SpvId member = this->nextId(); |
| 1741 | this->writeInstruction(SpvOpAccessChain, |
| 1742 | this->getPointerType(swizzle.fType, |
| 1743 | get_storage_class(*swizzle.fBase)), |
| 1744 | member, |
| 1745 | base, |
| 1746 | this->writeIntLiteral(index), |
| 1747 | out); |
| 1748 | return std::unique_ptr<SPIRVCodeGenerator::LValue>(new PointerLValue( |
| 1749 | *this, |
| 1750 | member, |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1751 | this->getType(expr.fType))); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1752 | } else { |
| 1753 | return std::unique_ptr<SPIRVCodeGenerator::LValue>(new SwizzleLValue( |
| 1754 | *this, |
| 1755 | base, |
| 1756 | swizzle.fComponents, |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1757 | swizzle.fBase->fType, |
| 1758 | expr.fType)); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1759 | } |
| 1760 | } |
| 1761 | |
| 1762 | default: |
| 1763 | // expr isn't actually an lvalue, create a dummy variable for it. This case happens due |
| 1764 | // to the need to store values in temporary variables during function calls (see |
| 1765 | // comments in getFunctionType); erroneous uses of rvalues as lvalues should have been |
| 1766 | // caught by IRGenerator |
| 1767 | SpvId result = this->nextId(); |
| 1768 | SpvId type = this->getPointerType(expr.fType, SpvStorageClassFunction); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1769 | this->writeInstruction(SpvOpVariable, type, result, SpvStorageClassFunction, |
| 1770 | fVariableBuffer); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1771 | this->writeInstruction(SpvOpStore, result, this->writeExpression(expr, out), out); |
| 1772 | return std::unique_ptr<SPIRVCodeGenerator::LValue>(new PointerLValue( |
| 1773 | *this, |
| 1774 | result, |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1775 | this->getType(expr.fType))); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1776 | } |
| 1777 | } |
| 1778 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1779 | SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, SkWStream& out) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1780 | auto entry = fVariableMap.find(&ref.fVariable); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1781 | ASSERT(entry != fVariableMap.end()); |
| 1782 | SpvId var = entry->second; |
| 1783 | SpvId result = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1784 | this->writeInstruction(SpvOpLoad, this->getType(ref.fVariable.fType), result, var, out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1785 | return result; |
| 1786 | } |
| 1787 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1788 | SpvId SPIRVCodeGenerator::writeIndexExpression(const IndexExpression& expr, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1789 | return getLValue(expr, out)->load(out); |
| 1790 | } |
| 1791 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1792 | SpvId SPIRVCodeGenerator::writeFieldAccess(const FieldAccess& f, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1793 | return getLValue(f, out)->load(out); |
| 1794 | } |
| 1795 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1796 | SpvId SPIRVCodeGenerator::writeSwizzle(const Swizzle& swizzle, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1797 | SpvId base = this->writeExpression(*swizzle.fBase, out); |
| 1798 | SpvId result = this->nextId(); |
| 1799 | size_t count = swizzle.fComponents.size(); |
| 1800 | if (count == 1) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1801 | this->writeInstruction(SpvOpCompositeExtract, this->getType(swizzle.fType), result, base, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1802 | swizzle.fComponents[0], out); |
| 1803 | } else { |
| 1804 | this->writeOpCode(SpvOpVectorShuffle, 5 + (int32_t) count, out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1805 | this->writeWord(this->getType(swizzle.fType), out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1806 | this->writeWord(result, out); |
| 1807 | this->writeWord(base, out); |
| 1808 | this->writeWord(base, out); |
| 1809 | for (int component : swizzle.fComponents) { |
| 1810 | this->writeWord(component, out); |
| 1811 | } |
| 1812 | } |
| 1813 | return result; |
| 1814 | } |
| 1815 | |
| 1816 | SpvId SPIRVCodeGenerator::writeBinaryOperation(const Type& resultType, |
| 1817 | const Type& operandType, SpvId lhs, |
| 1818 | SpvId rhs, SpvOp_ ifFloat, SpvOp_ ifInt, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1819 | SpvOp_ ifUInt, SpvOp_ ifBool, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1820 | SpvId result = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1821 | if (is_float(fContext, operandType)) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1822 | this->writeInstruction(ifFloat, this->getType(resultType), result, lhs, rhs, out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1823 | } else if (is_signed(fContext, operandType)) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1824 | this->writeInstruction(ifInt, this->getType(resultType), result, lhs, rhs, out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1825 | } else if (is_unsigned(fContext, operandType)) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1826 | this->writeInstruction(ifUInt, this->getType(resultType), result, lhs, rhs, out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1827 | } else if (operandType == *fContext.fBool_Type) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1828 | this->writeInstruction(ifBool, this->getType(resultType), result, lhs, rhs, out); |
| 1829 | } else { |
| 1830 | ABORT("invalid operandType: %s", operandType.description().c_str()); |
| 1831 | } |
| 1832 | return result; |
| 1833 | } |
| 1834 | |
| 1835 | bool is_assignment(Token::Kind op) { |
| 1836 | switch (op) { |
| 1837 | case Token::EQ: // fall through |
| 1838 | case Token::PLUSEQ: // fall through |
| 1839 | case Token::MINUSEQ: // fall through |
| 1840 | case Token::STAREQ: // fall through |
| 1841 | case Token::SLASHEQ: // fall through |
| 1842 | case Token::PERCENTEQ: // fall through |
| 1843 | case Token::SHLEQ: // fall through |
| 1844 | case Token::SHREQ: // fall through |
| 1845 | case Token::BITWISEOREQ: // fall through |
| 1846 | case Token::BITWISEXOREQ: // fall through |
| 1847 | case Token::BITWISEANDEQ: // fall through |
| 1848 | case Token::LOGICALOREQ: // fall through |
| 1849 | case Token::LOGICALXOREQ: // fall through |
| 1850 | case Token::LOGICALANDEQ: |
| 1851 | return true; |
| 1852 | default: |
| 1853 | return false; |
| 1854 | } |
| 1855 | } |
| 1856 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 1857 | SpvId SPIRVCodeGenerator::writeBinaryExpression(const BinaryExpression& b, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1858 | // handle cases where we don't necessarily evaluate both LHS and RHS |
| 1859 | switch (b.fOperator) { |
| 1860 | case Token::EQ: { |
| 1861 | SpvId rhs = this->writeExpression(*b.fRight, out); |
| 1862 | this->getLValue(*b.fLeft, out)->store(rhs, out); |
| 1863 | return rhs; |
| 1864 | } |
| 1865 | case Token::LOGICALAND: |
| 1866 | return this->writeLogicalAnd(b, out); |
| 1867 | case Token::LOGICALOR: |
| 1868 | return this->writeLogicalOr(b, out); |
| 1869 | default: |
| 1870 | break; |
| 1871 | } |
| 1872 | |
| 1873 | // "normal" operators |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1874 | const Type& resultType = b.fType; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1875 | std::unique_ptr<LValue> lvalue; |
| 1876 | SpvId lhs; |
| 1877 | if (is_assignment(b.fOperator)) { |
| 1878 | lvalue = this->getLValue(*b.fLeft, out); |
| 1879 | lhs = lvalue->load(out); |
| 1880 | } else { |
| 1881 | lvalue = nullptr; |
| 1882 | lhs = this->writeExpression(*b.fLeft, out); |
| 1883 | } |
| 1884 | SpvId rhs = this->writeExpression(*b.fRight, out); |
| 1885 | // component type we are operating on: float, int, uint |
| 1886 | const Type* operandType; |
| 1887 | // IR allows mismatched types in expressions (e.g. vec2 * float), but they need special handling |
| 1888 | // in SPIR-V |
| 1889 | if (b.fLeft->fType != b.fRight->fType) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1890 | if (b.fLeft->fType.kind() == Type::kVector_Kind && |
| 1891 | b.fRight->fType.isNumber()) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1892 | // promote number to vector |
| 1893 | SpvId vec = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1894 | this->writeOpCode(SpvOpCompositeConstruct, 3 + b.fType.columns(), out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1895 | this->writeWord(this->getType(resultType), out); |
| 1896 | this->writeWord(vec, out); |
| 1897 | for (int i = 0; i < resultType.columns(); i++) { |
| 1898 | this->writeWord(rhs, out); |
| 1899 | } |
| 1900 | rhs = vec; |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1901 | operandType = &b.fRight->fType; |
| 1902 | } else if (b.fRight->fType.kind() == Type::kVector_Kind && |
| 1903 | b.fLeft->fType.isNumber()) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1904 | // promote number to vector |
| 1905 | SpvId vec = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1906 | this->writeOpCode(SpvOpCompositeConstruct, 3 + b.fType.columns(), out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1907 | this->writeWord(this->getType(resultType), out); |
| 1908 | this->writeWord(vec, out); |
| 1909 | for (int i = 0; i < resultType.columns(); i++) { |
| 1910 | this->writeWord(lhs, out); |
| 1911 | } |
| 1912 | lhs = vec; |
| 1913 | ASSERT(!lvalue); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1914 | operandType = &b.fLeft->fType; |
| 1915 | } else if (b.fLeft->fType.kind() == Type::kMatrix_Kind) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1916 | SpvOp_ op; |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1917 | if (b.fRight->fType.kind() == Type::kMatrix_Kind) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1918 | op = SpvOpMatrixTimesMatrix; |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1919 | } else if (b.fRight->fType.kind() == Type::kVector_Kind) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1920 | op = SpvOpMatrixTimesVector; |
| 1921 | } else { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1922 | ASSERT(b.fRight->fType.kind() == Type::kScalar_Kind); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1923 | op = SpvOpMatrixTimesScalar; |
| 1924 | } |
| 1925 | SpvId result = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1926 | this->writeInstruction(op, this->getType(b.fType), result, lhs, rhs, out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1927 | if (b.fOperator == Token::STAREQ) { |
| 1928 | lvalue->store(result, out); |
| 1929 | } else { |
| 1930 | ASSERT(b.fOperator == Token::STAR); |
| 1931 | } |
| 1932 | return result; |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1933 | } else if (b.fRight->fType.kind() == Type::kMatrix_Kind) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1934 | SpvId result = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1935 | if (b.fLeft->fType.kind() == Type::kVector_Kind) { |
| 1936 | this->writeInstruction(SpvOpVectorTimesMatrix, this->getType(b.fType), result, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1937 | lhs, rhs, out); |
| 1938 | } else { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1939 | ASSERT(b.fLeft->fType.kind() == Type::kScalar_Kind); |
| 1940 | this->writeInstruction(SpvOpMatrixTimesScalar, this->getType(b.fType), result, rhs, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1941 | lhs, out); |
| 1942 | } |
| 1943 | if (b.fOperator == Token::STAREQ) { |
| 1944 | lvalue->store(result, out); |
| 1945 | } else { |
| 1946 | ASSERT(b.fOperator == Token::STAR); |
| 1947 | } |
| 1948 | return result; |
| 1949 | } else { |
| 1950 | ABORT("unsupported binary expression: %s", b.description().c_str()); |
| 1951 | } |
| 1952 | } else { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1953 | operandType = &b.fLeft->fType; |
| 1954 | ASSERT(*operandType == b.fRight->fType); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1955 | } |
| 1956 | switch (b.fOperator) { |
| 1957 | case Token::EQEQ: |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1958 | ASSERT(resultType == *fContext.fBool_Type); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1959 | return this->writeBinaryOperation(resultType, *operandType, lhs, rhs, SpvOpFOrdEqual, |
| 1960 | SpvOpIEqual, SpvOpIEqual, SpvOpLogicalEqual, out); |
| 1961 | case Token::NEQ: |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1962 | ASSERT(resultType == *fContext.fBool_Type); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1963 | return this->writeBinaryOperation(resultType, *operandType, lhs, rhs, SpvOpFOrdNotEqual, |
| 1964 | SpvOpINotEqual, SpvOpINotEqual, SpvOpLogicalNotEqual, |
| 1965 | out); |
| 1966 | case Token::GT: |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1967 | ASSERT(resultType == *fContext.fBool_Type); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1968 | return this->writeBinaryOperation(resultType, *operandType, lhs, rhs, |
| 1969 | SpvOpFOrdGreaterThan, SpvOpSGreaterThan, |
| 1970 | SpvOpUGreaterThan, SpvOpUndef, out); |
| 1971 | case Token::LT: |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1972 | ASSERT(resultType == *fContext.fBool_Type); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1973 | return this->writeBinaryOperation(resultType, *operandType, lhs, rhs, SpvOpFOrdLessThan, |
| 1974 | SpvOpSLessThan, SpvOpULessThan, SpvOpUndef, out); |
| 1975 | case Token::GTEQ: |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1976 | ASSERT(resultType == *fContext.fBool_Type); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1977 | return this->writeBinaryOperation(resultType, *operandType, lhs, rhs, |
| 1978 | SpvOpFOrdGreaterThanEqual, SpvOpSGreaterThanEqual, |
| 1979 | SpvOpUGreaterThanEqual, SpvOpUndef, out); |
| 1980 | case Token::LTEQ: |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1981 | ASSERT(resultType == *fContext.fBool_Type); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1982 | return this->writeBinaryOperation(resultType, *operandType, lhs, rhs, |
| 1983 | SpvOpFOrdLessThanEqual, SpvOpSLessThanEqual, |
| 1984 | SpvOpULessThanEqual, SpvOpUndef, out); |
| 1985 | case Token::PLUS: |
| 1986 | return this->writeBinaryOperation(resultType, *operandType, lhs, rhs, SpvOpFAdd, |
| 1987 | SpvOpIAdd, SpvOpIAdd, SpvOpUndef, out); |
| 1988 | case Token::MINUS: |
| 1989 | return this->writeBinaryOperation(resultType, *operandType, lhs, rhs, SpvOpFSub, |
| 1990 | SpvOpISub, SpvOpISub, SpvOpUndef, out); |
| 1991 | case Token::STAR: |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 1992 | if (b.fLeft->fType.kind() == Type::kMatrix_Kind && |
| 1993 | b.fRight->fType.kind() == Type::kMatrix_Kind) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1994 | // matrix multiply |
| 1995 | SpvId result = this->nextId(); |
| 1996 | this->writeInstruction(SpvOpMatrixTimesMatrix, this->getType(resultType), result, |
| 1997 | lhs, rhs, out); |
| 1998 | return result; |
| 1999 | } |
| 2000 | return this->writeBinaryOperation(resultType, *operandType, lhs, rhs, SpvOpFMul, |
| 2001 | SpvOpIMul, SpvOpIMul, SpvOpUndef, out); |
| 2002 | case Token::SLASH: |
| 2003 | return this->writeBinaryOperation(resultType, *operandType, lhs, rhs, SpvOpFDiv, |
| 2004 | SpvOpSDiv, SpvOpUDiv, SpvOpUndef, out); |
| 2005 | case Token::PLUSEQ: { |
| 2006 | SpvId result = this->writeBinaryOperation(resultType, *operandType, lhs, rhs, SpvOpFAdd, |
| 2007 | SpvOpIAdd, SpvOpIAdd, SpvOpUndef, out); |
| 2008 | ASSERT(lvalue); |
| 2009 | lvalue->store(result, out); |
| 2010 | return result; |
| 2011 | } |
| 2012 | case Token::MINUSEQ: { |
| 2013 | SpvId result = this->writeBinaryOperation(resultType, *operandType, lhs, rhs, SpvOpFSub, |
| 2014 | SpvOpISub, SpvOpISub, SpvOpUndef, out); |
| 2015 | ASSERT(lvalue); |
| 2016 | lvalue->store(result, out); |
| 2017 | return result; |
| 2018 | } |
| 2019 | case Token::STAREQ: { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2020 | if (b.fLeft->fType.kind() == Type::kMatrix_Kind && |
| 2021 | b.fRight->fType.kind() == Type::kMatrix_Kind) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2022 | // matrix multiply |
| 2023 | SpvId result = this->nextId(); |
| 2024 | this->writeInstruction(SpvOpMatrixTimesMatrix, this->getType(resultType), result, |
| 2025 | lhs, rhs, out); |
| 2026 | ASSERT(lvalue); |
| 2027 | lvalue->store(result, out); |
| 2028 | return result; |
| 2029 | } |
| 2030 | SpvId result = this->writeBinaryOperation(resultType, *operandType, lhs, rhs, SpvOpFMul, |
| 2031 | SpvOpIMul, SpvOpIMul, SpvOpUndef, out); |
| 2032 | ASSERT(lvalue); |
| 2033 | lvalue->store(result, out); |
| 2034 | return result; |
| 2035 | } |
| 2036 | case Token::SLASHEQ: { |
| 2037 | SpvId result = this->writeBinaryOperation(resultType, *operandType, lhs, rhs, SpvOpFDiv, |
| 2038 | SpvOpSDiv, SpvOpUDiv, SpvOpUndef, out); |
| 2039 | ASSERT(lvalue); |
| 2040 | lvalue->store(result, out); |
| 2041 | return result; |
| 2042 | } |
| 2043 | default: |
| 2044 | // FIXME: missing support for some operators (bitwise, &&=, ||=, shift...) |
| 2045 | ABORT("unsupported binary expression: %s", b.description().c_str()); |
| 2046 | } |
| 2047 | } |
| 2048 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2049 | SpvId SPIRVCodeGenerator::writeLogicalAnd(const BinaryExpression& a, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2050 | ASSERT(a.fOperator == Token::LOGICALAND); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2051 | BoolLiteral falseLiteral(fContext, Position(), false); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2052 | SpvId falseConstant = this->writeBoolLiteral(falseLiteral); |
| 2053 | SpvId lhs = this->writeExpression(*a.fLeft, out); |
| 2054 | SpvId rhsLabel = this->nextId(); |
| 2055 | SpvId end = this->nextId(); |
| 2056 | SpvId lhsBlock = fCurrentBlock; |
| 2057 | this->writeInstruction(SpvOpSelectionMerge, end, SpvSelectionControlMaskNone, out); |
| 2058 | this->writeInstruction(SpvOpBranchConditional, lhs, rhsLabel, end, out); |
| 2059 | this->writeLabel(rhsLabel, out); |
| 2060 | SpvId rhs = this->writeExpression(*a.fRight, out); |
| 2061 | SpvId rhsBlock = fCurrentBlock; |
| 2062 | this->writeInstruction(SpvOpBranch, end, out); |
| 2063 | this->writeLabel(end, out); |
| 2064 | SpvId result = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2065 | this->writeInstruction(SpvOpPhi, this->getType(*fContext.fBool_Type), result, falseConstant, |
| 2066 | lhsBlock, rhs, rhsBlock, out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2067 | return result; |
| 2068 | } |
| 2069 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2070 | SpvId SPIRVCodeGenerator::writeLogicalOr(const BinaryExpression& o, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2071 | ASSERT(o.fOperator == Token::LOGICALOR); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2072 | BoolLiteral trueLiteral(fContext, Position(), true); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2073 | SpvId trueConstant = this->writeBoolLiteral(trueLiteral); |
| 2074 | SpvId lhs = this->writeExpression(*o.fLeft, out); |
| 2075 | SpvId rhsLabel = this->nextId(); |
| 2076 | SpvId end = this->nextId(); |
| 2077 | SpvId lhsBlock = fCurrentBlock; |
| 2078 | this->writeInstruction(SpvOpSelectionMerge, end, SpvSelectionControlMaskNone, out); |
| 2079 | this->writeInstruction(SpvOpBranchConditional, lhs, end, rhsLabel, out); |
| 2080 | this->writeLabel(rhsLabel, out); |
| 2081 | SpvId rhs = this->writeExpression(*o.fRight, out); |
| 2082 | SpvId rhsBlock = fCurrentBlock; |
| 2083 | this->writeInstruction(SpvOpBranch, end, out); |
| 2084 | this->writeLabel(end, out); |
| 2085 | SpvId result = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2086 | this->writeInstruction(SpvOpPhi, this->getType(*fContext.fBool_Type), result, trueConstant, |
| 2087 | lhsBlock, rhs, rhsBlock, out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2088 | return result; |
| 2089 | } |
| 2090 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2091 | SpvId SPIRVCodeGenerator::writeTernaryExpression(const TernaryExpression& t, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2092 | SpvId test = this->writeExpression(*t.fTest, out); |
| 2093 | if (t.fIfTrue->isConstant() && t.fIfFalse->isConstant()) { |
| 2094 | // both true and false are constants, can just use OpSelect |
| 2095 | SpvId result = this->nextId(); |
| 2096 | SpvId trueId = this->writeExpression(*t.fIfTrue, out); |
| 2097 | SpvId falseId = this->writeExpression(*t.fIfFalse, out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2098 | this->writeInstruction(SpvOpSelect, this->getType(t.fType), result, test, trueId, falseId, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2099 | out); |
| 2100 | return result; |
| 2101 | } |
| 2102 | // was originally using OpPhi to choose the result, but for some reason that is crashing on |
| 2103 | // Adreno. Switched to storing the result in a temp variable as glslang does. |
| 2104 | SpvId var = this->nextId(); |
| 2105 | this->writeInstruction(SpvOpVariable, this->getPointerType(t.fType, SpvStorageClassFunction), |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2106 | var, SpvStorageClassFunction, fVariableBuffer); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2107 | SpvId trueLabel = this->nextId(); |
| 2108 | SpvId falseLabel = this->nextId(); |
| 2109 | SpvId end = this->nextId(); |
| 2110 | this->writeInstruction(SpvOpSelectionMerge, end, SpvSelectionControlMaskNone, out); |
| 2111 | this->writeInstruction(SpvOpBranchConditional, test, trueLabel, falseLabel, out); |
| 2112 | this->writeLabel(trueLabel, out); |
| 2113 | this->writeInstruction(SpvOpStore, var, this->writeExpression(*t.fIfTrue, out), out); |
| 2114 | this->writeInstruction(SpvOpBranch, end, out); |
| 2115 | this->writeLabel(falseLabel, out); |
| 2116 | this->writeInstruction(SpvOpStore, var, this->writeExpression(*t.fIfFalse, out), out); |
| 2117 | this->writeInstruction(SpvOpBranch, end, out); |
| 2118 | this->writeLabel(end, out); |
| 2119 | SpvId result = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2120 | this->writeInstruction(SpvOpLoad, this->getType(t.fType), result, var, out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2121 | return result; |
| 2122 | } |
| 2123 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2124 | std::unique_ptr<Expression> create_literal_1(const Context& context, const Type& type) { |
| 2125 | if (type == *context.fInt_Type) { |
| 2126 | return std::unique_ptr<Expression>(new IntLiteral(context, Position(), 1)); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2127 | } |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2128 | else if (type == *context.fFloat_Type) { |
| 2129 | return std::unique_ptr<Expression>(new FloatLiteral(context, Position(), 1.0)); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2130 | } else { |
| 2131 | ABORT("math is unsupported on type '%s'") |
| 2132 | } |
| 2133 | } |
| 2134 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2135 | SpvId SPIRVCodeGenerator::writePrefixExpression(const PrefixExpression& p, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2136 | if (p.fOperator == Token::MINUS) { |
| 2137 | SpvId result = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2138 | SpvId typeId = this->getType(p.fType); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2139 | SpvId expr = this->writeExpression(*p.fOperand, out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2140 | if (is_float(fContext, p.fType)) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2141 | this->writeInstruction(SpvOpFNegate, typeId, result, expr, out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2142 | } else if (is_signed(fContext, p.fType)) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2143 | this->writeInstruction(SpvOpSNegate, typeId, result, expr, out); |
| 2144 | } else { |
| 2145 | ABORT("unsupported prefix expression %s", p.description().c_str()); |
| 2146 | }; |
| 2147 | return result; |
| 2148 | } |
| 2149 | switch (p.fOperator) { |
| 2150 | case Token::PLUS: |
| 2151 | return this->writeExpression(*p.fOperand, out); |
| 2152 | case Token::PLUSPLUS: { |
| 2153 | std::unique_ptr<LValue> lv = this->getLValue(*p.fOperand, out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2154 | SpvId one = this->writeExpression(*create_literal_1(fContext, p.fType), out); |
| 2155 | SpvId result = this->writeBinaryOperation(p.fType, p.fType, lv->load(out), one, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2156 | SpvOpFAdd, SpvOpIAdd, SpvOpIAdd, SpvOpUndef, |
| 2157 | out); |
| 2158 | lv->store(result, out); |
| 2159 | return result; |
| 2160 | } |
| 2161 | case Token::MINUSMINUS: { |
| 2162 | std::unique_ptr<LValue> lv = this->getLValue(*p.fOperand, out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2163 | SpvId one = this->writeExpression(*create_literal_1(fContext, p.fType), out); |
| 2164 | SpvId result = this->writeBinaryOperation(p.fType, p.fType, lv->load(out), one, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2165 | SpvOpFSub, SpvOpISub, SpvOpISub, SpvOpUndef, |
| 2166 | out); |
| 2167 | lv->store(result, out); |
| 2168 | return result; |
| 2169 | } |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 2170 | case Token::LOGICALNOT: { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2171 | ASSERT(p.fOperand->fType == *fContext.fBool_Type); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2172 | SpvId result = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2173 | this->writeInstruction(SpvOpLogicalNot, this->getType(p.fOperand->fType), result, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2174 | this->writeExpression(*p.fOperand, out), out); |
| 2175 | return result; |
| 2176 | } |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 2177 | case Token::BITWISENOT: { |
| 2178 | SpvId result = this->nextId(); |
| 2179 | this->writeInstruction(SpvOpNot, this->getType(p.fOperand->fType), result, |
| 2180 | this->writeExpression(*p.fOperand, out), out); |
| 2181 | return result; |
| 2182 | } |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2183 | default: |
| 2184 | ABORT("unsupported prefix expression: %s", p.description().c_str()); |
| 2185 | } |
| 2186 | } |
| 2187 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2188 | SpvId SPIRVCodeGenerator::writePostfixExpression(const PostfixExpression& p, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2189 | std::unique_ptr<LValue> lv = this->getLValue(*p.fOperand, out); |
| 2190 | SpvId result = lv->load(out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2191 | SpvId one = this->writeExpression(*create_literal_1(fContext, p.fType), out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2192 | switch (p.fOperator) { |
| 2193 | case Token::PLUSPLUS: { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2194 | SpvId temp = this->writeBinaryOperation(p.fType, p.fType, result, one, SpvOpFAdd, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2195 | SpvOpIAdd, SpvOpIAdd, SpvOpUndef, out); |
| 2196 | lv->store(temp, out); |
| 2197 | return result; |
| 2198 | } |
| 2199 | case Token::MINUSMINUS: { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2200 | SpvId temp = this->writeBinaryOperation(p.fType, p.fType, result, one, SpvOpFSub, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2201 | SpvOpISub, SpvOpISub, SpvOpUndef, out); |
| 2202 | lv->store(temp, out); |
| 2203 | return result; |
| 2204 | } |
| 2205 | default: |
| 2206 | ABORT("unsupported postfix expression %s", p.description().c_str()); |
| 2207 | } |
| 2208 | } |
| 2209 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 2210 | SpvId SPIRVCodeGenerator::writeBoolLiteral(const BoolLiteral& b) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2211 | if (b.fValue) { |
| 2212 | if (fBoolTrue == 0) { |
| 2213 | fBoolTrue = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2214 | this->writeInstruction(SpvOpConstantTrue, this->getType(b.fType), fBoolTrue, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2215 | fConstantBuffer); |
| 2216 | } |
| 2217 | return fBoolTrue; |
| 2218 | } else { |
| 2219 | if (fBoolFalse == 0) { |
| 2220 | fBoolFalse = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2221 | this->writeInstruction(SpvOpConstantFalse, this->getType(b.fType), fBoolFalse, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2222 | fConstantBuffer); |
| 2223 | } |
| 2224 | return fBoolFalse; |
| 2225 | } |
| 2226 | } |
| 2227 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 2228 | SpvId SPIRVCodeGenerator::writeIntLiteral(const IntLiteral& i) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2229 | if (i.fType == *fContext.fInt_Type) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2230 | auto entry = fIntConstants.find(i.fValue); |
| 2231 | if (entry == fIntConstants.end()) { |
| 2232 | SpvId result = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2233 | this->writeInstruction(SpvOpConstant, this->getType(i.fType), result, (SpvId) i.fValue, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2234 | fConstantBuffer); |
| 2235 | fIntConstants[i.fValue] = result; |
| 2236 | return result; |
| 2237 | } |
| 2238 | return entry->second; |
| 2239 | } else { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2240 | ASSERT(i.fType == *fContext.fUInt_Type); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2241 | auto entry = fUIntConstants.find(i.fValue); |
| 2242 | if (entry == fUIntConstants.end()) { |
| 2243 | SpvId result = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2244 | this->writeInstruction(SpvOpConstant, this->getType(i.fType), result, (SpvId) i.fValue, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2245 | fConstantBuffer); |
| 2246 | fUIntConstants[i.fValue] = result; |
| 2247 | return result; |
| 2248 | } |
| 2249 | return entry->second; |
| 2250 | } |
| 2251 | } |
| 2252 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 2253 | SpvId SPIRVCodeGenerator::writeFloatLiteral(const FloatLiteral& f) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2254 | if (f.fType == *fContext.fFloat_Type) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2255 | float value = (float) f.fValue; |
| 2256 | auto entry = fFloatConstants.find(value); |
| 2257 | if (entry == fFloatConstants.end()) { |
| 2258 | SpvId result = this->nextId(); |
| 2259 | uint32_t bits; |
| 2260 | ASSERT(sizeof(bits) == sizeof(value)); |
| 2261 | memcpy(&bits, &value, sizeof(bits)); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2262 | this->writeInstruction(SpvOpConstant, this->getType(f.fType), result, bits, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2263 | fConstantBuffer); |
| 2264 | fFloatConstants[value] = result; |
| 2265 | return result; |
| 2266 | } |
| 2267 | return entry->second; |
| 2268 | } else { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2269 | ASSERT(f.fType == *fContext.fDouble_Type); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2270 | auto entry = fDoubleConstants.find(f.fValue); |
| 2271 | if (entry == fDoubleConstants.end()) { |
| 2272 | SpvId result = this->nextId(); |
| 2273 | uint64_t bits; |
| 2274 | ASSERT(sizeof(bits) == sizeof(f.fValue)); |
| 2275 | memcpy(&bits, &f.fValue, sizeof(bits)); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2276 | this->writeInstruction(SpvOpConstant, this->getType(f.fType), result, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2277 | bits & 0xffffffff, bits >> 32, fConstantBuffer); |
| 2278 | fDoubleConstants[f.fValue] = result; |
| 2279 | return result; |
| 2280 | } |
| 2281 | return entry->second; |
| 2282 | } |
| 2283 | } |
| 2284 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2285 | SpvId SPIRVCodeGenerator::writeFunctionStart(const FunctionDeclaration& f, SkWStream& out) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2286 | SpvId result = fFunctionMap[&f]; |
| 2287 | this->writeInstruction(SpvOpFunction, this->getType(f.fReturnType), result, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2288 | SpvFunctionControlMaskNone, this->getFunctionType(f), out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2289 | this->writeInstruction(SpvOpName, result, f.fName.c_str(), fNameBuffer); |
| 2290 | for (size_t i = 0; i < f.fParameters.size(); i++) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2291 | SpvId id = this->nextId(); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2292 | fVariableMap[f.fParameters[i]] = id; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2293 | SpvId type; |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2294 | type = this->getPointerType(f.fParameters[i]->fType, SpvStorageClassFunction); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2295 | this->writeInstruction(SpvOpFunctionParameter, type, id, out); |
| 2296 | } |
| 2297 | return result; |
| 2298 | } |
| 2299 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2300 | SpvId SPIRVCodeGenerator::writeFunction(const FunctionDefinition& f, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2301 | SpvId result = this->writeFunctionStart(f.fDeclaration, out); |
| 2302 | this->writeLabel(this->nextId(), out); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2303 | if (f.fDeclaration.fName == "main") { |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2304 | write_data(*fGlobalInitializersBuffer.detachAsData(), out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2305 | } |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2306 | SkDynamicMemoryWStream bodyBuffer; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2307 | this->writeBlock(*f.fBody, bodyBuffer); |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2308 | write_data(*fVariableBuffer.detachAsData(), out); |
| 2309 | write_data(*bodyBuffer.detachAsData(), out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2310 | if (fCurrentBlock) { |
| 2311 | this->writeInstruction(SpvOpReturn, out); |
| 2312 | } |
| 2313 | this->writeInstruction(SpvOpFunctionEnd, out); |
| 2314 | return result; |
| 2315 | } |
| 2316 | |
| 2317 | void SPIRVCodeGenerator::writeLayout(const Layout& layout, SpvId target) { |
| 2318 | if (layout.fLocation >= 0) { |
| 2319 | this->writeInstruction(SpvOpDecorate, target, SpvDecorationLocation, layout.fLocation, |
| 2320 | fDecorationBuffer); |
| 2321 | } |
| 2322 | if (layout.fBinding >= 0) { |
| 2323 | this->writeInstruction(SpvOpDecorate, target, SpvDecorationBinding, layout.fBinding, |
| 2324 | fDecorationBuffer); |
| 2325 | } |
| 2326 | if (layout.fIndex >= 0) { |
| 2327 | this->writeInstruction(SpvOpDecorate, target, SpvDecorationIndex, layout.fIndex, |
| 2328 | fDecorationBuffer); |
| 2329 | } |
| 2330 | if (layout.fSet >= 0) { |
| 2331 | this->writeInstruction(SpvOpDecorate, target, SpvDecorationDescriptorSet, layout.fSet, |
| 2332 | fDecorationBuffer); |
| 2333 | } |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 2334 | if (layout.fBuiltin >= 0 && layout.fBuiltin != SK_FRAGCOLOR_BUILTIN) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2335 | this->writeInstruction(SpvOpDecorate, target, SpvDecorationBuiltIn, layout.fBuiltin, |
| 2336 | fDecorationBuffer); |
| 2337 | } |
| 2338 | } |
| 2339 | |
| 2340 | void SPIRVCodeGenerator::writeLayout(const Layout& layout, SpvId target, int member) { |
| 2341 | if (layout.fLocation >= 0) { |
| 2342 | this->writeInstruction(SpvOpMemberDecorate, target, member, SpvDecorationLocation, |
| 2343 | layout.fLocation, fDecorationBuffer); |
| 2344 | } |
| 2345 | if (layout.fBinding >= 0) { |
| 2346 | this->writeInstruction(SpvOpMemberDecorate, target, member, SpvDecorationBinding, |
| 2347 | layout.fBinding, fDecorationBuffer); |
| 2348 | } |
| 2349 | if (layout.fIndex >= 0) { |
| 2350 | this->writeInstruction(SpvOpMemberDecorate, target, member, SpvDecorationIndex, |
| 2351 | layout.fIndex, fDecorationBuffer); |
| 2352 | } |
| 2353 | if (layout.fSet >= 0) { |
| 2354 | this->writeInstruction(SpvOpMemberDecorate, target, member, SpvDecorationDescriptorSet, |
| 2355 | layout.fSet, fDecorationBuffer); |
| 2356 | } |
| 2357 | if (layout.fBuiltin >= 0) { |
| 2358 | this->writeInstruction(SpvOpMemberDecorate, target, member, SpvDecorationBuiltIn, |
| 2359 | layout.fBuiltin, fDecorationBuffer); |
| 2360 | } |
| 2361 | } |
| 2362 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 2363 | SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf) { |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 2364 | SpvId type = this->getType(intf.fVariable.fType); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2365 | SpvId result = this->nextId(); |
| 2366 | this->writeInstruction(SpvOpDecorate, type, SpvDecorationBlock, fDecorationBuffer); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2367 | SpvStorageClass_ storageClass = get_storage_class(intf.fVariable.fModifiers); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2368 | SpvId ptrType = this->nextId(); |
| 2369 | this->writeInstruction(SpvOpTypePointer, ptrType, storageClass, type, fConstantBuffer); |
| 2370 | this->writeInstruction(SpvOpVariable, ptrType, result, storageClass, fConstantBuffer); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2371 | this->writeLayout(intf.fVariable.fModifiers.fLayout, result); |
| 2372 | fVariableMap[&intf.fVariable] = result; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2373 | return result; |
| 2374 | } |
| 2375 | |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 2376 | #define BUILTIN_IGNORE 9999 |
| 2377 | void SPIRVCodeGenerator::writeGlobalVars(Program::Kind kind, const VarDeclarations& decl, |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2378 | SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2379 | for (size_t i = 0; i < decl.fVars.size(); i++) { |
ethannicholas | 14fe8cc | 2016-09-07 13:37:16 -0700 | [diff] [blame] | 2380 | const VarDeclaration& varDecl = decl.fVars[i]; |
| 2381 | const Variable* var = varDecl.fVar; |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 2382 | if (var->fModifiers.fLayout.fBuiltin == BUILTIN_IGNORE) { |
| 2383 | continue; |
| 2384 | } |
| 2385 | if (var->fModifiers.fLayout.fBuiltin == SK_FRAGCOLOR_BUILTIN && |
| 2386 | kind != Program::kFragment_Kind) { |
| 2387 | continue; |
| 2388 | } |
ethannicholas | 14fe8cc | 2016-09-07 13:37:16 -0700 | [diff] [blame] | 2389 | if (!var->fIsReadFrom && !var->fIsWrittenTo && |
| 2390 | !(var->fModifiers.fFlags & (Modifiers::kIn_Flag | |
| 2391 | Modifiers::kOut_Flag | |
| 2392 | Modifiers::kUniform_Flag))) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2393 | // variable is dead and not an input / output var (the Vulkan debug layers complain if |
| 2394 | // we elide an interface var, even if it's dead) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2395 | continue; |
| 2396 | } |
| 2397 | SpvStorageClass_ storageClass; |
ethannicholas | 14fe8cc | 2016-09-07 13:37:16 -0700 | [diff] [blame] | 2398 | if (var->fModifiers.fFlags & Modifiers::kIn_Flag) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2399 | storageClass = SpvStorageClassInput; |
ethannicholas | 14fe8cc | 2016-09-07 13:37:16 -0700 | [diff] [blame] | 2400 | } else if (var->fModifiers.fFlags & Modifiers::kOut_Flag) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2401 | storageClass = SpvStorageClassOutput; |
ethannicholas | 14fe8cc | 2016-09-07 13:37:16 -0700 | [diff] [blame] | 2402 | } else if (var->fModifiers.fFlags & Modifiers::kUniform_Flag) { |
| 2403 | if (var->fType.kind() == Type::kSampler_Kind) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2404 | storageClass = SpvStorageClassUniformConstant; |
| 2405 | } else { |
| 2406 | storageClass = SpvStorageClassUniform; |
| 2407 | } |
| 2408 | } else { |
| 2409 | storageClass = SpvStorageClassPrivate; |
| 2410 | } |
| 2411 | SpvId id = this->nextId(); |
ethannicholas | 14fe8cc | 2016-09-07 13:37:16 -0700 | [diff] [blame] | 2412 | fVariableMap[var] = id; |
| 2413 | SpvId type = this->getPointerType(var->fType, storageClass); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2414 | this->writeInstruction(SpvOpVariable, type, id, storageClass, fConstantBuffer); |
ethannicholas | 14fe8cc | 2016-09-07 13:37:16 -0700 | [diff] [blame] | 2415 | this->writeInstruction(SpvOpName, id, var->fName.c_str(), fNameBuffer); |
| 2416 | if (var->fType.kind() == Type::kMatrix_Kind) { |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 2417 | this->writeInstruction(SpvOpMemberDecorate, id, (SpvId) i, SpvDecorationColMajor, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2418 | fDecorationBuffer); |
egdaniel | 988283c | 2016-11-16 07:29:51 -0800 | [diff] [blame] | 2419 | this->writeInstruction(SpvOpMemberDecorate, id, (SpvId) i, SpvDecorationMatrixStride, |
| 2420 | (SpvId) var->fType.stride(), fDecorationBuffer); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2421 | } |
ethannicholas | 14fe8cc | 2016-09-07 13:37:16 -0700 | [diff] [blame] | 2422 | if (varDecl.fValue) { |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 2423 | ASSERT(!fCurrentBlock); |
| 2424 | fCurrentBlock = -1; |
ethannicholas | 14fe8cc | 2016-09-07 13:37:16 -0700 | [diff] [blame] | 2425 | SpvId value = this->writeExpression(*varDecl.fValue, fGlobalInitializersBuffer); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2426 | this->writeInstruction(SpvOpStore, id, value, fGlobalInitializersBuffer); |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 2427 | fCurrentBlock = 0; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2428 | } |
ethannicholas | 14fe8cc | 2016-09-07 13:37:16 -0700 | [diff] [blame] | 2429 | this->writeLayout(var->fModifiers.fLayout, id); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2430 | } |
| 2431 | } |
| 2432 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2433 | void SPIRVCodeGenerator::writeVarDeclarations(const VarDeclarations& decl, SkWStream& out) { |
ethannicholas | 14fe8cc | 2016-09-07 13:37:16 -0700 | [diff] [blame] | 2434 | for (const auto& varDecl : decl.fVars) { |
| 2435 | const Variable* var = varDecl.fVar; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2436 | SpvId id = this->nextId(); |
ethannicholas | 14fe8cc | 2016-09-07 13:37:16 -0700 | [diff] [blame] | 2437 | fVariableMap[var] = id; |
| 2438 | SpvId type = this->getPointerType(var->fType, SpvStorageClassFunction); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2439 | this->writeInstruction(SpvOpVariable, type, id, SpvStorageClassFunction, fVariableBuffer); |
ethannicholas | 14fe8cc | 2016-09-07 13:37:16 -0700 | [diff] [blame] | 2440 | this->writeInstruction(SpvOpName, id, var->fName.c_str(), fNameBuffer); |
| 2441 | if (varDecl.fValue) { |
| 2442 | SpvId value = this->writeExpression(*varDecl.fValue, out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2443 | this->writeInstruction(SpvOpStore, id, value, out); |
| 2444 | } |
| 2445 | } |
| 2446 | } |
| 2447 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2448 | void SPIRVCodeGenerator::writeStatement(const Statement& s, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2449 | switch (s.fKind) { |
| 2450 | case Statement::kBlock_Kind: |
| 2451 | this->writeBlock((Block&) s, out); |
| 2452 | break; |
| 2453 | case Statement::kExpression_Kind: |
| 2454 | this->writeExpression(*((ExpressionStatement&) s).fExpression, out); |
| 2455 | break; |
| 2456 | case Statement::kReturn_Kind: |
| 2457 | this->writeReturnStatement((ReturnStatement&) s, out); |
| 2458 | break; |
ethannicholas | 14fe8cc | 2016-09-07 13:37:16 -0700 | [diff] [blame] | 2459 | case Statement::kVarDeclarations_Kind: |
| 2460 | this->writeVarDeclarations(*((VarDeclarationsStatement&) s).fDeclaration, out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2461 | break; |
| 2462 | case Statement::kIf_Kind: |
| 2463 | this->writeIfStatement((IfStatement&) s, out); |
| 2464 | break; |
| 2465 | case Statement::kFor_Kind: |
| 2466 | this->writeForStatement((ForStatement&) s, out); |
| 2467 | break; |
| 2468 | case Statement::kBreak_Kind: |
| 2469 | this->writeInstruction(SpvOpBranch, fBreakTarget.top(), out); |
| 2470 | break; |
| 2471 | case Statement::kContinue_Kind: |
| 2472 | this->writeInstruction(SpvOpBranch, fContinueTarget.top(), out); |
| 2473 | break; |
| 2474 | case Statement::kDiscard_Kind: |
| 2475 | this->writeInstruction(SpvOpKill, out); |
| 2476 | break; |
| 2477 | default: |
| 2478 | ABORT("unsupported statement: %s", s.description().c_str()); |
| 2479 | } |
| 2480 | } |
| 2481 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2482 | void SPIRVCodeGenerator::writeBlock(const Block& b, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2483 | for (size_t i = 0; i < b.fStatements.size(); i++) { |
| 2484 | this->writeStatement(*b.fStatements[i], out); |
| 2485 | } |
| 2486 | } |
| 2487 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2488 | void SPIRVCodeGenerator::writeIfStatement(const IfStatement& stmt, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2489 | SpvId test = this->writeExpression(*stmt.fTest, out); |
| 2490 | SpvId ifTrue = this->nextId(); |
| 2491 | SpvId ifFalse = this->nextId(); |
| 2492 | if (stmt.fIfFalse) { |
| 2493 | SpvId end = this->nextId(); |
| 2494 | this->writeInstruction(SpvOpSelectionMerge, end, SpvSelectionControlMaskNone, out); |
| 2495 | this->writeInstruction(SpvOpBranchConditional, test, ifTrue, ifFalse, out); |
| 2496 | this->writeLabel(ifTrue, out); |
| 2497 | this->writeStatement(*stmt.fIfTrue, out); |
| 2498 | if (fCurrentBlock) { |
| 2499 | this->writeInstruction(SpvOpBranch, end, out); |
| 2500 | } |
| 2501 | this->writeLabel(ifFalse, out); |
| 2502 | this->writeStatement(*stmt.fIfFalse, out); |
| 2503 | if (fCurrentBlock) { |
| 2504 | this->writeInstruction(SpvOpBranch, end, out); |
| 2505 | } |
| 2506 | this->writeLabel(end, out); |
| 2507 | } else { |
| 2508 | this->writeInstruction(SpvOpSelectionMerge, ifFalse, SpvSelectionControlMaskNone, out); |
| 2509 | this->writeInstruction(SpvOpBranchConditional, test, ifTrue, ifFalse, out); |
| 2510 | this->writeLabel(ifTrue, out); |
| 2511 | this->writeStatement(*stmt.fIfTrue, out); |
| 2512 | if (fCurrentBlock) { |
| 2513 | this->writeInstruction(SpvOpBranch, ifFalse, out); |
| 2514 | } |
| 2515 | this->writeLabel(ifFalse, out); |
| 2516 | } |
| 2517 | } |
| 2518 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2519 | void SPIRVCodeGenerator::writeForStatement(const ForStatement& f, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2520 | if (f.fInitializer) { |
| 2521 | this->writeStatement(*f.fInitializer, out); |
| 2522 | } |
| 2523 | SpvId header = this->nextId(); |
| 2524 | SpvId start = this->nextId(); |
| 2525 | SpvId body = this->nextId(); |
| 2526 | SpvId next = this->nextId(); |
| 2527 | fContinueTarget.push(next); |
| 2528 | SpvId end = this->nextId(); |
| 2529 | fBreakTarget.push(end); |
| 2530 | this->writeInstruction(SpvOpBranch, header, out); |
| 2531 | this->writeLabel(header, out); |
| 2532 | this->writeInstruction(SpvOpLoopMerge, end, next, SpvLoopControlMaskNone, out); |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 2533 | this->writeInstruction(SpvOpBranch, start, out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2534 | this->writeLabel(start, out); |
ethannicholas | 22f939e | 2016-10-13 13:25:34 -0700 | [diff] [blame] | 2535 | if (f.fTest) { |
| 2536 | SpvId test = this->writeExpression(*f.fTest, out); |
| 2537 | this->writeInstruction(SpvOpBranchConditional, test, body, end, out); |
| 2538 | } |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2539 | this->writeLabel(body, out); |
| 2540 | this->writeStatement(*f.fStatement, out); |
| 2541 | if (fCurrentBlock) { |
| 2542 | this->writeInstruction(SpvOpBranch, next, out); |
| 2543 | } |
| 2544 | this->writeLabel(next, out); |
| 2545 | if (f.fNext) { |
| 2546 | this->writeExpression(*f.fNext, out); |
| 2547 | } |
| 2548 | this->writeInstruction(SpvOpBranch, header, out); |
| 2549 | this->writeLabel(end, out); |
| 2550 | fBreakTarget.pop(); |
| 2551 | fContinueTarget.pop(); |
| 2552 | } |
| 2553 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2554 | void SPIRVCodeGenerator::writeReturnStatement(const ReturnStatement& r, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2555 | if (r.fExpression) { |
| 2556 | this->writeInstruction(SpvOpReturnValue, this->writeExpression(*r.fExpression, out), |
| 2557 | out); |
| 2558 | } else { |
| 2559 | this->writeInstruction(SpvOpReturn, out); |
| 2560 | } |
| 2561 | } |
| 2562 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2563 | void SPIRVCodeGenerator::writeInstructions(const Program& program, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2564 | fGLSLExtendedInstructions = this->nextId(); |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2565 | SkDynamicMemoryWStream body; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2566 | std::vector<SpvId> interfaceVars; |
| 2567 | // assign IDs to functions |
| 2568 | for (size_t i = 0; i < program.fElements.size(); i++) { |
| 2569 | if (program.fElements[i]->fKind == ProgramElement::kFunction_Kind) { |
| 2570 | FunctionDefinition& f = (FunctionDefinition&) *program.fElements[i]; |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2571 | fFunctionMap[&f.fDeclaration] = this->nextId(); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2572 | } |
| 2573 | } |
| 2574 | for (size_t i = 0; i < program.fElements.size(); i++) { |
| 2575 | if (program.fElements[i]->fKind == ProgramElement::kInterfaceBlock_Kind) { |
| 2576 | InterfaceBlock& intf = (InterfaceBlock&) *program.fElements[i]; |
| 2577 | SpvId id = this->writeInterfaceBlock(intf); |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2578 | if ((intf.fVariable.fModifiers.fFlags & Modifiers::kIn_Flag) || |
| 2579 | (intf.fVariable.fModifiers.fFlags & Modifiers::kOut_Flag)) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2580 | interfaceVars.push_back(id); |
| 2581 | } |
| 2582 | } |
| 2583 | } |
| 2584 | for (size_t i = 0; i < program.fElements.size(); i++) { |
| 2585 | if (program.fElements[i]->fKind == ProgramElement::kVar_Kind) { |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 2586 | this->writeGlobalVars(program.fKind, ((VarDeclarations&) *program.fElements[i]), |
| 2587 | body); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2588 | } |
| 2589 | } |
| 2590 | for (size_t i = 0; i < program.fElements.size(); i++) { |
| 2591 | if (program.fElements[i]->fKind == ProgramElement::kFunction_Kind) { |
| 2592 | this->writeFunction(((FunctionDefinition&) *program.fElements[i]), body); |
| 2593 | } |
| 2594 | } |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2595 | const FunctionDeclaration* main = nullptr; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2596 | for (auto entry : fFunctionMap) { |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 2597 | if (entry.first->fName == "main") { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2598 | main = entry.first; |
| 2599 | } |
| 2600 | } |
| 2601 | ASSERT(main); |
| 2602 | for (auto entry : fVariableMap) { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 2603 | const Variable* var = entry.first; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2604 | if (var->fStorage == Variable::kGlobal_Storage && |
| 2605 | ((var->fModifiers.fFlags & Modifiers::kIn_Flag) || |
| 2606 | (var->fModifiers.fFlags & Modifiers::kOut_Flag))) { |
| 2607 | interfaceVars.push_back(entry.second); |
| 2608 | } |
| 2609 | } |
| 2610 | this->writeCapabilities(out); |
| 2611 | this->writeInstruction(SpvOpExtInstImport, fGLSLExtendedInstructions, "GLSL.std.450", out); |
| 2612 | this->writeInstruction(SpvOpMemoryModel, SpvAddressingModelLogical, SpvMemoryModelGLSL450, out); |
| 2613 | this->writeOpCode(SpvOpEntryPoint, (SpvId) (3 + (strlen(main->fName.c_str()) + 4) / 4) + |
| 2614 | (int32_t) interfaceVars.size(), out); |
| 2615 | switch (program.fKind) { |
| 2616 | case Program::kVertex_Kind: |
| 2617 | this->writeWord(SpvExecutionModelVertex, out); |
| 2618 | break; |
| 2619 | case Program::kFragment_Kind: |
| 2620 | this->writeWord(SpvExecutionModelFragment, out); |
| 2621 | break; |
| 2622 | } |
| 2623 | this->writeWord(fFunctionMap[main], out); |
| 2624 | this->writeString(main->fName.c_str(), out); |
| 2625 | for (int var : interfaceVars) { |
| 2626 | this->writeWord(var, out); |
| 2627 | } |
| 2628 | if (program.fKind == Program::kFragment_Kind) { |
| 2629 | this->writeInstruction(SpvOpExecutionMode, |
| 2630 | fFunctionMap[main], |
| 2631 | SpvExecutionModeOriginUpperLeft, |
| 2632 | out); |
| 2633 | } |
| 2634 | for (size_t i = 0; i < program.fElements.size(); i++) { |
| 2635 | if (program.fElements[i]->fKind == ProgramElement::kExtension_Kind) { |
| 2636 | this->writeInstruction(SpvOpSourceExtension, |
| 2637 | ((Extension&) *program.fElements[i]).fName.c_str(), |
| 2638 | out); |
| 2639 | } |
| 2640 | } |
| 2641 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2642 | write_data(*fNameBuffer.detachAsData(), out); |
| 2643 | write_data(*fDecorationBuffer.detachAsData(), out); |
| 2644 | write_data(*fConstantBuffer.detachAsData(), out); |
| 2645 | write_data(*fExternalFunctionsBuffer.detachAsData(), out); |
| 2646 | write_data(*body.detachAsData(), out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2647 | } |
| 2648 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2649 | void SPIRVCodeGenerator::generateCode(const Program& program, SkWStream& out) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2650 | this->writeWord(SpvMagicNumber, out); |
| 2651 | this->writeWord(SpvVersion, out); |
| 2652 | this->writeWord(SKSL_MAGIC, out); |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2653 | SkDynamicMemoryWStream buffer; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2654 | this->writeInstructions(program, buffer); |
| 2655 | this->writeWord(fIdCount, out); |
| 2656 | this->writeWord(0, out); // reserved, always zero |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 2657 | write_data(*buffer.detachAsData(), out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | } |