1 //
2 // Copyright 2002 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 <algorithm>
11 #include <array>
12
13 #include "GLSLANG/ShaderLang.h"
14 #include "common/debug.h"
15 #include "compiler/translator/ImmutableString.h"
16
17 namespace sh
18 {
19
20 //
21 // Precision qualifiers
22 //
23 enum TPrecision
24 {
25 // These need to be kept sorted
26 EbpUndefined,
27 EbpLow,
28 EbpMedium,
29 EbpHigh,
30
31 // end of list
32 EbpLast
33 };
34
getPrecisionString(TPrecision p)35 inline const char *getPrecisionString(TPrecision p)
36 {
37 switch (p)
38 {
39 case EbpHigh:
40 return "highp";
41 case EbpMedium:
42 return "mediump";
43 case EbpLow:
44 return "lowp";
45 default:
46 return "mediump"; // Safest fallback
47 }
48 }
49
50 //
51 // Basic type. Arrays, vectors, etc., are orthogonal to this.
52 //
53 enum TBasicType
54 {
55 EbtVoid,
56 EbtFloat,
57 EbtDouble,
58 EbtInt,
59 EbtUInt,
60 EbtBool,
61
62 EbtAtomicCounter,
63 EbtYuvCscStandardEXT, // Only valid if EXT_YUV_target exists.
64
65 EbtGuardSamplerBegin, // non type: see implementation of IsSampler()
66 EbtSampler2D = EbtGuardSamplerBegin,
67 EbtSampler3D,
68 EbtSamplerCube,
69 EbtSampler2DArray,
70 EbtSamplerExternalOES, // Only valid if OES_EGL_image_external exists.
71 EbtSamplerExternal2DY2YEXT, // Only valid if GL_EXT_YUV_target exists.
72 EbtSampler2DRect, // Only valid if GL_ARB_texture_rectangle exists.
73 EbtSampler2DMS,
74 EbtSampler2DMSArray,
75 EbtISampler2D,
76 EbtISampler3D,
77 EbtISamplerCube,
78 EbtISampler2DArray,
79 EbtISampler2DMS,
80 EbtISampler2DMSArray,
81 EbtUSampler2D,
82 EbtUSampler3D,
83 EbtUSamplerCube,
84 EbtUSampler2DArray,
85 EbtUSampler2DMS,
86 EbtUSampler2DMSArray,
87 EbtSampler2DShadow,
88 EbtSamplerCubeShadow,
89 EbtSampler2DArrayShadow,
90 EbtSampler1D, // Desktop GLSL sampler types
91 EbtSampler1DArray,
92 EbtSampler1DArrayShadow,
93 EbtSamplerBuffer,
94 EbtSamplerCubeArray,
95 EbtSamplerCubeArrayShadow,
96 EbtSampler1DShadow,
97 EbtSampler2DRectShadow,
98 EbtISampler1D,
99 EbtISampler1DArray,
100 EbtISampler2DRect,
101 EbtISamplerBuffer,
102 EbtISamplerCubeArray,
103 EbtUSampler1D,
104 EbtUSampler1DArray,
105 EbtUSampler2DRect,
106 EbtUSamplerBuffer,
107 EbtUSamplerCubeArray,
108 EbtSamplerVideoWEBGL,
109 EbtGuardSamplerEnd = EbtSamplerVideoWEBGL, // non type: see implementation of IsSampler()
110
111 // images
112 EbtGuardImageBegin,
113 EbtImage2D = EbtGuardImageBegin,
114 EbtImage3D,
115 EbtImage2DArray,
116 EbtImageCube,
117 EbtImage1D,
118 EbtImage1DArray,
119 EbtImage2DMS,
120 EbtImage2DMSArray,
121 EbtImageCubeArray,
122 EbtImageRect,
123 EbtImageBuffer,
124 EbtIImage2D,
125 EbtIImage3D,
126 EbtIImage2DArray,
127 EbtIImageCube,
128 EbtIImage1D,
129 EbtIImage1DArray,
130 EbtIImage2DMS,
131 EbtIImage2DMSArray,
132 EbtIImageCubeArray,
133 EbtIImageRect,
134 EbtIImageBuffer,
135 EbtGuardUIntImageBegin,
136 EbtUImage2D = EbtGuardUIntImageBegin,
137 EbtUImage3D,
138 EbtUImage2DArray,
139 EbtUImageCube,
140 EbtUImage1D,
141 EbtUImage1DArray,
142 EbtUImage2DMS,
143 EbtUImage2DMSArray,
144 EbtUImageCubeArray,
145 EbtUImageRect,
146 EbtUImageBuffer,
147 EbtGuardUIntImageEnd = EbtUImageBuffer,
148 EbtGuardImageEnd = EbtGuardUIntImageEnd,
149
150 // Subpass Input
151 EbtGuardSubpassInputBegin,
152 EbtSubpassInput = EbtGuardSubpassInputBegin,
153 EbtISubpassInput,
154 EbtUSubpassInput,
155 EbtSubpassInputMS,
156 EbtISubpassInputMS,
157 EbtUSubpassInputMS,
158 EbtGuardSubpassInputEnd = EbtUSubpassInputMS,
159
160 EbtLastSimpleType = EbtGuardSubpassInputEnd,
161
162 EbtStruct,
163 EbtInterfaceBlock,
164
165 // end of list
166 EbtLast = EbtInterfaceBlock
167 };
168
169 class TBasicMangledName
170 {
171 public:
TBasicMangledName(TBasicType t)172 constexpr TBasicMangledName(TBasicType t) : mName{'\0', '\0'}
173 {
174 if (t > EbtLastSimpleType)
175 {
176 mName[0] = '{';
177 mName[1] = '\0';
178 }
179 else if (t < 26)
180 {
181 mName[0] = '0';
182 mName[1] = static_cast<char>('A' + t);
183 }
184 else if (t < 52)
185 {
186 mName[0] = '0';
187 mName[1] = static_cast<char>('a' - 26 + t);
188 }
189 else if (t < 78)
190 {
191 mName[0] = '1';
192 mName[1] = static_cast<char>('A' - 52 + t);
193 }
194 else if (t < 104)
195 {
196 mName[0] = '1';
197 mName[1] = static_cast<char>('a' - 78 + t);
198 }
199 }
200
getName()201 constexpr char *getName() { return mName; }
202
203 static constexpr int mangledNameSize = 2;
204
205 private:
206 char mName[mangledNameSize];
207 };
208
209 const char *getBasicString(TBasicType t);
210
IsSampler(TBasicType type)211 inline bool IsSampler(TBasicType type)
212 {
213 return type >= EbtGuardSamplerBegin && type <= EbtGuardSamplerEnd;
214 }
215
IsImage(TBasicType type)216 inline bool IsImage(TBasicType type)
217 {
218 return type >= EbtGuardImageBegin && type <= EbtGuardImageEnd;
219 }
220
IsUIntImage(TBasicType type)221 inline bool IsUIntImage(TBasicType type)
222 {
223 return type >= EbtGuardUIntImageBegin && type <= EbtGuardUIntImageEnd;
224 }
225
IsAtomicCounter(TBasicType type)226 inline bool IsAtomicCounter(TBasicType type)
227 {
228 return type == EbtAtomicCounter;
229 }
230
IsSubpassInputType(TBasicType type)231 inline bool IsSubpassInputType(TBasicType type)
232 {
233 return type >= EbtGuardSubpassInputBegin && type <= EbtGuardSubpassInputEnd;
234 }
235
IsOpaqueType(TBasicType type)236 inline bool IsOpaqueType(TBasicType type)
237 {
238 return IsSampler(type) || IsImage(type) || IsAtomicCounter(type) || IsSubpassInputType(type);
239 }
240
IsIntegerSampler(TBasicType type)241 inline bool IsIntegerSampler(TBasicType type)
242 {
243 switch (type)
244 {
245 case EbtISampler2D:
246 case EbtISampler3D:
247 case EbtISamplerCube:
248 case EbtISampler2DArray:
249 case EbtISampler2DMS:
250 case EbtISampler2DMSArray:
251 case EbtUSampler2D:
252 case EbtUSampler3D:
253 case EbtUSamplerCube:
254 case EbtUSampler2DArray:
255 case EbtUSampler2DMS:
256 case EbtUSampler2DMSArray:
257 case EbtISampler1D:
258 case EbtISampler1DArray:
259 case EbtISampler2DRect:
260 case EbtISamplerBuffer:
261 case EbtISamplerCubeArray:
262 case EbtUSampler1D:
263 case EbtUSampler1DArray:
264 case EbtUSampler2DRect:
265 case EbtUSamplerBuffer:
266 case EbtUSamplerCubeArray:
267 return true;
268 case EbtSampler2D:
269 case EbtSampler3D:
270 case EbtSamplerCube:
271 case EbtSamplerExternalOES:
272 case EbtSamplerExternal2DY2YEXT:
273 case EbtSampler2DRect:
274 case EbtSampler2DArray:
275 case EbtSampler2DShadow:
276 case EbtSamplerCubeShadow:
277 case EbtSampler2DArrayShadow:
278 case EbtSampler2DMS:
279 case EbtSampler2DMSArray:
280 case EbtSampler1D:
281 case EbtSampler1DArray:
282 case EbtSampler1DArrayShadow:
283 case EbtSamplerBuffer:
284 case EbtSamplerCubeArray:
285 case EbtSamplerCubeArrayShadow:
286 case EbtSampler1DShadow:
287 case EbtSampler2DRectShadow:
288 case EbtSamplerVideoWEBGL:
289 return false;
290 default:
291 ASSERT(!IsSampler(type));
292 }
293
294 return false;
295 }
296
IsIntegerSamplerUnsigned(TBasicType type)297 inline bool IsIntegerSamplerUnsigned(TBasicType type)
298 {
299 switch (type)
300 {
301 case EbtISampler2D:
302 case EbtISampler3D:
303 case EbtISamplerCube:
304 case EbtISampler2DArray:
305 case EbtISampler2DMS:
306 case EbtISampler2DMSArray:
307 case EbtISampler1D:
308 case EbtISampler1DArray:
309 case EbtISampler2DRect:
310 case EbtISamplerBuffer:
311 case EbtISamplerCubeArray:
312 return false;
313 case EbtUSampler2D:
314 case EbtUSampler3D:
315 case EbtUSamplerCube:
316 case EbtUSampler2DArray:
317 case EbtUSampler2DMS:
318 case EbtUSampler2DMSArray:
319 case EbtUSampler1D:
320 case EbtUSampler1DArray:
321 case EbtUSampler2DRect:
322 case EbtUSamplerBuffer:
323 case EbtUSamplerCubeArray:
324 return true;
325 default:
326 ASSERT(!IsIntegerSampler(type));
327 }
328
329 return false;
330 }
331
IsSampler2DMS(TBasicType type)332 inline bool IsSampler2DMS(TBasicType type)
333 {
334 switch (type)
335 {
336 case EbtSampler2DMS:
337 case EbtISampler2DMS:
338 case EbtUSampler2DMS:
339 return true;
340 default:
341 return false;
342 }
343 }
344
IsSampler2DMSArray(TBasicType type)345 inline bool IsSampler2DMSArray(TBasicType type)
346 {
347 switch (type)
348 {
349 case EbtSampler2DMSArray:
350 case EbtISampler2DMSArray:
351 case EbtUSampler2DMSArray:
352 return true;
353 default:
354 return false;
355 }
356 }
357
IsSamplerMS(TBasicType type)358 inline bool IsSamplerMS(TBasicType type)
359 {
360 return IsSampler2DMS(type) || IsSampler2DMSArray(type);
361 }
362
IsImageMS(TBasicType type)363 inline bool IsImageMS(TBasicType type)
364 {
365 switch (type)
366 {
367 case EbtImage2DMS:
368 case EbtImage2DMSArray:
369 case EbtIImage2DMS:
370 case EbtIImage2DMSArray:
371 case EbtUImage2DMS:
372 case EbtUImage2DMSArray:
373 return true;
374 default:
375 return false;
376 }
377 }
378
IsFloatImage(TBasicType type)379 inline bool IsFloatImage(TBasicType type)
380 {
381 switch (type)
382 {
383 case EbtImage1D:
384 case EbtImage2D:
385 case EbtImage3D:
386 case EbtImage1DArray:
387 case EbtImage2DArray:
388 case EbtImageCube:
389 case EbtImage2DMS:
390 case EbtImage2DMSArray:
391 case EbtImageCubeArray:
392 case EbtImageRect:
393 case EbtImageBuffer:
394 return true;
395 default:
396 break;
397 }
398
399 return false;
400 }
401
IsIntegerImage(TBasicType type)402 inline bool IsIntegerImage(TBasicType type)
403 {
404
405 switch (type)
406 {
407 case EbtIImage1D:
408 case EbtIImage2D:
409 case EbtIImage3D:
410 case EbtIImage1DArray:
411 case EbtIImage2DArray:
412 case EbtIImageCube:
413 case EbtIImage2DMS:
414 case EbtIImage2DMSArray:
415 case EbtIImageCubeArray:
416 case EbtIImageRect:
417 case EbtIImageBuffer:
418 return true;
419 default:
420 break;
421 }
422
423 return false;
424 }
425
IsUnsignedImage(TBasicType type)426 inline bool IsUnsignedImage(TBasicType type)
427 {
428
429 switch (type)
430 {
431 case EbtUImage1D:
432 case EbtUImage2D:
433 case EbtUImage3D:
434 case EbtUImage1DArray:
435 case EbtUImage2DArray:
436 case EbtUImageCube:
437 case EbtUImage2DMS:
438 case EbtUImage2DMSArray:
439 case EbtUImageCubeArray:
440 case EbtUImageRect:
441 case EbtUImageBuffer:
442 return true;
443 default:
444 break;
445 }
446
447 return false;
448 }
449
450 // Samplers are divided into 4 disjoint categories: 2D, cube, 3D, and array.
451 // Array samplers are not 2D samplers.
IsSampler2D(TBasicType type)452 inline bool IsSampler2D(TBasicType type)
453 {
454 switch (type)
455 {
456 case EbtSampler2D:
457 case EbtISampler2D:
458 case EbtUSampler2D:
459 case EbtSampler2DRect:
460 case EbtISampler2DRect:
461 case EbtUSampler2DRect:
462 case EbtSampler2DRectShadow:
463 case EbtSamplerExternalOES:
464 case EbtSamplerExternal2DY2YEXT:
465 case EbtSampler2DShadow:
466 case EbtSampler2DMS:
467 case EbtISampler2DMS:
468 case EbtUSampler2DMS:
469 case EbtSamplerVideoWEBGL:
470 return true;
471 case EbtSampler2DArray:
472 case EbtISampler2DArray:
473 case EbtUSampler2DArray:
474 case EbtSampler2DMSArray:
475 case EbtISampler2DMSArray:
476 case EbtUSampler2DMSArray:
477 case EbtSampler2DArrayShadow:
478 case EbtSampler3D:
479 case EbtISampler3D:
480 case EbtUSampler3D:
481 case EbtISamplerCube:
482 case EbtUSamplerCube:
483 case EbtSamplerCube:
484 case EbtSamplerCubeShadow:
485 case EbtSampler1D:
486 case EbtSampler1DArray:
487 case EbtSampler1DArrayShadow:
488 case EbtSamplerBuffer:
489 case EbtSamplerCubeArray:
490 case EbtSamplerCubeArrayShadow:
491 case EbtSampler1DShadow:
492 case EbtISampler1D:
493 case EbtISampler1DArray:
494 case EbtISamplerBuffer:
495 case EbtISamplerCubeArray:
496 case EbtUSampler1D:
497 case EbtUSampler1DArray:
498 case EbtUSamplerBuffer:
499 case EbtUSamplerCubeArray:
500 return false;
501 default:
502 ASSERT(!IsSampler(type));
503 }
504
505 return false;
506 }
507
IsSamplerCube(TBasicType type)508 inline bool IsSamplerCube(TBasicType type)
509 {
510 switch (type)
511 {
512 case EbtSamplerCube:
513 case EbtISamplerCube:
514 case EbtUSamplerCube:
515 case EbtSamplerCubeShadow:
516 return true;
517 case EbtSampler2D:
518 case EbtSampler3D:
519 case EbtSamplerExternalOES:
520 case EbtSamplerExternal2DY2YEXT:
521 case EbtSampler2DRect:
522 case EbtSampler2DArray:
523 case EbtSampler2DMS:
524 case EbtSampler2DMSArray:
525 case EbtISampler2D:
526 case EbtISampler3D:
527 case EbtISampler2DArray:
528 case EbtISampler2DMS:
529 case EbtISampler2DMSArray:
530 case EbtUSampler2D:
531 case EbtUSampler3D:
532 case EbtUSampler2DArray:
533 case EbtUSampler2DMS:
534 case EbtUSampler2DMSArray:
535 case EbtSampler2DShadow:
536 case EbtSampler2DArrayShadow:
537 case EbtSampler1D:
538 case EbtSampler1DArray:
539 case EbtSampler1DArrayShadow:
540 case EbtSamplerBuffer:
541 case EbtSamplerCubeArray:
542 case EbtSamplerCubeArrayShadow:
543 case EbtSampler1DShadow:
544 case EbtSampler2DRectShadow:
545 case EbtISampler1D:
546 case EbtISampler1DArray:
547 case EbtISampler2DRect:
548 case EbtISamplerBuffer:
549 case EbtISamplerCubeArray:
550 case EbtUSampler1D:
551 case EbtUSampler1DArray:
552 case EbtUSampler2DRect:
553 case EbtUSamplerBuffer:
554 case EbtUSamplerCubeArray:
555 case EbtSamplerVideoWEBGL:
556 return false;
557 default:
558 ASSERT(!IsSampler(type));
559 }
560
561 return false;
562 }
563
IsSampler3D(TBasicType type)564 inline bool IsSampler3D(TBasicType type)
565 {
566 switch (type)
567 {
568 case EbtSampler3D:
569 case EbtISampler3D:
570 case EbtUSampler3D:
571 return true;
572 case EbtSampler2D:
573 case EbtSamplerCube:
574 case EbtSamplerExternalOES:
575 case EbtSamplerExternal2DY2YEXT:
576 case EbtSampler2DRect:
577 case EbtSampler2DArray:
578 case EbtSampler2DMS:
579 case EbtSampler2DMSArray:
580 case EbtISampler2D:
581 case EbtISamplerCube:
582 case EbtISampler2DArray:
583 case EbtISampler2DMS:
584 case EbtISampler2DMSArray:
585 case EbtUSampler2D:
586 case EbtUSamplerCube:
587 case EbtUSampler2DArray:
588 case EbtUSampler2DMS:
589 case EbtUSampler2DMSArray:
590 case EbtSampler2DShadow:
591 case EbtSamplerCubeShadow:
592 case EbtSampler2DArrayShadow:
593 case EbtSampler1D:
594 case EbtSampler1DArray:
595 case EbtSampler1DArrayShadow:
596 case EbtSamplerBuffer:
597 case EbtSamplerCubeArray:
598 case EbtSamplerCubeArrayShadow:
599 case EbtSampler1DShadow:
600 case EbtSampler2DRectShadow:
601 case EbtISampler1D:
602 case EbtISampler1DArray:
603 case EbtISampler2DRect:
604 case EbtISamplerBuffer:
605 case EbtISamplerCubeArray:
606 case EbtUSampler1D:
607 case EbtUSampler1DArray:
608 case EbtUSampler2DRect:
609 case EbtUSamplerBuffer:
610 case EbtUSamplerCubeArray:
611 case EbtSamplerVideoWEBGL:
612 return false;
613 default:
614 ASSERT(!IsSampler(type));
615 }
616
617 return false;
618 }
619
IsSamplerArray(TBasicType type)620 inline bool IsSamplerArray(TBasicType type)
621 {
622 switch (type)
623 {
624 case EbtSampler1DArray:
625 case EbtISampler1DArray:
626 case EbtUSampler1DArray:
627 case EbtSampler1DArrayShadow:
628 case EbtSampler2DArray:
629 case EbtISampler2DArray:
630 case EbtUSampler2DArray:
631 case EbtSampler2DMSArray:
632 case EbtISampler2DMSArray:
633 case EbtUSampler2DMSArray:
634 case EbtSampler2DArrayShadow:
635 case EbtSamplerCubeArray:
636 case EbtISamplerCubeArray:
637 case EbtUSamplerCubeArray:
638 case EbtSamplerCubeArrayShadow:
639 return true;
640 case EbtSampler2D:
641 case EbtISampler2D:
642 case EbtUSampler2D:
643 case EbtSampler2DRect:
644 case EbtSamplerExternalOES:
645 case EbtSamplerExternal2DY2YEXT:
646 case EbtSampler3D:
647 case EbtISampler3D:
648 case EbtUSampler3D:
649 case EbtISamplerCube:
650 case EbtUSamplerCube:
651 case EbtSamplerCube:
652 case EbtSampler2DShadow:
653 case EbtSamplerCubeShadow:
654 case EbtSampler2DMS:
655 case EbtISampler2DMS:
656 case EbtUSampler2DMS:
657 case EbtSampler1D:
658 case EbtSamplerBuffer:
659 case EbtSampler1DShadow:
660 case EbtSampler2DRectShadow:
661 case EbtISampler1D:
662 case EbtISampler2DRect:
663 case EbtISamplerBuffer:
664 case EbtUSampler1D:
665 case EbtUSampler2DRect:
666 case EbtUSamplerBuffer:
667 case EbtSamplerVideoWEBGL:
668 return false;
669 default:
670 ASSERT(!IsSampler(type));
671 }
672
673 return false;
674 }
675
IsSampler1D(TBasicType type)676 inline bool IsSampler1D(TBasicType type)
677 {
678 switch (type)
679 {
680 case EbtSampler1D:
681 case EbtISampler1D:
682 case EbtUSampler1D:
683 case EbtSampler1DShadow:
684 return true;
685 case EbtSampler2D:
686 case EbtSamplerCube:
687 case EbtSampler3D:
688 case EbtISampler3D:
689 case EbtUSampler3D:
690 case EbtSamplerExternalOES:
691 case EbtSamplerExternal2DY2YEXT:
692 case EbtSampler2DRect:
693 case EbtSampler2DArray:
694 case EbtSampler2DMS:
695 case EbtSampler2DMSArray:
696 case EbtISampler2D:
697 case EbtISamplerCube:
698 case EbtISampler2DArray:
699 case EbtISampler2DMS:
700 case EbtISampler2DMSArray:
701 case EbtUSampler2D:
702 case EbtUSamplerCube:
703 case EbtUSampler2DArray:
704 case EbtUSampler2DMS:
705 case EbtUSampler2DMSArray:
706 case EbtSampler2DShadow:
707 case EbtSamplerCubeShadow:
708 case EbtSampler2DArrayShadow:
709 case EbtSampler1DArray:
710 case EbtSampler1DArrayShadow:
711 case EbtSamplerBuffer:
712 case EbtSamplerCubeArray:
713 case EbtSamplerCubeArrayShadow:
714 case EbtSampler2DRectShadow:
715 case EbtISampler1DArray:
716 case EbtISampler2DRect:
717 case EbtISamplerBuffer:
718 case EbtISamplerCubeArray:
719 case EbtUSampler1DArray:
720 case EbtUSampler2DRect:
721 case EbtUSamplerBuffer:
722 case EbtUSamplerCubeArray:
723 case EbtSamplerVideoWEBGL:
724 return false;
725 default:
726 ASSERT(!IsSampler(type));
727 }
728
729 return false;
730 }
731
IsSamplerBuffer(TBasicType type)732 inline bool IsSamplerBuffer(TBasicType type)
733 {
734 switch (type)
735 {
736 case EbtSamplerBuffer:
737 case EbtISamplerBuffer:
738 case EbtUSamplerBuffer:
739 return true;
740 default:
741 return false;
742 }
743 }
744
IsShadowSampler(TBasicType type)745 inline bool IsShadowSampler(TBasicType type)
746 {
747 switch (type)
748 {
749 case EbtSampler1DShadow:
750 case EbtSampler2DShadow:
751 case EbtSamplerCubeShadow:
752 case EbtSampler1DArrayShadow:
753 case EbtSampler2DArrayShadow:
754 case EbtSamplerCubeArrayShadow:
755 case EbtSampler2DRectShadow:
756 return true;
757 case EbtISampler2D:
758 case EbtISampler3D:
759 case EbtISamplerCube:
760 case EbtISampler2DArray:
761 case EbtISampler2DMS:
762 case EbtISampler2DMSArray:
763 case EbtUSampler2D:
764 case EbtUSampler3D:
765 case EbtUSamplerCube:
766 case EbtUSampler2DArray:
767 case EbtUSampler2DMS:
768 case EbtUSampler2DMSArray:
769 case EbtSampler2D:
770 case EbtSampler3D:
771 case EbtSamplerCube:
772 case EbtSamplerExternalOES:
773 case EbtSamplerExternal2DY2YEXT:
774 case EbtSampler2DRect:
775 case EbtSampler2DArray:
776 case EbtSampler2DMS:
777 case EbtSampler2DMSArray:
778 case EbtSampler1D:
779 case EbtSampler1DArray:
780 case EbtSamplerBuffer:
781 case EbtSamplerCubeArray:
782 case EbtISampler1D:
783 case EbtISampler1DArray:
784 case EbtISampler2DRect:
785 case EbtISamplerBuffer:
786 case EbtISamplerCubeArray:
787 case EbtUSampler1D:
788 case EbtUSampler1DArray:
789 case EbtUSampler2DRect:
790 case EbtUSamplerBuffer:
791 case EbtUSamplerCubeArray:
792 case EbtSamplerVideoWEBGL:
793 return false;
794 default:
795 ASSERT(!IsSampler(type));
796 }
797
798 return false;
799 }
800
IsImage2D(TBasicType type)801 inline bool IsImage2D(TBasicType type)
802 {
803 switch (type)
804 {
805 case EbtImage2D:
806 case EbtIImage2D:
807 case EbtUImage2D:
808 case EbtImage2DMS:
809 case EbtIImage2DMS:
810 case EbtUImage2DMS:
811 return true;
812 case EbtImage3D:
813 case EbtIImage3D:
814 case EbtUImage3D:
815 case EbtImage2DArray:
816 case EbtIImage2DArray:
817 case EbtUImage2DArray:
818 case EbtImageCube:
819 case EbtIImageCube:
820 case EbtUImageCube:
821 case EbtImage1D:
822 case EbtIImage1D:
823 case EbtUImage1D:
824 case EbtImage1DArray:
825 case EbtIImage1DArray:
826 case EbtUImage1DArray:
827 case EbtImage2DMSArray:
828 case EbtIImage2DMSArray:
829 case EbtUImage2DMSArray:
830 case EbtImageCubeArray:
831 case EbtIImageCubeArray:
832 case EbtUImageCubeArray:
833 case EbtImageRect:
834 case EbtIImageRect:
835 case EbtUImageRect:
836 case EbtImageBuffer:
837 case EbtIImageBuffer:
838 case EbtUImageBuffer:
839 return false;
840 default:
841 ASSERT(!IsImage(type));
842 }
843
844 return false;
845 }
846
IsImage3D(TBasicType type)847 inline bool IsImage3D(TBasicType type)
848 {
849 switch (type)
850 {
851 case EbtImage3D:
852 case EbtIImage3D:
853 case EbtUImage3D:
854 return true;
855 case EbtImage2D:
856 case EbtIImage2D:
857 case EbtUImage2D:
858 case EbtImage2DArray:
859 case EbtIImage2DArray:
860 case EbtUImage2DArray:
861 case EbtImageCube:
862 case EbtIImageCube:
863 case EbtUImageCube:
864 case EbtImage1D:
865 case EbtIImage1D:
866 case EbtUImage1D:
867 case EbtImage1DArray:
868 case EbtIImage1DArray:
869 case EbtUImage1DArray:
870 case EbtImage2DMS:
871 case EbtIImage2DMS:
872 case EbtUImage2DMS:
873 case EbtImage2DMSArray:
874 case EbtIImage2DMSArray:
875 case EbtUImage2DMSArray:
876 case EbtImageCubeArray:
877 case EbtIImageCubeArray:
878 case EbtUImageCubeArray:
879 case EbtImageRect:
880 case EbtIImageRect:
881 case EbtUImageRect:
882 case EbtImageBuffer:
883 case EbtIImageBuffer:
884 case EbtUImageBuffer:
885 return false;
886 default:
887 ASSERT(!IsImage(type));
888 }
889
890 return false;
891 }
892
IsImage2DArray(TBasicType type)893 inline bool IsImage2DArray(TBasicType type)
894 {
895 switch (type)
896 {
897 case EbtImage2DArray:
898 case EbtIImage2DArray:
899 case EbtUImage2DArray:
900 case EbtImage2DMSArray:
901 case EbtIImage2DMSArray:
902 case EbtUImage2DMSArray:
903 return true;
904 case EbtImage2D:
905 case EbtIImage2D:
906 case EbtUImage2D:
907 case EbtImage3D:
908 case EbtIImage3D:
909 case EbtUImage3D:
910 case EbtImageCube:
911 case EbtIImageCube:
912 case EbtUImageCube:
913 case EbtImage1D:
914 case EbtIImage1D:
915 case EbtUImage1D:
916 case EbtImage1DArray:
917 case EbtIImage1DArray:
918 case EbtUImage1DArray:
919 case EbtImage2DMS:
920 case EbtIImage2DMS:
921 case EbtUImage2DMS:
922 case EbtImageCubeArray:
923 case EbtIImageCubeArray:
924 case EbtUImageCubeArray:
925 case EbtImageRect:
926 case EbtIImageRect:
927 case EbtUImageRect:
928 case EbtImageBuffer:
929 case EbtIImageBuffer:
930 case EbtUImageBuffer:
931 return false;
932 default:
933 ASSERT(!IsImage(type));
934 }
935
936 return false;
937 }
938
IsImageCube(TBasicType type)939 inline bool IsImageCube(TBasicType type)
940 {
941 switch (type)
942 {
943 case EbtImageCube:
944 case EbtIImageCube:
945 case EbtUImageCube:
946 return true;
947 case EbtImage2D:
948 case EbtIImage2D:
949 case EbtUImage2D:
950 case EbtImage3D:
951 case EbtIImage3D:
952 case EbtUImage3D:
953 case EbtImage2DArray:
954 case EbtIImage2DArray:
955 case EbtUImage2DArray:
956 case EbtImage1D:
957 case EbtIImage1D:
958 case EbtUImage1D:
959 case EbtImage1DArray:
960 case EbtIImage1DArray:
961 case EbtUImage1DArray:
962 case EbtImage2DMS:
963 case EbtIImage2DMS:
964 case EbtUImage2DMS:
965 case EbtImage2DMSArray:
966 case EbtIImage2DMSArray:
967 case EbtUImage2DMSArray:
968 case EbtImageCubeArray:
969 case EbtIImageCubeArray:
970 case EbtUImageCubeArray:
971 case EbtImageRect:
972 case EbtIImageRect:
973 case EbtUImageRect:
974 case EbtImageBuffer:
975 case EbtIImageBuffer:
976 case EbtUImageBuffer:
977 return false;
978 default:
979 ASSERT(!IsImage(type));
980 }
981
982 return false;
983 }
984
IsImageBuffer(TBasicType type)985 inline bool IsImageBuffer(TBasicType type)
986 {
987 switch (type)
988 {
989 case EbtImageBuffer:
990 case EbtIImageBuffer:
991 case EbtUImageBuffer:
992 return true;
993 default:
994 return false;
995 }
996 }
997
IsInteger(TBasicType type)998 inline bool IsInteger(TBasicType type)
999 {
1000 return type == EbtInt || type == EbtUInt;
1001 }
1002
SupportsPrecision(TBasicType type)1003 inline bool SupportsPrecision(TBasicType type)
1004 {
1005 return type == EbtFloat || type == EbtInt || type == EbtUInt || IsOpaqueType(type);
1006 }
1007
1008 //
1009 // Qualifiers and built-ins. These are mainly used to see what can be read
1010 // or written, and by the machine dependent translator to know which registers
1011 // to allocate variables in. Since built-ins tend to go to different registers
1012 // than varying or uniform, it makes sense they are peers, not sub-classes.
1013 //
1014 enum TQualifier
1015 {
1016 EvqTemporary, // For temporaries (within a function), read/write
1017 EvqGlobal, // For globals read/write
1018 EvqConst, // User defined constants
1019 EvqAttribute, // Readonly
1020 EvqVaryingIn, // readonly, fragment shaders only
1021 EvqVaryingOut, // vertex shaders only read/write
1022 EvqUniform, // Readonly, vertex and fragment
1023 EvqBuffer, // read/write, vertex, fragment and compute shader
1024 EvqPatch, // EXT_tessellation_shader storage qualifier
1025
1026 EvqVertexIn, // Vertex shader input
1027 EvqFragmentOut, // Fragment shader output
1028 EvqVertexOut, // Vertex shader output
1029 EvqFragmentIn, // Fragment shader input
1030
1031 EvqFragmentInOut, // EXT_shader_framebuffer_fetch qualifier
1032
1033 // parameters
1034 EvqParamIn,
1035 EvqParamOut,
1036 EvqParamInOut,
1037 EvqParamConst,
1038
1039 // built-ins read by vertex shader
1040 EvqInstanceID,
1041 EvqVertexID,
1042
1043 // built-ins written by vertex shader
1044 EvqPosition,
1045 EvqPointSize,
1046
1047 EvqDrawID, // ANGLE_multi_draw
1048
1049 // built-ins read by fragment shader
1050 EvqFragCoord,
1051 EvqFrontFacing,
1052 EvqPointCoord,
1053 EvqHelperInvocation,
1054
1055 // built-ins written by fragment shader
1056 EvqFragColor,
1057 EvqFragData,
1058 EvqFragDepth, // gl_FragDepth for ESSL300, or gl_FragDepthEXT for ESSL100, EXT_frag_depth.
1059
1060 EvqSecondaryFragColorEXT, // EXT_blend_func_extended
1061 EvqSecondaryFragDataEXT, // EXT_blend_func_extended
1062
1063 EvqViewIDOVR, // OVR_multiview
1064 EvqViewportIndex, // gl_ViewportIndex
1065
1066 EvqClipDistance, // APPLE_clip_distance/EXT_clip_cull_distance
1067 EvqCullDistance, // EXT_clip_cull_distance
1068
1069 // built-ins written by the shader_framebuffer_fetch extension(s)
1070 EvqLastFragColor,
1071 EvqLastFragData,
1072
1073 // GLSL ES 3.0 vertex output and fragment input
1074 EvqSmooth, // Incomplete qualifier, smooth is the default
1075 EvqFlat, // Incomplete qualifier
1076 EvqNoPerspective, // Incomplete qualifier
1077 EvqCentroid, // Incomplete qualifier
1078 EvqSample,
1079 EvqSmoothOut,
1080 EvqFlatOut,
1081 EvqNoPerspectiveOut,
1082 EvqCentroidOut, // Implies smooth
1083 EvqSampleOut,
1084 EvqSmoothIn,
1085 EvqFlatIn,
1086 EvqNoPerspectiveIn,
1087 EvqCentroidIn, // Implies smooth
1088 EvqSampleIn,
1089
1090 // GLSL ES 3.0 extension OES_sample_variables
1091 EvqSampleID,
1092 EvqSamplePosition,
1093 EvqSampleMaskIn,
1094 EvqSampleMask,
1095 EvqNumSamples,
1096
1097 // GLSL ES 3.1 compute shader special variables
1098 EvqShared,
1099 EvqComputeIn,
1100 EvqNumWorkGroups,
1101 EvqWorkGroupSize,
1102 EvqWorkGroupID,
1103 EvqLocalInvocationID,
1104 EvqGlobalInvocationID,
1105 EvqLocalInvocationIndex,
1106
1107 // GLSL ES 3.1 memory qualifiers
1108 EvqReadOnly,
1109 EvqWriteOnly,
1110 EvqCoherent,
1111 EvqRestrict,
1112 EvqVolatile,
1113
1114 // GLSL ES 3.1 extension EXT_geometry_shader qualifiers
1115 EvqGeometryIn,
1116 EvqGeometryOut,
1117 EvqPerVertexIn, // gl_in
1118 EvqPrimitiveIDIn, // gl_PrimitiveIDIn
1119 EvqInvocationID, // gl_InvocationID
1120 EvqPrimitiveID, // gl_PrimitiveID
1121 EvqLayer, // gl_Layer
1122
1123 // GLSL ES 3.1 extension EXT_gpu_shader5 qualifiers
1124 EvqPrecise,
1125
1126 // GLES ES 3.1 extension EXT_tessellation_shader qualifiers
1127 EvqPatchIn,
1128 EvqPatchOut,
1129
1130 EvqTessControlIn,
1131 EvqTessControlOut,
1132 EvqPerVertexOut,
1133 EvqPatchVerticesIn,
1134 EvqTessLevelOuter,
1135 EvqTessLevelInner,
1136
1137 // GLES ES 3.1 extension EXT_primitive_bounding_box
1138 EvqBoundingBoxEXT,
1139
1140 EvqTessEvaluationIn,
1141 EvqTessEvaluationOut,
1142 EvqTessCoord,
1143
1144 // A specialization constant, which is not valid GLSL ES, but is there to support Vulkan output
1145 // generation. In that case, TLayoutQualifier::location will contain the somewhat equivalent
1146 // constant_id.
1147 EvqSpecConst,
1148
1149 // end of list
1150 EvqLast
1151 };
1152
IsQualifierUnspecified(TQualifier qualifier)1153 inline bool IsQualifierUnspecified(TQualifier qualifier)
1154 {
1155 return (qualifier == EvqTemporary || qualifier == EvqGlobal);
1156 }
1157
IsStorageBuffer(TQualifier qualifier)1158 inline bool IsStorageBuffer(TQualifier qualifier)
1159 {
1160 return qualifier == EvqBuffer;
1161 }
1162
IsShaderIn(TQualifier qualifier)1163 inline bool IsShaderIn(TQualifier qualifier)
1164 {
1165 switch (qualifier)
1166 {
1167 case EvqVertexIn:
1168 case EvqTessControlIn:
1169 case EvqTessEvaluationIn:
1170 case EvqGeometryIn:
1171 case EvqFragmentIn:
1172 case EvqPerVertexIn:
1173 case EvqAttribute:
1174 case EvqVaryingIn:
1175 case EvqSmoothIn:
1176 case EvqFlatIn:
1177 case EvqNoPerspectiveIn:
1178 case EvqCentroidIn:
1179 case EvqSampleIn:
1180 case EvqPatchIn:
1181 return true;
1182 default:
1183 return false;
1184 }
1185 }
1186
IsShaderOut(TQualifier qualifier)1187 inline bool IsShaderOut(TQualifier qualifier)
1188 {
1189 switch (qualifier)
1190 {
1191 case EvqVertexOut:
1192 case EvqTessControlOut:
1193 case EvqTessEvaluationOut:
1194 case EvqGeometryOut:
1195 case EvqFragmentOut:
1196 case EvqPerVertexOut:
1197 case EvqVaryingOut:
1198 case EvqSmoothOut:
1199 case EvqFlatOut:
1200 case EvqNoPerspectiveOut:
1201 case EvqCentroidOut:
1202 case EvqSampleOut:
1203 case EvqPatchOut:
1204 case EvqFragmentInOut:
1205 return true;
1206 default:
1207 return false;
1208 }
1209 }
1210
IsShaderIoBlock(TQualifier qualifier)1211 inline bool IsShaderIoBlock(TQualifier qualifier)
1212 {
1213 switch (qualifier)
1214 {
1215 case EvqPerVertexIn:
1216 case EvqPerVertexOut:
1217 case EvqVertexOut:
1218 case EvqTessControlIn:
1219 case EvqTessControlOut:
1220 case EvqTessEvaluationIn:
1221 case EvqTessEvaluationOut:
1222 case EvqPatchIn:
1223 case EvqPatchOut:
1224 case EvqGeometryIn:
1225 case EvqGeometryOut:
1226 case EvqFragmentIn:
1227 return true;
1228 default:
1229 return false;
1230 }
1231 }
1232
1233 enum TLayoutImageInternalFormat
1234 {
1235 EiifUnspecified,
1236 EiifRGBA32F,
1237 EiifRGBA16F,
1238 EiifR32F,
1239 EiifRGBA32UI,
1240 EiifRGBA16UI,
1241 EiifRGBA8UI,
1242 EiifR32UI,
1243 EiifRGBA32I,
1244 EiifRGBA16I,
1245 EiifRGBA8I,
1246 EiifR32I,
1247 EiifRGBA8,
1248 EiifRGBA8_SNORM,
1249
1250 EiifLast = EiifRGBA8_SNORM,
1251 };
1252
1253 enum TLayoutMatrixPacking
1254 {
1255 EmpUnspecified,
1256 EmpRowMajor,
1257 EmpColumnMajor,
1258
1259 EmpLast = EmpColumnMajor,
1260 };
1261
1262 enum TLayoutBlockStorage
1263 {
1264 EbsUnspecified,
1265 EbsShared,
1266 EbsPacked,
1267 EbsStd140,
1268 EbsStd430,
1269
1270 EbsLast = EbsStd430,
1271 };
1272
1273 enum TYuvCscStandardEXT
1274 {
1275 EycsUndefined,
1276 EycsItu601,
1277 EycsItu601FullRange,
1278 EycsItu709
1279 };
1280
1281 enum TLayoutPrimitiveType
1282 {
1283 EptUndefined,
1284 EptPoints,
1285 EptLines,
1286 EptLinesAdjacency,
1287 EptTriangles,
1288 EptTrianglesAdjacency,
1289 EptLineStrip,
1290 EptTriangleStrip
1291 };
1292
1293 enum TLayoutTessEvaluationType
1294 {
1295 EtetUndefined,
1296 EtetTriangles,
1297 EtetQuads,
1298 EtetIsolines,
1299 EtetEqualSpacing,
1300 EtetFractionalEvenSpacing,
1301 EtetFractionalOddSpacing,
1302 EtetCw,
1303 EtetCcw,
1304 EtetPointMode
1305 };
1306
1307 struct TLayoutQualifier
1308 {
1309 // Must have a trivial default constructor since it is used in YYSTYPE.
1310 TLayoutQualifier() = default;
1311
CreateTLayoutQualifier1312 constexpr static TLayoutQualifier Create() { return TLayoutQualifier(0); }
1313
isEmptyTLayoutQualifier1314 bool isEmpty() const
1315 {
1316 return location == -1 && binding == -1 && offset == -1 && numViews == -1 && yuv == false &&
1317 earlyFragmentTests == false && matrixPacking == EmpUnspecified &&
1318 blockStorage == EbsUnspecified && !localSize.isAnyValueSet() &&
1319 imageInternalFormat == EiifUnspecified && primitiveType == EptUndefined &&
1320 invocations == 0 && maxVertices == -1 && vertices == 0 &&
1321 tesPrimitiveType == EtetUndefined && tesVertexSpacingType == EtetUndefined &&
1322 tesOrderingType == EtetUndefined && tesPointType == EtetUndefined && index == -1 &&
1323 inputAttachmentIndex == -1 && noncoherent == false;
1324 }
1325
isCombinationValidTLayoutQualifier1326 bool isCombinationValid() const
1327 {
1328 bool workGroupSizeSpecified = localSize.isAnyValueSet();
1329 bool numViewsSet = (numViews != -1);
1330 bool geometryShaderSpecified =
1331 (primitiveType != EptUndefined) || (invocations != 0) || (maxVertices != -1);
1332 bool subpassInputSpecified = (inputAttachmentIndex != -1);
1333 bool otherLayoutQualifiersSpecified =
1334 (location != -1 || binding != -1 || index != -1 || matrixPacking != EmpUnspecified ||
1335 blockStorage != EbsUnspecified || imageInternalFormat != EiifUnspecified);
1336
1337 // we can have either the work group size specified, or number of views,
1338 // or yuv layout qualifier, or early_fragment_tests layout qualifier, or the other layout
1339 // qualifiers.
1340 return (workGroupSizeSpecified ? 1 : 0) + (numViewsSet ? 1 : 0) + (yuv ? 1 : 0) +
1341 (earlyFragmentTests ? 1 : 0) + (otherLayoutQualifiersSpecified ? 1 : 0) +
1342 (geometryShaderSpecified ? 1 : 0) + (subpassInputSpecified ? 1 : 0) +
1343 (noncoherent ? 1 : 0) <=
1344 1;
1345 }
1346
isLocalSizeEqualTLayoutQualifier1347 bool isLocalSizeEqual(const WorkGroupSize &localSizeIn) const
1348 {
1349 return localSize.isWorkGroupSizeMatching(localSizeIn);
1350 }
1351
1352 int location;
1353 unsigned int locationsSpecified;
1354 TLayoutMatrixPacking matrixPacking;
1355 TLayoutBlockStorage blockStorage;
1356
1357 // Compute shader layout qualifiers.
1358 WorkGroupSize localSize;
1359
1360 int binding;
1361 int offset;
1362
1363 // Image format layout qualifier
1364 TLayoutImageInternalFormat imageInternalFormat;
1365
1366 // OVR_multiview num_views.
1367 int numViews;
1368
1369 // EXT_YUV_target yuv layout qualifier.
1370 bool yuv;
1371
1372 // early_fragment_tests qualifier.
1373 bool earlyFragmentTests;
1374
1375 // OES_geometry_shader layout qualifiers.
1376 TLayoutPrimitiveType primitiveType;
1377 int invocations;
1378 int maxVertices;
1379
1380 // EXT_tessellation_shader shader layout qualifiers
1381 int vertices;
1382 TLayoutTessEvaluationType tesPrimitiveType;
1383 TLayoutTessEvaluationType tesVertexSpacingType;
1384 TLayoutTessEvaluationType tesOrderingType;
1385 TLayoutTessEvaluationType tesPointType;
1386
1387 // EXT_blend_func_extended fragment output layout qualifier
1388 int index;
1389
1390 // EXT_shader_framebuffer_fetch layout qualifiers.
1391 int inputAttachmentIndex;
1392 bool noncoherent;
1393
1394 private:
TLayoutQualifierTLayoutQualifier1395 explicit constexpr TLayoutQualifier(int /*placeholder*/)
1396 : location(-1),
1397 locationsSpecified(0),
1398 matrixPacking(EmpUnspecified),
1399 blockStorage(EbsUnspecified),
1400 localSize(-1),
1401 binding(-1),
1402 offset(-1),
1403 imageInternalFormat(EiifUnspecified),
1404 numViews(-1),
1405 yuv(false),
1406 earlyFragmentTests(false),
1407 primitiveType(EptUndefined),
1408 invocations(0),
1409 maxVertices(-1),
1410 vertices(0),
1411 tesPrimitiveType(EtetUndefined),
1412 tesVertexSpacingType(EtetUndefined),
1413 tesOrderingType(EtetUndefined),
1414 tesPointType(EtetUndefined),
1415 index(-1),
1416 inputAttachmentIndex(-1),
1417 noncoherent(false)
1418 {}
1419 };
1420
1421 struct TMemoryQualifier
1422 {
1423 // Must have a trivial default constructor since it is used in YYSTYPE.
1424 TMemoryQualifier() = default;
1425
isEmptyTMemoryQualifier1426 bool isEmpty() const
1427 {
1428 return !readonly && !writeonly && !coherent && !restrictQualifier && !volatileQualifier;
1429 }
1430
CreateTMemoryQualifier1431 constexpr static TMemoryQualifier Create() { return TMemoryQualifier(0); }
1432
1433 // GLSL ES 3.10 Revision 4, 4.9 Memory Access Qualifiers
1434 // An image can be qualified as both readonly and writeonly. It still can be can be used with
1435 // imageSize().
1436 bool readonly;
1437 bool writeonly;
1438 bool coherent;
1439
1440 // restrict and volatile are reserved keywords in C/C++
1441 bool restrictQualifier;
1442 bool volatileQualifier;
1443
1444 private:
TMemoryQualifierTMemoryQualifier1445 explicit constexpr TMemoryQualifier(int /*placeholder*/)
1446 : readonly(false),
1447 writeonly(false),
1448 coherent(false),
1449 restrictQualifier(false),
1450 volatileQualifier(false)
1451 {}
1452 };
1453
getWorkGroupSizeString(size_t dimension)1454 inline const char *getWorkGroupSizeString(size_t dimension)
1455 {
1456 switch (dimension)
1457 {
1458 case 0u:
1459 return "local_size_x";
1460 case 1u:
1461 return "local_size_y";
1462 case 2u:
1463 return "local_size_z";
1464 default:
1465 UNREACHABLE();
1466 return "dimension out of bounds";
1467 }
1468 }
1469
1470 // Used for GLSL generation, debugging and error messages.
getQualifierString(TQualifier q)1471 inline const char *getQualifierString(TQualifier q)
1472 {
1473 // clang-format off
1474 switch(q)
1475 {
1476 case EvqTemporary: return "Temporary";
1477 case EvqGlobal: return "Global";
1478 case EvqConst: return "const";
1479 case EvqAttribute: return "attribute";
1480 case EvqVaryingIn: return "varying";
1481 case EvqVaryingOut: return "varying";
1482 case EvqUniform: return "uniform";
1483 case EvqBuffer: return "buffer";
1484 case EvqPatch: return "patch";
1485 case EvqVertexIn: return "in";
1486 case EvqFragmentOut: return "out";
1487 case EvqVertexOut: return "out";
1488 case EvqFragmentIn: return "in";
1489 case EvqParamIn: return "in";
1490 case EvqParamOut: return "out";
1491 case EvqParamInOut: return "inout";
1492 case EvqParamConst: return "const";
1493 case EvqInstanceID: return "InstanceID";
1494 case EvqVertexID: return "VertexID";
1495 case EvqPosition: return "Position";
1496 case EvqPointSize: return "PointSize";
1497 case EvqDrawID: return "DrawID";
1498 case EvqFragCoord: return "FragCoord";
1499 case EvqFrontFacing: return "FrontFacing";
1500 case EvqHelperInvocation: return "HelperInvocation";
1501 case EvqPointCoord: return "PointCoord";
1502 case EvqFragColor: return "FragColor";
1503 case EvqFragData: return "FragData";
1504 case EvqFragDepth: return "FragDepth";
1505 case EvqSecondaryFragColorEXT: return "SecondaryFragColorEXT";
1506 case EvqSecondaryFragDataEXT: return "SecondaryFragDataEXT";
1507 case EvqViewIDOVR: return "ViewIDOVR";
1508 case EvqViewportIndex: return "ViewportIndex";
1509 case EvqLayer: return "Layer";
1510 case EvqLastFragColor: return "LastFragColor";
1511 case EvqLastFragData: return "LastFragData";
1512 case EvqFragmentInOut: return "inout";
1513 case EvqSmoothOut: return "smooth out";
1514 case EvqCentroidOut: return "smooth centroid out";
1515 case EvqFlatOut: return "flat out";
1516 case EvqNoPerspectiveOut: return "noperspective out";
1517 case EvqSmoothIn: return "smooth in";
1518 case EvqFlatIn: return "flat in";
1519 case EvqNoPerspectiveIn: return "noperspective in";
1520 case EvqCentroidIn: return "smooth centroid in";
1521 case EvqCentroid: return "centroid";
1522 case EvqFlat: return "flat";
1523 case EvqNoPerspective: return "noperspective";
1524 case EvqSmooth: return "smooth";
1525 case EvqShared: return "shared";
1526 case EvqComputeIn: return "in";
1527 case EvqNumWorkGroups: return "NumWorkGroups";
1528 case EvqWorkGroupSize: return "WorkGroupSize";
1529 case EvqWorkGroupID: return "WorkGroupID";
1530 case EvqLocalInvocationID: return "LocalInvocationID";
1531 case EvqGlobalInvocationID: return "GlobalInvocationID";
1532 case EvqLocalInvocationIndex: return "LocalInvocationIndex";
1533 case EvqReadOnly: return "readonly";
1534 case EvqWriteOnly: return "writeonly";
1535 case EvqGeometryIn: return "in";
1536 case EvqGeometryOut: return "out";
1537 case EvqPerVertexIn: return "gl_in";
1538 case EvqPrimitiveIDIn: return "gl_PrimitiveIDIn";
1539 case EvqInvocationID: return "gl_InvocationID";
1540 case EvqPrimitiveID: return "gl_PrimitiveID";
1541 case EvqPrecise: return "precise";
1542 case EvqClipDistance: return "ClipDistance";
1543 case EvqCullDistance: return "CullDistance";
1544 case EvqSample: return "sample";
1545 case EvqSampleIn: return "sample in";
1546 case EvqSampleOut: return "sample out";
1547 case EvqSampleID: return "SampleID";
1548 case EvqSamplePosition: return "SamplePosition";
1549 case EvqSampleMaskIn: return "SampleMaskIn";
1550 case EvqSampleMask: return "SampleMask";
1551 case EvqNumSamples: return "NumSamples";
1552 case EvqPatchIn: return "patch in";
1553 case EvqPatchOut: return "patch out";
1554 case EvqTessControlIn: return "in";
1555 case EvqTessControlOut: return "out";
1556 case EvqPerVertexOut: return "gl_out";
1557 case EvqPatchVerticesIn: return "PatchVerticesIn";
1558 case EvqTessLevelOuter: return "TessLevelOuter";
1559 case EvqTessLevelInner: return "TessLevelInner";
1560 case EvqBoundingBoxEXT: return "BoundingBoxEXT";
1561 case EvqTessEvaluationIn: return "in";
1562 case EvqTessEvaluationOut: return "out";
1563 case EvqTessCoord: return "TessCoord";
1564 case EvqSpecConst: return "const";
1565 default: UNREACHABLE(); return "unknown qualifier";
1566 }
1567 // clang-format on
1568 }
1569
getMatrixPackingString(TLayoutMatrixPacking mpq)1570 inline const char *getMatrixPackingString(TLayoutMatrixPacking mpq)
1571 {
1572 switch (mpq)
1573 {
1574 case EmpUnspecified:
1575 return "mp_unspecified";
1576 case EmpRowMajor:
1577 return "row_major";
1578 case EmpColumnMajor:
1579 return "column_major";
1580 default:
1581 UNREACHABLE();
1582 return "unknown matrix packing";
1583 }
1584 }
1585
getBlockStorageString(TLayoutBlockStorage bsq)1586 inline const char *getBlockStorageString(TLayoutBlockStorage bsq)
1587 {
1588 switch (bsq)
1589 {
1590 case EbsUnspecified:
1591 return "bs_unspecified";
1592 case EbsShared:
1593 return "shared";
1594 case EbsPacked:
1595 return "packed";
1596 case EbsStd140:
1597 return "std140";
1598 case EbsStd430:
1599 return "std430";
1600 default:
1601 UNREACHABLE();
1602 return "unknown block storage";
1603 }
1604 }
1605
getImageInternalFormatString(TLayoutImageInternalFormat iifq)1606 inline const char *getImageInternalFormatString(TLayoutImageInternalFormat iifq)
1607 {
1608 switch (iifq)
1609 {
1610 case EiifRGBA32F:
1611 return "rgba32f";
1612 case EiifRGBA16F:
1613 return "rgba16f";
1614 case EiifR32F:
1615 return "r32f";
1616 case EiifRGBA32UI:
1617 return "rgba32ui";
1618 case EiifRGBA16UI:
1619 return "rgba16ui";
1620 case EiifRGBA8UI:
1621 return "rgba8ui";
1622 case EiifR32UI:
1623 return "r32ui";
1624 case EiifRGBA32I:
1625 return "rgba32i";
1626 case EiifRGBA16I:
1627 return "rgba16i";
1628 case EiifRGBA8I:
1629 return "rgba8i";
1630 case EiifR32I:
1631 return "r32i";
1632 case EiifRGBA8:
1633 return "rgba8";
1634 case EiifRGBA8_SNORM:
1635 return "rgba8_snorm";
1636 default:
1637 UNREACHABLE();
1638 return "unknown internal image format";
1639 }
1640 }
1641
getYuvCscStandardEXT(const ImmutableString & str)1642 inline TYuvCscStandardEXT getYuvCscStandardEXT(const ImmutableString &str)
1643 {
1644 if (str == "itu_601")
1645 return EycsItu601;
1646 else if (str == "itu_601_full_range")
1647 return EycsItu601FullRange;
1648 else if (str == "itu_709")
1649 return EycsItu709;
1650 return EycsUndefined;
1651 }
1652
getYuvCscStandardEXTString(TYuvCscStandardEXT ycsq)1653 inline const char *getYuvCscStandardEXTString(TYuvCscStandardEXT ycsq)
1654 {
1655 switch (ycsq)
1656 {
1657 case EycsItu601:
1658 return "itu_601";
1659 case EycsItu601FullRange:
1660 return "itu_601_full_range";
1661 case EycsItu709:
1662 return "itu_709";
1663 default:
1664 UNREACHABLE();
1665 return "unknown color space conversion standard";
1666 }
1667 }
1668
getGeometryShaderPrimitiveTypeString(TLayoutPrimitiveType primitiveType)1669 inline const char *getGeometryShaderPrimitiveTypeString(TLayoutPrimitiveType primitiveType)
1670 {
1671 switch (primitiveType)
1672 {
1673 case EptPoints:
1674 return "points";
1675 case EptLines:
1676 return "lines";
1677 case EptTriangles:
1678 return "triangles";
1679 case EptLinesAdjacency:
1680 return "lines_adjacency";
1681 case EptTrianglesAdjacency:
1682 return "triangles_adjacency";
1683 case EptLineStrip:
1684 return "line_strip";
1685 case EptTriangleStrip:
1686 return "triangle_strip";
1687 default:
1688 UNREACHABLE();
1689 return "unknown geometry shader primitive type";
1690 }
1691 }
1692
getTessEvaluationShaderTypeString(TLayoutTessEvaluationType type)1693 inline const char *getTessEvaluationShaderTypeString(TLayoutTessEvaluationType type)
1694 {
1695 switch (type)
1696 {
1697 case EtetTriangles:
1698 return "triangles";
1699 case EtetQuads:
1700 return "quads";
1701 case EtetIsolines:
1702 return "isolines";
1703 case EtetEqualSpacing:
1704 return "equal_spacing";
1705 case EtetFractionalEvenSpacing:
1706 return "fractional_even_spacing";
1707 case EtetFractionalOddSpacing:
1708 return "fractional_odd_spacing";
1709 case EtetCw:
1710 return "cw";
1711 case EtetCcw:
1712 return "ccw";
1713 case EtetPointMode:
1714 return "point_mode";
1715 default:
1716 UNREACHABLE();
1717 return "unknown tessellation evaluation shader variable type";
1718 }
1719 }
1720
1721 } // namespace sh
1722
1723 #endif // COMPILER_TRANSLATOR_BASETYPES_H_
1724