Line data Source code
1 : /*
2 : * Copyright 2016 Google Inc.
3 : *
4 : * Use of this source code is governed by a BSD-style license that can be
5 : * found in the LICENSE file.
6 : */
7 :
8 : #ifndef SKSL_CONTEXT
9 : #define SKSL_CONTEXT
10 :
11 : #include "ir/SkSLType.h"
12 : #include "ir/SkSLExpression.h"
13 :
14 : namespace SkSL {
15 :
16 : /**
17 : * Contains compiler-wide objects, which currently means the core types.
18 : */
19 0 : class Context {
20 : public:
21 0 : Context()
22 0 : : fInvalid_Type(new Type(String("<INVALID>")))
23 0 : , fVoid_Type(new Type(String("void")))
24 0 : , fDouble_Type(new Type(String("double"), true))
25 0 : , fDVec2_Type(new Type(String("dvec2"), *fDouble_Type, 2))
26 0 : , fDVec3_Type(new Type(String("dvec3"), *fDouble_Type, 3))
27 0 : , fDVec4_Type(new Type(String("dvec4"), *fDouble_Type, 4))
28 0 : , fFloat_Type(new Type(String("float"), true, { fDouble_Type.get() }))
29 0 : , fVec2_Type(new Type(String("vec2"), *fFloat_Type, 2))
30 0 : , fVec3_Type(new Type(String("vec3"), *fFloat_Type, 3))
31 0 : , fVec4_Type(new Type(String("vec4"), *fFloat_Type, 4))
32 0 : , fUInt_Type(new Type(String("uint"), true, { fFloat_Type.get(), fDouble_Type.get() }))
33 0 : , fUVec2_Type(new Type(String("uvec2"), *fUInt_Type, 2))
34 0 : , fUVec3_Type(new Type(String("uvec3"), *fUInt_Type, 3))
35 0 : , fUVec4_Type(new Type(String("uvec4"), *fUInt_Type, 4))
36 0 : , fInt_Type(new Type(String("int"), true, { fUInt_Type.get(), fFloat_Type.get(),
37 0 : fDouble_Type.get() }))
38 0 : , fIVec2_Type(new Type(String("ivec2"), *fInt_Type, 2))
39 0 : , fIVec3_Type(new Type(String("ivec3"), *fInt_Type, 3))
40 0 : , fIVec4_Type(new Type(String("ivec4"), *fInt_Type, 4))
41 0 : , fBool_Type(new Type(String("bool"), false))
42 0 : , fBVec2_Type(new Type(String("bvec2"), *fBool_Type, 2))
43 0 : , fBVec3_Type(new Type(String("bvec3"), *fBool_Type, 3))
44 0 : , fBVec4_Type(new Type(String("bvec4"), *fBool_Type, 4))
45 0 : , fMat2x2_Type(new Type(String("mat2"), *fFloat_Type, 2, 2))
46 0 : , fMat2x3_Type(new Type(String("mat2x3"), *fFloat_Type, 2, 3))
47 0 : , fMat2x4_Type(new Type(String("mat2x4"), *fFloat_Type, 2, 4))
48 0 : , fMat3x2_Type(new Type(String("mat3x2"), *fFloat_Type, 3, 2))
49 0 : , fMat3x3_Type(new Type(String("mat3"), *fFloat_Type, 3, 3))
50 0 : , fMat3x4_Type(new Type(String("mat3x4"), *fFloat_Type, 3, 4))
51 0 : , fMat4x2_Type(new Type(String("mat4x2"), *fFloat_Type, 4, 2))
52 0 : , fMat4x3_Type(new Type(String("mat4x3"), *fFloat_Type, 4, 3))
53 0 : , fMat4x4_Type(new Type(String("mat4"), *fFloat_Type, 4, 4))
54 0 : , fDMat2x2_Type(new Type(String("dmat2"), *fFloat_Type, 2, 2))
55 0 : , fDMat2x3_Type(new Type(String("dmat2x3"), *fFloat_Type, 2, 3))
56 0 : , fDMat2x4_Type(new Type(String("dmat2x4"), *fFloat_Type, 2, 4))
57 0 : , fDMat3x2_Type(new Type(String("dmat3x2"), *fFloat_Type, 3, 2))
58 0 : , fDMat3x3_Type(new Type(String("dmat3"), *fFloat_Type, 3, 3))
59 0 : , fDMat3x4_Type(new Type(String("dmat3x4"), *fFloat_Type, 3, 4))
60 0 : , fDMat4x2_Type(new Type(String("dmat4x2"), *fFloat_Type, 4, 2))
61 0 : , fDMat4x3_Type(new Type(String("dmat4x3"), *fFloat_Type, 4, 3))
62 0 : , fDMat4x4_Type(new Type(String("dmat4"), *fFloat_Type, 4, 4))
63 0 : , fSampler1D_Type(new Type(String("sampler1D"), SpvDim1D, false, false, false, true))
64 0 : , fSampler2D_Type(new Type(String("sampler2D"), SpvDim2D, false, false, false, true))
65 0 : , fSampler3D_Type(new Type(String("sampler3D"), SpvDim3D, false, false, false, true))
66 0 : , fSamplerExternalOES_Type(new Type(String("samplerExternalOES"), SpvDim2D, false, false,
67 0 : false, true))
68 0 : , fSamplerCube_Type(new Type(String("samplerCube"), SpvDimCube, false, false, false, true))
69 0 : , fSampler2DRect_Type(new Type(String("sampler2DRect"), SpvDimRect, false, false, false,
70 0 : true))
71 0 : , fSampler1DArray_Type(new Type(String("sampler1DArray")))
72 0 : , fSampler2DArray_Type(new Type(String("sampler2DArray")))
73 0 : , fSamplerCubeArray_Type(new Type(String("samplerCubeArray")))
74 0 : , fSamplerBuffer_Type(new Type(String("samplerBuffer")))
75 0 : , fSampler2DMS_Type(new Type(String("sampler2DMS")))
76 0 : , fSampler2DMSArray_Type(new Type(String("sampler2DMSArray")))
77 0 : , fSampler1DShadow_Type(new Type(String("sampler1DShadow")))
78 0 : , fSampler2DShadow_Type(new Type(String("sampler2DShadow")))
79 0 : , fSamplerCubeShadow_Type(new Type(String("samplerCubeShadow")))
80 0 : , fSampler2DRectShadow_Type(new Type(String("sampler2DRectShadow")))
81 0 : , fSampler1DArrayShadow_Type(new Type(String("sampler1DArrayShadow")))
82 0 : , fSampler2DArrayShadow_Type(new Type(String("sampler2DArrayShadow")))
83 0 : , fSamplerCubeArrayShadow_Type(new Type(String("samplerCubeArrayShadow")))
84 :
85 : // Related to below FIXME, gsampler*s don't currently expand to cover integer case.
86 0 : , fISampler2D_Type(new Type(String("isampler2D"), SpvDim2D, false, false, false, true))
87 :
88 : // FIXME express these as "gimage2D" that expand to image2D, iimage2D, and uimage2D.
89 0 : , fImage2D_Type(new Type(String("image2D"), SpvDim2D, false, false, false, true))
90 0 : , fIImage2D_Type(new Type(String("iimage2D"), SpvDim2D, false, false, false, true))
91 :
92 : // FIXME express these as "gsubpassInput" that expand to subpassInput, isubpassInput,
93 : // and usubpassInput.
94 0 : , fSubpassInput_Type(new Type(String("subpassInput"), SpvDimSubpassData, false, false,
95 0 : false, false))
96 0 : , fSubpassInputMS_Type(new Type(String("subpassInputMS"), SpvDimSubpassData, false, false,
97 0 : true, false))
98 :
99 : // FIXME figure out what we're supposed to do with the gsampler et al. types)
100 0 : , fGSampler1D_Type(new Type(String("$gsampler1D"), static_type(*fSampler1D_Type)))
101 0 : , fGSampler2D_Type(new Type(String("$gsampler2D"), static_type(*fSampler2D_Type)))
102 0 : , fGSampler3D_Type(new Type(String("$gsampler3D"), static_type(*fSampler3D_Type)))
103 0 : , fGSamplerCube_Type(new Type(String("$gsamplerCube"), static_type(*fSamplerCube_Type)))
104 0 : , fGSampler2DRect_Type(new Type(String("$gsampler2DRect"), static_type(*fSampler2DRect_Type)))
105 0 : , fGSampler1DArray_Type(new Type(String("$gsampler1DArray"),
106 0 : static_type(*fSampler1DArray_Type)))
107 0 : , fGSampler2DArray_Type(new Type(String("$gsampler2DArray"),
108 0 : static_type(*fSampler2DArray_Type)))
109 0 : , fGSamplerCubeArray_Type(new Type(String("$gsamplerCubeArray"),
110 0 : static_type(*fSamplerCubeArray_Type)))
111 0 : , fGSamplerBuffer_Type(new Type(String("$gsamplerBuffer"), static_type(*fSamplerBuffer_Type)))
112 0 : , fGSampler2DMS_Type(new Type(String("$gsampler2DMS"), static_type(*fSampler2DMS_Type)))
113 0 : , fGSampler2DMSArray_Type(new Type(String("$gsampler2DMSArray"),
114 0 : static_type(*fSampler2DMSArray_Type)))
115 0 : , fGSampler2DArrayShadow_Type(new Type(String("$gsampler2DArrayShadow"),
116 0 : static_type(*fSampler2DArrayShadow_Type)))
117 0 : , fGSamplerCubeArrayShadow_Type(new Type(String("$gsamplerCubeArrayShadow"),
118 0 : static_type(*fSamplerCubeArrayShadow_Type)))
119 0 : , fGenType_Type(new Type(String("$genType"), { fFloat_Type.get(), fVec2_Type.get(),
120 0 : fVec3_Type.get(), fVec4_Type.get() }))
121 0 : , fGenDType_Type(new Type(String("$genDType"), { fDouble_Type.get(), fDVec2_Type.get(),
122 0 : fDVec3_Type.get(), fDVec4_Type.get() }))
123 0 : , fGenIType_Type(new Type(String("$genIType"), { fInt_Type.get(), fIVec2_Type.get(),
124 0 : fIVec3_Type.get(), fIVec4_Type.get() }))
125 0 : , fGenUType_Type(new Type(String("$genUType"), { fUInt_Type.get(), fUVec2_Type.get(),
126 0 : fUVec3_Type.get(), fUVec4_Type.get() }))
127 0 : , fGenBType_Type(new Type(String("$genBType"), { fBool_Type.get(), fBVec2_Type.get(),
128 0 : fBVec3_Type.get(), fBVec4_Type.get() }))
129 0 : , fMat_Type(new Type(String("$mat"), { fMat2x2_Type.get(), fMat2x3_Type.get(),
130 0 : fMat2x4_Type.get(), fMat3x2_Type.get(),
131 0 : fMat3x3_Type.get(), fMat3x4_Type.get(),
132 0 : fMat4x2_Type.get(), fMat4x3_Type.get(),
133 0 : fMat4x4_Type.get(), fDMat2x2_Type.get(),
134 0 : fDMat2x3_Type.get(), fDMat2x4_Type.get(),
135 0 : fDMat3x2_Type.get(), fDMat3x3_Type.get(),
136 0 : fDMat3x4_Type.get(), fDMat4x2_Type.get(),
137 0 : fDMat4x3_Type.get(), fDMat4x4_Type.get() }))
138 0 : , fVec_Type(new Type(String("$vec"), { fInvalid_Type.get(), fVec2_Type.get(),
139 0 : fVec3_Type.get(), fVec4_Type.get() }))
140 0 : , fGVec_Type(new Type(String("$gvec")))
141 0 : , fGVec2_Type(new Type(String("$gvec2")))
142 0 : , fGVec3_Type(new Type(String("$gvec3")))
143 0 : , fGVec4_Type(new Type(String("$gvec4"), static_type(*fVec4_Type)))
144 0 : , fDVec_Type(new Type(String("$dvec"), { fInvalid_Type.get(), fDVec2_Type.get(),
145 0 : fDVec3_Type.get(), fDVec4_Type.get() }))
146 0 : , fIVec_Type(new Type(String("$ivec"), { fInvalid_Type.get(), fIVec2_Type.get(),
147 0 : fIVec3_Type.get(), fIVec4_Type.get() }))
148 0 : , fUVec_Type(new Type(String("$uvec"), { fInvalid_Type.get(), fUVec2_Type.get(),
149 0 : fUVec3_Type.get(), fUVec4_Type.get() }))
150 0 : , fBVec_Type(new Type(String("$bvec"), { fInvalid_Type.get(), fBVec2_Type.get(),
151 0 : fBVec3_Type.get(), fBVec4_Type.get() }))
152 0 : , fSkCaps_Type(new Type(String("$sk_Caps")))
153 0 : , fDefined_Expression(new Defined(*fInvalid_Type)) {}
154 :
155 0 : static std::vector<const Type*> static_type(const Type& t) {
156 0 : return { &t, &t, &t, &t };
157 : }
158 :
159 : const std::unique_ptr<Type> fInvalid_Type;
160 : const std::unique_ptr<Type> fVoid_Type;
161 :
162 : const std::unique_ptr<Type> fDouble_Type;
163 : const std::unique_ptr<Type> fDVec2_Type;
164 : const std::unique_ptr<Type> fDVec3_Type;
165 : const std::unique_ptr<Type> fDVec4_Type;
166 :
167 : const std::unique_ptr<Type> fFloat_Type;
168 : const std::unique_ptr<Type> fVec2_Type;
169 : const std::unique_ptr<Type> fVec3_Type;
170 : const std::unique_ptr<Type> fVec4_Type;
171 :
172 : const std::unique_ptr<Type> fUInt_Type;
173 : const std::unique_ptr<Type> fUVec2_Type;
174 : const std::unique_ptr<Type> fUVec3_Type;
175 : const std::unique_ptr<Type> fUVec4_Type;
176 :
177 : const std::unique_ptr<Type> fInt_Type;
178 : const std::unique_ptr<Type> fIVec2_Type;
179 : const std::unique_ptr<Type> fIVec3_Type;
180 : const std::unique_ptr<Type> fIVec4_Type;
181 :
182 : const std::unique_ptr<Type> fBool_Type;
183 : const std::unique_ptr<Type> fBVec2_Type;
184 : const std::unique_ptr<Type> fBVec3_Type;
185 : const std::unique_ptr<Type> fBVec4_Type;
186 :
187 : const std::unique_ptr<Type> fMat2x2_Type;
188 : const std::unique_ptr<Type> fMat2x3_Type;
189 : const std::unique_ptr<Type> fMat2x4_Type;
190 : const std::unique_ptr<Type> fMat3x2_Type;
191 : const std::unique_ptr<Type> fMat3x3_Type;
192 : const std::unique_ptr<Type> fMat3x4_Type;
193 : const std::unique_ptr<Type> fMat4x2_Type;
194 : const std::unique_ptr<Type> fMat4x3_Type;
195 : const std::unique_ptr<Type> fMat4x4_Type;
196 :
197 : const std::unique_ptr<Type> fDMat2x2_Type;
198 : const std::unique_ptr<Type> fDMat2x3_Type;
199 : const std::unique_ptr<Type> fDMat2x4_Type;
200 : const std::unique_ptr<Type> fDMat3x2_Type;
201 : const std::unique_ptr<Type> fDMat3x3_Type;
202 : const std::unique_ptr<Type> fDMat3x4_Type;
203 : const std::unique_ptr<Type> fDMat4x2_Type;
204 : const std::unique_ptr<Type> fDMat4x3_Type;
205 : const std::unique_ptr<Type> fDMat4x4_Type;
206 :
207 : const std::unique_ptr<Type> fSampler1D_Type;
208 : const std::unique_ptr<Type> fSampler2D_Type;
209 : const std::unique_ptr<Type> fSampler3D_Type;
210 : const std::unique_ptr<Type> fSamplerExternalOES_Type;
211 : const std::unique_ptr<Type> fSamplerCube_Type;
212 : const std::unique_ptr<Type> fSampler2DRect_Type;
213 : const std::unique_ptr<Type> fSampler1DArray_Type;
214 : const std::unique_ptr<Type> fSampler2DArray_Type;
215 : const std::unique_ptr<Type> fSamplerCubeArray_Type;
216 : const std::unique_ptr<Type> fSamplerBuffer_Type;
217 : const std::unique_ptr<Type> fSampler2DMS_Type;
218 : const std::unique_ptr<Type> fSampler2DMSArray_Type;
219 : const std::unique_ptr<Type> fSampler1DShadow_Type;
220 : const std::unique_ptr<Type> fSampler2DShadow_Type;
221 : const std::unique_ptr<Type> fSamplerCubeShadow_Type;
222 : const std::unique_ptr<Type> fSampler2DRectShadow_Type;
223 : const std::unique_ptr<Type> fSampler1DArrayShadow_Type;
224 : const std::unique_ptr<Type> fSampler2DArrayShadow_Type;
225 : const std::unique_ptr<Type> fSamplerCubeArrayShadow_Type;
226 :
227 :
228 : const std::unique_ptr<Type> fISampler2D_Type;
229 :
230 : const std::unique_ptr<Type> fImage2D_Type;
231 : const std::unique_ptr<Type> fIImage2D_Type;
232 :
233 : const std::unique_ptr<Type> fSubpassInput_Type;
234 : const std::unique_ptr<Type> fSubpassInputMS_Type;
235 :
236 : const std::unique_ptr<Type> fGSampler1D_Type;
237 : const std::unique_ptr<Type> fGSampler2D_Type;
238 : const std::unique_ptr<Type> fGSampler3D_Type;
239 : const std::unique_ptr<Type> fGSamplerCube_Type;
240 : const std::unique_ptr<Type> fGSampler2DRect_Type;
241 : const std::unique_ptr<Type> fGSampler1DArray_Type;
242 : const std::unique_ptr<Type> fGSampler2DArray_Type;
243 : const std::unique_ptr<Type> fGSamplerCubeArray_Type;
244 : const std::unique_ptr<Type> fGSamplerBuffer_Type;
245 : const std::unique_ptr<Type> fGSampler2DMS_Type;
246 : const std::unique_ptr<Type> fGSampler2DMSArray_Type;
247 : const std::unique_ptr<Type> fGSampler2DArrayShadow_Type;
248 : const std::unique_ptr<Type> fGSamplerCubeArrayShadow_Type;
249 :
250 : const std::unique_ptr<Type> fGenType_Type;
251 : const std::unique_ptr<Type> fGenDType_Type;
252 : const std::unique_ptr<Type> fGenIType_Type;
253 : const std::unique_ptr<Type> fGenUType_Type;
254 : const std::unique_ptr<Type> fGenBType_Type;
255 :
256 : const std::unique_ptr<Type> fMat_Type;
257 :
258 : const std::unique_ptr<Type> fVec_Type;
259 :
260 : const std::unique_ptr<Type> fGVec_Type;
261 : const std::unique_ptr<Type> fGVec2_Type;
262 : const std::unique_ptr<Type> fGVec3_Type;
263 : const std::unique_ptr<Type> fGVec4_Type;
264 : const std::unique_ptr<Type> fDVec_Type;
265 : const std::unique_ptr<Type> fIVec_Type;
266 : const std::unique_ptr<Type> fUVec_Type;
267 :
268 : const std::unique_ptr<Type> fBVec_Type;
269 :
270 : const std::unique_ptr<Type> fSkCaps_Type;
271 :
272 : // dummy expression used to mark that a variable has a value during dataflow analysis (when it
273 : // could have several different values, or the analyzer is otherwise unable to assign it a
274 : // specific expression)
275 : const std::unique_ptr<Expression> fDefined_Expression;
276 :
277 : private:
278 0 : class Defined : public Expression {
279 : public:
280 0 : Defined(const Type& type)
281 0 : : INHERITED(Position(), kDefined_Kind, type) {}
282 :
283 0 : virtual String description() const override {
284 0 : return String("<defined>");
285 : }
286 :
287 : typedef Expression INHERITED;
288 : };
289 : };
290 :
291 : } // namespace
292 :
293 : #endif
|