• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
IsShadowSampler(TBasicType type)732 inline bool IsShadowSampler(TBasicType type)
733 {
734     switch (type)
735     {
736         case EbtSampler1DShadow:
737         case EbtSampler2DShadow:
738         case EbtSamplerCubeShadow:
739         case EbtSampler1DArrayShadow:
740         case EbtSampler2DArrayShadow:
741         case EbtSamplerCubeArrayShadow:
742         case EbtSampler2DRectShadow:
743             return true;
744         case EbtISampler2D:
745         case EbtISampler3D:
746         case EbtISamplerCube:
747         case EbtISampler2DArray:
748         case EbtISampler2DMS:
749         case EbtISampler2DMSArray:
750         case EbtUSampler2D:
751         case EbtUSampler3D:
752         case EbtUSamplerCube:
753         case EbtUSampler2DArray:
754         case EbtUSampler2DMS:
755         case EbtUSampler2DMSArray:
756         case EbtSampler2D:
757         case EbtSampler3D:
758         case EbtSamplerCube:
759         case EbtSamplerExternalOES:
760         case EbtSamplerExternal2DY2YEXT:
761         case EbtSampler2DRect:
762         case EbtSampler2DArray:
763         case EbtSampler2DMS:
764         case EbtSampler2DMSArray:
765         case EbtSampler1D:
766         case EbtSampler1DArray:
767         case EbtSamplerBuffer:
768         case EbtSamplerCubeArray:
769         case EbtISampler1D:
770         case EbtISampler1DArray:
771         case EbtISampler2DRect:
772         case EbtISamplerBuffer:
773         case EbtISamplerCubeArray:
774         case EbtUSampler1D:
775         case EbtUSampler1DArray:
776         case EbtUSampler2DRect:
777         case EbtUSamplerBuffer:
778         case EbtUSamplerCubeArray:
779         case EbtSamplerVideoWEBGL:
780             return false;
781         default:
782             ASSERT(!IsSampler(type));
783     }
784 
785     return false;
786 }
787 
IsImage2D(TBasicType type)788 inline bool IsImage2D(TBasicType type)
789 {
790     switch (type)
791     {
792         case EbtImage2D:
793         case EbtIImage2D:
794         case EbtUImage2D:
795         case EbtImage2DMS:
796         case EbtIImage2DMS:
797         case EbtUImage2DMS:
798             return true;
799         case EbtImage3D:
800         case EbtIImage3D:
801         case EbtUImage3D:
802         case EbtImage2DArray:
803         case EbtIImage2DArray:
804         case EbtUImage2DArray:
805         case EbtImageCube:
806         case EbtIImageCube:
807         case EbtUImageCube:
808         case EbtImage1D:
809         case EbtIImage1D:
810         case EbtUImage1D:
811         case EbtImage1DArray:
812         case EbtIImage1DArray:
813         case EbtUImage1DArray:
814         case EbtImage2DMSArray:
815         case EbtIImage2DMSArray:
816         case EbtUImage2DMSArray:
817         case EbtImageCubeArray:
818         case EbtIImageCubeArray:
819         case EbtUImageCubeArray:
820         case EbtImageRect:
821         case EbtIImageRect:
822         case EbtUImageRect:
823         case EbtImageBuffer:
824         case EbtIImageBuffer:
825         case EbtUImageBuffer:
826             return false;
827         default:
828             ASSERT(!IsImage(type));
829     }
830 
831     return false;
832 }
833 
IsImage3D(TBasicType type)834 inline bool IsImage3D(TBasicType type)
835 {
836     switch (type)
837     {
838         case EbtImage3D:
839         case EbtIImage3D:
840         case EbtUImage3D:
841             return true;
842         case EbtImage2D:
843         case EbtIImage2D:
844         case EbtUImage2D:
845         case EbtImage2DArray:
846         case EbtIImage2DArray:
847         case EbtUImage2DArray:
848         case EbtImageCube:
849         case EbtIImageCube:
850         case EbtUImageCube:
851         case EbtImage1D:
852         case EbtIImage1D:
853         case EbtUImage1D:
854         case EbtImage1DArray:
855         case EbtIImage1DArray:
856         case EbtUImage1DArray:
857         case EbtImage2DMS:
858         case EbtIImage2DMS:
859         case EbtUImage2DMS:
860         case EbtImage2DMSArray:
861         case EbtIImage2DMSArray:
862         case EbtUImage2DMSArray:
863         case EbtImageCubeArray:
864         case EbtIImageCubeArray:
865         case EbtUImageCubeArray:
866         case EbtImageRect:
867         case EbtIImageRect:
868         case EbtUImageRect:
869         case EbtImageBuffer:
870         case EbtIImageBuffer:
871         case EbtUImageBuffer:
872             return false;
873         default:
874             ASSERT(!IsImage(type));
875     }
876 
877     return false;
878 }
879 
IsImage2DArray(TBasicType type)880 inline bool IsImage2DArray(TBasicType type)
881 {
882     switch (type)
883     {
884         case EbtImage2DArray:
885         case EbtIImage2DArray:
886         case EbtUImage2DArray:
887         case EbtImage2DMSArray:
888         case EbtIImage2DMSArray:
889         case EbtUImage2DMSArray:
890             return true;
891         case EbtImage2D:
892         case EbtIImage2D:
893         case EbtUImage2D:
894         case EbtImage3D:
895         case EbtIImage3D:
896         case EbtUImage3D:
897         case EbtImageCube:
898         case EbtIImageCube:
899         case EbtUImageCube:
900         case EbtImage1D:
901         case EbtIImage1D:
902         case EbtUImage1D:
903         case EbtImage1DArray:
904         case EbtIImage1DArray:
905         case EbtUImage1DArray:
906         case EbtImage2DMS:
907         case EbtIImage2DMS:
908         case EbtUImage2DMS:
909         case EbtImageCubeArray:
910         case EbtIImageCubeArray:
911         case EbtUImageCubeArray:
912         case EbtImageRect:
913         case EbtIImageRect:
914         case EbtUImageRect:
915         case EbtImageBuffer:
916         case EbtIImageBuffer:
917         case EbtUImageBuffer:
918             return false;
919         default:
920             ASSERT(!IsImage(type));
921     }
922 
923     return false;
924 }
925 
IsImageCube(TBasicType type)926 inline bool IsImageCube(TBasicType type)
927 {
928     switch (type)
929     {
930         case EbtImageCube:
931         case EbtIImageCube:
932         case EbtUImageCube:
933             return true;
934         case EbtImage2D:
935         case EbtIImage2D:
936         case EbtUImage2D:
937         case EbtImage3D:
938         case EbtIImage3D:
939         case EbtUImage3D:
940         case EbtImage2DArray:
941         case EbtIImage2DArray:
942         case EbtUImage2DArray:
943         case EbtImage1D:
944         case EbtIImage1D:
945         case EbtUImage1D:
946         case EbtImage1DArray:
947         case EbtIImage1DArray:
948         case EbtUImage1DArray:
949         case EbtImage2DMS:
950         case EbtIImage2DMS:
951         case EbtUImage2DMS:
952         case EbtImage2DMSArray:
953         case EbtIImage2DMSArray:
954         case EbtUImage2DMSArray:
955         case EbtImageCubeArray:
956         case EbtIImageCubeArray:
957         case EbtUImageCubeArray:
958         case EbtImageRect:
959         case EbtIImageRect:
960         case EbtUImageRect:
961         case EbtImageBuffer:
962         case EbtIImageBuffer:
963         case EbtUImageBuffer:
964             return false;
965         default:
966             ASSERT(!IsImage(type));
967     }
968 
969     return false;
970 }
971 
IsInteger(TBasicType type)972 inline bool IsInteger(TBasicType type)
973 {
974     return type == EbtInt || type == EbtUInt;
975 }
976 
SupportsPrecision(TBasicType type)977 inline bool SupportsPrecision(TBasicType type)
978 {
979     return type == EbtFloat || type == EbtInt || type == EbtUInt || IsOpaqueType(type);
980 }
981 
982 //
983 // Qualifiers and built-ins.  These are mainly used to see what can be read
984 // or written, and by the machine dependent translator to know which registers
985 // to allocate variables in.  Since built-ins tend to go to different registers
986 // than varying or uniform, it makes sense they are peers, not sub-classes.
987 //
988 enum TQualifier
989 {
990     EvqTemporary,   // For temporaries (within a function), read/write
991     EvqGlobal,      // For globals read/write
992     EvqConst,       // User defined constants and non-output parameters in functions
993     EvqAttribute,   // Readonly
994     EvqVaryingIn,   // readonly, fragment shaders only
995     EvqVaryingOut,  // vertex shaders only  read/write
996     EvqUniform,     // Readonly, vertex and fragment
997     EvqBuffer,      // read/write, vertex, fragment and compute shader
998     EvqPatch,       // EXT_tessellation_shader storage qualifier
999 
1000     EvqVertexIn,     // Vertex shader input
1001     EvqFragmentOut,  // Fragment shader output
1002     EvqVertexOut,    // Vertex shader output
1003     EvqFragmentIn,   // Fragment shader input
1004 
1005     EvqFragmentInOut,  // EXT_shader_framebuffer_fetch qualifier
1006 
1007     // parameters
1008     EvqIn,
1009     EvqOut,
1010     EvqInOut,
1011     EvqConstReadOnly,
1012 
1013     // built-ins read by vertex shader
1014     EvqInstanceID,
1015     EvqVertexID,
1016 
1017     // built-ins written by vertex shader
1018     EvqPosition,
1019     EvqPointSize,
1020 
1021     EvqDrawID,  // ANGLE_multi_draw
1022 
1023     // built-ins read by fragment shader
1024     EvqFragCoord,
1025     EvqFrontFacing,
1026     EvqPointCoord,
1027     EvqHelperInvocation,
1028 
1029     // built-ins written by fragment shader
1030     EvqFragColor,
1031     EvqFragData,
1032 
1033     EvqFragDepth,     // gl_FragDepth for ESSL300.
1034     EvqFragDepthEXT,  // gl_FragDepthEXT for ESSL100, EXT_frag_depth.
1035 
1036     EvqSecondaryFragColorEXT,  // EXT_blend_func_extended
1037     EvqSecondaryFragDataEXT,   // EXT_blend_func_extended
1038 
1039     EvqViewIDOVR,      // OVR_multiview
1040     EvqViewportIndex,  // gl_ViewportIndex
1041 
1042     EvqClipDistance,  // APPLE_clip_distance/EXT_clip_cull_distance
1043     EvqCullDistance,  // EXT_clip_cull_distance
1044 
1045     // built-ins written by the shader_framebuffer_fetch extension(s)
1046     EvqLastFragColor,
1047     EvqLastFragData,
1048 
1049     // GLSL ES 3.0 vertex output and fragment input
1050     EvqSmooth,         // Incomplete qualifier, smooth is the default
1051     EvqFlat,           // Incomplete qualifier
1052     EvqNoPerspective,  // Incomplete qualifier
1053     EvqCentroid,       // Incomplete qualifier
1054     EvqSample,
1055     EvqSmoothOut,
1056     EvqFlatOut,
1057     EvqNoPerspectiveOut,
1058     EvqCentroidOut,  // Implies smooth
1059     EvqSampleOut,
1060     EvqSmoothIn,
1061     EvqFlatIn,
1062     EvqNoPerspectiveIn,
1063     EvqCentroidIn,  // Implies smooth
1064     EvqSampleIn,
1065 
1066     // GLSL ES 3.0 extension OES_sample_variables
1067     EvqSampleID,
1068     EvqSamplePosition,
1069     EvqSampleMaskIn,
1070     EvqSampleMask,
1071     EvqNumSamples,
1072 
1073     // GLSL ES 3.1 compute shader special variables
1074     EvqShared,
1075     EvqComputeIn,
1076     EvqNumWorkGroups,
1077     EvqWorkGroupSize,
1078     EvqWorkGroupID,
1079     EvqLocalInvocationID,
1080     EvqGlobalInvocationID,
1081     EvqLocalInvocationIndex,
1082 
1083     // GLSL ES 3.1 memory qualifiers
1084     EvqReadOnly,
1085     EvqWriteOnly,
1086     EvqCoherent,
1087     EvqRestrict,
1088     EvqVolatile,
1089 
1090     // GLSL ES 3.1 extension EXT_geometry_shader qualifiers
1091     EvqGeometryIn,
1092     EvqGeometryOut,
1093     EvqPerVertexIn,    // gl_in
1094     EvqPrimitiveIDIn,  // gl_PrimitiveIDIn
1095     EvqInvocationID,   // gl_InvocationID
1096     EvqPrimitiveID,    // gl_PrimitiveID
1097     EvqLayer,          // gl_Layer
1098 
1099     // GLSL ES 3.1 extension EXT_gpu_shader5 qualifiers
1100     EvqPrecise,
1101 
1102     // GLES ES 3.1 extension EXT_tessellation_shader qualifiers
1103     EvqPatchIn,
1104     EvqPatchOut,
1105 
1106     EvqTessControlIn,
1107     EvqTessControlOut,
1108     EvqPerVertexOut,
1109     EvqPatchVerticesIn,
1110     EvqTessLevelOuter,
1111     EvqTessLevelInner,
1112 
1113     EvqTessEvaluationIn,
1114     EvqTessEvaluationOut,
1115     EvqTessCoord,
1116 
1117     // A specialization constant, which is not valid GLSL ES, but is there to support Vulkan output
1118     // generation.  In that case, TLayoutQualifier::location will contain the somewhat equivalent
1119     // constant_id.
1120     EvqSpecConst,
1121 
1122     // end of list
1123     EvqLast
1124 };
1125 
IsQualifierUnspecified(TQualifier qualifier)1126 inline bool IsQualifierUnspecified(TQualifier qualifier)
1127 {
1128     return (qualifier == EvqTemporary || qualifier == EvqGlobal);
1129 }
1130 
IsStorageBuffer(TQualifier qualifier)1131 inline bool IsStorageBuffer(TQualifier qualifier)
1132 {
1133     return qualifier == EvqBuffer;
1134 }
1135 
IsShaderIn(TQualifier qualifier)1136 inline bool IsShaderIn(TQualifier qualifier)
1137 {
1138     switch (qualifier)
1139     {
1140         case EvqVertexIn:
1141         case EvqTessControlIn:
1142         case EvqTessEvaluationIn:
1143         case EvqGeometryIn:
1144         case EvqFragmentIn:
1145         case EvqPerVertexIn:
1146         case EvqAttribute:
1147         case EvqVaryingIn:
1148         case EvqSmoothIn:
1149         case EvqFlatIn:
1150         case EvqNoPerspectiveIn:
1151         case EvqCentroidIn:
1152         case EvqSampleIn:
1153         case EvqPatchIn:
1154             return true;
1155         default:
1156             return false;
1157     }
1158 }
1159 
IsShaderOut(TQualifier qualifier)1160 inline bool IsShaderOut(TQualifier qualifier)
1161 {
1162     switch (qualifier)
1163     {
1164         case EvqVertexOut:
1165         case EvqTessControlOut:
1166         case EvqTessEvaluationOut:
1167         case EvqGeometryOut:
1168         case EvqFragmentOut:
1169         case EvqPerVertexOut:
1170         case EvqVaryingOut:
1171         case EvqSmoothOut:
1172         case EvqFlatOut:
1173         case EvqNoPerspectiveOut:
1174         case EvqCentroidOut:
1175         case EvqSampleOut:
1176         case EvqPatchOut:
1177         case EvqFragmentInOut:
1178         // Per-vertex built-ins when used without gl_in or gl_out are always output.
1179         case EvqPosition:
1180         case EvqPointSize:
1181         case EvqClipDistance:
1182         case EvqCullDistance:
1183             return true;
1184         default:
1185             return false;
1186     }
1187 }
1188 
IsShaderIoBlock(TQualifier qualifier)1189 inline bool IsShaderIoBlock(TQualifier qualifier)
1190 {
1191     switch (qualifier)
1192     {
1193         case EvqPerVertexIn:
1194         case EvqPerVertexOut:
1195         case EvqVertexOut:
1196         case EvqTessControlIn:
1197         case EvqTessControlOut:
1198         case EvqTessEvaluationIn:
1199         case EvqTessEvaluationOut:
1200         case EvqGeometryIn:
1201         case EvqGeometryOut:
1202         case EvqFragmentIn:
1203             return true;
1204         default:
1205             return false;
1206     }
1207 }
1208 
1209 enum TLayoutImageInternalFormat
1210 {
1211     EiifUnspecified,
1212     EiifRGBA32F,
1213     EiifRGBA16F,
1214     EiifR32F,
1215     EiifRGBA32UI,
1216     EiifRGBA16UI,
1217     EiifRGBA8UI,
1218     EiifR32UI,
1219     EiifRGBA32I,
1220     EiifRGBA16I,
1221     EiifRGBA8I,
1222     EiifR32I,
1223     EiifRGBA8,
1224     EiifRGBA8_SNORM,
1225 
1226     EiifLast = EiifRGBA8_SNORM,
1227 };
1228 
1229 enum TLayoutMatrixPacking
1230 {
1231     EmpUnspecified,
1232     EmpRowMajor,
1233     EmpColumnMajor,
1234 
1235     EmpLast = EmpColumnMajor,
1236 };
1237 
1238 enum TLayoutBlockStorage
1239 {
1240     EbsUnspecified,
1241     EbsShared,
1242     EbsPacked,
1243     EbsStd140,
1244     EbsStd430,
1245 
1246     EbsLast = EbsStd430,
1247 };
1248 
1249 enum TYuvCscStandardEXT
1250 {
1251     EycsUndefined,
1252     EycsItu601,
1253     EycsItu601FullRange,
1254     EycsItu709
1255 };
1256 
1257 enum TLayoutPrimitiveType
1258 {
1259     EptUndefined,
1260     EptPoints,
1261     EptLines,
1262     EptLinesAdjacency,
1263     EptTriangles,
1264     EptTrianglesAdjacency,
1265     EptLineStrip,
1266     EptTriangleStrip
1267 };
1268 
1269 enum TLayoutTessEvaluationType
1270 {
1271     EtetUndefined,
1272     EtetTriangles,
1273     EtetQuads,
1274     EtetIsolines,
1275     EtetEqualSpacing,
1276     EtetFractionalEvenSpacing,
1277     EtetFractionalOddSpacing,
1278     EtetCw,
1279     EtetCcw,
1280     EtetPointMode
1281 };
1282 
1283 struct TLayoutQualifier
1284 {
1285     // Must have a trivial default constructor since it is used in YYSTYPE.
1286     TLayoutQualifier() = default;
1287 
CreateTLayoutQualifier1288     constexpr static TLayoutQualifier Create() { return TLayoutQualifier(0); }
1289 
isEmptyTLayoutQualifier1290     bool isEmpty() const
1291     {
1292         return location == -1 && binding == -1 && offset == -1 && numViews == -1 && yuv == false &&
1293                earlyFragmentTests == false && matrixPacking == EmpUnspecified &&
1294                blockStorage == EbsUnspecified && !localSize.isAnyValueSet() &&
1295                imageInternalFormat == EiifUnspecified && primitiveType == EptUndefined &&
1296                invocations == 0 && maxVertices == -1 && vertices == 0 &&
1297                tesPrimitiveType == EtetUndefined && tesVertexSpacingType == EtetUndefined &&
1298                tesOrderingType == EtetUndefined && tesPointType == EtetUndefined && index == -1 &&
1299                inputAttachmentIndex == -1 && noncoherent == false;
1300     }
1301 
isCombinationValidTLayoutQualifier1302     bool isCombinationValid() const
1303     {
1304         bool workGroupSizeSpecified = localSize.isAnyValueSet();
1305         bool numViewsSet            = (numViews != -1);
1306         bool geometryShaderSpecified =
1307             (primitiveType != EptUndefined) || (invocations != 0) || (maxVertices != -1);
1308         bool subpassInputSpecified = (inputAttachmentIndex != -1);
1309         bool otherLayoutQualifiersSpecified =
1310             (location != -1 || binding != -1 || index != -1 || matrixPacking != EmpUnspecified ||
1311              blockStorage != EbsUnspecified || imageInternalFormat != EiifUnspecified);
1312 
1313         // we can have either the work group size specified, or number of views,
1314         // or yuv layout qualifier, or early_fragment_tests layout qualifier, or the other layout
1315         // qualifiers.
1316         return (workGroupSizeSpecified ? 1 : 0) + (numViewsSet ? 1 : 0) + (yuv ? 1 : 0) +
1317                    (earlyFragmentTests ? 1 : 0) + (otherLayoutQualifiersSpecified ? 1 : 0) +
1318                    (geometryShaderSpecified ? 1 : 0) + (subpassInputSpecified ? 1 : 0) +
1319                    (noncoherent ? 1 : 0) <=
1320                1;
1321     }
1322 
isLocalSizeEqualTLayoutQualifier1323     bool isLocalSizeEqual(const WorkGroupSize &localSizeIn) const
1324     {
1325         return localSize.isWorkGroupSizeMatching(localSizeIn);
1326     }
1327 
1328     int location;
1329     unsigned int locationsSpecified;
1330     TLayoutMatrixPacking matrixPacking;
1331     TLayoutBlockStorage blockStorage;
1332 
1333     // Compute shader layout qualifiers.
1334     WorkGroupSize localSize;
1335 
1336     int binding;
1337     int offset;
1338 
1339     // Image format layout qualifier
1340     TLayoutImageInternalFormat imageInternalFormat;
1341 
1342     // OVR_multiview num_views.
1343     int numViews;
1344 
1345     // EXT_YUV_target yuv layout qualifier.
1346     bool yuv;
1347 
1348     // early_fragment_tests qualifier.
1349     bool earlyFragmentTests;
1350 
1351     // OES_geometry_shader layout qualifiers.
1352     TLayoutPrimitiveType primitiveType;
1353     int invocations;
1354     int maxVertices;
1355 
1356     // EXT_tessellation_shader shader layout qualifiers
1357     int vertices;
1358     TLayoutTessEvaluationType tesPrimitiveType;
1359     TLayoutTessEvaluationType tesVertexSpacingType;
1360     TLayoutTessEvaluationType tesOrderingType;
1361     TLayoutTessEvaluationType tesPointType;
1362 
1363     // EXT_blend_func_extended fragment output layout qualifier
1364     int index;
1365 
1366     // EXT_shader_framebuffer_fetch layout qualifiers.
1367     int inputAttachmentIndex;
1368     bool noncoherent;
1369 
1370   private:
TLayoutQualifierTLayoutQualifier1371     explicit constexpr TLayoutQualifier(int /*placeholder*/)
1372         : location(-1),
1373           locationsSpecified(0),
1374           matrixPacking(EmpUnspecified),
1375           blockStorage(EbsUnspecified),
1376           localSize(-1),
1377           binding(-1),
1378           offset(-1),
1379           imageInternalFormat(EiifUnspecified),
1380           numViews(-1),
1381           yuv(false),
1382           earlyFragmentTests(false),
1383           primitiveType(EptUndefined),
1384           invocations(0),
1385           maxVertices(-1),
1386           vertices(0),
1387           tesPrimitiveType(EtetUndefined),
1388           tesVertexSpacingType(EtetUndefined),
1389           tesOrderingType(EtetUndefined),
1390           tesPointType(EtetUndefined),
1391           index(-1),
1392           inputAttachmentIndex(-1),
1393           noncoherent(false)
1394     {}
1395 };
1396 
1397 struct TMemoryQualifier
1398 {
1399     // Must have a trivial default constructor since it is used in YYSTYPE.
1400     TMemoryQualifier() = default;
1401 
isEmptyTMemoryQualifier1402     bool isEmpty() const
1403     {
1404         return !readonly && !writeonly && !coherent && !restrictQualifier && !volatileQualifier;
1405     }
1406 
CreateTMemoryQualifier1407     constexpr static TMemoryQualifier Create() { return TMemoryQualifier(0); }
1408 
1409     // GLSL ES 3.10 Revision 4, 4.9 Memory Access Qualifiers
1410     // An image can be qualified as both readonly and writeonly. It still can be can be used with
1411     // imageSize().
1412     bool readonly;
1413     bool writeonly;
1414     bool coherent;
1415 
1416     // restrict and volatile are reserved keywords in C/C++
1417     bool restrictQualifier;
1418     bool volatileQualifier;
1419 
1420   private:
TMemoryQualifierTMemoryQualifier1421     explicit constexpr TMemoryQualifier(int /*placeholder*/)
1422         : readonly(false),
1423           writeonly(false),
1424           coherent(false),
1425           restrictQualifier(false),
1426           volatileQualifier(false)
1427     {}
1428 };
1429 
getWorkGroupSizeString(size_t dimension)1430 inline const char *getWorkGroupSizeString(size_t dimension)
1431 {
1432     switch (dimension)
1433     {
1434         case 0u:
1435             return "local_size_x";
1436         case 1u:
1437             return "local_size_y";
1438         case 2u:
1439             return "local_size_z";
1440         default:
1441             UNREACHABLE();
1442             return "dimension out of bounds";
1443     }
1444 }
1445 
1446 //
1447 // This is just for debug and error message print out, carried along with the definitions above.
1448 //
getQualifierString(TQualifier q)1449 inline const char *getQualifierString(TQualifier q)
1450 {
1451     // clang-format off
1452     switch(q)
1453     {
1454     case EvqTemporary:              return "Temporary";
1455     case EvqGlobal:                 return "Global";
1456     case EvqConst:                  return "const";
1457     case EvqAttribute:              return "attribute";
1458     case EvqVaryingIn:              return "varying";
1459     case EvqVaryingOut:             return "varying";
1460     case EvqUniform:                return "uniform";
1461     case EvqBuffer:                 return "buffer";
1462     case EvqPatch:                  return "patch";
1463     case EvqVertexIn:               return "in";
1464     case EvqFragmentOut:            return "out";
1465     case EvqVertexOut:              return "out";
1466     case EvqFragmentIn:             return "in";
1467     case EvqIn:                     return "in";
1468     case EvqOut:                    return "out";
1469     case EvqInOut:                  return "inout";
1470     case EvqConstReadOnly:          return "const";
1471     case EvqInstanceID:             return "InstanceID";
1472     case EvqVertexID:               return "VertexID";
1473     case EvqPosition:               return "Position";
1474     case EvqPointSize:              return "PointSize";
1475     case EvqDrawID:                 return "DrawID";
1476     case EvqFragCoord:              return "FragCoord";
1477     case EvqFrontFacing:            return "FrontFacing";
1478     case EvqHelperInvocation:       return "HelperInvocation";
1479     case EvqPointCoord:             return "PointCoord";
1480     case EvqFragColor:              return "FragColor";
1481     case EvqFragData:               return "FragData";
1482     case EvqFragDepthEXT:           return "FragDepth";
1483     case EvqFragDepth:              return "FragDepth";
1484     case EvqSecondaryFragColorEXT:  return "SecondaryFragColorEXT";
1485     case EvqSecondaryFragDataEXT:   return "SecondaryFragDataEXT";
1486     case EvqViewIDOVR:              return "ViewIDOVR";
1487     case EvqViewportIndex:          return "ViewportIndex";
1488     case EvqLayer:                  return "Layer";
1489     case EvqLastFragColor:          return "LastFragColor";
1490     case EvqLastFragData:           return "LastFragData";
1491     case EvqFragmentInOut:          return "inout";
1492     case EvqSmoothOut:              return "smooth out";
1493     case EvqCentroidOut:            return "smooth centroid out";
1494     case EvqFlatOut:                return "flat out";
1495     case EvqNoPerspectiveOut:       return "noperspective out";
1496     case EvqSmoothIn:               return "smooth in";
1497     case EvqFlatIn:                 return "flat in";
1498     case EvqNoPerspectiveIn:        return "noperspective in";
1499     case EvqCentroidIn:             return "smooth centroid in";
1500     case EvqCentroid:               return "centroid";
1501     case EvqFlat:                   return "flat";
1502     case EvqNoPerspective:          return "noperspective";
1503     case EvqSmooth:                 return "smooth";
1504     case EvqShared:                 return "shared";
1505     case EvqComputeIn:              return "in";
1506     case EvqNumWorkGroups:          return "NumWorkGroups";
1507     case EvqWorkGroupSize:          return "WorkGroupSize";
1508     case EvqWorkGroupID:            return "WorkGroupID";
1509     case EvqLocalInvocationID:      return "LocalInvocationID";
1510     case EvqGlobalInvocationID:     return "GlobalInvocationID";
1511     case EvqLocalInvocationIndex:   return "LocalInvocationIndex";
1512     case EvqReadOnly:               return "readonly";
1513     case EvqWriteOnly:              return "writeonly";
1514     case EvqGeometryIn:             return "in";
1515     case EvqGeometryOut:            return "out";
1516     case EvqPerVertexIn:            return "gl_in";
1517     case EvqPrimitiveIDIn:          return "gl_PrimitiveIDIn";
1518     case EvqInvocationID:           return "gl_InvocationID";
1519     case EvqPrimitiveID:            return "gl_PrimitiveID";
1520     case EvqPrecise:                return "precise";
1521     case EvqClipDistance:           return "ClipDistance";
1522     case EvqSample:                 return "sample";
1523     case EvqSampleIn:               return "sample in";
1524     case EvqSampleOut:              return "sample out";
1525     case EvqSampleID:               return "SampleID";
1526     case EvqSamplePosition:         return "SamplePosition";
1527     case EvqSampleMaskIn:           return "SampleMaskIn";
1528     case EvqSampleMask:             return "SampleMask";
1529     case EvqNumSamples:             return "NumSamples";
1530     case EvqPatchIn:                return "patch in";
1531     case EvqPatchOut:               return "patch out";
1532     case EvqTessControlIn:          return "in";
1533     case EvqTessControlOut:         return "out";
1534     case EvqPerVertexOut:           return "gl_out";
1535     case EvqPatchVerticesIn:        return "PatchVerticesIn";
1536     case EvqTessLevelOuter:         return "TessLevelOuter";
1537     case EvqTessLevelInner:         return "TessLevelInner";
1538     case EvqTessEvaluationIn:       return "in";
1539     case EvqTessEvaluationOut:      return "out";
1540     case EvqTessCoord:              return "TessCoord";
1541     case EvqSpecConst:              return "const";
1542     default: UNREACHABLE();         return "unknown qualifier";
1543     }
1544     // clang-format on
1545 }
1546 
getMatrixPackingString(TLayoutMatrixPacking mpq)1547 inline const char *getMatrixPackingString(TLayoutMatrixPacking mpq)
1548 {
1549     switch (mpq)
1550     {
1551         case EmpUnspecified:
1552             return "mp_unspecified";
1553         case EmpRowMajor:
1554             return "row_major";
1555         case EmpColumnMajor:
1556             return "column_major";
1557         default:
1558             UNREACHABLE();
1559             return "unknown matrix packing";
1560     }
1561 }
1562 
getBlockStorageString(TLayoutBlockStorage bsq)1563 inline const char *getBlockStorageString(TLayoutBlockStorage bsq)
1564 {
1565     switch (bsq)
1566     {
1567         case EbsUnspecified:
1568             return "bs_unspecified";
1569         case EbsShared:
1570             return "shared";
1571         case EbsPacked:
1572             return "packed";
1573         case EbsStd140:
1574             return "std140";
1575         case EbsStd430:
1576             return "std430";
1577         default:
1578             UNREACHABLE();
1579             return "unknown block storage";
1580     }
1581 }
1582 
getImageInternalFormatString(TLayoutImageInternalFormat iifq)1583 inline const char *getImageInternalFormatString(TLayoutImageInternalFormat iifq)
1584 {
1585     switch (iifq)
1586     {
1587         case EiifRGBA32F:
1588             return "rgba32f";
1589         case EiifRGBA16F:
1590             return "rgba16f";
1591         case EiifR32F:
1592             return "r32f";
1593         case EiifRGBA32UI:
1594             return "rgba32ui";
1595         case EiifRGBA16UI:
1596             return "rgba16ui";
1597         case EiifRGBA8UI:
1598             return "rgba8ui";
1599         case EiifR32UI:
1600             return "r32ui";
1601         case EiifRGBA32I:
1602             return "rgba32i";
1603         case EiifRGBA16I:
1604             return "rgba16i";
1605         case EiifRGBA8I:
1606             return "rgba8i";
1607         case EiifR32I:
1608             return "r32i";
1609         case EiifRGBA8:
1610             return "rgba8";
1611         case EiifRGBA8_SNORM:
1612             return "rgba8_snorm";
1613         default:
1614             UNREACHABLE();
1615             return "unknown internal image format";
1616     }
1617 }
1618 
getYuvCscStandardEXT(const ImmutableString & str)1619 inline TYuvCscStandardEXT getYuvCscStandardEXT(const ImmutableString &str)
1620 {
1621     if (str == "itu_601")
1622         return EycsItu601;
1623     else if (str == "itu_601_full_range")
1624         return EycsItu601FullRange;
1625     else if (str == "itu_709")
1626         return EycsItu709;
1627     return EycsUndefined;
1628 }
1629 
getYuvCscStandardEXTString(TYuvCscStandardEXT ycsq)1630 inline const char *getYuvCscStandardEXTString(TYuvCscStandardEXT ycsq)
1631 {
1632     switch (ycsq)
1633     {
1634         case EycsItu601:
1635             return "itu_601";
1636         case EycsItu601FullRange:
1637             return "itu_601_full_range";
1638         case EycsItu709:
1639             return "itu_709";
1640         default:
1641             UNREACHABLE();
1642             return "unknown color space conversion standard";
1643     }
1644 }
1645 
getGeometryShaderPrimitiveTypeString(TLayoutPrimitiveType primitiveType)1646 inline const char *getGeometryShaderPrimitiveTypeString(TLayoutPrimitiveType primitiveType)
1647 {
1648     switch (primitiveType)
1649     {
1650         case EptPoints:
1651             return "points";
1652         case EptLines:
1653             return "lines";
1654         case EptTriangles:
1655             return "triangles";
1656         case EptLinesAdjacency:
1657             return "lines_adjacency";
1658         case EptTrianglesAdjacency:
1659             return "triangles_adjacency";
1660         case EptLineStrip:
1661             return "line_strip";
1662         case EptTriangleStrip:
1663             return "triangle_strip";
1664         default:
1665             UNREACHABLE();
1666             return "unknown geometry shader primitive type";
1667     }
1668 }
1669 
getTessEvaluationShaderTypeString(TLayoutTessEvaluationType type)1670 inline const char *getTessEvaluationShaderTypeString(TLayoutTessEvaluationType type)
1671 {
1672     switch (type)
1673     {
1674         case EtetTriangles:
1675             return "triangles";
1676         case EtetQuads:
1677             return "quads";
1678         case EtetIsolines:
1679             return "isolines";
1680         case EtetEqualSpacing:
1681             return "equal_spacing";
1682         case EtetFractionalEvenSpacing:
1683             return "fractional_even_spacing";
1684         case EtetFractionalOddSpacing:
1685             return "fractional_odd_spacing";
1686         case EtetCw:
1687             return "cw";
1688         case EtetCcw:
1689             return "ccw";
1690         case EtetPointMode:
1691             return "point_mode";
1692         default:
1693             UNREACHABLE();
1694             return "unknown tessellation evaluation shader variable type";
1695     }
1696 }
1697 
1698 }  // namespace sh
1699 
1700 #endif  // COMPILER_TRANSLATOR_BASETYPES_H_
1701