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