blob: 87a3dda100761a7c829da40a4aed7232421461f2 [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;
337 case EbtSampler2DRect:
338 return GL_SAMPLER_2D_RECT_ARB;
339 case EbtSampler2DArray:
340 return GL_SAMPLER_2D_ARRAY;
JiangYizhou40219322016-12-09 09:50:51 +0800341 case EbtSampler2DMS:
342 return GL_SAMPLER_2D_MULTISAMPLE;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500343 case EbtISampler2D:
344 return GL_INT_SAMPLER_2D;
345 case EbtISampler3D:
346 return GL_INT_SAMPLER_3D;
347 case EbtISamplerCube:
348 return GL_INT_SAMPLER_CUBE;
349 case EbtISampler2DArray:
350 return GL_INT_SAMPLER_2D_ARRAY;
JiangYizhou40219322016-12-09 09:50:51 +0800351 case EbtISampler2DMS:
352 return GL_INT_SAMPLER_2D_MULTISAMPLE;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500353 case EbtUSampler2D:
354 return GL_UNSIGNED_INT_SAMPLER_2D;
355 case EbtUSampler3D:
356 return GL_UNSIGNED_INT_SAMPLER_3D;
357 case EbtUSamplerCube:
358 return GL_UNSIGNED_INT_SAMPLER_CUBE;
359 case EbtUSampler2DArray:
360 return GL_UNSIGNED_INT_SAMPLER_2D_ARRAY;
JiangYizhou40219322016-12-09 09:50:51 +0800361 case EbtUSampler2DMS:
362 return GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500363 case EbtSampler2DShadow:
364 return GL_SAMPLER_2D_SHADOW;
365 case EbtSamplerCubeShadow:
366 return GL_SAMPLER_CUBE_SHADOW;
367 case EbtSampler2DArrayShadow:
368 return GL_SAMPLER_2D_ARRAY_SHADOW;
369 case EbtImage2D:
370 return GL_IMAGE_2D;
371 case EbtIImage2D:
372 return GL_INT_IMAGE_2D;
373 case EbtUImage2D:
374 return GL_UNSIGNED_INT_IMAGE_2D;
375 case EbtImage2DArray:
376 return GL_IMAGE_2D_ARRAY;
377 case EbtIImage2DArray:
378 return GL_INT_IMAGE_2D_ARRAY;
379 case EbtUImage2DArray:
380 return GL_UNSIGNED_INT_IMAGE_2D_ARRAY;
381 case EbtImage3D:
382 return GL_IMAGE_3D;
383 case EbtIImage3D:
384 return GL_INT_IMAGE_3D;
385 case EbtUImage3D:
386 return GL_UNSIGNED_INT_IMAGE_3D;
387 case EbtImageCube:
388 return GL_IMAGE_CUBE;
389 case EbtIImageCube:
390 return GL_INT_IMAGE_CUBE;
391 case EbtUImageCube:
392 return GL_UNSIGNED_INT_IMAGE_CUBE;
393 default:
394 UNREACHABLE();
Jamie Madill033dae62014-06-18 12:56:28 -0400395 }
396
397 return GL_NONE;
398}
399
400GLenum GLVariablePrecision(const TType &type)
401{
402 if (type.getBasicType() == EbtFloat)
403 {
404 switch (type.getPrecision())
405 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500406 case EbpHigh:
407 return GL_HIGH_FLOAT;
408 case EbpMedium:
409 return GL_MEDIUM_FLOAT;
410 case EbpLow:
411 return GL_LOW_FLOAT;
412 case EbpUndefined:
413 // Should be defined as the default precision by the parser
414 default:
415 UNREACHABLE();
Jamie Madill033dae62014-06-18 12:56:28 -0400416 }
417 }
418 else if (type.getBasicType() == EbtInt || type.getBasicType() == EbtUInt)
419 {
420 switch (type.getPrecision())
421 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500422 case EbpHigh:
423 return GL_HIGH_INT;
424 case EbpMedium:
425 return GL_MEDIUM_INT;
426 case EbpLow:
427 return GL_LOW_INT;
428 case EbpUndefined:
429 // Should be defined as the default precision by the parser
430 default:
431 UNREACHABLE();
Jamie Madill033dae62014-06-18 12:56:28 -0400432 }
433 }
434
435 // Other types (boolean, sampler) don't have a precision
436 return GL_NONE;
437}
438
439TString ArrayString(const TType &type)
440{
441 if (!type.isArray())
442 {
443 return "";
444 }
445
446 return "[" + str(type.getArraySize()) + "]";
447}
448
449bool IsVaryingOut(TQualifier qualifier)
450{
451 switch (qualifier)
452 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500453 case EvqVaryingOut:
454 case EvqSmoothOut:
455 case EvqFlatOut:
456 case EvqCentroidOut:
457 case EvqVertexOut:
458 return true;
Jamie Madill033dae62014-06-18 12:56:28 -0400459
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500460 default:
461 break;
Jamie Madill033dae62014-06-18 12:56:28 -0400462 }
463
464 return false;
465}
466
467bool IsVaryingIn(TQualifier qualifier)
468{
469 switch (qualifier)
470 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500471 case EvqVaryingIn:
472 case EvqSmoothIn:
473 case EvqFlatIn:
474 case EvqCentroidIn:
475 case EvqFragmentIn:
476 return true;
Jamie Madill033dae62014-06-18 12:56:28 -0400477
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500478 default:
479 break;
Jamie Madill033dae62014-06-18 12:56:28 -0400480 }
481
482 return false;
483}
484
485bool IsVarying(TQualifier qualifier)
486{
487 return IsVaryingIn(qualifier) || IsVaryingOut(qualifier);
488}
489
Jamie Madillf2575982014-06-25 16:04:54 -0400490InterpolationType GetInterpolationType(TQualifier qualifier)
Jamie Madill033dae62014-06-18 12:56:28 -0400491{
492 switch (qualifier)
493 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500494 case EvqFlatIn:
495 case EvqFlatOut:
496 return INTERPOLATION_FLAT;
Jamie Madill033dae62014-06-18 12:56:28 -0400497
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500498 case EvqSmoothIn:
499 case EvqSmoothOut:
500 case EvqVertexOut:
501 case EvqFragmentIn:
502 case EvqVaryingIn:
503 case EvqVaryingOut:
504 return INTERPOLATION_SMOOTH;
Jamie Madill033dae62014-06-18 12:56:28 -0400505
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500506 case EvqCentroidIn:
507 case EvqCentroidOut:
508 return INTERPOLATION_CENTROID;
Jamie Madill033dae62014-06-18 12:56:28 -0400509
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500510 default:
511 UNREACHABLE();
512 return INTERPOLATION_SMOOTH;
Jamie Madill033dae62014-06-18 12:56:28 -0400513 }
514}
515
Corentin Wallez509e4562016-08-25 14:55:44 -0400516TType GetShaderVariableBasicType(const sh::ShaderVariable &var)
Zhenyao Mo72111912016-07-20 17:45:56 -0700517{
Corentin Wallez509e4562016-08-25 14:55:44 -0400518 switch (var.type)
Zhenyao Mo72111912016-07-20 17:45:56 -0700519 {
Qin Jiajia7835b522016-10-08 11:20:17 +0800520 case GL_BOOL:
521 return TType(EbtBool);
522 case GL_BOOL_VEC2:
523 return TType(EbtBool, 2);
524 case GL_BOOL_VEC3:
525 return TType(EbtBool, 3);
526 case GL_BOOL_VEC4:
527 return TType(EbtBool, 4);
Zhenyao Mo72111912016-07-20 17:45:56 -0700528 case GL_FLOAT:
529 return TType(EbtFloat);
530 case GL_FLOAT_VEC2:
531 return TType(EbtFloat, 2);
532 case GL_FLOAT_VEC3:
533 return TType(EbtFloat, 3);
534 case GL_FLOAT_VEC4:
535 return TType(EbtFloat, 4);
536 case GL_FLOAT_MAT2:
537 return TType(EbtFloat, 2, 2);
538 case GL_FLOAT_MAT3:
539 return TType(EbtFloat, 3, 3);
540 case GL_FLOAT_MAT4:
541 return TType(EbtFloat, 4, 4);
542 case GL_FLOAT_MAT2x3:
543 return TType(EbtFloat, 2, 3);
544 case GL_FLOAT_MAT2x4:
545 return TType(EbtFloat, 2, 4);
546 case GL_FLOAT_MAT3x2:
547 return TType(EbtFloat, 3, 2);
548 case GL_FLOAT_MAT3x4:
549 return TType(EbtFloat, 3, 4);
550 case GL_FLOAT_MAT4x2:
551 return TType(EbtFloat, 4, 2);
552 case GL_FLOAT_MAT4x3:
553 return TType(EbtFloat, 4, 3);
554 case GL_INT:
555 return TType(EbtInt);
556 case GL_INT_VEC2:
557 return TType(EbtInt, 2);
558 case GL_INT_VEC3:
559 return TType(EbtInt, 3);
560 case GL_INT_VEC4:
561 return TType(EbtInt, 4);
562 case GL_UNSIGNED_INT:
563 return TType(EbtUInt);
564 case GL_UNSIGNED_INT_VEC2:
565 return TType(EbtUInt, 2);
566 case GL_UNSIGNED_INT_VEC3:
567 return TType(EbtUInt, 3);
568 case GL_UNSIGNED_INT_VEC4:
569 return TType(EbtUInt, 4);
570 default:
571 UNREACHABLE();
572 return TType();
573 }
574}
575
Geoff Lang156d7192016-07-21 16:11:00 -0400576TOperator TypeToConstructorOperator(const TType &type)
577{
578 switch (type.getBasicType())
579 {
580 case EbtFloat:
581 if (type.isMatrix())
582 {
583 switch (type.getCols())
584 {
585 case 2:
586 switch (type.getRows())
587 {
588 case 2:
589 return EOpConstructMat2;
590 case 3:
591 return EOpConstructMat2x3;
592 case 4:
593 return EOpConstructMat2x4;
594 default:
595 break;
596 }
597 break;
598
599 case 3:
600 switch (type.getRows())
601 {
602 case 2:
603 return EOpConstructMat3x2;
604 case 3:
605 return EOpConstructMat3;
606 case 4:
607 return EOpConstructMat3x4;
608 default:
609 break;
610 }
611 break;
612
613 case 4:
614 switch (type.getRows())
615 {
616 case 2:
617 return EOpConstructMat4x2;
618 case 3:
619 return EOpConstructMat4x3;
620 case 4:
621 return EOpConstructMat4;
622 default:
623 break;
624 }
625 break;
626 }
627 }
628 else
629 {
630 switch (type.getNominalSize())
631 {
632 case 1:
633 return EOpConstructFloat;
634 case 2:
635 return EOpConstructVec2;
636 case 3:
637 return EOpConstructVec3;
638 case 4:
639 return EOpConstructVec4;
640 default:
641 break;
642 }
643 }
644 break;
645
646 case EbtInt:
647 switch (type.getNominalSize())
648 {
649 case 1:
650 return EOpConstructInt;
651 case 2:
652 return EOpConstructIVec2;
653 case 3:
654 return EOpConstructIVec3;
655 case 4:
656 return EOpConstructIVec4;
657 default:
658 break;
659 }
660 break;
661
662 case EbtUInt:
663 switch (type.getNominalSize())
664 {
665 case 1:
666 return EOpConstructUInt;
667 case 2:
668 return EOpConstructUVec2;
669 case 3:
670 return EOpConstructUVec3;
671 case 4:
672 return EOpConstructUVec4;
673 default:
674 break;
675 }
676 break;
677
678 case EbtBool:
679 switch (type.getNominalSize())
680 {
681 case 1:
682 return EOpConstructBool;
683 case 2:
684 return EOpConstructBVec2;
685 case 3:
686 return EOpConstructBVec3;
687 case 4:
688 return EOpConstructBVec4;
689 default:
690 break;
691 }
692 break;
693
694 case EbtStruct:
695 return EOpConstructStruct;
696
697 default:
698 break;
699 }
700
701 return EOpNull;
702}
703
Martin Radev70866b82016-07-22 15:27:42 +0300704// GLSL ES 1.0.17 4.6.1 The Invariant Qualifier
705bool CanBeInvariantESSL1(TQualifier qualifier)
706{
707 return IsVaryingIn(qualifier) || IsVaryingOut(qualifier) ||
708 IsBuiltinOutputVariable(qualifier) ||
709 (IsBuiltinFragmentInputVariable(qualifier) && qualifier != EvqFrontFacing);
Jamie Madill033dae62014-06-18 12:56:28 -0400710}
Martin Radev70866b82016-07-22 15:27:42 +0300711
712// GLSL ES 3.00 Revision 6, 4.6.1 The Invariant Qualifier
713// GLSL ES 3.10 Revision 4, 4.8.1 The Invariant Qualifier
714bool CanBeInvariantESSL3OrGreater(TQualifier qualifier)
715{
716 return IsVaryingOut(qualifier) || qualifier == EvqFragmentOut ||
717 IsBuiltinOutputVariable(qualifier);
718}
719
720bool IsBuiltinOutputVariable(TQualifier qualifier)
721{
722 switch (qualifier)
723 {
724 case EvqPosition:
725 case EvqPointSize:
726 case EvqFragDepth:
727 case EvqFragDepthEXT:
728 case EvqFragColor:
729 case EvqSecondaryFragColorEXT:
730 case EvqFragData:
731 case EvqSecondaryFragDataEXT:
732 return true;
733 default:
734 break;
735 }
736 return false;
737}
738
739bool IsBuiltinFragmentInputVariable(TQualifier qualifier)
740{
741 switch (qualifier)
742 {
743 case EvqFragCoord:
744 case EvqPointCoord:
745 case EvqFrontFacing:
746 return true;
747 default:
748 break;
749 }
750 return false;
751}
752} // namespace sh