1 //
2 // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6
7 #ifndef _BASICTYPES_INCLUDED_
8 #define _BASICTYPES_INCLUDED_
9
10 #include <assert.h>
11
12 //
13 // Precision qualifiers
14 //
15 enum TPrecision
16 {
17 // These need to be kept sorted
18 EbpUndefined,
19 EbpLow,
20 EbpMedium,
21 EbpHigh
22 };
23
getPrecisionString(TPrecision p)24 inline const char* getPrecisionString(TPrecision p)
25 {
26 switch(p)
27 {
28 case EbpHigh: return "highp"; break;
29 case EbpMedium: return "mediump"; break;
30 case EbpLow: return "lowp"; break;
31 default: return "mediump"; break; // Safest fallback
32 }
33 }
34
35 //
36 // Basic type. Arrays, vectors, etc., are orthogonal to this.
37 //
38 enum TBasicType
39 {
40 EbtVoid,
41 EbtFloat,
42 EbtInt,
43 EbtUInt,
44 EbtBool,
45 EbtGVec4, // non type: represents vec4, ivec4 and uvec4
46 EbtGuardSamplerBegin, // non type: see implementation of IsSampler()
47 EbtSampler2D,
48 EbtSampler3D,
49 EbtSamplerCube,
50 EbtSampler2DArray,
51 EbtSamplerExternalOES, // Only valid if OES_EGL_image_external exists.
52 EbtSampler2DRect, // Only valid if GL_ARB_texture_rectangle exists.
53 EbtISampler2D,
54 EbtISampler3D,
55 EbtISamplerCube,
56 EbtISampler2DArray,
57 EbtUSampler2D,
58 EbtUSampler3D,
59 EbtUSamplerCube,
60 EbtUSampler2DArray,
61 EbtSampler2DShadow,
62 EbtSamplerCubeShadow,
63 EbtSampler2DArrayShadow,
64 EbtGuardSamplerEnd, // non type: see implementation of IsSampler()
65 EbtGSampler2D, // non type: represents sampler2D, isampler2D and usampler2D
66 EbtGSampler3D, // non type: represents sampler3D, isampler3D and usampler3D
67 EbtGSamplerCube, // non type: represents samplerCube, isamplerCube and usamplerCube
68 EbtGSampler2DArray, // non type: represents sampler2DArray, isampler2DArray and usampler2DArray
69 EbtStruct,
70 EbtInterfaceBlock,
71 EbtAddress, // should be deprecated??
72 EbtInvariant // used as a type when qualifying a previously declared variable as being invariant
73 };
74
getBasicString(TBasicType t)75 inline const char* getBasicString(TBasicType t)
76 {
77 switch (t)
78 {
79 case EbtVoid: return "void"; break;
80 case EbtFloat: return "float"; break;
81 case EbtInt: return "int"; break;
82 case EbtUInt: return "uint"; break;
83 case EbtBool: return "bool"; break;
84 case EbtSampler2D: return "sampler2D"; break;
85 case EbtSampler3D: return "sampler3D"; break;
86 case EbtSamplerCube: return "samplerCube"; break;
87 case EbtSamplerExternalOES: return "samplerExternalOES"; break;
88 case EbtSampler2DRect: return "sampler2DRect"; break;
89 case EbtSampler2DArray: return "sampler2DArray"; break;
90 case EbtISampler2D: return "isampler2D"; break;
91 case EbtISampler3D: return "isampler3D"; break;
92 case EbtISamplerCube: return "isamplerCube"; break;
93 case EbtISampler2DArray: return "isampler2DArray"; break;
94 case EbtUSampler2D: return "usampler2D"; break;
95 case EbtUSampler3D: return "usampler3D"; break;
96 case EbtUSamplerCube: return "usamplerCube"; break;
97 case EbtUSampler2DArray: return "usampler2DArray"; break;
98 case EbtSampler2DShadow: return "sampler2DShadow"; break;
99 case EbtSamplerCubeShadow: return "samplerCubeShadow"; break;
100 case EbtSampler2DArrayShadow: return "sampler2DArrayShadow"; break;
101 case EbtStruct: return "structure"; break;
102 case EbtInterfaceBlock: return "interface block"; break;
103 default: return "unknown type";
104 }
105 }
106
IsSampler(TBasicType type)107 inline bool IsSampler(TBasicType type)
108 {
109 return type > EbtGuardSamplerBegin && type < EbtGuardSamplerEnd;
110 }
111
IsIntegerSampler(TBasicType type)112 inline bool IsIntegerSampler(TBasicType type)
113 {
114 switch (type)
115 {
116 case EbtISampler2D:
117 case EbtISampler3D:
118 case EbtISamplerCube:
119 case EbtISampler2DArray:
120 case EbtUSampler2D:
121 case EbtUSampler3D:
122 case EbtUSamplerCube:
123 case EbtUSampler2DArray:
124 return true;
125 case EbtSampler2D:
126 case EbtSampler3D:
127 case EbtSamplerCube:
128 case EbtSamplerExternalOES:
129 case EbtSampler2DRect:
130 case EbtSampler2DArray:
131 case EbtSampler2DShadow:
132 case EbtSamplerCubeShadow:
133 case EbtSampler2DArrayShadow:
134 return false;
135 default:
136 assert(!IsSampler(type));
137 }
138
139 return false;
140 }
141
IsSampler2D(TBasicType type)142 inline bool IsSampler2D(TBasicType type)
143 {
144 switch (type)
145 {
146 case EbtSampler2D:
147 case EbtISampler2D:
148 case EbtUSampler2D:
149 case EbtSampler2DArray:
150 case EbtISampler2DArray:
151 case EbtUSampler2DArray:
152 case EbtSampler2DRect:
153 case EbtSamplerExternalOES:
154 case EbtSampler2DShadow:
155 case EbtSampler2DArrayShadow:
156 return true;
157 case EbtSampler3D:
158 case EbtISampler3D:
159 case EbtUSampler3D:
160 case EbtISamplerCube:
161 case EbtUSamplerCube:
162 case EbtSamplerCube:
163 case EbtSamplerCubeShadow:
164 return false;
165 default:
166 assert(!IsSampler(type));
167 }
168
169 return false;
170 }
171
IsSamplerCube(TBasicType type)172 inline bool IsSamplerCube(TBasicType type)
173 {
174 switch (type)
175 {
176 case EbtSamplerCube:
177 case EbtISamplerCube:
178 case EbtUSamplerCube:
179 case EbtSamplerCubeShadow:
180 return true;
181 case EbtSampler2D:
182 case EbtSampler3D:
183 case EbtSamplerExternalOES:
184 case EbtSampler2DRect:
185 case EbtSampler2DArray:
186 case EbtISampler2D:
187 case EbtISampler3D:
188 case EbtISampler2DArray:
189 case EbtUSampler2D:
190 case EbtUSampler3D:
191 case EbtUSampler2DArray:
192 case EbtSampler2DShadow:
193 case EbtSampler2DArrayShadow:
194 return false;
195 default:
196 assert(!IsSampler(type));
197 }
198
199 return false;
200 }
201
IsSampler3D(TBasicType type)202 inline bool IsSampler3D(TBasicType type)
203 {
204 switch (type)
205 {
206 case EbtSampler3D:
207 case EbtISampler3D:
208 case EbtUSampler3D:
209 return true;
210 case EbtSampler2D:
211 case EbtSamplerCube:
212 case EbtSamplerExternalOES:
213 case EbtSampler2DRect:
214 case EbtSampler2DArray:
215 case EbtISampler2D:
216 case EbtISamplerCube:
217 case EbtISampler2DArray:
218 case EbtUSampler2D:
219 case EbtUSamplerCube:
220 case EbtUSampler2DArray:
221 case EbtSampler2DShadow:
222 case EbtSamplerCubeShadow:
223 case EbtSampler2DArrayShadow:
224 return false;
225 default:
226 assert(!IsSampler(type));
227 }
228
229 return false;
230 }
231
IsSamplerArray(TBasicType type)232 inline bool IsSamplerArray(TBasicType type)
233 {
234 switch (type)
235 {
236 case EbtSampler2DArray:
237 case EbtISampler2DArray:
238 case EbtUSampler2DArray:
239 case EbtSampler2DArrayShadow:
240 return true;
241 case EbtSampler2D:
242 case EbtISampler2D:
243 case EbtUSampler2D:
244 case EbtSampler2DRect:
245 case EbtSamplerExternalOES:
246 case EbtSampler3D:
247 case EbtISampler3D:
248 case EbtUSampler3D:
249 case EbtISamplerCube:
250 case EbtUSamplerCube:
251 case EbtSamplerCube:
252 case EbtSampler2DShadow:
253 case EbtSamplerCubeShadow:
254 return false;
255 default:
256 assert(!IsSampler(type));
257 }
258
259 return false;
260 }
261
IsShadowSampler(TBasicType type)262 inline bool IsShadowSampler(TBasicType type)
263 {
264 switch (type)
265 {
266 case EbtSampler2DShadow:
267 case EbtSamplerCubeShadow:
268 case EbtSampler2DArrayShadow:
269 return true;
270 case EbtISampler2D:
271 case EbtISampler3D:
272 case EbtISamplerCube:
273 case EbtISampler2DArray:
274 case EbtUSampler2D:
275 case EbtUSampler3D:
276 case EbtUSamplerCube:
277 case EbtUSampler2DArray:
278 case EbtSampler2D:
279 case EbtSampler3D:
280 case EbtSamplerCube:
281 case EbtSamplerExternalOES:
282 case EbtSampler2DRect:
283 case EbtSampler2DArray:
284 return false;
285 default:
286 assert(!IsSampler(type));
287 }
288
289 return false;
290 }
291
SupportsPrecision(TBasicType type)292 inline bool SupportsPrecision(TBasicType type)
293 {
294 return type == EbtFloat || type == EbtInt || type == EbtUInt || IsSampler(type);
295 }
296
297 //
298 // Qualifiers and built-ins. These are mainly used to see what can be read
299 // or written, and by the machine dependent translator to know which registers
300 // to allocate variables in. Since built-ins tend to go to different registers
301 // than varying or uniform, it makes sense they are peers, not sub-classes.
302 //
303 enum TQualifier
304 {
305 EvqTemporary, // For temporaries (within a function), read/write
306 EvqGlobal, // For globals read/write
307 EvqInternal, // For internal use, not visible to the user
308 EvqConst, // User defined constants and non-output parameters in functions
309 EvqAttribute, // Readonly
310 EvqVaryingIn, // readonly, fragment shaders only
311 EvqVaryingOut, // vertex shaders only read/write
312 EvqInvariantVaryingIn, // readonly, fragment shaders only
313 EvqInvariantVaryingOut, // vertex shaders only read/write
314 EvqUniform, // Readonly, vertex and fragment
315
316 EvqVertexIn, // Vertex shader input
317 EvqFragmentOut, // Fragment shader output
318 EvqVertexOut, // Vertex shader output
319 EvqFragmentIn, // Fragment shader input
320
321 // parameters
322 EvqIn,
323 EvqOut,
324 EvqInOut,
325 EvqConstReadOnly,
326
327 // built-ins written by vertex shader
328 EvqPosition,
329 EvqPointSize,
330
331 // built-ins read by fragment shader
332 EvqFragCoord,
333 EvqFrontFacing,
334 EvqPointCoord,
335
336 // built-ins written by fragment shader
337 EvqFragColor,
338 EvqFragData,
339 EvqFragDepth,
340
341 // GLSL ES 3.0 vertex output and fragment input
342 EvqSmooth, // Incomplete qualifier, smooth is the default
343 EvqFlat, // Incomplete qualifier
344 EvqSmoothOut = EvqSmooth,
345 EvqFlatOut = EvqFlat,
346 EvqCentroidOut, // Implies smooth
347 EvqSmoothIn,
348 EvqFlatIn,
349 EvqCentroidIn, // Implies smooth
350
351 // end of list
352 EvqLast
353 };
354
355 enum TLayoutMatrixPacking
356 {
357 EmpUnspecified,
358 EmpRowMajor,
359 EmpColumnMajor
360 };
361
362 enum TLayoutBlockStorage
363 {
364 EbsUnspecified,
365 EbsShared,
366 EbsPacked,
367 EbsStd140
368 };
369
370 struct TLayoutQualifier
371 {
372 int location;
373 TLayoutMatrixPacking matrixPacking;
374 TLayoutBlockStorage blockStorage;
375
createTLayoutQualifier376 static TLayoutQualifier create()
377 {
378 TLayoutQualifier layoutQualifier;
379
380 layoutQualifier.location = -1;
381 layoutQualifier.matrixPacking = EmpUnspecified;
382 layoutQualifier.blockStorage = EbsUnspecified;
383
384 return layoutQualifier;
385 }
386
isEmptyTLayoutQualifier387 bool isEmpty() const
388 {
389 return location == -1 && matrixPacking == EmpUnspecified && blockStorage == EbsUnspecified;
390 }
391 };
392
393 //
394 // This is just for debug print out, carried along with the definitions above.
395 //
getQualifierString(TQualifier q)396 inline const char* getQualifierString(TQualifier q)
397 {
398 switch(q)
399 {
400 case EvqTemporary: return "Temporary"; break;
401 case EvqGlobal: return "Global"; break;
402 case EvqConst: return "const"; break;
403 case EvqConstReadOnly: return "const"; break;
404 case EvqAttribute: return "attribute"; break;
405 case EvqVaryingIn: return "varying"; break;
406 case EvqVaryingOut: return "varying"; break;
407 case EvqInvariantVaryingIn: return "invariant varying"; break;
408 case EvqInvariantVaryingOut:return "invariant varying"; break;
409 case EvqUniform: return "uniform"; break;
410 case EvqVertexIn: return "in"; break;
411 case EvqFragmentOut: return "out"; break;
412 case EvqVertexOut: return "out"; break;
413 case EvqFragmentIn: return "in"; break;
414 case EvqIn: return "in"; break;
415 case EvqOut: return "out"; break;
416 case EvqInOut: return "inout"; break;
417 case EvqPosition: return "Position"; break;
418 case EvqPointSize: return "PointSize"; break;
419 case EvqFragCoord: return "FragCoord"; break;
420 case EvqFrontFacing: return "FrontFacing"; break;
421 case EvqFragColor: return "FragColor"; break;
422 case EvqFragData: return "FragData"; break;
423 case EvqFragDepth: return "FragDepth"; break;
424 case EvqSmoothOut: return "smooth out"; break;
425 case EvqCentroidOut: return "centroid out"; break;
426 case EvqFlatOut: return "flat out"; break;
427 case EvqSmoothIn: return "smooth in"; break;
428 case EvqCentroidIn: return "centroid in"; break;
429 case EvqFlatIn: return "flat in"; break;
430 default: return "unknown qualifier";
431 }
432 }
433
getMatrixPackingString(TLayoutMatrixPacking mpq)434 inline const char* getMatrixPackingString(TLayoutMatrixPacking mpq)
435 {
436 switch (mpq)
437 {
438 case EmpUnspecified: return "mp_unspecified";
439 case EmpRowMajor: return "row_major";
440 case EmpColumnMajor: return "column_major";
441 default: return "unknown matrix packing";
442 }
443 }
444
getBlockStorageString(TLayoutBlockStorage bsq)445 inline const char* getBlockStorageString(TLayoutBlockStorage bsq)
446 {
447 switch (bsq)
448 {
449 case EbsUnspecified: return "bs_unspecified";
450 case EbsShared: return "shared";
451 case EbsPacked: return "packed";
452 case EbsStd140: return "std140";
453 default: return "unknown block storage";
454 }
455 }
456
getInterpolationString(TQualifier q)457 inline const char* getInterpolationString(TQualifier q)
458 {
459 switch(q)
460 {
461 case EvqSmoothOut: return "smooth"; break;
462 case EvqCentroidOut: return "centroid"; break;
463 case EvqFlatOut: return "flat"; break;
464 case EvqSmoothIn: return "smooth"; break;
465 case EvqCentroidIn: return "centroid"; break;
466 case EvqFlatIn: return "flat"; break;
467 default: return "unknown interpolation";
468 }
469 }
470
471 #endif // _BASICTYPES_INCLUDED_
472