1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 #ifndef _BASICTYPES_INCLUDED_
16 #define _BASICTYPES_INCLUDED_
21 // Precision qualifiers
23 enum TPrecision : unsigned char
25 // These need to be kept sorted
32 inline const char *getPrecisionString(TPrecision precision)
36 case EbpHigh: return "highp"; break;
37 case EbpMedium: return "mediump"; break;
38 case EbpLow: return "lowp"; break;
39 default: return "mediump"; break; // Safest fallback
44 // Basic type. Arrays, vectors, etc., are orthogonal to this.
46 enum TBasicType : unsigned char
53 EbtGVec4, // non type: represents vec4, ivec4, and uvec4
54 EbtGenType, // non type: represents float, vec2, vec3, and vec4
55 EbtGenIType, // non type: represents int, ivec2, ivec3, and ivec4
56 EbtGenUType, // non type: represents uint, uvec2, uvec3, and uvec4
57 EbtGenBType, // non type: represents bool, bvec2, bvec3, and bvec4
58 EbtVec, // non type: represents vec2, vec3, and vec4
59 EbtIVec, // non type: represents ivec2, ivec3, and ivec4
60 EbtUVec, // non type: represents uvec2, uvec3, and uvec4
61 EbtBVec, // non type: represents bvec2, bvec3, and bvec4
62 EbtGuardSamplerBegin, // non type: see implementation of IsSampler()
67 EbtSamplerExternalOES, // Only valid if OES_EGL_image_external exists.
78 EbtSampler2DArrayShadow,
79 EbtGuardSamplerEnd, // non type: see implementation of IsSampler()
80 EbtGSampler2D, // non type: represents sampler2D, isampler2D, and usampler2D
81 EbtGSampler3D, // non type: represents sampler3D, isampler3D, and usampler3D
82 EbtGSamplerCube, // non type: represents samplerCube, isamplerCube, and usamplerCube
83 EbtGSampler2DArray, // non type: represents sampler2DArray, isampler2DArray, and usampler2DArray
86 EbtAddress, // should be deprecated??
87 EbtInvariant // used as a type when qualifying a previously declared variable as being invariant
90 enum TLayoutMatrixPacking
97 enum TLayoutBlockStorage
105 inline const char *getBasicString(TBasicType type)
109 case EbtVoid: return "void";
110 case EbtFloat: return "float";
111 case EbtInt: return "int";
112 case EbtUInt: return "uint";
113 case EbtBool: return "bool";
114 case EbtSampler2D: return "sampler2D";
115 case EbtSamplerCube: return "samplerCube";
116 case EbtSamplerExternalOES: return "samplerExternalOES";
117 case EbtSampler3D: return "sampler3D";
118 case EbtStruct: return "structure";
119 default: UNREACHABLE(type); return "unknown type";
123 inline const char* getMatrixPackingString(TLayoutMatrixPacking mpq)
127 case EmpUnspecified: return "mp_unspecified";
128 case EmpRowMajor: return "row_major";
129 case EmpColumnMajor: return "column_major";
130 default: UNREACHABLE(mpq); return "unknown matrix packing";
134 inline const char* getBlockStorageString(TLayoutBlockStorage bsq)
138 case EbsUnspecified: return "bs_unspecified";
139 case EbsShared: return "shared";
140 case EbsPacked: return "packed";
141 case EbsStd140: return "std140";
142 default: UNREACHABLE(bsq); return "unknown block storage";
146 inline bool IsSampler(TBasicType type)
148 return type > EbtGuardSamplerBegin && type < EbtGuardSamplerEnd;
151 inline bool IsIntegerSampler(TBasicType type)
157 case EbtISamplerCube:
158 case EbtISampler2DArray:
161 case EbtUSamplerCube:
162 case EbtUSampler2DArray:
167 case EbtSamplerExternalOES:
168 case EbtSampler2DArray:
169 case EbtSampler2DShadow:
170 case EbtSamplerCubeShadow:
171 case EbtSampler2DArrayShadow:
174 assert(!IsSampler(type));
180 inline bool IsSampler2D(TBasicType type)
187 case EbtSampler2DArray:
188 case EbtISampler2DArray:
189 case EbtUSampler2DArray:
190 case EbtSamplerExternalOES:
191 case EbtSampler2DShadow:
192 case EbtSampler2DArrayShadow:
197 case EbtISamplerCube:
198 case EbtUSamplerCube:
200 case EbtSamplerCubeShadow:
203 assert(!IsSampler(type));
209 inline bool IsSamplerCube(TBasicType type)
214 case EbtISamplerCube:
215 case EbtUSamplerCube:
216 case EbtSamplerCubeShadow:
220 case EbtSamplerExternalOES:
221 case EbtSampler2DArray:
224 case EbtISampler2DArray:
227 case EbtUSampler2DArray:
228 case EbtSampler2DShadow:
229 case EbtSampler2DArrayShadow:
232 assert(!IsSampler(type));
238 inline bool IsSampler3D(TBasicType type)
248 case EbtSamplerExternalOES:
249 case EbtSampler2DArray:
251 case EbtISamplerCube:
252 case EbtISampler2DArray:
254 case EbtUSamplerCube:
255 case EbtUSampler2DArray:
256 case EbtSampler2DShadow:
257 case EbtSamplerCubeShadow:
258 case EbtSampler2DArrayShadow:
261 assert(!IsSampler(type));
267 inline bool IsSamplerArray(TBasicType type)
271 case EbtSampler2DArray:
272 case EbtISampler2DArray:
273 case EbtUSampler2DArray:
274 case EbtSampler2DArrayShadow:
279 case EbtSamplerExternalOES:
283 case EbtISamplerCube:
284 case EbtUSamplerCube:
286 case EbtSampler2DShadow:
287 case EbtSamplerCubeShadow:
290 assert(!IsSampler(type));
296 inline bool IsShadowSampler(TBasicType type)
300 case EbtSampler2DShadow:
301 case EbtSamplerCubeShadow:
302 case EbtSampler2DArrayShadow:
306 case EbtISamplerCube:
307 case EbtISampler2DArray:
310 case EbtUSamplerCube:
311 case EbtUSampler2DArray:
315 case EbtSamplerExternalOES:
316 case EbtSampler2DArray:
319 assert(!IsSampler(type));
325 inline bool IsInteger(TBasicType type)
327 return type == EbtInt || type == EbtUInt;
330 inline bool SupportsPrecision(TBasicType type)
332 return type == EbtFloat || type == EbtInt || type == EbtUInt || IsSampler(type);
336 // Qualifiers and built-ins. These are mainly used to see what can be read
337 // or written, and by the machine dependent translator to know which registers
338 // to allocate variables in. Since built-ins tend to go to different registers
339 // than varying or uniform, it makes sense they are peers, not sub-classes.
341 enum TQualifier : unsigned char
343 EvqTemporary, // For temporaries (within a function), read/write
344 EvqGlobal, // For globals read/write
345 EvqConstExpr, // User defined constants
346 EvqAttribute, // Readonly
347 EvqVaryingIn, // readonly, fragment shaders only
348 EvqVaryingOut, // vertex shaders only read/write
349 EvqInvariantVaryingIn, // readonly, fragment shaders only
350 EvqInvariantVaryingOut, // vertex shaders only read/write
351 EvqUniform, // Readonly, vertex and fragment
353 EvqVertexIn, // Vertex shader input
354 EvqFragmentOut, // Fragment shader output
355 EvqVertexOut, // Vertex shader output
356 EvqFragmentIn, // Fragment shader input
358 // pack/unpack input and output
368 // built-ins written by vertex shader
373 // built-ins read by fragment shader
378 // built-ins written by fragment shader
383 // GLSL ES 3.0 vertex output and fragment input
384 EvqSmooth, // Incomplete qualifier, smooth is the default
385 EvqFlat, // Incomplete qualifier
386 EvqSmoothOut = EvqSmooth,
387 EvqFlatOut = EvqFlat,
388 EvqCentroidOut, // Implies smooth
391 EvqCentroidIn, // Implies smooth
397 struct TLayoutQualifier
399 static TLayoutQualifier create()
401 TLayoutQualifier layoutQualifier;
403 layoutQualifier.location = -1;
404 layoutQualifier.matrixPacking = EmpUnspecified;
405 layoutQualifier.blockStorage = EbsUnspecified;
407 return layoutQualifier;
412 return location == -1 && matrixPacking == EmpUnspecified && blockStorage == EbsUnspecified;
416 TLayoutMatrixPacking matrixPacking;
417 TLayoutBlockStorage blockStorage;
421 // This is just for debug print out, carried along with the definitions above.
423 inline const char *getQualifierString(TQualifier qualifier)
427 case EvqTemporary: return "Temporary"; break;
428 case EvqGlobal: return "Global"; break;
429 case EvqConstExpr: return "const"; break;
430 case EvqConstReadOnly: return "const"; break;
431 case EvqAttribute: return "attribute"; break;
432 case EvqVaryingIn: return "varying"; break;
433 case EvqVaryingOut: return "varying"; break;
434 case EvqInvariantVaryingIn: return "invariant varying"; break;
435 case EvqInvariantVaryingOut:return "invariant varying"; break;
436 case EvqUniform: return "uniform"; break;
437 case EvqVertexIn: return "in"; break;
438 case EvqFragmentOut: return "out"; break;
439 case EvqVertexOut: return "out"; break;
440 case EvqFragmentIn: return "in"; break;
441 case EvqIn: return "in"; break;
442 case EvqOut: return "out"; break;
443 case EvqInOut: return "inout"; break;
444 case EvqInput: return "input"; break;
445 case EvqOutput: return "output"; break;
446 case EvqPosition: return "Position"; break;
447 case EvqPointSize: return "PointSize"; break;
448 case EvqInstanceID: return "InstanceID"; break;
449 case EvqFragCoord: return "FragCoord"; break;
450 case EvqFrontFacing: return "FrontFacing"; break;
451 case EvqFragColor: return "FragColor"; break;
452 case EvqFragData: return "FragData"; break;
453 case EvqFragDepth: return "FragDepth"; break;
454 case EvqSmooth: return "Smooth"; break;
455 case EvqFlat: return "Flat"; break;
456 case EvqCentroidOut: return "CentroidOut"; break;
457 case EvqSmoothIn: return "SmoothIn"; break;
458 case EvqFlatIn: return "FlatIn"; break;
459 case EvqCentroidIn: return "CentroidIn"; break;
460 default: UNREACHABLE(qualifier); return "unknown qualifier";
464 #endif // _BASICTYPES_INCLUDED_