blob: 6a2f9faa89064a862a3d5c31ac31bef5f8c88405 [file] [log] [blame]
daniel@transgaming.com91ed1492010-10-29 03:11:43 +00001//
2// Copyright (c) 2010 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
Geoff Lang17732822013-08-29 13:46:49 -04007#include "compiler/translator/util.h"
daniel@transgaming.com91ed1492010-10-29 03:11:43 +00008
Zhenyao Mof1d723c2013-09-23 14:57:07 -04009#include <limits>
10
Olli Etuaho99bd5f42016-11-07 12:44:29 +000011#include "common/utilities.h"
Zhenyao Mocc4ec642013-09-23 14:57:10 -040012#include "compiler/preprocessor/numeric_lex.h"
Zhenyao Mo94ac7b72014-10-15 18:22:08 -070013#include "compiler/translator/SymbolTable.h"
Zhenyao Mof1d723c2013-09-23 14:57:07 -040014
Olli Etuahof541f522015-10-13 12:21:01 +030015bool atoi_clamp(const char *str, unsigned int *value)
Zhenyao Mof1d723c2013-09-23 14:57:07 -040016{
Zhenyao Mocc4ec642013-09-23 14:57:10 -040017 bool success = pp::numeric_lex_int(str, value);
18 if (!success)
Olli Etuahof541f522015-10-13 12:21:01 +030019 *value = std::numeric_limits<unsigned int>::max();
Zhenyao Mocc4ec642013-09-23 14:57:10 -040020 return success;
Zhenyao Mof1d723c2013-09-23 14:57:07 -040021}
22
Jamie Madill033dae62014-06-18 12:56:28 -040023namespace sh
24{
25
Olli Etuaho99bd5f42016-11-07 12:44:29 +000026float NumericLexFloat32OutOfRangeToInfinity(const std::string &str)
27{
28 // Parses a decimal string using scientific notation into a floating point number.
29 // Out-of-range values are converted to infinity. Values that are too small to be
30 // represented are converted to zero.
31
32 // The mantissa in decimal scientific notation. The magnitude of the mantissa integer does not
33 // matter.
34 unsigned int decimalMantissa = 0;
35 size_t i = 0;
36 bool decimalPointSeen = false;
37 bool nonZeroSeenInMantissa = false;
38
39 // The exponent offset reflects the position of the decimal point.
40 int exponentOffset = -1;
41 while (i < str.length())
42 {
43 const char c = str[i];
44 if (c == 'e' || c == 'E')
45 {
46 break;
47 }
48 if (c == '.')
49 {
50 decimalPointSeen = true;
51 ++i;
52 continue;
53 }
54
55 unsigned int digit = static_cast<unsigned int>(c - '0');
56 ASSERT(digit < 10u);
57 if (digit != 0u)
58 {
59 nonZeroSeenInMantissa = true;
60 }
61 if (nonZeroSeenInMantissa)
62 {
63 // Add bits to the mantissa until space runs out in 32-bit int. This should be
64 // enough precision to make the resulting binary mantissa accurate to 1 ULP.
65 if (decimalMantissa <= (std::numeric_limits<unsigned int>::max() - 9u) / 10u)
66 {
67 decimalMantissa = decimalMantissa * 10u + digit;
68 }
69 if (!decimalPointSeen)
70 {
71 ++exponentOffset;
72 }
73 }
74 else if (decimalPointSeen)
75 {
76 --exponentOffset;
77 }
78 ++i;
79 }
80 if (decimalMantissa == 0)
81 {
82 return 0.0f;
83 }
84 int exponent = 0;
85 if (i < str.length())
86 {
87 ASSERT(str[i] == 'e' || str[i] == 'E');
88 ++i;
89 bool exponentOutOfRange = false;
90 bool negativeExponent = false;
91 if (str[i] == '-')
92 {
93 negativeExponent = true;
94 ++i;
95 }
96 else if (str[i] == '+')
97 {
98 ++i;
99 }
100 while (i < str.length())
101 {
102 const char c = str[i];
103 unsigned int digit = static_cast<unsigned int>(c - '0');
104 ASSERT(digit < 10u);
105 if (exponent <= (std::numeric_limits<int>::max() - 9) / 10)
106 {
107 exponent = exponent * 10 + digit;
108 }
109 else
110 {
111 exponentOutOfRange = true;
112 }
113 ++i;
114 }
115 if (negativeExponent)
116 {
117 exponent = -exponent;
118 }
119 if (exponentOutOfRange)
120 {
121 if (negativeExponent)
122 {
123 return 0.0f;
124 }
125 else
126 {
127 return std::numeric_limits<float>::infinity();
128 }
129 }
130 }
131 // Do the calculation in 64-bit to avoid overflow.
132 long long exponentLong =
133 static_cast<long long>(exponent) + static_cast<long long>(exponentOffset);
134 if (exponentLong > std::numeric_limits<float>::max_exponent10)
135 {
136 return std::numeric_limits<float>::infinity();
137 }
138 else if (exponentLong < std::numeric_limits<float>::min_exponent10)
139 {
140 return 0.0f;
141 }
142 // The exponent is in range, so we need to actually evaluate the float.
143 exponent = static_cast<int>(exponentLong);
144 double value = decimalMantissa;
145
146 // Calculate the exponent offset to normalize the mantissa.
147 int normalizationExponentOffset = 0;
148 while (decimalMantissa >= 10u)
149 {
150 --normalizationExponentOffset;
151 decimalMantissa /= 10u;
152 }
153 // Apply the exponent.
154 value *= std::pow(10.0, static_cast<double>(exponent + normalizationExponentOffset));
155 if (value > static_cast<double>(std::numeric_limits<float>::max()))
156 {
157 return std::numeric_limits<float>::infinity();
158 }
159 if (value < static_cast<double>(std::numeric_limits<float>::min()))
160 {
161 return 0.0f;
162 }
163 return static_cast<float>(value);
164}
165
166bool strtof_clamp(const std::string &str, float *value)
167{
168 // Try the standard float parsing path first.
169 bool success = pp::numeric_lex_float(str, value);
170
171 // If the standard path doesn't succeed, take the path that can handle the following corner
172 // cases:
173 // 1. The decimal mantissa is very small but the exponent is very large, putting the resulting
174 // number inside the float range.
175 // 2. The decimal mantissa is very large but the exponent is very small, putting the resulting
176 // number inside the float range.
177 // 3. The value is out-of-range and should be evaluated as infinity.
178 // 4. The value is too small and should be evaluated as zero.
179 // See ESSL 3.00.6 section 4.1.4 for the relevant specification.
180 if (!success)
181 *value = NumericLexFloat32OutOfRangeToInfinity(str);
182 return !gl::isInf(*value);
183}
184
Jamie Madill033dae62014-06-18 12:56:28 -0400185GLenum GLVariableType(const TType &type)
186{
187 if (type.getBasicType() == EbtFloat)
188 {
189 if (type.isScalar())
190 {
191 return GL_FLOAT;
192 }
193 else if (type.isVector())
194 {
195 switch (type.getNominalSize())
196 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500197 case 2:
198 return GL_FLOAT_VEC2;
199 case 3:
200 return GL_FLOAT_VEC3;
201 case 4:
202 return GL_FLOAT_VEC4;
203 default:
204 UNREACHABLE();
Jamie Madill033dae62014-06-18 12:56:28 -0400205 }
206 }
207 else if (type.isMatrix())
208 {
209 switch (type.getCols())
210 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500211 case 2:
212 switch (type.getRows())
213 {
214 case 2:
215 return GL_FLOAT_MAT2;
216 case 3:
217 return GL_FLOAT_MAT2x3;
218 case 4:
219 return GL_FLOAT_MAT2x4;
220 default:
221 UNREACHABLE();
222 }
Jamie Madill033dae62014-06-18 12:56:28 -0400223
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500224 case 3:
225 switch (type.getRows())
226 {
227 case 2:
228 return GL_FLOAT_MAT3x2;
229 case 3:
230 return GL_FLOAT_MAT3;
231 case 4:
232 return GL_FLOAT_MAT3x4;
233 default:
234 UNREACHABLE();
235 }
Jamie Madill033dae62014-06-18 12:56:28 -0400236
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500237 case 4:
238 switch (type.getRows())
239 {
240 case 2:
241 return GL_FLOAT_MAT4x2;
242 case 3:
243 return GL_FLOAT_MAT4x3;
244 case 4:
245 return GL_FLOAT_MAT4;
246 default:
247 UNREACHABLE();
248 }
Jamie Madill033dae62014-06-18 12:56:28 -0400249
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500250 default:
251 UNREACHABLE();
Jamie Madill033dae62014-06-18 12:56:28 -0400252 }
253 }
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500254 else
255 UNREACHABLE();
Jamie Madill033dae62014-06-18 12:56:28 -0400256 }
257 else if (type.getBasicType() == EbtInt)
258 {
259 if (type.isScalar())
260 {
261 return GL_INT;
262 }
263 else if (type.isVector())
264 {
265 switch (type.getNominalSize())
266 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500267 case 2:
268 return GL_INT_VEC2;
269 case 3:
270 return GL_INT_VEC3;
271 case 4:
272 return GL_INT_VEC4;
273 default:
274 UNREACHABLE();
Jamie Madill033dae62014-06-18 12:56:28 -0400275 }
276 }
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500277 else
278 UNREACHABLE();
Jamie Madill033dae62014-06-18 12:56:28 -0400279 }
280 else if (type.getBasicType() == EbtUInt)
281 {
282 if (type.isScalar())
283 {
284 return GL_UNSIGNED_INT;
285 }
286 else if (type.isVector())
287 {
288 switch (type.getNominalSize())
289 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500290 case 2:
291 return GL_UNSIGNED_INT_VEC2;
292 case 3:
293 return GL_UNSIGNED_INT_VEC3;
294 case 4:
295 return GL_UNSIGNED_INT_VEC4;
296 default:
297 UNREACHABLE();
Jamie Madill033dae62014-06-18 12:56:28 -0400298 }
299 }
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500300 else
301 UNREACHABLE();
Jamie Madill033dae62014-06-18 12:56:28 -0400302 }
303 else if (type.getBasicType() == EbtBool)
304 {
305 if (type.isScalar())
306 {
307 return GL_BOOL;
308 }
309 else if (type.isVector())
310 {
311 switch (type.getNominalSize())
312 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500313 case 2:
314 return GL_BOOL_VEC2;
315 case 3:
316 return GL_BOOL_VEC3;
317 case 4:
318 return GL_BOOL_VEC4;
319 default:
320 UNREACHABLE();
Jamie Madill033dae62014-06-18 12:56:28 -0400321 }
322 }
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500323 else
324 UNREACHABLE();
Jamie Madill033dae62014-06-18 12:56:28 -0400325 }
326
327 switch (type.getBasicType())
328 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500329 case EbtSampler2D:
330 return GL_SAMPLER_2D;
331 case EbtSampler3D:
332 return GL_SAMPLER_3D;
333 case EbtSamplerCube:
334 return GL_SAMPLER_CUBE;
335 case EbtSamplerExternalOES:
336 return GL_SAMPLER_EXTERNAL_OES;
Andrei Volykhina5527072017-03-22 16:46:30 +0300337 case EbtSamplerExternal2DY2YEXT:
338 return GL_SAMPLER_EXTERNAL_2D_Y2Y_EXT;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500339 case EbtSampler2DRect:
340 return GL_SAMPLER_2D_RECT_ARB;
341 case EbtSampler2DArray:
342 return GL_SAMPLER_2D_ARRAY;
JiangYizhou40219322016-12-09 09:50:51 +0800343 case EbtSampler2DMS:
344 return GL_SAMPLER_2D_MULTISAMPLE;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500345 case EbtISampler2D:
346 return GL_INT_SAMPLER_2D;
347 case EbtISampler3D:
348 return GL_INT_SAMPLER_3D;
349 case EbtISamplerCube:
350 return GL_INT_SAMPLER_CUBE;
351 case EbtISampler2DArray:
352 return GL_INT_SAMPLER_2D_ARRAY;
JiangYizhou40219322016-12-09 09:50:51 +0800353 case EbtISampler2DMS:
354 return GL_INT_SAMPLER_2D_MULTISAMPLE;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500355 case EbtUSampler2D:
356 return GL_UNSIGNED_INT_SAMPLER_2D;
357 case EbtUSampler3D:
358 return GL_UNSIGNED_INT_SAMPLER_3D;
359 case EbtUSamplerCube:
360 return GL_UNSIGNED_INT_SAMPLER_CUBE;
361 case EbtUSampler2DArray:
362 return GL_UNSIGNED_INT_SAMPLER_2D_ARRAY;
JiangYizhou40219322016-12-09 09:50:51 +0800363 case EbtUSampler2DMS:
364 return GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500365 case EbtSampler2DShadow:
366 return GL_SAMPLER_2D_SHADOW;
367 case EbtSamplerCubeShadow:
368 return GL_SAMPLER_CUBE_SHADOW;
369 case EbtSampler2DArrayShadow:
370 return GL_SAMPLER_2D_ARRAY_SHADOW;
371 case EbtImage2D:
372 return GL_IMAGE_2D;
373 case EbtIImage2D:
374 return GL_INT_IMAGE_2D;
375 case EbtUImage2D:
376 return GL_UNSIGNED_INT_IMAGE_2D;
377 case EbtImage2DArray:
378 return GL_IMAGE_2D_ARRAY;
379 case EbtIImage2DArray:
380 return GL_INT_IMAGE_2D_ARRAY;
381 case EbtUImage2DArray:
382 return GL_UNSIGNED_INT_IMAGE_2D_ARRAY;
383 case EbtImage3D:
384 return GL_IMAGE_3D;
385 case EbtIImage3D:
386 return GL_INT_IMAGE_3D;
387 case EbtUImage3D:
388 return GL_UNSIGNED_INT_IMAGE_3D;
389 case EbtImageCube:
390 return GL_IMAGE_CUBE;
391 case EbtIImageCube:
392 return GL_INT_IMAGE_CUBE;
393 case EbtUImageCube:
394 return GL_UNSIGNED_INT_IMAGE_CUBE;
395 default:
396 UNREACHABLE();
Jamie Madill033dae62014-06-18 12:56:28 -0400397 }
398
399 return GL_NONE;
400}
401
402GLenum GLVariablePrecision(const TType &type)
403{
404 if (type.getBasicType() == EbtFloat)
405 {
406 switch (type.getPrecision())
407 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500408 case EbpHigh:
409 return GL_HIGH_FLOAT;
410 case EbpMedium:
411 return GL_MEDIUM_FLOAT;
412 case EbpLow:
413 return GL_LOW_FLOAT;
414 case EbpUndefined:
415 // Should be defined as the default precision by the parser
416 default:
417 UNREACHABLE();
Jamie Madill033dae62014-06-18 12:56:28 -0400418 }
419 }
420 else if (type.getBasicType() == EbtInt || type.getBasicType() == EbtUInt)
421 {
422 switch (type.getPrecision())
423 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500424 case EbpHigh:
425 return GL_HIGH_INT;
426 case EbpMedium:
427 return GL_MEDIUM_INT;
428 case EbpLow:
429 return GL_LOW_INT;
430 case EbpUndefined:
431 // Should be defined as the default precision by the parser
432 default:
433 UNREACHABLE();
Jamie Madill033dae62014-06-18 12:56:28 -0400434 }
435 }
436
437 // Other types (boolean, sampler) don't have a precision
438 return GL_NONE;
439}
440
441TString ArrayString(const TType &type)
442{
443 if (!type.isArray())
444 {
445 return "";
446 }
447
448 return "[" + str(type.getArraySize()) + "]";
449}
450
451bool IsVaryingOut(TQualifier qualifier)
452{
453 switch (qualifier)
454 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500455 case EvqVaryingOut:
456 case EvqSmoothOut:
457 case EvqFlatOut:
458 case EvqCentroidOut:
459 case EvqVertexOut:
460 return true;
Jamie Madill033dae62014-06-18 12:56:28 -0400461
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500462 default:
463 break;
Jamie Madill033dae62014-06-18 12:56:28 -0400464 }
465
466 return false;
467}
468
469bool IsVaryingIn(TQualifier qualifier)
470{
471 switch (qualifier)
472 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500473 case EvqVaryingIn:
474 case EvqSmoothIn:
475 case EvqFlatIn:
476 case EvqCentroidIn:
477 case EvqFragmentIn:
478 return true;
Jamie Madill033dae62014-06-18 12:56:28 -0400479
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500480 default:
481 break;
Jamie Madill033dae62014-06-18 12:56:28 -0400482 }
483
484 return false;
485}
486
487bool IsVarying(TQualifier qualifier)
488{
489 return IsVaryingIn(qualifier) || IsVaryingOut(qualifier);
490}
491
Jamie Madillf2575982014-06-25 16:04:54 -0400492InterpolationType GetInterpolationType(TQualifier qualifier)
Jamie Madill033dae62014-06-18 12:56:28 -0400493{
494 switch (qualifier)
495 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500496 case EvqFlatIn:
497 case EvqFlatOut:
498 return INTERPOLATION_FLAT;
Jamie Madill033dae62014-06-18 12:56:28 -0400499
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500500 case EvqSmoothIn:
501 case EvqSmoothOut:
502 case EvqVertexOut:
503 case EvqFragmentIn:
504 case EvqVaryingIn:
505 case EvqVaryingOut:
506 return INTERPOLATION_SMOOTH;
Jamie Madill033dae62014-06-18 12:56:28 -0400507
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500508 case EvqCentroidIn:
509 case EvqCentroidOut:
510 return INTERPOLATION_CENTROID;
Jamie Madill033dae62014-06-18 12:56:28 -0400511
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500512 default:
513 UNREACHABLE();
514 return INTERPOLATION_SMOOTH;
Jamie Madill033dae62014-06-18 12:56:28 -0400515 }
516}
517
Corentin Wallez509e4562016-08-25 14:55:44 -0400518TType GetShaderVariableBasicType(const sh::ShaderVariable &var)
Zhenyao Mo72111912016-07-20 17:45:56 -0700519{
Corentin Wallez509e4562016-08-25 14:55:44 -0400520 switch (var.type)
Zhenyao Mo72111912016-07-20 17:45:56 -0700521 {
Qin Jiajia7835b522016-10-08 11:20:17 +0800522 case GL_BOOL:
523 return TType(EbtBool);
524 case GL_BOOL_VEC2:
525 return TType(EbtBool, 2);
526 case GL_BOOL_VEC3:
527 return TType(EbtBool, 3);
528 case GL_BOOL_VEC4:
529 return TType(EbtBool, 4);
Zhenyao Mo72111912016-07-20 17:45:56 -0700530 case GL_FLOAT:
531 return TType(EbtFloat);
532 case GL_FLOAT_VEC2:
533 return TType(EbtFloat, 2);
534 case GL_FLOAT_VEC3:
535 return TType(EbtFloat, 3);
536 case GL_FLOAT_VEC4:
537 return TType(EbtFloat, 4);
538 case GL_FLOAT_MAT2:
539 return TType(EbtFloat, 2, 2);
540 case GL_FLOAT_MAT3:
541 return TType(EbtFloat, 3, 3);
542 case GL_FLOAT_MAT4:
543 return TType(EbtFloat, 4, 4);
544 case GL_FLOAT_MAT2x3:
545 return TType(EbtFloat, 2, 3);
546 case GL_FLOAT_MAT2x4:
547 return TType(EbtFloat, 2, 4);
548 case GL_FLOAT_MAT3x2:
549 return TType(EbtFloat, 3, 2);
550 case GL_FLOAT_MAT3x4:
551 return TType(EbtFloat, 3, 4);
552 case GL_FLOAT_MAT4x2:
553 return TType(EbtFloat, 4, 2);
554 case GL_FLOAT_MAT4x3:
555 return TType(EbtFloat, 4, 3);
556 case GL_INT:
557 return TType(EbtInt);
558 case GL_INT_VEC2:
559 return TType(EbtInt, 2);
560 case GL_INT_VEC3:
561 return TType(EbtInt, 3);
562 case GL_INT_VEC4:
563 return TType(EbtInt, 4);
564 case GL_UNSIGNED_INT:
565 return TType(EbtUInt);
566 case GL_UNSIGNED_INT_VEC2:
567 return TType(EbtUInt, 2);
568 case GL_UNSIGNED_INT_VEC3:
569 return TType(EbtUInt, 3);
570 case GL_UNSIGNED_INT_VEC4:
571 return TType(EbtUInt, 4);
572 default:
573 UNREACHABLE();
574 return TType();
575 }
576}
577
Geoff Lang156d7192016-07-21 16:11:00 -0400578TOperator TypeToConstructorOperator(const TType &type)
579{
580 switch (type.getBasicType())
581 {
582 case EbtFloat:
583 if (type.isMatrix())
584 {
585 switch (type.getCols())
586 {
587 case 2:
588 switch (type.getRows())
589 {
590 case 2:
591 return EOpConstructMat2;
592 case 3:
593 return EOpConstructMat2x3;
594 case 4:
595 return EOpConstructMat2x4;
596 default:
597 break;
598 }
599 break;
600
601 case 3:
602 switch (type.getRows())
603 {
604 case 2:
605 return EOpConstructMat3x2;
606 case 3:
607 return EOpConstructMat3;
608 case 4:
609 return EOpConstructMat3x4;
610 default:
611 break;
612 }
613 break;
614
615 case 4:
616 switch (type.getRows())
617 {
618 case 2:
619 return EOpConstructMat4x2;
620 case 3:
621 return EOpConstructMat4x3;
622 case 4:
623 return EOpConstructMat4;
624 default:
625 break;
626 }
627 break;
628 }
629 }
630 else
631 {
632 switch (type.getNominalSize())
633 {
634 case 1:
635 return EOpConstructFloat;
636 case 2:
637 return EOpConstructVec2;
638 case 3:
639 return EOpConstructVec3;
640 case 4:
641 return EOpConstructVec4;
642 default:
643 break;
644 }
645 }
646 break;
647
648 case EbtInt:
649 switch (type.getNominalSize())
650 {
651 case 1:
652 return EOpConstructInt;
653 case 2:
654 return EOpConstructIVec2;
655 case 3:
656 return EOpConstructIVec3;
657 case 4:
658 return EOpConstructIVec4;
659 default:
660 break;
661 }
662 break;
663
664 case EbtUInt:
665 switch (type.getNominalSize())
666 {
667 case 1:
668 return EOpConstructUInt;
669 case 2:
670 return EOpConstructUVec2;
671 case 3:
672 return EOpConstructUVec3;
673 case 4:
674 return EOpConstructUVec4;
675 default:
676 break;
677 }
678 break;
679
680 case EbtBool:
681 switch (type.getNominalSize())
682 {
683 case 1:
684 return EOpConstructBool;
685 case 2:
686 return EOpConstructBVec2;
687 case 3:
688 return EOpConstructBVec3;
689 case 4:
690 return EOpConstructBVec4;
691 default:
692 break;
693 }
694 break;
695
696 case EbtStruct:
697 return EOpConstructStruct;
698
699 default:
700 break;
701 }
702
703 return EOpNull;
704}
705
Martin Radev70866b82016-07-22 15:27:42 +0300706// GLSL ES 1.0.17 4.6.1 The Invariant Qualifier
707bool CanBeInvariantESSL1(TQualifier qualifier)
708{
709 return IsVaryingIn(qualifier) || IsVaryingOut(qualifier) ||
710 IsBuiltinOutputVariable(qualifier) ||
711 (IsBuiltinFragmentInputVariable(qualifier) && qualifier != EvqFrontFacing);
Jamie Madill033dae62014-06-18 12:56:28 -0400712}
Martin Radev70866b82016-07-22 15:27:42 +0300713
714// GLSL ES 3.00 Revision 6, 4.6.1 The Invariant Qualifier
715// GLSL ES 3.10 Revision 4, 4.8.1 The Invariant Qualifier
716bool CanBeInvariantESSL3OrGreater(TQualifier qualifier)
717{
718 return IsVaryingOut(qualifier) || qualifier == EvqFragmentOut ||
719 IsBuiltinOutputVariable(qualifier);
720}
721
722bool IsBuiltinOutputVariable(TQualifier qualifier)
723{
724 switch (qualifier)
725 {
726 case EvqPosition:
727 case EvqPointSize:
728 case EvqFragDepth:
729 case EvqFragDepthEXT:
730 case EvqFragColor:
731 case EvqSecondaryFragColorEXT:
732 case EvqFragData:
733 case EvqSecondaryFragDataEXT:
734 return true;
735 default:
736 break;
737 }
738 return false;
739}
740
741bool IsBuiltinFragmentInputVariable(TQualifier qualifier)
742{
743 switch (qualifier)
744 {
745 case EvqFragCoord:
746 case EvqPointCoord:
747 case EvqFrontFacing:
748 return true;
749 default:
750 break;
751 }
752 return false;
753}
754} // namespace sh