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