Fix variable scoping of do-while
[platform/upstream/glslang.git] / glslang / MachineIndependent / Initialize.cpp
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 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.
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.
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>
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.
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.
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
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.
491 TBuiltInParseables::TBuiltInParseables()
492 {
493 }
494
495 // Destroy TBuiltInParseables.
496 TBuiltInParseables::~TBuiltInParseables()
497 {
498 }
499
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
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 //
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
4163             "float64_t radians(float64_t);"
4164             "f64vec2   radians(f64vec2);"
4165             "f64vec3   radians(f64vec3);"
4166             "f64vec4   radians(f64vec4);"
4167
4168             "float64_t degrees(float64_t);"
4169             "f64vec2   degrees(f64vec2);"
4170             "f64vec3   degrees(f64vec3);"
4171             "f64vec4   degrees(f64vec4);"
4172
4173             "float64_t sin(float64_t);"
4174             "f64vec2   sin(f64vec2);"
4175             "f64vec3   sin(f64vec3);"
4176             "f64vec4   sin(f64vec4);"
4177
4178             "float64_t cos(float64_t);"
4179             "f64vec2   cos(f64vec2);"
4180             "f64vec3   cos(f64vec3);"
4181             "f64vec4   cos(f64vec4);"
4182
4183             "float64_t tan(float64_t);"
4184             "f64vec2   tan(f64vec2);"
4185             "f64vec3   tan(f64vec3);"
4186             "f64vec4   tan(f64vec4);"
4187
4188             "float64_t asin(float64_t);"
4189             "f64vec2   asin(f64vec2);"
4190             "f64vec3   asin(f64vec3);"
4191             "f64vec4   asin(f64vec4);"
4192
4193             "float64_t acos(float64_t);"
4194             "f64vec2   acos(f64vec2);"
4195             "f64vec3   acos(f64vec3);"
4196             "f64vec4   acos(f64vec4);"
4197
4198             "float64_t atan(float64_t, float64_t);"
4199             "f64vec2   atan(f64vec2,   f64vec2);"
4200             "f64vec3   atan(f64vec3,   f64vec3);"
4201             "f64vec4   atan(f64vec4,   f64vec4);"
4202
4203             "float64_t atan(float64_t);"
4204             "f64vec2   atan(f64vec2);"
4205             "f64vec3   atan(f64vec3);"
4206             "f64vec4   atan(f64vec4);"
4207
4208             "float64_t sinh(float64_t);"
4209             "f64vec2   sinh(f64vec2);"
4210             "f64vec3   sinh(f64vec3);"
4211             "f64vec4   sinh(f64vec4);"
4212
4213             "float64_t cosh(float64_t);"
4214             "f64vec2   cosh(f64vec2);"
4215             "f64vec3   cosh(f64vec3);"
4216             "f64vec4   cosh(f64vec4);"
4217
4218             "float64_t tanh(float64_t);"
4219             "f64vec2   tanh(f64vec2);"
4220             "f64vec3   tanh(f64vec3);"
4221             "f64vec4   tanh(f64vec4);"
4222
4223             "float64_t asinh(float64_t);"
4224             "f64vec2   asinh(f64vec2);"
4225             "f64vec3   asinh(f64vec3);"
4226             "f64vec4   asinh(f64vec4);"
4227
4228             "float64_t acosh(float64_t);"
4229             "f64vec2   acosh(f64vec2);"
4230             "f64vec3   acosh(f64vec3);"
4231             "f64vec4   acosh(f64vec4);"
4232
4233             "float64_t atanh(float64_t);"
4234             "f64vec2   atanh(f64vec2);"
4235             "f64vec3   atanh(f64vec3);"
4236             "f64vec4   atanh(f64vec4);"
4237
4238             "float64_t pow(float64_t, float64_t);"
4239             "f64vec2   pow(f64vec2,   f64vec2);"
4240             "f64vec3   pow(f64vec3,   f64vec3);"
4241             "f64vec4   pow(f64vec4,   f64vec4);"
4242
4243             "float64_t exp(float64_t);"
4244             "f64vec2   exp(f64vec2);"
4245             "f64vec3   exp(f64vec3);"
4246             "f64vec4   exp(f64vec4);"
4247
4248             "float64_t log(float64_t);"
4249             "f64vec2   log(f64vec2);"
4250             "f64vec3   log(f64vec3);"
4251             "f64vec4   log(f64vec4);"
4252
4253             "float64_t exp2(float64_t);"
4254             "f64vec2   exp2(f64vec2);"
4255             "f64vec3   exp2(f64vec3);"
4256             "f64vec4   exp2(f64vec4);"
4257
4258             "float64_t log2(float64_t);"
4259             "f64vec2   log2(f64vec2);"
4260             "f64vec3   log2(f64vec3);"
4261             "f64vec4   log2(f64vec4);"
4262             "\n");
4263     }
4264
4265     if (profile != EEsProfile && version >= 450) {
4266         stageBuiltins[EShLangFragment].append(derivativesAndControl64bits);
4267         stageBuiltins[EShLangFragment].append(
4268             "float64_t interpolateAtCentroid(float64_t);"
4269             "f64vec2   interpolateAtCentroid(f64vec2);"
4270             "f64vec3   interpolateAtCentroid(f64vec3);"
4271             "f64vec4   interpolateAtCentroid(f64vec4);"
4272
4273             "float64_t interpolateAtSample(float64_t, int);"
4274             "f64vec2   interpolateAtSample(f64vec2,   int);"
4275             "f64vec3   interpolateAtSample(f64vec3,   int);"
4276             "f64vec4   interpolateAtSample(f64vec4,   int);"
4277
4278             "float64_t interpolateAtOffset(float64_t, f64vec2);"
4279             "f64vec2   interpolateAtOffset(f64vec2,   f64vec2);"
4280             "f64vec3   interpolateAtOffset(f64vec3,   f64vec2);"
4281             "f64vec4   interpolateAtOffset(f64vec4,   f64vec2);"
4282
4283             "\n");
4284
4285     }
4286 #endif // !GLSLANG_ANGLE
4287
4288     //============================================================================
4289     //
4290     // Prototypes for built-in functions seen by vertex shaders only.
4291     // (Except legacy lod functions, where it depends which release they are
4292     // vertex only.)
4293     //
4294     //============================================================================
4295
4296     //
4297     // Geometric Functions.
4298     //
4299     if (spvVersion.vulkan == 0 && IncludeLegacy(version, profile, spvVersion))
4300         stageBuiltins[EShLangVertex].append("vec4 ftransform();");
4301
4302 #ifndef GLSLANG_ANGLE
4303     //
4304     // Original-style texture Functions with lod.
4305     //
4306     TString* s;
4307     if (version == 100)
4308         s = &stageBuiltins[EShLangVertex];
4309     else
4310         s = &commonBuiltins;
4311     if ((profile == EEsProfile && version == 100) ||
4312          profile == ECompatibilityProfile ||
4313         (profile == ECoreProfile && version < 420) ||
4314          profile == ENoProfile) {
4315         if (spvVersion.spv == 0) {
4316             s->append(
4317                 "vec4 texture2DLod(sampler2D, vec2, float);"         // GL_ARB_shader_texture_lod
4318                 "vec4 texture2DProjLod(sampler2D, vec3, float);"     // GL_ARB_shader_texture_lod
4319                 "vec4 texture2DProjLod(sampler2D, vec4, float);"     // GL_ARB_shader_texture_lod
4320                 "vec4 texture3DLod(sampler3D, vec3, float);"         // GL_ARB_shader_texture_lod  // OES_texture_3D, but caught by keyword check
4321                 "vec4 texture3DProjLod(sampler3D, vec4, float);"     // GL_ARB_shader_texture_lod  // OES_texture_3D, but caught by keyword check
4322                 "vec4 textureCubeLod(samplerCube, vec3, float);"     // GL_ARB_shader_texture_lod
4323
4324                 "\n");
4325         }
4326     }
4327     if ( profile == ECompatibilityProfile ||
4328         (profile == ECoreProfile && version < 420) ||
4329          profile == ENoProfile) {
4330         if (spvVersion.spv == 0) {
4331             s->append(
4332                 "vec4 texture1DLod(sampler1D, float, float);"                          // GL_ARB_shader_texture_lod
4333                 "vec4 texture1DProjLod(sampler1D, vec2, float);"                       // GL_ARB_shader_texture_lod
4334                 "vec4 texture1DProjLod(sampler1D, vec4, float);"                       // GL_ARB_shader_texture_lod
4335                 "vec4 shadow1DLod(sampler1DShadow, vec3, float);"                      // GL_ARB_shader_texture_lod
4336                 "vec4 shadow2DLod(sampler2DShadow, vec3, float);"                      // GL_ARB_shader_texture_lod
4337                 "vec4 shadow1DProjLod(sampler1DShadow, vec4, float);"                  // GL_ARB_shader_texture_lod
4338                 "vec4 shadow2DProjLod(sampler2DShadow, vec4, float);"                  // GL_ARB_shader_texture_lod
4339
4340                 "vec4 texture1DGradARB(sampler1D, float, float, float);"               // GL_ARB_shader_texture_lod
4341                 "vec4 texture1DProjGradARB(sampler1D, vec2, float, float);"            // GL_ARB_shader_texture_lod
4342                 "vec4 texture1DProjGradARB(sampler1D, vec4, float, float);"            // GL_ARB_shader_texture_lod
4343                 "vec4 texture2DGradARB(sampler2D, vec2, vec2, vec2);"                  // GL_ARB_shader_texture_lod
4344                 "vec4 texture2DProjGradARB(sampler2D, vec3, vec2, vec2);"              // GL_ARB_shader_texture_lod
4345                 "vec4 texture2DProjGradARB(sampler2D, vec4, vec2, vec2);"              // GL_ARB_shader_texture_lod
4346                 "vec4 texture3DGradARB(sampler3D, vec3, vec3, vec3);"                  // GL_ARB_shader_texture_lod
4347                 "vec4 texture3DProjGradARB(sampler3D, vec4, vec3, vec3);"              // GL_ARB_shader_texture_lod
4348                 "vec4 textureCubeGradARB(samplerCube, vec3, vec3, vec3);"              // GL_ARB_shader_texture_lod
4349                 "vec4 shadow1DGradARB(sampler1DShadow, vec3, float, float);"           // GL_ARB_shader_texture_lod
4350                 "vec4 shadow1DProjGradARB( sampler1DShadow, vec4, float, float);"      // GL_ARB_shader_texture_lod
4351                 "vec4 shadow2DGradARB(sampler2DShadow, vec3, vec2, vec2);"             // GL_ARB_shader_texture_lod
4352                 "vec4 shadow2DProjGradARB( sampler2DShadow, vec4, vec2, vec2);"        // GL_ARB_shader_texture_lod
4353                 "vec4 texture2DRectGradARB(sampler2DRect, vec2, vec2, vec2);"          // GL_ARB_shader_texture_lod
4354                 "vec4 texture2DRectProjGradARB( sampler2DRect, vec3, vec2, vec2);"     // GL_ARB_shader_texture_lod
4355                 "vec4 texture2DRectProjGradARB( sampler2DRect, vec4, vec2, vec2);"     // GL_ARB_shader_texture_lod
4356                 "vec4 shadow2DRectGradARB( sampler2DRectShadow, vec3, vec2, vec2);"    // GL_ARB_shader_texture_lod
4357                 "vec4 shadow2DRectProjGradARB(sampler2DRectShadow, vec4, vec2, vec2);" // GL_ARB_shader_texture_lod
4358
4359                 "\n");
4360         }
4361     }
4362 #endif // !GLSLANG_ANGLE
4363
4364     if ((profile != EEsProfile && version >= 150) ||
4365         (profile == EEsProfile && version >= 310)) {
4366         //============================================================================
4367         //
4368         // Prototypes for built-in functions seen by geometry shaders only.
4369         //
4370         //============================================================================
4371
4372         if (profile != EEsProfile && version >= 400) {
4373             stageBuiltins[EShLangGeometry].append(
4374                 "void EmitStreamVertex(int);"
4375                 "void EndStreamPrimitive(int);"
4376                 );
4377         }
4378         stageBuiltins[EShLangGeometry].append(
4379             "void EmitVertex();"
4380             "void EndPrimitive();"
4381             "\n");
4382     }
4383 #endif // !GLSLANG_WEB
4384
4385     //============================================================================
4386     //
4387     // Prototypes for all control functions.
4388     //
4389     //============================================================================
4390     bool esBarrier = (profile == EEsProfile && version >= 310);
4391     if ((profile != EEsProfile && version >= 150) || esBarrier)
4392         stageBuiltins[EShLangTessControl].append(
4393             "void barrier();"
4394             );
4395     if ((profile != EEsProfile && version >= 420) || esBarrier)
4396         stageBuiltins[EShLangCompute].append(
4397             "void barrier();"
4398             );
4399     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
4400         stageBuiltins[EShLangMeshNV].append(
4401             "void barrier();"
4402             );
4403         stageBuiltins[EShLangTaskNV].append(
4404             "void barrier();"
4405             );
4406     }
4407     if ((profile != EEsProfile && version >= 130) || esBarrier)
4408         commonBuiltins.append(
4409             "void memoryBarrier();"
4410             );
4411     if ((profile != EEsProfile && version >= 420) || esBarrier) {
4412         commonBuiltins.append(
4413             "void memoryBarrierBuffer();"
4414             );
4415         stageBuiltins[EShLangCompute].append(
4416             "void memoryBarrierShared();"
4417             "void groupMemoryBarrier();"
4418             );
4419     }
4420 #ifndef GLSLANG_WEB
4421     if ((profile != EEsProfile && version >= 420) || esBarrier) {
4422         if (spvVersion.vulkan == 0 || spvVersion.vulkanRelaxed) {
4423             commonBuiltins.append("void memoryBarrierAtomicCounter();");
4424         }
4425         commonBuiltins.append("void memoryBarrierImage();");
4426     }
4427     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
4428         stageBuiltins[EShLangMeshNV].append(
4429             "void memoryBarrierShared();"
4430             "void groupMemoryBarrier();"
4431         );
4432         stageBuiltins[EShLangTaskNV].append(
4433             "void memoryBarrierShared();"
4434             "void groupMemoryBarrier();"
4435         );
4436     }
4437
4438     commonBuiltins.append("void controlBarrier(int, int, int, int);\n"
4439                           "void memoryBarrier(int, int, int);\n");
4440
4441     commonBuiltins.append("void debugPrintfEXT();\n");
4442
4443 #ifndef GLSLANG_ANGLE
4444     if (profile != EEsProfile && version >= 450) {
4445         // coopMatStoreNV perhaps ought to have "out" on the buf parameter, but
4446         // adding it introduces undesirable tempArgs on the stack. What we want
4447         // is more like "buf" thought of as a pointer value being an in parameter.
4448         stageBuiltins[EShLangCompute].append(
4449             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent float16_t[] buf, uint element, uint stride, bool colMajor);\n"
4450             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent float[] buf, uint element, uint stride, bool colMajor);\n"
4451             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
4452             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
4453             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
4454             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
4455             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
4456             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
4457
4458             "void coopMatStoreNV(fcoopmatNV m, volatile coherent float16_t[] buf, uint element, uint stride, bool colMajor);\n"
4459             "void coopMatStoreNV(fcoopmatNV m, volatile coherent float[] buf, uint element, uint stride, bool colMajor);\n"
4460             "void coopMatStoreNV(fcoopmatNV m, volatile coherent float64_t[] buf, uint element, uint stride, bool colMajor);\n"
4461             "void coopMatStoreNV(fcoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
4462             "void coopMatStoreNV(fcoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
4463             "void coopMatStoreNV(fcoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
4464             "void coopMatStoreNV(fcoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
4465             "void coopMatStoreNV(fcoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
4466             "void coopMatStoreNV(fcoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
4467
4468             "fcoopmatNV coopMatMulAddNV(fcoopmatNV A, fcoopmatNV B, fcoopmatNV C);\n"
4469             "void coopMatLoadNV(out icoopmatNV m, volatile coherent int8_t[] buf, uint element, uint stride, bool colMajor);\n"
4470             "void coopMatLoadNV(out icoopmatNV m, volatile coherent int16_t[] buf, uint element, uint stride, bool colMajor);\n"
4471             "void coopMatLoadNV(out icoopmatNV m, volatile coherent int[] buf, uint element, uint stride, bool colMajor);\n"
4472             "void coopMatLoadNV(out icoopmatNV m, volatile coherent int64_t[] buf, uint element, uint stride, bool colMajor);\n"
4473             "void coopMatLoadNV(out icoopmatNV m, volatile coherent ivec2[] buf, uint element, uint stride, bool colMajor);\n"
4474             "void coopMatLoadNV(out icoopmatNV m, volatile coherent ivec4[] buf, uint element, uint stride, bool colMajor);\n"
4475             "void coopMatLoadNV(out icoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
4476             "void coopMatLoadNV(out icoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
4477             "void coopMatLoadNV(out icoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
4478             "void coopMatLoadNV(out icoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
4479             "void coopMatLoadNV(out icoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
4480             "void coopMatLoadNV(out icoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
4481
4482             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent int8_t[] buf, uint element, uint stride, bool colMajor);\n"
4483             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent int16_t[] buf, uint element, uint stride, bool colMajor);\n"
4484             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent int[] buf, uint element, uint stride, bool colMajor);\n"
4485             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent int64_t[] buf, uint element, uint stride, bool colMajor);\n"
4486             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent ivec2[] buf, uint element, uint stride, bool colMajor);\n"
4487             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent ivec4[] buf, uint element, uint stride, bool colMajor);\n"
4488             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
4489             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
4490             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
4491             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
4492             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
4493             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
4494
4495             "void coopMatStoreNV(icoopmatNV m, volatile coherent int8_t[] buf, uint element, uint stride, bool colMajor);\n"
4496             "void coopMatStoreNV(icoopmatNV m, volatile coherent int16_t[] buf, uint element, uint stride, bool colMajor);\n"
4497             "void coopMatStoreNV(icoopmatNV m, volatile coherent int[] buf, uint element, uint stride, bool colMajor);\n"
4498             "void coopMatStoreNV(icoopmatNV m, volatile coherent int64_t[] buf, uint element, uint stride, bool colMajor);\n"
4499             "void coopMatStoreNV(icoopmatNV m, volatile coherent ivec2[] buf, uint element, uint stride, bool colMajor);\n"
4500             "void coopMatStoreNV(icoopmatNV m, volatile coherent ivec4[] buf, uint element, uint stride, bool colMajor);\n"
4501             "void coopMatStoreNV(icoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
4502             "void coopMatStoreNV(icoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
4503             "void coopMatStoreNV(icoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
4504             "void coopMatStoreNV(icoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
4505             "void coopMatStoreNV(icoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
4506             "void coopMatStoreNV(icoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
4507
4508             "void coopMatStoreNV(ucoopmatNV m, volatile coherent int8_t[] buf, uint element, uint stride, bool colMajor);\n"
4509             "void coopMatStoreNV(ucoopmatNV m, volatile coherent int16_t[] buf, uint element, uint stride, bool colMajor);\n"
4510             "void coopMatStoreNV(ucoopmatNV m, volatile coherent int[] buf, uint element, uint stride, bool colMajor);\n"
4511             "void coopMatStoreNV(ucoopmatNV m, volatile coherent int64_t[] buf, uint element, uint stride, bool colMajor);\n"
4512             "void coopMatStoreNV(ucoopmatNV m, volatile coherent ivec2[] buf, uint element, uint stride, bool colMajor);\n"
4513             "void coopMatStoreNV(ucoopmatNV m, volatile coherent ivec4[] buf, uint element, uint stride, bool colMajor);\n"
4514             "void coopMatStoreNV(ucoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
4515             "void coopMatStoreNV(ucoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
4516             "void coopMatStoreNV(ucoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
4517             "void coopMatStoreNV(ucoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
4518             "void coopMatStoreNV(ucoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
4519             "void coopMatStoreNV(ucoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
4520
4521             "icoopmatNV coopMatMulAddNV(icoopmatNV A, icoopmatNV B, icoopmatNV C);\n"
4522             "ucoopmatNV coopMatMulAddNV(ucoopmatNV A, ucoopmatNV B, ucoopmatNV C);\n"
4523             );
4524     }
4525
4526     //============================================================================
4527     //
4528     // Prototypes for built-in functions seen by fragment shaders only.
4529     //
4530     //============================================================================
4531
4532     //
4533     // Original-style texture Functions with bias.
4534     //
4535     if (spvVersion.spv == 0 && (profile != EEsProfile || version == 100)) {
4536         stageBuiltins[EShLangFragment].append(
4537             "vec4 texture2D(sampler2D, vec2, float);"
4538             "vec4 texture2DProj(sampler2D, vec3, float);"
4539             "vec4 texture2DProj(sampler2D, vec4, float);"
4540             "vec4 texture3D(sampler3D, vec3, float);"        // OES_texture_3D
4541             "vec4 texture3DProj(sampler3D, vec4, float);"    // OES_texture_3D
4542             "vec4 textureCube(samplerCube, vec3, float);"
4543
4544             "\n");
4545     }
4546     if (spvVersion.spv == 0 && (profile != EEsProfile && version > 100)) {
4547         stageBuiltins[EShLangFragment].append(
4548             "vec4 texture1D(sampler1D, float, float);"
4549             "vec4 texture1DProj(sampler1D, vec2, float);"
4550             "vec4 texture1DProj(sampler1D, vec4, float);"
4551             "vec4 shadow1D(sampler1DShadow, vec3, float);"
4552             "vec4 shadow2D(sampler2DShadow, vec3, float);"
4553             "vec4 shadow1DProj(sampler1DShadow, vec4, float);"
4554             "vec4 shadow2DProj(sampler2DShadow, vec4, float);"
4555
4556             "\n");
4557     }
4558     if (spvVersion.spv == 0 && profile == EEsProfile) {
4559         stageBuiltins[EShLangFragment].append(
4560             "vec4 texture2DLodEXT(sampler2D, vec2, float);"      // GL_EXT_shader_texture_lod
4561             "vec4 texture2DProjLodEXT(sampler2D, vec3, float);"  // GL_EXT_shader_texture_lod
4562             "vec4 texture2DProjLodEXT(sampler2D, vec4, float);"  // GL_EXT_shader_texture_lod
4563             "vec4 textureCubeLodEXT(samplerCube, vec3, float);"  // GL_EXT_shader_texture_lod
4564
4565             "\n");
4566     }
4567 #endif // !GLSLANG_ANGLE
4568
4569     // GL_ARB_derivative_control
4570     if (profile != EEsProfile && version >= 400) {
4571         stageBuiltins[EShLangFragment].append(derivativeControls);
4572         stageBuiltins[EShLangFragment].append("\n");
4573     }
4574
4575     // GL_OES_shader_multisample_interpolation
4576     if ((profile == EEsProfile && version >= 310) ||
4577         (profile != EEsProfile && version >= 400)) {
4578         stageBuiltins[EShLangFragment].append(
4579             "float interpolateAtCentroid(float);"
4580             "vec2  interpolateAtCentroid(vec2);"
4581             "vec3  interpolateAtCentroid(vec3);"
4582             "vec4  interpolateAtCentroid(vec4);"
4583
4584             "float interpolateAtSample(float, int);"
4585             "vec2  interpolateAtSample(vec2,  int);"
4586             "vec3  interpolateAtSample(vec3,  int);"
4587             "vec4  interpolateAtSample(vec4,  int);"
4588
4589             "float interpolateAtOffset(float, vec2);"
4590             "vec2  interpolateAtOffset(vec2,  vec2);"
4591             "vec3  interpolateAtOffset(vec3,  vec2);"
4592             "vec4  interpolateAtOffset(vec4,  vec2);"
4593
4594             "\n");
4595     }
4596
4597     stageBuiltins[EShLangFragment].append(
4598         "void beginInvocationInterlockARB(void);"
4599         "void endInvocationInterlockARB(void);");
4600
4601     stageBuiltins[EShLangFragment].append(
4602         "bool helperInvocationEXT();"
4603         "\n");
4604
4605 #ifndef GLSLANG_ANGLE
4606     // GL_AMD_shader_explicit_vertex_parameter
4607     if (profile != EEsProfile && version >= 450) {
4608         stageBuiltins[EShLangFragment].append(
4609             "float interpolateAtVertexAMD(float, uint);"
4610             "vec2  interpolateAtVertexAMD(vec2,  uint);"
4611             "vec3  interpolateAtVertexAMD(vec3,  uint);"
4612             "vec4  interpolateAtVertexAMD(vec4,  uint);"
4613
4614             "int   interpolateAtVertexAMD(int,   uint);"
4615             "ivec2 interpolateAtVertexAMD(ivec2, uint);"
4616             "ivec3 interpolateAtVertexAMD(ivec3, uint);"
4617             "ivec4 interpolateAtVertexAMD(ivec4, uint);"
4618
4619             "uint  interpolateAtVertexAMD(uint,  uint);"
4620             "uvec2 interpolateAtVertexAMD(uvec2, uint);"
4621             "uvec3 interpolateAtVertexAMD(uvec3, uint);"
4622             "uvec4 interpolateAtVertexAMD(uvec4, uint);"
4623
4624             "float16_t interpolateAtVertexAMD(float16_t, uint);"
4625             "f16vec2   interpolateAtVertexAMD(f16vec2,   uint);"
4626             "f16vec3   interpolateAtVertexAMD(f16vec3,   uint);"
4627             "f16vec4   interpolateAtVertexAMD(f16vec4,   uint);"
4628
4629             "\n");
4630     }
4631
4632     // GL_AMD_gpu_shader_half_float
4633     if (profile != EEsProfile && version >= 450) {
4634         stageBuiltins[EShLangFragment].append(derivativesAndControl16bits);
4635         stageBuiltins[EShLangFragment].append("\n");
4636
4637         stageBuiltins[EShLangFragment].append(
4638             "float16_t interpolateAtCentroid(float16_t);"
4639             "f16vec2   interpolateAtCentroid(f16vec2);"
4640             "f16vec3   interpolateAtCentroid(f16vec3);"
4641             "f16vec4   interpolateAtCentroid(f16vec4);"
4642
4643             "float16_t interpolateAtSample(float16_t, int);"
4644             "f16vec2   interpolateAtSample(f16vec2,   int);"
4645             "f16vec3   interpolateAtSample(f16vec3,   int);"
4646             "f16vec4   interpolateAtSample(f16vec4,   int);"
4647
4648             "float16_t interpolateAtOffset(float16_t, f16vec2);"
4649             "f16vec2   interpolateAtOffset(f16vec2,   f16vec2);"
4650             "f16vec3   interpolateAtOffset(f16vec3,   f16vec2);"
4651             "f16vec4   interpolateAtOffset(f16vec4,   f16vec2);"
4652
4653             "\n");
4654     }
4655
4656     // GL_ARB_shader_clock & GL_EXT_shader_realtime_clock
4657     if (profile != EEsProfile && version >= 450) {
4658         commonBuiltins.append(
4659             "uvec2 clock2x32ARB();"
4660             "uint64_t clockARB();"
4661             "uvec2 clockRealtime2x32EXT();"
4662             "uint64_t clockRealtimeEXT();"
4663             "\n");
4664     }
4665
4666     // GL_AMD_shader_fragment_mask
4667     if (profile != EEsProfile && version >= 450 && spvVersion.vulkan > 0) {
4668         stageBuiltins[EShLangFragment].append(
4669             "uint fragmentMaskFetchAMD(subpassInputMS);"
4670             "uint fragmentMaskFetchAMD(isubpassInputMS);"
4671             "uint fragmentMaskFetchAMD(usubpassInputMS);"
4672
4673             "vec4  fragmentFetchAMD(subpassInputMS,  uint);"
4674             "ivec4 fragmentFetchAMD(isubpassInputMS, uint);"
4675             "uvec4 fragmentFetchAMD(usubpassInputMS, uint);"
4676
4677             "\n");
4678         }
4679
4680     // Builtins for GL_NV_ray_tracing/GL_NV_ray_tracing_motion_blur/GL_EXT_ray_tracing/GL_EXT_ray_query
4681     if (profile != EEsProfile && version >= 460) {
4682          commonBuiltins.append("void rayQueryInitializeEXT(rayQueryEXT, accelerationStructureEXT, uint, uint, vec3, float, vec3, float);"
4683             "void rayQueryTerminateEXT(rayQueryEXT);"
4684             "void rayQueryGenerateIntersectionEXT(rayQueryEXT, float);"
4685             "void rayQueryConfirmIntersectionEXT(rayQueryEXT);"
4686             "bool rayQueryProceedEXT(rayQueryEXT);"
4687             "uint rayQueryGetIntersectionTypeEXT(rayQueryEXT, bool);"
4688             "float rayQueryGetRayTMinEXT(rayQueryEXT);"
4689             "uint rayQueryGetRayFlagsEXT(rayQueryEXT);"
4690             "vec3 rayQueryGetWorldRayOriginEXT(rayQueryEXT);"
4691             "vec3 rayQueryGetWorldRayDirectionEXT(rayQueryEXT);"
4692             "float rayQueryGetIntersectionTEXT(rayQueryEXT, bool);"
4693             "int rayQueryGetIntersectionInstanceCustomIndexEXT(rayQueryEXT, bool);"
4694             "int rayQueryGetIntersectionInstanceIdEXT(rayQueryEXT, bool);"
4695             "uint rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT(rayQueryEXT, bool);"
4696             "int rayQueryGetIntersectionGeometryIndexEXT(rayQueryEXT, bool);"
4697             "int rayQueryGetIntersectionPrimitiveIndexEXT(rayQueryEXT, bool);"
4698             "vec2 rayQueryGetIntersectionBarycentricsEXT(rayQueryEXT, bool);"
4699             "bool rayQueryGetIntersectionFrontFaceEXT(rayQueryEXT, bool);"
4700             "bool rayQueryGetIntersectionCandidateAABBOpaqueEXT(rayQueryEXT);"
4701             "vec3 rayQueryGetIntersectionObjectRayDirectionEXT(rayQueryEXT, bool);"
4702             "vec3 rayQueryGetIntersectionObjectRayOriginEXT(rayQueryEXT, bool);"
4703             "mat4x3 rayQueryGetIntersectionObjectToWorldEXT(rayQueryEXT, bool);"
4704             "mat4x3 rayQueryGetIntersectionWorldToObjectEXT(rayQueryEXT, bool);"
4705             "\n");
4706
4707         stageBuiltins[EShLangRayGen].append(
4708             "void traceNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4709             "void traceRayMotionNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,float,int);"
4710             "void traceRayEXT(accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4711             "void executeCallableNV(uint, int);"
4712             "void executeCallableEXT(uint, int);"
4713             "\n");
4714         stageBuiltins[EShLangIntersect].append(
4715             "bool reportIntersectionNV(float, uint);"
4716             "bool reportIntersectionEXT(float, uint);"
4717             "\n");
4718         stageBuiltins[EShLangAnyHit].append(
4719             "void ignoreIntersectionNV();"
4720             "void terminateRayNV();"
4721             "\n");
4722         stageBuiltins[EShLangClosestHit].append(
4723             "void traceNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4724             "void traceRayMotionNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,float,int);"
4725             "void traceRayEXT(accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4726             "void executeCallableNV(uint, int);"
4727             "void executeCallableEXT(uint, int);"
4728             "\n");
4729         stageBuiltins[EShLangMiss].append(
4730             "void traceNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4731             "void traceRayMotionNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,float,int);"
4732             "void traceRayEXT(accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4733             "void executeCallableNV(uint, int);"
4734             "void executeCallableEXT(uint, int);"
4735             "\n");
4736         stageBuiltins[EShLangCallable].append(
4737             "void executeCallableNV(uint, int);"
4738             "void executeCallableEXT(uint, int);"
4739             "\n");
4740     }
4741 #endif // !GLSLANG_ANGLE
4742
4743     //E_SPV_NV_compute_shader_derivatives
4744     if ((profile == EEsProfile && version >= 320) || (profile != EEsProfile && version >= 450)) {
4745         stageBuiltins[EShLangCompute].append(derivativeControls);
4746         stageBuiltins[EShLangCompute].append("\n");
4747     }
4748 #ifndef GLSLANG_ANGLE
4749     if (profile != EEsProfile && version >= 450) {
4750         stageBuiltins[EShLangCompute].append(derivativesAndControl16bits);
4751         stageBuiltins[EShLangCompute].append(derivativesAndControl64bits);
4752         stageBuiltins[EShLangCompute].append("\n");
4753     }
4754
4755     // Builtins for GL_NV_mesh_shader
4756     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
4757         stageBuiltins[EShLangMeshNV].append(
4758             "void writePackedPrimitiveIndices4x8NV(uint, uint);"
4759             "\n");
4760     }
4761 #endif // !GLSLANG_ANGLE
4762 #endif // !GLSLANG_WEB
4763
4764     //============================================================================
4765     //
4766     // Standard Uniforms
4767     //
4768     //============================================================================
4769
4770     //
4771     // Depth range in window coordinates, p. 33
4772     //
4773     if (spvVersion.spv == 0) {
4774         commonBuiltins.append(
4775             "struct gl_DepthRangeParameters {"
4776             );
4777         if (profile == EEsProfile) {
4778             commonBuiltins.append(
4779                 "highp float near;"   // n
4780                 "highp float far;"    // f
4781                 "highp float diff;"   // f - n
4782                 );
4783         } else {
4784 #ifndef GLSLANG_WEB
4785             commonBuiltins.append(
4786                 "float near;"  // n
4787                 "float far;"   // f
4788                 "float diff;"  // f - n
4789                 );
4790 #endif
4791         }
4792
4793         commonBuiltins.append(
4794             "};"
4795             "uniform gl_DepthRangeParameters gl_DepthRange;"
4796             "\n");
4797     }
4798
4799 #if !defined(GLSLANG_WEB) && !defined(GLSLANG_ANGLE)
4800     if (spvVersion.spv == 0 && IncludeLegacy(version, profile, spvVersion)) {
4801         //
4802         // Matrix state. p. 31, 32, 37, 39, 40.
4803         //
4804         commonBuiltins.append(
4805             "uniform mat4  gl_ModelViewMatrix;"
4806             "uniform mat4  gl_ProjectionMatrix;"
4807             "uniform mat4  gl_ModelViewProjectionMatrix;"
4808
4809             //
4810             // Derived matrix state that provides inverse and transposed versions
4811             // of the matrices above.
4812             //
4813             "uniform mat3  gl_NormalMatrix;"
4814
4815             "uniform mat4  gl_ModelViewMatrixInverse;"
4816             "uniform mat4  gl_ProjectionMatrixInverse;"
4817             "uniform mat4  gl_ModelViewProjectionMatrixInverse;"
4818
4819             "uniform mat4  gl_ModelViewMatrixTranspose;"
4820             "uniform mat4  gl_ProjectionMatrixTranspose;"
4821             "uniform mat4  gl_ModelViewProjectionMatrixTranspose;"
4822
4823             "uniform mat4  gl_ModelViewMatrixInverseTranspose;"
4824             "uniform mat4  gl_ProjectionMatrixInverseTranspose;"
4825             "uniform mat4  gl_ModelViewProjectionMatrixInverseTranspose;"
4826
4827             //
4828             // Normal scaling p. 39.
4829             //
4830             "uniform float gl_NormalScale;"
4831
4832             //
4833             // Point Size, p. 66, 67.
4834             //
4835             "struct gl_PointParameters {"
4836                 "float size;"
4837                 "float sizeMin;"
4838                 "float sizeMax;"
4839                 "float fadeThresholdSize;"
4840                 "float distanceConstantAttenuation;"
4841                 "float distanceLinearAttenuation;"
4842                 "float distanceQuadraticAttenuation;"
4843             "};"
4844
4845             "uniform gl_PointParameters gl_Point;"
4846
4847             //
4848             // Material State p. 50, 55.
4849             //
4850             "struct gl_MaterialParameters {"
4851                 "vec4  emission;"    // Ecm
4852                 "vec4  ambient;"     // Acm
4853                 "vec4  diffuse;"     // Dcm
4854                 "vec4  specular;"    // Scm
4855                 "float shininess;"   // Srm
4856             "};"
4857             "uniform gl_MaterialParameters  gl_FrontMaterial;"
4858             "uniform gl_MaterialParameters  gl_BackMaterial;"
4859
4860             //
4861             // Light State p 50, 53, 55.
4862             //
4863             "struct gl_LightSourceParameters {"
4864                 "vec4  ambient;"             // Acli
4865                 "vec4  diffuse;"             // Dcli
4866                 "vec4  specular;"            // Scli
4867                 "vec4  position;"            // Ppli
4868                 "vec4  halfVector;"          // Derived: Hi
4869                 "vec3  spotDirection;"       // Sdli
4870                 "float spotExponent;"        // Srli
4871                 "float spotCutoff;"          // Crli
4872                                                         // (range: [0.0,90.0], 180.0)
4873                 "float spotCosCutoff;"       // Derived: cos(Crli)
4874                                                         // (range: [1.0,0.0],-1.0)
4875                 "float constantAttenuation;" // K0
4876                 "float linearAttenuation;"   // K1
4877                 "float quadraticAttenuation;"// K2
4878             "};"
4879
4880             "struct gl_LightModelParameters {"
4881                 "vec4  ambient;"       // Acs
4882             "};"
4883
4884             "uniform gl_LightModelParameters  gl_LightModel;"
4885
4886             //
4887             // Derived state from products of light and material.
4888             //
4889             "struct gl_LightModelProducts {"
4890                 "vec4  sceneColor;"     // Derived. Ecm + Acm * Acs
4891             "};"
4892
4893             "uniform gl_LightModelProducts gl_FrontLightModelProduct;"
4894             "uniform gl_LightModelProducts gl_BackLightModelProduct;"
4895
4896             "struct gl_LightProducts {"
4897                 "vec4  ambient;"        // Acm * Acli
4898                 "vec4  diffuse;"        // Dcm * Dcli
4899                 "vec4  specular;"       // Scm * Scli
4900             "};"
4901
4902             //
4903             // Fog p. 161
4904             //
4905             "struct gl_FogParameters {"
4906                 "vec4  color;"
4907                 "float density;"
4908                 "float start;"
4909                 "float end;"
4910                 "float scale;"   //  1 / (gl_FogEnd - gl_FogStart)
4911             "};"
4912
4913             "uniform gl_FogParameters gl_Fog;"
4914
4915             "\n");
4916     }
4917 #endif // !GLSLANG_WEB && !GLSLANG_ANGLE
4918
4919     //============================================================================
4920     //
4921     // Define the interface to the compute shader.
4922     //
4923     //============================================================================
4924
4925     if ((profile != EEsProfile && version >= 420) ||
4926         (profile == EEsProfile && version >= 310)) {
4927         stageBuiltins[EShLangCompute].append(
4928             "in    highp uvec3 gl_NumWorkGroups;"
4929             "const highp uvec3 gl_WorkGroupSize = uvec3(1,1,1);"
4930
4931             "in highp uvec3 gl_WorkGroupID;"
4932             "in highp uvec3 gl_LocalInvocationID;"
4933
4934             "in highp uvec3 gl_GlobalInvocationID;"
4935             "in highp uint gl_LocalInvocationIndex;"
4936
4937             "\n");
4938     }
4939
4940     if ((profile != EEsProfile && version >= 140) ||
4941         (profile == EEsProfile && version >= 310)) {
4942         stageBuiltins[EShLangCompute].append(
4943             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
4944             "\n");
4945     }
4946
4947 #ifndef GLSLANG_WEB
4948 #ifndef GLSLANG_ANGLE
4949     //============================================================================
4950     //
4951     // Define the interface to the mesh/task shader.
4952     //
4953     //============================================================================
4954
4955     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
4956         // per-vertex attributes
4957         stageBuiltins[EShLangMeshNV].append(
4958             "out gl_MeshPerVertexNV {"
4959                 "vec4 gl_Position;"
4960                 "float gl_PointSize;"
4961                 "float gl_ClipDistance[];"
4962                 "float gl_CullDistance[];"
4963                 "perviewNV vec4 gl_PositionPerViewNV[];"
4964                 "perviewNV float gl_ClipDistancePerViewNV[][];"
4965                 "perviewNV float gl_CullDistancePerViewNV[][];"
4966             "} gl_MeshVerticesNV[];"
4967         );
4968
4969         // per-primitive attributes
4970         stageBuiltins[EShLangMeshNV].append(
4971             "perprimitiveNV out gl_MeshPerPrimitiveNV {"
4972                 "int gl_PrimitiveID;"
4973                 "int gl_Layer;"
4974                 "int gl_ViewportIndex;"
4975                 "int gl_ViewportMask[];"
4976                 "perviewNV int gl_LayerPerViewNV[];"
4977                 "perviewNV int gl_ViewportMaskPerViewNV[][];"
4978             "} gl_MeshPrimitivesNV[];"
4979         );
4980
4981         stageBuiltins[EShLangMeshNV].append(
4982             "out uint gl_PrimitiveCountNV;"
4983             "out uint gl_PrimitiveIndicesNV[];"
4984
4985             "in uint gl_MeshViewCountNV;"
4986             "in uint gl_MeshViewIndicesNV[4];"
4987
4988             "const highp uvec3 gl_WorkGroupSize = uvec3(1,1,1);"
4989
4990             "in highp uvec3 gl_WorkGroupID;"
4991             "in highp uvec3 gl_LocalInvocationID;"
4992
4993             "in highp uvec3 gl_GlobalInvocationID;"
4994             "in highp uint gl_LocalInvocationIndex;"
4995
4996             "\n");
4997
4998         stageBuiltins[EShLangTaskNV].append(
4999             "out uint gl_TaskCountNV;"
5000
5001             "const highp uvec3 gl_WorkGroupSize = uvec3(1,1,1);"
5002
5003             "in highp uvec3 gl_WorkGroupID;"
5004             "in highp uvec3 gl_LocalInvocationID;"
5005
5006             "in highp uvec3 gl_GlobalInvocationID;"
5007             "in highp uint gl_LocalInvocationIndex;"
5008
5009             "in uint gl_MeshViewCountNV;"
5010             "in uint gl_MeshViewIndicesNV[4];"
5011
5012             "\n");
5013     }
5014
5015     if (profile != EEsProfile && version >= 450) {
5016         stageBuiltins[EShLangMeshNV].append(
5017             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5018             "in int gl_DrawIDARB;"             // GL_ARB_shader_draw_parameters
5019             "\n");
5020
5021         stageBuiltins[EShLangTaskNV].append(
5022             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5023             "in int gl_DrawIDARB;"             // GL_ARB_shader_draw_parameters
5024             "\n");
5025
5026         if (version >= 460) {
5027             stageBuiltins[EShLangMeshNV].append(
5028                 "in int gl_DrawID;"
5029                 "\n");
5030
5031             stageBuiltins[EShLangTaskNV].append(
5032                 "in int gl_DrawID;"
5033                 "\n");
5034         }
5035     }
5036 #endif // !GLSLANG_ANGLE
5037
5038     //============================================================================
5039     //
5040     // Define the interface to the vertex shader.
5041     //
5042     //============================================================================
5043
5044     if (profile != EEsProfile) {
5045         if (version < 130) {
5046             stageBuiltins[EShLangVertex].append(
5047                 "attribute vec4  gl_Color;"
5048                 "attribute vec4  gl_SecondaryColor;"
5049                 "attribute vec3  gl_Normal;"
5050                 "attribute vec4  gl_Vertex;"
5051                 "attribute vec4  gl_MultiTexCoord0;"
5052                 "attribute vec4  gl_MultiTexCoord1;"
5053                 "attribute vec4  gl_MultiTexCoord2;"
5054                 "attribute vec4  gl_MultiTexCoord3;"
5055                 "attribute vec4  gl_MultiTexCoord4;"
5056                 "attribute vec4  gl_MultiTexCoord5;"
5057                 "attribute vec4  gl_MultiTexCoord6;"
5058                 "attribute vec4  gl_MultiTexCoord7;"
5059                 "attribute float gl_FogCoord;"
5060                 "\n");
5061         } else if (IncludeLegacy(version, profile, spvVersion)) {
5062             stageBuiltins[EShLangVertex].append(
5063                 "in vec4  gl_Color;"
5064                 "in vec4  gl_SecondaryColor;"
5065                 "in vec3  gl_Normal;"
5066                 "in vec4  gl_Vertex;"
5067                 "in vec4  gl_MultiTexCoord0;"
5068                 "in vec4  gl_MultiTexCoord1;"
5069                 "in vec4  gl_MultiTexCoord2;"
5070                 "in vec4  gl_MultiTexCoord3;"
5071                 "in vec4  gl_MultiTexCoord4;"
5072                 "in vec4  gl_MultiTexCoord5;"
5073                 "in vec4  gl_MultiTexCoord6;"
5074                 "in vec4  gl_MultiTexCoord7;"
5075                 "in float gl_FogCoord;"
5076                 "\n");
5077         }
5078
5079         if (version < 150) {
5080             if (version < 130) {
5081                 stageBuiltins[EShLangVertex].append(
5082                     "        vec4  gl_ClipVertex;"       // needs qualifier fixed later
5083                     "varying vec4  gl_FrontColor;"
5084                     "varying vec4  gl_BackColor;"
5085                     "varying vec4  gl_FrontSecondaryColor;"
5086                     "varying vec4  gl_BackSecondaryColor;"
5087                     "varying vec4  gl_TexCoord[];"
5088                     "varying float gl_FogFragCoord;"
5089                     "\n");
5090             } else if (IncludeLegacy(version, profile, spvVersion)) {
5091                 stageBuiltins[EShLangVertex].append(
5092                     "    vec4  gl_ClipVertex;"       // needs qualifier fixed later
5093                     "out vec4  gl_FrontColor;"
5094                     "out vec4  gl_BackColor;"
5095                     "out vec4  gl_FrontSecondaryColor;"
5096                     "out vec4  gl_BackSecondaryColor;"
5097                     "out vec4  gl_TexCoord[];"
5098                     "out float gl_FogFragCoord;"
5099                     "\n");
5100             }
5101             stageBuiltins[EShLangVertex].append(
5102                 "vec4 gl_Position;"   // needs qualifier fixed later
5103                 "float gl_PointSize;" // needs qualifier fixed later
5104                 );
5105
5106             if (version == 130 || version == 140)
5107                 stageBuiltins[EShLangVertex].append(
5108                     "out float gl_ClipDistance[];"
5109                     );
5110         } else {
5111             // version >= 150
5112             stageBuiltins[EShLangVertex].append(
5113                 "out gl_PerVertex {"
5114                     "vec4 gl_Position;"     // needs qualifier fixed later
5115                     "float gl_PointSize;"   // needs qualifier fixed later
5116                     "float gl_ClipDistance[];"
5117                     );
5118             if (IncludeLegacy(version, profile, spvVersion))
5119                 stageBuiltins[EShLangVertex].append(
5120                     "vec4 gl_ClipVertex;"   // needs qualifier fixed later
5121                     "vec4 gl_FrontColor;"
5122                     "vec4 gl_BackColor;"
5123                     "vec4 gl_FrontSecondaryColor;"
5124                     "vec4 gl_BackSecondaryColor;"
5125                     "vec4 gl_TexCoord[];"
5126                     "float gl_FogFragCoord;"
5127                     );
5128             if (version >= 450)
5129                 stageBuiltins[EShLangVertex].append(
5130                     "float gl_CullDistance[];"
5131                     );
5132             stageBuiltins[EShLangVertex].append(
5133                 "};"
5134                 "\n");
5135         }
5136         if (version >= 130 && spvVersion.vulkan == 0)
5137             stageBuiltins[EShLangVertex].append(
5138                 "int gl_VertexID;"            // needs qualifier fixed later
5139                 );
5140         if (version >= 140 && spvVersion.vulkan == 0)
5141             stageBuiltins[EShLangVertex].append(
5142                 "int gl_InstanceID;"          // needs qualifier fixed later
5143                 );
5144         if (spvVersion.vulkan > 0 && version >= 140)
5145             stageBuiltins[EShLangVertex].append(
5146                 "in int gl_VertexIndex;"
5147                 "in int gl_InstanceIndex;"
5148                 );
5149
5150         if (spvVersion.vulkan > 0 && version >= 140 && spvVersion.vulkanRelaxed)
5151             stageBuiltins[EShLangVertex].append(
5152                 "in int gl_VertexID;"         // declare with 'in' qualifier
5153                 "in int gl_InstanceID;"
5154                 );
5155
5156         if (version >= 440) {
5157             stageBuiltins[EShLangVertex].append(
5158                 "in int gl_BaseVertexARB;"
5159                 "in int gl_BaseInstanceARB;"
5160                 "in int gl_DrawIDARB;"
5161                 );
5162         }
5163         if (version >= 410) {
5164             stageBuiltins[EShLangVertex].append(
5165                 "out int gl_ViewportIndex;"
5166                 "out int gl_Layer;"
5167                 );
5168         }
5169         if (version >= 460) {
5170             stageBuiltins[EShLangVertex].append(
5171                 "in int gl_BaseVertex;"
5172                 "in int gl_BaseInstance;"
5173                 "in int gl_DrawID;"
5174                 );
5175         }
5176
5177         if (version >= 450)
5178             stageBuiltins[EShLangVertex].append(
5179                 "out int gl_ViewportMask[];"             // GL_NV_viewport_array2
5180                 "out int gl_SecondaryViewportMaskNV[];"  // GL_NV_stereo_view_rendering
5181                 "out vec4 gl_SecondaryPositionNV;"       // GL_NV_stereo_view_rendering
5182                 "out vec4 gl_PositionPerViewNV[];"       // GL_NVX_multiview_per_view_attributes
5183                 "out int  gl_ViewportMaskPerViewNV[];"   // GL_NVX_multiview_per_view_attributes
5184                 );
5185     } else {
5186         // ES profile
5187         if (version == 100) {
5188             stageBuiltins[EShLangVertex].append(
5189                 "highp   vec4  gl_Position;"  // needs qualifier fixed later
5190                 "mediump float gl_PointSize;" // needs qualifier fixed later
5191                 );
5192         } else {
5193             if (spvVersion.vulkan == 0 || spvVersion.vulkanRelaxed)
5194                 stageBuiltins[EShLangVertex].append(
5195                     "in highp int gl_VertexID;"      // needs qualifier fixed later
5196                     "in highp int gl_InstanceID;"    // needs qualifier fixed later
5197                     );
5198             if (spvVersion.vulkan > 0)
5199 #endif
5200                 stageBuiltins[EShLangVertex].append(
5201                     "in highp int gl_VertexIndex;"
5202                     "in highp int gl_InstanceIndex;"
5203                     );
5204 #ifndef GLSLANG_WEB
5205             if (version < 310)
5206 #endif
5207                 stageBuiltins[EShLangVertex].append(
5208                     "highp vec4  gl_Position;"    // needs qualifier fixed later
5209                     "highp float gl_PointSize;"   // needs qualifier fixed later
5210                     );
5211 #ifndef GLSLANG_WEB
5212             else
5213                 stageBuiltins[EShLangVertex].append(
5214                     "out gl_PerVertex {"
5215                         "highp vec4  gl_Position;"    // needs qualifier fixed later
5216                         "highp float gl_PointSize;"   // needs qualifier fixed later
5217                     "};"
5218                     );
5219         }
5220     }
5221
5222     if ((profile != EEsProfile && version >= 140) ||
5223         (profile == EEsProfile && version >= 310)) {
5224         stageBuiltins[EShLangVertex].append(
5225             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5226             "in highp int gl_ViewIndex;"       // GL_EXT_multiview
5227             "\n");
5228     }
5229
5230     if (version >= 300 /* both ES and non-ES */) {
5231         stageBuiltins[EShLangVertex].append(
5232             "in highp uint gl_ViewID_OVR;"     // GL_OVR_multiview, GL_OVR_multiview2
5233             "\n");
5234     }
5235
5236     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
5237         stageBuiltins[EShLangVertex].append(
5238             "out highp int gl_PrimitiveShadingRateEXT;" // GL_EXT_fragment_shading_rate
5239             "\n");
5240     }
5241
5242     //============================================================================
5243     //
5244     // Define the interface to the geometry shader.
5245     //
5246     //============================================================================
5247
5248     if (profile == ECoreProfile || profile == ECompatibilityProfile) {
5249         stageBuiltins[EShLangGeometry].append(
5250             "in gl_PerVertex {"
5251                 "vec4 gl_Position;"
5252                 "float gl_PointSize;"
5253                 "float gl_ClipDistance[];"
5254                 );
5255         if (profile == ECompatibilityProfile)
5256             stageBuiltins[EShLangGeometry].append(
5257                 "vec4 gl_ClipVertex;"
5258                 "vec4 gl_FrontColor;"
5259                 "vec4 gl_BackColor;"
5260                 "vec4 gl_FrontSecondaryColor;"
5261                 "vec4 gl_BackSecondaryColor;"
5262                 "vec4 gl_TexCoord[];"
5263                 "float gl_FogFragCoord;"
5264                 );
5265         if (version >= 450)
5266             stageBuiltins[EShLangGeometry].append(
5267                 "float gl_CullDistance[];"
5268                 "vec4 gl_SecondaryPositionNV;"   // GL_NV_stereo_view_rendering
5269                 "vec4 gl_PositionPerViewNV[];"   // GL_NVX_multiview_per_view_attributes
5270                 );
5271         stageBuiltins[EShLangGeometry].append(
5272             "} gl_in[];"
5273
5274             "in int gl_PrimitiveIDIn;"
5275             "out gl_PerVertex {"
5276                 "vec4 gl_Position;"
5277                 "float gl_PointSize;"
5278                 "float gl_ClipDistance[];"
5279                 "\n");
5280         if (profile == ECompatibilityProfile && version >= 400)
5281             stageBuiltins[EShLangGeometry].append(
5282                 "vec4 gl_ClipVertex;"
5283                 "vec4 gl_FrontColor;"
5284                 "vec4 gl_BackColor;"
5285                 "vec4 gl_FrontSecondaryColor;"
5286                 "vec4 gl_BackSecondaryColor;"
5287                 "vec4 gl_TexCoord[];"
5288                 "float gl_FogFragCoord;"
5289                 );
5290         if (version >= 450)
5291             stageBuiltins[EShLangGeometry].append(
5292                 "float gl_CullDistance[];"
5293                 );
5294         stageBuiltins[EShLangGeometry].append(
5295             "};"
5296
5297             "out int gl_PrimitiveID;"
5298             "out int gl_Layer;");
5299
5300         if (version >= 150)
5301             stageBuiltins[EShLangGeometry].append(
5302             "out int gl_ViewportIndex;"
5303             );
5304
5305         if (profile == ECompatibilityProfile && version < 400)
5306             stageBuiltins[EShLangGeometry].append(
5307             "out vec4 gl_ClipVertex;"
5308             );
5309
5310         if (version >= 400)
5311             stageBuiltins[EShLangGeometry].append(
5312             "in int gl_InvocationID;"
5313             );
5314
5315         if (version >= 450)
5316             stageBuiltins[EShLangGeometry].append(
5317                 "out int gl_ViewportMask[];"               // GL_NV_viewport_array2
5318                 "out int gl_SecondaryViewportMaskNV[];"    // GL_NV_stereo_view_rendering
5319                 "out vec4 gl_SecondaryPositionNV;"         // GL_NV_stereo_view_rendering
5320                 "out vec4 gl_PositionPerViewNV[];"         // GL_NVX_multiview_per_view_attributes
5321                 "out int  gl_ViewportMaskPerViewNV[];"     // GL_NVX_multiview_per_view_attributes
5322             );
5323
5324         stageBuiltins[EShLangGeometry].append("\n");
5325     } else if (profile == EEsProfile && version >= 310) {
5326         stageBuiltins[EShLangGeometry].append(
5327             "in gl_PerVertex {"
5328                 "highp vec4 gl_Position;"
5329                 "highp float gl_PointSize;"
5330             "} gl_in[];"
5331             "\n"
5332             "in highp int gl_PrimitiveIDIn;"
5333             "in highp int gl_InvocationID;"
5334             "\n"
5335             "out gl_PerVertex {"
5336                 "highp vec4 gl_Position;"
5337                 "highp float gl_PointSize;"
5338             "};"
5339             "\n"
5340             "out highp int gl_PrimitiveID;"
5341             "out highp int gl_Layer;"
5342             "\n"
5343             );
5344     }
5345
5346     if ((profile != EEsProfile && version >= 140) ||
5347         (profile == EEsProfile && version >= 310)) {
5348         stageBuiltins[EShLangGeometry].append(
5349             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5350             "in highp int gl_ViewIndex;"       // GL_EXT_multiview
5351             "\n");
5352     }
5353
5354     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
5355         stageBuiltins[EShLangGeometry].append(
5356             "out highp int gl_PrimitiveShadingRateEXT;" // GL_EXT_fragment_shading_rate
5357             "\n");
5358     }
5359
5360     //============================================================================
5361     //
5362     // Define the interface to the tessellation control shader.
5363     //
5364     //============================================================================
5365
5366     if (profile != EEsProfile && version >= 150) {
5367         // Note:  "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below,
5368         // as it depends on the resource sizing of gl_MaxPatchVertices.
5369
5370         stageBuiltins[EShLangTessControl].append(
5371             "in int gl_PatchVerticesIn;"
5372             "in int gl_PrimitiveID;"
5373             "in int gl_InvocationID;"
5374
5375             "out gl_PerVertex {"
5376                 "vec4 gl_Position;"
5377                 "float gl_PointSize;"
5378                 "float gl_ClipDistance[];"
5379                 );
5380         if (profile == ECompatibilityProfile)
5381             stageBuiltins[EShLangTessControl].append(
5382                 "vec4 gl_ClipVertex;"
5383                 "vec4 gl_FrontColor;"
5384                 "vec4 gl_BackColor;"
5385                 "vec4 gl_FrontSecondaryColor;"
5386                 "vec4 gl_BackSecondaryColor;"
5387                 "vec4 gl_TexCoord[];"
5388                 "float gl_FogFragCoord;"
5389                 );
5390         if (version >= 450)
5391             stageBuiltins[EShLangTessControl].append(
5392                 "float gl_CullDistance[];"
5393                 "int  gl_ViewportMask[];"             // GL_NV_viewport_array2
5394                 "vec4 gl_SecondaryPositionNV;"        // GL_NV_stereo_view_rendering
5395                 "int  gl_SecondaryViewportMaskNV[];"  // GL_NV_stereo_view_rendering
5396                 "vec4 gl_PositionPerViewNV[];"        // GL_NVX_multiview_per_view_attributes
5397                 "int  gl_ViewportMaskPerViewNV[];"    // GL_NVX_multiview_per_view_attributes
5398                 );
5399         stageBuiltins[EShLangTessControl].append(
5400             "} gl_out[];"
5401
5402             "patch out float gl_TessLevelOuter[4];"
5403             "patch out float gl_TessLevelInner[2];"
5404             "\n");
5405
5406         if (version >= 410)
5407             stageBuiltins[EShLangTessControl].append(
5408                 "out int gl_ViewportIndex;"
5409                 "out int gl_Layer;"
5410                 "\n");
5411
5412     } else {
5413         // Note:  "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below,
5414         // as it depends on the resource sizing of gl_MaxPatchVertices.
5415
5416         stageBuiltins[EShLangTessControl].append(
5417             "in highp int gl_PatchVerticesIn;"
5418             "in highp int gl_PrimitiveID;"
5419             "in highp int gl_InvocationID;"
5420
5421             "out gl_PerVertex {"
5422                 "highp vec4 gl_Position;"
5423                 "highp float gl_PointSize;"
5424                 );
5425         stageBuiltins[EShLangTessControl].append(
5426             "} gl_out[];"
5427
5428             "patch out highp float gl_TessLevelOuter[4];"
5429             "patch out highp float gl_TessLevelInner[2];"
5430             "patch out highp vec4 gl_BoundingBoxOES[2];"
5431             "patch out highp vec4 gl_BoundingBoxEXT[2];"
5432             "\n");
5433         if (profile == EEsProfile && version >= 320) {
5434             stageBuiltins[EShLangTessControl].append(
5435                 "patch out highp vec4 gl_BoundingBox[2];"
5436                 "\n"
5437             );
5438         }
5439     }
5440
5441     if ((profile != EEsProfile && version >= 140) ||
5442         (profile == EEsProfile && version >= 310)) {
5443         stageBuiltins[EShLangTessControl].append(
5444             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5445             "in highp int gl_ViewIndex;"       // GL_EXT_multiview
5446             "\n");
5447     }
5448
5449     //============================================================================
5450     //
5451     // Define the interface to the tessellation evaluation shader.
5452     //
5453     //============================================================================
5454
5455     if (profile != EEsProfile && version >= 150) {
5456         // Note:  "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below,
5457         // as it depends on the resource sizing of gl_MaxPatchVertices.
5458
5459         stageBuiltins[EShLangTessEvaluation].append(
5460             "in int gl_PatchVerticesIn;"
5461             "in int gl_PrimitiveID;"
5462             "in vec3 gl_TessCoord;"
5463
5464             "patch in float gl_TessLevelOuter[4];"
5465             "patch in float gl_TessLevelInner[2];"
5466
5467             "out gl_PerVertex {"
5468                 "vec4 gl_Position;"
5469                 "float gl_PointSize;"
5470                 "float gl_ClipDistance[];"
5471             );
5472         if (version >= 400 && profile == ECompatibilityProfile)
5473             stageBuiltins[EShLangTessEvaluation].append(
5474                 "vec4 gl_ClipVertex;"
5475                 "vec4 gl_FrontColor;"
5476                 "vec4 gl_BackColor;"
5477                 "vec4 gl_FrontSecondaryColor;"
5478                 "vec4 gl_BackSecondaryColor;"
5479                 "vec4 gl_TexCoord[];"
5480                 "float gl_FogFragCoord;"
5481                 );
5482         if (version >= 450)
5483             stageBuiltins[EShLangTessEvaluation].append(
5484                 "float gl_CullDistance[];"
5485                 );
5486         stageBuiltins[EShLangTessEvaluation].append(
5487             "};"
5488             "\n");
5489
5490         if (version >= 410)
5491             stageBuiltins[EShLangTessEvaluation].append(
5492                 "out int gl_ViewportIndex;"
5493                 "out int gl_Layer;"
5494                 "\n");
5495
5496         if (version >= 450)
5497             stageBuiltins[EShLangTessEvaluation].append(
5498                 "out int  gl_ViewportMask[];"             // GL_NV_viewport_array2
5499                 "out vec4 gl_SecondaryPositionNV;"        // GL_NV_stereo_view_rendering
5500                 "out int  gl_SecondaryViewportMaskNV[];"  // GL_NV_stereo_view_rendering
5501                 "out vec4 gl_PositionPerViewNV[];"        // GL_NVX_multiview_per_view_attributes
5502                 "out int  gl_ViewportMaskPerViewNV[];"    // GL_NVX_multiview_per_view_attributes
5503                 );
5504
5505     } else if (profile == EEsProfile && version >= 310) {
5506         // Note:  "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below,
5507         // as it depends on the resource sizing of gl_MaxPatchVertices.
5508
5509         stageBuiltins[EShLangTessEvaluation].append(
5510             "in highp int gl_PatchVerticesIn;"
5511             "in highp int gl_PrimitiveID;"
5512             "in highp vec3 gl_TessCoord;"
5513
5514             "patch in highp float gl_TessLevelOuter[4];"
5515             "patch in highp float gl_TessLevelInner[2];"
5516
5517             "out gl_PerVertex {"
5518                 "highp vec4 gl_Position;"
5519                 "highp float gl_PointSize;"
5520             );
5521         stageBuiltins[EShLangTessEvaluation].append(
5522             "};"
5523             "\n");
5524     }
5525
5526     if ((profile != EEsProfile && version >= 140) ||
5527         (profile == EEsProfile && version >= 310)) {
5528         stageBuiltins[EShLangTessEvaluation].append(
5529             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5530             "in highp int gl_ViewIndex;"       // GL_EXT_multiview
5531             "\n");
5532     }
5533
5534     //============================================================================
5535     //
5536     // Define the interface to the fragment shader.
5537     //
5538     //============================================================================
5539
5540     if (profile != EEsProfile) {
5541
5542         stageBuiltins[EShLangFragment].append(
5543             "vec4  gl_FragCoord;"   // needs qualifier fixed later
5544             "bool  gl_FrontFacing;" // needs qualifier fixed later
5545             "float gl_FragDepth;"   // needs qualifier fixed later
5546             );
5547         if (version >= 120)
5548             stageBuiltins[EShLangFragment].append(
5549                 "vec2 gl_PointCoord;"  // needs qualifier fixed later
5550                 );
5551         if (version >= 140)
5552             stageBuiltins[EShLangFragment].append(
5553                 "out int gl_FragStencilRefARB;"
5554                 );
5555         if (IncludeLegacy(version, profile, spvVersion) || (! ForwardCompatibility && version < 420))
5556             stageBuiltins[EShLangFragment].append(
5557                 "vec4 gl_FragColor;"   // needs qualifier fixed later
5558                 );
5559
5560         if (version < 130) {
5561             stageBuiltins[EShLangFragment].append(
5562                 "varying vec4  gl_Color;"
5563                 "varying vec4  gl_SecondaryColor;"
5564                 "varying vec4  gl_TexCoord[];"
5565                 "varying float gl_FogFragCoord;"
5566                 );
5567         } else {
5568             stageBuiltins[EShLangFragment].append(
5569                 "in float gl_ClipDistance[];"
5570                 );
5571
5572             if (IncludeLegacy(version, profile, spvVersion)) {
5573                 if (version < 150)
5574                     stageBuiltins[EShLangFragment].append(
5575                         "in float gl_FogFragCoord;"
5576                         "in vec4  gl_TexCoord[];"
5577                         "in vec4  gl_Color;"
5578                         "in vec4  gl_SecondaryColor;"
5579                         );
5580                 else
5581                     stageBuiltins[EShLangFragment].append(
5582                         "in gl_PerFragment {"
5583                             "in float gl_FogFragCoord;"
5584                             "in vec4  gl_TexCoord[];"
5585                             "in vec4  gl_Color;"
5586                             "in vec4  gl_SecondaryColor;"
5587                         "};"
5588                         );
5589             }
5590         }
5591
5592         if (version >= 150)
5593             stageBuiltins[EShLangFragment].append(
5594                 "flat in int gl_PrimitiveID;"
5595                 );
5596
5597         if (version >= 130) { // ARB_sample_shading
5598             stageBuiltins[EShLangFragment].append(
5599                 "flat in  int  gl_SampleID;"
5600                 "     in  vec2 gl_SamplePosition;"
5601                 "     out int  gl_SampleMask[];"
5602                 );
5603
5604             if (spvVersion.spv == 0) {
5605                 stageBuiltins[EShLangFragment].append(
5606                     "uniform int gl_NumSamples;"
5607                 );
5608             }
5609         }
5610
5611         if (version >= 400)
5612             stageBuiltins[EShLangFragment].append(
5613                 "flat in  int  gl_SampleMaskIn[];"
5614             );
5615
5616         if (version >= 430)
5617             stageBuiltins[EShLangFragment].append(
5618                 "flat in int gl_Layer;"
5619                 "flat in int gl_ViewportIndex;"
5620                 );
5621
5622         if (version >= 450)
5623             stageBuiltins[EShLangFragment].append(
5624                 "in float gl_CullDistance[];"
5625                 "bool gl_HelperInvocation;"     // needs qualifier fixed later
5626                 );
5627
5628         if (version >= 450)
5629             stageBuiltins[EShLangFragment].append( // GL_EXT_fragment_invocation_density
5630                 "flat in ivec2 gl_FragSizeEXT;"
5631                 "flat in int   gl_FragInvocationCountEXT;"
5632                 );
5633
5634         if (version >= 450)
5635             stageBuiltins[EShLangFragment].append(
5636                 "in vec2 gl_BaryCoordNoPerspAMD;"
5637                 "in vec2 gl_BaryCoordNoPerspCentroidAMD;"
5638                 "in vec2 gl_BaryCoordNoPerspSampleAMD;"
5639                 "in vec2 gl_BaryCoordSmoothAMD;"
5640                 "in vec2 gl_BaryCoordSmoothCentroidAMD;"
5641                 "in vec2 gl_BaryCoordSmoothSampleAMD;"
5642                 "in vec3 gl_BaryCoordPullModelAMD;"
5643                 );
5644
5645         if (version >= 430)
5646             stageBuiltins[EShLangFragment].append(
5647                 "in bool gl_FragFullyCoveredNV;"
5648                 );
5649         if (version >= 450)
5650             stageBuiltins[EShLangFragment].append(
5651                 "flat in ivec2 gl_FragmentSizeNV;"          // GL_NV_shading_rate_image
5652                 "flat in int   gl_InvocationsPerPixelNV;"
5653                 "in vec3 gl_BaryCoordNV;"                   // GL_NV_fragment_shader_barycentric
5654                 "in vec3 gl_BaryCoordNoPerspNV;"
5655                 );
5656
5657         if (version >= 450)
5658             stageBuiltins[EShLangFragment].append(
5659                 "flat in int gl_ShadingRateEXT;" // GL_EXT_fragment_shading_rate
5660             );
5661
5662     } else {
5663         // ES profile
5664
5665         if (version == 100) {
5666             stageBuiltins[EShLangFragment].append(
5667                 "mediump vec4 gl_FragCoord;"    // needs qualifier fixed later
5668                 "        bool gl_FrontFacing;"  // needs qualifier fixed later
5669                 "mediump vec4 gl_FragColor;"    // needs qualifier fixed later
5670                 "mediump vec2 gl_PointCoord;"   // needs qualifier fixed later
5671                 );
5672         }
5673 #endif
5674         if (version >= 300) {
5675             stageBuiltins[EShLangFragment].append(
5676                 "highp   vec4  gl_FragCoord;"    // needs qualifier fixed later
5677                 "        bool  gl_FrontFacing;"  // needs qualifier fixed later
5678                 "mediump vec2  gl_PointCoord;"   // needs qualifier fixed later
5679                 "highp   float gl_FragDepth;"    // needs qualifier fixed later
5680                 );
5681         }
5682 #ifndef GLSLANG_WEB
5683         if (version >= 310) {
5684             stageBuiltins[EShLangFragment].append(
5685                 "bool gl_HelperInvocation;"          // needs qualifier fixed later
5686                 "flat in highp int gl_PrimitiveID;"  // needs qualifier fixed later
5687                 "flat in highp int gl_Layer;"        // needs qualifier fixed later
5688                 );
5689
5690             stageBuiltins[EShLangFragment].append(  // GL_OES_sample_variables
5691                 "flat  in lowp     int gl_SampleID;"
5692                 "      in mediump vec2 gl_SamplePosition;"
5693                 "flat  in highp    int gl_SampleMaskIn[];"
5694                 "     out highp    int gl_SampleMask[];"
5695                 );
5696             if (spvVersion.spv == 0)
5697                 stageBuiltins[EShLangFragment].append(  // GL_OES_sample_variables
5698                     "uniform lowp int gl_NumSamples;"
5699                     );
5700         }
5701         stageBuiltins[EShLangFragment].append(
5702             "highp float gl_FragDepthEXT;"       // GL_EXT_frag_depth
5703             );
5704
5705         if (version >= 310)
5706             stageBuiltins[EShLangFragment].append( // GL_EXT_fragment_invocation_density
5707                 "flat in ivec2 gl_FragSizeEXT;"
5708                 "flat in int   gl_FragInvocationCountEXT;"
5709             );
5710         if (version >= 320)
5711             stageBuiltins[EShLangFragment].append( // GL_NV_shading_rate_image
5712                 "flat in ivec2 gl_FragmentSizeNV;"
5713                 "flat in int   gl_InvocationsPerPixelNV;"
5714             );
5715         if (version >= 320)
5716             stageBuiltins[EShLangFragment].append(
5717                 "in vec3 gl_BaryCoordNV;"
5718                 "in vec3 gl_BaryCoordNoPerspNV;"
5719                 );
5720         if (version >= 310)
5721             stageBuiltins[EShLangFragment].append(
5722                 "flat in highp int gl_ShadingRateEXT;" // GL_EXT_fragment_shading_rate
5723             );
5724     }
5725 #endif
5726
5727     stageBuiltins[EShLangFragment].append("\n");
5728
5729     if (version >= 130)
5730         add2ndGenerationSamplingImaging(version, profile, spvVersion);
5731
5732 #ifndef GLSLANG_WEB
5733
5734     if ((profile != EEsProfile && version >= 140) ||
5735         (profile == EEsProfile && version >= 310)) {
5736         stageBuiltins[EShLangFragment].append(
5737             "flat in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5738             "flat in highp int gl_ViewIndex;"       // GL_EXT_multiview
5739             "\n");
5740     }
5741
5742     if (version >= 300 /* both ES and non-ES */) {
5743         stageBuiltins[EShLangFragment].append(
5744             "flat in highp uint gl_ViewID_OVR;"     // GL_OVR_multiview, GL_OVR_multiview2
5745             "\n");
5746     }
5747
5748 #ifndef GLSLANG_ANGLE
5749     // GL_ARB_shader_ballot
5750     if (profile != EEsProfile && version >= 450) {
5751         const char* ballotDecls =
5752             "uniform uint gl_SubGroupSizeARB;"
5753             "in uint     gl_SubGroupInvocationARB;"
5754             "in uint64_t gl_SubGroupEqMaskARB;"
5755             "in uint64_t gl_SubGroupGeMaskARB;"
5756             "in uint64_t gl_SubGroupGtMaskARB;"
5757             "in uint64_t gl_SubGroupLeMaskARB;"
5758             "in uint64_t gl_SubGroupLtMaskARB;"
5759             "\n";
5760         const char* rtBallotDecls =
5761             "uniform volatile uint gl_SubGroupSizeARB;"
5762             "in volatile uint     gl_SubGroupInvocationARB;"
5763             "in volatile uint64_t gl_SubGroupEqMaskARB;"
5764             "in volatile uint64_t gl_SubGroupGeMaskARB;"
5765             "in volatile uint64_t gl_SubGroupGtMaskARB;"
5766             "in volatile uint64_t gl_SubGroupLeMaskARB;"
5767             "in volatile uint64_t gl_SubGroupLtMaskARB;"
5768             "\n";
5769         const char* fragmentBallotDecls =
5770             "uniform uint gl_SubGroupSizeARB;"
5771             "flat in uint     gl_SubGroupInvocationARB;"
5772             "flat in uint64_t gl_SubGroupEqMaskARB;"
5773             "flat in uint64_t gl_SubGroupGeMaskARB;"
5774             "flat in uint64_t gl_SubGroupGtMaskARB;"
5775             "flat in uint64_t gl_SubGroupLeMaskARB;"
5776             "flat in uint64_t gl_SubGroupLtMaskARB;"
5777             "\n";
5778         stageBuiltins[EShLangVertex]        .append(ballotDecls);
5779         stageBuiltins[EShLangTessControl]   .append(ballotDecls);
5780         stageBuiltins[EShLangTessEvaluation].append(ballotDecls);
5781         stageBuiltins[EShLangGeometry]      .append(ballotDecls);
5782         stageBuiltins[EShLangCompute]       .append(ballotDecls);
5783         stageBuiltins[EShLangFragment]      .append(fragmentBallotDecls);
5784         stageBuiltins[EShLangMeshNV]        .append(ballotDecls);
5785         stageBuiltins[EShLangTaskNV]        .append(ballotDecls);
5786         stageBuiltins[EShLangRayGen]        .append(rtBallotDecls);
5787         stageBuiltins[EShLangIntersect]     .append(rtBallotDecls);
5788         // No volatile qualifier on these builtins in any-hit
5789         stageBuiltins[EShLangAnyHit]        .append(ballotDecls);
5790         stageBuiltins[EShLangClosestHit]    .append(rtBallotDecls);
5791         stageBuiltins[EShLangMiss]          .append(rtBallotDecls);
5792         stageBuiltins[EShLangCallable]      .append(rtBallotDecls);
5793     }
5794
5795     // GL_KHR_shader_subgroup
5796     if ((profile == EEsProfile && version >= 310) ||
5797         (profile != EEsProfile && version >= 140)) {
5798         const char* subgroupDecls =
5799             "in mediump uint  gl_SubgroupSize;"
5800             "in mediump uint  gl_SubgroupInvocationID;"
5801             "in highp   uvec4 gl_SubgroupEqMask;"
5802             "in highp   uvec4 gl_SubgroupGeMask;"
5803             "in highp   uvec4 gl_SubgroupGtMask;"
5804             "in highp   uvec4 gl_SubgroupLeMask;"
5805             "in highp   uvec4 gl_SubgroupLtMask;"
5806             // GL_NV_shader_sm_builtins
5807             "in highp   uint  gl_WarpsPerSMNV;"
5808             "in highp   uint  gl_SMCountNV;"
5809             "in highp   uint  gl_WarpIDNV;"
5810             "in highp   uint  gl_SMIDNV;"
5811             "\n";
5812         const char* fragmentSubgroupDecls =
5813             "flat in mediump uint  gl_SubgroupSize;"
5814             "flat in mediump uint  gl_SubgroupInvocationID;"
5815             "flat in highp   uvec4 gl_SubgroupEqMask;"
5816             "flat in highp   uvec4 gl_SubgroupGeMask;"
5817             "flat in highp   uvec4 gl_SubgroupGtMask;"
5818             "flat in highp   uvec4 gl_SubgroupLeMask;"
5819             "flat in highp   uvec4 gl_SubgroupLtMask;"
5820             // GL_NV_shader_sm_builtins
5821             "flat in highp   uint  gl_WarpsPerSMNV;"
5822             "flat in highp   uint  gl_SMCountNV;"
5823             "flat in highp   uint  gl_WarpIDNV;"
5824             "flat in highp   uint  gl_SMIDNV;"
5825             "\n";
5826         const char* computeSubgroupDecls =
5827             "in highp   uint  gl_NumSubgroups;"
5828             "in highp   uint  gl_SubgroupID;"
5829             "\n";
5830         // These builtins are volatile for RT stages
5831         const char* rtSubgroupDecls =
5832             "in mediump volatile uint  gl_SubgroupSize;"
5833             "in mediump volatile uint  gl_SubgroupInvocationID;"
5834             "in highp   volatile uvec4 gl_SubgroupEqMask;"
5835             "in highp   volatile uvec4 gl_SubgroupGeMask;"
5836             "in highp   volatile uvec4 gl_SubgroupGtMask;"
5837             "in highp   volatile uvec4 gl_SubgroupLeMask;"
5838             "in highp   volatile uvec4 gl_SubgroupLtMask;"
5839             // GL_NV_shader_sm_builtins
5840             "in highp    uint  gl_WarpsPerSMNV;"
5841             "in highp    uint  gl_SMCountNV;"
5842             "in highp volatile uint  gl_WarpIDNV;"
5843             "in highp volatile uint  gl_SMIDNV;"
5844             "\n";
5845
5846         stageBuiltins[EShLangVertex]        .append(subgroupDecls);
5847         stageBuiltins[EShLangTessControl]   .append(subgroupDecls);
5848         stageBuiltins[EShLangTessEvaluation].append(subgroupDecls);
5849         stageBuiltins[EShLangGeometry]      .append(subgroupDecls);
5850         stageBuiltins[EShLangCompute]       .append(subgroupDecls);
5851         stageBuiltins[EShLangCompute]       .append(computeSubgroupDecls);
5852         stageBuiltins[EShLangFragment]      .append(fragmentSubgroupDecls);
5853         stageBuiltins[EShLangMeshNV]        .append(subgroupDecls);
5854         stageBuiltins[EShLangMeshNV]        .append(computeSubgroupDecls);
5855         stageBuiltins[EShLangTaskNV]        .append(subgroupDecls);
5856         stageBuiltins[EShLangTaskNV]        .append(computeSubgroupDecls);
5857         stageBuiltins[EShLangRayGen]        .append(rtSubgroupDecls);
5858         stageBuiltins[EShLangIntersect]     .append(rtSubgroupDecls);
5859         // No volatile qualifier on these builtins in any-hit
5860         stageBuiltins[EShLangAnyHit]        .append(subgroupDecls);
5861         stageBuiltins[EShLangClosestHit]    .append(rtSubgroupDecls);
5862         stageBuiltins[EShLangMiss]          .append(rtSubgroupDecls);
5863         stageBuiltins[EShLangCallable]      .append(rtSubgroupDecls);
5864     }
5865
5866     // GL_NV_ray_tracing/GL_EXT_ray_tracing
5867     if (profile != EEsProfile && version >= 460) {
5868
5869         const char *constRayFlags =
5870             "const uint gl_RayFlagsNoneNV = 0U;"
5871             "const uint gl_RayFlagsNoneEXT = 0U;"
5872             "const uint gl_RayFlagsOpaqueNV = 1U;"
5873             "const uint gl_RayFlagsOpaqueEXT = 1U;"
5874             "const uint gl_RayFlagsNoOpaqueNV = 2U;"
5875             "const uint gl_RayFlagsNoOpaqueEXT = 2U;"
5876             "const uint gl_RayFlagsTerminateOnFirstHitNV = 4U;"
5877             "const uint gl_RayFlagsTerminateOnFirstHitEXT = 4U;"
5878             "const uint gl_RayFlagsSkipClosestHitShaderNV = 8U;"
5879             "const uint gl_RayFlagsSkipClosestHitShaderEXT = 8U;"
5880             "const uint gl_RayFlagsCullBackFacingTrianglesNV = 16U;"
5881             "const uint gl_RayFlagsCullBackFacingTrianglesEXT = 16U;"
5882             "const uint gl_RayFlagsCullFrontFacingTrianglesNV = 32U;"
5883             "const uint gl_RayFlagsCullFrontFacingTrianglesEXT = 32U;"
5884             "const uint gl_RayFlagsCullOpaqueNV = 64U;"
5885             "const uint gl_RayFlagsCullOpaqueEXT = 64U;"
5886             "const uint gl_RayFlagsCullNoOpaqueNV = 128U;"
5887             "const uint gl_RayFlagsCullNoOpaqueEXT = 128U;"
5888             "const uint gl_RayFlagsSkipTrianglesEXT = 256U;"
5889             "const uint gl_RayFlagsSkipAABBEXT = 512U;"
5890             "const uint gl_HitKindFrontFacingTriangleEXT = 254U;"
5891             "const uint gl_HitKindBackFacingTriangleEXT = 255U;"
5892             "\n";
5893
5894         const char *constRayQueryIntersection =
5895             "const uint gl_RayQueryCandidateIntersectionEXT = 0U;"
5896             "const uint gl_RayQueryCommittedIntersectionEXT = 1U;"
5897             "const uint gl_RayQueryCommittedIntersectionNoneEXT = 0U;"
5898             "const uint gl_RayQueryCommittedIntersectionTriangleEXT = 1U;"
5899             "const uint gl_RayQueryCommittedIntersectionGeneratedEXT = 2U;"
5900             "const uint gl_RayQueryCandidateIntersectionTriangleEXT = 0U;"
5901             "const uint gl_RayQueryCandidateIntersectionAABBEXT = 1U;"
5902             "\n";
5903
5904         const char *rayGenDecls =
5905             "in    uvec3  gl_LaunchIDNV;"
5906             "in    uvec3  gl_LaunchIDEXT;"
5907             "in    uvec3  gl_LaunchSizeNV;"
5908             "in    uvec3  gl_LaunchSizeEXT;"
5909             "\n";
5910         const char *intersectDecls =
5911             "in    uvec3  gl_LaunchIDNV;"
5912             "in    uvec3  gl_LaunchIDEXT;"
5913             "in    uvec3  gl_LaunchSizeNV;"
5914             "in    uvec3  gl_LaunchSizeEXT;"
5915             "in     int   gl_PrimitiveID;"
5916             "in     int   gl_InstanceID;"
5917             "in     int   gl_InstanceCustomIndexNV;"
5918             "in     int   gl_InstanceCustomIndexEXT;"
5919             "in     int   gl_GeometryIndexEXT;"
5920             "in    vec3   gl_WorldRayOriginNV;"
5921             "in    vec3   gl_WorldRayOriginEXT;"
5922             "in    vec3   gl_WorldRayDirectionNV;"
5923             "in    vec3   gl_WorldRayDirectionEXT;"
5924             "in    vec3   gl_ObjectRayOriginNV;"
5925             "in    vec3   gl_ObjectRayOriginEXT;"
5926             "in    vec3   gl_ObjectRayDirectionNV;"
5927             "in    vec3   gl_ObjectRayDirectionEXT;"
5928             "in    float  gl_RayTminNV;"
5929             "in    float  gl_RayTminEXT;"
5930             "in    float  gl_RayTmaxNV;"
5931             "in volatile float gl_RayTmaxEXT;"
5932             "in    mat4x3 gl_ObjectToWorldNV;"
5933             "in    mat4x3 gl_ObjectToWorldEXT;"
5934             "in    mat3x4 gl_ObjectToWorld3x4EXT;"
5935             "in    mat4x3 gl_WorldToObjectNV;"
5936             "in    mat4x3 gl_WorldToObjectEXT;"
5937             "in    mat3x4 gl_WorldToObject3x4EXT;"
5938             "in    uint   gl_IncomingRayFlagsNV;"
5939             "in    uint   gl_IncomingRayFlagsEXT;"
5940             "in    float  gl_CurrentRayTimeNV;"
5941             "\n";
5942         const char *hitDecls =
5943             "in    uvec3  gl_LaunchIDNV;"
5944             "in    uvec3  gl_LaunchIDEXT;"
5945             "in    uvec3  gl_LaunchSizeNV;"
5946             "in    uvec3  gl_LaunchSizeEXT;"
5947             "in     int   gl_PrimitiveID;"
5948             "in     int   gl_InstanceID;"
5949             "in     int   gl_InstanceCustomIndexNV;"
5950             "in     int   gl_InstanceCustomIndexEXT;"
5951             "in     int   gl_GeometryIndexEXT;"
5952             "in    vec3   gl_WorldRayOriginNV;"
5953             "in    vec3   gl_WorldRayOriginEXT;"
5954             "in    vec3   gl_WorldRayDirectionNV;"
5955             "in    vec3   gl_WorldRayDirectionEXT;"
5956             "in    vec3   gl_ObjectRayOriginNV;"
5957             "in    vec3   gl_ObjectRayOriginEXT;"
5958             "in    vec3   gl_ObjectRayDirectionNV;"
5959             "in    vec3   gl_ObjectRayDirectionEXT;"
5960             "in    float  gl_RayTminNV;"
5961             "in    float  gl_RayTminEXT;"
5962             "in    float  gl_RayTmaxNV;"
5963             "in    float  gl_RayTmaxEXT;"
5964             "in    float  gl_HitTNV;"
5965             "in    float  gl_HitTEXT;"
5966             "in    uint   gl_HitKindNV;"
5967             "in    uint   gl_HitKindEXT;"
5968             "in    mat4x3 gl_ObjectToWorldNV;"
5969             "in    mat4x3 gl_ObjectToWorldEXT;"
5970             "in    mat3x4 gl_ObjectToWorld3x4EXT;"
5971             "in    mat4x3 gl_WorldToObjectNV;"
5972             "in    mat4x3 gl_WorldToObjectEXT;"
5973             "in    mat3x4 gl_WorldToObject3x4EXT;"
5974             "in    uint   gl_IncomingRayFlagsNV;"
5975             "in    uint   gl_IncomingRayFlagsEXT;"
5976             "in    float  gl_CurrentRayTimeNV;"
5977             "\n";
5978         const char *missDecls =
5979             "in    uvec3  gl_LaunchIDNV;"
5980             "in    uvec3  gl_LaunchIDEXT;"
5981             "in    uvec3  gl_LaunchSizeNV;"
5982             "in    uvec3  gl_LaunchSizeEXT;"
5983             "in    vec3   gl_WorldRayOriginNV;"
5984             "in    vec3   gl_WorldRayOriginEXT;"
5985             "in    vec3   gl_WorldRayDirectionNV;"
5986             "in    vec3   gl_WorldRayDirectionEXT;"
5987             "in    vec3   gl_ObjectRayOriginNV;"
5988             "in    vec3   gl_ObjectRayDirectionNV;"
5989             "in    float  gl_RayTminNV;"
5990             "in    float  gl_RayTminEXT;"
5991             "in    float  gl_RayTmaxNV;"
5992             "in    float  gl_RayTmaxEXT;"
5993             "in    uint   gl_IncomingRayFlagsNV;"
5994             "in    uint   gl_IncomingRayFlagsEXT;"
5995             "in    float  gl_CurrentRayTimeNV;"
5996             "\n";
5997
5998         const char *callableDecls =
5999             "in    uvec3  gl_LaunchIDNV;"
6000             "in    uvec3  gl_LaunchIDEXT;"
6001             "in    uvec3  gl_LaunchSizeNV;"
6002             "in    uvec3  gl_LaunchSizeEXT;"
6003             "\n";
6004
6005
6006         commonBuiltins.append(constRayQueryIntersection);
6007         commonBuiltins.append(constRayFlags);
6008
6009         stageBuiltins[EShLangRayGen].append(rayGenDecls);
6010         stageBuiltins[EShLangIntersect].append(intersectDecls);
6011         stageBuiltins[EShLangAnyHit].append(hitDecls);
6012         stageBuiltins[EShLangClosestHit].append(hitDecls);
6013         stageBuiltins[EShLangMiss].append(missDecls);
6014         stageBuiltins[EShLangCallable].append(callableDecls);
6015
6016     }
6017
6018     if ((profile != EEsProfile && version >= 140)) {
6019         const char *deviceIndex =
6020             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
6021             "\n";
6022
6023         stageBuiltins[EShLangRayGen].append(deviceIndex);
6024         stageBuiltins[EShLangIntersect].append(deviceIndex);
6025         stageBuiltins[EShLangAnyHit].append(deviceIndex);
6026         stageBuiltins[EShLangClosestHit].append(deviceIndex);
6027         stageBuiltins[EShLangMiss].append(deviceIndex);
6028     }
6029
6030     if ((profile != EEsProfile && version >= 420) ||
6031         (profile == EEsProfile && version >= 310)) {
6032         commonBuiltins.append("const int gl_ScopeDevice      = 1;\n");
6033         commonBuiltins.append("const int gl_ScopeWorkgroup   = 2;\n");
6034         commonBuiltins.append("const int gl_ScopeSubgroup    = 3;\n");
6035         commonBuiltins.append("const int gl_ScopeInvocation  = 4;\n");
6036         commonBuiltins.append("const int gl_ScopeQueueFamily = 5;\n");
6037         commonBuiltins.append("const int gl_ScopeShaderCallEXT = 6;\n");
6038
6039         commonBuiltins.append("const int gl_SemanticsRelaxed         = 0x0;\n");
6040         commonBuiltins.append("const int gl_SemanticsAcquire         = 0x2;\n");
6041         commonBuiltins.append("const int gl_SemanticsRelease         = 0x4;\n");
6042         commonBuiltins.append("const int gl_SemanticsAcquireRelease  = 0x8;\n");
6043         commonBuiltins.append("const int gl_SemanticsMakeAvailable   = 0x2000;\n");
6044         commonBuiltins.append("const int gl_SemanticsMakeVisible     = 0x4000;\n");
6045         commonBuiltins.append("const int gl_SemanticsVolatile        = 0x8000;\n");
6046
6047         commonBuiltins.append("const int gl_StorageSemanticsNone     = 0x0;\n");
6048         commonBuiltins.append("const int gl_StorageSemanticsBuffer   = 0x40;\n");
6049         commonBuiltins.append("const int gl_StorageSemanticsShared   = 0x100;\n");
6050         commonBuiltins.append("const int gl_StorageSemanticsImage    = 0x800;\n");
6051         commonBuiltins.append("const int gl_StorageSemanticsOutput   = 0x1000;\n");
6052     }
6053
6054     // Adding these to common built-ins triggers an assert due to a memory corruption in related code when testing
6055     // So instead add to each stage individually, avoiding the GLSLang bug
6056     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
6057         for (int stage=EShLangVertex; stage<EShLangCount; stage++)
6058         {
6059             stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag2VerticalPixelsEXT       = 1;\n");
6060             stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag4VerticalPixelsEXT       = 2;\n");
6061             stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag2HorizontalPixelsEXT     = 4;\n");
6062             stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag4HorizontalPixelsEXT     = 8;\n");
6063         }
6064     }
6065     
6066     // GL_EXT_shader_image_int64
6067     if ((profile != EEsProfile && version >= 420) ||
6068         (profile == EEsProfile && version >= 310)) {
6069             
6070         const TBasicType bTypes[] = { EbtInt64, EbtUint64 };
6071         for (int ms = 0; ms <= 1; ++ms) { // loop over "bool" multisample or not
6072             for (int arrayed = 0; arrayed <= 1; ++arrayed) { // loop over "bool" arrayed or not
6073                 for (int dim = Esd1D; dim < EsdSubpass; ++dim) { // 1D, ..., buffer
6074                     if ((dim == Esd1D || dim == EsdRect) && profile == EEsProfile)
6075                         continue;
6076                     
6077                     if ((dim == Esd3D || dim == EsdRect || dim == EsdBuffer) && arrayed)
6078                         continue;
6079                     
6080                     if (dim != Esd2D && ms)
6081                         continue;
6082                     
6083                     // Loop over the bTypes
6084                     for (size_t bType = 0; bType < sizeof(bTypes)/sizeof(TBasicType); ++bType) {
6085                         //
6086                         // Now, make all the function prototypes for the type we just built...
6087                         //
6088                         TSampler sampler;
6089                     
6090                         sampler.setImage(bTypes[bType], (TSamplerDim)dim, arrayed ? true : false,
6091                                                                           false,
6092                                                                           ms      ? true : false);
6093
6094                         TString typeName = sampler.getString();
6095
6096                         addQueryFunctions(sampler, typeName, version, profile);
6097                         addImageFunctions(sampler, typeName, version, profile);
6098                     }
6099                 }
6100             }
6101         }
6102     }
6103 #endif // !GLSLANG_ANGLE
6104     
6105 #endif // !GLSLANG_WEB
6106
6107     // printf("%s\n", commonBuiltins.c_str());
6108     // printf("%s\n", stageBuiltins[EShLangFragment].c_str());
6109 }
6110
6111 //
6112 // Helper function for initialize(), to add the second set of names for texturing,
6113 // when adding context-independent built-in functions.
6114 //
6115 void TBuiltIns::add2ndGenerationSamplingImaging(int version, EProfile profile, const SpvVersion& spvVersion)
6116 {
6117     //
6118     // In this function proper, enumerate the types, then calls the next set of functions
6119     // to enumerate all the uses for that type.
6120     //
6121
6122     // enumerate all the types
6123     const TBasicType bTypes[] = { EbtFloat, EbtInt, EbtUint,
6124 #if !defined(GLSLANG_WEB) && !defined(GLSLANG_ANGLE)
6125         EbtFloat16
6126 #endif
6127     };
6128 #ifdef GLSLANG_WEB
6129     bool skipBuffer = true;
6130     bool skipCubeArrayed = true;
6131     const int image = 0;
6132 #else
6133     bool skipBuffer = (profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 140);
6134     bool skipCubeArrayed = (profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 130);
6135     for (int image = 0; image <= 1; ++image) // loop over "bool" image vs sampler
6136 #endif
6137     {
6138         for (int shadow = 0; shadow <= 1; ++shadow) { // loop over "bool" shadow or not
6139 #ifdef GLSLANG_WEB
6140             const int ms = 0;
6141 #else
6142             for (int ms = 0; ms <= 1; ++ms) // loop over "bool" multisample or not
6143 #endif
6144             {
6145                 if ((ms || image) && shadow)
6146                     continue;
6147                 if (ms && profile != EEsProfile && version < 150)
6148                     continue;
6149                 if (ms && image && profile == EEsProfile)
6150                     continue;
6151                 if (ms && profile == EEsProfile && version < 310)
6152                     continue;
6153
6154                 for (int arrayed = 0; arrayed <= 1; ++arrayed) { // loop over "bool" arrayed or not
6155 #ifdef GLSLANG_WEB
6156                     for (int dim = Esd2D; dim <= EsdCube; ++dim) { // 2D, 3D, and Cube
6157 #else
6158 #if defined(GLSLANG_ANGLE)
6159                     for (int dim = Esd2D; dim < EsdNumDims; ++dim) { // 2D, ..., buffer, subpass
6160 #else
6161                     for (int dim = Esd1D; dim < EsdNumDims; ++dim) { // 1D, ..., buffer, subpass
6162 #endif
6163                         if (dim == EsdSubpass && spvVersion.vulkan == 0)
6164                             continue;
6165                         if (dim == EsdSubpass && (image || shadow || arrayed))
6166                             continue;
6167                         if ((dim == Esd1D || dim == EsdRect) && profile == EEsProfile)
6168                             continue;
6169                         if (dim == EsdSubpass && spvVersion.vulkan == 0)
6170                             continue;
6171                         if (dim == EsdSubpass && (image || shadow || arrayed))
6172                             continue;
6173                         if ((dim == Esd1D || dim == EsdRect) && profile == EEsProfile)
6174                             continue;
6175                         if (dim != Esd2D && dim != EsdSubpass && ms)
6176                             continue;
6177                         if (dim == EsdBuffer && skipBuffer)
6178                             continue;
6179                         if (dim == EsdBuffer && (shadow || arrayed || ms))
6180                             continue;
6181                         if (ms && arrayed && profile == EEsProfile && version < 310)
6182                             continue;
6183 #endif
6184                         if (dim == Esd3D && shadow)
6185                             continue;
6186                         if (dim == EsdCube && arrayed && skipCubeArrayed)
6187                             continue;
6188                         if ((dim == Esd3D || dim == EsdRect) && arrayed)
6189                             continue;
6190
6191                         // Loop over the bTypes
6192                         for (size_t bType = 0; bType < sizeof(bTypes)/sizeof(TBasicType); ++bType) {
6193 #ifndef GLSLANG_WEB
6194                             if (bTypes[bType] == EbtFloat16 && (profile == EEsProfile || version < 450))
6195                                 continue;
6196                             if (dim == EsdRect && version < 140 && bType > 0)
6197                                 continue;
6198 #endif
6199                             if (shadow && (bTypes[bType] == EbtInt || bTypes[bType] == EbtUint))
6200                                 continue;
6201                             //
6202                             // Now, make all the function prototypes for the type we just built...
6203                             //
6204                             TSampler sampler;
6205 #ifndef GLSLANG_WEB
6206                             if (dim == EsdSubpass) {
6207                                 sampler.setSubpass(bTypes[bType], ms ? true : false);
6208                             } else
6209 #endif
6210                             if (image) {
6211                                 sampler.setImage(bTypes[bType], (TSamplerDim)dim, arrayed ? true : false,
6212                                                                                   shadow  ? true : false,
6213                                                                                   ms      ? true : false);
6214                             } else {
6215                                 sampler.set(bTypes[bType], (TSamplerDim)dim, arrayed ? true : false,
6216                                                                              shadow  ? true : false,
6217                                                                              ms      ? true : false);
6218                             }
6219
6220                             TString typeName = sampler.getString();
6221
6222 #ifndef GLSLANG_WEB
6223                             if (dim == EsdSubpass) {
6224                                 addSubpassSampling(sampler, typeName, version, profile);
6225                                 continue;
6226                             }
6227 #endif
6228
6229                             addQueryFunctions(sampler, typeName, version, profile);
6230
6231                             if (image)
6232                                 addImageFunctions(sampler, typeName, version, profile);
6233                             else {
6234                                 addSamplingFunctions(sampler, typeName, version, profile);
6235 #ifndef GLSLANG_WEB
6236                                 addGatherFunctions(sampler, typeName, version, profile);
6237                                 if (spvVersion.vulkan > 0 && sampler.isCombined() && !sampler.shadow) {
6238                                     // Base Vulkan allows texelFetch() for
6239                                     // textureBuffer (i.e. without sampler).
6240                                     //
6241                                     // GL_EXT_samplerless_texture_functions
6242                                     // allows texelFetch() and query functions
6243                                     // (other than textureQueryLod()) for all
6244                                     // texture types.
6245                                     sampler.setTexture(sampler.type, sampler.dim, sampler.arrayed, sampler.shadow,
6246                                                        sampler.ms);
6247                                     TString textureTypeName = sampler.getString();
6248                                     addSamplingFunctions(sampler, textureTypeName, version, profile);
6249                                     addQueryFunctions(sampler, textureTypeName, version, profile);
6250                                 }
6251 #endif
6252                             }
6253                         }
6254                     }
6255                 }
6256             }
6257         }
6258     }
6259
6260     //
6261     // sparseTexelsResidentARB()
6262     //
6263     if (profile != EEsProfile && version >= 450) {
6264         commonBuiltins.append("bool sparseTexelsResidentARB(int code);\n");
6265     }
6266 }
6267
6268 //
6269 // Helper function for add2ndGenerationSamplingImaging(),
6270 // when adding context-independent built-in functions.
6271 //
6272 // Add all the query functions for the given type.
6273 //
6274 void TBuiltIns::addQueryFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
6275 {
6276     //
6277     // textureSize() and imageSize()
6278     //
6279
6280     int sizeDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0) - (sampler.dim == EsdCube ? 1 : 0);
6281
6282 #ifdef GLSLANG_WEB
6283     commonBuiltins.append("highp ");
6284     commonBuiltins.append("ivec");
6285     commonBuiltins.append(postfixes[sizeDims]);
6286     commonBuiltins.append(" textureSize(");
6287     commonBuiltins.append(typeName);
6288     commonBuiltins.append(",int);\n");
6289     return;
6290 #endif
6291
6292     if (sampler.isImage() && ((profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 420)))
6293         return;
6294
6295     if (profile == EEsProfile)
6296         commonBuiltins.append("highp ");
6297     if (sizeDims == 1)
6298         commonBuiltins.append("int");
6299     else {
6300         commonBuiltins.append("ivec");
6301         commonBuiltins.append(postfixes[sizeDims]);
6302     }
6303     if (sampler.isImage())
6304         commonBuiltins.append(" imageSize(readonly writeonly volatile coherent ");
6305     else
6306         commonBuiltins.append(" textureSize(");
6307     commonBuiltins.append(typeName);
6308     if (! sampler.isImage() && ! sampler.isRect() && ! sampler.isBuffer() && ! sampler.isMultiSample())
6309         commonBuiltins.append(",int);\n");
6310     else
6311         commonBuiltins.append(");\n");
6312
6313     //
6314     // textureSamples() and imageSamples()
6315     //
6316
6317     // GL_ARB_shader_texture_image_samples
6318     // TODO: spec issue? there are no memory qualifiers; how to query a writeonly/readonly image, etc?
6319     if (profile != EEsProfile && version >= 430 && sampler.isMultiSample()) {
6320         commonBuiltins.append("int ");
6321         if (sampler.isImage())
6322             commonBuiltins.append("imageSamples(readonly writeonly volatile coherent ");
6323         else
6324             commonBuiltins.append("textureSamples(");
6325         commonBuiltins.append(typeName);
6326         commonBuiltins.append(");\n");
6327     }
6328
6329     //
6330     // textureQueryLod(), fragment stage only
6331     // Also enabled with extension GL_ARB_texture_query_lod
6332
6333     if (profile != EEsProfile && version >= 150 && sampler.isCombined() && sampler.dim != EsdRect &&
6334         ! sampler.isMultiSample() && ! sampler.isBuffer()) {
6335         for (int f16TexAddr = 0; f16TexAddr < 2; ++f16TexAddr) {
6336             if (f16TexAddr && sampler.type != EbtFloat16)
6337                 continue;
6338             stageBuiltins[EShLangFragment].append("vec2 textureQueryLod(");
6339             stageBuiltins[EShLangFragment].append(typeName);
6340             if (dimMap[sampler.dim] == 1)
6341                 if (f16TexAddr)
6342                     stageBuiltins[EShLangFragment].append(", float16_t");
6343                 else
6344                     stageBuiltins[EShLangFragment].append(", float");
6345             else {
6346                 if (f16TexAddr)
6347                     stageBuiltins[EShLangFragment].append(", f16vec");
6348                 else
6349                     stageBuiltins[EShLangFragment].append(", vec");
6350                 stageBuiltins[EShLangFragment].append(postfixes[dimMap[sampler.dim]]);
6351             }
6352             stageBuiltins[EShLangFragment].append(");\n");
6353         }
6354
6355         stageBuiltins[EShLangCompute].append("vec2 textureQueryLod(");
6356         stageBuiltins[EShLangCompute].append(typeName);
6357         if (dimMap[sampler.dim] == 1)
6358             stageBuiltins[EShLangCompute].append(", float");
6359         else {
6360             stageBuiltins[EShLangCompute].append(", vec");
6361             stageBuiltins[EShLangCompute].append(postfixes[dimMap[sampler.dim]]);
6362         }
6363         stageBuiltins[EShLangCompute].append(");\n");
6364     }
6365
6366     //
6367     // textureQueryLevels()
6368     //
6369
6370     if (profile != EEsProfile && version >= 430 && ! sampler.isImage() && sampler.dim != EsdRect &&
6371         ! sampler.isMultiSample() && ! sampler.isBuffer()) {
6372         commonBuiltins.append("int textureQueryLevels(");
6373         commonBuiltins.append(typeName);
6374         commonBuiltins.append(");\n");
6375     }
6376 }
6377
6378 //
6379 // Helper function for add2ndGenerationSamplingImaging(),
6380 // when adding context-independent built-in functions.
6381 //
6382 // Add all the image access functions for the given type.
6383 //
6384 void TBuiltIns::addImageFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
6385 {
6386     int dims = dimMap[sampler.dim];
6387     // most things with an array add a dimension, except for cubemaps
6388     if (sampler.arrayed && sampler.dim != EsdCube)
6389         ++dims;
6390
6391     TString imageParams = typeName;
6392     if (dims == 1)
6393         imageParams.append(", int");
6394     else {
6395         imageParams.append(", ivec");
6396         imageParams.append(postfixes[dims]);
6397     }
6398     if (sampler.isMultiSample())
6399         imageParams.append(", int");
6400
6401     if (profile == EEsProfile)
6402         commonBuiltins.append("highp ");
6403     commonBuiltins.append(prefixes[sampler.type]);
6404     commonBuiltins.append("vec4 imageLoad(readonly volatile coherent ");
6405     commonBuiltins.append(imageParams);
6406     commonBuiltins.append(");\n");
6407
6408     commonBuiltins.append("void imageStore(writeonly volatile coherent ");
6409     commonBuiltins.append(imageParams);
6410     commonBuiltins.append(", ");
6411     commonBuiltins.append(prefixes[sampler.type]);
6412     commonBuiltins.append("vec4);\n");
6413
6414     if (! sampler.is1D() && ! sampler.isBuffer() && profile != EEsProfile && version >= 450) {
6415         commonBuiltins.append("int sparseImageLoadARB(readonly volatile coherent ");
6416         commonBuiltins.append(imageParams);
6417         commonBuiltins.append(", out ");
6418         commonBuiltins.append(prefixes[sampler.type]);
6419         commonBuiltins.append("vec4");
6420         commonBuiltins.append(");\n");
6421     }
6422
6423     if ( profile != EEsProfile ||
6424         (profile == EEsProfile && version >= 310)) {
6425         if (sampler.type == EbtInt || sampler.type == EbtUint || sampler.type == EbtInt64 || sampler.type == EbtUint64 ) {
6426             
6427             const char* dataType;
6428             switch (sampler.type) {
6429                 case(EbtInt): dataType = "highp int"; break;
6430                 case(EbtUint): dataType = "highp uint"; break;
6431                 case(EbtInt64): dataType = "highp int64_t"; break;
6432                 case(EbtUint64): dataType = "highp uint64_t"; break;
6433                 default: dataType = "";
6434             }
6435
6436             const int numBuiltins = 7;
6437
6438             static const char* atomicFunc[numBuiltins] = {
6439                 " imageAtomicAdd(volatile coherent ",
6440                 " imageAtomicMin(volatile coherent ",
6441                 " imageAtomicMax(volatile coherent ",
6442                 " imageAtomicAnd(volatile coherent ",
6443                 " imageAtomicOr(volatile coherent ",
6444                 " imageAtomicXor(volatile coherent ",
6445                 " imageAtomicExchange(volatile coherent "
6446             };
6447
6448             // Loop twice to add prototypes with/without scope/semantics
6449             for (int j = 0; j < 2; ++j) {
6450                 for (size_t i = 0; i < numBuiltins; ++i) {
6451                     commonBuiltins.append(dataType);
6452                     commonBuiltins.append(atomicFunc[i]);
6453                     commonBuiltins.append(imageParams);
6454                     commonBuiltins.append(", ");
6455                     commonBuiltins.append(dataType);
6456                     if (j == 1) {
6457                         commonBuiltins.append(", int, int, int");
6458                     }
6459                     commonBuiltins.append(");\n");
6460                 }
6461
6462                 commonBuiltins.append(dataType);
6463                 commonBuiltins.append(" imageAtomicCompSwap(volatile coherent ");
6464                 commonBuiltins.append(imageParams);
6465                 commonBuiltins.append(", ");
6466                 commonBuiltins.append(dataType);
6467                 commonBuiltins.append(", ");
6468                 commonBuiltins.append(dataType);
6469                 if (j == 1) {
6470                     commonBuiltins.append(", int, int, int, int, int");
6471                 }
6472                 commonBuiltins.append(");\n");
6473             }
6474
6475             commonBuiltins.append(dataType);
6476             commonBuiltins.append(" imageAtomicLoad(volatile coherent ");
6477             commonBuiltins.append(imageParams);
6478             commonBuiltins.append(", int, int, int);\n");
6479
6480             commonBuiltins.append("void imageAtomicStore(volatile coherent ");
6481             commonBuiltins.append(imageParams);
6482             commonBuiltins.append(", ");
6483             commonBuiltins.append(dataType);
6484             commonBuiltins.append(", int, int, int);\n");
6485
6486         } else {
6487             // not int or uint
6488             // GL_ARB_ES3_1_compatibility
6489             // TODO: spec issue: are there restrictions on the kind of layout() that can be used?  what about dropping memory qualifiers?
6490             if (profile == EEsProfile && version >= 310) {
6491                 commonBuiltins.append("float imageAtomicExchange(volatile coherent ");
6492                 commonBuiltins.append(imageParams);
6493                 commonBuiltins.append(", float);\n");
6494             }
6495             if (profile != EEsProfile && version >= 450) {
6496                 commonBuiltins.append("float imageAtomicAdd(volatile coherent ");
6497                 commonBuiltins.append(imageParams);
6498                 commonBuiltins.append(", float);\n");
6499
6500                 commonBuiltins.append("float imageAtomicAdd(volatile coherent ");
6501                 commonBuiltins.append(imageParams);
6502                 commonBuiltins.append(", float");
6503                 commonBuiltins.append(", int, int, int);\n");
6504
6505                 commonBuiltins.append("float imageAtomicExchange(volatile coherent ");
6506                 commonBuiltins.append(imageParams);
6507                 commonBuiltins.append(", float);\n");
6508
6509                 commonBuiltins.append("float imageAtomicExchange(volatile coherent ");
6510                 commonBuiltins.append(imageParams);
6511                 commonBuiltins.append(", float");
6512                 commonBuiltins.append(", int, int, int);\n");
6513
6514                 commonBuiltins.append("float imageAtomicLoad(readonly volatile coherent ");
6515                 commonBuiltins.append(imageParams);
6516                 commonBuiltins.append(", int, int, int);\n");
6517
6518                 commonBuiltins.append("void imageAtomicStore(writeonly volatile coherent ");
6519                 commonBuiltins.append(imageParams);
6520                 commonBuiltins.append(", float");
6521                 commonBuiltins.append(", int, int, int);\n");
6522
6523                 commonBuiltins.append("float imageAtomicMin(volatile coherent ");
6524                 commonBuiltins.append(imageParams);
6525                 commonBuiltins.append(", float);\n");
6526
6527                 commonBuiltins.append("float imageAtomicMin(volatile coherent ");
6528                 commonBuiltins.append(imageParams);
6529                 commonBuiltins.append(", float");
6530                 commonBuiltins.append(", int, int, int);\n");
6531
6532                 commonBuiltins.append("float imageAtomicMax(volatile coherent ");
6533                 commonBuiltins.append(imageParams);
6534                 commonBuiltins.append(", float);\n");
6535
6536                 commonBuiltins.append("float imageAtomicMax(volatile coherent ");
6537                 commonBuiltins.append(imageParams);
6538                 commonBuiltins.append(", float");
6539                 commonBuiltins.append(", int, int, int);\n");
6540             }
6541         }
6542     }
6543
6544     if (sampler.dim == EsdRect || sampler.dim == EsdBuffer || sampler.shadow || sampler.isMultiSample())
6545         return;
6546
6547     if (profile == EEsProfile || version < 450)
6548         return;
6549
6550     TString imageLodParams = typeName;
6551     if (dims == 1)
6552         imageLodParams.append(", int");
6553     else {
6554         imageLodParams.append(", ivec");
6555         imageLodParams.append(postfixes[dims]);
6556     }
6557     imageLodParams.append(", int");
6558
6559     commonBuiltins.append(prefixes[sampler.type]);
6560     commonBuiltins.append("vec4 imageLoadLodAMD(readonly volatile coherent ");
6561     commonBuiltins.append(imageLodParams);
6562     commonBuiltins.append(");\n");
6563
6564     commonBuiltins.append("void imageStoreLodAMD(writeonly volatile coherent ");
6565     commonBuiltins.append(imageLodParams);
6566     commonBuiltins.append(", ");
6567     commonBuiltins.append(prefixes[sampler.type]);
6568     commonBuiltins.append("vec4);\n");
6569
6570     if (! sampler.is1D()) {
6571         commonBuiltins.append("int sparseImageLoadLodAMD(readonly volatile coherent ");
6572         commonBuiltins.append(imageLodParams);
6573         commonBuiltins.append(", out ");
6574         commonBuiltins.append(prefixes[sampler.type]);
6575         commonBuiltins.append("vec4");
6576         commonBuiltins.append(");\n");
6577     }
6578 }
6579
6580 //
6581 // Helper function for initialize(),
6582 // when adding context-independent built-in functions.
6583 //
6584 // Add all the subpass access functions for the given type.
6585 //
6586 void TBuiltIns::addSubpassSampling(TSampler sampler, const TString& typeName, int /*version*/, EProfile /*profile*/)
6587 {
6588     stageBuiltins[EShLangFragment].append(prefixes[sampler.type]);
6589     stageBuiltins[EShLangFragment].append("vec4 subpassLoad");
6590     stageBuiltins[EShLangFragment].append("(");
6591     stageBuiltins[EShLangFragment].append(typeName.c_str());
6592     if (sampler.isMultiSample())
6593         stageBuiltins[EShLangFragment].append(", int");
6594     stageBuiltins[EShLangFragment].append(");\n");
6595 }
6596
6597 //
6598 // Helper function for add2ndGenerationSamplingImaging(),
6599 // when adding context-independent built-in functions.
6600 //
6601 // Add all the texture lookup functions for the given type.
6602 //
6603 void TBuiltIns::addSamplingFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
6604 {
6605 #ifdef GLSLANG_WEB
6606     profile = EEsProfile;
6607     version = 310;
6608 #elif defined(GLSLANG_ANGLE)
6609     profile = ECoreProfile;
6610     version = 450;
6611 #endif
6612
6613     //
6614     // texturing
6615     //
6616     for (int proj = 0; proj <= 1; ++proj) { // loop over "bool" projective or not
6617
6618         if (proj && (sampler.dim == EsdCube || sampler.isBuffer() || sampler.arrayed || sampler.isMultiSample()
6619             || !sampler.isCombined()))
6620             continue;
6621
6622         for (int lod = 0; lod <= 1; ++lod) {
6623
6624             if (lod && (sampler.isBuffer() || sampler.isRect() || sampler.isMultiSample() || !sampler.isCombined()))
6625                 continue;
6626             if (lod && sampler.dim == Esd2D && sampler.arrayed && sampler.shadow)
6627                 continue;
6628             if (lod && sampler.dim == EsdCube && sampler.shadow)
6629                 continue;
6630
6631             for (int bias = 0; bias <= 1; ++bias) {
6632
6633                 if (bias && (lod || sampler.isMultiSample() || !sampler.isCombined()))
6634                     continue;
6635                 if (bias && (sampler.dim == Esd2D || sampler.dim == EsdCube) && sampler.shadow && sampler.arrayed)
6636                     continue;
6637                 if (bias && (sampler.isRect() || sampler.isBuffer()))
6638                     continue;
6639
6640                 for (int offset = 0; offset <= 1; ++offset) { // loop over "bool" offset or not
6641
6642                     if (proj + offset + bias + lod > 3)
6643                         continue;
6644                     if (offset && (sampler.dim == EsdCube || sampler.isBuffer() || sampler.isMultiSample()))
6645                         continue;
6646
6647                     for (int fetch = 0; fetch <= 1; ++fetch) { // loop over "bool" fetch or not
6648
6649                         if (proj + offset + fetch + bias + lod > 3)
6650                             continue;
6651                         if (fetch && (lod || bias))
6652                             continue;
6653                         if (fetch && (sampler.shadow || sampler.dim == EsdCube))
6654                             continue;
6655                         if (fetch == 0 && (sampler.isMultiSample() || sampler.isBuffer()
6656                             || !sampler.isCombined()))
6657                             continue;
6658
6659                         for (int grad = 0; grad <= 1; ++grad) { // loop over "bool" grad or not
6660
6661                             if (grad && (lod || bias || sampler.isMultiSample() || !sampler.isCombined()))
6662                                 continue;
6663                             if (grad && sampler.isBuffer())
6664                                 continue;
6665                             if (proj + offset + fetch + grad + bias + lod > 3)
6666                                 continue;
6667
6668                             for (int extraProj = 0; extraProj <= 1; ++extraProj) {
6669                                 bool compare = false;
6670                                 int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0);
6671                                 // skip dummy unused second component for 1D non-array shadows
6672                                 if (sampler.shadow && totalDims < 2)
6673                                     totalDims = 2;
6674                                 totalDims += (sampler.shadow ? 1 : 0) + proj;
6675                                 if (totalDims > 4 && sampler.shadow) {
6676                                     compare = true;
6677                                     totalDims = 4;
6678                                 }
6679                                 assert(totalDims <= 4);
6680
6681                                 if (extraProj && ! proj)
6682                                     continue;
6683                                 if (extraProj && (sampler.dim == Esd3D || sampler.shadow || !sampler.isCombined()))
6684                                     continue;
6685
6686                                 // loop over 16-bit floating-point texel addressing
6687 #if defined(GLSLANG_WEB) || defined(GLSLANG_ANGLE)
6688                                 const int f16TexAddr = 0;
6689 #else
6690                                 for (int f16TexAddr = 0; f16TexAddr <= 1; ++f16TexAddr)
6691 #endif
6692                                 {
6693                                     if (f16TexAddr && sampler.type != EbtFloat16)
6694                                         continue;
6695                                     if (f16TexAddr && sampler.shadow && ! compare) {
6696                                         compare = true; // compare argument is always present
6697                                         totalDims--;
6698                                     }
6699                                     // loop over "bool" lod clamp
6700 #if defined(GLSLANG_WEB) || defined(GLSLANG_ANGLE)
6701                                     const int lodClamp = 0;
6702 #else
6703                                     for (int lodClamp = 0; lodClamp <= 1 ;++lodClamp)
6704 #endif
6705                                     {
6706                                         if (lodClamp && (profile == EEsProfile || version < 450))
6707                                             continue;
6708                                         if (lodClamp && (proj || lod || fetch))
6709                                             continue;
6710
6711                                         // loop over "bool" sparse or not
6712 #if defined(GLSLANG_WEB) || defined(GLSLANG_ANGLE)
6713                                         const int sparse = 0;
6714 #else
6715                                         for (int sparse = 0; sparse <= 1; ++sparse)
6716 #endif
6717                                         {
6718                                             if (sparse && (profile == EEsProfile || version < 450))
6719                                                 continue;
6720                                             // Sparse sampling is not for 1D/1D array texture, buffer texture, and
6721                                             // projective texture
6722                                             if (sparse && (sampler.is1D() || sampler.isBuffer() || proj))
6723                                                 continue;
6724
6725                                             TString s;
6726
6727                                             // return type
6728                                             if (sparse)
6729                                                 s.append("int ");
6730                                             else {
6731                                                 if (sampler.shadow)
6732                                                     if (sampler.type == EbtFloat16)
6733                                                         s.append("float16_t ");
6734                                                     else
6735                                                         s.append("float ");
6736                                                 else {
6737                                                     s.append(prefixes[sampler.type]);
6738                                                     s.append("vec4 ");
6739                                                 }
6740                                             }
6741
6742                                             // name
6743                                             if (sparse) {
6744                                                 if (fetch)
6745                                                     s.append("sparseTexel");
6746                                                 else
6747                                                     s.append("sparseTexture");
6748                                             }
6749                                             else {
6750                                                 if (fetch)
6751                                                     s.append("texel");
6752                                                 else
6753                                                     s.append("texture");
6754                                             }
6755                                             if (proj)
6756                                                 s.append("Proj");
6757                                             if (lod)
6758                                                 s.append("Lod");
6759                                             if (grad)
6760                                                 s.append("Grad");
6761                                             if (fetch)
6762                                                 s.append("Fetch");
6763                                             if (offset)
6764                                                 s.append("Offset");
6765                                             if (lodClamp)
6766                                                 s.append("Clamp");
6767                                             if (lodClamp != 0 || sparse)
6768                                                 s.append("ARB");
6769                                             s.append("(");
6770
6771                                             // sampler type
6772                                             s.append(typeName);
6773                                             // P coordinate
6774                                             if (extraProj) {
6775                                                 if (f16TexAddr)
6776                                                     s.append(",f16vec4");
6777                                                 else
6778                                                     s.append(",vec4");
6779                                             } else {
6780                                                 s.append(",");
6781                                                 TBasicType t = fetch ? EbtInt : (f16TexAddr ? EbtFloat16 : EbtFloat);
6782                                                 if (totalDims == 1)
6783                                                     s.append(TType::getBasicString(t));
6784                                                 else {
6785                                                     s.append(prefixes[t]);
6786                                                     s.append("vec");
6787                                                     s.append(postfixes[totalDims]);
6788                                                 }
6789                                             }
6790                                             // non-optional compare
6791                                             if (compare)
6792                                                 s.append(",float");
6793
6794                                             // non-optional lod argument (lod that's not driven by lod loop) or sample
6795                                             if ((fetch && !sampler.isBuffer() &&
6796                                                  !sampler.isRect() && !sampler.isMultiSample())
6797                                                  || (sampler.isMultiSample() && fetch))
6798                                                 s.append(",int");
6799                                             // non-optional lod
6800                                             if (lod) {
6801                                                 if (f16TexAddr)
6802                                                     s.append(",float16_t");
6803                                                 else
6804                                                     s.append(",float");
6805                                             }
6806
6807                                             // gradient arguments
6808                                             if (grad) {
6809                                                 if (dimMap[sampler.dim] == 1) {
6810                                                     if (f16TexAddr)
6811                                                         s.append(",float16_t,float16_t");
6812                                                     else
6813                                                         s.append(",float,float");
6814                                                 } else {
6815                                                     if (f16TexAddr)
6816                                                         s.append(",f16vec");
6817                                                     else
6818                                                         s.append(",vec");
6819                                                     s.append(postfixes[dimMap[sampler.dim]]);
6820                                                     if (f16TexAddr)
6821                                                         s.append(",f16vec");
6822                                                     else
6823                                                         s.append(",vec");
6824                                                     s.append(postfixes[dimMap[sampler.dim]]);
6825                                                 }
6826                                             }
6827                                             // offset
6828                                             if (offset) {
6829                                                 if (dimMap[sampler.dim] == 1)
6830                                                     s.append(",int");
6831                                                 else {
6832                                                     s.append(",ivec");
6833                                                     s.append(postfixes[dimMap[sampler.dim]]);
6834                                                 }
6835                                             }
6836
6837                                             // lod clamp
6838                                             if (lodClamp) {
6839                                                 if (f16TexAddr)
6840                                                     s.append(",float16_t");
6841                                                 else
6842                                                     s.append(",float");
6843                                             }
6844                                             // texel out (for sparse texture)
6845                                             if (sparse) {
6846                                                 s.append(",out ");
6847                                                 if (sampler.shadow)
6848                                                     if (sampler.type == EbtFloat16)
6849                                                         s.append("float16_t");
6850                                                     else
6851                                                         s.append("float");
6852                                                 else {
6853                                                     s.append(prefixes[sampler.type]);
6854                                                     s.append("vec4");
6855                                                 }
6856                                             }
6857                                             // optional bias
6858                                             if (bias) {
6859                                                 if (f16TexAddr)
6860                                                     s.append(",float16_t");
6861                                                 else
6862                                                     s.append(",float");
6863                                             }
6864                                             s.append(");\n");
6865
6866                                             // Add to the per-language set of built-ins
6867                                             if (!grad && (bias || lodClamp != 0)) {
6868                                                 stageBuiltins[EShLangFragment].append(s);
6869                                                 stageBuiltins[EShLangCompute].append(s);
6870                                             } else
6871                                                 commonBuiltins.append(s);
6872
6873                                         }
6874                                     }
6875                                 }
6876                             }
6877                         }
6878                     }
6879                 }
6880             }
6881         }
6882     }
6883 }
6884
6885 //
6886 // Helper function for add2ndGenerationSamplingImaging(),
6887 // when adding context-independent built-in functions.
6888 //
6889 // Add all the texture gather functions for the given type.
6890 //
6891 void TBuiltIns::addGatherFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
6892 {
6893 #ifdef GLSLANG_WEB
6894     profile = EEsProfile;
6895     version = 310;
6896 #elif defined(GLSLANG_ANGLE)
6897     profile = ECoreProfile;
6898     version = 450;
6899 #endif
6900
6901     switch (sampler.dim) {
6902     case Esd2D:
6903     case EsdRect:
6904     case EsdCube:
6905         break;
6906     default:
6907         return;
6908     }
6909
6910     if (sampler.isMultiSample())
6911         return;
6912
6913     if (version < 140 && sampler.dim == EsdRect && sampler.type != EbtFloat)
6914         return;
6915
6916     for (int f16TexAddr = 0; f16TexAddr <= 1; ++f16TexAddr) { // loop over 16-bit floating-point texel addressing
6917
6918         if (f16TexAddr && sampler.type != EbtFloat16)
6919             continue;
6920         for (int offset = 0; offset < 3; ++offset) { // loop over three forms of offset in the call name:  none, Offset, and Offsets
6921
6922             for (int comp = 0; comp < 2; ++comp) { // loop over presence of comp argument
6923
6924                 if (comp > 0 && sampler.shadow)
6925                     continue;
6926
6927                 if (offset > 0 && sampler.dim == EsdCube)
6928                     continue;
6929
6930                 for (int sparse = 0; sparse <= 1; ++sparse) { // loop over "bool" sparse or not
6931                     if (sparse && (profile == EEsProfile || version < 450))
6932                         continue;
6933
6934                     TString s;
6935
6936                     // return type
6937                     if (sparse)
6938                         s.append("int ");
6939                     else {
6940                         s.append(prefixes[sampler.type]);
6941                         s.append("vec4 ");
6942                     }
6943
6944                     // name
6945                     if (sparse)
6946                         s.append("sparseTextureGather");
6947                     else
6948                         s.append("textureGather");
6949                     switch (offset) {
6950                     case 1:
6951                         s.append("Offset");
6952                         break;
6953                     case 2:
6954                         s.append("Offsets");
6955                         break;
6956                     default:
6957                         break;
6958                     }
6959                     if (sparse)
6960                         s.append("ARB");
6961                     s.append("(");
6962
6963                     // sampler type argument
6964                     s.append(typeName);
6965
6966                     // P coordinate argument
6967                     if (f16TexAddr)
6968                         s.append(",f16vec");
6969                     else
6970                         s.append(",vec");
6971                     int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0);
6972                     s.append(postfixes[totalDims]);
6973
6974                     // refZ argument
6975                     if (sampler.shadow)
6976                         s.append(",float");
6977
6978                     // offset argument
6979                     if (offset > 0) {
6980                         s.append(",ivec2");
6981                         if (offset == 2)
6982                             s.append("[4]");
6983                     }
6984
6985                     // texel out (for sparse texture)
6986                     if (sparse) {
6987                         s.append(",out ");
6988                         s.append(prefixes[sampler.type]);
6989                         s.append("vec4 ");
6990                     }
6991
6992                     // comp argument
6993                     if (comp)
6994                         s.append(",int");
6995
6996                     s.append(");\n");
6997                     commonBuiltins.append(s);
6998                 }
6999             }
7000         }
7001     }
7002
7003     if (sampler.dim == EsdRect || sampler.shadow)
7004         return;
7005
7006     if (profile == EEsProfile || version < 450)
7007         return;
7008
7009     for (int bias = 0; bias < 2; ++bias) { // loop over presence of bias argument
7010
7011         for (int lod = 0; lod < 2; ++lod) { // loop over presence of lod argument
7012
7013             if ((lod && bias) || (lod == 0 && bias == 0))
7014                 continue;
7015
7016             for (int f16TexAddr = 0; f16TexAddr <= 1; ++f16TexAddr) { // loop over 16-bit floating-point texel addressing
7017
7018                 if (f16TexAddr && sampler.type != EbtFloat16)
7019                     continue;
7020
7021                 for (int offset = 0; offset < 3; ++offset) { // loop over three forms of offset in the call name:  none, Offset, and Offsets
7022
7023                     for (int comp = 0; comp < 2; ++comp) { // loop over presence of comp argument
7024
7025                         if (comp == 0 && bias)
7026                             continue;
7027
7028                         if (offset > 0 && sampler.dim == EsdCube)
7029                             continue;
7030
7031                         for (int sparse = 0; sparse <= 1; ++sparse) { // loop over "bool" sparse or not
7032                             if (sparse && (profile == EEsProfile || version < 450))
7033                                 continue;
7034
7035                             TString s;
7036
7037                             // return type
7038                             if (sparse)
7039                                 s.append("int ");
7040                             else {
7041                                 s.append(prefixes[sampler.type]);
7042                                 s.append("vec4 ");
7043                             }
7044
7045                             // name
7046                             if (sparse)
7047                                 s.append("sparseTextureGather");
7048                             else
7049                                 s.append("textureGather");
7050
7051                             if (lod)
7052                                 s.append("Lod");
7053
7054                             switch (offset) {
7055                             case 1:
7056                                 s.append("Offset");
7057                                 break;
7058                             case 2:
7059                                 s.append("Offsets");
7060                                 break;
7061                             default:
7062                                 break;
7063                             }
7064
7065                             if (lod)
7066                                 s.append("AMD");
7067                             else if (sparse)
7068                                 s.append("ARB");
7069
7070                             s.append("(");
7071
7072                             // sampler type argument
7073                             s.append(typeName);
7074
7075                             // P coordinate argument
7076                             if (f16TexAddr)
7077                                 s.append(",f16vec");
7078                             else
7079                                 s.append(",vec");
7080                             int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0);
7081                             s.append(postfixes[totalDims]);
7082
7083                             // lod argument
7084                             if (lod) {
7085                                 if (f16TexAddr)
7086                                     s.append(",float16_t");
7087                                 else
7088                                     s.append(",float");
7089                             }
7090
7091                             // offset argument
7092                             if (offset > 0) {
7093                                 s.append(",ivec2");
7094                                 if (offset == 2)
7095                                     s.append("[4]");
7096                             }
7097
7098                             // texel out (for sparse texture)
7099                             if (sparse) {
7100                                 s.append(",out ");
7101                                 s.append(prefixes[sampler.type]);
7102                                 s.append("vec4 ");
7103                             }
7104
7105                             // comp argument
7106                             if (comp)
7107                                 s.append(",int");
7108
7109                             // bias argument
7110                             if (bias) {
7111                                 if (f16TexAddr)
7112                                     s.append(",float16_t");
7113                                 else
7114                                     s.append(",float");
7115                             }
7116
7117                             s.append(");\n");
7118                             if (bias)
7119                                 stageBuiltins[EShLangFragment].append(s);
7120                             else
7121                                 commonBuiltins.append(s);
7122                         }
7123                     }
7124                 }
7125             }
7126         }
7127     }
7128 }
7129
7130 //
7131 // Add context-dependent built-in functions and variables that are present
7132 // for the given version and profile.  All the results are put into just the
7133 // commonBuiltins, because it is called for just a specific stage.  So,
7134 // add stage-specific entries to the commonBuiltins, and only if that stage
7135 // was requested.
7136 //
7137 void TBuiltIns::initialize(const TBuiltInResource &resources, int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language)
7138 {
7139 #ifdef GLSLANG_WEB
7140     version = 310;
7141     profile = EEsProfile;
7142 #elif defined(GLSLANG_ANGLE)
7143     version = 450;
7144     profile = ECoreProfile;
7145 #endif
7146
7147     //
7148     // Initialize the context-dependent (resource-dependent) built-in strings for parsing.
7149     //
7150
7151     //============================================================================
7152     //
7153     // Standard Uniforms
7154     //
7155     //============================================================================
7156
7157     TString& s = commonBuiltins;
7158     const int maxSize = 200;
7159     char builtInConstant[maxSize];
7160
7161     //
7162     // Build string of implementation dependent constants.
7163     //
7164
7165     if (profile == EEsProfile) {
7166         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVertexAttribs = %d;", resources.maxVertexAttribs);
7167         s.append(builtInConstant);
7168
7169         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVertexUniformVectors = %d;", resources.maxVertexUniformVectors);
7170         s.append(builtInConstant);
7171
7172         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVertexTextureImageUnits = %d;", resources.maxVertexTextureImageUnits);
7173         s.append(builtInConstant);
7174
7175         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxCombinedTextureImageUnits = %d;", resources.maxCombinedTextureImageUnits);
7176         s.append(builtInConstant);
7177
7178         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxTextureImageUnits = %d;", resources.maxTextureImageUnits);
7179         s.append(builtInConstant);
7180
7181         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxFragmentUniformVectors = %d;", resources.maxFragmentUniformVectors);
7182         s.append(builtInConstant);
7183
7184         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxDrawBuffers = %d;", resources.maxDrawBuffers);
7185         s.append(builtInConstant);
7186
7187         if (version == 100) {
7188             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVaryingVectors = %d;", resources.maxVaryingVectors);
7189             s.append(builtInConstant);
7190         } else {
7191             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVertexOutputVectors = %d;", resources.maxVertexOutputVectors);
7192             s.append(builtInConstant);
7193
7194             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxFragmentInputVectors = %d;", resources.maxFragmentInputVectors);
7195             s.append(builtInConstant);
7196
7197             snprintf(builtInConstant, maxSize, "const mediump int  gl_MinProgramTexelOffset = %d;", resources.minProgramTexelOffset);
7198             s.append(builtInConstant);
7199
7200             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxProgramTexelOffset = %d;", resources.maxProgramTexelOffset);
7201             s.append(builtInConstant);
7202         }
7203
7204 #ifndef GLSLANG_WEB
7205         if (version >= 310) {
7206             // geometry
7207
7208             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryInputComponents = %d;", resources.maxGeometryInputComponents);
7209             s.append(builtInConstant);
7210             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputComponents = %d;", resources.maxGeometryOutputComponents);
7211             s.append(builtInConstant);
7212             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryImageUniforms = %d;", resources.maxGeometryImageUniforms);
7213             s.append(builtInConstant);
7214             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTextureImageUnits = %d;", resources.maxGeometryTextureImageUnits);
7215             s.append(builtInConstant);
7216             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputVertices = %d;", resources.maxGeometryOutputVertices);
7217             s.append(builtInConstant);
7218             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTotalOutputComponents = %d;", resources.maxGeometryTotalOutputComponents);
7219             s.append(builtInConstant);
7220             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryUniformComponents = %d;", resources.maxGeometryUniformComponents);
7221             s.append(builtInConstant);
7222             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounters = %d;", resources.maxGeometryAtomicCounters);
7223             s.append(builtInConstant);
7224             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounterBuffers = %d;", resources.maxGeometryAtomicCounterBuffers);
7225             s.append(builtInConstant);
7226
7227             // tessellation
7228
7229             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlInputComponents = %d;", resources.maxTessControlInputComponents);
7230             s.append(builtInConstant);
7231             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlOutputComponents = %d;", resources.maxTessControlOutputComponents);
7232             s.append(builtInConstant);
7233             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTextureImageUnits = %d;", resources.maxTessControlTextureImageUnits);
7234             s.append(builtInConstant);
7235             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlUniformComponents = %d;", resources.maxTessControlUniformComponents);
7236             s.append(builtInConstant);
7237             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTotalOutputComponents = %d;", resources.maxTessControlTotalOutputComponents);
7238             s.append(builtInConstant);
7239
7240             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationInputComponents = %d;", resources.maxTessEvaluationInputComponents);
7241             s.append(builtInConstant);
7242             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationOutputComponents = %d;", resources.maxTessEvaluationOutputComponents);
7243             s.append(builtInConstant);
7244             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationTextureImageUnits = %d;", resources.maxTessEvaluationTextureImageUnits);
7245             s.append(builtInConstant);
7246             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationUniformComponents = %d;", resources.maxTessEvaluationUniformComponents);
7247             s.append(builtInConstant);
7248
7249             snprintf(builtInConstant, maxSize, "const int gl_MaxTessPatchComponents = %d;", resources.maxTessPatchComponents);
7250             s.append(builtInConstant);
7251
7252             snprintf(builtInConstant, maxSize, "const int gl_MaxPatchVertices = %d;", resources.maxPatchVertices);
7253             s.append(builtInConstant);
7254             snprintf(builtInConstant, maxSize, "const int gl_MaxTessGenLevel = %d;", resources.maxTessGenLevel);
7255             s.append(builtInConstant);
7256
7257             // this is here instead of with the others in initialize(version, profile) due to the dependence on gl_MaxPatchVertices
7258             if (language == EShLangTessControl || language == EShLangTessEvaluation) {
7259                 s.append(
7260                     "in gl_PerVertex {"
7261                         "highp vec4 gl_Position;"
7262                         "highp float gl_PointSize;"
7263                         "highp vec4 gl_SecondaryPositionNV;"  // GL_NV_stereo_view_rendering
7264                         "highp vec4 gl_PositionPerViewNV[];"  // GL_NVX_multiview_per_view_attributes
7265                     "} gl_in[gl_MaxPatchVertices];"
7266                     "\n");
7267             }
7268         }
7269
7270         if (version >= 320) {
7271             // tessellation
7272
7273             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlImageUniforms = %d;", resources.maxTessControlImageUniforms);
7274             s.append(builtInConstant);
7275             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationImageUniforms = %d;", resources.maxTessEvaluationImageUniforms);
7276             s.append(builtInConstant);
7277             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounters = %d;", resources.maxTessControlAtomicCounters);
7278             s.append(builtInConstant);
7279             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounters = %d;", resources.maxTessEvaluationAtomicCounters);
7280             s.append(builtInConstant);
7281             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounterBuffers = %d;", resources.maxTessControlAtomicCounterBuffers);
7282             s.append(builtInConstant);
7283             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounterBuffers = %d;", resources.maxTessEvaluationAtomicCounterBuffers);
7284             s.append(builtInConstant);
7285         }
7286
7287         if (version >= 100) {
7288             // GL_EXT_blend_func_extended
7289             snprintf(builtInConstant, maxSize, "const mediump int gl_MaxDualSourceDrawBuffersEXT = %d;", resources.maxDualSourceDrawBuffersEXT);
7290             s.append(builtInConstant);
7291             // this is here instead of with the others in initialize(version, profile) due to the dependence on gl_MaxDualSourceDrawBuffersEXT
7292             if (language == EShLangFragment) {
7293                 s.append(
7294                     "mediump vec4 gl_SecondaryFragColorEXT;"
7295                     "mediump vec4 gl_SecondaryFragDataEXT[gl_MaxDualSourceDrawBuffersEXT];"
7296                     "\n");
7297             }
7298         }
7299     } else {
7300         // non-ES profile
7301
7302         if (version > 400) {
7303             snprintf(builtInConstant, maxSize, "const int  gl_MaxVertexUniformVectors = %d;", resources.maxVertexUniformVectors);
7304             s.append(builtInConstant);
7305
7306             snprintf(builtInConstant, maxSize, "const int  gl_MaxFragmentUniformVectors = %d;", resources.maxFragmentUniformVectors);
7307             s.append(builtInConstant);
7308
7309             snprintf(builtInConstant, maxSize, "const int  gl_MaxVaryingVectors = %d;", resources.maxVaryingVectors);
7310             s.append(builtInConstant);
7311         }
7312
7313         snprintf(builtInConstant, maxSize, "const int  gl_MaxVertexAttribs = %d;", resources.maxVertexAttribs);
7314         s.append(builtInConstant);
7315
7316         snprintf(builtInConstant, maxSize, "const int  gl_MaxVertexTextureImageUnits = %d;", resources.maxVertexTextureImageUnits);
7317         s.append(builtInConstant);
7318
7319         snprintf(builtInConstant, maxSize, "const int  gl_MaxCombinedTextureImageUnits = %d;", resources.maxCombinedTextureImageUnits);
7320         s.append(builtInConstant);
7321
7322         snprintf(builtInConstant, maxSize, "const int  gl_MaxTextureImageUnits = %d;", resources.maxTextureImageUnits);
7323         s.append(builtInConstant);
7324
7325         snprintf(builtInConstant, maxSize, "const int  gl_MaxDrawBuffers = %d;", resources.maxDrawBuffers);
7326         s.append(builtInConstant);
7327
7328         snprintf(builtInConstant, maxSize, "const int  gl_MaxLights = %d;", resources.maxLights);
7329         s.append(builtInConstant);
7330
7331         snprintf(builtInConstant, maxSize, "const int  gl_MaxClipPlanes = %d;", resources.maxClipPlanes);
7332         s.append(builtInConstant);
7333
7334         snprintf(builtInConstant, maxSize, "const int  gl_MaxTextureUnits = %d;", resources.maxTextureUnits);
7335         s.append(builtInConstant);
7336
7337         snprintf(builtInConstant, maxSize, "const int  gl_MaxTextureCoords = %d;", resources.maxTextureCoords);
7338         s.append(builtInConstant);
7339
7340         snprintf(builtInConstant, maxSize, "const int  gl_MaxVertexUniformComponents = %d;", resources.maxVertexUniformComponents);
7341         s.append(builtInConstant);
7342
7343         // Moved from just being deprecated into compatibility profile only as of 4.20
7344         if (version < 420 || profile == ECompatibilityProfile) {
7345             snprintf(builtInConstant, maxSize, "const int  gl_MaxVaryingFloats = %d;", resources.maxVaryingFloats);
7346             s.append(builtInConstant);
7347         }
7348
7349         snprintf(builtInConstant, maxSize, "const int  gl_MaxFragmentUniformComponents = %d;", resources.maxFragmentUniformComponents);
7350         s.append(builtInConstant);
7351
7352         if (spvVersion.spv == 0 && IncludeLegacy(version, profile, spvVersion)) {
7353             //
7354             // OpenGL'uniform' state.  Page numbers are in reference to version
7355             // 1.4 of the OpenGL specification.
7356             //
7357
7358             //
7359             // Matrix state. p. 31, 32, 37, 39, 40.
7360             //
7361             s.append("uniform mat4  gl_TextureMatrix[gl_MaxTextureCoords];"
7362
7363             //
7364             // Derived matrix state that provides inverse and transposed versions
7365             // of the matrices above.
7366             //
7367                         "uniform mat4  gl_TextureMatrixInverse[gl_MaxTextureCoords];"
7368
7369                         "uniform mat4  gl_TextureMatrixTranspose[gl_MaxTextureCoords];"
7370
7371                         "uniform mat4  gl_TextureMatrixInverseTranspose[gl_MaxTextureCoords];"
7372
7373             //
7374             // Clip planes p. 42.
7375             //
7376                         "uniform vec4  gl_ClipPlane[gl_MaxClipPlanes];"
7377
7378             //
7379             // Light State p 50, 53, 55.
7380             //
7381                         "uniform gl_LightSourceParameters  gl_LightSource[gl_MaxLights];"
7382
7383             //
7384             // Derived state from products of light.
7385             //
7386                         "uniform gl_LightProducts gl_FrontLightProduct[gl_MaxLights];"
7387                         "uniform gl_LightProducts gl_BackLightProduct[gl_MaxLights];"
7388
7389             //
7390             // Texture Environment and Generation, p. 152, p. 40-42.
7391             //
7392                         "uniform vec4  gl_TextureEnvColor[gl_MaxTextureImageUnits];"
7393                         "uniform vec4  gl_EyePlaneS[gl_MaxTextureCoords];"
7394                         "uniform vec4  gl_EyePlaneT[gl_MaxTextureCoords];"
7395                         "uniform vec4  gl_EyePlaneR[gl_MaxTextureCoords];"
7396                         "uniform vec4  gl_EyePlaneQ[gl_MaxTextureCoords];"
7397                         "uniform vec4  gl_ObjectPlaneS[gl_MaxTextureCoords];"
7398                         "uniform vec4  gl_ObjectPlaneT[gl_MaxTextureCoords];"
7399                         "uniform vec4  gl_ObjectPlaneR[gl_MaxTextureCoords];"
7400                         "uniform vec4  gl_ObjectPlaneQ[gl_MaxTextureCoords];");
7401         }
7402
7403         if (version >= 130) {
7404             snprintf(builtInConstant, maxSize, "const int gl_MaxClipDistances = %d;", resources.maxClipDistances);
7405             s.append(builtInConstant);
7406             snprintf(builtInConstant, maxSize, "const int gl_MaxVaryingComponents = %d;", resources.maxVaryingComponents);
7407             s.append(builtInConstant);
7408
7409             // GL_ARB_shading_language_420pack
7410             snprintf(builtInConstant, maxSize, "const mediump int  gl_MinProgramTexelOffset = %d;", resources.minProgramTexelOffset);
7411             s.append(builtInConstant);
7412             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxProgramTexelOffset = %d;", resources.maxProgramTexelOffset);
7413             s.append(builtInConstant);
7414         }
7415
7416         // geometry
7417         if (version >= 150) {
7418             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryInputComponents = %d;", resources.maxGeometryInputComponents);
7419             s.append(builtInConstant);
7420             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputComponents = %d;", resources.maxGeometryOutputComponents);
7421             s.append(builtInConstant);
7422             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTextureImageUnits = %d;", resources.maxGeometryTextureImageUnits);
7423             s.append(builtInConstant);
7424             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputVertices = %d;", resources.maxGeometryOutputVertices);
7425             s.append(builtInConstant);
7426             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTotalOutputComponents = %d;", resources.maxGeometryTotalOutputComponents);
7427             s.append(builtInConstant);
7428             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryUniformComponents = %d;", resources.maxGeometryUniformComponents);
7429             s.append(builtInConstant);
7430             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryVaryingComponents = %d;", resources.maxGeometryVaryingComponents);
7431             s.append(builtInConstant);
7432
7433         }
7434
7435         if (version >= 150) {
7436             snprintf(builtInConstant, maxSize, "const int gl_MaxVertexOutputComponents = %d;", resources.maxVertexOutputComponents);
7437             s.append(builtInConstant);
7438             snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentInputComponents = %d;", resources.maxFragmentInputComponents);
7439             s.append(builtInConstant);
7440         }
7441
7442         // tessellation
7443         if (version >= 150) {
7444             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlInputComponents = %d;", resources.maxTessControlInputComponents);
7445             s.append(builtInConstant);
7446             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlOutputComponents = %d;", resources.maxTessControlOutputComponents);
7447             s.append(builtInConstant);
7448             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTextureImageUnits = %d;", resources.maxTessControlTextureImageUnits);
7449             s.append(builtInConstant);
7450             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlUniformComponents = %d;", resources.maxTessControlUniformComponents);
7451             s.append(builtInConstant);
7452             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTotalOutputComponents = %d;", resources.maxTessControlTotalOutputComponents);
7453             s.append(builtInConstant);
7454
7455             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationInputComponents = %d;", resources.maxTessEvaluationInputComponents);
7456             s.append(builtInConstant);
7457             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationOutputComponents = %d;", resources.maxTessEvaluationOutputComponents);
7458             s.append(builtInConstant);
7459             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationTextureImageUnits = %d;", resources.maxTessEvaluationTextureImageUnits);
7460             s.append(builtInConstant);
7461             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationUniformComponents = %d;", resources.maxTessEvaluationUniformComponents);
7462             s.append(builtInConstant);
7463
7464             snprintf(builtInConstant, maxSize, "const int gl_MaxTessPatchComponents = %d;", resources.maxTessPatchComponents);
7465             s.append(builtInConstant);
7466             snprintf(builtInConstant, maxSize, "const int gl_MaxTessGenLevel = %d;", resources.maxTessGenLevel);
7467             s.append(builtInConstant);
7468             snprintf(builtInConstant, maxSize, "const int gl_MaxPatchVertices = %d;", resources.maxPatchVertices);
7469             s.append(builtInConstant);
7470
7471             // this is here instead of with the others in initialize(version, profile) due to the dependence on gl_MaxPatchVertices
7472             if (language == EShLangTessControl || language == EShLangTessEvaluation) {
7473                 s.append(
7474                     "in gl_PerVertex {"
7475                         "vec4 gl_Position;"
7476                         "float gl_PointSize;"
7477                         "float gl_ClipDistance[];"
7478                     );
7479                 if (profile == ECompatibilityProfile)
7480                     s.append(
7481                         "vec4 gl_ClipVertex;"
7482                         "vec4 gl_FrontColor;"
7483                         "vec4 gl_BackColor;"
7484                         "vec4 gl_FrontSecondaryColor;"
7485                         "vec4 gl_BackSecondaryColor;"
7486                         "vec4 gl_TexCoord[];"
7487                         "float gl_FogFragCoord;"
7488                         );
7489                 if (profile != EEsProfile && version >= 450)
7490                     s.append(
7491                         "float gl_CullDistance[];"
7492                         "vec4 gl_SecondaryPositionNV;"  // GL_NV_stereo_view_rendering
7493                         "vec4 gl_PositionPerViewNV[];"  // GL_NVX_multiview_per_view_attributes
7494                        );
7495                 s.append(
7496                     "} gl_in[gl_MaxPatchVertices];"
7497                     "\n");
7498             }
7499         }
7500
7501         if (version >= 150) {
7502             snprintf(builtInConstant, maxSize, "const int gl_MaxViewports = %d;", resources.maxViewports);
7503             s.append(builtInConstant);
7504         }
7505
7506         // images
7507         if (version >= 130) {
7508             snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedImageUnitsAndFragmentOutputs = %d;", resources.maxCombinedImageUnitsAndFragmentOutputs);
7509             s.append(builtInConstant);
7510             snprintf(builtInConstant, maxSize, "const int gl_MaxImageSamples = %d;", resources.maxImageSamples);
7511             s.append(builtInConstant);
7512             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlImageUniforms = %d;", resources.maxTessControlImageUniforms);
7513             s.append(builtInConstant);
7514             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationImageUniforms = %d;", resources.maxTessEvaluationImageUniforms);
7515             s.append(builtInConstant);
7516             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryImageUniforms = %d;", resources.maxGeometryImageUniforms);
7517             s.append(builtInConstant);
7518         }
7519
7520         // enhanced layouts
7521         if (version >= 430) {
7522             snprintf(builtInConstant, maxSize, "const int gl_MaxTransformFeedbackBuffers = %d;", resources.maxTransformFeedbackBuffers);
7523             s.append(builtInConstant);
7524             snprintf(builtInConstant, maxSize, "const int gl_MaxTransformFeedbackInterleavedComponents = %d;", resources.maxTransformFeedbackInterleavedComponents);
7525             s.append(builtInConstant);
7526         }
7527 #endif
7528     }
7529
7530     // compute
7531     if ((profile == EEsProfile && version >= 310) || (profile != EEsProfile && version >= 420)) {
7532         snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxComputeWorkGroupCount = ivec3(%d,%d,%d);", resources.maxComputeWorkGroupCountX,
7533                                                                                                          resources.maxComputeWorkGroupCountY,
7534                                                                                                          resources.maxComputeWorkGroupCountZ);
7535         s.append(builtInConstant);
7536         snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxComputeWorkGroupSize = ivec3(%d,%d,%d);", resources.maxComputeWorkGroupSizeX,
7537                                                                                                         resources.maxComputeWorkGroupSizeY,
7538                                                                                                         resources.maxComputeWorkGroupSizeZ);
7539         s.append(builtInConstant);
7540
7541         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeUniformComponents = %d;", resources.maxComputeUniformComponents);
7542         s.append(builtInConstant);
7543         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeTextureImageUnits = %d;", resources.maxComputeTextureImageUnits);
7544         s.append(builtInConstant);
7545
7546         s.append("\n");
7547     }
7548
7549 #ifndef GLSLANG_WEB
7550     // images (some in compute below)
7551     if ((profile == EEsProfile && version >= 310) ||
7552         (profile != EEsProfile && version >= 130)) {
7553         snprintf(builtInConstant, maxSize, "const int gl_MaxImageUnits = %d;", resources.maxImageUnits);
7554         s.append(builtInConstant);
7555         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedShaderOutputResources = %d;", resources.maxCombinedShaderOutputResources);
7556         s.append(builtInConstant);
7557         snprintf(builtInConstant, maxSize, "const int gl_MaxVertexImageUniforms = %d;", resources.maxVertexImageUniforms);
7558         s.append(builtInConstant);
7559         snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentImageUniforms = %d;", resources.maxFragmentImageUniforms);
7560         s.append(builtInConstant);
7561         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedImageUniforms = %d;", resources.maxCombinedImageUniforms);
7562         s.append(builtInConstant);
7563     }
7564
7565     // compute
7566     if ((profile == EEsProfile && version >= 310) || (profile != EEsProfile && version >= 420)) {
7567         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeImageUniforms = %d;", resources.maxComputeImageUniforms);
7568         s.append(builtInConstant);
7569         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeAtomicCounters = %d;", resources.maxComputeAtomicCounters);
7570         s.append(builtInConstant);
7571         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeAtomicCounterBuffers = %d;", resources.maxComputeAtomicCounterBuffers);
7572         s.append(builtInConstant);
7573
7574         s.append("\n");
7575     }
7576
7577 #ifndef GLSLANG_ANGLE
7578     // atomic counters (some in compute below)
7579     if ((profile == EEsProfile && version >= 310) ||
7580         (profile != EEsProfile && version >= 420)) {
7581         snprintf(builtInConstant, maxSize, "const int gl_MaxVertexAtomicCounters = %d;", resources.               maxVertexAtomicCounters);
7582         s.append(builtInConstant);
7583         snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentAtomicCounters = %d;", resources.             maxFragmentAtomicCounters);
7584         s.append(builtInConstant);
7585         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedAtomicCounters = %d;", resources.             maxCombinedAtomicCounters);
7586         s.append(builtInConstant);
7587         snprintf(builtInConstant, maxSize, "const int gl_MaxAtomicCounterBindings = %d;", resources.              maxAtomicCounterBindings);
7588         s.append(builtInConstant);
7589         snprintf(builtInConstant, maxSize, "const int gl_MaxVertexAtomicCounterBuffers = %d;", resources.         maxVertexAtomicCounterBuffers);
7590         s.append(builtInConstant);
7591         snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentAtomicCounterBuffers = %d;", resources.       maxFragmentAtomicCounterBuffers);
7592         s.append(builtInConstant);
7593         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedAtomicCounterBuffers = %d;", resources.       maxCombinedAtomicCounterBuffers);
7594         s.append(builtInConstant);
7595         snprintf(builtInConstant, maxSize, "const int gl_MaxAtomicCounterBufferSize = %d;", resources.            maxAtomicCounterBufferSize);
7596         s.append(builtInConstant);
7597     }
7598     if (profile != EEsProfile && version >= 420) {
7599         snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounters = %d;", resources.          maxTessControlAtomicCounters);
7600         s.append(builtInConstant);
7601         snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounters = %d;", resources.       maxTessEvaluationAtomicCounters);
7602         s.append(builtInConstant);
7603         snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounters = %d;", resources.             maxGeometryAtomicCounters);
7604         s.append(builtInConstant);
7605         snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounterBuffers = %d;", resources.    maxTessControlAtomicCounterBuffers);
7606         s.append(builtInConstant);
7607         snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounterBuffers = %d;", resources. maxTessEvaluationAtomicCounterBuffers);
7608         s.append(builtInConstant);
7609         snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounterBuffers = %d;", resources.       maxGeometryAtomicCounterBuffers);
7610         s.append(builtInConstant);
7611
7612         s.append("\n");
7613     }
7614 #endif // !GLSLANG_ANGLE
7615
7616     // GL_ARB_cull_distance
7617     if (profile != EEsProfile && version >= 450) {
7618         snprintf(builtInConstant, maxSize, "const int gl_MaxCullDistances = %d;",                resources.maxCullDistances);
7619         s.append(builtInConstant);
7620         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedClipAndCullDistances = %d;", resources.maxCombinedClipAndCullDistances);
7621         s.append(builtInConstant);
7622     }
7623
7624     // GL_ARB_ES3_1_compatibility
7625     if ((profile != EEsProfile && version >= 450) ||
7626         (profile == EEsProfile && version >= 310)) {
7627         snprintf(builtInConstant, maxSize, "const int gl_MaxSamples = %d;", resources.maxSamples);
7628         s.append(builtInConstant);
7629     }
7630
7631 #ifndef GLSLANG_ANGLE
7632     // SPV_NV_mesh_shader
7633     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
7634         snprintf(builtInConstant, maxSize, "const int gl_MaxMeshOutputVerticesNV = %d;", resources.maxMeshOutputVerticesNV);
7635         s.append(builtInConstant);
7636
7637         snprintf(builtInConstant, maxSize, "const int gl_MaxMeshOutputPrimitivesNV = %d;", resources.maxMeshOutputPrimitivesNV);
7638         s.append(builtInConstant);
7639
7640         snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxMeshWorkGroupSizeNV = ivec3(%d,%d,%d);", resources.maxMeshWorkGroupSizeX_NV,
7641                                                                                                        resources.maxMeshWorkGroupSizeY_NV,
7642                                                                                                        resources.maxMeshWorkGroupSizeZ_NV);
7643         s.append(builtInConstant);
7644         snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxTaskWorkGroupSizeNV = ivec3(%d,%d,%d);", resources.maxTaskWorkGroupSizeX_NV,
7645                                                                                                        resources.maxTaskWorkGroupSizeY_NV,
7646                                                                                                        resources.maxTaskWorkGroupSizeZ_NV);
7647         s.append(builtInConstant);
7648
7649         snprintf(builtInConstant, maxSize, "const int gl_MaxMeshViewCountNV = %d;", resources.maxMeshViewCountNV);
7650         s.append(builtInConstant);
7651
7652         s.append("\n");
7653     }
7654 #endif
7655 #endif
7656
7657     s.append("\n");
7658 }
7659
7660 //
7661 // To support special built-ins that have a special qualifier that cannot be declared textually
7662 // in a shader, like gl_Position.
7663 //
7664 // This lets the type of the built-in be declared textually, and then have just its qualifier be
7665 // updated afterward.
7666 //
7667 // Safe to call even if name is not present.
7668 //
7669 // Only use this for built-in variables that have a special qualifier in TStorageQualifier.
7670 // New built-in variables should use a generic (textually declarable) qualifier in
7671 // TStoraregQualifier and only call BuiltInVariable().
7672 //
7673 static void SpecialQualifier(const char* name, TStorageQualifier qualifier, TBuiltInVariable builtIn, TSymbolTable& symbolTable)
7674 {
7675     TSymbol* symbol = symbolTable.find(name);
7676     if (symbol == nullptr)
7677         return;
7678
7679     TQualifier& symQualifier = symbol->getWritableType().getQualifier();
7680     symQualifier.storage = qualifier;
7681     symQualifier.builtIn = builtIn;
7682 }
7683
7684 //
7685 // To tag built-in variables with their TBuiltInVariable enum.  Use this when the
7686 // normal declaration text already gets the qualifier right, and all that's needed
7687 // is setting the builtIn field.  This should be the normal way for all new
7688 // built-in variables.
7689 //
7690 // If SpecialQualifier() was called, this does not need to be called.
7691 //
7692 // Safe to call even if name is not present.
7693 //
7694 static void BuiltInVariable(const char* name, TBuiltInVariable builtIn, TSymbolTable& symbolTable)
7695 {
7696     TSymbol* symbol = symbolTable.find(name);
7697     if (symbol == nullptr)
7698         return;
7699
7700     TQualifier& symQualifier = symbol->getWritableType().getQualifier();
7701     symQualifier.builtIn = builtIn;
7702 }
7703
7704 static void RetargetVariable(const char* from, const char* to, TSymbolTable& symbolTable)
7705 {
7706     symbolTable.retargetSymbol(from, to);
7707 }
7708
7709 //
7710 // For built-in variables inside a named block.
7711 // SpecialQualifier() won't ever go inside a block; their member's qualifier come
7712 // from the qualification of the block.
7713 //
7714 // See comments above for other detail.
7715 //
7716 static void BuiltInVariable(const char* blockName, const char* name, TBuiltInVariable builtIn, TSymbolTable& symbolTable)
7717 {
7718     TSymbol* symbol = symbolTable.find(blockName);
7719     if (symbol == nullptr)
7720         return;
7721
7722     TTypeList& structure = *symbol->getWritableType().getWritableStruct();
7723     for (int i = 0; i < (int)structure.size(); ++i) {
7724         if (structure[i].type->getFieldName().compare(name) == 0) {
7725             structure[i].type->getQualifier().builtIn = builtIn;
7726             return;
7727         }
7728     }
7729 }
7730
7731 //
7732 // Finish adding/processing context-independent built-in symbols.
7733 // 1) Programmatically add symbols that could not be added by simple text strings above.
7734 // 2) Map built-in functions to operators, for those that will turn into an operation node
7735 //    instead of remaining a function call.
7736 // 3) Tag extension-related symbols added to their base version with their extensions, so
7737 //    that if an early version has the extension turned off, there is an error reported on use.
7738 //
7739 void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable)
7740 {
7741 #ifdef GLSLANG_WEB
7742     version = 310;
7743     profile = EEsProfile;
7744 #elif defined(GLSLANG_ANGLE)
7745     version = 450;
7746     profile = ECoreProfile;
7747 #endif
7748
7749     //
7750     // Tag built-in variables and functions with additional qualifier and extension information
7751     // that cannot be declared with the text strings.
7752     //
7753
7754     // N.B.: a symbol should only be tagged once, and this function is called multiple times, once
7755     // per stage that's used for this profile.  So
7756     //  - generally, stick common ones in the fragment stage to ensure they are tagged exactly once
7757     //  - for ES, which has different precisions for different stages, the coarsest-grained tagging
7758     //    for a built-in used in many stages needs to be once for the fragment stage and once for
7759     //    the vertex stage
7760
7761     switch(language) {
7762     case EShLangVertex:
7763         if (spvVersion.vulkan > 0) {
7764             BuiltInVariable("gl_VertexIndex",   EbvVertexIndex,   symbolTable);
7765             BuiltInVariable("gl_InstanceIndex", EbvInstanceIndex, symbolTable);
7766         }
7767
7768 #ifndef GLSLANG_WEB
7769         if (spvVersion.vulkan == 0) {
7770             SpecialQualifier("gl_VertexID",   EvqVertexId,   EbvVertexId,   symbolTable);
7771             SpecialQualifier("gl_InstanceID", EvqInstanceId, EbvInstanceId, symbolTable);
7772         }
7773
7774         if (spvVersion.vulkan > 0 && spvVersion.vulkanRelaxed) {
7775             // treat these built-ins as aliases of VertexIndex and InstanceIndex
7776             RetargetVariable("gl_InstanceID", "gl_InstanceIndex", symbolTable);
7777             RetargetVariable("gl_VertexID", "gl_VertexIndex", symbolTable);
7778         }
7779
7780         if (profile != EEsProfile) {
7781             if (version >= 440) {
7782                 symbolTable.setVariableExtensions("gl_BaseVertexARB",   1, &E_GL_ARB_shader_draw_parameters);
7783                 symbolTable.setVariableExtensions("gl_BaseInstanceARB", 1, &E_GL_ARB_shader_draw_parameters);
7784                 symbolTable.setVariableExtensions("gl_DrawIDARB",       1, &E_GL_ARB_shader_draw_parameters);
7785                 BuiltInVariable("gl_BaseVertexARB",   EbvBaseVertex,   symbolTable);
7786                 BuiltInVariable("gl_BaseInstanceARB", EbvBaseInstance, symbolTable);
7787                 BuiltInVariable("gl_DrawIDARB",       EbvDrawId,       symbolTable);
7788             }
7789             if (version >= 460) {
7790                 BuiltInVariable("gl_BaseVertex",   EbvBaseVertex,   symbolTable);
7791                 BuiltInVariable("gl_BaseInstance", EbvBaseInstance, symbolTable);
7792                 BuiltInVariable("gl_DrawID",       EbvDrawId,       symbolTable);
7793             }
7794             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
7795             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
7796             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
7797             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
7798             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
7799             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
7800             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
7801
7802             symbolTable.setFunctionExtensions("ballotARB",              1, &E_GL_ARB_shader_ballot);
7803             symbolTable.setFunctionExtensions("readInvocationARB",      1, &E_GL_ARB_shader_ballot);
7804             symbolTable.setFunctionExtensions("readFirstInvocationARB", 1, &E_GL_ARB_shader_ballot);
7805
7806             if (version >= 430) {
7807                 symbolTable.setFunctionExtensions("anyInvocationARB",       1, &E_GL_ARB_shader_group_vote);
7808                 symbolTable.setFunctionExtensions("allInvocationsARB",      1, &E_GL_ARB_shader_group_vote);
7809                 symbolTable.setFunctionExtensions("allInvocationsEqualARB", 1, &E_GL_ARB_shader_group_vote);
7810             }
7811         }
7812
7813
7814         if (profile != EEsProfile) {
7815             symbolTable.setFunctionExtensions("minInvocationsAMD",                1, &E_GL_AMD_shader_ballot);
7816             symbolTable.setFunctionExtensions("maxInvocationsAMD",                1, &E_GL_AMD_shader_ballot);
7817             symbolTable.setFunctionExtensions("addInvocationsAMD",                1, &E_GL_AMD_shader_ballot);
7818             symbolTable.setFunctionExtensions("minInvocationsNonUniformAMD",      1, &E_GL_AMD_shader_ballot);
7819             symbolTable.setFunctionExtensions("maxInvocationsNonUniformAMD",      1, &E_GL_AMD_shader_ballot);
7820             symbolTable.setFunctionExtensions("addInvocationsNonUniformAMD",      1, &E_GL_AMD_shader_ballot);
7821             symbolTable.setFunctionExtensions("swizzleInvocationsAMD",            1, &E_GL_AMD_shader_ballot);
7822             symbolTable.setFunctionExtensions("swizzleInvocationsWithPatternAMD", 1, &E_GL_AMD_shader_ballot);
7823             symbolTable.setFunctionExtensions("writeInvocationAMD",               1, &E_GL_AMD_shader_ballot);
7824             symbolTable.setFunctionExtensions("mbcntAMD",                         1, &E_GL_AMD_shader_ballot);
7825
7826             symbolTable.setFunctionExtensions("minInvocationsInclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
7827             symbolTable.setFunctionExtensions("maxInvocationsInclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
7828             symbolTable.setFunctionExtensions("addInvocationsInclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
7829             symbolTable.setFunctionExtensions("minInvocationsInclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
7830             symbolTable.setFunctionExtensions("maxInvocationsInclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
7831             symbolTable.setFunctionExtensions("addInvocationsInclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
7832             symbolTable.setFunctionExtensions("minInvocationsExclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
7833             symbolTable.setFunctionExtensions("maxInvocationsExclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
7834             symbolTable.setFunctionExtensions("addInvocationsExclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
7835             symbolTable.setFunctionExtensions("minInvocationsExclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
7836             symbolTable.setFunctionExtensions("maxInvocationsExclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
7837             symbolTable.setFunctionExtensions("addInvocationsExclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
7838         }
7839
7840         if (profile != EEsProfile) {
7841             symbolTable.setFunctionExtensions("min3", 1, &E_GL_AMD_shader_trinary_minmax);
7842             symbolTable.setFunctionExtensions("max3", 1, &E_GL_AMD_shader_trinary_minmax);
7843             symbolTable.setFunctionExtensions("mid3", 1, &E_GL_AMD_shader_trinary_minmax);
7844         }
7845
7846         if (profile != EEsProfile) {
7847             symbolTable.setVariableExtensions("gl_SIMDGroupSizeAMD", 1, &E_GL_AMD_gcn_shader);
7848             SpecialQualifier("gl_SIMDGroupSizeAMD", EvqVaryingIn, EbvSubGroupSize, symbolTable);
7849
7850             symbolTable.setFunctionExtensions("cubeFaceIndexAMD", 1, &E_GL_AMD_gcn_shader);
7851             symbolTable.setFunctionExtensions("cubeFaceCoordAMD", 1, &E_GL_AMD_gcn_shader);
7852             symbolTable.setFunctionExtensions("timeAMD",          1, &E_GL_AMD_gcn_shader);
7853         }
7854
7855         if (profile != EEsProfile) {
7856             symbolTable.setFunctionExtensions("fragmentMaskFetchAMD", 1, &E_GL_AMD_shader_fragment_mask);
7857             symbolTable.setFunctionExtensions("fragmentFetchAMD",     1, &E_GL_AMD_shader_fragment_mask);
7858         }
7859
7860         symbolTable.setFunctionExtensions("countLeadingZeros",  1, &E_GL_INTEL_shader_integer_functions2);
7861         symbolTable.setFunctionExtensions("countTrailingZeros", 1, &E_GL_INTEL_shader_integer_functions2);
7862         symbolTable.setFunctionExtensions("absoluteDifference", 1, &E_GL_INTEL_shader_integer_functions2);
7863         symbolTable.setFunctionExtensions("addSaturate",        1, &E_GL_INTEL_shader_integer_functions2);
7864         symbolTable.setFunctionExtensions("subtractSaturate",   1, &E_GL_INTEL_shader_integer_functions2);
7865         symbolTable.setFunctionExtensions("average",            1, &E_GL_INTEL_shader_integer_functions2);
7866         symbolTable.setFunctionExtensions("averageRounded",     1, &E_GL_INTEL_shader_integer_functions2);
7867         symbolTable.setFunctionExtensions("multiply32x16",      1, &E_GL_INTEL_shader_integer_functions2);
7868
7869         symbolTable.setFunctionExtensions("textureFootprintNV",          1, &E_GL_NV_shader_texture_footprint);
7870         symbolTable.setFunctionExtensions("textureFootprintClampNV",     1, &E_GL_NV_shader_texture_footprint);
7871         symbolTable.setFunctionExtensions("textureFootprintLodNV",       1, &E_GL_NV_shader_texture_footprint);
7872         symbolTable.setFunctionExtensions("textureFootprintGradNV",      1, &E_GL_NV_shader_texture_footprint);
7873         symbolTable.setFunctionExtensions("textureFootprintGradClampNV", 1, &E_GL_NV_shader_texture_footprint);
7874         // Compatibility variables, vertex only
7875         if (spvVersion.spv == 0) {
7876             BuiltInVariable("gl_Color",          EbvColor,          symbolTable);
7877             BuiltInVariable("gl_SecondaryColor", EbvSecondaryColor, symbolTable);
7878             BuiltInVariable("gl_Normal",         EbvNormal,         symbolTable);
7879             BuiltInVariable("gl_Vertex",         EbvVertex,         symbolTable);
7880             BuiltInVariable("gl_MultiTexCoord0", EbvMultiTexCoord0, symbolTable);
7881             BuiltInVariable("gl_MultiTexCoord1", EbvMultiTexCoord1, symbolTable);
7882             BuiltInVariable("gl_MultiTexCoord2", EbvMultiTexCoord2, symbolTable);
7883             BuiltInVariable("gl_MultiTexCoord3", EbvMultiTexCoord3, symbolTable);
7884             BuiltInVariable("gl_MultiTexCoord4", EbvMultiTexCoord4, symbolTable);
7885             BuiltInVariable("gl_MultiTexCoord5", EbvMultiTexCoord5, symbolTable);
7886             BuiltInVariable("gl_MultiTexCoord6", EbvMultiTexCoord6, symbolTable);
7887             BuiltInVariable("gl_MultiTexCoord7", EbvMultiTexCoord7, symbolTable);
7888             BuiltInVariable("gl_FogCoord",       EbvFogFragCoord,   symbolTable);
7889         }
7890
7891         if (profile == EEsProfile) {
7892             if (spvVersion.spv == 0) {
7893                 symbolTable.setFunctionExtensions("texture2DGradEXT",     1, &E_GL_EXT_shader_texture_lod);
7894                 symbolTable.setFunctionExtensions("texture2DProjGradEXT", 1, &E_GL_EXT_shader_texture_lod);
7895                 symbolTable.setFunctionExtensions("textureCubeGradEXT",   1, &E_GL_EXT_shader_texture_lod);
7896                 if (version == 310)
7897                     symbolTable.setFunctionExtensions("textureGatherOffsets", Num_AEP_gpu_shader5, AEP_gpu_shader5);
7898             }
7899             if (version == 310)
7900                 symbolTable.setFunctionExtensions("fma", Num_AEP_gpu_shader5, AEP_gpu_shader5);
7901         }
7902
7903         if (profile == EEsProfile && version < 320) {
7904             symbolTable.setFunctionExtensions("imageAtomicAdd",      1, &E_GL_OES_shader_image_atomic);
7905             symbolTable.setFunctionExtensions("imageAtomicMin",      1, &E_GL_OES_shader_image_atomic);
7906             symbolTable.setFunctionExtensions("imageAtomicMax",      1, &E_GL_OES_shader_image_atomic);
7907             symbolTable.setFunctionExtensions("imageAtomicAnd",      1, &E_GL_OES_shader_image_atomic);
7908             symbolTable.setFunctionExtensions("imageAtomicOr",       1, &E_GL_OES_shader_image_atomic);
7909             symbolTable.setFunctionExtensions("imageAtomicXor",      1, &E_GL_OES_shader_image_atomic);
7910             symbolTable.setFunctionExtensions("imageAtomicExchange", 1, &E_GL_OES_shader_image_atomic);
7911             symbolTable.setFunctionExtensions("imageAtomicCompSwap", 1, &E_GL_OES_shader_image_atomic);
7912         }
7913
7914         if (version >= 300 /* both ES and non-ES */) {
7915             symbolTable.setVariableExtensions("gl_ViewID_OVR", Num_OVR_multiview_EXTs, OVR_multiview_EXTs);
7916             BuiltInVariable("gl_ViewID_OVR", EbvViewIndex, symbolTable);
7917         }
7918
7919         if (profile == EEsProfile) {
7920             symbolTable.setFunctionExtensions("shadow2DEXT",        1, &E_GL_EXT_shadow_samplers);
7921             symbolTable.setFunctionExtensions("shadow2DProjEXT",    1, &E_GL_EXT_shadow_samplers);
7922         }
7923         // Fall through
7924
7925     case EShLangTessControl:
7926         if (profile == EEsProfile && version >= 310) {
7927             BuiltInVariable("gl_BoundingBoxEXT", EbvBoundingBox, symbolTable);
7928             symbolTable.setVariableExtensions("gl_BoundingBoxEXT", 1,
7929                                               &E_GL_EXT_primitive_bounding_box);
7930             BuiltInVariable("gl_BoundingBoxOES", EbvBoundingBox, symbolTable);
7931             symbolTable.setVariableExtensions("gl_BoundingBoxOES", 1,
7932                                               &E_GL_OES_primitive_bounding_box);
7933
7934             if (version >= 320) {
7935                 BuiltInVariable("gl_BoundingBox", EbvBoundingBox, symbolTable);
7936             }
7937         }
7938         // Fall through
7939
7940     case EShLangTessEvaluation:
7941     case EShLangGeometry:
7942 #endif // !GLSLANG_WEB
7943         SpecialQualifier("gl_Position",   EvqPosition,   EbvPosition,   symbolTable);
7944         SpecialQualifier("gl_PointSize",  EvqPointSize,  EbvPointSize,  symbolTable);
7945
7946         BuiltInVariable("gl_in",  "gl_Position",     EbvPosition,     symbolTable);
7947         BuiltInVariable("gl_in",  "gl_PointSize",    EbvPointSize,    symbolTable);
7948
7949         BuiltInVariable("gl_out", "gl_Position",     EbvPosition,     symbolTable);
7950         BuiltInVariable("gl_out", "gl_PointSize",    EbvPointSize,    symbolTable);
7951
7952 #ifndef GLSLANG_WEB
7953         SpecialQualifier("gl_ClipVertex", EvqClipVertex, EbvClipVertex, symbolTable);
7954
7955         BuiltInVariable("gl_in",  "gl_ClipDistance", EbvClipDistance, symbolTable);
7956         BuiltInVariable("gl_in",  "gl_CullDistance", EbvCullDistance, symbolTable);
7957
7958         BuiltInVariable("gl_out", "gl_ClipDistance", EbvClipDistance, symbolTable);
7959         BuiltInVariable("gl_out", "gl_CullDistance", EbvCullDistance, symbolTable);
7960
7961         BuiltInVariable("gl_ClipDistance",    EbvClipDistance,   symbolTable);
7962         BuiltInVariable("gl_CullDistance",    EbvCullDistance,   symbolTable);
7963         BuiltInVariable("gl_PrimitiveIDIn",   EbvPrimitiveId,    symbolTable);
7964         BuiltInVariable("gl_PrimitiveID",     EbvPrimitiveId,    symbolTable);
7965         BuiltInVariable("gl_InvocationID",    EbvInvocationId,   symbolTable);
7966         BuiltInVariable("gl_Layer",           EbvLayer,          symbolTable);
7967         BuiltInVariable("gl_ViewportIndex",   EbvViewportIndex,  symbolTable);
7968
7969         if (language != EShLangGeometry) {
7970             symbolTable.setVariableExtensions("gl_Layer",         Num_viewportEXTs, viewportEXTs);
7971             symbolTable.setVariableExtensions("gl_ViewportIndex", Num_viewportEXTs, viewportEXTs);
7972         }
7973         symbolTable.setVariableExtensions("gl_ViewportMask",            1, &E_GL_NV_viewport_array2);
7974         symbolTable.setVariableExtensions("gl_SecondaryPositionNV",     1, &E_GL_NV_stereo_view_rendering);
7975         symbolTable.setVariableExtensions("gl_SecondaryViewportMaskNV", 1, &E_GL_NV_stereo_view_rendering);
7976         symbolTable.setVariableExtensions("gl_PositionPerViewNV",       1, &E_GL_NVX_multiview_per_view_attributes);
7977         symbolTable.setVariableExtensions("gl_ViewportMaskPerViewNV",   1, &E_GL_NVX_multiview_per_view_attributes);
7978
7979         BuiltInVariable("gl_ViewportMask",              EbvViewportMaskNV,          symbolTable);
7980         BuiltInVariable("gl_SecondaryPositionNV",       EbvSecondaryPositionNV,     symbolTable);
7981         BuiltInVariable("gl_SecondaryViewportMaskNV",   EbvSecondaryViewportMaskNV, symbolTable);
7982         BuiltInVariable("gl_PositionPerViewNV",         EbvPositionPerViewNV,       symbolTable);
7983         BuiltInVariable("gl_ViewportMaskPerViewNV",     EbvViewportMaskPerViewNV,   symbolTable);
7984
7985         if (language == EShLangVertex || language == EShLangGeometry) {
7986             symbolTable.setVariableExtensions("gl_in", "gl_SecondaryPositionNV", 1, &E_GL_NV_stereo_view_rendering);
7987             symbolTable.setVariableExtensions("gl_in", "gl_PositionPerViewNV",   1, &E_GL_NVX_multiview_per_view_attributes);
7988
7989             BuiltInVariable("gl_in", "gl_SecondaryPositionNV", EbvSecondaryPositionNV, symbolTable);
7990             BuiltInVariable("gl_in", "gl_PositionPerViewNV",   EbvPositionPerViewNV,   symbolTable);
7991         }
7992         symbolTable.setVariableExtensions("gl_out", "gl_ViewportMask",            1, &E_GL_NV_viewport_array2);
7993         symbolTable.setVariableExtensions("gl_out", "gl_SecondaryPositionNV",     1, &E_GL_NV_stereo_view_rendering);
7994         symbolTable.setVariableExtensions("gl_out", "gl_SecondaryViewportMaskNV", 1, &E_GL_NV_stereo_view_rendering);
7995         symbolTable.setVariableExtensions("gl_out", "gl_PositionPerViewNV",       1, &E_GL_NVX_multiview_per_view_attributes);
7996         symbolTable.setVariableExtensions("gl_out", "gl_ViewportMaskPerViewNV",   1, &E_GL_NVX_multiview_per_view_attributes);
7997
7998         BuiltInVariable("gl_out", "gl_ViewportMask",            EbvViewportMaskNV,          symbolTable);
7999         BuiltInVariable("gl_out", "gl_SecondaryPositionNV",     EbvSecondaryPositionNV,     symbolTable);
8000         BuiltInVariable("gl_out", "gl_SecondaryViewportMaskNV", EbvSecondaryViewportMaskNV, symbolTable);
8001         BuiltInVariable("gl_out", "gl_PositionPerViewNV",       EbvPositionPerViewNV,       symbolTable);
8002         BuiltInVariable("gl_out", "gl_ViewportMaskPerViewNV",   EbvViewportMaskPerViewNV,   symbolTable);
8003
8004         BuiltInVariable("gl_PatchVerticesIn", EbvPatchVertices,  symbolTable);
8005         BuiltInVariable("gl_TessLevelOuter",  EbvTessLevelOuter, symbolTable);
8006         BuiltInVariable("gl_TessLevelInner",  EbvTessLevelInner, symbolTable);
8007         BuiltInVariable("gl_TessCoord",       EbvTessCoord,      symbolTable);
8008
8009         if (version < 410)
8010             symbolTable.setVariableExtensions("gl_ViewportIndex", 1, &E_GL_ARB_viewport_array);
8011
8012         // Compatibility variables
8013
8014         BuiltInVariable("gl_in", "gl_ClipVertex",          EbvClipVertex,          symbolTable);
8015         BuiltInVariable("gl_in", "gl_FrontColor",          EbvFrontColor,          symbolTable);
8016         BuiltInVariable("gl_in", "gl_BackColor",           EbvBackColor,           symbolTable);
8017         BuiltInVariable("gl_in", "gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
8018         BuiltInVariable("gl_in", "gl_BackSecondaryColor",  EbvBackSecondaryColor,  symbolTable);
8019         BuiltInVariable("gl_in", "gl_TexCoord",            EbvTexCoord,            symbolTable);
8020         BuiltInVariable("gl_in", "gl_FogFragCoord",        EbvFogFragCoord,        symbolTable);
8021
8022         BuiltInVariable("gl_out", "gl_ClipVertex",          EbvClipVertex,          symbolTable);
8023         BuiltInVariable("gl_out", "gl_FrontColor",          EbvFrontColor,          symbolTable);
8024         BuiltInVariable("gl_out", "gl_BackColor",           EbvBackColor,           symbolTable);
8025         BuiltInVariable("gl_out", "gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
8026         BuiltInVariable("gl_out", "gl_BackSecondaryColor",  EbvBackSecondaryColor,  symbolTable);
8027         BuiltInVariable("gl_out", "gl_TexCoord",            EbvTexCoord,            symbolTable);
8028         BuiltInVariable("gl_out", "gl_FogFragCoord",        EbvFogFragCoord,        symbolTable);
8029
8030         BuiltInVariable("gl_ClipVertex",          EbvClipVertex,          symbolTable);
8031         BuiltInVariable("gl_FrontColor",          EbvFrontColor,          symbolTable);
8032         BuiltInVariable("gl_BackColor",           EbvBackColor,           symbolTable);
8033         BuiltInVariable("gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
8034         BuiltInVariable("gl_BackSecondaryColor",  EbvBackSecondaryColor,  symbolTable);
8035         BuiltInVariable("gl_TexCoord",            EbvTexCoord,            symbolTable);
8036         BuiltInVariable("gl_FogFragCoord",        EbvFogFragCoord,        symbolTable);
8037
8038         // gl_PointSize, when it needs to be tied to an extension, is always a member of a block.
8039         // (Sometimes with an instance name, sometimes anonymous).
8040         if (profile == EEsProfile) {
8041             if (language == EShLangGeometry) {
8042                 symbolTable.setVariableExtensions("gl_PointSize", Num_AEP_geometry_point_size, AEP_geometry_point_size);
8043                 symbolTable.setVariableExtensions("gl_in", "gl_PointSize", Num_AEP_geometry_point_size, AEP_geometry_point_size);
8044             } else if (language == EShLangTessEvaluation || language == EShLangTessControl) {
8045                 // gl_in tessellation settings of gl_PointSize are in the context-dependent paths
8046                 symbolTable.setVariableExtensions("gl_PointSize", Num_AEP_tessellation_point_size, AEP_tessellation_point_size);
8047                 symbolTable.setVariableExtensions("gl_out", "gl_PointSize", Num_AEP_tessellation_point_size, AEP_tessellation_point_size);
8048             }
8049         }
8050
8051         if ((profile != EEsProfile && version >= 140) ||
8052             (profile == EEsProfile && version >= 310)) {
8053             symbolTable.setVariableExtensions("gl_DeviceIndex",  1, &E_GL_EXT_device_group);
8054             BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
8055             symbolTable.setVariableExtensions("gl_ViewIndex", 1, &E_GL_EXT_multiview);
8056             BuiltInVariable("gl_ViewIndex", EbvViewIndex, symbolTable);
8057         }
8058
8059         if (profile != EEsProfile) {
8060             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
8061             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
8062             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
8063             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
8064             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
8065             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
8066
8067             if (spvVersion.vulkan > 0)
8068                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
8069                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
8070             else
8071                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
8072         }
8073
8074         // GL_KHR_shader_subgroup
8075         if ((profile == EEsProfile && version >= 310) ||
8076             (profile != EEsProfile && version >= 140)) {
8077             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
8078             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
8079             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8080             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8081             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8082             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8083             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8084
8085             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
8086             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
8087             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
8088             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
8089             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
8090             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
8091             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
8092
8093             // GL_NV_shader_sm_builtins
8094             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
8095             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
8096             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
8097             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
8098             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
8099             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
8100             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
8101             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
8102         }
8103
8104                 if (language == EShLangGeometry || language == EShLangVertex) {
8105                         if ((profile == EEsProfile && version >= 310) ||
8106                                 (profile != EEsProfile && version >= 450)) {
8107                                 symbolTable.setVariableExtensions("gl_PrimitiveShadingRateEXT", 1, &E_GL_EXT_fragment_shading_rate);
8108                                 BuiltInVariable("gl_PrimitiveShadingRateEXT", EbvPrimitiveShadingRateKHR, symbolTable);
8109
8110                                 symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8111                                 symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8112                                 symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8113                                 symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8114                         }
8115                 }
8116
8117 #endif // !GLSLANG_WEB
8118         break;
8119
8120     case EShLangFragment:
8121         SpecialQualifier("gl_FrontFacing",      EvqFace,       EbvFace,             symbolTable);
8122         SpecialQualifier("gl_FragCoord",        EvqFragCoord,  EbvFragCoord,        symbolTable);
8123         SpecialQualifier("gl_PointCoord",       EvqPointCoord, EbvPointCoord,       symbolTable);
8124         if (spvVersion.spv == 0)
8125             SpecialQualifier("gl_FragColor",    EvqFragColor,  EbvFragColor,        symbolTable);
8126         else {
8127             TSymbol* symbol = symbolTable.find("gl_FragColor");
8128             if (symbol) {
8129                 symbol->getWritableType().getQualifier().storage = EvqVaryingOut;
8130                 symbol->getWritableType().getQualifier().layoutLocation = 0;
8131             }
8132         }
8133         SpecialQualifier("gl_FragDepth",        EvqFragDepth,  EbvFragDepth,        symbolTable);
8134 #ifndef GLSLANG_WEB
8135         SpecialQualifier("gl_FragDepthEXT",     EvqFragDepth,  EbvFragDepth,        symbolTable);
8136         SpecialQualifier("gl_HelperInvocation", EvqVaryingIn,  EbvHelperInvocation, symbolTable);
8137
8138         BuiltInVariable("gl_ClipDistance",    EbvClipDistance,   symbolTable);
8139         BuiltInVariable("gl_CullDistance",    EbvCullDistance,   symbolTable);
8140         BuiltInVariable("gl_PrimitiveID",     EbvPrimitiveId,    symbolTable);
8141
8142         if (profile != EEsProfile && version >= 140) {
8143             symbolTable.setVariableExtensions("gl_FragStencilRefARB", 1, &E_GL_ARB_shader_stencil_export);
8144             BuiltInVariable("gl_FragStencilRefARB", EbvFragStencilRef, symbolTable);
8145         }
8146
8147         if (profile != EEsProfile && version < 400) {
8148             symbolTable.setFunctionExtensions("textureQueryLod", 1, &E_GL_ARB_texture_query_lod);
8149         }
8150
8151         if (profile != EEsProfile && version >= 460) {
8152             symbolTable.setFunctionExtensions("rayQueryInitializeEXT",                                            1, &E_GL_EXT_ray_query);
8153             symbolTable.setFunctionExtensions("rayQueryTerminateEXT",                                             1, &E_GL_EXT_ray_query);
8154             symbolTable.setFunctionExtensions("rayQueryGenerateIntersectionEXT",                                  1, &E_GL_EXT_ray_query);
8155             symbolTable.setFunctionExtensions("rayQueryConfirmIntersectionEXT",                                   1, &E_GL_EXT_ray_query);
8156             symbolTable.setFunctionExtensions("rayQueryProceedEXT",                                               1, &E_GL_EXT_ray_query);
8157             symbolTable.setFunctionExtensions("rayQueryGetIntersectionTypeEXT",                                   1, &E_GL_EXT_ray_query);
8158             symbolTable.setFunctionExtensions("rayQueryGetIntersectionTEXT",                                      1, &E_GL_EXT_ray_query);
8159             symbolTable.setFunctionExtensions("rayQueryGetRayFlagsEXT",                                           1, &E_GL_EXT_ray_query);
8160             symbolTable.setFunctionExtensions("rayQueryGetRayTMinEXT",                                            1, &E_GL_EXT_ray_query);
8161             symbolTable.setFunctionExtensions("rayQueryGetIntersectionInstanceCustomIndexEXT",                    1, &E_GL_EXT_ray_query);
8162             symbolTable.setFunctionExtensions("rayQueryGetIntersectionInstanceIdEXT",                             1, &E_GL_EXT_ray_query);
8163             symbolTable.setFunctionExtensions("rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT", 1, &E_GL_EXT_ray_query);
8164             symbolTable.setFunctionExtensions("rayQueryGetIntersectionGeometryIndexEXT",                          1, &E_GL_EXT_ray_query);
8165             symbolTable.setFunctionExtensions("rayQueryGetIntersectionPrimitiveIndexEXT",                         1, &E_GL_EXT_ray_query);
8166             symbolTable.setFunctionExtensions("rayQueryGetIntersectionBarycentricsEXT",                           1, &E_GL_EXT_ray_query);
8167             symbolTable.setFunctionExtensions("rayQueryGetIntersectionFrontFaceEXT",                              1, &E_GL_EXT_ray_query);
8168             symbolTable.setFunctionExtensions("rayQueryGetIntersectionCandidateAABBOpaqueEXT",                    1, &E_GL_EXT_ray_query);
8169             symbolTable.setFunctionExtensions("rayQueryGetIntersectionObjectRayDirectionEXT",                     1, &E_GL_EXT_ray_query);
8170             symbolTable.setFunctionExtensions("rayQueryGetIntersectionObjectRayOriginEXT",                        1, &E_GL_EXT_ray_query);
8171             symbolTable.setFunctionExtensions("rayQueryGetIntersectionObjectToWorldEXT",                          1, &E_GL_EXT_ray_query);
8172             symbolTable.setFunctionExtensions("rayQueryGetIntersectionWorldToObjectEXT",                          1, &E_GL_EXT_ray_query);
8173             symbolTable.setFunctionExtensions("rayQueryGetWorldRayOriginEXT",                                     1, &E_GL_EXT_ray_query);
8174             symbolTable.setFunctionExtensions("rayQueryGetWorldRayDirectionEXT",                                  1, &E_GL_EXT_ray_query);
8175             symbolTable.setVariableExtensions("gl_RayFlagsSkipAABBEXT",                         1, &E_GL_EXT_ray_flags_primitive_culling);
8176             symbolTable.setVariableExtensions("gl_RayFlagsSkipTrianglesEXT",                    1, &E_GL_EXT_ray_flags_primitive_culling);
8177         }
8178
8179         if ((profile != EEsProfile && version >= 130) ||
8180             (profile == EEsProfile && version >= 310)) {
8181             BuiltInVariable("gl_SampleID",           EbvSampleId,       symbolTable);
8182             BuiltInVariable("gl_SamplePosition",     EbvSamplePosition, symbolTable);
8183             BuiltInVariable("gl_SampleMask",         EbvSampleMask,     symbolTable);
8184
8185             if (profile != EEsProfile && version < 400) {
8186                 BuiltInVariable("gl_NumSamples",     EbvSampleMask,     symbolTable);
8187
8188                 symbolTable.setVariableExtensions("gl_SampleMask",     1, &E_GL_ARB_sample_shading);
8189                 symbolTable.setVariableExtensions("gl_SampleID",       1, &E_GL_ARB_sample_shading);
8190                 symbolTable.setVariableExtensions("gl_SamplePosition", 1, &E_GL_ARB_sample_shading);
8191                 symbolTable.setVariableExtensions("gl_NumSamples",     1, &E_GL_ARB_sample_shading);
8192             } else {
8193                 BuiltInVariable("gl_SampleMaskIn",    EbvSampleMask,     symbolTable);
8194
8195                 if (profile == EEsProfile && version < 320) {
8196                     symbolTable.setVariableExtensions("gl_SampleID", 1, &E_GL_OES_sample_variables);
8197                     symbolTable.setVariableExtensions("gl_SamplePosition", 1, &E_GL_OES_sample_variables);
8198                     symbolTable.setVariableExtensions("gl_SampleMaskIn", 1, &E_GL_OES_sample_variables);
8199                     symbolTable.setVariableExtensions("gl_SampleMask", 1, &E_GL_OES_sample_variables);
8200                     symbolTable.setVariableExtensions("gl_NumSamples", 1, &E_GL_OES_sample_variables);
8201                 }
8202             }
8203         }
8204
8205         BuiltInVariable("gl_Layer",           EbvLayer,          symbolTable);
8206         BuiltInVariable("gl_ViewportIndex",   EbvViewportIndex,  symbolTable);
8207
8208         // Compatibility variables
8209
8210         BuiltInVariable("gl_in", "gl_FogFragCoord",   EbvFogFragCoord,   symbolTable);
8211         BuiltInVariable("gl_in", "gl_TexCoord",       EbvTexCoord,       symbolTable);
8212         BuiltInVariable("gl_in", "gl_Color",          EbvColor,          symbolTable);
8213         BuiltInVariable("gl_in", "gl_SecondaryColor", EbvSecondaryColor, symbolTable);
8214
8215         BuiltInVariable("gl_FogFragCoord",   EbvFogFragCoord,   symbolTable);
8216         BuiltInVariable("gl_TexCoord",       EbvTexCoord,       symbolTable);
8217         BuiltInVariable("gl_Color",          EbvColor,          symbolTable);
8218         BuiltInVariable("gl_SecondaryColor", EbvSecondaryColor, symbolTable);
8219
8220         // built-in functions
8221
8222         if (profile == EEsProfile) {
8223             if (spvVersion.spv == 0) {
8224                 symbolTable.setFunctionExtensions("texture2DLodEXT",      1, &E_GL_EXT_shader_texture_lod);
8225                 symbolTable.setFunctionExtensions("texture2DProjLodEXT",  1, &E_GL_EXT_shader_texture_lod);
8226                 symbolTable.setFunctionExtensions("textureCubeLodEXT",    1, &E_GL_EXT_shader_texture_lod);
8227                 symbolTable.setFunctionExtensions("texture2DGradEXT",     1, &E_GL_EXT_shader_texture_lod);
8228                 symbolTable.setFunctionExtensions("texture2DProjGradEXT", 1, &E_GL_EXT_shader_texture_lod);
8229                 symbolTable.setFunctionExtensions("textureCubeGradEXT",   1, &E_GL_EXT_shader_texture_lod);
8230                 if (version < 320)
8231                     symbolTable.setFunctionExtensions("textureGatherOffsets", Num_AEP_gpu_shader5, AEP_gpu_shader5);
8232             }
8233             if (version == 100) {
8234                 symbolTable.setFunctionExtensions("dFdx",   1, &E_GL_OES_standard_derivatives);
8235                 symbolTable.setFunctionExtensions("dFdy",   1, &E_GL_OES_standard_derivatives);
8236                 symbolTable.setFunctionExtensions("fwidth", 1, &E_GL_OES_standard_derivatives);
8237             }
8238             if (version == 310) {
8239                 symbolTable.setFunctionExtensions("fma", Num_AEP_gpu_shader5, AEP_gpu_shader5);
8240                 symbolTable.setFunctionExtensions("interpolateAtCentroid", 1, &E_GL_OES_shader_multisample_interpolation);
8241                 symbolTable.setFunctionExtensions("interpolateAtSample",   1, &E_GL_OES_shader_multisample_interpolation);
8242                 symbolTable.setFunctionExtensions("interpolateAtOffset",   1, &E_GL_OES_shader_multisample_interpolation);
8243             }
8244         } else if (version < 130) {
8245             if (spvVersion.spv == 0) {
8246                 symbolTable.setFunctionExtensions("texture1DLod",        1, &E_GL_ARB_shader_texture_lod);
8247                 symbolTable.setFunctionExtensions("texture2DLod",        1, &E_GL_ARB_shader_texture_lod);
8248                 symbolTable.setFunctionExtensions("texture3DLod",        1, &E_GL_ARB_shader_texture_lod);
8249                 symbolTable.setFunctionExtensions("textureCubeLod",      1, &E_GL_ARB_shader_texture_lod);
8250                 symbolTable.setFunctionExtensions("texture1DProjLod",    1, &E_GL_ARB_shader_texture_lod);
8251                 symbolTable.setFunctionExtensions("texture2DProjLod",    1, &E_GL_ARB_shader_texture_lod);
8252                 symbolTable.setFunctionExtensions("texture3DProjLod",    1, &E_GL_ARB_shader_texture_lod);
8253                 symbolTable.setFunctionExtensions("shadow1DLod",         1, &E_GL_ARB_shader_texture_lod);
8254                 symbolTable.setFunctionExtensions("shadow2DLod",         1, &E_GL_ARB_shader_texture_lod);
8255                 symbolTable.setFunctionExtensions("shadow1DProjLod",     1, &E_GL_ARB_shader_texture_lod);
8256                 symbolTable.setFunctionExtensions("shadow2DProjLod",     1, &E_GL_ARB_shader_texture_lod);
8257             }
8258         }
8259
8260         // E_GL_ARB_shader_texture_lod functions usable only with the extension enabled
8261         if (profile != EEsProfile && spvVersion.spv == 0) {
8262             symbolTable.setFunctionExtensions("texture1DGradARB",         1, &E_GL_ARB_shader_texture_lod);
8263             symbolTable.setFunctionExtensions("texture1DProjGradARB",     1, &E_GL_ARB_shader_texture_lod);
8264             symbolTable.setFunctionExtensions("texture2DGradARB",         1, &E_GL_ARB_shader_texture_lod);
8265             symbolTable.setFunctionExtensions("texture2DProjGradARB",     1, &E_GL_ARB_shader_texture_lod);
8266             symbolTable.setFunctionExtensions("texture3DGradARB",         1, &E_GL_ARB_shader_texture_lod);
8267             symbolTable.setFunctionExtensions("texture3DProjGradARB",     1, &E_GL_ARB_shader_texture_lod);
8268             symbolTable.setFunctionExtensions("textureCubeGradARB",       1, &E_GL_ARB_shader_texture_lod);
8269             symbolTable.setFunctionExtensions("shadow1DGradARB",          1, &E_GL_ARB_shader_texture_lod);
8270             symbolTable.setFunctionExtensions("shadow1DProjGradARB",      1, &E_GL_ARB_shader_texture_lod);
8271             symbolTable.setFunctionExtensions("shadow2DGradARB",          1, &E_GL_ARB_shader_texture_lod);
8272             symbolTable.setFunctionExtensions("shadow2DProjGradARB",      1, &E_GL_ARB_shader_texture_lod);
8273             symbolTable.setFunctionExtensions("texture2DRectGradARB",     1, &E_GL_ARB_shader_texture_lod);
8274             symbolTable.setFunctionExtensions("texture2DRectProjGradARB", 1, &E_GL_ARB_shader_texture_lod);
8275             symbolTable.setFunctionExtensions("shadow2DRectGradARB",      1, &E_GL_ARB_shader_texture_lod);
8276             symbolTable.setFunctionExtensions("shadow2DRectProjGradARB",  1, &E_GL_ARB_shader_texture_lod);
8277         }
8278
8279         // E_GL_ARB_shader_image_load_store
8280         if (profile != EEsProfile && version < 420)
8281             symbolTable.setFunctionExtensions("memoryBarrier", 1, &E_GL_ARB_shader_image_load_store);
8282         // All the image access functions are protected by checks on the type of the first argument.
8283
8284         // E_GL_ARB_shader_atomic_counters
8285         if (profile != EEsProfile && version < 420) {
8286             symbolTable.setFunctionExtensions("atomicCounterIncrement", 1, &E_GL_ARB_shader_atomic_counters);
8287             symbolTable.setFunctionExtensions("atomicCounterDecrement", 1, &E_GL_ARB_shader_atomic_counters);
8288             symbolTable.setFunctionExtensions("atomicCounter"         , 1, &E_GL_ARB_shader_atomic_counters);
8289         }
8290
8291         // E_GL_ARB_shader_atomic_counter_ops
8292         if (profile != EEsProfile && version == 450) {
8293             symbolTable.setFunctionExtensions("atomicCounterAddARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8294             symbolTable.setFunctionExtensions("atomicCounterSubtractARB", 1, &E_GL_ARB_shader_atomic_counter_ops);
8295             symbolTable.setFunctionExtensions("atomicCounterMinARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8296             symbolTable.setFunctionExtensions("atomicCounterMaxARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8297             symbolTable.setFunctionExtensions("atomicCounterAndARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8298             symbolTable.setFunctionExtensions("atomicCounterOrARB"      , 1, &E_GL_ARB_shader_atomic_counter_ops);
8299             symbolTable.setFunctionExtensions("atomicCounterXorARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8300             symbolTable.setFunctionExtensions("atomicCounterExchangeARB", 1, &E_GL_ARB_shader_atomic_counter_ops);
8301             symbolTable.setFunctionExtensions("atomicCounterCompSwapARB", 1, &E_GL_ARB_shader_atomic_counter_ops);
8302         }
8303
8304         // E_GL_ARB_derivative_control
8305         if (profile != EEsProfile && version < 450) {
8306             symbolTable.setFunctionExtensions("dFdxFine",     1, &E_GL_ARB_derivative_control);
8307             symbolTable.setFunctionExtensions("dFdyFine",     1, &E_GL_ARB_derivative_control);
8308             symbolTable.setFunctionExtensions("fwidthFine",   1, &E_GL_ARB_derivative_control);
8309             symbolTable.setFunctionExtensions("dFdxCoarse",   1, &E_GL_ARB_derivative_control);
8310             symbolTable.setFunctionExtensions("dFdyCoarse",   1, &E_GL_ARB_derivative_control);
8311             symbolTable.setFunctionExtensions("fwidthCoarse", 1, &E_GL_ARB_derivative_control);
8312         }
8313
8314         // E_GL_ARB_sparse_texture2
8315         if (profile != EEsProfile)
8316         {
8317             symbolTable.setFunctionExtensions("sparseTextureARB",              1, &E_GL_ARB_sparse_texture2);
8318             symbolTable.setFunctionExtensions("sparseTextureLodARB",           1, &E_GL_ARB_sparse_texture2);
8319             symbolTable.setFunctionExtensions("sparseTextureOffsetARB",        1, &E_GL_ARB_sparse_texture2);
8320             symbolTable.setFunctionExtensions("sparseTexelFetchARB",           1, &E_GL_ARB_sparse_texture2);
8321             symbolTable.setFunctionExtensions("sparseTexelFetchOffsetARB",     1, &E_GL_ARB_sparse_texture2);
8322             symbolTable.setFunctionExtensions("sparseTextureLodOffsetARB",     1, &E_GL_ARB_sparse_texture2);
8323             symbolTable.setFunctionExtensions("sparseTextureGradARB",          1, &E_GL_ARB_sparse_texture2);
8324             symbolTable.setFunctionExtensions("sparseTextureGradOffsetARB",    1, &E_GL_ARB_sparse_texture2);
8325             symbolTable.setFunctionExtensions("sparseTextureGatherARB",        1, &E_GL_ARB_sparse_texture2);
8326             symbolTable.setFunctionExtensions("sparseTextureGatherOffsetARB",  1, &E_GL_ARB_sparse_texture2);
8327             symbolTable.setFunctionExtensions("sparseTextureGatherOffsetsARB", 1, &E_GL_ARB_sparse_texture2);
8328             symbolTable.setFunctionExtensions("sparseImageLoadARB",            1, &E_GL_ARB_sparse_texture2);
8329             symbolTable.setFunctionExtensions("sparseTexelsResident",          1, &E_GL_ARB_sparse_texture2);
8330         }
8331
8332         // E_GL_ARB_sparse_texture_clamp
8333         if (profile != EEsProfile)
8334         {
8335             symbolTable.setFunctionExtensions("sparseTextureClampARB",              1, &E_GL_ARB_sparse_texture_clamp);
8336             symbolTable.setFunctionExtensions("sparseTextureOffsetClampARB",        1, &E_GL_ARB_sparse_texture_clamp);
8337             symbolTable.setFunctionExtensions("sparseTextureGradClampARB",          1, &E_GL_ARB_sparse_texture_clamp);
8338             symbolTable.setFunctionExtensions("sparseTextureGradOffsetClampARB",    1, &E_GL_ARB_sparse_texture_clamp);
8339             symbolTable.setFunctionExtensions("textureClampARB",                    1, &E_GL_ARB_sparse_texture_clamp);
8340             symbolTable.setFunctionExtensions("textureOffsetClampARB",              1, &E_GL_ARB_sparse_texture_clamp);
8341             symbolTable.setFunctionExtensions("textureGradClampARB",                1, &E_GL_ARB_sparse_texture_clamp);
8342             symbolTable.setFunctionExtensions("textureGradOffsetClampARB",          1, &E_GL_ARB_sparse_texture_clamp);
8343         }
8344
8345         // E_GL_AMD_shader_explicit_vertex_parameter
8346         if (profile != EEsProfile) {
8347             symbolTable.setVariableExtensions("gl_BaryCoordNoPerspAMD",         1, &E_GL_AMD_shader_explicit_vertex_parameter);
8348             symbolTable.setVariableExtensions("gl_BaryCoordNoPerspCentroidAMD", 1, &E_GL_AMD_shader_explicit_vertex_parameter);
8349             symbolTable.setVariableExtensions("gl_BaryCoordNoPerspSampleAMD",   1, &E_GL_AMD_shader_explicit_vertex_parameter);
8350             symbolTable.setVariableExtensions("gl_BaryCoordSmoothAMD",          1, &E_GL_AMD_shader_explicit_vertex_parameter);
8351             symbolTable.setVariableExtensions("gl_BaryCoordSmoothCentroidAMD",  1, &E_GL_AMD_shader_explicit_vertex_parameter);
8352             symbolTable.setVariableExtensions("gl_BaryCoordSmoothSampleAMD",    1, &E_GL_AMD_shader_explicit_vertex_parameter);
8353             symbolTable.setVariableExtensions("gl_BaryCoordPullModelAMD",       1, &E_GL_AMD_shader_explicit_vertex_parameter);
8354
8355             symbolTable.setFunctionExtensions("interpolateAtVertexAMD",         1, &E_GL_AMD_shader_explicit_vertex_parameter);
8356
8357             BuiltInVariable("gl_BaryCoordNoPerspAMD",           EbvBaryCoordNoPersp,         symbolTable);
8358             BuiltInVariable("gl_BaryCoordNoPerspCentroidAMD",   EbvBaryCoordNoPerspCentroid, symbolTable);
8359             BuiltInVariable("gl_BaryCoordNoPerspSampleAMD",     EbvBaryCoordNoPerspSample,   symbolTable);
8360             BuiltInVariable("gl_BaryCoordSmoothAMD",            EbvBaryCoordSmooth,          symbolTable);
8361             BuiltInVariable("gl_BaryCoordSmoothCentroidAMD",    EbvBaryCoordSmoothCentroid,  symbolTable);
8362             BuiltInVariable("gl_BaryCoordSmoothSampleAMD",      EbvBaryCoordSmoothSample,    symbolTable);
8363             BuiltInVariable("gl_BaryCoordPullModelAMD",         EbvBaryCoordPullModel,       symbolTable);
8364         }
8365
8366         // E_GL_AMD_texture_gather_bias_lod
8367         if (profile != EEsProfile) {
8368             symbolTable.setFunctionExtensions("textureGatherLodAMD",                1, &E_GL_AMD_texture_gather_bias_lod);
8369             symbolTable.setFunctionExtensions("textureGatherLodOffsetAMD",          1, &E_GL_AMD_texture_gather_bias_lod);
8370             symbolTable.setFunctionExtensions("textureGatherLodOffsetsAMD",         1, &E_GL_AMD_texture_gather_bias_lod);
8371             symbolTable.setFunctionExtensions("sparseTextureGatherLodAMD",          1, &E_GL_AMD_texture_gather_bias_lod);
8372             symbolTable.setFunctionExtensions("sparseTextureGatherLodOffsetAMD",    1, &E_GL_AMD_texture_gather_bias_lod);
8373             symbolTable.setFunctionExtensions("sparseTextureGatherLodOffsetsAMD",   1, &E_GL_AMD_texture_gather_bias_lod);
8374         }
8375
8376         // E_GL_AMD_shader_image_load_store_lod
8377         if (profile != EEsProfile) {
8378             symbolTable.setFunctionExtensions("imageLoadLodAMD",        1, &E_GL_AMD_shader_image_load_store_lod);
8379             symbolTable.setFunctionExtensions("imageStoreLodAMD",       1, &E_GL_AMD_shader_image_load_store_lod);
8380             symbolTable.setFunctionExtensions("sparseImageLoadLodAMD",  1, &E_GL_AMD_shader_image_load_store_lod);
8381         }
8382         if (profile != EEsProfile && version >= 430) {
8383             symbolTable.setVariableExtensions("gl_FragFullyCoveredNV", 1, &E_GL_NV_conservative_raster_underestimation);
8384             BuiltInVariable("gl_FragFullyCoveredNV", EbvFragFullyCoveredNV, symbolTable);
8385         }
8386         if ((profile != EEsProfile && version >= 450) ||
8387             (profile == EEsProfile && version >= 320)) {
8388             symbolTable.setVariableExtensions("gl_FragmentSizeNV",        1, &E_GL_NV_shading_rate_image);
8389             symbolTable.setVariableExtensions("gl_InvocationsPerPixelNV", 1, &E_GL_NV_shading_rate_image);
8390             BuiltInVariable("gl_FragmentSizeNV",        EbvFragmentSizeNV, symbolTable);
8391             BuiltInVariable("gl_InvocationsPerPixelNV", EbvInvocationsPerPixelNV, symbolTable);
8392             symbolTable.setVariableExtensions("gl_BaryCoordNV",        1, &E_GL_NV_fragment_shader_barycentric);
8393             symbolTable.setVariableExtensions("gl_BaryCoordNoPerspNV", 1, &E_GL_NV_fragment_shader_barycentric);
8394             BuiltInVariable("gl_BaryCoordNV",        EbvBaryCoordNV,        symbolTable);
8395             BuiltInVariable("gl_BaryCoordNoPerspNV", EbvBaryCoordNoPerspNV, symbolTable);
8396         }
8397
8398         if ((profile != EEsProfile && version >= 450) ||
8399             (profile == EEsProfile && version >= 310)) {
8400             symbolTable.setVariableExtensions("gl_FragSizeEXT",            1, &E_GL_EXT_fragment_invocation_density);
8401             symbolTable.setVariableExtensions("gl_FragInvocationCountEXT", 1, &E_GL_EXT_fragment_invocation_density);
8402             BuiltInVariable("gl_FragSizeEXT",            EbvFragSizeEXT, symbolTable);
8403             BuiltInVariable("gl_FragInvocationCountEXT", EbvFragInvocationCountEXT, symbolTable);
8404         }
8405
8406         symbolTable.setVariableExtensions("gl_FragDepthEXT", 1, &E_GL_EXT_frag_depth);
8407
8408         symbolTable.setFunctionExtensions("clockARB",     1, &E_GL_ARB_shader_clock);
8409         symbolTable.setFunctionExtensions("clock2x32ARB", 1, &E_GL_ARB_shader_clock);
8410
8411         symbolTable.setFunctionExtensions("clockRealtimeEXT",     1, &E_GL_EXT_shader_realtime_clock);
8412         symbolTable.setFunctionExtensions("clockRealtime2x32EXT", 1, &E_GL_EXT_shader_realtime_clock);
8413
8414         if (profile == EEsProfile && version < 320) {
8415             symbolTable.setVariableExtensions("gl_PrimitiveID",  Num_AEP_geometry_shader, AEP_geometry_shader);
8416             symbolTable.setVariableExtensions("gl_Layer",        Num_AEP_geometry_shader, AEP_geometry_shader);
8417         }
8418
8419         if (profile == EEsProfile && version < 320) {
8420             symbolTable.setFunctionExtensions("imageAtomicAdd",      1, &E_GL_OES_shader_image_atomic);
8421             symbolTable.setFunctionExtensions("imageAtomicMin",      1, &E_GL_OES_shader_image_atomic);
8422             symbolTable.setFunctionExtensions("imageAtomicMax",      1, &E_GL_OES_shader_image_atomic);
8423             symbolTable.setFunctionExtensions("imageAtomicAnd",      1, &E_GL_OES_shader_image_atomic);
8424             symbolTable.setFunctionExtensions("imageAtomicOr",       1, &E_GL_OES_shader_image_atomic);
8425             symbolTable.setFunctionExtensions("imageAtomicXor",      1, &E_GL_OES_shader_image_atomic);
8426             symbolTable.setFunctionExtensions("imageAtomicExchange", 1, &E_GL_OES_shader_image_atomic);
8427             symbolTable.setFunctionExtensions("imageAtomicCompSwap", 1, &E_GL_OES_shader_image_atomic);
8428         }
8429
8430         if (profile != EEsProfile && version < 330 ) {
8431             symbolTable.setFunctionExtensions("floatBitsToInt", 1, &E_GL_ARB_shader_bit_encoding);
8432             symbolTable.setFunctionExtensions("floatBitsToUint", 1, &E_GL_ARB_shader_bit_encoding);
8433             symbolTable.setFunctionExtensions("intBitsToFloat", 1, &E_GL_ARB_shader_bit_encoding);
8434             symbolTable.setFunctionExtensions("uintBitsToFloat", 1, &E_GL_ARB_shader_bit_encoding);
8435         }
8436
8437         if (profile != EEsProfile && version < 430 ) {
8438             symbolTable.setFunctionExtensions("imageSize", 1, &E_GL_ARB_shader_image_size);
8439         }
8440
8441         // GL_ARB_shader_storage_buffer_object
8442         if (profile != EEsProfile && version < 430 ) {
8443             symbolTable.setFunctionExtensions("atomicAdd", 1, &E_GL_ARB_shader_storage_buffer_object);
8444             symbolTable.setFunctionExtensions("atomicMin", 1, &E_GL_ARB_shader_storage_buffer_object);
8445             symbolTable.setFunctionExtensions("atomicMax", 1, &E_GL_ARB_shader_storage_buffer_object);
8446             symbolTable.setFunctionExtensions("atomicAnd", 1, &E_GL_ARB_shader_storage_buffer_object);
8447             symbolTable.setFunctionExtensions("atomicOr", 1, &E_GL_ARB_shader_storage_buffer_object);
8448             symbolTable.setFunctionExtensions("atomicXor", 1, &E_GL_ARB_shader_storage_buffer_object);
8449             symbolTable.setFunctionExtensions("atomicExchange", 1, &E_GL_ARB_shader_storage_buffer_object);
8450             symbolTable.setFunctionExtensions("atomicCompSwap", 1, &E_GL_ARB_shader_storage_buffer_object);
8451         }
8452
8453         // GL_ARB_shading_language_packing
8454         if (profile != EEsProfile && version < 400 ) {
8455             symbolTable.setFunctionExtensions("packUnorm2x16", 1, &E_GL_ARB_shading_language_packing);
8456             symbolTable.setFunctionExtensions("unpackUnorm2x16", 1, &E_GL_ARB_shading_language_packing);
8457             symbolTable.setFunctionExtensions("packSnorm4x8", 1, &E_GL_ARB_shading_language_packing);
8458             symbolTable.setFunctionExtensions("packUnorm4x8", 1, &E_GL_ARB_shading_language_packing);
8459             symbolTable.setFunctionExtensions("unpackSnorm4x8", 1, &E_GL_ARB_shading_language_packing);
8460             symbolTable.setFunctionExtensions("unpackUnorm4x8", 1, &E_GL_ARB_shading_language_packing);
8461         }
8462         if (profile != EEsProfile && version < 420 ) {
8463             symbolTable.setFunctionExtensions("packSnorm2x16", 1, &E_GL_ARB_shading_language_packing);
8464             symbolTable.setFunctionExtensions("unpackSnorm2x16", 1, &E_GL_ARB_shading_language_packing);
8465             symbolTable.setFunctionExtensions("unpackHalf2x16", 1, &E_GL_ARB_shading_language_packing);
8466             symbolTable.setFunctionExtensions("packHalf2x16", 1, &E_GL_ARB_shading_language_packing);
8467         }
8468
8469         symbolTable.setVariableExtensions("gl_DeviceIndex",  1, &E_GL_EXT_device_group);
8470         BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
8471         symbolTable.setVariableExtensions("gl_ViewIndex", 1, &E_GL_EXT_multiview);
8472         BuiltInVariable("gl_ViewIndex", EbvViewIndex, symbolTable);
8473         if (version >= 300 /* both ES and non-ES */) {
8474             symbolTable.setVariableExtensions("gl_ViewID_OVR", Num_OVR_multiview_EXTs, OVR_multiview_EXTs);
8475             BuiltInVariable("gl_ViewID_OVR", EbvViewIndex, symbolTable);
8476         }
8477
8478         // GL_ARB_shader_ballot
8479         if (profile != EEsProfile) {
8480             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
8481             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
8482             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
8483             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
8484             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
8485             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
8486             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
8487
8488             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
8489             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
8490             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
8491             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
8492             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
8493             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
8494
8495             if (spvVersion.vulkan > 0)
8496                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
8497                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
8498             else
8499                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
8500         }
8501
8502         // GL_KHR_shader_subgroup
8503         if ((profile == EEsProfile && version >= 310) ||
8504             (profile != EEsProfile && version >= 140)) {
8505             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
8506             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
8507             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8508             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8509             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8510             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8511             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8512
8513             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
8514             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
8515             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
8516             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
8517             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
8518             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
8519             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
8520
8521             symbolTable.setFunctionExtensions("subgroupBarrier",                 1, &E_GL_KHR_shader_subgroup_basic);
8522             symbolTable.setFunctionExtensions("subgroupMemoryBarrier",           1, &E_GL_KHR_shader_subgroup_basic);
8523             symbolTable.setFunctionExtensions("subgroupMemoryBarrierBuffer",     1, &E_GL_KHR_shader_subgroup_basic);
8524             symbolTable.setFunctionExtensions("subgroupMemoryBarrierImage",      1, &E_GL_KHR_shader_subgroup_basic);
8525             symbolTable.setFunctionExtensions("subgroupElect",                   1, &E_GL_KHR_shader_subgroup_basic);
8526             symbolTable.setFunctionExtensions("subgroupAll",                     1, &E_GL_KHR_shader_subgroup_vote);
8527             symbolTable.setFunctionExtensions("subgroupAny",                     1, &E_GL_KHR_shader_subgroup_vote);
8528             symbolTable.setFunctionExtensions("subgroupAllEqual",                1, &E_GL_KHR_shader_subgroup_vote);
8529             symbolTable.setFunctionExtensions("subgroupBroadcast",               1, &E_GL_KHR_shader_subgroup_ballot);
8530             symbolTable.setFunctionExtensions("subgroupBroadcastFirst",          1, &E_GL_KHR_shader_subgroup_ballot);
8531             symbolTable.setFunctionExtensions("subgroupBallot",                  1, &E_GL_KHR_shader_subgroup_ballot);
8532             symbolTable.setFunctionExtensions("subgroupInverseBallot",           1, &E_GL_KHR_shader_subgroup_ballot);
8533             symbolTable.setFunctionExtensions("subgroupBallotBitExtract",        1, &E_GL_KHR_shader_subgroup_ballot);
8534             symbolTable.setFunctionExtensions("subgroupBallotBitCount",          1, &E_GL_KHR_shader_subgroup_ballot);
8535             symbolTable.setFunctionExtensions("subgroupBallotInclusiveBitCount", 1, &E_GL_KHR_shader_subgroup_ballot);
8536             symbolTable.setFunctionExtensions("subgroupBallotExclusiveBitCount", 1, &E_GL_KHR_shader_subgroup_ballot);
8537             symbolTable.setFunctionExtensions("subgroupBallotFindLSB",           1, &E_GL_KHR_shader_subgroup_ballot);
8538             symbolTable.setFunctionExtensions("subgroupBallotFindMSB",           1, &E_GL_KHR_shader_subgroup_ballot);
8539             symbolTable.setFunctionExtensions("subgroupShuffle",                 1, &E_GL_KHR_shader_subgroup_shuffle);
8540             symbolTable.setFunctionExtensions("subgroupShuffleXor",              1, &E_GL_KHR_shader_subgroup_shuffle);
8541             symbolTable.setFunctionExtensions("subgroupShuffleUp",               1, &E_GL_KHR_shader_subgroup_shuffle_relative);
8542             symbolTable.setFunctionExtensions("subgroupShuffleDown",             1, &E_GL_KHR_shader_subgroup_shuffle_relative);
8543             symbolTable.setFunctionExtensions("subgroupAdd",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8544             symbolTable.setFunctionExtensions("subgroupMul",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8545             symbolTable.setFunctionExtensions("subgroupMin",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8546             symbolTable.setFunctionExtensions("subgroupMax",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8547             symbolTable.setFunctionExtensions("subgroupAnd",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8548             symbolTable.setFunctionExtensions("subgroupOr",                      1, &E_GL_KHR_shader_subgroup_arithmetic);
8549             symbolTable.setFunctionExtensions("subgroupXor",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8550             symbolTable.setFunctionExtensions("subgroupInclusiveAdd",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8551             symbolTable.setFunctionExtensions("subgroupInclusiveMul",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8552             symbolTable.setFunctionExtensions("subgroupInclusiveMin",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8553             symbolTable.setFunctionExtensions("subgroupInclusiveMax",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8554             symbolTable.setFunctionExtensions("subgroupInclusiveAnd",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8555             symbolTable.setFunctionExtensions("subgroupInclusiveOr",             1, &E_GL_KHR_shader_subgroup_arithmetic);
8556             symbolTable.setFunctionExtensions("subgroupInclusiveXor",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8557             symbolTable.setFunctionExtensions("subgroupExclusiveAdd",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8558             symbolTable.setFunctionExtensions("subgroupExclusiveMul",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8559             symbolTable.setFunctionExtensions("subgroupExclusiveMin",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8560             symbolTable.setFunctionExtensions("subgroupExclusiveMax",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8561             symbolTable.setFunctionExtensions("subgroupExclusiveAnd",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8562             symbolTable.setFunctionExtensions("subgroupExclusiveOr",             1, &E_GL_KHR_shader_subgroup_arithmetic);
8563             symbolTable.setFunctionExtensions("subgroupExclusiveXor",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8564             symbolTable.setFunctionExtensions("subgroupClusteredAdd",            1, &E_GL_KHR_shader_subgroup_clustered);
8565             symbolTable.setFunctionExtensions("subgroupClusteredMul",            1, &E_GL_KHR_shader_subgroup_clustered);
8566             symbolTable.setFunctionExtensions("subgroupClusteredMin",            1, &E_GL_KHR_shader_subgroup_clustered);
8567             symbolTable.setFunctionExtensions("subgroupClusteredMax",            1, &E_GL_KHR_shader_subgroup_clustered);
8568             symbolTable.setFunctionExtensions("subgroupClusteredAnd",            1, &E_GL_KHR_shader_subgroup_clustered);
8569             symbolTable.setFunctionExtensions("subgroupClusteredOr",             1, &E_GL_KHR_shader_subgroup_clustered);
8570             symbolTable.setFunctionExtensions("subgroupClusteredXor",            1, &E_GL_KHR_shader_subgroup_clustered);
8571             symbolTable.setFunctionExtensions("subgroupQuadBroadcast",           1, &E_GL_KHR_shader_subgroup_quad);
8572             symbolTable.setFunctionExtensions("subgroupQuadSwapHorizontal",      1, &E_GL_KHR_shader_subgroup_quad);
8573             symbolTable.setFunctionExtensions("subgroupQuadSwapVertical",        1, &E_GL_KHR_shader_subgroup_quad);
8574             symbolTable.setFunctionExtensions("subgroupQuadSwapDiagonal",        1, &E_GL_KHR_shader_subgroup_quad);
8575             symbolTable.setFunctionExtensions("subgroupPartitionNV",                          1, &E_GL_NV_shader_subgroup_partitioned);
8576             symbolTable.setFunctionExtensions("subgroupPartitionedAddNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8577             symbolTable.setFunctionExtensions("subgroupPartitionedMulNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8578             symbolTable.setFunctionExtensions("subgroupPartitionedMinNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8579             symbolTable.setFunctionExtensions("subgroupPartitionedMaxNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8580             symbolTable.setFunctionExtensions("subgroupPartitionedAndNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8581             symbolTable.setFunctionExtensions("subgroupPartitionedOrNV",                      1, &E_GL_NV_shader_subgroup_partitioned);
8582             symbolTable.setFunctionExtensions("subgroupPartitionedXorNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8583             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveAddNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8584             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveMulNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8585             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveMinNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8586             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveMaxNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8587             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveAndNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8588             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveOrNV",             1, &E_GL_NV_shader_subgroup_partitioned);
8589             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveXorNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8590             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveAddNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8591             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveMulNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8592             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveMinNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8593             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveMaxNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8594             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveAndNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8595             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveOrNV",             1, &E_GL_NV_shader_subgroup_partitioned);
8596             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveXorNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8597
8598             // GL_NV_shader_sm_builtins
8599             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
8600             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
8601             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
8602             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
8603             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
8604             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
8605             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
8606             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
8607         }
8608
8609         if (profile == EEsProfile) {
8610             symbolTable.setFunctionExtensions("shadow2DEXT",        1, &E_GL_EXT_shadow_samplers);
8611             symbolTable.setFunctionExtensions("shadow2DProjEXT",    1, &E_GL_EXT_shadow_samplers);
8612         }
8613
8614         if (spvVersion.vulkan > 0) {
8615             symbolTable.setVariableExtensions("gl_ScopeDevice",             1, &E_GL_KHR_memory_scope_semantics);
8616             symbolTable.setVariableExtensions("gl_ScopeWorkgroup",          1, &E_GL_KHR_memory_scope_semantics);
8617             symbolTable.setVariableExtensions("gl_ScopeSubgroup",           1, &E_GL_KHR_memory_scope_semantics);
8618             symbolTable.setVariableExtensions("gl_ScopeInvocation",         1, &E_GL_KHR_memory_scope_semantics);
8619
8620             symbolTable.setVariableExtensions("gl_SemanticsRelaxed",        1, &E_GL_KHR_memory_scope_semantics);
8621             symbolTable.setVariableExtensions("gl_SemanticsAcquire",        1, &E_GL_KHR_memory_scope_semantics);
8622             symbolTable.setVariableExtensions("gl_SemanticsRelease",        1, &E_GL_KHR_memory_scope_semantics);
8623             symbolTable.setVariableExtensions("gl_SemanticsAcquireRelease", 1, &E_GL_KHR_memory_scope_semantics);
8624             symbolTable.setVariableExtensions("gl_SemanticsMakeAvailable",  1, &E_GL_KHR_memory_scope_semantics);
8625             symbolTable.setVariableExtensions("gl_SemanticsMakeVisible",    1, &E_GL_KHR_memory_scope_semantics);
8626             symbolTable.setVariableExtensions("gl_SemanticsVolatile",       1, &E_GL_KHR_memory_scope_semantics);
8627
8628             symbolTable.setVariableExtensions("gl_StorageSemanticsNone",    1, &E_GL_KHR_memory_scope_semantics);
8629             symbolTable.setVariableExtensions("gl_StorageSemanticsBuffer",  1, &E_GL_KHR_memory_scope_semantics);
8630             symbolTable.setVariableExtensions("gl_StorageSemanticsShared",  1, &E_GL_KHR_memory_scope_semantics);
8631             symbolTable.setVariableExtensions("gl_StorageSemanticsImage",   1, &E_GL_KHR_memory_scope_semantics);
8632             symbolTable.setVariableExtensions("gl_StorageSemanticsOutput",  1, &E_GL_KHR_memory_scope_semantics);
8633         }
8634
8635         symbolTable.setFunctionExtensions("helperInvocationEXT",            1, &E_GL_EXT_demote_to_helper_invocation);
8636
8637         if ((profile == EEsProfile && version >= 310) ||
8638             (profile != EEsProfile && version >= 450)) {
8639             symbolTable.setVariableExtensions("gl_ShadingRateEXT", 1, &E_GL_EXT_fragment_shading_rate);
8640             BuiltInVariable("gl_ShadingRateEXT", EbvShadingRateKHR, symbolTable);
8641
8642             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8643             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8644             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8645             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8646         }
8647 #endif // !GLSLANG_WEB
8648         break;
8649
8650     case EShLangCompute:
8651         BuiltInVariable("gl_NumWorkGroups",         EbvNumWorkGroups,        symbolTable);
8652         BuiltInVariable("gl_WorkGroupSize",         EbvWorkGroupSize,        symbolTable);
8653         BuiltInVariable("gl_WorkGroupID",           EbvWorkGroupId,          symbolTable);
8654         BuiltInVariable("gl_LocalInvocationID",     EbvLocalInvocationId,    symbolTable);
8655         BuiltInVariable("gl_GlobalInvocationID",    EbvGlobalInvocationId,   symbolTable);
8656         BuiltInVariable("gl_LocalInvocationIndex",  EbvLocalInvocationIndex, symbolTable);
8657         BuiltInVariable("gl_DeviceIndex",           EbvDeviceIndex,          symbolTable);
8658         BuiltInVariable("gl_ViewIndex",             EbvViewIndex,            symbolTable);
8659
8660 #ifndef GLSLANG_WEB
8661         if ((profile != EEsProfile && version >= 140) ||
8662             (profile == EEsProfile && version >= 310)) {
8663             symbolTable.setVariableExtensions("gl_DeviceIndex",  1, &E_GL_EXT_device_group);
8664             symbolTable.setVariableExtensions("gl_ViewIndex",    1, &E_GL_EXT_multiview);
8665         }
8666
8667         if (profile != EEsProfile && version < 430) {
8668             symbolTable.setVariableExtensions("gl_NumWorkGroups",        1, &E_GL_ARB_compute_shader);
8669             symbolTable.setVariableExtensions("gl_WorkGroupSize",        1, &E_GL_ARB_compute_shader);
8670             symbolTable.setVariableExtensions("gl_WorkGroupID",          1, &E_GL_ARB_compute_shader);
8671             symbolTable.setVariableExtensions("gl_LocalInvocationID",    1, &E_GL_ARB_compute_shader);
8672             symbolTable.setVariableExtensions("gl_GlobalInvocationID",   1, &E_GL_ARB_compute_shader);
8673             symbolTable.setVariableExtensions("gl_LocalInvocationIndex", 1, &E_GL_ARB_compute_shader);
8674
8675             symbolTable.setVariableExtensions("gl_MaxComputeWorkGroupCount",       1, &E_GL_ARB_compute_shader);
8676             symbolTable.setVariableExtensions("gl_MaxComputeWorkGroupSize",        1, &E_GL_ARB_compute_shader);
8677             symbolTable.setVariableExtensions("gl_MaxComputeUniformComponents",    1, &E_GL_ARB_compute_shader);
8678             symbolTable.setVariableExtensions("gl_MaxComputeTextureImageUnits",    1, &E_GL_ARB_compute_shader);
8679             symbolTable.setVariableExtensions("gl_MaxComputeImageUniforms",        1, &E_GL_ARB_compute_shader);
8680             symbolTable.setVariableExtensions("gl_MaxComputeAtomicCounters",       1, &E_GL_ARB_compute_shader);
8681             symbolTable.setVariableExtensions("gl_MaxComputeAtomicCounterBuffers", 1, &E_GL_ARB_compute_shader);
8682
8683             symbolTable.setFunctionExtensions("barrier",                    1, &E_GL_ARB_compute_shader);
8684             symbolTable.setFunctionExtensions("memoryBarrierAtomicCounter", 1, &E_GL_ARB_compute_shader);
8685             symbolTable.setFunctionExtensions("memoryBarrierBuffer",        1, &E_GL_ARB_compute_shader);
8686             symbolTable.setFunctionExtensions("memoryBarrierImage",         1, &E_GL_ARB_compute_shader);
8687             symbolTable.setFunctionExtensions("memoryBarrierShared",        1, &E_GL_ARB_compute_shader);
8688             symbolTable.setFunctionExtensions("groupMemoryBarrier",         1, &E_GL_ARB_compute_shader);
8689         }
8690
8691
8692         symbolTable.setFunctionExtensions("controlBarrier",                 1, &E_GL_KHR_memory_scope_semantics);
8693         symbolTable.setFunctionExtensions("debugPrintfEXT",                 1, &E_GL_EXT_debug_printf);
8694
8695         // GL_ARB_shader_ballot
8696         if (profile != EEsProfile) {
8697             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
8698             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
8699             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
8700             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
8701             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
8702             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
8703             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
8704
8705             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
8706             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
8707             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
8708             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
8709             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
8710             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
8711
8712             if (spvVersion.vulkan > 0)
8713                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
8714                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
8715             else
8716                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
8717         }
8718
8719         // GL_KHR_shader_subgroup
8720         if ((profile == EEsProfile && version >= 310) ||
8721             (profile != EEsProfile && version >= 140)) {
8722             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
8723             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
8724             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8725             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8726             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8727             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8728             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8729
8730             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
8731             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
8732             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
8733             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
8734             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
8735             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
8736             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
8737
8738             // GL_NV_shader_sm_builtins
8739             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
8740             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
8741             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
8742             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
8743             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
8744             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
8745             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
8746             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
8747         }
8748
8749         // GL_KHR_shader_subgroup
8750         if ((profile == EEsProfile && version >= 310) ||
8751             (profile != EEsProfile && version >= 140)) {
8752             symbolTable.setVariableExtensions("gl_NumSubgroups", 1, &E_GL_KHR_shader_subgroup_basic);
8753             symbolTable.setVariableExtensions("gl_SubgroupID",   1, &E_GL_KHR_shader_subgroup_basic);
8754
8755             BuiltInVariable("gl_NumSubgroups", EbvNumSubgroups, symbolTable);
8756             BuiltInVariable("gl_SubgroupID",   EbvSubgroupID,   symbolTable);
8757
8758             symbolTable.setFunctionExtensions("subgroupMemoryBarrierShared", 1, &E_GL_KHR_shader_subgroup_basic);
8759         }
8760
8761         {
8762             const char *coopExt[2] = { E_GL_NV_cooperative_matrix, E_GL_NV_integer_cooperative_matrix };
8763             symbolTable.setFunctionExtensions("coopMatLoadNV",   2, coopExt);
8764             symbolTable.setFunctionExtensions("coopMatStoreNV",  2, coopExt);
8765             symbolTable.setFunctionExtensions("coopMatMulAddNV", 2, coopExt);
8766         }
8767
8768         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
8769             symbolTable.setFunctionExtensions("dFdx",                   1, &E_GL_NV_compute_shader_derivatives);
8770             symbolTable.setFunctionExtensions("dFdy",                   1, &E_GL_NV_compute_shader_derivatives);
8771             symbolTable.setFunctionExtensions("fwidth",                 1, &E_GL_NV_compute_shader_derivatives);
8772             symbolTable.setFunctionExtensions("dFdxFine",               1, &E_GL_NV_compute_shader_derivatives);
8773             symbolTable.setFunctionExtensions("dFdyFine",               1, &E_GL_NV_compute_shader_derivatives);
8774             symbolTable.setFunctionExtensions("fwidthFine",             1, &E_GL_NV_compute_shader_derivatives);
8775             symbolTable.setFunctionExtensions("dFdxCoarse",             1, &E_GL_NV_compute_shader_derivatives);
8776             symbolTable.setFunctionExtensions("dFdyCoarse",             1, &E_GL_NV_compute_shader_derivatives);
8777             symbolTable.setFunctionExtensions("fwidthCoarse",           1, &E_GL_NV_compute_shader_derivatives);
8778         }
8779
8780         if ((profile == EEsProfile && version >= 310) ||
8781             (profile != EEsProfile && version >= 450)) {
8782             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8783             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8784             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8785             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8786         }
8787 #endif // !GLSLANG_WEB
8788         break;
8789
8790 #if !defined(GLSLANG_WEB) && !defined(GLSLANG_ANGLE)
8791     case EShLangRayGen:
8792     case EShLangIntersect:
8793     case EShLangAnyHit:
8794     case EShLangClosestHit:
8795     case EShLangMiss:
8796     case EShLangCallable:
8797         if (profile != EEsProfile && version >= 460) {
8798             const char *rtexts[] = { E_GL_NV_ray_tracing, E_GL_EXT_ray_tracing };
8799             symbolTable.setVariableExtensions("gl_LaunchIDNV", 1, &E_GL_NV_ray_tracing);
8800             symbolTable.setVariableExtensions("gl_LaunchIDEXT", 1, &E_GL_EXT_ray_tracing);
8801             symbolTable.setVariableExtensions("gl_LaunchSizeNV", 1, &E_GL_NV_ray_tracing);
8802             symbolTable.setVariableExtensions("gl_LaunchSizeEXT", 1, &E_GL_EXT_ray_tracing);
8803             symbolTable.setVariableExtensions("gl_PrimitiveID", 2, rtexts);
8804             symbolTable.setVariableExtensions("gl_InstanceID", 2, rtexts);
8805             symbolTable.setVariableExtensions("gl_InstanceCustomIndexNV", 1, &E_GL_NV_ray_tracing);
8806             symbolTable.setVariableExtensions("gl_InstanceCustomIndexEXT", 1, &E_GL_EXT_ray_tracing);
8807             symbolTable.setVariableExtensions("gl_GeometryIndexEXT", 1, &E_GL_EXT_ray_tracing);
8808             symbolTable.setVariableExtensions("gl_WorldRayOriginNV", 1, &E_GL_NV_ray_tracing);
8809             symbolTable.setVariableExtensions("gl_WorldRayOriginEXT", 1, &E_GL_EXT_ray_tracing);
8810             symbolTable.setVariableExtensions("gl_WorldRayDirectionNV", 1, &E_GL_NV_ray_tracing);
8811             symbolTable.setVariableExtensions("gl_WorldRayDirectionEXT", 1, &E_GL_EXT_ray_tracing);
8812             symbolTable.setVariableExtensions("gl_ObjectRayOriginNV", 1, &E_GL_NV_ray_tracing);
8813             symbolTable.setVariableExtensions("gl_ObjectRayOriginEXT", 1, &E_GL_EXT_ray_tracing);
8814             symbolTable.setVariableExtensions("gl_ObjectRayDirectionNV", 1, &E_GL_NV_ray_tracing);
8815             symbolTable.setVariableExtensions("gl_ObjectRayDirectionEXT", 1, &E_GL_EXT_ray_tracing);
8816             symbolTable.setVariableExtensions("gl_RayTminNV", 1, &E_GL_NV_ray_tracing);
8817             symbolTable.setVariableExtensions("gl_RayTminEXT", 1, &E_GL_EXT_ray_tracing);
8818             symbolTable.setVariableExtensions("gl_RayTmaxNV", 1, &E_GL_NV_ray_tracing);
8819             symbolTable.setVariableExtensions("gl_RayTmaxEXT", 1, &E_GL_EXT_ray_tracing);
8820             symbolTable.setVariableExtensions("gl_HitTNV", 1, &E_GL_NV_ray_tracing);
8821             symbolTable.setVariableExtensions("gl_HitTEXT", 1, &E_GL_EXT_ray_tracing);
8822             symbolTable.setVariableExtensions("gl_HitKindNV", 1, &E_GL_NV_ray_tracing);
8823             symbolTable.setVariableExtensions("gl_HitKindEXT", 1, &E_GL_EXT_ray_tracing);
8824             symbolTable.setVariableExtensions("gl_ObjectToWorldNV", 1, &E_GL_NV_ray_tracing);
8825             symbolTable.setVariableExtensions("gl_ObjectToWorldEXT", 1, &E_GL_EXT_ray_tracing);
8826             symbolTable.setVariableExtensions("gl_ObjectToWorld3x4EXT", 1, &E_GL_EXT_ray_tracing);
8827             symbolTable.setVariableExtensions("gl_WorldToObjectNV", 1, &E_GL_NV_ray_tracing);
8828             symbolTable.setVariableExtensions("gl_WorldToObjectEXT", 1, &E_GL_EXT_ray_tracing);
8829             symbolTable.setVariableExtensions("gl_WorldToObject3x4EXT", 1, &E_GL_EXT_ray_tracing);
8830             symbolTable.setVariableExtensions("gl_IncomingRayFlagsNV", 1, &E_GL_NV_ray_tracing);
8831             symbolTable.setVariableExtensions("gl_IncomingRayFlagsEXT", 1, &E_GL_EXT_ray_tracing);
8832             symbolTable.setVariableExtensions("gl_CurrentRayTimeNV", 1, &E_GL_NV_ray_tracing_motion_blur);
8833
8834             symbolTable.setVariableExtensions("gl_DeviceIndex", 1, &E_GL_EXT_device_group);
8835
8836
8837             symbolTable.setFunctionExtensions("traceNV", 1, &E_GL_NV_ray_tracing);
8838             symbolTable.setFunctionExtensions("traceRayMotionNV", 1, &E_GL_NV_ray_tracing_motion_blur);
8839             symbolTable.setFunctionExtensions("traceRayEXT", 1, &E_GL_EXT_ray_tracing);
8840             symbolTable.setFunctionExtensions("reportIntersectionNV", 1, &E_GL_NV_ray_tracing);
8841             symbolTable.setFunctionExtensions("reportIntersectionEXT", 1, &E_GL_EXT_ray_tracing);
8842             symbolTable.setFunctionExtensions("ignoreIntersectionNV", 1, &E_GL_NV_ray_tracing);
8843             symbolTable.setFunctionExtensions("terminateRayNV", 1, &E_GL_NV_ray_tracing);
8844             symbolTable.setFunctionExtensions("executeCallableNV", 1, &E_GL_NV_ray_tracing);
8845             symbolTable.setFunctionExtensions("executeCallableEXT", 1, &E_GL_EXT_ray_tracing);
8846
8847
8848             BuiltInVariable("gl_LaunchIDNV",             EbvLaunchId,           symbolTable);
8849             BuiltInVariable("gl_LaunchIDEXT",            EbvLaunchId,           symbolTable);
8850             BuiltInVariable("gl_LaunchSizeNV",           EbvLaunchSize,         symbolTable);
8851             BuiltInVariable("gl_LaunchSizeEXT",          EbvLaunchSize,         symbolTable);
8852             BuiltInVariable("gl_PrimitiveID",            EbvPrimitiveId,        symbolTable);
8853             BuiltInVariable("gl_InstanceID",             EbvInstanceId,         symbolTable);
8854             BuiltInVariable("gl_InstanceCustomIndexNV",  EbvInstanceCustomIndex,symbolTable);
8855             BuiltInVariable("gl_InstanceCustomIndexEXT", EbvInstanceCustomIndex,symbolTable);
8856             BuiltInVariable("gl_GeometryIndexEXT",       EbvGeometryIndex,      symbolTable);
8857             BuiltInVariable("gl_WorldRayOriginNV",       EbvWorldRayOrigin,     symbolTable);
8858             BuiltInVariable("gl_WorldRayOriginEXT",      EbvWorldRayOrigin,     symbolTable);
8859             BuiltInVariable("gl_WorldRayDirectionNV",    EbvWorldRayDirection,  symbolTable);
8860             BuiltInVariable("gl_WorldRayDirectionEXT",   EbvWorldRayDirection,  symbolTable);
8861             BuiltInVariable("gl_ObjectRayOriginNV",      EbvObjectRayOrigin,    symbolTable);
8862             BuiltInVariable("gl_ObjectRayOriginEXT",     EbvObjectRayOrigin,    symbolTable);
8863             BuiltInVariable("gl_ObjectRayDirectionNV",   EbvObjectRayDirection, symbolTable);
8864             BuiltInVariable("gl_ObjectRayDirectionEXT",  EbvObjectRayDirection, symbolTable);
8865             BuiltInVariable("gl_RayTminNV",              EbvRayTmin,            symbolTable);
8866             BuiltInVariable("gl_RayTminEXT",             EbvRayTmin,            symbolTable);
8867             BuiltInVariable("gl_RayTmaxNV",              EbvRayTmax,            symbolTable);
8868             BuiltInVariable("gl_RayTmaxEXT",             EbvRayTmax,            symbolTable);
8869             BuiltInVariable("gl_HitTNV",                 EbvHitT,               symbolTable);
8870             BuiltInVariable("gl_HitTEXT",                EbvHitT,               symbolTable);
8871             BuiltInVariable("gl_HitKindNV",              EbvHitKind,            symbolTable);
8872             BuiltInVariable("gl_HitKindEXT",             EbvHitKind,            symbolTable);
8873             BuiltInVariable("gl_ObjectToWorldNV",        EbvObjectToWorld,      symbolTable);
8874             BuiltInVariable("gl_ObjectToWorldEXT",       EbvObjectToWorld,      symbolTable);
8875             BuiltInVariable("gl_ObjectToWorld3x4EXT",    EbvObjectToWorld3x4,   symbolTable);
8876             BuiltInVariable("gl_WorldToObjectNV",        EbvWorldToObject,      symbolTable);
8877             BuiltInVariable("gl_WorldToObjectEXT",       EbvWorldToObject,      symbolTable);
8878             BuiltInVariable("gl_WorldToObject3x4EXT",    EbvWorldToObject3x4,   symbolTable);
8879             BuiltInVariable("gl_IncomingRayFlagsNV",     EbvIncomingRayFlags,   symbolTable);
8880             BuiltInVariable("gl_IncomingRayFlagsEXT",    EbvIncomingRayFlags,   symbolTable);
8881             BuiltInVariable("gl_DeviceIndex",            EbvDeviceIndex,        symbolTable);
8882             BuiltInVariable("gl_CurrentRayTimeNV",       EbvCurrentRayTimeNV,   symbolTable);
8883
8884             // GL_ARB_shader_ballot
8885             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
8886             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
8887             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
8888             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
8889             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
8890             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
8891             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
8892
8893             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
8894             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
8895             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
8896             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
8897             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
8898             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
8899
8900             if (spvVersion.vulkan > 0)
8901                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
8902                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
8903             else
8904                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
8905
8906             // GL_KHR_shader_subgroup
8907             symbolTable.setVariableExtensions("gl_NumSubgroups",         1, &E_GL_KHR_shader_subgroup_basic);
8908             symbolTable.setVariableExtensions("gl_SubgroupID",           1, &E_GL_KHR_shader_subgroup_basic);
8909             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
8910             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
8911             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8912             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8913             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8914             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8915             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8916
8917             BuiltInVariable("gl_NumSubgroups",         EbvNumSubgroups,        symbolTable);
8918             BuiltInVariable("gl_SubgroupID",           EbvSubgroupID,          symbolTable);
8919             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
8920             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
8921             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
8922             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
8923             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
8924             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
8925             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
8926
8927             // GL_NV_shader_sm_builtins
8928             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
8929             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
8930             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
8931             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
8932             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
8933             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
8934             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
8935             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
8936         }
8937         if ((profile == EEsProfile && version >= 310) ||
8938             (profile != EEsProfile && version >= 450)) {
8939             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8940             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8941             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8942             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8943         }
8944         break;
8945
8946     case EShLangMeshNV:
8947         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
8948             // per-vertex builtins
8949             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_Position",     1, &E_GL_NV_mesh_shader);
8950             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_PointSize",    1, &E_GL_NV_mesh_shader);
8951             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_ClipDistance", 1, &E_GL_NV_mesh_shader);
8952             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_CullDistance", 1, &E_GL_NV_mesh_shader);
8953
8954             BuiltInVariable("gl_MeshVerticesNV", "gl_Position",     EbvPosition,     symbolTable);
8955             BuiltInVariable("gl_MeshVerticesNV", "gl_PointSize",    EbvPointSize,    symbolTable);
8956             BuiltInVariable("gl_MeshVerticesNV", "gl_ClipDistance", EbvClipDistance, symbolTable);
8957             BuiltInVariable("gl_MeshVerticesNV", "gl_CullDistance", EbvCullDistance, symbolTable);
8958
8959             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_PositionPerViewNV",     1, &E_GL_NV_mesh_shader);
8960             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_ClipDistancePerViewNV", 1, &E_GL_NV_mesh_shader);
8961             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_CullDistancePerViewNV", 1, &E_GL_NV_mesh_shader);
8962
8963             BuiltInVariable("gl_MeshVerticesNV", "gl_PositionPerViewNV",     EbvPositionPerViewNV,     symbolTable);
8964             BuiltInVariable("gl_MeshVerticesNV", "gl_ClipDistancePerViewNV", EbvClipDistancePerViewNV, symbolTable);
8965             BuiltInVariable("gl_MeshVerticesNV", "gl_CullDistancePerViewNV", EbvCullDistancePerViewNV, symbolTable);
8966
8967             // per-primitive builtins
8968             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_PrimitiveID",   1, &E_GL_NV_mesh_shader);
8969             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_Layer",         1, &E_GL_NV_mesh_shader);
8970             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_ViewportIndex", 1, &E_GL_NV_mesh_shader);
8971             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_ViewportMask",  1, &E_GL_NV_mesh_shader);
8972
8973             BuiltInVariable("gl_MeshPrimitivesNV", "gl_PrimitiveID",   EbvPrimitiveId,    symbolTable);
8974             BuiltInVariable("gl_MeshPrimitivesNV", "gl_Layer",         EbvLayer,          symbolTable);
8975             BuiltInVariable("gl_MeshPrimitivesNV", "gl_ViewportIndex", EbvViewportIndex,  symbolTable);
8976             BuiltInVariable("gl_MeshPrimitivesNV", "gl_ViewportMask",  EbvViewportMaskNV, symbolTable);
8977
8978             // per-view per-primitive builtins
8979             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_LayerPerViewNV",        1, &E_GL_NV_mesh_shader);
8980             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_ViewportMaskPerViewNV", 1, &E_GL_NV_mesh_shader);
8981
8982             BuiltInVariable("gl_MeshPrimitivesNV", "gl_LayerPerViewNV",        EbvLayerPerViewNV,        symbolTable);
8983             BuiltInVariable("gl_MeshPrimitivesNV", "gl_ViewportMaskPerViewNV", EbvViewportMaskPerViewNV, symbolTable);
8984
8985             // other builtins
8986             symbolTable.setVariableExtensions("gl_PrimitiveCountNV",     1, &E_GL_NV_mesh_shader);
8987             symbolTable.setVariableExtensions("gl_PrimitiveIndicesNV",   1, &E_GL_NV_mesh_shader);
8988             symbolTable.setVariableExtensions("gl_MeshViewCountNV",      1, &E_GL_NV_mesh_shader);
8989             symbolTable.setVariableExtensions("gl_MeshViewIndicesNV",    1, &E_GL_NV_mesh_shader);
8990             symbolTable.setVariableExtensions("gl_WorkGroupSize",        1, &E_GL_NV_mesh_shader);
8991             symbolTable.setVariableExtensions("gl_WorkGroupID",          1, &E_GL_NV_mesh_shader);
8992             symbolTable.setVariableExtensions("gl_LocalInvocationID",    1, &E_GL_NV_mesh_shader);
8993             symbolTable.setVariableExtensions("gl_GlobalInvocationID",   1, &E_GL_NV_mesh_shader);
8994             symbolTable.setVariableExtensions("gl_LocalInvocationIndex", 1, &E_GL_NV_mesh_shader);
8995
8996             BuiltInVariable("gl_PrimitiveCountNV",     EbvPrimitiveCountNV,     symbolTable);
8997             BuiltInVariable("gl_PrimitiveIndicesNV",   EbvPrimitiveIndicesNV,   symbolTable);
8998             BuiltInVariable("gl_MeshViewCountNV",      EbvMeshViewCountNV,      symbolTable);
8999             BuiltInVariable("gl_MeshViewIndicesNV",    EbvMeshViewIndicesNV,    symbolTable);
9000             BuiltInVariable("gl_WorkGroupSize",        EbvWorkGroupSize,        symbolTable);
9001             BuiltInVariable("gl_WorkGroupID",          EbvWorkGroupId,          symbolTable);
9002             BuiltInVariable("gl_LocalInvocationID",    EbvLocalInvocationId,    symbolTable);
9003             BuiltInVariable("gl_GlobalInvocationID",   EbvGlobalInvocationId,   symbolTable);
9004             BuiltInVariable("gl_LocalInvocationIndex", EbvLocalInvocationIndex, symbolTable);
9005
9006             // builtin constants
9007             symbolTable.setVariableExtensions("gl_MaxMeshOutputVerticesNV",   1, &E_GL_NV_mesh_shader);
9008             symbolTable.setVariableExtensions("gl_MaxMeshOutputPrimitivesNV", 1, &E_GL_NV_mesh_shader);
9009             symbolTable.setVariableExtensions("gl_MaxMeshWorkGroupSizeNV",    1, &E_GL_NV_mesh_shader);
9010             symbolTable.setVariableExtensions("gl_MaxMeshViewCountNV",        1, &E_GL_NV_mesh_shader);
9011
9012             // builtin functions
9013             symbolTable.setFunctionExtensions("barrier",                      1, &E_GL_NV_mesh_shader);
9014             symbolTable.setFunctionExtensions("memoryBarrierShared",          1, &E_GL_NV_mesh_shader);
9015             symbolTable.setFunctionExtensions("groupMemoryBarrier",           1, &E_GL_NV_mesh_shader);
9016         }
9017
9018         if (profile != EEsProfile && version >= 450) {
9019             // GL_EXT_device_group
9020             symbolTable.setVariableExtensions("gl_DeviceIndex", 1, &E_GL_EXT_device_group);
9021             BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
9022
9023             // GL_ARB_shader_draw_parameters
9024             symbolTable.setVariableExtensions("gl_DrawIDARB", 1, &E_GL_ARB_shader_draw_parameters);
9025             BuiltInVariable("gl_DrawIDARB", EbvDrawId, symbolTable);
9026             if (version >= 460) {
9027                 BuiltInVariable("gl_DrawID", EbvDrawId, symbolTable);
9028             }
9029
9030             // GL_ARB_shader_ballot
9031             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
9032             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
9033             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
9034             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
9035             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
9036             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
9037             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
9038
9039             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
9040             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
9041             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
9042             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
9043             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
9044             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
9045
9046             if (spvVersion.vulkan > 0)
9047                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
9048                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
9049             else
9050                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
9051         }
9052
9053         // GL_KHR_shader_subgroup
9054         if ((profile == EEsProfile && version >= 310) ||
9055             (profile != EEsProfile && version >= 140)) {
9056             symbolTable.setVariableExtensions("gl_NumSubgroups",         1, &E_GL_KHR_shader_subgroup_basic);
9057             symbolTable.setVariableExtensions("gl_SubgroupID",           1, &E_GL_KHR_shader_subgroup_basic);
9058             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
9059             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
9060             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9061             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9062             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9063             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9064             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9065
9066             BuiltInVariable("gl_NumSubgroups",         EbvNumSubgroups,        symbolTable);
9067             BuiltInVariable("gl_SubgroupID",           EbvSubgroupID,          symbolTable);
9068             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
9069             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
9070             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
9071             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
9072             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
9073             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
9074             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
9075
9076             symbolTable.setFunctionExtensions("subgroupMemoryBarrierShared", 1, &E_GL_KHR_shader_subgroup_basic);
9077
9078             // GL_NV_shader_sm_builtins
9079             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
9080             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
9081             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
9082             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
9083             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
9084             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
9085             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
9086             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
9087         }
9088
9089         if ((profile == EEsProfile && version >= 310) ||
9090             (profile != EEsProfile && version >= 450)) {
9091             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9092             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9093             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9094             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9095         }
9096         break;
9097
9098     case EShLangTaskNV:
9099         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
9100             symbolTable.setVariableExtensions("gl_TaskCountNV",          1, &E_GL_NV_mesh_shader);
9101             symbolTable.setVariableExtensions("gl_WorkGroupSize",        1, &E_GL_NV_mesh_shader);
9102             symbolTable.setVariableExtensions("gl_WorkGroupID",          1, &E_GL_NV_mesh_shader);
9103             symbolTable.setVariableExtensions("gl_LocalInvocationID",    1, &E_GL_NV_mesh_shader);
9104             symbolTable.setVariableExtensions("gl_GlobalInvocationID",   1, &E_GL_NV_mesh_shader);
9105             symbolTable.setVariableExtensions("gl_LocalInvocationIndex", 1, &E_GL_NV_mesh_shader);
9106             symbolTable.setVariableExtensions("gl_MeshViewCountNV",      1, &E_GL_NV_mesh_shader);
9107             symbolTable.setVariableExtensions("gl_MeshViewIndicesNV",    1, &E_GL_NV_mesh_shader);
9108
9109             BuiltInVariable("gl_TaskCountNV",          EbvTaskCountNV,          symbolTable);
9110             BuiltInVariable("gl_WorkGroupSize",        EbvWorkGroupSize,        symbolTable);
9111             BuiltInVariable("gl_WorkGroupID",          EbvWorkGroupId,          symbolTable);
9112             BuiltInVariable("gl_LocalInvocationID",    EbvLocalInvocationId,    symbolTable);
9113             BuiltInVariable("gl_GlobalInvocationID",   EbvGlobalInvocationId,   symbolTable);
9114             BuiltInVariable("gl_LocalInvocationIndex", EbvLocalInvocationIndex, symbolTable);
9115             BuiltInVariable("gl_MeshViewCountNV",      EbvMeshViewCountNV,      symbolTable);
9116             BuiltInVariable("gl_MeshViewIndicesNV",    EbvMeshViewIndicesNV,    symbolTable);
9117
9118             symbolTable.setVariableExtensions("gl_MaxTaskWorkGroupSizeNV", 1, &E_GL_NV_mesh_shader);
9119             symbolTable.setVariableExtensions("gl_MaxMeshViewCountNV",     1, &E_GL_NV_mesh_shader);
9120
9121             symbolTable.setFunctionExtensions("barrier",                   1, &E_GL_NV_mesh_shader);
9122             symbolTable.setFunctionExtensions("memoryBarrierShared",       1, &E_GL_NV_mesh_shader);
9123             symbolTable.setFunctionExtensions("groupMemoryBarrier",        1, &E_GL_NV_mesh_shader);
9124         }
9125
9126         if (profile != EEsProfile && version >= 450) {
9127             // GL_EXT_device_group
9128             symbolTable.setVariableExtensions("gl_DeviceIndex", 1, &E_GL_EXT_device_group);
9129             BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
9130
9131             // GL_ARB_shader_draw_parameters
9132             symbolTable.setVariableExtensions("gl_DrawIDARB", 1, &E_GL_ARB_shader_draw_parameters);
9133             BuiltInVariable("gl_DrawIDARB", EbvDrawId, symbolTable);
9134             if (version >= 460) {
9135                 BuiltInVariable("gl_DrawID", EbvDrawId, symbolTable);
9136             }
9137
9138             // GL_ARB_shader_ballot
9139             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
9140             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
9141             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
9142             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
9143             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
9144             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
9145             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
9146
9147             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
9148             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
9149             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
9150             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
9151             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
9152             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
9153
9154             if (spvVersion.vulkan > 0)
9155                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
9156                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
9157             else
9158                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
9159         }
9160
9161         // GL_KHR_shader_subgroup
9162         if ((profile == EEsProfile && version >= 310) ||
9163             (profile != EEsProfile && version >= 140)) {
9164             symbolTable.setVariableExtensions("gl_NumSubgroups",         1, &E_GL_KHR_shader_subgroup_basic);
9165             symbolTable.setVariableExtensions("gl_SubgroupID",           1, &E_GL_KHR_shader_subgroup_basic);
9166             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
9167             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
9168             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9169             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9170             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9171             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9172             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9173
9174             BuiltInVariable("gl_NumSubgroups",         EbvNumSubgroups,        symbolTable);
9175             BuiltInVariable("gl_SubgroupID",           EbvSubgroupID,          symbolTable);
9176             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
9177             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
9178             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
9179             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
9180             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
9181             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
9182             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
9183
9184             symbolTable.setFunctionExtensions("subgroupMemoryBarrierShared", 1, &E_GL_KHR_shader_subgroup_basic);
9185
9186             // GL_NV_shader_sm_builtins
9187             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
9188             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
9189             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
9190             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
9191             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
9192             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
9193             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
9194             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
9195         }
9196         if ((profile == EEsProfile && version >= 310) ||
9197             (profile != EEsProfile && version >= 450)) {
9198             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9199             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9200             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9201             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9202         }
9203         break;
9204 #endif
9205
9206     default:
9207         assert(false && "Language not supported");
9208         break;
9209     }
9210
9211     //
9212     // Next, identify which built-ins have a mapping to an operator.
9213     // If PureOperatorBuiltins is false, those that are not identified as such are
9214     // expected to be resolved through a library of functions, versus as
9215     // operations.
9216     //
9217
9218     relateTabledBuiltins(version, profile, spvVersion, language, symbolTable);
9219
9220 #ifndef GLSLANG_WEB
9221     symbolTable.relateToOperator("doubleBitsToInt64",  EOpDoubleBitsToInt64);
9222     symbolTable.relateToOperator("doubleBitsToUint64", EOpDoubleBitsToUint64);
9223     symbolTable.relateToOperator("int64BitsToDouble",  EOpInt64BitsToDouble);
9224     symbolTable.relateToOperator("uint64BitsToDouble", EOpUint64BitsToDouble);
9225     symbolTable.relateToOperator("halfBitsToInt16",  EOpFloat16BitsToInt16);
9226     symbolTable.relateToOperator("halfBitsToUint16", EOpFloat16BitsToUint16);
9227     symbolTable.relateToOperator("float16BitsToInt16",  EOpFloat16BitsToInt16);
9228     symbolTable.relateToOperator("float16BitsToUint16", EOpFloat16BitsToUint16);
9229     symbolTable.relateToOperator("int16BitsToFloat16",  EOpInt16BitsToFloat16);
9230     symbolTable.relateToOperator("uint16BitsToFloat16", EOpUint16BitsToFloat16);
9231
9232     symbolTable.relateToOperator("int16BitsToHalf",  EOpInt16BitsToFloat16);
9233     symbolTable.relateToOperator("uint16BitsToHalf", EOpUint16BitsToFloat16);
9234
9235     symbolTable.relateToOperator("packSnorm4x8",    EOpPackSnorm4x8);
9236     symbolTable.relateToOperator("unpackSnorm4x8",  EOpUnpackSnorm4x8);
9237     symbolTable.relateToOperator("packUnorm4x8",    EOpPackUnorm4x8);
9238     symbolTable.relateToOperator("unpackUnorm4x8",  EOpUnpackUnorm4x8);
9239
9240     symbolTable.relateToOperator("packDouble2x32",    EOpPackDouble2x32);
9241     symbolTable.relateToOperator("unpackDouble2x32",  EOpUnpackDouble2x32);
9242
9243     symbolTable.relateToOperator("packInt2x32",     EOpPackInt2x32);
9244     symbolTable.relateToOperator("unpackInt2x32",   EOpUnpackInt2x32);
9245     symbolTable.relateToOperator("packUint2x32",    EOpPackUint2x32);
9246     symbolTable.relateToOperator("unpackUint2x32",  EOpUnpackUint2x32);
9247
9248     symbolTable.relateToOperator("packInt2x16",     EOpPackInt2x16);
9249     symbolTable.relateToOperator("unpackInt2x16",   EOpUnpackInt2x16);
9250     symbolTable.relateToOperator("packUint2x16",    EOpPackUint2x16);
9251     symbolTable.relateToOperator("unpackUint2x16",  EOpUnpackUint2x16);
9252
9253     symbolTable.relateToOperator("packInt4x16",     EOpPackInt4x16);
9254     symbolTable.relateToOperator("unpackInt4x16",   EOpUnpackInt4x16);
9255     symbolTable.relateToOperator("packUint4x16",    EOpPackUint4x16);
9256     symbolTable.relateToOperator("unpackUint4x16",  EOpUnpackUint4x16);
9257     symbolTable.relateToOperator("packFloat2x16",   EOpPackFloat2x16);
9258     symbolTable.relateToOperator("unpackFloat2x16", EOpUnpackFloat2x16);
9259
9260     symbolTable.relateToOperator("pack16",          EOpPack16);
9261     symbolTable.relateToOperator("pack32",          EOpPack32);
9262     symbolTable.relateToOperator("pack64",          EOpPack64);
9263
9264     symbolTable.relateToOperator("unpack32",        EOpUnpack32);
9265     symbolTable.relateToOperator("unpack16",        EOpUnpack16);
9266     symbolTable.relateToOperator("unpack8",         EOpUnpack8);
9267
9268     symbolTable.relateToOperator("controlBarrier",             EOpBarrier);
9269     symbolTable.relateToOperator("memoryBarrierAtomicCounter", EOpMemoryBarrierAtomicCounter);
9270     symbolTable.relateToOperator("memoryBarrierImage",         EOpMemoryBarrierImage);
9271
9272     if (spvVersion.vulkanRelaxed) {
9273         //
9274         // functions signature have been replaced to take uint operations on buffer variables
9275         // remap atomic counter functions to atomic operations
9276         //
9277         symbolTable.relateToOperator("memoryBarrierAtomicCounter", EOpMemoryBarrierBuffer);
9278     }
9279
9280     symbolTable.relateToOperator("atomicLoad",     EOpAtomicLoad);
9281     symbolTable.relateToOperator("atomicStore",    EOpAtomicStore);
9282
9283     symbolTable.relateToOperator("atomicCounterIncrement", EOpAtomicCounterIncrement);
9284     symbolTable.relateToOperator("atomicCounterDecrement", EOpAtomicCounterDecrement);
9285     symbolTable.relateToOperator("atomicCounter",          EOpAtomicCounter);
9286
9287     if (spvVersion.vulkanRelaxed) {
9288         //
9289         // functions signature have been replaced to take uint operations
9290         // remap atomic counter functions to atomic operations
9291         //
9292         // these atomic counter functions do not match signatures of glsl
9293         // atomic functions, so they will be remapped to semantically
9294         // equivalent functions in the parser
9295         //
9296         symbolTable.relateToOperator("atomicCounterIncrement", EOpNull);
9297         symbolTable.relateToOperator("atomicCounterDecrement", EOpNull);
9298         symbolTable.relateToOperator("atomicCounter", EOpNull);
9299     }
9300
9301     symbolTable.relateToOperator("clockARB",     EOpReadClockSubgroupKHR);
9302     symbolTable.relateToOperator("clock2x32ARB", EOpReadClockSubgroupKHR);
9303
9304     symbolTable.relateToOperator("clockRealtimeEXT",     EOpReadClockDeviceKHR);
9305     symbolTable.relateToOperator("clockRealtime2x32EXT", EOpReadClockDeviceKHR);
9306
9307     if (profile != EEsProfile && version == 450) {
9308         symbolTable.relateToOperator("atomicCounterAddARB",      EOpAtomicCounterAdd);
9309         symbolTable.relateToOperator("atomicCounterSubtractARB", EOpAtomicCounterSubtract);
9310         symbolTable.relateToOperator("atomicCounterMinARB",      EOpAtomicCounterMin);
9311         symbolTable.relateToOperator("atomicCounterMaxARB",      EOpAtomicCounterMax);
9312         symbolTable.relateToOperator("atomicCounterAndARB",      EOpAtomicCounterAnd);
9313         symbolTable.relateToOperator("atomicCounterOrARB",       EOpAtomicCounterOr);
9314         symbolTable.relateToOperator("atomicCounterXorARB",      EOpAtomicCounterXor);
9315         symbolTable.relateToOperator("atomicCounterExchangeARB", EOpAtomicCounterExchange);
9316         symbolTable.relateToOperator("atomicCounterCompSwapARB", EOpAtomicCounterCompSwap);
9317     }
9318
9319     if (profile != EEsProfile && version >= 460) {
9320         symbolTable.relateToOperator("atomicCounterAdd",      EOpAtomicCounterAdd);
9321         symbolTable.relateToOperator("atomicCounterSubtract", EOpAtomicCounterSubtract);
9322         symbolTable.relateToOperator("atomicCounterMin",      EOpAtomicCounterMin);
9323         symbolTable.relateToOperator("atomicCounterMax",      EOpAtomicCounterMax);
9324         symbolTable.relateToOperator("atomicCounterAnd",      EOpAtomicCounterAnd);
9325         symbolTable.relateToOperator("atomicCounterOr",       EOpAtomicCounterOr);
9326         symbolTable.relateToOperator("atomicCounterXor",      EOpAtomicCounterXor);
9327         symbolTable.relateToOperator("atomicCounterExchange", EOpAtomicCounterExchange);
9328         symbolTable.relateToOperator("atomicCounterCompSwap", EOpAtomicCounterCompSwap);
9329     }
9330
9331     if (spvVersion.vulkanRelaxed) {
9332         //
9333         // functions signature have been replaced to take 'uint' instead of 'atomic_uint'
9334         // remap atomic counter functions to non-counter atomic ops so
9335         // functions act as aliases to non-counter atomic ops
9336         //
9337         symbolTable.relateToOperator("atomicCounterAdd", EOpAtomicAdd);
9338         symbolTable.relateToOperator("atomicCounterSubtract", EOpAtomicSubtract);
9339         symbolTable.relateToOperator("atomicCounterMin", EOpAtomicMin);
9340         symbolTable.relateToOperator("atomicCounterMax", EOpAtomicMax);
9341         symbolTable.relateToOperator("atomicCounterAnd", EOpAtomicAnd);
9342         symbolTable.relateToOperator("atomicCounterOr", EOpAtomicOr);
9343         symbolTable.relateToOperator("atomicCounterXor", EOpAtomicXor);
9344         symbolTable.relateToOperator("atomicCounterExchange", EOpAtomicExchange);
9345         symbolTable.relateToOperator("atomicCounterCompSwap", EOpAtomicCompSwap);
9346     }
9347
9348     symbolTable.relateToOperator("fma",               EOpFma);
9349     symbolTable.relateToOperator("frexp",             EOpFrexp);
9350     symbolTable.relateToOperator("ldexp",             EOpLdexp);
9351     symbolTable.relateToOperator("uaddCarry",         EOpAddCarry);
9352     symbolTable.relateToOperator("usubBorrow",        EOpSubBorrow);
9353     symbolTable.relateToOperator("umulExtended",      EOpUMulExtended);
9354     symbolTable.relateToOperator("imulExtended",      EOpIMulExtended);
9355     symbolTable.relateToOperator("bitfieldExtract",   EOpBitfieldExtract);
9356     symbolTable.relateToOperator("bitfieldInsert",    EOpBitfieldInsert);
9357     symbolTable.relateToOperator("bitfieldReverse",   EOpBitFieldReverse);
9358     symbolTable.relateToOperator("bitCount",          EOpBitCount);
9359     symbolTable.relateToOperator("findLSB",           EOpFindLSB);
9360     symbolTable.relateToOperator("findMSB",           EOpFindMSB);
9361
9362     symbolTable.relateToOperator("helperInvocationEXT",  EOpIsHelperInvocation);
9363
9364     symbolTable.relateToOperator("countLeadingZeros",  EOpCountLeadingZeros);
9365     symbolTable.relateToOperator("countTrailingZeros", EOpCountTrailingZeros);
9366     symbolTable.relateToOperator("absoluteDifference", EOpAbsDifference);
9367     symbolTable.relateToOperator("addSaturate",        EOpAddSaturate);
9368     symbolTable.relateToOperator("subtractSaturate",   EOpSubSaturate);
9369     symbolTable.relateToOperator("average",            EOpAverage);
9370     symbolTable.relateToOperator("averageRounded",     EOpAverageRounded);
9371     symbolTable.relateToOperator("multiply32x16",      EOpMul32x16);
9372     symbolTable.relateToOperator("debugPrintfEXT",     EOpDebugPrintf);
9373
9374
9375     if (PureOperatorBuiltins) {
9376         symbolTable.relateToOperator("imageSize",               EOpImageQuerySize);
9377         symbolTable.relateToOperator("imageSamples",            EOpImageQuerySamples);
9378         symbolTable.relateToOperator("imageLoad",               EOpImageLoad);
9379         symbolTable.relateToOperator("imageStore",              EOpImageStore);
9380         symbolTable.relateToOperator("imageAtomicAdd",          EOpImageAtomicAdd);
9381         symbolTable.relateToOperator("imageAtomicMin",          EOpImageAtomicMin);
9382         symbolTable.relateToOperator("imageAtomicMax",          EOpImageAtomicMax);
9383         symbolTable.relateToOperator("imageAtomicAnd",          EOpImageAtomicAnd);
9384         symbolTable.relateToOperator("imageAtomicOr",           EOpImageAtomicOr);
9385         symbolTable.relateToOperator("imageAtomicXor",          EOpImageAtomicXor);
9386         symbolTable.relateToOperator("imageAtomicExchange",     EOpImageAtomicExchange);
9387         symbolTable.relateToOperator("imageAtomicCompSwap",     EOpImageAtomicCompSwap);
9388         symbolTable.relateToOperator("imageAtomicLoad",         EOpImageAtomicLoad);
9389         symbolTable.relateToOperator("imageAtomicStore",        EOpImageAtomicStore);
9390
9391         symbolTable.relateToOperator("subpassLoad",             EOpSubpassLoad);
9392         symbolTable.relateToOperator("subpassLoadMS",           EOpSubpassLoadMS);
9393
9394         symbolTable.relateToOperator("textureGather",           EOpTextureGather);
9395         symbolTable.relateToOperator("textureGatherOffset",     EOpTextureGatherOffset);
9396         symbolTable.relateToOperator("textureGatherOffsets",    EOpTextureGatherOffsets);
9397
9398         symbolTable.relateToOperator("noise1", EOpNoise);
9399         symbolTable.relateToOperator("noise2", EOpNoise);
9400         symbolTable.relateToOperator("noise3", EOpNoise);
9401         symbolTable.relateToOperator("noise4", EOpNoise);
9402
9403         symbolTable.relateToOperator("textureFootprintNV",          EOpImageSampleFootprintNV);
9404         symbolTable.relateToOperator("textureFootprintClampNV",     EOpImageSampleFootprintClampNV);
9405         symbolTable.relateToOperator("textureFootprintLodNV",       EOpImageSampleFootprintLodNV);
9406         symbolTable.relateToOperator("textureFootprintGradNV",      EOpImageSampleFootprintGradNV);
9407         symbolTable.relateToOperator("textureFootprintGradClampNV", EOpImageSampleFootprintGradClampNV);
9408
9409         if (spvVersion.spv == 0 && IncludeLegacy(version, profile, spvVersion))
9410             symbolTable.relateToOperator("ftransform", EOpFtransform);
9411
9412         if (spvVersion.spv == 0 && (IncludeLegacy(version, profile, spvVersion) ||
9413             (profile == EEsProfile && version == 100))) {
9414
9415             symbolTable.relateToOperator("texture1D",                EOpTexture);
9416             symbolTable.relateToOperator("texture1DGradARB",         EOpTextureGrad);
9417             symbolTable.relateToOperator("texture1DProj",            EOpTextureProj);
9418             symbolTable.relateToOperator("texture1DProjGradARB",     EOpTextureProjGrad);
9419             symbolTable.relateToOperator("texture1DLod",             EOpTextureLod);
9420             symbolTable.relateToOperator("texture1DProjLod",         EOpTextureProjLod);
9421
9422             symbolTable.relateToOperator("texture2DRect",            EOpTexture);
9423             symbolTable.relateToOperator("texture2DRectProj",        EOpTextureProj);
9424             symbolTable.relateToOperator("texture2DRectGradARB",     EOpTextureGrad);
9425             symbolTable.relateToOperator("texture2DRectProjGradARB", EOpTextureProjGrad);
9426             symbolTable.relateToOperator("shadow2DRect",             EOpTexture);
9427             symbolTable.relateToOperator("shadow2DRectProj",         EOpTextureProj);
9428             symbolTable.relateToOperator("shadow2DRectGradARB",      EOpTextureGrad);
9429             symbolTable.relateToOperator("shadow2DRectProjGradARB",  EOpTextureProjGrad);
9430
9431             symbolTable.relateToOperator("texture2D",                EOpTexture);
9432             symbolTable.relateToOperator("texture2DProj",            EOpTextureProj);
9433             symbolTable.relateToOperator("texture2DGradEXT",         EOpTextureGrad);
9434             symbolTable.relateToOperator("texture2DGradARB",         EOpTextureGrad);
9435             symbolTable.relateToOperator("texture2DProjGradEXT",     EOpTextureProjGrad);
9436             symbolTable.relateToOperator("texture2DProjGradARB",     EOpTextureProjGrad);
9437             symbolTable.relateToOperator("texture2DLod",             EOpTextureLod);
9438             symbolTable.relateToOperator("texture2DLodEXT",          EOpTextureLod);
9439             symbolTable.relateToOperator("texture2DProjLod",         EOpTextureProjLod);
9440             symbolTable.relateToOperator("texture2DProjLodEXT",      EOpTextureProjLod);
9441
9442             symbolTable.relateToOperator("texture3D",                EOpTexture);
9443             symbolTable.relateToOperator("texture3DGradARB",         EOpTextureGrad);
9444             symbolTable.relateToOperator("texture3DProj",            EOpTextureProj);
9445             symbolTable.relateToOperator("texture3DProjGradARB",     EOpTextureProjGrad);
9446             symbolTable.relateToOperator("texture3DLod",             EOpTextureLod);
9447             symbolTable.relateToOperator("texture3DProjLod",         EOpTextureProjLod);
9448             symbolTable.relateToOperator("textureCube",              EOpTexture);
9449             symbolTable.relateToOperator("textureCubeGradEXT",       EOpTextureGrad);
9450             symbolTable.relateToOperator("textureCubeGradARB",       EOpTextureGrad);
9451             symbolTable.relateToOperator("textureCubeLod",           EOpTextureLod);
9452             symbolTable.relateToOperator("textureCubeLodEXT",        EOpTextureLod);
9453             symbolTable.relateToOperator("shadow1D",                 EOpTexture);
9454             symbolTable.relateToOperator("shadow1DGradARB",          EOpTextureGrad);
9455             symbolTable.relateToOperator("shadow2D",                 EOpTexture);
9456             symbolTable.relateToOperator("shadow2DGradARB",          EOpTextureGrad);
9457             symbolTable.relateToOperator("shadow1DProj",             EOpTextureProj);
9458             symbolTable.relateToOperator("shadow2DProj",             EOpTextureProj);
9459             symbolTable.relateToOperator("shadow1DProjGradARB",      EOpTextureProjGrad);
9460             symbolTable.relateToOperator("shadow2DProjGradARB",      EOpTextureProjGrad);
9461             symbolTable.relateToOperator("shadow1DLod",              EOpTextureLod);
9462             symbolTable.relateToOperator("shadow2DLod",              EOpTextureLod);
9463             symbolTable.relateToOperator("shadow1DProjLod",          EOpTextureProjLod);
9464             symbolTable.relateToOperator("shadow2DProjLod",          EOpTextureProjLod);
9465         }
9466
9467         if (profile != EEsProfile) {
9468             symbolTable.relateToOperator("sparseTextureARB",                EOpSparseTexture);
9469             symbolTable.relateToOperator("sparseTextureLodARB",             EOpSparseTextureLod);
9470             symbolTable.relateToOperator("sparseTextureOffsetARB",          EOpSparseTextureOffset);
9471             symbolTable.relateToOperator("sparseTexelFetchARB",             EOpSparseTextureFetch);
9472             symbolTable.relateToOperator("sparseTexelFetchOffsetARB",       EOpSparseTextureFetchOffset);
9473             symbolTable.relateToOperator("sparseTextureLodOffsetARB",       EOpSparseTextureLodOffset);
9474             symbolTable.relateToOperator("sparseTextureGradARB",            EOpSparseTextureGrad);
9475             symbolTable.relateToOperator("sparseTextureGradOffsetARB",      EOpSparseTextureGradOffset);
9476             symbolTable.relateToOperator("sparseTextureGatherARB",          EOpSparseTextureGather);
9477             symbolTable.relateToOperator("sparseTextureGatherOffsetARB",    EOpSparseTextureGatherOffset);
9478             symbolTable.relateToOperator("sparseTextureGatherOffsetsARB",   EOpSparseTextureGatherOffsets);
9479             symbolTable.relateToOperator("sparseImageLoadARB",              EOpSparseImageLoad);
9480             symbolTable.relateToOperator("sparseTexelsResidentARB",         EOpSparseTexelsResident);
9481
9482             symbolTable.relateToOperator("sparseTextureClampARB",           EOpSparseTextureClamp);
9483             symbolTable.relateToOperator("sparseTextureOffsetClampARB",     EOpSparseTextureOffsetClamp);
9484             symbolTable.relateToOperator("sparseTextureGradClampARB",       EOpSparseTextureGradClamp);
9485             symbolTable.relateToOperator("sparseTextureGradOffsetClampARB", EOpSparseTextureGradOffsetClamp);
9486             symbolTable.relateToOperator("textureClampARB",                 EOpTextureClamp);
9487             symbolTable.relateToOperator("textureOffsetClampARB",           EOpTextureOffsetClamp);
9488             symbolTable.relateToOperator("textureGradClampARB",             EOpTextureGradClamp);
9489             symbolTable.relateToOperator("textureGradOffsetClampARB",       EOpTextureGradOffsetClamp);
9490
9491             symbolTable.relateToOperator("ballotARB",                       EOpBallot);
9492             symbolTable.relateToOperator("readInvocationARB",               EOpReadInvocation);
9493             symbolTable.relateToOperator("readFirstInvocationARB",          EOpReadFirstInvocation);
9494
9495             if (version >= 430) {
9496                 symbolTable.relateToOperator("anyInvocationARB",            EOpAnyInvocation);
9497                 symbolTable.relateToOperator("allInvocationsARB",           EOpAllInvocations);
9498                 symbolTable.relateToOperator("allInvocationsEqualARB",      EOpAllInvocationsEqual);
9499             }
9500             if (version >= 460) {
9501                 symbolTable.relateToOperator("anyInvocation",               EOpAnyInvocation);
9502                 symbolTable.relateToOperator("allInvocations",              EOpAllInvocations);
9503                 symbolTable.relateToOperator("allInvocationsEqual",         EOpAllInvocationsEqual);
9504             }
9505             symbolTable.relateToOperator("minInvocationsAMD",                           EOpMinInvocations);
9506             symbolTable.relateToOperator("maxInvocationsAMD",                           EOpMaxInvocations);
9507             symbolTable.relateToOperator("addInvocationsAMD",                           EOpAddInvocations);
9508             symbolTable.relateToOperator("minInvocationsNonUniformAMD",                 EOpMinInvocationsNonUniform);
9509             symbolTable.relateToOperator("maxInvocationsNonUniformAMD",                 EOpMaxInvocationsNonUniform);
9510             symbolTable.relateToOperator("addInvocationsNonUniformAMD",                 EOpAddInvocationsNonUniform);
9511             symbolTable.relateToOperator("minInvocationsInclusiveScanAMD",              EOpMinInvocationsInclusiveScan);
9512             symbolTable.relateToOperator("maxInvocationsInclusiveScanAMD",              EOpMaxInvocationsInclusiveScan);
9513             symbolTable.relateToOperator("addInvocationsInclusiveScanAMD",              EOpAddInvocationsInclusiveScan);
9514             symbolTable.relateToOperator("minInvocationsInclusiveScanNonUniformAMD",    EOpMinInvocationsInclusiveScanNonUniform);
9515             symbolTable.relateToOperator("maxInvocationsInclusiveScanNonUniformAMD",    EOpMaxInvocationsInclusiveScanNonUniform);
9516             symbolTable.relateToOperator("addInvocationsInclusiveScanNonUniformAMD",    EOpAddInvocationsInclusiveScanNonUniform);
9517             symbolTable.relateToOperator("minInvocationsExclusiveScanAMD",              EOpMinInvocationsExclusiveScan);
9518             symbolTable.relateToOperator("maxInvocationsExclusiveScanAMD",              EOpMaxInvocationsExclusiveScan);
9519             symbolTable.relateToOperator("addInvocationsExclusiveScanAMD",              EOpAddInvocationsExclusiveScan);
9520             symbolTable.relateToOperator("minInvocationsExclusiveScanNonUniformAMD",    EOpMinInvocationsExclusiveScanNonUniform);
9521             symbolTable.relateToOperator("maxInvocationsExclusiveScanNonUniformAMD",    EOpMaxInvocationsExclusiveScanNonUniform);
9522             symbolTable.relateToOperator("addInvocationsExclusiveScanNonUniformAMD",    EOpAddInvocationsExclusiveScanNonUniform);
9523             symbolTable.relateToOperator("swizzleInvocationsAMD",                       EOpSwizzleInvocations);
9524             symbolTable.relateToOperator("swizzleInvocationsMaskedAMD",                 EOpSwizzleInvocationsMasked);
9525             symbolTable.relateToOperator("writeInvocationAMD",                          EOpWriteInvocation);
9526             symbolTable.relateToOperator("mbcntAMD",                                    EOpMbcnt);
9527
9528             symbolTable.relateToOperator("min3",    EOpMin3);
9529             symbolTable.relateToOperator("max3",    EOpMax3);
9530             symbolTable.relateToOperator("mid3",    EOpMid3);
9531
9532             symbolTable.relateToOperator("cubeFaceIndexAMD",    EOpCubeFaceIndex);
9533             symbolTable.relateToOperator("cubeFaceCoordAMD",    EOpCubeFaceCoord);
9534             symbolTable.relateToOperator("timeAMD",             EOpTime);
9535
9536             symbolTable.relateToOperator("textureGatherLodAMD",                 EOpTextureGatherLod);
9537             symbolTable.relateToOperator("textureGatherLodOffsetAMD",           EOpTextureGatherLodOffset);
9538             symbolTable.relateToOperator("textureGatherLodOffsetsAMD",          EOpTextureGatherLodOffsets);
9539             symbolTable.relateToOperator("sparseTextureGatherLodAMD",           EOpSparseTextureGatherLod);
9540             symbolTable.relateToOperator("sparseTextureGatherLodOffsetAMD",     EOpSparseTextureGatherLodOffset);
9541             symbolTable.relateToOperator("sparseTextureGatherLodOffsetsAMD",    EOpSparseTextureGatherLodOffsets);
9542
9543             symbolTable.relateToOperator("imageLoadLodAMD",                     EOpImageLoadLod);
9544             symbolTable.relateToOperator("imageStoreLodAMD",                    EOpImageStoreLod);
9545             symbolTable.relateToOperator("sparseImageLoadLodAMD",               EOpSparseImageLoadLod);
9546
9547             symbolTable.relateToOperator("fragmentMaskFetchAMD",                EOpFragmentMaskFetch);
9548             symbolTable.relateToOperator("fragmentFetchAMD",                    EOpFragmentFetch);
9549         }
9550
9551         // GL_KHR_shader_subgroup
9552         if ((profile == EEsProfile && version >= 310) ||
9553             (profile != EEsProfile && version >= 140)) {
9554             symbolTable.relateToOperator("subgroupBarrier",                 EOpSubgroupBarrier);
9555             symbolTable.relateToOperator("subgroupMemoryBarrier",           EOpSubgroupMemoryBarrier);
9556             symbolTable.relateToOperator("subgroupMemoryBarrierBuffer",     EOpSubgroupMemoryBarrierBuffer);
9557             symbolTable.relateToOperator("subgroupMemoryBarrierImage",      EOpSubgroupMemoryBarrierImage);
9558             symbolTable.relateToOperator("subgroupElect",                   EOpSubgroupElect);
9559             symbolTable.relateToOperator("subgroupAll",                     EOpSubgroupAll);
9560             symbolTable.relateToOperator("subgroupAny",                     EOpSubgroupAny);
9561             symbolTable.relateToOperator("subgroupAllEqual",                EOpSubgroupAllEqual);
9562             symbolTable.relateToOperator("subgroupBroadcast",               EOpSubgroupBroadcast);
9563             symbolTable.relateToOperator("subgroupBroadcastFirst",          EOpSubgroupBroadcastFirst);
9564             symbolTable.relateToOperator("subgroupBallot",                  EOpSubgroupBallot);
9565             symbolTable.relateToOperator("subgroupInverseBallot",           EOpSubgroupInverseBallot);
9566             symbolTable.relateToOperator("subgroupBallotBitExtract",        EOpSubgroupBallotBitExtract);
9567             symbolTable.relateToOperator("subgroupBallotBitCount",          EOpSubgroupBallotBitCount);
9568             symbolTable.relateToOperator("subgroupBallotInclusiveBitCount", EOpSubgroupBallotInclusiveBitCount);
9569             symbolTable.relateToOperator("subgroupBallotExclusiveBitCount", EOpSubgroupBallotExclusiveBitCount);
9570             symbolTable.relateToOperator("subgroupBallotFindLSB",           EOpSubgroupBallotFindLSB);
9571             symbolTable.relateToOperator("subgroupBallotFindMSB",           EOpSubgroupBallotFindMSB);
9572             symbolTable.relateToOperator("subgroupShuffle",                 EOpSubgroupShuffle);
9573             symbolTable.relateToOperator("subgroupShuffleXor",              EOpSubgroupShuffleXor);
9574             symbolTable.relateToOperator("subgroupShuffleUp",               EOpSubgroupShuffleUp);
9575             symbolTable.relateToOperator("subgroupShuffleDown",             EOpSubgroupShuffleDown);
9576             symbolTable.relateToOperator("subgroupAdd",                     EOpSubgroupAdd);
9577             symbolTable.relateToOperator("subgroupMul",                     EOpSubgroupMul);
9578             symbolTable.relateToOperator("subgroupMin",                     EOpSubgroupMin);
9579             symbolTable.relateToOperator("subgroupMax",                     EOpSubgroupMax);
9580             symbolTable.relateToOperator("subgroupAnd",                     EOpSubgroupAnd);
9581             symbolTable.relateToOperator("subgroupOr",                      EOpSubgroupOr);
9582             symbolTable.relateToOperator("subgroupXor",                     EOpSubgroupXor);
9583             symbolTable.relateToOperator("subgroupInclusiveAdd",            EOpSubgroupInclusiveAdd);
9584             symbolTable.relateToOperator("subgroupInclusiveMul",            EOpSubgroupInclusiveMul);
9585             symbolTable.relateToOperator("subgroupInclusiveMin",            EOpSubgroupInclusiveMin);
9586             symbolTable.relateToOperator("subgroupInclusiveMax",            EOpSubgroupInclusiveMax);
9587             symbolTable.relateToOperator("subgroupInclusiveAnd",            EOpSubgroupInclusiveAnd);
9588             symbolTable.relateToOperator("subgroupInclusiveOr",             EOpSubgroupInclusiveOr);
9589             symbolTable.relateToOperator("subgroupInclusiveXor",            EOpSubgroupInclusiveXor);
9590             symbolTable.relateToOperator("subgroupExclusiveAdd",            EOpSubgroupExclusiveAdd);
9591             symbolTable.relateToOperator("subgroupExclusiveMul",            EOpSubgroupExclusiveMul);
9592             symbolTable.relateToOperator("subgroupExclusiveMin",            EOpSubgroupExclusiveMin);
9593             symbolTable.relateToOperator("subgroupExclusiveMax",            EOpSubgroupExclusiveMax);
9594             symbolTable.relateToOperator("subgroupExclusiveAnd",            EOpSubgroupExclusiveAnd);
9595             symbolTable.relateToOperator("subgroupExclusiveOr",             EOpSubgroupExclusiveOr);
9596             symbolTable.relateToOperator("subgroupExclusiveXor",            EOpSubgroupExclusiveXor);
9597             symbolTable.relateToOperator("subgroupClusteredAdd",            EOpSubgroupClusteredAdd);
9598             symbolTable.relateToOperator("subgroupClusteredMul",            EOpSubgroupClusteredMul);
9599             symbolTable.relateToOperator("subgroupClusteredMin",            EOpSubgroupClusteredMin);
9600             symbolTable.relateToOperator("subgroupClusteredMax",            EOpSubgroupClusteredMax);
9601             symbolTable.relateToOperator("subgroupClusteredAnd",            EOpSubgroupClusteredAnd);
9602             symbolTable.relateToOperator("subgroupClusteredOr",             EOpSubgroupClusteredOr);
9603             symbolTable.relateToOperator("subgroupClusteredXor",            EOpSubgroupClusteredXor);
9604             symbolTable.relateToOperator("subgroupQuadBroadcast",           EOpSubgroupQuadBroadcast);
9605             symbolTable.relateToOperator("subgroupQuadSwapHorizontal",      EOpSubgroupQuadSwapHorizontal);
9606             symbolTable.relateToOperator("subgroupQuadSwapVertical",        EOpSubgroupQuadSwapVertical);
9607             symbolTable.relateToOperator("subgroupQuadSwapDiagonal",        EOpSubgroupQuadSwapDiagonal);
9608
9609             symbolTable.relateToOperator("subgroupPartitionNV",                          EOpSubgroupPartition);
9610             symbolTable.relateToOperator("subgroupPartitionedAddNV",                     EOpSubgroupPartitionedAdd);
9611             symbolTable.relateToOperator("subgroupPartitionedMulNV",                     EOpSubgroupPartitionedMul);
9612             symbolTable.relateToOperator("subgroupPartitionedMinNV",                     EOpSubgroupPartitionedMin);
9613             symbolTable.relateToOperator("subgroupPartitionedMaxNV",                     EOpSubgroupPartitionedMax);
9614             symbolTable.relateToOperator("subgroupPartitionedAndNV",                     EOpSubgroupPartitionedAnd);
9615             symbolTable.relateToOperator("subgroupPartitionedOrNV",                      EOpSubgroupPartitionedOr);
9616             symbolTable.relateToOperator("subgroupPartitionedXorNV",                     EOpSubgroupPartitionedXor);
9617             symbolTable.relateToOperator("subgroupPartitionedInclusiveAddNV",            EOpSubgroupPartitionedInclusiveAdd);
9618             symbolTable.relateToOperator("subgroupPartitionedInclusiveMulNV",            EOpSubgroupPartitionedInclusiveMul);
9619             symbolTable.relateToOperator("subgroupPartitionedInclusiveMinNV",            EOpSubgroupPartitionedInclusiveMin);
9620             symbolTable.relateToOperator("subgroupPartitionedInclusiveMaxNV",            EOpSubgroupPartitionedInclusiveMax);
9621             symbolTable.relateToOperator("subgroupPartitionedInclusiveAndNV",            EOpSubgroupPartitionedInclusiveAnd);
9622             symbolTable.relateToOperator("subgroupPartitionedInclusiveOrNV",             EOpSubgroupPartitionedInclusiveOr);
9623             symbolTable.relateToOperator("subgroupPartitionedInclusiveXorNV",            EOpSubgroupPartitionedInclusiveXor);
9624             symbolTable.relateToOperator("subgroupPartitionedExclusiveAddNV",            EOpSubgroupPartitionedExclusiveAdd);
9625             symbolTable.relateToOperator("subgroupPartitionedExclusiveMulNV",            EOpSubgroupPartitionedExclusiveMul);
9626             symbolTable.relateToOperator("subgroupPartitionedExclusiveMinNV",            EOpSubgroupPartitionedExclusiveMin);
9627             symbolTable.relateToOperator("subgroupPartitionedExclusiveMaxNV",            EOpSubgroupPartitionedExclusiveMax);
9628             symbolTable.relateToOperator("subgroupPartitionedExclusiveAndNV",            EOpSubgroupPartitionedExclusiveAnd);
9629             symbolTable.relateToOperator("subgroupPartitionedExclusiveOrNV",             EOpSubgroupPartitionedExclusiveOr);
9630             symbolTable.relateToOperator("subgroupPartitionedExclusiveXorNV",            EOpSubgroupPartitionedExclusiveXor);
9631         }
9632
9633         if (profile == EEsProfile) {
9634             symbolTable.relateToOperator("shadow2DEXT",              EOpTexture);
9635             symbolTable.relateToOperator("shadow2DProjEXT",          EOpTextureProj);
9636         }
9637     }
9638
9639     switch(language) {
9640     case EShLangVertex:
9641         break;
9642
9643     case EShLangTessControl:
9644     case EShLangTessEvaluation:
9645         break;
9646
9647     case EShLangGeometry:
9648         symbolTable.relateToOperator("EmitStreamVertex",   EOpEmitStreamVertex);
9649         symbolTable.relateToOperator("EndStreamPrimitive", EOpEndStreamPrimitive);
9650         symbolTable.relateToOperator("EmitVertex",         EOpEmitVertex);
9651         symbolTable.relateToOperator("EndPrimitive",       EOpEndPrimitive);
9652         break;
9653
9654     case EShLangFragment:
9655         if (profile != EEsProfile && version >= 400) {
9656             symbolTable.relateToOperator("dFdxFine",     EOpDPdxFine);
9657             symbolTable.relateToOperator("dFdyFine",     EOpDPdyFine);
9658             symbolTable.relateToOperator("fwidthFine",   EOpFwidthFine);
9659             symbolTable.relateToOperator("dFdxCoarse",   EOpDPdxCoarse);
9660             symbolTable.relateToOperator("dFdyCoarse",   EOpDPdyCoarse);
9661             symbolTable.relateToOperator("fwidthCoarse", EOpFwidthCoarse);
9662         }
9663
9664         if (profile != EEsProfile && version >= 460) {
9665             symbolTable.relateToOperator("rayQueryInitializeEXT",                                             EOpRayQueryInitialize);
9666             symbolTable.relateToOperator("rayQueryTerminateEXT",                                              EOpRayQueryTerminate);
9667             symbolTable.relateToOperator("rayQueryGenerateIntersectionEXT",                                   EOpRayQueryGenerateIntersection);
9668             symbolTable.relateToOperator("rayQueryConfirmIntersectionEXT",                                    EOpRayQueryConfirmIntersection);
9669             symbolTable.relateToOperator("rayQueryProceedEXT",                                                EOpRayQueryProceed);
9670             symbolTable.relateToOperator("rayQueryGetIntersectionTypeEXT",                                    EOpRayQueryGetIntersectionType);
9671             symbolTable.relateToOperator("rayQueryGetRayTMinEXT",                                             EOpRayQueryGetRayTMin);
9672             symbolTable.relateToOperator("rayQueryGetRayFlagsEXT",                                            EOpRayQueryGetRayFlags);
9673             symbolTable.relateToOperator("rayQueryGetIntersectionTEXT",                                       EOpRayQueryGetIntersectionT);
9674             symbolTable.relateToOperator("rayQueryGetIntersectionInstanceCustomIndexEXT",                     EOpRayQueryGetIntersectionInstanceCustomIndex);
9675             symbolTable.relateToOperator("rayQueryGetIntersectionInstanceIdEXT",                              EOpRayQueryGetIntersectionInstanceId);
9676             symbolTable.relateToOperator("rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT",  EOpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffset);
9677             symbolTable.relateToOperator("rayQueryGetIntersectionGeometryIndexEXT",                           EOpRayQueryGetIntersectionGeometryIndex);
9678             symbolTable.relateToOperator("rayQueryGetIntersectionPrimitiveIndexEXT",                          EOpRayQueryGetIntersectionPrimitiveIndex);
9679             symbolTable.relateToOperator("rayQueryGetIntersectionBarycentricsEXT",                            EOpRayQueryGetIntersectionBarycentrics);
9680             symbolTable.relateToOperator("rayQueryGetIntersectionFrontFaceEXT",                               EOpRayQueryGetIntersectionFrontFace);
9681             symbolTable.relateToOperator("rayQueryGetIntersectionCandidateAABBOpaqueEXT",                     EOpRayQueryGetIntersectionCandidateAABBOpaque);
9682             symbolTable.relateToOperator("rayQueryGetIntersectionObjectRayDirectionEXT",                      EOpRayQueryGetIntersectionObjectRayDirection);
9683             symbolTable.relateToOperator("rayQueryGetIntersectionObjectRayOriginEXT",                         EOpRayQueryGetIntersectionObjectRayOrigin);
9684             symbolTable.relateToOperator("rayQueryGetWorldRayDirectionEXT",                                   EOpRayQueryGetWorldRayDirection);
9685             symbolTable.relateToOperator("rayQueryGetWorldRayOriginEXT",                                      EOpRayQueryGetWorldRayOrigin);
9686             symbolTable.relateToOperator("rayQueryGetIntersectionObjectToWorldEXT",                           EOpRayQueryGetIntersectionObjectToWorld);
9687             symbolTable.relateToOperator("rayQueryGetIntersectionWorldToObjectEXT",                           EOpRayQueryGetIntersectionWorldToObject);
9688         }
9689
9690         symbolTable.relateToOperator("interpolateAtCentroid", EOpInterpolateAtCentroid);
9691         symbolTable.relateToOperator("interpolateAtSample",   EOpInterpolateAtSample);
9692         symbolTable.relateToOperator("interpolateAtOffset",   EOpInterpolateAtOffset);
9693
9694         if (profile != EEsProfile)
9695             symbolTable.relateToOperator("interpolateAtVertexAMD", EOpInterpolateAtVertex);
9696
9697         symbolTable.relateToOperator("beginInvocationInterlockARB", EOpBeginInvocationInterlock);
9698         symbolTable.relateToOperator("endInvocationInterlockARB",   EOpEndInvocationInterlock);
9699
9700         break;
9701
9702     case EShLangCompute:
9703         symbolTable.relateToOperator("subgroupMemoryBarrierShared", EOpSubgroupMemoryBarrierShared);
9704         if ((profile != EEsProfile && version >= 450) ||
9705             (profile == EEsProfile && version >= 320)) {
9706             symbolTable.relateToOperator("dFdx",        EOpDPdx);
9707             symbolTable.relateToOperator("dFdy",        EOpDPdy);
9708             symbolTable.relateToOperator("fwidth",      EOpFwidth);
9709             symbolTable.relateToOperator("dFdxFine",    EOpDPdxFine);
9710             symbolTable.relateToOperator("dFdyFine",    EOpDPdyFine);
9711             symbolTable.relateToOperator("fwidthFine",  EOpFwidthFine);
9712             symbolTable.relateToOperator("dFdxCoarse",  EOpDPdxCoarse);
9713             symbolTable.relateToOperator("dFdyCoarse",  EOpDPdyCoarse);
9714             symbolTable.relateToOperator("fwidthCoarse",EOpFwidthCoarse);
9715         }
9716         symbolTable.relateToOperator("coopMatLoadNV",              EOpCooperativeMatrixLoad);
9717         symbolTable.relateToOperator("coopMatStoreNV",             EOpCooperativeMatrixStore);
9718         symbolTable.relateToOperator("coopMatMulAddNV",            EOpCooperativeMatrixMulAdd);
9719         break;
9720
9721     case EShLangRayGen:
9722     case EShLangClosestHit:
9723     case EShLangMiss:
9724         if (profile != EEsProfile && version >= 460) {
9725             symbolTable.relateToOperator("traceNV", EOpTraceNV);
9726             symbolTable.relateToOperator("traceRayMotionNV", EOpTraceRayMotionNV);
9727             symbolTable.relateToOperator("traceRayEXT", EOpTraceKHR);
9728             symbolTable.relateToOperator("executeCallableNV", EOpExecuteCallableNV);
9729             symbolTable.relateToOperator("executeCallableEXT", EOpExecuteCallableKHR);
9730         }
9731         break;
9732     case EShLangIntersect:
9733         if (profile != EEsProfile && version >= 460) {
9734             symbolTable.relateToOperator("reportIntersectionNV", EOpReportIntersection);
9735             symbolTable.relateToOperator("reportIntersectionEXT", EOpReportIntersection);
9736         }
9737         break;
9738     case EShLangAnyHit:
9739         if (profile != EEsProfile && version >= 460) {
9740             symbolTable.relateToOperator("ignoreIntersectionNV", EOpIgnoreIntersectionNV);
9741             symbolTable.relateToOperator("terminateRayNV", EOpTerminateRayNV);
9742         }
9743         break;
9744     case EShLangCallable:
9745         if (profile != EEsProfile && version >= 460) {
9746             symbolTable.relateToOperator("executeCallableNV", EOpExecuteCallableNV);
9747             symbolTable.relateToOperator("executeCallableEXT", EOpExecuteCallableKHR);
9748         }
9749         break;
9750     case EShLangMeshNV:
9751         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
9752             symbolTable.relateToOperator("writePackedPrimitiveIndices4x8NV", EOpWritePackedPrimitiveIndices4x8NV);
9753         }
9754         // fall through
9755     case EShLangTaskNV:
9756         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
9757             symbolTable.relateToOperator("memoryBarrierShared", EOpMemoryBarrierShared);
9758             symbolTable.relateToOperator("groupMemoryBarrier", EOpGroupMemoryBarrier);
9759             symbolTable.relateToOperator("subgroupMemoryBarrierShared", EOpSubgroupMemoryBarrierShared);
9760         }
9761         break;
9762
9763     default:
9764         assert(false && "Language not supported");
9765     }
9766 #endif // !GLSLANG_WEB
9767 }
9768
9769 //
9770 // Add context-dependent (resource-specific) built-ins not handled by the above.  These
9771 // would be ones that need to be programmatically added because they cannot
9772 // be added by simple text strings.  For these, also
9773 // 1) Map built-in functions to operators, for those that will turn into an operation node
9774 //    instead of remaining a function call.
9775 // 2) Tag extension-related symbols added to their base version with their extensions, so
9776 //    that if an early version has the extension turned off, there is an error reported on use.
9777 //
9778 void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable, const TBuiltInResource &resources)
9779 {
9780 #ifndef GLSLANG_WEB
9781 #if defined(GLSLANG_ANGLE)
9782     profile = ECoreProfile;
9783     version = 450;
9784 #endif
9785     if (profile != EEsProfile && version >= 430 && version < 440) {
9786         symbolTable.setVariableExtensions("gl_MaxTransformFeedbackBuffers", 1, &E_GL_ARB_enhanced_layouts);
9787         symbolTable.setVariableExtensions("gl_MaxTransformFeedbackInterleavedComponents", 1, &E_GL_ARB_enhanced_layouts);
9788     }
9789     if (profile != EEsProfile && version >= 130 && version < 420) {
9790         symbolTable.setVariableExtensions("gl_MinProgramTexelOffset", 1, &E_GL_ARB_shading_language_420pack);
9791         symbolTable.setVariableExtensions("gl_MaxProgramTexelOffset", 1, &E_GL_ARB_shading_language_420pack);
9792     }
9793     if (profile != EEsProfile && version >= 150 && version < 410)
9794         symbolTable.setVariableExtensions("gl_MaxViewports", 1, &E_GL_ARB_viewport_array);
9795
9796     switch(language) {
9797     case EShLangFragment:
9798         // Set up gl_FragData based on current array size.
9799         if (version == 100 || IncludeLegacy(version, profile, spvVersion) || (! ForwardCompatibility && profile != EEsProfile && version < 420)) {
9800             TPrecisionQualifier pq = profile == EEsProfile ? EpqMedium : EpqNone;
9801             TType fragData(EbtFloat, EvqFragColor, pq, 4);
9802             TArraySizes* arraySizes = new TArraySizes;
9803             arraySizes->addInnerSize(resources.maxDrawBuffers);
9804             fragData.transferArraySizes(arraySizes);
9805             symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData"), fragData));
9806             SpecialQualifier("gl_FragData", EvqFragColor, EbvFragData, symbolTable);
9807         }
9808
9809         // GL_EXT_blend_func_extended
9810         if (profile == EEsProfile && version >= 100) {
9811            symbolTable.setVariableExtensions("gl_MaxDualSourceDrawBuffersEXT",    1, &E_GL_EXT_blend_func_extended);
9812            symbolTable.setVariableExtensions("gl_SecondaryFragColorEXT",    1, &E_GL_EXT_blend_func_extended);
9813            symbolTable.setVariableExtensions("gl_SecondaryFragDataEXT",    1, &E_GL_EXT_blend_func_extended);
9814            SpecialQualifier("gl_SecondaryFragColorEXT", EvqVaryingOut, EbvSecondaryFragColorEXT, symbolTable);
9815            SpecialQualifier("gl_SecondaryFragDataEXT", EvqVaryingOut, EbvSecondaryFragDataEXT, symbolTable);
9816         }
9817
9818         break;
9819
9820     case EShLangTessControl:
9821     case EShLangTessEvaluation:
9822         // Because of the context-dependent array size (gl_MaxPatchVertices),
9823         // these variables were added later than the others and need to be mapped now.
9824
9825         // standard members
9826         BuiltInVariable("gl_in", "gl_Position",     EbvPosition,     symbolTable);
9827         BuiltInVariable("gl_in", "gl_PointSize",    EbvPointSize,    symbolTable);
9828         BuiltInVariable("gl_in", "gl_ClipDistance", EbvClipDistance, symbolTable);
9829         BuiltInVariable("gl_in", "gl_CullDistance", EbvCullDistance, symbolTable);
9830
9831         // compatibility members
9832         BuiltInVariable("gl_in", "gl_ClipVertex",          EbvClipVertex,          symbolTable);
9833         BuiltInVariable("gl_in", "gl_FrontColor",          EbvFrontColor,          symbolTable);
9834         BuiltInVariable("gl_in", "gl_BackColor",           EbvBackColor,           symbolTable);
9835         BuiltInVariable("gl_in", "gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
9836         BuiltInVariable("gl_in", "gl_BackSecondaryColor",  EbvBackSecondaryColor,  symbolTable);
9837         BuiltInVariable("gl_in", "gl_TexCoord",            EbvTexCoord,            symbolTable);
9838         BuiltInVariable("gl_in", "gl_FogFragCoord",        EbvFogFragCoord,        symbolTable);
9839
9840         symbolTable.setVariableExtensions("gl_in", "gl_SecondaryPositionNV", 1, &E_GL_NV_stereo_view_rendering);
9841         symbolTable.setVariableExtensions("gl_in", "gl_PositionPerViewNV",   1, &E_GL_NVX_multiview_per_view_attributes);
9842
9843         BuiltInVariable("gl_in", "gl_SecondaryPositionNV", EbvSecondaryPositionNV, symbolTable);
9844         BuiltInVariable("gl_in", "gl_PositionPerViewNV",   EbvPositionPerViewNV,   symbolTable);
9845
9846         // extension requirements
9847         if (profile == EEsProfile) {
9848             symbolTable.setVariableExtensions("gl_in", "gl_PointSize", Num_AEP_tessellation_point_size, AEP_tessellation_point_size);
9849         }
9850
9851         break;
9852
9853     default:
9854         break;
9855     }
9856 #endif
9857 }
9858
9859 } // end namespace glslang