1 //
2 // Copyright (C) 2002-2005  3Dlabs Inc. Ltd.
3 // Copyright (C) 2012-2016 LunarG, Inc.
4 // Copyright (C) 2015-2020 Google, Inc.
5 // Copyright (C) 2017 ARM Limited.
6 // Modifications Copyright (C) 2020-2021 Advanced Micro Devices, Inc. All rights reserved.
7 //
8 // All rights reserved.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions
12 // are met:
13 //
14 //    Redistributions of source code must retain the above copyright
15 //    notice, this list of conditions and the following disclaimer.
16 //
17 //    Redistributions in binary form must reproduce the above
18 //    copyright notice, this list of conditions and the following
19 //    disclaimer in the documentation and/or other materials provided
20 //    with the distribution.
21 //
22 //    Neither the name of 3Dlabs Inc. Ltd. nor the names of its
23 //    contributors may be used to endorse or promote products derived
24 //    from this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 // POSSIBILITY OF SUCH DAMAGE.
38 //
39 
40 //
41 // Create strings that declare built-in definitions, add built-ins programmatically
42 // that cannot be expressed in the strings, and establish mappings between
43 // built-in functions and operators.
44 //
45 // Where to put a built-in:
46 //   TBuiltIns::initialize(version,profile)       context-independent textual built-ins; add them to the right string
47 //   TBuiltIns::initialize(resources,...)         context-dependent textual built-ins; add them to the right string
48 //   TBuiltIns::identifyBuiltIns(...,symbolTable) context-independent programmatic additions/mappings to the symbol table,
49 //                                                including identifying what extensions are needed if a version does not allow a symbol
50 //   TBuiltIns::identifyBuiltIns(...,symbolTable, resources) context-dependent programmatic additions/mappings to the symbol table,
51 //                                                including identifying what extensions are needed if a version does not allow a symbol
52 //
53 
54 #include "../Include/intermediate.h"
55 #include "Initialize.h"
56 
57 namespace glslang {
58 
59 // TODO: ARB_Compatability: do full extension support
60 const bool ARBCompatibility = true;
61 
62 const bool ForwardCompatibility = false;
63 
64 // change this back to false if depending on textual spellings of texturing calls when consuming the AST
65 // Using PureOperatorBuiltins=false is deprecated.
66 bool PureOperatorBuiltins = true;
67 
68 namespace {
69 
70 //
71 // A set of definitions for tabling of the built-in functions.
72 //
73 
74 // Order matters here, as does correlation with the subsequent
75 // "const int ..." declarations and the ArgType enumerants.
76 const char* TypeString[] = {
77    "bool",  "bvec2", "bvec3", "bvec4",
78    "float",  "vec2",  "vec3",  "vec4",
79    "int",   "ivec2", "ivec3", "ivec4",
80    "uint",  "uvec2", "uvec3", "uvec4",
81 };
82 const int TypeStringCount = sizeof(TypeString) / sizeof(char*); // number of entries in 'TypeString'
83 const int TypeStringRowShift = 2;                               // shift amount to go downe one row in 'TypeString'
84 const int TypeStringColumnMask = (1 << TypeStringRowShift) - 1; // reduce type to its column number in 'TypeString'
85 const int TypeStringScalarMask = ~TypeStringColumnMask;         // take type to its scalar column in 'TypeString'
86 
87 enum ArgType {
88     // numbers hardcoded to correspond to 'TypeString'; order and value matter
89     TypeB    = 1 << 0,  // Boolean
90     TypeF    = 1 << 1,  // float 32
91     TypeI    = 1 << 2,  // int 32
92     TypeU    = 1 << 3,  // uint 32
93     TypeF16  = 1 << 4,  // float 16
94     TypeF64  = 1 << 5,  // float 64
95     TypeI8   = 1 << 6,  // int 8
96     TypeI16  = 1 << 7,  // int 16
97     TypeI64  = 1 << 8,  // int 64
98     TypeU8   = 1 << 9,  // uint 8
99     TypeU16  = 1 << 10, // uint 16
100     TypeU64  = 1 << 11, // uint 64
101 };
102 // Mixtures of the above, to help the function tables
103 const ArgType TypeFI  = static_cast<ArgType>(TypeF | TypeI);
104 const ArgType TypeFIB = static_cast<ArgType>(TypeF | TypeI | TypeB);
105 const ArgType TypeIU  = static_cast<ArgType>(TypeI | TypeU);
106 
107 // The relationships between arguments and return type, whether anything is
108 // output, or other unusual situations.
109 enum ArgClass {
110     ClassRegular     = 0,  // nothing special, just all vector widths with matching return type; traditional arithmetic
111     ClassLS     = 1 << 0,  // the last argument is also held fixed as a (type-matched) scalar while the others cycle
112     ClassXLS    = 1 << 1,  // the last argument is exclusively a (type-matched) scalar while the others cycle
113     ClassLS2    = 1 << 2,  // the last two arguments are held fixed as a (type-matched) scalar while the others cycle
114     ClassFS     = 1 << 3,  // the first argument is held fixed as a (type-matched) scalar while the others cycle
115     ClassFS2    = 1 << 4,  // the first two arguments are held fixed as a (type-matched) scalar while the others cycle
116     ClassLO     = 1 << 5,  // the last argument is an output
117     ClassB      = 1 << 6,  // return type cycles through only bool/bvec, matching vector width of args
118     ClassLB     = 1 << 7,  // last argument cycles through only bool/bvec, matching vector width of args
119     ClassV1     = 1 << 8,  // scalar only
120     ClassFIO    = 1 << 9,  // first argument is inout
121     ClassRS     = 1 << 10, // the return is held scalar as the arguments cycle
122     ClassNS     = 1 << 11, // no scalar prototype
123     ClassCV     = 1 << 12, // first argument is 'coherent volatile'
124     ClassFO     = 1 << 13, // first argument is output
125     ClassV3     = 1 << 14, // vec3 only
126 };
127 // Mixtures of the above, to help the function tables
128 const ArgClass ClassV1FIOCV = (ArgClass)(ClassV1 | ClassFIO | ClassCV);
129 const ArgClass ClassBNS     = (ArgClass)(ClassB  | ClassNS);
130 const ArgClass ClassRSNS    = (ArgClass)(ClassRS | ClassNS);
131 
132 // A descriptor, for a single profile, of when something is available.
133 // If the current profile does not match 'profile' mask below, the other fields
134 // do not apply (nor validate).
135 // profiles == EBadProfile is the end of an array of these
136 struct Versioning {
137     EProfile profiles;       // the profile(s) (mask) that the following fields are valid for
138     int minExtendedVersion;  // earliest version when extensions are enabled; ignored if numExtensions is 0
139     int minCoreVersion;      // earliest version function is in core; 0 means never
140     int numExtensions;       // how many extensions are in the 'extensions' list
141     const char** extensions; // list of extension names enabling the function
142 };
143 
144 EProfile EDesktopProfile = static_cast<EProfile>(ENoProfile | ECoreProfile | ECompatibilityProfile);
145 
146 // Declare pointers to put into the table for versioning.
147 #ifdef GLSLANG_WEB
148     const Versioning* Es300Desktop130 = nullptr;
149     const Versioning* Es310Desktop420 = nullptr;
150 #elif defined(GLSLANG_ANGLE)
151     const Versioning* Es300Desktop130 = nullptr;
152     const Versioning* Es310Desktop420 = nullptr;
153     const Versioning* Es310Desktop450 = nullptr;
154 #else
155     const Versioning Es300Desktop130Version[] = { { EEsProfile,      0, 300, 0, nullptr },
156                                                   { EDesktopProfile, 0, 130, 0, nullptr },
157                                                   { EBadProfile } };
158     const Versioning* Es300Desktop130 = &Es300Desktop130Version[0];
159 
160     const Versioning Es310Desktop420Version[] = { { EEsProfile,      0, 310, 0, nullptr },
161                                                   { EDesktopProfile, 0, 420, 0, nullptr },
162                                                   { EBadProfile } };
163     const Versioning* Es310Desktop420 = &Es310Desktop420Version[0];
164 
165     const Versioning Es310Desktop450Version[] = { { EEsProfile,      0, 310, 0, nullptr },
166                                                   { EDesktopProfile, 0, 450, 0, nullptr },
167                                                   { EBadProfile } };
168     const Versioning* Es310Desktop450 = &Es310Desktop450Version[0];
169 #endif
170 
171 // The main descriptor of what a set of function prototypes can look like, and
172 // a pointer to extra versioning information, when needed.
173 struct BuiltInFunction {
174     TOperator op;                 // operator to map the name to
175     const char* name;             // function name
176     int numArguments;             // number of arguments (overloads with varying arguments need different entries)
177     ArgType types;                // ArgType mask
178     ArgClass classes;             // the ways this particular function entry manifests
179     const Versioning* versioning; // nullptr means always a valid version
180 };
181 
182 // The tables can have the same built-in function name more than one time,
183 // but the exact same prototype must be indicated at most once.
184 // The prototypes that get declared are the union of all those indicated.
185 // This is important when different releases add new prototypes for the same name.
186 // It also also congnitively simpler tiling of the prototype space.
187 // In practice, most names can be fully represented with one entry.
188 //
189 // Table is terminated by an OpNull TOperator.
190 
191 const BuiltInFunction BaseFunctions[] = {
192 //    TOperator,           name,       arg-count,   ArgType,   ArgClass,     versioning
193 //    ---------            ----        ---------    -------    --------      ----------
194     { EOpRadians,          "radians",          1,   TypeF,     ClassRegular, nullptr },
195     { EOpDegrees,          "degrees",          1,   TypeF,     ClassRegular, nullptr },
196     { EOpSin,              "sin",              1,   TypeF,     ClassRegular, nullptr },
197     { EOpCos,              "cos",              1,   TypeF,     ClassRegular, nullptr },
198     { EOpTan,              "tan",              1,   TypeF,     ClassRegular, nullptr },
199     { EOpAsin,             "asin",             1,   TypeF,     ClassRegular, nullptr },
200     { EOpAcos,             "acos",             1,   TypeF,     ClassRegular, nullptr },
201     { EOpAtan,             "atan",             2,   TypeF,     ClassRegular, nullptr },
202     { EOpAtan,             "atan",             1,   TypeF,     ClassRegular, nullptr },
203     { EOpPow,              "pow",              2,   TypeF,     ClassRegular, nullptr },
204     { EOpExp,              "exp",              1,   TypeF,     ClassRegular, nullptr },
205     { EOpLog,              "log",              1,   TypeF,     ClassRegular, nullptr },
206     { EOpExp2,             "exp2",             1,   TypeF,     ClassRegular, nullptr },
207     { EOpLog2,             "log2",             1,   TypeF,     ClassRegular, nullptr },
208     { EOpSqrt,             "sqrt",             1,   TypeF,     ClassRegular, nullptr },
209     { EOpInverseSqrt,      "inversesqrt",      1,   TypeF,     ClassRegular, nullptr },
210     { EOpAbs,              "abs",              1,   TypeF,     ClassRegular, nullptr },
211     { EOpSign,             "sign",             1,   TypeF,     ClassRegular, nullptr },
212     { EOpFloor,            "floor",            1,   TypeF,     ClassRegular, nullptr },
213     { EOpCeil,             "ceil",             1,   TypeF,     ClassRegular, nullptr },
214     { EOpFract,            "fract",            1,   TypeF,     ClassRegular, nullptr },
215     { EOpMod,              "mod",              2,   TypeF,     ClassLS,      nullptr },
216     { EOpMin,              "min",              2,   TypeF,     ClassLS,      nullptr },
217     { EOpMax,              "max",              2,   TypeF,     ClassLS,      nullptr },
218     { EOpClamp,            "clamp",            3,   TypeF,     ClassLS2,     nullptr },
219     { EOpMix,              "mix",              3,   TypeF,     ClassLS,      nullptr },
220     { EOpStep,             "step",             2,   TypeF,     ClassFS,      nullptr },
221     { EOpSmoothStep,       "smoothstep",       3,   TypeF,     ClassFS2,     nullptr },
222     { EOpNormalize,        "normalize",        1,   TypeF,     ClassRegular, nullptr },
223     { EOpFaceForward,      "faceforward",      3,   TypeF,     ClassRegular, nullptr },
224     { EOpReflect,          "reflect",          2,   TypeF,     ClassRegular, nullptr },
225     { EOpRefract,          "refract",          3,   TypeF,     ClassXLS,     nullptr },
226     { EOpLength,           "length",           1,   TypeF,     ClassRS,      nullptr },
227     { EOpDistance,         "distance",         2,   TypeF,     ClassRS,      nullptr },
228     { EOpDot,              "dot",              2,   TypeF,     ClassRS,      nullptr },
229     { EOpCross,            "cross",            2,   TypeF,     ClassV3,      nullptr },
230     { EOpLessThan,         "lessThan",         2,   TypeFI,    ClassBNS,     nullptr },
231     { EOpLessThanEqual,    "lessThanEqual",    2,   TypeFI,    ClassBNS,     nullptr },
232     { EOpGreaterThan,      "greaterThan",      2,   TypeFI,    ClassBNS,     nullptr },
233     { EOpGreaterThanEqual, "greaterThanEqual", 2,   TypeFI,    ClassBNS,     nullptr },
234     { EOpVectorEqual,      "equal",            2,   TypeFIB,   ClassBNS,     nullptr },
235     { EOpVectorNotEqual,   "notEqual",         2,   TypeFIB,   ClassBNS,     nullptr },
236     { EOpAny,              "any",              1,   TypeB,     ClassRSNS,    nullptr },
237     { EOpAll,              "all",              1,   TypeB,     ClassRSNS,    nullptr },
238     { EOpVectorLogicalNot, "not",              1,   TypeB,     ClassNS,      nullptr },
239     { EOpSinh,             "sinh",             1,   TypeF,     ClassRegular, Es300Desktop130 },
240     { EOpCosh,             "cosh",             1,   TypeF,     ClassRegular, Es300Desktop130 },
241     { EOpTanh,             "tanh",             1,   TypeF,     ClassRegular, Es300Desktop130 },
242     { EOpAsinh,            "asinh",            1,   TypeF,     ClassRegular, Es300Desktop130 },
243     { EOpAcosh,            "acosh",            1,   TypeF,     ClassRegular, Es300Desktop130 },
244     { EOpAtanh,            "atanh",            1,   TypeF,     ClassRegular, Es300Desktop130 },
245     { EOpAbs,              "abs",              1,   TypeI,     ClassRegular, Es300Desktop130 },
246     { EOpSign,             "sign",             1,   TypeI,     ClassRegular, Es300Desktop130 },
247     { EOpTrunc,            "trunc",            1,   TypeF,     ClassRegular, Es300Desktop130 },
248     { EOpRound,            "round",            1,   TypeF,     ClassRegular, Es300Desktop130 },
249     { EOpRoundEven,        "roundEven",        1,   TypeF,     ClassRegular, Es300Desktop130 },
250     { EOpModf,             "modf",             2,   TypeF,     ClassLO,      Es300Desktop130 },
251     { EOpMin,              "min",              2,   TypeIU,    ClassLS,      Es300Desktop130 },
252     { EOpMax,              "max",              2,   TypeIU,    ClassLS,      Es300Desktop130 },
253     { EOpClamp,            "clamp",            3,   TypeIU,    ClassLS2,     Es300Desktop130 },
254     { EOpMix,              "mix",              3,   TypeF,     ClassLB,      Es300Desktop130 },
255     { EOpIsInf,            "isinf",            1,   TypeF,     ClassB,       Es300Desktop130 },
256     { EOpIsNan,            "isnan",            1,   TypeF,     ClassB,       Es300Desktop130 },
257     { EOpLessThan,         "lessThan",         2,   TypeU,     ClassBNS,     Es300Desktop130 },
258     { EOpLessThanEqual,    "lessThanEqual",    2,   TypeU,     ClassBNS,     Es300Desktop130 },
259     { EOpGreaterThan,      "greaterThan",      2,   TypeU,     ClassBNS,     Es300Desktop130 },
260     { EOpGreaterThanEqual, "greaterThanEqual", 2,   TypeU,     ClassBNS,     Es300Desktop130 },
261     { EOpVectorEqual,      "equal",            2,   TypeU,     ClassBNS,     Es300Desktop130 },
262     { EOpVectorNotEqual,   "notEqual",         2,   TypeU,     ClassBNS,     Es300Desktop130 },
263     { EOpAtomicAdd,        "atomicAdd",        2,   TypeIU,    ClassV1FIOCV, Es310Desktop420 },
264     { EOpAtomicMin,        "atomicMin",        2,   TypeIU,    ClassV1FIOCV, Es310Desktop420 },
265     { EOpAtomicMax,        "atomicMax",        2,   TypeIU,    ClassV1FIOCV, Es310Desktop420 },
266     { EOpAtomicAnd,        "atomicAnd",        2,   TypeIU,    ClassV1FIOCV, Es310Desktop420 },
267     { EOpAtomicOr,         "atomicOr",         2,   TypeIU,    ClassV1FIOCV, Es310Desktop420 },
268     { EOpAtomicXor,        "atomicXor",        2,   TypeIU,    ClassV1FIOCV, Es310Desktop420 },
269     { EOpAtomicExchange,   "atomicExchange",   2,   TypeIU,    ClassV1FIOCV, Es310Desktop420 },
270     { EOpAtomicCompSwap,   "atomicCompSwap",   3,   TypeIU,    ClassV1FIOCV, Es310Desktop420 },
271 #ifndef GLSLANG_WEB
272     { EOpMix,              "mix",              3,   TypeB,     ClassRegular, Es310Desktop450 },
273     { EOpMix,              "mix",              3,   TypeIU,    ClassLB,      Es310Desktop450 },
274 #endif
275 
276     { EOpNull }
277 };
278 
279 const BuiltInFunction DerivativeFunctions[] = {
280     { EOpDPdx,             "dFdx",             1,   TypeF,     ClassRegular, nullptr },
281     { EOpDPdy,             "dFdy",             1,   TypeF,     ClassRegular, nullptr },
282     { EOpFwidth,           "fwidth",           1,   TypeF,     ClassRegular, nullptr },
283     { EOpNull }
284 };
285 
286 // For functions declared some other way, but still use the table to relate to operator.
287 struct CustomFunction {
288     TOperator op;                 // operator to map the name to
289     const char* name;             // function name
290     const Versioning* versioning; // nullptr means always a valid version
291 };
292 
293 const CustomFunction CustomFunctions[] = {
294     { EOpBarrier,             "barrier",             nullptr },
295     { EOpMemoryBarrierShared, "memoryBarrierShared", nullptr },
296     { EOpGroupMemoryBarrier,  "groupMemoryBarrier",  nullptr },
297     { EOpMemoryBarrier,       "memoryBarrier",       nullptr },
298     { EOpMemoryBarrierBuffer, "memoryBarrierBuffer", nullptr },
299 
300     { EOpPackSnorm2x16,       "packSnorm2x16",       nullptr },
301     { EOpUnpackSnorm2x16,     "unpackSnorm2x16",     nullptr },
302     { EOpPackUnorm2x16,       "packUnorm2x16",       nullptr },
303     { EOpUnpackUnorm2x16,     "unpackUnorm2x16",     nullptr },
304     { EOpPackHalf2x16,        "packHalf2x16",        nullptr },
305     { EOpUnpackHalf2x16,      "unpackHalf2x16",      nullptr },
306 
307     { EOpMul,                 "matrixCompMult",      nullptr },
308     { EOpOuterProduct,        "outerProduct",        nullptr },
309     { EOpTranspose,           "transpose",           nullptr },
310     { EOpDeterminant,         "determinant",         nullptr },
311     { EOpMatrixInverse,       "inverse",             nullptr },
312     { EOpFloatBitsToInt,      "floatBitsToInt",      nullptr },
313     { EOpFloatBitsToUint,     "floatBitsToUint",     nullptr },
314     { EOpIntBitsToFloat,      "intBitsToFloat",      nullptr },
315     { EOpUintBitsToFloat,     "uintBitsToFloat",     nullptr },
316 
317     { EOpTextureQuerySize,      "textureSize",           nullptr },
318     { EOpTextureQueryLod,       "textureQueryLod",       nullptr },
319     { EOpTextureQueryLevels,    "textureQueryLevels",    nullptr },
320     { EOpTextureQuerySamples,   "textureSamples",        nullptr },
321     { EOpTexture,               "texture",               nullptr },
322     { EOpTextureProj,           "textureProj",           nullptr },
323     { EOpTextureLod,            "textureLod",            nullptr },
324     { EOpTextureOffset,         "textureOffset",         nullptr },
325     { EOpTextureFetch,          "texelFetch",            nullptr },
326     { EOpTextureFetchOffset,    "texelFetchOffset",      nullptr },
327     { EOpTextureProjOffset,     "textureProjOffset",     nullptr },
328     { EOpTextureLodOffset,      "textureLodOffset",      nullptr },
329     { EOpTextureProjLod,        "textureProjLod",        nullptr },
330     { EOpTextureProjLodOffset,  "textureProjLodOffset",  nullptr },
331     { EOpTextureGrad,           "textureGrad",           nullptr },
332     { EOpTextureGradOffset,     "textureGradOffset",     nullptr },
333     { EOpTextureProjGrad,       "textureProjGrad",       nullptr },
334     { EOpTextureProjGradOffset, "textureProjGradOffset", nullptr },
335 
336     { EOpNull }
337 };
338 
339 // For the given table of functions, add all the indicated prototypes for each
340 // one, to be returned in the passed in decls.
AddTabledBuiltin(TString & decls,const BuiltInFunction & function)341 void AddTabledBuiltin(TString& decls, const BuiltInFunction& function)
342 {
343     const auto isScalarType = [](int type) { return (type & TypeStringColumnMask) == 0; };
344 
345     // loop across these two:
346     //  0: the varying arg set, and
347     //  1: the fixed scalar args
348     const ArgClass ClassFixed = (ArgClass)(ClassLS | ClassXLS | ClassLS2 | ClassFS | ClassFS2);
349     for (int fixed = 0; fixed < ((function.classes & ClassFixed) > 0 ? 2 : 1); ++fixed) {
350 
351         if (fixed == 0 && (function.classes & ClassXLS))
352             continue;
353 
354         // walk the type strings in TypeString[]
355         for (int type = 0; type < TypeStringCount; ++type) {
356             // skip types not selected: go from type to row number to type bit
357             if ((function.types & (1 << (type >> TypeStringRowShift))) == 0)
358                 continue;
359 
360             // if we aren't on a scalar, and should be, skip
361             if ((function.classes & ClassV1) && !isScalarType(type))
362                 continue;
363 
364             // if we aren't on a 3-vector, and should be, skip
365             if ((function.classes & ClassV3) && (type & TypeStringColumnMask) != 2)
366                 continue;
367 
368             // skip replication of all arg scalars between the varying arg set and the fixed args
369             if (fixed == 1 && type == (type & TypeStringScalarMask) && (function.classes & ClassXLS) == 0)
370                 continue;
371 
372             // skip scalars when we are told to
373             if ((function.classes & ClassNS) && isScalarType(type))
374                 continue;
375 
376             // return type
377             if (function.classes & ClassB)
378                 decls.append(TypeString[type & TypeStringColumnMask]);
379             else if (function.classes & ClassRS)
380                 decls.append(TypeString[type & TypeStringScalarMask]);
381             else
382                 decls.append(TypeString[type]);
383             decls.append(" ");
384             decls.append(function.name);
385             decls.append("(");
386 
387             // arguments
388             for (int arg = 0; arg < function.numArguments; ++arg) {
389                 if (arg == function.numArguments - 1 && (function.classes & ClassLO))
390                     decls.append("out ");
391                 if (arg == 0) {
392 #ifndef GLSLANG_WEB
393                     if (function.classes & ClassCV)
394                         decls.append("coherent volatile ");
395 #endif
396                     if (function.classes & ClassFIO)
397                         decls.append("inout ");
398                     if (function.classes & ClassFO)
399                         decls.append("out ");
400                 }
401                 if ((function.classes & ClassLB) && arg == function.numArguments - 1)
402                     decls.append(TypeString[type & TypeStringColumnMask]);
403                 else if (fixed && ((arg == function.numArguments - 1 && (function.classes & (ClassLS | ClassXLS |
404                                                                                                        ClassLS2))) ||
405                                    (arg == function.numArguments - 2 && (function.classes & ClassLS2))             ||
406                                    (arg == 0                         && (function.classes & (ClassFS | ClassFS2))) ||
407                                    (arg == 1                         && (function.classes & ClassFS2))))
408                     decls.append(TypeString[type & TypeStringScalarMask]);
409                 else
410                     decls.append(TypeString[type]);
411                 if (arg < function.numArguments - 1)
412                     decls.append(",");
413             }
414             decls.append(");\n");
415         }
416     }
417 }
418 
419 // See if the tabled versioning information allows the current version.
ValidVersion(const BuiltInFunction & function,int version,EProfile profile,const SpvVersion &)420 bool ValidVersion(const BuiltInFunction& function, int version, EProfile profile, const SpvVersion& /* spVersion */)
421 {
422 #if defined(GLSLANG_WEB) || defined(GLSLANG_ANGLE)
423     // all entries in table are valid
424     return true;
425 #endif
426 
427     // nullptr means always valid
428     if (function.versioning == nullptr)
429         return true;
430 
431     // check for what is said about our current profile
432     for (const Versioning* v = function.versioning; v->profiles != EBadProfile; ++v) {
433         if ((v->profiles & profile) != 0) {
434             if (v->minCoreVersion <= version || (v->numExtensions > 0 && v->minExtendedVersion <= version))
435                 return true;
436         }
437     }
438 
439     return false;
440 }
441 
442 // Relate a single table of built-ins to their AST operator.
443 // This can get called redundantly (especially for the common built-ins, when
444 // called once per stage). This is a performance issue only, not a correctness
445 // concern.  It is done for quality arising from simplicity, as there are subtleties
446 // to get correct if instead trying to do it surgically.
447 template<class FunctionT>
RelateTabledBuiltins(const FunctionT * functions,TSymbolTable & symbolTable)448 void RelateTabledBuiltins(const FunctionT* functions, TSymbolTable& symbolTable)
449 {
450     while (functions->op != EOpNull) {
451         symbolTable.relateToOperator(functions->name, functions->op);
452         ++functions;
453     }
454 }
455 
456 } // end anonymous namespace
457 
458 // Add declarations for all tables of built-in functions.
addTabledBuiltins(int version,EProfile profile,const SpvVersion & spvVersion)459 void TBuiltIns::addTabledBuiltins(int version, EProfile profile, const SpvVersion& spvVersion)
460 {
461     const auto forEachFunction = [&](TString& decls, const BuiltInFunction* function) {
462         while (function->op != EOpNull) {
463             if (ValidVersion(*function, version, profile, spvVersion))
464                 AddTabledBuiltin(decls, *function);
465             ++function;
466         }
467     };
468 
469     forEachFunction(commonBuiltins, BaseFunctions);
470     forEachFunction(stageBuiltins[EShLangFragment], DerivativeFunctions);
471 
472     if ((profile == EEsProfile && version >= 320) || (profile != EEsProfile && version >= 450))
473         forEachFunction(stageBuiltins[EShLangCompute], DerivativeFunctions);
474 }
475 
476 // Relate all tables of built-ins to the AST operators.
relateTabledBuiltins(int,EProfile,const SpvVersion &,EShLanguage,TSymbolTable & symbolTable)477 void TBuiltIns::relateTabledBuiltins(int /* version */, EProfile /* profile */, const SpvVersion& /* spvVersion */, EShLanguage /* stage */, TSymbolTable& symbolTable)
478 {
479     RelateTabledBuiltins(BaseFunctions, symbolTable);
480     RelateTabledBuiltins(DerivativeFunctions, symbolTable);
481     RelateTabledBuiltins(CustomFunctions, symbolTable);
482 }
483 
IncludeLegacy(int version,EProfile profile,const SpvVersion & spvVersion)484 inline bool IncludeLegacy(int version, EProfile profile, const SpvVersion& spvVersion)
485 {
486     return profile != EEsProfile && (version <= 130 || (spvVersion.spv == 0 && version == 140 && ARBCompatibility) ||
487            profile == ECompatibilityProfile);
488 }
489 
490 // Construct TBuiltInParseables base class.  This can be used for language-common constructs.
TBuiltInParseables()491 TBuiltInParseables::TBuiltInParseables()
492 {
493 }
494 
495 // Destroy TBuiltInParseables.
~TBuiltInParseables()496 TBuiltInParseables::~TBuiltInParseables()
497 {
498 }
499 
TBuiltIns()500 TBuiltIns::TBuiltIns()
501 {
502     // Set up textual representations for making all the permutations
503     // of texturing/imaging functions.
504     prefixes[EbtFloat] =  "";
505     prefixes[EbtInt]   = "i";
506     prefixes[EbtUint]  = "u";
507 #if !defined(GLSLANG_WEB) && !defined(GLSLANG_ANGLE)
508     prefixes[EbtFloat16] = "f16";
509     prefixes[EbtInt8]  = "i8";
510     prefixes[EbtUint8] = "u8";
511     prefixes[EbtInt16]  = "i16";
512     prefixes[EbtUint16] = "u16";
513     prefixes[EbtInt64]  = "i64";
514     prefixes[EbtUint64] = "u64";
515 #endif
516 
517     postfixes[2] = "2";
518     postfixes[3] = "3";
519     postfixes[4] = "4";
520 
521     // Map from symbolic class of texturing dimension to numeric dimensions.
522     dimMap[Esd2D] = 2;
523     dimMap[Esd3D] = 3;
524     dimMap[EsdCube] = 3;
525 #ifndef GLSLANG_WEB
526 #ifndef GLSLANG_ANGLE
527     dimMap[Esd1D] = 1;
528 #endif
529     dimMap[EsdRect] = 2;
530     dimMap[EsdBuffer] = 1;
531     dimMap[EsdSubpass] = 2;  // potentially unused for now
532 #endif
533 }
534 
~TBuiltIns()535 TBuiltIns::~TBuiltIns()
536 {
537 }
538 
539 
540 //
541 // Add all context-independent built-in functions and variables that are present
542 // for the given version and profile.  Share common ones across stages, otherwise
543 // make stage-specific entries.
544 //
545 // Most built-ins variables can be added as simple text strings.  Some need to
546 // be added programmatically, which is done later in IdentifyBuiltIns() below.
547 //
initialize(int version,EProfile profile,const SpvVersion & spvVersion)548 void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvVersion)
549 {
550 #ifdef GLSLANG_WEB
551     version = 310;
552     profile = EEsProfile;
553 #elif defined(GLSLANG_ANGLE)
554     version = 450;
555     profile = ECoreProfile;
556 #endif
557     addTabledBuiltins(version, profile, spvVersion);
558 
559     //============================================================================
560     //
561     // Prototypes for built-in functions used repeatly by different shaders
562     //
563     //============================================================================
564 
565 #ifndef GLSLANG_WEB
566     //
567     // Derivatives Functions.
568     //
569     TString derivativeControls (
570         "float dFdxFine(float p);"
571         "vec2  dFdxFine(vec2  p);"
572         "vec3  dFdxFine(vec3  p);"
573         "vec4  dFdxFine(vec4  p);"
574 
575         "float dFdyFine(float p);"
576         "vec2  dFdyFine(vec2  p);"
577         "vec3  dFdyFine(vec3  p);"
578         "vec4  dFdyFine(vec4  p);"
579 
580         "float fwidthFine(float p);"
581         "vec2  fwidthFine(vec2  p);"
582         "vec3  fwidthFine(vec3  p);"
583         "vec4  fwidthFine(vec4  p);"
584 
585         "float dFdxCoarse(float p);"
586         "vec2  dFdxCoarse(vec2  p);"
587         "vec3  dFdxCoarse(vec3  p);"
588         "vec4  dFdxCoarse(vec4  p);"
589 
590         "float dFdyCoarse(float p);"
591         "vec2  dFdyCoarse(vec2  p);"
592         "vec3  dFdyCoarse(vec3  p);"
593         "vec4  dFdyCoarse(vec4  p);"
594 
595         "float fwidthCoarse(float p);"
596         "vec2  fwidthCoarse(vec2  p);"
597         "vec3  fwidthCoarse(vec3  p);"
598         "vec4  fwidthCoarse(vec4  p);"
599     );
600 
601 #ifndef GLSLANG_ANGLE
602     TString derivativesAndControl16bits (
603         "float16_t dFdx(float16_t);"
604         "f16vec2   dFdx(f16vec2);"
605         "f16vec3   dFdx(f16vec3);"
606         "f16vec4   dFdx(f16vec4);"
607 
608         "float16_t dFdy(float16_t);"
609         "f16vec2   dFdy(f16vec2);"
610         "f16vec3   dFdy(f16vec3);"
611         "f16vec4   dFdy(f16vec4);"
612 
613         "float16_t dFdxFine(float16_t);"
614         "f16vec2   dFdxFine(f16vec2);"
615         "f16vec3   dFdxFine(f16vec3);"
616         "f16vec4   dFdxFine(f16vec4);"
617 
618         "float16_t dFdyFine(float16_t);"
619         "f16vec2   dFdyFine(f16vec2);"
620         "f16vec3   dFdyFine(f16vec3);"
621         "f16vec4   dFdyFine(f16vec4);"
622 
623         "float16_t dFdxCoarse(float16_t);"
624         "f16vec2   dFdxCoarse(f16vec2);"
625         "f16vec3   dFdxCoarse(f16vec3);"
626         "f16vec4   dFdxCoarse(f16vec4);"
627 
628         "float16_t dFdyCoarse(float16_t);"
629         "f16vec2   dFdyCoarse(f16vec2);"
630         "f16vec3   dFdyCoarse(f16vec3);"
631         "f16vec4   dFdyCoarse(f16vec4);"
632 
633         "float16_t fwidth(float16_t);"
634         "f16vec2   fwidth(f16vec2);"
635         "f16vec3   fwidth(f16vec3);"
636         "f16vec4   fwidth(f16vec4);"
637 
638         "float16_t fwidthFine(float16_t);"
639         "f16vec2   fwidthFine(f16vec2);"
640         "f16vec3   fwidthFine(f16vec3);"
641         "f16vec4   fwidthFine(f16vec4);"
642 
643         "float16_t fwidthCoarse(float16_t);"
644         "f16vec2   fwidthCoarse(f16vec2);"
645         "f16vec3   fwidthCoarse(f16vec3);"
646         "f16vec4   fwidthCoarse(f16vec4);"
647     );
648 
649     TString derivativesAndControl64bits (
650         "float64_t dFdx(float64_t);"
651         "f64vec2   dFdx(f64vec2);"
652         "f64vec3   dFdx(f64vec3);"
653         "f64vec4   dFdx(f64vec4);"
654 
655         "float64_t dFdy(float64_t);"
656         "f64vec2   dFdy(f64vec2);"
657         "f64vec3   dFdy(f64vec3);"
658         "f64vec4   dFdy(f64vec4);"
659 
660         "float64_t dFdxFine(float64_t);"
661         "f64vec2   dFdxFine(f64vec2);"
662         "f64vec3   dFdxFine(f64vec3);"
663         "f64vec4   dFdxFine(f64vec4);"
664 
665         "float64_t dFdyFine(float64_t);"
666         "f64vec2   dFdyFine(f64vec2);"
667         "f64vec3   dFdyFine(f64vec3);"
668         "f64vec4   dFdyFine(f64vec4);"
669 
670         "float64_t dFdxCoarse(float64_t);"
671         "f64vec2   dFdxCoarse(f64vec2);"
672         "f64vec3   dFdxCoarse(f64vec3);"
673         "f64vec4   dFdxCoarse(f64vec4);"
674 
675         "float64_t dFdyCoarse(float64_t);"
676         "f64vec2   dFdyCoarse(f64vec2);"
677         "f64vec3   dFdyCoarse(f64vec3);"
678         "f64vec4   dFdyCoarse(f64vec4);"
679 
680         "float64_t fwidth(float64_t);"
681         "f64vec2   fwidth(f64vec2);"
682         "f64vec3   fwidth(f64vec3);"
683         "f64vec4   fwidth(f64vec4);"
684 
685         "float64_t fwidthFine(float64_t);"
686         "f64vec2   fwidthFine(f64vec2);"
687         "f64vec3   fwidthFine(f64vec3);"
688         "f64vec4   fwidthFine(f64vec4);"
689 
690         "float64_t fwidthCoarse(float64_t);"
691         "f64vec2   fwidthCoarse(f64vec2);"
692         "f64vec3   fwidthCoarse(f64vec3);"
693         "f64vec4   fwidthCoarse(f64vec4);"
694     );
695 
696     //============================================================================
697     //
698     // Prototypes for built-in functions seen by both vertex and fragment shaders.
699     //
700     //============================================================================
701 
702     //
703     // double functions added to desktop 4.00, but not fma, frexp, ldexp, or pack/unpack
704     //
705     if (profile != EEsProfile && version >= 150) {  // ARB_gpu_shader_fp64
706         commonBuiltins.append(
707 
708             "double sqrt(double);"
709             "dvec2  sqrt(dvec2);"
710             "dvec3  sqrt(dvec3);"
711             "dvec4  sqrt(dvec4);"
712 
713             "double inversesqrt(double);"
714             "dvec2  inversesqrt(dvec2);"
715             "dvec3  inversesqrt(dvec3);"
716             "dvec4  inversesqrt(dvec4);"
717 
718             "double abs(double);"
719             "dvec2  abs(dvec2);"
720             "dvec3  abs(dvec3);"
721             "dvec4  abs(dvec4);"
722 
723             "double sign(double);"
724             "dvec2  sign(dvec2);"
725             "dvec3  sign(dvec3);"
726             "dvec4  sign(dvec4);"
727 
728             "double floor(double);"
729             "dvec2  floor(dvec2);"
730             "dvec3  floor(dvec3);"
731             "dvec4  floor(dvec4);"
732 
733             "double trunc(double);"
734             "dvec2  trunc(dvec2);"
735             "dvec3  trunc(dvec3);"
736             "dvec4  trunc(dvec4);"
737 
738             "double round(double);"
739             "dvec2  round(dvec2);"
740             "dvec3  round(dvec3);"
741             "dvec4  round(dvec4);"
742 
743             "double roundEven(double);"
744             "dvec2  roundEven(dvec2);"
745             "dvec3  roundEven(dvec3);"
746             "dvec4  roundEven(dvec4);"
747 
748             "double ceil(double);"
749             "dvec2  ceil(dvec2);"
750             "dvec3  ceil(dvec3);"
751             "dvec4  ceil(dvec4);"
752 
753             "double fract(double);"
754             "dvec2  fract(dvec2);"
755             "dvec3  fract(dvec3);"
756             "dvec4  fract(dvec4);"
757 
758             "double mod(double, double);"
759             "dvec2  mod(dvec2 , double);"
760             "dvec3  mod(dvec3 , double);"
761             "dvec4  mod(dvec4 , double);"
762             "dvec2  mod(dvec2 , dvec2);"
763             "dvec3  mod(dvec3 , dvec3);"
764             "dvec4  mod(dvec4 , dvec4);"
765 
766             "double modf(double, out double);"
767             "dvec2  modf(dvec2,  out dvec2);"
768             "dvec3  modf(dvec3,  out dvec3);"
769             "dvec4  modf(dvec4,  out dvec4);"
770 
771             "double min(double, double);"
772             "dvec2  min(dvec2,  double);"
773             "dvec3  min(dvec3,  double);"
774             "dvec4  min(dvec4,  double);"
775             "dvec2  min(dvec2,  dvec2);"
776             "dvec3  min(dvec3,  dvec3);"
777             "dvec4  min(dvec4,  dvec4);"
778 
779             "double max(double, double);"
780             "dvec2  max(dvec2 , double);"
781             "dvec3  max(dvec3 , double);"
782             "dvec4  max(dvec4 , double);"
783             "dvec2  max(dvec2 , dvec2);"
784             "dvec3  max(dvec3 , dvec3);"
785             "dvec4  max(dvec4 , dvec4);"
786 
787             "double clamp(double, double, double);"
788             "dvec2  clamp(dvec2 , double, double);"
789             "dvec3  clamp(dvec3 , double, double);"
790             "dvec4  clamp(dvec4 , double, double);"
791             "dvec2  clamp(dvec2 , dvec2 , dvec2);"
792             "dvec3  clamp(dvec3 , dvec3 , dvec3);"
793             "dvec4  clamp(dvec4 , dvec4 , dvec4);"
794 
795             "double mix(double, double, double);"
796             "dvec2  mix(dvec2,  dvec2,  double);"
797             "dvec3  mix(dvec3,  dvec3,  double);"
798             "dvec4  mix(dvec4,  dvec4,  double);"
799             "dvec2  mix(dvec2,  dvec2,  dvec2);"
800             "dvec3  mix(dvec3,  dvec3,  dvec3);"
801             "dvec4  mix(dvec4,  dvec4,  dvec4);"
802             "double mix(double, double, bool);"
803             "dvec2  mix(dvec2,  dvec2,  bvec2);"
804             "dvec3  mix(dvec3,  dvec3,  bvec3);"
805             "dvec4  mix(dvec4,  dvec4,  bvec4);"
806 
807             "double step(double, double);"
808             "dvec2  step(dvec2 , dvec2);"
809             "dvec3  step(dvec3 , dvec3);"
810             "dvec4  step(dvec4 , dvec4);"
811             "dvec2  step(double, dvec2);"
812             "dvec3  step(double, dvec3);"
813             "dvec4  step(double, dvec4);"
814 
815             "double smoothstep(double, double, double);"
816             "dvec2  smoothstep(dvec2 , dvec2 , dvec2);"
817             "dvec3  smoothstep(dvec3 , dvec3 , dvec3);"
818             "dvec4  smoothstep(dvec4 , dvec4 , dvec4);"
819             "dvec2  smoothstep(double, double, dvec2);"
820             "dvec3  smoothstep(double, double, dvec3);"
821             "dvec4  smoothstep(double, double, dvec4);"
822 
823             "bool  isnan(double);"
824             "bvec2 isnan(dvec2);"
825             "bvec3 isnan(dvec3);"
826             "bvec4 isnan(dvec4);"
827 
828             "bool  isinf(double);"
829             "bvec2 isinf(dvec2);"
830             "bvec3 isinf(dvec3);"
831             "bvec4 isinf(dvec4);"
832 
833             "double length(double);"
834             "double length(dvec2);"
835             "double length(dvec3);"
836             "double length(dvec4);"
837 
838             "double distance(double, double);"
839             "double distance(dvec2 , dvec2);"
840             "double distance(dvec3 , dvec3);"
841             "double distance(dvec4 , dvec4);"
842 
843             "double dot(double, double);"
844             "double dot(dvec2 , dvec2);"
845             "double dot(dvec3 , dvec3);"
846             "double dot(dvec4 , dvec4);"
847 
848             "dvec3 cross(dvec3, dvec3);"
849 
850             "double normalize(double);"
851             "dvec2  normalize(dvec2);"
852             "dvec3  normalize(dvec3);"
853             "dvec4  normalize(dvec4);"
854 
855             "double faceforward(double, double, double);"
856             "dvec2  faceforward(dvec2,  dvec2,  dvec2);"
857             "dvec3  faceforward(dvec3,  dvec3,  dvec3);"
858             "dvec4  faceforward(dvec4,  dvec4,  dvec4);"
859 
860             "double reflect(double, double);"
861             "dvec2  reflect(dvec2 , dvec2 );"
862             "dvec3  reflect(dvec3 , dvec3 );"
863             "dvec4  reflect(dvec4 , dvec4 );"
864 
865             "double refract(double, double, double);"
866             "dvec2  refract(dvec2 , dvec2 , double);"
867             "dvec3  refract(dvec3 , dvec3 , double);"
868             "dvec4  refract(dvec4 , dvec4 , double);"
869 
870             "dmat2 matrixCompMult(dmat2, dmat2);"
871             "dmat3 matrixCompMult(dmat3, dmat3);"
872             "dmat4 matrixCompMult(dmat4, dmat4);"
873             "dmat2x3 matrixCompMult(dmat2x3, dmat2x3);"
874             "dmat2x4 matrixCompMult(dmat2x4, dmat2x4);"
875             "dmat3x2 matrixCompMult(dmat3x2, dmat3x2);"
876             "dmat3x4 matrixCompMult(dmat3x4, dmat3x4);"
877             "dmat4x2 matrixCompMult(dmat4x2, dmat4x2);"
878             "dmat4x3 matrixCompMult(dmat4x3, dmat4x3);"
879 
880             "dmat2   outerProduct(dvec2, dvec2);"
881             "dmat3   outerProduct(dvec3, dvec3);"
882             "dmat4   outerProduct(dvec4, dvec4);"
883             "dmat2x3 outerProduct(dvec3, dvec2);"
884             "dmat3x2 outerProduct(dvec2, dvec3);"
885             "dmat2x4 outerProduct(dvec4, dvec2);"
886             "dmat4x2 outerProduct(dvec2, dvec4);"
887             "dmat3x4 outerProduct(dvec4, dvec3);"
888             "dmat4x3 outerProduct(dvec3, dvec4);"
889 
890             "dmat2   transpose(dmat2);"
891             "dmat3   transpose(dmat3);"
892             "dmat4   transpose(dmat4);"
893             "dmat2x3 transpose(dmat3x2);"
894             "dmat3x2 transpose(dmat2x3);"
895             "dmat2x4 transpose(dmat4x2);"
896             "dmat4x2 transpose(dmat2x4);"
897             "dmat3x4 transpose(dmat4x3);"
898             "dmat4x3 transpose(dmat3x4);"
899 
900             "double determinant(dmat2);"
901             "double determinant(dmat3);"
902             "double determinant(dmat4);"
903 
904             "dmat2 inverse(dmat2);"
905             "dmat3 inverse(dmat3);"
906             "dmat4 inverse(dmat4);"
907 
908             "bvec2 lessThan(dvec2, dvec2);"
909             "bvec3 lessThan(dvec3, dvec3);"
910             "bvec4 lessThan(dvec4, dvec4);"
911 
912             "bvec2 lessThanEqual(dvec2, dvec2);"
913             "bvec3 lessThanEqual(dvec3, dvec3);"
914             "bvec4 lessThanEqual(dvec4, dvec4);"
915 
916             "bvec2 greaterThan(dvec2, dvec2);"
917             "bvec3 greaterThan(dvec3, dvec3);"
918             "bvec4 greaterThan(dvec4, dvec4);"
919 
920             "bvec2 greaterThanEqual(dvec2, dvec2);"
921             "bvec3 greaterThanEqual(dvec3, dvec3);"
922             "bvec4 greaterThanEqual(dvec4, dvec4);"
923 
924             "bvec2 equal(dvec2, dvec2);"
925             "bvec3 equal(dvec3, dvec3);"
926             "bvec4 equal(dvec4, dvec4);"
927 
928             "bvec2 notEqual(dvec2, dvec2);"
929             "bvec3 notEqual(dvec3, dvec3);"
930             "bvec4 notEqual(dvec4, dvec4);"
931 
932             "\n");
933     }
934 
935     if (profile == EEsProfile && version >= 310) {  // Explicit Types
936       commonBuiltins.append(
937 
938         "float64_t sqrt(float64_t);"
939         "f64vec2  sqrt(f64vec2);"
940         "f64vec3  sqrt(f64vec3);"
941         "f64vec4  sqrt(f64vec4);"
942 
943         "float64_t inversesqrt(float64_t);"
944         "f64vec2  inversesqrt(f64vec2);"
945         "f64vec3  inversesqrt(f64vec3);"
946         "f64vec4  inversesqrt(f64vec4);"
947 
948         "float64_t abs(float64_t);"
949         "f64vec2  abs(f64vec2);"
950         "f64vec3  abs(f64vec3);"
951         "f64vec4  abs(f64vec4);"
952 
953         "float64_t sign(float64_t);"
954         "f64vec2  sign(f64vec2);"
955         "f64vec3  sign(f64vec3);"
956         "f64vec4  sign(f64vec4);"
957 
958         "float64_t floor(float64_t);"
959         "f64vec2  floor(f64vec2);"
960         "f64vec3  floor(f64vec3);"
961         "f64vec4  floor(f64vec4);"
962 
963         "float64_t trunc(float64_t);"
964         "f64vec2  trunc(f64vec2);"
965         "f64vec3  trunc(f64vec3);"
966         "f64vec4  trunc(f64vec4);"
967 
968         "float64_t round(float64_t);"
969         "f64vec2  round(f64vec2);"
970         "f64vec3  round(f64vec3);"
971         "f64vec4  round(f64vec4);"
972 
973         "float64_t roundEven(float64_t);"
974         "f64vec2  roundEven(f64vec2);"
975         "f64vec3  roundEven(f64vec3);"
976         "f64vec4  roundEven(f64vec4);"
977 
978         "float64_t ceil(float64_t);"
979         "f64vec2  ceil(f64vec2);"
980         "f64vec3  ceil(f64vec3);"
981         "f64vec4  ceil(f64vec4);"
982 
983         "float64_t fract(float64_t);"
984         "f64vec2  fract(f64vec2);"
985         "f64vec3  fract(f64vec3);"
986         "f64vec4  fract(f64vec4);"
987 
988         "float64_t mod(float64_t, float64_t);"
989         "f64vec2  mod(f64vec2 , float64_t);"
990         "f64vec3  mod(f64vec3 , float64_t);"
991         "f64vec4  mod(f64vec4 , float64_t);"
992         "f64vec2  mod(f64vec2 , f64vec2);"
993         "f64vec3  mod(f64vec3 , f64vec3);"
994         "f64vec4  mod(f64vec4 , f64vec4);"
995 
996         "float64_t modf(float64_t, out float64_t);"
997         "f64vec2  modf(f64vec2,  out f64vec2);"
998         "f64vec3  modf(f64vec3,  out f64vec3);"
999         "f64vec4  modf(f64vec4,  out f64vec4);"
1000 
1001         "float64_t min(float64_t, float64_t);"
1002         "f64vec2  min(f64vec2,  float64_t);"
1003         "f64vec3  min(f64vec3,  float64_t);"
1004         "f64vec4  min(f64vec4,  float64_t);"
1005         "f64vec2  min(f64vec2,  f64vec2);"
1006         "f64vec3  min(f64vec3,  f64vec3);"
1007         "f64vec4  min(f64vec4,  f64vec4);"
1008 
1009         "float64_t max(float64_t, float64_t);"
1010         "f64vec2  max(f64vec2 , float64_t);"
1011         "f64vec3  max(f64vec3 , float64_t);"
1012         "f64vec4  max(f64vec4 , float64_t);"
1013         "f64vec2  max(f64vec2 , f64vec2);"
1014         "f64vec3  max(f64vec3 , f64vec3);"
1015         "f64vec4  max(f64vec4 , f64vec4);"
1016 
1017         "float64_t clamp(float64_t, float64_t, float64_t);"
1018         "f64vec2  clamp(f64vec2 , float64_t, float64_t);"
1019         "f64vec3  clamp(f64vec3 , float64_t, float64_t);"
1020         "f64vec4  clamp(f64vec4 , float64_t, float64_t);"
1021         "f64vec2  clamp(f64vec2 , f64vec2 , f64vec2);"
1022         "f64vec3  clamp(f64vec3 , f64vec3 , f64vec3);"
1023         "f64vec4  clamp(f64vec4 , f64vec4 , f64vec4);"
1024 
1025         "float64_t mix(float64_t, float64_t, float64_t);"
1026         "f64vec2  mix(f64vec2,  f64vec2,  float64_t);"
1027         "f64vec3  mix(f64vec3,  f64vec3,  float64_t);"
1028         "f64vec4  mix(f64vec4,  f64vec4,  float64_t);"
1029         "f64vec2  mix(f64vec2,  f64vec2,  f64vec2);"
1030         "f64vec3  mix(f64vec3,  f64vec3,  f64vec3);"
1031         "f64vec4  mix(f64vec4,  f64vec4,  f64vec4);"
1032         "float64_t mix(float64_t, float64_t, bool);"
1033         "f64vec2  mix(f64vec2,  f64vec2,  bvec2);"
1034         "f64vec3  mix(f64vec3,  f64vec3,  bvec3);"
1035         "f64vec4  mix(f64vec4,  f64vec4,  bvec4);"
1036 
1037         "float64_t step(float64_t, float64_t);"
1038         "f64vec2  step(f64vec2 , f64vec2);"
1039         "f64vec3  step(f64vec3 , f64vec3);"
1040         "f64vec4  step(f64vec4 , f64vec4);"
1041         "f64vec2  step(float64_t, f64vec2);"
1042         "f64vec3  step(float64_t, f64vec3);"
1043         "f64vec4  step(float64_t, f64vec4);"
1044 
1045         "float64_t smoothstep(float64_t, float64_t, float64_t);"
1046         "f64vec2  smoothstep(f64vec2 , f64vec2 , f64vec2);"
1047         "f64vec3  smoothstep(f64vec3 , f64vec3 , f64vec3);"
1048         "f64vec4  smoothstep(f64vec4 , f64vec4 , f64vec4);"
1049         "f64vec2  smoothstep(float64_t, float64_t, f64vec2);"
1050         "f64vec3  smoothstep(float64_t, float64_t, f64vec3);"
1051         "f64vec4  smoothstep(float64_t, float64_t, f64vec4);"
1052 
1053         "float64_t length(float64_t);"
1054         "float64_t length(f64vec2);"
1055         "float64_t length(f64vec3);"
1056         "float64_t length(f64vec4);"
1057 
1058         "float64_t distance(float64_t, float64_t);"
1059         "float64_t distance(f64vec2 , f64vec2);"
1060         "float64_t distance(f64vec3 , f64vec3);"
1061         "float64_t distance(f64vec4 , f64vec4);"
1062 
1063         "float64_t dot(float64_t, float64_t);"
1064         "float64_t dot(f64vec2 , f64vec2);"
1065         "float64_t dot(f64vec3 , f64vec3);"
1066         "float64_t dot(f64vec4 , f64vec4);"
1067 
1068         "f64vec3 cross(f64vec3, f64vec3);"
1069 
1070         "float64_t normalize(float64_t);"
1071         "f64vec2  normalize(f64vec2);"
1072         "f64vec3  normalize(f64vec3);"
1073         "f64vec4  normalize(f64vec4);"
1074 
1075         "float64_t faceforward(float64_t, float64_t, float64_t);"
1076         "f64vec2  faceforward(f64vec2,  f64vec2,  f64vec2);"
1077         "f64vec3  faceforward(f64vec3,  f64vec3,  f64vec3);"
1078         "f64vec4  faceforward(f64vec4,  f64vec4,  f64vec4);"
1079 
1080         "float64_t reflect(float64_t, float64_t);"
1081         "f64vec2  reflect(f64vec2 , f64vec2 );"
1082         "f64vec3  reflect(f64vec3 , f64vec3 );"
1083         "f64vec4  reflect(f64vec4 , f64vec4 );"
1084 
1085         "float64_t refract(float64_t, float64_t, float64_t);"
1086         "f64vec2  refract(f64vec2 , f64vec2 , float64_t);"
1087         "f64vec3  refract(f64vec3 , f64vec3 , float64_t);"
1088         "f64vec4  refract(f64vec4 , f64vec4 , float64_t);"
1089 
1090         "f64mat2 matrixCompMult(f64mat2, f64mat2);"
1091         "f64mat3 matrixCompMult(f64mat3, f64mat3);"
1092         "f64mat4 matrixCompMult(f64mat4, f64mat4);"
1093         "f64mat2x3 matrixCompMult(f64mat2x3, f64mat2x3);"
1094         "f64mat2x4 matrixCompMult(f64mat2x4, f64mat2x4);"
1095         "f64mat3x2 matrixCompMult(f64mat3x2, f64mat3x2);"
1096         "f64mat3x4 matrixCompMult(f64mat3x4, f64mat3x4);"
1097         "f64mat4x2 matrixCompMult(f64mat4x2, f64mat4x2);"
1098         "f64mat4x3 matrixCompMult(f64mat4x3, f64mat4x3);"
1099 
1100         "f64mat2   outerProduct(f64vec2, f64vec2);"
1101         "f64mat3   outerProduct(f64vec3, f64vec3);"
1102         "f64mat4   outerProduct(f64vec4, f64vec4);"
1103         "f64mat2x3 outerProduct(f64vec3, f64vec2);"
1104         "f64mat3x2 outerProduct(f64vec2, f64vec3);"
1105         "f64mat2x4 outerProduct(f64vec4, f64vec2);"
1106         "f64mat4x2 outerProduct(f64vec2, f64vec4);"
1107         "f64mat3x4 outerProduct(f64vec4, f64vec3);"
1108         "f64mat4x3 outerProduct(f64vec3, f64vec4);"
1109 
1110         "f64mat2   transpose(f64mat2);"
1111         "f64mat3   transpose(f64mat3);"
1112         "f64mat4   transpose(f64mat4);"
1113         "f64mat2x3 transpose(f64mat3x2);"
1114         "f64mat3x2 transpose(f64mat2x3);"
1115         "f64mat2x4 transpose(f64mat4x2);"
1116         "f64mat4x2 transpose(f64mat2x4);"
1117         "f64mat3x4 transpose(f64mat4x3);"
1118         "f64mat4x3 transpose(f64mat3x4);"
1119 
1120         "float64_t determinant(f64mat2);"
1121         "float64_t determinant(f64mat3);"
1122         "float64_t determinant(f64mat4);"
1123 
1124         "f64mat2 inverse(f64mat2);"
1125         "f64mat3 inverse(f64mat3);"
1126         "f64mat4 inverse(f64mat4);"
1127 
1128         "\n");
1129     }
1130 
1131     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
1132         commonBuiltins.append(
1133 
1134             "int64_t abs(int64_t);"
1135             "i64vec2 abs(i64vec2);"
1136             "i64vec3 abs(i64vec3);"
1137             "i64vec4 abs(i64vec4);"
1138 
1139             "int64_t sign(int64_t);"
1140             "i64vec2 sign(i64vec2);"
1141             "i64vec3 sign(i64vec3);"
1142             "i64vec4 sign(i64vec4);"
1143 
1144             "int64_t  min(int64_t,  int64_t);"
1145             "i64vec2  min(i64vec2,  int64_t);"
1146             "i64vec3  min(i64vec3,  int64_t);"
1147             "i64vec4  min(i64vec4,  int64_t);"
1148             "i64vec2  min(i64vec2,  i64vec2);"
1149             "i64vec3  min(i64vec3,  i64vec3);"
1150             "i64vec4  min(i64vec4,  i64vec4);"
1151             "uint64_t min(uint64_t, uint64_t);"
1152             "u64vec2  min(u64vec2,  uint64_t);"
1153             "u64vec3  min(u64vec3,  uint64_t);"
1154             "u64vec4  min(u64vec4,  uint64_t);"
1155             "u64vec2  min(u64vec2,  u64vec2);"
1156             "u64vec3  min(u64vec3,  u64vec3);"
1157             "u64vec4  min(u64vec4,  u64vec4);"
1158 
1159             "int64_t  max(int64_t,  int64_t);"
1160             "i64vec2  max(i64vec2,  int64_t);"
1161             "i64vec3  max(i64vec3,  int64_t);"
1162             "i64vec4  max(i64vec4,  int64_t);"
1163             "i64vec2  max(i64vec2,  i64vec2);"
1164             "i64vec3  max(i64vec3,  i64vec3);"
1165             "i64vec4  max(i64vec4,  i64vec4);"
1166             "uint64_t max(uint64_t, uint64_t);"
1167             "u64vec2  max(u64vec2,  uint64_t);"
1168             "u64vec3  max(u64vec3,  uint64_t);"
1169             "u64vec4  max(u64vec4,  uint64_t);"
1170             "u64vec2  max(u64vec2,  u64vec2);"
1171             "u64vec3  max(u64vec3,  u64vec3);"
1172             "u64vec4  max(u64vec4,  u64vec4);"
1173 
1174             "int64_t  clamp(int64_t,  int64_t,  int64_t);"
1175             "i64vec2  clamp(i64vec2,  int64_t,  int64_t);"
1176             "i64vec3  clamp(i64vec3,  int64_t,  int64_t);"
1177             "i64vec4  clamp(i64vec4,  int64_t,  int64_t);"
1178             "i64vec2  clamp(i64vec2,  i64vec2,  i64vec2);"
1179             "i64vec3  clamp(i64vec3,  i64vec3,  i64vec3);"
1180             "i64vec4  clamp(i64vec4,  i64vec4,  i64vec4);"
1181             "uint64_t clamp(uint64_t, uint64_t, uint64_t);"
1182             "u64vec2  clamp(u64vec2,  uint64_t, uint64_t);"
1183             "u64vec3  clamp(u64vec3,  uint64_t, uint64_t);"
1184             "u64vec4  clamp(u64vec4,  uint64_t, uint64_t);"
1185             "u64vec2  clamp(u64vec2,  u64vec2,  u64vec2);"
1186             "u64vec3  clamp(u64vec3,  u64vec3,  u64vec3);"
1187             "u64vec4  clamp(u64vec4,  u64vec4,  u64vec4);"
1188 
1189             "int64_t  mix(int64_t,  int64_t,  bool);"
1190             "i64vec2  mix(i64vec2,  i64vec2,  bvec2);"
1191             "i64vec3  mix(i64vec3,  i64vec3,  bvec3);"
1192             "i64vec4  mix(i64vec4,  i64vec4,  bvec4);"
1193             "uint64_t mix(uint64_t, uint64_t, bool);"
1194             "u64vec2  mix(u64vec2,  u64vec2,  bvec2);"
1195             "u64vec3  mix(u64vec3,  u64vec3,  bvec3);"
1196             "u64vec4  mix(u64vec4,  u64vec4,  bvec4);"
1197 
1198             "int64_t doubleBitsToInt64(float64_t);"
1199             "i64vec2 doubleBitsToInt64(f64vec2);"
1200             "i64vec3 doubleBitsToInt64(f64vec3);"
1201             "i64vec4 doubleBitsToInt64(f64vec4);"
1202 
1203             "uint64_t doubleBitsToUint64(float64_t);"
1204             "u64vec2  doubleBitsToUint64(f64vec2);"
1205             "u64vec3  doubleBitsToUint64(f64vec3);"
1206             "u64vec4  doubleBitsToUint64(f64vec4);"
1207 
1208             "float64_t int64BitsToDouble(int64_t);"
1209             "f64vec2  int64BitsToDouble(i64vec2);"
1210             "f64vec3  int64BitsToDouble(i64vec3);"
1211             "f64vec4  int64BitsToDouble(i64vec4);"
1212 
1213             "float64_t uint64BitsToDouble(uint64_t);"
1214             "f64vec2  uint64BitsToDouble(u64vec2);"
1215             "f64vec3  uint64BitsToDouble(u64vec3);"
1216             "f64vec4  uint64BitsToDouble(u64vec4);"
1217 
1218             "int64_t  packInt2x32(ivec2);"
1219             "uint64_t packUint2x32(uvec2);"
1220             "ivec2    unpackInt2x32(int64_t);"
1221             "uvec2    unpackUint2x32(uint64_t);"
1222 
1223             "bvec2 lessThan(i64vec2, i64vec2);"
1224             "bvec3 lessThan(i64vec3, i64vec3);"
1225             "bvec4 lessThan(i64vec4, i64vec4);"
1226             "bvec2 lessThan(u64vec2, u64vec2);"
1227             "bvec3 lessThan(u64vec3, u64vec3);"
1228             "bvec4 lessThan(u64vec4, u64vec4);"
1229 
1230             "bvec2 lessThanEqual(i64vec2, i64vec2);"
1231             "bvec3 lessThanEqual(i64vec3, i64vec3);"
1232             "bvec4 lessThanEqual(i64vec4, i64vec4);"
1233             "bvec2 lessThanEqual(u64vec2, u64vec2);"
1234             "bvec3 lessThanEqual(u64vec3, u64vec3);"
1235             "bvec4 lessThanEqual(u64vec4, u64vec4);"
1236 
1237             "bvec2 greaterThan(i64vec2, i64vec2);"
1238             "bvec3 greaterThan(i64vec3, i64vec3);"
1239             "bvec4 greaterThan(i64vec4, i64vec4);"
1240             "bvec2 greaterThan(u64vec2, u64vec2);"
1241             "bvec3 greaterThan(u64vec3, u64vec3);"
1242             "bvec4 greaterThan(u64vec4, u64vec4);"
1243 
1244             "bvec2 greaterThanEqual(i64vec2, i64vec2);"
1245             "bvec3 greaterThanEqual(i64vec3, i64vec3);"
1246             "bvec4 greaterThanEqual(i64vec4, i64vec4);"
1247             "bvec2 greaterThanEqual(u64vec2, u64vec2);"
1248             "bvec3 greaterThanEqual(u64vec3, u64vec3);"
1249             "bvec4 greaterThanEqual(u64vec4, u64vec4);"
1250 
1251             "bvec2 equal(i64vec2, i64vec2);"
1252             "bvec3 equal(i64vec3, i64vec3);"
1253             "bvec4 equal(i64vec4, i64vec4);"
1254             "bvec2 equal(u64vec2, u64vec2);"
1255             "bvec3 equal(u64vec3, u64vec3);"
1256             "bvec4 equal(u64vec4, u64vec4);"
1257 
1258             "bvec2 notEqual(i64vec2, i64vec2);"
1259             "bvec3 notEqual(i64vec3, i64vec3);"
1260             "bvec4 notEqual(i64vec4, i64vec4);"
1261             "bvec2 notEqual(u64vec2, u64vec2);"
1262             "bvec3 notEqual(u64vec3, u64vec3);"
1263             "bvec4 notEqual(u64vec4, u64vec4);"
1264 
1265             "int64_t bitCount(int64_t);"
1266             "i64vec2 bitCount(i64vec2);"
1267             "i64vec3 bitCount(i64vec3);"
1268             "i64vec4 bitCount(i64vec4);"
1269 
1270             "int64_t bitCount(uint64_t);"
1271             "i64vec2 bitCount(u64vec2);"
1272             "i64vec3 bitCount(u64vec3);"
1273             "i64vec4 bitCount(u64vec4);"
1274 
1275             "int64_t findLSB(int64_t);"
1276             "i64vec2 findLSB(i64vec2);"
1277             "i64vec3 findLSB(i64vec3);"
1278             "i64vec4 findLSB(i64vec4);"
1279 
1280             "int64_t findLSB(uint64_t);"
1281             "i64vec2 findLSB(u64vec2);"
1282             "i64vec3 findLSB(u64vec3);"
1283             "i64vec4 findLSB(u64vec4);"
1284 
1285             "int64_t findMSB(int64_t);"
1286             "i64vec2 findMSB(i64vec2);"
1287             "i64vec3 findMSB(i64vec3);"
1288             "i64vec4 findMSB(i64vec4);"
1289 
1290             "int64_t findMSB(uint64_t);"
1291             "i64vec2 findMSB(u64vec2);"
1292             "i64vec3 findMSB(u64vec3);"
1293             "i64vec4 findMSB(u64vec4);"
1294 
1295             "\n"
1296         );
1297     }
1298 
1299     // GL_AMD_shader_trinary_minmax
1300     if (profile != EEsProfile && version >= 430) {
1301         commonBuiltins.append(
1302             "float min3(float, float, float);"
1303             "vec2  min3(vec2,  vec2,  vec2);"
1304             "vec3  min3(vec3,  vec3,  vec3);"
1305             "vec4  min3(vec4,  vec4,  vec4);"
1306 
1307             "int   min3(int,   int,   int);"
1308             "ivec2 min3(ivec2, ivec2, ivec2);"
1309             "ivec3 min3(ivec3, ivec3, ivec3);"
1310             "ivec4 min3(ivec4, ivec4, ivec4);"
1311 
1312             "uint  min3(uint,  uint,  uint);"
1313             "uvec2 min3(uvec2, uvec2, uvec2);"
1314             "uvec3 min3(uvec3, uvec3, uvec3);"
1315             "uvec4 min3(uvec4, uvec4, uvec4);"
1316 
1317             "float max3(float, float, float);"
1318             "vec2  max3(vec2,  vec2,  vec2);"
1319             "vec3  max3(vec3,  vec3,  vec3);"
1320             "vec4  max3(vec4,  vec4,  vec4);"
1321 
1322             "int   max3(int,   int,   int);"
1323             "ivec2 max3(ivec2, ivec2, ivec2);"
1324             "ivec3 max3(ivec3, ivec3, ivec3);"
1325             "ivec4 max3(ivec4, ivec4, ivec4);"
1326 
1327             "uint  max3(uint,  uint,  uint);"
1328             "uvec2 max3(uvec2, uvec2, uvec2);"
1329             "uvec3 max3(uvec3, uvec3, uvec3);"
1330             "uvec4 max3(uvec4, uvec4, uvec4);"
1331 
1332             "float mid3(float, float, float);"
1333             "vec2  mid3(vec2,  vec2,  vec2);"
1334             "vec3  mid3(vec3,  vec3,  vec3);"
1335             "vec4  mid3(vec4,  vec4,  vec4);"
1336 
1337             "int   mid3(int,   int,   int);"
1338             "ivec2 mid3(ivec2, ivec2, ivec2);"
1339             "ivec3 mid3(ivec3, ivec3, ivec3);"
1340             "ivec4 mid3(ivec4, ivec4, ivec4);"
1341 
1342             "uint  mid3(uint,  uint,  uint);"
1343             "uvec2 mid3(uvec2, uvec2, uvec2);"
1344             "uvec3 mid3(uvec3, uvec3, uvec3);"
1345             "uvec4 mid3(uvec4, uvec4, uvec4);"
1346 
1347             "float16_t min3(float16_t, float16_t, float16_t);"
1348             "f16vec2   min3(f16vec2,   f16vec2,   f16vec2);"
1349             "f16vec3   min3(f16vec3,   f16vec3,   f16vec3);"
1350             "f16vec4   min3(f16vec4,   f16vec4,   f16vec4);"
1351 
1352             "float16_t max3(float16_t, float16_t, float16_t);"
1353             "f16vec2   max3(f16vec2,   f16vec2,   f16vec2);"
1354             "f16vec3   max3(f16vec3,   f16vec3,   f16vec3);"
1355             "f16vec4   max3(f16vec4,   f16vec4,   f16vec4);"
1356 
1357             "float16_t mid3(float16_t, float16_t, float16_t);"
1358             "f16vec2   mid3(f16vec2,   f16vec2,   f16vec2);"
1359             "f16vec3   mid3(f16vec3,   f16vec3,   f16vec3);"
1360             "f16vec4   mid3(f16vec4,   f16vec4,   f16vec4);"
1361 
1362             "int16_t   min3(int16_t,   int16_t,   int16_t);"
1363             "i16vec2   min3(i16vec2,   i16vec2,   i16vec2);"
1364             "i16vec3   min3(i16vec3,   i16vec3,   i16vec3);"
1365             "i16vec4   min3(i16vec4,   i16vec4,   i16vec4);"
1366 
1367             "int16_t   max3(int16_t,   int16_t,   int16_t);"
1368             "i16vec2   max3(i16vec2,   i16vec2,   i16vec2);"
1369             "i16vec3   max3(i16vec3,   i16vec3,   i16vec3);"
1370             "i16vec4   max3(i16vec4,   i16vec4,   i16vec4);"
1371 
1372             "int16_t   mid3(int16_t,   int16_t,   int16_t);"
1373             "i16vec2   mid3(i16vec2,   i16vec2,   i16vec2);"
1374             "i16vec3   mid3(i16vec3,   i16vec3,   i16vec3);"
1375             "i16vec4   mid3(i16vec4,   i16vec4,   i16vec4);"
1376 
1377             "uint16_t  min3(uint16_t,  uint16_t,  uint16_t);"
1378             "u16vec2   min3(u16vec2,   u16vec2,   u16vec2);"
1379             "u16vec3   min3(u16vec3,   u16vec3,   u16vec3);"
1380             "u16vec4   min3(u16vec4,   u16vec4,   u16vec4);"
1381 
1382             "uint16_t  max3(uint16_t,  uint16_t,  uint16_t);"
1383             "u16vec2   max3(u16vec2,   u16vec2,   u16vec2);"
1384             "u16vec3   max3(u16vec3,   u16vec3,   u16vec3);"
1385             "u16vec4   max3(u16vec4,   u16vec4,   u16vec4);"
1386 
1387             "uint16_t  mid3(uint16_t,  uint16_t,  uint16_t);"
1388             "u16vec2   mid3(u16vec2,   u16vec2,   u16vec2);"
1389             "u16vec3   mid3(u16vec3,   u16vec3,   u16vec3);"
1390             "u16vec4   mid3(u16vec4,   u16vec4,   u16vec4);"
1391 
1392             "\n"
1393         );
1394     }
1395 #endif // !GLSLANG_ANGLE
1396 
1397     if ((profile == EEsProfile && version >= 310) ||
1398         (profile != EEsProfile && version >= 430)) {
1399         commonBuiltins.append(
1400             "uint atomicAdd(coherent volatile inout uint, uint, int, int, int);"
1401             " int atomicAdd(coherent volatile inout  int,  int, int, int, int);"
1402 
1403             "uint atomicMin(coherent volatile inout uint, uint, int, int, int);"
1404             " int atomicMin(coherent volatile inout  int,  int, int, int, int);"
1405 
1406             "uint atomicMax(coherent volatile inout uint, uint, int, int, int);"
1407             " int atomicMax(coherent volatile inout  int,  int, int, int, int);"
1408 
1409             "uint atomicAnd(coherent volatile inout uint, uint, int, int, int);"
1410             " int atomicAnd(coherent volatile inout  int,  int, int, int, int);"
1411 
1412             "uint atomicOr (coherent volatile inout uint, uint, int, int, int);"
1413             " int atomicOr (coherent volatile inout  int,  int, int, int, int);"
1414 
1415             "uint atomicXor(coherent volatile inout uint, uint, int, int, int);"
1416             " int atomicXor(coherent volatile inout  int,  int, int, int, int);"
1417 
1418             "uint atomicExchange(coherent volatile inout uint, uint, int, int, int);"
1419             " int atomicExchange(coherent volatile inout  int,  int, int, int, int);"
1420 
1421             "uint atomicCompSwap(coherent volatile inout uint, uint, uint, int, int, int, int, int);"
1422             " int atomicCompSwap(coherent volatile inout  int,  int,  int, int, int, int, int, int);"
1423 
1424             "uint atomicLoad(coherent volatile in uint, int, int, int);"
1425             " int atomicLoad(coherent volatile in  int, int, int, int);"
1426 
1427             "void atomicStore(coherent volatile out uint, uint, int, int, int);"
1428             "void atomicStore(coherent volatile out  int,  int, int, int, int);"
1429 
1430             "\n");
1431     }
1432 
1433 #ifndef GLSLANG_ANGLE
1434     if (profile != EEsProfile && version >= 440) {
1435         commonBuiltins.append(
1436             "uint64_t atomicMin(coherent volatile inout uint64_t, uint64_t);"
1437             " int64_t atomicMin(coherent volatile inout  int64_t,  int64_t);"
1438             "uint64_t atomicMin(coherent volatile inout uint64_t, uint64_t, int, int, int);"
1439             " int64_t atomicMin(coherent volatile inout  int64_t,  int64_t, int, int, int);"
1440             "float16_t atomicMin(coherent volatile inout float16_t, float16_t);"
1441             "float16_t atomicMin(coherent volatile inout float16_t, float16_t, int, int, int);"
1442             "   float atomicMin(coherent volatile inout float, float);"
1443             "   float atomicMin(coherent volatile inout float, float, int, int, int);"
1444             "  double atomicMin(coherent volatile inout double, double);"
1445             "  double atomicMin(coherent volatile inout double, double, int, int, int);"
1446 
1447             "uint64_t atomicMax(coherent volatile inout uint64_t, uint64_t);"
1448             " int64_t atomicMax(coherent volatile inout  int64_t,  int64_t);"
1449             "uint64_t atomicMax(coherent volatile inout uint64_t, uint64_t, int, int, int);"
1450             " int64_t atomicMax(coherent volatile inout  int64_t,  int64_t, int, int, int);"
1451             "float16_t atomicMax(coherent volatile inout float16_t, float16_t);"
1452             "float16_t atomicMax(coherent volatile inout float16_t, float16_t, int, int, int);"
1453             "   float atomicMax(coherent volatile inout float, float);"
1454             "   float atomicMax(coherent volatile inout float, float, int, int, int);"
1455             "  double atomicMax(coherent volatile inout double, double);"
1456             "  double atomicMax(coherent volatile inout double, double, int, int, int);"
1457 
1458             "uint64_t atomicAnd(coherent volatile inout uint64_t, uint64_t);"
1459             " int64_t atomicAnd(coherent volatile inout  int64_t,  int64_t);"
1460             "uint64_t atomicAnd(coherent volatile inout uint64_t, uint64_t, int, int, int);"
1461             " int64_t atomicAnd(coherent volatile inout  int64_t,  int64_t, int, int, int);"
1462 
1463             "uint64_t atomicOr (coherent volatile inout uint64_t, uint64_t);"
1464             " int64_t atomicOr (coherent volatile inout  int64_t,  int64_t);"
1465             "uint64_t atomicOr (coherent volatile inout uint64_t, uint64_t, int, int, int);"
1466             " int64_t atomicOr (coherent volatile inout  int64_t,  int64_t, int, int, int);"
1467 
1468             "uint64_t atomicXor(coherent volatile inout uint64_t, uint64_t);"
1469             " int64_t atomicXor(coherent volatile inout  int64_t,  int64_t);"
1470             "uint64_t atomicXor(coherent volatile inout uint64_t, uint64_t, int, int, int);"
1471             " int64_t atomicXor(coherent volatile inout  int64_t,  int64_t, int, int, int);"
1472 
1473             "uint64_t atomicAdd(coherent volatile inout uint64_t, uint64_t);"
1474             " int64_t atomicAdd(coherent volatile inout  int64_t,  int64_t);"
1475             "uint64_t atomicAdd(coherent volatile inout uint64_t, uint64_t, int, int, int);"
1476             " int64_t atomicAdd(coherent volatile inout  int64_t,  int64_t, int, int, int);"
1477             "float16_t atomicAdd(coherent volatile inout float16_t, float16_t);"
1478             "float16_t atomicAdd(coherent volatile inout float16_t, float16_t, int, int, int);"
1479             "   float atomicAdd(coherent volatile inout float, float);"
1480             "   float atomicAdd(coherent volatile inout float, float, int, int, int);"
1481             "  double atomicAdd(coherent volatile inout double, double);"
1482             "  double atomicAdd(coherent volatile inout double, double, int, int, int);"
1483 
1484             "uint64_t atomicExchange(coherent volatile inout uint64_t, uint64_t);"
1485             " int64_t atomicExchange(coherent volatile inout  int64_t,  int64_t);"
1486             "uint64_t atomicExchange(coherent volatile inout uint64_t, uint64_t, int, int, int);"
1487             " int64_t atomicExchange(coherent volatile inout  int64_t,  int64_t, int, int, int);"
1488             "float16_t atomicExchange(coherent volatile inout float16_t, float16_t);"
1489             "float16_t atomicExchange(coherent volatile inout float16_t, float16_t, int, int, int);"
1490             "   float atomicExchange(coherent volatile inout float, float);"
1491             "   float atomicExchange(coherent volatile inout float, float, int, int, int);"
1492             "  double atomicExchange(coherent volatile inout double, double);"
1493             "  double atomicExchange(coherent volatile inout double, double, int, int, int);"
1494 
1495             "uint64_t atomicCompSwap(coherent volatile inout uint64_t, uint64_t, uint64_t);"
1496             " int64_t atomicCompSwap(coherent volatile inout  int64_t,  int64_t,  int64_t);"
1497             "uint64_t atomicCompSwap(coherent volatile inout uint64_t, uint64_t, uint64_t, int, int, int, int, int);"
1498             " int64_t atomicCompSwap(coherent volatile inout  int64_t,  int64_t,  int64_t, int, int, int, int, int);"
1499 
1500             "uint64_t atomicLoad(coherent volatile in uint64_t, int, int, int);"
1501             " int64_t atomicLoad(coherent volatile in  int64_t, int, int, int);"
1502             "float16_t atomicLoad(coherent volatile in float16_t, int, int, int);"
1503             "   float atomicLoad(coherent volatile in float, int, int, int);"
1504             "  double atomicLoad(coherent volatile in double, int, int, int);"
1505 
1506             "void atomicStore(coherent volatile out uint64_t, uint64_t, int, int, int);"
1507             "void atomicStore(coherent volatile out  int64_t,  int64_t, int, int, int);"
1508             "void atomicStore(coherent volatile out float16_t, float16_t, int, int, int);"
1509             "void atomicStore(coherent volatile out float, float, int, int, int);"
1510             "void atomicStore(coherent volatile out double, double, int, int, int);"
1511             "\n");
1512     }
1513 #endif // !GLSLANG_ANGLE
1514 #endif // !GLSLANG_WEB
1515 
1516     if ((profile == EEsProfile && version >= 300) ||
1517         (profile != EEsProfile && version >= 150)) { // GL_ARB_shader_bit_encoding
1518         commonBuiltins.append(
1519             "int   floatBitsToInt(highp float value);"
1520             "ivec2 floatBitsToInt(highp vec2  value);"
1521             "ivec3 floatBitsToInt(highp vec3  value);"
1522             "ivec4 floatBitsToInt(highp vec4  value);"
1523 
1524             "uint  floatBitsToUint(highp float value);"
1525             "uvec2 floatBitsToUint(highp vec2  value);"
1526             "uvec3 floatBitsToUint(highp vec3  value);"
1527             "uvec4 floatBitsToUint(highp vec4  value);"
1528 
1529             "float intBitsToFloat(highp int   value);"
1530             "vec2  intBitsToFloat(highp ivec2 value);"
1531             "vec3  intBitsToFloat(highp ivec3 value);"
1532             "vec4  intBitsToFloat(highp ivec4 value);"
1533 
1534             "float uintBitsToFloat(highp uint  value);"
1535             "vec2  uintBitsToFloat(highp uvec2 value);"
1536             "vec3  uintBitsToFloat(highp uvec3 value);"
1537             "vec4  uintBitsToFloat(highp uvec4 value);"
1538 
1539             "\n");
1540     }
1541 
1542 #ifndef GLSLANG_WEB
1543     if ((profile != EEsProfile && version >= 400) ||
1544         (profile == EEsProfile && version >= 310)) {    // GL_OES_gpu_shader5
1545 
1546         commonBuiltins.append(
1547             "float  fma(float,  float,  float );"
1548             "vec2   fma(vec2,   vec2,   vec2  );"
1549             "vec3   fma(vec3,   vec3,   vec3  );"
1550             "vec4   fma(vec4,   vec4,   vec4  );"
1551             "\n");
1552     }
1553 
1554 #ifndef GLSLANG_ANGLE
1555     if (profile != EEsProfile && version >= 150) {  // ARB_gpu_shader_fp64
1556             commonBuiltins.append(
1557                 "double fma(double, double, double);"
1558                 "dvec2  fma(dvec2,  dvec2,  dvec2 );"
1559                 "dvec3  fma(dvec3,  dvec3,  dvec3 );"
1560                 "dvec4  fma(dvec4,  dvec4,  dvec4 );"
1561                 "\n");
1562     }
1563 
1564     if (profile == EEsProfile && version >= 310) {  // ARB_gpu_shader_fp64
1565             commonBuiltins.append(
1566                 "float64_t fma(float64_t, float64_t, float64_t);"
1567                 "f64vec2  fma(f64vec2,  f64vec2,  f64vec2 );"
1568                 "f64vec3  fma(f64vec3,  f64vec3,  f64vec3 );"
1569                 "f64vec4  fma(f64vec4,  f64vec4,  f64vec4 );"
1570                 "\n");
1571     }
1572 #endif
1573 
1574     if ((profile == EEsProfile && version >= 310) ||
1575         (profile != EEsProfile && version >= 400)) {
1576         commonBuiltins.append(
1577             "float frexp(highp float, out highp int);"
1578             "vec2  frexp(highp vec2,  out highp ivec2);"
1579             "vec3  frexp(highp vec3,  out highp ivec3);"
1580             "vec4  frexp(highp vec4,  out highp ivec4);"
1581 
1582             "float ldexp(highp float, highp int);"
1583             "vec2  ldexp(highp vec2,  highp ivec2);"
1584             "vec3  ldexp(highp vec3,  highp ivec3);"
1585             "vec4  ldexp(highp vec4,  highp ivec4);"
1586 
1587             "\n");
1588     }
1589 
1590 #ifndef GLSLANG_ANGLE
1591     if (profile != EEsProfile && version >= 150) { // ARB_gpu_shader_fp64
1592         commonBuiltins.append(
1593             "double frexp(double, out int);"
1594             "dvec2  frexp( dvec2, out ivec2);"
1595             "dvec3  frexp( dvec3, out ivec3);"
1596             "dvec4  frexp( dvec4, out ivec4);"
1597 
1598             "double ldexp(double, int);"
1599             "dvec2  ldexp( dvec2, ivec2);"
1600             "dvec3  ldexp( dvec3, ivec3);"
1601             "dvec4  ldexp( dvec4, ivec4);"
1602 
1603             "double packDouble2x32(uvec2);"
1604             "uvec2 unpackDouble2x32(double);"
1605 
1606             "\n");
1607     }
1608 
1609     if (profile == EEsProfile && version >= 310) { // ARB_gpu_shader_fp64
1610         commonBuiltins.append(
1611             "float64_t frexp(float64_t, out int);"
1612             "f64vec2  frexp( f64vec2, out ivec2);"
1613             "f64vec3  frexp( f64vec3, out ivec3);"
1614             "f64vec4  frexp( f64vec4, out ivec4);"
1615 
1616             "float64_t ldexp(float64_t, int);"
1617             "f64vec2  ldexp( f64vec2, ivec2);"
1618             "f64vec3  ldexp( f64vec3, ivec3);"
1619             "f64vec4  ldexp( f64vec4, ivec4);"
1620 
1621             "\n");
1622     }
1623 #endif
1624 #endif
1625 
1626     if ((profile == EEsProfile && version >= 300) ||
1627         (profile != EEsProfile && version >= 150)) {
1628         commonBuiltins.append(
1629             "highp uint packUnorm2x16(vec2);"
1630                   "vec2 unpackUnorm2x16(highp uint);"
1631             "\n");
1632     }
1633 
1634     if ((profile == EEsProfile && version >= 300) ||
1635         (profile != EEsProfile && version >= 150)) {
1636         commonBuiltins.append(
1637             "highp uint packSnorm2x16(vec2);"
1638             "      vec2 unpackSnorm2x16(highp uint);"
1639             "highp uint packHalf2x16(vec2);"
1640             "\n");
1641     }
1642 
1643     if (profile == EEsProfile && version >= 300) {
1644         commonBuiltins.append(
1645             "mediump vec2 unpackHalf2x16(highp uint);"
1646             "\n");
1647     } else if (profile != EEsProfile && version >= 150) {
1648         commonBuiltins.append(
1649             "        vec2 unpackHalf2x16(highp uint);"
1650             "\n");
1651     }
1652 
1653 #ifndef GLSLANG_WEB
1654     if ((profile == EEsProfile && version >= 310) ||
1655         (profile != EEsProfile && version >= 150)) {
1656         commonBuiltins.append(
1657             "highp uint packSnorm4x8(vec4);"
1658             "highp uint packUnorm4x8(vec4);"
1659             "\n");
1660     }
1661 
1662     if (profile == EEsProfile && version >= 310) {
1663         commonBuiltins.append(
1664             "mediump vec4 unpackSnorm4x8(highp uint);"
1665             "mediump vec4 unpackUnorm4x8(highp uint);"
1666             "\n");
1667     } else if (profile != EEsProfile && version >= 150) {
1668         commonBuiltins.append(
1669                     "vec4 unpackSnorm4x8(highp uint);"
1670                     "vec4 unpackUnorm4x8(highp uint);"
1671             "\n");
1672     }
1673 #endif
1674 
1675     //
1676     // Matrix Functions.
1677     //
1678     commonBuiltins.append(
1679         "mat2 matrixCompMult(mat2 x, mat2 y);"
1680         "mat3 matrixCompMult(mat3 x, mat3 y);"
1681         "mat4 matrixCompMult(mat4 x, mat4 y);"
1682 
1683         "\n");
1684 
1685     // 120 is correct for both ES and desktop
1686     if (version >= 120) {
1687         commonBuiltins.append(
1688             "mat2   outerProduct(vec2 c, vec2 r);"
1689             "mat3   outerProduct(vec3 c, vec3 r);"
1690             "mat4   outerProduct(vec4 c, vec4 r);"
1691             "mat2x3 outerProduct(vec3 c, vec2 r);"
1692             "mat3x2 outerProduct(vec2 c, vec3 r);"
1693             "mat2x4 outerProduct(vec4 c, vec2 r);"
1694             "mat4x2 outerProduct(vec2 c, vec4 r);"
1695             "mat3x4 outerProduct(vec4 c, vec3 r);"
1696             "mat4x3 outerProduct(vec3 c, vec4 r);"
1697 
1698             "mat2   transpose(mat2   m);"
1699             "mat3   transpose(mat3   m);"
1700             "mat4   transpose(mat4   m);"
1701             "mat2x3 transpose(mat3x2 m);"
1702             "mat3x2 transpose(mat2x3 m);"
1703             "mat2x4 transpose(mat4x2 m);"
1704             "mat4x2 transpose(mat2x4 m);"
1705             "mat3x4 transpose(mat4x3 m);"
1706             "mat4x3 transpose(mat3x4 m);"
1707 
1708             "mat2x3 matrixCompMult(mat2x3, mat2x3);"
1709             "mat2x4 matrixCompMult(mat2x4, mat2x4);"
1710             "mat3x2 matrixCompMult(mat3x2, mat3x2);"
1711             "mat3x4 matrixCompMult(mat3x4, mat3x4);"
1712             "mat4x2 matrixCompMult(mat4x2, mat4x2);"
1713             "mat4x3 matrixCompMult(mat4x3, mat4x3);"
1714 
1715             "\n");
1716 
1717         // 150 is correct for both ES and desktop
1718         if (version >= 150) {
1719             commonBuiltins.append(
1720                 "float determinant(mat2 m);"
1721                 "float determinant(mat3 m);"
1722                 "float determinant(mat4 m);"
1723 
1724                 "mat2 inverse(mat2 m);"
1725                 "mat3 inverse(mat3 m);"
1726                 "mat4 inverse(mat4 m);"
1727 
1728                 "\n");
1729         }
1730     }
1731 
1732 #ifndef GLSLANG_WEB
1733 #ifndef GLSLANG_ANGLE
1734     //
1735     // Original-style texture functions existing in all stages.
1736     // (Per-stage functions below.)
1737     //
1738     if ((profile == EEsProfile && version == 100) ||
1739          profile == ECompatibilityProfile ||
1740         (profile == ECoreProfile && version < 420) ||
1741          profile == ENoProfile) {
1742         if (spvVersion.spv == 0) {
1743             commonBuiltins.append(
1744                 "vec4 texture2D(sampler2D, vec2);"
1745 
1746                 "vec4 texture2DProj(sampler2D, vec3);"
1747                 "vec4 texture2DProj(sampler2D, vec4);"
1748 
1749                 "vec4 texture3D(sampler3D, vec3);"     // OES_texture_3D, but caught by keyword check
1750                 "vec4 texture3DProj(sampler3D, vec4);" // OES_texture_3D, but caught by keyword check
1751 
1752                 "vec4 textureCube(samplerCube, vec3);"
1753 
1754                 "\n");
1755         }
1756     }
1757 
1758     if ( profile == ECompatibilityProfile ||
1759         (profile == ECoreProfile && version < 420) ||
1760          profile == ENoProfile) {
1761         if (spvVersion.spv == 0) {
1762             commonBuiltins.append(
1763                 "vec4 texture1D(sampler1D, float);"
1764 
1765                 "vec4 texture1DProj(sampler1D, vec2);"
1766                 "vec4 texture1DProj(sampler1D, vec4);"
1767 
1768                 "vec4 shadow1D(sampler1DShadow, vec3);"
1769                 "vec4 shadow2D(sampler2DShadow, vec3);"
1770                 "vec4 shadow1DProj(sampler1DShadow, vec4);"
1771                 "vec4 shadow2DProj(sampler2DShadow, vec4);"
1772 
1773                 "vec4 texture2DRect(sampler2DRect, vec2);"          // GL_ARB_texture_rectangle, caught by keyword check
1774                 "vec4 texture2DRectProj(sampler2DRect, vec3);"      // GL_ARB_texture_rectangle, caught by keyword check
1775                 "vec4 texture2DRectProj(sampler2DRect, vec4);"      // GL_ARB_texture_rectangle, caught by keyword check
1776                 "vec4 shadow2DRect(sampler2DRectShadow, vec3);"     // GL_ARB_texture_rectangle, caught by keyword check
1777                 "vec4 shadow2DRectProj(sampler2DRectShadow, vec4);" // GL_ARB_texture_rectangle, caught by keyword check
1778 
1779                 "\n");
1780         }
1781     }
1782 
1783     if (profile == EEsProfile) {
1784         if (spvVersion.spv == 0) {
1785             if (version < 300) {
1786                 commonBuiltins.append(
1787                     "vec4 texture2D(samplerExternalOES, vec2 coord);" // GL_OES_EGL_image_external
1788                     "vec4 texture2DProj(samplerExternalOES, vec3);"   // GL_OES_EGL_image_external
1789                     "vec4 texture2DProj(samplerExternalOES, vec4);"   // GL_OES_EGL_image_external
1790                 "\n");
1791             } else {
1792                 commonBuiltins.append(
1793                     "highp ivec2 textureSize(samplerExternalOES, int lod);"   // GL_OES_EGL_image_external_essl3
1794                     "vec4 texture(samplerExternalOES, vec2);"                 // GL_OES_EGL_image_external_essl3
1795                     "vec4 texture(samplerExternalOES, vec2, float bias);"     // GL_OES_EGL_image_external_essl3
1796                     "vec4 textureProj(samplerExternalOES, vec3);"             // GL_OES_EGL_image_external_essl3
1797                     "vec4 textureProj(samplerExternalOES, vec3, float bias);" // GL_OES_EGL_image_external_essl3
1798                     "vec4 textureProj(samplerExternalOES, vec4);"             // GL_OES_EGL_image_external_essl3
1799                     "vec4 textureProj(samplerExternalOES, vec4, float bias);" // GL_OES_EGL_image_external_essl3
1800                     "vec4 texelFetch(samplerExternalOES, ivec2, int lod);"    // GL_OES_EGL_image_external_essl3
1801                 "\n");
1802             }
1803             commonBuiltins.append(
1804                 "highp ivec2 textureSize(__samplerExternal2DY2YEXT, int lod);" // GL_EXT_YUV_target
1805                 "vec4 texture(__samplerExternal2DY2YEXT, vec2);"               // GL_EXT_YUV_target
1806                 "vec4 texture(__samplerExternal2DY2YEXT, vec2, float bias);"   // GL_EXT_YUV_target
1807                 "vec4 textureProj(__samplerExternal2DY2YEXT, vec3);"           // GL_EXT_YUV_target
1808                 "vec4 textureProj(__samplerExternal2DY2YEXT, vec3, float bias);" // GL_EXT_YUV_target
1809                 "vec4 textureProj(__samplerExternal2DY2YEXT, vec4);"           // GL_EXT_YUV_target
1810                 "vec4 textureProj(__samplerExternal2DY2YEXT, vec4, float bias);" // GL_EXT_YUV_target
1811                 "vec4 texelFetch(__samplerExternal2DY2YEXT sampler, ivec2, int lod);" // GL_EXT_YUV_target
1812                 "\n");
1813             commonBuiltins.append(
1814                 "vec4 texture2DGradEXT(sampler2D, vec2, vec2, vec2);"      // GL_EXT_shader_texture_lod
1815                 "vec4 texture2DProjGradEXT(sampler2D, vec3, vec2, vec2);"  // GL_EXT_shader_texture_lod
1816                 "vec4 texture2DProjGradEXT(sampler2D, vec4, vec2, vec2);"  // GL_EXT_shader_texture_lod
1817                 "vec4 textureCubeGradEXT(samplerCube, vec3, vec3, vec3);"  // GL_EXT_shader_texture_lod
1818 
1819                 "float shadow2DEXT(sampler2DShadow, vec3);"     // GL_EXT_shadow_samplers
1820                 "float shadow2DProjEXT(sampler2DShadow, vec4);" // GL_EXT_shadow_samplers
1821 
1822                 "\n");
1823         }
1824     }
1825 
1826     //
1827     // Noise functions.
1828     //
1829     if (spvVersion.spv == 0 && profile != EEsProfile) {
1830         commonBuiltins.append(
1831             "float noise1(float x);"
1832             "float noise1(vec2  x);"
1833             "float noise1(vec3  x);"
1834             "float noise1(vec4  x);"
1835 
1836             "vec2 noise2(float x);"
1837             "vec2 noise2(vec2  x);"
1838             "vec2 noise2(vec3  x);"
1839             "vec2 noise2(vec4  x);"
1840 
1841             "vec3 noise3(float x);"
1842             "vec3 noise3(vec2  x);"
1843             "vec3 noise3(vec3  x);"
1844             "vec3 noise3(vec4  x);"
1845 
1846             "vec4 noise4(float x);"
1847             "vec4 noise4(vec2  x);"
1848             "vec4 noise4(vec3  x);"
1849             "vec4 noise4(vec4  x);"
1850 
1851             "\n");
1852     }
1853 
1854     if (spvVersion.vulkan == 0) {
1855         //
1856         // Atomic counter functions.
1857         //
1858         if ((profile != EEsProfile && version >= 300) ||
1859             (profile == EEsProfile && version >= 310)) {
1860             commonBuiltins.append(
1861                 "uint atomicCounterIncrement(atomic_uint);"
1862                 "uint atomicCounterDecrement(atomic_uint);"
1863                 "uint atomicCounter(atomic_uint);"
1864 
1865                 "\n");
1866         }
1867         if (profile != EEsProfile && version == 450) {
1868             commonBuiltins.append(
1869                 "uint atomicCounterAddARB(atomic_uint, uint);"
1870                 "uint atomicCounterSubtractARB(atomic_uint, uint);"
1871                 "uint atomicCounterMinARB(atomic_uint, uint);"
1872                 "uint atomicCounterMaxARB(atomic_uint, uint);"
1873                 "uint atomicCounterAndARB(atomic_uint, uint);"
1874                 "uint atomicCounterOrARB(atomic_uint, uint);"
1875                 "uint atomicCounterXorARB(atomic_uint, uint);"
1876                 "uint atomicCounterExchangeARB(atomic_uint, uint);"
1877                 "uint atomicCounterCompSwapARB(atomic_uint, uint, uint);"
1878 
1879                 "\n");
1880         }
1881 
1882 
1883         if (profile != EEsProfile && version >= 460) {
1884             commonBuiltins.append(
1885                 "uint atomicCounterAdd(atomic_uint, uint);"
1886                 "uint atomicCounterSubtract(atomic_uint, uint);"
1887                 "uint atomicCounterMin(atomic_uint, uint);"
1888                 "uint atomicCounterMax(atomic_uint, uint);"
1889                 "uint atomicCounterAnd(atomic_uint, uint);"
1890                 "uint atomicCounterOr(atomic_uint, uint);"
1891                 "uint atomicCounterXor(atomic_uint, uint);"
1892                 "uint atomicCounterExchange(atomic_uint, uint);"
1893                 "uint atomicCounterCompSwap(atomic_uint, uint, uint);"
1894 
1895                 "\n");
1896         }
1897     }
1898     else if (spvVersion.vulkanRelaxed) {
1899         //
1900         // Atomic counter functions act as aliases to normal atomic functions.
1901         // replace definitions to take 'volatile coherent uint' instead of 'atomic_uint'
1902         // and map to equivalent non-counter atomic op
1903         //
1904         if ((profile != EEsProfile && version >= 300) ||
1905             (profile == EEsProfile && version >= 310)) {
1906             commonBuiltins.append(
1907                 "uint atomicCounterIncrement(volatile coherent uint);"
1908                 "uint atomicCounterDecrement(volatile coherent uint);"
1909                 "uint atomicCounter(volatile coherent uint);"
1910 
1911                 "\n");
1912         }
1913         if (profile != EEsProfile && version >= 460) {
1914             commonBuiltins.append(
1915                 "uint atomicCounterAdd(volatile coherent uint, uint);"
1916                 "uint atomicCounterSubtract(volatile coherent uint, uint);"
1917                 "uint atomicCounterMin(volatile coherent uint, uint);"
1918                 "uint atomicCounterMax(volatile coherent uint, uint);"
1919                 "uint atomicCounterAnd(volatile coherent uint, uint);"
1920                 "uint atomicCounterOr(volatile coherent uint, uint);"
1921                 "uint atomicCounterXor(volatile coherent uint, uint);"
1922                 "uint atomicCounterExchange(volatile coherent uint, uint);"
1923                 "uint atomicCounterCompSwap(volatile coherent uint, uint, uint);"
1924 
1925                 "\n");
1926         }
1927     }
1928 #endif // !GLSLANG_ANGLE
1929 
1930     // Bitfield
1931     if ((profile == EEsProfile && version >= 310) ||
1932         (profile != EEsProfile && version >= 400)) {
1933         commonBuiltins.append(
1934             "  int bitfieldExtract(  int, int, int);"
1935             "ivec2 bitfieldExtract(ivec2, int, int);"
1936             "ivec3 bitfieldExtract(ivec3, int, int);"
1937             "ivec4 bitfieldExtract(ivec4, int, int);"
1938 
1939             " uint bitfieldExtract( uint, int, int);"
1940             "uvec2 bitfieldExtract(uvec2, int, int);"
1941             "uvec3 bitfieldExtract(uvec3, int, int);"
1942             "uvec4 bitfieldExtract(uvec4, int, int);"
1943 
1944             "  int bitfieldInsert(  int base,   int, int, int);"
1945             "ivec2 bitfieldInsert(ivec2 base, ivec2, int, int);"
1946             "ivec3 bitfieldInsert(ivec3 base, ivec3, int, int);"
1947             "ivec4 bitfieldInsert(ivec4 base, ivec4, int, int);"
1948 
1949             " uint bitfieldInsert( uint base,  uint, int, int);"
1950             "uvec2 bitfieldInsert(uvec2 base, uvec2, int, int);"
1951             "uvec3 bitfieldInsert(uvec3 base, uvec3, int, int);"
1952             "uvec4 bitfieldInsert(uvec4 base, uvec4, int, int);"
1953 
1954             "\n");
1955     }
1956 
1957     if (profile != EEsProfile && version >= 400) {
1958         commonBuiltins.append(
1959             "  int findLSB(  int);"
1960             "ivec2 findLSB(ivec2);"
1961             "ivec3 findLSB(ivec3);"
1962             "ivec4 findLSB(ivec4);"
1963 
1964             "  int findLSB( uint);"
1965             "ivec2 findLSB(uvec2);"
1966             "ivec3 findLSB(uvec3);"
1967             "ivec4 findLSB(uvec4);"
1968 
1969             "\n");
1970     } else if (profile == EEsProfile && version >= 310) {
1971         commonBuiltins.append(
1972             "lowp   int findLSB(  int);"
1973             "lowp ivec2 findLSB(ivec2);"
1974             "lowp ivec3 findLSB(ivec3);"
1975             "lowp ivec4 findLSB(ivec4);"
1976 
1977             "lowp   int findLSB( uint);"
1978             "lowp ivec2 findLSB(uvec2);"
1979             "lowp ivec3 findLSB(uvec3);"
1980             "lowp ivec4 findLSB(uvec4);"
1981 
1982             "\n");
1983     }
1984 
1985     if (profile != EEsProfile && version >= 400) {
1986         commonBuiltins.append(
1987             "  int bitCount(  int);"
1988             "ivec2 bitCount(ivec2);"
1989             "ivec3 bitCount(ivec3);"
1990             "ivec4 bitCount(ivec4);"
1991 
1992             "  int bitCount( uint);"
1993             "ivec2 bitCount(uvec2);"
1994             "ivec3 bitCount(uvec3);"
1995             "ivec4 bitCount(uvec4);"
1996 
1997             "  int findMSB(highp   int);"
1998             "ivec2 findMSB(highp ivec2);"
1999             "ivec3 findMSB(highp ivec3);"
2000             "ivec4 findMSB(highp ivec4);"
2001 
2002             "  int findMSB(highp  uint);"
2003             "ivec2 findMSB(highp uvec2);"
2004             "ivec3 findMSB(highp uvec3);"
2005             "ivec4 findMSB(highp uvec4);"
2006 
2007             "\n");
2008     }
2009 
2010     if ((profile == EEsProfile && version >= 310) ||
2011         (profile != EEsProfile && version >= 400)) {
2012         commonBuiltins.append(
2013             " uint uaddCarry(highp  uint, highp  uint, out lowp  uint carry);"
2014             "uvec2 uaddCarry(highp uvec2, highp uvec2, out lowp uvec2 carry);"
2015             "uvec3 uaddCarry(highp uvec3, highp uvec3, out lowp uvec3 carry);"
2016             "uvec4 uaddCarry(highp uvec4, highp uvec4, out lowp uvec4 carry);"
2017 
2018             " uint usubBorrow(highp  uint, highp  uint, out lowp  uint borrow);"
2019             "uvec2 usubBorrow(highp uvec2, highp uvec2, out lowp uvec2 borrow);"
2020             "uvec3 usubBorrow(highp uvec3, highp uvec3, out lowp uvec3 borrow);"
2021             "uvec4 usubBorrow(highp uvec4, highp uvec4, out lowp uvec4 borrow);"
2022 
2023             "void umulExtended(highp  uint, highp  uint, out highp  uint, out highp  uint lsb);"
2024             "void umulExtended(highp uvec2, highp uvec2, out highp uvec2, out highp uvec2 lsb);"
2025             "void umulExtended(highp uvec3, highp uvec3, out highp uvec3, out highp uvec3 lsb);"
2026             "void umulExtended(highp uvec4, highp uvec4, out highp uvec4, out highp uvec4 lsb);"
2027 
2028             "void imulExtended(highp   int, highp   int, out highp   int, out highp   int lsb);"
2029             "void imulExtended(highp ivec2, highp ivec2, out highp ivec2, out highp ivec2 lsb);"
2030             "void imulExtended(highp ivec3, highp ivec3, out highp ivec3, out highp ivec3 lsb);"
2031             "void imulExtended(highp ivec4, highp ivec4, out highp ivec4, out highp ivec4 lsb);"
2032 
2033             "  int bitfieldReverse(highp   int);"
2034             "ivec2 bitfieldReverse(highp ivec2);"
2035             "ivec3 bitfieldReverse(highp ivec3);"
2036             "ivec4 bitfieldReverse(highp ivec4);"
2037 
2038             " uint bitfieldReverse(highp  uint);"
2039             "uvec2 bitfieldReverse(highp uvec2);"
2040             "uvec3 bitfieldReverse(highp uvec3);"
2041             "uvec4 bitfieldReverse(highp uvec4);"
2042 
2043             "\n");
2044     }
2045 
2046     if (profile == EEsProfile && version >= 310) {
2047         commonBuiltins.append(
2048             "lowp   int bitCount(  int);"
2049             "lowp ivec2 bitCount(ivec2);"
2050             "lowp ivec3 bitCount(ivec3);"
2051             "lowp ivec4 bitCount(ivec4);"
2052 
2053             "lowp   int bitCount( uint);"
2054             "lowp ivec2 bitCount(uvec2);"
2055             "lowp ivec3 bitCount(uvec3);"
2056             "lowp ivec4 bitCount(uvec4);"
2057 
2058             "lowp   int findMSB(highp   int);"
2059             "lowp ivec2 findMSB(highp ivec2);"
2060             "lowp ivec3 findMSB(highp ivec3);"
2061             "lowp ivec4 findMSB(highp ivec4);"
2062 
2063             "lowp   int findMSB(highp  uint);"
2064             "lowp ivec2 findMSB(highp uvec2);"
2065             "lowp ivec3 findMSB(highp uvec3);"
2066             "lowp ivec4 findMSB(highp uvec4);"
2067 
2068             "\n");
2069     }
2070 
2071 #ifndef GLSLANG_ANGLE
2072     // GL_ARB_shader_ballot
2073     if (profile != EEsProfile && version >= 450) {
2074         commonBuiltins.append(
2075             "uint64_t ballotARB(bool);"
2076 
2077             "float readInvocationARB(float, uint);"
2078             "vec2  readInvocationARB(vec2,  uint);"
2079             "vec3  readInvocationARB(vec3,  uint);"
2080             "vec4  readInvocationARB(vec4,  uint);"
2081 
2082             "int   readInvocationARB(int,   uint);"
2083             "ivec2 readInvocationARB(ivec2, uint);"
2084             "ivec3 readInvocationARB(ivec3, uint);"
2085             "ivec4 readInvocationARB(ivec4, uint);"
2086 
2087             "uint  readInvocationARB(uint,  uint);"
2088             "uvec2 readInvocationARB(uvec2, uint);"
2089             "uvec3 readInvocationARB(uvec3, uint);"
2090             "uvec4 readInvocationARB(uvec4, uint);"
2091 
2092             "float readFirstInvocationARB(float);"
2093             "vec2  readFirstInvocationARB(vec2);"
2094             "vec3  readFirstInvocationARB(vec3);"
2095             "vec4  readFirstInvocationARB(vec4);"
2096 
2097             "int   readFirstInvocationARB(int);"
2098             "ivec2 readFirstInvocationARB(ivec2);"
2099             "ivec3 readFirstInvocationARB(ivec3);"
2100             "ivec4 readFirstInvocationARB(ivec4);"
2101 
2102             "uint  readFirstInvocationARB(uint);"
2103             "uvec2 readFirstInvocationARB(uvec2);"
2104             "uvec3 readFirstInvocationARB(uvec3);"
2105             "uvec4 readFirstInvocationARB(uvec4);"
2106 
2107             "\n");
2108     }
2109 
2110     // GL_ARB_shader_group_vote
2111     if (profile != EEsProfile && version >= 430) {
2112         commonBuiltins.append(
2113             "bool anyInvocationARB(bool);"
2114             "bool allInvocationsARB(bool);"
2115             "bool allInvocationsEqualARB(bool);"
2116 
2117             "\n");
2118     }
2119 
2120     // GL_KHR_shader_subgroup
2121     if ((profile == EEsProfile && version >= 310) ||
2122         (profile != EEsProfile && version >= 140)) {
2123         commonBuiltins.append(
2124             "void subgroupBarrier();"
2125             "void subgroupMemoryBarrier();"
2126             "void subgroupMemoryBarrierBuffer();"
2127             "void subgroupMemoryBarrierImage();"
2128             "bool subgroupElect();"
2129 
2130             "bool   subgroupAll(bool);\n"
2131             "bool   subgroupAny(bool);\n"
2132             "uvec4  subgroupBallot(bool);\n"
2133             "bool   subgroupInverseBallot(uvec4);\n"
2134             "bool   subgroupBallotBitExtract(uvec4, uint);\n"
2135             "uint   subgroupBallotBitCount(uvec4);\n"
2136             "uint   subgroupBallotInclusiveBitCount(uvec4);\n"
2137             "uint   subgroupBallotExclusiveBitCount(uvec4);\n"
2138             "uint   subgroupBallotFindLSB(uvec4);\n"
2139             "uint   subgroupBallotFindMSB(uvec4);\n"
2140             );
2141 
2142         // Generate all flavors of subgroup ops.
2143         static const char *subgroupOps[] =
2144         {
2145             "bool   subgroupAllEqual(%s);\n",
2146             "%s     subgroupBroadcast(%s, uint);\n",
2147             "%s     subgroupBroadcastFirst(%s);\n",
2148             "%s     subgroupShuffle(%s, uint);\n",
2149             "%s     subgroupShuffleXor(%s, uint);\n",
2150             "%s     subgroupShuffleUp(%s, uint delta);\n",
2151             "%s     subgroupShuffleDown(%s, uint delta);\n",
2152             "%s     subgroupAdd(%s);\n",
2153             "%s     subgroupMul(%s);\n",
2154             "%s     subgroupMin(%s);\n",
2155             "%s     subgroupMax(%s);\n",
2156             "%s     subgroupAnd(%s);\n",
2157             "%s     subgroupOr(%s);\n",
2158             "%s     subgroupXor(%s);\n",
2159             "%s     subgroupInclusiveAdd(%s);\n",
2160             "%s     subgroupInclusiveMul(%s);\n",
2161             "%s     subgroupInclusiveMin(%s);\n",
2162             "%s     subgroupInclusiveMax(%s);\n",
2163             "%s     subgroupInclusiveAnd(%s);\n",
2164             "%s     subgroupInclusiveOr(%s);\n",
2165             "%s     subgroupInclusiveXor(%s);\n",
2166             "%s     subgroupExclusiveAdd(%s);\n",
2167             "%s     subgroupExclusiveMul(%s);\n",
2168             "%s     subgroupExclusiveMin(%s);\n",
2169             "%s     subgroupExclusiveMax(%s);\n",
2170             "%s     subgroupExclusiveAnd(%s);\n",
2171             "%s     subgroupExclusiveOr(%s);\n",
2172             "%s     subgroupExclusiveXor(%s);\n",
2173             "%s     subgroupClusteredAdd(%s, uint);\n",
2174             "%s     subgroupClusteredMul(%s, uint);\n",
2175             "%s     subgroupClusteredMin(%s, uint);\n",
2176             "%s     subgroupClusteredMax(%s, uint);\n",
2177             "%s     subgroupClusteredAnd(%s, uint);\n",
2178             "%s     subgroupClusteredOr(%s, uint);\n",
2179             "%s     subgroupClusteredXor(%s, uint);\n",
2180             "%s     subgroupQuadBroadcast(%s, uint);\n",
2181             "%s     subgroupQuadSwapHorizontal(%s);\n",
2182             "%s     subgroupQuadSwapVertical(%s);\n",
2183             "%s     subgroupQuadSwapDiagonal(%s);\n",
2184             "uvec4  subgroupPartitionNV(%s);\n",
2185             "%s     subgroupPartitionedAddNV(%s, uvec4 ballot);\n",
2186             "%s     subgroupPartitionedMulNV(%s, uvec4 ballot);\n",
2187             "%s     subgroupPartitionedMinNV(%s, uvec4 ballot);\n",
2188             "%s     subgroupPartitionedMaxNV(%s, uvec4 ballot);\n",
2189             "%s     subgroupPartitionedAndNV(%s, uvec4 ballot);\n",
2190             "%s     subgroupPartitionedOrNV(%s, uvec4 ballot);\n",
2191             "%s     subgroupPartitionedXorNV(%s, uvec4 ballot);\n",
2192             "%s     subgroupPartitionedInclusiveAddNV(%s, uvec4 ballot);\n",
2193             "%s     subgroupPartitionedInclusiveMulNV(%s, uvec4 ballot);\n",
2194             "%s     subgroupPartitionedInclusiveMinNV(%s, uvec4 ballot);\n",
2195             "%s     subgroupPartitionedInclusiveMaxNV(%s, uvec4 ballot);\n",
2196             "%s     subgroupPartitionedInclusiveAndNV(%s, uvec4 ballot);\n",
2197             "%s     subgroupPartitionedInclusiveOrNV(%s, uvec4 ballot);\n",
2198             "%s     subgroupPartitionedInclusiveXorNV(%s, uvec4 ballot);\n",
2199             "%s     subgroupPartitionedExclusiveAddNV(%s, uvec4 ballot);\n",
2200             "%s     subgroupPartitionedExclusiveMulNV(%s, uvec4 ballot);\n",
2201             "%s     subgroupPartitionedExclusiveMinNV(%s, uvec4 ballot);\n",
2202             "%s     subgroupPartitionedExclusiveMaxNV(%s, uvec4 ballot);\n",
2203             "%s     subgroupPartitionedExclusiveAndNV(%s, uvec4 ballot);\n",
2204             "%s     subgroupPartitionedExclusiveOrNV(%s, uvec4 ballot);\n",
2205             "%s     subgroupPartitionedExclusiveXorNV(%s, uvec4 ballot);\n",
2206         };
2207 
2208         static const char *floatTypes[] = {
2209             "float", "vec2", "vec3", "vec4",
2210             "float16_t", "f16vec2", "f16vec3", "f16vec4",
2211         };
2212         static const char *doubleTypes[] = {
2213             "double", "dvec2", "dvec3", "dvec4",
2214         };
2215         static const char *intTypes[] = {
2216             "int8_t", "i8vec2", "i8vec3", "i8vec4",
2217             "int16_t", "i16vec2", "i16vec3", "i16vec4",
2218             "int", "ivec2", "ivec3", "ivec4",
2219             "int64_t", "i64vec2", "i64vec3", "i64vec4",
2220             "uint8_t", "u8vec2", "u8vec3", "u8vec4",
2221             "uint16_t", "u16vec2", "u16vec3", "u16vec4",
2222             "uint", "uvec2", "uvec3", "uvec4",
2223             "uint64_t", "u64vec2", "u64vec3", "u64vec4",
2224         };
2225         static const char *boolTypes[] = {
2226             "bool", "bvec2", "bvec3", "bvec4",
2227         };
2228 
2229         for (size_t i = 0; i < sizeof(subgroupOps)/sizeof(subgroupOps[0]); ++i) {
2230             const char *op = subgroupOps[i];
2231 
2232             // Logical operations don't support float
2233             bool logicalOp = strstr(op, "Or") || strstr(op, "And") ||
2234                              (strstr(op, "Xor") && !strstr(op, "ShuffleXor"));
2235             // Math operations don't support bool
2236             bool mathOp = strstr(op, "Add") || strstr(op, "Mul") || strstr(op, "Min") || strstr(op, "Max");
2237 
2238             const int bufSize = 256;
2239             char buf[bufSize];
2240 
2241             if (!logicalOp) {
2242                 for (size_t j = 0; j < sizeof(floatTypes)/sizeof(floatTypes[0]); ++j) {
2243                     snprintf(buf, bufSize, op, floatTypes[j], floatTypes[j]);
2244                     commonBuiltins.append(buf);
2245                 }
2246                 if (profile != EEsProfile && version >= 400) {
2247                     for (size_t j = 0; j < sizeof(doubleTypes)/sizeof(doubleTypes[0]); ++j) {
2248                         snprintf(buf, bufSize, op, doubleTypes[j], doubleTypes[j]);
2249                         commonBuiltins.append(buf);
2250                     }
2251                 }
2252             }
2253             if (!mathOp) {
2254                 for (size_t j = 0; j < sizeof(boolTypes)/sizeof(boolTypes[0]); ++j) {
2255                     snprintf(buf, bufSize, op, boolTypes[j], boolTypes[j]);
2256                     commonBuiltins.append(buf);
2257                 }
2258             }
2259             for (size_t j = 0; j < sizeof(intTypes)/sizeof(intTypes[0]); ++j) {
2260                 snprintf(buf, bufSize, op, intTypes[j], intTypes[j]);
2261                 commonBuiltins.append(buf);
2262             }
2263         }
2264 
2265         stageBuiltins[EShLangCompute].append(
2266             "void subgroupMemoryBarrierShared();"
2267 
2268             "\n"
2269             );
2270         stageBuiltins[EShLangMeshNV].append(
2271             "void subgroupMemoryBarrierShared();"
2272             "\n"
2273             );
2274         stageBuiltins[EShLangTaskNV].append(
2275             "void subgroupMemoryBarrierShared();"
2276             "\n"
2277             );
2278     }
2279 
2280     if (profile != EEsProfile && version >= 460) {
2281         commonBuiltins.append(
2282             "bool anyInvocation(bool);"
2283             "bool allInvocations(bool);"
2284             "bool allInvocationsEqual(bool);"
2285 
2286             "\n");
2287     }
2288 
2289     // GL_AMD_shader_ballot
2290     if (profile != EEsProfile && version >= 450) {
2291         commonBuiltins.append(
2292             "float minInvocationsAMD(float);"
2293             "vec2  minInvocationsAMD(vec2);"
2294             "vec3  minInvocationsAMD(vec3);"
2295             "vec4  minInvocationsAMD(vec4);"
2296 
2297             "int   minInvocationsAMD(int);"
2298             "ivec2 minInvocationsAMD(ivec2);"
2299             "ivec3 minInvocationsAMD(ivec3);"
2300             "ivec4 minInvocationsAMD(ivec4);"
2301 
2302             "uint  minInvocationsAMD(uint);"
2303             "uvec2 minInvocationsAMD(uvec2);"
2304             "uvec3 minInvocationsAMD(uvec3);"
2305             "uvec4 minInvocationsAMD(uvec4);"
2306 
2307             "double minInvocationsAMD(double);"
2308             "dvec2  minInvocationsAMD(dvec2);"
2309             "dvec3  minInvocationsAMD(dvec3);"
2310             "dvec4  minInvocationsAMD(dvec4);"
2311 
2312             "int64_t minInvocationsAMD(int64_t);"
2313             "i64vec2 minInvocationsAMD(i64vec2);"
2314             "i64vec3 minInvocationsAMD(i64vec3);"
2315             "i64vec4 minInvocationsAMD(i64vec4);"
2316 
2317             "uint64_t minInvocationsAMD(uint64_t);"
2318             "u64vec2  minInvocationsAMD(u64vec2);"
2319             "u64vec3  minInvocationsAMD(u64vec3);"
2320             "u64vec4  minInvocationsAMD(u64vec4);"
2321 
2322             "float16_t minInvocationsAMD(float16_t);"
2323             "f16vec2   minInvocationsAMD(f16vec2);"
2324             "f16vec3   minInvocationsAMD(f16vec3);"
2325             "f16vec4   minInvocationsAMD(f16vec4);"
2326 
2327             "int16_t minInvocationsAMD(int16_t);"
2328             "i16vec2 minInvocationsAMD(i16vec2);"
2329             "i16vec3 minInvocationsAMD(i16vec3);"
2330             "i16vec4 minInvocationsAMD(i16vec4);"
2331 
2332             "uint16_t minInvocationsAMD(uint16_t);"
2333             "u16vec2  minInvocationsAMD(u16vec2);"
2334             "u16vec3  minInvocationsAMD(u16vec3);"
2335             "u16vec4  minInvocationsAMD(u16vec4);"
2336 
2337             "float minInvocationsInclusiveScanAMD(float);"
2338             "vec2  minInvocationsInclusiveScanAMD(vec2);"
2339             "vec3  minInvocationsInclusiveScanAMD(vec3);"
2340             "vec4  minInvocationsInclusiveScanAMD(vec4);"
2341 
2342             "int   minInvocationsInclusiveScanAMD(int);"
2343             "ivec2 minInvocationsInclusiveScanAMD(ivec2);"
2344             "ivec3 minInvocationsInclusiveScanAMD(ivec3);"
2345             "ivec4 minInvocationsInclusiveScanAMD(ivec4);"
2346 
2347             "uint  minInvocationsInclusiveScanAMD(uint);"
2348             "uvec2 minInvocationsInclusiveScanAMD(uvec2);"
2349             "uvec3 minInvocationsInclusiveScanAMD(uvec3);"
2350             "uvec4 minInvocationsInclusiveScanAMD(uvec4);"
2351 
2352             "double minInvocationsInclusiveScanAMD(double);"
2353             "dvec2  minInvocationsInclusiveScanAMD(dvec2);"
2354             "dvec3  minInvocationsInclusiveScanAMD(dvec3);"
2355             "dvec4  minInvocationsInclusiveScanAMD(dvec4);"
2356 
2357             "int64_t minInvocationsInclusiveScanAMD(int64_t);"
2358             "i64vec2 minInvocationsInclusiveScanAMD(i64vec2);"
2359             "i64vec3 minInvocationsInclusiveScanAMD(i64vec3);"
2360             "i64vec4 minInvocationsInclusiveScanAMD(i64vec4);"
2361 
2362             "uint64_t minInvocationsInclusiveScanAMD(uint64_t);"
2363             "u64vec2  minInvocationsInclusiveScanAMD(u64vec2);"
2364             "u64vec3  minInvocationsInclusiveScanAMD(u64vec3);"
2365             "u64vec4  minInvocationsInclusiveScanAMD(u64vec4);"
2366 
2367             "float16_t minInvocationsInclusiveScanAMD(float16_t);"
2368             "f16vec2   minInvocationsInclusiveScanAMD(f16vec2);"
2369             "f16vec3   minInvocationsInclusiveScanAMD(f16vec3);"
2370             "f16vec4   minInvocationsInclusiveScanAMD(f16vec4);"
2371 
2372             "int16_t minInvocationsInclusiveScanAMD(int16_t);"
2373             "i16vec2 minInvocationsInclusiveScanAMD(i16vec2);"
2374             "i16vec3 minInvocationsInclusiveScanAMD(i16vec3);"
2375             "i16vec4 minInvocationsInclusiveScanAMD(i16vec4);"
2376 
2377             "uint16_t minInvocationsInclusiveScanAMD(uint16_t);"
2378             "u16vec2  minInvocationsInclusiveScanAMD(u16vec2);"
2379             "u16vec3  minInvocationsInclusiveScanAMD(u16vec3);"
2380             "u16vec4  minInvocationsInclusiveScanAMD(u16vec4);"
2381 
2382             "float minInvocationsExclusiveScanAMD(float);"
2383             "vec2  minInvocationsExclusiveScanAMD(vec2);"
2384             "vec3  minInvocationsExclusiveScanAMD(vec3);"
2385             "vec4  minInvocationsExclusiveScanAMD(vec4);"
2386 
2387             "int   minInvocationsExclusiveScanAMD(int);"
2388             "ivec2 minInvocationsExclusiveScanAMD(ivec2);"
2389             "ivec3 minInvocationsExclusiveScanAMD(ivec3);"
2390             "ivec4 minInvocationsExclusiveScanAMD(ivec4);"
2391 
2392             "uint  minInvocationsExclusiveScanAMD(uint);"
2393             "uvec2 minInvocationsExclusiveScanAMD(uvec2);"
2394             "uvec3 minInvocationsExclusiveScanAMD(uvec3);"
2395             "uvec4 minInvocationsExclusiveScanAMD(uvec4);"
2396 
2397             "double minInvocationsExclusiveScanAMD(double);"
2398             "dvec2  minInvocationsExclusiveScanAMD(dvec2);"
2399             "dvec3  minInvocationsExclusiveScanAMD(dvec3);"
2400             "dvec4  minInvocationsExclusiveScanAMD(dvec4);"
2401 
2402             "int64_t minInvocationsExclusiveScanAMD(int64_t);"
2403             "i64vec2 minInvocationsExclusiveScanAMD(i64vec2);"
2404             "i64vec3 minInvocationsExclusiveScanAMD(i64vec3);"
2405             "i64vec4 minInvocationsExclusiveScanAMD(i64vec4);"
2406 
2407             "uint64_t minInvocationsExclusiveScanAMD(uint64_t);"
2408             "u64vec2  minInvocationsExclusiveScanAMD(u64vec2);"
2409             "u64vec3  minInvocationsExclusiveScanAMD(u64vec3);"
2410             "u64vec4  minInvocationsExclusiveScanAMD(u64vec4);"
2411 
2412             "float16_t minInvocationsExclusiveScanAMD(float16_t);"
2413             "f16vec2   minInvocationsExclusiveScanAMD(f16vec2);"
2414             "f16vec3   minInvocationsExclusiveScanAMD(f16vec3);"
2415             "f16vec4   minInvocationsExclusiveScanAMD(f16vec4);"
2416 
2417             "int16_t minInvocationsExclusiveScanAMD(int16_t);"
2418             "i16vec2 minInvocationsExclusiveScanAMD(i16vec2);"
2419             "i16vec3 minInvocationsExclusiveScanAMD(i16vec3);"
2420             "i16vec4 minInvocationsExclusiveScanAMD(i16vec4);"
2421 
2422             "uint16_t minInvocationsExclusiveScanAMD(uint16_t);"
2423             "u16vec2  minInvocationsExclusiveScanAMD(u16vec2);"
2424             "u16vec3  minInvocationsExclusiveScanAMD(u16vec3);"
2425             "u16vec4  minInvocationsExclusiveScanAMD(u16vec4);"
2426 
2427             "float maxInvocationsAMD(float);"
2428             "vec2  maxInvocationsAMD(vec2);"
2429             "vec3  maxInvocationsAMD(vec3);"
2430             "vec4  maxInvocationsAMD(vec4);"
2431 
2432             "int   maxInvocationsAMD(int);"
2433             "ivec2 maxInvocationsAMD(ivec2);"
2434             "ivec3 maxInvocationsAMD(ivec3);"
2435             "ivec4 maxInvocationsAMD(ivec4);"
2436 
2437             "uint  maxInvocationsAMD(uint);"
2438             "uvec2 maxInvocationsAMD(uvec2);"
2439             "uvec3 maxInvocationsAMD(uvec3);"
2440             "uvec4 maxInvocationsAMD(uvec4);"
2441 
2442             "double maxInvocationsAMD(double);"
2443             "dvec2  maxInvocationsAMD(dvec2);"
2444             "dvec3  maxInvocationsAMD(dvec3);"
2445             "dvec4  maxInvocationsAMD(dvec4);"
2446 
2447             "int64_t maxInvocationsAMD(int64_t);"
2448             "i64vec2 maxInvocationsAMD(i64vec2);"
2449             "i64vec3 maxInvocationsAMD(i64vec3);"
2450             "i64vec4 maxInvocationsAMD(i64vec4);"
2451 
2452             "uint64_t maxInvocationsAMD(uint64_t);"
2453             "u64vec2  maxInvocationsAMD(u64vec2);"
2454             "u64vec3  maxInvocationsAMD(u64vec3);"
2455             "u64vec4  maxInvocationsAMD(u64vec4);"
2456 
2457             "float16_t maxInvocationsAMD(float16_t);"
2458             "f16vec2   maxInvocationsAMD(f16vec2);"
2459             "f16vec3   maxInvocationsAMD(f16vec3);"
2460             "f16vec4   maxInvocationsAMD(f16vec4);"
2461 
2462             "int16_t maxInvocationsAMD(int16_t);"
2463             "i16vec2 maxInvocationsAMD(i16vec2);"
2464             "i16vec3 maxInvocationsAMD(i16vec3);"
2465             "i16vec4 maxInvocationsAMD(i16vec4);"
2466 
2467             "uint16_t maxInvocationsAMD(uint16_t);"
2468             "u16vec2  maxInvocationsAMD(u16vec2);"
2469             "u16vec3  maxInvocationsAMD(u16vec3);"
2470             "u16vec4  maxInvocationsAMD(u16vec4);"
2471 
2472             "float maxInvocationsInclusiveScanAMD(float);"
2473             "vec2  maxInvocationsInclusiveScanAMD(vec2);"
2474             "vec3  maxInvocationsInclusiveScanAMD(vec3);"
2475             "vec4  maxInvocationsInclusiveScanAMD(vec4);"
2476 
2477             "int   maxInvocationsInclusiveScanAMD(int);"
2478             "ivec2 maxInvocationsInclusiveScanAMD(ivec2);"
2479             "ivec3 maxInvocationsInclusiveScanAMD(ivec3);"
2480             "ivec4 maxInvocationsInclusiveScanAMD(ivec4);"
2481 
2482             "uint  maxInvocationsInclusiveScanAMD(uint);"
2483             "uvec2 maxInvocationsInclusiveScanAMD(uvec2);"
2484             "uvec3 maxInvocationsInclusiveScanAMD(uvec3);"
2485             "uvec4 maxInvocationsInclusiveScanAMD(uvec4);"
2486 
2487             "double maxInvocationsInclusiveScanAMD(double);"
2488             "dvec2  maxInvocationsInclusiveScanAMD(dvec2);"
2489             "dvec3  maxInvocationsInclusiveScanAMD(dvec3);"
2490             "dvec4  maxInvocationsInclusiveScanAMD(dvec4);"
2491 
2492             "int64_t maxInvocationsInclusiveScanAMD(int64_t);"
2493             "i64vec2 maxInvocationsInclusiveScanAMD(i64vec2);"
2494             "i64vec3 maxInvocationsInclusiveScanAMD(i64vec3);"
2495             "i64vec4 maxInvocationsInclusiveScanAMD(i64vec4);"
2496 
2497             "uint64_t maxInvocationsInclusiveScanAMD(uint64_t);"
2498             "u64vec2  maxInvocationsInclusiveScanAMD(u64vec2);"
2499             "u64vec3  maxInvocationsInclusiveScanAMD(u64vec3);"
2500             "u64vec4  maxInvocationsInclusiveScanAMD(u64vec4);"
2501 
2502             "float16_t maxInvocationsInclusiveScanAMD(float16_t);"
2503             "f16vec2   maxInvocationsInclusiveScanAMD(f16vec2);"
2504             "f16vec3   maxInvocationsInclusiveScanAMD(f16vec3);"
2505             "f16vec4   maxInvocationsInclusiveScanAMD(f16vec4);"
2506 
2507             "int16_t maxInvocationsInclusiveScanAMD(int16_t);"
2508             "i16vec2 maxInvocationsInclusiveScanAMD(i16vec2);"
2509             "i16vec3 maxInvocationsInclusiveScanAMD(i16vec3);"
2510             "i16vec4 maxInvocationsInclusiveScanAMD(i16vec4);"
2511 
2512             "uint16_t maxInvocationsInclusiveScanAMD(uint16_t);"
2513             "u16vec2  maxInvocationsInclusiveScanAMD(u16vec2);"
2514             "u16vec3  maxInvocationsInclusiveScanAMD(u16vec3);"
2515             "u16vec4  maxInvocationsInclusiveScanAMD(u16vec4);"
2516 
2517             "float maxInvocationsExclusiveScanAMD(float);"
2518             "vec2  maxInvocationsExclusiveScanAMD(vec2);"
2519             "vec3  maxInvocationsExclusiveScanAMD(vec3);"
2520             "vec4  maxInvocationsExclusiveScanAMD(vec4);"
2521 
2522             "int   maxInvocationsExclusiveScanAMD(int);"
2523             "ivec2 maxInvocationsExclusiveScanAMD(ivec2);"
2524             "ivec3 maxInvocationsExclusiveScanAMD(ivec3);"
2525             "ivec4 maxInvocationsExclusiveScanAMD(ivec4);"
2526 
2527             "uint  maxInvocationsExclusiveScanAMD(uint);"
2528             "uvec2 maxInvocationsExclusiveScanAMD(uvec2);"
2529             "uvec3 maxInvocationsExclusiveScanAMD(uvec3);"
2530             "uvec4 maxInvocationsExclusiveScanAMD(uvec4);"
2531 
2532             "double maxInvocationsExclusiveScanAMD(double);"
2533             "dvec2  maxInvocationsExclusiveScanAMD(dvec2);"
2534             "dvec3  maxInvocationsExclusiveScanAMD(dvec3);"
2535             "dvec4  maxInvocationsExclusiveScanAMD(dvec4);"
2536 
2537             "int64_t maxInvocationsExclusiveScanAMD(int64_t);"
2538             "i64vec2 maxInvocationsExclusiveScanAMD(i64vec2);"
2539             "i64vec3 maxInvocationsExclusiveScanAMD(i64vec3);"
2540             "i64vec4 maxInvocationsExclusiveScanAMD(i64vec4);"
2541 
2542             "uint64_t maxInvocationsExclusiveScanAMD(uint64_t);"
2543             "u64vec2  maxInvocationsExclusiveScanAMD(u64vec2);"
2544             "u64vec3  maxInvocationsExclusiveScanAMD(u64vec3);"
2545             "u64vec4  maxInvocationsExclusiveScanAMD(u64vec4);"
2546 
2547             "float16_t maxInvocationsExclusiveScanAMD(float16_t);"
2548             "f16vec2   maxInvocationsExclusiveScanAMD(f16vec2);"
2549             "f16vec3   maxInvocationsExclusiveScanAMD(f16vec3);"
2550             "f16vec4   maxInvocationsExclusiveScanAMD(f16vec4);"
2551 
2552             "int16_t maxInvocationsExclusiveScanAMD(int16_t);"
2553             "i16vec2 maxInvocationsExclusiveScanAMD(i16vec2);"
2554             "i16vec3 maxInvocationsExclusiveScanAMD(i16vec3);"
2555             "i16vec4 maxInvocationsExclusiveScanAMD(i16vec4);"
2556 
2557             "uint16_t maxInvocationsExclusiveScanAMD(uint16_t);"
2558             "u16vec2  maxInvocationsExclusiveScanAMD(u16vec2);"
2559             "u16vec3  maxInvocationsExclusiveScanAMD(u16vec3);"
2560             "u16vec4  maxInvocationsExclusiveScanAMD(u16vec4);"
2561 
2562             "float addInvocationsAMD(float);"
2563             "vec2  addInvocationsAMD(vec2);"
2564             "vec3  addInvocationsAMD(vec3);"
2565             "vec4  addInvocationsAMD(vec4);"
2566 
2567             "int   addInvocationsAMD(int);"
2568             "ivec2 addInvocationsAMD(ivec2);"
2569             "ivec3 addInvocationsAMD(ivec3);"
2570             "ivec4 addInvocationsAMD(ivec4);"
2571 
2572             "uint  addInvocationsAMD(uint);"
2573             "uvec2 addInvocationsAMD(uvec2);"
2574             "uvec3 addInvocationsAMD(uvec3);"
2575             "uvec4 addInvocationsAMD(uvec4);"
2576 
2577             "double  addInvocationsAMD(double);"
2578             "dvec2   addInvocationsAMD(dvec2);"
2579             "dvec3   addInvocationsAMD(dvec3);"
2580             "dvec4   addInvocationsAMD(dvec4);"
2581 
2582             "int64_t addInvocationsAMD(int64_t);"
2583             "i64vec2 addInvocationsAMD(i64vec2);"
2584             "i64vec3 addInvocationsAMD(i64vec3);"
2585             "i64vec4 addInvocationsAMD(i64vec4);"
2586 
2587             "uint64_t addInvocationsAMD(uint64_t);"
2588             "u64vec2  addInvocationsAMD(u64vec2);"
2589             "u64vec3  addInvocationsAMD(u64vec3);"
2590             "u64vec4  addInvocationsAMD(u64vec4);"
2591 
2592             "float16_t addInvocationsAMD(float16_t);"
2593             "f16vec2   addInvocationsAMD(f16vec2);"
2594             "f16vec3   addInvocationsAMD(f16vec3);"
2595             "f16vec4   addInvocationsAMD(f16vec4);"
2596 
2597             "int16_t addInvocationsAMD(int16_t);"
2598             "i16vec2 addInvocationsAMD(i16vec2);"
2599             "i16vec3 addInvocationsAMD(i16vec3);"
2600             "i16vec4 addInvocationsAMD(i16vec4);"
2601 
2602             "uint16_t addInvocationsAMD(uint16_t);"
2603             "u16vec2  addInvocationsAMD(u16vec2);"
2604             "u16vec3  addInvocationsAMD(u16vec3);"
2605             "u16vec4  addInvocationsAMD(u16vec4);"
2606 
2607             "float addInvocationsInclusiveScanAMD(float);"
2608             "vec2  addInvocationsInclusiveScanAMD(vec2);"
2609             "vec3  addInvocationsInclusiveScanAMD(vec3);"
2610             "vec4  addInvocationsInclusiveScanAMD(vec4);"
2611 
2612             "int   addInvocationsInclusiveScanAMD(int);"
2613             "ivec2 addInvocationsInclusiveScanAMD(ivec2);"
2614             "ivec3 addInvocationsInclusiveScanAMD(ivec3);"
2615             "ivec4 addInvocationsInclusiveScanAMD(ivec4);"
2616 
2617             "uint  addInvocationsInclusiveScanAMD(uint);"
2618             "uvec2 addInvocationsInclusiveScanAMD(uvec2);"
2619             "uvec3 addInvocationsInclusiveScanAMD(uvec3);"
2620             "uvec4 addInvocationsInclusiveScanAMD(uvec4);"
2621 
2622             "double  addInvocationsInclusiveScanAMD(double);"
2623             "dvec2   addInvocationsInclusiveScanAMD(dvec2);"
2624             "dvec3   addInvocationsInclusiveScanAMD(dvec3);"
2625             "dvec4   addInvocationsInclusiveScanAMD(dvec4);"
2626 
2627             "int64_t addInvocationsInclusiveScanAMD(int64_t);"
2628             "i64vec2 addInvocationsInclusiveScanAMD(i64vec2);"
2629             "i64vec3 addInvocationsInclusiveScanAMD(i64vec3);"
2630             "i64vec4 addInvocationsInclusiveScanAMD(i64vec4);"
2631 
2632             "uint64_t addInvocationsInclusiveScanAMD(uint64_t);"
2633             "u64vec2  addInvocationsInclusiveScanAMD(u64vec2);"
2634             "u64vec3  addInvocationsInclusiveScanAMD(u64vec3);"
2635             "u64vec4  addInvocationsInclusiveScanAMD(u64vec4);"
2636 
2637             "float16_t addInvocationsInclusiveScanAMD(float16_t);"
2638             "f16vec2   addInvocationsInclusiveScanAMD(f16vec2);"
2639             "f16vec3   addInvocationsInclusiveScanAMD(f16vec3);"
2640             "f16vec4   addInvocationsInclusiveScanAMD(f16vec4);"
2641 
2642             "int16_t addInvocationsInclusiveScanAMD(int16_t);"
2643             "i16vec2 addInvocationsInclusiveScanAMD(i16vec2);"
2644             "i16vec3 addInvocationsInclusiveScanAMD(i16vec3);"
2645             "i16vec4 addInvocationsInclusiveScanAMD(i16vec4);"
2646 
2647             "uint16_t addInvocationsInclusiveScanAMD(uint16_t);"
2648             "u16vec2  addInvocationsInclusiveScanAMD(u16vec2);"
2649             "u16vec3  addInvocationsInclusiveScanAMD(u16vec3);"
2650             "u16vec4  addInvocationsInclusiveScanAMD(u16vec4);"
2651 
2652             "float addInvocationsExclusiveScanAMD(float);"
2653             "vec2  addInvocationsExclusiveScanAMD(vec2);"
2654             "vec3  addInvocationsExclusiveScanAMD(vec3);"
2655             "vec4  addInvocationsExclusiveScanAMD(vec4);"
2656 
2657             "int   addInvocationsExclusiveScanAMD(int);"
2658             "ivec2 addInvocationsExclusiveScanAMD(ivec2);"
2659             "ivec3 addInvocationsExclusiveScanAMD(ivec3);"
2660             "ivec4 addInvocationsExclusiveScanAMD(ivec4);"
2661 
2662             "uint  addInvocationsExclusiveScanAMD(uint);"
2663             "uvec2 addInvocationsExclusiveScanAMD(uvec2);"
2664             "uvec3 addInvocationsExclusiveScanAMD(uvec3);"
2665             "uvec4 addInvocationsExclusiveScanAMD(uvec4);"
2666 
2667             "double  addInvocationsExclusiveScanAMD(double);"
2668             "dvec2   addInvocationsExclusiveScanAMD(dvec2);"
2669             "dvec3   addInvocationsExclusiveScanAMD(dvec3);"
2670             "dvec4   addInvocationsExclusiveScanAMD(dvec4);"
2671 
2672             "int64_t addInvocationsExclusiveScanAMD(int64_t);"
2673             "i64vec2 addInvocationsExclusiveScanAMD(i64vec2);"
2674             "i64vec3 addInvocationsExclusiveScanAMD(i64vec3);"
2675             "i64vec4 addInvocationsExclusiveScanAMD(i64vec4);"
2676 
2677             "uint64_t addInvocationsExclusiveScanAMD(uint64_t);"
2678             "u64vec2  addInvocationsExclusiveScanAMD(u64vec2);"
2679             "u64vec3  addInvocationsExclusiveScanAMD(u64vec3);"
2680             "u64vec4  addInvocationsExclusiveScanAMD(u64vec4);"
2681 
2682             "float16_t addInvocationsExclusiveScanAMD(float16_t);"
2683             "f16vec2   addInvocationsExclusiveScanAMD(f16vec2);"
2684             "f16vec3   addInvocationsExclusiveScanAMD(f16vec3);"
2685             "f16vec4   addInvocationsExclusiveScanAMD(f16vec4);"
2686 
2687             "int16_t addInvocationsExclusiveScanAMD(int16_t);"
2688             "i16vec2 addInvocationsExclusiveScanAMD(i16vec2);"
2689             "i16vec3 addInvocationsExclusiveScanAMD(i16vec3);"
2690             "i16vec4 addInvocationsExclusiveScanAMD(i16vec4);"
2691 
2692             "uint16_t addInvocationsExclusiveScanAMD(uint16_t);"
2693             "u16vec2  addInvocationsExclusiveScanAMD(u16vec2);"
2694             "u16vec3  addInvocationsExclusiveScanAMD(u16vec3);"
2695             "u16vec4  addInvocationsExclusiveScanAMD(u16vec4);"
2696 
2697             "float minInvocationsNonUniformAMD(float);"
2698             "vec2  minInvocationsNonUniformAMD(vec2);"
2699             "vec3  minInvocationsNonUniformAMD(vec3);"
2700             "vec4  minInvocationsNonUniformAMD(vec4);"
2701 
2702             "int   minInvocationsNonUniformAMD(int);"
2703             "ivec2 minInvocationsNonUniformAMD(ivec2);"
2704             "ivec3 minInvocationsNonUniformAMD(ivec3);"
2705             "ivec4 minInvocationsNonUniformAMD(ivec4);"
2706 
2707             "uint  minInvocationsNonUniformAMD(uint);"
2708             "uvec2 minInvocationsNonUniformAMD(uvec2);"
2709             "uvec3 minInvocationsNonUniformAMD(uvec3);"
2710             "uvec4 minInvocationsNonUniformAMD(uvec4);"
2711 
2712             "double minInvocationsNonUniformAMD(double);"
2713             "dvec2  minInvocationsNonUniformAMD(dvec2);"
2714             "dvec3  minInvocationsNonUniformAMD(dvec3);"
2715             "dvec4  minInvocationsNonUniformAMD(dvec4);"
2716 
2717             "int64_t minInvocationsNonUniformAMD(int64_t);"
2718             "i64vec2 minInvocationsNonUniformAMD(i64vec2);"
2719             "i64vec3 minInvocationsNonUniformAMD(i64vec3);"
2720             "i64vec4 minInvocationsNonUniformAMD(i64vec4);"
2721 
2722             "uint64_t minInvocationsNonUniformAMD(uint64_t);"
2723             "u64vec2  minInvocationsNonUniformAMD(u64vec2);"
2724             "u64vec3  minInvocationsNonUniformAMD(u64vec3);"
2725             "u64vec4  minInvocationsNonUniformAMD(u64vec4);"
2726 
2727             "float16_t minInvocationsNonUniformAMD(float16_t);"
2728             "f16vec2   minInvocationsNonUniformAMD(f16vec2);"
2729             "f16vec3   minInvocationsNonUniformAMD(f16vec3);"
2730             "f16vec4   minInvocationsNonUniformAMD(f16vec4);"
2731 
2732             "int16_t minInvocationsNonUniformAMD(int16_t);"
2733             "i16vec2 minInvocationsNonUniformAMD(i16vec2);"
2734             "i16vec3 minInvocationsNonUniformAMD(i16vec3);"
2735             "i16vec4 minInvocationsNonUniformAMD(i16vec4);"
2736 
2737             "uint16_t minInvocationsNonUniformAMD(uint16_t);"
2738             "u16vec2  minInvocationsNonUniformAMD(u16vec2);"
2739             "u16vec3  minInvocationsNonUniformAMD(u16vec3);"
2740             "u16vec4  minInvocationsNonUniformAMD(u16vec4);"
2741 
2742             "float minInvocationsInclusiveScanNonUniformAMD(float);"
2743             "vec2  minInvocationsInclusiveScanNonUniformAMD(vec2);"
2744             "vec3  minInvocationsInclusiveScanNonUniformAMD(vec3);"
2745             "vec4  minInvocationsInclusiveScanNonUniformAMD(vec4);"
2746 
2747             "int   minInvocationsInclusiveScanNonUniformAMD(int);"
2748             "ivec2 minInvocationsInclusiveScanNonUniformAMD(ivec2);"
2749             "ivec3 minInvocationsInclusiveScanNonUniformAMD(ivec3);"
2750             "ivec4 minInvocationsInclusiveScanNonUniformAMD(ivec4);"
2751 
2752             "uint  minInvocationsInclusiveScanNonUniformAMD(uint);"
2753             "uvec2 minInvocationsInclusiveScanNonUniformAMD(uvec2);"
2754             "uvec3 minInvocationsInclusiveScanNonUniformAMD(uvec3);"
2755             "uvec4 minInvocationsInclusiveScanNonUniformAMD(uvec4);"
2756 
2757             "double minInvocationsInclusiveScanNonUniformAMD(double);"
2758             "dvec2  minInvocationsInclusiveScanNonUniformAMD(dvec2);"
2759             "dvec3  minInvocationsInclusiveScanNonUniformAMD(dvec3);"
2760             "dvec4  minInvocationsInclusiveScanNonUniformAMD(dvec4);"
2761 
2762             "int64_t minInvocationsInclusiveScanNonUniformAMD(int64_t);"
2763             "i64vec2 minInvocationsInclusiveScanNonUniformAMD(i64vec2);"
2764             "i64vec3 minInvocationsInclusiveScanNonUniformAMD(i64vec3);"
2765             "i64vec4 minInvocationsInclusiveScanNonUniformAMD(i64vec4);"
2766 
2767             "uint64_t minInvocationsInclusiveScanNonUniformAMD(uint64_t);"
2768             "u64vec2  minInvocationsInclusiveScanNonUniformAMD(u64vec2);"
2769             "u64vec3  minInvocationsInclusiveScanNonUniformAMD(u64vec3);"
2770             "u64vec4  minInvocationsInclusiveScanNonUniformAMD(u64vec4);"
2771 
2772             "float16_t minInvocationsInclusiveScanNonUniformAMD(float16_t);"
2773             "f16vec2   minInvocationsInclusiveScanNonUniformAMD(f16vec2);"
2774             "f16vec3   minInvocationsInclusiveScanNonUniformAMD(f16vec3);"
2775             "f16vec4   minInvocationsInclusiveScanNonUniformAMD(f16vec4);"
2776 
2777             "int16_t minInvocationsInclusiveScanNonUniformAMD(int16_t);"
2778             "i16vec2 minInvocationsInclusiveScanNonUniformAMD(i16vec2);"
2779             "i16vec3 minInvocationsInclusiveScanNonUniformAMD(i16vec3);"
2780             "i16vec4 minInvocationsInclusiveScanNonUniformAMD(i16vec4);"
2781 
2782             "uint16_t minInvocationsInclusiveScanNonUniformAMD(uint16_t);"
2783             "u16vec2  minInvocationsInclusiveScanNonUniformAMD(u16vec2);"
2784             "u16vec3  minInvocationsInclusiveScanNonUniformAMD(u16vec3);"
2785             "u16vec4  minInvocationsInclusiveScanNonUniformAMD(u16vec4);"
2786 
2787             "float minInvocationsExclusiveScanNonUniformAMD(float);"
2788             "vec2  minInvocationsExclusiveScanNonUniformAMD(vec2);"
2789             "vec3  minInvocationsExclusiveScanNonUniformAMD(vec3);"
2790             "vec4  minInvocationsExclusiveScanNonUniformAMD(vec4);"
2791 
2792             "int   minInvocationsExclusiveScanNonUniformAMD(int);"
2793             "ivec2 minInvocationsExclusiveScanNonUniformAMD(ivec2);"
2794             "ivec3 minInvocationsExclusiveScanNonUniformAMD(ivec3);"
2795             "ivec4 minInvocationsExclusiveScanNonUniformAMD(ivec4);"
2796 
2797             "uint  minInvocationsExclusiveScanNonUniformAMD(uint);"
2798             "uvec2 minInvocationsExclusiveScanNonUniformAMD(uvec2);"
2799             "uvec3 minInvocationsExclusiveScanNonUniformAMD(uvec3);"
2800             "uvec4 minInvocationsExclusiveScanNonUniformAMD(uvec4);"
2801 
2802             "double minInvocationsExclusiveScanNonUniformAMD(double);"
2803             "dvec2  minInvocationsExclusiveScanNonUniformAMD(dvec2);"
2804             "dvec3  minInvocationsExclusiveScanNonUniformAMD(dvec3);"
2805             "dvec4  minInvocationsExclusiveScanNonUniformAMD(dvec4);"
2806 
2807             "int64_t minInvocationsExclusiveScanNonUniformAMD(int64_t);"
2808             "i64vec2 minInvocationsExclusiveScanNonUniformAMD(i64vec2);"
2809             "i64vec3 minInvocationsExclusiveScanNonUniformAMD(i64vec3);"
2810             "i64vec4 minInvocationsExclusiveScanNonUniformAMD(i64vec4);"
2811 
2812             "uint64_t minInvocationsExclusiveScanNonUniformAMD(uint64_t);"
2813             "u64vec2  minInvocationsExclusiveScanNonUniformAMD(u64vec2);"
2814             "u64vec3  minInvocationsExclusiveScanNonUniformAMD(u64vec3);"
2815             "u64vec4  minInvocationsExclusiveScanNonUniformAMD(u64vec4);"
2816 
2817             "float16_t minInvocationsExclusiveScanNonUniformAMD(float16_t);"
2818             "f16vec2   minInvocationsExclusiveScanNonUniformAMD(f16vec2);"
2819             "f16vec3   minInvocationsExclusiveScanNonUniformAMD(f16vec3);"
2820             "f16vec4   minInvocationsExclusiveScanNonUniformAMD(f16vec4);"
2821 
2822             "int16_t minInvocationsExclusiveScanNonUniformAMD(int16_t);"
2823             "i16vec2 minInvocationsExclusiveScanNonUniformAMD(i16vec2);"
2824             "i16vec3 minInvocationsExclusiveScanNonUniformAMD(i16vec3);"
2825             "i16vec4 minInvocationsExclusiveScanNonUniformAMD(i16vec4);"
2826 
2827             "uint16_t minInvocationsExclusiveScanNonUniformAMD(uint16_t);"
2828             "u16vec2  minInvocationsExclusiveScanNonUniformAMD(u16vec2);"
2829             "u16vec3  minInvocationsExclusiveScanNonUniformAMD(u16vec3);"
2830             "u16vec4  minInvocationsExclusiveScanNonUniformAMD(u16vec4);"
2831 
2832             "float maxInvocationsNonUniformAMD(float);"
2833             "vec2  maxInvocationsNonUniformAMD(vec2);"
2834             "vec3  maxInvocationsNonUniformAMD(vec3);"
2835             "vec4  maxInvocationsNonUniformAMD(vec4);"
2836 
2837             "int   maxInvocationsNonUniformAMD(int);"
2838             "ivec2 maxInvocationsNonUniformAMD(ivec2);"
2839             "ivec3 maxInvocationsNonUniformAMD(ivec3);"
2840             "ivec4 maxInvocationsNonUniformAMD(ivec4);"
2841 
2842             "uint  maxInvocationsNonUniformAMD(uint);"
2843             "uvec2 maxInvocationsNonUniformAMD(uvec2);"
2844             "uvec3 maxInvocationsNonUniformAMD(uvec3);"
2845             "uvec4 maxInvocationsNonUniformAMD(uvec4);"
2846 
2847             "double maxInvocationsNonUniformAMD(double);"
2848             "dvec2  maxInvocationsNonUniformAMD(dvec2);"
2849             "dvec3  maxInvocationsNonUniformAMD(dvec3);"
2850             "dvec4  maxInvocationsNonUniformAMD(dvec4);"
2851 
2852             "int64_t maxInvocationsNonUniformAMD(int64_t);"
2853             "i64vec2 maxInvocationsNonUniformAMD(i64vec2);"
2854             "i64vec3 maxInvocationsNonUniformAMD(i64vec3);"
2855             "i64vec4 maxInvocationsNonUniformAMD(i64vec4);"
2856 
2857             "uint64_t maxInvocationsNonUniformAMD(uint64_t);"
2858             "u64vec2  maxInvocationsNonUniformAMD(u64vec2);"
2859             "u64vec3  maxInvocationsNonUniformAMD(u64vec3);"
2860             "u64vec4  maxInvocationsNonUniformAMD(u64vec4);"
2861 
2862             "float16_t maxInvocationsNonUniformAMD(float16_t);"
2863             "f16vec2   maxInvocationsNonUniformAMD(f16vec2);"
2864             "f16vec3   maxInvocationsNonUniformAMD(f16vec3);"
2865             "f16vec4   maxInvocationsNonUniformAMD(f16vec4);"
2866 
2867             "int16_t maxInvocationsNonUniformAMD(int16_t);"
2868             "i16vec2 maxInvocationsNonUniformAMD(i16vec2);"
2869             "i16vec3 maxInvocationsNonUniformAMD(i16vec3);"
2870             "i16vec4 maxInvocationsNonUniformAMD(i16vec4);"
2871 
2872             "uint16_t maxInvocationsNonUniformAMD(uint16_t);"
2873             "u16vec2  maxInvocationsNonUniformAMD(u16vec2);"
2874             "u16vec3  maxInvocationsNonUniformAMD(u16vec3);"
2875             "u16vec4  maxInvocationsNonUniformAMD(u16vec4);"
2876 
2877             "float maxInvocationsInclusiveScanNonUniformAMD(float);"
2878             "vec2  maxInvocationsInclusiveScanNonUniformAMD(vec2);"
2879             "vec3  maxInvocationsInclusiveScanNonUniformAMD(vec3);"
2880             "vec4  maxInvocationsInclusiveScanNonUniformAMD(vec4);"
2881 
2882             "int   maxInvocationsInclusiveScanNonUniformAMD(int);"
2883             "ivec2 maxInvocationsInclusiveScanNonUniformAMD(ivec2);"
2884             "ivec3 maxInvocationsInclusiveScanNonUniformAMD(ivec3);"
2885             "ivec4 maxInvocationsInclusiveScanNonUniformAMD(ivec4);"
2886 
2887             "uint  maxInvocationsInclusiveScanNonUniformAMD(uint);"
2888             "uvec2 maxInvocationsInclusiveScanNonUniformAMD(uvec2);"
2889             "uvec3 maxInvocationsInclusiveScanNonUniformAMD(uvec3);"
2890             "uvec4 maxInvocationsInclusiveScanNonUniformAMD(uvec4);"
2891 
2892             "double maxInvocationsInclusiveScanNonUniformAMD(double);"
2893             "dvec2  maxInvocationsInclusiveScanNonUniformAMD(dvec2);"
2894             "dvec3  maxInvocationsInclusiveScanNonUniformAMD(dvec3);"
2895             "dvec4  maxInvocationsInclusiveScanNonUniformAMD(dvec4);"
2896 
2897             "int64_t maxInvocationsInclusiveScanNonUniformAMD(int64_t);"
2898             "i64vec2 maxInvocationsInclusiveScanNonUniformAMD(i64vec2);"
2899             "i64vec3 maxInvocationsInclusiveScanNonUniformAMD(i64vec3);"
2900             "i64vec4 maxInvocationsInclusiveScanNonUniformAMD(i64vec4);"
2901 
2902             "uint64_t maxInvocationsInclusiveScanNonUniformAMD(uint64_t);"
2903             "u64vec2  maxInvocationsInclusiveScanNonUniformAMD(u64vec2);"
2904             "u64vec3  maxInvocationsInclusiveScanNonUniformAMD(u64vec3);"
2905             "u64vec4  maxInvocationsInclusiveScanNonUniformAMD(u64vec4);"
2906 
2907             "float16_t maxInvocationsInclusiveScanNonUniformAMD(float16_t);"
2908             "f16vec2   maxInvocationsInclusiveScanNonUniformAMD(f16vec2);"
2909             "f16vec3   maxInvocationsInclusiveScanNonUniformAMD(f16vec3);"
2910             "f16vec4   maxInvocationsInclusiveScanNonUniformAMD(f16vec4);"
2911 
2912             "int16_t maxInvocationsInclusiveScanNonUniformAMD(int16_t);"
2913             "i16vec2 maxInvocationsInclusiveScanNonUniformAMD(i16vec2);"
2914             "i16vec3 maxInvocationsInclusiveScanNonUniformAMD(i16vec3);"
2915             "i16vec4 maxInvocationsInclusiveScanNonUniformAMD(i16vec4);"
2916 
2917             "uint16_t maxInvocationsInclusiveScanNonUniformAMD(uint16_t);"
2918             "u16vec2  maxInvocationsInclusiveScanNonUniformAMD(u16vec2);"
2919             "u16vec3  maxInvocationsInclusiveScanNonUniformAMD(u16vec3);"
2920             "u16vec4  maxInvocationsInclusiveScanNonUniformAMD(u16vec4);"
2921 
2922             "float maxInvocationsExclusiveScanNonUniformAMD(float);"
2923             "vec2  maxInvocationsExclusiveScanNonUniformAMD(vec2);"
2924             "vec3  maxInvocationsExclusiveScanNonUniformAMD(vec3);"
2925             "vec4  maxInvocationsExclusiveScanNonUniformAMD(vec4);"
2926 
2927             "int   maxInvocationsExclusiveScanNonUniformAMD(int);"
2928             "ivec2 maxInvocationsExclusiveScanNonUniformAMD(ivec2);"
2929             "ivec3 maxInvocationsExclusiveScanNonUniformAMD(ivec3);"
2930             "ivec4 maxInvocationsExclusiveScanNonUniformAMD(ivec4);"
2931 
2932             "uint  maxInvocationsExclusiveScanNonUniformAMD(uint);"
2933             "uvec2 maxInvocationsExclusiveScanNonUniformAMD(uvec2);"
2934             "uvec3 maxInvocationsExclusiveScanNonUniformAMD(uvec3);"
2935             "uvec4 maxInvocationsExclusiveScanNonUniformAMD(uvec4);"
2936 
2937             "double maxInvocationsExclusiveScanNonUniformAMD(double);"
2938             "dvec2  maxInvocationsExclusiveScanNonUniformAMD(dvec2);"
2939             "dvec3  maxInvocationsExclusiveScanNonUniformAMD(dvec3);"
2940             "dvec4  maxInvocationsExclusiveScanNonUniformAMD(dvec4);"
2941 
2942             "int64_t maxInvocationsExclusiveScanNonUniformAMD(int64_t);"
2943             "i64vec2 maxInvocationsExclusiveScanNonUniformAMD(i64vec2);"
2944             "i64vec3 maxInvocationsExclusiveScanNonUniformAMD(i64vec3);"
2945             "i64vec4 maxInvocationsExclusiveScanNonUniformAMD(i64vec4);"
2946 
2947             "uint64_t maxInvocationsExclusiveScanNonUniformAMD(uint64_t);"
2948             "u64vec2  maxInvocationsExclusiveScanNonUniformAMD(u64vec2);"
2949             "u64vec3  maxInvocationsExclusiveScanNonUniformAMD(u64vec3);"
2950             "u64vec4  maxInvocationsExclusiveScanNonUniformAMD(u64vec4);"
2951 
2952             "float16_t maxInvocationsExclusiveScanNonUniformAMD(float16_t);"
2953             "f16vec2   maxInvocationsExclusiveScanNonUniformAMD(f16vec2);"
2954             "f16vec3   maxInvocationsExclusiveScanNonUniformAMD(f16vec3);"
2955             "f16vec4   maxInvocationsExclusiveScanNonUniformAMD(f16vec4);"
2956 
2957             "int16_t maxInvocationsExclusiveScanNonUniformAMD(int16_t);"
2958             "i16vec2 maxInvocationsExclusiveScanNonUniformAMD(i16vec2);"
2959             "i16vec3 maxInvocationsExclusiveScanNonUniformAMD(i16vec3);"
2960             "i16vec4 maxInvocationsExclusiveScanNonUniformAMD(i16vec4);"
2961 
2962             "uint16_t maxInvocationsExclusiveScanNonUniformAMD(uint16_t);"
2963             "u16vec2  maxInvocationsExclusiveScanNonUniformAMD(u16vec2);"
2964             "u16vec3  maxInvocationsExclusiveScanNonUniformAMD(u16vec3);"
2965             "u16vec4  maxInvocationsExclusiveScanNonUniformAMD(u16vec4);"
2966 
2967             "float addInvocationsNonUniformAMD(float);"
2968             "vec2  addInvocationsNonUniformAMD(vec2);"
2969             "vec3  addInvocationsNonUniformAMD(vec3);"
2970             "vec4  addInvocationsNonUniformAMD(vec4);"
2971 
2972             "int   addInvocationsNonUniformAMD(int);"
2973             "ivec2 addInvocationsNonUniformAMD(ivec2);"
2974             "ivec3 addInvocationsNonUniformAMD(ivec3);"
2975             "ivec4 addInvocationsNonUniformAMD(ivec4);"
2976 
2977             "uint  addInvocationsNonUniformAMD(uint);"
2978             "uvec2 addInvocationsNonUniformAMD(uvec2);"
2979             "uvec3 addInvocationsNonUniformAMD(uvec3);"
2980             "uvec4 addInvocationsNonUniformAMD(uvec4);"
2981 
2982             "double addInvocationsNonUniformAMD(double);"
2983             "dvec2  addInvocationsNonUniformAMD(dvec2);"
2984             "dvec3  addInvocationsNonUniformAMD(dvec3);"
2985             "dvec4  addInvocationsNonUniformAMD(dvec4);"
2986 
2987             "int64_t addInvocationsNonUniformAMD(int64_t);"
2988             "i64vec2 addInvocationsNonUniformAMD(i64vec2);"
2989             "i64vec3 addInvocationsNonUniformAMD(i64vec3);"
2990             "i64vec4 addInvocationsNonUniformAMD(i64vec4);"
2991 
2992             "uint64_t addInvocationsNonUniformAMD(uint64_t);"
2993             "u64vec2  addInvocationsNonUniformAMD(u64vec2);"
2994             "u64vec3  addInvocationsNonUniformAMD(u64vec3);"
2995             "u64vec4  addInvocationsNonUniformAMD(u64vec4);"
2996 
2997             "float16_t addInvocationsNonUniformAMD(float16_t);"
2998             "f16vec2   addInvocationsNonUniformAMD(f16vec2);"
2999             "f16vec3   addInvocationsNonUniformAMD(f16vec3);"
3000             "f16vec4   addInvocationsNonUniformAMD(f16vec4);"
3001 
3002             "int16_t addInvocationsNonUniformAMD(int16_t);"
3003             "i16vec2 addInvocationsNonUniformAMD(i16vec2);"
3004             "i16vec3 addInvocationsNonUniformAMD(i16vec3);"
3005             "i16vec4 addInvocationsNonUniformAMD(i16vec4);"
3006 
3007             "uint16_t addInvocationsNonUniformAMD(uint16_t);"
3008             "u16vec2  addInvocationsNonUniformAMD(u16vec2);"
3009             "u16vec3  addInvocationsNonUniformAMD(u16vec3);"
3010             "u16vec4  addInvocationsNonUniformAMD(u16vec4);"
3011 
3012             "float addInvocationsInclusiveScanNonUniformAMD(float);"
3013             "vec2  addInvocationsInclusiveScanNonUniformAMD(vec2);"
3014             "vec3  addInvocationsInclusiveScanNonUniformAMD(vec3);"
3015             "vec4  addInvocationsInclusiveScanNonUniformAMD(vec4);"
3016 
3017             "int   addInvocationsInclusiveScanNonUniformAMD(int);"
3018             "ivec2 addInvocationsInclusiveScanNonUniformAMD(ivec2);"
3019             "ivec3 addInvocationsInclusiveScanNonUniformAMD(ivec3);"
3020             "ivec4 addInvocationsInclusiveScanNonUniformAMD(ivec4);"
3021 
3022             "uint  addInvocationsInclusiveScanNonUniformAMD(uint);"
3023             "uvec2 addInvocationsInclusiveScanNonUniformAMD(uvec2);"
3024             "uvec3 addInvocationsInclusiveScanNonUniformAMD(uvec3);"
3025             "uvec4 addInvocationsInclusiveScanNonUniformAMD(uvec4);"
3026 
3027             "double addInvocationsInclusiveScanNonUniformAMD(double);"
3028             "dvec2  addInvocationsInclusiveScanNonUniformAMD(dvec2);"
3029             "dvec3  addInvocationsInclusiveScanNonUniformAMD(dvec3);"
3030             "dvec4  addInvocationsInclusiveScanNonUniformAMD(dvec4);"
3031 
3032             "int64_t addInvocationsInclusiveScanNonUniformAMD(int64_t);"
3033             "i64vec2 addInvocationsInclusiveScanNonUniformAMD(i64vec2);"
3034             "i64vec3 addInvocationsInclusiveScanNonUniformAMD(i64vec3);"
3035             "i64vec4 addInvocationsInclusiveScanNonUniformAMD(i64vec4);"
3036 
3037             "uint64_t addInvocationsInclusiveScanNonUniformAMD(uint64_t);"
3038             "u64vec2  addInvocationsInclusiveScanNonUniformAMD(u64vec2);"
3039             "u64vec3  addInvocationsInclusiveScanNonUniformAMD(u64vec3);"
3040             "u64vec4  addInvocationsInclusiveScanNonUniformAMD(u64vec4);"
3041 
3042             "float16_t addInvocationsInclusiveScanNonUniformAMD(float16_t);"
3043             "f16vec2   addInvocationsInclusiveScanNonUniformAMD(f16vec2);"
3044             "f16vec3   addInvocationsInclusiveScanNonUniformAMD(f16vec3);"
3045             "f16vec4   addInvocationsInclusiveScanNonUniformAMD(f16vec4);"
3046 
3047             "int16_t addInvocationsInclusiveScanNonUniformAMD(int16_t);"
3048             "i16vec2 addInvocationsInclusiveScanNonUniformAMD(i16vec2);"
3049             "i16vec3 addInvocationsInclusiveScanNonUniformAMD(i16vec3);"
3050             "i16vec4 addInvocationsInclusiveScanNonUniformAMD(i16vec4);"
3051 
3052             "uint16_t addInvocationsInclusiveScanNonUniformAMD(uint16_t);"
3053             "u16vec2  addInvocationsInclusiveScanNonUniformAMD(u16vec2);"
3054             "u16vec3  addInvocationsInclusiveScanNonUniformAMD(u16vec3);"
3055             "u16vec4  addInvocationsInclusiveScanNonUniformAMD(u16vec4);"
3056 
3057             "float addInvocationsExclusiveScanNonUniformAMD(float);"
3058             "vec2  addInvocationsExclusiveScanNonUniformAMD(vec2);"
3059             "vec3  addInvocationsExclusiveScanNonUniformAMD(vec3);"
3060             "vec4  addInvocationsExclusiveScanNonUniformAMD(vec4);"
3061 
3062             "int   addInvocationsExclusiveScanNonUniformAMD(int);"
3063             "ivec2 addInvocationsExclusiveScanNonUniformAMD(ivec2);"
3064             "ivec3 addInvocationsExclusiveScanNonUniformAMD(ivec3);"
3065             "ivec4 addInvocationsExclusiveScanNonUniformAMD(ivec4);"
3066 
3067             "uint  addInvocationsExclusiveScanNonUniformAMD(uint);"
3068             "uvec2 addInvocationsExclusiveScanNonUniformAMD(uvec2);"
3069             "uvec3 addInvocationsExclusiveScanNonUniformAMD(uvec3);"
3070             "uvec4 addInvocationsExclusiveScanNonUniformAMD(uvec4);"
3071 
3072             "double addInvocationsExclusiveScanNonUniformAMD(double);"
3073             "dvec2  addInvocationsExclusiveScanNonUniformAMD(dvec2);"
3074             "dvec3  addInvocationsExclusiveScanNonUniformAMD(dvec3);"
3075             "dvec4  addInvocationsExclusiveScanNonUniformAMD(dvec4);"
3076 
3077             "int64_t addInvocationsExclusiveScanNonUniformAMD(int64_t);"
3078             "i64vec2 addInvocationsExclusiveScanNonUniformAMD(i64vec2);"
3079             "i64vec3 addInvocationsExclusiveScanNonUniformAMD(i64vec3);"
3080             "i64vec4 addInvocationsExclusiveScanNonUniformAMD(i64vec4);"
3081 
3082             "uint64_t addInvocationsExclusiveScanNonUniformAMD(uint64_t);"
3083             "u64vec2  addInvocationsExclusiveScanNonUniformAMD(u64vec2);"
3084             "u64vec3  addInvocationsExclusiveScanNonUniformAMD(u64vec3);"
3085             "u64vec4  addInvocationsExclusiveScanNonUniformAMD(u64vec4);"
3086 
3087             "float16_t addInvocationsExclusiveScanNonUniformAMD(float16_t);"
3088             "f16vec2   addInvocationsExclusiveScanNonUniformAMD(f16vec2);"
3089             "f16vec3   addInvocationsExclusiveScanNonUniformAMD(f16vec3);"
3090             "f16vec4   addInvocationsExclusiveScanNonUniformAMD(f16vec4);"
3091 
3092             "int16_t addInvocationsExclusiveScanNonUniformAMD(int16_t);"
3093             "i16vec2 addInvocationsExclusiveScanNonUniformAMD(i16vec2);"
3094             "i16vec3 addInvocationsExclusiveScanNonUniformAMD(i16vec3);"
3095             "i16vec4 addInvocationsExclusiveScanNonUniformAMD(i16vec4);"
3096 
3097             "uint16_t addInvocationsExclusiveScanNonUniformAMD(uint16_t);"
3098             "u16vec2  addInvocationsExclusiveScanNonUniformAMD(u16vec2);"
3099             "u16vec3  addInvocationsExclusiveScanNonUniformAMD(u16vec3);"
3100             "u16vec4  addInvocationsExclusiveScanNonUniformAMD(u16vec4);"
3101 
3102             "float swizzleInvocationsAMD(float, uvec4);"
3103             "vec2  swizzleInvocationsAMD(vec2,  uvec4);"
3104             "vec3  swizzleInvocationsAMD(vec3,  uvec4);"
3105             "vec4  swizzleInvocationsAMD(vec4,  uvec4);"
3106 
3107             "int   swizzleInvocationsAMD(int,   uvec4);"
3108             "ivec2 swizzleInvocationsAMD(ivec2, uvec4);"
3109             "ivec3 swizzleInvocationsAMD(ivec3, uvec4);"
3110             "ivec4 swizzleInvocationsAMD(ivec4, uvec4);"
3111 
3112             "uint  swizzleInvocationsAMD(uint,  uvec4);"
3113             "uvec2 swizzleInvocationsAMD(uvec2, uvec4);"
3114             "uvec3 swizzleInvocationsAMD(uvec3, uvec4);"
3115             "uvec4 swizzleInvocationsAMD(uvec4, uvec4);"
3116 
3117             "float swizzleInvocationsMaskedAMD(float, uvec3);"
3118             "vec2  swizzleInvocationsMaskedAMD(vec2,  uvec3);"
3119             "vec3  swizzleInvocationsMaskedAMD(vec3,  uvec3);"
3120             "vec4  swizzleInvocationsMaskedAMD(vec4,  uvec3);"
3121 
3122             "int   swizzleInvocationsMaskedAMD(int,   uvec3);"
3123             "ivec2 swizzleInvocationsMaskedAMD(ivec2, uvec3);"
3124             "ivec3 swizzleInvocationsMaskedAMD(ivec3, uvec3);"
3125             "ivec4 swizzleInvocationsMaskedAMD(ivec4, uvec3);"
3126 
3127             "uint  swizzleInvocationsMaskedAMD(uint,  uvec3);"
3128             "uvec2 swizzleInvocationsMaskedAMD(uvec2, uvec3);"
3129             "uvec3 swizzleInvocationsMaskedAMD(uvec3, uvec3);"
3130             "uvec4 swizzleInvocationsMaskedAMD(uvec4, uvec3);"
3131 
3132             "float writeInvocationAMD(float, float, uint);"
3133             "vec2  writeInvocationAMD(vec2,  vec2,  uint);"
3134             "vec3  writeInvocationAMD(vec3,  vec3,  uint);"
3135             "vec4  writeInvocationAMD(vec4,  vec4,  uint);"
3136 
3137             "int   writeInvocationAMD(int,   int,   uint);"
3138             "ivec2 writeInvocationAMD(ivec2, ivec2, uint);"
3139             "ivec3 writeInvocationAMD(ivec3, ivec3, uint);"
3140             "ivec4 writeInvocationAMD(ivec4, ivec4, uint);"
3141 
3142             "uint  writeInvocationAMD(uint,  uint,  uint);"
3143             "uvec2 writeInvocationAMD(uvec2, uvec2, uint);"
3144             "uvec3 writeInvocationAMD(uvec3, uvec3, uint);"
3145             "uvec4 writeInvocationAMD(uvec4, uvec4, uint);"
3146 
3147             "uint mbcntAMD(uint64_t);"
3148 
3149             "\n");
3150     }
3151 
3152     // GL_AMD_gcn_shader
3153     if (profile != EEsProfile && version >= 440) {
3154         commonBuiltins.append(
3155             "float cubeFaceIndexAMD(vec3);"
3156             "vec2  cubeFaceCoordAMD(vec3);"
3157             "uint64_t timeAMD();"
3158 
3159             "in int gl_SIMDGroupSizeAMD;"
3160             "\n");
3161     }
3162 
3163     // GL_AMD_shader_fragment_mask
3164     if (profile != EEsProfile && version >= 450) {
3165         commonBuiltins.append(
3166             "uint fragmentMaskFetchAMD(sampler2DMS,       ivec2);"
3167             "uint fragmentMaskFetchAMD(isampler2DMS,      ivec2);"
3168             "uint fragmentMaskFetchAMD(usampler2DMS,      ivec2);"
3169 
3170             "uint fragmentMaskFetchAMD(sampler2DMSArray,  ivec3);"
3171             "uint fragmentMaskFetchAMD(isampler2DMSArray, ivec3);"
3172             "uint fragmentMaskFetchAMD(usampler2DMSArray, ivec3);"
3173 
3174             "vec4  fragmentFetchAMD(sampler2DMS,       ivec2, uint);"
3175             "ivec4 fragmentFetchAMD(isampler2DMS,      ivec2, uint);"
3176             "uvec4 fragmentFetchAMD(usampler2DMS,      ivec2, uint);"
3177 
3178             "vec4  fragmentFetchAMD(sampler2DMSArray,  ivec3, uint);"
3179             "ivec4 fragmentFetchAMD(isampler2DMSArray, ivec3, uint);"
3180             "uvec4 fragmentFetchAMD(usampler2DMSArray, ivec3, uint);"
3181 
3182             "\n");
3183     }
3184 
3185     if ((profile != EEsProfile && version >= 130) ||
3186         (profile == EEsProfile && version >= 300)) {
3187         commonBuiltins.append(
3188             "uint countLeadingZeros(uint);"
3189             "uvec2 countLeadingZeros(uvec2);"
3190             "uvec3 countLeadingZeros(uvec3);"
3191             "uvec4 countLeadingZeros(uvec4);"
3192 
3193             "uint countTrailingZeros(uint);"
3194             "uvec2 countTrailingZeros(uvec2);"
3195             "uvec3 countTrailingZeros(uvec3);"
3196             "uvec4 countTrailingZeros(uvec4);"
3197 
3198             "uint absoluteDifference(int, int);"
3199             "uvec2 absoluteDifference(ivec2, ivec2);"
3200             "uvec3 absoluteDifference(ivec3, ivec3);"
3201             "uvec4 absoluteDifference(ivec4, ivec4);"
3202 
3203             "uint16_t absoluteDifference(int16_t, int16_t);"
3204             "u16vec2 absoluteDifference(i16vec2, i16vec2);"
3205             "u16vec3 absoluteDifference(i16vec3, i16vec3);"
3206             "u16vec4 absoluteDifference(i16vec4, i16vec4);"
3207 
3208             "uint64_t absoluteDifference(int64_t, int64_t);"
3209             "u64vec2 absoluteDifference(i64vec2, i64vec2);"
3210             "u64vec3 absoluteDifference(i64vec3, i64vec3);"
3211             "u64vec4 absoluteDifference(i64vec4, i64vec4);"
3212 
3213             "uint absoluteDifference(uint, uint);"
3214             "uvec2 absoluteDifference(uvec2, uvec2);"
3215             "uvec3 absoluteDifference(uvec3, uvec3);"
3216             "uvec4 absoluteDifference(uvec4, uvec4);"
3217 
3218             "uint16_t absoluteDifference(uint16_t, uint16_t);"
3219             "u16vec2 absoluteDifference(u16vec2, u16vec2);"
3220             "u16vec3 absoluteDifference(u16vec3, u16vec3);"
3221             "u16vec4 absoluteDifference(u16vec4, u16vec4);"
3222 
3223             "uint64_t absoluteDifference(uint64_t, uint64_t);"
3224             "u64vec2 absoluteDifference(u64vec2, u64vec2);"
3225             "u64vec3 absoluteDifference(u64vec3, u64vec3);"
3226             "u64vec4 absoluteDifference(u64vec4, u64vec4);"
3227 
3228             "int addSaturate(int, int);"
3229             "ivec2 addSaturate(ivec2, ivec2);"
3230             "ivec3 addSaturate(ivec3, ivec3);"
3231             "ivec4 addSaturate(ivec4, ivec4);"
3232 
3233             "int16_t addSaturate(int16_t, int16_t);"
3234             "i16vec2 addSaturate(i16vec2, i16vec2);"
3235             "i16vec3 addSaturate(i16vec3, i16vec3);"
3236             "i16vec4 addSaturate(i16vec4, i16vec4);"
3237 
3238             "int64_t addSaturate(int64_t, int64_t);"
3239             "i64vec2 addSaturate(i64vec2, i64vec2);"
3240             "i64vec3 addSaturate(i64vec3, i64vec3);"
3241             "i64vec4 addSaturate(i64vec4, i64vec4);"
3242 
3243             "uint addSaturate(uint, uint);"
3244             "uvec2 addSaturate(uvec2, uvec2);"
3245             "uvec3 addSaturate(uvec3, uvec3);"
3246             "uvec4 addSaturate(uvec4, uvec4);"
3247 
3248             "uint16_t addSaturate(uint16_t, uint16_t);"
3249             "u16vec2 addSaturate(u16vec2, u16vec2);"
3250             "u16vec3 addSaturate(u16vec3, u16vec3);"
3251             "u16vec4 addSaturate(u16vec4, u16vec4);"
3252 
3253             "uint64_t addSaturate(uint64_t, uint64_t);"
3254             "u64vec2 addSaturate(u64vec2, u64vec2);"
3255             "u64vec3 addSaturate(u64vec3, u64vec3);"
3256             "u64vec4 addSaturate(u64vec4, u64vec4);"
3257 
3258             "int subtractSaturate(int, int);"
3259             "ivec2 subtractSaturate(ivec2, ivec2);"
3260             "ivec3 subtractSaturate(ivec3, ivec3);"
3261             "ivec4 subtractSaturate(ivec4, ivec4);"
3262 
3263             "int16_t subtractSaturate(int16_t, int16_t);"
3264             "i16vec2 subtractSaturate(i16vec2, i16vec2);"
3265             "i16vec3 subtractSaturate(i16vec3, i16vec3);"
3266             "i16vec4 subtractSaturate(i16vec4, i16vec4);"
3267 
3268             "int64_t subtractSaturate(int64_t, int64_t);"
3269             "i64vec2 subtractSaturate(i64vec2, i64vec2);"
3270             "i64vec3 subtractSaturate(i64vec3, i64vec3);"
3271             "i64vec4 subtractSaturate(i64vec4, i64vec4);"
3272 
3273             "uint subtractSaturate(uint, uint);"
3274             "uvec2 subtractSaturate(uvec2, uvec2);"
3275             "uvec3 subtractSaturate(uvec3, uvec3);"
3276             "uvec4 subtractSaturate(uvec4, uvec4);"
3277 
3278             "uint16_t subtractSaturate(uint16_t, uint16_t);"
3279             "u16vec2 subtractSaturate(u16vec2, u16vec2);"
3280             "u16vec3 subtractSaturate(u16vec3, u16vec3);"
3281             "u16vec4 subtractSaturate(u16vec4, u16vec4);"
3282 
3283             "uint64_t subtractSaturate(uint64_t, uint64_t);"
3284             "u64vec2 subtractSaturate(u64vec2, u64vec2);"
3285             "u64vec3 subtractSaturate(u64vec3, u64vec3);"
3286             "u64vec4 subtractSaturate(u64vec4, u64vec4);"
3287 
3288             "int average(int, int);"
3289             "ivec2 average(ivec2, ivec2);"
3290             "ivec3 average(ivec3, ivec3);"
3291             "ivec4 average(ivec4, ivec4);"
3292 
3293             "int16_t average(int16_t, int16_t);"
3294             "i16vec2 average(i16vec2, i16vec2);"
3295             "i16vec3 average(i16vec3, i16vec3);"
3296             "i16vec4 average(i16vec4, i16vec4);"
3297 
3298             "int64_t average(int64_t, int64_t);"
3299             "i64vec2 average(i64vec2, i64vec2);"
3300             "i64vec3 average(i64vec3, i64vec3);"
3301             "i64vec4 average(i64vec4, i64vec4);"
3302 
3303             "uint average(uint, uint);"
3304             "uvec2 average(uvec2, uvec2);"
3305             "uvec3 average(uvec3, uvec3);"
3306             "uvec4 average(uvec4, uvec4);"
3307 
3308             "uint16_t average(uint16_t, uint16_t);"
3309             "u16vec2 average(u16vec2, u16vec2);"
3310             "u16vec3 average(u16vec3, u16vec3);"
3311             "u16vec4 average(u16vec4, u16vec4);"
3312 
3313             "uint64_t average(uint64_t, uint64_t);"
3314             "u64vec2 average(u64vec2, u64vec2);"
3315             "u64vec3 average(u64vec3, u64vec3);"
3316             "u64vec4 average(u64vec4, u64vec4);"
3317 
3318             "int averageRounded(int, int);"
3319             "ivec2 averageRounded(ivec2, ivec2);"
3320             "ivec3 averageRounded(ivec3, ivec3);"
3321             "ivec4 averageRounded(ivec4, ivec4);"
3322 
3323             "int16_t averageRounded(int16_t, int16_t);"
3324             "i16vec2 averageRounded(i16vec2, i16vec2);"
3325             "i16vec3 averageRounded(i16vec3, i16vec3);"
3326             "i16vec4 averageRounded(i16vec4, i16vec4);"
3327 
3328             "int64_t averageRounded(int64_t, int64_t);"
3329             "i64vec2 averageRounded(i64vec2, i64vec2);"
3330             "i64vec3 averageRounded(i64vec3, i64vec3);"
3331             "i64vec4 averageRounded(i64vec4, i64vec4);"
3332 
3333             "uint averageRounded(uint, uint);"
3334             "uvec2 averageRounded(uvec2, uvec2);"
3335             "uvec3 averageRounded(uvec3, uvec3);"
3336             "uvec4 averageRounded(uvec4, uvec4);"
3337 
3338             "uint16_t averageRounded(uint16_t, uint16_t);"
3339             "u16vec2 averageRounded(u16vec2, u16vec2);"
3340             "u16vec3 averageRounded(u16vec3, u16vec3);"
3341             "u16vec4 averageRounded(u16vec4, u16vec4);"
3342 
3343             "uint64_t averageRounded(uint64_t, uint64_t);"
3344             "u64vec2 averageRounded(u64vec2, u64vec2);"
3345             "u64vec3 averageRounded(u64vec3, u64vec3);"
3346             "u64vec4 averageRounded(u64vec4, u64vec4);"
3347 
3348             "int multiply32x16(int, int);"
3349             "ivec2 multiply32x16(ivec2, ivec2);"
3350             "ivec3 multiply32x16(ivec3, ivec3);"
3351             "ivec4 multiply32x16(ivec4, ivec4);"
3352 
3353             "uint multiply32x16(uint, uint);"
3354             "uvec2 multiply32x16(uvec2, uvec2);"
3355             "uvec3 multiply32x16(uvec3, uvec3);"
3356             "uvec4 multiply32x16(uvec4, uvec4);"
3357             "\n");
3358     }
3359 
3360     if ((profile != EEsProfile && version >= 450) ||
3361         (profile == EEsProfile && version >= 320)) {
3362         commonBuiltins.append(
3363             "struct gl_TextureFootprint2DNV {"
3364                 "uvec2 anchor;"
3365                 "uvec2 offset;"
3366                 "uvec2 mask;"
3367                 "uint lod;"
3368                 "uint granularity;"
3369             "};"
3370 
3371             "struct gl_TextureFootprint3DNV {"
3372                 "uvec3 anchor;"
3373                 "uvec3 offset;"
3374                 "uvec2 mask;"
3375                 "uint lod;"
3376                 "uint granularity;"
3377             "};"
3378             "bool textureFootprintNV(sampler2D, vec2, int, bool, out gl_TextureFootprint2DNV);"
3379             "bool textureFootprintNV(sampler3D, vec3, int, bool, out gl_TextureFootprint3DNV);"
3380             "bool textureFootprintNV(sampler2D, vec2, int, bool, out gl_TextureFootprint2DNV, float);"
3381             "bool textureFootprintNV(sampler3D, vec3, int, bool, out gl_TextureFootprint3DNV, float);"
3382             "bool textureFootprintClampNV(sampler2D, vec2, float, int, bool, out gl_TextureFootprint2DNV);"
3383             "bool textureFootprintClampNV(sampler3D, vec3, float, int, bool, out gl_TextureFootprint3DNV);"
3384             "bool textureFootprintClampNV(sampler2D, vec2, float, int, bool, out gl_TextureFootprint2DNV, float);"
3385             "bool textureFootprintClampNV(sampler3D, vec3, float, int, bool, out gl_TextureFootprint3DNV, float);"
3386             "bool textureFootprintLodNV(sampler2D, vec2, float, int, bool, out gl_TextureFootprint2DNV);"
3387             "bool textureFootprintLodNV(sampler3D, vec3, float, int, bool, out gl_TextureFootprint3DNV);"
3388             "bool textureFootprintGradNV(sampler2D, vec2, vec2, vec2, int, bool, out gl_TextureFootprint2DNV);"
3389             "bool textureFootprintGradClampNV(sampler2D, vec2, vec2, vec2, float, int, bool, out gl_TextureFootprint2DNV);"
3390             "\n");
3391     }
3392 #endif // !GLSLANG_ANGLE
3393 
3394     if ((profile == EEsProfile && version >= 300 && version < 310) ||
3395         (profile != EEsProfile && version >= 150 && version < 450)) { // GL_EXT_shader_integer_mix
3396         commonBuiltins.append("int mix(int, int, bool);"
3397                               "ivec2 mix(ivec2, ivec2, bvec2);"
3398                               "ivec3 mix(ivec3, ivec3, bvec3);"
3399                               "ivec4 mix(ivec4, ivec4, bvec4);"
3400                               "uint  mix(uint,  uint,  bool );"
3401                               "uvec2 mix(uvec2, uvec2, bvec2);"
3402                               "uvec3 mix(uvec3, uvec3, bvec3);"
3403                               "uvec4 mix(uvec4, uvec4, bvec4);"
3404                               "bool  mix(bool,  bool,  bool );"
3405                               "bvec2 mix(bvec2, bvec2, bvec2);"
3406                               "bvec3 mix(bvec3, bvec3, bvec3);"
3407                               "bvec4 mix(bvec4, bvec4, bvec4);"
3408 
3409                               "\n");
3410     }
3411 
3412 #ifndef GLSLANG_ANGLE
3413     // GL_AMD_gpu_shader_half_float/Explicit types
3414     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
3415         commonBuiltins.append(
3416             "float16_t radians(float16_t);"
3417             "f16vec2   radians(f16vec2);"
3418             "f16vec3   radians(f16vec3);"
3419             "f16vec4   radians(f16vec4);"
3420 
3421             "float16_t degrees(float16_t);"
3422             "f16vec2   degrees(f16vec2);"
3423             "f16vec3   degrees(f16vec3);"
3424             "f16vec4   degrees(f16vec4);"
3425 
3426             "float16_t sin(float16_t);"
3427             "f16vec2   sin(f16vec2);"
3428             "f16vec3   sin(f16vec3);"
3429             "f16vec4   sin(f16vec4);"
3430 
3431             "float16_t cos(float16_t);"
3432             "f16vec2   cos(f16vec2);"
3433             "f16vec3   cos(f16vec3);"
3434             "f16vec4   cos(f16vec4);"
3435 
3436             "float16_t tan(float16_t);"
3437             "f16vec2   tan(f16vec2);"
3438             "f16vec3   tan(f16vec3);"
3439             "f16vec4   tan(f16vec4);"
3440 
3441             "float16_t asin(float16_t);"
3442             "f16vec2   asin(f16vec2);"
3443             "f16vec3   asin(f16vec3);"
3444             "f16vec4   asin(f16vec4);"
3445 
3446             "float16_t acos(float16_t);"
3447             "f16vec2   acos(f16vec2);"
3448             "f16vec3   acos(f16vec3);"
3449             "f16vec4   acos(f16vec4);"
3450 
3451             "float16_t atan(float16_t, float16_t);"
3452             "f16vec2   atan(f16vec2,   f16vec2);"
3453             "f16vec3   atan(f16vec3,   f16vec3);"
3454             "f16vec4   atan(f16vec4,   f16vec4);"
3455 
3456             "float16_t atan(float16_t);"
3457             "f16vec2   atan(f16vec2);"
3458             "f16vec3   atan(f16vec3);"
3459             "f16vec4   atan(f16vec4);"
3460 
3461             "float16_t sinh(float16_t);"
3462             "f16vec2   sinh(f16vec2);"
3463             "f16vec3   sinh(f16vec3);"
3464             "f16vec4   sinh(f16vec4);"
3465 
3466             "float16_t cosh(float16_t);"
3467             "f16vec2   cosh(f16vec2);"
3468             "f16vec3   cosh(f16vec3);"
3469             "f16vec4   cosh(f16vec4);"
3470 
3471             "float16_t tanh(float16_t);"
3472             "f16vec2   tanh(f16vec2);"
3473             "f16vec3   tanh(f16vec3);"
3474             "f16vec4   tanh(f16vec4);"
3475 
3476             "float16_t asinh(float16_t);"
3477             "f16vec2   asinh(f16vec2);"
3478             "f16vec3   asinh(f16vec3);"
3479             "f16vec4   asinh(f16vec4);"
3480 
3481             "float16_t acosh(float16_t);"
3482             "f16vec2   acosh(f16vec2);"
3483             "f16vec3   acosh(f16vec3);"
3484             "f16vec4   acosh(f16vec4);"
3485 
3486             "float16_t atanh(float16_t);"
3487             "f16vec2   atanh(f16vec2);"
3488             "f16vec3   atanh(f16vec3);"
3489             "f16vec4   atanh(f16vec4);"
3490 
3491             "float16_t pow(float16_t, float16_t);"
3492             "f16vec2   pow(f16vec2,   f16vec2);"
3493             "f16vec3   pow(f16vec3,   f16vec3);"
3494             "f16vec4   pow(f16vec4,   f16vec4);"
3495 
3496             "float16_t exp(float16_t);"
3497             "f16vec2   exp(f16vec2);"
3498             "f16vec3   exp(f16vec3);"
3499             "f16vec4   exp(f16vec4);"
3500 
3501             "float16_t log(float16_t);"
3502             "f16vec2   log(f16vec2);"
3503             "f16vec3   log(f16vec3);"
3504             "f16vec4   log(f16vec4);"
3505 
3506             "float16_t exp2(float16_t);"
3507             "f16vec2   exp2(f16vec2);"
3508             "f16vec3   exp2(f16vec3);"
3509             "f16vec4   exp2(f16vec4);"
3510 
3511             "float16_t log2(float16_t);"
3512             "f16vec2   log2(f16vec2);"
3513             "f16vec3   log2(f16vec3);"
3514             "f16vec4   log2(f16vec4);"
3515 
3516             "float16_t sqrt(float16_t);"
3517             "f16vec2   sqrt(f16vec2);"
3518             "f16vec3   sqrt(f16vec3);"
3519             "f16vec4   sqrt(f16vec4);"
3520 
3521             "float16_t inversesqrt(float16_t);"
3522             "f16vec2   inversesqrt(f16vec2);"
3523             "f16vec3   inversesqrt(f16vec3);"
3524             "f16vec4   inversesqrt(f16vec4);"
3525 
3526             "float16_t abs(float16_t);"
3527             "f16vec2   abs(f16vec2);"
3528             "f16vec3   abs(f16vec3);"
3529             "f16vec4   abs(f16vec4);"
3530 
3531             "float16_t sign(float16_t);"
3532             "f16vec2   sign(f16vec2);"
3533             "f16vec3   sign(f16vec3);"
3534             "f16vec4   sign(f16vec4);"
3535 
3536             "float16_t floor(float16_t);"
3537             "f16vec2   floor(f16vec2);"
3538             "f16vec3   floor(f16vec3);"
3539             "f16vec4   floor(f16vec4);"
3540 
3541             "float16_t trunc(float16_t);"
3542             "f16vec2   trunc(f16vec2);"
3543             "f16vec3   trunc(f16vec3);"
3544             "f16vec4   trunc(f16vec4);"
3545 
3546             "float16_t round(float16_t);"
3547             "f16vec2   round(f16vec2);"
3548             "f16vec3   round(f16vec3);"
3549             "f16vec4   round(f16vec4);"
3550 
3551             "float16_t roundEven(float16_t);"
3552             "f16vec2   roundEven(f16vec2);"
3553             "f16vec3   roundEven(f16vec3);"
3554             "f16vec4   roundEven(f16vec4);"
3555 
3556             "float16_t ceil(float16_t);"
3557             "f16vec2   ceil(f16vec2);"
3558             "f16vec3   ceil(f16vec3);"
3559             "f16vec4   ceil(f16vec4);"
3560 
3561             "float16_t fract(float16_t);"
3562             "f16vec2   fract(f16vec2);"
3563             "f16vec3   fract(f16vec3);"
3564             "f16vec4   fract(f16vec4);"
3565 
3566             "float16_t mod(float16_t, float16_t);"
3567             "f16vec2   mod(f16vec2,   float16_t);"
3568             "f16vec3   mod(f16vec3,   float16_t);"
3569             "f16vec4   mod(f16vec4,   float16_t);"
3570             "f16vec2   mod(f16vec2,   f16vec2);"
3571             "f16vec3   mod(f16vec3,   f16vec3);"
3572             "f16vec4   mod(f16vec4,   f16vec4);"
3573 
3574             "float16_t modf(float16_t, out float16_t);"
3575             "f16vec2   modf(f16vec2,   out f16vec2);"
3576             "f16vec3   modf(f16vec3,   out f16vec3);"
3577             "f16vec4   modf(f16vec4,   out f16vec4);"
3578 
3579             "float16_t min(float16_t, float16_t);"
3580             "f16vec2   min(f16vec2,   float16_t);"
3581             "f16vec3   min(f16vec3,   float16_t);"
3582             "f16vec4   min(f16vec4,   float16_t);"
3583             "f16vec2   min(f16vec2,   f16vec2);"
3584             "f16vec3   min(f16vec3,   f16vec3);"
3585             "f16vec4   min(f16vec4,   f16vec4);"
3586 
3587             "float16_t max(float16_t, float16_t);"
3588             "f16vec2   max(f16vec2,   float16_t);"
3589             "f16vec3   max(f16vec3,   float16_t);"
3590             "f16vec4   max(f16vec4,   float16_t);"
3591             "f16vec2   max(f16vec2,   f16vec2);"
3592             "f16vec3   max(f16vec3,   f16vec3);"
3593             "f16vec4   max(f16vec4,   f16vec4);"
3594 
3595             "float16_t clamp(float16_t, float16_t, float16_t);"
3596             "f16vec2   clamp(f16vec2,   float16_t, float16_t);"
3597             "f16vec3   clamp(f16vec3,   float16_t, float16_t);"
3598             "f16vec4   clamp(f16vec4,   float16_t, float16_t);"
3599             "f16vec2   clamp(f16vec2,   f16vec2,   f16vec2);"
3600             "f16vec3   clamp(f16vec3,   f16vec3,   f16vec3);"
3601             "f16vec4   clamp(f16vec4,   f16vec4,   f16vec4);"
3602 
3603             "float16_t mix(float16_t, float16_t, float16_t);"
3604             "f16vec2   mix(f16vec2,   f16vec2,   float16_t);"
3605             "f16vec3   mix(f16vec3,   f16vec3,   float16_t);"
3606             "f16vec4   mix(f16vec4,   f16vec4,   float16_t);"
3607             "f16vec2   mix(f16vec2,   f16vec2,   f16vec2);"
3608             "f16vec3   mix(f16vec3,   f16vec3,   f16vec3);"
3609             "f16vec4   mix(f16vec4,   f16vec4,   f16vec4);"
3610             "float16_t mix(float16_t, float16_t, bool);"
3611             "f16vec2   mix(f16vec2,   f16vec2,   bvec2);"
3612             "f16vec3   mix(f16vec3,   f16vec3,   bvec3);"
3613             "f16vec4   mix(f16vec4,   f16vec4,   bvec4);"
3614 
3615             "float16_t step(float16_t, float16_t);"
3616             "f16vec2   step(f16vec2,   f16vec2);"
3617             "f16vec3   step(f16vec3,   f16vec3);"
3618             "f16vec4   step(f16vec4,   f16vec4);"
3619             "f16vec2   step(float16_t, f16vec2);"
3620             "f16vec3   step(float16_t, f16vec3);"
3621             "f16vec4   step(float16_t, f16vec4);"
3622 
3623             "float16_t smoothstep(float16_t, float16_t, float16_t);"
3624             "f16vec2   smoothstep(f16vec2,   f16vec2,   f16vec2);"
3625             "f16vec3   smoothstep(f16vec3,   f16vec3,   f16vec3);"
3626             "f16vec4   smoothstep(f16vec4,   f16vec4,   f16vec4);"
3627             "f16vec2   smoothstep(float16_t, float16_t, f16vec2);"
3628             "f16vec3   smoothstep(float16_t, float16_t, f16vec3);"
3629             "f16vec4   smoothstep(float16_t, float16_t, f16vec4);"
3630 
3631             "bool  isnan(float16_t);"
3632             "bvec2 isnan(f16vec2);"
3633             "bvec3 isnan(f16vec3);"
3634             "bvec4 isnan(f16vec4);"
3635 
3636             "bool  isinf(float16_t);"
3637             "bvec2 isinf(f16vec2);"
3638             "bvec3 isinf(f16vec3);"
3639             "bvec4 isinf(f16vec4);"
3640 
3641             "float16_t fma(float16_t, float16_t, float16_t);"
3642             "f16vec2   fma(f16vec2,   f16vec2,   f16vec2);"
3643             "f16vec3   fma(f16vec3,   f16vec3,   f16vec3);"
3644             "f16vec4   fma(f16vec4,   f16vec4,   f16vec4);"
3645 
3646             "float16_t frexp(float16_t, out int);"
3647             "f16vec2   frexp(f16vec2,   out ivec2);"
3648             "f16vec3   frexp(f16vec3,   out ivec3);"
3649             "f16vec4   frexp(f16vec4,   out ivec4);"
3650 
3651             "float16_t ldexp(float16_t, in int);"
3652             "f16vec2   ldexp(f16vec2,   in ivec2);"
3653             "f16vec3   ldexp(f16vec3,   in ivec3);"
3654             "f16vec4   ldexp(f16vec4,   in ivec4);"
3655 
3656             "uint    packFloat2x16(f16vec2);"
3657             "f16vec2 unpackFloat2x16(uint);"
3658 
3659             "float16_t length(float16_t);"
3660             "float16_t length(f16vec2);"
3661             "float16_t length(f16vec3);"
3662             "float16_t length(f16vec4);"
3663 
3664             "float16_t distance(float16_t, float16_t);"
3665             "float16_t distance(f16vec2,   f16vec2);"
3666             "float16_t distance(f16vec3,   f16vec3);"
3667             "float16_t distance(f16vec4,   f16vec4);"
3668 
3669             "float16_t dot(float16_t, float16_t);"
3670             "float16_t dot(f16vec2,   f16vec2);"
3671             "float16_t dot(f16vec3,   f16vec3);"
3672             "float16_t dot(f16vec4,   f16vec4);"
3673 
3674             "f16vec3 cross(f16vec3, f16vec3);"
3675 
3676             "float16_t normalize(float16_t);"
3677             "f16vec2   normalize(f16vec2);"
3678             "f16vec3   normalize(f16vec3);"
3679             "f16vec4   normalize(f16vec4);"
3680 
3681             "float16_t faceforward(float16_t, float16_t, float16_t);"
3682             "f16vec2   faceforward(f16vec2,   f16vec2,   f16vec2);"
3683             "f16vec3   faceforward(f16vec3,   f16vec3,   f16vec3);"
3684             "f16vec4   faceforward(f16vec4,   f16vec4,   f16vec4);"
3685 
3686             "float16_t reflect(float16_t, float16_t);"
3687             "f16vec2   reflect(f16vec2,   f16vec2);"
3688             "f16vec3   reflect(f16vec3,   f16vec3);"
3689             "f16vec4   reflect(f16vec4,   f16vec4);"
3690 
3691             "float16_t refract(float16_t, float16_t, float16_t);"
3692             "f16vec2   refract(f16vec2,   f16vec2,   float16_t);"
3693             "f16vec3   refract(f16vec3,   f16vec3,   float16_t);"
3694             "f16vec4   refract(f16vec4,   f16vec4,   float16_t);"
3695 
3696             "f16mat2   matrixCompMult(f16mat2,   f16mat2);"
3697             "f16mat3   matrixCompMult(f16mat3,   f16mat3);"
3698             "f16mat4   matrixCompMult(f16mat4,   f16mat4);"
3699             "f16mat2x3 matrixCompMult(f16mat2x3, f16mat2x3);"
3700             "f16mat2x4 matrixCompMult(f16mat2x4, f16mat2x4);"
3701             "f16mat3x2 matrixCompMult(f16mat3x2, f16mat3x2);"
3702             "f16mat3x4 matrixCompMult(f16mat3x4, f16mat3x4);"
3703             "f16mat4x2 matrixCompMult(f16mat4x2, f16mat4x2);"
3704             "f16mat4x3 matrixCompMult(f16mat4x3, f16mat4x3);"
3705 
3706             "f16mat2   outerProduct(f16vec2, f16vec2);"
3707             "f16mat3   outerProduct(f16vec3, f16vec3);"
3708             "f16mat4   outerProduct(f16vec4, f16vec4);"
3709             "f16mat2x3 outerProduct(f16vec3, f16vec2);"
3710             "f16mat3x2 outerProduct(f16vec2, f16vec3);"
3711             "f16mat2x4 outerProduct(f16vec4, f16vec2);"
3712             "f16mat4x2 outerProduct(f16vec2, f16vec4);"
3713             "f16mat3x4 outerProduct(f16vec4, f16vec3);"
3714             "f16mat4x3 outerProduct(f16vec3, f16vec4);"
3715 
3716             "f16mat2   transpose(f16mat2);"
3717             "f16mat3   transpose(f16mat3);"
3718             "f16mat4   transpose(f16mat4);"
3719             "f16mat2x3 transpose(f16mat3x2);"
3720             "f16mat3x2 transpose(f16mat2x3);"
3721             "f16mat2x4 transpose(f16mat4x2);"
3722             "f16mat4x2 transpose(f16mat2x4);"
3723             "f16mat3x4 transpose(f16mat4x3);"
3724             "f16mat4x3 transpose(f16mat3x4);"
3725 
3726             "float16_t determinant(f16mat2);"
3727             "float16_t determinant(f16mat3);"
3728             "float16_t determinant(f16mat4);"
3729 
3730             "f16mat2 inverse(f16mat2);"
3731             "f16mat3 inverse(f16mat3);"
3732             "f16mat4 inverse(f16mat4);"
3733 
3734             "bvec2 lessThan(f16vec2, f16vec2);"
3735             "bvec3 lessThan(f16vec3, f16vec3);"
3736             "bvec4 lessThan(f16vec4, f16vec4);"
3737 
3738             "bvec2 lessThanEqual(f16vec2, f16vec2);"
3739             "bvec3 lessThanEqual(f16vec3, f16vec3);"
3740             "bvec4 lessThanEqual(f16vec4, f16vec4);"
3741 
3742             "bvec2 greaterThan(f16vec2, f16vec2);"
3743             "bvec3 greaterThan(f16vec3, f16vec3);"
3744             "bvec4 greaterThan(f16vec4, f16vec4);"
3745 
3746             "bvec2 greaterThanEqual(f16vec2, f16vec2);"
3747             "bvec3 greaterThanEqual(f16vec3, f16vec3);"
3748             "bvec4 greaterThanEqual(f16vec4, f16vec4);"
3749 
3750             "bvec2 equal(f16vec2, f16vec2);"
3751             "bvec3 equal(f16vec3, f16vec3);"
3752             "bvec4 equal(f16vec4, f16vec4);"
3753 
3754             "bvec2 notEqual(f16vec2, f16vec2);"
3755             "bvec3 notEqual(f16vec3, f16vec3);"
3756             "bvec4 notEqual(f16vec4, f16vec4);"
3757 
3758             "\n");
3759     }
3760 
3761     // Explicit types
3762     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
3763         commonBuiltins.append(
3764             "int8_t abs(int8_t);"
3765             "i8vec2 abs(i8vec2);"
3766             "i8vec3 abs(i8vec3);"
3767             "i8vec4 abs(i8vec4);"
3768 
3769             "int8_t sign(int8_t);"
3770             "i8vec2 sign(i8vec2);"
3771             "i8vec3 sign(i8vec3);"
3772             "i8vec4 sign(i8vec4);"
3773 
3774             "int8_t min(int8_t x, int8_t y);"
3775             "i8vec2 min(i8vec2 x, int8_t y);"
3776             "i8vec3 min(i8vec3 x, int8_t y);"
3777             "i8vec4 min(i8vec4 x, int8_t y);"
3778             "i8vec2 min(i8vec2 x, i8vec2 y);"
3779             "i8vec3 min(i8vec3 x, i8vec3 y);"
3780             "i8vec4 min(i8vec4 x, i8vec4 y);"
3781 
3782             "uint8_t min(uint8_t x, uint8_t y);"
3783             "u8vec2 min(u8vec2 x, uint8_t y);"
3784             "u8vec3 min(u8vec3 x, uint8_t y);"
3785             "u8vec4 min(u8vec4 x, uint8_t y);"
3786             "u8vec2 min(u8vec2 x, u8vec2 y);"
3787             "u8vec3 min(u8vec3 x, u8vec3 y);"
3788             "u8vec4 min(u8vec4 x, u8vec4 y);"
3789 
3790             "int8_t max(int8_t x, int8_t y);"
3791             "i8vec2 max(i8vec2 x, int8_t y);"
3792             "i8vec3 max(i8vec3 x, int8_t y);"
3793             "i8vec4 max(i8vec4 x, int8_t y);"
3794             "i8vec2 max(i8vec2 x, i8vec2 y);"
3795             "i8vec3 max(i8vec3 x, i8vec3 y);"
3796             "i8vec4 max(i8vec4 x, i8vec4 y);"
3797 
3798             "uint8_t max(uint8_t x, uint8_t y);"
3799             "u8vec2 max(u8vec2 x, uint8_t y);"
3800             "u8vec3 max(u8vec3 x, uint8_t y);"
3801             "u8vec4 max(u8vec4 x, uint8_t y);"
3802             "u8vec2 max(u8vec2 x, u8vec2 y);"
3803             "u8vec3 max(u8vec3 x, u8vec3 y);"
3804             "u8vec4 max(u8vec4 x, u8vec4 y);"
3805 
3806             "int8_t    clamp(int8_t x, int8_t minVal, int8_t maxVal);"
3807             "i8vec2  clamp(i8vec2  x, int8_t minVal, int8_t maxVal);"
3808             "i8vec3  clamp(i8vec3  x, int8_t minVal, int8_t maxVal);"
3809             "i8vec4  clamp(i8vec4  x, int8_t minVal, int8_t maxVal);"
3810             "i8vec2  clamp(i8vec2  x, i8vec2  minVal, i8vec2  maxVal);"
3811             "i8vec3  clamp(i8vec3  x, i8vec3  minVal, i8vec3  maxVal);"
3812             "i8vec4  clamp(i8vec4  x, i8vec4  minVal, i8vec4  maxVal);"
3813 
3814             "uint8_t   clamp(uint8_t x, uint8_t minVal, uint8_t maxVal);"
3815             "u8vec2  clamp(u8vec2  x, uint8_t minVal, uint8_t maxVal);"
3816             "u8vec3  clamp(u8vec3  x, uint8_t minVal, uint8_t maxVal);"
3817             "u8vec4  clamp(u8vec4  x, uint8_t minVal, uint8_t maxVal);"
3818             "u8vec2  clamp(u8vec2  x, u8vec2  minVal, u8vec2  maxVal);"
3819             "u8vec3  clamp(u8vec3  x, u8vec3  minVal, u8vec3  maxVal);"
3820             "u8vec4  clamp(u8vec4  x, u8vec4  minVal, u8vec4  maxVal);"
3821 
3822             "int8_t  mix(int8_t,  int8_t,  bool);"
3823             "i8vec2  mix(i8vec2,  i8vec2,  bvec2);"
3824             "i8vec3  mix(i8vec3,  i8vec3,  bvec3);"
3825             "i8vec4  mix(i8vec4,  i8vec4,  bvec4);"
3826             "uint8_t mix(uint8_t, uint8_t, bool);"
3827             "u8vec2  mix(u8vec2,  u8vec2,  bvec2);"
3828             "u8vec3  mix(u8vec3,  u8vec3,  bvec3);"
3829             "u8vec4  mix(u8vec4,  u8vec4,  bvec4);"
3830 
3831             "bvec2 lessThan(i8vec2, i8vec2);"
3832             "bvec3 lessThan(i8vec3, i8vec3);"
3833             "bvec4 lessThan(i8vec4, i8vec4);"
3834             "bvec2 lessThan(u8vec2, u8vec2);"
3835             "bvec3 lessThan(u8vec3, u8vec3);"
3836             "bvec4 lessThan(u8vec4, u8vec4);"
3837 
3838             "bvec2 lessThanEqual(i8vec2, i8vec2);"
3839             "bvec3 lessThanEqual(i8vec3, i8vec3);"
3840             "bvec4 lessThanEqual(i8vec4, i8vec4);"
3841             "bvec2 lessThanEqual(u8vec2, u8vec2);"
3842             "bvec3 lessThanEqual(u8vec3, u8vec3);"
3843             "bvec4 lessThanEqual(u8vec4, u8vec4);"
3844 
3845             "bvec2 greaterThan(i8vec2, i8vec2);"
3846             "bvec3 greaterThan(i8vec3, i8vec3);"
3847             "bvec4 greaterThan(i8vec4, i8vec4);"
3848             "bvec2 greaterThan(u8vec2, u8vec2);"
3849             "bvec3 greaterThan(u8vec3, u8vec3);"
3850             "bvec4 greaterThan(u8vec4, u8vec4);"
3851 
3852             "bvec2 greaterThanEqual(i8vec2, i8vec2);"
3853             "bvec3 greaterThanEqual(i8vec3, i8vec3);"
3854             "bvec4 greaterThanEqual(i8vec4, i8vec4);"
3855             "bvec2 greaterThanEqual(u8vec2, u8vec2);"
3856             "bvec3 greaterThanEqual(u8vec3, u8vec3);"
3857             "bvec4 greaterThanEqual(u8vec4, u8vec4);"
3858 
3859             "bvec2 equal(i8vec2, i8vec2);"
3860             "bvec3 equal(i8vec3, i8vec3);"
3861             "bvec4 equal(i8vec4, i8vec4);"
3862             "bvec2 equal(u8vec2, u8vec2);"
3863             "bvec3 equal(u8vec3, u8vec3);"
3864             "bvec4 equal(u8vec4, u8vec4);"
3865 
3866             "bvec2 notEqual(i8vec2, i8vec2);"
3867             "bvec3 notEqual(i8vec3, i8vec3);"
3868             "bvec4 notEqual(i8vec4, i8vec4);"
3869             "bvec2 notEqual(u8vec2, u8vec2);"
3870             "bvec3 notEqual(u8vec3, u8vec3);"
3871             "bvec4 notEqual(u8vec4, u8vec4);"
3872 
3873             "  int8_t bitfieldExtract(  int8_t, int8_t, int8_t);"
3874             "i8vec2 bitfieldExtract(i8vec2, int8_t, int8_t);"
3875             "i8vec3 bitfieldExtract(i8vec3, int8_t, int8_t);"
3876             "i8vec4 bitfieldExtract(i8vec4, int8_t, int8_t);"
3877 
3878             " uint8_t bitfieldExtract( uint8_t, int8_t, int8_t);"
3879             "u8vec2 bitfieldExtract(u8vec2, int8_t, int8_t);"
3880             "u8vec3 bitfieldExtract(u8vec3, int8_t, int8_t);"
3881             "u8vec4 bitfieldExtract(u8vec4, int8_t, int8_t);"
3882 
3883             "  int8_t bitfieldInsert(  int8_t base,   int8_t, int8_t, int8_t);"
3884             "i8vec2 bitfieldInsert(i8vec2 base, i8vec2, int8_t, int8_t);"
3885             "i8vec3 bitfieldInsert(i8vec3 base, i8vec3, int8_t, int8_t);"
3886             "i8vec4 bitfieldInsert(i8vec4 base, i8vec4, int8_t, int8_t);"
3887 
3888             " uint8_t bitfieldInsert( uint8_t base,  uint8_t, int8_t, int8_t);"
3889             "u8vec2 bitfieldInsert(u8vec2 base, u8vec2, int8_t, int8_t);"
3890             "u8vec3 bitfieldInsert(u8vec3 base, u8vec3, int8_t, int8_t);"
3891             "u8vec4 bitfieldInsert(u8vec4 base, u8vec4, int8_t, int8_t);"
3892 
3893             "  int8_t bitCount(  int8_t);"
3894             "i8vec2 bitCount(i8vec2);"
3895             "i8vec3 bitCount(i8vec3);"
3896             "i8vec4 bitCount(i8vec4);"
3897 
3898             "  int8_t bitCount( uint8_t);"
3899             "i8vec2 bitCount(u8vec2);"
3900             "i8vec3 bitCount(u8vec3);"
3901             "i8vec4 bitCount(u8vec4);"
3902 
3903             "  int8_t findLSB(  int8_t);"
3904             "i8vec2 findLSB(i8vec2);"
3905             "i8vec3 findLSB(i8vec3);"
3906             "i8vec4 findLSB(i8vec4);"
3907 
3908             "  int8_t findLSB( uint8_t);"
3909             "i8vec2 findLSB(u8vec2);"
3910             "i8vec3 findLSB(u8vec3);"
3911             "i8vec4 findLSB(u8vec4);"
3912 
3913             "  int8_t findMSB(  int8_t);"
3914             "i8vec2 findMSB(i8vec2);"
3915             "i8vec3 findMSB(i8vec3);"
3916             "i8vec4 findMSB(i8vec4);"
3917 
3918             "  int8_t findMSB( uint8_t);"
3919             "i8vec2 findMSB(u8vec2);"
3920             "i8vec3 findMSB(u8vec3);"
3921             "i8vec4 findMSB(u8vec4);"
3922 
3923             "int16_t abs(int16_t);"
3924             "i16vec2 abs(i16vec2);"
3925             "i16vec3 abs(i16vec3);"
3926             "i16vec4 abs(i16vec4);"
3927 
3928             "int16_t sign(int16_t);"
3929             "i16vec2 sign(i16vec2);"
3930             "i16vec3 sign(i16vec3);"
3931             "i16vec4 sign(i16vec4);"
3932 
3933             "int16_t min(int16_t x, int16_t y);"
3934             "i16vec2 min(i16vec2 x, int16_t y);"
3935             "i16vec3 min(i16vec3 x, int16_t y);"
3936             "i16vec4 min(i16vec4 x, int16_t y);"
3937             "i16vec2 min(i16vec2 x, i16vec2 y);"
3938             "i16vec3 min(i16vec3 x, i16vec3 y);"
3939             "i16vec4 min(i16vec4 x, i16vec4 y);"
3940 
3941             "uint16_t min(uint16_t x, uint16_t y);"
3942             "u16vec2 min(u16vec2 x, uint16_t y);"
3943             "u16vec3 min(u16vec3 x, uint16_t y);"
3944             "u16vec4 min(u16vec4 x, uint16_t y);"
3945             "u16vec2 min(u16vec2 x, u16vec2 y);"
3946             "u16vec3 min(u16vec3 x, u16vec3 y);"
3947             "u16vec4 min(u16vec4 x, u16vec4 y);"
3948 
3949             "int16_t max(int16_t x, int16_t y);"
3950             "i16vec2 max(i16vec2 x, int16_t y);"
3951             "i16vec3 max(i16vec3 x, int16_t y);"
3952             "i16vec4 max(i16vec4 x, int16_t y);"
3953             "i16vec2 max(i16vec2 x, i16vec2 y);"
3954             "i16vec3 max(i16vec3 x, i16vec3 y);"
3955             "i16vec4 max(i16vec4 x, i16vec4 y);"
3956 
3957             "uint16_t max(uint16_t x, uint16_t y);"
3958             "u16vec2 max(u16vec2 x, uint16_t y);"
3959             "u16vec3 max(u16vec3 x, uint16_t y);"
3960             "u16vec4 max(u16vec4 x, uint16_t y);"
3961             "u16vec2 max(u16vec2 x, u16vec2 y);"
3962             "u16vec3 max(u16vec3 x, u16vec3 y);"
3963             "u16vec4 max(u16vec4 x, u16vec4 y);"
3964 
3965             "int16_t    clamp(int16_t x, int16_t minVal, int16_t maxVal);"
3966             "i16vec2  clamp(i16vec2  x, int16_t minVal, int16_t maxVal);"
3967             "i16vec3  clamp(i16vec3  x, int16_t minVal, int16_t maxVal);"
3968             "i16vec4  clamp(i16vec4  x, int16_t minVal, int16_t maxVal);"
3969             "i16vec2  clamp(i16vec2  x, i16vec2  minVal, i16vec2  maxVal);"
3970             "i16vec3  clamp(i16vec3  x, i16vec3  minVal, i16vec3  maxVal);"
3971             "i16vec4  clamp(i16vec4  x, i16vec4  minVal, i16vec4  maxVal);"
3972 
3973             "uint16_t   clamp(uint16_t x, uint16_t minVal, uint16_t maxVal);"
3974             "u16vec2  clamp(u16vec2  x, uint16_t minVal, uint16_t maxVal);"
3975             "u16vec3  clamp(u16vec3  x, uint16_t minVal, uint16_t maxVal);"
3976             "u16vec4  clamp(u16vec4  x, uint16_t minVal, uint16_t maxVal);"
3977             "u16vec2  clamp(u16vec2  x, u16vec2  minVal, u16vec2  maxVal);"
3978             "u16vec3  clamp(u16vec3  x, u16vec3  minVal, u16vec3  maxVal);"
3979             "u16vec4  clamp(u16vec4  x, u16vec4  minVal, u16vec4  maxVal);"
3980 
3981             "int16_t  mix(int16_t,  int16_t,  bool);"
3982             "i16vec2  mix(i16vec2,  i16vec2,  bvec2);"
3983             "i16vec3  mix(i16vec3,  i16vec3,  bvec3);"
3984             "i16vec4  mix(i16vec4,  i16vec4,  bvec4);"
3985             "uint16_t mix(uint16_t, uint16_t, bool);"
3986             "u16vec2  mix(u16vec2,  u16vec2,  bvec2);"
3987             "u16vec3  mix(u16vec3,  u16vec3,  bvec3);"
3988             "u16vec4  mix(u16vec4,  u16vec4,  bvec4);"
3989 
3990             "float16_t frexp(float16_t, out int16_t);"
3991             "f16vec2   frexp(f16vec2,   out i16vec2);"
3992             "f16vec3   frexp(f16vec3,   out i16vec3);"
3993             "f16vec4   frexp(f16vec4,   out i16vec4);"
3994 
3995             "float16_t ldexp(float16_t, int16_t);"
3996             "f16vec2   ldexp(f16vec2,   i16vec2);"
3997             "f16vec3   ldexp(f16vec3,   i16vec3);"
3998             "f16vec4   ldexp(f16vec4,   i16vec4);"
3999 
4000             "int16_t halfBitsToInt16(float16_t);"
4001             "i16vec2 halfBitsToInt16(f16vec2);"
4002             "i16vec3 halhBitsToInt16(f16vec3);"
4003             "i16vec4 halfBitsToInt16(f16vec4);"
4004 
4005             "uint16_t halfBitsToUint16(float16_t);"
4006             "u16vec2  halfBitsToUint16(f16vec2);"
4007             "u16vec3  halfBitsToUint16(f16vec3);"
4008             "u16vec4  halfBitsToUint16(f16vec4);"
4009 
4010             "int16_t float16BitsToInt16(float16_t);"
4011             "i16vec2 float16BitsToInt16(f16vec2);"
4012             "i16vec3 float16BitsToInt16(f16vec3);"
4013             "i16vec4 float16BitsToInt16(f16vec4);"
4014 
4015             "uint16_t float16BitsToUint16(float16_t);"
4016             "u16vec2  float16BitsToUint16(f16vec2);"
4017             "u16vec3  float16BitsToUint16(f16vec3);"
4018             "u16vec4  float16BitsToUint16(f16vec4);"
4019 
4020             "float16_t int16BitsToFloat16(int16_t);"
4021             "f16vec2   int16BitsToFloat16(i16vec2);"
4022             "f16vec3   int16BitsToFloat16(i16vec3);"
4023             "f16vec4   int16BitsToFloat16(i16vec4);"
4024 
4025             "float16_t uint16BitsToFloat16(uint16_t);"
4026             "f16vec2   uint16BitsToFloat16(u16vec2);"
4027             "f16vec3   uint16BitsToFloat16(u16vec3);"
4028             "f16vec4   uint16BitsToFloat16(u16vec4);"
4029 
4030             "float16_t int16BitsToHalf(int16_t);"
4031             "f16vec2   int16BitsToHalf(i16vec2);"
4032             "f16vec3   int16BitsToHalf(i16vec3);"
4033             "f16vec4   int16BitsToHalf(i16vec4);"
4034 
4035             "float16_t uint16BitsToHalf(uint16_t);"
4036             "f16vec2   uint16BitsToHalf(u16vec2);"
4037             "f16vec3   uint16BitsToHalf(u16vec3);"
4038             "f16vec4   uint16BitsToHalf(u16vec4);"
4039 
4040             "int      packInt2x16(i16vec2);"
4041             "uint     packUint2x16(u16vec2);"
4042             "int64_t  packInt4x16(i16vec4);"
4043             "uint64_t packUint4x16(u16vec4);"
4044             "i16vec2  unpackInt2x16(int);"
4045             "u16vec2  unpackUint2x16(uint);"
4046             "i16vec4  unpackInt4x16(int64_t);"
4047             "u16vec4  unpackUint4x16(uint64_t);"
4048 
4049             "bvec2 lessThan(i16vec2, i16vec2);"
4050             "bvec3 lessThan(i16vec3, i16vec3);"
4051             "bvec4 lessThan(i16vec4, i16vec4);"
4052             "bvec2 lessThan(u16vec2, u16vec2);"
4053             "bvec3 lessThan(u16vec3, u16vec3);"
4054             "bvec4 lessThan(u16vec4, u16vec4);"
4055 
4056             "bvec2 lessThanEqual(i16vec2, i16vec2);"
4057             "bvec3 lessThanEqual(i16vec3, i16vec3);"
4058             "bvec4 lessThanEqual(i16vec4, i16vec4);"
4059             "bvec2 lessThanEqual(u16vec2, u16vec2);"
4060             "bvec3 lessThanEqual(u16vec3, u16vec3);"
4061             "bvec4 lessThanEqual(u16vec4, u16vec4);"
4062 
4063             "bvec2 greaterThan(i16vec2, i16vec2);"
4064             "bvec3 greaterThan(i16vec3, i16vec3);"
4065             "bvec4 greaterThan(i16vec4, i16vec4);"
4066             "bvec2 greaterThan(u16vec2, u16vec2);"
4067             "bvec3 greaterThan(u16vec3, u16vec3);"
4068             "bvec4 greaterThan(u16vec4, u16vec4);"
4069 
4070             "bvec2 greaterThanEqual(i16vec2, i16vec2);"
4071             "bvec3 greaterThanEqual(i16vec3, i16vec3);"
4072             "bvec4 greaterThanEqual(i16vec4, i16vec4);"
4073             "bvec2 greaterThanEqual(u16vec2, u16vec2);"
4074             "bvec3 greaterThanEqual(u16vec3, u16vec3);"
4075             "bvec4 greaterThanEqual(u16vec4, u16vec4);"
4076 
4077             "bvec2 equal(i16vec2, i16vec2);"
4078             "bvec3 equal(i16vec3, i16vec3);"
4079             "bvec4 equal(i16vec4, i16vec4);"
4080             "bvec2 equal(u16vec2, u16vec2);"
4081             "bvec3 equal(u16vec3, u16vec3);"
4082             "bvec4 equal(u16vec4, u16vec4);"
4083 
4084             "bvec2 notEqual(i16vec2, i16vec2);"
4085             "bvec3 notEqual(i16vec3, i16vec3);"
4086             "bvec4 notEqual(i16vec4, i16vec4);"
4087             "bvec2 notEqual(u16vec2, u16vec2);"
4088             "bvec3 notEqual(u16vec3, u16vec3);"
4089             "bvec4 notEqual(u16vec4, u16vec4);"
4090 
4091             "  int16_t bitfieldExtract(  int16_t, int16_t, int16_t);"
4092             "i16vec2 bitfieldExtract(i16vec2, int16_t, int16_t);"
4093             "i16vec3 bitfieldExtract(i16vec3, int16_t, int16_t);"
4094             "i16vec4 bitfieldExtract(i16vec4, int16_t, int16_t);"
4095 
4096             " uint16_t bitfieldExtract( uint16_t, int16_t, int16_t);"
4097             "u16vec2 bitfieldExtract(u16vec2, int16_t, int16_t);"
4098             "u16vec3 bitfieldExtract(u16vec3, int16_t, int16_t);"
4099             "u16vec4 bitfieldExtract(u16vec4, int16_t, int16_t);"
4100 
4101             "  int16_t bitfieldInsert(  int16_t base,   int16_t, int16_t, int16_t);"
4102             "i16vec2 bitfieldInsert(i16vec2 base, i16vec2, int16_t, int16_t);"
4103             "i16vec3 bitfieldInsert(i16vec3 base, i16vec3, int16_t, int16_t);"
4104             "i16vec4 bitfieldInsert(i16vec4 base, i16vec4, int16_t, int16_t);"
4105 
4106             " uint16_t bitfieldInsert( uint16_t base,  uint16_t, int16_t, int16_t);"
4107             "u16vec2 bitfieldInsert(u16vec2 base, u16vec2, int16_t, int16_t);"
4108             "u16vec3 bitfieldInsert(u16vec3 base, u16vec3, int16_t, int16_t);"
4109             "u16vec4 bitfieldInsert(u16vec4 base, u16vec4, int16_t, int16_t);"
4110 
4111             "  int16_t bitCount(  int16_t);"
4112             "i16vec2 bitCount(i16vec2);"
4113             "i16vec3 bitCount(i16vec3);"
4114             "i16vec4 bitCount(i16vec4);"
4115 
4116             "  int16_t bitCount( uint16_t);"
4117             "i16vec2 bitCount(u16vec2);"
4118             "i16vec3 bitCount(u16vec3);"
4119             "i16vec4 bitCount(u16vec4);"
4120 
4121             "  int16_t findLSB(  int16_t);"
4122             "i16vec2 findLSB(i16vec2);"
4123             "i16vec3 findLSB(i16vec3);"
4124             "i16vec4 findLSB(i16vec4);"
4125 
4126             "  int16_t findLSB( uint16_t);"
4127             "i16vec2 findLSB(u16vec2);"
4128             "i16vec3 findLSB(u16vec3);"
4129             "i16vec4 findLSB(u16vec4);"
4130 
4131             "  int16_t findMSB(  int16_t);"
4132             "i16vec2 findMSB(i16vec2);"
4133             "i16vec3 findMSB(i16vec3);"
4134             "i16vec4 findMSB(i16vec4);"
4135 
4136             "  int16_t findMSB( uint16_t);"
4137             "i16vec2 findMSB(u16vec2);"
4138             "i16vec3 findMSB(u16vec3);"
4139             "i16vec4 findMSB(u16vec4);"
4140 
4141             "int16_t  pack16(i8vec2);"
4142             "uint16_t pack16(u8vec2);"
4143             "int32_t  pack32(i8vec4);"
4144             "uint32_t pack32(u8vec4);"
4145             "int32_t  pack32(i16vec2);"
4146             "uint32_t pack32(u16vec2);"
4147             "int64_t  pack64(i16vec4);"
4148             "uint64_t pack64(u16vec4);"
4149             "int64_t  pack64(i32vec2);"
4150             "uint64_t pack64(u32vec2);"
4151 
4152             "i8vec2   unpack8(int16_t);"
4153             "u8vec2   unpack8(uint16_t);"
4154             "i8vec4   unpack8(int32_t);"
4155             "u8vec4   unpack8(uint32_t);"
4156             "i16vec2  unpack16(int32_t);"
4157             "u16vec2  unpack16(uint32_t);"
4158             "i16vec4  unpack16(int64_t);"
4159             "u16vec4  unpack16(uint64_t);"
4160             "i32vec2  unpack32(int64_t);"
4161             "u32vec2  unpack32(uint64_t);"
4162             "\n");
4163     }
4164 
4165     if (profile != EEsProfile && version >= 450) {
4166         stageBuiltins[EShLangFragment].append(derivativesAndControl64bits);
4167         stageBuiltins[EShLangFragment].append(
4168             "float64_t interpolateAtCentroid(float64_t);"
4169             "f64vec2   interpolateAtCentroid(f64vec2);"
4170             "f64vec3   interpolateAtCentroid(f64vec3);"
4171             "f64vec4   interpolateAtCentroid(f64vec4);"
4172 
4173             "float64_t interpolateAtSample(float64_t, int);"
4174             "f64vec2   interpolateAtSample(f64vec2,   int);"
4175             "f64vec3   interpolateAtSample(f64vec3,   int);"
4176             "f64vec4   interpolateAtSample(f64vec4,   int);"
4177 
4178             "float64_t interpolateAtOffset(float64_t, f64vec2);"
4179             "f64vec2   interpolateAtOffset(f64vec2,   f64vec2);"
4180             "f64vec3   interpolateAtOffset(f64vec3,   f64vec2);"
4181             "f64vec4   interpolateAtOffset(f64vec4,   f64vec2);"
4182 
4183             "\n");
4184 
4185     }
4186 #endif // !GLSLANG_ANGLE
4187 
4188     //============================================================================
4189     //
4190     // Prototypes for built-in functions seen by vertex shaders only.
4191     // (Except legacy lod functions, where it depends which release they are
4192     // vertex only.)
4193     //
4194     //============================================================================
4195 
4196     //
4197     // Geometric Functions.
4198     //
4199     if (spvVersion.vulkan == 0 && IncludeLegacy(version, profile, spvVersion))
4200         stageBuiltins[EShLangVertex].append("vec4 ftransform();");
4201 
4202 #ifndef GLSLANG_ANGLE
4203     //
4204     // Original-style texture Functions with lod.
4205     //
4206     TString* s;
4207     if (version == 100)
4208         s = &stageBuiltins[EShLangVertex];
4209     else
4210         s = &commonBuiltins;
4211     if ((profile == EEsProfile && version == 100) ||
4212          profile == ECompatibilityProfile ||
4213         (profile == ECoreProfile && version < 420) ||
4214          profile == ENoProfile) {
4215         if (spvVersion.spv == 0) {
4216             s->append(
4217                 "vec4 texture2DLod(sampler2D, vec2, float);"         // GL_ARB_shader_texture_lod
4218                 "vec4 texture2DProjLod(sampler2D, vec3, float);"     // GL_ARB_shader_texture_lod
4219                 "vec4 texture2DProjLod(sampler2D, vec4, float);"     // GL_ARB_shader_texture_lod
4220                 "vec4 texture3DLod(sampler3D, vec3, float);"         // GL_ARB_shader_texture_lod  // OES_texture_3D, but caught by keyword check
4221                 "vec4 texture3DProjLod(sampler3D, vec4, float);"     // GL_ARB_shader_texture_lod  // OES_texture_3D, but caught by keyword check
4222                 "vec4 textureCubeLod(samplerCube, vec3, float);"     // GL_ARB_shader_texture_lod
4223 
4224                 "\n");
4225         }
4226     }
4227     if ( profile == ECompatibilityProfile ||
4228         (profile == ECoreProfile && version < 420) ||
4229          profile == ENoProfile) {
4230         if (spvVersion.spv == 0) {
4231             s->append(
4232                 "vec4 texture1DLod(sampler1D, float, float);"                          // GL_ARB_shader_texture_lod
4233                 "vec4 texture1DProjLod(sampler1D, vec2, float);"                       // GL_ARB_shader_texture_lod
4234                 "vec4 texture1DProjLod(sampler1D, vec4, float);"                       // GL_ARB_shader_texture_lod
4235                 "vec4 shadow1DLod(sampler1DShadow, vec3, float);"                      // GL_ARB_shader_texture_lod
4236                 "vec4 shadow2DLod(sampler2DShadow, vec3, float);"                      // GL_ARB_shader_texture_lod
4237                 "vec4 shadow1DProjLod(sampler1DShadow, vec4, float);"                  // GL_ARB_shader_texture_lod
4238                 "vec4 shadow2DProjLod(sampler2DShadow, vec4, float);"                  // GL_ARB_shader_texture_lod
4239 
4240                 "vec4 texture1DGradARB(sampler1D, float, float, float);"               // GL_ARB_shader_texture_lod
4241                 "vec4 texture1DProjGradARB(sampler1D, vec2, float, float);"            // GL_ARB_shader_texture_lod
4242                 "vec4 texture1DProjGradARB(sampler1D, vec4, float, float);"            // GL_ARB_shader_texture_lod
4243                 "vec4 texture2DGradARB(sampler2D, vec2, vec2, vec2);"                  // GL_ARB_shader_texture_lod
4244                 "vec4 texture2DProjGradARB(sampler2D, vec3, vec2, vec2);"              // GL_ARB_shader_texture_lod
4245                 "vec4 texture2DProjGradARB(sampler2D, vec4, vec2, vec2);"              // GL_ARB_shader_texture_lod
4246                 "vec4 texture3DGradARB(sampler3D, vec3, vec3, vec3);"                  // GL_ARB_shader_texture_lod
4247                 "vec4 texture3DProjGradARB(sampler3D, vec4, vec3, vec3);"              // GL_ARB_shader_texture_lod
4248                 "vec4 textureCubeGradARB(samplerCube, vec3, vec3, vec3);"              // GL_ARB_shader_texture_lod
4249                 "vec4 shadow1DGradARB(sampler1DShadow, vec3, float, float);"           // GL_ARB_shader_texture_lod
4250                 "vec4 shadow1DProjGradARB( sampler1DShadow, vec4, float, float);"      // GL_ARB_shader_texture_lod
4251                 "vec4 shadow2DGradARB(sampler2DShadow, vec3, vec2, vec2);"             // GL_ARB_shader_texture_lod
4252                 "vec4 shadow2DProjGradARB( sampler2DShadow, vec4, vec2, vec2);"        // GL_ARB_shader_texture_lod
4253                 "vec4 texture2DRectGradARB(sampler2DRect, vec2, vec2, vec2);"          // GL_ARB_shader_texture_lod
4254                 "vec4 texture2DRectProjGradARB( sampler2DRect, vec3, vec2, vec2);"     // GL_ARB_shader_texture_lod
4255                 "vec4 texture2DRectProjGradARB( sampler2DRect, vec4, vec2, vec2);"     // GL_ARB_shader_texture_lod
4256                 "vec4 shadow2DRectGradARB( sampler2DRectShadow, vec3, vec2, vec2);"    // GL_ARB_shader_texture_lod
4257                 "vec4 shadow2DRectProjGradARB(sampler2DRectShadow, vec4, vec2, vec2);" // GL_ARB_shader_texture_lod
4258 
4259                 "\n");
4260         }
4261     }
4262 #endif // !GLSLANG_ANGLE
4263 
4264     if ((profile != EEsProfile && version >= 150) ||
4265         (profile == EEsProfile && version >= 310)) {
4266         //============================================================================
4267         //
4268         // Prototypes for built-in functions seen by geometry shaders only.
4269         //
4270         //============================================================================
4271 
4272         if (profile != EEsProfile && version >= 400) {
4273             stageBuiltins[EShLangGeometry].append(
4274                 "void EmitStreamVertex(int);"
4275                 "void EndStreamPrimitive(int);"
4276                 );
4277         }
4278         stageBuiltins[EShLangGeometry].append(
4279             "void EmitVertex();"
4280             "void EndPrimitive();"
4281             "\n");
4282     }
4283 #endif // !GLSLANG_WEB
4284 
4285     //============================================================================
4286     //
4287     // Prototypes for all control functions.
4288     //
4289     //============================================================================
4290     bool esBarrier = (profile == EEsProfile && version >= 310);
4291     if ((profile != EEsProfile && version >= 150) || esBarrier)
4292         stageBuiltins[EShLangTessControl].append(
4293             "void barrier();"
4294             );
4295     if ((profile != EEsProfile && version >= 420) || esBarrier)
4296         stageBuiltins[EShLangCompute].append(
4297             "void barrier();"
4298             );
4299     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
4300         stageBuiltins[EShLangMeshNV].append(
4301             "void barrier();"
4302             );
4303         stageBuiltins[EShLangTaskNV].append(
4304             "void barrier();"
4305             );
4306     }
4307     if ((profile != EEsProfile && version >= 130) || esBarrier)
4308         commonBuiltins.append(
4309             "void memoryBarrier();"
4310             );
4311     if ((profile != EEsProfile && version >= 420) || esBarrier) {
4312         commonBuiltins.append(
4313             "void memoryBarrierBuffer();"
4314             );
4315         stageBuiltins[EShLangCompute].append(
4316             "void memoryBarrierShared();"
4317             "void groupMemoryBarrier();"
4318             );
4319     }
4320 #ifndef GLSLANG_WEB
4321     if ((profile != EEsProfile && version >= 420) || esBarrier) {
4322         if (spvVersion.vulkan == 0 || spvVersion.vulkanRelaxed) {
4323             commonBuiltins.append("void memoryBarrierAtomicCounter();");
4324         }
4325         commonBuiltins.append("void memoryBarrierImage();");
4326     }
4327     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
4328         stageBuiltins[EShLangMeshNV].append(
4329             "void memoryBarrierShared();"
4330             "void groupMemoryBarrier();"
4331         );
4332         stageBuiltins[EShLangTaskNV].append(
4333             "void memoryBarrierShared();"
4334             "void groupMemoryBarrier();"
4335         );
4336     }
4337 
4338     commonBuiltins.append("void controlBarrier(int, int, int, int);\n"
4339                           "void memoryBarrier(int, int, int);\n");
4340 
4341     commonBuiltins.append("void debugPrintfEXT();\n");
4342 
4343 #ifndef GLSLANG_ANGLE
4344     if (profile != EEsProfile && version >= 450) {
4345         // coopMatStoreNV perhaps ought to have "out" on the buf parameter, but
4346         // adding it introduces undesirable tempArgs on the stack. What we want
4347         // is more like "buf" thought of as a pointer value being an in parameter.
4348         stageBuiltins[EShLangCompute].append(
4349             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent float16_t[] buf, uint element, uint stride, bool colMajor);\n"
4350             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent float[] buf, uint element, uint stride, bool colMajor);\n"
4351             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
4352             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
4353             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
4354             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
4355             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
4356             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
4357 
4358             "void coopMatStoreNV(fcoopmatNV m, volatile coherent float16_t[] buf, uint element, uint stride, bool colMajor);\n"
4359             "void coopMatStoreNV(fcoopmatNV m, volatile coherent float[] buf, uint element, uint stride, bool colMajor);\n"
4360             "void coopMatStoreNV(fcoopmatNV m, volatile coherent float64_t[] buf, uint element, uint stride, bool colMajor);\n"
4361             "void coopMatStoreNV(fcoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
4362             "void coopMatStoreNV(fcoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
4363             "void coopMatStoreNV(fcoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
4364             "void coopMatStoreNV(fcoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
4365             "void coopMatStoreNV(fcoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
4366             "void coopMatStoreNV(fcoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
4367 
4368             "fcoopmatNV coopMatMulAddNV(fcoopmatNV A, fcoopmatNV B, fcoopmatNV C);\n"
4369             "void coopMatLoadNV(out icoopmatNV m, volatile coherent int8_t[] buf, uint element, uint stride, bool colMajor);\n"
4370             "void coopMatLoadNV(out icoopmatNV m, volatile coherent int16_t[] buf, uint element, uint stride, bool colMajor);\n"
4371             "void coopMatLoadNV(out icoopmatNV m, volatile coherent int[] buf, uint element, uint stride, bool colMajor);\n"
4372             "void coopMatLoadNV(out icoopmatNV m, volatile coherent int64_t[] buf, uint element, uint stride, bool colMajor);\n"
4373             "void coopMatLoadNV(out icoopmatNV m, volatile coherent ivec2[] buf, uint element, uint stride, bool colMajor);\n"
4374             "void coopMatLoadNV(out icoopmatNV m, volatile coherent ivec4[] buf, uint element, uint stride, bool colMajor);\n"
4375             "void coopMatLoadNV(out icoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
4376             "void coopMatLoadNV(out icoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
4377             "void coopMatLoadNV(out icoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
4378             "void coopMatLoadNV(out icoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
4379             "void coopMatLoadNV(out icoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
4380             "void coopMatLoadNV(out icoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
4381 
4382             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent int8_t[] buf, uint element, uint stride, bool colMajor);\n"
4383             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent int16_t[] buf, uint element, uint stride, bool colMajor);\n"
4384             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent int[] buf, uint element, uint stride, bool colMajor);\n"
4385             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent int64_t[] buf, uint element, uint stride, bool colMajor);\n"
4386             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent ivec2[] buf, uint element, uint stride, bool colMajor);\n"
4387             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent ivec4[] buf, uint element, uint stride, bool colMajor);\n"
4388             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
4389             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
4390             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
4391             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
4392             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
4393             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
4394 
4395             "void coopMatStoreNV(icoopmatNV m, volatile coherent int8_t[] buf, uint element, uint stride, bool colMajor);\n"
4396             "void coopMatStoreNV(icoopmatNV m, volatile coherent int16_t[] buf, uint element, uint stride, bool colMajor);\n"
4397             "void coopMatStoreNV(icoopmatNV m, volatile coherent int[] buf, uint element, uint stride, bool colMajor);\n"
4398             "void coopMatStoreNV(icoopmatNV m, volatile coherent int64_t[] buf, uint element, uint stride, bool colMajor);\n"
4399             "void coopMatStoreNV(icoopmatNV m, volatile coherent ivec2[] buf, uint element, uint stride, bool colMajor);\n"
4400             "void coopMatStoreNV(icoopmatNV m, volatile coherent ivec4[] buf, uint element, uint stride, bool colMajor);\n"
4401             "void coopMatStoreNV(icoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
4402             "void coopMatStoreNV(icoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
4403             "void coopMatStoreNV(icoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
4404             "void coopMatStoreNV(icoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
4405             "void coopMatStoreNV(icoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
4406             "void coopMatStoreNV(icoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
4407 
4408             "void coopMatStoreNV(ucoopmatNV m, volatile coherent int8_t[] buf, uint element, uint stride, bool colMajor);\n"
4409             "void coopMatStoreNV(ucoopmatNV m, volatile coherent int16_t[] buf, uint element, uint stride, bool colMajor);\n"
4410             "void coopMatStoreNV(ucoopmatNV m, volatile coherent int[] buf, uint element, uint stride, bool colMajor);\n"
4411             "void coopMatStoreNV(ucoopmatNV m, volatile coherent int64_t[] buf, uint element, uint stride, bool colMajor);\n"
4412             "void coopMatStoreNV(ucoopmatNV m, volatile coherent ivec2[] buf, uint element, uint stride, bool colMajor);\n"
4413             "void coopMatStoreNV(ucoopmatNV m, volatile coherent ivec4[] buf, uint element, uint stride, bool colMajor);\n"
4414             "void coopMatStoreNV(ucoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
4415             "void coopMatStoreNV(ucoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
4416             "void coopMatStoreNV(ucoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
4417             "void coopMatStoreNV(ucoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
4418             "void coopMatStoreNV(ucoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
4419             "void coopMatStoreNV(ucoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
4420 
4421             "icoopmatNV coopMatMulAddNV(icoopmatNV A, icoopmatNV B, icoopmatNV C);\n"
4422             "ucoopmatNV coopMatMulAddNV(ucoopmatNV A, ucoopmatNV B, ucoopmatNV C);\n"
4423             );
4424     }
4425 
4426     //============================================================================
4427     //
4428     // Prototypes for built-in functions seen by fragment shaders only.
4429     //
4430     //============================================================================
4431 
4432     //
4433     // Original-style texture Functions with bias.
4434     //
4435     if (spvVersion.spv == 0 && (profile != EEsProfile || version == 100)) {
4436         stageBuiltins[EShLangFragment].append(
4437             "vec4 texture2D(sampler2D, vec2, float);"
4438             "vec4 texture2DProj(sampler2D, vec3, float);"
4439             "vec4 texture2DProj(sampler2D, vec4, float);"
4440             "vec4 texture3D(sampler3D, vec3, float);"        // OES_texture_3D
4441             "vec4 texture3DProj(sampler3D, vec4, float);"    // OES_texture_3D
4442             "vec4 textureCube(samplerCube, vec3, float);"
4443 
4444             "\n");
4445     }
4446     if (spvVersion.spv == 0 && (profile != EEsProfile && version > 100)) {
4447         stageBuiltins[EShLangFragment].append(
4448             "vec4 texture1D(sampler1D, float, float);"
4449             "vec4 texture1DProj(sampler1D, vec2, float);"
4450             "vec4 texture1DProj(sampler1D, vec4, float);"
4451             "vec4 shadow1D(sampler1DShadow, vec3, float);"
4452             "vec4 shadow2D(sampler2DShadow, vec3, float);"
4453             "vec4 shadow1DProj(sampler1DShadow, vec4, float);"
4454             "vec4 shadow2DProj(sampler2DShadow, vec4, float);"
4455 
4456             "\n");
4457     }
4458     if (spvVersion.spv == 0 && profile == EEsProfile) {
4459         stageBuiltins[EShLangFragment].append(
4460             "vec4 texture2DLodEXT(sampler2D, vec2, float);"      // GL_EXT_shader_texture_lod
4461             "vec4 texture2DProjLodEXT(sampler2D, vec3, float);"  // GL_EXT_shader_texture_lod
4462             "vec4 texture2DProjLodEXT(sampler2D, vec4, float);"  // GL_EXT_shader_texture_lod
4463             "vec4 textureCubeLodEXT(samplerCube, vec3, float);"  // GL_EXT_shader_texture_lod
4464 
4465             "\n");
4466     }
4467 #endif // !GLSLANG_ANGLE
4468 
4469     // GL_ARB_derivative_control
4470     if (profile != EEsProfile && version >= 400) {
4471         stageBuiltins[EShLangFragment].append(derivativeControls);
4472         stageBuiltins[EShLangFragment].append("\n");
4473     }
4474 
4475     // GL_OES_shader_multisample_interpolation
4476     if ((profile == EEsProfile && version >= 310) ||
4477         (profile != EEsProfile && version >= 400)) {
4478         stageBuiltins[EShLangFragment].append(
4479             "float interpolateAtCentroid(float);"
4480             "vec2  interpolateAtCentroid(vec2);"
4481             "vec3  interpolateAtCentroid(vec3);"
4482             "vec4  interpolateAtCentroid(vec4);"
4483 
4484             "float interpolateAtSample(float, int);"
4485             "vec2  interpolateAtSample(vec2,  int);"
4486             "vec3  interpolateAtSample(vec3,  int);"
4487             "vec4  interpolateAtSample(vec4,  int);"
4488 
4489             "float interpolateAtOffset(float, vec2);"
4490             "vec2  interpolateAtOffset(vec2,  vec2);"
4491             "vec3  interpolateAtOffset(vec3,  vec2);"
4492             "vec4  interpolateAtOffset(vec4,  vec2);"
4493 
4494             "\n");
4495     }
4496 
4497     stageBuiltins[EShLangFragment].append(
4498         "void beginInvocationInterlockARB(void);"
4499         "void endInvocationInterlockARB(void);");
4500 
4501     stageBuiltins[EShLangFragment].append(
4502         "bool helperInvocationEXT();"
4503         "\n");
4504 
4505 #ifndef GLSLANG_ANGLE
4506     // GL_AMD_shader_explicit_vertex_parameter
4507     if (profile != EEsProfile && version >= 450) {
4508         stageBuiltins[EShLangFragment].append(
4509             "float interpolateAtVertexAMD(float, uint);"
4510             "vec2  interpolateAtVertexAMD(vec2,  uint);"
4511             "vec3  interpolateAtVertexAMD(vec3,  uint);"
4512             "vec4  interpolateAtVertexAMD(vec4,  uint);"
4513 
4514             "int   interpolateAtVertexAMD(int,   uint);"
4515             "ivec2 interpolateAtVertexAMD(ivec2, uint);"
4516             "ivec3 interpolateAtVertexAMD(ivec3, uint);"
4517             "ivec4 interpolateAtVertexAMD(ivec4, uint);"
4518 
4519             "uint  interpolateAtVertexAMD(uint,  uint);"
4520             "uvec2 interpolateAtVertexAMD(uvec2, uint);"
4521             "uvec3 interpolateAtVertexAMD(uvec3, uint);"
4522             "uvec4 interpolateAtVertexAMD(uvec4, uint);"
4523 
4524             "float16_t interpolateAtVertexAMD(float16_t, uint);"
4525             "f16vec2   interpolateAtVertexAMD(f16vec2,   uint);"
4526             "f16vec3   interpolateAtVertexAMD(f16vec3,   uint);"
4527             "f16vec4   interpolateAtVertexAMD(f16vec4,   uint);"
4528 
4529             "\n");
4530     }
4531 
4532     // GL_AMD_gpu_shader_half_float
4533     if (profile != EEsProfile && version >= 450) {
4534         stageBuiltins[EShLangFragment].append(derivativesAndControl16bits);
4535         stageBuiltins[EShLangFragment].append("\n");
4536 
4537         stageBuiltins[EShLangFragment].append(
4538             "float16_t interpolateAtCentroid(float16_t);"
4539             "f16vec2   interpolateAtCentroid(f16vec2);"
4540             "f16vec3   interpolateAtCentroid(f16vec3);"
4541             "f16vec4   interpolateAtCentroid(f16vec4);"
4542 
4543             "float16_t interpolateAtSample(float16_t, int);"
4544             "f16vec2   interpolateAtSample(f16vec2,   int);"
4545             "f16vec3   interpolateAtSample(f16vec3,   int);"
4546             "f16vec4   interpolateAtSample(f16vec4,   int);"
4547 
4548             "float16_t interpolateAtOffset(float16_t, f16vec2);"
4549             "f16vec2   interpolateAtOffset(f16vec2,   f16vec2);"
4550             "f16vec3   interpolateAtOffset(f16vec3,   f16vec2);"
4551             "f16vec4   interpolateAtOffset(f16vec4,   f16vec2);"
4552 
4553             "\n");
4554     }
4555 
4556     // GL_ARB_shader_clock& GL_EXT_shader_realtime_clock
4557     if (profile != EEsProfile && version >= 450) {
4558         commonBuiltins.append(
4559             "uvec2 clock2x32ARB();"
4560             "uint64_t clockARB();"
4561             "uvec2 clockRealtime2x32EXT();"
4562             "uint64_t clockRealtimeEXT();"
4563             "\n");
4564     }
4565 
4566     // GL_AMD_shader_fragment_mask
4567     if (profile != EEsProfile && version >= 450 && spvVersion.vulkan > 0) {
4568         stageBuiltins[EShLangFragment].append(
4569             "uint fragmentMaskFetchAMD(subpassInputMS);"
4570             "uint fragmentMaskFetchAMD(isubpassInputMS);"
4571             "uint fragmentMaskFetchAMD(usubpassInputMS);"
4572 
4573             "vec4  fragmentFetchAMD(subpassInputMS,  uint);"
4574             "ivec4 fragmentFetchAMD(isubpassInputMS, uint);"
4575             "uvec4 fragmentFetchAMD(usubpassInputMS, uint);"
4576 
4577             "\n");
4578         }
4579 
4580     // Builtins for GL_NV_ray_tracing/GL_NV_ray_tracing_motion_blur/GL_EXT_ray_tracing/GL_EXT_ray_query
4581     if (profile != EEsProfile && version >= 460) {
4582          commonBuiltins.append("void rayQueryInitializeEXT(rayQueryEXT, accelerationStructureEXT, uint, uint, vec3, float, vec3, float);"
4583             "void rayQueryTerminateEXT(rayQueryEXT);"
4584             "void rayQueryGenerateIntersectionEXT(rayQueryEXT, float);"
4585             "void rayQueryConfirmIntersectionEXT(rayQueryEXT);"
4586             "bool rayQueryProceedEXT(rayQueryEXT);"
4587             "uint rayQueryGetIntersectionTypeEXT(rayQueryEXT, bool);"
4588             "float rayQueryGetRayTMinEXT(rayQueryEXT);"
4589             "uint rayQueryGetRayFlagsEXT(rayQueryEXT);"
4590             "vec3 rayQueryGetWorldRayOriginEXT(rayQueryEXT);"
4591             "vec3 rayQueryGetWorldRayDirectionEXT(rayQueryEXT);"
4592             "float rayQueryGetIntersectionTEXT(rayQueryEXT, bool);"
4593             "int rayQueryGetIntersectionInstanceCustomIndexEXT(rayQueryEXT, bool);"
4594             "int rayQueryGetIntersectionInstanceIdEXT(rayQueryEXT, bool);"
4595             "uint rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT(rayQueryEXT, bool);"
4596             "int rayQueryGetIntersectionGeometryIndexEXT(rayQueryEXT, bool);"
4597             "int rayQueryGetIntersectionPrimitiveIndexEXT(rayQueryEXT, bool);"
4598             "vec2 rayQueryGetIntersectionBarycentricsEXT(rayQueryEXT, bool);"
4599             "bool rayQueryGetIntersectionFrontFaceEXT(rayQueryEXT, bool);"
4600             "bool rayQueryGetIntersectionCandidateAABBOpaqueEXT(rayQueryEXT);"
4601             "vec3 rayQueryGetIntersectionObjectRayDirectionEXT(rayQueryEXT, bool);"
4602             "vec3 rayQueryGetIntersectionObjectRayOriginEXT(rayQueryEXT, bool);"
4603             "mat4x3 rayQueryGetIntersectionObjectToWorldEXT(rayQueryEXT, bool);"
4604             "mat4x3 rayQueryGetIntersectionWorldToObjectEXT(rayQueryEXT, bool);"
4605             "\n");
4606 
4607         stageBuiltins[EShLangRayGen].append(
4608             "void traceNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4609             "void traceRayMotionNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,float,int);"
4610             "void traceRayEXT(accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4611             "void executeCallableNV(uint, int);"
4612             "void executeCallableEXT(uint, int);"
4613             "\n");
4614         stageBuiltins[EShLangIntersect].append(
4615             "bool reportIntersectionNV(float, uint);"
4616             "bool reportIntersectionEXT(float, uint);"
4617             "\n");
4618         stageBuiltins[EShLangAnyHit].append(
4619             "void ignoreIntersectionNV();"
4620             "void terminateRayNV();"
4621             "\n");
4622         stageBuiltins[EShLangClosestHit].append(
4623             "void traceNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4624             "void traceRayMotionNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,float,int);"
4625             "void traceRayEXT(accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4626             "void executeCallableNV(uint, int);"
4627             "void executeCallableEXT(uint, int);"
4628             "\n");
4629         stageBuiltins[EShLangMiss].append(
4630             "void traceNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4631             "void traceRayMotionNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,float,int);"
4632             "void traceRayEXT(accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4633             "void executeCallableNV(uint, int);"
4634             "void executeCallableEXT(uint, int);"
4635             "\n");
4636         stageBuiltins[EShLangCallable].append(
4637             "void executeCallableNV(uint, int);"
4638             "void executeCallableEXT(uint, int);"
4639             "\n");
4640     }
4641 #endif // !GLSLANG_ANGLE
4642 
4643     //E_SPV_NV_compute_shader_derivatives
4644     if ((profile == EEsProfile && version >= 320) || (profile != EEsProfile && version >= 450)) {
4645         stageBuiltins[EShLangCompute].append(derivativeControls);
4646         stageBuiltins[EShLangCompute].append("\n");
4647     }
4648 #ifndef GLSLANG_ANGLE
4649     if (profile != EEsProfile && version >= 450) {
4650         stageBuiltins[EShLangCompute].append(derivativesAndControl16bits);
4651         stageBuiltins[EShLangCompute].append(derivativesAndControl64bits);
4652         stageBuiltins[EShLangCompute].append("\n");
4653     }
4654 
4655     // Builtins for GL_NV_mesh_shader
4656     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
4657         stageBuiltins[EShLangMeshNV].append(
4658             "void writePackedPrimitiveIndices4x8NV(uint, uint);"
4659             "\n");
4660     }
4661 #endif // !GLSLANG_ANGLE
4662 #endif // !GLSLANG_WEB
4663 
4664     //============================================================================
4665     //
4666     // Standard Uniforms
4667     //
4668     //============================================================================
4669 
4670     //
4671     // Depth range in window coordinates, p. 33
4672     //
4673     if (spvVersion.spv == 0) {
4674         commonBuiltins.append(
4675             "struct gl_DepthRangeParameters {"
4676             );
4677         if (profile == EEsProfile) {
4678             commonBuiltins.append(
4679                 "highp float near;"   // n
4680                 "highp float far;"    // f
4681                 "highp float diff;"   // f - n
4682                 );
4683         } else {
4684 #ifndef GLSLANG_WEB
4685             commonBuiltins.append(
4686                 "float near;"  // n
4687                 "float far;"   // f
4688                 "float diff;"  // f - n
4689                 );
4690 #endif
4691         }
4692 
4693         commonBuiltins.append(
4694             "};"
4695             "uniform gl_DepthRangeParameters gl_DepthRange;"
4696             "\n");
4697     }
4698 
4699 #if !defined(GLSLANG_WEB) && !defined(GLSLANG_ANGLE)
4700     if (spvVersion.spv == 0 && IncludeLegacy(version, profile, spvVersion)) {
4701         //
4702         // Matrix state. p. 31, 32, 37, 39, 40.
4703         //
4704         commonBuiltins.append(
4705             "uniform mat4  gl_ModelViewMatrix;"
4706             "uniform mat4  gl_ProjectionMatrix;"
4707             "uniform mat4  gl_ModelViewProjectionMatrix;"
4708 
4709             //
4710             // Derived matrix state that provides inverse and transposed versions
4711             // of the matrices above.
4712             //
4713             "uniform mat3  gl_NormalMatrix;"
4714 
4715             "uniform mat4  gl_ModelViewMatrixInverse;"
4716             "uniform mat4  gl_ProjectionMatrixInverse;"
4717             "uniform mat4  gl_ModelViewProjectionMatrixInverse;"
4718 
4719             "uniform mat4  gl_ModelViewMatrixTranspose;"
4720             "uniform mat4  gl_ProjectionMatrixTranspose;"
4721             "uniform mat4  gl_ModelViewProjectionMatrixTranspose;"
4722 
4723             "uniform mat4  gl_ModelViewMatrixInverseTranspose;"
4724             "uniform mat4  gl_ProjectionMatrixInverseTranspose;"
4725             "uniform mat4  gl_ModelViewProjectionMatrixInverseTranspose;"
4726 
4727             //
4728             // Normal scaling p. 39.
4729             //
4730             "uniform float gl_NormalScale;"
4731 
4732             //
4733             // Point Size, p. 66, 67.
4734             //
4735             "struct gl_PointParameters {"
4736                 "float size;"
4737                 "float sizeMin;"
4738                 "float sizeMax;"
4739                 "float fadeThresholdSize;"
4740                 "float distanceConstantAttenuation;"
4741                 "float distanceLinearAttenuation;"
4742                 "float distanceQuadraticAttenuation;"
4743             "};"
4744 
4745             "uniform gl_PointParameters gl_Point;"
4746 
4747             //
4748             // Material State p. 50, 55.
4749             //
4750             "struct gl_MaterialParameters {"
4751                 "vec4  emission;"    // Ecm
4752                 "vec4  ambient;"     // Acm
4753                 "vec4  diffuse;"     // Dcm
4754                 "vec4  specular;"    // Scm
4755                 "float shininess;"   // Srm
4756             "};"
4757             "uniform gl_MaterialParameters  gl_FrontMaterial;"
4758             "uniform gl_MaterialParameters  gl_BackMaterial;"
4759 
4760             //
4761             // Light State p 50, 53, 55.
4762             //
4763             "struct gl_LightSourceParameters {"
4764                 "vec4  ambient;"             // Acli
4765                 "vec4  diffuse;"             // Dcli
4766                 "vec4  specular;"            // Scli
4767                 "vec4  position;"            // Ppli
4768                 "vec4  halfVector;"          // Derived: Hi
4769                 "vec3  spotDirection;"       // Sdli
4770                 "float spotExponent;"        // Srli
4771                 "float spotCutoff;"          // Crli
4772                                                         // (range: [0.0,90.0], 180.0)
4773                 "float spotCosCutoff;"       // Derived: cos(Crli)
4774                                                         // (range: [1.0,0.0],-1.0)
4775                 "float constantAttenuation;" // K0
4776                 "float linearAttenuation;"   // K1
4777                 "float quadraticAttenuation;"// K2
4778             "};"
4779 
4780             "struct gl_LightModelParameters {"
4781                 "vec4  ambient;"       // Acs
4782             "};"
4783 
4784             "uniform gl_LightModelParameters  gl_LightModel;"
4785 
4786             //
4787             // Derived state from products of light and material.
4788             //
4789             "struct gl_LightModelProducts {"
4790                 "vec4  sceneColor;"     // Derived. Ecm + Acm * Acs
4791             "};"
4792 
4793             "uniform gl_LightModelProducts gl_FrontLightModelProduct;"
4794             "uniform gl_LightModelProducts gl_BackLightModelProduct;"
4795 
4796             "struct gl_LightProducts {"
4797                 "vec4  ambient;"        // Acm * Acli
4798                 "vec4  diffuse;"        // Dcm * Dcli
4799                 "vec4  specular;"       // Scm * Scli
4800             "};"
4801 
4802             //
4803             // Fog p. 161
4804             //
4805             "struct gl_FogParameters {"
4806                 "vec4  color;"
4807                 "float density;"
4808                 "float start;"
4809                 "float end;"
4810                 "float scale;"   //  1 / (gl_FogEnd - gl_FogStart)
4811             "};"
4812 
4813             "uniform gl_FogParameters gl_Fog;"
4814 
4815             "\n");
4816     }
4817 #endif // !GLSLANG_WEB && !GLSLANG_ANGLE
4818 
4819     //============================================================================
4820     //
4821     // Define the interface to the compute shader.
4822     //
4823     //============================================================================
4824 
4825     if ((profile != EEsProfile && version >= 420) ||
4826         (profile == EEsProfile && version >= 310)) {
4827         stageBuiltins[EShLangCompute].append(
4828             "in    highp uvec3 gl_NumWorkGroups;"
4829             "const highp uvec3 gl_WorkGroupSize = uvec3(1,1,1);"
4830 
4831             "in highp uvec3 gl_WorkGroupID;"
4832             "in highp uvec3 gl_LocalInvocationID;"
4833 
4834             "in highp uvec3 gl_GlobalInvocationID;"
4835             "in highp uint gl_LocalInvocationIndex;"
4836 
4837             "\n");
4838     }
4839 
4840     if ((profile != EEsProfile && version >= 140) ||
4841         (profile == EEsProfile && version >= 310)) {
4842         stageBuiltins[EShLangCompute].append(
4843             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
4844             "\n");
4845     }
4846 
4847 #ifndef GLSLANG_WEB
4848 #ifndef GLSLANG_ANGLE
4849     //============================================================================
4850     //
4851     // Define the interface to the mesh/task shader.
4852     //
4853     //============================================================================
4854 
4855     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
4856         // per-vertex attributes
4857         stageBuiltins[EShLangMeshNV].append(
4858             "out gl_MeshPerVertexNV {"
4859                 "vec4 gl_Position;"
4860                 "float gl_PointSize;"
4861                 "float gl_ClipDistance[];"
4862                 "float gl_CullDistance[];"
4863                 "perviewNV vec4 gl_PositionPerViewNV[];"
4864                 "perviewNV float gl_ClipDistancePerViewNV[][];"
4865                 "perviewNV float gl_CullDistancePerViewNV[][];"
4866             "} gl_MeshVerticesNV[];"
4867         );
4868 
4869         // per-primitive attributes
4870         stageBuiltins[EShLangMeshNV].append(
4871             "perprimitiveNV out gl_MeshPerPrimitiveNV {"
4872                 "int gl_PrimitiveID;"
4873                 "int gl_Layer;"
4874                 "int gl_ViewportIndex;"
4875                 "int gl_ViewportMask[];"
4876                 "perviewNV int gl_LayerPerViewNV[];"
4877                 "perviewNV int gl_ViewportMaskPerViewNV[][];"
4878             "} gl_MeshPrimitivesNV[];"
4879         );
4880 
4881         stageBuiltins[EShLangMeshNV].append(
4882             "out uint gl_PrimitiveCountNV;"
4883             "out uint gl_PrimitiveIndicesNV[];"
4884 
4885             "in uint gl_MeshViewCountNV;"
4886             "in uint gl_MeshViewIndicesNV[4];"
4887 
4888             "const highp uvec3 gl_WorkGroupSize = uvec3(1,1,1);"
4889 
4890             "in highp uvec3 gl_WorkGroupID;"
4891             "in highp uvec3 gl_LocalInvocationID;"
4892 
4893             "in highp uvec3 gl_GlobalInvocationID;"
4894             "in highp uint gl_LocalInvocationIndex;"
4895 
4896             "\n");
4897 
4898         stageBuiltins[EShLangTaskNV].append(
4899             "out uint gl_TaskCountNV;"
4900 
4901             "const highp uvec3 gl_WorkGroupSize = uvec3(1,1,1);"
4902 
4903             "in highp uvec3 gl_WorkGroupID;"
4904             "in highp uvec3 gl_LocalInvocationID;"
4905 
4906             "in highp uvec3 gl_GlobalInvocationID;"
4907             "in highp uint gl_LocalInvocationIndex;"
4908 
4909             "in uint gl_MeshViewCountNV;"
4910             "in uint gl_MeshViewIndicesNV[4];"
4911 
4912             "\n");
4913     }
4914 
4915     if (profile != EEsProfile && version >= 450) {
4916         stageBuiltins[EShLangMeshNV].append(
4917             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
4918             "in int gl_DrawIDARB;"             // GL_ARB_shader_draw_parameters
4919             "\n");
4920 
4921         stageBuiltins[EShLangTaskNV].append(
4922             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
4923             "in int gl_DrawIDARB;"             // GL_ARB_shader_draw_parameters
4924             "\n");
4925 
4926         if (version >= 460) {
4927             stageBuiltins[EShLangMeshNV].append(
4928                 "in int gl_DrawID;"
4929                 "\n");
4930 
4931             stageBuiltins[EShLangTaskNV].append(
4932                 "in int gl_DrawID;"
4933                 "\n");
4934         }
4935     }
4936 #endif // !GLSLANG_ANGLE
4937 
4938     //============================================================================
4939     //
4940     // Define the interface to the vertex shader.
4941     //
4942     //============================================================================
4943 
4944     if (profile != EEsProfile) {
4945         if (version < 130) {
4946             stageBuiltins[EShLangVertex].append(
4947                 "attribute vec4  gl_Color;"
4948                 "attribute vec4  gl_SecondaryColor;"
4949                 "attribute vec3  gl_Normal;"
4950                 "attribute vec4  gl_Vertex;"
4951                 "attribute vec4  gl_MultiTexCoord0;"
4952                 "attribute vec4  gl_MultiTexCoord1;"
4953                 "attribute vec4  gl_MultiTexCoord2;"
4954                 "attribute vec4  gl_MultiTexCoord3;"
4955                 "attribute vec4  gl_MultiTexCoord4;"
4956                 "attribute vec4  gl_MultiTexCoord5;"
4957                 "attribute vec4  gl_MultiTexCoord6;"
4958                 "attribute vec4  gl_MultiTexCoord7;"
4959                 "attribute float gl_FogCoord;"
4960                 "\n");
4961         } else if (IncludeLegacy(version, profile, spvVersion)) {
4962             stageBuiltins[EShLangVertex].append(
4963                 "in vec4  gl_Color;"
4964                 "in vec4  gl_SecondaryColor;"
4965                 "in vec3  gl_Normal;"
4966                 "in vec4  gl_Vertex;"
4967                 "in vec4  gl_MultiTexCoord0;"
4968                 "in vec4  gl_MultiTexCoord1;"
4969                 "in vec4  gl_MultiTexCoord2;"
4970                 "in vec4  gl_MultiTexCoord3;"
4971                 "in vec4  gl_MultiTexCoord4;"
4972                 "in vec4  gl_MultiTexCoord5;"
4973                 "in vec4  gl_MultiTexCoord6;"
4974                 "in vec4  gl_MultiTexCoord7;"
4975                 "in float gl_FogCoord;"
4976                 "\n");
4977         }
4978 
4979         if (version < 150) {
4980             if (version < 130) {
4981                 stageBuiltins[EShLangVertex].append(
4982                     "        vec4  gl_ClipVertex;"       // needs qualifier fixed later
4983                     "varying vec4  gl_FrontColor;"
4984                     "varying vec4  gl_BackColor;"
4985                     "varying vec4  gl_FrontSecondaryColor;"
4986                     "varying vec4  gl_BackSecondaryColor;"
4987                     "varying vec4  gl_TexCoord[];"
4988                     "varying float gl_FogFragCoord;"
4989                     "\n");
4990             } else if (IncludeLegacy(version, profile, spvVersion)) {
4991                 stageBuiltins[EShLangVertex].append(
4992                     "    vec4  gl_ClipVertex;"       // needs qualifier fixed later
4993                     "out vec4  gl_FrontColor;"
4994                     "out vec4  gl_BackColor;"
4995                     "out vec4  gl_FrontSecondaryColor;"
4996                     "out vec4  gl_BackSecondaryColor;"
4997                     "out vec4  gl_TexCoord[];"
4998                     "out float gl_FogFragCoord;"
4999                     "\n");
5000             }
5001             stageBuiltins[EShLangVertex].append(
5002                 "vec4 gl_Position;"   // needs qualifier fixed later
5003                 "float gl_PointSize;" // needs qualifier fixed later
5004                 );
5005 
5006             if (version == 130 || version == 140)
5007                 stageBuiltins[EShLangVertex].append(
5008                     "out float gl_ClipDistance[];"
5009                     );
5010         } else {
5011             // version >= 150
5012             stageBuiltins[EShLangVertex].append(
5013                 "out gl_PerVertex {"
5014                     "vec4 gl_Position;"     // needs qualifier fixed later
5015                     "float gl_PointSize;"   // needs qualifier fixed later
5016                     "float gl_ClipDistance[];"
5017                     );
5018             if (IncludeLegacy(version, profile, spvVersion))
5019                 stageBuiltins[EShLangVertex].append(
5020                     "vec4 gl_ClipVertex;"   // needs qualifier fixed later
5021                     "vec4 gl_FrontColor;"
5022                     "vec4 gl_BackColor;"
5023                     "vec4 gl_FrontSecondaryColor;"
5024                     "vec4 gl_BackSecondaryColor;"
5025                     "vec4 gl_TexCoord[];"
5026                     "float gl_FogFragCoord;"
5027                     );
5028             if (version >= 450)
5029                 stageBuiltins[EShLangVertex].append(
5030                     "float gl_CullDistance[];"
5031                     );
5032             stageBuiltins[EShLangVertex].append(
5033                 "};"
5034                 "\n");
5035         }
5036         if (version >= 130 && spvVersion.vulkan == 0)
5037             stageBuiltins[EShLangVertex].append(
5038                 "int gl_VertexID;"            // needs qualifier fixed later
5039                 );
5040         if (version >= 140 && spvVersion.vulkan == 0)
5041             stageBuiltins[EShLangVertex].append(
5042                 "int gl_InstanceID;"          // needs qualifier fixed later
5043                 );
5044         if (spvVersion.vulkan > 0 && version >= 140)
5045             stageBuiltins[EShLangVertex].append(
5046                 "in int gl_VertexIndex;"
5047                 "in int gl_InstanceIndex;"
5048                 );
5049 
5050         if (spvVersion.vulkan > 0 && version >= 140 && spvVersion.vulkanRelaxed)
5051             stageBuiltins[EShLangVertex].append(
5052                 "in int gl_VertexID;"         // declare with 'in' qualifier
5053                 "in int gl_InstanceID;"
5054                 );
5055 
5056         if (version >= 440) {
5057             stageBuiltins[EShLangVertex].append(
5058                 "in int gl_BaseVertexARB;"
5059                 "in int gl_BaseInstanceARB;"
5060                 "in int gl_DrawIDARB;"
5061                 );
5062         }
5063         if (version >= 410) {
5064             stageBuiltins[EShLangVertex].append(
5065                 "out int gl_ViewportIndex;"
5066                 "out int gl_Layer;"
5067                 );
5068         }
5069         if (version >= 460) {
5070             stageBuiltins[EShLangVertex].append(
5071                 "in int gl_BaseVertex;"
5072                 "in int gl_BaseInstance;"
5073                 "in int gl_DrawID;"
5074                 );
5075         }
5076 
5077         if (version >= 430)
5078             stageBuiltins[EShLangVertex].append(
5079                 "out int gl_ViewportMask[];"             // GL_NV_viewport_array2
5080                 );
5081 
5082         if (version >= 450)
5083             stageBuiltins[EShLangVertex].append(
5084                 "out int gl_SecondaryViewportMaskNV[];"  // GL_NV_stereo_view_rendering
5085                 "out vec4 gl_SecondaryPositionNV;"       // GL_NV_stereo_view_rendering
5086                 "out vec4 gl_PositionPerViewNV[];"       // GL_NVX_multiview_per_view_attributes
5087                 "out int  gl_ViewportMaskPerViewNV[];"   // GL_NVX_multiview_per_view_attributes
5088                 );
5089     } else {
5090         // ES profile
5091         if (version == 100) {
5092             stageBuiltins[EShLangVertex].append(
5093                 "highp   vec4  gl_Position;"  // needs qualifier fixed later
5094                 "mediump float gl_PointSize;" // needs qualifier fixed later
5095                 );
5096         } else {
5097             if (spvVersion.vulkan == 0 || spvVersion.vulkanRelaxed)
5098                 stageBuiltins[EShLangVertex].append(
5099                     "in highp int gl_VertexID;"      // needs qualifier fixed later
5100                     "in highp int gl_InstanceID;"    // needs qualifier fixed later
5101                     );
5102             if (spvVersion.vulkan > 0)
5103 #endif
5104                 stageBuiltins[EShLangVertex].append(
5105                     "in highp int gl_VertexIndex;"
5106                     "in highp int gl_InstanceIndex;"
5107                     );
5108 #ifndef GLSLANG_WEB
5109             if (version < 310)
5110 #endif
5111                 stageBuiltins[EShLangVertex].append(
5112                     "highp vec4  gl_Position;"    // needs qualifier fixed later
5113                     "highp float gl_PointSize;"   // needs qualifier fixed later
5114                     );
5115 #ifndef GLSLANG_WEB
5116             else
5117                 stageBuiltins[EShLangVertex].append(
5118                     "out gl_PerVertex {"
5119                         "highp vec4  gl_Position;"    // needs qualifier fixed later
5120                         "highp float gl_PointSize;"   // needs qualifier fixed later
5121                     "};"
5122                     );
5123         }
5124     }
5125 
5126     if ((profile != EEsProfile && version >= 140) ||
5127         (profile == EEsProfile && version >= 310)) {
5128         stageBuiltins[EShLangVertex].append(
5129             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5130             "in highp int gl_ViewIndex;"       // GL_EXT_multiview
5131             "\n");
5132     }
5133 
5134     if (version >= 300 /* both ES and non-ES */) {
5135         stageBuiltins[EShLangVertex].append(
5136             "in highp uint gl_ViewID_OVR;"     // GL_OVR_multiview, GL_OVR_multiview2
5137             "\n");
5138     }
5139 
5140     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
5141         stageBuiltins[EShLangVertex].append(
5142             "out highp int gl_PrimitiveShadingRateEXT;" // GL_EXT_fragment_shading_rate
5143             "\n");
5144     }
5145 
5146     //============================================================================
5147     //
5148     // Define the interface to the geometry shader.
5149     //
5150     //============================================================================
5151 
5152     if (profile == ECoreProfile || profile == ECompatibilityProfile) {
5153         stageBuiltins[EShLangGeometry].append(
5154             "in gl_PerVertex {"
5155                 "vec4 gl_Position;"
5156                 "float gl_PointSize;"
5157                 "float gl_ClipDistance[];"
5158                 );
5159         if (profile == ECompatibilityProfile)
5160             stageBuiltins[EShLangGeometry].append(
5161                 "vec4 gl_ClipVertex;"
5162                 "vec4 gl_FrontColor;"
5163                 "vec4 gl_BackColor;"
5164                 "vec4 gl_FrontSecondaryColor;"
5165                 "vec4 gl_BackSecondaryColor;"
5166                 "vec4 gl_TexCoord[];"
5167                 "float gl_FogFragCoord;"
5168                 );
5169         if (version >= 450)
5170             stageBuiltins[EShLangGeometry].append(
5171                 "float gl_CullDistance[];"
5172                 "vec4 gl_SecondaryPositionNV;"   // GL_NV_stereo_view_rendering
5173                 "vec4 gl_PositionPerViewNV[];"   // GL_NVX_multiview_per_view_attributes
5174                 );
5175         stageBuiltins[EShLangGeometry].append(
5176             "} gl_in[];"
5177 
5178             "in int gl_PrimitiveIDIn;"
5179             "out gl_PerVertex {"
5180                 "vec4 gl_Position;"
5181                 "float gl_PointSize;"
5182                 "float gl_ClipDistance[];"
5183                 "\n");
5184         if (profile == ECompatibilityProfile && version >= 400)
5185             stageBuiltins[EShLangGeometry].append(
5186                 "vec4 gl_ClipVertex;"
5187                 "vec4 gl_FrontColor;"
5188                 "vec4 gl_BackColor;"
5189                 "vec4 gl_FrontSecondaryColor;"
5190                 "vec4 gl_BackSecondaryColor;"
5191                 "vec4 gl_TexCoord[];"
5192                 "float gl_FogFragCoord;"
5193                 );
5194         if (version >= 450)
5195             stageBuiltins[EShLangGeometry].append(
5196                 "float gl_CullDistance[];"
5197                 );
5198         stageBuiltins[EShLangGeometry].append(
5199             "};"
5200 
5201             "out int gl_PrimitiveID;"
5202             "out int gl_Layer;");
5203 
5204         if (version >= 150)
5205             stageBuiltins[EShLangGeometry].append(
5206             "out int gl_ViewportIndex;"
5207             );
5208 
5209         if (profile == ECompatibilityProfile && version < 400)
5210             stageBuiltins[EShLangGeometry].append(
5211             "out vec4 gl_ClipVertex;"
5212             );
5213 
5214         if (version >= 400)
5215             stageBuiltins[EShLangGeometry].append(
5216             "in int gl_InvocationID;"
5217             );
5218 
5219         if (version >= 430)
5220             stageBuiltins[EShLangGeometry].append(
5221                 "out int gl_ViewportMask[];"               // GL_NV_viewport_array2
5222             );
5223 
5224         if (version >= 450)
5225             stageBuiltins[EShLangGeometry].append(
5226                 "out int gl_SecondaryViewportMaskNV[];"    // GL_NV_stereo_view_rendering
5227                 "out vec4 gl_SecondaryPositionNV;"         // GL_NV_stereo_view_rendering
5228                 "out vec4 gl_PositionPerViewNV[];"         // GL_NVX_multiview_per_view_attributes
5229                 "out int  gl_ViewportMaskPerViewNV[];"     // GL_NVX_multiview_per_view_attributes
5230             );
5231 
5232         stageBuiltins[EShLangGeometry].append("\n");
5233     } else if (profile == EEsProfile && version >= 310) {
5234         stageBuiltins[EShLangGeometry].append(
5235             "in gl_PerVertex {"
5236                 "highp vec4 gl_Position;"
5237                 "highp float gl_PointSize;"
5238             "} gl_in[];"
5239             "\n"
5240             "in highp int gl_PrimitiveIDIn;"
5241             "in highp int gl_InvocationID;"
5242             "\n"
5243             "out gl_PerVertex {"
5244                 "highp vec4 gl_Position;"
5245                 "highp float gl_PointSize;"
5246             "};"
5247             "\n"
5248             "out highp int gl_PrimitiveID;"
5249             "out highp int gl_Layer;"
5250             "\n"
5251             );
5252     }
5253 
5254     if ((profile != EEsProfile && version >= 140) ||
5255         (profile == EEsProfile && version >= 310)) {
5256         stageBuiltins[EShLangGeometry].append(
5257             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5258             "in highp int gl_ViewIndex;"       // GL_EXT_multiview
5259             "\n");
5260     }
5261 
5262     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
5263         stageBuiltins[EShLangGeometry].append(
5264             "out highp int gl_PrimitiveShadingRateEXT;" // GL_EXT_fragment_shading_rate
5265             "\n");
5266     }
5267 
5268     //============================================================================
5269     //
5270     // Define the interface to the tessellation control shader.
5271     //
5272     //============================================================================
5273 
5274     if (profile != EEsProfile && version >= 150) {
5275         // Note:  "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below,
5276         // as it depends on the resource sizing of gl_MaxPatchVertices.
5277 
5278         stageBuiltins[EShLangTessControl].append(
5279             "in int gl_PatchVerticesIn;"
5280             "in int gl_PrimitiveID;"
5281             "in int gl_InvocationID;"
5282 
5283             "out gl_PerVertex {"
5284                 "vec4 gl_Position;"
5285                 "float gl_PointSize;"
5286                 "float gl_ClipDistance[];"
5287                 );
5288         if (profile == ECompatibilityProfile)
5289             stageBuiltins[EShLangTessControl].append(
5290                 "vec4 gl_ClipVertex;"
5291                 "vec4 gl_FrontColor;"
5292                 "vec4 gl_BackColor;"
5293                 "vec4 gl_FrontSecondaryColor;"
5294                 "vec4 gl_BackSecondaryColor;"
5295                 "vec4 gl_TexCoord[];"
5296                 "float gl_FogFragCoord;"
5297                 );
5298         if (version >= 450)
5299             stageBuiltins[EShLangTessControl].append(
5300                 "float gl_CullDistance[];"
5301             );
5302         if (version >= 430)
5303             stageBuiltins[EShLangTessControl].append(
5304                 "int  gl_ViewportMask[];"             // GL_NV_viewport_array2
5305             );
5306         if (version >= 450)
5307             stageBuiltins[EShLangTessControl].append(
5308                 "vec4 gl_SecondaryPositionNV;"        // GL_NV_stereo_view_rendering
5309                 "int  gl_SecondaryViewportMaskNV[];"  // GL_NV_stereo_view_rendering
5310                 "vec4 gl_PositionPerViewNV[];"        // GL_NVX_multiview_per_view_attributes
5311                 "int  gl_ViewportMaskPerViewNV[];"    // GL_NVX_multiview_per_view_attributes
5312                 );
5313         stageBuiltins[EShLangTessControl].append(
5314             "} gl_out[];"
5315 
5316             "patch out float gl_TessLevelOuter[4];"
5317             "patch out float gl_TessLevelInner[2];"
5318             "\n");
5319 
5320         if (version >= 410)
5321             stageBuiltins[EShLangTessControl].append(
5322                 "out int gl_ViewportIndex;"
5323                 "out int gl_Layer;"
5324                 "\n");
5325 
5326     } else {
5327         // Note:  "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below,
5328         // as it depends on the resource sizing of gl_MaxPatchVertices.
5329 
5330         stageBuiltins[EShLangTessControl].append(
5331             "in highp int gl_PatchVerticesIn;"
5332             "in highp int gl_PrimitiveID;"
5333             "in highp int gl_InvocationID;"
5334 
5335             "out gl_PerVertex {"
5336                 "highp vec4 gl_Position;"
5337                 "highp float gl_PointSize;"
5338                 );
5339         stageBuiltins[EShLangTessControl].append(
5340             "} gl_out[];"
5341 
5342             "patch out highp float gl_TessLevelOuter[4];"
5343             "patch out highp float gl_TessLevelInner[2];"
5344             "patch out highp vec4 gl_BoundingBoxOES[2];"
5345             "patch out highp vec4 gl_BoundingBoxEXT[2];"
5346             "\n");
5347         if (profile == EEsProfile && version >= 320) {
5348             stageBuiltins[EShLangTessControl].append(
5349                 "patch out highp vec4 gl_BoundingBox[2];"
5350                 "\n"
5351             );
5352         }
5353     }
5354 
5355     if ((profile != EEsProfile && version >= 140) ||
5356         (profile == EEsProfile && version >= 310)) {
5357         stageBuiltins[EShLangTessControl].append(
5358             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5359             "in highp int gl_ViewIndex;"       // GL_EXT_multiview
5360             "\n");
5361     }
5362 
5363     //============================================================================
5364     //
5365     // Define the interface to the tessellation evaluation shader.
5366     //
5367     //============================================================================
5368 
5369     if (profile != EEsProfile && version >= 150) {
5370         // Note:  "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below,
5371         // as it depends on the resource sizing of gl_MaxPatchVertices.
5372 
5373         stageBuiltins[EShLangTessEvaluation].append(
5374             "in int gl_PatchVerticesIn;"
5375             "in int gl_PrimitiveID;"
5376             "in vec3 gl_TessCoord;"
5377 
5378             "patch in float gl_TessLevelOuter[4];"
5379             "patch in float gl_TessLevelInner[2];"
5380 
5381             "out gl_PerVertex {"
5382                 "vec4 gl_Position;"
5383                 "float gl_PointSize;"
5384                 "float gl_ClipDistance[];"
5385             );
5386         if (version >= 400 && profile == ECompatibilityProfile)
5387             stageBuiltins[EShLangTessEvaluation].append(
5388                 "vec4 gl_ClipVertex;"
5389                 "vec4 gl_FrontColor;"
5390                 "vec4 gl_BackColor;"
5391                 "vec4 gl_FrontSecondaryColor;"
5392                 "vec4 gl_BackSecondaryColor;"
5393                 "vec4 gl_TexCoord[];"
5394                 "float gl_FogFragCoord;"
5395                 );
5396         if (version >= 450)
5397             stageBuiltins[EShLangTessEvaluation].append(
5398                 "float gl_CullDistance[];"
5399                 );
5400         stageBuiltins[EShLangTessEvaluation].append(
5401             "};"
5402             "\n");
5403 
5404         if (version >= 410)
5405             stageBuiltins[EShLangTessEvaluation].append(
5406                 "out int gl_ViewportIndex;"
5407                 "out int gl_Layer;"
5408                 "\n");
5409 
5410         if (version >= 430)
5411             stageBuiltins[EShLangTessEvaluation].append(
5412                 "out int  gl_ViewportMask[];"             // GL_NV_viewport_array2
5413             );
5414 
5415         if (version >= 450)
5416             stageBuiltins[EShLangTessEvaluation].append(
5417                 "out vec4 gl_SecondaryPositionNV;"        // GL_NV_stereo_view_rendering
5418                 "out int  gl_SecondaryViewportMaskNV[];"  // GL_NV_stereo_view_rendering
5419                 "out vec4 gl_PositionPerViewNV[];"        // GL_NVX_multiview_per_view_attributes
5420                 "out int  gl_ViewportMaskPerViewNV[];"    // GL_NVX_multiview_per_view_attributes
5421                 );
5422 
5423     } else if (profile == EEsProfile && version >= 310) {
5424         // Note:  "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below,
5425         // as it depends on the resource sizing of gl_MaxPatchVertices.
5426 
5427         stageBuiltins[EShLangTessEvaluation].append(
5428             "in highp int gl_PatchVerticesIn;"
5429             "in highp int gl_PrimitiveID;"
5430             "in highp vec3 gl_TessCoord;"
5431 
5432             "patch in highp float gl_TessLevelOuter[4];"
5433             "patch in highp float gl_TessLevelInner[2];"
5434 
5435             "out gl_PerVertex {"
5436                 "highp vec4 gl_Position;"
5437                 "highp float gl_PointSize;"
5438             );
5439         stageBuiltins[EShLangTessEvaluation].append(
5440             "};"
5441             "\n");
5442     }
5443 
5444     if ((profile != EEsProfile && version >= 140) ||
5445         (profile == EEsProfile && version >= 310)) {
5446         stageBuiltins[EShLangTessEvaluation].append(
5447             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5448             "in highp int gl_ViewIndex;"       // GL_EXT_multiview
5449             "\n");
5450     }
5451 
5452     //============================================================================
5453     //
5454     // Define the interface to the fragment shader.
5455     //
5456     //============================================================================
5457 
5458     if (profile != EEsProfile) {
5459 
5460         stageBuiltins[EShLangFragment].append(
5461             "vec4  gl_FragCoord;"   // needs qualifier fixed later
5462             "bool  gl_FrontFacing;" // needs qualifier fixed later
5463             "float gl_FragDepth;"   // needs qualifier fixed later
5464             );
5465         if (version >= 120)
5466             stageBuiltins[EShLangFragment].append(
5467                 "vec2 gl_PointCoord;"  // needs qualifier fixed later
5468                 );
5469         if (version >= 140)
5470             stageBuiltins[EShLangFragment].append(
5471                 "out int gl_FragStencilRefARB;"
5472                 );
5473         if (IncludeLegacy(version, profile, spvVersion) || (! ForwardCompatibility && version < 420))
5474             stageBuiltins[EShLangFragment].append(
5475                 "vec4 gl_FragColor;"   // needs qualifier fixed later
5476                 );
5477 
5478         if (version < 130) {
5479             stageBuiltins[EShLangFragment].append(
5480                 "varying vec4  gl_Color;"
5481                 "varying vec4  gl_SecondaryColor;"
5482                 "varying vec4  gl_TexCoord[];"
5483                 "varying float gl_FogFragCoord;"
5484                 );
5485         } else {
5486             stageBuiltins[EShLangFragment].append(
5487                 "in float gl_ClipDistance[];"
5488                 );
5489 
5490             if (IncludeLegacy(version, profile, spvVersion)) {
5491                 if (version < 150)
5492                     stageBuiltins[EShLangFragment].append(
5493                         "in float gl_FogFragCoord;"
5494                         "in vec4  gl_TexCoord[];"
5495                         "in vec4  gl_Color;"
5496                         "in vec4  gl_SecondaryColor;"
5497                         );
5498                 else
5499                     stageBuiltins[EShLangFragment].append(
5500                         "in gl_PerFragment {"
5501                             "in float gl_FogFragCoord;"
5502                             "in vec4  gl_TexCoord[];"
5503                             "in vec4  gl_Color;"
5504                             "in vec4  gl_SecondaryColor;"
5505                         "};"
5506                         );
5507             }
5508         }
5509 
5510         if (version >= 150)
5511             stageBuiltins[EShLangFragment].append(
5512                 "flat in int gl_PrimitiveID;"
5513                 );
5514 
5515         if (version >= 130) { // ARB_sample_shading
5516             stageBuiltins[EShLangFragment].append(
5517                 "flat in  int  gl_SampleID;"
5518                 "     in  vec2 gl_SamplePosition;"
5519                 "     out int  gl_SampleMask[];"
5520                 );
5521 
5522             if (spvVersion.spv == 0) {
5523                 stageBuiltins[EShLangFragment].append(
5524                     "uniform int gl_NumSamples;"
5525                 );
5526             }
5527         }
5528 
5529         if (version >= 400)
5530             stageBuiltins[EShLangFragment].append(
5531                 "flat in  int  gl_SampleMaskIn[];"
5532             );
5533 
5534         if (version >= 430)
5535             stageBuiltins[EShLangFragment].append(
5536                 "flat in int gl_Layer;"
5537                 "flat in int gl_ViewportIndex;"
5538                 );
5539 
5540         if (version >= 450)
5541             stageBuiltins[EShLangFragment].append(
5542                 "in float gl_CullDistance[];"
5543                 "bool gl_HelperInvocation;"     // needs qualifier fixed later
5544                 );
5545 
5546         if (version >= 450)
5547             stageBuiltins[EShLangFragment].append( // GL_EXT_fragment_invocation_density
5548                 "flat in ivec2 gl_FragSizeEXT;"
5549                 "flat in int   gl_FragInvocationCountEXT;"
5550                 );
5551 
5552         if (version >= 450)
5553             stageBuiltins[EShLangFragment].append(
5554                 "in vec2 gl_BaryCoordNoPerspAMD;"
5555                 "in vec2 gl_BaryCoordNoPerspCentroidAMD;"
5556                 "in vec2 gl_BaryCoordNoPerspSampleAMD;"
5557                 "in vec2 gl_BaryCoordSmoothAMD;"
5558                 "in vec2 gl_BaryCoordSmoothCentroidAMD;"
5559                 "in vec2 gl_BaryCoordSmoothSampleAMD;"
5560                 "in vec3 gl_BaryCoordPullModelAMD;"
5561                 );
5562 
5563         if (version >= 430)
5564             stageBuiltins[EShLangFragment].append(
5565                 "in bool gl_FragFullyCoveredNV;"
5566                 );
5567         if (version >= 450)
5568             stageBuiltins[EShLangFragment].append(
5569                 "flat in ivec2 gl_FragmentSizeNV;"          // GL_NV_shading_rate_image
5570                 "flat in int   gl_InvocationsPerPixelNV;"
5571                 "in vec3 gl_BaryCoordNV;"                   // GL_NV_fragment_shader_barycentric
5572                 "in vec3 gl_BaryCoordNoPerspNV;"
5573                 );
5574 
5575         if (version >= 450)
5576             stageBuiltins[EShLangFragment].append(
5577                 "flat in int gl_ShadingRateEXT;" // GL_EXT_fragment_shading_rate
5578             );
5579 
5580     } else {
5581         // ES profile
5582 
5583         if (version == 100) {
5584             stageBuiltins[EShLangFragment].append(
5585                 "mediump vec4 gl_FragCoord;"    // needs qualifier fixed later
5586                 "        bool gl_FrontFacing;"  // needs qualifier fixed later
5587                 "mediump vec4 gl_FragColor;"    // needs qualifier fixed later
5588                 "mediump vec2 gl_PointCoord;"   // needs qualifier fixed later
5589                 );
5590         }
5591 #endif
5592         if (version >= 300) {
5593             stageBuiltins[EShLangFragment].append(
5594                 "highp   vec4  gl_FragCoord;"    // needs qualifier fixed later
5595                 "        bool  gl_FrontFacing;"  // needs qualifier fixed later
5596                 "mediump vec2  gl_PointCoord;"   // needs qualifier fixed later
5597                 "highp   float gl_FragDepth;"    // needs qualifier fixed later
5598                 );
5599         }
5600 #ifndef GLSLANG_WEB
5601         if (version >= 310) {
5602             stageBuiltins[EShLangFragment].append(
5603                 "bool gl_HelperInvocation;"          // needs qualifier fixed later
5604                 "flat in highp int gl_PrimitiveID;"  // needs qualifier fixed later
5605                 "flat in highp int gl_Layer;"        // needs qualifier fixed later
5606                 );
5607 
5608             stageBuiltins[EShLangFragment].append(  // GL_OES_sample_variables
5609                 "flat  in lowp     int gl_SampleID;"
5610                 "      in mediump vec2 gl_SamplePosition;"
5611                 "flat  in highp    int gl_SampleMaskIn[];"
5612                 "     out highp    int gl_SampleMask[];"
5613                 );
5614             if (spvVersion.spv == 0)
5615                 stageBuiltins[EShLangFragment].append(  // GL_OES_sample_variables
5616                     "uniform lowp int gl_NumSamples;"
5617                     );
5618         }
5619         stageBuiltins[EShLangFragment].append(
5620             "highp float gl_FragDepthEXT;"       // GL_EXT_frag_depth
5621             );
5622 
5623         if (version >= 310)
5624             stageBuiltins[EShLangFragment].append( // GL_EXT_fragment_invocation_density
5625                 "flat in ivec2 gl_FragSizeEXT;"
5626                 "flat in int   gl_FragInvocationCountEXT;"
5627             );
5628         if (version >= 320)
5629             stageBuiltins[EShLangFragment].append( // GL_NV_shading_rate_image
5630                 "flat in ivec2 gl_FragmentSizeNV;"
5631                 "flat in int   gl_InvocationsPerPixelNV;"
5632             );
5633         if (version >= 320)
5634             stageBuiltins[EShLangFragment].append(
5635                 "in vec3 gl_BaryCoordNV;"
5636                 "in vec3 gl_BaryCoordNoPerspNV;"
5637                 );
5638         if (version >= 310)
5639             stageBuiltins[EShLangFragment].append(
5640                 "flat in highp int gl_ShadingRateEXT;" // GL_EXT_fragment_shading_rate
5641             );
5642     }
5643 #endif
5644 
5645     stageBuiltins[EShLangFragment].append("\n");
5646 
5647     if (version >= 130)
5648         add2ndGenerationSamplingImaging(version, profile, spvVersion);
5649 
5650 #ifndef GLSLANG_WEB
5651 
5652     if ((profile != EEsProfile && version >= 140) ||
5653         (profile == EEsProfile && version >= 310)) {
5654         stageBuiltins[EShLangFragment].append(
5655             "flat in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5656             "flat in highp int gl_ViewIndex;"       // GL_EXT_multiview
5657             "\n");
5658     }
5659 
5660     if (version >= 300 /* both ES and non-ES */) {
5661         stageBuiltins[EShLangFragment].append(
5662             "flat in highp uint gl_ViewID_OVR;"     // GL_OVR_multiview, GL_OVR_multiview2
5663             "\n");
5664     }
5665 
5666 #ifndef GLSLANG_ANGLE
5667     // GL_ARB_shader_ballot
5668     if (profile != EEsProfile && version >= 450) {
5669         const char* ballotDecls =
5670             "uniform uint gl_SubGroupSizeARB;"
5671             "in uint     gl_SubGroupInvocationARB;"
5672             "in uint64_t gl_SubGroupEqMaskARB;"
5673             "in uint64_t gl_SubGroupGeMaskARB;"
5674             "in uint64_t gl_SubGroupGtMaskARB;"
5675             "in uint64_t gl_SubGroupLeMaskARB;"
5676             "in uint64_t gl_SubGroupLtMaskARB;"
5677             "\n";
5678         const char* rtBallotDecls =
5679             "uniform volatile uint gl_SubGroupSizeARB;"
5680             "in volatile uint     gl_SubGroupInvocationARB;"
5681             "in volatile uint64_t gl_SubGroupEqMaskARB;"
5682             "in volatile uint64_t gl_SubGroupGeMaskARB;"
5683             "in volatile uint64_t gl_SubGroupGtMaskARB;"
5684             "in volatile uint64_t gl_SubGroupLeMaskARB;"
5685             "in volatile uint64_t gl_SubGroupLtMaskARB;"
5686             "\n";
5687         const char* fragmentBallotDecls =
5688             "uniform uint gl_SubGroupSizeARB;"
5689             "flat in uint     gl_SubGroupInvocationARB;"
5690             "flat in uint64_t gl_SubGroupEqMaskARB;"
5691             "flat in uint64_t gl_SubGroupGeMaskARB;"
5692             "flat in uint64_t gl_SubGroupGtMaskARB;"
5693             "flat in uint64_t gl_SubGroupLeMaskARB;"
5694             "flat in uint64_t gl_SubGroupLtMaskARB;"
5695             "\n";
5696         stageBuiltins[EShLangVertex]        .append(ballotDecls);
5697         stageBuiltins[EShLangTessControl]   .append(ballotDecls);
5698         stageBuiltins[EShLangTessEvaluation].append(ballotDecls);
5699         stageBuiltins[EShLangGeometry]      .append(ballotDecls);
5700         stageBuiltins[EShLangCompute]       .append(ballotDecls);
5701         stageBuiltins[EShLangFragment]      .append(fragmentBallotDecls);
5702         stageBuiltins[EShLangMeshNV]        .append(ballotDecls);
5703         stageBuiltins[EShLangTaskNV]        .append(ballotDecls);
5704         stageBuiltins[EShLangRayGen]        .append(rtBallotDecls);
5705         stageBuiltins[EShLangIntersect]     .append(rtBallotDecls);
5706         // No volatile qualifier on these builtins in any-hit
5707         stageBuiltins[EShLangAnyHit]        .append(ballotDecls);
5708         stageBuiltins[EShLangClosestHit]    .append(rtBallotDecls);
5709         stageBuiltins[EShLangMiss]          .append(rtBallotDecls);
5710         stageBuiltins[EShLangCallable]      .append(rtBallotDecls);
5711     }
5712 
5713     // GL_KHR_shader_subgroup
5714     if ((profile == EEsProfile && version >= 310) ||
5715         (profile != EEsProfile && version >= 140)) {
5716         const char* subgroupDecls =
5717             "in mediump uint  gl_SubgroupSize;"
5718             "in mediump uint  gl_SubgroupInvocationID;"
5719             "in highp   uvec4 gl_SubgroupEqMask;"
5720             "in highp   uvec4 gl_SubgroupGeMask;"
5721             "in highp   uvec4 gl_SubgroupGtMask;"
5722             "in highp   uvec4 gl_SubgroupLeMask;"
5723             "in highp   uvec4 gl_SubgroupLtMask;"
5724             // GL_NV_shader_sm_builtins
5725             "in highp   uint  gl_WarpsPerSMNV;"
5726             "in highp   uint  gl_SMCountNV;"
5727             "in highp   uint  gl_WarpIDNV;"
5728             "in highp   uint  gl_SMIDNV;"
5729             "\n";
5730         const char* fragmentSubgroupDecls =
5731             "flat in mediump uint  gl_SubgroupSize;"
5732             "flat in mediump uint  gl_SubgroupInvocationID;"
5733             "flat in highp   uvec4 gl_SubgroupEqMask;"
5734             "flat in highp   uvec4 gl_SubgroupGeMask;"
5735             "flat in highp   uvec4 gl_SubgroupGtMask;"
5736             "flat in highp   uvec4 gl_SubgroupLeMask;"
5737             "flat in highp   uvec4 gl_SubgroupLtMask;"
5738             // GL_NV_shader_sm_builtins
5739             "flat in highp   uint  gl_WarpsPerSMNV;"
5740             "flat in highp   uint  gl_SMCountNV;"
5741             "flat in highp   uint  gl_WarpIDNV;"
5742             "flat in highp   uint  gl_SMIDNV;"
5743             "\n";
5744         const char* computeSubgroupDecls =
5745             "in highp   uint  gl_NumSubgroups;"
5746             "in highp   uint  gl_SubgroupID;"
5747             "\n";
5748         // These builtins are volatile for RT stages
5749         const char* rtSubgroupDecls =
5750             "in mediump volatile uint  gl_SubgroupSize;"
5751             "in mediump volatile uint  gl_SubgroupInvocationID;"
5752             "in highp   volatile uvec4 gl_SubgroupEqMask;"
5753             "in highp   volatile uvec4 gl_SubgroupGeMask;"
5754             "in highp   volatile uvec4 gl_SubgroupGtMask;"
5755             "in highp   volatile uvec4 gl_SubgroupLeMask;"
5756             "in highp   volatile uvec4 gl_SubgroupLtMask;"
5757             // GL_NV_shader_sm_builtins
5758             "in highp    uint  gl_WarpsPerSMNV;"
5759             "in highp    uint  gl_SMCountNV;"
5760             "in highp volatile uint  gl_WarpIDNV;"
5761             "in highp volatile uint  gl_SMIDNV;"
5762             "\n";
5763 
5764         stageBuiltins[EShLangVertex]        .append(subgroupDecls);
5765         stageBuiltins[EShLangTessControl]   .append(subgroupDecls);
5766         stageBuiltins[EShLangTessEvaluation].append(subgroupDecls);
5767         stageBuiltins[EShLangGeometry]      .append(subgroupDecls);
5768         stageBuiltins[EShLangCompute]       .append(subgroupDecls);
5769         stageBuiltins[EShLangCompute]       .append(computeSubgroupDecls);
5770         stageBuiltins[EShLangFragment]      .append(fragmentSubgroupDecls);
5771         stageBuiltins[EShLangMeshNV]        .append(subgroupDecls);
5772         stageBuiltins[EShLangMeshNV]        .append(computeSubgroupDecls);
5773         stageBuiltins[EShLangTaskNV]        .append(subgroupDecls);
5774         stageBuiltins[EShLangTaskNV]        .append(computeSubgroupDecls);
5775         stageBuiltins[EShLangRayGen]        .append(rtSubgroupDecls);
5776         stageBuiltins[EShLangIntersect]     .append(rtSubgroupDecls);
5777         // No volatile qualifier on these builtins in any-hit
5778         stageBuiltins[EShLangAnyHit]        .append(subgroupDecls);
5779         stageBuiltins[EShLangClosestHit]    .append(rtSubgroupDecls);
5780         stageBuiltins[EShLangMiss]          .append(rtSubgroupDecls);
5781         stageBuiltins[EShLangCallable]      .append(rtSubgroupDecls);
5782     }
5783 
5784     // GL_NV_ray_tracing/GL_EXT_ray_tracing
5785     if (profile != EEsProfile && version >= 460) {
5786 
5787         const char *constRayFlags =
5788             "const uint gl_RayFlagsNoneNV = 0U;"
5789             "const uint gl_RayFlagsNoneEXT = 0U;"
5790             "const uint gl_RayFlagsOpaqueNV = 1U;"
5791             "const uint gl_RayFlagsOpaqueEXT = 1U;"
5792             "const uint gl_RayFlagsNoOpaqueNV = 2U;"
5793             "const uint gl_RayFlagsNoOpaqueEXT = 2U;"
5794             "const uint gl_RayFlagsTerminateOnFirstHitNV = 4U;"
5795             "const uint gl_RayFlagsTerminateOnFirstHitEXT = 4U;"
5796             "const uint gl_RayFlagsSkipClosestHitShaderNV = 8U;"
5797             "const uint gl_RayFlagsSkipClosestHitShaderEXT = 8U;"
5798             "const uint gl_RayFlagsCullBackFacingTrianglesNV = 16U;"
5799             "const uint gl_RayFlagsCullBackFacingTrianglesEXT = 16U;"
5800             "const uint gl_RayFlagsCullFrontFacingTrianglesNV = 32U;"
5801             "const uint gl_RayFlagsCullFrontFacingTrianglesEXT = 32U;"
5802             "const uint gl_RayFlagsCullOpaqueNV = 64U;"
5803             "const uint gl_RayFlagsCullOpaqueEXT = 64U;"
5804             "const uint gl_RayFlagsCullNoOpaqueNV = 128U;"
5805             "const uint gl_RayFlagsCullNoOpaqueEXT = 128U;"
5806             "const uint gl_RayFlagsSkipTrianglesEXT = 256U;"
5807             "const uint gl_RayFlagsSkipAABBEXT = 512U;"
5808             "const uint gl_HitKindFrontFacingTriangleEXT = 254U;"
5809             "const uint gl_HitKindBackFacingTriangleEXT = 255U;"
5810             "\n";
5811 
5812         const char *constRayQueryIntersection =
5813             "const uint gl_RayQueryCandidateIntersectionEXT = 0U;"
5814             "const uint gl_RayQueryCommittedIntersectionEXT = 1U;"
5815             "const uint gl_RayQueryCommittedIntersectionNoneEXT = 0U;"
5816             "const uint gl_RayQueryCommittedIntersectionTriangleEXT = 1U;"
5817             "const uint gl_RayQueryCommittedIntersectionGeneratedEXT = 2U;"
5818             "const uint gl_RayQueryCandidateIntersectionTriangleEXT = 0U;"
5819             "const uint gl_RayQueryCandidateIntersectionAABBEXT = 1U;"
5820             "\n";
5821 
5822         const char *rayGenDecls =
5823             "in    uvec3  gl_LaunchIDNV;"
5824             "in    uvec3  gl_LaunchIDEXT;"
5825             "in    uvec3  gl_LaunchSizeNV;"
5826             "in    uvec3  gl_LaunchSizeEXT;"
5827             "\n";
5828         const char *intersectDecls =
5829             "in    uvec3  gl_LaunchIDNV;"
5830             "in    uvec3  gl_LaunchIDEXT;"
5831             "in    uvec3  gl_LaunchSizeNV;"
5832             "in    uvec3  gl_LaunchSizeEXT;"
5833             "in     int   gl_PrimitiveID;"
5834             "in     int   gl_InstanceID;"
5835             "in     int   gl_InstanceCustomIndexNV;"
5836             "in     int   gl_InstanceCustomIndexEXT;"
5837             "in     int   gl_GeometryIndexEXT;"
5838             "in    vec3   gl_WorldRayOriginNV;"
5839             "in    vec3   gl_WorldRayOriginEXT;"
5840             "in    vec3   gl_WorldRayDirectionNV;"
5841             "in    vec3   gl_WorldRayDirectionEXT;"
5842             "in    vec3   gl_ObjectRayOriginNV;"
5843             "in    vec3   gl_ObjectRayOriginEXT;"
5844             "in    vec3   gl_ObjectRayDirectionNV;"
5845             "in    vec3   gl_ObjectRayDirectionEXT;"
5846             "in    float  gl_RayTminNV;"
5847             "in    float  gl_RayTminEXT;"
5848             "in    float  gl_RayTmaxNV;"
5849             "in volatile float gl_RayTmaxEXT;"
5850             "in    mat4x3 gl_ObjectToWorldNV;"
5851             "in    mat4x3 gl_ObjectToWorldEXT;"
5852             "in    mat3x4 gl_ObjectToWorld3x4EXT;"
5853             "in    mat4x3 gl_WorldToObjectNV;"
5854             "in    mat4x3 gl_WorldToObjectEXT;"
5855             "in    mat3x4 gl_WorldToObject3x4EXT;"
5856             "in    uint   gl_IncomingRayFlagsNV;"
5857             "in    uint   gl_IncomingRayFlagsEXT;"
5858             "in    float  gl_CurrentRayTimeNV;"
5859             "\n";
5860         const char *hitDecls =
5861             "in    uvec3  gl_LaunchIDNV;"
5862             "in    uvec3  gl_LaunchIDEXT;"
5863             "in    uvec3  gl_LaunchSizeNV;"
5864             "in    uvec3  gl_LaunchSizeEXT;"
5865             "in     int   gl_PrimitiveID;"
5866             "in     int   gl_InstanceID;"
5867             "in     int   gl_InstanceCustomIndexNV;"
5868             "in     int   gl_InstanceCustomIndexEXT;"
5869             "in     int   gl_GeometryIndexEXT;"
5870             "in    vec3   gl_WorldRayOriginNV;"
5871             "in    vec3   gl_WorldRayOriginEXT;"
5872             "in    vec3   gl_WorldRayDirectionNV;"
5873             "in    vec3   gl_WorldRayDirectionEXT;"
5874             "in    vec3   gl_ObjectRayOriginNV;"
5875             "in    vec3   gl_ObjectRayOriginEXT;"
5876             "in    vec3   gl_ObjectRayDirectionNV;"
5877             "in    vec3   gl_ObjectRayDirectionEXT;"
5878             "in    float  gl_RayTminNV;"
5879             "in    float  gl_RayTminEXT;"
5880             "in    float  gl_RayTmaxNV;"
5881             "in    float  gl_RayTmaxEXT;"
5882             "in    float  gl_HitTNV;"
5883             "in    float  gl_HitTEXT;"
5884             "in    uint   gl_HitKindNV;"
5885             "in    uint   gl_HitKindEXT;"
5886             "in    mat4x3 gl_ObjectToWorldNV;"
5887             "in    mat4x3 gl_ObjectToWorldEXT;"
5888             "in    mat3x4 gl_ObjectToWorld3x4EXT;"
5889             "in    mat4x3 gl_WorldToObjectNV;"
5890             "in    mat4x3 gl_WorldToObjectEXT;"
5891             "in    mat3x4 gl_WorldToObject3x4EXT;"
5892             "in    uint   gl_IncomingRayFlagsNV;"
5893             "in    uint   gl_IncomingRayFlagsEXT;"
5894             "in    float  gl_CurrentRayTimeNV;"
5895             "\n";
5896         const char *missDecls =
5897             "in    uvec3  gl_LaunchIDNV;"
5898             "in    uvec3  gl_LaunchIDEXT;"
5899             "in    uvec3  gl_LaunchSizeNV;"
5900             "in    uvec3  gl_LaunchSizeEXT;"
5901             "in    vec3   gl_WorldRayOriginNV;"
5902             "in    vec3   gl_WorldRayOriginEXT;"
5903             "in    vec3   gl_WorldRayDirectionNV;"
5904             "in    vec3   gl_WorldRayDirectionEXT;"
5905             "in    vec3   gl_ObjectRayOriginNV;"
5906             "in    vec3   gl_ObjectRayDirectionNV;"
5907             "in    float  gl_RayTminNV;"
5908             "in    float  gl_RayTminEXT;"
5909             "in    float  gl_RayTmaxNV;"
5910             "in    float  gl_RayTmaxEXT;"
5911             "in    uint   gl_IncomingRayFlagsNV;"
5912             "in    uint   gl_IncomingRayFlagsEXT;"
5913             "in    float  gl_CurrentRayTimeNV;"
5914             "\n";
5915 
5916         const char *callableDecls =
5917             "in    uvec3  gl_LaunchIDNV;"
5918             "in    uvec3  gl_LaunchIDEXT;"
5919             "in    uvec3  gl_LaunchSizeNV;"
5920             "in    uvec3  gl_LaunchSizeEXT;"
5921             "\n";
5922 
5923 
5924         commonBuiltins.append(constRayQueryIntersection);
5925         commonBuiltins.append(constRayFlags);
5926 
5927         stageBuiltins[EShLangRayGen].append(rayGenDecls);
5928         stageBuiltins[EShLangIntersect].append(intersectDecls);
5929         stageBuiltins[EShLangAnyHit].append(hitDecls);
5930         stageBuiltins[EShLangClosestHit].append(hitDecls);
5931         stageBuiltins[EShLangMiss].append(missDecls);
5932         stageBuiltins[EShLangCallable].append(callableDecls);
5933 
5934     }
5935 
5936     if ((profile != EEsProfile && version >= 140)) {
5937         const char *deviceIndex =
5938             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5939             "\n";
5940 
5941         stageBuiltins[EShLangRayGen].append(deviceIndex);
5942         stageBuiltins[EShLangIntersect].append(deviceIndex);
5943         stageBuiltins[EShLangAnyHit].append(deviceIndex);
5944         stageBuiltins[EShLangClosestHit].append(deviceIndex);
5945         stageBuiltins[EShLangMiss].append(deviceIndex);
5946     }
5947 
5948     if ((profile != EEsProfile && version >= 420) ||
5949         (profile == EEsProfile && version >= 310)) {
5950         commonBuiltins.append("const int gl_ScopeDevice      = 1;\n");
5951         commonBuiltins.append("const int gl_ScopeWorkgroup   = 2;\n");
5952         commonBuiltins.append("const int gl_ScopeSubgroup    = 3;\n");
5953         commonBuiltins.append("const int gl_ScopeInvocation  = 4;\n");
5954         commonBuiltins.append("const int gl_ScopeQueueFamily = 5;\n");
5955         commonBuiltins.append("const int gl_ScopeShaderCallEXT = 6;\n");
5956 
5957         commonBuiltins.append("const int gl_SemanticsRelaxed         = 0x0;\n");
5958         commonBuiltins.append("const int gl_SemanticsAcquire         = 0x2;\n");
5959         commonBuiltins.append("const int gl_SemanticsRelease         = 0x4;\n");
5960         commonBuiltins.append("const int gl_SemanticsAcquireRelease  = 0x8;\n");
5961         commonBuiltins.append("const int gl_SemanticsMakeAvailable   = 0x2000;\n");
5962         commonBuiltins.append("const int gl_SemanticsMakeVisible     = 0x4000;\n");
5963         commonBuiltins.append("const int gl_SemanticsVolatile        = 0x8000;\n");
5964 
5965         commonBuiltins.append("const int gl_StorageSemanticsNone     = 0x0;\n");
5966         commonBuiltins.append("const int gl_StorageSemanticsBuffer   = 0x40;\n");
5967         commonBuiltins.append("const int gl_StorageSemanticsShared   = 0x100;\n");
5968         commonBuiltins.append("const int gl_StorageSemanticsImage    = 0x800;\n");
5969         commonBuiltins.append("const int gl_StorageSemanticsOutput   = 0x1000;\n");
5970     }
5971 
5972     // Adding these to common built-ins triggers an assert due to a memory corruption in related code when testing
5973     // So instead add to each stage individually, avoiding the GLSLang bug
5974     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
5975         for (int stage=EShLangVertex; stage<EShLangCount; stage++)
5976         {
5977             stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag2VerticalPixelsEXT       = 1;\n");
5978             stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag4VerticalPixelsEXT       = 2;\n");
5979             stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag2HorizontalPixelsEXT     = 4;\n");
5980             stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag4HorizontalPixelsEXT     = 8;\n");
5981         }
5982     }
5983 
5984     // GL_EXT_shader_image_int64
5985     if ((profile != EEsProfile && version >= 420) ||
5986         (profile == EEsProfile && version >= 310)) {
5987 
5988         const TBasicType bTypes[] = { EbtInt64, EbtUint64 };
5989         for (int ms = 0; ms <= 1; ++ms) { // loop over "bool" multisample or not
5990             for (int arrayed = 0; arrayed <= 1; ++arrayed) { // loop over "bool" arrayed or not
5991                 for (int dim = Esd1D; dim < EsdSubpass; ++dim) { // 1D, ..., buffer
5992                     if ((dim == Esd1D || dim == EsdRect) && profile == EEsProfile)
5993                         continue;
5994 
5995                     if ((dim == Esd3D || dim == EsdRect || dim == EsdBuffer) && arrayed)
5996                         continue;
5997 
5998                     if (dim != Esd2D && ms)
5999                         continue;
6000 
6001                     // Loop over the bTypes
6002                     for (size_t bType = 0; bType < sizeof(bTypes)/sizeof(TBasicType); ++bType) {
6003                         //
6004                         // Now, make all the function prototypes for the type we just built...
6005                         //
6006                         TSampler sampler;
6007 
6008                         sampler.setImage(bTypes[bType], (TSamplerDim)dim, arrayed ? true : false,
6009                                                                           false,
6010                                                                           ms      ? true : false);
6011 
6012                         TString typeName = sampler.getString();
6013 
6014                         addQueryFunctions(sampler, typeName, version, profile);
6015                         addImageFunctions(sampler, typeName, version, profile);
6016                     }
6017                 }
6018             }
6019         }
6020     }
6021 #endif // !GLSLANG_ANGLE
6022 
6023 #endif // !GLSLANG_WEB
6024 
6025     // printf("%s\n", commonBuiltins.c_str());
6026     // printf("%s\n", stageBuiltins[EShLangFragment].c_str());
6027 }
6028 
6029 //
6030 // Helper function for initialize(), to add the second set of names for texturing,
6031 // when adding context-independent built-in functions.
6032 //
add2ndGenerationSamplingImaging(int version,EProfile profile,const SpvVersion & spvVersion)6033 void TBuiltIns::add2ndGenerationSamplingImaging(int version, EProfile profile, const SpvVersion& spvVersion)
6034 {
6035     //
6036     // In this function proper, enumerate the types, then calls the next set of functions
6037     // to enumerate all the uses for that type.
6038     //
6039 
6040     // enumerate all the types
6041     const TBasicType bTypes[] = { EbtFloat, EbtInt, EbtUint,
6042 #if !defined(GLSLANG_WEB) && !defined(GLSLANG_ANGLE)
6043         EbtFloat16
6044 #endif
6045     };
6046 #ifdef GLSLANG_WEB
6047     bool skipBuffer = true;
6048     bool skipCubeArrayed = true;
6049     const int image = 0;
6050 #else
6051     bool skipBuffer = (profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 140);
6052     bool skipCubeArrayed = (profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 130);
6053     for (int image = 0; image <= 1; ++image) // loop over "bool" image vs sampler
6054 #endif
6055     {
6056         for (int shadow = 0; shadow <= 1; ++shadow) { // loop over "bool" shadow or not
6057 #ifdef GLSLANG_WEB
6058             const int ms = 0;
6059 #else
6060             for (int ms = 0; ms <= 1; ++ms) // loop over "bool" multisample or not
6061 #endif
6062             {
6063                 if ((ms || image) && shadow)
6064                     continue;
6065                 if (ms && profile != EEsProfile && version < 150)
6066                     continue;
6067                 if (ms && image && profile == EEsProfile)
6068                     continue;
6069                 if (ms && profile == EEsProfile && version < 310)
6070                     continue;
6071 
6072                 for (int arrayed = 0; arrayed <= 1; ++arrayed) { // loop over "bool" arrayed or not
6073 #ifdef GLSLANG_WEB
6074                     for (int dim = Esd2D; dim <= EsdCube; ++dim) { // 2D, 3D, and Cube
6075 #else
6076 #if defined(GLSLANG_ANGLE)
6077                     for (int dim = Esd2D; dim < EsdNumDims; ++dim) { // 2D, ..., buffer, subpass
6078 #else
6079                     for (int dim = Esd1D; dim < EsdNumDims; ++dim) { // 1D, ..., buffer, subpass
6080 #endif
6081                         if (dim == EsdSubpass && spvVersion.vulkan == 0)
6082                             continue;
6083                         if (dim == EsdSubpass && (image || shadow || arrayed))
6084                             continue;
6085                         if ((dim == Esd1D || dim == EsdRect) && profile == EEsProfile)
6086                             continue;
6087                         if (dim == EsdSubpass && spvVersion.vulkan == 0)
6088                             continue;
6089                         if (dim == EsdSubpass && (image || shadow || arrayed))
6090                             continue;
6091                         if ((dim == Esd1D || dim == EsdRect) && profile == EEsProfile)
6092                             continue;
6093                         if (dim != Esd2D && dim != EsdSubpass && ms)
6094                             continue;
6095                         if (dim == EsdBuffer && skipBuffer)
6096                             continue;
6097                         if (dim == EsdBuffer && (shadow || arrayed || ms))
6098                             continue;
6099                         if (ms && arrayed && profile == EEsProfile && version < 310)
6100                             continue;
6101 #endif
6102                         if (dim == Esd3D && shadow)
6103                             continue;
6104                         if (dim == EsdCube && arrayed && skipCubeArrayed)
6105                             continue;
6106                         if ((dim == Esd3D || dim == EsdRect) && arrayed)
6107                             continue;
6108 
6109                         // Loop over the bTypes
6110                         for (size_t bType = 0; bType < sizeof(bTypes)/sizeof(TBasicType); ++bType) {
6111 #ifndef GLSLANG_WEB
6112                             if (bTypes[bType] == EbtFloat16 && (profile == EEsProfile || version < 450))
6113                                 continue;
6114                             if (dim == EsdRect && version < 140 && bType > 0)
6115                                 continue;
6116 #endif
6117                             if (shadow && (bTypes[bType] == EbtInt || bTypes[bType] == EbtUint))
6118                                 continue;
6119                             //
6120                             // Now, make all the function prototypes for the type we just built...
6121                             //
6122                             TSampler sampler;
6123 #ifndef GLSLANG_WEB
6124                             if (dim == EsdSubpass) {
6125                                 sampler.setSubpass(bTypes[bType], ms ? true : false);
6126                             } else
6127 #endif
6128                             if (image) {
6129                                 sampler.setImage(bTypes[bType], (TSamplerDim)dim, arrayed ? true : false,
6130                                                                                   shadow  ? true : false,
6131                                                                                   ms      ? true : false);
6132                             } else {
6133                                 sampler.set(bTypes[bType], (TSamplerDim)dim, arrayed ? true : false,
6134                                                                              shadow  ? true : false,
6135                                                                              ms      ? true : false);
6136                             }
6137 
6138                             TString typeName = sampler.getString();
6139 
6140 #ifndef GLSLANG_WEB
6141                             if (dim == EsdSubpass) {
6142                                 addSubpassSampling(sampler, typeName, version, profile);
6143                                 continue;
6144                             }
6145 #endif
6146 
6147                             addQueryFunctions(sampler, typeName, version, profile);
6148 
6149                             if (image)
6150                                 addImageFunctions(sampler, typeName, version, profile);
6151                             else {
6152                                 addSamplingFunctions(sampler, typeName, version, profile);
6153 #ifndef GLSLANG_WEB
6154                                 addGatherFunctions(sampler, typeName, version, profile);
6155                                 if (spvVersion.vulkan > 0 && sampler.isCombined() && !sampler.shadow) {
6156                                     // Base Vulkan allows texelFetch() for
6157                                     // textureBuffer (i.e. without sampler).
6158                                     //
6159                                     // GL_EXT_samplerless_texture_functions
6160                                     // allows texelFetch() and query functions
6161                                     // (other than textureQueryLod()) for all
6162                                     // texture types.
6163                                     sampler.setTexture(sampler.type, sampler.dim, sampler.arrayed, sampler.shadow,
6164                                                        sampler.ms);
6165                                     TString textureTypeName = sampler.getString();
6166                                     addSamplingFunctions(sampler, textureTypeName, version, profile);
6167                                     addQueryFunctions(sampler, textureTypeName, version, profile);
6168                                 }
6169 #endif
6170                             }
6171                         }
6172                     }
6173                 }
6174             }
6175         }
6176     }
6177 
6178     //
6179     // sparseTexelsResidentARB()
6180     //
6181     if (profile != EEsProfile && version >= 450) {
6182         commonBuiltins.append("bool sparseTexelsResidentARB(int code);\n");
6183     }
6184 }
6185 
6186 //
6187 // Helper function for add2ndGenerationSamplingImaging(),
6188 // when adding context-independent built-in functions.
6189 //
6190 // Add all the query functions for the given type.
6191 //
6192 void TBuiltIns::addQueryFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
6193 {
6194     //
6195     // textureSize() and imageSize()
6196     //
6197 
6198     int sizeDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0) - (sampler.dim == EsdCube ? 1 : 0);
6199 
6200 #ifdef GLSLANG_WEB
6201     commonBuiltins.append("highp ");
6202     commonBuiltins.append("ivec");
6203     commonBuiltins.append(postfixes[sizeDims]);
6204     commonBuiltins.append(" textureSize(");
6205     commonBuiltins.append(typeName);
6206     commonBuiltins.append(",int);\n");
6207     return;
6208 #endif
6209 
6210     if (sampler.isImage() && ((profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 420)))
6211         return;
6212 
6213     if (profile == EEsProfile)
6214         commonBuiltins.append("highp ");
6215     if (sizeDims == 1)
6216         commonBuiltins.append("int");
6217     else {
6218         commonBuiltins.append("ivec");
6219         commonBuiltins.append(postfixes[sizeDims]);
6220     }
6221     if (sampler.isImage())
6222         commonBuiltins.append(" imageSize(readonly writeonly volatile coherent ");
6223     else
6224         commonBuiltins.append(" textureSize(");
6225     commonBuiltins.append(typeName);
6226     if (! sampler.isImage() && ! sampler.isRect() && ! sampler.isBuffer() && ! sampler.isMultiSample())
6227         commonBuiltins.append(",int);\n");
6228     else
6229         commonBuiltins.append(");\n");
6230 
6231     //
6232     // textureSamples() and imageSamples()
6233     //
6234 
6235     // GL_ARB_shader_texture_image_samples
6236     // TODO: spec issue? there are no memory qualifiers; how to query a writeonly/readonly image, etc?
6237     if (profile != EEsProfile && version >= 430 && sampler.isMultiSample()) {
6238         commonBuiltins.append("int ");
6239         if (sampler.isImage())
6240             commonBuiltins.append("imageSamples(readonly writeonly volatile coherent ");
6241         else
6242             commonBuiltins.append("textureSamples(");
6243         commonBuiltins.append(typeName);
6244         commonBuiltins.append(");\n");
6245     }
6246 
6247     //
6248     // textureQueryLod(), fragment stage only
6249     // Also enabled with extension GL_ARB_texture_query_lod
6250 
6251     if (profile != EEsProfile && version >= 150 && sampler.isCombined() && sampler.dim != EsdRect &&
6252         ! sampler.isMultiSample() && ! sampler.isBuffer()) {
6253         for (int f16TexAddr = 0; f16TexAddr < 2; ++f16TexAddr) {
6254             if (f16TexAddr && sampler.type != EbtFloat16)
6255                 continue;
6256             stageBuiltins[EShLangFragment].append("vec2 textureQueryLod(");
6257             stageBuiltins[EShLangFragment].append(typeName);
6258             if (dimMap[sampler.dim] == 1)
6259                 if (f16TexAddr)
6260                     stageBuiltins[EShLangFragment].append(", float16_t");
6261                 else
6262                     stageBuiltins[EShLangFragment].append(", float");
6263             else {
6264                 if (f16TexAddr)
6265                     stageBuiltins[EShLangFragment].append(", f16vec");
6266                 else
6267                     stageBuiltins[EShLangFragment].append(", vec");
6268                 stageBuiltins[EShLangFragment].append(postfixes[dimMap[sampler.dim]]);
6269             }
6270             stageBuiltins[EShLangFragment].append(");\n");
6271         }
6272 
6273         stageBuiltins[EShLangCompute].append("vec2 textureQueryLod(");
6274         stageBuiltins[EShLangCompute].append(typeName);
6275         if (dimMap[sampler.dim] == 1)
6276             stageBuiltins[EShLangCompute].append(", float");
6277         else {
6278             stageBuiltins[EShLangCompute].append(", vec");
6279             stageBuiltins[EShLangCompute].append(postfixes[dimMap[sampler.dim]]);
6280         }
6281         stageBuiltins[EShLangCompute].append(");\n");
6282     }
6283 
6284     //
6285     // textureQueryLevels()
6286     //
6287 
6288     if (profile != EEsProfile && version >= 430 && ! sampler.isImage() && sampler.dim != EsdRect &&
6289         ! sampler.isMultiSample() && ! sampler.isBuffer()) {
6290         commonBuiltins.append("int textureQueryLevels(");
6291         commonBuiltins.append(typeName);
6292         commonBuiltins.append(");\n");
6293     }
6294 }
6295 
6296 //
6297 // Helper function for add2ndGenerationSamplingImaging(),
6298 // when adding context-independent built-in functions.
6299 //
6300 // Add all the image access functions for the given type.
6301 //
6302 void TBuiltIns::addImageFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
6303 {
6304     int dims = dimMap[sampler.dim];
6305     // most things with an array add a dimension, except for cubemaps
6306     if (sampler.arrayed && sampler.dim != EsdCube)
6307         ++dims;
6308 
6309     TString imageParams = typeName;
6310     if (dims == 1)
6311         imageParams.append(", int");
6312     else {
6313         imageParams.append(", ivec");
6314         imageParams.append(postfixes[dims]);
6315     }
6316     if (sampler.isMultiSample())
6317         imageParams.append(", int");
6318 
6319     if (profile == EEsProfile)
6320         commonBuiltins.append("highp ");
6321     commonBuiltins.append(prefixes[sampler.type]);
6322     commonBuiltins.append("vec4 imageLoad(readonly volatile coherent ");
6323     commonBuiltins.append(imageParams);
6324     commonBuiltins.append(");\n");
6325 
6326     commonBuiltins.append("void imageStore(writeonly volatile coherent ");
6327     commonBuiltins.append(imageParams);
6328     commonBuiltins.append(", ");
6329     commonBuiltins.append(prefixes[sampler.type]);
6330     commonBuiltins.append("vec4);\n");
6331 
6332     if (! sampler.is1D() && ! sampler.isBuffer() && profile != EEsProfile && version >= 450) {
6333         commonBuiltins.append("int sparseImageLoadARB(readonly volatile coherent ");
6334         commonBuiltins.append(imageParams);
6335         commonBuiltins.append(", out ");
6336         commonBuiltins.append(prefixes[sampler.type]);
6337         commonBuiltins.append("vec4");
6338         commonBuiltins.append(");\n");
6339     }
6340 
6341     if ( profile != EEsProfile ||
6342         (profile == EEsProfile && version >= 310)) {
6343         if (sampler.type == EbtInt || sampler.type == EbtUint || sampler.type == EbtInt64 || sampler.type == EbtUint64 ) {
6344 
6345             const char* dataType;
6346             switch (sampler.type) {
6347                 case(EbtInt): dataType = "highp int"; break;
6348                 case(EbtUint): dataType = "highp uint"; break;
6349                 case(EbtInt64): dataType = "highp int64_t"; break;
6350                 case(EbtUint64): dataType = "highp uint64_t"; break;
6351                 default: dataType = "";
6352             }
6353 
6354             const int numBuiltins = 7;
6355 
6356             static const char* atomicFunc[numBuiltins] = {
6357                 " imageAtomicAdd(volatile coherent ",
6358                 " imageAtomicMin(volatile coherent ",
6359                 " imageAtomicMax(volatile coherent ",
6360                 " imageAtomicAnd(volatile coherent ",
6361                 " imageAtomicOr(volatile coherent ",
6362                 " imageAtomicXor(volatile coherent ",
6363                 " imageAtomicExchange(volatile coherent "
6364             };
6365 
6366             // Loop twice to add prototypes with/without scope/semantics
6367             for (int j = 0; j < 2; ++j) {
6368                 for (size_t i = 0; i < numBuiltins; ++i) {
6369                     commonBuiltins.append(dataType);
6370                     commonBuiltins.append(atomicFunc[i]);
6371                     commonBuiltins.append(imageParams);
6372                     commonBuiltins.append(", ");
6373                     commonBuiltins.append(dataType);
6374                     if (j == 1) {
6375                         commonBuiltins.append(", int, int, int");
6376                     }
6377                     commonBuiltins.append(");\n");
6378                 }
6379 
6380                 commonBuiltins.append(dataType);
6381                 commonBuiltins.append(" imageAtomicCompSwap(volatile coherent ");
6382                 commonBuiltins.append(imageParams);
6383                 commonBuiltins.append(", ");
6384                 commonBuiltins.append(dataType);
6385                 commonBuiltins.append(", ");
6386                 commonBuiltins.append(dataType);
6387                 if (j == 1) {
6388                     commonBuiltins.append(", int, int, int, int, int");
6389                 }
6390                 commonBuiltins.append(");\n");
6391             }
6392 
6393             commonBuiltins.append(dataType);
6394             commonBuiltins.append(" imageAtomicLoad(volatile coherent ");
6395             commonBuiltins.append(imageParams);
6396             commonBuiltins.append(", int, int, int);\n");
6397 
6398             commonBuiltins.append("void imageAtomicStore(volatile coherent ");
6399             commonBuiltins.append(imageParams);
6400             commonBuiltins.append(", ");
6401             commonBuiltins.append(dataType);
6402             commonBuiltins.append(", int, int, int);\n");
6403 
6404         } else {
6405             // not int or uint
6406             // GL_ARB_ES3_1_compatibility
6407             // TODO: spec issue: are there restrictions on the kind of layout() that can be used?  what about dropping memory qualifiers?
6408             if (profile == EEsProfile && version >= 310) {
6409                 commonBuiltins.append("float imageAtomicExchange(volatile coherent ");
6410                 commonBuiltins.append(imageParams);
6411                 commonBuiltins.append(", float);\n");
6412             }
6413             if (profile != EEsProfile && version >= 450) {
6414                 commonBuiltins.append("float imageAtomicAdd(volatile coherent ");
6415                 commonBuiltins.append(imageParams);
6416                 commonBuiltins.append(", float);\n");
6417 
6418                 commonBuiltins.append("float imageAtomicAdd(volatile coherent ");
6419                 commonBuiltins.append(imageParams);
6420                 commonBuiltins.append(", float");
6421                 commonBuiltins.append(", int, int, int);\n");
6422 
6423                 commonBuiltins.append("float imageAtomicExchange(volatile coherent ");
6424                 commonBuiltins.append(imageParams);
6425                 commonBuiltins.append(", float);\n");
6426 
6427                 commonBuiltins.append("float imageAtomicExchange(volatile coherent ");
6428                 commonBuiltins.append(imageParams);
6429                 commonBuiltins.append(", float");
6430                 commonBuiltins.append(", int, int, int);\n");
6431 
6432                 commonBuiltins.append("float imageAtomicLoad(readonly volatile coherent ");
6433                 commonBuiltins.append(imageParams);
6434                 commonBuiltins.append(", int, int, int);\n");
6435 
6436                 commonBuiltins.append("void imageAtomicStore(writeonly volatile coherent ");
6437                 commonBuiltins.append(imageParams);
6438                 commonBuiltins.append(", float");
6439                 commonBuiltins.append(", int, int, int);\n");
6440 
6441                 commonBuiltins.append("float imageAtomicMin(volatile coherent ");
6442                 commonBuiltins.append(imageParams);
6443                 commonBuiltins.append(", float);\n");
6444 
6445                 commonBuiltins.append("float imageAtomicMin(volatile coherent ");
6446                 commonBuiltins.append(imageParams);
6447                 commonBuiltins.append(", float");
6448                 commonBuiltins.append(", int, int, int);\n");
6449 
6450                 commonBuiltins.append("float imageAtomicMax(volatile coherent ");
6451                 commonBuiltins.append(imageParams);
6452                 commonBuiltins.append(", float);\n");
6453 
6454                 commonBuiltins.append("float imageAtomicMax(volatile coherent ");
6455                 commonBuiltins.append(imageParams);
6456                 commonBuiltins.append(", float");
6457                 commonBuiltins.append(", int, int, int);\n");
6458             }
6459         }
6460     }
6461 
6462     if (sampler.dim == EsdRect || sampler.dim == EsdBuffer || sampler.shadow || sampler.isMultiSample())
6463         return;
6464 
6465     if (profile == EEsProfile || version < 450)
6466         return;
6467 
6468     TString imageLodParams = typeName;
6469     if (dims == 1)
6470         imageLodParams.append(", int");
6471     else {
6472         imageLodParams.append(", ivec");
6473         imageLodParams.append(postfixes[dims]);
6474     }
6475     imageLodParams.append(", int");
6476 
6477     commonBuiltins.append(prefixes[sampler.type]);
6478     commonBuiltins.append("vec4 imageLoadLodAMD(readonly volatile coherent ");
6479     commonBuiltins.append(imageLodParams);
6480     commonBuiltins.append(");\n");
6481 
6482     commonBuiltins.append("void imageStoreLodAMD(writeonly volatile coherent ");
6483     commonBuiltins.append(imageLodParams);
6484     commonBuiltins.append(", ");
6485     commonBuiltins.append(prefixes[sampler.type]);
6486     commonBuiltins.append("vec4);\n");
6487 
6488     if (! sampler.is1D()) {
6489         commonBuiltins.append("int sparseImageLoadLodAMD(readonly volatile coherent ");
6490         commonBuiltins.append(imageLodParams);
6491         commonBuiltins.append(", out ");
6492         commonBuiltins.append(prefixes[sampler.type]);
6493         commonBuiltins.append("vec4");
6494         commonBuiltins.append(");\n");
6495     }
6496 }
6497 
6498 //
6499 // Helper function for initialize(),
6500 // when adding context-independent built-in functions.
6501 //
6502 // Add all the subpass access functions for the given type.
6503 //
6504 void TBuiltIns::addSubpassSampling(TSampler sampler, const TString& typeName, int /*version*/, EProfile /*profile*/)
6505 {
6506     stageBuiltins[EShLangFragment].append(prefixes[sampler.type]);
6507     stageBuiltins[EShLangFragment].append("vec4 subpassLoad");
6508     stageBuiltins[EShLangFragment].append("(");
6509     stageBuiltins[EShLangFragment].append(typeName.c_str());
6510     if (sampler.isMultiSample())
6511         stageBuiltins[EShLangFragment].append(", int");
6512     stageBuiltins[EShLangFragment].append(");\n");
6513 }
6514 
6515 //
6516 // Helper function for add2ndGenerationSamplingImaging(),
6517 // when adding context-independent built-in functions.
6518 //
6519 // Add all the texture lookup functions for the given type.
6520 //
6521 void TBuiltIns::addSamplingFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
6522 {
6523 #ifdef GLSLANG_WEB
6524     profile = EEsProfile;
6525     version = 310;
6526 #elif defined(GLSLANG_ANGLE)
6527     profile = ECoreProfile;
6528     version = 450;
6529 #endif
6530 
6531     //
6532     // texturing
6533     //
6534     for (int proj = 0; proj <= 1; ++proj) { // loop over "bool" projective or not
6535 
6536         if (proj && (sampler.dim == EsdCube || sampler.isBuffer() || sampler.arrayed || sampler.isMultiSample()
6537             || !sampler.isCombined()))
6538             continue;
6539 
6540         for (int lod = 0; lod <= 1; ++lod) {
6541 
6542             if (lod && (sampler.isBuffer() || sampler.isRect() || sampler.isMultiSample() || !sampler.isCombined()))
6543                 continue;
6544             if (lod && sampler.dim == Esd2D && sampler.arrayed && sampler.shadow)
6545                 continue;
6546             if (lod && sampler.dim == EsdCube && sampler.shadow)
6547                 continue;
6548 
6549             for (int bias = 0; bias <= 1; ++bias) {
6550 
6551                 if (bias && (lod || sampler.isMultiSample() || !sampler.isCombined()))
6552                     continue;
6553                 if (bias && (sampler.dim == Esd2D || sampler.dim == EsdCube) && sampler.shadow && sampler.arrayed)
6554                     continue;
6555                 if (bias && (sampler.isRect() || sampler.isBuffer()))
6556                     continue;
6557 
6558                 for (int offset = 0; offset <= 1; ++offset) { // loop over "bool" offset or not
6559 
6560                     if (proj + offset + bias + lod > 3)
6561                         continue;
6562                     if (offset && (sampler.dim == EsdCube || sampler.isBuffer() || sampler.isMultiSample()))
6563                         continue;
6564 
6565                     for (int fetch = 0; fetch <= 1; ++fetch) { // loop over "bool" fetch or not
6566 
6567                         if (proj + offset + fetch + bias + lod > 3)
6568                             continue;
6569                         if (fetch && (lod || bias))
6570                             continue;
6571                         if (fetch && (sampler.shadow || sampler.dim == EsdCube))
6572                             continue;
6573                         if (fetch == 0 && (sampler.isMultiSample() || sampler.isBuffer()
6574                             || !sampler.isCombined()))
6575                             continue;
6576 
6577                         for (int grad = 0; grad <= 1; ++grad) { // loop over "bool" grad or not
6578 
6579                             if (grad && (lod || bias || sampler.isMultiSample() || !sampler.isCombined()))
6580                                 continue;
6581                             if (grad && sampler.isBuffer())
6582                                 continue;
6583                             if (proj + offset + fetch + grad + bias + lod > 3)
6584                                 continue;
6585 
6586                             for (int extraProj = 0; extraProj <= 1; ++extraProj) {
6587                                 bool compare = false;
6588                                 int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0);
6589                                 // skip dummy unused second component for 1D non-array shadows
6590                                 if (sampler.shadow && totalDims < 2)
6591                                     totalDims = 2;
6592                                 totalDims += (sampler.shadow ? 1 : 0) + proj;
6593                                 if (totalDims > 4 && sampler.shadow) {
6594                                     compare = true;
6595                                     totalDims = 4;
6596                                 }
6597                                 assert(totalDims <= 4);
6598 
6599                                 if (extraProj && ! proj)
6600                                     continue;
6601                                 if (extraProj && (sampler.dim == Esd3D || sampler.shadow || !sampler.isCombined()))
6602                                     continue;
6603 
6604                                 // loop over 16-bit floating-point texel addressing
6605 #if defined(GLSLANG_WEB) || defined(GLSLANG_ANGLE)
6606                                 const int f16TexAddr = 0;
6607 #else
6608                                 for (int f16TexAddr = 0; f16TexAddr <= 1; ++f16TexAddr)
6609 #endif
6610                                 {
6611                                     if (f16TexAddr && sampler.type != EbtFloat16)
6612                                         continue;
6613                                     if (f16TexAddr && sampler.shadow && ! compare) {
6614                                         compare = true; // compare argument is always present
6615                                         totalDims--;
6616                                     }
6617                                     // loop over "bool" lod clamp
6618 #if defined(GLSLANG_WEB) || defined(GLSLANG_ANGLE)
6619                                     const int lodClamp = 0;
6620 #else
6621                                     for (int lodClamp = 0; lodClamp <= 1 ;++lodClamp)
6622 #endif
6623                                     {
6624                                         if (lodClamp && (profile == EEsProfile || version < 450))
6625                                             continue;
6626                                         if (lodClamp && (proj || lod || fetch))
6627                                             continue;
6628 
6629                                         // loop over "bool" sparse or not
6630 #if defined(GLSLANG_WEB) || defined(GLSLANG_ANGLE)
6631                                         const int sparse = 0;
6632 #else
6633                                         for (int sparse = 0; sparse <= 1; ++sparse)
6634 #endif
6635                                         {
6636                                             if (sparse && (profile == EEsProfile || version < 450))
6637                                                 continue;
6638                                             // Sparse sampling is not for 1D/1D array texture, buffer texture, and
6639                                             // projective texture
6640                                             if (sparse && (sampler.is1D() || sampler.isBuffer() || proj))
6641                                                 continue;
6642 
6643                                             TString s;
6644 
6645                                             // return type
6646                                             if (sparse)
6647                                                 s.append("int ");
6648                                             else {
6649                                                 if (sampler.shadow)
6650                                                     if (sampler.type == EbtFloat16)
6651                                                         s.append("float16_t ");
6652                                                     else
6653                                                         s.append("float ");
6654                                                 else {
6655                                                     s.append(prefixes[sampler.type]);
6656                                                     s.append("vec4 ");
6657                                                 }
6658                                             }
6659 
6660                                             // name
6661                                             if (sparse) {
6662                                                 if (fetch)
6663                                                     s.append("sparseTexel");
6664                                                 else
6665                                                     s.append("sparseTexture");
6666                                             }
6667                                             else {
6668                                                 if (fetch)
6669                                                     s.append("texel");
6670                                                 else
6671                                                     s.append("texture");
6672                                             }
6673                                             if (proj)
6674                                                 s.append("Proj");
6675                                             if (lod)
6676                                                 s.append("Lod");
6677                                             if (grad)
6678                                                 s.append("Grad");
6679                                             if (fetch)
6680                                                 s.append("Fetch");
6681                                             if (offset)
6682                                                 s.append("Offset");
6683                                             if (lodClamp)
6684                                                 s.append("Clamp");
6685                                             if (lodClamp != 0 || sparse)
6686                                                 s.append("ARB");
6687                                             s.append("(");
6688 
6689                                             // sampler type
6690                                             s.append(typeName);
6691                                             // P coordinate
6692                                             if (extraProj) {
6693                                                 if (f16TexAddr)
6694                                                     s.append(",f16vec4");
6695                                                 else
6696                                                     s.append(",vec4");
6697                                             } else {
6698                                                 s.append(",");
6699                                                 TBasicType t = fetch ? EbtInt : (f16TexAddr ? EbtFloat16 : EbtFloat);
6700                                                 if (totalDims == 1)
6701                                                     s.append(TType::getBasicString(t));
6702                                                 else {
6703                                                     s.append(prefixes[t]);
6704                                                     s.append("vec");
6705                                                     s.append(postfixes[totalDims]);
6706                                                 }
6707                                             }
6708                                             // non-optional compare
6709                                             if (compare)
6710                                                 s.append(",float");
6711 
6712                                             // non-optional lod argument (lod that's not driven by lod loop) or sample
6713                                             if ((fetch && !sampler.isBuffer() &&
6714                                                  !sampler.isRect() && !sampler.isMultiSample())
6715                                                  || (sampler.isMultiSample() && fetch))
6716                                                 s.append(",int");
6717                                             // non-optional lod
6718                                             if (lod) {
6719                                                 if (f16TexAddr)
6720                                                     s.append(",float16_t");
6721                                                 else
6722                                                     s.append(",float");
6723                                             }
6724 
6725                                             // gradient arguments
6726                                             if (grad) {
6727                                                 if (dimMap[sampler.dim] == 1) {
6728                                                     if (f16TexAddr)
6729                                                         s.append(",float16_t,float16_t");
6730                                                     else
6731                                                         s.append(",float,float");
6732                                                 } else {
6733                                                     if (f16TexAddr)
6734                                                         s.append(",f16vec");
6735                                                     else
6736                                                         s.append(",vec");
6737                                                     s.append(postfixes[dimMap[sampler.dim]]);
6738                                                     if (f16TexAddr)
6739                                                         s.append(",f16vec");
6740                                                     else
6741                                                         s.append(",vec");
6742                                                     s.append(postfixes[dimMap[sampler.dim]]);
6743                                                 }
6744                                             }
6745                                             // offset
6746                                             if (offset) {
6747                                                 if (dimMap[sampler.dim] == 1)
6748                                                     s.append(",int");
6749                                                 else {
6750                                                     s.append(",ivec");
6751                                                     s.append(postfixes[dimMap[sampler.dim]]);
6752                                                 }
6753                                             }
6754 
6755                                             // lod clamp
6756                                             if (lodClamp) {
6757                                                 if (f16TexAddr)
6758                                                     s.append(",float16_t");
6759                                                 else
6760                                                     s.append(",float");
6761                                             }
6762                                             // texel out (for sparse texture)
6763                                             if (sparse) {
6764                                                 s.append(",out ");
6765                                                 if (sampler.shadow)
6766                                                     if (sampler.type == EbtFloat16)
6767                                                         s.append("float16_t");
6768                                                     else
6769                                                         s.append("float");
6770                                                 else {
6771                                                     s.append(prefixes[sampler.type]);
6772                                                     s.append("vec4");
6773                                                 }
6774                                             }
6775                                             // optional bias
6776                                             if (bias) {
6777                                                 if (f16TexAddr)
6778                                                     s.append(",float16_t");
6779                                                 else
6780                                                     s.append(",float");
6781                                             }
6782                                             s.append(");\n");
6783 
6784                                             // Add to the per-language set of built-ins
6785                                             if (!grad && (bias || lodClamp != 0)) {
6786                                                 stageBuiltins[EShLangFragment].append(s);
6787                                                 stageBuiltins[EShLangCompute].append(s);
6788                                             } else
6789                                                 commonBuiltins.append(s);
6790 
6791                                         }
6792                                     }
6793                                 }
6794                             }
6795                         }
6796                     }
6797                 }
6798             }
6799         }
6800     }
6801 }
6802 
6803 //
6804 // Helper function for add2ndGenerationSamplingImaging(),
6805 // when adding context-independent built-in functions.
6806 //
6807 // Add all the texture gather functions for the given type.
6808 //
6809 void TBuiltIns::addGatherFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
6810 {
6811 #ifdef GLSLANG_WEB
6812     profile = EEsProfile;
6813     version = 310;
6814 #elif defined(GLSLANG_ANGLE)
6815     profile = ECoreProfile;
6816     version = 450;
6817 #endif
6818 
6819     switch (sampler.dim) {
6820     case Esd2D:
6821     case EsdRect:
6822     case EsdCube:
6823         break;
6824     default:
6825         return;
6826     }
6827 
6828     if (sampler.isMultiSample())
6829         return;
6830 
6831     if (version < 140 && sampler.dim == EsdRect && sampler.type != EbtFloat)
6832         return;
6833 
6834     for (int f16TexAddr = 0; f16TexAddr <= 1; ++f16TexAddr) { // loop over 16-bit floating-point texel addressing
6835 
6836         if (f16TexAddr && sampler.type != EbtFloat16)
6837             continue;
6838         for (int offset = 0; offset < 3; ++offset) { // loop over three forms of offset in the call name:  none, Offset, and Offsets
6839 
6840             for (int comp = 0; comp < 2; ++comp) { // loop over presence of comp argument
6841 
6842                 if (comp > 0 && sampler.shadow)
6843                     continue;
6844 
6845                 if (offset > 0 && sampler.dim == EsdCube)
6846                     continue;
6847 
6848                 for (int sparse = 0; sparse <= 1; ++sparse) { // loop over "bool" sparse or not
6849                     if (sparse && (profile == EEsProfile || version < 450))
6850                         continue;
6851 
6852                     TString s;
6853 
6854                     // return type
6855                     if (sparse)
6856                         s.append("int ");
6857                     else {
6858                         s.append(prefixes[sampler.type]);
6859                         s.append("vec4 ");
6860                     }
6861 
6862                     // name
6863                     if (sparse)
6864                         s.append("sparseTextureGather");
6865                     else
6866                         s.append("textureGather");
6867                     switch (offset) {
6868                     case 1:
6869                         s.append("Offset");
6870                         break;
6871                     case 2:
6872                         s.append("Offsets");
6873                         break;
6874                     default:
6875                         break;
6876                     }
6877                     if (sparse)
6878                         s.append("ARB");
6879                     s.append("(");
6880 
6881                     // sampler type argument
6882                     s.append(typeName);
6883 
6884                     // P coordinate argument
6885                     if (f16TexAddr)
6886                         s.append(",f16vec");
6887                     else
6888                         s.append(",vec");
6889                     int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0);
6890                     s.append(postfixes[totalDims]);
6891 
6892                     // refZ argument
6893                     if (sampler.shadow)
6894                         s.append(",float");
6895 
6896                     // offset argument
6897                     if (offset > 0) {
6898                         s.append(",ivec2");
6899                         if (offset == 2)
6900                             s.append("[4]");
6901                     }
6902 
6903                     // texel out (for sparse texture)
6904                     if (sparse) {
6905                         s.append(",out ");
6906                         s.append(prefixes[sampler.type]);
6907                         s.append("vec4 ");
6908                     }
6909 
6910                     // comp argument
6911                     if (comp)
6912                         s.append(",int");
6913 
6914                     s.append(");\n");
6915                     commonBuiltins.append(s);
6916                 }
6917             }
6918         }
6919     }
6920 
6921     if (sampler.dim == EsdRect || sampler.shadow)
6922         return;
6923 
6924     if (profile == EEsProfile || version < 450)
6925         return;
6926 
6927     for (int bias = 0; bias < 2; ++bias) { // loop over presence of bias argument
6928 
6929         for (int lod = 0; lod < 2; ++lod) { // loop over presence of lod argument
6930 
6931             if ((lod && bias) || (lod == 0 && bias == 0))
6932                 continue;
6933 
6934             for (int f16TexAddr = 0; f16TexAddr <= 1; ++f16TexAddr) { // loop over 16-bit floating-point texel addressing
6935 
6936                 if (f16TexAddr && sampler.type != EbtFloat16)
6937                     continue;
6938 
6939                 for (int offset = 0; offset < 3; ++offset) { // loop over three forms of offset in the call name:  none, Offset, and Offsets
6940 
6941                     for (int comp = 0; comp < 2; ++comp) { // loop over presence of comp argument
6942 
6943                         if (comp == 0 && bias)
6944                             continue;
6945 
6946                         if (offset > 0 && sampler.dim == EsdCube)
6947                             continue;
6948 
6949                         for (int sparse = 0; sparse <= 1; ++sparse) { // loop over "bool" sparse or not
6950                             if (sparse && (profile == EEsProfile || version < 450))
6951                                 continue;
6952 
6953                             TString s;
6954 
6955                             // return type
6956                             if (sparse)
6957                                 s.append("int ");
6958                             else {
6959                                 s.append(prefixes[sampler.type]);
6960                                 s.append("vec4 ");
6961                             }
6962 
6963                             // name
6964                             if (sparse)
6965                                 s.append("sparseTextureGather");
6966                             else
6967                                 s.append("textureGather");
6968 
6969                             if (lod)
6970                                 s.append("Lod");
6971 
6972                             switch (offset) {
6973                             case 1:
6974                                 s.append("Offset");
6975                                 break;
6976                             case 2:
6977                                 s.append("Offsets");
6978                                 break;
6979                             default:
6980                                 break;
6981                             }
6982 
6983                             if (lod)
6984                                 s.append("AMD");
6985                             else if (sparse)
6986                                 s.append("ARB");
6987 
6988                             s.append("(");
6989 
6990                             // sampler type argument
6991                             s.append(typeName);
6992 
6993                             // P coordinate argument
6994                             if (f16TexAddr)
6995                                 s.append(",f16vec");
6996                             else
6997                                 s.append(",vec");
6998                             int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0);
6999                             s.append(postfixes[totalDims]);
7000 
7001                             // lod argument
7002                             if (lod) {
7003                                 if (f16TexAddr)
7004                                     s.append(",float16_t");
7005                                 else
7006                                     s.append(",float");
7007                             }
7008 
7009                             // offset argument
7010                             if (offset > 0) {
7011                                 s.append(",ivec2");
7012                                 if (offset == 2)
7013                                     s.append("[4]");
7014                             }
7015 
7016                             // texel out (for sparse texture)
7017                             if (sparse) {
7018                                 s.append(",out ");
7019                                 s.append(prefixes[sampler.type]);
7020                                 s.append("vec4 ");
7021                             }
7022 
7023                             // comp argument
7024                             if (comp)
7025                                 s.append(",int");
7026 
7027                             // bias argument
7028                             if (bias) {
7029                                 if (f16TexAddr)
7030                                     s.append(",float16_t");
7031                                 else
7032                                     s.append(",float");
7033                             }
7034 
7035                             s.append(");\n");
7036                             if (bias)
7037                                 stageBuiltins[EShLangFragment].append(s);
7038                             else
7039                                 commonBuiltins.append(s);
7040                         }
7041                     }
7042                 }
7043             }
7044         }
7045     }
7046 }
7047 
7048 //
7049 // Add context-dependent built-in functions and variables that are present
7050 // for the given version and profile.  All the results are put into just the
7051 // commonBuiltins, because it is called for just a specific stage.  So,
7052 // add stage-specific entries to the commonBuiltins, and only if that stage
7053 // was requested.
7054 //
7055 void TBuiltIns::initialize(const TBuiltInResource &resources, int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language)
7056 {
7057 #ifdef GLSLANG_WEB
7058     version = 310;
7059     profile = EEsProfile;
7060 #elif defined(GLSLANG_ANGLE)
7061     version = 450;
7062     profile = ECoreProfile;
7063 #endif
7064 
7065     //
7066     // Initialize the context-dependent (resource-dependent) built-in strings for parsing.
7067     //
7068 
7069     //============================================================================
7070     //
7071     // Standard Uniforms
7072     //
7073     //============================================================================
7074 
7075     TString& s = commonBuiltins;
7076     const int maxSize = 200;
7077     char builtInConstant[maxSize];
7078 
7079     //
7080     // Build string of implementation dependent constants.
7081     //
7082 
7083     if (profile == EEsProfile) {
7084         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVertexAttribs = %d;", resources.maxVertexAttribs);
7085         s.append(builtInConstant);
7086 
7087         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVertexUniformVectors = %d;", resources.maxVertexUniformVectors);
7088         s.append(builtInConstant);
7089 
7090         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVertexTextureImageUnits = %d;", resources.maxVertexTextureImageUnits);
7091         s.append(builtInConstant);
7092 
7093         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxCombinedTextureImageUnits = %d;", resources.maxCombinedTextureImageUnits);
7094         s.append(builtInConstant);
7095 
7096         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxTextureImageUnits = %d;", resources.maxTextureImageUnits);
7097         s.append(builtInConstant);
7098 
7099         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxFragmentUniformVectors = %d;", resources.maxFragmentUniformVectors);
7100         s.append(builtInConstant);
7101 
7102         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxDrawBuffers = %d;", resources.maxDrawBuffers);
7103         s.append(builtInConstant);
7104 
7105         if (version == 100) {
7106             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVaryingVectors = %d;", resources.maxVaryingVectors);
7107             s.append(builtInConstant);
7108         } else {
7109             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVertexOutputVectors = %d;", resources.maxVertexOutputVectors);
7110             s.append(builtInConstant);
7111 
7112             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxFragmentInputVectors = %d;", resources.maxFragmentInputVectors);
7113             s.append(builtInConstant);
7114 
7115             snprintf(builtInConstant, maxSize, "const mediump int  gl_MinProgramTexelOffset = %d;", resources.minProgramTexelOffset);
7116             s.append(builtInConstant);
7117 
7118             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxProgramTexelOffset = %d;", resources.maxProgramTexelOffset);
7119             s.append(builtInConstant);
7120         }
7121 
7122 #ifndef GLSLANG_WEB
7123         if (version >= 310) {
7124             // geometry
7125 
7126             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryInputComponents = %d;", resources.maxGeometryInputComponents);
7127             s.append(builtInConstant);
7128             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputComponents = %d;", resources.maxGeometryOutputComponents);
7129             s.append(builtInConstant);
7130             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryImageUniforms = %d;", resources.maxGeometryImageUniforms);
7131             s.append(builtInConstant);
7132             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTextureImageUnits = %d;", resources.maxGeometryTextureImageUnits);
7133             s.append(builtInConstant);
7134             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputVertices = %d;", resources.maxGeometryOutputVertices);
7135             s.append(builtInConstant);
7136             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTotalOutputComponents = %d;", resources.maxGeometryTotalOutputComponents);
7137             s.append(builtInConstant);
7138             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryUniformComponents = %d;", resources.maxGeometryUniformComponents);
7139             s.append(builtInConstant);
7140             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounters = %d;", resources.maxGeometryAtomicCounters);
7141             s.append(builtInConstant);
7142             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounterBuffers = %d;", resources.maxGeometryAtomicCounterBuffers);
7143             s.append(builtInConstant);
7144 
7145             // tessellation
7146 
7147             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlInputComponents = %d;", resources.maxTessControlInputComponents);
7148             s.append(builtInConstant);
7149             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlOutputComponents = %d;", resources.maxTessControlOutputComponents);
7150             s.append(builtInConstant);
7151             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTextureImageUnits = %d;", resources.maxTessControlTextureImageUnits);
7152             s.append(builtInConstant);
7153             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlUniformComponents = %d;", resources.maxTessControlUniformComponents);
7154             s.append(builtInConstant);
7155             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTotalOutputComponents = %d;", resources.maxTessControlTotalOutputComponents);
7156             s.append(builtInConstant);
7157 
7158             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationInputComponents = %d;", resources.maxTessEvaluationInputComponents);
7159             s.append(builtInConstant);
7160             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationOutputComponents = %d;", resources.maxTessEvaluationOutputComponents);
7161             s.append(builtInConstant);
7162             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationTextureImageUnits = %d;", resources.maxTessEvaluationTextureImageUnits);
7163             s.append(builtInConstant);
7164             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationUniformComponents = %d;", resources.maxTessEvaluationUniformComponents);
7165             s.append(builtInConstant);
7166 
7167             snprintf(builtInConstant, maxSize, "const int gl_MaxTessPatchComponents = %d;", resources.maxTessPatchComponents);
7168             s.append(builtInConstant);
7169 
7170             snprintf(builtInConstant, maxSize, "const int gl_MaxPatchVertices = %d;", resources.maxPatchVertices);
7171             s.append(builtInConstant);
7172             snprintf(builtInConstant, maxSize, "const int gl_MaxTessGenLevel = %d;", resources.maxTessGenLevel);
7173             s.append(builtInConstant);
7174 
7175             // this is here instead of with the others in initialize(version, profile) due to the dependence on gl_MaxPatchVertices
7176             if (language == EShLangTessControl || language == EShLangTessEvaluation) {
7177                 s.append(
7178                     "in gl_PerVertex {"
7179                         "highp vec4 gl_Position;"
7180                         "highp float gl_PointSize;"
7181                         "highp vec4 gl_SecondaryPositionNV;"  // GL_NV_stereo_view_rendering
7182                         "highp vec4 gl_PositionPerViewNV[];"  // GL_NVX_multiview_per_view_attributes
7183                     "} gl_in[gl_MaxPatchVertices];"
7184                     "\n");
7185             }
7186         }
7187 
7188         if (version >= 320) {
7189             // tessellation
7190 
7191             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlImageUniforms = %d;", resources.maxTessControlImageUniforms);
7192             s.append(builtInConstant);
7193             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationImageUniforms = %d;", resources.maxTessEvaluationImageUniforms);
7194             s.append(builtInConstant);
7195             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounters = %d;", resources.maxTessControlAtomicCounters);
7196             s.append(builtInConstant);
7197             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounters = %d;", resources.maxTessEvaluationAtomicCounters);
7198             s.append(builtInConstant);
7199             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounterBuffers = %d;", resources.maxTessControlAtomicCounterBuffers);
7200             s.append(builtInConstant);
7201             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounterBuffers = %d;", resources.maxTessEvaluationAtomicCounterBuffers);
7202             s.append(builtInConstant);
7203         }
7204 
7205         if (version >= 100) {
7206             // GL_EXT_blend_func_extended
7207             snprintf(builtInConstant, maxSize, "const mediump int gl_MaxDualSourceDrawBuffersEXT = %d;", resources.maxDualSourceDrawBuffersEXT);
7208             s.append(builtInConstant);
7209             // this is here instead of with the others in initialize(version, profile) due to the dependence on gl_MaxDualSourceDrawBuffersEXT
7210             if (language == EShLangFragment) {
7211                 s.append(
7212                     "mediump vec4 gl_SecondaryFragColorEXT;"
7213                     "mediump vec4 gl_SecondaryFragDataEXT[gl_MaxDualSourceDrawBuffersEXT];"
7214                     "\n");
7215             }
7216         }
7217     } else {
7218         // non-ES profile
7219 
7220         if (version > 400) {
7221             snprintf(builtInConstant, maxSize, "const int  gl_MaxVertexUniformVectors = %d;", resources.maxVertexUniformVectors);
7222             s.append(builtInConstant);
7223 
7224             snprintf(builtInConstant, maxSize, "const int  gl_MaxFragmentUniformVectors = %d;", resources.maxFragmentUniformVectors);
7225             s.append(builtInConstant);
7226 
7227             snprintf(builtInConstant, maxSize, "const int  gl_MaxVaryingVectors = %d;", resources.maxVaryingVectors);
7228             s.append(builtInConstant);
7229         }
7230 
7231         snprintf(builtInConstant, maxSize, "const int  gl_MaxVertexAttribs = %d;", resources.maxVertexAttribs);
7232         s.append(builtInConstant);
7233 
7234         snprintf(builtInConstant, maxSize, "const int  gl_MaxVertexTextureImageUnits = %d;", resources.maxVertexTextureImageUnits);
7235         s.append(builtInConstant);
7236 
7237         snprintf(builtInConstant, maxSize, "const int  gl_MaxCombinedTextureImageUnits = %d;", resources.maxCombinedTextureImageUnits);
7238         s.append(builtInConstant);
7239 
7240         snprintf(builtInConstant, maxSize, "const int  gl_MaxTextureImageUnits = %d;", resources.maxTextureImageUnits);
7241         s.append(builtInConstant);
7242 
7243         snprintf(builtInConstant, maxSize, "const int  gl_MaxDrawBuffers = %d;", resources.maxDrawBuffers);
7244         s.append(builtInConstant);
7245 
7246         snprintf(builtInConstant, maxSize, "const int  gl_MaxLights = %d;", resources.maxLights);
7247         s.append(builtInConstant);
7248 
7249         snprintf(builtInConstant, maxSize, "const int  gl_MaxClipPlanes = %d;", resources.maxClipPlanes);
7250         s.append(builtInConstant);
7251 
7252         snprintf(builtInConstant, maxSize, "const int  gl_MaxTextureUnits = %d;", resources.maxTextureUnits);
7253         s.append(builtInConstant);
7254 
7255         snprintf(builtInConstant, maxSize, "const int  gl_MaxTextureCoords = %d;", resources.maxTextureCoords);
7256         s.append(builtInConstant);
7257 
7258         snprintf(builtInConstant, maxSize, "const int  gl_MaxVertexUniformComponents = %d;", resources.maxVertexUniformComponents);
7259         s.append(builtInConstant);
7260 
7261         // Moved from just being deprecated into compatibility profile only as of 4.20
7262         if (version < 420 || profile == ECompatibilityProfile) {
7263             snprintf(builtInConstant, maxSize, "const int  gl_MaxVaryingFloats = %d;", resources.maxVaryingFloats);
7264             s.append(builtInConstant);
7265         }
7266 
7267         snprintf(builtInConstant, maxSize, "const int  gl_MaxFragmentUniformComponents = %d;", resources.maxFragmentUniformComponents);
7268         s.append(builtInConstant);
7269 
7270         if (spvVersion.spv == 0 && IncludeLegacy(version, profile, spvVersion)) {
7271             //
7272             // OpenGL'uniform' state.  Page numbers are in reference to version
7273             // 1.4 of the OpenGL specification.
7274             //
7275 
7276             //
7277             // Matrix state. p. 31, 32, 37, 39, 40.
7278             //
7279             s.append("uniform mat4  gl_TextureMatrix[gl_MaxTextureCoords];"
7280 
7281             //
7282             // Derived matrix state that provides inverse and transposed versions
7283             // of the matrices above.
7284             //
7285                         "uniform mat4  gl_TextureMatrixInverse[gl_MaxTextureCoords];"
7286 
7287                         "uniform mat4  gl_TextureMatrixTranspose[gl_MaxTextureCoords];"
7288 
7289                         "uniform mat4  gl_TextureMatrixInverseTranspose[gl_MaxTextureCoords];"
7290 
7291             //
7292             // Clip planes p. 42.
7293             //
7294                         "uniform vec4  gl_ClipPlane[gl_MaxClipPlanes];"
7295 
7296             //
7297             // Light State p 50, 53, 55.
7298             //
7299                         "uniform gl_LightSourceParameters  gl_LightSource[gl_MaxLights];"
7300 
7301             //
7302             // Derived state from products of light.
7303             //
7304                         "uniform gl_LightProducts gl_FrontLightProduct[gl_MaxLights];"
7305                         "uniform gl_LightProducts gl_BackLightProduct[gl_MaxLights];"
7306 
7307             //
7308             // Texture Environment and Generation, p. 152, p. 40-42.
7309             //
7310                         "uniform vec4  gl_TextureEnvColor[gl_MaxTextureImageUnits];"
7311                         "uniform vec4  gl_EyePlaneS[gl_MaxTextureCoords];"
7312                         "uniform vec4  gl_EyePlaneT[gl_MaxTextureCoords];"
7313                         "uniform vec4  gl_EyePlaneR[gl_MaxTextureCoords];"
7314                         "uniform vec4  gl_EyePlaneQ[gl_MaxTextureCoords];"
7315                         "uniform vec4  gl_ObjectPlaneS[gl_MaxTextureCoords];"
7316                         "uniform vec4  gl_ObjectPlaneT[gl_MaxTextureCoords];"
7317                         "uniform vec4  gl_ObjectPlaneR[gl_MaxTextureCoords];"
7318                         "uniform vec4  gl_ObjectPlaneQ[gl_MaxTextureCoords];");
7319         }
7320 
7321         if (version >= 130) {
7322             snprintf(builtInConstant, maxSize, "const int gl_MaxClipDistances = %d;", resources.maxClipDistances);
7323             s.append(builtInConstant);
7324             snprintf(builtInConstant, maxSize, "const int gl_MaxVaryingComponents = %d;", resources.maxVaryingComponents);
7325             s.append(builtInConstant);
7326 
7327             // GL_ARB_shading_language_420pack
7328             snprintf(builtInConstant, maxSize, "const mediump int  gl_MinProgramTexelOffset = %d;", resources.minProgramTexelOffset);
7329             s.append(builtInConstant);
7330             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxProgramTexelOffset = %d;", resources.maxProgramTexelOffset);
7331             s.append(builtInConstant);
7332         }
7333 
7334         // geometry
7335         if (version >= 150) {
7336             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryInputComponents = %d;", resources.maxGeometryInputComponents);
7337             s.append(builtInConstant);
7338             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputComponents = %d;", resources.maxGeometryOutputComponents);
7339             s.append(builtInConstant);
7340             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTextureImageUnits = %d;", resources.maxGeometryTextureImageUnits);
7341             s.append(builtInConstant);
7342             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputVertices = %d;", resources.maxGeometryOutputVertices);
7343             s.append(builtInConstant);
7344             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTotalOutputComponents = %d;", resources.maxGeometryTotalOutputComponents);
7345             s.append(builtInConstant);
7346             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryUniformComponents = %d;", resources.maxGeometryUniformComponents);
7347             s.append(builtInConstant);
7348             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryVaryingComponents = %d;", resources.maxGeometryVaryingComponents);
7349             s.append(builtInConstant);
7350 
7351         }
7352 
7353         if (version >= 150) {
7354             snprintf(builtInConstant, maxSize, "const int gl_MaxVertexOutputComponents = %d;", resources.maxVertexOutputComponents);
7355             s.append(builtInConstant);
7356             snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentInputComponents = %d;", resources.maxFragmentInputComponents);
7357             s.append(builtInConstant);
7358         }
7359 
7360         // tessellation
7361         if (version >= 150) {
7362             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlInputComponents = %d;", resources.maxTessControlInputComponents);
7363             s.append(builtInConstant);
7364             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlOutputComponents = %d;", resources.maxTessControlOutputComponents);
7365             s.append(builtInConstant);
7366             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTextureImageUnits = %d;", resources.maxTessControlTextureImageUnits);
7367             s.append(builtInConstant);
7368             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlUniformComponents = %d;", resources.maxTessControlUniformComponents);
7369             s.append(builtInConstant);
7370             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTotalOutputComponents = %d;", resources.maxTessControlTotalOutputComponents);
7371             s.append(builtInConstant);
7372 
7373             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationInputComponents = %d;", resources.maxTessEvaluationInputComponents);
7374             s.append(builtInConstant);
7375             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationOutputComponents = %d;", resources.maxTessEvaluationOutputComponents);
7376             s.append(builtInConstant);
7377             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationTextureImageUnits = %d;", resources.maxTessEvaluationTextureImageUnits);
7378             s.append(builtInConstant);
7379             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationUniformComponents = %d;", resources.maxTessEvaluationUniformComponents);
7380             s.append(builtInConstant);
7381 
7382             snprintf(builtInConstant, maxSize, "const int gl_MaxTessPatchComponents = %d;", resources.maxTessPatchComponents);
7383             s.append(builtInConstant);
7384             snprintf(builtInConstant, maxSize, "const int gl_MaxTessGenLevel = %d;", resources.maxTessGenLevel);
7385             s.append(builtInConstant);
7386             snprintf(builtInConstant, maxSize, "const int gl_MaxPatchVertices = %d;", resources.maxPatchVertices);
7387             s.append(builtInConstant);
7388 
7389             // this is here instead of with the others in initialize(version, profile) due to the dependence on gl_MaxPatchVertices
7390             if (language == EShLangTessControl || language == EShLangTessEvaluation) {
7391                 s.append(
7392                     "in gl_PerVertex {"
7393                         "vec4 gl_Position;"
7394                         "float gl_PointSize;"
7395                         "float gl_ClipDistance[];"
7396                     );
7397                 if (profile == ECompatibilityProfile)
7398                     s.append(
7399                         "vec4 gl_ClipVertex;"
7400                         "vec4 gl_FrontColor;"
7401                         "vec4 gl_BackColor;"
7402                         "vec4 gl_FrontSecondaryColor;"
7403                         "vec4 gl_BackSecondaryColor;"
7404                         "vec4 gl_TexCoord[];"
7405                         "float gl_FogFragCoord;"
7406                         );
7407                 if (profile != EEsProfile && version >= 450)
7408                     s.append(
7409                         "float gl_CullDistance[];"
7410                         "vec4 gl_SecondaryPositionNV;"  // GL_NV_stereo_view_rendering
7411                         "vec4 gl_PositionPerViewNV[];"  // GL_NVX_multiview_per_view_attributes
7412                        );
7413                 s.append(
7414                     "} gl_in[gl_MaxPatchVertices];"
7415                     "\n");
7416             }
7417         }
7418 
7419         if (version >= 150) {
7420             snprintf(builtInConstant, maxSize, "const int gl_MaxViewports = %d;", resources.maxViewports);
7421             s.append(builtInConstant);
7422         }
7423 
7424         // images
7425         if (version >= 130) {
7426             snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedImageUnitsAndFragmentOutputs = %d;", resources.maxCombinedImageUnitsAndFragmentOutputs);
7427             s.append(builtInConstant);
7428             snprintf(builtInConstant, maxSize, "const int gl_MaxImageSamples = %d;", resources.maxImageSamples);
7429             s.append(builtInConstant);
7430             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlImageUniforms = %d;", resources.maxTessControlImageUniforms);
7431             s.append(builtInConstant);
7432             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationImageUniforms = %d;", resources.maxTessEvaluationImageUniforms);
7433             s.append(builtInConstant);
7434             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryImageUniforms = %d;", resources.maxGeometryImageUniforms);
7435             s.append(builtInConstant);
7436         }
7437 
7438         // enhanced layouts
7439         if (version >= 430) {
7440             snprintf(builtInConstant, maxSize, "const int gl_MaxTransformFeedbackBuffers = %d;", resources.maxTransformFeedbackBuffers);
7441             s.append(builtInConstant);
7442             snprintf(builtInConstant, maxSize, "const int gl_MaxTransformFeedbackInterleavedComponents = %d;", resources.maxTransformFeedbackInterleavedComponents);
7443             s.append(builtInConstant);
7444         }
7445 #endif
7446     }
7447 
7448     // compute
7449     if ((profile == EEsProfile && version >= 310) || (profile != EEsProfile && version >= 420)) {
7450         snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxComputeWorkGroupCount = ivec3(%d,%d,%d);", resources.maxComputeWorkGroupCountX,
7451                                                                                                          resources.maxComputeWorkGroupCountY,
7452                                                                                                          resources.maxComputeWorkGroupCountZ);
7453         s.append(builtInConstant);
7454         snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxComputeWorkGroupSize = ivec3(%d,%d,%d);", resources.maxComputeWorkGroupSizeX,
7455                                                                                                         resources.maxComputeWorkGroupSizeY,
7456                                                                                                         resources.maxComputeWorkGroupSizeZ);
7457         s.append(builtInConstant);
7458 
7459         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeUniformComponents = %d;", resources.maxComputeUniformComponents);
7460         s.append(builtInConstant);
7461         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeTextureImageUnits = %d;", resources.maxComputeTextureImageUnits);
7462         s.append(builtInConstant);
7463 
7464         s.append("\n");
7465     }
7466 
7467 #ifndef GLSLANG_WEB
7468     // images (some in compute below)
7469     if ((profile == EEsProfile && version >= 310) ||
7470         (profile != EEsProfile && version >= 130)) {
7471         snprintf(builtInConstant, maxSize, "const int gl_MaxImageUnits = %d;", resources.maxImageUnits);
7472         s.append(builtInConstant);
7473         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedShaderOutputResources = %d;", resources.maxCombinedShaderOutputResources);
7474         s.append(builtInConstant);
7475         snprintf(builtInConstant, maxSize, "const int gl_MaxVertexImageUniforms = %d;", resources.maxVertexImageUniforms);
7476         s.append(builtInConstant);
7477         snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentImageUniforms = %d;", resources.maxFragmentImageUniforms);
7478         s.append(builtInConstant);
7479         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedImageUniforms = %d;", resources.maxCombinedImageUniforms);
7480         s.append(builtInConstant);
7481     }
7482 
7483     // compute
7484     if ((profile == EEsProfile && version >= 310) || (profile != EEsProfile && version >= 420)) {
7485         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeImageUniforms = %d;", resources.maxComputeImageUniforms);
7486         s.append(builtInConstant);
7487         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeAtomicCounters = %d;", resources.maxComputeAtomicCounters);
7488         s.append(builtInConstant);
7489         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeAtomicCounterBuffers = %d;", resources.maxComputeAtomicCounterBuffers);
7490         s.append(builtInConstant);
7491 
7492         s.append("\n");
7493     }
7494 
7495 #ifndef GLSLANG_ANGLE
7496     // atomic counters (some in compute below)
7497     if ((profile == EEsProfile && version >= 310) ||
7498         (profile != EEsProfile && version >= 420)) {
7499         snprintf(builtInConstant, maxSize, "const int gl_MaxVertexAtomicCounters = %d;", resources.               maxVertexAtomicCounters);
7500         s.append(builtInConstant);
7501         snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentAtomicCounters = %d;", resources.             maxFragmentAtomicCounters);
7502         s.append(builtInConstant);
7503         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedAtomicCounters = %d;", resources.             maxCombinedAtomicCounters);
7504         s.append(builtInConstant);
7505         snprintf(builtInConstant, maxSize, "const int gl_MaxAtomicCounterBindings = %d;", resources.              maxAtomicCounterBindings);
7506         s.append(builtInConstant);
7507         snprintf(builtInConstant, maxSize, "const int gl_MaxVertexAtomicCounterBuffers = %d;", resources.         maxVertexAtomicCounterBuffers);
7508         s.append(builtInConstant);
7509         snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentAtomicCounterBuffers = %d;", resources.       maxFragmentAtomicCounterBuffers);
7510         s.append(builtInConstant);
7511         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedAtomicCounterBuffers = %d;", resources.       maxCombinedAtomicCounterBuffers);
7512         s.append(builtInConstant);
7513         snprintf(builtInConstant, maxSize, "const int gl_MaxAtomicCounterBufferSize = %d;", resources.            maxAtomicCounterBufferSize);
7514         s.append(builtInConstant);
7515     }
7516     if (profile != EEsProfile && version >= 420) {
7517         snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounters = %d;", resources.          maxTessControlAtomicCounters);
7518         s.append(builtInConstant);
7519         snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounters = %d;", resources.       maxTessEvaluationAtomicCounters);
7520         s.append(builtInConstant);
7521         snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounters = %d;", resources.             maxGeometryAtomicCounters);
7522         s.append(builtInConstant);
7523         snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounterBuffers = %d;", resources.    maxTessControlAtomicCounterBuffers);
7524         s.append(builtInConstant);
7525         snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounterBuffers = %d;", resources. maxTessEvaluationAtomicCounterBuffers);
7526         s.append(builtInConstant);
7527         snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounterBuffers = %d;", resources.       maxGeometryAtomicCounterBuffers);
7528         s.append(builtInConstant);
7529 
7530         s.append("\n");
7531     }
7532 #endif // !GLSLANG_ANGLE
7533 
7534     // GL_ARB_cull_distance
7535     if (profile != EEsProfile && version >= 450) {
7536         snprintf(builtInConstant, maxSize, "const int gl_MaxCullDistances = %d;",                resources.maxCullDistances);
7537         s.append(builtInConstant);
7538         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedClipAndCullDistances = %d;", resources.maxCombinedClipAndCullDistances);
7539         s.append(builtInConstant);
7540     }
7541 
7542     // GL_ARB_ES3_1_compatibility
7543     if ((profile != EEsProfile && version >= 450) ||
7544         (profile == EEsProfile && version >= 310)) {
7545         snprintf(builtInConstant, maxSize, "const int gl_MaxSamples = %d;", resources.maxSamples);
7546         s.append(builtInConstant);
7547     }
7548 
7549 #ifndef GLSLANG_ANGLE
7550     // SPV_NV_mesh_shader
7551     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
7552         snprintf(builtInConstant, maxSize, "const int gl_MaxMeshOutputVerticesNV = %d;", resources.maxMeshOutputVerticesNV);
7553         s.append(builtInConstant);
7554 
7555         snprintf(builtInConstant, maxSize, "const int gl_MaxMeshOutputPrimitivesNV = %d;", resources.maxMeshOutputPrimitivesNV);
7556         s.append(builtInConstant);
7557 
7558         snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxMeshWorkGroupSizeNV = ivec3(%d,%d,%d);", resources.maxMeshWorkGroupSizeX_NV,
7559                                                                                                        resources.maxMeshWorkGroupSizeY_NV,
7560                                                                                                        resources.maxMeshWorkGroupSizeZ_NV);
7561         s.append(builtInConstant);
7562         snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxTaskWorkGroupSizeNV = ivec3(%d,%d,%d);", resources.maxTaskWorkGroupSizeX_NV,
7563                                                                                                        resources.maxTaskWorkGroupSizeY_NV,
7564                                                                                                        resources.maxTaskWorkGroupSizeZ_NV);
7565         s.append(builtInConstant);
7566 
7567         snprintf(builtInConstant, maxSize, "const int gl_MaxMeshViewCountNV = %d;", resources.maxMeshViewCountNV);
7568         s.append(builtInConstant);
7569 
7570         s.append("\n");
7571     }
7572 #endif
7573 #endif
7574 
7575     s.append("\n");
7576 }
7577 
7578 //
7579 // To support special built-ins that have a special qualifier that cannot be declared textually
7580 // in a shader, like gl_Position.
7581 //
7582 // This lets the type of the built-in be declared textually, and then have just its qualifier be
7583 // updated afterward.
7584 //
7585 // Safe to call even if name is not present.
7586 //
7587 // Only use this for built-in variables that have a special qualifier in TStorageQualifier.
7588 // New built-in variables should use a generic (textually declarable) qualifier in
7589 // TStoraregQualifier and only call BuiltInVariable().
7590 //
7591 static void SpecialQualifier(const char* name, TStorageQualifier qualifier, TBuiltInVariable builtIn, TSymbolTable& symbolTable)
7592 {
7593     TSymbol* symbol = symbolTable.find(name);
7594     if (symbol == nullptr)
7595         return;
7596 
7597     TQualifier& symQualifier = symbol->getWritableType().getQualifier();
7598     symQualifier.storage = qualifier;
7599     symQualifier.builtIn = builtIn;
7600 }
7601 
7602 //
7603 // To tag built-in variables with their TBuiltInVariable enum.  Use this when the
7604 // normal declaration text already gets the qualifier right, and all that's needed
7605 // is setting the builtIn field.  This should be the normal way for all new
7606 // built-in variables.
7607 //
7608 // If SpecialQualifier() was called, this does not need to be called.
7609 //
7610 // Safe to call even if name is not present.
7611 //
7612 static void BuiltInVariable(const char* name, TBuiltInVariable builtIn, TSymbolTable& symbolTable)
7613 {
7614     TSymbol* symbol = symbolTable.find(name);
7615     if (symbol == nullptr)
7616         return;
7617 
7618     TQualifier& symQualifier = symbol->getWritableType().getQualifier();
7619     symQualifier.builtIn = builtIn;
7620 }
7621 
7622 static void RetargetVariable(const char* from, const char* to, TSymbolTable& symbolTable)
7623 {
7624     symbolTable.retargetSymbol(from, to);
7625 }
7626 
7627 //
7628 // For built-in variables inside a named block.
7629 // SpecialQualifier() won't ever go inside a block; their member's qualifier come
7630 // from the qualification of the block.
7631 //
7632 // See comments above for other detail.
7633 //
7634 static void BuiltInVariable(const char* blockName, const char* name, TBuiltInVariable builtIn, TSymbolTable& symbolTable)
7635 {
7636     TSymbol* symbol = symbolTable.find(blockName);
7637     if (symbol == nullptr)
7638         return;
7639 
7640     TTypeList& structure = *symbol->getWritableType().getWritableStruct();
7641     for (int i = 0; i < (int)structure.size(); ++i) {
7642         if (structure[i].type->getFieldName().compare(name) == 0) {
7643             structure[i].type->getQualifier().builtIn = builtIn;
7644             return;
7645         }
7646     }
7647 }
7648 
7649 //
7650 // Finish adding/processing context-independent built-in symbols.
7651 // 1) Programmatically add symbols that could not be added by simple text strings above.
7652 // 2) Map built-in functions to operators, for those that will turn into an operation node
7653 //    instead of remaining a function call.
7654 // 3) Tag extension-related symbols added to their base version with their extensions, so
7655 //    that if an early version has the extension turned off, there is an error reported on use.
7656 //
7657 void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable)
7658 {
7659 #ifdef GLSLANG_WEB
7660     version = 310;
7661     profile = EEsProfile;
7662 #elif defined(GLSLANG_ANGLE)
7663     version = 450;
7664     profile = ECoreProfile;
7665 #endif
7666 
7667     //
7668     // Tag built-in variables and functions with additional qualifier and extension information
7669     // that cannot be declared with the text strings.
7670     //
7671 
7672     // N.B.: a symbol should only be tagged once, and this function is called multiple times, once
7673     // per stage that's used for this profile.  So
7674     //  - generally, stick common ones in the fragment stage to ensure they are tagged exactly once
7675     //  - for ES, which has different precisions for different stages, the coarsest-grained tagging
7676     //    for a built-in used in many stages needs to be once for the fragment stage and once for
7677     //    the vertex stage
7678 
7679     switch(language) {
7680     case EShLangVertex:
7681         if (spvVersion.vulkan > 0) {
7682             BuiltInVariable("gl_VertexIndex",   EbvVertexIndex,   symbolTable);
7683             BuiltInVariable("gl_InstanceIndex", EbvInstanceIndex, symbolTable);
7684         }
7685 
7686 #ifndef GLSLANG_WEB
7687         if (spvVersion.vulkan == 0) {
7688             SpecialQualifier("gl_VertexID",   EvqVertexId,   EbvVertexId,   symbolTable);
7689             SpecialQualifier("gl_InstanceID", EvqInstanceId, EbvInstanceId, symbolTable);
7690         }
7691 
7692         if (spvVersion.vulkan > 0 && spvVersion.vulkanRelaxed) {
7693             // treat these built-ins as aliases of VertexIndex and InstanceIndex
7694             RetargetVariable("gl_InstanceID", "gl_InstanceIndex", symbolTable);
7695             RetargetVariable("gl_VertexID", "gl_VertexIndex", symbolTable);
7696         }
7697 
7698         if (profile != EEsProfile) {
7699             if (version >= 440) {
7700                 symbolTable.setVariableExtensions("gl_BaseVertexARB",   1, &E_GL_ARB_shader_draw_parameters);
7701                 symbolTable.setVariableExtensions("gl_BaseInstanceARB", 1, &E_GL_ARB_shader_draw_parameters);
7702                 symbolTable.setVariableExtensions("gl_DrawIDARB",       1, &E_GL_ARB_shader_draw_parameters);
7703                 BuiltInVariable("gl_BaseVertexARB",   EbvBaseVertex,   symbolTable);
7704                 BuiltInVariable("gl_BaseInstanceARB", EbvBaseInstance, symbolTable);
7705                 BuiltInVariable("gl_DrawIDARB",       EbvDrawId,       symbolTable);
7706             }
7707             if (version >= 460) {
7708                 BuiltInVariable("gl_BaseVertex",   EbvBaseVertex,   symbolTable);
7709                 BuiltInVariable("gl_BaseInstance", EbvBaseInstance, symbolTable);
7710                 BuiltInVariable("gl_DrawID",       EbvDrawId,       symbolTable);
7711             }
7712             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
7713             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
7714             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
7715             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
7716             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
7717             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
7718             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
7719 
7720             symbolTable.setFunctionExtensions("ballotARB",              1, &E_GL_ARB_shader_ballot);
7721             symbolTable.setFunctionExtensions("readInvocationARB",      1, &E_GL_ARB_shader_ballot);
7722             symbolTable.setFunctionExtensions("readFirstInvocationARB", 1, &E_GL_ARB_shader_ballot);
7723 
7724             if (version >= 430) {
7725                 symbolTable.setFunctionExtensions("anyInvocationARB",       1, &E_GL_ARB_shader_group_vote);
7726                 symbolTable.setFunctionExtensions("allInvocationsARB",      1, &E_GL_ARB_shader_group_vote);
7727                 symbolTable.setFunctionExtensions("allInvocationsEqualARB", 1, &E_GL_ARB_shader_group_vote);
7728             }
7729         }
7730 
7731 
7732         if (profile != EEsProfile) {
7733             symbolTable.setFunctionExtensions("minInvocationsAMD",                1, &E_GL_AMD_shader_ballot);
7734             symbolTable.setFunctionExtensions("maxInvocationsAMD",                1, &E_GL_AMD_shader_ballot);
7735             symbolTable.setFunctionExtensions("addInvocationsAMD",                1, &E_GL_AMD_shader_ballot);
7736             symbolTable.setFunctionExtensions("minInvocationsNonUniformAMD",      1, &E_GL_AMD_shader_ballot);
7737             symbolTable.setFunctionExtensions("maxInvocationsNonUniformAMD",      1, &E_GL_AMD_shader_ballot);
7738             symbolTable.setFunctionExtensions("addInvocationsNonUniformAMD",      1, &E_GL_AMD_shader_ballot);
7739             symbolTable.setFunctionExtensions("swizzleInvocationsAMD",            1, &E_GL_AMD_shader_ballot);
7740             symbolTable.setFunctionExtensions("swizzleInvocationsWithPatternAMD", 1, &E_GL_AMD_shader_ballot);
7741             symbolTable.setFunctionExtensions("writeInvocationAMD",               1, &E_GL_AMD_shader_ballot);
7742             symbolTable.setFunctionExtensions("mbcntAMD",                         1, &E_GL_AMD_shader_ballot);
7743 
7744             symbolTable.setFunctionExtensions("minInvocationsInclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
7745             symbolTable.setFunctionExtensions("maxInvocationsInclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
7746             symbolTable.setFunctionExtensions("addInvocationsInclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
7747             symbolTable.setFunctionExtensions("minInvocationsInclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
7748             symbolTable.setFunctionExtensions("maxInvocationsInclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
7749             symbolTable.setFunctionExtensions("addInvocationsInclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
7750             symbolTable.setFunctionExtensions("minInvocationsExclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
7751             symbolTable.setFunctionExtensions("maxInvocationsExclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
7752             symbolTable.setFunctionExtensions("addInvocationsExclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
7753             symbolTable.setFunctionExtensions("minInvocationsExclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
7754             symbolTable.setFunctionExtensions("maxInvocationsExclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
7755             symbolTable.setFunctionExtensions("addInvocationsExclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
7756         }
7757 
7758         if (profile != EEsProfile) {
7759             symbolTable.setFunctionExtensions("min3", 1, &E_GL_AMD_shader_trinary_minmax);
7760             symbolTable.setFunctionExtensions("max3", 1, &E_GL_AMD_shader_trinary_minmax);
7761             symbolTable.setFunctionExtensions("mid3", 1, &E_GL_AMD_shader_trinary_minmax);
7762         }
7763 
7764         if (profile != EEsProfile) {
7765             symbolTable.setVariableExtensions("gl_SIMDGroupSizeAMD", 1, &E_GL_AMD_gcn_shader);
7766             SpecialQualifier("gl_SIMDGroupSizeAMD", EvqVaryingIn, EbvSubGroupSize, symbolTable);
7767 
7768             symbolTable.setFunctionExtensions("cubeFaceIndexAMD", 1, &E_GL_AMD_gcn_shader);
7769             symbolTable.setFunctionExtensions("cubeFaceCoordAMD", 1, &E_GL_AMD_gcn_shader);
7770             symbolTable.setFunctionExtensions("timeAMD",          1, &E_GL_AMD_gcn_shader);
7771         }
7772 
7773         if (profile != EEsProfile) {
7774             symbolTable.setFunctionExtensions("fragmentMaskFetchAMD", 1, &E_GL_AMD_shader_fragment_mask);
7775             symbolTable.setFunctionExtensions("fragmentFetchAMD",     1, &E_GL_AMD_shader_fragment_mask);
7776         }
7777 
7778         symbolTable.setFunctionExtensions("countLeadingZeros",  1, &E_GL_INTEL_shader_integer_functions2);
7779         symbolTable.setFunctionExtensions("countTrailingZeros", 1, &E_GL_INTEL_shader_integer_functions2);
7780         symbolTable.setFunctionExtensions("absoluteDifference", 1, &E_GL_INTEL_shader_integer_functions2);
7781         symbolTable.setFunctionExtensions("addSaturate",        1, &E_GL_INTEL_shader_integer_functions2);
7782         symbolTable.setFunctionExtensions("subtractSaturate",   1, &E_GL_INTEL_shader_integer_functions2);
7783         symbolTable.setFunctionExtensions("average",            1, &E_GL_INTEL_shader_integer_functions2);
7784         symbolTable.setFunctionExtensions("averageRounded",     1, &E_GL_INTEL_shader_integer_functions2);
7785         symbolTable.setFunctionExtensions("multiply32x16",      1, &E_GL_INTEL_shader_integer_functions2);
7786 
7787         symbolTable.setFunctionExtensions("textureFootprintNV",          1, &E_GL_NV_shader_texture_footprint);
7788         symbolTable.setFunctionExtensions("textureFootprintClampNV",     1, &E_GL_NV_shader_texture_footprint);
7789         symbolTable.setFunctionExtensions("textureFootprintLodNV",       1, &E_GL_NV_shader_texture_footprint);
7790         symbolTable.setFunctionExtensions("textureFootprintGradNV",      1, &E_GL_NV_shader_texture_footprint);
7791         symbolTable.setFunctionExtensions("textureFootprintGradClampNV", 1, &E_GL_NV_shader_texture_footprint);
7792         // Compatibility variables, vertex only
7793         if (spvVersion.spv == 0) {
7794             BuiltInVariable("gl_Color",          EbvColor,          symbolTable);
7795             BuiltInVariable("gl_SecondaryColor", EbvSecondaryColor, symbolTable);
7796             BuiltInVariable("gl_Normal",         EbvNormal,         symbolTable);
7797             BuiltInVariable("gl_Vertex",         EbvVertex,         symbolTable);
7798             BuiltInVariable("gl_MultiTexCoord0", EbvMultiTexCoord0, symbolTable);
7799             BuiltInVariable("gl_MultiTexCoord1", EbvMultiTexCoord1, symbolTable);
7800             BuiltInVariable("gl_MultiTexCoord2", EbvMultiTexCoord2, symbolTable);
7801             BuiltInVariable("gl_MultiTexCoord3", EbvMultiTexCoord3, symbolTable);
7802             BuiltInVariable("gl_MultiTexCoord4", EbvMultiTexCoord4, symbolTable);
7803             BuiltInVariable("gl_MultiTexCoord5", EbvMultiTexCoord5, symbolTable);
7804             BuiltInVariable("gl_MultiTexCoord6", EbvMultiTexCoord6, symbolTable);
7805             BuiltInVariable("gl_MultiTexCoord7", EbvMultiTexCoord7, symbolTable);
7806             BuiltInVariable("gl_FogCoord",       EbvFogFragCoord,   symbolTable);
7807         }
7808 
7809         if (profile == EEsProfile) {
7810             if (spvVersion.spv == 0) {
7811                 symbolTable.setFunctionExtensions("texture2DGradEXT",     1, &E_GL_EXT_shader_texture_lod);
7812                 symbolTable.setFunctionExtensions("texture2DProjGradEXT", 1, &E_GL_EXT_shader_texture_lod);
7813                 symbolTable.setFunctionExtensions("textureCubeGradEXT",   1, &E_GL_EXT_shader_texture_lod);
7814                 if (version == 310)
7815                     symbolTable.setFunctionExtensions("textureGatherOffsets", Num_AEP_gpu_shader5, AEP_gpu_shader5);
7816             }
7817             if (version == 310)
7818                 symbolTable.setFunctionExtensions("fma", Num_AEP_gpu_shader5, AEP_gpu_shader5);
7819         }
7820 
7821         if (profile == EEsProfile && version < 320) {
7822             symbolTable.setFunctionExtensions("imageAtomicAdd",      1, &E_GL_OES_shader_image_atomic);
7823             symbolTable.setFunctionExtensions("imageAtomicMin",      1, &E_GL_OES_shader_image_atomic);
7824             symbolTable.setFunctionExtensions("imageAtomicMax",      1, &E_GL_OES_shader_image_atomic);
7825             symbolTable.setFunctionExtensions("imageAtomicAnd",      1, &E_GL_OES_shader_image_atomic);
7826             symbolTable.setFunctionExtensions("imageAtomicOr",       1, &E_GL_OES_shader_image_atomic);
7827             symbolTable.setFunctionExtensions("imageAtomicXor",      1, &E_GL_OES_shader_image_atomic);
7828             symbolTable.setFunctionExtensions("imageAtomicExchange", 1, &E_GL_OES_shader_image_atomic);
7829             symbolTable.setFunctionExtensions("imageAtomicCompSwap", 1, &E_GL_OES_shader_image_atomic);
7830         }
7831 
7832         if (version >= 300 /* both ES and non-ES */) {
7833             symbolTable.setVariableExtensions("gl_ViewID_OVR", Num_OVR_multiview_EXTs, OVR_multiview_EXTs);
7834             BuiltInVariable("gl_ViewID_OVR", EbvViewIndex, symbolTable);
7835         }
7836 
7837         if (profile == EEsProfile) {
7838             symbolTable.setFunctionExtensions("shadow2DEXT",        1, &E_GL_EXT_shadow_samplers);
7839             symbolTable.setFunctionExtensions("shadow2DProjEXT",    1, &E_GL_EXT_shadow_samplers);
7840         }
7841         // Fall through
7842 
7843     case EShLangTessControl:
7844         if (profile == EEsProfile && version >= 310) {
7845             BuiltInVariable("gl_BoundingBoxEXT", EbvBoundingBox, symbolTable);
7846             symbolTable.setVariableExtensions("gl_BoundingBoxEXT", 1,
7847                                               &E_GL_EXT_primitive_bounding_box);
7848             BuiltInVariable("gl_BoundingBoxOES", EbvBoundingBox, symbolTable);
7849             symbolTable.setVariableExtensions("gl_BoundingBoxOES", 1,
7850                                               &E_GL_OES_primitive_bounding_box);
7851 
7852             if (version >= 320) {
7853                 BuiltInVariable("gl_BoundingBox", EbvBoundingBox, symbolTable);
7854             }
7855         }
7856         // Fall through
7857 
7858     case EShLangTessEvaluation:
7859     case EShLangGeometry:
7860 #endif // !GLSLANG_WEB
7861         SpecialQualifier("gl_Position",   EvqPosition,   EbvPosition,   symbolTable);
7862         SpecialQualifier("gl_PointSize",  EvqPointSize,  EbvPointSize,  symbolTable);
7863 
7864         BuiltInVariable("gl_in",  "gl_Position",     EbvPosition,     symbolTable);
7865         BuiltInVariable("gl_in",  "gl_PointSize",    EbvPointSize,    symbolTable);
7866 
7867         BuiltInVariable("gl_out", "gl_Position",     EbvPosition,     symbolTable);
7868         BuiltInVariable("gl_out", "gl_PointSize",    EbvPointSize,    symbolTable);
7869 
7870 #ifndef GLSLANG_WEB
7871         SpecialQualifier("gl_ClipVertex", EvqClipVertex, EbvClipVertex, symbolTable);
7872 
7873         BuiltInVariable("gl_in",  "gl_ClipDistance", EbvClipDistance, symbolTable);
7874         BuiltInVariable("gl_in",  "gl_CullDistance", EbvCullDistance, symbolTable);
7875 
7876         BuiltInVariable("gl_out", "gl_ClipDistance", EbvClipDistance, symbolTable);
7877         BuiltInVariable("gl_out", "gl_CullDistance", EbvCullDistance, symbolTable);
7878 
7879         BuiltInVariable("gl_ClipDistance",    EbvClipDistance,   symbolTable);
7880         BuiltInVariable("gl_CullDistance",    EbvCullDistance,   symbolTable);
7881         BuiltInVariable("gl_PrimitiveIDIn",   EbvPrimitiveId,    symbolTable);
7882         BuiltInVariable("gl_PrimitiveID",     EbvPrimitiveId,    symbolTable);
7883         BuiltInVariable("gl_InvocationID",    EbvInvocationId,   symbolTable);
7884         BuiltInVariable("gl_Layer",           EbvLayer,          symbolTable);
7885         BuiltInVariable("gl_ViewportIndex",   EbvViewportIndex,  symbolTable);
7886 
7887         if (language != EShLangGeometry) {
7888             symbolTable.setVariableExtensions("gl_Layer",         Num_viewportEXTs, viewportEXTs);
7889             symbolTable.setVariableExtensions("gl_ViewportIndex", Num_viewportEXTs, viewportEXTs);
7890         }
7891         symbolTable.setVariableExtensions("gl_ViewportMask",            1, &E_GL_NV_viewport_array2);
7892         symbolTable.setVariableExtensions("gl_SecondaryPositionNV",     1, &E_GL_NV_stereo_view_rendering);
7893         symbolTable.setVariableExtensions("gl_SecondaryViewportMaskNV", 1, &E_GL_NV_stereo_view_rendering);
7894         symbolTable.setVariableExtensions("gl_PositionPerViewNV",       1, &E_GL_NVX_multiview_per_view_attributes);
7895         symbolTable.setVariableExtensions("gl_ViewportMaskPerViewNV",   1, &E_GL_NVX_multiview_per_view_attributes);
7896 
7897         BuiltInVariable("gl_ViewportMask",              EbvViewportMaskNV,          symbolTable);
7898         BuiltInVariable("gl_SecondaryPositionNV",       EbvSecondaryPositionNV,     symbolTable);
7899         BuiltInVariable("gl_SecondaryViewportMaskNV",   EbvSecondaryViewportMaskNV, symbolTable);
7900         BuiltInVariable("gl_PositionPerViewNV",         EbvPositionPerViewNV,       symbolTable);
7901         BuiltInVariable("gl_ViewportMaskPerViewNV",     EbvViewportMaskPerViewNV,   symbolTable);
7902 
7903         if (language == EShLangVertex || language == EShLangGeometry) {
7904             symbolTable.setVariableExtensions("gl_in", "gl_SecondaryPositionNV", 1, &E_GL_NV_stereo_view_rendering);
7905             symbolTable.setVariableExtensions("gl_in", "gl_PositionPerViewNV",   1, &E_GL_NVX_multiview_per_view_attributes);
7906 
7907             BuiltInVariable("gl_in", "gl_SecondaryPositionNV", EbvSecondaryPositionNV, symbolTable);
7908             BuiltInVariable("gl_in", "gl_PositionPerViewNV",   EbvPositionPerViewNV,   symbolTable);
7909         }
7910         symbolTable.setVariableExtensions("gl_out", "gl_ViewportMask",            1, &E_GL_NV_viewport_array2);
7911         symbolTable.setVariableExtensions("gl_out", "gl_SecondaryPositionNV",     1, &E_GL_NV_stereo_view_rendering);
7912         symbolTable.setVariableExtensions("gl_out", "gl_SecondaryViewportMaskNV", 1, &E_GL_NV_stereo_view_rendering);
7913         symbolTable.setVariableExtensions("gl_out", "gl_PositionPerViewNV",       1, &E_GL_NVX_multiview_per_view_attributes);
7914         symbolTable.setVariableExtensions("gl_out", "gl_ViewportMaskPerViewNV",   1, &E_GL_NVX_multiview_per_view_attributes);
7915 
7916         BuiltInVariable("gl_out", "gl_ViewportMask",            EbvViewportMaskNV,          symbolTable);
7917         BuiltInVariable("gl_out", "gl_SecondaryPositionNV",     EbvSecondaryPositionNV,     symbolTable);
7918         BuiltInVariable("gl_out", "gl_SecondaryViewportMaskNV", EbvSecondaryViewportMaskNV, symbolTable);
7919         BuiltInVariable("gl_out", "gl_PositionPerViewNV",       EbvPositionPerViewNV,       symbolTable);
7920         BuiltInVariable("gl_out", "gl_ViewportMaskPerViewNV",   EbvViewportMaskPerViewNV,   symbolTable);
7921 
7922         BuiltInVariable("gl_PatchVerticesIn", EbvPatchVertices,  symbolTable);
7923         BuiltInVariable("gl_TessLevelOuter",  EbvTessLevelOuter, symbolTable);
7924         BuiltInVariable("gl_TessLevelInner",  EbvTessLevelInner, symbolTable);
7925         BuiltInVariable("gl_TessCoord",       EbvTessCoord,      symbolTable);
7926 
7927         if (version < 410)
7928             symbolTable.setVariableExtensions("gl_ViewportIndex", 1, &E_GL_ARB_viewport_array);
7929 
7930         // Compatibility variables
7931 
7932         BuiltInVariable("gl_in", "gl_ClipVertex",          EbvClipVertex,          symbolTable);
7933         BuiltInVariable("gl_in", "gl_FrontColor",          EbvFrontColor,          symbolTable);
7934         BuiltInVariable("gl_in", "gl_BackColor",           EbvBackColor,           symbolTable);
7935         BuiltInVariable("gl_in", "gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
7936         BuiltInVariable("gl_in", "gl_BackSecondaryColor",  EbvBackSecondaryColor,  symbolTable);
7937         BuiltInVariable("gl_in", "gl_TexCoord",            EbvTexCoord,            symbolTable);
7938         BuiltInVariable("gl_in", "gl_FogFragCoord",        EbvFogFragCoord,        symbolTable);
7939 
7940         BuiltInVariable("gl_out", "gl_ClipVertex",          EbvClipVertex,          symbolTable);
7941         BuiltInVariable("gl_out", "gl_FrontColor",          EbvFrontColor,          symbolTable);
7942         BuiltInVariable("gl_out", "gl_BackColor",           EbvBackColor,           symbolTable);
7943         BuiltInVariable("gl_out", "gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
7944         BuiltInVariable("gl_out", "gl_BackSecondaryColor",  EbvBackSecondaryColor,  symbolTable);
7945         BuiltInVariable("gl_out", "gl_TexCoord",            EbvTexCoord,            symbolTable);
7946         BuiltInVariable("gl_out", "gl_FogFragCoord",        EbvFogFragCoord,        symbolTable);
7947 
7948         BuiltInVariable("gl_ClipVertex",          EbvClipVertex,          symbolTable);
7949         BuiltInVariable("gl_FrontColor",          EbvFrontColor,          symbolTable);
7950         BuiltInVariable("gl_BackColor",           EbvBackColor,           symbolTable);
7951         BuiltInVariable("gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
7952         BuiltInVariable("gl_BackSecondaryColor",  EbvBackSecondaryColor,  symbolTable);
7953         BuiltInVariable("gl_TexCoord",            EbvTexCoord,            symbolTable);
7954         BuiltInVariable("gl_FogFragCoord",        EbvFogFragCoord,        symbolTable);
7955 
7956         // gl_PointSize, when it needs to be tied to an extension, is always a member of a block.
7957         // (Sometimes with an instance name, sometimes anonymous).
7958         if (profile == EEsProfile) {
7959             if (language == EShLangGeometry) {
7960                 symbolTable.setVariableExtensions("gl_PointSize", Num_AEP_geometry_point_size, AEP_geometry_point_size);
7961                 symbolTable.setVariableExtensions("gl_in", "gl_PointSize", Num_AEP_geometry_point_size, AEP_geometry_point_size);
7962             } else if (language == EShLangTessEvaluation || language == EShLangTessControl) {
7963                 // gl_in tessellation settings of gl_PointSize are in the context-dependent paths
7964                 symbolTable.setVariableExtensions("gl_PointSize", Num_AEP_tessellation_point_size, AEP_tessellation_point_size);
7965                 symbolTable.setVariableExtensions("gl_out", "gl_PointSize", Num_AEP_tessellation_point_size, AEP_tessellation_point_size);
7966             }
7967         }
7968 
7969         if ((profile != EEsProfile && version >= 140) ||
7970             (profile == EEsProfile && version >= 310)) {
7971             symbolTable.setVariableExtensions("gl_DeviceIndex",  1, &E_GL_EXT_device_group);
7972             BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
7973             symbolTable.setVariableExtensions("gl_ViewIndex", 1, &E_GL_EXT_multiview);
7974             BuiltInVariable("gl_ViewIndex", EbvViewIndex, symbolTable);
7975         }
7976 
7977 	if (profile != EEsProfile) {
7978             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
7979             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
7980             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
7981             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
7982             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
7983             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
7984 
7985             if (spvVersion.vulkan > 0)
7986                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
7987                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
7988             else
7989                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
7990         }
7991 
7992         // GL_KHR_shader_subgroup
7993         if ((profile == EEsProfile && version >= 310) ||
7994             (profile != EEsProfile && version >= 140)) {
7995             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
7996             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
7997             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
7998             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
7999             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8000             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8001             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8002 
8003             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
8004             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
8005             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
8006             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
8007             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
8008             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
8009             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
8010 
8011             // GL_NV_shader_sm_builtins
8012             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
8013             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
8014             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
8015             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
8016             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
8017             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
8018             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
8019             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
8020         }
8021 
8022 		if (language == EShLangGeometry || language == EShLangVertex) {
8023 			if ((profile == EEsProfile && version >= 310) ||
8024 				(profile != EEsProfile && version >= 450)) {
8025 				symbolTable.setVariableExtensions("gl_PrimitiveShadingRateEXT", 1, &E_GL_EXT_fragment_shading_rate);
8026 				BuiltInVariable("gl_PrimitiveShadingRateEXT", EbvPrimitiveShadingRateKHR, symbolTable);
8027 
8028 				symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8029 				symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8030 				symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8031 				symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8032 			}
8033 		}
8034 
8035 #endif // !GLSLANG_WEB
8036         break;
8037 
8038     case EShLangFragment:
8039         SpecialQualifier("gl_FrontFacing",      EvqFace,       EbvFace,             symbolTable);
8040         SpecialQualifier("gl_FragCoord",        EvqFragCoord,  EbvFragCoord,        symbolTable);
8041         SpecialQualifier("gl_PointCoord",       EvqPointCoord, EbvPointCoord,       symbolTable);
8042         if (spvVersion.spv == 0)
8043             SpecialQualifier("gl_FragColor",    EvqFragColor,  EbvFragColor,        symbolTable);
8044         else {
8045             TSymbol* symbol = symbolTable.find("gl_FragColor");
8046             if (symbol) {
8047                 symbol->getWritableType().getQualifier().storage = EvqVaryingOut;
8048                 symbol->getWritableType().getQualifier().layoutLocation = 0;
8049             }
8050         }
8051         SpecialQualifier("gl_FragDepth",        EvqFragDepth,  EbvFragDepth,        symbolTable);
8052 #ifndef GLSLANG_WEB
8053         SpecialQualifier("gl_FragDepthEXT",     EvqFragDepth,  EbvFragDepth,        symbolTable);
8054         SpecialQualifier("gl_HelperInvocation", EvqVaryingIn,  EbvHelperInvocation, symbolTable);
8055 
8056         BuiltInVariable("gl_ClipDistance",    EbvClipDistance,   symbolTable);
8057         BuiltInVariable("gl_CullDistance",    EbvCullDistance,   symbolTable);
8058         BuiltInVariable("gl_PrimitiveID",     EbvPrimitiveId,    symbolTable);
8059 
8060         if (profile != EEsProfile && version >= 140) {
8061             symbolTable.setVariableExtensions("gl_FragStencilRefARB", 1, &E_GL_ARB_shader_stencil_export);
8062             BuiltInVariable("gl_FragStencilRefARB", EbvFragStencilRef, symbolTable);
8063         }
8064 
8065         if (profile != EEsProfile && version < 400) {
8066             symbolTable.setFunctionExtensions("textureQueryLod", 1, &E_GL_ARB_texture_query_lod);
8067         }
8068 
8069         if (profile != EEsProfile && version >= 460) {
8070             symbolTable.setFunctionExtensions("rayQueryInitializeEXT",                                            1, &E_GL_EXT_ray_query);
8071             symbolTable.setFunctionExtensions("rayQueryTerminateEXT",                                             1, &E_GL_EXT_ray_query);
8072             symbolTable.setFunctionExtensions("rayQueryGenerateIntersectionEXT",                                  1, &E_GL_EXT_ray_query);
8073             symbolTable.setFunctionExtensions("rayQueryConfirmIntersectionEXT",                                   1, &E_GL_EXT_ray_query);
8074             symbolTable.setFunctionExtensions("rayQueryProceedEXT",                                               1, &E_GL_EXT_ray_query);
8075             symbolTable.setFunctionExtensions("rayQueryGetIntersectionTypeEXT",                                   1, &E_GL_EXT_ray_query);
8076             symbolTable.setFunctionExtensions("rayQueryGetIntersectionTEXT",                                      1, &E_GL_EXT_ray_query);
8077             symbolTable.setFunctionExtensions("rayQueryGetRayFlagsEXT",                                           1, &E_GL_EXT_ray_query);
8078             symbolTable.setFunctionExtensions("rayQueryGetRayTMinEXT",                                            1, &E_GL_EXT_ray_query);
8079             symbolTable.setFunctionExtensions("rayQueryGetIntersectionInstanceCustomIndexEXT",                    1, &E_GL_EXT_ray_query);
8080             symbolTable.setFunctionExtensions("rayQueryGetIntersectionInstanceIdEXT",                             1, &E_GL_EXT_ray_query);
8081             symbolTable.setFunctionExtensions("rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT", 1, &E_GL_EXT_ray_query);
8082             symbolTable.setFunctionExtensions("rayQueryGetIntersectionGeometryIndexEXT",                          1, &E_GL_EXT_ray_query);
8083             symbolTable.setFunctionExtensions("rayQueryGetIntersectionPrimitiveIndexEXT",                         1, &E_GL_EXT_ray_query);
8084             symbolTable.setFunctionExtensions("rayQueryGetIntersectionBarycentricsEXT",                           1, &E_GL_EXT_ray_query);
8085             symbolTable.setFunctionExtensions("rayQueryGetIntersectionFrontFaceEXT",                              1, &E_GL_EXT_ray_query);
8086             symbolTable.setFunctionExtensions("rayQueryGetIntersectionCandidateAABBOpaqueEXT",                    1, &E_GL_EXT_ray_query);
8087             symbolTable.setFunctionExtensions("rayQueryGetIntersectionObjectRayDirectionEXT",                     1, &E_GL_EXT_ray_query);
8088             symbolTable.setFunctionExtensions("rayQueryGetIntersectionObjectRayOriginEXT",                        1, &E_GL_EXT_ray_query);
8089             symbolTable.setFunctionExtensions("rayQueryGetIntersectionObjectToWorldEXT",                          1, &E_GL_EXT_ray_query);
8090             symbolTable.setFunctionExtensions("rayQueryGetIntersectionWorldToObjectEXT",                          1, &E_GL_EXT_ray_query);
8091             symbolTable.setFunctionExtensions("rayQueryGetWorldRayOriginEXT",                                     1, &E_GL_EXT_ray_query);
8092             symbolTable.setFunctionExtensions("rayQueryGetWorldRayDirectionEXT",                                  1, &E_GL_EXT_ray_query);
8093             symbolTable.setVariableExtensions("gl_RayFlagsSkipAABBEXT",                         1, &E_GL_EXT_ray_flags_primitive_culling);
8094             symbolTable.setVariableExtensions("gl_RayFlagsSkipTrianglesEXT",                    1, &E_GL_EXT_ray_flags_primitive_culling);
8095         }
8096 
8097         if ((profile != EEsProfile && version >= 130) ||
8098             (profile == EEsProfile && version >= 310)) {
8099             BuiltInVariable("gl_SampleID",           EbvSampleId,       symbolTable);
8100             BuiltInVariable("gl_SamplePosition",     EbvSamplePosition, symbolTable);
8101             BuiltInVariable("gl_SampleMask",         EbvSampleMask,     symbolTable);
8102 
8103             if (profile != EEsProfile && version < 400) {
8104                 BuiltInVariable("gl_NumSamples",     EbvSampleMask,     symbolTable);
8105 
8106                 symbolTable.setVariableExtensions("gl_SampleMask",     1, &E_GL_ARB_sample_shading);
8107                 symbolTable.setVariableExtensions("gl_SampleID",       1, &E_GL_ARB_sample_shading);
8108                 symbolTable.setVariableExtensions("gl_SamplePosition", 1, &E_GL_ARB_sample_shading);
8109                 symbolTable.setVariableExtensions("gl_NumSamples",     1, &E_GL_ARB_sample_shading);
8110             } else {
8111                 BuiltInVariable("gl_SampleMaskIn",    EbvSampleMask,     symbolTable);
8112 
8113                 if (profile == EEsProfile && version < 320) {
8114                     symbolTable.setVariableExtensions("gl_SampleID", 1, &E_GL_OES_sample_variables);
8115                     symbolTable.setVariableExtensions("gl_SamplePosition", 1, &E_GL_OES_sample_variables);
8116                     symbolTable.setVariableExtensions("gl_SampleMaskIn", 1, &E_GL_OES_sample_variables);
8117                     symbolTable.setVariableExtensions("gl_SampleMask", 1, &E_GL_OES_sample_variables);
8118                     symbolTable.setVariableExtensions("gl_NumSamples", 1, &E_GL_OES_sample_variables);
8119                 }
8120             }
8121         }
8122 
8123         BuiltInVariable("gl_Layer",           EbvLayer,          symbolTable);
8124         BuiltInVariable("gl_ViewportIndex",   EbvViewportIndex,  symbolTable);
8125 
8126         // Compatibility variables
8127 
8128         BuiltInVariable("gl_in", "gl_FogFragCoord",   EbvFogFragCoord,   symbolTable);
8129         BuiltInVariable("gl_in", "gl_TexCoord",       EbvTexCoord,       symbolTable);
8130         BuiltInVariable("gl_in", "gl_Color",          EbvColor,          symbolTable);
8131         BuiltInVariable("gl_in", "gl_SecondaryColor", EbvSecondaryColor, symbolTable);
8132 
8133         BuiltInVariable("gl_FogFragCoord",   EbvFogFragCoord,   symbolTable);
8134         BuiltInVariable("gl_TexCoord",       EbvTexCoord,       symbolTable);
8135         BuiltInVariable("gl_Color",          EbvColor,          symbolTable);
8136         BuiltInVariable("gl_SecondaryColor", EbvSecondaryColor, symbolTable);
8137 
8138         // built-in functions
8139 
8140         if (profile == EEsProfile) {
8141             if (spvVersion.spv == 0) {
8142                 symbolTable.setFunctionExtensions("texture2DLodEXT",      1, &E_GL_EXT_shader_texture_lod);
8143                 symbolTable.setFunctionExtensions("texture2DProjLodEXT",  1, &E_GL_EXT_shader_texture_lod);
8144                 symbolTable.setFunctionExtensions("textureCubeLodEXT",    1, &E_GL_EXT_shader_texture_lod);
8145                 symbolTable.setFunctionExtensions("texture2DGradEXT",     1, &E_GL_EXT_shader_texture_lod);
8146                 symbolTable.setFunctionExtensions("texture2DProjGradEXT", 1, &E_GL_EXT_shader_texture_lod);
8147                 symbolTable.setFunctionExtensions("textureCubeGradEXT",   1, &E_GL_EXT_shader_texture_lod);
8148                 if (version < 320)
8149                     symbolTable.setFunctionExtensions("textureGatherOffsets", Num_AEP_gpu_shader5, AEP_gpu_shader5);
8150             }
8151             if (version == 100) {
8152                 symbolTable.setFunctionExtensions("dFdx",   1, &E_GL_OES_standard_derivatives);
8153                 symbolTable.setFunctionExtensions("dFdy",   1, &E_GL_OES_standard_derivatives);
8154                 symbolTable.setFunctionExtensions("fwidth", 1, &E_GL_OES_standard_derivatives);
8155             }
8156             if (version == 310) {
8157                 symbolTable.setFunctionExtensions("fma", Num_AEP_gpu_shader5, AEP_gpu_shader5);
8158                 symbolTable.setFunctionExtensions("interpolateAtCentroid", 1, &E_GL_OES_shader_multisample_interpolation);
8159                 symbolTable.setFunctionExtensions("interpolateAtSample",   1, &E_GL_OES_shader_multisample_interpolation);
8160                 symbolTable.setFunctionExtensions("interpolateAtOffset",   1, &E_GL_OES_shader_multisample_interpolation);
8161             }
8162         } else if (version < 130) {
8163             if (spvVersion.spv == 0) {
8164                 symbolTable.setFunctionExtensions("texture1DLod",        1, &E_GL_ARB_shader_texture_lod);
8165                 symbolTable.setFunctionExtensions("texture2DLod",        1, &E_GL_ARB_shader_texture_lod);
8166                 symbolTable.setFunctionExtensions("texture3DLod",        1, &E_GL_ARB_shader_texture_lod);
8167                 symbolTable.setFunctionExtensions("textureCubeLod",      1, &E_GL_ARB_shader_texture_lod);
8168                 symbolTable.setFunctionExtensions("texture1DProjLod",    1, &E_GL_ARB_shader_texture_lod);
8169                 symbolTable.setFunctionExtensions("texture2DProjLod",    1, &E_GL_ARB_shader_texture_lod);
8170                 symbolTable.setFunctionExtensions("texture3DProjLod",    1, &E_GL_ARB_shader_texture_lod);
8171                 symbolTable.setFunctionExtensions("shadow1DLod",         1, &E_GL_ARB_shader_texture_lod);
8172                 symbolTable.setFunctionExtensions("shadow2DLod",         1, &E_GL_ARB_shader_texture_lod);
8173                 symbolTable.setFunctionExtensions("shadow1DProjLod",     1, &E_GL_ARB_shader_texture_lod);
8174                 symbolTable.setFunctionExtensions("shadow2DProjLod",     1, &E_GL_ARB_shader_texture_lod);
8175             }
8176         }
8177 
8178         // E_GL_ARB_shader_texture_lod functions usable only with the extension enabled
8179         if (profile != EEsProfile && spvVersion.spv == 0) {
8180             symbolTable.setFunctionExtensions("texture1DGradARB",         1, &E_GL_ARB_shader_texture_lod);
8181             symbolTable.setFunctionExtensions("texture1DProjGradARB",     1, &E_GL_ARB_shader_texture_lod);
8182             symbolTable.setFunctionExtensions("texture2DGradARB",         1, &E_GL_ARB_shader_texture_lod);
8183             symbolTable.setFunctionExtensions("texture2DProjGradARB",     1, &E_GL_ARB_shader_texture_lod);
8184             symbolTable.setFunctionExtensions("texture3DGradARB",         1, &E_GL_ARB_shader_texture_lod);
8185             symbolTable.setFunctionExtensions("texture3DProjGradARB",     1, &E_GL_ARB_shader_texture_lod);
8186             symbolTable.setFunctionExtensions("textureCubeGradARB",       1, &E_GL_ARB_shader_texture_lod);
8187             symbolTable.setFunctionExtensions("shadow1DGradARB",          1, &E_GL_ARB_shader_texture_lod);
8188             symbolTable.setFunctionExtensions("shadow1DProjGradARB",      1, &E_GL_ARB_shader_texture_lod);
8189             symbolTable.setFunctionExtensions("shadow2DGradARB",          1, &E_GL_ARB_shader_texture_lod);
8190             symbolTable.setFunctionExtensions("shadow2DProjGradARB",      1, &E_GL_ARB_shader_texture_lod);
8191             symbolTable.setFunctionExtensions("texture2DRectGradARB",     1, &E_GL_ARB_shader_texture_lod);
8192             symbolTable.setFunctionExtensions("texture2DRectProjGradARB", 1, &E_GL_ARB_shader_texture_lod);
8193             symbolTable.setFunctionExtensions("shadow2DRectGradARB",      1, &E_GL_ARB_shader_texture_lod);
8194             symbolTable.setFunctionExtensions("shadow2DRectProjGradARB",  1, &E_GL_ARB_shader_texture_lod);
8195         }
8196 
8197         // E_GL_ARB_shader_image_load_store
8198         if (profile != EEsProfile && version < 420)
8199             symbolTable.setFunctionExtensions("memoryBarrier", 1, &E_GL_ARB_shader_image_load_store);
8200         // All the image access functions are protected by checks on the type of the first argument.
8201 
8202         // E_GL_ARB_shader_atomic_counters
8203         if (profile != EEsProfile && version < 420) {
8204             symbolTable.setFunctionExtensions("atomicCounterIncrement", 1, &E_GL_ARB_shader_atomic_counters);
8205             symbolTable.setFunctionExtensions("atomicCounterDecrement", 1, &E_GL_ARB_shader_atomic_counters);
8206             symbolTable.setFunctionExtensions("atomicCounter"         , 1, &E_GL_ARB_shader_atomic_counters);
8207         }
8208 
8209         // E_GL_ARB_shader_atomic_counter_ops
8210         if (profile != EEsProfile && version == 450) {
8211             symbolTable.setFunctionExtensions("atomicCounterAddARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8212             symbolTable.setFunctionExtensions("atomicCounterSubtractARB", 1, &E_GL_ARB_shader_atomic_counter_ops);
8213             symbolTable.setFunctionExtensions("atomicCounterMinARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8214             symbolTable.setFunctionExtensions("atomicCounterMaxARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8215             symbolTable.setFunctionExtensions("atomicCounterAndARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8216             symbolTable.setFunctionExtensions("atomicCounterOrARB"      , 1, &E_GL_ARB_shader_atomic_counter_ops);
8217             symbolTable.setFunctionExtensions("atomicCounterXorARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8218             symbolTable.setFunctionExtensions("atomicCounterExchangeARB", 1, &E_GL_ARB_shader_atomic_counter_ops);
8219             symbolTable.setFunctionExtensions("atomicCounterCompSwapARB", 1, &E_GL_ARB_shader_atomic_counter_ops);
8220         }
8221 
8222         // E_GL_ARB_derivative_control
8223         if (profile != EEsProfile && version < 450) {
8224             symbolTable.setFunctionExtensions("dFdxFine",     1, &E_GL_ARB_derivative_control);
8225             symbolTable.setFunctionExtensions("dFdyFine",     1, &E_GL_ARB_derivative_control);
8226             symbolTable.setFunctionExtensions("fwidthFine",   1, &E_GL_ARB_derivative_control);
8227             symbolTable.setFunctionExtensions("dFdxCoarse",   1, &E_GL_ARB_derivative_control);
8228             symbolTable.setFunctionExtensions("dFdyCoarse",   1, &E_GL_ARB_derivative_control);
8229             symbolTable.setFunctionExtensions("fwidthCoarse", 1, &E_GL_ARB_derivative_control);
8230         }
8231 
8232         // E_GL_ARB_sparse_texture2
8233         if (profile != EEsProfile)
8234         {
8235             symbolTable.setFunctionExtensions("sparseTextureARB",              1, &E_GL_ARB_sparse_texture2);
8236             symbolTable.setFunctionExtensions("sparseTextureLodARB",           1, &E_GL_ARB_sparse_texture2);
8237             symbolTable.setFunctionExtensions("sparseTextureOffsetARB",        1, &E_GL_ARB_sparse_texture2);
8238             symbolTable.setFunctionExtensions("sparseTexelFetchARB",           1, &E_GL_ARB_sparse_texture2);
8239             symbolTable.setFunctionExtensions("sparseTexelFetchOffsetARB",     1, &E_GL_ARB_sparse_texture2);
8240             symbolTable.setFunctionExtensions("sparseTextureLodOffsetARB",     1, &E_GL_ARB_sparse_texture2);
8241             symbolTable.setFunctionExtensions("sparseTextureGradARB",          1, &E_GL_ARB_sparse_texture2);
8242             symbolTable.setFunctionExtensions("sparseTextureGradOffsetARB",    1, &E_GL_ARB_sparse_texture2);
8243             symbolTable.setFunctionExtensions("sparseTextureGatherARB",        1, &E_GL_ARB_sparse_texture2);
8244             symbolTable.setFunctionExtensions("sparseTextureGatherOffsetARB",  1, &E_GL_ARB_sparse_texture2);
8245             symbolTable.setFunctionExtensions("sparseTextureGatherOffsetsARB", 1, &E_GL_ARB_sparse_texture2);
8246             symbolTable.setFunctionExtensions("sparseImageLoadARB",            1, &E_GL_ARB_sparse_texture2);
8247             symbolTable.setFunctionExtensions("sparseTexelsResident",          1, &E_GL_ARB_sparse_texture2);
8248         }
8249 
8250         // E_GL_ARB_sparse_texture_clamp
8251         if (profile != EEsProfile)
8252         {
8253             symbolTable.setFunctionExtensions("sparseTextureClampARB",              1, &E_GL_ARB_sparse_texture_clamp);
8254             symbolTable.setFunctionExtensions("sparseTextureOffsetClampARB",        1, &E_GL_ARB_sparse_texture_clamp);
8255             symbolTable.setFunctionExtensions("sparseTextureGradClampARB",          1, &E_GL_ARB_sparse_texture_clamp);
8256             symbolTable.setFunctionExtensions("sparseTextureGradOffsetClampARB",    1, &E_GL_ARB_sparse_texture_clamp);
8257             symbolTable.setFunctionExtensions("textureClampARB",                    1, &E_GL_ARB_sparse_texture_clamp);
8258             symbolTable.setFunctionExtensions("textureOffsetClampARB",              1, &E_GL_ARB_sparse_texture_clamp);
8259             symbolTable.setFunctionExtensions("textureGradClampARB",                1, &E_GL_ARB_sparse_texture_clamp);
8260             symbolTable.setFunctionExtensions("textureGradOffsetClampARB",          1, &E_GL_ARB_sparse_texture_clamp);
8261         }
8262 
8263         // E_GL_AMD_shader_explicit_vertex_parameter
8264         if (profile != EEsProfile) {
8265             symbolTable.setVariableExtensions("gl_BaryCoordNoPerspAMD",         1, &E_GL_AMD_shader_explicit_vertex_parameter);
8266             symbolTable.setVariableExtensions("gl_BaryCoordNoPerspCentroidAMD", 1, &E_GL_AMD_shader_explicit_vertex_parameter);
8267             symbolTable.setVariableExtensions("gl_BaryCoordNoPerspSampleAMD",   1, &E_GL_AMD_shader_explicit_vertex_parameter);
8268             symbolTable.setVariableExtensions("gl_BaryCoordSmoothAMD",          1, &E_GL_AMD_shader_explicit_vertex_parameter);
8269             symbolTable.setVariableExtensions("gl_BaryCoordSmoothCentroidAMD",  1, &E_GL_AMD_shader_explicit_vertex_parameter);
8270             symbolTable.setVariableExtensions("gl_BaryCoordSmoothSampleAMD",    1, &E_GL_AMD_shader_explicit_vertex_parameter);
8271             symbolTable.setVariableExtensions("gl_BaryCoordPullModelAMD",       1, &E_GL_AMD_shader_explicit_vertex_parameter);
8272 
8273             symbolTable.setFunctionExtensions("interpolateAtVertexAMD",         1, &E_GL_AMD_shader_explicit_vertex_parameter);
8274 
8275             BuiltInVariable("gl_BaryCoordNoPerspAMD",           EbvBaryCoordNoPersp,         symbolTable);
8276             BuiltInVariable("gl_BaryCoordNoPerspCentroidAMD",   EbvBaryCoordNoPerspCentroid, symbolTable);
8277             BuiltInVariable("gl_BaryCoordNoPerspSampleAMD",     EbvBaryCoordNoPerspSample,   symbolTable);
8278             BuiltInVariable("gl_BaryCoordSmoothAMD",            EbvBaryCoordSmooth,          symbolTable);
8279             BuiltInVariable("gl_BaryCoordSmoothCentroidAMD",    EbvBaryCoordSmoothCentroid,  symbolTable);
8280             BuiltInVariable("gl_BaryCoordSmoothSampleAMD",      EbvBaryCoordSmoothSample,    symbolTable);
8281             BuiltInVariable("gl_BaryCoordPullModelAMD",         EbvBaryCoordPullModel,       symbolTable);
8282         }
8283 
8284         // E_GL_AMD_texture_gather_bias_lod
8285         if (profile != EEsProfile) {
8286             symbolTable.setFunctionExtensions("textureGatherLodAMD",                1, &E_GL_AMD_texture_gather_bias_lod);
8287             symbolTable.setFunctionExtensions("textureGatherLodOffsetAMD",          1, &E_GL_AMD_texture_gather_bias_lod);
8288             symbolTable.setFunctionExtensions("textureGatherLodOffsetsAMD",         1, &E_GL_AMD_texture_gather_bias_lod);
8289             symbolTable.setFunctionExtensions("sparseTextureGatherLodAMD",          1, &E_GL_AMD_texture_gather_bias_lod);
8290             symbolTable.setFunctionExtensions("sparseTextureGatherLodOffsetAMD",    1, &E_GL_AMD_texture_gather_bias_lod);
8291             symbolTable.setFunctionExtensions("sparseTextureGatherLodOffsetsAMD",   1, &E_GL_AMD_texture_gather_bias_lod);
8292         }
8293 
8294         // E_GL_AMD_shader_image_load_store_lod
8295         if (profile != EEsProfile) {
8296             symbolTable.setFunctionExtensions("imageLoadLodAMD",        1, &E_GL_AMD_shader_image_load_store_lod);
8297             symbolTable.setFunctionExtensions("imageStoreLodAMD",       1, &E_GL_AMD_shader_image_load_store_lod);
8298             symbolTable.setFunctionExtensions("sparseImageLoadLodAMD",  1, &E_GL_AMD_shader_image_load_store_lod);
8299         }
8300         if (profile != EEsProfile && version >= 430) {
8301             symbolTable.setVariableExtensions("gl_FragFullyCoveredNV", 1, &E_GL_NV_conservative_raster_underestimation);
8302             BuiltInVariable("gl_FragFullyCoveredNV", EbvFragFullyCoveredNV, symbolTable);
8303         }
8304         if ((profile != EEsProfile && version >= 450) ||
8305             (profile == EEsProfile && version >= 320)) {
8306             symbolTable.setVariableExtensions("gl_FragmentSizeNV",        1, &E_GL_NV_shading_rate_image);
8307             symbolTable.setVariableExtensions("gl_InvocationsPerPixelNV", 1, &E_GL_NV_shading_rate_image);
8308             BuiltInVariable("gl_FragmentSizeNV",        EbvFragmentSizeNV, symbolTable);
8309             BuiltInVariable("gl_InvocationsPerPixelNV", EbvInvocationsPerPixelNV, symbolTable);
8310             symbolTable.setVariableExtensions("gl_BaryCoordNV",        1, &E_GL_NV_fragment_shader_barycentric);
8311             symbolTable.setVariableExtensions("gl_BaryCoordNoPerspNV", 1, &E_GL_NV_fragment_shader_barycentric);
8312             BuiltInVariable("gl_BaryCoordNV",        EbvBaryCoordNV,        symbolTable);
8313             BuiltInVariable("gl_BaryCoordNoPerspNV", EbvBaryCoordNoPerspNV, symbolTable);
8314         }
8315 
8316         if ((profile != EEsProfile && version >= 450) ||
8317             (profile == EEsProfile && version >= 310)) {
8318             symbolTable.setVariableExtensions("gl_FragSizeEXT",            1, &E_GL_EXT_fragment_invocation_density);
8319             symbolTable.setVariableExtensions("gl_FragInvocationCountEXT", 1, &E_GL_EXT_fragment_invocation_density);
8320             BuiltInVariable("gl_FragSizeEXT",            EbvFragSizeEXT, symbolTable);
8321             BuiltInVariable("gl_FragInvocationCountEXT", EbvFragInvocationCountEXT, symbolTable);
8322         }
8323 
8324         symbolTable.setVariableExtensions("gl_FragDepthEXT", 1, &E_GL_EXT_frag_depth);
8325 
8326         symbolTable.setFunctionExtensions("clockARB",     1, &E_GL_ARB_shader_clock);
8327         symbolTable.setFunctionExtensions("clock2x32ARB", 1, &E_GL_ARB_shader_clock);
8328 
8329         symbolTable.setFunctionExtensions("clockRealtimeEXT", 1, &E_GL_EXT_shader_realtime_clock);
8330         symbolTable.setFunctionExtensions("clockRealtime2x32EXT", 1, &E_GL_EXT_shader_realtime_clock);
8331 
8332         if (profile == EEsProfile && version < 320) {
8333             symbolTable.setVariableExtensions("gl_PrimitiveID",  Num_AEP_geometry_shader, AEP_geometry_shader);
8334             symbolTable.setVariableExtensions("gl_Layer",        Num_AEP_geometry_shader, AEP_geometry_shader);
8335         }
8336 
8337         if (profile == EEsProfile && version < 320) {
8338             symbolTable.setFunctionExtensions("imageAtomicAdd",      1, &E_GL_OES_shader_image_atomic);
8339             symbolTable.setFunctionExtensions("imageAtomicMin",      1, &E_GL_OES_shader_image_atomic);
8340             symbolTable.setFunctionExtensions("imageAtomicMax",      1, &E_GL_OES_shader_image_atomic);
8341             symbolTable.setFunctionExtensions("imageAtomicAnd",      1, &E_GL_OES_shader_image_atomic);
8342             symbolTable.setFunctionExtensions("imageAtomicOr",       1, &E_GL_OES_shader_image_atomic);
8343             symbolTable.setFunctionExtensions("imageAtomicXor",      1, &E_GL_OES_shader_image_atomic);
8344             symbolTable.setFunctionExtensions("imageAtomicExchange", 1, &E_GL_OES_shader_image_atomic);
8345             symbolTable.setFunctionExtensions("imageAtomicCompSwap", 1, &E_GL_OES_shader_image_atomic);
8346         }
8347 
8348         if (profile != EEsProfile && version < 330 ) {
8349             symbolTable.setFunctionExtensions("floatBitsToInt", 1, &E_GL_ARB_shader_bit_encoding);
8350             symbolTable.setFunctionExtensions("floatBitsToUint", 1, &E_GL_ARB_shader_bit_encoding);
8351             symbolTable.setFunctionExtensions("intBitsToFloat", 1, &E_GL_ARB_shader_bit_encoding);
8352             symbolTable.setFunctionExtensions("uintBitsToFloat", 1, &E_GL_ARB_shader_bit_encoding);
8353         }
8354 
8355         if (profile != EEsProfile && version < 430 ) {
8356             symbolTable.setFunctionExtensions("imageSize", 1, &E_GL_ARB_shader_image_size);
8357         }
8358 
8359         // GL_ARB_shader_storage_buffer_object
8360         if (profile != EEsProfile && version < 430 ) {
8361             symbolTable.setFunctionExtensions("atomicAdd", 1, &E_GL_ARB_shader_storage_buffer_object);
8362             symbolTable.setFunctionExtensions("atomicMin", 1, &E_GL_ARB_shader_storage_buffer_object);
8363             symbolTable.setFunctionExtensions("atomicMax", 1, &E_GL_ARB_shader_storage_buffer_object);
8364             symbolTable.setFunctionExtensions("atomicAnd", 1, &E_GL_ARB_shader_storage_buffer_object);
8365             symbolTable.setFunctionExtensions("atomicOr", 1, &E_GL_ARB_shader_storage_buffer_object);
8366             symbolTable.setFunctionExtensions("atomicXor", 1, &E_GL_ARB_shader_storage_buffer_object);
8367             symbolTable.setFunctionExtensions("atomicExchange", 1, &E_GL_ARB_shader_storage_buffer_object);
8368             symbolTable.setFunctionExtensions("atomicCompSwap", 1, &E_GL_ARB_shader_storage_buffer_object);
8369         }
8370 
8371         // GL_ARB_shading_language_packing
8372         if (profile != EEsProfile && version < 400 ) {
8373             symbolTable.setFunctionExtensions("packUnorm2x16", 1, &E_GL_ARB_shading_language_packing);
8374             symbolTable.setFunctionExtensions("unpackUnorm2x16", 1, &E_GL_ARB_shading_language_packing);
8375             symbolTable.setFunctionExtensions("packSnorm4x8", 1, &E_GL_ARB_shading_language_packing);
8376             symbolTable.setFunctionExtensions("packUnorm4x8", 1, &E_GL_ARB_shading_language_packing);
8377             symbolTable.setFunctionExtensions("unpackSnorm4x8", 1, &E_GL_ARB_shading_language_packing);
8378             symbolTable.setFunctionExtensions("unpackUnorm4x8", 1, &E_GL_ARB_shading_language_packing);
8379         }
8380         if (profile != EEsProfile && version < 420 ) {
8381             symbolTable.setFunctionExtensions("packSnorm2x16", 1, &E_GL_ARB_shading_language_packing);
8382             symbolTable.setFunctionExtensions("unpackSnorm2x16", 1, &E_GL_ARB_shading_language_packing);
8383             symbolTable.setFunctionExtensions("unpackHalf2x16", 1, &E_GL_ARB_shading_language_packing);
8384             symbolTable.setFunctionExtensions("packHalf2x16", 1, &E_GL_ARB_shading_language_packing);
8385         }
8386 
8387         symbolTable.setVariableExtensions("gl_DeviceIndex",  1, &E_GL_EXT_device_group);
8388         BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
8389         symbolTable.setVariableExtensions("gl_ViewIndex", 1, &E_GL_EXT_multiview);
8390         BuiltInVariable("gl_ViewIndex", EbvViewIndex, symbolTable);
8391         if (version >= 300 /* both ES and non-ES */) {
8392             symbolTable.setVariableExtensions("gl_ViewID_OVR", Num_OVR_multiview_EXTs, OVR_multiview_EXTs);
8393             BuiltInVariable("gl_ViewID_OVR", EbvViewIndex, symbolTable);
8394         }
8395 
8396         // GL_ARB_shader_ballot
8397         if (profile != EEsProfile) {
8398             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
8399             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
8400             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
8401             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
8402             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
8403             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
8404             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
8405 
8406             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
8407             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
8408             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
8409             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
8410             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
8411             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
8412 
8413             if (spvVersion.vulkan > 0)
8414                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
8415                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
8416             else
8417                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
8418         }
8419 
8420         // GL_KHR_shader_subgroup
8421         if ((profile == EEsProfile && version >= 310) ||
8422             (profile != EEsProfile && version >= 140)) {
8423             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
8424             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
8425             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8426             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8427             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8428             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8429             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8430 
8431             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
8432             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
8433             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
8434             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
8435             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
8436             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
8437             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
8438 
8439             symbolTable.setFunctionExtensions("subgroupBarrier",                 1, &E_GL_KHR_shader_subgroup_basic);
8440             symbolTable.setFunctionExtensions("subgroupMemoryBarrier",           1, &E_GL_KHR_shader_subgroup_basic);
8441             symbolTable.setFunctionExtensions("subgroupMemoryBarrierBuffer",     1, &E_GL_KHR_shader_subgroup_basic);
8442             symbolTable.setFunctionExtensions("subgroupMemoryBarrierImage",      1, &E_GL_KHR_shader_subgroup_basic);
8443             symbolTable.setFunctionExtensions("subgroupElect",                   1, &E_GL_KHR_shader_subgroup_basic);
8444             symbolTable.setFunctionExtensions("subgroupAll",                     1, &E_GL_KHR_shader_subgroup_vote);
8445             symbolTable.setFunctionExtensions("subgroupAny",                     1, &E_GL_KHR_shader_subgroup_vote);
8446             symbolTable.setFunctionExtensions("subgroupAllEqual",                1, &E_GL_KHR_shader_subgroup_vote);
8447             symbolTable.setFunctionExtensions("subgroupBroadcast",               1, &E_GL_KHR_shader_subgroup_ballot);
8448             symbolTable.setFunctionExtensions("subgroupBroadcastFirst",          1, &E_GL_KHR_shader_subgroup_ballot);
8449             symbolTable.setFunctionExtensions("subgroupBallot",                  1, &E_GL_KHR_shader_subgroup_ballot);
8450             symbolTable.setFunctionExtensions("subgroupInverseBallot",           1, &E_GL_KHR_shader_subgroup_ballot);
8451             symbolTable.setFunctionExtensions("subgroupBallotBitExtract",        1, &E_GL_KHR_shader_subgroup_ballot);
8452             symbolTable.setFunctionExtensions("subgroupBallotBitCount",          1, &E_GL_KHR_shader_subgroup_ballot);
8453             symbolTable.setFunctionExtensions("subgroupBallotInclusiveBitCount", 1, &E_GL_KHR_shader_subgroup_ballot);
8454             symbolTable.setFunctionExtensions("subgroupBallotExclusiveBitCount", 1, &E_GL_KHR_shader_subgroup_ballot);
8455             symbolTable.setFunctionExtensions("subgroupBallotFindLSB",           1, &E_GL_KHR_shader_subgroup_ballot);
8456             symbolTable.setFunctionExtensions("subgroupBallotFindMSB",           1, &E_GL_KHR_shader_subgroup_ballot);
8457             symbolTable.setFunctionExtensions("subgroupShuffle",                 1, &E_GL_KHR_shader_subgroup_shuffle);
8458             symbolTable.setFunctionExtensions("subgroupShuffleXor",              1, &E_GL_KHR_shader_subgroup_shuffle);
8459             symbolTable.setFunctionExtensions("subgroupShuffleUp",               1, &E_GL_KHR_shader_subgroup_shuffle_relative);
8460             symbolTable.setFunctionExtensions("subgroupShuffleDown",             1, &E_GL_KHR_shader_subgroup_shuffle_relative);
8461             symbolTable.setFunctionExtensions("subgroupAdd",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8462             symbolTable.setFunctionExtensions("subgroupMul",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8463             symbolTable.setFunctionExtensions("subgroupMin",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8464             symbolTable.setFunctionExtensions("subgroupMax",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8465             symbolTable.setFunctionExtensions("subgroupAnd",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8466             symbolTable.setFunctionExtensions("subgroupOr",                      1, &E_GL_KHR_shader_subgroup_arithmetic);
8467             symbolTable.setFunctionExtensions("subgroupXor",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8468             symbolTable.setFunctionExtensions("subgroupInclusiveAdd",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8469             symbolTable.setFunctionExtensions("subgroupInclusiveMul",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8470             symbolTable.setFunctionExtensions("subgroupInclusiveMin",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8471             symbolTable.setFunctionExtensions("subgroupInclusiveMax",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8472             symbolTable.setFunctionExtensions("subgroupInclusiveAnd",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8473             symbolTable.setFunctionExtensions("subgroupInclusiveOr",             1, &E_GL_KHR_shader_subgroup_arithmetic);
8474             symbolTable.setFunctionExtensions("subgroupInclusiveXor",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8475             symbolTable.setFunctionExtensions("subgroupExclusiveAdd",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8476             symbolTable.setFunctionExtensions("subgroupExclusiveMul",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8477             symbolTable.setFunctionExtensions("subgroupExclusiveMin",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8478             symbolTable.setFunctionExtensions("subgroupExclusiveMax",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8479             symbolTable.setFunctionExtensions("subgroupExclusiveAnd",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8480             symbolTable.setFunctionExtensions("subgroupExclusiveOr",             1, &E_GL_KHR_shader_subgroup_arithmetic);
8481             symbolTable.setFunctionExtensions("subgroupExclusiveXor",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8482             symbolTable.setFunctionExtensions("subgroupClusteredAdd",            1, &E_GL_KHR_shader_subgroup_clustered);
8483             symbolTable.setFunctionExtensions("subgroupClusteredMul",            1, &E_GL_KHR_shader_subgroup_clustered);
8484             symbolTable.setFunctionExtensions("subgroupClusteredMin",            1, &E_GL_KHR_shader_subgroup_clustered);
8485             symbolTable.setFunctionExtensions("subgroupClusteredMax",            1, &E_GL_KHR_shader_subgroup_clustered);
8486             symbolTable.setFunctionExtensions("subgroupClusteredAnd",            1, &E_GL_KHR_shader_subgroup_clustered);
8487             symbolTable.setFunctionExtensions("subgroupClusteredOr",             1, &E_GL_KHR_shader_subgroup_clustered);
8488             symbolTable.setFunctionExtensions("subgroupClusteredXor",            1, &E_GL_KHR_shader_subgroup_clustered);
8489             symbolTable.setFunctionExtensions("subgroupQuadBroadcast",           1, &E_GL_KHR_shader_subgroup_quad);
8490             symbolTable.setFunctionExtensions("subgroupQuadSwapHorizontal",      1, &E_GL_KHR_shader_subgroup_quad);
8491             symbolTable.setFunctionExtensions("subgroupQuadSwapVertical",        1, &E_GL_KHR_shader_subgroup_quad);
8492             symbolTable.setFunctionExtensions("subgroupQuadSwapDiagonal",        1, &E_GL_KHR_shader_subgroup_quad);
8493             symbolTable.setFunctionExtensions("subgroupPartitionNV",                          1, &E_GL_NV_shader_subgroup_partitioned);
8494             symbolTable.setFunctionExtensions("subgroupPartitionedAddNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8495             symbolTable.setFunctionExtensions("subgroupPartitionedMulNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8496             symbolTable.setFunctionExtensions("subgroupPartitionedMinNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8497             symbolTable.setFunctionExtensions("subgroupPartitionedMaxNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8498             symbolTable.setFunctionExtensions("subgroupPartitionedAndNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8499             symbolTable.setFunctionExtensions("subgroupPartitionedOrNV",                      1, &E_GL_NV_shader_subgroup_partitioned);
8500             symbolTable.setFunctionExtensions("subgroupPartitionedXorNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8501             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveAddNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8502             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveMulNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8503             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveMinNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8504             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveMaxNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8505             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveAndNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8506             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveOrNV",             1, &E_GL_NV_shader_subgroup_partitioned);
8507             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveXorNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8508             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveAddNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8509             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveMulNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8510             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveMinNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8511             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveMaxNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8512             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveAndNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8513             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveOrNV",             1, &E_GL_NV_shader_subgroup_partitioned);
8514             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveXorNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8515 
8516             // GL_NV_shader_sm_builtins
8517             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
8518             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
8519             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
8520             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
8521             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
8522             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
8523             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
8524             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
8525         }
8526 
8527         if (profile == EEsProfile) {
8528             symbolTable.setFunctionExtensions("shadow2DEXT",        1, &E_GL_EXT_shadow_samplers);
8529             symbolTable.setFunctionExtensions("shadow2DProjEXT",    1, &E_GL_EXT_shadow_samplers);
8530         }
8531 
8532         if (spvVersion.vulkan > 0) {
8533             symbolTable.setVariableExtensions("gl_ScopeDevice",             1, &E_GL_KHR_memory_scope_semantics);
8534             symbolTable.setVariableExtensions("gl_ScopeWorkgroup",          1, &E_GL_KHR_memory_scope_semantics);
8535             symbolTable.setVariableExtensions("gl_ScopeSubgroup",           1, &E_GL_KHR_memory_scope_semantics);
8536             symbolTable.setVariableExtensions("gl_ScopeInvocation",         1, &E_GL_KHR_memory_scope_semantics);
8537 
8538             symbolTable.setVariableExtensions("gl_SemanticsRelaxed",        1, &E_GL_KHR_memory_scope_semantics);
8539             symbolTable.setVariableExtensions("gl_SemanticsAcquire",        1, &E_GL_KHR_memory_scope_semantics);
8540             symbolTable.setVariableExtensions("gl_SemanticsRelease",        1, &E_GL_KHR_memory_scope_semantics);
8541             symbolTable.setVariableExtensions("gl_SemanticsAcquireRelease", 1, &E_GL_KHR_memory_scope_semantics);
8542             symbolTable.setVariableExtensions("gl_SemanticsMakeAvailable",  1, &E_GL_KHR_memory_scope_semantics);
8543             symbolTable.setVariableExtensions("gl_SemanticsMakeVisible",    1, &E_GL_KHR_memory_scope_semantics);
8544             symbolTable.setVariableExtensions("gl_SemanticsVolatile",       1, &E_GL_KHR_memory_scope_semantics);
8545 
8546             symbolTable.setVariableExtensions("gl_StorageSemanticsNone",    1, &E_GL_KHR_memory_scope_semantics);
8547             symbolTable.setVariableExtensions("gl_StorageSemanticsBuffer",  1, &E_GL_KHR_memory_scope_semantics);
8548             symbolTable.setVariableExtensions("gl_StorageSemanticsShared",  1, &E_GL_KHR_memory_scope_semantics);
8549             symbolTable.setVariableExtensions("gl_StorageSemanticsImage",   1, &E_GL_KHR_memory_scope_semantics);
8550             symbolTable.setVariableExtensions("gl_StorageSemanticsOutput",  1, &E_GL_KHR_memory_scope_semantics);
8551         }
8552 
8553         symbolTable.setFunctionExtensions("helperInvocationEXT",            1, &E_GL_EXT_demote_to_helper_invocation);
8554 
8555         if ((profile == EEsProfile && version >= 310) ||
8556             (profile != EEsProfile && version >= 450)) {
8557             symbolTable.setVariableExtensions("gl_ShadingRateEXT", 1, &E_GL_EXT_fragment_shading_rate);
8558             BuiltInVariable("gl_ShadingRateEXT", EbvShadingRateKHR, symbolTable);
8559 
8560             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8561             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8562             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8563             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8564         }
8565 #endif // !GLSLANG_WEB
8566         break;
8567 
8568     case EShLangCompute:
8569         BuiltInVariable("gl_NumWorkGroups",         EbvNumWorkGroups,        symbolTable);
8570         BuiltInVariable("gl_WorkGroupSize",         EbvWorkGroupSize,        symbolTable);
8571         BuiltInVariable("gl_WorkGroupID",           EbvWorkGroupId,          symbolTable);
8572         BuiltInVariable("gl_LocalInvocationID",     EbvLocalInvocationId,    symbolTable);
8573         BuiltInVariable("gl_GlobalInvocationID",    EbvGlobalInvocationId,   symbolTable);
8574         BuiltInVariable("gl_LocalInvocationIndex",  EbvLocalInvocationIndex, symbolTable);
8575         BuiltInVariable("gl_DeviceIndex",           EbvDeviceIndex,          symbolTable);
8576         BuiltInVariable("gl_ViewIndex",             EbvViewIndex,            symbolTable);
8577 
8578 #ifndef GLSLANG_WEB
8579         if ((profile != EEsProfile && version >= 140) ||
8580             (profile == EEsProfile && version >= 310)) {
8581             symbolTable.setVariableExtensions("gl_DeviceIndex",  1, &E_GL_EXT_device_group);
8582             symbolTable.setVariableExtensions("gl_ViewIndex",    1, &E_GL_EXT_multiview);
8583         }
8584 
8585         if (profile != EEsProfile && version < 430) {
8586             symbolTable.setVariableExtensions("gl_NumWorkGroups",        1, &E_GL_ARB_compute_shader);
8587             symbolTable.setVariableExtensions("gl_WorkGroupSize",        1, &E_GL_ARB_compute_shader);
8588             symbolTable.setVariableExtensions("gl_WorkGroupID",          1, &E_GL_ARB_compute_shader);
8589             symbolTable.setVariableExtensions("gl_LocalInvocationID",    1, &E_GL_ARB_compute_shader);
8590             symbolTable.setVariableExtensions("gl_GlobalInvocationID",   1, &E_GL_ARB_compute_shader);
8591             symbolTable.setVariableExtensions("gl_LocalInvocationIndex", 1, &E_GL_ARB_compute_shader);
8592 
8593             symbolTable.setVariableExtensions("gl_MaxComputeWorkGroupCount",       1, &E_GL_ARB_compute_shader);
8594             symbolTable.setVariableExtensions("gl_MaxComputeWorkGroupSize",        1, &E_GL_ARB_compute_shader);
8595             symbolTable.setVariableExtensions("gl_MaxComputeUniformComponents",    1, &E_GL_ARB_compute_shader);
8596             symbolTable.setVariableExtensions("gl_MaxComputeTextureImageUnits",    1, &E_GL_ARB_compute_shader);
8597             symbolTable.setVariableExtensions("gl_MaxComputeImageUniforms",        1, &E_GL_ARB_compute_shader);
8598             symbolTable.setVariableExtensions("gl_MaxComputeAtomicCounters",       1, &E_GL_ARB_compute_shader);
8599             symbolTable.setVariableExtensions("gl_MaxComputeAtomicCounterBuffers", 1, &E_GL_ARB_compute_shader);
8600 
8601             symbolTable.setFunctionExtensions("barrier",                    1, &E_GL_ARB_compute_shader);
8602             symbolTable.setFunctionExtensions("memoryBarrierAtomicCounter", 1, &E_GL_ARB_compute_shader);
8603             symbolTable.setFunctionExtensions("memoryBarrierBuffer",        1, &E_GL_ARB_compute_shader);
8604             symbolTable.setFunctionExtensions("memoryBarrierImage",         1, &E_GL_ARB_compute_shader);
8605             symbolTable.setFunctionExtensions("memoryBarrierShared",        1, &E_GL_ARB_compute_shader);
8606             symbolTable.setFunctionExtensions("groupMemoryBarrier",         1, &E_GL_ARB_compute_shader);
8607         }
8608 
8609 
8610         symbolTable.setFunctionExtensions("controlBarrier",                 1, &E_GL_KHR_memory_scope_semantics);
8611         symbolTable.setFunctionExtensions("debugPrintfEXT",                 1, &E_GL_EXT_debug_printf);
8612 
8613         // GL_ARB_shader_ballot
8614         if (profile != EEsProfile) {
8615             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
8616             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
8617             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
8618             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
8619             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
8620             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
8621             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
8622 
8623             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
8624             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
8625             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
8626             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
8627             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
8628             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
8629 
8630             if (spvVersion.vulkan > 0)
8631                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
8632                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
8633             else
8634                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
8635         }
8636 
8637         // GL_KHR_shader_subgroup
8638         if ((profile == EEsProfile && version >= 310) ||
8639             (profile != EEsProfile && version >= 140)) {
8640             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
8641             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
8642             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8643             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8644             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8645             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8646             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8647 
8648             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
8649             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
8650             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
8651             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
8652             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
8653             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
8654             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
8655 
8656             // GL_NV_shader_sm_builtins
8657             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
8658             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
8659             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
8660             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
8661             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
8662             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
8663             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
8664             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
8665         }
8666 
8667         // GL_KHR_shader_subgroup
8668         if ((profile == EEsProfile && version >= 310) ||
8669             (profile != EEsProfile && version >= 140)) {
8670             symbolTable.setVariableExtensions("gl_NumSubgroups", 1, &E_GL_KHR_shader_subgroup_basic);
8671             symbolTable.setVariableExtensions("gl_SubgroupID",   1, &E_GL_KHR_shader_subgroup_basic);
8672 
8673             BuiltInVariable("gl_NumSubgroups", EbvNumSubgroups, symbolTable);
8674             BuiltInVariable("gl_SubgroupID",   EbvSubgroupID,   symbolTable);
8675 
8676             symbolTable.setFunctionExtensions("subgroupMemoryBarrierShared", 1, &E_GL_KHR_shader_subgroup_basic);
8677         }
8678 
8679         {
8680             const char *coopExt[2] = { E_GL_NV_cooperative_matrix, E_GL_NV_integer_cooperative_matrix };
8681             symbolTable.setFunctionExtensions("coopMatLoadNV",   2, coopExt);
8682             symbolTable.setFunctionExtensions("coopMatStoreNV",  2, coopExt);
8683             symbolTable.setFunctionExtensions("coopMatMulAddNV", 2, coopExt);
8684         }
8685 
8686         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
8687             symbolTable.setFunctionExtensions("dFdx",                   1, &E_GL_NV_compute_shader_derivatives);
8688             symbolTable.setFunctionExtensions("dFdy",                   1, &E_GL_NV_compute_shader_derivatives);
8689             symbolTable.setFunctionExtensions("fwidth",                 1, &E_GL_NV_compute_shader_derivatives);
8690             symbolTable.setFunctionExtensions("dFdxFine",               1, &E_GL_NV_compute_shader_derivatives);
8691             symbolTable.setFunctionExtensions("dFdyFine",               1, &E_GL_NV_compute_shader_derivatives);
8692             symbolTable.setFunctionExtensions("fwidthFine",             1, &E_GL_NV_compute_shader_derivatives);
8693             symbolTable.setFunctionExtensions("dFdxCoarse",             1, &E_GL_NV_compute_shader_derivatives);
8694             symbolTable.setFunctionExtensions("dFdyCoarse",             1, &E_GL_NV_compute_shader_derivatives);
8695             symbolTable.setFunctionExtensions("fwidthCoarse",           1, &E_GL_NV_compute_shader_derivatives);
8696         }
8697 
8698         if ((profile == EEsProfile && version >= 310) ||
8699             (profile != EEsProfile && version >= 450)) {
8700             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8701             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8702             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8703             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8704         }
8705 #endif // !GLSLANG_WEB
8706         break;
8707 
8708 #if !defined(GLSLANG_WEB) && !defined(GLSLANG_ANGLE)
8709     case EShLangRayGen:
8710     case EShLangIntersect:
8711     case EShLangAnyHit:
8712     case EShLangClosestHit:
8713     case EShLangMiss:
8714     case EShLangCallable:
8715         if (profile != EEsProfile && version >= 460) {
8716             const char *rtexts[] = { E_GL_NV_ray_tracing, E_GL_EXT_ray_tracing };
8717             symbolTable.setVariableExtensions("gl_LaunchIDNV", 1, &E_GL_NV_ray_tracing);
8718             symbolTable.setVariableExtensions("gl_LaunchIDEXT", 1, &E_GL_EXT_ray_tracing);
8719             symbolTable.setVariableExtensions("gl_LaunchSizeNV", 1, &E_GL_NV_ray_tracing);
8720             symbolTable.setVariableExtensions("gl_LaunchSizeEXT", 1, &E_GL_EXT_ray_tracing);
8721             symbolTable.setVariableExtensions("gl_PrimitiveID", 2, rtexts);
8722             symbolTable.setVariableExtensions("gl_InstanceID", 2, rtexts);
8723             symbolTable.setVariableExtensions("gl_InstanceCustomIndexNV", 1, &E_GL_NV_ray_tracing);
8724             symbolTable.setVariableExtensions("gl_InstanceCustomIndexEXT", 1, &E_GL_EXT_ray_tracing);
8725             symbolTable.setVariableExtensions("gl_GeometryIndexEXT", 1, &E_GL_EXT_ray_tracing);
8726             symbolTable.setVariableExtensions("gl_WorldRayOriginNV", 1, &E_GL_NV_ray_tracing);
8727             symbolTable.setVariableExtensions("gl_WorldRayOriginEXT", 1, &E_GL_EXT_ray_tracing);
8728             symbolTable.setVariableExtensions("gl_WorldRayDirectionNV", 1, &E_GL_NV_ray_tracing);
8729             symbolTable.setVariableExtensions("gl_WorldRayDirectionEXT", 1, &E_GL_EXT_ray_tracing);
8730             symbolTable.setVariableExtensions("gl_ObjectRayOriginNV", 1, &E_GL_NV_ray_tracing);
8731             symbolTable.setVariableExtensions("gl_ObjectRayOriginEXT", 1, &E_GL_EXT_ray_tracing);
8732             symbolTable.setVariableExtensions("gl_ObjectRayDirectionNV", 1, &E_GL_NV_ray_tracing);
8733             symbolTable.setVariableExtensions("gl_ObjectRayDirectionEXT", 1, &E_GL_EXT_ray_tracing);
8734             symbolTable.setVariableExtensions("gl_RayTminNV", 1, &E_GL_NV_ray_tracing);
8735             symbolTable.setVariableExtensions("gl_RayTminEXT", 1, &E_GL_EXT_ray_tracing);
8736             symbolTable.setVariableExtensions("gl_RayTmaxNV", 1, &E_GL_NV_ray_tracing);
8737             symbolTable.setVariableExtensions("gl_RayTmaxEXT", 1, &E_GL_EXT_ray_tracing);
8738             symbolTable.setVariableExtensions("gl_HitTNV", 1, &E_GL_NV_ray_tracing);
8739             symbolTable.setVariableExtensions("gl_HitTEXT", 1, &E_GL_EXT_ray_tracing);
8740             symbolTable.setVariableExtensions("gl_HitKindNV", 1, &E_GL_NV_ray_tracing);
8741             symbolTable.setVariableExtensions("gl_HitKindEXT", 1, &E_GL_EXT_ray_tracing);
8742             symbolTable.setVariableExtensions("gl_ObjectToWorldNV", 1, &E_GL_NV_ray_tracing);
8743             symbolTable.setVariableExtensions("gl_ObjectToWorldEXT", 1, &E_GL_EXT_ray_tracing);
8744             symbolTable.setVariableExtensions("gl_ObjectToWorld3x4EXT", 1, &E_GL_EXT_ray_tracing);
8745             symbolTable.setVariableExtensions("gl_WorldToObjectNV", 1, &E_GL_NV_ray_tracing);
8746             symbolTable.setVariableExtensions("gl_WorldToObjectEXT", 1, &E_GL_EXT_ray_tracing);
8747             symbolTable.setVariableExtensions("gl_WorldToObject3x4EXT", 1, &E_GL_EXT_ray_tracing);
8748             symbolTable.setVariableExtensions("gl_IncomingRayFlagsNV", 1, &E_GL_NV_ray_tracing);
8749             symbolTable.setVariableExtensions("gl_IncomingRayFlagsEXT", 1, &E_GL_EXT_ray_tracing);
8750             symbolTable.setVariableExtensions("gl_CurrentRayTimeNV", 1, &E_GL_NV_ray_tracing_motion_blur);
8751 
8752             symbolTable.setVariableExtensions("gl_DeviceIndex", 1, &E_GL_EXT_device_group);
8753 
8754 
8755             symbolTable.setFunctionExtensions("traceNV", 1, &E_GL_NV_ray_tracing);
8756             symbolTable.setFunctionExtensions("traceRayMotionNV", 1, &E_GL_NV_ray_tracing_motion_blur);
8757             symbolTable.setFunctionExtensions("traceRayEXT", 1, &E_GL_EXT_ray_tracing);
8758             symbolTable.setFunctionExtensions("reportIntersectionNV", 1, &E_GL_NV_ray_tracing);
8759             symbolTable.setFunctionExtensions("reportIntersectionEXT", 1, &E_GL_EXT_ray_tracing);
8760             symbolTable.setFunctionExtensions("ignoreIntersectionNV", 1, &E_GL_NV_ray_tracing);
8761             symbolTable.setFunctionExtensions("terminateRayNV", 1, &E_GL_NV_ray_tracing);
8762             symbolTable.setFunctionExtensions("executeCallableNV", 1, &E_GL_NV_ray_tracing);
8763             symbolTable.setFunctionExtensions("executeCallableEXT", 1, &E_GL_EXT_ray_tracing);
8764 
8765 
8766             BuiltInVariable("gl_LaunchIDNV",             EbvLaunchId,           symbolTable);
8767             BuiltInVariable("gl_LaunchIDEXT",            EbvLaunchId,           symbolTable);
8768             BuiltInVariable("gl_LaunchSizeNV",           EbvLaunchSize,         symbolTable);
8769             BuiltInVariable("gl_LaunchSizeEXT",          EbvLaunchSize,         symbolTable);
8770             BuiltInVariable("gl_PrimitiveID",            EbvPrimitiveId,        symbolTable);
8771             BuiltInVariable("gl_InstanceID",             EbvInstanceId,         symbolTable);
8772             BuiltInVariable("gl_InstanceCustomIndexNV",  EbvInstanceCustomIndex,symbolTable);
8773             BuiltInVariable("gl_InstanceCustomIndexEXT", EbvInstanceCustomIndex,symbolTable);
8774             BuiltInVariable("gl_GeometryIndexEXT",       EbvGeometryIndex,      symbolTable);
8775             BuiltInVariable("gl_WorldRayOriginNV",       EbvWorldRayOrigin,     symbolTable);
8776             BuiltInVariable("gl_WorldRayOriginEXT",      EbvWorldRayOrigin,     symbolTable);
8777             BuiltInVariable("gl_WorldRayDirectionNV",    EbvWorldRayDirection,  symbolTable);
8778             BuiltInVariable("gl_WorldRayDirectionEXT",   EbvWorldRayDirection,  symbolTable);
8779             BuiltInVariable("gl_ObjectRayOriginNV",      EbvObjectRayOrigin,    symbolTable);
8780             BuiltInVariable("gl_ObjectRayOriginEXT",     EbvObjectRayOrigin,    symbolTable);
8781             BuiltInVariable("gl_ObjectRayDirectionNV",   EbvObjectRayDirection, symbolTable);
8782             BuiltInVariable("gl_ObjectRayDirectionEXT",  EbvObjectRayDirection, symbolTable);
8783             BuiltInVariable("gl_RayTminNV",              EbvRayTmin,            symbolTable);
8784             BuiltInVariable("gl_RayTminEXT",             EbvRayTmin,            symbolTable);
8785             BuiltInVariable("gl_RayTmaxNV",              EbvRayTmax,            symbolTable);
8786             BuiltInVariable("gl_RayTmaxEXT",             EbvRayTmax,            symbolTable);
8787             BuiltInVariable("gl_HitTNV",                 EbvHitT,               symbolTable);
8788             BuiltInVariable("gl_HitTEXT",                EbvHitT,               symbolTable);
8789             BuiltInVariable("gl_HitKindNV",              EbvHitKind,            symbolTable);
8790             BuiltInVariable("gl_HitKindEXT",             EbvHitKind,            symbolTable);
8791             BuiltInVariable("gl_ObjectToWorldNV",        EbvObjectToWorld,      symbolTable);
8792             BuiltInVariable("gl_ObjectToWorldEXT",       EbvObjectToWorld,      symbolTable);
8793             BuiltInVariable("gl_ObjectToWorld3x4EXT",    EbvObjectToWorld3x4,   symbolTable);
8794             BuiltInVariable("gl_WorldToObjectNV",        EbvWorldToObject,      symbolTable);
8795             BuiltInVariable("gl_WorldToObjectEXT",       EbvWorldToObject,      symbolTable);
8796             BuiltInVariable("gl_WorldToObject3x4EXT",    EbvWorldToObject3x4,   symbolTable);
8797             BuiltInVariable("gl_IncomingRayFlagsNV",     EbvIncomingRayFlags,   symbolTable);
8798             BuiltInVariable("gl_IncomingRayFlagsEXT",    EbvIncomingRayFlags,   symbolTable);
8799             BuiltInVariable("gl_DeviceIndex",            EbvDeviceIndex,        symbolTable);
8800             BuiltInVariable("gl_CurrentRayTimeNV",       EbvCurrentRayTimeNV,   symbolTable);
8801 
8802             // GL_ARB_shader_ballot
8803             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
8804             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
8805             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
8806             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
8807             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
8808             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
8809             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
8810 
8811             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
8812             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
8813             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
8814             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
8815             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
8816             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
8817 
8818             if (spvVersion.vulkan > 0)
8819                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
8820                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
8821             else
8822                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
8823 
8824             // GL_KHR_shader_subgroup
8825             symbolTable.setVariableExtensions("gl_NumSubgroups",         1, &E_GL_KHR_shader_subgroup_basic);
8826             symbolTable.setVariableExtensions("gl_SubgroupID",           1, &E_GL_KHR_shader_subgroup_basic);
8827             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
8828             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
8829             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8830             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8831             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8832             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8833             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8834 
8835             BuiltInVariable("gl_NumSubgroups",         EbvNumSubgroups,        symbolTable);
8836             BuiltInVariable("gl_SubgroupID",           EbvSubgroupID,          symbolTable);
8837             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
8838             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
8839             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
8840             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
8841             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
8842             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
8843             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
8844 
8845             // GL_NV_shader_sm_builtins
8846             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
8847             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
8848             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
8849             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
8850             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
8851             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
8852             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
8853             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
8854         }
8855         if ((profile == EEsProfile && version >= 310) ||
8856             (profile != EEsProfile && version >= 450)) {
8857             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8858             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8859             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8860             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8861         }
8862         break;
8863 
8864     case EShLangMeshNV:
8865         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
8866             // per-vertex builtins
8867             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_Position",     1, &E_GL_NV_mesh_shader);
8868             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_PointSize",    1, &E_GL_NV_mesh_shader);
8869             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_ClipDistance", 1, &E_GL_NV_mesh_shader);
8870             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_CullDistance", 1, &E_GL_NV_mesh_shader);
8871 
8872             BuiltInVariable("gl_MeshVerticesNV", "gl_Position",     EbvPosition,     symbolTable);
8873             BuiltInVariable("gl_MeshVerticesNV", "gl_PointSize",    EbvPointSize,    symbolTable);
8874             BuiltInVariable("gl_MeshVerticesNV", "gl_ClipDistance", EbvClipDistance, symbolTable);
8875             BuiltInVariable("gl_MeshVerticesNV", "gl_CullDistance", EbvCullDistance, symbolTable);
8876 
8877             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_PositionPerViewNV",     1, &E_GL_NV_mesh_shader);
8878             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_ClipDistancePerViewNV", 1, &E_GL_NV_mesh_shader);
8879             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_CullDistancePerViewNV", 1, &E_GL_NV_mesh_shader);
8880 
8881             BuiltInVariable("gl_MeshVerticesNV", "gl_PositionPerViewNV",     EbvPositionPerViewNV,     symbolTable);
8882             BuiltInVariable("gl_MeshVerticesNV", "gl_ClipDistancePerViewNV", EbvClipDistancePerViewNV, symbolTable);
8883             BuiltInVariable("gl_MeshVerticesNV", "gl_CullDistancePerViewNV", EbvCullDistancePerViewNV, symbolTable);
8884 
8885             // per-primitive builtins
8886             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_PrimitiveID",   1, &E_GL_NV_mesh_shader);
8887             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_Layer",         1, &E_GL_NV_mesh_shader);
8888             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_ViewportIndex", 1, &E_GL_NV_mesh_shader);
8889             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_ViewportMask",  1, &E_GL_NV_mesh_shader);
8890 
8891             BuiltInVariable("gl_MeshPrimitivesNV", "gl_PrimitiveID",   EbvPrimitiveId,    symbolTable);
8892             BuiltInVariable("gl_MeshPrimitivesNV", "gl_Layer",         EbvLayer,          symbolTable);
8893             BuiltInVariable("gl_MeshPrimitivesNV", "gl_ViewportIndex", EbvViewportIndex,  symbolTable);
8894             BuiltInVariable("gl_MeshPrimitivesNV", "gl_ViewportMask",  EbvViewportMaskNV, symbolTable);
8895 
8896             // per-view per-primitive builtins
8897             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_LayerPerViewNV",        1, &E_GL_NV_mesh_shader);
8898             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_ViewportMaskPerViewNV", 1, &E_GL_NV_mesh_shader);
8899 
8900             BuiltInVariable("gl_MeshPrimitivesNV", "gl_LayerPerViewNV",        EbvLayerPerViewNV,        symbolTable);
8901             BuiltInVariable("gl_MeshPrimitivesNV", "gl_ViewportMaskPerViewNV", EbvViewportMaskPerViewNV, symbolTable);
8902 
8903             // other builtins
8904             symbolTable.setVariableExtensions("gl_PrimitiveCountNV",     1, &E_GL_NV_mesh_shader);
8905             symbolTable.setVariableExtensions("gl_PrimitiveIndicesNV",   1, &E_GL_NV_mesh_shader);
8906             symbolTable.setVariableExtensions("gl_MeshViewCountNV",      1, &E_GL_NV_mesh_shader);
8907             symbolTable.setVariableExtensions("gl_MeshViewIndicesNV",    1, &E_GL_NV_mesh_shader);
8908             symbolTable.setVariableExtensions("gl_WorkGroupSize",        1, &E_GL_NV_mesh_shader);
8909             symbolTable.setVariableExtensions("gl_WorkGroupID",          1, &E_GL_NV_mesh_shader);
8910             symbolTable.setVariableExtensions("gl_LocalInvocationID",    1, &E_GL_NV_mesh_shader);
8911             symbolTable.setVariableExtensions("gl_GlobalInvocationID",   1, &E_GL_NV_mesh_shader);
8912             symbolTable.setVariableExtensions("gl_LocalInvocationIndex", 1, &E_GL_NV_mesh_shader);
8913 
8914             BuiltInVariable("gl_PrimitiveCountNV",     EbvPrimitiveCountNV,     symbolTable);
8915             BuiltInVariable("gl_PrimitiveIndicesNV",   EbvPrimitiveIndicesNV,   symbolTable);
8916             BuiltInVariable("gl_MeshViewCountNV",      EbvMeshViewCountNV,      symbolTable);
8917             BuiltInVariable("gl_MeshViewIndicesNV",    EbvMeshViewIndicesNV,    symbolTable);
8918             BuiltInVariable("gl_WorkGroupSize",        EbvWorkGroupSize,        symbolTable);
8919             BuiltInVariable("gl_WorkGroupID",          EbvWorkGroupId,          symbolTable);
8920             BuiltInVariable("gl_LocalInvocationID",    EbvLocalInvocationId,    symbolTable);
8921             BuiltInVariable("gl_GlobalInvocationID",   EbvGlobalInvocationId,   symbolTable);
8922             BuiltInVariable("gl_LocalInvocationIndex", EbvLocalInvocationIndex, symbolTable);
8923 
8924             // builtin constants
8925             symbolTable.setVariableExtensions("gl_MaxMeshOutputVerticesNV",   1, &E_GL_NV_mesh_shader);
8926             symbolTable.setVariableExtensions("gl_MaxMeshOutputPrimitivesNV", 1, &E_GL_NV_mesh_shader);
8927             symbolTable.setVariableExtensions("gl_MaxMeshWorkGroupSizeNV",    1, &E_GL_NV_mesh_shader);
8928             symbolTable.setVariableExtensions("gl_MaxMeshViewCountNV",        1, &E_GL_NV_mesh_shader);
8929 
8930             // builtin functions
8931             symbolTable.setFunctionExtensions("barrier",                      1, &E_GL_NV_mesh_shader);
8932             symbolTable.setFunctionExtensions("memoryBarrierShared",          1, &E_GL_NV_mesh_shader);
8933             symbolTable.setFunctionExtensions("groupMemoryBarrier",           1, &E_GL_NV_mesh_shader);
8934         }
8935 
8936         if (profile != EEsProfile && version >= 450) {
8937             // GL_EXT_device_group
8938             symbolTable.setVariableExtensions("gl_DeviceIndex", 1, &E_GL_EXT_device_group);
8939             BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
8940 
8941             // GL_ARB_shader_draw_parameters
8942             symbolTable.setVariableExtensions("gl_DrawIDARB", 1, &E_GL_ARB_shader_draw_parameters);
8943             BuiltInVariable("gl_DrawIDARB", EbvDrawId, symbolTable);
8944             if (version >= 460) {
8945                 BuiltInVariable("gl_DrawID", EbvDrawId, symbolTable);
8946             }
8947 
8948             // GL_ARB_shader_ballot
8949             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
8950             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
8951             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
8952             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
8953             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
8954             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
8955             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
8956 
8957             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
8958             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
8959             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
8960             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
8961             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
8962             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
8963 
8964             if (spvVersion.vulkan > 0)
8965                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
8966                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
8967             else
8968                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
8969         }
8970 
8971         // GL_KHR_shader_subgroup
8972         if ((profile == EEsProfile && version >= 310) ||
8973             (profile != EEsProfile && version >= 140)) {
8974             symbolTable.setVariableExtensions("gl_NumSubgroups",         1, &E_GL_KHR_shader_subgroup_basic);
8975             symbolTable.setVariableExtensions("gl_SubgroupID",           1, &E_GL_KHR_shader_subgroup_basic);
8976             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
8977             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
8978             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8979             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8980             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8981             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8982             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8983 
8984             BuiltInVariable("gl_NumSubgroups",         EbvNumSubgroups,        symbolTable);
8985             BuiltInVariable("gl_SubgroupID",           EbvSubgroupID,          symbolTable);
8986             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
8987             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
8988             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
8989             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
8990             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
8991             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
8992             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
8993 
8994             symbolTable.setFunctionExtensions("subgroupMemoryBarrierShared", 1, &E_GL_KHR_shader_subgroup_basic);
8995 
8996             // GL_NV_shader_sm_builtins
8997             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
8998             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
8999             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
9000             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
9001             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
9002             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
9003             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
9004             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
9005         }
9006 
9007         if ((profile == EEsProfile && version >= 310) ||
9008             (profile != EEsProfile && version >= 450)) {
9009             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9010             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9011             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9012             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9013         }
9014         break;
9015 
9016     case EShLangTaskNV:
9017         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
9018             symbolTable.setVariableExtensions("gl_TaskCountNV",          1, &E_GL_NV_mesh_shader);
9019             symbolTable.setVariableExtensions("gl_WorkGroupSize",        1, &E_GL_NV_mesh_shader);
9020             symbolTable.setVariableExtensions("gl_WorkGroupID",          1, &E_GL_NV_mesh_shader);
9021             symbolTable.setVariableExtensions("gl_LocalInvocationID",    1, &E_GL_NV_mesh_shader);
9022             symbolTable.setVariableExtensions("gl_GlobalInvocationID",   1, &E_GL_NV_mesh_shader);
9023             symbolTable.setVariableExtensions("gl_LocalInvocationIndex", 1, &E_GL_NV_mesh_shader);
9024             symbolTable.setVariableExtensions("gl_MeshViewCountNV",      1, &E_GL_NV_mesh_shader);
9025             symbolTable.setVariableExtensions("gl_MeshViewIndicesNV",    1, &E_GL_NV_mesh_shader);
9026 
9027             BuiltInVariable("gl_TaskCountNV",          EbvTaskCountNV,          symbolTable);
9028             BuiltInVariable("gl_WorkGroupSize",        EbvWorkGroupSize,        symbolTable);
9029             BuiltInVariable("gl_WorkGroupID",          EbvWorkGroupId,          symbolTable);
9030             BuiltInVariable("gl_LocalInvocationID",    EbvLocalInvocationId,    symbolTable);
9031             BuiltInVariable("gl_GlobalInvocationID",   EbvGlobalInvocationId,   symbolTable);
9032             BuiltInVariable("gl_LocalInvocationIndex", EbvLocalInvocationIndex, symbolTable);
9033             BuiltInVariable("gl_MeshViewCountNV",      EbvMeshViewCountNV,      symbolTable);
9034             BuiltInVariable("gl_MeshViewIndicesNV",    EbvMeshViewIndicesNV,    symbolTable);
9035 
9036             symbolTable.setVariableExtensions("gl_MaxTaskWorkGroupSizeNV", 1, &E_GL_NV_mesh_shader);
9037             symbolTable.setVariableExtensions("gl_MaxMeshViewCountNV",     1, &E_GL_NV_mesh_shader);
9038 
9039             symbolTable.setFunctionExtensions("barrier",                   1, &E_GL_NV_mesh_shader);
9040             symbolTable.setFunctionExtensions("memoryBarrierShared",       1, &E_GL_NV_mesh_shader);
9041             symbolTable.setFunctionExtensions("groupMemoryBarrier",        1, &E_GL_NV_mesh_shader);
9042         }
9043 
9044         if (profile != EEsProfile && version >= 450) {
9045             // GL_EXT_device_group
9046             symbolTable.setVariableExtensions("gl_DeviceIndex", 1, &E_GL_EXT_device_group);
9047             BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
9048 
9049             // GL_ARB_shader_draw_parameters
9050             symbolTable.setVariableExtensions("gl_DrawIDARB", 1, &E_GL_ARB_shader_draw_parameters);
9051             BuiltInVariable("gl_DrawIDARB", EbvDrawId, symbolTable);
9052             if (version >= 460) {
9053                 BuiltInVariable("gl_DrawID", EbvDrawId, symbolTable);
9054             }
9055 
9056             // GL_ARB_shader_ballot
9057             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
9058             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
9059             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
9060             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
9061             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
9062             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
9063             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
9064 
9065             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
9066             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
9067             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
9068             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
9069             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
9070             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
9071 
9072             if (spvVersion.vulkan > 0)
9073                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
9074                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
9075             else
9076                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
9077         }
9078 
9079         // GL_KHR_shader_subgroup
9080         if ((profile == EEsProfile && version >= 310) ||
9081             (profile != EEsProfile && version >= 140)) {
9082             symbolTable.setVariableExtensions("gl_NumSubgroups",         1, &E_GL_KHR_shader_subgroup_basic);
9083             symbolTable.setVariableExtensions("gl_SubgroupID",           1, &E_GL_KHR_shader_subgroup_basic);
9084             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
9085             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
9086             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9087             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9088             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9089             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9090             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9091 
9092             BuiltInVariable("gl_NumSubgroups",         EbvNumSubgroups,        symbolTable);
9093             BuiltInVariable("gl_SubgroupID",           EbvSubgroupID,          symbolTable);
9094             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
9095             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
9096             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
9097             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
9098             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
9099             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
9100             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
9101 
9102             symbolTable.setFunctionExtensions("subgroupMemoryBarrierShared", 1, &E_GL_KHR_shader_subgroup_basic);
9103 
9104             // GL_NV_shader_sm_builtins
9105             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
9106             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
9107             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
9108             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
9109             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
9110             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
9111             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
9112             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
9113         }
9114         if ((profile == EEsProfile && version >= 310) ||
9115             (profile != EEsProfile && version >= 450)) {
9116             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9117             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9118             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9119             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9120         }
9121         break;
9122 #endif
9123 
9124     default:
9125         assert(false && "Language not supported");
9126         break;
9127     }
9128 
9129     //
9130     // Next, identify which built-ins have a mapping to an operator.
9131     // If PureOperatorBuiltins is false, those that are not identified as such are
9132     // expected to be resolved through a library of functions, versus as
9133     // operations.
9134     //
9135 
9136     relateTabledBuiltins(version, profile, spvVersion, language, symbolTable);
9137 
9138 #ifndef GLSLANG_WEB
9139     symbolTable.relateToOperator("doubleBitsToInt64",  EOpDoubleBitsToInt64);
9140     symbolTable.relateToOperator("doubleBitsToUint64", EOpDoubleBitsToUint64);
9141     symbolTable.relateToOperator("int64BitsToDouble",  EOpInt64BitsToDouble);
9142     symbolTable.relateToOperator("uint64BitsToDouble", EOpUint64BitsToDouble);
9143     symbolTable.relateToOperator("halfBitsToInt16",  EOpFloat16BitsToInt16);
9144     symbolTable.relateToOperator("halfBitsToUint16", EOpFloat16BitsToUint16);
9145     symbolTable.relateToOperator("float16BitsToInt16",  EOpFloat16BitsToInt16);
9146     symbolTable.relateToOperator("float16BitsToUint16", EOpFloat16BitsToUint16);
9147     symbolTable.relateToOperator("int16BitsToFloat16",  EOpInt16BitsToFloat16);
9148     symbolTable.relateToOperator("uint16BitsToFloat16", EOpUint16BitsToFloat16);
9149 
9150     symbolTable.relateToOperator("int16BitsToHalf",  EOpInt16BitsToFloat16);
9151     symbolTable.relateToOperator("uint16BitsToHalf", EOpUint16BitsToFloat16);
9152 
9153     symbolTable.relateToOperator("packSnorm4x8",    EOpPackSnorm4x8);
9154     symbolTable.relateToOperator("unpackSnorm4x8",  EOpUnpackSnorm4x8);
9155     symbolTable.relateToOperator("packUnorm4x8",    EOpPackUnorm4x8);
9156     symbolTable.relateToOperator("unpackUnorm4x8",  EOpUnpackUnorm4x8);
9157 
9158     symbolTable.relateToOperator("packDouble2x32",    EOpPackDouble2x32);
9159     symbolTable.relateToOperator("unpackDouble2x32",  EOpUnpackDouble2x32);
9160 
9161     symbolTable.relateToOperator("packInt2x32",     EOpPackInt2x32);
9162     symbolTable.relateToOperator("unpackInt2x32",   EOpUnpackInt2x32);
9163     symbolTable.relateToOperator("packUint2x32",    EOpPackUint2x32);
9164     symbolTable.relateToOperator("unpackUint2x32",  EOpUnpackUint2x32);
9165 
9166     symbolTable.relateToOperator("packInt2x16",     EOpPackInt2x16);
9167     symbolTable.relateToOperator("unpackInt2x16",   EOpUnpackInt2x16);
9168     symbolTable.relateToOperator("packUint2x16",    EOpPackUint2x16);
9169     symbolTable.relateToOperator("unpackUint2x16",  EOpUnpackUint2x16);
9170 
9171     symbolTable.relateToOperator("packInt4x16",     EOpPackInt4x16);
9172     symbolTable.relateToOperator("unpackInt4x16",   EOpUnpackInt4x16);
9173     symbolTable.relateToOperator("packUint4x16",    EOpPackUint4x16);
9174     symbolTable.relateToOperator("unpackUint4x16",  EOpUnpackUint4x16);
9175     symbolTable.relateToOperator("packFloat2x16",   EOpPackFloat2x16);
9176     symbolTable.relateToOperator("unpackFloat2x16", EOpUnpackFloat2x16);
9177 
9178     symbolTable.relateToOperator("pack16",          EOpPack16);
9179     symbolTable.relateToOperator("pack32",          EOpPack32);
9180     symbolTable.relateToOperator("pack64",          EOpPack64);
9181 
9182     symbolTable.relateToOperator("unpack32",        EOpUnpack32);
9183     symbolTable.relateToOperator("unpack16",        EOpUnpack16);
9184     symbolTable.relateToOperator("unpack8",         EOpUnpack8);
9185 
9186     symbolTable.relateToOperator("controlBarrier",             EOpBarrier);
9187     symbolTable.relateToOperator("memoryBarrierAtomicCounter", EOpMemoryBarrierAtomicCounter);
9188     symbolTable.relateToOperator("memoryBarrierImage",         EOpMemoryBarrierImage);
9189 
9190     if (spvVersion.vulkanRelaxed) {
9191         //
9192         // functions signature have been replaced to take uint operations on buffer variables
9193         // remap atomic counter functions to atomic operations
9194         //
9195         symbolTable.relateToOperator("memoryBarrierAtomicCounter", EOpMemoryBarrierBuffer);
9196     }
9197 
9198     symbolTable.relateToOperator("atomicLoad",     EOpAtomicLoad);
9199     symbolTable.relateToOperator("atomicStore",    EOpAtomicStore);
9200 
9201     symbolTable.relateToOperator("atomicCounterIncrement", EOpAtomicCounterIncrement);
9202     symbolTable.relateToOperator("atomicCounterDecrement", EOpAtomicCounterDecrement);
9203     symbolTable.relateToOperator("atomicCounter",          EOpAtomicCounter);
9204 
9205     if (spvVersion.vulkanRelaxed) {
9206         //
9207         // functions signature have been replaced to take uint operations
9208         // remap atomic counter functions to atomic operations
9209         //
9210         // these atomic counter functions do not match signatures of glsl
9211         // atomic functions, so they will be remapped to semantically
9212         // equivalent functions in the parser
9213         //
9214         symbolTable.relateToOperator("atomicCounterIncrement", EOpNull);
9215         symbolTable.relateToOperator("atomicCounterDecrement", EOpNull);
9216         symbolTable.relateToOperator("atomicCounter", EOpNull);
9217     }
9218 
9219     symbolTable.relateToOperator("clockARB",     EOpReadClockSubgroupKHR);
9220     symbolTable.relateToOperator("clock2x32ARB", EOpReadClockSubgroupKHR);
9221 
9222     symbolTable.relateToOperator("clockRealtimeEXT",     EOpReadClockDeviceKHR);
9223     symbolTable.relateToOperator("clockRealtime2x32EXT", EOpReadClockDeviceKHR);
9224 
9225     if (profile != EEsProfile && version == 450) {
9226         symbolTable.relateToOperator("atomicCounterAddARB",      EOpAtomicCounterAdd);
9227         symbolTable.relateToOperator("atomicCounterSubtractARB", EOpAtomicCounterSubtract);
9228         symbolTable.relateToOperator("atomicCounterMinARB",      EOpAtomicCounterMin);
9229         symbolTable.relateToOperator("atomicCounterMaxARB",      EOpAtomicCounterMax);
9230         symbolTable.relateToOperator("atomicCounterAndARB",      EOpAtomicCounterAnd);
9231         symbolTable.relateToOperator("atomicCounterOrARB",       EOpAtomicCounterOr);
9232         symbolTable.relateToOperator("atomicCounterXorARB",      EOpAtomicCounterXor);
9233         symbolTable.relateToOperator("atomicCounterExchangeARB", EOpAtomicCounterExchange);
9234         symbolTable.relateToOperator("atomicCounterCompSwapARB", EOpAtomicCounterCompSwap);
9235     }
9236 
9237     if (profile != EEsProfile && version >= 460) {
9238         symbolTable.relateToOperator("atomicCounterAdd",      EOpAtomicCounterAdd);
9239         symbolTable.relateToOperator("atomicCounterSubtract", EOpAtomicCounterSubtract);
9240         symbolTable.relateToOperator("atomicCounterMin",      EOpAtomicCounterMin);
9241         symbolTable.relateToOperator("atomicCounterMax",      EOpAtomicCounterMax);
9242         symbolTable.relateToOperator("atomicCounterAnd",      EOpAtomicCounterAnd);
9243         symbolTable.relateToOperator("atomicCounterOr",       EOpAtomicCounterOr);
9244         symbolTable.relateToOperator("atomicCounterXor",      EOpAtomicCounterXor);
9245         symbolTable.relateToOperator("atomicCounterExchange", EOpAtomicCounterExchange);
9246         symbolTable.relateToOperator("atomicCounterCompSwap", EOpAtomicCounterCompSwap);
9247     }
9248 
9249     if (spvVersion.vulkanRelaxed) {
9250         //
9251         // functions signature have been replaced to take 'uint' instead of 'atomic_uint'
9252         // remap atomic counter functions to non-counter atomic ops so
9253         // functions act as aliases to non-counter atomic ops
9254         //
9255         symbolTable.relateToOperator("atomicCounterAdd", EOpAtomicAdd);
9256         symbolTable.relateToOperator("atomicCounterSubtract", EOpAtomicSubtract);
9257         symbolTable.relateToOperator("atomicCounterMin", EOpAtomicMin);
9258         symbolTable.relateToOperator("atomicCounterMax", EOpAtomicMax);
9259         symbolTable.relateToOperator("atomicCounterAnd", EOpAtomicAnd);
9260         symbolTable.relateToOperator("atomicCounterOr", EOpAtomicOr);
9261         symbolTable.relateToOperator("atomicCounterXor", EOpAtomicXor);
9262         symbolTable.relateToOperator("atomicCounterExchange", EOpAtomicExchange);
9263         symbolTable.relateToOperator("atomicCounterCompSwap", EOpAtomicCompSwap);
9264     }
9265 
9266     symbolTable.relateToOperator("fma",               EOpFma);
9267     symbolTable.relateToOperator("frexp",             EOpFrexp);
9268     symbolTable.relateToOperator("ldexp",             EOpLdexp);
9269     symbolTable.relateToOperator("uaddCarry",         EOpAddCarry);
9270     symbolTable.relateToOperator("usubBorrow",        EOpSubBorrow);
9271     symbolTable.relateToOperator("umulExtended",      EOpUMulExtended);
9272     symbolTable.relateToOperator("imulExtended",      EOpIMulExtended);
9273     symbolTable.relateToOperator("bitfieldExtract",   EOpBitfieldExtract);
9274     symbolTable.relateToOperator("bitfieldInsert",    EOpBitfieldInsert);
9275     symbolTable.relateToOperator("bitfieldReverse",   EOpBitFieldReverse);
9276     symbolTable.relateToOperator("bitCount",          EOpBitCount);
9277     symbolTable.relateToOperator("findLSB",           EOpFindLSB);
9278     symbolTable.relateToOperator("findMSB",           EOpFindMSB);
9279 
9280     symbolTable.relateToOperator("helperInvocationEXT",  EOpIsHelperInvocation);
9281 
9282     symbolTable.relateToOperator("countLeadingZeros",  EOpCountLeadingZeros);
9283     symbolTable.relateToOperator("countTrailingZeros", EOpCountTrailingZeros);
9284     symbolTable.relateToOperator("absoluteDifference", EOpAbsDifference);
9285     symbolTable.relateToOperator("addSaturate",        EOpAddSaturate);
9286     symbolTable.relateToOperator("subtractSaturate",   EOpSubSaturate);
9287     symbolTable.relateToOperator("average",            EOpAverage);
9288     symbolTable.relateToOperator("averageRounded",     EOpAverageRounded);
9289     symbolTable.relateToOperator("multiply32x16",      EOpMul32x16);
9290     symbolTable.relateToOperator("debugPrintfEXT",     EOpDebugPrintf);
9291 
9292 
9293     if (PureOperatorBuiltins) {
9294         symbolTable.relateToOperator("imageSize",               EOpImageQuerySize);
9295         symbolTable.relateToOperator("imageSamples",            EOpImageQuerySamples);
9296         symbolTable.relateToOperator("imageLoad",               EOpImageLoad);
9297         symbolTable.relateToOperator("imageStore",              EOpImageStore);
9298         symbolTable.relateToOperator("imageAtomicAdd",          EOpImageAtomicAdd);
9299         symbolTable.relateToOperator("imageAtomicMin",          EOpImageAtomicMin);
9300         symbolTable.relateToOperator("imageAtomicMax",          EOpImageAtomicMax);
9301         symbolTable.relateToOperator("imageAtomicAnd",          EOpImageAtomicAnd);
9302         symbolTable.relateToOperator("imageAtomicOr",           EOpImageAtomicOr);
9303         symbolTable.relateToOperator("imageAtomicXor",          EOpImageAtomicXor);
9304         symbolTable.relateToOperator("imageAtomicExchange",     EOpImageAtomicExchange);
9305         symbolTable.relateToOperator("imageAtomicCompSwap",     EOpImageAtomicCompSwap);
9306         symbolTable.relateToOperator("imageAtomicLoad",         EOpImageAtomicLoad);
9307         symbolTable.relateToOperator("imageAtomicStore",        EOpImageAtomicStore);
9308 
9309         symbolTable.relateToOperator("subpassLoad",             EOpSubpassLoad);
9310         symbolTable.relateToOperator("subpassLoadMS",           EOpSubpassLoadMS);
9311 
9312         symbolTable.relateToOperator("textureGather",           EOpTextureGather);
9313         symbolTable.relateToOperator("textureGatherOffset",     EOpTextureGatherOffset);
9314         symbolTable.relateToOperator("textureGatherOffsets",    EOpTextureGatherOffsets);
9315 
9316         symbolTable.relateToOperator("noise1", EOpNoise);
9317         symbolTable.relateToOperator("noise2", EOpNoise);
9318         symbolTable.relateToOperator("noise3", EOpNoise);
9319         symbolTable.relateToOperator("noise4", EOpNoise);
9320 
9321         symbolTable.relateToOperator("textureFootprintNV",          EOpImageSampleFootprintNV);
9322         symbolTable.relateToOperator("textureFootprintClampNV",     EOpImageSampleFootprintClampNV);
9323         symbolTable.relateToOperator("textureFootprintLodNV",       EOpImageSampleFootprintLodNV);
9324         symbolTable.relateToOperator("textureFootprintGradNV",      EOpImageSampleFootprintGradNV);
9325         symbolTable.relateToOperator("textureFootprintGradClampNV", EOpImageSampleFootprintGradClampNV);
9326 
9327         if (spvVersion.spv == 0 && IncludeLegacy(version, profile, spvVersion))
9328             symbolTable.relateToOperator("ftransform", EOpFtransform);
9329 
9330         if (spvVersion.spv == 0 && (IncludeLegacy(version, profile, spvVersion) ||
9331             (profile == EEsProfile && version == 100))) {
9332 
9333             symbolTable.relateToOperator("texture1D",                EOpTexture);
9334             symbolTable.relateToOperator("texture1DGradARB",         EOpTextureGrad);
9335             symbolTable.relateToOperator("texture1DProj",            EOpTextureProj);
9336             symbolTable.relateToOperator("texture1DProjGradARB",     EOpTextureProjGrad);
9337             symbolTable.relateToOperator("texture1DLod",             EOpTextureLod);
9338             symbolTable.relateToOperator("texture1DProjLod",         EOpTextureProjLod);
9339 
9340             symbolTable.relateToOperator("texture2DRect",            EOpTexture);
9341             symbolTable.relateToOperator("texture2DRectProj",        EOpTextureProj);
9342             symbolTable.relateToOperator("texture2DRectGradARB",     EOpTextureGrad);
9343             symbolTable.relateToOperator("texture2DRectProjGradARB", EOpTextureProjGrad);
9344             symbolTable.relateToOperator("shadow2DRect",             EOpTexture);
9345             symbolTable.relateToOperator("shadow2DRectProj",         EOpTextureProj);
9346             symbolTable.relateToOperator("shadow2DRectGradARB",      EOpTextureGrad);
9347             symbolTable.relateToOperator("shadow2DRectProjGradARB",  EOpTextureProjGrad);
9348 
9349             symbolTable.relateToOperator("texture2D",                EOpTexture);
9350             symbolTable.relateToOperator("texture2DProj",            EOpTextureProj);
9351             symbolTable.relateToOperator("texture2DGradEXT",         EOpTextureGrad);
9352             symbolTable.relateToOperator("texture2DGradARB",         EOpTextureGrad);
9353             symbolTable.relateToOperator("texture2DProjGradEXT",     EOpTextureProjGrad);
9354             symbolTable.relateToOperator("texture2DProjGradARB",     EOpTextureProjGrad);
9355             symbolTable.relateToOperator("texture2DLod",             EOpTextureLod);
9356             symbolTable.relateToOperator("texture2DLodEXT",          EOpTextureLod);
9357             symbolTable.relateToOperator("texture2DProjLod",         EOpTextureProjLod);
9358             symbolTable.relateToOperator("texture2DProjLodEXT",      EOpTextureProjLod);
9359 
9360             symbolTable.relateToOperator("texture3D",                EOpTexture);
9361             symbolTable.relateToOperator("texture3DGradARB",         EOpTextureGrad);
9362             symbolTable.relateToOperator("texture3DProj",            EOpTextureProj);
9363             symbolTable.relateToOperator("texture3DProjGradARB",     EOpTextureProjGrad);
9364             symbolTable.relateToOperator("texture3DLod",             EOpTextureLod);
9365             symbolTable.relateToOperator("texture3DProjLod",         EOpTextureProjLod);
9366             symbolTable.relateToOperator("textureCube",              EOpTexture);
9367             symbolTable.relateToOperator("textureCubeGradEXT",       EOpTextureGrad);
9368             symbolTable.relateToOperator("textureCubeGradARB",       EOpTextureGrad);
9369             symbolTable.relateToOperator("textureCubeLod",           EOpTextureLod);
9370             symbolTable.relateToOperator("textureCubeLodEXT",        EOpTextureLod);
9371             symbolTable.relateToOperator("shadow1D",                 EOpTexture);
9372             symbolTable.relateToOperator("shadow1DGradARB",          EOpTextureGrad);
9373             symbolTable.relateToOperator("shadow2D",                 EOpTexture);
9374             symbolTable.relateToOperator("shadow2DGradARB",          EOpTextureGrad);
9375             symbolTable.relateToOperator("shadow1DProj",             EOpTextureProj);
9376             symbolTable.relateToOperator("shadow2DProj",             EOpTextureProj);
9377             symbolTable.relateToOperator("shadow1DProjGradARB",      EOpTextureProjGrad);
9378             symbolTable.relateToOperator("shadow2DProjGradARB",      EOpTextureProjGrad);
9379             symbolTable.relateToOperator("shadow1DLod",              EOpTextureLod);
9380             symbolTable.relateToOperator("shadow2DLod",              EOpTextureLod);
9381             symbolTable.relateToOperator("shadow1DProjLod",          EOpTextureProjLod);
9382             symbolTable.relateToOperator("shadow2DProjLod",          EOpTextureProjLod);
9383         }
9384 
9385         if (profile != EEsProfile) {
9386             symbolTable.relateToOperator("sparseTextureARB",                EOpSparseTexture);
9387             symbolTable.relateToOperator("sparseTextureLodARB",             EOpSparseTextureLod);
9388             symbolTable.relateToOperator("sparseTextureOffsetARB",          EOpSparseTextureOffset);
9389             symbolTable.relateToOperator("sparseTexelFetchARB",             EOpSparseTextureFetch);
9390             symbolTable.relateToOperator("sparseTexelFetchOffsetARB",       EOpSparseTextureFetchOffset);
9391             symbolTable.relateToOperator("sparseTextureLodOffsetARB",       EOpSparseTextureLodOffset);
9392             symbolTable.relateToOperator("sparseTextureGradARB",            EOpSparseTextureGrad);
9393             symbolTable.relateToOperator("sparseTextureGradOffsetARB",      EOpSparseTextureGradOffset);
9394             symbolTable.relateToOperator("sparseTextureGatherARB",          EOpSparseTextureGather);
9395             symbolTable.relateToOperator("sparseTextureGatherOffsetARB",    EOpSparseTextureGatherOffset);
9396             symbolTable.relateToOperator("sparseTextureGatherOffsetsARB",   EOpSparseTextureGatherOffsets);
9397             symbolTable.relateToOperator("sparseImageLoadARB",              EOpSparseImageLoad);
9398             symbolTable.relateToOperator("sparseTexelsResidentARB",         EOpSparseTexelsResident);
9399 
9400             symbolTable.relateToOperator("sparseTextureClampARB",           EOpSparseTextureClamp);
9401             symbolTable.relateToOperator("sparseTextureOffsetClampARB",     EOpSparseTextureOffsetClamp);
9402             symbolTable.relateToOperator("sparseTextureGradClampARB",       EOpSparseTextureGradClamp);
9403             symbolTable.relateToOperator("sparseTextureGradOffsetClampARB", EOpSparseTextureGradOffsetClamp);
9404             symbolTable.relateToOperator("textureClampARB",                 EOpTextureClamp);
9405             symbolTable.relateToOperator("textureOffsetClampARB",           EOpTextureOffsetClamp);
9406             symbolTable.relateToOperator("textureGradClampARB",             EOpTextureGradClamp);
9407             symbolTable.relateToOperator("textureGradOffsetClampARB",       EOpTextureGradOffsetClamp);
9408 
9409             symbolTable.relateToOperator("ballotARB",                       EOpBallot);
9410             symbolTable.relateToOperator("readInvocationARB",               EOpReadInvocation);
9411             symbolTable.relateToOperator("readFirstInvocationARB",          EOpReadFirstInvocation);
9412 
9413             if (version >= 430) {
9414                 symbolTable.relateToOperator("anyInvocationARB",            EOpAnyInvocation);
9415                 symbolTable.relateToOperator("allInvocationsARB",           EOpAllInvocations);
9416                 symbolTable.relateToOperator("allInvocationsEqualARB",      EOpAllInvocationsEqual);
9417             }
9418             if (version >= 460) {
9419                 symbolTable.relateToOperator("anyInvocation",               EOpAnyInvocation);
9420                 symbolTable.relateToOperator("allInvocations",              EOpAllInvocations);
9421                 symbolTable.relateToOperator("allInvocationsEqual",         EOpAllInvocationsEqual);
9422             }
9423             symbolTable.relateToOperator("minInvocationsAMD",                           EOpMinInvocations);
9424             symbolTable.relateToOperator("maxInvocationsAMD",                           EOpMaxInvocations);
9425             symbolTable.relateToOperator("addInvocationsAMD",                           EOpAddInvocations);
9426             symbolTable.relateToOperator("minInvocationsNonUniformAMD",                 EOpMinInvocationsNonUniform);
9427             symbolTable.relateToOperator("maxInvocationsNonUniformAMD",                 EOpMaxInvocationsNonUniform);
9428             symbolTable.relateToOperator("addInvocationsNonUniformAMD",                 EOpAddInvocationsNonUniform);
9429             symbolTable.relateToOperator("minInvocationsInclusiveScanAMD",              EOpMinInvocationsInclusiveScan);
9430             symbolTable.relateToOperator("maxInvocationsInclusiveScanAMD",              EOpMaxInvocationsInclusiveScan);
9431             symbolTable.relateToOperator("addInvocationsInclusiveScanAMD",              EOpAddInvocationsInclusiveScan);
9432             symbolTable.relateToOperator("minInvocationsInclusiveScanNonUniformAMD",    EOpMinInvocationsInclusiveScanNonUniform);
9433             symbolTable.relateToOperator("maxInvocationsInclusiveScanNonUniformAMD",    EOpMaxInvocationsInclusiveScanNonUniform);
9434             symbolTable.relateToOperator("addInvocationsInclusiveScanNonUniformAMD",    EOpAddInvocationsInclusiveScanNonUniform);
9435             symbolTable.relateToOperator("minInvocationsExclusiveScanAMD",              EOpMinInvocationsExclusiveScan);
9436             symbolTable.relateToOperator("maxInvocationsExclusiveScanAMD",              EOpMaxInvocationsExclusiveScan);
9437             symbolTable.relateToOperator("addInvocationsExclusiveScanAMD",              EOpAddInvocationsExclusiveScan);
9438             symbolTable.relateToOperator("minInvocationsExclusiveScanNonUniformAMD",    EOpMinInvocationsExclusiveScanNonUniform);
9439             symbolTable.relateToOperator("maxInvocationsExclusiveScanNonUniformAMD",    EOpMaxInvocationsExclusiveScanNonUniform);
9440             symbolTable.relateToOperator("addInvocationsExclusiveScanNonUniformAMD",    EOpAddInvocationsExclusiveScanNonUniform);
9441             symbolTable.relateToOperator("swizzleInvocationsAMD",                       EOpSwizzleInvocations);
9442             symbolTable.relateToOperator("swizzleInvocationsMaskedAMD",                 EOpSwizzleInvocationsMasked);
9443             symbolTable.relateToOperator("writeInvocationAMD",                          EOpWriteInvocation);
9444             symbolTable.relateToOperator("mbcntAMD",                                    EOpMbcnt);
9445 
9446             symbolTable.relateToOperator("min3",    EOpMin3);
9447             symbolTable.relateToOperator("max3",    EOpMax3);
9448             symbolTable.relateToOperator("mid3",    EOpMid3);
9449 
9450             symbolTable.relateToOperator("cubeFaceIndexAMD",    EOpCubeFaceIndex);
9451             symbolTable.relateToOperator("cubeFaceCoordAMD",    EOpCubeFaceCoord);
9452             symbolTable.relateToOperator("timeAMD",             EOpTime);
9453 
9454             symbolTable.relateToOperator("textureGatherLodAMD",                 EOpTextureGatherLod);
9455             symbolTable.relateToOperator("textureGatherLodOffsetAMD",           EOpTextureGatherLodOffset);
9456             symbolTable.relateToOperator("textureGatherLodOffsetsAMD",          EOpTextureGatherLodOffsets);
9457             symbolTable.relateToOperator("sparseTextureGatherLodAMD",           EOpSparseTextureGatherLod);
9458             symbolTable.relateToOperator("sparseTextureGatherLodOffsetAMD",     EOpSparseTextureGatherLodOffset);
9459             symbolTable.relateToOperator("sparseTextureGatherLodOffsetsAMD",    EOpSparseTextureGatherLodOffsets);
9460 
9461             symbolTable.relateToOperator("imageLoadLodAMD",                     EOpImageLoadLod);
9462             symbolTable.relateToOperator("imageStoreLodAMD",                    EOpImageStoreLod);
9463             symbolTable.relateToOperator("sparseImageLoadLodAMD",               EOpSparseImageLoadLod);
9464 
9465             symbolTable.relateToOperator("fragmentMaskFetchAMD",                EOpFragmentMaskFetch);
9466             symbolTable.relateToOperator("fragmentFetchAMD",                    EOpFragmentFetch);
9467         }
9468 
9469         // GL_KHR_shader_subgroup
9470         if ((profile == EEsProfile && version >= 310) ||
9471             (profile != EEsProfile && version >= 140)) {
9472             symbolTable.relateToOperator("subgroupBarrier",                 EOpSubgroupBarrier);
9473             symbolTable.relateToOperator("subgroupMemoryBarrier",           EOpSubgroupMemoryBarrier);
9474             symbolTable.relateToOperator("subgroupMemoryBarrierBuffer",     EOpSubgroupMemoryBarrierBuffer);
9475             symbolTable.relateToOperator("subgroupMemoryBarrierImage",      EOpSubgroupMemoryBarrierImage);
9476             symbolTable.relateToOperator("subgroupElect",                   EOpSubgroupElect);
9477             symbolTable.relateToOperator("subgroupAll",                     EOpSubgroupAll);
9478             symbolTable.relateToOperator("subgroupAny",                     EOpSubgroupAny);
9479             symbolTable.relateToOperator("subgroupAllEqual",                EOpSubgroupAllEqual);
9480             symbolTable.relateToOperator("subgroupBroadcast",               EOpSubgroupBroadcast);
9481             symbolTable.relateToOperator("subgroupBroadcastFirst",          EOpSubgroupBroadcastFirst);
9482             symbolTable.relateToOperator("subgroupBallot",                  EOpSubgroupBallot);
9483             symbolTable.relateToOperator("subgroupInverseBallot",           EOpSubgroupInverseBallot);
9484             symbolTable.relateToOperator("subgroupBallotBitExtract",        EOpSubgroupBallotBitExtract);
9485             symbolTable.relateToOperator("subgroupBallotBitCount",          EOpSubgroupBallotBitCount);
9486             symbolTable.relateToOperator("subgroupBallotInclusiveBitCount", EOpSubgroupBallotInclusiveBitCount);
9487             symbolTable.relateToOperator("subgroupBallotExclusiveBitCount", EOpSubgroupBallotExclusiveBitCount);
9488             symbolTable.relateToOperator("subgroupBallotFindLSB",           EOpSubgroupBallotFindLSB);
9489             symbolTable.relateToOperator("subgroupBallotFindMSB",           EOpSubgroupBallotFindMSB);
9490             symbolTable.relateToOperator("subgroupShuffle",                 EOpSubgroupShuffle);
9491             symbolTable.relateToOperator("subgroupShuffleXor",              EOpSubgroupShuffleXor);
9492             symbolTable.relateToOperator("subgroupShuffleUp",               EOpSubgroupShuffleUp);
9493             symbolTable.relateToOperator("subgroupShuffleDown",             EOpSubgroupShuffleDown);
9494             symbolTable.relateToOperator("subgroupAdd",                     EOpSubgroupAdd);
9495             symbolTable.relateToOperator("subgroupMul",                     EOpSubgroupMul);
9496             symbolTable.relateToOperator("subgroupMin",                     EOpSubgroupMin);
9497             symbolTable.relateToOperator("subgroupMax",                     EOpSubgroupMax);
9498             symbolTable.relateToOperator("subgroupAnd",                     EOpSubgroupAnd);
9499             symbolTable.relateToOperator("subgroupOr",                      EOpSubgroupOr);
9500             symbolTable.relateToOperator("subgroupXor",                     EOpSubgroupXor);
9501             symbolTable.relateToOperator("subgroupInclusiveAdd",            EOpSubgroupInclusiveAdd);
9502             symbolTable.relateToOperator("subgroupInclusiveMul",            EOpSubgroupInclusiveMul);
9503             symbolTable.relateToOperator("subgroupInclusiveMin",            EOpSubgroupInclusiveMin);
9504             symbolTable.relateToOperator("subgroupInclusiveMax",            EOpSubgroupInclusiveMax);
9505             symbolTable.relateToOperator("subgroupInclusiveAnd",            EOpSubgroupInclusiveAnd);
9506             symbolTable.relateToOperator("subgroupInclusiveOr",             EOpSubgroupInclusiveOr);
9507             symbolTable.relateToOperator("subgroupInclusiveXor",            EOpSubgroupInclusiveXor);
9508             symbolTable.relateToOperator("subgroupExclusiveAdd",            EOpSubgroupExclusiveAdd);
9509             symbolTable.relateToOperator("subgroupExclusiveMul",            EOpSubgroupExclusiveMul);
9510             symbolTable.relateToOperator("subgroupExclusiveMin",            EOpSubgroupExclusiveMin);
9511             symbolTable.relateToOperator("subgroupExclusiveMax",            EOpSubgroupExclusiveMax);
9512             symbolTable.relateToOperator("subgroupExclusiveAnd",            EOpSubgroupExclusiveAnd);
9513             symbolTable.relateToOperator("subgroupExclusiveOr",             EOpSubgroupExclusiveOr);
9514             symbolTable.relateToOperator("subgroupExclusiveXor",            EOpSubgroupExclusiveXor);
9515             symbolTable.relateToOperator("subgroupClusteredAdd",            EOpSubgroupClusteredAdd);
9516             symbolTable.relateToOperator("subgroupClusteredMul",            EOpSubgroupClusteredMul);
9517             symbolTable.relateToOperator("subgroupClusteredMin",            EOpSubgroupClusteredMin);
9518             symbolTable.relateToOperator("subgroupClusteredMax",            EOpSubgroupClusteredMax);
9519             symbolTable.relateToOperator("subgroupClusteredAnd",            EOpSubgroupClusteredAnd);
9520             symbolTable.relateToOperator("subgroupClusteredOr",             EOpSubgroupClusteredOr);
9521             symbolTable.relateToOperator("subgroupClusteredXor",            EOpSubgroupClusteredXor);
9522             symbolTable.relateToOperator("subgroupQuadBroadcast",           EOpSubgroupQuadBroadcast);
9523             symbolTable.relateToOperator("subgroupQuadSwapHorizontal",      EOpSubgroupQuadSwapHorizontal);
9524             symbolTable.relateToOperator("subgroupQuadSwapVertical",        EOpSubgroupQuadSwapVertical);
9525             symbolTable.relateToOperator("subgroupQuadSwapDiagonal",        EOpSubgroupQuadSwapDiagonal);
9526 
9527             symbolTable.relateToOperator("subgroupPartitionNV",                          EOpSubgroupPartition);
9528             symbolTable.relateToOperator("subgroupPartitionedAddNV",                     EOpSubgroupPartitionedAdd);
9529             symbolTable.relateToOperator("subgroupPartitionedMulNV",                     EOpSubgroupPartitionedMul);
9530             symbolTable.relateToOperator("subgroupPartitionedMinNV",                     EOpSubgroupPartitionedMin);
9531             symbolTable.relateToOperator("subgroupPartitionedMaxNV",                     EOpSubgroupPartitionedMax);
9532             symbolTable.relateToOperator("subgroupPartitionedAndNV",                     EOpSubgroupPartitionedAnd);
9533             symbolTable.relateToOperator("subgroupPartitionedOrNV",                      EOpSubgroupPartitionedOr);
9534             symbolTable.relateToOperator("subgroupPartitionedXorNV",                     EOpSubgroupPartitionedXor);
9535             symbolTable.relateToOperator("subgroupPartitionedInclusiveAddNV",            EOpSubgroupPartitionedInclusiveAdd);
9536             symbolTable.relateToOperator("subgroupPartitionedInclusiveMulNV",            EOpSubgroupPartitionedInclusiveMul);
9537             symbolTable.relateToOperator("subgroupPartitionedInclusiveMinNV",            EOpSubgroupPartitionedInclusiveMin);
9538             symbolTable.relateToOperator("subgroupPartitionedInclusiveMaxNV",            EOpSubgroupPartitionedInclusiveMax);
9539             symbolTable.relateToOperator("subgroupPartitionedInclusiveAndNV",            EOpSubgroupPartitionedInclusiveAnd);
9540             symbolTable.relateToOperator("subgroupPartitionedInclusiveOrNV",             EOpSubgroupPartitionedInclusiveOr);
9541             symbolTable.relateToOperator("subgroupPartitionedInclusiveXorNV",            EOpSubgroupPartitionedInclusiveXor);
9542             symbolTable.relateToOperator("subgroupPartitionedExclusiveAddNV",            EOpSubgroupPartitionedExclusiveAdd);
9543             symbolTable.relateToOperator("subgroupPartitionedExclusiveMulNV",            EOpSubgroupPartitionedExclusiveMul);
9544             symbolTable.relateToOperator("subgroupPartitionedExclusiveMinNV",            EOpSubgroupPartitionedExclusiveMin);
9545             symbolTable.relateToOperator("subgroupPartitionedExclusiveMaxNV",            EOpSubgroupPartitionedExclusiveMax);
9546             symbolTable.relateToOperator("subgroupPartitionedExclusiveAndNV",            EOpSubgroupPartitionedExclusiveAnd);
9547             symbolTable.relateToOperator("subgroupPartitionedExclusiveOrNV",             EOpSubgroupPartitionedExclusiveOr);
9548             symbolTable.relateToOperator("subgroupPartitionedExclusiveXorNV",            EOpSubgroupPartitionedExclusiveXor);
9549         }
9550 
9551         if (profile == EEsProfile) {
9552             symbolTable.relateToOperator("shadow2DEXT",              EOpTexture);
9553             symbolTable.relateToOperator("shadow2DProjEXT",          EOpTextureProj);
9554         }
9555     }
9556 
9557     switch(language) {
9558     case EShLangVertex:
9559         break;
9560 
9561     case EShLangTessControl:
9562     case EShLangTessEvaluation:
9563         break;
9564 
9565     case EShLangGeometry:
9566         symbolTable.relateToOperator("EmitStreamVertex",   EOpEmitStreamVertex);
9567         symbolTable.relateToOperator("EndStreamPrimitive", EOpEndStreamPrimitive);
9568         symbolTable.relateToOperator("EmitVertex",         EOpEmitVertex);
9569         symbolTable.relateToOperator("EndPrimitive",       EOpEndPrimitive);
9570         break;
9571 
9572     case EShLangFragment:
9573         if (profile != EEsProfile && version >= 400) {
9574             symbolTable.relateToOperator("dFdxFine",     EOpDPdxFine);
9575             symbolTable.relateToOperator("dFdyFine",     EOpDPdyFine);
9576             symbolTable.relateToOperator("fwidthFine",   EOpFwidthFine);
9577             symbolTable.relateToOperator("dFdxCoarse",   EOpDPdxCoarse);
9578             symbolTable.relateToOperator("dFdyCoarse",   EOpDPdyCoarse);
9579             symbolTable.relateToOperator("fwidthCoarse", EOpFwidthCoarse);
9580         }
9581 
9582         if (profile != EEsProfile && version >= 460) {
9583             symbolTable.relateToOperator("rayQueryInitializeEXT",                                             EOpRayQueryInitialize);
9584             symbolTable.relateToOperator("rayQueryTerminateEXT",                                              EOpRayQueryTerminate);
9585             symbolTable.relateToOperator("rayQueryGenerateIntersectionEXT",                                   EOpRayQueryGenerateIntersection);
9586             symbolTable.relateToOperator("rayQueryConfirmIntersectionEXT",                                    EOpRayQueryConfirmIntersection);
9587             symbolTable.relateToOperator("rayQueryProceedEXT",                                                EOpRayQueryProceed);
9588             symbolTable.relateToOperator("rayQueryGetIntersectionTypeEXT",                                    EOpRayQueryGetIntersectionType);
9589             symbolTable.relateToOperator("rayQueryGetRayTMinEXT",                                             EOpRayQueryGetRayTMin);
9590             symbolTable.relateToOperator("rayQueryGetRayFlagsEXT",                                            EOpRayQueryGetRayFlags);
9591             symbolTable.relateToOperator("rayQueryGetIntersectionTEXT",                                       EOpRayQueryGetIntersectionT);
9592             symbolTable.relateToOperator("rayQueryGetIntersectionInstanceCustomIndexEXT",                     EOpRayQueryGetIntersectionInstanceCustomIndex);
9593             symbolTable.relateToOperator("rayQueryGetIntersectionInstanceIdEXT",                              EOpRayQueryGetIntersectionInstanceId);
9594             symbolTable.relateToOperator("rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT",  EOpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffset);
9595             symbolTable.relateToOperator("rayQueryGetIntersectionGeometryIndexEXT",                           EOpRayQueryGetIntersectionGeometryIndex);
9596             symbolTable.relateToOperator("rayQueryGetIntersectionPrimitiveIndexEXT",                          EOpRayQueryGetIntersectionPrimitiveIndex);
9597             symbolTable.relateToOperator("rayQueryGetIntersectionBarycentricsEXT",                            EOpRayQueryGetIntersectionBarycentrics);
9598             symbolTable.relateToOperator("rayQueryGetIntersectionFrontFaceEXT",                               EOpRayQueryGetIntersectionFrontFace);
9599             symbolTable.relateToOperator("rayQueryGetIntersectionCandidateAABBOpaqueEXT",                     EOpRayQueryGetIntersectionCandidateAABBOpaque);
9600             symbolTable.relateToOperator("rayQueryGetIntersectionObjectRayDirectionEXT",                      EOpRayQueryGetIntersectionObjectRayDirection);
9601             symbolTable.relateToOperator("rayQueryGetIntersectionObjectRayOriginEXT",                         EOpRayQueryGetIntersectionObjectRayOrigin);
9602             symbolTable.relateToOperator("rayQueryGetWorldRayDirectionEXT",                                   EOpRayQueryGetWorldRayDirection);
9603             symbolTable.relateToOperator("rayQueryGetWorldRayOriginEXT",                                      EOpRayQueryGetWorldRayOrigin);
9604             symbolTable.relateToOperator("rayQueryGetIntersectionObjectToWorldEXT",                           EOpRayQueryGetIntersectionObjectToWorld);
9605             symbolTable.relateToOperator("rayQueryGetIntersectionWorldToObjectEXT",                           EOpRayQueryGetIntersectionWorldToObject);
9606         }
9607 
9608         symbolTable.relateToOperator("interpolateAtCentroid", EOpInterpolateAtCentroid);
9609         symbolTable.relateToOperator("interpolateAtSample",   EOpInterpolateAtSample);
9610         symbolTable.relateToOperator("interpolateAtOffset",   EOpInterpolateAtOffset);
9611 
9612         if (profile != EEsProfile)
9613             symbolTable.relateToOperator("interpolateAtVertexAMD", EOpInterpolateAtVertex);
9614 
9615         symbolTable.relateToOperator("beginInvocationInterlockARB", EOpBeginInvocationInterlock);
9616         symbolTable.relateToOperator("endInvocationInterlockARB",   EOpEndInvocationInterlock);
9617 
9618         break;
9619 
9620     case EShLangCompute:
9621         symbolTable.relateToOperator("subgroupMemoryBarrierShared", EOpSubgroupMemoryBarrierShared);
9622         if ((profile != EEsProfile && version >= 450) ||
9623             (profile == EEsProfile && version >= 320)) {
9624             symbolTable.relateToOperator("dFdx",        EOpDPdx);
9625             symbolTable.relateToOperator("dFdy",        EOpDPdy);
9626             symbolTable.relateToOperator("fwidth",      EOpFwidth);
9627             symbolTable.relateToOperator("dFdxFine",    EOpDPdxFine);
9628             symbolTable.relateToOperator("dFdyFine",    EOpDPdyFine);
9629             symbolTable.relateToOperator("fwidthFine",  EOpFwidthFine);
9630             symbolTable.relateToOperator("dFdxCoarse",  EOpDPdxCoarse);
9631             symbolTable.relateToOperator("dFdyCoarse",  EOpDPdyCoarse);
9632             symbolTable.relateToOperator("fwidthCoarse",EOpFwidthCoarse);
9633         }
9634         symbolTable.relateToOperator("coopMatLoadNV",              EOpCooperativeMatrixLoad);
9635         symbolTable.relateToOperator("coopMatStoreNV",             EOpCooperativeMatrixStore);
9636         symbolTable.relateToOperator("coopMatMulAddNV",            EOpCooperativeMatrixMulAdd);
9637         break;
9638 
9639     case EShLangRayGen:
9640     case EShLangClosestHit:
9641     case EShLangMiss:
9642         if (profile != EEsProfile && version >= 460) {
9643             symbolTable.relateToOperator("traceNV", EOpTraceNV);
9644             symbolTable.relateToOperator("traceRayMotionNV", EOpTraceRayMotionNV);
9645             symbolTable.relateToOperator("traceRayEXT", EOpTraceKHR);
9646             symbolTable.relateToOperator("executeCallableNV", EOpExecuteCallableNV);
9647             symbolTable.relateToOperator("executeCallableEXT", EOpExecuteCallableKHR);
9648         }
9649         break;
9650     case EShLangIntersect:
9651         if (profile != EEsProfile && version >= 460) {
9652             symbolTable.relateToOperator("reportIntersectionNV", EOpReportIntersection);
9653             symbolTable.relateToOperator("reportIntersectionEXT", EOpReportIntersection);
9654 	}
9655         break;
9656     case EShLangAnyHit:
9657         if (profile != EEsProfile && version >= 460) {
9658             symbolTable.relateToOperator("ignoreIntersectionNV", EOpIgnoreIntersectionNV);
9659             symbolTable.relateToOperator("terminateRayNV", EOpTerminateRayNV);
9660         }
9661         break;
9662     case EShLangCallable:
9663         if (profile != EEsProfile && version >= 460) {
9664             symbolTable.relateToOperator("executeCallableNV", EOpExecuteCallableNV);
9665             symbolTable.relateToOperator("executeCallableEXT", EOpExecuteCallableKHR);
9666         }
9667         break;
9668     case EShLangMeshNV:
9669         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
9670             symbolTable.relateToOperator("writePackedPrimitiveIndices4x8NV", EOpWritePackedPrimitiveIndices4x8NV);
9671         }
9672         // fall through
9673     case EShLangTaskNV:
9674         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
9675             symbolTable.relateToOperator("memoryBarrierShared", EOpMemoryBarrierShared);
9676             symbolTable.relateToOperator("groupMemoryBarrier", EOpGroupMemoryBarrier);
9677             symbolTable.relateToOperator("subgroupMemoryBarrierShared", EOpSubgroupMemoryBarrierShared);
9678         }
9679         break;
9680 
9681     default:
9682         assert(false && "Language not supported");
9683     }
9684 #endif // !GLSLANG_WEB
9685 }
9686 
9687 //
9688 // Add context-dependent (resource-specific) built-ins not handled by the above.  These
9689 // would be ones that need to be programmatically added because they cannot
9690 // be added by simple text strings.  For these, also
9691 // 1) Map built-in functions to operators, for those that will turn into an operation node
9692 //    instead of remaining a function call.
9693 // 2) Tag extension-related symbols added to their base version with their extensions, so
9694 //    that if an early version has the extension turned off, there is an error reported on use.
9695 //
9696 void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable, const TBuiltInResource &resources)
9697 {
9698 #ifndef GLSLANG_WEB
9699 #if defined(GLSLANG_ANGLE)
9700     profile = ECoreProfile;
9701     version = 450;
9702 #endif
9703     if (profile != EEsProfile && version >= 430 && version < 440) {
9704         symbolTable.setVariableExtensions("gl_MaxTransformFeedbackBuffers", 1, &E_GL_ARB_enhanced_layouts);
9705         symbolTable.setVariableExtensions("gl_MaxTransformFeedbackInterleavedComponents", 1, &E_GL_ARB_enhanced_layouts);
9706     }
9707     if (profile != EEsProfile && version >= 130 && version < 420) {
9708         symbolTable.setVariableExtensions("gl_MinProgramTexelOffset", 1, &E_GL_ARB_shading_language_420pack);
9709         symbolTable.setVariableExtensions("gl_MaxProgramTexelOffset", 1, &E_GL_ARB_shading_language_420pack);
9710     }
9711     if (profile != EEsProfile && version >= 150 && version < 410)
9712         symbolTable.setVariableExtensions("gl_MaxViewports", 1, &E_GL_ARB_viewport_array);
9713 
9714     switch(language) {
9715     case EShLangFragment:
9716         // Set up gl_FragData based on current array size.
9717         if (version == 100 || IncludeLegacy(version, profile, spvVersion) || (! ForwardCompatibility && profile != EEsProfile && version < 420)) {
9718             TPrecisionQualifier pq = profile == EEsProfile ? EpqMedium : EpqNone;
9719             TType fragData(EbtFloat, EvqFragColor, pq, 4);
9720             TArraySizes* arraySizes = new TArraySizes;
9721             arraySizes->addInnerSize(resources.maxDrawBuffers);
9722             fragData.transferArraySizes(arraySizes);
9723             symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData"), fragData));
9724             SpecialQualifier("gl_FragData", EvqFragColor, EbvFragData, symbolTable);
9725         }
9726 
9727         // GL_EXT_blend_func_extended
9728         if (profile == EEsProfile && version >= 100) {
9729            symbolTable.setVariableExtensions("gl_MaxDualSourceDrawBuffersEXT",    1, &E_GL_EXT_blend_func_extended);
9730            symbolTable.setVariableExtensions("gl_SecondaryFragColorEXT",    1, &E_GL_EXT_blend_func_extended);
9731            symbolTable.setVariableExtensions("gl_SecondaryFragDataEXT",    1, &E_GL_EXT_blend_func_extended);
9732            SpecialQualifier("gl_SecondaryFragColorEXT", EvqVaryingOut, EbvSecondaryFragColorEXT, symbolTable);
9733            SpecialQualifier("gl_SecondaryFragDataEXT", EvqVaryingOut, EbvSecondaryFragDataEXT, symbolTable);
9734         }
9735 
9736         break;
9737 
9738     case EShLangTessControl:
9739     case EShLangTessEvaluation:
9740         // Because of the context-dependent array size (gl_MaxPatchVertices),
9741         // these variables were added later than the others and need to be mapped now.
9742 
9743         // standard members
9744         BuiltInVariable("gl_in", "gl_Position",     EbvPosition,     symbolTable);
9745         BuiltInVariable("gl_in", "gl_PointSize",    EbvPointSize,    symbolTable);
9746         BuiltInVariable("gl_in", "gl_ClipDistance", EbvClipDistance, symbolTable);
9747         BuiltInVariable("gl_in", "gl_CullDistance", EbvCullDistance, symbolTable);
9748 
9749         // compatibility members
9750         BuiltInVariable("gl_in", "gl_ClipVertex",          EbvClipVertex,          symbolTable);
9751         BuiltInVariable("gl_in", "gl_FrontColor",          EbvFrontColor,          symbolTable);
9752         BuiltInVariable("gl_in", "gl_BackColor",           EbvBackColor,           symbolTable);
9753         BuiltInVariable("gl_in", "gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
9754         BuiltInVariable("gl_in", "gl_BackSecondaryColor",  EbvBackSecondaryColor,  symbolTable);
9755         BuiltInVariable("gl_in", "gl_TexCoord",            EbvTexCoord,            symbolTable);
9756         BuiltInVariable("gl_in", "gl_FogFragCoord",        EbvFogFragCoord,        symbolTable);
9757 
9758         symbolTable.setVariableExtensions("gl_in", "gl_SecondaryPositionNV", 1, &E_GL_NV_stereo_view_rendering);
9759         symbolTable.setVariableExtensions("gl_in", "gl_PositionPerViewNV",   1, &E_GL_NVX_multiview_per_view_attributes);
9760 
9761         BuiltInVariable("gl_in", "gl_SecondaryPositionNV", EbvSecondaryPositionNV, symbolTable);
9762         BuiltInVariable("gl_in", "gl_PositionPerViewNV",   EbvPositionPerViewNV,   symbolTable);
9763 
9764         // extension requirements
9765         if (profile == EEsProfile) {
9766             symbolTable.setVariableExtensions("gl_in", "gl_PointSize", Num_AEP_tessellation_point_size, AEP_tessellation_point_size);
9767         }
9768 
9769         break;
9770 
9771     default:
9772         break;
9773     }
9774 #endif
9775 }
9776 
9777 } // end namespace glslang
9778