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