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