blob: abe7322ceb13f722c5d1579fef97b6e9f09f4060 [file] [log] [blame]
ethannicholasd598f792016-07-25 10:08:54 -07001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
Ethan Nicholas0df1b042017-03-31 13:56:23 -04007
ethannicholasd598f792016-07-25 10:08:54 -07008#ifndef SKSL_CONTEXT
9#define SKSL_CONTEXT
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/sksl/ir/SkSLExpression.h"
12#include "src/sksl/ir/SkSLType.h"
ethannicholasd598f792016-07-25 10:08:54 -070013
14namespace SkSL {
15
16/**
17 * Contains compiler-wide objects, which currently means the core types.
18 */
19class Context {
20public:
21 Context()
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070022 : fInvalid_Type(new Type("<INVALID>"))
23 , fVoid_Type(new Type("void"))
Ethan Nicholasee1c8a72019-02-22 10:50:47 -050024 , fNull_Type(new Type("null"))
Ethan Nicholase1f55022019-02-05 17:17:40 -050025 , fFloatLiteral_Type(new Type("$floatLiteral", Type::kFloat_NumberKind, 3))
26 , fIntLiteral_Type(new Type("$intLiteral", Type::kSigned_NumberKind, 1))
Ethan Nicholas858fecc2019-03-07 13:19:18 -050027 , fDouble_Type(new Type("double", Type::kFloat_NumberKind, 6, true))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070028 , fDouble2_Type(new Type("double2", *fDouble_Type, 2))
29 , fDouble3_Type(new Type("double3", *fDouble_Type, 3))
30 , fDouble4_Type(new Type("double4", *fDouble_Type, 4))
Ethan Nicholas858fecc2019-03-07 13:19:18 -050031 , fFloat_Type(new Type("float", Type::kFloat_NumberKind, 5, true))
Ethan Nicholas8aa45692017-09-20 11:24:15 -040032 , fFloat2_Type(new Type("float2", *fFloat_Type, 2))
33 , fFloat3_Type(new Type("float3", *fFloat_Type, 3))
34 , fFloat4_Type(new Type("float4", *fFloat_Type, 4))
Ethan Nicholase1f55022019-02-05 17:17:40 -050035 , fHalf_Type(new Type("half", Type::kFloat_NumberKind, 4))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070036 , fHalf2_Type(new Type("half2", *fHalf_Type, 2))
37 , fHalf3_Type(new Type("half3", *fHalf_Type, 3))
38 , fHalf4_Type(new Type("half4", *fHalf_Type, 4))
Ethan Nicholas858fecc2019-03-07 13:19:18 -050039 , fUInt_Type(new Type("uint", Type::kUnsigned_NumberKind, 2, true))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070040 , fUInt2_Type(new Type("uint2", *fUInt_Type, 2))
41 , fUInt3_Type(new Type("uint3", *fUInt_Type, 3))
42 , fUInt4_Type(new Type("uint4", *fUInt_Type, 4))
Ethan Nicholas858fecc2019-03-07 13:19:18 -050043 , fInt_Type(new Type("int", Type::kSigned_NumberKind, 2, true))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070044 , fInt2_Type(new Type("int2", *fInt_Type, 2))
45 , fInt3_Type(new Type("int3", *fInt_Type, 3))
46 , fInt4_Type(new Type("int4", *fInt_Type, 4))
Ethan Nicholasf7b88202017-09-18 14:10:39 -040047 , fUShort_Type(new Type("ushort", Type::kUnsigned_NumberKind, 0))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070048 , fUShort2_Type(new Type("ushort2", *fUShort_Type, 2))
49 , fUShort3_Type(new Type("ushort3", *fUShort_Type, 3))
50 , fUShort4_Type(new Type("ushort4", *fUShort_Type, 4))
Ethan Nicholasf7b88202017-09-18 14:10:39 -040051 , fShort_Type(new Type("short", Type::kSigned_NumberKind, 0))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070052 , fShort2_Type(new Type("short2", *fShort_Type, 2))
53 , fShort3_Type(new Type("short3", *fShort_Type, 3))
54 , fShort4_Type(new Type("short4", *fShort_Type, 4))
Ruiqi Maob609e6d2018-07-17 10:19:38 -040055 , fUByte_Type(new Type("ubyte", Type::kUnsigned_NumberKind, 0))
56 , fUByte2_Type(new Type("ubyte2", *fUByte_Type, 2))
57 , fUByte3_Type(new Type("ubyte3", *fUByte_Type, 3))
58 , fUByte4_Type(new Type("ubyte4", *fUByte_Type, 4))
59 , fByte_Type(new Type("byte", Type::kSigned_NumberKind, 0))
60 , fByte2_Type(new Type("byte2", *fByte_Type, 2))
61 , fByte3_Type(new Type("byte3", *fByte_Type, 3))
62 , fByte4_Type(new Type("byte4", *fByte_Type, 4))
Ethan Nicholasf7b88202017-09-18 14:10:39 -040063 , fBool_Type(new Type("bool", Type::kNonnumeric_NumberKind, -1))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070064 , fBool2_Type(new Type("bool2", *fBool_Type, 2))
65 , fBool3_Type(new Type("bool3", *fBool_Type, 3))
66 , fBool4_Type(new Type("bool4", *fBool_Type, 4))
Ethan Nicholas8aa45692017-09-20 11:24:15 -040067 , fFloat2x2_Type(new Type("float2x2", *fFloat_Type, 2, 2))
68 , fFloat2x3_Type(new Type("float2x3", *fFloat_Type, 2, 3))
69 , fFloat2x4_Type(new Type("float2x4", *fFloat_Type, 2, 4))
70 , fFloat3x2_Type(new Type("float3x2", *fFloat_Type, 3, 2))
71 , fFloat3x3_Type(new Type("float3x3", *fFloat_Type, 3, 3))
72 , fFloat3x4_Type(new Type("float3x4", *fFloat_Type, 3, 4))
73 , fFloat4x2_Type(new Type("float4x2", *fFloat_Type, 4, 2))
74 , fFloat4x3_Type(new Type("float4x3", *fFloat_Type, 4, 3))
75 , fFloat4x4_Type(new Type("float4x4", *fFloat_Type, 4, 4))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070076 , fHalf2x2_Type(new Type("half2x2", *fHalf_Type, 2, 2))
77 , fHalf2x3_Type(new Type("half2x3", *fHalf_Type, 2, 3))
78 , fHalf2x4_Type(new Type("half2x4", *fHalf_Type, 2, 4))
79 , fHalf3x2_Type(new Type("half3x2", *fHalf_Type, 3, 2))
80 , fHalf3x3_Type(new Type("half3x3", *fHalf_Type, 3, 3))
81 , fHalf3x4_Type(new Type("half3x4", *fHalf_Type, 3, 4))
82 , fHalf4x2_Type(new Type("half4x2", *fHalf_Type, 4, 2))
83 , fHalf4x3_Type(new Type("half4x3", *fHalf_Type, 4, 3))
84 , fHalf4x4_Type(new Type("half4x4", *fHalf_Type, 4, 4))
85 , fDouble2x2_Type(new Type("double2x2", *fDouble_Type, 2, 2))
86 , fDouble2x3_Type(new Type("double2x3", *fDouble_Type, 2, 3))
87 , fDouble2x4_Type(new Type("double2x4", *fDouble_Type, 2, 4))
88 , fDouble3x2_Type(new Type("double3x2", *fDouble_Type, 3, 2))
89 , fDouble3x3_Type(new Type("double3x3", *fDouble_Type, 3, 3))
90 , fDouble3x4_Type(new Type("double3x4", *fDouble_Type, 3, 4))
91 , fDouble4x2_Type(new Type("double4x2", *fDouble_Type, 4, 2))
92 , fDouble4x3_Type(new Type("double4x3", *fDouble_Type, 4, 3))
93 , fDouble4x4_Type(new Type("double4x4", *fDouble_Type, 4, 4))
94 , fSampler1D_Type(new Type("sampler1D", SpvDim1D, false, false, false, true))
95 , fSampler2D_Type(new Type("sampler2D", SpvDim2D, false, false, false, true))
96 , fSampler3D_Type(new Type("sampler3D", SpvDim3D, false, false, false, true))
97 , fSamplerExternalOES_Type(new Type("samplerExternalOES", SpvDim2D, false, false,
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050098 false, true))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070099 , fSamplerCube_Type(new Type("samplerCube", SpvDimCube, false, false, false, true))
100 , fSampler2DRect_Type(new Type("sampler2DRect", SpvDimRect, false, false, false, true))
101 , fSampler1DArray_Type(new Type("sampler1DArray"))
102 , fSampler2DArray_Type(new Type("sampler2DArray"))
103 , fSamplerCubeArray_Type(new Type("samplerCubeArray"))
104 , fSamplerBuffer_Type(new Type("samplerBuffer", SpvDimBuffer, false, false, false,
Ethan Nicholas0187ae62017-05-03 11:03:44 -0400105 true))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700106 , fSampler2DMS_Type(new Type("sampler2DMS"))
107 , fSampler2DMSArray_Type(new Type("sampler2DMSArray"))
108 , fSampler1DShadow_Type(new Type("sampler1DShadow"))
109 , fSampler2DShadow_Type(new Type("sampler2DShadow"))
110 , fSamplerCubeShadow_Type(new Type("samplerCubeShadow"))
111 , fSampler2DRectShadow_Type(new Type("sampler2DRectShadow"))
112 , fSampler1DArrayShadow_Type(new Type("sampler1DArrayShadow"))
113 , fSampler2DArrayShadow_Type(new Type("sampler2DArrayShadow"))
114 , fSamplerCubeArrayShadow_Type(new Type("samplerCubeArrayShadow"))
Brian Salomon2a51de82016-11-16 12:06:01 -0500115
Brian Salomonbf7b6202016-11-11 16:08:03 -0500116 // Related to below FIXME, gsampler*s don't currently expand to cover integer case.
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700117 , fISampler2D_Type(new Type("isampler2D", SpvDim2D, false, false, false, true))
Brian Salomon2a51de82016-11-16 12:06:01 -0500118
119 // FIXME express these as "gimage2D" that expand to image2D, iimage2D, and uimage2D.
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700120 , fImage2D_Type(new Type("image2D", SpvDim2D, false, false, false, true))
121 , fIImage2D_Type(new Type("iimage2D", SpvDim2D, false, false, false, true))
Brian Salomon2a51de82016-11-16 12:06:01 -0500122
Greg Daniel64773e62016-11-22 09:44:03 -0500123 // FIXME express these as "gsubpassInput" that expand to subpassInput, isubpassInput,
124 // and usubpassInput.
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700125 , fSubpassInput_Type(new Type("subpassInput", SpvDimSubpassData, false, false,
126 false, false))
127 , fSubpassInputMS_Type(new Type("subpassInputMS", SpvDimSubpassData, false, false,
128 true, false))
Greg Daniel64773e62016-11-22 09:44:03 -0500129
ethannicholasd598f792016-07-25 10:08:54 -0700130 // FIXME figure out what we're supposed to do with the gsampler et al. types)
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700131 , fGSampler1D_Type(new Type("$gsampler1D", static_type(*fSampler1D_Type)))
132 , fGSampler2D_Type(new Type("$gsampler2D", static_type(*fSampler2D_Type)))
133 , fGSampler3D_Type(new Type("$gsampler3D", static_type(*fSampler3D_Type)))
134 , fGSamplerCube_Type(new Type("$gsamplerCube", static_type(*fSamplerCube_Type)))
135 , fGSampler2DRect_Type(new Type("$gsampler2DRect", static_type(*fSampler2DRect_Type)))
136 , fGSampler1DArray_Type(new Type("$gsampler1DArray",
Ethan Nicholas9e1138d2016-11-21 10:39:35 -0500137 static_type(*fSampler1DArray_Type)))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700138 , fGSampler2DArray_Type(new Type("$gsampler2DArray",
Ethan Nicholas9e1138d2016-11-21 10:39:35 -0500139 static_type(*fSampler2DArray_Type)))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700140 , fGSamplerCubeArray_Type(new Type("$gsamplerCubeArray",
Ethan Nicholas9e1138d2016-11-21 10:39:35 -0500141 static_type(*fSamplerCubeArray_Type)))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700142 , fGSamplerBuffer_Type(new Type("$gsamplerBuffer", static_type(*fSamplerBuffer_Type)))
143 , fGSampler2DMS_Type(new Type("$gsampler2DMS", static_type(*fSampler2DMS_Type)))
144 , fGSampler2DMSArray_Type(new Type("$gsampler2DMSArray",
Ethan Nicholas9e1138d2016-11-21 10:39:35 -0500145 static_type(*fSampler2DMSArray_Type)))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700146 , fGSampler2DArrayShadow_Type(new Type("$gsampler2DArrayShadow",
ethannicholasd598f792016-07-25 10:08:54 -0700147 static_type(*fSampler2DArrayShadow_Type)))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700148 , fGSamplerCubeArrayShadow_Type(new Type("$gsamplerCubeArrayShadow",
ethannicholasd598f792016-07-25 10:08:54 -0700149 static_type(*fSamplerCubeArrayShadow_Type)))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700150 , fGenType_Type(new Type("$genType", { fFloat_Type.get(), fFloat2_Type.get(),
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400151 fFloat3_Type.get(), fFloat4_Type.get() }))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700152 , fGenHType_Type(new Type("$genHType", { fHalf_Type.get(), fHalf2_Type.get(),
Ethan Nicholasdcba08e2017-08-02 10:52:54 -0400153 fHalf3_Type.get(), fHalf4_Type.get() }))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700154 , fGenDType_Type(new Type("$genDType", { fDouble_Type.get(), fDouble2_Type.get(),
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400155 fDouble3_Type.get(), fDouble4_Type.get() }))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700156 , fGenIType_Type(new Type("$genIType", { fInt_Type.get(), fInt2_Type.get(),
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400157 fInt3_Type.get(), fInt4_Type.get() }))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700158 , fGenUType_Type(new Type("$genUType", { fUInt_Type.get(), fUInt2_Type.get(),
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400159 fUInt3_Type.get(), fUInt4_Type.get() }))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700160 , fGenBType_Type(new Type("$genBType", { fBool_Type.get(), fBool2_Type.get(),
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400161 fBool3_Type.get(), fBool4_Type.get() }))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700162 , fMat_Type(new Type("$mat", { fFloat2x2_Type.get(), fFloat2x3_Type.get(),
163 fFloat2x4_Type.get(), fFloat3x2_Type.get(),
164 fFloat3x3_Type.get(), fFloat3x4_Type.get(),
165 fFloat4x2_Type.get(), fFloat4x3_Type.get(),
166 fFloat4x4_Type.get(), fHalf2x2_Type.get(),
167 fHalf2x3_Type.get(), fHalf2x4_Type.get(),
168 fHalf3x2_Type.get(), fHalf3x3_Type.get(),
169 fHalf3x4_Type.get(), fHalf4x2_Type.get(),
170 fHalf4x3_Type.get(), fHalf4x4_Type.get(),
171 fDouble2x2_Type.get(), fDouble2x3_Type.get(),
172 fDouble2x4_Type.get(), fDouble3x2_Type.get(),
173 fDouble3x3_Type.get(), fDouble3x4_Type.get(),
174 fDouble4x2_Type.get(), fDouble4x3_Type.get(),
175 fDouble4x4_Type.get() }))
176 , fVec_Type(new Type("$vec", { fInvalid_Type.get(), fFloat2_Type.get(),
177 fFloat3_Type.get(), fFloat4_Type.get() }))
178 , fGVec_Type(new Type("$gvec"))
179 , fGVec2_Type(new Type("$gfloat2"))
180 , fGVec3_Type(new Type("$gfloat3"))
181 , fGVec4_Type(new Type("$gfloat4", static_type(*fFloat4_Type)))
182 , fHVec_Type(new Type("$hvec", { fInvalid_Type.get(), fHalf2_Type.get(),
183 fHalf3_Type.get(), fHalf4_Type.get() }))
184 , fDVec_Type(new Type("$dvec", { fInvalid_Type.get(), fDouble2_Type.get(),
185 fDouble3_Type.get(), fDouble4_Type.get() }))
186 , fIVec_Type(new Type("$ivec", { fInvalid_Type.get(), fInt2_Type.get(),
187 fInt3_Type.get(), fInt4_Type.get() }))
188 , fUVec_Type(new Type("$uvec", { fInvalid_Type.get(), fUInt2_Type.get(),
189 fUInt3_Type.get(), fUInt4_Type.get() }))
190 , fSVec_Type(new Type("$svec", { fInvalid_Type.get(), fShort2_Type.get(),
191 fShort3_Type.get(), fShort4_Type.get() }))
192 , fUSVec_Type(new Type("$usvec", { fInvalid_Type.get(), fUShort2_Type.get(),
193 fUShort3_Type.get(), fUShort4_Type.get() }))
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400194 , fByteVec_Type(new Type("$bytevec", { fInvalid_Type.get(), fByte2_Type.get(),
195 fByte3_Type.get(), fByte4_Type.get() }))
196 , fUByteVec_Type(new Type("$ubytevec", { fInvalid_Type.get(), fUByte2_Type.get(),
197 fUByte3_Type.get(), fUByte4_Type.get() }))
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700198 , fBVec_Type(new Type("$bvec", { fInvalid_Type.get(), fBool2_Type.get(),
199 fBool3_Type.get(), fBool4_Type.get() }))
200 , fSkCaps_Type(new Type("$sk_Caps"))
201 , fSkArgs_Type(new Type("$sk_Args"))
Michael Ludwig9094f2c2018-09-07 13:44:21 -0400202 , fFragmentProcessor_Type(fp_type(fInt_Type.get(), fBool_Type.get()))
Ethan Nicholas26a9aad2018-03-27 14:10:52 -0400203 , fSkRasterPipeline_Type(new Type("SkRasterPipeline"))
ethannicholas22f939e2016-10-13 13:25:34 -0700204 , fDefined_Expression(new Defined(*fInvalid_Type)) {}
ethannicholasd598f792016-07-25 10:08:54 -0700205
206 static std::vector<const Type*> static_type(const Type& t) {
Greg Daniel64773e62016-11-22 09:44:03 -0500207 return { &t, &t, &t, &t };
ethannicholasd598f792016-07-25 10:08:54 -0700208 }
209
ethannicholas471e8942016-10-28 09:02:46 -0700210 const std::unique_ptr<Type> fInvalid_Type;
ethannicholasd598f792016-07-25 10:08:54 -0700211 const std::unique_ptr<Type> fVoid_Type;
Ethan Nicholasee1c8a72019-02-22 10:50:47 -0500212 const std::unique_ptr<Type> fNull_Type;
Ethan Nicholase1f55022019-02-05 17:17:40 -0500213 const std::unique_ptr<Type> fFloatLiteral_Type;
214 const std::unique_ptr<Type> fIntLiteral_Type;
ethannicholasd598f792016-07-25 10:08:54 -0700215
216 const std::unique_ptr<Type> fDouble_Type;
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400217 const std::unique_ptr<Type> fDouble2_Type;
218 const std::unique_ptr<Type> fDouble3_Type;
219 const std::unique_ptr<Type> fDouble4_Type;
ethannicholasd598f792016-07-25 10:08:54 -0700220
221 const std::unique_ptr<Type> fFloat_Type;
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400222 const std::unique_ptr<Type> fFloat2_Type;
223 const std::unique_ptr<Type> fFloat3_Type;
224 const std::unique_ptr<Type> fFloat4_Type;
ethannicholasd598f792016-07-25 10:08:54 -0700225
Ethan Nicholasdcba08e2017-08-02 10:52:54 -0400226 const std::unique_ptr<Type> fHalf_Type;
227 const std::unique_ptr<Type> fHalf2_Type;
228 const std::unique_ptr<Type> fHalf3_Type;
229 const std::unique_ptr<Type> fHalf4_Type;
230
ethannicholasd598f792016-07-25 10:08:54 -0700231 const std::unique_ptr<Type> fUInt_Type;
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400232 const std::unique_ptr<Type> fUInt2_Type;
233 const std::unique_ptr<Type> fUInt3_Type;
234 const std::unique_ptr<Type> fUInt4_Type;
ethannicholasd598f792016-07-25 10:08:54 -0700235
236 const std::unique_ptr<Type> fInt_Type;
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400237 const std::unique_ptr<Type> fInt2_Type;
238 const std::unique_ptr<Type> fInt3_Type;
239 const std::unique_ptr<Type> fInt4_Type;
ethannicholasd598f792016-07-25 10:08:54 -0700240
Ethan Nicholasdcba08e2017-08-02 10:52:54 -0400241 const std::unique_ptr<Type> fUShort_Type;
242 const std::unique_ptr<Type> fUShort2_Type;
243 const std::unique_ptr<Type> fUShort3_Type;
244 const std::unique_ptr<Type> fUShort4_Type;
245
246 const std::unique_ptr<Type> fShort_Type;
247 const std::unique_ptr<Type> fShort2_Type;
248 const std::unique_ptr<Type> fShort3_Type;
249 const std::unique_ptr<Type> fShort4_Type;
250
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400251 const std::unique_ptr<Type> fUByte_Type;
252 const std::unique_ptr<Type> fUByte2_Type;
253 const std::unique_ptr<Type> fUByte3_Type;
254 const std::unique_ptr<Type> fUByte4_Type;
255
256 const std::unique_ptr<Type> fByte_Type;
257 const std::unique_ptr<Type> fByte2_Type;
258 const std::unique_ptr<Type> fByte3_Type;
259 const std::unique_ptr<Type> fByte4_Type;
260
ethannicholasd598f792016-07-25 10:08:54 -0700261 const std::unique_ptr<Type> fBool_Type;
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400262 const std::unique_ptr<Type> fBool2_Type;
263 const std::unique_ptr<Type> fBool3_Type;
264 const std::unique_ptr<Type> fBool4_Type;
ethannicholasd598f792016-07-25 10:08:54 -0700265
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400266 const std::unique_ptr<Type> fFloat2x2_Type;
267 const std::unique_ptr<Type> fFloat2x3_Type;
268 const std::unique_ptr<Type> fFloat2x4_Type;
269 const std::unique_ptr<Type> fFloat3x2_Type;
270 const std::unique_ptr<Type> fFloat3x3_Type;
271 const std::unique_ptr<Type> fFloat3x4_Type;
272 const std::unique_ptr<Type> fFloat4x2_Type;
273 const std::unique_ptr<Type> fFloat4x3_Type;
274 const std::unique_ptr<Type> fFloat4x4_Type;
ethannicholasd598f792016-07-25 10:08:54 -0700275
Ethan Nicholasdcba08e2017-08-02 10:52:54 -0400276 const std::unique_ptr<Type> fHalf2x2_Type;
277 const std::unique_ptr<Type> fHalf2x3_Type;
278 const std::unique_ptr<Type> fHalf2x4_Type;
279 const std::unique_ptr<Type> fHalf3x2_Type;
280 const std::unique_ptr<Type> fHalf3x3_Type;
281 const std::unique_ptr<Type> fHalf3x4_Type;
282 const std::unique_ptr<Type> fHalf4x2_Type;
283 const std::unique_ptr<Type> fHalf4x3_Type;
284 const std::unique_ptr<Type> fHalf4x4_Type;
285
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400286 const std::unique_ptr<Type> fDouble2x2_Type;
287 const std::unique_ptr<Type> fDouble2x3_Type;
288 const std::unique_ptr<Type> fDouble2x4_Type;
289 const std::unique_ptr<Type> fDouble3x2_Type;
290 const std::unique_ptr<Type> fDouble3x3_Type;
291 const std::unique_ptr<Type> fDouble3x4_Type;
292 const std::unique_ptr<Type> fDouble4x2_Type;
293 const std::unique_ptr<Type> fDouble4x3_Type;
294 const std::unique_ptr<Type> fDouble4x4_Type;
ethannicholasd598f792016-07-25 10:08:54 -0700295
296 const std::unique_ptr<Type> fSampler1D_Type;
297 const std::unique_ptr<Type> fSampler2D_Type;
298 const std::unique_ptr<Type> fSampler3D_Type;
ethannicholas5961bc92016-10-12 06:39:56 -0700299 const std::unique_ptr<Type> fSamplerExternalOES_Type;
ethannicholasd598f792016-07-25 10:08:54 -0700300 const std::unique_ptr<Type> fSamplerCube_Type;
301 const std::unique_ptr<Type> fSampler2DRect_Type;
302 const std::unique_ptr<Type> fSampler1DArray_Type;
303 const std::unique_ptr<Type> fSampler2DArray_Type;
304 const std::unique_ptr<Type> fSamplerCubeArray_Type;
305 const std::unique_ptr<Type> fSamplerBuffer_Type;
306 const std::unique_ptr<Type> fSampler2DMS_Type;
307 const std::unique_ptr<Type> fSampler2DMSArray_Type;
308 const std::unique_ptr<Type> fSampler1DShadow_Type;
309 const std::unique_ptr<Type> fSampler2DShadow_Type;
310 const std::unique_ptr<Type> fSamplerCubeShadow_Type;
311 const std::unique_ptr<Type> fSampler2DRectShadow_Type;
312 const std::unique_ptr<Type> fSampler1DArrayShadow_Type;
313 const std::unique_ptr<Type> fSampler2DArrayShadow_Type;
314 const std::unique_ptr<Type> fSamplerCubeArrayShadow_Type;
315
Brian Salomonbf7b6202016-11-11 16:08:03 -0500316 const std::unique_ptr<Type> fISampler2D_Type;
317
Brian Salomon2a51de82016-11-16 12:06:01 -0500318 const std::unique_ptr<Type> fImage2D_Type;
319 const std::unique_ptr<Type> fIImage2D_Type;
320
Greg Daniel64773e62016-11-22 09:44:03 -0500321 const std::unique_ptr<Type> fSubpassInput_Type;
322 const std::unique_ptr<Type> fSubpassInputMS_Type;
323
ethannicholasd598f792016-07-25 10:08:54 -0700324 const std::unique_ptr<Type> fGSampler1D_Type;
325 const std::unique_ptr<Type> fGSampler2D_Type;
326 const std::unique_ptr<Type> fGSampler3D_Type;
327 const std::unique_ptr<Type> fGSamplerCube_Type;
328 const std::unique_ptr<Type> fGSampler2DRect_Type;
329 const std::unique_ptr<Type> fGSampler1DArray_Type;
330 const std::unique_ptr<Type> fGSampler2DArray_Type;
331 const std::unique_ptr<Type> fGSamplerCubeArray_Type;
332 const std::unique_ptr<Type> fGSamplerBuffer_Type;
333 const std::unique_ptr<Type> fGSampler2DMS_Type;
334 const std::unique_ptr<Type> fGSampler2DMSArray_Type;
335 const std::unique_ptr<Type> fGSampler2DArrayShadow_Type;
336 const std::unique_ptr<Type> fGSamplerCubeArrayShadow_Type;
337
338 const std::unique_ptr<Type> fGenType_Type;
Ethan Nicholasdcba08e2017-08-02 10:52:54 -0400339 const std::unique_ptr<Type> fGenHType_Type;
ethannicholasd598f792016-07-25 10:08:54 -0700340 const std::unique_ptr<Type> fGenDType_Type;
341 const std::unique_ptr<Type> fGenIType_Type;
342 const std::unique_ptr<Type> fGenUType_Type;
343 const std::unique_ptr<Type> fGenBType_Type;
344
345 const std::unique_ptr<Type> fMat_Type;
346
347 const std::unique_ptr<Type> fVec_Type;
348
349 const std::unique_ptr<Type> fGVec_Type;
350 const std::unique_ptr<Type> fGVec2_Type;
351 const std::unique_ptr<Type> fGVec3_Type;
352 const std::unique_ptr<Type> fGVec4_Type;
Ethan Nicholasdcba08e2017-08-02 10:52:54 -0400353 const std::unique_ptr<Type> fHVec_Type;
ethannicholasd598f792016-07-25 10:08:54 -0700354 const std::unique_ptr<Type> fDVec_Type;
355 const std::unique_ptr<Type> fIVec_Type;
356 const std::unique_ptr<Type> fUVec_Type;
Ethan Nicholasdcba08e2017-08-02 10:52:54 -0400357 const std::unique_ptr<Type> fSVec_Type;
358 const std::unique_ptr<Type> fUSVec_Type;
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400359 const std::unique_ptr<Type> fByteVec_Type;
360 const std::unique_ptr<Type> fUByteVec_Type;
ethannicholasd598f792016-07-25 10:08:54 -0700361
362 const std::unique_ptr<Type> fBVec_Type;
363
Ethan Nicholas3605ace2016-11-21 15:59:48 -0500364 const std::unique_ptr<Type> fSkCaps_Type;
Ethan Nicholas762466e2017-06-29 10:03:38 -0400365 const std::unique_ptr<Type> fSkArgs_Type;
Ethan Nicholasc9472af2017-10-10 16:30:21 -0400366 const std::unique_ptr<Type> fFragmentProcessor_Type;
Ethan Nicholas26a9aad2018-03-27 14:10:52 -0400367 const std::unique_ptr<Type> fSkRasterPipeline_Type;
Ethan Nicholas3605ace2016-11-21 15:59:48 -0500368
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400369 // dummy expression used to mark that a variable has a value during dataflow analysis (when it
ethannicholas22f939e2016-10-13 13:25:34 -0700370 // could have several different values, or the analyzer is otherwise unable to assign it a
371 // specific expression)
372 const std::unique_ptr<Expression> fDefined_Expression;
373
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400374private:
ethannicholas22f939e2016-10-13 13:25:34 -0700375 class Defined : public Expression {
376 public:
377 Defined(const Type& type)
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700378 : INHERITED(-1, kDefined_Kind, type) {}
ethannicholas22f939e2016-10-13 13:25:34 -0700379
Ethan Nicholascb670962017-04-20 19:31:52 -0400380 bool hasSideEffects() const override {
381 return false;
382 }
ethannicholas22f939e2016-10-13 13:25:34 -0700383
Ethan Nicholas762466e2017-06-29 10:03:38 -0400384 String description() const override {
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700385 return "<defined>";
Ethan Nicholas762466e2017-06-29 10:03:38 -0400386 }
387
Ethan Nicholas00543112018-07-31 09:44:36 -0400388 std::unique_ptr<Expression> clone() const override {
389 return std::unique_ptr<Expression>(new Defined(fType));
390 }
391
ethannicholas22f939e2016-10-13 13:25:34 -0700392 typedef Expression INHERITED;
393 };
Michael Ludwig9094f2c2018-09-07 13:44:21 -0400394
395 static std::unique_ptr<Type> fp_type(const Type* intType, const Type* boolType) {
396 // Build fields for FragmentProcessors, which should parallel the
397 // C++ API for GrFragmentProcessor.
398 Modifiers mods(Layout(), Modifiers::kConst_Flag);
399 std::vector<Type::Field> fields = {
400 Type::Field(mods, "numTextureSamplers", intType),
401 Type::Field(mods, "numCoordTransforms", intType),
402 Type::Field(mods, "numChildProcessors", intType),
403 Type::Field(mods, "usesLocalCoords", boolType),
404 Type::Field(mods, "compatibleWithCoverageAsAlpha", boolType),
405 Type::Field(mods, "preservesOpaqueInput", boolType),
406 Type::Field(mods, "hasConstantOutputForConstantInput", boolType)
407 };
408 return std::unique_ptr<Type>(new Type("fragmentProcessor", fields));
409 }
ethannicholasd598f792016-07-25 10:08:54 -0700410};
411
412} // namespace
413
414#endif