GL_EXT_opacity_micromap
[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_RayFlagsForceOpacityMicromap2StateEXT = 1024U;"
5854             "const uint gl_HitKindFrontFacingTriangleEXT = 254U;"
5855             "const uint gl_HitKindBackFacingTriangleEXT = 255U;"
5856             "\n";
5857
5858         const char *constRayQueryIntersection =
5859             "const uint gl_RayQueryCandidateIntersectionEXT = 0U;"
5860             "const uint gl_RayQueryCommittedIntersectionEXT = 1U;"
5861             "const uint gl_RayQueryCommittedIntersectionNoneEXT = 0U;"
5862             "const uint gl_RayQueryCommittedIntersectionTriangleEXT = 1U;"
5863             "const uint gl_RayQueryCommittedIntersectionGeneratedEXT = 2U;"
5864             "const uint gl_RayQueryCandidateIntersectionTriangleEXT = 0U;"
5865             "const uint gl_RayQueryCandidateIntersectionAABBEXT = 1U;"
5866             "\n";
5867
5868         const char *rayGenDecls =
5869             "in    uvec3  gl_LaunchIDNV;"
5870             "in    uvec3  gl_LaunchIDEXT;"
5871             "in    uvec3  gl_LaunchSizeNV;"
5872             "in    uvec3  gl_LaunchSizeEXT;"
5873             "\n";
5874         const char *intersectDecls =
5875             "in    uvec3  gl_LaunchIDNV;"
5876             "in    uvec3  gl_LaunchIDEXT;"
5877             "in    uvec3  gl_LaunchSizeNV;"
5878             "in    uvec3  gl_LaunchSizeEXT;"
5879             "in     int   gl_PrimitiveID;"
5880             "in     int   gl_InstanceID;"
5881             "in     int   gl_InstanceCustomIndexNV;"
5882             "in     int   gl_InstanceCustomIndexEXT;"
5883             "in     int   gl_GeometryIndexEXT;"
5884             "in    vec3   gl_WorldRayOriginNV;"
5885             "in    vec3   gl_WorldRayOriginEXT;"
5886             "in    vec3   gl_WorldRayDirectionNV;"
5887             "in    vec3   gl_WorldRayDirectionEXT;"
5888             "in    vec3   gl_ObjectRayOriginNV;"
5889             "in    vec3   gl_ObjectRayOriginEXT;"
5890             "in    vec3   gl_ObjectRayDirectionNV;"
5891             "in    vec3   gl_ObjectRayDirectionEXT;"
5892             "in    float  gl_RayTminNV;"
5893             "in    float  gl_RayTminEXT;"
5894             "in    float  gl_RayTmaxNV;"
5895             "in volatile float gl_RayTmaxEXT;"
5896             "in    mat4x3 gl_ObjectToWorldNV;"
5897             "in    mat4x3 gl_ObjectToWorldEXT;"
5898             "in    mat3x4 gl_ObjectToWorld3x4EXT;"
5899             "in    mat4x3 gl_WorldToObjectNV;"
5900             "in    mat4x3 gl_WorldToObjectEXT;"
5901             "in    mat3x4 gl_WorldToObject3x4EXT;"
5902             "in    uint   gl_IncomingRayFlagsNV;"
5903             "in    uint   gl_IncomingRayFlagsEXT;"
5904             "in    float  gl_CurrentRayTimeNV;"
5905             "in    uint   gl_CullMaskEXT;"
5906             "\n";
5907         const char *hitDecls =
5908             "in    uvec3  gl_LaunchIDNV;"
5909             "in    uvec3  gl_LaunchIDEXT;"
5910             "in    uvec3  gl_LaunchSizeNV;"
5911             "in    uvec3  gl_LaunchSizeEXT;"
5912             "in     int   gl_PrimitiveID;"
5913             "in     int   gl_InstanceID;"
5914             "in     int   gl_InstanceCustomIndexNV;"
5915             "in     int   gl_InstanceCustomIndexEXT;"
5916             "in     int   gl_GeometryIndexEXT;"
5917             "in    vec3   gl_WorldRayOriginNV;"
5918             "in    vec3   gl_WorldRayOriginEXT;"
5919             "in    vec3   gl_WorldRayDirectionNV;"
5920             "in    vec3   gl_WorldRayDirectionEXT;"
5921             "in    vec3   gl_ObjectRayOriginNV;"
5922             "in    vec3   gl_ObjectRayOriginEXT;"
5923             "in    vec3   gl_ObjectRayDirectionNV;"
5924             "in    vec3   gl_ObjectRayDirectionEXT;"
5925             "in    float  gl_RayTminNV;"
5926             "in    float  gl_RayTminEXT;"
5927             "in    float  gl_RayTmaxNV;"
5928             "in    float  gl_RayTmaxEXT;"
5929             "in    float  gl_HitTNV;"
5930             "in    float  gl_HitTEXT;"
5931             "in    uint   gl_HitKindNV;"
5932             "in    uint   gl_HitKindEXT;"
5933             "in    mat4x3 gl_ObjectToWorldNV;"
5934             "in    mat4x3 gl_ObjectToWorldEXT;"
5935             "in    mat3x4 gl_ObjectToWorld3x4EXT;"
5936             "in    mat4x3 gl_WorldToObjectNV;"
5937             "in    mat4x3 gl_WorldToObjectEXT;"
5938             "in    mat3x4 gl_WorldToObject3x4EXT;"
5939             "in    uint   gl_IncomingRayFlagsNV;"
5940             "in    uint   gl_IncomingRayFlagsEXT;"
5941             "in    float  gl_CurrentRayTimeNV;"
5942             "in    uint   gl_CullMaskEXT;"
5943             "\n";
5944         const char *missDecls =
5945             "in    uvec3  gl_LaunchIDNV;"
5946             "in    uvec3  gl_LaunchIDEXT;"
5947             "in    uvec3  gl_LaunchSizeNV;"
5948             "in    uvec3  gl_LaunchSizeEXT;"
5949             "in    vec3   gl_WorldRayOriginNV;"
5950             "in    vec3   gl_WorldRayOriginEXT;"
5951             "in    vec3   gl_WorldRayDirectionNV;"
5952             "in    vec3   gl_WorldRayDirectionEXT;"
5953             "in    vec3   gl_ObjectRayOriginNV;"
5954             "in    vec3   gl_ObjectRayDirectionNV;"
5955             "in    float  gl_RayTminNV;"
5956             "in    float  gl_RayTminEXT;"
5957             "in    float  gl_RayTmaxNV;"
5958             "in    float  gl_RayTmaxEXT;"
5959             "in    uint   gl_IncomingRayFlagsNV;"
5960             "in    uint   gl_IncomingRayFlagsEXT;"
5961             "in    float  gl_CurrentRayTimeNV;"
5962             "in    uint   gl_CullMaskEXT;"
5963             "\n";
5964
5965         const char *callableDecls =
5966             "in    uvec3  gl_LaunchIDNV;"
5967             "in    uvec3  gl_LaunchIDEXT;"
5968             "in    uvec3  gl_LaunchSizeNV;"
5969             "in    uvec3  gl_LaunchSizeEXT;"
5970             "\n";
5971
5972
5973         commonBuiltins.append(constRayQueryIntersection);
5974         commonBuiltins.append(constRayFlags);
5975
5976         stageBuiltins[EShLangRayGen].append(rayGenDecls);
5977         stageBuiltins[EShLangIntersect].append(intersectDecls);
5978         stageBuiltins[EShLangAnyHit].append(hitDecls);
5979         stageBuiltins[EShLangClosestHit].append(hitDecls);
5980         stageBuiltins[EShLangMiss].append(missDecls);
5981         stageBuiltins[EShLangCallable].append(callableDecls);
5982
5983     }
5984
5985     if ((profile != EEsProfile && version >= 140)) {
5986         const char *deviceIndex =
5987             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5988             "\n";
5989
5990         stageBuiltins[EShLangRayGen].append(deviceIndex);
5991         stageBuiltins[EShLangIntersect].append(deviceIndex);
5992         stageBuiltins[EShLangAnyHit].append(deviceIndex);
5993         stageBuiltins[EShLangClosestHit].append(deviceIndex);
5994         stageBuiltins[EShLangMiss].append(deviceIndex);
5995     }
5996
5997     if ((profile != EEsProfile && version >= 420) ||
5998         (profile == EEsProfile && version >= 310)) {
5999         commonBuiltins.append("const int gl_ScopeDevice      = 1;\n");
6000         commonBuiltins.append("const int gl_ScopeWorkgroup   = 2;\n");
6001         commonBuiltins.append("const int gl_ScopeSubgroup    = 3;\n");
6002         commonBuiltins.append("const int gl_ScopeInvocation  = 4;\n");
6003         commonBuiltins.append("const int gl_ScopeQueueFamily = 5;\n");
6004         commonBuiltins.append("const int gl_ScopeShaderCallEXT = 6;\n");
6005
6006         commonBuiltins.append("const int gl_SemanticsRelaxed         = 0x0;\n");
6007         commonBuiltins.append("const int gl_SemanticsAcquire         = 0x2;\n");
6008         commonBuiltins.append("const int gl_SemanticsRelease         = 0x4;\n");
6009         commonBuiltins.append("const int gl_SemanticsAcquireRelease  = 0x8;\n");
6010         commonBuiltins.append("const int gl_SemanticsMakeAvailable   = 0x2000;\n");
6011         commonBuiltins.append("const int gl_SemanticsMakeVisible     = 0x4000;\n");
6012         commonBuiltins.append("const int gl_SemanticsVolatile        = 0x8000;\n");
6013
6014         commonBuiltins.append("const int gl_StorageSemanticsNone     = 0x0;\n");
6015         commonBuiltins.append("const int gl_StorageSemanticsBuffer   = 0x40;\n");
6016         commonBuiltins.append("const int gl_StorageSemanticsShared   = 0x100;\n");
6017         commonBuiltins.append("const int gl_StorageSemanticsImage    = 0x800;\n");
6018         commonBuiltins.append("const int gl_StorageSemanticsOutput   = 0x1000;\n");
6019     }
6020
6021     // Adding these to common built-ins triggers an assert due to a memory corruption in related code when testing
6022     // So instead add to each stage individually, avoiding the GLSLang bug
6023     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
6024         for (int stage=EShLangVertex; stage<EShLangCount; stage++)
6025         {
6026             stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag2VerticalPixelsEXT       = 1;\n");
6027             stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag4VerticalPixelsEXT       = 2;\n");
6028             stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag2HorizontalPixelsEXT     = 4;\n");
6029             stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag4HorizontalPixelsEXT     = 8;\n");
6030         }
6031     }
6032     
6033     // GL_EXT_shader_image_int64
6034     if ((profile != EEsProfile && version >= 420) ||
6035         (profile == EEsProfile && version >= 310)) {
6036             
6037         const TBasicType bTypes[] = { EbtInt64, EbtUint64 };
6038         for (int ms = 0; ms <= 1; ++ms) { // loop over "bool" multisample or not
6039             for (int arrayed = 0; arrayed <= 1; ++arrayed) { // loop over "bool" arrayed or not
6040                 for (int dim = Esd1D; dim < EsdSubpass; ++dim) { // 1D, ..., buffer
6041                     if ((dim == Esd1D || dim == EsdRect) && profile == EEsProfile)
6042                         continue;
6043                     
6044                     if ((dim == Esd3D || dim == EsdRect || dim == EsdBuffer) && arrayed)
6045                         continue;
6046                     
6047                     if (dim != Esd2D && ms)
6048                         continue;
6049                     
6050                     // Loop over the bTypes
6051                     for (size_t bType = 0; bType < sizeof(bTypes)/sizeof(TBasicType); ++bType) {
6052                         //
6053                         // Now, make all the function prototypes for the type we just built...
6054                         //
6055                         TSampler sampler;
6056                     
6057                         sampler.setImage(bTypes[bType], (TSamplerDim)dim, arrayed ? true : false,
6058                                                                           false,
6059                                                                           ms      ? true : false);
6060
6061                         TString typeName = sampler.getString();
6062
6063                         addQueryFunctions(sampler, typeName, version, profile);
6064                         addImageFunctions(sampler, typeName, version, profile);
6065                     }
6066                 }
6067             }
6068         }
6069     }
6070 #endif // !GLSLANG_ANGLE
6071     
6072 #endif // !GLSLANG_WEB
6073
6074     // printf("%s\n", commonBuiltins.c_str());
6075     // printf("%s\n", stageBuiltins[EShLangFragment].c_str());
6076 }
6077
6078 //
6079 // Helper function for initialize(), to add the second set of names for texturing,
6080 // when adding context-independent built-in functions.
6081 //
6082 void TBuiltIns::add2ndGenerationSamplingImaging(int version, EProfile profile, const SpvVersion& spvVersion)
6083 {
6084     //
6085     // In this function proper, enumerate the types, then calls the next set of functions
6086     // to enumerate all the uses for that type.
6087     //
6088
6089     // enumerate all the types
6090     const TBasicType bTypes[] = { EbtFloat, EbtInt, EbtUint,
6091 #if !defined(GLSLANG_WEB) && !defined(GLSLANG_ANGLE)
6092         EbtFloat16
6093 #endif
6094     };
6095 #ifdef GLSLANG_WEB
6096     bool skipBuffer = true;
6097     bool skipCubeArrayed = true;
6098     const int image = 0;
6099 #else
6100     bool skipBuffer = (profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 140);
6101     bool skipCubeArrayed = (profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 130);
6102     for (int image = 0; image <= 1; ++image) // loop over "bool" image vs sampler
6103 #endif
6104     {
6105         for (int shadow = 0; shadow <= 1; ++shadow) { // loop over "bool" shadow or not
6106 #ifdef GLSLANG_WEB
6107             const int ms = 0;
6108 #else
6109             for (int ms = 0; ms <= 1; ++ms) // loop over "bool" multisample or not
6110 #endif
6111             {
6112                 if ((ms || image) && shadow)
6113                     continue;
6114                 if (ms && profile != EEsProfile && version < 150)
6115                     continue;
6116                 if (ms && image && profile == EEsProfile)
6117                     continue;
6118                 if (ms && profile == EEsProfile && version < 310)
6119                     continue;
6120
6121                 for (int arrayed = 0; arrayed <= 1; ++arrayed) { // loop over "bool" arrayed or not
6122 #ifdef GLSLANG_WEB
6123                     for (int dim = Esd2D; dim <= EsdCube; ++dim) { // 2D, 3D, and Cube
6124 #else
6125 #if defined(GLSLANG_ANGLE)
6126                     for (int dim = Esd2D; dim < EsdNumDims; ++dim) { // 2D, ..., buffer, subpass
6127 #else
6128                     for (int dim = Esd1D; dim < EsdNumDims; ++dim) { // 1D, ..., buffer, subpass
6129 #endif
6130                         if (dim == EsdSubpass && spvVersion.vulkan == 0)
6131                             continue;
6132                         if (dim == EsdSubpass && (image || shadow || arrayed))
6133                             continue;
6134                         if ((dim == Esd1D || dim == EsdRect) && profile == EEsProfile)
6135                             continue;
6136                         if (dim == EsdSubpass && spvVersion.vulkan == 0)
6137                             continue;
6138                         if (dim == EsdSubpass && (image || shadow || arrayed))
6139                             continue;
6140                         if ((dim == Esd1D || dim == EsdRect) && profile == EEsProfile)
6141                             continue;
6142                         if (dim != Esd2D && dim != EsdSubpass && ms)
6143                             continue;
6144                         if (dim == EsdBuffer && skipBuffer)
6145                             continue;
6146                         if (dim == EsdBuffer && (shadow || arrayed || ms))
6147                             continue;
6148                         if (ms && arrayed && profile == EEsProfile && version < 310)
6149                             continue;
6150 #endif
6151                         if (dim == Esd3D && shadow)
6152                             continue;
6153                         if (dim == EsdCube && arrayed && skipCubeArrayed)
6154                             continue;
6155                         if ((dim == Esd3D || dim == EsdRect) && arrayed)
6156                             continue;
6157
6158                         // Loop over the bTypes
6159                         for (size_t bType = 0; bType < sizeof(bTypes)/sizeof(TBasicType); ++bType) {
6160 #ifndef GLSLANG_WEB
6161                             if (bTypes[bType] == EbtFloat16 && (profile == EEsProfile || version < 450))
6162                                 continue;
6163                             if (dim == EsdRect && version < 140 && bType > 0)
6164                                 continue;
6165 #endif
6166                             if (shadow && (bTypes[bType] == EbtInt || bTypes[bType] == EbtUint))
6167                                 continue;
6168                             //
6169                             // Now, make all the function prototypes for the type we just built...
6170                             //
6171                             TSampler sampler;
6172 #ifndef GLSLANG_WEB
6173                             if (dim == EsdSubpass) {
6174                                 sampler.setSubpass(bTypes[bType], ms ? true : false);
6175                             } else
6176 #endif
6177                             if (image) {
6178                                 sampler.setImage(bTypes[bType], (TSamplerDim)dim, arrayed ? true : false,
6179                                                                                   shadow  ? true : false,
6180                                                                                   ms      ? true : false);
6181                             } else {
6182                                 sampler.set(bTypes[bType], (TSamplerDim)dim, arrayed ? true : false,
6183                                                                              shadow  ? true : false,
6184                                                                              ms      ? true : false);
6185                             }
6186
6187                             TString typeName = sampler.getString();
6188
6189 #ifndef GLSLANG_WEB
6190                             if (dim == EsdSubpass) {
6191                                 addSubpassSampling(sampler, typeName, version, profile);
6192                                 continue;
6193                             }
6194 #endif
6195
6196                             addQueryFunctions(sampler, typeName, version, profile);
6197
6198                             if (image)
6199                                 addImageFunctions(sampler, typeName, version, profile);
6200                             else {
6201                                 addSamplingFunctions(sampler, typeName, version, profile);
6202 #ifndef GLSLANG_WEB
6203                                 addGatherFunctions(sampler, typeName, version, profile);
6204                                 if (spvVersion.vulkan > 0 && sampler.isCombined() && !sampler.shadow) {
6205                                     // Base Vulkan allows texelFetch() for
6206                                     // textureBuffer (i.e. without sampler).
6207                                     //
6208                                     // GL_EXT_samplerless_texture_functions
6209                                     // allows texelFetch() and query functions
6210                                     // (other than textureQueryLod()) for all
6211                                     // texture types.
6212                                     sampler.setTexture(sampler.type, sampler.dim, sampler.arrayed, sampler.shadow,
6213                                                        sampler.ms);
6214                                     TString textureTypeName = sampler.getString();
6215                                     addSamplingFunctions(sampler, textureTypeName, version, profile);
6216                                     addQueryFunctions(sampler, textureTypeName, version, profile);
6217                                 }
6218 #endif
6219                             }
6220                         }
6221                     }
6222                 }
6223             }
6224         }
6225     }
6226
6227     //
6228     // sparseTexelsResidentARB()
6229     //
6230     if (profile != EEsProfile && version >= 450) {
6231         commonBuiltins.append("bool sparseTexelsResidentARB(int code);\n");
6232     }
6233 }
6234
6235 //
6236 // Helper function for add2ndGenerationSamplingImaging(),
6237 // when adding context-independent built-in functions.
6238 //
6239 // Add all the query functions for the given type.
6240 //
6241 void TBuiltIns::addQueryFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
6242 {
6243     //
6244     // textureSize() and imageSize()
6245     //
6246
6247     int sizeDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0) - (sampler.dim == EsdCube ? 1 : 0);
6248
6249 #ifdef GLSLANG_WEB
6250     commonBuiltins.append("highp ");
6251     commonBuiltins.append("ivec");
6252     commonBuiltins.append(postfixes[sizeDims]);
6253     commonBuiltins.append(" textureSize(");
6254     commonBuiltins.append(typeName);
6255     commonBuiltins.append(",int);\n");
6256     return;
6257 #endif
6258
6259     if (sampler.isImage() && ((profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 420)))
6260         return;
6261
6262     if (profile == EEsProfile)
6263         commonBuiltins.append("highp ");
6264     if (sizeDims == 1)
6265         commonBuiltins.append("int");
6266     else {
6267         commonBuiltins.append("ivec");
6268         commonBuiltins.append(postfixes[sizeDims]);
6269     }
6270     if (sampler.isImage())
6271         commonBuiltins.append(" imageSize(readonly writeonly volatile coherent ");
6272     else
6273         commonBuiltins.append(" textureSize(");
6274     commonBuiltins.append(typeName);
6275     if (! sampler.isImage() && ! sampler.isRect() && ! sampler.isBuffer() && ! sampler.isMultiSample())
6276         commonBuiltins.append(",int);\n");
6277     else
6278         commonBuiltins.append(");\n");
6279
6280     //
6281     // textureSamples() and imageSamples()
6282     //
6283
6284     // GL_ARB_shader_texture_image_samples
6285     // TODO: spec issue? there are no memory qualifiers; how to query a writeonly/readonly image, etc?
6286     if (profile != EEsProfile && version >= 430 && sampler.isMultiSample()) {
6287         commonBuiltins.append("int ");
6288         if (sampler.isImage())
6289             commonBuiltins.append("imageSamples(readonly writeonly volatile coherent ");
6290         else
6291             commonBuiltins.append("textureSamples(");
6292         commonBuiltins.append(typeName);
6293         commonBuiltins.append(");\n");
6294     }
6295
6296     //
6297     // textureQueryLod(), fragment stage only
6298     // Also enabled with extension GL_ARB_texture_query_lod
6299     // Extension GL_ARB_texture_query_lod says that textureQueryLOD() also exist at extension.
6300
6301     if (profile != EEsProfile && version >= 150 && sampler.isCombined() && sampler.dim != EsdRect &&
6302         ! sampler.isMultiSample() && ! sampler.isBuffer()) {
6303
6304         const TString funcName[2] = {"vec2 textureQueryLod(", "vec2 textureQueryLOD("};
6305
6306         for (int i = 0; i < 2; ++i){
6307             for (int f16TexAddr = 0; f16TexAddr < 2; ++f16TexAddr) {
6308                 if (f16TexAddr && sampler.type != EbtFloat16)
6309                     continue;
6310                 stageBuiltins[EShLangFragment].append(funcName[i]);
6311                 stageBuiltins[EShLangFragment].append(typeName);
6312                 if (dimMap[sampler.dim] == 1)
6313                     if (f16TexAddr)
6314                         stageBuiltins[EShLangFragment].append(", float16_t");
6315                     else
6316                         stageBuiltins[EShLangFragment].append(", float");
6317                 else {
6318                     if (f16TexAddr)
6319                         stageBuiltins[EShLangFragment].append(", f16vec");
6320                     else
6321                         stageBuiltins[EShLangFragment].append(", vec");
6322                     stageBuiltins[EShLangFragment].append(postfixes[dimMap[sampler.dim]]);
6323                 }
6324                 stageBuiltins[EShLangFragment].append(");\n");
6325             }
6326
6327             stageBuiltins[EShLangCompute].append(funcName[i]);
6328             stageBuiltins[EShLangCompute].append(typeName);
6329             if (dimMap[sampler.dim] == 1)
6330                 stageBuiltins[EShLangCompute].append(", float");
6331             else {
6332                 stageBuiltins[EShLangCompute].append(", vec");
6333                 stageBuiltins[EShLangCompute].append(postfixes[dimMap[sampler.dim]]);
6334             }
6335             stageBuiltins[EShLangCompute].append(");\n");
6336         }
6337     }
6338
6339     //
6340     // textureQueryLevels()
6341     //
6342
6343     if (profile != EEsProfile && version >= 430 && ! sampler.isImage() && sampler.dim != EsdRect &&
6344         ! sampler.isMultiSample() && ! sampler.isBuffer()) {
6345         commonBuiltins.append("int textureQueryLevels(");
6346         commonBuiltins.append(typeName);
6347         commonBuiltins.append(");\n");
6348     }
6349 }
6350
6351 //
6352 // Helper function for add2ndGenerationSamplingImaging(),
6353 // when adding context-independent built-in functions.
6354 //
6355 // Add all the image access functions for the given type.
6356 //
6357 void TBuiltIns::addImageFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
6358 {
6359     int dims = dimMap[sampler.dim];
6360     // most things with an array add a dimension, except for cubemaps
6361     if (sampler.arrayed && sampler.dim != EsdCube)
6362         ++dims;
6363
6364     TString imageParams = typeName;
6365     if (dims == 1)
6366         imageParams.append(", int");
6367     else {
6368         imageParams.append(", ivec");
6369         imageParams.append(postfixes[dims]);
6370     }
6371     if (sampler.isMultiSample())
6372         imageParams.append(", int");
6373
6374     if (profile == EEsProfile)
6375         commonBuiltins.append("highp ");
6376     commonBuiltins.append(prefixes[sampler.type]);
6377     commonBuiltins.append("vec4 imageLoad(readonly volatile coherent ");
6378     commonBuiltins.append(imageParams);
6379     commonBuiltins.append(");\n");
6380
6381     commonBuiltins.append("void imageStore(writeonly volatile coherent ");
6382     commonBuiltins.append(imageParams);
6383     commonBuiltins.append(", ");
6384     commonBuiltins.append(prefixes[sampler.type]);
6385     commonBuiltins.append("vec4);\n");
6386
6387     if (! sampler.is1D() && ! sampler.isBuffer() && profile != EEsProfile && version >= 450) {
6388         commonBuiltins.append("int sparseImageLoadARB(readonly volatile coherent ");
6389         commonBuiltins.append(imageParams);
6390         commonBuiltins.append(", out ");
6391         commonBuiltins.append(prefixes[sampler.type]);
6392         commonBuiltins.append("vec4");
6393         commonBuiltins.append(");\n");
6394     }
6395
6396     if ( profile != EEsProfile ||
6397         (profile == EEsProfile && version >= 310)) {
6398         if (sampler.type == EbtInt || sampler.type == EbtUint || sampler.type == EbtInt64 || sampler.type == EbtUint64 ) {
6399             
6400             const char* dataType;
6401             switch (sampler.type) {
6402                 case(EbtInt): dataType = "highp int"; break;
6403                 case(EbtUint): dataType = "highp uint"; break;
6404                 case(EbtInt64): dataType = "highp int64_t"; break;
6405                 case(EbtUint64): dataType = "highp uint64_t"; break;
6406                 default: dataType = "";
6407             }
6408
6409             const int numBuiltins = 7;
6410
6411             static const char* atomicFunc[numBuiltins] = {
6412                 " imageAtomicAdd(volatile coherent ",
6413                 " imageAtomicMin(volatile coherent ",
6414                 " imageAtomicMax(volatile coherent ",
6415                 " imageAtomicAnd(volatile coherent ",
6416                 " imageAtomicOr(volatile coherent ",
6417                 " imageAtomicXor(volatile coherent ",
6418                 " imageAtomicExchange(volatile coherent "
6419             };
6420
6421             // Loop twice to add prototypes with/without scope/semantics
6422             for (int j = 0; j < 2; ++j) {
6423                 for (size_t i = 0; i < numBuiltins; ++i) {
6424                     commonBuiltins.append(dataType);
6425                     commonBuiltins.append(atomicFunc[i]);
6426                     commonBuiltins.append(imageParams);
6427                     commonBuiltins.append(", ");
6428                     commonBuiltins.append(dataType);
6429                     if (j == 1) {
6430                         commonBuiltins.append(", int, int, int");
6431                     }
6432                     commonBuiltins.append(");\n");
6433                 }
6434
6435                 commonBuiltins.append(dataType);
6436                 commonBuiltins.append(" imageAtomicCompSwap(volatile coherent ");
6437                 commonBuiltins.append(imageParams);
6438                 commonBuiltins.append(", ");
6439                 commonBuiltins.append(dataType);
6440                 commonBuiltins.append(", ");
6441                 commonBuiltins.append(dataType);
6442                 if (j == 1) {
6443                     commonBuiltins.append(", int, int, int, int, int");
6444                 }
6445                 commonBuiltins.append(");\n");
6446             }
6447
6448             commonBuiltins.append(dataType);
6449             commonBuiltins.append(" imageAtomicLoad(volatile coherent ");
6450             commonBuiltins.append(imageParams);
6451             commonBuiltins.append(", int, int, int);\n");
6452
6453             commonBuiltins.append("void imageAtomicStore(volatile coherent ");
6454             commonBuiltins.append(imageParams);
6455             commonBuiltins.append(", ");
6456             commonBuiltins.append(dataType);
6457             commonBuiltins.append(", int, int, int);\n");
6458
6459         } else {
6460             // not int or uint
6461             // GL_ARB_ES3_1_compatibility
6462             // TODO: spec issue: are there restrictions on the kind of layout() that can be used?  what about dropping memory qualifiers?
6463             if (profile == EEsProfile && version >= 310) {
6464                 commonBuiltins.append("float imageAtomicExchange(volatile coherent ");
6465                 commonBuiltins.append(imageParams);
6466                 commonBuiltins.append(", float);\n");
6467             }
6468             if (profile != EEsProfile && version >= 450) {
6469                 commonBuiltins.append("float imageAtomicAdd(volatile coherent ");
6470                 commonBuiltins.append(imageParams);
6471                 commonBuiltins.append(", float);\n");
6472
6473                 commonBuiltins.append("float imageAtomicAdd(volatile coherent ");
6474                 commonBuiltins.append(imageParams);
6475                 commonBuiltins.append(", float");
6476                 commonBuiltins.append(", int, int, int);\n");
6477
6478                 commonBuiltins.append("float imageAtomicExchange(volatile coherent ");
6479                 commonBuiltins.append(imageParams);
6480                 commonBuiltins.append(", float);\n");
6481
6482                 commonBuiltins.append("float imageAtomicExchange(volatile coherent ");
6483                 commonBuiltins.append(imageParams);
6484                 commonBuiltins.append(", float");
6485                 commonBuiltins.append(", int, int, int);\n");
6486
6487                 commonBuiltins.append("float imageAtomicLoad(readonly volatile coherent ");
6488                 commonBuiltins.append(imageParams);
6489                 commonBuiltins.append(", int, int, int);\n");
6490
6491                 commonBuiltins.append("void imageAtomicStore(writeonly volatile coherent ");
6492                 commonBuiltins.append(imageParams);
6493                 commonBuiltins.append(", float");
6494                 commonBuiltins.append(", int, int, int);\n");
6495
6496                 commonBuiltins.append("float imageAtomicMin(volatile coherent ");
6497                 commonBuiltins.append(imageParams);
6498                 commonBuiltins.append(", float);\n");
6499
6500                 commonBuiltins.append("float imageAtomicMin(volatile coherent ");
6501                 commonBuiltins.append(imageParams);
6502                 commonBuiltins.append(", float");
6503                 commonBuiltins.append(", int, int, int);\n");
6504
6505                 commonBuiltins.append("float imageAtomicMax(volatile coherent ");
6506                 commonBuiltins.append(imageParams);
6507                 commonBuiltins.append(", float);\n");
6508
6509                 commonBuiltins.append("float imageAtomicMax(volatile coherent ");
6510                 commonBuiltins.append(imageParams);
6511                 commonBuiltins.append(", float");
6512                 commonBuiltins.append(", int, int, int);\n");
6513             }
6514         }
6515     }
6516
6517     if (sampler.dim == EsdRect || sampler.dim == EsdBuffer || sampler.shadow || sampler.isMultiSample())
6518         return;
6519
6520     if (profile == EEsProfile || version < 450)
6521         return;
6522
6523     TString imageLodParams = typeName;
6524     if (dims == 1)
6525         imageLodParams.append(", int");
6526     else {
6527         imageLodParams.append(", ivec");
6528         imageLodParams.append(postfixes[dims]);
6529     }
6530     imageLodParams.append(", int");
6531
6532     commonBuiltins.append(prefixes[sampler.type]);
6533     commonBuiltins.append("vec4 imageLoadLodAMD(readonly volatile coherent ");
6534     commonBuiltins.append(imageLodParams);
6535     commonBuiltins.append(");\n");
6536
6537     commonBuiltins.append("void imageStoreLodAMD(writeonly volatile coherent ");
6538     commonBuiltins.append(imageLodParams);
6539     commonBuiltins.append(", ");
6540     commonBuiltins.append(prefixes[sampler.type]);
6541     commonBuiltins.append("vec4);\n");
6542
6543     if (! sampler.is1D()) {
6544         commonBuiltins.append("int sparseImageLoadLodAMD(readonly volatile coherent ");
6545         commonBuiltins.append(imageLodParams);
6546         commonBuiltins.append(", out ");
6547         commonBuiltins.append(prefixes[sampler.type]);
6548         commonBuiltins.append("vec4");
6549         commonBuiltins.append(");\n");
6550     }
6551 }
6552
6553 //
6554 // Helper function for initialize(),
6555 // when adding context-independent built-in functions.
6556 //
6557 // Add all the subpass access functions for the given type.
6558 //
6559 void TBuiltIns::addSubpassSampling(TSampler sampler, const TString& typeName, int /*version*/, EProfile /*profile*/)
6560 {
6561     stageBuiltins[EShLangFragment].append(prefixes[sampler.type]);
6562     stageBuiltins[EShLangFragment].append("vec4 subpassLoad");
6563     stageBuiltins[EShLangFragment].append("(");
6564     stageBuiltins[EShLangFragment].append(typeName.c_str());
6565     if (sampler.isMultiSample())
6566         stageBuiltins[EShLangFragment].append(", int");
6567     stageBuiltins[EShLangFragment].append(");\n");
6568 }
6569
6570 //
6571 // Helper function for add2ndGenerationSamplingImaging(),
6572 // when adding context-independent built-in functions.
6573 //
6574 // Add all the texture lookup functions for the given type.
6575 //
6576 void TBuiltIns::addSamplingFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
6577 {
6578 #ifdef GLSLANG_WEB
6579     profile = EEsProfile;
6580     version = 310;
6581 #elif defined(GLSLANG_ANGLE)
6582     profile = ECoreProfile;
6583     version = 450;
6584 #endif
6585
6586     //
6587     // texturing
6588     //
6589     for (int proj = 0; proj <= 1; ++proj) { // loop over "bool" projective or not
6590
6591         if (proj && (sampler.dim == EsdCube || sampler.isBuffer() || sampler.arrayed || sampler.isMultiSample()
6592             || !sampler.isCombined()))
6593             continue;
6594
6595         for (int lod = 0; lod <= 1; ++lod) {
6596
6597             if (lod && (sampler.isBuffer() || sampler.isRect() || sampler.isMultiSample() || !sampler.isCombined()))
6598                 continue;
6599             if (lod && sampler.dim == Esd2D && sampler.arrayed && sampler.shadow)
6600                 continue;
6601             if (lod && sampler.dim == EsdCube && sampler.shadow)
6602                 continue;
6603
6604             for (int bias = 0; bias <= 1; ++bias) {
6605
6606                 if (bias && (lod || sampler.isMultiSample() || !sampler.isCombined()))
6607                     continue;
6608                 if (bias && (sampler.dim == Esd2D || sampler.dim == EsdCube) && sampler.shadow && sampler.arrayed)
6609                     continue;
6610                 if (bias && (sampler.isRect() || sampler.isBuffer()))
6611                     continue;
6612
6613                 for (int offset = 0; offset <= 1; ++offset) { // loop over "bool" offset or not
6614
6615                     if (proj + offset + bias + lod > 3)
6616                         continue;
6617                     if (offset && (sampler.dim == EsdCube || sampler.isBuffer() || sampler.isMultiSample()))
6618                         continue;
6619
6620                     for (int fetch = 0; fetch <= 1; ++fetch) { // loop over "bool" fetch or not
6621
6622                         if (proj + offset + fetch + bias + lod > 3)
6623                             continue;
6624                         if (fetch && (lod || bias))
6625                             continue;
6626                         if (fetch && (sampler.shadow || sampler.dim == EsdCube))
6627                             continue;
6628                         if (fetch == 0 && (sampler.isMultiSample() || sampler.isBuffer()
6629                             || !sampler.isCombined()))
6630                             continue;
6631
6632                         for (int grad = 0; grad <= 1; ++grad) { // loop over "bool" grad or not
6633
6634                             if (grad && (lod || bias || sampler.isMultiSample() || !sampler.isCombined()))
6635                                 continue;
6636                             if (grad && sampler.isBuffer())
6637                                 continue;
6638                             if (proj + offset + fetch + grad + bias + lod > 3)
6639                                 continue;
6640
6641                             for (int extraProj = 0; extraProj <= 1; ++extraProj) {
6642                                 bool compare = false;
6643                                 int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0);
6644                                 // skip dummy unused second component for 1D non-array shadows
6645                                 if (sampler.shadow && totalDims < 2)
6646                                     totalDims = 2;
6647                                 totalDims += (sampler.shadow ? 1 : 0) + proj;
6648                                 if (totalDims > 4 && sampler.shadow) {
6649                                     compare = true;
6650                                     totalDims = 4;
6651                                 }
6652                                 assert(totalDims <= 4);
6653
6654                                 if (extraProj && ! proj)
6655                                     continue;
6656                                 if (extraProj && (sampler.dim == Esd3D || sampler.shadow || !sampler.isCombined()))
6657                                     continue;
6658
6659                                 // loop over 16-bit floating-point texel addressing
6660 #if defined(GLSLANG_WEB) || defined(GLSLANG_ANGLE)
6661                                 const int f16TexAddr = 0;
6662 #else
6663                                 for (int f16TexAddr = 0; f16TexAddr <= 1; ++f16TexAddr)
6664 #endif
6665                                 {
6666                                     if (f16TexAddr && sampler.type != EbtFloat16)
6667                                         continue;
6668                                     if (f16TexAddr && sampler.shadow && ! compare) {
6669                                         compare = true; // compare argument is always present
6670                                         totalDims--;
6671                                     }
6672                                     // loop over "bool" lod clamp
6673 #if defined(GLSLANG_WEB) || defined(GLSLANG_ANGLE)
6674                                     const int lodClamp = 0;
6675 #else
6676                                     for (int lodClamp = 0; lodClamp <= 1 ;++lodClamp)
6677 #endif
6678                                     {
6679                                         if (lodClamp && (profile == EEsProfile || version < 450))
6680                                             continue;
6681                                         if (lodClamp && (proj || lod || fetch))
6682                                             continue;
6683
6684                                         // loop over "bool" sparse or not
6685 #if defined(GLSLANG_WEB) || defined(GLSLANG_ANGLE)
6686                                         const int sparse = 0;
6687 #else
6688                                         for (int sparse = 0; sparse <= 1; ++sparse)
6689 #endif
6690                                         {
6691                                             if (sparse && (profile == EEsProfile || version < 450))
6692                                                 continue;
6693                                             // Sparse sampling is not for 1D/1D array texture, buffer texture, and
6694                                             // projective texture
6695                                             if (sparse && (sampler.is1D() || sampler.isBuffer() || proj))
6696                                                 continue;
6697
6698                                             TString s;
6699
6700                                             // return type
6701                                             if (sparse)
6702                                                 s.append("int ");
6703                                             else {
6704                                                 if (sampler.shadow)
6705                                                     if (sampler.type == EbtFloat16)
6706                                                         s.append("float16_t ");
6707                                                     else
6708                                                         s.append("float ");
6709                                                 else {
6710                                                     s.append(prefixes[sampler.type]);
6711                                                     s.append("vec4 ");
6712                                                 }
6713                                             }
6714
6715                                             // name
6716                                             if (sparse) {
6717                                                 if (fetch)
6718                                                     s.append("sparseTexel");
6719                                                 else
6720                                                     s.append("sparseTexture");
6721                                             }
6722                                             else {
6723                                                 if (fetch)
6724                                                     s.append("texel");
6725                                                 else
6726                                                     s.append("texture");
6727                                             }
6728                                             if (proj)
6729                                                 s.append("Proj");
6730                                             if (lod)
6731                                                 s.append("Lod");
6732                                             if (grad)
6733                                                 s.append("Grad");
6734                                             if (fetch)
6735                                                 s.append("Fetch");
6736                                             if (offset)
6737                                                 s.append("Offset");
6738                                             if (lodClamp)
6739                                                 s.append("Clamp");
6740                                             if (lodClamp != 0 || sparse)
6741                                                 s.append("ARB");
6742                                             s.append("(");
6743
6744                                             // sampler type
6745                                             s.append(typeName);
6746                                             // P coordinate
6747                                             if (extraProj) {
6748                                                 if (f16TexAddr)
6749                                                     s.append(",f16vec4");
6750                                                 else
6751                                                     s.append(",vec4");
6752                                             } else {
6753                                                 s.append(",");
6754                                                 TBasicType t = fetch ? EbtInt : (f16TexAddr ? EbtFloat16 : EbtFloat);
6755                                                 if (totalDims == 1)
6756                                                     s.append(TType::getBasicString(t));
6757                                                 else {
6758                                                     s.append(prefixes[t]);
6759                                                     s.append("vec");
6760                                                     s.append(postfixes[totalDims]);
6761                                                 }
6762                                             }
6763                                             // non-optional compare
6764                                             if (compare)
6765                                                 s.append(",float");
6766
6767                                             // non-optional lod argument (lod that's not driven by lod loop) or sample
6768                                             if ((fetch && !sampler.isBuffer() &&
6769                                                  !sampler.isRect() && !sampler.isMultiSample())
6770                                                  || (sampler.isMultiSample() && fetch))
6771                                                 s.append(",int");
6772                                             // non-optional lod
6773                                             if (lod) {
6774                                                 if (f16TexAddr)
6775                                                     s.append(",float16_t");
6776                                                 else
6777                                                     s.append(",float");
6778                                             }
6779
6780                                             // gradient arguments
6781                                             if (grad) {
6782                                                 if (dimMap[sampler.dim] == 1) {
6783                                                     if (f16TexAddr)
6784                                                         s.append(",float16_t,float16_t");
6785                                                     else
6786                                                         s.append(",float,float");
6787                                                 } else {
6788                                                     if (f16TexAddr)
6789                                                         s.append(",f16vec");
6790                                                     else
6791                                                         s.append(",vec");
6792                                                     s.append(postfixes[dimMap[sampler.dim]]);
6793                                                     if (f16TexAddr)
6794                                                         s.append(",f16vec");
6795                                                     else
6796                                                         s.append(",vec");
6797                                                     s.append(postfixes[dimMap[sampler.dim]]);
6798                                                 }
6799                                             }
6800                                             // offset
6801                                             if (offset) {
6802                                                 if (dimMap[sampler.dim] == 1)
6803                                                     s.append(",int");
6804                                                 else {
6805                                                     s.append(",ivec");
6806                                                     s.append(postfixes[dimMap[sampler.dim]]);
6807                                                 }
6808                                             }
6809
6810                                             // lod clamp
6811                                             if (lodClamp) {
6812                                                 if (f16TexAddr)
6813                                                     s.append(",float16_t");
6814                                                 else
6815                                                     s.append(",float");
6816                                             }
6817                                             // texel out (for sparse texture)
6818                                             if (sparse) {
6819                                                 s.append(",out ");
6820                                                 if (sampler.shadow)
6821                                                     if (sampler.type == EbtFloat16)
6822                                                         s.append("float16_t");
6823                                                     else
6824                                                         s.append("float");
6825                                                 else {
6826                                                     s.append(prefixes[sampler.type]);
6827                                                     s.append("vec4");
6828                                                 }
6829                                             }
6830                                             // optional bias
6831                                             if (bias) {
6832                                                 if (f16TexAddr)
6833                                                     s.append(",float16_t");
6834                                                 else
6835                                                     s.append(",float");
6836                                             }
6837                                             s.append(");\n");
6838
6839                                             // Add to the per-language set of built-ins
6840                                             if (!grad && (bias || lodClamp != 0)) {
6841                                                 stageBuiltins[EShLangFragment].append(s);
6842                                                 stageBuiltins[EShLangCompute].append(s);
6843                                             } else
6844                                                 commonBuiltins.append(s);
6845
6846                                         }
6847                                     }
6848                                 }
6849                             }
6850                         }
6851                     }
6852                 }
6853             }
6854         }
6855     }
6856 }
6857
6858 //
6859 // Helper function for add2ndGenerationSamplingImaging(),
6860 // when adding context-independent built-in functions.
6861 //
6862 // Add all the texture gather functions for the given type.
6863 //
6864 void TBuiltIns::addGatherFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
6865 {
6866 #ifdef GLSLANG_WEB
6867     profile = EEsProfile;
6868     version = 310;
6869 #elif defined(GLSLANG_ANGLE)
6870     profile = ECoreProfile;
6871     version = 450;
6872 #endif
6873
6874     switch (sampler.dim) {
6875     case Esd2D:
6876     case EsdRect:
6877     case EsdCube:
6878         break;
6879     default:
6880         return;
6881     }
6882
6883     if (sampler.isMultiSample())
6884         return;
6885
6886     if (version < 140 && sampler.dim == EsdRect && sampler.type != EbtFloat)
6887         return;
6888
6889     for (int f16TexAddr = 0; f16TexAddr <= 1; ++f16TexAddr) { // loop over 16-bit floating-point texel addressing
6890
6891         if (f16TexAddr && sampler.type != EbtFloat16)
6892             continue;
6893         for (int offset = 0; offset < 3; ++offset) { // loop over three forms of offset in the call name:  none, Offset, and Offsets
6894
6895             for (int comp = 0; comp < 2; ++comp) { // loop over presence of comp argument
6896
6897                 if (comp > 0 && sampler.shadow)
6898                     continue;
6899
6900                 if (offset > 0 && sampler.dim == EsdCube)
6901                     continue;
6902
6903                 for (int sparse = 0; sparse <= 1; ++sparse) { // loop over "bool" sparse or not
6904                     if (sparse && (profile == EEsProfile || version < 450))
6905                         continue;
6906
6907                     TString s;
6908
6909                     // return type
6910                     if (sparse)
6911                         s.append("int ");
6912                     else {
6913                         s.append(prefixes[sampler.type]);
6914                         s.append("vec4 ");
6915                     }
6916
6917                     // name
6918                     if (sparse)
6919                         s.append("sparseTextureGather");
6920                     else
6921                         s.append("textureGather");
6922                     switch (offset) {
6923                     case 1:
6924                         s.append("Offset");
6925                         break;
6926                     case 2:
6927                         s.append("Offsets");
6928                         break;
6929                     default:
6930                         break;
6931                     }
6932                     if (sparse)
6933                         s.append("ARB");
6934                     s.append("(");
6935
6936                     // sampler type argument
6937                     s.append(typeName);
6938
6939                     // P coordinate argument
6940                     if (f16TexAddr)
6941                         s.append(",f16vec");
6942                     else
6943                         s.append(",vec");
6944                     int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0);
6945                     s.append(postfixes[totalDims]);
6946
6947                     // refZ argument
6948                     if (sampler.shadow)
6949                         s.append(",float");
6950
6951                     // offset argument
6952                     if (offset > 0) {
6953                         s.append(",ivec2");
6954                         if (offset == 2)
6955                             s.append("[4]");
6956                     }
6957
6958                     // texel out (for sparse texture)
6959                     if (sparse) {
6960                         s.append(",out ");
6961                         s.append(prefixes[sampler.type]);
6962                         s.append("vec4 ");
6963                     }
6964
6965                     // comp argument
6966                     if (comp)
6967                         s.append(",int");
6968
6969                     s.append(");\n");
6970                     commonBuiltins.append(s);
6971                 }
6972             }
6973         }
6974     }
6975
6976     if (sampler.dim == EsdRect || sampler.shadow)
6977         return;
6978
6979     if (profile == EEsProfile || version < 450)
6980         return;
6981
6982     for (int bias = 0; bias < 2; ++bias) { // loop over presence of bias argument
6983
6984         for (int lod = 0; lod < 2; ++lod) { // loop over presence of lod argument
6985
6986             if ((lod && bias) || (lod == 0 && bias == 0))
6987                 continue;
6988
6989             for (int f16TexAddr = 0; f16TexAddr <= 1; ++f16TexAddr) { // loop over 16-bit floating-point texel addressing
6990
6991                 if (f16TexAddr && sampler.type != EbtFloat16)
6992                     continue;
6993
6994                 for (int offset = 0; offset < 3; ++offset) { // loop over three forms of offset in the call name:  none, Offset, and Offsets
6995
6996                     for (int comp = 0; comp < 2; ++comp) { // loop over presence of comp argument
6997
6998                         if (comp == 0 && bias)
6999                             continue;
7000
7001                         if (offset > 0 && sampler.dim == EsdCube)
7002                             continue;
7003
7004                         for (int sparse = 0; sparse <= 1; ++sparse) { // loop over "bool" sparse or not
7005                             if (sparse && (profile == EEsProfile || version < 450))
7006                                 continue;
7007
7008                             TString s;
7009
7010                             // return type
7011                             if (sparse)
7012                                 s.append("int ");
7013                             else {
7014                                 s.append(prefixes[sampler.type]);
7015                                 s.append("vec4 ");
7016                             }
7017
7018                             // name
7019                             if (sparse)
7020                                 s.append("sparseTextureGather");
7021                             else
7022                                 s.append("textureGather");
7023
7024                             if (lod)
7025                                 s.append("Lod");
7026
7027                             switch (offset) {
7028                             case 1:
7029                                 s.append("Offset");
7030                                 break;
7031                             case 2:
7032                                 s.append("Offsets");
7033                                 break;
7034                             default:
7035                                 break;
7036                             }
7037
7038                             if (lod)
7039                                 s.append("AMD");
7040                             else if (sparse)
7041                                 s.append("ARB");
7042
7043                             s.append("(");
7044
7045                             // sampler type argument
7046                             s.append(typeName);
7047
7048                             // P coordinate argument
7049                             if (f16TexAddr)
7050                                 s.append(",f16vec");
7051                             else
7052                                 s.append(",vec");
7053                             int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0);
7054                             s.append(postfixes[totalDims]);
7055
7056                             // lod argument
7057                             if (lod) {
7058                                 if (f16TexAddr)
7059                                     s.append(",float16_t");
7060                                 else
7061                                     s.append(",float");
7062                             }
7063
7064                             // offset argument
7065                             if (offset > 0) {
7066                                 s.append(",ivec2");
7067                                 if (offset == 2)
7068                                     s.append("[4]");
7069                             }
7070
7071                             // texel out (for sparse texture)
7072                             if (sparse) {
7073                                 s.append(",out ");
7074                                 s.append(prefixes[sampler.type]);
7075                                 s.append("vec4 ");
7076                             }
7077
7078                             // comp argument
7079                             if (comp)
7080                                 s.append(",int");
7081
7082                             // bias argument
7083                             if (bias) {
7084                                 if (f16TexAddr)
7085                                     s.append(",float16_t");
7086                                 else
7087                                     s.append(",float");
7088                             }
7089
7090                             s.append(");\n");
7091                             if (bias)
7092                                 stageBuiltins[EShLangFragment].append(s);
7093                             else
7094                                 commonBuiltins.append(s);
7095                         }
7096                     }
7097                 }
7098             }
7099         }
7100     }
7101 }
7102
7103 //
7104 // Add context-dependent built-in functions and variables that are present
7105 // for the given version and profile.  All the results are put into just the
7106 // commonBuiltins, because it is called for just a specific stage.  So,
7107 // add stage-specific entries to the commonBuiltins, and only if that stage
7108 // was requested.
7109 //
7110 void TBuiltIns::initialize(const TBuiltInResource &resources, int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language)
7111 {
7112 #ifdef GLSLANG_WEB
7113     version = 310;
7114     profile = EEsProfile;
7115 #elif defined(GLSLANG_ANGLE)
7116     version = 450;
7117     profile = ECoreProfile;
7118 #endif
7119
7120     //
7121     // Initialize the context-dependent (resource-dependent) built-in strings for parsing.
7122     //
7123
7124     //============================================================================
7125     //
7126     // Standard Uniforms
7127     //
7128     //============================================================================
7129
7130     TString& s = commonBuiltins;
7131     const int maxSize = 200;
7132     char builtInConstant[maxSize];
7133
7134     //
7135     // Build string of implementation dependent constants.
7136     //
7137
7138     if (profile == EEsProfile) {
7139         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVertexAttribs = %d;", resources.maxVertexAttribs);
7140         s.append(builtInConstant);
7141
7142         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVertexUniformVectors = %d;", resources.maxVertexUniformVectors);
7143         s.append(builtInConstant);
7144
7145         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVertexTextureImageUnits = %d;", resources.maxVertexTextureImageUnits);
7146         s.append(builtInConstant);
7147
7148         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxCombinedTextureImageUnits = %d;", resources.maxCombinedTextureImageUnits);
7149         s.append(builtInConstant);
7150
7151         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxTextureImageUnits = %d;", resources.maxTextureImageUnits);
7152         s.append(builtInConstant);
7153
7154         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxFragmentUniformVectors = %d;", resources.maxFragmentUniformVectors);
7155         s.append(builtInConstant);
7156
7157         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxDrawBuffers = %d;", resources.maxDrawBuffers);
7158         s.append(builtInConstant);
7159
7160         if (version == 100) {
7161             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVaryingVectors = %d;", resources.maxVaryingVectors);
7162             s.append(builtInConstant);
7163         } else {
7164             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVertexOutputVectors = %d;", resources.maxVertexOutputVectors);
7165             s.append(builtInConstant);
7166
7167             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxFragmentInputVectors = %d;", resources.maxFragmentInputVectors);
7168             s.append(builtInConstant);
7169
7170             snprintf(builtInConstant, maxSize, "const mediump int  gl_MinProgramTexelOffset = %d;", resources.minProgramTexelOffset);
7171             s.append(builtInConstant);
7172
7173             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxProgramTexelOffset = %d;", resources.maxProgramTexelOffset);
7174             s.append(builtInConstant);
7175         }
7176
7177 #ifndef GLSLANG_WEB
7178         if (version >= 310) {
7179             // geometry
7180
7181             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryInputComponents = %d;", resources.maxGeometryInputComponents);
7182             s.append(builtInConstant);
7183             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputComponents = %d;", resources.maxGeometryOutputComponents);
7184             s.append(builtInConstant);
7185             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryImageUniforms = %d;", resources.maxGeometryImageUniforms);
7186             s.append(builtInConstant);
7187             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTextureImageUnits = %d;", resources.maxGeometryTextureImageUnits);
7188             s.append(builtInConstant);
7189             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputVertices = %d;", resources.maxGeometryOutputVertices);
7190             s.append(builtInConstant);
7191             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTotalOutputComponents = %d;", resources.maxGeometryTotalOutputComponents);
7192             s.append(builtInConstant);
7193             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryUniformComponents = %d;", resources.maxGeometryUniformComponents);
7194             s.append(builtInConstant);
7195             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounters = %d;", resources.maxGeometryAtomicCounters);
7196             s.append(builtInConstant);
7197             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounterBuffers = %d;", resources.maxGeometryAtomicCounterBuffers);
7198             s.append(builtInConstant);
7199
7200             // tessellation
7201
7202             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlInputComponents = %d;", resources.maxTessControlInputComponents);
7203             s.append(builtInConstant);
7204             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlOutputComponents = %d;", resources.maxTessControlOutputComponents);
7205             s.append(builtInConstant);
7206             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTextureImageUnits = %d;", resources.maxTessControlTextureImageUnits);
7207             s.append(builtInConstant);
7208             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlUniformComponents = %d;", resources.maxTessControlUniformComponents);
7209             s.append(builtInConstant);
7210             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTotalOutputComponents = %d;", resources.maxTessControlTotalOutputComponents);
7211             s.append(builtInConstant);
7212
7213             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationInputComponents = %d;", resources.maxTessEvaluationInputComponents);
7214             s.append(builtInConstant);
7215             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationOutputComponents = %d;", resources.maxTessEvaluationOutputComponents);
7216             s.append(builtInConstant);
7217             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationTextureImageUnits = %d;", resources.maxTessEvaluationTextureImageUnits);
7218             s.append(builtInConstant);
7219             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationUniformComponents = %d;", resources.maxTessEvaluationUniformComponents);
7220             s.append(builtInConstant);
7221
7222             snprintf(builtInConstant, maxSize, "const int gl_MaxTessPatchComponents = %d;", resources.maxTessPatchComponents);
7223             s.append(builtInConstant);
7224
7225             snprintf(builtInConstant, maxSize, "const int gl_MaxPatchVertices = %d;", resources.maxPatchVertices);
7226             s.append(builtInConstant);
7227             snprintf(builtInConstant, maxSize, "const int gl_MaxTessGenLevel = %d;", resources.maxTessGenLevel);
7228             s.append(builtInConstant);
7229
7230             // this is here instead of with the others in initialize(version, profile) due to the dependence on gl_MaxPatchVertices
7231             if (language == EShLangTessControl || language == EShLangTessEvaluation) {
7232                 s.append(
7233                     "in gl_PerVertex {"
7234                         "highp vec4 gl_Position;"
7235                         "highp float gl_PointSize;"
7236                         "highp vec4 gl_SecondaryPositionNV;"  // GL_NV_stereo_view_rendering
7237                         "highp vec4 gl_PositionPerViewNV[];"  // GL_NVX_multiview_per_view_attributes
7238                     "} gl_in[gl_MaxPatchVertices];"
7239                     "\n");
7240             }
7241         }
7242
7243         if (version >= 320) {
7244             // tessellation
7245
7246             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlImageUniforms = %d;", resources.maxTessControlImageUniforms);
7247             s.append(builtInConstant);
7248             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationImageUniforms = %d;", resources.maxTessEvaluationImageUniforms);
7249             s.append(builtInConstant);
7250             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounters = %d;", resources.maxTessControlAtomicCounters);
7251             s.append(builtInConstant);
7252             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounters = %d;", resources.maxTessEvaluationAtomicCounters);
7253             s.append(builtInConstant);
7254             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounterBuffers = %d;", resources.maxTessControlAtomicCounterBuffers);
7255             s.append(builtInConstant);
7256             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounterBuffers = %d;", resources.maxTessEvaluationAtomicCounterBuffers);
7257             s.append(builtInConstant);
7258         }
7259
7260         if (version >= 100) {
7261             // GL_EXT_blend_func_extended
7262             snprintf(builtInConstant, maxSize, "const mediump int gl_MaxDualSourceDrawBuffersEXT = %d;", resources.maxDualSourceDrawBuffersEXT);
7263             s.append(builtInConstant);
7264             // this is here instead of with the others in initialize(version, profile) due to the dependence on gl_MaxDualSourceDrawBuffersEXT
7265             if (language == EShLangFragment) {
7266                 s.append(
7267                     "mediump vec4 gl_SecondaryFragColorEXT;"
7268                     "mediump vec4 gl_SecondaryFragDataEXT[gl_MaxDualSourceDrawBuffersEXT];"
7269                     "\n");
7270             }
7271         }
7272     } else {
7273         // non-ES profile
7274
7275         if (version > 400) {
7276             snprintf(builtInConstant, maxSize, "const int  gl_MaxVertexUniformVectors = %d;", resources.maxVertexUniformVectors);
7277             s.append(builtInConstant);
7278
7279             snprintf(builtInConstant, maxSize, "const int  gl_MaxFragmentUniformVectors = %d;", resources.maxFragmentUniformVectors);
7280             s.append(builtInConstant);
7281
7282             snprintf(builtInConstant, maxSize, "const int  gl_MaxVaryingVectors = %d;", resources.maxVaryingVectors);
7283             s.append(builtInConstant);
7284         }
7285
7286         snprintf(builtInConstant, maxSize, "const int  gl_MaxVertexAttribs = %d;", resources.maxVertexAttribs);
7287         s.append(builtInConstant);
7288
7289         snprintf(builtInConstant, maxSize, "const int  gl_MaxVertexTextureImageUnits = %d;", resources.maxVertexTextureImageUnits);
7290         s.append(builtInConstant);
7291
7292         snprintf(builtInConstant, maxSize, "const int  gl_MaxCombinedTextureImageUnits = %d;", resources.maxCombinedTextureImageUnits);
7293         s.append(builtInConstant);
7294
7295         snprintf(builtInConstant, maxSize, "const int  gl_MaxTextureImageUnits = %d;", resources.maxTextureImageUnits);
7296         s.append(builtInConstant);
7297
7298         snprintf(builtInConstant, maxSize, "const int  gl_MaxDrawBuffers = %d;", resources.maxDrawBuffers);
7299         s.append(builtInConstant);
7300
7301         snprintf(builtInConstant, maxSize, "const int  gl_MaxLights = %d;", resources.maxLights);
7302         s.append(builtInConstant);
7303
7304         snprintf(builtInConstant, maxSize, "const int  gl_MaxClipPlanes = %d;", resources.maxClipPlanes);
7305         s.append(builtInConstant);
7306
7307         snprintf(builtInConstant, maxSize, "const int  gl_MaxTextureUnits = %d;", resources.maxTextureUnits);
7308         s.append(builtInConstant);
7309
7310         snprintf(builtInConstant, maxSize, "const int  gl_MaxTextureCoords = %d;", resources.maxTextureCoords);
7311         s.append(builtInConstant);
7312
7313         snprintf(builtInConstant, maxSize, "const int  gl_MaxVertexUniformComponents = %d;", resources.maxVertexUniformComponents);
7314         s.append(builtInConstant);
7315
7316         // Moved from just being deprecated into compatibility profile only as of 4.20
7317         if (version < 420 || profile == ECompatibilityProfile) {
7318             snprintf(builtInConstant, maxSize, "const int  gl_MaxVaryingFloats = %d;", resources.maxVaryingFloats);
7319             s.append(builtInConstant);
7320         }
7321
7322         snprintf(builtInConstant, maxSize, "const int  gl_MaxFragmentUniformComponents = %d;", resources.maxFragmentUniformComponents);
7323         s.append(builtInConstant);
7324
7325         if (spvVersion.spv == 0 && IncludeLegacy(version, profile, spvVersion)) {
7326             //
7327             // OpenGL'uniform' state.  Page numbers are in reference to version
7328             // 1.4 of the OpenGL specification.
7329             //
7330
7331             //
7332             // Matrix state. p. 31, 32, 37, 39, 40.
7333             //
7334             s.append("uniform mat4  gl_TextureMatrix[gl_MaxTextureCoords];"
7335
7336             //
7337             // Derived matrix state that provides inverse and transposed versions
7338             // of the matrices above.
7339             //
7340                         "uniform mat4  gl_TextureMatrixInverse[gl_MaxTextureCoords];"
7341
7342                         "uniform mat4  gl_TextureMatrixTranspose[gl_MaxTextureCoords];"
7343
7344                         "uniform mat4  gl_TextureMatrixInverseTranspose[gl_MaxTextureCoords];"
7345
7346             //
7347             // Clip planes p. 42.
7348             //
7349                         "uniform vec4  gl_ClipPlane[gl_MaxClipPlanes];"
7350
7351             //
7352             // Light State p 50, 53, 55.
7353             //
7354                         "uniform gl_LightSourceParameters  gl_LightSource[gl_MaxLights];"
7355
7356             //
7357             // Derived state from products of light.
7358             //
7359                         "uniform gl_LightProducts gl_FrontLightProduct[gl_MaxLights];"
7360                         "uniform gl_LightProducts gl_BackLightProduct[gl_MaxLights];"
7361
7362             //
7363             // Texture Environment and Generation, p. 152, p. 40-42.
7364             //
7365                         "uniform vec4  gl_TextureEnvColor[gl_MaxTextureImageUnits];"
7366                         "uniform vec4  gl_EyePlaneS[gl_MaxTextureCoords];"
7367                         "uniform vec4  gl_EyePlaneT[gl_MaxTextureCoords];"
7368                         "uniform vec4  gl_EyePlaneR[gl_MaxTextureCoords];"
7369                         "uniform vec4  gl_EyePlaneQ[gl_MaxTextureCoords];"
7370                         "uniform vec4  gl_ObjectPlaneS[gl_MaxTextureCoords];"
7371                         "uniform vec4  gl_ObjectPlaneT[gl_MaxTextureCoords];"
7372                         "uniform vec4  gl_ObjectPlaneR[gl_MaxTextureCoords];"
7373                         "uniform vec4  gl_ObjectPlaneQ[gl_MaxTextureCoords];");
7374         }
7375
7376         if (version >= 130) {
7377             snprintf(builtInConstant, maxSize, "const int gl_MaxClipDistances = %d;", resources.maxClipDistances);
7378             s.append(builtInConstant);
7379             snprintf(builtInConstant, maxSize, "const int gl_MaxVaryingComponents = %d;", resources.maxVaryingComponents);
7380             s.append(builtInConstant);
7381
7382             // GL_ARB_shading_language_420pack
7383             snprintf(builtInConstant, maxSize, "const mediump int  gl_MinProgramTexelOffset = %d;", resources.minProgramTexelOffset);
7384             s.append(builtInConstant);
7385             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxProgramTexelOffset = %d;", resources.maxProgramTexelOffset);
7386             s.append(builtInConstant);
7387         }
7388
7389         // geometry
7390         if (version >= 150) {
7391             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryInputComponents = %d;", resources.maxGeometryInputComponents);
7392             s.append(builtInConstant);
7393             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputComponents = %d;", resources.maxGeometryOutputComponents);
7394             s.append(builtInConstant);
7395             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTextureImageUnits = %d;", resources.maxGeometryTextureImageUnits);
7396             s.append(builtInConstant);
7397             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputVertices = %d;", resources.maxGeometryOutputVertices);
7398             s.append(builtInConstant);
7399             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTotalOutputComponents = %d;", resources.maxGeometryTotalOutputComponents);
7400             s.append(builtInConstant);
7401             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryUniformComponents = %d;", resources.maxGeometryUniformComponents);
7402             s.append(builtInConstant);
7403             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryVaryingComponents = %d;", resources.maxGeometryVaryingComponents);
7404             s.append(builtInConstant);
7405
7406         }
7407
7408         if (version >= 150) {
7409             snprintf(builtInConstant, maxSize, "const int gl_MaxVertexOutputComponents = %d;", resources.maxVertexOutputComponents);
7410             s.append(builtInConstant);
7411             snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentInputComponents = %d;", resources.maxFragmentInputComponents);
7412             s.append(builtInConstant);
7413         }
7414
7415         // tessellation
7416         if (version >= 150) {
7417             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlInputComponents = %d;", resources.maxTessControlInputComponents);
7418             s.append(builtInConstant);
7419             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlOutputComponents = %d;", resources.maxTessControlOutputComponents);
7420             s.append(builtInConstant);
7421             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTextureImageUnits = %d;", resources.maxTessControlTextureImageUnits);
7422             s.append(builtInConstant);
7423             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlUniformComponents = %d;", resources.maxTessControlUniformComponents);
7424             s.append(builtInConstant);
7425             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTotalOutputComponents = %d;", resources.maxTessControlTotalOutputComponents);
7426             s.append(builtInConstant);
7427
7428             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationInputComponents = %d;", resources.maxTessEvaluationInputComponents);
7429             s.append(builtInConstant);
7430             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationOutputComponents = %d;", resources.maxTessEvaluationOutputComponents);
7431             s.append(builtInConstant);
7432             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationTextureImageUnits = %d;", resources.maxTessEvaluationTextureImageUnits);
7433             s.append(builtInConstant);
7434             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationUniformComponents = %d;", resources.maxTessEvaluationUniformComponents);
7435             s.append(builtInConstant);
7436
7437             snprintf(builtInConstant, maxSize, "const int gl_MaxTessPatchComponents = %d;", resources.maxTessPatchComponents);
7438             s.append(builtInConstant);
7439             snprintf(builtInConstant, maxSize, "const int gl_MaxTessGenLevel = %d;", resources.maxTessGenLevel);
7440             s.append(builtInConstant);
7441             snprintf(builtInConstant, maxSize, "const int gl_MaxPatchVertices = %d;", resources.maxPatchVertices);
7442             s.append(builtInConstant);
7443
7444             // this is here instead of with the others in initialize(version, profile) due to the dependence on gl_MaxPatchVertices
7445             if (language == EShLangTessControl || language == EShLangTessEvaluation) {
7446                 s.append(
7447                     "in gl_PerVertex {"
7448                         "vec4 gl_Position;"
7449                         "float gl_PointSize;"
7450                         "float gl_ClipDistance[];"
7451                     );
7452                 if (profile == ECompatibilityProfile)
7453                     s.append(
7454                         "vec4 gl_ClipVertex;"
7455                         "vec4 gl_FrontColor;"
7456                         "vec4 gl_BackColor;"
7457                         "vec4 gl_FrontSecondaryColor;"
7458                         "vec4 gl_BackSecondaryColor;"
7459                         "vec4 gl_TexCoord[];"
7460                         "float gl_FogFragCoord;"
7461                         );
7462                 if (profile != EEsProfile && version >= 450)
7463                     s.append(
7464                         "float gl_CullDistance[];"
7465                         "vec4 gl_SecondaryPositionNV;"  // GL_NV_stereo_view_rendering
7466                         "vec4 gl_PositionPerViewNV[];"  // GL_NVX_multiview_per_view_attributes
7467                        );
7468                 s.append(
7469                     "} gl_in[gl_MaxPatchVertices];"
7470                     "\n");
7471             }
7472         }
7473
7474         if (version >= 150) {
7475             snprintf(builtInConstant, maxSize, "const int gl_MaxViewports = %d;", resources.maxViewports);
7476             s.append(builtInConstant);
7477         }
7478
7479         // images
7480         if (version >= 130) {
7481             snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedImageUnitsAndFragmentOutputs = %d;", resources.maxCombinedImageUnitsAndFragmentOutputs);
7482             s.append(builtInConstant);
7483             snprintf(builtInConstant, maxSize, "const int gl_MaxImageSamples = %d;", resources.maxImageSamples);
7484             s.append(builtInConstant);
7485             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlImageUniforms = %d;", resources.maxTessControlImageUniforms);
7486             s.append(builtInConstant);
7487             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationImageUniforms = %d;", resources.maxTessEvaluationImageUniforms);
7488             s.append(builtInConstant);
7489             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryImageUniforms = %d;", resources.maxGeometryImageUniforms);
7490             s.append(builtInConstant);
7491         }
7492
7493         // enhanced layouts
7494         if (version >= 430) {
7495             snprintf(builtInConstant, maxSize, "const int gl_MaxTransformFeedbackBuffers = %d;", resources.maxTransformFeedbackBuffers);
7496             s.append(builtInConstant);
7497             snprintf(builtInConstant, maxSize, "const int gl_MaxTransformFeedbackInterleavedComponents = %d;", resources.maxTransformFeedbackInterleavedComponents);
7498             s.append(builtInConstant);
7499         }
7500 #endif
7501     }
7502
7503     // compute
7504     if ((profile == EEsProfile && version >= 310) || (profile != EEsProfile && version >= 420)) {
7505         snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxComputeWorkGroupCount = ivec3(%d,%d,%d);", resources.maxComputeWorkGroupCountX,
7506                                                                                                          resources.maxComputeWorkGroupCountY,
7507                                                                                                          resources.maxComputeWorkGroupCountZ);
7508         s.append(builtInConstant);
7509         snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxComputeWorkGroupSize = ivec3(%d,%d,%d);", resources.maxComputeWorkGroupSizeX,
7510                                                                                                         resources.maxComputeWorkGroupSizeY,
7511                                                                                                         resources.maxComputeWorkGroupSizeZ);
7512         s.append(builtInConstant);
7513
7514         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeUniformComponents = %d;", resources.maxComputeUniformComponents);
7515         s.append(builtInConstant);
7516         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeTextureImageUnits = %d;", resources.maxComputeTextureImageUnits);
7517         s.append(builtInConstant);
7518
7519         s.append("\n");
7520     }
7521
7522 #ifndef GLSLANG_WEB
7523     // images (some in compute below)
7524     if ((profile == EEsProfile && version >= 310) ||
7525         (profile != EEsProfile && version >= 130)) {
7526         snprintf(builtInConstant, maxSize, "const int gl_MaxImageUnits = %d;", resources.maxImageUnits);
7527         s.append(builtInConstant);
7528         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedShaderOutputResources = %d;", resources.maxCombinedShaderOutputResources);
7529         s.append(builtInConstant);
7530         snprintf(builtInConstant, maxSize, "const int gl_MaxVertexImageUniforms = %d;", resources.maxVertexImageUniforms);
7531         s.append(builtInConstant);
7532         snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentImageUniforms = %d;", resources.maxFragmentImageUniforms);
7533         s.append(builtInConstant);
7534         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedImageUniforms = %d;", resources.maxCombinedImageUniforms);
7535         s.append(builtInConstant);
7536     }
7537
7538     // compute
7539     if ((profile == EEsProfile && version >= 310) || (profile != EEsProfile && version >= 420)) {
7540         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeImageUniforms = %d;", resources.maxComputeImageUniforms);
7541         s.append(builtInConstant);
7542         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeAtomicCounters = %d;", resources.maxComputeAtomicCounters);
7543         s.append(builtInConstant);
7544         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeAtomicCounterBuffers = %d;", resources.maxComputeAtomicCounterBuffers);
7545         s.append(builtInConstant);
7546
7547         s.append("\n");
7548     }
7549
7550 #ifndef GLSLANG_ANGLE
7551     // atomic counters (some in compute below)
7552     if ((profile == EEsProfile && version >= 310) ||
7553         (profile != EEsProfile && version >= 420)) {
7554         snprintf(builtInConstant, maxSize, "const int gl_MaxVertexAtomicCounters = %d;", resources.               maxVertexAtomicCounters);
7555         s.append(builtInConstant);
7556         snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentAtomicCounters = %d;", resources.             maxFragmentAtomicCounters);
7557         s.append(builtInConstant);
7558         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedAtomicCounters = %d;", resources.             maxCombinedAtomicCounters);
7559         s.append(builtInConstant);
7560         snprintf(builtInConstant, maxSize, "const int gl_MaxAtomicCounterBindings = %d;", resources.              maxAtomicCounterBindings);
7561         s.append(builtInConstant);
7562         snprintf(builtInConstant, maxSize, "const int gl_MaxVertexAtomicCounterBuffers = %d;", resources.         maxVertexAtomicCounterBuffers);
7563         s.append(builtInConstant);
7564         snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentAtomicCounterBuffers = %d;", resources.       maxFragmentAtomicCounterBuffers);
7565         s.append(builtInConstant);
7566         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedAtomicCounterBuffers = %d;", resources.       maxCombinedAtomicCounterBuffers);
7567         s.append(builtInConstant);
7568         snprintf(builtInConstant, maxSize, "const int gl_MaxAtomicCounterBufferSize = %d;", resources.            maxAtomicCounterBufferSize);
7569         s.append(builtInConstant);
7570     }
7571     if (profile != EEsProfile && version >= 420) {
7572         snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounters = %d;", resources.          maxTessControlAtomicCounters);
7573         s.append(builtInConstant);
7574         snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounters = %d;", resources.       maxTessEvaluationAtomicCounters);
7575         s.append(builtInConstant);
7576         snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounters = %d;", resources.             maxGeometryAtomicCounters);
7577         s.append(builtInConstant);
7578         snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounterBuffers = %d;", resources.    maxTessControlAtomicCounterBuffers);
7579         s.append(builtInConstant);
7580         snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounterBuffers = %d;", resources. maxTessEvaluationAtomicCounterBuffers);
7581         s.append(builtInConstant);
7582         snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounterBuffers = %d;", resources.       maxGeometryAtomicCounterBuffers);
7583         s.append(builtInConstant);
7584
7585         s.append("\n");
7586     }
7587 #endif // !GLSLANG_ANGLE
7588
7589     // GL_ARB_cull_distance
7590     if (profile != EEsProfile && version >= 450) {
7591         snprintf(builtInConstant, maxSize, "const int gl_MaxCullDistances = %d;",                resources.maxCullDistances);
7592         s.append(builtInConstant);
7593         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedClipAndCullDistances = %d;", resources.maxCombinedClipAndCullDistances);
7594         s.append(builtInConstant);
7595     }
7596
7597     // GL_ARB_ES3_1_compatibility
7598     if ((profile != EEsProfile && version >= 450) ||
7599         (profile == EEsProfile && version >= 310)) {
7600         snprintf(builtInConstant, maxSize, "const int gl_MaxSamples = %d;", resources.maxSamples);
7601         s.append(builtInConstant);
7602     }
7603
7604 #ifndef GLSLANG_ANGLE
7605     // SPV_NV_mesh_shader
7606     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
7607         snprintf(builtInConstant, maxSize, "const int gl_MaxMeshOutputVerticesNV = %d;", resources.maxMeshOutputVerticesNV);
7608         s.append(builtInConstant);
7609
7610         snprintf(builtInConstant, maxSize, "const int gl_MaxMeshOutputPrimitivesNV = %d;", resources.maxMeshOutputPrimitivesNV);
7611         s.append(builtInConstant);
7612
7613         snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxMeshWorkGroupSizeNV = ivec3(%d,%d,%d);", resources.maxMeshWorkGroupSizeX_NV,
7614                                                                                                        resources.maxMeshWorkGroupSizeY_NV,
7615                                                                                                        resources.maxMeshWorkGroupSizeZ_NV);
7616         s.append(builtInConstant);
7617         snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxTaskWorkGroupSizeNV = ivec3(%d,%d,%d);", resources.maxTaskWorkGroupSizeX_NV,
7618                                                                                                        resources.maxTaskWorkGroupSizeY_NV,
7619                                                                                                        resources.maxTaskWorkGroupSizeZ_NV);
7620         s.append(builtInConstant);
7621
7622         snprintf(builtInConstant, maxSize, "const int gl_MaxMeshViewCountNV = %d;", resources.maxMeshViewCountNV);
7623         s.append(builtInConstant);
7624
7625         s.append("\n");
7626     }
7627 #endif
7628 #endif
7629
7630     s.append("\n");
7631 }
7632
7633 //
7634 // To support special built-ins that have a special qualifier that cannot be declared textually
7635 // in a shader, like gl_Position.
7636 //
7637 // This lets the type of the built-in be declared textually, and then have just its qualifier be
7638 // updated afterward.
7639 //
7640 // Safe to call even if name is not present.
7641 //
7642 // Only use this for built-in variables that have a special qualifier in TStorageQualifier.
7643 // New built-in variables should use a generic (textually declarable) qualifier in
7644 // TStoraregQualifier and only call BuiltInVariable().
7645 //
7646 static void SpecialQualifier(const char* name, TStorageQualifier qualifier, TBuiltInVariable builtIn, TSymbolTable& symbolTable)
7647 {
7648     TSymbol* symbol = symbolTable.find(name);
7649     if (symbol == nullptr)
7650         return;
7651
7652     TQualifier& symQualifier = symbol->getWritableType().getQualifier();
7653     symQualifier.storage = qualifier;
7654     symQualifier.builtIn = builtIn;
7655 }
7656
7657 //
7658 // Modify the symbol's flat decoration.
7659 //
7660 // Safe to call even if name is not present.
7661 //
7662 // Originally written to transform gl_SubGroupSizeARB from uniform to fragment input in Vulkan.
7663 //
7664 static void ModifyFlatDecoration(const char* name, bool flat, TSymbolTable& symbolTable)
7665 {
7666     TSymbol* symbol = symbolTable.find(name);
7667     if (symbol == nullptr)
7668         return;
7669
7670     TQualifier& symQualifier = symbol->getWritableType().getQualifier();
7671     symQualifier.flat = flat;
7672 }
7673
7674 //
7675 // To tag built-in variables with their TBuiltInVariable enum.  Use this when the
7676 // normal declaration text already gets the qualifier right, and all that's needed
7677 // is setting the builtIn field.  This should be the normal way for all new
7678 // built-in variables.
7679 //
7680 // If SpecialQualifier() was called, this does not need to be called.
7681 //
7682 // Safe to call even if name is not present.
7683 //
7684 static void BuiltInVariable(const char* name, TBuiltInVariable builtIn, TSymbolTable& symbolTable)
7685 {
7686     TSymbol* symbol = symbolTable.find(name);
7687     if (symbol == nullptr)
7688         return;
7689
7690     TQualifier& symQualifier = symbol->getWritableType().getQualifier();
7691     symQualifier.builtIn = builtIn;
7692 }
7693
7694 static void RetargetVariable(const char* from, const char* to, TSymbolTable& symbolTable)
7695 {
7696     symbolTable.retargetSymbol(from, to);
7697 }
7698
7699 //
7700 // For built-in variables inside a named block.
7701 // SpecialQualifier() won't ever go inside a block; their member's qualifier come
7702 // from the qualification of the block.
7703 //
7704 // See comments above for other detail.
7705 //
7706 static void BuiltInVariable(const char* blockName, const char* name, TBuiltInVariable builtIn, TSymbolTable& symbolTable)
7707 {
7708     TSymbol* symbol = symbolTable.find(blockName);
7709     if (symbol == nullptr)
7710         return;
7711
7712     TTypeList& structure = *symbol->getWritableType().getWritableStruct();
7713     for (int i = 0; i < (int)structure.size(); ++i) {
7714         if (structure[i].type->getFieldName().compare(name) == 0) {
7715             structure[i].type->getQualifier().builtIn = builtIn;
7716             return;
7717         }
7718     }
7719 }
7720
7721 //
7722 // Finish adding/processing context-independent built-in symbols.
7723 // 1) Programmatically add symbols that could not be added by simple text strings above.
7724 // 2) Map built-in functions to operators, for those that will turn into an operation node
7725 //    instead of remaining a function call.
7726 // 3) Tag extension-related symbols added to their base version with their extensions, so
7727 //    that if an early version has the extension turned off, there is an error reported on use.
7728 //
7729 void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable)
7730 {
7731 #ifdef GLSLANG_WEB
7732     version = 310;
7733     profile = EEsProfile;
7734 #elif defined(GLSLANG_ANGLE)
7735     version = 450;
7736     profile = ECoreProfile;
7737 #endif
7738
7739     //
7740     // Tag built-in variables and functions with additional qualifier and extension information
7741     // that cannot be declared with the text strings.
7742     //
7743
7744     // N.B.: a symbol should only be tagged once, and this function is called multiple times, once
7745     // per stage that's used for this profile.  So
7746     //  - generally, stick common ones in the fragment stage to ensure they are tagged exactly once
7747     //  - for ES, which has different precisions for different stages, the coarsest-grained tagging
7748     //    for a built-in used in many stages needs to be once for the fragment stage and once for
7749     //    the vertex stage
7750
7751     switch(language) {
7752     case EShLangVertex:
7753         if (spvVersion.vulkan > 0) {
7754             BuiltInVariable("gl_VertexIndex",   EbvVertexIndex,   symbolTable);
7755             BuiltInVariable("gl_InstanceIndex", EbvInstanceIndex, symbolTable);
7756         }
7757
7758 #ifndef GLSLANG_WEB
7759         if (spvVersion.vulkan == 0) {
7760             SpecialQualifier("gl_VertexID",   EvqVertexId,   EbvVertexId,   symbolTable);
7761             SpecialQualifier("gl_InstanceID", EvqInstanceId, EbvInstanceId, symbolTable);
7762         }
7763
7764         if (spvVersion.vulkan > 0 && spvVersion.vulkanRelaxed) {
7765             // treat these built-ins as aliases of VertexIndex and InstanceIndex
7766             RetargetVariable("gl_InstanceID", "gl_InstanceIndex", symbolTable);
7767             RetargetVariable("gl_VertexID", "gl_VertexIndex", symbolTable);
7768         }
7769
7770         if (profile != EEsProfile) {
7771             if (version >= 440) {
7772                 symbolTable.setVariableExtensions("gl_BaseVertexARB",   1, &E_GL_ARB_shader_draw_parameters);
7773                 symbolTable.setVariableExtensions("gl_BaseInstanceARB", 1, &E_GL_ARB_shader_draw_parameters);
7774                 symbolTable.setVariableExtensions("gl_DrawIDARB",       1, &E_GL_ARB_shader_draw_parameters);
7775                 BuiltInVariable("gl_BaseVertexARB",   EbvBaseVertex,   symbolTable);
7776                 BuiltInVariable("gl_BaseInstanceARB", EbvBaseInstance, symbolTable);
7777                 BuiltInVariable("gl_DrawIDARB",       EbvDrawId,       symbolTable);
7778             }
7779             if (version >= 460) {
7780                 BuiltInVariable("gl_BaseVertex",   EbvBaseVertex,   symbolTable);
7781                 BuiltInVariable("gl_BaseInstance", EbvBaseInstance, symbolTable);
7782                 BuiltInVariable("gl_DrawID",       EbvDrawId,       symbolTable);
7783             }
7784             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
7785             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
7786             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
7787             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
7788             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
7789             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
7790             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
7791
7792             symbolTable.setFunctionExtensions("ballotARB",              1, &E_GL_ARB_shader_ballot);
7793             symbolTable.setFunctionExtensions("readInvocationARB",      1, &E_GL_ARB_shader_ballot);
7794             symbolTable.setFunctionExtensions("readFirstInvocationARB", 1, &E_GL_ARB_shader_ballot);
7795
7796             if (version >= 430) {
7797                 symbolTable.setFunctionExtensions("anyInvocationARB",       1, &E_GL_ARB_shader_group_vote);
7798                 symbolTable.setFunctionExtensions("allInvocationsARB",      1, &E_GL_ARB_shader_group_vote);
7799                 symbolTable.setFunctionExtensions("allInvocationsEqualARB", 1, &E_GL_ARB_shader_group_vote);
7800             }
7801         }
7802
7803
7804         if (profile != EEsProfile) {
7805             symbolTable.setFunctionExtensions("minInvocationsAMD",                1, &E_GL_AMD_shader_ballot);
7806             symbolTable.setFunctionExtensions("maxInvocationsAMD",                1, &E_GL_AMD_shader_ballot);
7807             symbolTable.setFunctionExtensions("addInvocationsAMD",                1, &E_GL_AMD_shader_ballot);
7808             symbolTable.setFunctionExtensions("minInvocationsNonUniformAMD",      1, &E_GL_AMD_shader_ballot);
7809             symbolTable.setFunctionExtensions("maxInvocationsNonUniformAMD",      1, &E_GL_AMD_shader_ballot);
7810             symbolTable.setFunctionExtensions("addInvocationsNonUniformAMD",      1, &E_GL_AMD_shader_ballot);
7811             symbolTable.setFunctionExtensions("swizzleInvocationsAMD",            1, &E_GL_AMD_shader_ballot);
7812             symbolTable.setFunctionExtensions("swizzleInvocationsWithPatternAMD", 1, &E_GL_AMD_shader_ballot);
7813             symbolTable.setFunctionExtensions("writeInvocationAMD",               1, &E_GL_AMD_shader_ballot);
7814             symbolTable.setFunctionExtensions("mbcntAMD",                         1, &E_GL_AMD_shader_ballot);
7815
7816             symbolTable.setFunctionExtensions("minInvocationsInclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
7817             symbolTable.setFunctionExtensions("maxInvocationsInclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
7818             symbolTable.setFunctionExtensions("addInvocationsInclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
7819             symbolTable.setFunctionExtensions("minInvocationsInclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
7820             symbolTable.setFunctionExtensions("maxInvocationsInclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
7821             symbolTable.setFunctionExtensions("addInvocationsInclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
7822             symbolTable.setFunctionExtensions("minInvocationsExclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
7823             symbolTable.setFunctionExtensions("maxInvocationsExclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
7824             symbolTable.setFunctionExtensions("addInvocationsExclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
7825             symbolTable.setFunctionExtensions("minInvocationsExclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
7826             symbolTable.setFunctionExtensions("maxInvocationsExclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
7827             symbolTable.setFunctionExtensions("addInvocationsExclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
7828         }
7829
7830         if (profile != EEsProfile) {
7831             symbolTable.setFunctionExtensions("min3", 1, &E_GL_AMD_shader_trinary_minmax);
7832             symbolTable.setFunctionExtensions("max3", 1, &E_GL_AMD_shader_trinary_minmax);
7833             symbolTable.setFunctionExtensions("mid3", 1, &E_GL_AMD_shader_trinary_minmax);
7834         }
7835
7836         if (profile != EEsProfile) {
7837             symbolTable.setVariableExtensions("gl_SIMDGroupSizeAMD", 1, &E_GL_AMD_gcn_shader);
7838             SpecialQualifier("gl_SIMDGroupSizeAMD", EvqVaryingIn, EbvSubGroupSize, symbolTable);
7839
7840             symbolTable.setFunctionExtensions("cubeFaceIndexAMD", 1, &E_GL_AMD_gcn_shader);
7841             symbolTable.setFunctionExtensions("cubeFaceCoordAMD", 1, &E_GL_AMD_gcn_shader);
7842             symbolTable.setFunctionExtensions("timeAMD",          1, &E_GL_AMD_gcn_shader);
7843         }
7844
7845         if (profile != EEsProfile) {
7846             symbolTable.setFunctionExtensions("fragmentMaskFetchAMD", 1, &E_GL_AMD_shader_fragment_mask);
7847             symbolTable.setFunctionExtensions("fragmentFetchAMD",     1, &E_GL_AMD_shader_fragment_mask);
7848         }
7849
7850         symbolTable.setFunctionExtensions("countLeadingZeros",  1, &E_GL_INTEL_shader_integer_functions2);
7851         symbolTable.setFunctionExtensions("countTrailingZeros", 1, &E_GL_INTEL_shader_integer_functions2);
7852         symbolTable.setFunctionExtensions("absoluteDifference", 1, &E_GL_INTEL_shader_integer_functions2);
7853         symbolTable.setFunctionExtensions("addSaturate",        1, &E_GL_INTEL_shader_integer_functions2);
7854         symbolTable.setFunctionExtensions("subtractSaturate",   1, &E_GL_INTEL_shader_integer_functions2);
7855         symbolTable.setFunctionExtensions("average",            1, &E_GL_INTEL_shader_integer_functions2);
7856         symbolTable.setFunctionExtensions("averageRounded",     1, &E_GL_INTEL_shader_integer_functions2);
7857         symbolTable.setFunctionExtensions("multiply32x16",      1, &E_GL_INTEL_shader_integer_functions2);
7858
7859         symbolTable.setFunctionExtensions("textureFootprintNV",          1, &E_GL_NV_shader_texture_footprint);
7860         symbolTable.setFunctionExtensions("textureFootprintClampNV",     1, &E_GL_NV_shader_texture_footprint);
7861         symbolTable.setFunctionExtensions("textureFootprintLodNV",       1, &E_GL_NV_shader_texture_footprint);
7862         symbolTable.setFunctionExtensions("textureFootprintGradNV",      1, &E_GL_NV_shader_texture_footprint);
7863         symbolTable.setFunctionExtensions("textureFootprintGradClampNV", 1, &E_GL_NV_shader_texture_footprint);
7864         // Compatibility variables, vertex only
7865         if (spvVersion.spv == 0) {
7866             BuiltInVariable("gl_Color",          EbvColor,          symbolTable);
7867             BuiltInVariable("gl_SecondaryColor", EbvSecondaryColor, symbolTable);
7868             BuiltInVariable("gl_Normal",         EbvNormal,         symbolTable);
7869             BuiltInVariable("gl_Vertex",         EbvVertex,         symbolTable);
7870             BuiltInVariable("gl_MultiTexCoord0", EbvMultiTexCoord0, symbolTable);
7871             BuiltInVariable("gl_MultiTexCoord1", EbvMultiTexCoord1, symbolTable);
7872             BuiltInVariable("gl_MultiTexCoord2", EbvMultiTexCoord2, symbolTable);
7873             BuiltInVariable("gl_MultiTexCoord3", EbvMultiTexCoord3, symbolTable);
7874             BuiltInVariable("gl_MultiTexCoord4", EbvMultiTexCoord4, symbolTable);
7875             BuiltInVariable("gl_MultiTexCoord5", EbvMultiTexCoord5, symbolTable);
7876             BuiltInVariable("gl_MultiTexCoord6", EbvMultiTexCoord6, symbolTable);
7877             BuiltInVariable("gl_MultiTexCoord7", EbvMultiTexCoord7, symbolTable);
7878             BuiltInVariable("gl_FogCoord",       EbvFogFragCoord,   symbolTable);
7879         }
7880
7881         if (profile == EEsProfile) {
7882             if (spvVersion.spv == 0) {
7883                 symbolTable.setFunctionExtensions("texture2DGradEXT",     1, &E_GL_EXT_shader_texture_lod);
7884                 symbolTable.setFunctionExtensions("texture2DProjGradEXT", 1, &E_GL_EXT_shader_texture_lod);
7885                 symbolTable.setFunctionExtensions("textureCubeGradEXT",   1, &E_GL_EXT_shader_texture_lod);
7886                 if (version == 310)
7887                     symbolTable.setFunctionExtensions("textureGatherOffsets", Num_AEP_gpu_shader5, AEP_gpu_shader5);
7888             }
7889             if (version == 310)
7890                 symbolTable.setFunctionExtensions("fma", Num_AEP_gpu_shader5, AEP_gpu_shader5);
7891         }
7892
7893         if (profile == EEsProfile && version < 320) {
7894             symbolTable.setFunctionExtensions("imageAtomicAdd",      1, &E_GL_OES_shader_image_atomic);
7895             symbolTable.setFunctionExtensions("imageAtomicMin",      1, &E_GL_OES_shader_image_atomic);
7896             symbolTable.setFunctionExtensions("imageAtomicMax",      1, &E_GL_OES_shader_image_atomic);
7897             symbolTable.setFunctionExtensions("imageAtomicAnd",      1, &E_GL_OES_shader_image_atomic);
7898             symbolTable.setFunctionExtensions("imageAtomicOr",       1, &E_GL_OES_shader_image_atomic);
7899             symbolTable.setFunctionExtensions("imageAtomicXor",      1, &E_GL_OES_shader_image_atomic);
7900             symbolTable.setFunctionExtensions("imageAtomicExchange", 1, &E_GL_OES_shader_image_atomic);
7901             symbolTable.setFunctionExtensions("imageAtomicCompSwap", 1, &E_GL_OES_shader_image_atomic);
7902         }
7903
7904         if (version >= 300 /* both ES and non-ES */) {
7905             symbolTable.setVariableExtensions("gl_ViewID_OVR", Num_OVR_multiview_EXTs, OVR_multiview_EXTs);
7906             BuiltInVariable("gl_ViewID_OVR", EbvViewIndex, symbolTable);
7907         }
7908
7909         if (profile == EEsProfile) {
7910             symbolTable.setFunctionExtensions("shadow2DEXT",        1, &E_GL_EXT_shadow_samplers);
7911             symbolTable.setFunctionExtensions("shadow2DProjEXT",    1, &E_GL_EXT_shadow_samplers);
7912         }
7913         // Fall through
7914
7915     case EShLangTessControl:
7916         if (profile == EEsProfile && version >= 310) {
7917             BuiltInVariable("gl_BoundingBoxEXT", EbvBoundingBox, symbolTable);
7918             symbolTable.setVariableExtensions("gl_BoundingBoxEXT", 1,
7919                                               &E_GL_EXT_primitive_bounding_box);
7920             BuiltInVariable("gl_BoundingBoxOES", EbvBoundingBox, symbolTable);
7921             symbolTable.setVariableExtensions("gl_BoundingBoxOES", 1,
7922                                               &E_GL_OES_primitive_bounding_box);
7923
7924             if (version >= 320) {
7925                 BuiltInVariable("gl_BoundingBox", EbvBoundingBox, symbolTable);
7926             }
7927         }
7928         // Fall through
7929
7930     case EShLangTessEvaluation:
7931     case EShLangGeometry:
7932 #endif // !GLSLANG_WEB
7933         SpecialQualifier("gl_Position",   EvqPosition,   EbvPosition,   symbolTable);
7934         SpecialQualifier("gl_PointSize",  EvqPointSize,  EbvPointSize,  symbolTable);
7935
7936         BuiltInVariable("gl_in",  "gl_Position",     EbvPosition,     symbolTable);
7937         BuiltInVariable("gl_in",  "gl_PointSize",    EbvPointSize,    symbolTable);
7938
7939         BuiltInVariable("gl_out", "gl_Position",     EbvPosition,     symbolTable);
7940         BuiltInVariable("gl_out", "gl_PointSize",    EbvPointSize,    symbolTable);
7941
7942 #ifndef GLSLANG_WEB
7943         SpecialQualifier("gl_ClipVertex", EvqClipVertex, EbvClipVertex, symbolTable);
7944
7945         BuiltInVariable("gl_in",  "gl_ClipDistance", EbvClipDistance, symbolTable);
7946         BuiltInVariable("gl_in",  "gl_CullDistance", EbvCullDistance, symbolTable);
7947
7948         BuiltInVariable("gl_out", "gl_ClipDistance", EbvClipDistance, symbolTable);
7949         BuiltInVariable("gl_out", "gl_CullDistance", EbvCullDistance, symbolTable);
7950
7951         BuiltInVariable("gl_ClipDistance",    EbvClipDistance,   symbolTable);
7952         BuiltInVariable("gl_CullDistance",    EbvCullDistance,   symbolTable);
7953         BuiltInVariable("gl_PrimitiveIDIn",   EbvPrimitiveId,    symbolTable);
7954         BuiltInVariable("gl_PrimitiveID",     EbvPrimitiveId,    symbolTable);
7955         BuiltInVariable("gl_InvocationID",    EbvInvocationId,   symbolTable);
7956         BuiltInVariable("gl_Layer",           EbvLayer,          symbolTable);
7957         BuiltInVariable("gl_ViewportIndex",   EbvViewportIndex,  symbolTable);
7958
7959         if (language != EShLangGeometry) {
7960             symbolTable.setVariableExtensions("gl_Layer",         Num_viewportEXTs, viewportEXTs);
7961             symbolTable.setVariableExtensions("gl_ViewportIndex", Num_viewportEXTs, viewportEXTs);
7962         }
7963         symbolTable.setVariableExtensions("gl_ViewportMask",            1, &E_GL_NV_viewport_array2);
7964         symbolTable.setVariableExtensions("gl_SecondaryPositionNV",     1, &E_GL_NV_stereo_view_rendering);
7965         symbolTable.setVariableExtensions("gl_SecondaryViewportMaskNV", 1, &E_GL_NV_stereo_view_rendering);
7966         symbolTable.setVariableExtensions("gl_PositionPerViewNV",       1, &E_GL_NVX_multiview_per_view_attributes);
7967         symbolTable.setVariableExtensions("gl_ViewportMaskPerViewNV",   1, &E_GL_NVX_multiview_per_view_attributes);
7968
7969         BuiltInVariable("gl_ViewportMask",              EbvViewportMaskNV,          symbolTable);
7970         BuiltInVariable("gl_SecondaryPositionNV",       EbvSecondaryPositionNV,     symbolTable);
7971         BuiltInVariable("gl_SecondaryViewportMaskNV",   EbvSecondaryViewportMaskNV, symbolTable);
7972         BuiltInVariable("gl_PositionPerViewNV",         EbvPositionPerViewNV,       symbolTable);
7973         BuiltInVariable("gl_ViewportMaskPerViewNV",     EbvViewportMaskPerViewNV,   symbolTable);
7974
7975         if (language == EShLangVertex || language == EShLangGeometry) {
7976             symbolTable.setVariableExtensions("gl_in", "gl_SecondaryPositionNV", 1, &E_GL_NV_stereo_view_rendering);
7977             symbolTable.setVariableExtensions("gl_in", "gl_PositionPerViewNV",   1, &E_GL_NVX_multiview_per_view_attributes);
7978
7979             BuiltInVariable("gl_in", "gl_SecondaryPositionNV", EbvSecondaryPositionNV, symbolTable);
7980             BuiltInVariable("gl_in", "gl_PositionPerViewNV",   EbvPositionPerViewNV,   symbolTable);
7981         }
7982         symbolTable.setVariableExtensions("gl_out", "gl_ViewportMask",            1, &E_GL_NV_viewport_array2);
7983         symbolTable.setVariableExtensions("gl_out", "gl_SecondaryPositionNV",     1, &E_GL_NV_stereo_view_rendering);
7984         symbolTable.setVariableExtensions("gl_out", "gl_SecondaryViewportMaskNV", 1, &E_GL_NV_stereo_view_rendering);
7985         symbolTable.setVariableExtensions("gl_out", "gl_PositionPerViewNV",       1, &E_GL_NVX_multiview_per_view_attributes);
7986         symbolTable.setVariableExtensions("gl_out", "gl_ViewportMaskPerViewNV",   1, &E_GL_NVX_multiview_per_view_attributes);
7987
7988         BuiltInVariable("gl_out", "gl_ViewportMask",            EbvViewportMaskNV,          symbolTable);
7989         BuiltInVariable("gl_out", "gl_SecondaryPositionNV",     EbvSecondaryPositionNV,     symbolTable);
7990         BuiltInVariable("gl_out", "gl_SecondaryViewportMaskNV", EbvSecondaryViewportMaskNV, symbolTable);
7991         BuiltInVariable("gl_out", "gl_PositionPerViewNV",       EbvPositionPerViewNV,       symbolTable);
7992         BuiltInVariable("gl_out", "gl_ViewportMaskPerViewNV",   EbvViewportMaskPerViewNV,   symbolTable);
7993
7994         BuiltInVariable("gl_PatchVerticesIn", EbvPatchVertices,  symbolTable);
7995         BuiltInVariable("gl_TessLevelOuter",  EbvTessLevelOuter, symbolTable);
7996         BuiltInVariable("gl_TessLevelInner",  EbvTessLevelInner, symbolTable);
7997         BuiltInVariable("gl_TessCoord",       EbvTessCoord,      symbolTable);
7998
7999         if (version < 410)
8000             symbolTable.setVariableExtensions("gl_ViewportIndex", 1, &E_GL_ARB_viewport_array);
8001
8002         // Compatibility variables
8003
8004         BuiltInVariable("gl_in", "gl_ClipVertex",          EbvClipVertex,          symbolTable);
8005         BuiltInVariable("gl_in", "gl_FrontColor",          EbvFrontColor,          symbolTable);
8006         BuiltInVariable("gl_in", "gl_BackColor",           EbvBackColor,           symbolTable);
8007         BuiltInVariable("gl_in", "gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
8008         BuiltInVariable("gl_in", "gl_BackSecondaryColor",  EbvBackSecondaryColor,  symbolTable);
8009         BuiltInVariable("gl_in", "gl_TexCoord",            EbvTexCoord,            symbolTable);
8010         BuiltInVariable("gl_in", "gl_FogFragCoord",        EbvFogFragCoord,        symbolTable);
8011
8012         BuiltInVariable("gl_out", "gl_ClipVertex",          EbvClipVertex,          symbolTable);
8013         BuiltInVariable("gl_out", "gl_FrontColor",          EbvFrontColor,          symbolTable);
8014         BuiltInVariable("gl_out", "gl_BackColor",           EbvBackColor,           symbolTable);
8015         BuiltInVariable("gl_out", "gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
8016         BuiltInVariable("gl_out", "gl_BackSecondaryColor",  EbvBackSecondaryColor,  symbolTable);
8017         BuiltInVariable("gl_out", "gl_TexCoord",            EbvTexCoord,            symbolTable);
8018         BuiltInVariable("gl_out", "gl_FogFragCoord",        EbvFogFragCoord,        symbolTable);
8019
8020         BuiltInVariable("gl_ClipVertex",          EbvClipVertex,          symbolTable);
8021         BuiltInVariable("gl_FrontColor",          EbvFrontColor,          symbolTable);
8022         BuiltInVariable("gl_BackColor",           EbvBackColor,           symbolTable);
8023         BuiltInVariable("gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
8024         BuiltInVariable("gl_BackSecondaryColor",  EbvBackSecondaryColor,  symbolTable);
8025         BuiltInVariable("gl_TexCoord",            EbvTexCoord,            symbolTable);
8026         BuiltInVariable("gl_FogFragCoord",        EbvFogFragCoord,        symbolTable);
8027
8028         // gl_PointSize, when it needs to be tied to an extension, is always a member of a block.
8029         // (Sometimes with an instance name, sometimes anonymous).
8030         if (profile == EEsProfile) {
8031             if (language == EShLangGeometry) {
8032                 symbolTable.setVariableExtensions("gl_PointSize", Num_AEP_geometry_point_size, AEP_geometry_point_size);
8033                 symbolTable.setVariableExtensions("gl_in", "gl_PointSize", Num_AEP_geometry_point_size, AEP_geometry_point_size);
8034             } else if (language == EShLangTessEvaluation || language == EShLangTessControl) {
8035                 // gl_in tessellation settings of gl_PointSize are in the context-dependent paths
8036                 symbolTable.setVariableExtensions("gl_PointSize", Num_AEP_tessellation_point_size, AEP_tessellation_point_size);
8037                 symbolTable.setVariableExtensions("gl_out", "gl_PointSize", Num_AEP_tessellation_point_size, AEP_tessellation_point_size);
8038             }
8039         }
8040
8041         if ((profile != EEsProfile && version >= 140) ||
8042             (profile == EEsProfile && version >= 310)) {
8043             symbolTable.setVariableExtensions("gl_DeviceIndex",  1, &E_GL_EXT_device_group);
8044             BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
8045             symbolTable.setVariableExtensions("gl_ViewIndex", 1, &E_GL_EXT_multiview);
8046             BuiltInVariable("gl_ViewIndex", EbvViewIndex, symbolTable);
8047         }
8048
8049         if (profile != EEsProfile) {
8050             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
8051             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
8052             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
8053             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
8054             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
8055             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
8056
8057             if (spvVersion.vulkan > 0) {
8058                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
8059                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
8060                 if (language == EShLangFragment)
8061                     ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
8062             }
8063             else
8064                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
8065         }
8066
8067         // GL_KHR_shader_subgroup
8068         if ((profile == EEsProfile && version >= 310) ||
8069             (profile != EEsProfile && version >= 140)) {
8070             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
8071             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
8072             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8073             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8074             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8075             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8076             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8077
8078             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
8079             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
8080             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
8081             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
8082             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
8083             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
8084             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
8085
8086             // GL_NV_shader_sm_builtins
8087             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
8088             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
8089             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
8090             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
8091             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
8092             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
8093             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
8094             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
8095         }
8096
8097                 if (language == EShLangGeometry || language == EShLangVertex) {
8098                         if ((profile == EEsProfile && version >= 310) ||
8099                                 (profile != EEsProfile && version >= 450)) {
8100                                 symbolTable.setVariableExtensions("gl_PrimitiveShadingRateEXT", 1, &E_GL_EXT_fragment_shading_rate);
8101                                 BuiltInVariable("gl_PrimitiveShadingRateEXT", EbvPrimitiveShadingRateKHR, symbolTable);
8102
8103                                 symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8104                                 symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8105                                 symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8106                                 symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8107                         }
8108                 }
8109
8110 #endif // !GLSLANG_WEB
8111         break;
8112
8113     case EShLangFragment:
8114         SpecialQualifier("gl_FrontFacing",      EvqFace,       EbvFace,             symbolTable);
8115         SpecialQualifier("gl_FragCoord",        EvqFragCoord,  EbvFragCoord,        symbolTable);
8116         SpecialQualifier("gl_PointCoord",       EvqPointCoord, EbvPointCoord,       symbolTable);
8117         if (spvVersion.spv == 0)
8118             SpecialQualifier("gl_FragColor",    EvqFragColor,  EbvFragColor,        symbolTable);
8119         else {
8120             TSymbol* symbol = symbolTable.find("gl_FragColor");
8121             if (symbol) {
8122                 symbol->getWritableType().getQualifier().storage = EvqVaryingOut;
8123                 symbol->getWritableType().getQualifier().layoutLocation = 0;
8124             }
8125         }
8126         SpecialQualifier("gl_FragDepth",        EvqFragDepth,  EbvFragDepth,        symbolTable);
8127 #ifndef GLSLANG_WEB
8128         SpecialQualifier("gl_FragDepthEXT",     EvqFragDepth,  EbvFragDepth,        symbolTable);
8129         SpecialQualifier("gl_FragStencilRefARB", EvqFragStencil, EbvFragStencilRef, symbolTable);
8130         SpecialQualifier("gl_HelperInvocation", EvqVaryingIn,  EbvHelperInvocation, symbolTable);
8131
8132         BuiltInVariable("gl_ClipDistance",    EbvClipDistance,   symbolTable);
8133         BuiltInVariable("gl_CullDistance",    EbvCullDistance,   symbolTable);
8134         BuiltInVariable("gl_PrimitiveID",     EbvPrimitiveId,    symbolTable);
8135
8136         if (profile != EEsProfile && version >= 140) {
8137             symbolTable.setVariableExtensions("gl_FragStencilRefARB", 1, &E_GL_ARB_shader_stencil_export);
8138             BuiltInVariable("gl_FragStencilRefARB", EbvFragStencilRef, symbolTable);
8139         }
8140
8141         if (profile != EEsProfile && version < 400) {
8142             symbolTable.setFunctionExtensions("textureQueryLOD", 1, &E_GL_ARB_texture_query_lod);
8143         }
8144
8145         if (profile != EEsProfile && version >= 460) {
8146             symbolTable.setFunctionExtensions("rayQueryInitializeEXT",                                            1, &E_GL_EXT_ray_query);
8147             symbolTable.setFunctionExtensions("rayQueryTerminateEXT",                                             1, &E_GL_EXT_ray_query);
8148             symbolTable.setFunctionExtensions("rayQueryGenerateIntersectionEXT",                                  1, &E_GL_EXT_ray_query);
8149             symbolTable.setFunctionExtensions("rayQueryConfirmIntersectionEXT",                                   1, &E_GL_EXT_ray_query);
8150             symbolTable.setFunctionExtensions("rayQueryProceedEXT",                                               1, &E_GL_EXT_ray_query);
8151             symbolTable.setFunctionExtensions("rayQueryGetIntersectionTypeEXT",                                   1, &E_GL_EXT_ray_query);
8152             symbolTable.setFunctionExtensions("rayQueryGetIntersectionTEXT",                                      1, &E_GL_EXT_ray_query);
8153             symbolTable.setFunctionExtensions("rayQueryGetRayFlagsEXT",                                           1, &E_GL_EXT_ray_query);
8154             symbolTable.setFunctionExtensions("rayQueryGetRayTMinEXT",                                            1, &E_GL_EXT_ray_query);
8155             symbolTable.setFunctionExtensions("rayQueryGetIntersectionInstanceCustomIndexEXT",                    1, &E_GL_EXT_ray_query);
8156             symbolTable.setFunctionExtensions("rayQueryGetIntersectionInstanceIdEXT",                             1, &E_GL_EXT_ray_query);
8157             symbolTable.setFunctionExtensions("rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT", 1, &E_GL_EXT_ray_query);
8158             symbolTable.setFunctionExtensions("rayQueryGetIntersectionGeometryIndexEXT",                          1, &E_GL_EXT_ray_query);
8159             symbolTable.setFunctionExtensions("rayQueryGetIntersectionPrimitiveIndexEXT",                         1, &E_GL_EXT_ray_query);
8160             symbolTable.setFunctionExtensions("rayQueryGetIntersectionBarycentricsEXT",                           1, &E_GL_EXT_ray_query);
8161             symbolTable.setFunctionExtensions("rayQueryGetIntersectionFrontFaceEXT",                              1, &E_GL_EXT_ray_query);
8162             symbolTable.setFunctionExtensions("rayQueryGetIntersectionCandidateAABBOpaqueEXT",                    1, &E_GL_EXT_ray_query);
8163             symbolTable.setFunctionExtensions("rayQueryGetIntersectionObjectRayDirectionEXT",                     1, &E_GL_EXT_ray_query);
8164             symbolTable.setFunctionExtensions("rayQueryGetIntersectionObjectRayOriginEXT",                        1, &E_GL_EXT_ray_query);
8165             symbolTable.setFunctionExtensions("rayQueryGetIntersectionObjectToWorldEXT",                          1, &E_GL_EXT_ray_query);
8166             symbolTable.setFunctionExtensions("rayQueryGetIntersectionWorldToObjectEXT",                          1, &E_GL_EXT_ray_query);
8167             symbolTable.setFunctionExtensions("rayQueryGetWorldRayOriginEXT",                                     1, &E_GL_EXT_ray_query);
8168             symbolTable.setFunctionExtensions("rayQueryGetWorldRayDirectionEXT",                                  1, &E_GL_EXT_ray_query);
8169             symbolTable.setVariableExtensions("gl_RayFlagsSkipAABBEXT",                         1, &E_GL_EXT_ray_flags_primitive_culling);
8170             symbolTable.setVariableExtensions("gl_RayFlagsSkipTrianglesEXT",                    1, &E_GL_EXT_ray_flags_primitive_culling);
8171             symbolTable.setVariableExtensions("gl_RayFlagsForceOpacityMicromap2StateEXT",                  1, &E_GL_EXT_opacity_micromap);
8172         }
8173
8174         if ((profile != EEsProfile && version >= 130) ||
8175             (profile == EEsProfile && version >= 310)) {
8176             BuiltInVariable("gl_SampleID",           EbvSampleId,       symbolTable);
8177             BuiltInVariable("gl_SamplePosition",     EbvSamplePosition, symbolTable);
8178             BuiltInVariable("gl_SampleMask",         EbvSampleMask,     symbolTable);
8179
8180             if (profile != EEsProfile && version < 400) {
8181                 BuiltInVariable("gl_NumSamples",     EbvSampleMask,     symbolTable);
8182
8183                 symbolTable.setVariableExtensions("gl_SampleMask",     1, &E_GL_ARB_sample_shading);
8184                 symbolTable.setVariableExtensions("gl_SampleID",       1, &E_GL_ARB_sample_shading);
8185                 symbolTable.setVariableExtensions("gl_SamplePosition", 1, &E_GL_ARB_sample_shading);
8186                 symbolTable.setVariableExtensions("gl_NumSamples",     1, &E_GL_ARB_sample_shading);
8187             } else {
8188                 BuiltInVariable("gl_SampleMaskIn",    EbvSampleMask,     symbolTable);
8189
8190                 if (profile == EEsProfile && version < 320) {
8191                     symbolTable.setVariableExtensions("gl_SampleID", 1, &E_GL_OES_sample_variables);
8192                     symbolTable.setVariableExtensions("gl_SamplePosition", 1, &E_GL_OES_sample_variables);
8193                     symbolTable.setVariableExtensions("gl_SampleMaskIn", 1, &E_GL_OES_sample_variables);
8194                     symbolTable.setVariableExtensions("gl_SampleMask", 1, &E_GL_OES_sample_variables);
8195                     symbolTable.setVariableExtensions("gl_NumSamples", 1, &E_GL_OES_sample_variables);
8196                 }
8197             }
8198         }
8199
8200         BuiltInVariable("gl_Layer",           EbvLayer,          symbolTable);
8201         BuiltInVariable("gl_ViewportIndex",   EbvViewportIndex,  symbolTable);
8202
8203         // Compatibility variables
8204
8205         BuiltInVariable("gl_in", "gl_FogFragCoord",   EbvFogFragCoord,   symbolTable);
8206         BuiltInVariable("gl_in", "gl_TexCoord",       EbvTexCoord,       symbolTable);
8207         BuiltInVariable("gl_in", "gl_Color",          EbvColor,          symbolTable);
8208         BuiltInVariable("gl_in", "gl_SecondaryColor", EbvSecondaryColor, symbolTable);
8209
8210         BuiltInVariable("gl_FogFragCoord",   EbvFogFragCoord,   symbolTable);
8211         BuiltInVariable("gl_TexCoord",       EbvTexCoord,       symbolTable);
8212         BuiltInVariable("gl_Color",          EbvColor,          symbolTable);
8213         BuiltInVariable("gl_SecondaryColor", EbvSecondaryColor, symbolTable);
8214
8215         // built-in functions
8216
8217         if (profile == EEsProfile) {
8218             if (spvVersion.spv == 0) {
8219                 symbolTable.setFunctionExtensions("texture2DLodEXT",      1, &E_GL_EXT_shader_texture_lod);
8220                 symbolTable.setFunctionExtensions("texture2DProjLodEXT",  1, &E_GL_EXT_shader_texture_lod);
8221                 symbolTable.setFunctionExtensions("textureCubeLodEXT",    1, &E_GL_EXT_shader_texture_lod);
8222                 symbolTable.setFunctionExtensions("texture2DGradEXT",     1, &E_GL_EXT_shader_texture_lod);
8223                 symbolTable.setFunctionExtensions("texture2DProjGradEXT", 1, &E_GL_EXT_shader_texture_lod);
8224                 symbolTable.setFunctionExtensions("textureCubeGradEXT",   1, &E_GL_EXT_shader_texture_lod);
8225                 if (version < 320)
8226                     symbolTable.setFunctionExtensions("textureGatherOffsets", Num_AEP_gpu_shader5, AEP_gpu_shader5);
8227             }
8228             if (version == 100) {
8229                 symbolTable.setFunctionExtensions("dFdx",   1, &E_GL_OES_standard_derivatives);
8230                 symbolTable.setFunctionExtensions("dFdy",   1, &E_GL_OES_standard_derivatives);
8231                 symbolTable.setFunctionExtensions("fwidth", 1, &E_GL_OES_standard_derivatives);
8232             }
8233             if (version == 310) {
8234                 symbolTable.setFunctionExtensions("fma", Num_AEP_gpu_shader5, AEP_gpu_shader5);
8235                 symbolTable.setFunctionExtensions("interpolateAtCentroid", 1, &E_GL_OES_shader_multisample_interpolation);
8236                 symbolTable.setFunctionExtensions("interpolateAtSample",   1, &E_GL_OES_shader_multisample_interpolation);
8237                 symbolTable.setFunctionExtensions("interpolateAtOffset",   1, &E_GL_OES_shader_multisample_interpolation);
8238             }
8239         } else if (version < 130) {
8240             if (spvVersion.spv == 0) {
8241                 symbolTable.setFunctionExtensions("texture1DLod",        1, &E_GL_ARB_shader_texture_lod);
8242                 symbolTable.setFunctionExtensions("texture2DLod",        1, &E_GL_ARB_shader_texture_lod);
8243                 symbolTable.setFunctionExtensions("texture3DLod",        1, &E_GL_ARB_shader_texture_lod);
8244                 symbolTable.setFunctionExtensions("textureCubeLod",      1, &E_GL_ARB_shader_texture_lod);
8245                 symbolTable.setFunctionExtensions("texture1DProjLod",    1, &E_GL_ARB_shader_texture_lod);
8246                 symbolTable.setFunctionExtensions("texture2DProjLod",    1, &E_GL_ARB_shader_texture_lod);
8247                 symbolTable.setFunctionExtensions("texture3DProjLod",    1, &E_GL_ARB_shader_texture_lod);
8248                 symbolTable.setFunctionExtensions("shadow1DLod",         1, &E_GL_ARB_shader_texture_lod);
8249                 symbolTable.setFunctionExtensions("shadow2DLod",         1, &E_GL_ARB_shader_texture_lod);
8250                 symbolTable.setFunctionExtensions("shadow1DProjLod",     1, &E_GL_ARB_shader_texture_lod);
8251                 symbolTable.setFunctionExtensions("shadow2DProjLod",     1, &E_GL_ARB_shader_texture_lod);
8252             }
8253         }
8254
8255         // E_GL_ARB_shader_texture_lod functions usable only with the extension enabled
8256         if (profile != EEsProfile && spvVersion.spv == 0) {
8257             symbolTable.setFunctionExtensions("texture1DGradARB",         1, &E_GL_ARB_shader_texture_lod);
8258             symbolTable.setFunctionExtensions("texture1DProjGradARB",     1, &E_GL_ARB_shader_texture_lod);
8259             symbolTable.setFunctionExtensions("texture2DGradARB",         1, &E_GL_ARB_shader_texture_lod);
8260             symbolTable.setFunctionExtensions("texture2DProjGradARB",     1, &E_GL_ARB_shader_texture_lod);
8261             symbolTable.setFunctionExtensions("texture3DGradARB",         1, &E_GL_ARB_shader_texture_lod);
8262             symbolTable.setFunctionExtensions("texture3DProjGradARB",     1, &E_GL_ARB_shader_texture_lod);
8263             symbolTable.setFunctionExtensions("textureCubeGradARB",       1, &E_GL_ARB_shader_texture_lod);
8264             symbolTable.setFunctionExtensions("shadow1DGradARB",          1, &E_GL_ARB_shader_texture_lod);
8265             symbolTable.setFunctionExtensions("shadow1DProjGradARB",      1, &E_GL_ARB_shader_texture_lod);
8266             symbolTable.setFunctionExtensions("shadow2DGradARB",          1, &E_GL_ARB_shader_texture_lod);
8267             symbolTable.setFunctionExtensions("shadow2DProjGradARB",      1, &E_GL_ARB_shader_texture_lod);
8268             symbolTable.setFunctionExtensions("texture2DRectGradARB",     1, &E_GL_ARB_shader_texture_lod);
8269             symbolTable.setFunctionExtensions("texture2DRectProjGradARB", 1, &E_GL_ARB_shader_texture_lod);
8270             symbolTable.setFunctionExtensions("shadow2DRectGradARB",      1, &E_GL_ARB_shader_texture_lod);
8271             symbolTable.setFunctionExtensions("shadow2DRectProjGradARB",  1, &E_GL_ARB_shader_texture_lod);
8272         }
8273
8274         // E_GL_ARB_shader_image_load_store
8275         if (profile != EEsProfile && version < 420)
8276             symbolTable.setFunctionExtensions("memoryBarrier", 1, &E_GL_ARB_shader_image_load_store);
8277         // All the image access functions are protected by checks on the type of the first argument.
8278
8279         // E_GL_ARB_shader_atomic_counters
8280         if (profile != EEsProfile && version < 420) {
8281             symbolTable.setFunctionExtensions("atomicCounterIncrement", 1, &E_GL_ARB_shader_atomic_counters);
8282             symbolTable.setFunctionExtensions("atomicCounterDecrement", 1, &E_GL_ARB_shader_atomic_counters);
8283             symbolTable.setFunctionExtensions("atomicCounter"         , 1, &E_GL_ARB_shader_atomic_counters);
8284         }
8285
8286         // E_GL_ARB_shader_atomic_counter_ops
8287         if (profile != EEsProfile && version == 450) {
8288             symbolTable.setFunctionExtensions("atomicCounterAddARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8289             symbolTable.setFunctionExtensions("atomicCounterSubtractARB", 1, &E_GL_ARB_shader_atomic_counter_ops);
8290             symbolTable.setFunctionExtensions("atomicCounterMinARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8291             symbolTable.setFunctionExtensions("atomicCounterMaxARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8292             symbolTable.setFunctionExtensions("atomicCounterAndARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8293             symbolTable.setFunctionExtensions("atomicCounterOrARB"      , 1, &E_GL_ARB_shader_atomic_counter_ops);
8294             symbolTable.setFunctionExtensions("atomicCounterXorARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8295             symbolTable.setFunctionExtensions("atomicCounterExchangeARB", 1, &E_GL_ARB_shader_atomic_counter_ops);
8296             symbolTable.setFunctionExtensions("atomicCounterCompSwapARB", 1, &E_GL_ARB_shader_atomic_counter_ops);
8297         }
8298
8299         // E_GL_ARB_derivative_control
8300         if (profile != EEsProfile && version < 450) {
8301             symbolTable.setFunctionExtensions("dFdxFine",     1, &E_GL_ARB_derivative_control);
8302             symbolTable.setFunctionExtensions("dFdyFine",     1, &E_GL_ARB_derivative_control);
8303             symbolTable.setFunctionExtensions("fwidthFine",   1, &E_GL_ARB_derivative_control);
8304             symbolTable.setFunctionExtensions("dFdxCoarse",   1, &E_GL_ARB_derivative_control);
8305             symbolTable.setFunctionExtensions("dFdyCoarse",   1, &E_GL_ARB_derivative_control);
8306             symbolTable.setFunctionExtensions("fwidthCoarse", 1, &E_GL_ARB_derivative_control);
8307         }
8308
8309         // E_GL_ARB_sparse_texture2
8310         if (profile != EEsProfile)
8311         {
8312             symbolTable.setFunctionExtensions("sparseTextureARB",              1, &E_GL_ARB_sparse_texture2);
8313             symbolTable.setFunctionExtensions("sparseTextureLodARB",           1, &E_GL_ARB_sparse_texture2);
8314             symbolTable.setFunctionExtensions("sparseTextureOffsetARB",        1, &E_GL_ARB_sparse_texture2);
8315             symbolTable.setFunctionExtensions("sparseTexelFetchARB",           1, &E_GL_ARB_sparse_texture2);
8316             symbolTable.setFunctionExtensions("sparseTexelFetchOffsetARB",     1, &E_GL_ARB_sparse_texture2);
8317             symbolTable.setFunctionExtensions("sparseTextureLodOffsetARB",     1, &E_GL_ARB_sparse_texture2);
8318             symbolTable.setFunctionExtensions("sparseTextureGradARB",          1, &E_GL_ARB_sparse_texture2);
8319             symbolTable.setFunctionExtensions("sparseTextureGradOffsetARB",    1, &E_GL_ARB_sparse_texture2);
8320             symbolTable.setFunctionExtensions("sparseTextureGatherARB",        1, &E_GL_ARB_sparse_texture2);
8321             symbolTable.setFunctionExtensions("sparseTextureGatherOffsetARB",  1, &E_GL_ARB_sparse_texture2);
8322             symbolTable.setFunctionExtensions("sparseTextureGatherOffsetsARB", 1, &E_GL_ARB_sparse_texture2);
8323             symbolTable.setFunctionExtensions("sparseImageLoadARB",            1, &E_GL_ARB_sparse_texture2);
8324             symbolTable.setFunctionExtensions("sparseTexelsResident",          1, &E_GL_ARB_sparse_texture2);
8325         }
8326
8327         // E_GL_ARB_sparse_texture_clamp
8328         if (profile != EEsProfile)
8329         {
8330             symbolTable.setFunctionExtensions("sparseTextureClampARB",              1, &E_GL_ARB_sparse_texture_clamp);
8331             symbolTable.setFunctionExtensions("sparseTextureOffsetClampARB",        1, &E_GL_ARB_sparse_texture_clamp);
8332             symbolTable.setFunctionExtensions("sparseTextureGradClampARB",          1, &E_GL_ARB_sparse_texture_clamp);
8333             symbolTable.setFunctionExtensions("sparseTextureGradOffsetClampARB",    1, &E_GL_ARB_sparse_texture_clamp);
8334             symbolTable.setFunctionExtensions("textureClampARB",                    1, &E_GL_ARB_sparse_texture_clamp);
8335             symbolTable.setFunctionExtensions("textureOffsetClampARB",              1, &E_GL_ARB_sparse_texture_clamp);
8336             symbolTable.setFunctionExtensions("textureGradClampARB",                1, &E_GL_ARB_sparse_texture_clamp);
8337             symbolTable.setFunctionExtensions("textureGradOffsetClampARB",          1, &E_GL_ARB_sparse_texture_clamp);
8338         }
8339
8340         // E_GL_AMD_shader_explicit_vertex_parameter
8341         if (profile != EEsProfile) {
8342             symbolTable.setVariableExtensions("gl_BaryCoordNoPerspAMD",         1, &E_GL_AMD_shader_explicit_vertex_parameter);
8343             symbolTable.setVariableExtensions("gl_BaryCoordNoPerspCentroidAMD", 1, &E_GL_AMD_shader_explicit_vertex_parameter);
8344             symbolTable.setVariableExtensions("gl_BaryCoordNoPerspSampleAMD",   1, &E_GL_AMD_shader_explicit_vertex_parameter);
8345             symbolTable.setVariableExtensions("gl_BaryCoordSmoothAMD",          1, &E_GL_AMD_shader_explicit_vertex_parameter);
8346             symbolTable.setVariableExtensions("gl_BaryCoordSmoothCentroidAMD",  1, &E_GL_AMD_shader_explicit_vertex_parameter);
8347             symbolTable.setVariableExtensions("gl_BaryCoordSmoothSampleAMD",    1, &E_GL_AMD_shader_explicit_vertex_parameter);
8348             symbolTable.setVariableExtensions("gl_BaryCoordPullModelAMD",       1, &E_GL_AMD_shader_explicit_vertex_parameter);
8349
8350             symbolTable.setFunctionExtensions("interpolateAtVertexAMD",         1, &E_GL_AMD_shader_explicit_vertex_parameter);
8351
8352             BuiltInVariable("gl_BaryCoordNoPerspAMD",           EbvBaryCoordNoPersp,         symbolTable);
8353             BuiltInVariable("gl_BaryCoordNoPerspCentroidAMD",   EbvBaryCoordNoPerspCentroid, symbolTable);
8354             BuiltInVariable("gl_BaryCoordNoPerspSampleAMD",     EbvBaryCoordNoPerspSample,   symbolTable);
8355             BuiltInVariable("gl_BaryCoordSmoothAMD",            EbvBaryCoordSmooth,          symbolTable);
8356             BuiltInVariable("gl_BaryCoordSmoothCentroidAMD",    EbvBaryCoordSmoothCentroid,  symbolTable);
8357             BuiltInVariable("gl_BaryCoordSmoothSampleAMD",      EbvBaryCoordSmoothSample,    symbolTable);
8358             BuiltInVariable("gl_BaryCoordPullModelAMD",         EbvBaryCoordPullModel,       symbolTable);
8359         }
8360
8361         // E_GL_AMD_texture_gather_bias_lod
8362         if (profile != EEsProfile) {
8363             symbolTable.setFunctionExtensions("textureGatherLodAMD",                1, &E_GL_AMD_texture_gather_bias_lod);
8364             symbolTable.setFunctionExtensions("textureGatherLodOffsetAMD",          1, &E_GL_AMD_texture_gather_bias_lod);
8365             symbolTable.setFunctionExtensions("textureGatherLodOffsetsAMD",         1, &E_GL_AMD_texture_gather_bias_lod);
8366             symbolTable.setFunctionExtensions("sparseTextureGatherLodAMD",          1, &E_GL_AMD_texture_gather_bias_lod);
8367             symbolTable.setFunctionExtensions("sparseTextureGatherLodOffsetAMD",    1, &E_GL_AMD_texture_gather_bias_lod);
8368             symbolTable.setFunctionExtensions("sparseTextureGatherLodOffsetsAMD",   1, &E_GL_AMD_texture_gather_bias_lod);
8369         }
8370
8371         // E_GL_AMD_shader_image_load_store_lod
8372         if (profile != EEsProfile) {
8373             symbolTable.setFunctionExtensions("imageLoadLodAMD",        1, &E_GL_AMD_shader_image_load_store_lod);
8374             symbolTable.setFunctionExtensions("imageStoreLodAMD",       1, &E_GL_AMD_shader_image_load_store_lod);
8375             symbolTable.setFunctionExtensions("sparseImageLoadLodAMD",  1, &E_GL_AMD_shader_image_load_store_lod);
8376         }
8377         if (profile != EEsProfile && version >= 430) {
8378             symbolTable.setVariableExtensions("gl_FragFullyCoveredNV", 1, &E_GL_NV_conservative_raster_underestimation);
8379             BuiltInVariable("gl_FragFullyCoveredNV", EbvFragFullyCoveredNV, symbolTable);
8380         }
8381         if ((profile != EEsProfile && version >= 450) ||
8382             (profile == EEsProfile && version >= 320)) {
8383             symbolTable.setVariableExtensions("gl_FragmentSizeNV",        1, &E_GL_NV_shading_rate_image);
8384             symbolTable.setVariableExtensions("gl_InvocationsPerPixelNV", 1, &E_GL_NV_shading_rate_image);
8385             BuiltInVariable("gl_FragmentSizeNV",        EbvFragmentSizeNV, symbolTable);
8386             BuiltInVariable("gl_InvocationsPerPixelNV", EbvInvocationsPerPixelNV, symbolTable);
8387             symbolTable.setVariableExtensions("gl_BaryCoordNV",        1, &E_GL_NV_fragment_shader_barycentric);
8388             symbolTable.setVariableExtensions("gl_BaryCoordNoPerspNV", 1, &E_GL_NV_fragment_shader_barycentric);
8389             BuiltInVariable("gl_BaryCoordNV",        EbvBaryCoordNV,        symbolTable);
8390             BuiltInVariable("gl_BaryCoordNoPerspNV", EbvBaryCoordNoPerspNV, symbolTable);
8391             symbolTable.setVariableExtensions("gl_BaryCoordEXT",        1, &E_GL_EXT_fragment_shader_barycentric);
8392             symbolTable.setVariableExtensions("gl_BaryCoordNoPerspEXT", 1, &E_GL_EXT_fragment_shader_barycentric);
8393             BuiltInVariable("gl_BaryCoordEXT",        EbvBaryCoordEXT,        symbolTable);
8394             BuiltInVariable("gl_BaryCoordNoPerspEXT", EbvBaryCoordNoPerspEXT, symbolTable);
8395         }
8396
8397         if ((profile != EEsProfile && version >= 450) ||
8398             (profile == EEsProfile && version >= 310)) {
8399             symbolTable.setVariableExtensions("gl_FragSizeEXT",            1, &E_GL_EXT_fragment_invocation_density);
8400             symbolTable.setVariableExtensions("gl_FragInvocationCountEXT", 1, &E_GL_EXT_fragment_invocation_density);
8401             BuiltInVariable("gl_FragSizeEXT",            EbvFragSizeEXT, symbolTable);
8402             BuiltInVariable("gl_FragInvocationCountEXT", EbvFragInvocationCountEXT, symbolTable);
8403         }
8404
8405         symbolTable.setVariableExtensions("gl_FragDepthEXT", 1, &E_GL_EXT_frag_depth);
8406
8407         symbolTable.setFunctionExtensions("clockARB",     1, &E_GL_ARB_shader_clock);
8408         symbolTable.setFunctionExtensions("clock2x32ARB", 1, &E_GL_ARB_shader_clock);
8409
8410         symbolTable.setFunctionExtensions("clockRealtimeEXT", 1, &E_GL_EXT_shader_realtime_clock);
8411         symbolTable.setFunctionExtensions("clockRealtime2x32EXT", 1, &E_GL_EXT_shader_realtime_clock);
8412
8413         if (profile == EEsProfile && version < 320) {
8414             symbolTable.setVariableExtensions("gl_PrimitiveID",  Num_AEP_geometry_shader, AEP_geometry_shader);
8415             symbolTable.setVariableExtensions("gl_Layer",        Num_AEP_geometry_shader, AEP_geometry_shader);
8416         }
8417
8418         if (profile == EEsProfile && version < 320) {
8419             symbolTable.setFunctionExtensions("imageAtomicAdd",      1, &E_GL_OES_shader_image_atomic);
8420             symbolTable.setFunctionExtensions("imageAtomicMin",      1, &E_GL_OES_shader_image_atomic);
8421             symbolTable.setFunctionExtensions("imageAtomicMax",      1, &E_GL_OES_shader_image_atomic);
8422             symbolTable.setFunctionExtensions("imageAtomicAnd",      1, &E_GL_OES_shader_image_atomic);
8423             symbolTable.setFunctionExtensions("imageAtomicOr",       1, &E_GL_OES_shader_image_atomic);
8424             symbolTable.setFunctionExtensions("imageAtomicXor",      1, &E_GL_OES_shader_image_atomic);
8425             symbolTable.setFunctionExtensions("imageAtomicExchange", 1, &E_GL_OES_shader_image_atomic);
8426             symbolTable.setFunctionExtensions("imageAtomicCompSwap", 1, &E_GL_OES_shader_image_atomic);
8427         }
8428
8429         if (profile != EEsProfile && version < 330 ) {
8430             const char* bitsConvertExt[2] = {E_GL_ARB_shader_bit_encoding, E_GL_ARB_gpu_shader5};
8431             symbolTable.setFunctionExtensions("floatBitsToInt", 2, bitsConvertExt);
8432             symbolTable.setFunctionExtensions("floatBitsToUint", 2, bitsConvertExt);
8433             symbolTable.setFunctionExtensions("intBitsToFloat", 2, bitsConvertExt);
8434             symbolTable.setFunctionExtensions("uintBitsToFloat", 2, bitsConvertExt);
8435         }
8436
8437         if (profile != EEsProfile && version < 430 ) {
8438             symbolTable.setFunctionExtensions("imageSize", 1, &E_GL_ARB_shader_image_size);
8439         }
8440
8441         // GL_ARB_shader_storage_buffer_object
8442         if (profile != EEsProfile && version < 430 ) {
8443             symbolTable.setFunctionExtensions("atomicAdd", 1, &E_GL_ARB_shader_storage_buffer_object);
8444             symbolTable.setFunctionExtensions("atomicMin", 1, &E_GL_ARB_shader_storage_buffer_object);
8445             symbolTable.setFunctionExtensions("atomicMax", 1, &E_GL_ARB_shader_storage_buffer_object);
8446             symbolTable.setFunctionExtensions("atomicAnd", 1, &E_GL_ARB_shader_storage_buffer_object);
8447             symbolTable.setFunctionExtensions("atomicOr", 1, &E_GL_ARB_shader_storage_buffer_object);
8448             symbolTable.setFunctionExtensions("atomicXor", 1, &E_GL_ARB_shader_storage_buffer_object);
8449             symbolTable.setFunctionExtensions("atomicExchange", 1, &E_GL_ARB_shader_storage_buffer_object);
8450             symbolTable.setFunctionExtensions("atomicCompSwap", 1, &E_GL_ARB_shader_storage_buffer_object);
8451         }
8452
8453         // GL_ARB_shading_language_packing
8454         if (profile != EEsProfile && version < 400 ) {
8455             symbolTable.setFunctionExtensions("packUnorm2x16", 1, &E_GL_ARB_shading_language_packing);
8456             symbolTable.setFunctionExtensions("unpackUnorm2x16", 1, &E_GL_ARB_shading_language_packing);
8457             symbolTable.setFunctionExtensions("packSnorm4x8", 1, &E_GL_ARB_shading_language_packing);
8458             symbolTable.setFunctionExtensions("packUnorm4x8", 1, &E_GL_ARB_shading_language_packing);
8459             symbolTable.setFunctionExtensions("unpackSnorm4x8", 1, &E_GL_ARB_shading_language_packing);
8460             symbolTable.setFunctionExtensions("unpackUnorm4x8", 1, &E_GL_ARB_shading_language_packing);
8461         }
8462         if (profile != EEsProfile && version < 420 ) {
8463             symbolTable.setFunctionExtensions("packSnorm2x16", 1, &E_GL_ARB_shading_language_packing);
8464             symbolTable.setFunctionExtensions("unpackSnorm2x16", 1, &E_GL_ARB_shading_language_packing);
8465             symbolTable.setFunctionExtensions("unpackHalf2x16", 1, &E_GL_ARB_shading_language_packing);
8466             symbolTable.setFunctionExtensions("packHalf2x16", 1, &E_GL_ARB_shading_language_packing);
8467         }
8468
8469         symbolTable.setVariableExtensions("gl_DeviceIndex",  1, &E_GL_EXT_device_group);
8470         BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
8471         symbolTable.setVariableExtensions("gl_ViewIndex", 1, &E_GL_EXT_multiview);
8472         BuiltInVariable("gl_ViewIndex", EbvViewIndex, symbolTable);
8473         if (version >= 300 /* both ES and non-ES */) {
8474             symbolTable.setVariableExtensions("gl_ViewID_OVR", Num_OVR_multiview_EXTs, OVR_multiview_EXTs);
8475             BuiltInVariable("gl_ViewID_OVR", EbvViewIndex, symbolTable);
8476         }
8477
8478         // GL_ARB_shader_ballot
8479         if (profile != EEsProfile) {
8480             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
8481             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
8482             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
8483             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
8484             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
8485             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
8486             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
8487
8488             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
8489             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
8490             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
8491             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
8492             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
8493             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
8494
8495             if (spvVersion.vulkan > 0) {
8496                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
8497                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
8498                 if (language == EShLangFragment)
8499                     ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
8500             }
8501             else
8502                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
8503         }
8504
8505         // GL_KHR_shader_subgroup
8506         if ((profile == EEsProfile && version >= 310) ||
8507             (profile != EEsProfile && version >= 140)) {
8508             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
8509             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
8510             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8511             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8512             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8513             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8514             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8515
8516             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
8517             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
8518             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
8519             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
8520             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
8521             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
8522             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
8523
8524             symbolTable.setFunctionExtensions("subgroupBarrier",                 1, &E_GL_KHR_shader_subgroup_basic);
8525             symbolTable.setFunctionExtensions("subgroupMemoryBarrier",           1, &E_GL_KHR_shader_subgroup_basic);
8526             symbolTable.setFunctionExtensions("subgroupMemoryBarrierBuffer",     1, &E_GL_KHR_shader_subgroup_basic);
8527             symbolTable.setFunctionExtensions("subgroupMemoryBarrierImage",      1, &E_GL_KHR_shader_subgroup_basic);
8528             symbolTable.setFunctionExtensions("subgroupElect",                   1, &E_GL_KHR_shader_subgroup_basic);
8529             symbolTable.setFunctionExtensions("subgroupAll",                     1, &E_GL_KHR_shader_subgroup_vote);
8530             symbolTable.setFunctionExtensions("subgroupAny",                     1, &E_GL_KHR_shader_subgroup_vote);
8531             symbolTable.setFunctionExtensions("subgroupAllEqual",                1, &E_GL_KHR_shader_subgroup_vote);
8532             symbolTable.setFunctionExtensions("subgroupBroadcast",               1, &E_GL_KHR_shader_subgroup_ballot);
8533             symbolTable.setFunctionExtensions("subgroupBroadcastFirst",          1, &E_GL_KHR_shader_subgroup_ballot);
8534             symbolTable.setFunctionExtensions("subgroupBallot",                  1, &E_GL_KHR_shader_subgroup_ballot);
8535             symbolTable.setFunctionExtensions("subgroupInverseBallot",           1, &E_GL_KHR_shader_subgroup_ballot);
8536             symbolTable.setFunctionExtensions("subgroupBallotBitExtract",        1, &E_GL_KHR_shader_subgroup_ballot);
8537             symbolTable.setFunctionExtensions("subgroupBallotBitCount",          1, &E_GL_KHR_shader_subgroup_ballot);
8538             symbolTable.setFunctionExtensions("subgroupBallotInclusiveBitCount", 1, &E_GL_KHR_shader_subgroup_ballot);
8539             symbolTable.setFunctionExtensions("subgroupBallotExclusiveBitCount", 1, &E_GL_KHR_shader_subgroup_ballot);
8540             symbolTable.setFunctionExtensions("subgroupBallotFindLSB",           1, &E_GL_KHR_shader_subgroup_ballot);
8541             symbolTable.setFunctionExtensions("subgroupBallotFindMSB",           1, &E_GL_KHR_shader_subgroup_ballot);
8542             symbolTable.setFunctionExtensions("subgroupShuffle",                 1, &E_GL_KHR_shader_subgroup_shuffle);
8543             symbolTable.setFunctionExtensions("subgroupShuffleXor",              1, &E_GL_KHR_shader_subgroup_shuffle);
8544             symbolTable.setFunctionExtensions("subgroupShuffleUp",               1, &E_GL_KHR_shader_subgroup_shuffle_relative);
8545             symbolTable.setFunctionExtensions("subgroupShuffleDown",             1, &E_GL_KHR_shader_subgroup_shuffle_relative);
8546             symbolTable.setFunctionExtensions("subgroupAdd",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8547             symbolTable.setFunctionExtensions("subgroupMul",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8548             symbolTable.setFunctionExtensions("subgroupMin",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8549             symbolTable.setFunctionExtensions("subgroupMax",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8550             symbolTable.setFunctionExtensions("subgroupAnd",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8551             symbolTable.setFunctionExtensions("subgroupOr",                      1, &E_GL_KHR_shader_subgroup_arithmetic);
8552             symbolTable.setFunctionExtensions("subgroupXor",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8553             symbolTable.setFunctionExtensions("subgroupInclusiveAdd",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8554             symbolTable.setFunctionExtensions("subgroupInclusiveMul",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8555             symbolTable.setFunctionExtensions("subgroupInclusiveMin",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8556             symbolTable.setFunctionExtensions("subgroupInclusiveMax",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8557             symbolTable.setFunctionExtensions("subgroupInclusiveAnd",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8558             symbolTable.setFunctionExtensions("subgroupInclusiveOr",             1, &E_GL_KHR_shader_subgroup_arithmetic);
8559             symbolTable.setFunctionExtensions("subgroupInclusiveXor",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8560             symbolTable.setFunctionExtensions("subgroupExclusiveAdd",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8561             symbolTable.setFunctionExtensions("subgroupExclusiveMul",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8562             symbolTable.setFunctionExtensions("subgroupExclusiveMin",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8563             symbolTable.setFunctionExtensions("subgroupExclusiveMax",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8564             symbolTable.setFunctionExtensions("subgroupExclusiveAnd",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8565             symbolTable.setFunctionExtensions("subgroupExclusiveOr",             1, &E_GL_KHR_shader_subgroup_arithmetic);
8566             symbolTable.setFunctionExtensions("subgroupExclusiveXor",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8567             symbolTable.setFunctionExtensions("subgroupClusteredAdd",            1, &E_GL_KHR_shader_subgroup_clustered);
8568             symbolTable.setFunctionExtensions("subgroupClusteredMul",            1, &E_GL_KHR_shader_subgroup_clustered);
8569             symbolTable.setFunctionExtensions("subgroupClusteredMin",            1, &E_GL_KHR_shader_subgroup_clustered);
8570             symbolTable.setFunctionExtensions("subgroupClusteredMax",            1, &E_GL_KHR_shader_subgroup_clustered);
8571             symbolTable.setFunctionExtensions("subgroupClusteredAnd",            1, &E_GL_KHR_shader_subgroup_clustered);
8572             symbolTable.setFunctionExtensions("subgroupClusteredOr",             1, &E_GL_KHR_shader_subgroup_clustered);
8573             symbolTable.setFunctionExtensions("subgroupClusteredXor",            1, &E_GL_KHR_shader_subgroup_clustered);
8574             symbolTable.setFunctionExtensions("subgroupQuadBroadcast",           1, &E_GL_KHR_shader_subgroup_quad);
8575             symbolTable.setFunctionExtensions("subgroupQuadSwapHorizontal",      1, &E_GL_KHR_shader_subgroup_quad);
8576             symbolTable.setFunctionExtensions("subgroupQuadSwapVertical",        1, &E_GL_KHR_shader_subgroup_quad);
8577             symbolTable.setFunctionExtensions("subgroupQuadSwapDiagonal",        1, &E_GL_KHR_shader_subgroup_quad);
8578             symbolTable.setFunctionExtensions("subgroupPartitionNV",                          1, &E_GL_NV_shader_subgroup_partitioned);
8579             symbolTable.setFunctionExtensions("subgroupPartitionedAddNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8580             symbolTable.setFunctionExtensions("subgroupPartitionedMulNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8581             symbolTable.setFunctionExtensions("subgroupPartitionedMinNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8582             symbolTable.setFunctionExtensions("subgroupPartitionedMaxNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8583             symbolTable.setFunctionExtensions("subgroupPartitionedAndNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8584             symbolTable.setFunctionExtensions("subgroupPartitionedOrNV",                      1, &E_GL_NV_shader_subgroup_partitioned);
8585             symbolTable.setFunctionExtensions("subgroupPartitionedXorNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8586             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveAddNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8587             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveMulNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8588             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveMinNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8589             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveMaxNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8590             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveAndNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8591             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveOrNV",             1, &E_GL_NV_shader_subgroup_partitioned);
8592             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveXorNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8593             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveAddNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8594             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveMulNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8595             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveMinNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8596             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveMaxNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8597             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveAndNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8598             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveOrNV",             1, &E_GL_NV_shader_subgroup_partitioned);
8599             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveXorNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8600
8601             // GL_NV_shader_sm_builtins
8602             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
8603             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
8604             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
8605             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
8606             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
8607             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
8608             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
8609             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
8610         }
8611
8612         if (profile == EEsProfile) {
8613             symbolTable.setFunctionExtensions("shadow2DEXT",        1, &E_GL_EXT_shadow_samplers);
8614             symbolTable.setFunctionExtensions("shadow2DProjEXT",    1, &E_GL_EXT_shadow_samplers);
8615         }
8616
8617         if (spvVersion.vulkan > 0) {
8618             symbolTable.setVariableExtensions("gl_ScopeDevice",             1, &E_GL_KHR_memory_scope_semantics);
8619             symbolTable.setVariableExtensions("gl_ScopeWorkgroup",          1, &E_GL_KHR_memory_scope_semantics);
8620             symbolTable.setVariableExtensions("gl_ScopeSubgroup",           1, &E_GL_KHR_memory_scope_semantics);
8621             symbolTable.setVariableExtensions("gl_ScopeInvocation",         1, &E_GL_KHR_memory_scope_semantics);
8622
8623             symbolTable.setVariableExtensions("gl_SemanticsRelaxed",        1, &E_GL_KHR_memory_scope_semantics);
8624             symbolTable.setVariableExtensions("gl_SemanticsAcquire",        1, &E_GL_KHR_memory_scope_semantics);
8625             symbolTable.setVariableExtensions("gl_SemanticsRelease",        1, &E_GL_KHR_memory_scope_semantics);
8626             symbolTable.setVariableExtensions("gl_SemanticsAcquireRelease", 1, &E_GL_KHR_memory_scope_semantics);
8627             symbolTable.setVariableExtensions("gl_SemanticsMakeAvailable",  1, &E_GL_KHR_memory_scope_semantics);
8628             symbolTable.setVariableExtensions("gl_SemanticsMakeVisible",    1, &E_GL_KHR_memory_scope_semantics);
8629             symbolTable.setVariableExtensions("gl_SemanticsVolatile",       1, &E_GL_KHR_memory_scope_semantics);
8630
8631             symbolTable.setVariableExtensions("gl_StorageSemanticsNone",    1, &E_GL_KHR_memory_scope_semantics);
8632             symbolTable.setVariableExtensions("gl_StorageSemanticsBuffer",  1, &E_GL_KHR_memory_scope_semantics);
8633             symbolTable.setVariableExtensions("gl_StorageSemanticsShared",  1, &E_GL_KHR_memory_scope_semantics);
8634             symbolTable.setVariableExtensions("gl_StorageSemanticsImage",   1, &E_GL_KHR_memory_scope_semantics);
8635             symbolTable.setVariableExtensions("gl_StorageSemanticsOutput",  1, &E_GL_KHR_memory_scope_semantics);
8636         }
8637
8638         symbolTable.setFunctionExtensions("helperInvocationEXT",            1, &E_GL_EXT_demote_to_helper_invocation);
8639
8640         if ((profile == EEsProfile && version >= 310) ||
8641             (profile != EEsProfile && version >= 450)) {
8642             symbolTable.setVariableExtensions("gl_ShadingRateEXT", 1, &E_GL_EXT_fragment_shading_rate);
8643             BuiltInVariable("gl_ShadingRateEXT", EbvShadingRateKHR, symbolTable);
8644
8645             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8646             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8647             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8648             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8649         }
8650 #endif // !GLSLANG_WEB
8651         break;
8652
8653     case EShLangCompute:
8654         BuiltInVariable("gl_NumWorkGroups",         EbvNumWorkGroups,        symbolTable);
8655         BuiltInVariable("gl_WorkGroupSize",         EbvWorkGroupSize,        symbolTable);
8656         BuiltInVariable("gl_WorkGroupID",           EbvWorkGroupId,          symbolTable);
8657         BuiltInVariable("gl_LocalInvocationID",     EbvLocalInvocationId,    symbolTable);
8658         BuiltInVariable("gl_GlobalInvocationID",    EbvGlobalInvocationId,   symbolTable);
8659         BuiltInVariable("gl_LocalInvocationIndex",  EbvLocalInvocationIndex, symbolTable);
8660         BuiltInVariable("gl_DeviceIndex",           EbvDeviceIndex,          symbolTable);
8661         BuiltInVariable("gl_ViewIndex",             EbvViewIndex,            symbolTable);
8662
8663 #ifndef GLSLANG_WEB
8664         if ((profile != EEsProfile && version >= 140) ||
8665             (profile == EEsProfile && version >= 310)) {
8666             symbolTable.setVariableExtensions("gl_DeviceIndex",  1, &E_GL_EXT_device_group);
8667             symbolTable.setVariableExtensions("gl_ViewIndex",    1, &E_GL_EXT_multiview);
8668         }
8669
8670         if (profile != EEsProfile && version < 430) {
8671             symbolTable.setVariableExtensions("gl_NumWorkGroups",        1, &E_GL_ARB_compute_shader);
8672             symbolTable.setVariableExtensions("gl_WorkGroupSize",        1, &E_GL_ARB_compute_shader);
8673             symbolTable.setVariableExtensions("gl_WorkGroupID",          1, &E_GL_ARB_compute_shader);
8674             symbolTable.setVariableExtensions("gl_LocalInvocationID",    1, &E_GL_ARB_compute_shader);
8675             symbolTable.setVariableExtensions("gl_GlobalInvocationID",   1, &E_GL_ARB_compute_shader);
8676             symbolTable.setVariableExtensions("gl_LocalInvocationIndex", 1, &E_GL_ARB_compute_shader);
8677
8678             symbolTable.setVariableExtensions("gl_MaxComputeWorkGroupCount",       1, &E_GL_ARB_compute_shader);
8679             symbolTable.setVariableExtensions("gl_MaxComputeWorkGroupSize",        1, &E_GL_ARB_compute_shader);
8680             symbolTable.setVariableExtensions("gl_MaxComputeUniformComponents",    1, &E_GL_ARB_compute_shader);
8681             symbolTable.setVariableExtensions("gl_MaxComputeTextureImageUnits",    1, &E_GL_ARB_compute_shader);
8682             symbolTable.setVariableExtensions("gl_MaxComputeImageUniforms",        1, &E_GL_ARB_compute_shader);
8683             symbolTable.setVariableExtensions("gl_MaxComputeAtomicCounters",       1, &E_GL_ARB_compute_shader);
8684             symbolTable.setVariableExtensions("gl_MaxComputeAtomicCounterBuffers", 1, &E_GL_ARB_compute_shader);
8685
8686             symbolTable.setFunctionExtensions("barrier",                    1, &E_GL_ARB_compute_shader);
8687             symbolTable.setFunctionExtensions("memoryBarrierAtomicCounter", 1, &E_GL_ARB_compute_shader);
8688             symbolTable.setFunctionExtensions("memoryBarrierBuffer",        1, &E_GL_ARB_compute_shader);
8689             symbolTable.setFunctionExtensions("memoryBarrierImage",         1, &E_GL_ARB_compute_shader);
8690             symbolTable.setFunctionExtensions("memoryBarrierShared",        1, &E_GL_ARB_compute_shader);
8691             symbolTable.setFunctionExtensions("groupMemoryBarrier",         1, &E_GL_ARB_compute_shader);
8692         }
8693
8694
8695         symbolTable.setFunctionExtensions("controlBarrier",                 1, &E_GL_KHR_memory_scope_semantics);
8696         symbolTable.setFunctionExtensions("debugPrintfEXT",                 1, &E_GL_EXT_debug_printf);
8697
8698         // GL_ARB_shader_ballot
8699         if (profile != EEsProfile) {
8700             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
8701             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
8702             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
8703             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
8704             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
8705             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
8706             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
8707
8708             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
8709             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
8710             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
8711             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
8712             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
8713             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
8714
8715             if (spvVersion.vulkan > 0) {
8716                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
8717                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
8718                 if (language == EShLangFragment)
8719                     ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
8720             }
8721             else
8722                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
8723         }
8724
8725         // GL_KHR_shader_subgroup
8726         if ((profile == EEsProfile && version >= 310) ||
8727             (profile != EEsProfile && version >= 140)) {
8728             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
8729             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
8730             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8731             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8732             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8733             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8734             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8735
8736             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
8737             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
8738             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
8739             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
8740             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
8741             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
8742             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
8743
8744             // GL_NV_shader_sm_builtins
8745             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
8746             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
8747             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
8748             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
8749             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
8750             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
8751             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
8752             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
8753         }
8754
8755         // GL_KHR_shader_subgroup
8756         if ((profile == EEsProfile && version >= 310) ||
8757             (profile != EEsProfile && version >= 140)) {
8758             symbolTable.setVariableExtensions("gl_NumSubgroups", 1, &E_GL_KHR_shader_subgroup_basic);
8759             symbolTable.setVariableExtensions("gl_SubgroupID",   1, &E_GL_KHR_shader_subgroup_basic);
8760
8761             BuiltInVariable("gl_NumSubgroups", EbvNumSubgroups, symbolTable);
8762             BuiltInVariable("gl_SubgroupID",   EbvSubgroupID,   symbolTable);
8763
8764             symbolTable.setFunctionExtensions("subgroupMemoryBarrierShared", 1, &E_GL_KHR_shader_subgroup_basic);
8765         }
8766
8767         {
8768             const char *coopExt[2] = { E_GL_NV_cooperative_matrix, E_GL_NV_integer_cooperative_matrix };
8769             symbolTable.setFunctionExtensions("coopMatLoadNV",   2, coopExt);
8770             symbolTable.setFunctionExtensions("coopMatStoreNV",  2, coopExt);
8771             symbolTable.setFunctionExtensions("coopMatMulAddNV", 2, coopExt);
8772         }
8773
8774         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
8775             symbolTable.setFunctionExtensions("dFdx",                   1, &E_GL_NV_compute_shader_derivatives);
8776             symbolTable.setFunctionExtensions("dFdy",                   1, &E_GL_NV_compute_shader_derivatives);
8777             symbolTable.setFunctionExtensions("fwidth",                 1, &E_GL_NV_compute_shader_derivatives);
8778             symbolTable.setFunctionExtensions("dFdxFine",               1, &E_GL_NV_compute_shader_derivatives);
8779             symbolTable.setFunctionExtensions("dFdyFine",               1, &E_GL_NV_compute_shader_derivatives);
8780             symbolTable.setFunctionExtensions("fwidthFine",             1, &E_GL_NV_compute_shader_derivatives);
8781             symbolTable.setFunctionExtensions("dFdxCoarse",             1, &E_GL_NV_compute_shader_derivatives);
8782             symbolTable.setFunctionExtensions("dFdyCoarse",             1, &E_GL_NV_compute_shader_derivatives);
8783             symbolTable.setFunctionExtensions("fwidthCoarse",           1, &E_GL_NV_compute_shader_derivatives);
8784         }
8785
8786         if ((profile == EEsProfile && version >= 310) ||
8787             (profile != EEsProfile && version >= 450)) {
8788             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8789             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8790             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8791             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8792         }
8793 #endif // !GLSLANG_WEB
8794         break;
8795
8796 #if !defined(GLSLANG_WEB) && !defined(GLSLANG_ANGLE)
8797     case EShLangRayGen:
8798     case EShLangIntersect:
8799     case EShLangAnyHit:
8800     case EShLangClosestHit:
8801     case EShLangMiss:
8802     case EShLangCallable:
8803         if (profile != EEsProfile && version >= 460) {
8804             const char *rtexts[] = { E_GL_NV_ray_tracing, E_GL_EXT_ray_tracing };
8805             symbolTable.setVariableExtensions("gl_LaunchIDNV", 1, &E_GL_NV_ray_tracing);
8806             symbolTable.setVariableExtensions("gl_LaunchIDEXT", 1, &E_GL_EXT_ray_tracing);
8807             symbolTable.setVariableExtensions("gl_LaunchSizeNV", 1, &E_GL_NV_ray_tracing);
8808             symbolTable.setVariableExtensions("gl_LaunchSizeEXT", 1, &E_GL_EXT_ray_tracing);
8809             symbolTable.setVariableExtensions("gl_PrimitiveID", 2, rtexts);
8810             symbolTable.setVariableExtensions("gl_InstanceID", 2, rtexts);
8811             symbolTable.setVariableExtensions("gl_InstanceCustomIndexNV", 1, &E_GL_NV_ray_tracing);
8812             symbolTable.setVariableExtensions("gl_InstanceCustomIndexEXT", 1, &E_GL_EXT_ray_tracing);
8813             symbolTable.setVariableExtensions("gl_GeometryIndexEXT", 1, &E_GL_EXT_ray_tracing);
8814             symbolTable.setVariableExtensions("gl_WorldRayOriginNV", 1, &E_GL_NV_ray_tracing);
8815             symbolTable.setVariableExtensions("gl_WorldRayOriginEXT", 1, &E_GL_EXT_ray_tracing);
8816             symbolTable.setVariableExtensions("gl_WorldRayDirectionNV", 1, &E_GL_NV_ray_tracing);
8817             symbolTable.setVariableExtensions("gl_WorldRayDirectionEXT", 1, &E_GL_EXT_ray_tracing);
8818             symbolTable.setVariableExtensions("gl_ObjectRayOriginNV", 1, &E_GL_NV_ray_tracing);
8819             symbolTable.setVariableExtensions("gl_ObjectRayOriginEXT", 1, &E_GL_EXT_ray_tracing);
8820             symbolTable.setVariableExtensions("gl_ObjectRayDirectionNV", 1, &E_GL_NV_ray_tracing);
8821             symbolTable.setVariableExtensions("gl_ObjectRayDirectionEXT", 1, &E_GL_EXT_ray_tracing);
8822             symbolTable.setVariableExtensions("gl_RayTminNV", 1, &E_GL_NV_ray_tracing);
8823             symbolTable.setVariableExtensions("gl_RayTminEXT", 1, &E_GL_EXT_ray_tracing);
8824             symbolTable.setVariableExtensions("gl_RayTmaxNV", 1, &E_GL_NV_ray_tracing);
8825             symbolTable.setVariableExtensions("gl_RayTmaxEXT", 1, &E_GL_EXT_ray_tracing);
8826             symbolTable.setVariableExtensions("gl_CullMaskEXT", 1, &E_GL_EXT_ray_cull_mask);
8827             symbolTable.setVariableExtensions("gl_HitTNV", 1, &E_GL_NV_ray_tracing);
8828             symbolTable.setVariableExtensions("gl_HitTEXT", 1, &E_GL_EXT_ray_tracing);
8829             symbolTable.setVariableExtensions("gl_HitKindNV", 1, &E_GL_NV_ray_tracing);
8830             symbolTable.setVariableExtensions("gl_HitKindEXT", 1, &E_GL_EXT_ray_tracing);
8831             symbolTable.setVariableExtensions("gl_ObjectToWorldNV", 1, &E_GL_NV_ray_tracing);
8832             symbolTable.setVariableExtensions("gl_ObjectToWorldEXT", 1, &E_GL_EXT_ray_tracing);
8833             symbolTable.setVariableExtensions("gl_ObjectToWorld3x4EXT", 1, &E_GL_EXT_ray_tracing);
8834             symbolTable.setVariableExtensions("gl_WorldToObjectNV", 1, &E_GL_NV_ray_tracing);
8835             symbolTable.setVariableExtensions("gl_WorldToObjectEXT", 1, &E_GL_EXT_ray_tracing);
8836             symbolTable.setVariableExtensions("gl_WorldToObject3x4EXT", 1, &E_GL_EXT_ray_tracing);
8837             symbolTable.setVariableExtensions("gl_IncomingRayFlagsNV", 1, &E_GL_NV_ray_tracing);
8838             symbolTable.setVariableExtensions("gl_IncomingRayFlagsEXT", 1, &E_GL_EXT_ray_tracing);
8839             symbolTable.setVariableExtensions("gl_CurrentRayTimeNV", 1, &E_GL_NV_ray_tracing_motion_blur);
8840
8841             symbolTable.setVariableExtensions("gl_DeviceIndex", 1, &E_GL_EXT_device_group);
8842
8843
8844             symbolTable.setFunctionExtensions("traceNV", 1, &E_GL_NV_ray_tracing);
8845             symbolTable.setFunctionExtensions("traceRayMotionNV", 1, &E_GL_NV_ray_tracing_motion_blur);
8846             symbolTable.setFunctionExtensions("traceRayEXT", 1, &E_GL_EXT_ray_tracing);
8847             symbolTable.setFunctionExtensions("reportIntersectionNV", 1, &E_GL_NV_ray_tracing);
8848             symbolTable.setFunctionExtensions("reportIntersectionEXT", 1, &E_GL_EXT_ray_tracing);
8849             symbolTable.setFunctionExtensions("ignoreIntersectionNV", 1, &E_GL_NV_ray_tracing);
8850             symbolTable.setFunctionExtensions("terminateRayNV", 1, &E_GL_NV_ray_tracing);
8851             symbolTable.setFunctionExtensions("executeCallableNV", 1, &E_GL_NV_ray_tracing);
8852             symbolTable.setFunctionExtensions("executeCallableEXT", 1, &E_GL_EXT_ray_tracing);
8853
8854
8855             BuiltInVariable("gl_LaunchIDNV",             EbvLaunchId,           symbolTable);
8856             BuiltInVariable("gl_LaunchIDEXT",            EbvLaunchId,           symbolTable);
8857             BuiltInVariable("gl_LaunchSizeNV",           EbvLaunchSize,         symbolTable);
8858             BuiltInVariable("gl_LaunchSizeEXT",          EbvLaunchSize,         symbolTable);
8859             BuiltInVariable("gl_PrimitiveID",            EbvPrimitiveId,        symbolTable);
8860             BuiltInVariable("gl_InstanceID",             EbvInstanceId,         symbolTable);
8861             BuiltInVariable("gl_InstanceCustomIndexNV",  EbvInstanceCustomIndex,symbolTable);
8862             BuiltInVariable("gl_InstanceCustomIndexEXT", EbvInstanceCustomIndex,symbolTable);
8863             BuiltInVariable("gl_GeometryIndexEXT",       EbvGeometryIndex,      symbolTable);
8864             BuiltInVariable("gl_WorldRayOriginNV",       EbvWorldRayOrigin,     symbolTable);
8865             BuiltInVariable("gl_WorldRayOriginEXT",      EbvWorldRayOrigin,     symbolTable);
8866             BuiltInVariable("gl_WorldRayDirectionNV",    EbvWorldRayDirection,  symbolTable);
8867             BuiltInVariable("gl_WorldRayDirectionEXT",   EbvWorldRayDirection,  symbolTable);
8868             BuiltInVariable("gl_ObjectRayOriginNV",      EbvObjectRayOrigin,    symbolTable);
8869             BuiltInVariable("gl_ObjectRayOriginEXT",     EbvObjectRayOrigin,    symbolTable);
8870             BuiltInVariable("gl_ObjectRayDirectionNV",   EbvObjectRayDirection, symbolTable);
8871             BuiltInVariable("gl_ObjectRayDirectionEXT",  EbvObjectRayDirection, symbolTable);
8872             BuiltInVariable("gl_RayTminNV",              EbvRayTmin,            symbolTable);
8873             BuiltInVariable("gl_RayTminEXT",             EbvRayTmin,            symbolTable);
8874             BuiltInVariable("gl_RayTmaxNV",              EbvRayTmax,            symbolTable);
8875             BuiltInVariable("gl_RayTmaxEXT",             EbvRayTmax,            symbolTable);
8876             BuiltInVariable("gl_CullMaskEXT",            EbvCullMask,           symbolTable);
8877             BuiltInVariable("gl_HitTNV",                 EbvHitT,               symbolTable);
8878             BuiltInVariable("gl_HitTEXT",                EbvHitT,               symbolTable);
8879             BuiltInVariable("gl_HitKindNV",              EbvHitKind,            symbolTable);
8880             BuiltInVariable("gl_HitKindEXT",             EbvHitKind,            symbolTable);
8881             BuiltInVariable("gl_ObjectToWorldNV",        EbvObjectToWorld,      symbolTable);
8882             BuiltInVariable("gl_ObjectToWorldEXT",       EbvObjectToWorld,      symbolTable);
8883             BuiltInVariable("gl_ObjectToWorld3x4EXT",    EbvObjectToWorld3x4,   symbolTable);
8884             BuiltInVariable("gl_WorldToObjectNV",        EbvWorldToObject,      symbolTable);
8885             BuiltInVariable("gl_WorldToObjectEXT",       EbvWorldToObject,      symbolTable);
8886             BuiltInVariable("gl_WorldToObject3x4EXT",    EbvWorldToObject3x4,   symbolTable);
8887             BuiltInVariable("gl_IncomingRayFlagsNV",     EbvIncomingRayFlags,   symbolTable);
8888             BuiltInVariable("gl_IncomingRayFlagsEXT",    EbvIncomingRayFlags,   symbolTable);
8889             BuiltInVariable("gl_DeviceIndex",            EbvDeviceIndex,        symbolTable);
8890             BuiltInVariable("gl_CurrentRayTimeNV",       EbvCurrentRayTimeNV,   symbolTable);
8891
8892             // GL_ARB_shader_ballot
8893             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
8894             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
8895             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
8896             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
8897             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
8898             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
8899             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
8900
8901             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
8902             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
8903             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
8904             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
8905             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
8906             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
8907
8908             if (spvVersion.vulkan > 0) {
8909                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
8910                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
8911                 if (language == EShLangFragment)
8912                     ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
8913             }
8914             else
8915                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
8916
8917             // GL_KHR_shader_subgroup
8918             symbolTable.setVariableExtensions("gl_NumSubgroups",         1, &E_GL_KHR_shader_subgroup_basic);
8919             symbolTable.setVariableExtensions("gl_SubgroupID",           1, &E_GL_KHR_shader_subgroup_basic);
8920             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
8921             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
8922             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8923             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8924             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8925             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8926             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8927
8928             BuiltInVariable("gl_NumSubgroups",         EbvNumSubgroups,        symbolTable);
8929             BuiltInVariable("gl_SubgroupID",           EbvSubgroupID,          symbolTable);
8930             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
8931             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
8932             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
8933             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
8934             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
8935             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
8936             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
8937
8938             // GL_NV_shader_sm_builtins
8939             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
8940             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
8941             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
8942             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
8943             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
8944             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
8945             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
8946             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
8947         }
8948         if ((profile == EEsProfile && version >= 310) ||
8949             (profile != EEsProfile && version >= 450)) {
8950             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8951             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8952             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8953             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8954         }
8955         break;
8956
8957     case EShLangMesh:
8958         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
8959             // per-vertex builtins
8960             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_Position",     1, &E_GL_NV_mesh_shader);
8961             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_PointSize",    1, &E_GL_NV_mesh_shader);
8962             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_ClipDistance", 1, &E_GL_NV_mesh_shader);
8963             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_CullDistance", 1, &E_GL_NV_mesh_shader);
8964
8965             BuiltInVariable("gl_MeshVerticesNV", "gl_Position",     EbvPosition,     symbolTable);
8966             BuiltInVariable("gl_MeshVerticesNV", "gl_PointSize",    EbvPointSize,    symbolTable);
8967             BuiltInVariable("gl_MeshVerticesNV", "gl_ClipDistance", EbvClipDistance, symbolTable);
8968             BuiltInVariable("gl_MeshVerticesNV", "gl_CullDistance", EbvCullDistance, symbolTable);
8969
8970             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_PositionPerViewNV",     1, &E_GL_NV_mesh_shader);
8971             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_ClipDistancePerViewNV", 1, &E_GL_NV_mesh_shader);
8972             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_CullDistancePerViewNV", 1, &E_GL_NV_mesh_shader);
8973
8974             BuiltInVariable("gl_MeshVerticesNV", "gl_PositionPerViewNV",     EbvPositionPerViewNV,     symbolTable);
8975             BuiltInVariable("gl_MeshVerticesNV", "gl_ClipDistancePerViewNV", EbvClipDistancePerViewNV, symbolTable);
8976             BuiltInVariable("gl_MeshVerticesNV", "gl_CullDistancePerViewNV", EbvCullDistancePerViewNV, symbolTable);
8977
8978             // per-primitive builtins
8979             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_PrimitiveID",   1, &E_GL_NV_mesh_shader);
8980             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_Layer",         1, &E_GL_NV_mesh_shader);
8981             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_ViewportIndex", 1, &E_GL_NV_mesh_shader);
8982             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_ViewportMask",  1, &E_GL_NV_mesh_shader);
8983
8984             BuiltInVariable("gl_MeshPrimitivesNV", "gl_PrimitiveID",   EbvPrimitiveId,    symbolTable);
8985             BuiltInVariable("gl_MeshPrimitivesNV", "gl_Layer",         EbvLayer,          symbolTable);
8986             BuiltInVariable("gl_MeshPrimitivesNV", "gl_ViewportIndex", EbvViewportIndex,  symbolTable);
8987             BuiltInVariable("gl_MeshPrimitivesNV", "gl_ViewportMask",  EbvViewportMaskNV, symbolTable);
8988
8989             // per-view per-primitive builtins
8990             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_LayerPerViewNV",        1, &E_GL_NV_mesh_shader);
8991             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_ViewportMaskPerViewNV", 1, &E_GL_NV_mesh_shader);
8992
8993             BuiltInVariable("gl_MeshPrimitivesNV", "gl_LayerPerViewNV",        EbvLayerPerViewNV,        symbolTable);
8994             BuiltInVariable("gl_MeshPrimitivesNV", "gl_ViewportMaskPerViewNV", EbvViewportMaskPerViewNV, symbolTable);
8995
8996             // other builtins
8997             symbolTable.setVariableExtensions("gl_PrimitiveCountNV",     1, &E_GL_NV_mesh_shader);
8998             symbolTable.setVariableExtensions("gl_PrimitiveIndicesNV",   1, &E_GL_NV_mesh_shader);
8999             symbolTable.setVariableExtensions("gl_MeshViewCountNV",      1, &E_GL_NV_mesh_shader);
9000             symbolTable.setVariableExtensions("gl_MeshViewIndicesNV",    1, &E_GL_NV_mesh_shader);
9001             if (profile != EEsProfile) {
9002                 symbolTable.setVariableExtensions("gl_WorkGroupSize",        Num_AEP_mesh_shader, AEP_mesh_shader);
9003                 symbolTable.setVariableExtensions("gl_WorkGroupID",          Num_AEP_mesh_shader, AEP_mesh_shader);
9004                 symbolTable.setVariableExtensions("gl_LocalInvocationID",    Num_AEP_mesh_shader, AEP_mesh_shader);
9005                 symbolTable.setVariableExtensions("gl_GlobalInvocationID",   Num_AEP_mesh_shader, AEP_mesh_shader);
9006                 symbolTable.setVariableExtensions("gl_LocalInvocationIndex", Num_AEP_mesh_shader, AEP_mesh_shader);
9007             } else {
9008                 symbolTable.setVariableExtensions("gl_WorkGroupSize",        1, &E_GL_NV_mesh_shader);
9009                 symbolTable.setVariableExtensions("gl_WorkGroupID",          1, &E_GL_NV_mesh_shader);
9010                 symbolTable.setVariableExtensions("gl_LocalInvocationID",    1, &E_GL_NV_mesh_shader);
9011                 symbolTable.setVariableExtensions("gl_GlobalInvocationID",   1, &E_GL_NV_mesh_shader);
9012                 symbolTable.setVariableExtensions("gl_LocalInvocationIndex", 1, &E_GL_NV_mesh_shader);
9013             }
9014             BuiltInVariable("gl_PrimitiveCountNV",     EbvPrimitiveCountNV,     symbolTable);
9015             BuiltInVariable("gl_PrimitiveIndicesNV",   EbvPrimitiveIndicesNV,   symbolTable);
9016             BuiltInVariable("gl_MeshViewCountNV",      EbvMeshViewCountNV,      symbolTable);
9017             BuiltInVariable("gl_MeshViewIndicesNV",    EbvMeshViewIndicesNV,    symbolTable);
9018             BuiltInVariable("gl_WorkGroupSize",        EbvWorkGroupSize,        symbolTable);
9019             BuiltInVariable("gl_WorkGroupID",          EbvWorkGroupId,          symbolTable);
9020             BuiltInVariable("gl_LocalInvocationID",    EbvLocalInvocationId,    symbolTable);
9021             BuiltInVariable("gl_GlobalInvocationID",   EbvGlobalInvocationId,   symbolTable);
9022             BuiltInVariable("gl_LocalInvocationIndex", EbvLocalInvocationIndex, symbolTable);
9023
9024             // builtin constants
9025             symbolTable.setVariableExtensions("gl_MaxMeshOutputVerticesNV",   1, &E_GL_NV_mesh_shader);
9026             symbolTable.setVariableExtensions("gl_MaxMeshOutputPrimitivesNV", 1, &E_GL_NV_mesh_shader);
9027             symbolTable.setVariableExtensions("gl_MaxMeshWorkGroupSizeNV",    1, &E_GL_NV_mesh_shader);
9028             symbolTable.setVariableExtensions("gl_MaxMeshViewCountNV",        1, &E_GL_NV_mesh_shader);
9029
9030             // builtin functions
9031             if (profile != EEsProfile) {
9032                 symbolTable.setFunctionExtensions("barrier",                      Num_AEP_mesh_shader, AEP_mesh_shader);
9033                 symbolTable.setFunctionExtensions("memoryBarrierShared",          Num_AEP_mesh_shader, AEP_mesh_shader);
9034                 symbolTable.setFunctionExtensions("groupMemoryBarrier",           Num_AEP_mesh_shader, AEP_mesh_shader);
9035             } else {
9036                 symbolTable.setFunctionExtensions("barrier",                      1, &E_GL_NV_mesh_shader);
9037                 symbolTable.setFunctionExtensions("memoryBarrierShared",          1, &E_GL_NV_mesh_shader);
9038                 symbolTable.setFunctionExtensions("groupMemoryBarrier",           1, &E_GL_NV_mesh_shader);
9039             }
9040             symbolTable.setFunctionExtensions("writePackedPrimitiveIndices4x8NV",  1, &E_GL_NV_mesh_shader);
9041         }
9042
9043         if (profile != EEsProfile && version >= 450) {
9044             // GL_EXT_Mesh_shader
9045             symbolTable.setVariableExtensions("gl_PrimitivePointIndicesEXT",    1, &E_GL_EXT_mesh_shader);
9046             symbolTable.setVariableExtensions("gl_PrimitiveLineIndicesEXT",     1, &E_GL_EXT_mesh_shader);
9047             symbolTable.setVariableExtensions("gl_PrimitiveTriangleIndicesEXT", 1, &E_GL_EXT_mesh_shader);
9048             symbolTable.setVariableExtensions("gl_NumWorkGroups",               1, &E_GL_EXT_mesh_shader);
9049
9050             BuiltInVariable("gl_PrimitivePointIndicesEXT",    EbvPrimitivePointIndicesEXT,    symbolTable);
9051             BuiltInVariable("gl_PrimitiveLineIndicesEXT",     EbvPrimitiveLineIndicesEXT,     symbolTable);
9052             BuiltInVariable("gl_PrimitiveTriangleIndicesEXT", EbvPrimitiveTriangleIndicesEXT, symbolTable);
9053             BuiltInVariable("gl_NumWorkGroups",        EbvNumWorkGroups,        symbolTable);
9054
9055             symbolTable.setVariableExtensions("gl_MeshVerticesEXT", "gl_Position",     1, &E_GL_EXT_mesh_shader);
9056             symbolTable.setVariableExtensions("gl_MeshVerticesEXT", "gl_PointSize",    1, &E_GL_EXT_mesh_shader);
9057             symbolTable.setVariableExtensions("gl_MeshVerticesEXT", "gl_ClipDistance", 1, &E_GL_EXT_mesh_shader);
9058             symbolTable.setVariableExtensions("gl_MeshVerticesEXT", "gl_CullDistance", 1, &E_GL_EXT_mesh_shader);
9059             
9060             BuiltInVariable("gl_MeshVerticesEXT", "gl_Position",     EbvPosition,     symbolTable);
9061             BuiltInVariable("gl_MeshVerticesEXT", "gl_PointSize",    EbvPointSize,    symbolTable);
9062             BuiltInVariable("gl_MeshVerticesEXT", "gl_ClipDistance", EbvClipDistance, symbolTable);
9063             BuiltInVariable("gl_MeshVerticesEXT", "gl_CullDistance", EbvCullDistance, symbolTable);
9064             
9065             symbolTable.setVariableExtensions("gl_MeshPrimitivesEXT", "gl_PrimitiveID",             1, &E_GL_EXT_mesh_shader);
9066             symbolTable.setVariableExtensions("gl_MeshPrimitivesEXT", "gl_Layer",                   1, &E_GL_EXT_mesh_shader);
9067             symbolTable.setVariableExtensions("gl_MeshPrimitivesEXT", "gl_ViewportIndex",           1, &E_GL_EXT_mesh_shader);
9068             symbolTable.setVariableExtensions("gl_MeshPrimitivesEXT", "gl_CullPrimitiveEXT",        1, &E_GL_EXT_mesh_shader);
9069             symbolTable.setVariableExtensions("gl_MeshPrimitivesEXT", "gl_PrimitiveShadingRateEXT", 1, &E_GL_EXT_mesh_shader);
9070
9071             BuiltInVariable("gl_MeshPrimitivesEXT", "gl_PrimitiveID",              EbvPrimitiveId,    symbolTable);
9072             BuiltInVariable("gl_MeshPrimitivesEXT", "gl_Layer",                    EbvLayer,          symbolTable);
9073             BuiltInVariable("gl_MeshPrimitivesEXT", "gl_ViewportIndex",            EbvViewportIndex,  symbolTable);
9074             BuiltInVariable("gl_MeshPrimitivesEXT", "gl_CullPrimitiveEXT",         EbvCullPrimitiveEXT, symbolTable);
9075             BuiltInVariable("gl_MeshPrimitivesEXT", "gl_PrimitiveShadingRateEXT",  EbvPrimitiveShadingRateKHR, symbolTable);
9076
9077             symbolTable.setFunctionExtensions("SetMeshOutputsEXT",  1, &E_GL_EXT_mesh_shader);
9078
9079             // GL_EXT_device_group
9080             symbolTable.setVariableExtensions("gl_DeviceIndex", 1, &E_GL_EXT_device_group);
9081             BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
9082
9083             // GL_ARB_shader_draw_parameters
9084             symbolTable.setVariableExtensions("gl_DrawIDARB", 1, &E_GL_ARB_shader_draw_parameters);
9085             BuiltInVariable("gl_DrawIDARB", EbvDrawId, symbolTable);
9086             if (version >= 460) {
9087                 BuiltInVariable("gl_DrawID", EbvDrawId, symbolTable);
9088             }
9089             // GL_EXT_multiview
9090             BuiltInVariable("gl_ViewIndex", EbvViewIndex, symbolTable);
9091             symbolTable.setVariableExtensions("gl_ViewIndex", 1, &E_GL_EXT_multiview);
9092
9093             // GL_ARB_shader_ballot
9094             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
9095             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
9096             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
9097             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
9098             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
9099             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
9100             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
9101
9102             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
9103             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
9104             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
9105             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
9106             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
9107             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
9108
9109             if (spvVersion.vulkan > 0) {
9110                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
9111                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
9112                 if (language == EShLangFragment)
9113                     ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
9114             }
9115             else
9116                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
9117         }
9118
9119         // GL_KHR_shader_subgroup
9120         if ((profile == EEsProfile && version >= 310) ||
9121             (profile != EEsProfile && version >= 140)) {
9122             symbolTable.setVariableExtensions("gl_NumSubgroups",         1, &E_GL_KHR_shader_subgroup_basic);
9123             symbolTable.setVariableExtensions("gl_SubgroupID",           1, &E_GL_KHR_shader_subgroup_basic);
9124             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
9125             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
9126             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9127             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9128             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9129             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9130             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9131
9132             BuiltInVariable("gl_NumSubgroups",         EbvNumSubgroups,        symbolTable);
9133             BuiltInVariable("gl_SubgroupID",           EbvSubgroupID,          symbolTable);
9134             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
9135             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
9136             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
9137             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
9138             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
9139             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
9140             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
9141
9142             symbolTable.setFunctionExtensions("subgroupMemoryBarrierShared", 1, &E_GL_KHR_shader_subgroup_basic);
9143
9144             // GL_NV_shader_sm_builtins
9145             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
9146             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
9147             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
9148             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
9149             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
9150             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
9151             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
9152             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
9153         }
9154
9155         if ((profile == EEsProfile && version >= 310) ||
9156             (profile != EEsProfile && version >= 450)) {
9157             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9158             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9159             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9160             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9161         }
9162         break;
9163
9164     case EShLangTask:
9165         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
9166             symbolTable.setVariableExtensions("gl_TaskCountNV",          1, &E_GL_NV_mesh_shader);
9167             symbolTable.setVariableExtensions("gl_MeshViewCountNV",      1, &E_GL_NV_mesh_shader);
9168             symbolTable.setVariableExtensions("gl_MeshViewIndicesNV",    1, &E_GL_NV_mesh_shader);
9169             if (profile != EEsProfile) {
9170                 symbolTable.setVariableExtensions("gl_WorkGroupSize",        Num_AEP_mesh_shader, AEP_mesh_shader);
9171                 symbolTable.setVariableExtensions("gl_WorkGroupID",          Num_AEP_mesh_shader, AEP_mesh_shader);
9172                 symbolTable.setVariableExtensions("gl_LocalInvocationID",    Num_AEP_mesh_shader, AEP_mesh_shader);
9173                 symbolTable.setVariableExtensions("gl_GlobalInvocationID",   Num_AEP_mesh_shader, AEP_mesh_shader);
9174                 symbolTable.setVariableExtensions("gl_LocalInvocationIndex", Num_AEP_mesh_shader, AEP_mesh_shader);
9175             } else {
9176                 symbolTable.setVariableExtensions("gl_WorkGroupSize",        1, &E_GL_NV_mesh_shader);
9177                 symbolTable.setVariableExtensions("gl_WorkGroupID",          1, &E_GL_NV_mesh_shader);
9178                 symbolTable.setVariableExtensions("gl_LocalInvocationID",    1, &E_GL_NV_mesh_shader);
9179                 symbolTable.setVariableExtensions("gl_GlobalInvocationID",   1, &E_GL_NV_mesh_shader);
9180                 symbolTable.setVariableExtensions("gl_LocalInvocationIndex", 1, &E_GL_NV_mesh_shader);
9181             }
9182
9183             BuiltInVariable("gl_TaskCountNV",          EbvTaskCountNV,          symbolTable);
9184             BuiltInVariable("gl_WorkGroupSize",        EbvWorkGroupSize,        symbolTable);
9185             BuiltInVariable("gl_WorkGroupID",          EbvWorkGroupId,          symbolTable);
9186             BuiltInVariable("gl_LocalInvocationID",    EbvLocalInvocationId,    symbolTable);
9187             BuiltInVariable("gl_GlobalInvocationID",   EbvGlobalInvocationId,   symbolTable);
9188             BuiltInVariable("gl_LocalInvocationIndex", EbvLocalInvocationIndex, symbolTable);
9189             BuiltInVariable("gl_MeshViewCountNV",      EbvMeshViewCountNV,      symbolTable);
9190             BuiltInVariable("gl_MeshViewIndicesNV",    EbvMeshViewIndicesNV,    symbolTable);
9191
9192             symbolTable.setVariableExtensions("gl_MaxTaskWorkGroupSizeNV", 1, &E_GL_NV_mesh_shader);
9193             symbolTable.setVariableExtensions("gl_MaxMeshViewCountNV",     1, &E_GL_NV_mesh_shader);
9194
9195             if (profile != EEsProfile) {
9196                 symbolTable.setFunctionExtensions("barrier",                   Num_AEP_mesh_shader, AEP_mesh_shader);
9197                 symbolTable.setFunctionExtensions("memoryBarrierShared",       Num_AEP_mesh_shader, AEP_mesh_shader);
9198                 symbolTable.setFunctionExtensions("groupMemoryBarrier",        Num_AEP_mesh_shader, AEP_mesh_shader);
9199             } else {
9200                 symbolTable.setFunctionExtensions("barrier",                   1, &E_GL_NV_mesh_shader);
9201                 symbolTable.setFunctionExtensions("memoryBarrierShared",       1, &E_GL_NV_mesh_shader);
9202                 symbolTable.setFunctionExtensions("groupMemoryBarrier",        1, &E_GL_NV_mesh_shader);
9203             }
9204         }
9205
9206         if (profile != EEsProfile && version >= 450) {
9207             // GL_EXT_mesh_shader
9208             symbolTable.setFunctionExtensions("EmitMeshTasksEXT",          1, &E_GL_EXT_mesh_shader);
9209             symbolTable.setVariableExtensions("gl_NumWorkGroups",        1, &E_GL_EXT_mesh_shader);
9210             BuiltInVariable("gl_NumWorkGroups",        EbvNumWorkGroups,        symbolTable);
9211
9212             // GL_EXT_device_group
9213             symbolTable.setVariableExtensions("gl_DeviceIndex", 1, &E_GL_EXT_device_group);
9214             BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
9215
9216             // GL_ARB_shader_draw_parameters
9217             symbolTable.setVariableExtensions("gl_DrawIDARB", 1, &E_GL_ARB_shader_draw_parameters);
9218             BuiltInVariable("gl_DrawIDARB", EbvDrawId, symbolTable);
9219             if (version >= 460) {
9220                 BuiltInVariable("gl_DrawID", EbvDrawId, symbolTable);
9221             }
9222
9223             // GL_ARB_shader_ballot
9224             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
9225             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
9226             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
9227             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
9228             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
9229             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
9230             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
9231
9232             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
9233             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
9234             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
9235             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
9236             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
9237             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
9238
9239             if (spvVersion.vulkan > 0) {
9240                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
9241                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
9242                 if (language == EShLangFragment)
9243                     ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
9244             }
9245             else
9246                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
9247         }
9248
9249         // GL_KHR_shader_subgroup
9250         if ((profile == EEsProfile && version >= 310) ||
9251             (profile != EEsProfile && version >= 140)) {
9252             symbolTable.setVariableExtensions("gl_NumSubgroups",         1, &E_GL_KHR_shader_subgroup_basic);
9253             symbolTable.setVariableExtensions("gl_SubgroupID",           1, &E_GL_KHR_shader_subgroup_basic);
9254             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
9255             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
9256             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9257             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9258             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9259             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9260             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9261
9262             BuiltInVariable("gl_NumSubgroups",         EbvNumSubgroups,        symbolTable);
9263             BuiltInVariable("gl_SubgroupID",           EbvSubgroupID,          symbolTable);
9264             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
9265             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
9266             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
9267             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
9268             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
9269             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
9270             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
9271
9272             symbolTable.setFunctionExtensions("subgroupMemoryBarrierShared", 1, &E_GL_KHR_shader_subgroup_basic);
9273
9274             // GL_NV_shader_sm_builtins
9275             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
9276             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
9277             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
9278             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
9279             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
9280             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
9281             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
9282             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
9283         }
9284         if ((profile == EEsProfile && version >= 310) ||
9285             (profile != EEsProfile && version >= 450)) {
9286             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9287             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9288             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9289             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9290         }
9291         break;
9292 #endif
9293
9294     default:
9295         assert(false && "Language not supported");
9296         break;
9297     }
9298
9299     //
9300     // Next, identify which built-ins have a mapping to an operator.
9301     // If PureOperatorBuiltins is false, those that are not identified as such are
9302     // expected to be resolved through a library of functions, versus as
9303     // operations.
9304     //
9305
9306     relateTabledBuiltins(version, profile, spvVersion, language, symbolTable);
9307
9308 #ifndef GLSLANG_WEB
9309     symbolTable.relateToOperator("doubleBitsToInt64",  EOpDoubleBitsToInt64);
9310     symbolTable.relateToOperator("doubleBitsToUint64", EOpDoubleBitsToUint64);
9311     symbolTable.relateToOperator("int64BitsToDouble",  EOpInt64BitsToDouble);
9312     symbolTable.relateToOperator("uint64BitsToDouble", EOpUint64BitsToDouble);
9313     symbolTable.relateToOperator("halfBitsToInt16",  EOpFloat16BitsToInt16);
9314     symbolTable.relateToOperator("halfBitsToUint16", EOpFloat16BitsToUint16);
9315     symbolTable.relateToOperator("float16BitsToInt16",  EOpFloat16BitsToInt16);
9316     symbolTable.relateToOperator("float16BitsToUint16", EOpFloat16BitsToUint16);
9317     symbolTable.relateToOperator("int16BitsToFloat16",  EOpInt16BitsToFloat16);
9318     symbolTable.relateToOperator("uint16BitsToFloat16", EOpUint16BitsToFloat16);
9319
9320     symbolTable.relateToOperator("int16BitsToHalf",  EOpInt16BitsToFloat16);
9321     symbolTable.relateToOperator("uint16BitsToHalf", EOpUint16BitsToFloat16);
9322
9323     symbolTable.relateToOperator("packSnorm4x8",    EOpPackSnorm4x8);
9324     symbolTable.relateToOperator("unpackSnorm4x8",  EOpUnpackSnorm4x8);
9325     symbolTable.relateToOperator("packUnorm4x8",    EOpPackUnorm4x8);
9326     symbolTable.relateToOperator("unpackUnorm4x8",  EOpUnpackUnorm4x8);
9327
9328     symbolTable.relateToOperator("packDouble2x32",    EOpPackDouble2x32);
9329     symbolTable.relateToOperator("unpackDouble2x32",  EOpUnpackDouble2x32);
9330
9331     symbolTable.relateToOperator("packInt2x32",     EOpPackInt2x32);
9332     symbolTable.relateToOperator("unpackInt2x32",   EOpUnpackInt2x32);
9333     symbolTable.relateToOperator("packUint2x32",    EOpPackUint2x32);
9334     symbolTable.relateToOperator("unpackUint2x32",  EOpUnpackUint2x32);
9335
9336     symbolTable.relateToOperator("packInt2x16",     EOpPackInt2x16);
9337     symbolTable.relateToOperator("unpackInt2x16",   EOpUnpackInt2x16);
9338     symbolTable.relateToOperator("packUint2x16",    EOpPackUint2x16);
9339     symbolTable.relateToOperator("unpackUint2x16",  EOpUnpackUint2x16);
9340
9341     symbolTable.relateToOperator("packInt4x16",     EOpPackInt4x16);
9342     symbolTable.relateToOperator("unpackInt4x16",   EOpUnpackInt4x16);
9343     symbolTable.relateToOperator("packUint4x16",    EOpPackUint4x16);
9344     symbolTable.relateToOperator("unpackUint4x16",  EOpUnpackUint4x16);
9345     symbolTable.relateToOperator("packFloat2x16",   EOpPackFloat2x16);
9346     symbolTable.relateToOperator("unpackFloat2x16", EOpUnpackFloat2x16);
9347
9348     symbolTable.relateToOperator("pack16",          EOpPack16);
9349     symbolTable.relateToOperator("pack32",          EOpPack32);
9350     symbolTable.relateToOperator("pack64",          EOpPack64);
9351
9352     symbolTable.relateToOperator("unpack32",        EOpUnpack32);
9353     symbolTable.relateToOperator("unpack16",        EOpUnpack16);
9354     symbolTable.relateToOperator("unpack8",         EOpUnpack8);
9355
9356     symbolTable.relateToOperator("controlBarrier",             EOpBarrier);
9357     symbolTable.relateToOperator("memoryBarrierAtomicCounter", EOpMemoryBarrierAtomicCounter);
9358     symbolTable.relateToOperator("memoryBarrierImage",         EOpMemoryBarrierImage);
9359
9360     if (spvVersion.vulkanRelaxed) {
9361         //
9362         // functions signature have been replaced to take uint operations on buffer variables
9363         // remap atomic counter functions to atomic operations
9364         //
9365         symbolTable.relateToOperator("memoryBarrierAtomicCounter", EOpMemoryBarrierBuffer);
9366     }
9367
9368     symbolTable.relateToOperator("atomicLoad",     EOpAtomicLoad);
9369     symbolTable.relateToOperator("atomicStore",    EOpAtomicStore);
9370
9371     symbolTable.relateToOperator("atomicCounterIncrement", EOpAtomicCounterIncrement);
9372     symbolTable.relateToOperator("atomicCounterDecrement", EOpAtomicCounterDecrement);
9373     symbolTable.relateToOperator("atomicCounter",          EOpAtomicCounter);
9374
9375     if (spvVersion.vulkanRelaxed) {
9376         //
9377         // functions signature have been replaced to take uint operations
9378         // remap atomic counter functions to atomic operations
9379         //
9380         // these atomic counter functions do not match signatures of glsl
9381         // atomic functions, so they will be remapped to semantically
9382         // equivalent functions in the parser
9383         //
9384         symbolTable.relateToOperator("atomicCounterIncrement", EOpNull);
9385         symbolTable.relateToOperator("atomicCounterDecrement", EOpNull);
9386         symbolTable.relateToOperator("atomicCounter", EOpNull);
9387     }
9388
9389     symbolTable.relateToOperator("clockARB",     EOpReadClockSubgroupKHR);
9390     symbolTable.relateToOperator("clock2x32ARB", EOpReadClockSubgroupKHR);
9391
9392     symbolTable.relateToOperator("clockRealtimeEXT",     EOpReadClockDeviceKHR);
9393     symbolTable.relateToOperator("clockRealtime2x32EXT", EOpReadClockDeviceKHR);
9394
9395     if (profile != EEsProfile && version == 450) {
9396         symbolTable.relateToOperator("atomicCounterAddARB",      EOpAtomicCounterAdd);
9397         symbolTable.relateToOperator("atomicCounterSubtractARB", EOpAtomicCounterSubtract);
9398         symbolTable.relateToOperator("atomicCounterMinARB",      EOpAtomicCounterMin);
9399         symbolTable.relateToOperator("atomicCounterMaxARB",      EOpAtomicCounterMax);
9400         symbolTable.relateToOperator("atomicCounterAndARB",      EOpAtomicCounterAnd);
9401         symbolTable.relateToOperator("atomicCounterOrARB",       EOpAtomicCounterOr);
9402         symbolTable.relateToOperator("atomicCounterXorARB",      EOpAtomicCounterXor);
9403         symbolTable.relateToOperator("atomicCounterExchangeARB", EOpAtomicCounterExchange);
9404         symbolTable.relateToOperator("atomicCounterCompSwapARB", EOpAtomicCounterCompSwap);
9405     }
9406
9407     if (profile != EEsProfile && version >= 460) {
9408         symbolTable.relateToOperator("atomicCounterAdd",      EOpAtomicCounterAdd);
9409         symbolTable.relateToOperator("atomicCounterSubtract", EOpAtomicCounterSubtract);
9410         symbolTable.relateToOperator("atomicCounterMin",      EOpAtomicCounterMin);
9411         symbolTable.relateToOperator("atomicCounterMax",      EOpAtomicCounterMax);
9412         symbolTable.relateToOperator("atomicCounterAnd",      EOpAtomicCounterAnd);
9413         symbolTable.relateToOperator("atomicCounterOr",       EOpAtomicCounterOr);
9414         symbolTable.relateToOperator("atomicCounterXor",      EOpAtomicCounterXor);
9415         symbolTable.relateToOperator("atomicCounterExchange", EOpAtomicCounterExchange);
9416         symbolTable.relateToOperator("atomicCounterCompSwap", EOpAtomicCounterCompSwap);
9417     }
9418
9419     if (spvVersion.vulkanRelaxed) {
9420         //
9421         // functions signature have been replaced to take 'uint' instead of 'atomic_uint'
9422         // remap atomic counter functions to non-counter atomic ops so
9423         // functions act as aliases to non-counter atomic ops
9424         //
9425         symbolTable.relateToOperator("atomicCounterAdd", EOpAtomicAdd);
9426         symbolTable.relateToOperator("atomicCounterSubtract", EOpAtomicSubtract);
9427         symbolTable.relateToOperator("atomicCounterMin", EOpAtomicMin);
9428         symbolTable.relateToOperator("atomicCounterMax", EOpAtomicMax);
9429         symbolTable.relateToOperator("atomicCounterAnd", EOpAtomicAnd);
9430         symbolTable.relateToOperator("atomicCounterOr", EOpAtomicOr);
9431         symbolTable.relateToOperator("atomicCounterXor", EOpAtomicXor);
9432         symbolTable.relateToOperator("atomicCounterExchange", EOpAtomicExchange);
9433         symbolTable.relateToOperator("atomicCounterCompSwap", EOpAtomicCompSwap);
9434     }
9435
9436     symbolTable.relateToOperator("fma",               EOpFma);
9437     symbolTable.relateToOperator("frexp",             EOpFrexp);
9438     symbolTable.relateToOperator("ldexp",             EOpLdexp);
9439     symbolTable.relateToOperator("uaddCarry",         EOpAddCarry);
9440     symbolTable.relateToOperator("usubBorrow",        EOpSubBorrow);
9441     symbolTable.relateToOperator("umulExtended",      EOpUMulExtended);
9442     symbolTable.relateToOperator("imulExtended",      EOpIMulExtended);
9443     symbolTable.relateToOperator("bitfieldExtract",   EOpBitfieldExtract);
9444     symbolTable.relateToOperator("bitfieldInsert",    EOpBitfieldInsert);
9445     symbolTable.relateToOperator("bitfieldReverse",   EOpBitFieldReverse);
9446     symbolTable.relateToOperator("bitCount",          EOpBitCount);
9447     symbolTable.relateToOperator("findLSB",           EOpFindLSB);
9448     symbolTable.relateToOperator("findMSB",           EOpFindMSB);
9449
9450     symbolTable.relateToOperator("helperInvocationEXT",  EOpIsHelperInvocation);
9451
9452     symbolTable.relateToOperator("countLeadingZeros",  EOpCountLeadingZeros);
9453     symbolTable.relateToOperator("countTrailingZeros", EOpCountTrailingZeros);
9454     symbolTable.relateToOperator("absoluteDifference", EOpAbsDifference);
9455     symbolTable.relateToOperator("addSaturate",        EOpAddSaturate);
9456     symbolTable.relateToOperator("subtractSaturate",   EOpSubSaturate);
9457     symbolTable.relateToOperator("average",            EOpAverage);
9458     symbolTable.relateToOperator("averageRounded",     EOpAverageRounded);
9459     symbolTable.relateToOperator("multiply32x16",      EOpMul32x16);
9460     symbolTable.relateToOperator("debugPrintfEXT",     EOpDebugPrintf);
9461
9462
9463     if (PureOperatorBuiltins) {
9464         symbolTable.relateToOperator("imageSize",               EOpImageQuerySize);
9465         symbolTable.relateToOperator("imageSamples",            EOpImageQuerySamples);
9466         symbolTable.relateToOperator("imageLoad",               EOpImageLoad);
9467         symbolTable.relateToOperator("imageStore",              EOpImageStore);
9468         symbolTable.relateToOperator("imageAtomicAdd",          EOpImageAtomicAdd);
9469         symbolTable.relateToOperator("imageAtomicMin",          EOpImageAtomicMin);
9470         symbolTable.relateToOperator("imageAtomicMax",          EOpImageAtomicMax);
9471         symbolTable.relateToOperator("imageAtomicAnd",          EOpImageAtomicAnd);
9472         symbolTable.relateToOperator("imageAtomicOr",           EOpImageAtomicOr);
9473         symbolTable.relateToOperator("imageAtomicXor",          EOpImageAtomicXor);
9474         symbolTable.relateToOperator("imageAtomicExchange",     EOpImageAtomicExchange);
9475         symbolTable.relateToOperator("imageAtomicCompSwap",     EOpImageAtomicCompSwap);
9476         symbolTable.relateToOperator("imageAtomicLoad",         EOpImageAtomicLoad);
9477         symbolTable.relateToOperator("imageAtomicStore",        EOpImageAtomicStore);
9478
9479         symbolTable.relateToOperator("subpassLoad",             EOpSubpassLoad);
9480         symbolTable.relateToOperator("subpassLoadMS",           EOpSubpassLoadMS);
9481
9482         symbolTable.relateToOperator("textureGather",           EOpTextureGather);
9483         symbolTable.relateToOperator("textureGatherOffset",     EOpTextureGatherOffset);
9484         symbolTable.relateToOperator("textureGatherOffsets",    EOpTextureGatherOffsets);
9485
9486         symbolTable.relateToOperator("noise1", EOpNoise);
9487         symbolTable.relateToOperator("noise2", EOpNoise);
9488         symbolTable.relateToOperator("noise3", EOpNoise);
9489         symbolTable.relateToOperator("noise4", EOpNoise);
9490
9491         symbolTable.relateToOperator("textureFootprintNV",          EOpImageSampleFootprintNV);
9492         symbolTable.relateToOperator("textureFootprintClampNV",     EOpImageSampleFootprintClampNV);
9493         symbolTable.relateToOperator("textureFootprintLodNV",       EOpImageSampleFootprintLodNV);
9494         symbolTable.relateToOperator("textureFootprintGradNV",      EOpImageSampleFootprintGradNV);
9495         symbolTable.relateToOperator("textureFootprintGradClampNV", EOpImageSampleFootprintGradClampNV);
9496
9497         if (spvVersion.spv == 0 && IncludeLegacy(version, profile, spvVersion))
9498             symbolTable.relateToOperator("ftransform", EOpFtransform);
9499
9500         if (spvVersion.spv == 0 && (IncludeLegacy(version, profile, spvVersion) ||
9501             (profile == EEsProfile && version == 100))) {
9502
9503             symbolTable.relateToOperator("texture1D",                EOpTexture);
9504             symbolTable.relateToOperator("texture1DGradARB",         EOpTextureGrad);
9505             symbolTable.relateToOperator("texture1DProj",            EOpTextureProj);
9506             symbolTable.relateToOperator("texture1DProjGradARB",     EOpTextureProjGrad);
9507             symbolTable.relateToOperator("texture1DLod",             EOpTextureLod);
9508             symbolTable.relateToOperator("texture1DProjLod",         EOpTextureProjLod);
9509
9510             symbolTable.relateToOperator("texture2DRect",            EOpTexture);
9511             symbolTable.relateToOperator("texture2DRectProj",        EOpTextureProj);
9512             symbolTable.relateToOperator("texture2DRectGradARB",     EOpTextureGrad);
9513             symbolTable.relateToOperator("texture2DRectProjGradARB", EOpTextureProjGrad);
9514             symbolTable.relateToOperator("shadow2DRect",             EOpTexture);
9515             symbolTable.relateToOperator("shadow2DRectProj",         EOpTextureProj);
9516             symbolTable.relateToOperator("shadow2DRectGradARB",      EOpTextureGrad);
9517             symbolTable.relateToOperator("shadow2DRectProjGradARB",  EOpTextureProjGrad);
9518
9519             symbolTable.relateToOperator("texture2D",                EOpTexture);
9520             symbolTable.relateToOperator("texture2DProj",            EOpTextureProj);
9521             symbolTable.relateToOperator("texture2DGradEXT",         EOpTextureGrad);
9522             symbolTable.relateToOperator("texture2DGradARB",         EOpTextureGrad);
9523             symbolTable.relateToOperator("texture2DProjGradEXT",     EOpTextureProjGrad);
9524             symbolTable.relateToOperator("texture2DProjGradARB",     EOpTextureProjGrad);
9525             symbolTable.relateToOperator("texture2DLod",             EOpTextureLod);
9526             symbolTable.relateToOperator("texture2DLodEXT",          EOpTextureLod);
9527             symbolTable.relateToOperator("texture2DProjLod",         EOpTextureProjLod);
9528             symbolTable.relateToOperator("texture2DProjLodEXT",      EOpTextureProjLod);
9529
9530             symbolTable.relateToOperator("texture3D",                EOpTexture);
9531             symbolTable.relateToOperator("texture3DGradARB",         EOpTextureGrad);
9532             symbolTable.relateToOperator("texture3DProj",            EOpTextureProj);
9533             symbolTable.relateToOperator("texture3DProjGradARB",     EOpTextureProjGrad);
9534             symbolTable.relateToOperator("texture3DLod",             EOpTextureLod);
9535             symbolTable.relateToOperator("texture3DProjLod",         EOpTextureProjLod);
9536             symbolTable.relateToOperator("textureCube",              EOpTexture);
9537             symbolTable.relateToOperator("textureCubeGradEXT",       EOpTextureGrad);
9538             symbolTable.relateToOperator("textureCubeGradARB",       EOpTextureGrad);
9539             symbolTable.relateToOperator("textureCubeLod",           EOpTextureLod);
9540             symbolTable.relateToOperator("textureCubeLodEXT",        EOpTextureLod);
9541             symbolTable.relateToOperator("shadow1D",                 EOpTexture);
9542             symbolTable.relateToOperator("shadow1DGradARB",          EOpTextureGrad);
9543             symbolTable.relateToOperator("shadow2D",                 EOpTexture);
9544             symbolTable.relateToOperator("shadow2DGradARB",          EOpTextureGrad);
9545             symbolTable.relateToOperator("shadow1DProj",             EOpTextureProj);
9546             symbolTable.relateToOperator("shadow2DProj",             EOpTextureProj);
9547             symbolTable.relateToOperator("shadow1DProjGradARB",      EOpTextureProjGrad);
9548             symbolTable.relateToOperator("shadow2DProjGradARB",      EOpTextureProjGrad);
9549             symbolTable.relateToOperator("shadow1DLod",              EOpTextureLod);
9550             symbolTable.relateToOperator("shadow2DLod",              EOpTextureLod);
9551             symbolTable.relateToOperator("shadow1DProjLod",          EOpTextureProjLod);
9552             symbolTable.relateToOperator("shadow2DProjLod",          EOpTextureProjLod);
9553         }
9554
9555         if (profile != EEsProfile) {
9556             symbolTable.relateToOperator("sparseTextureARB",                EOpSparseTexture);
9557             symbolTable.relateToOperator("sparseTextureLodARB",             EOpSparseTextureLod);
9558             symbolTable.relateToOperator("sparseTextureOffsetARB",          EOpSparseTextureOffset);
9559             symbolTable.relateToOperator("sparseTexelFetchARB",             EOpSparseTextureFetch);
9560             symbolTable.relateToOperator("sparseTexelFetchOffsetARB",       EOpSparseTextureFetchOffset);
9561             symbolTable.relateToOperator("sparseTextureLodOffsetARB",       EOpSparseTextureLodOffset);
9562             symbolTable.relateToOperator("sparseTextureGradARB",            EOpSparseTextureGrad);
9563             symbolTable.relateToOperator("sparseTextureGradOffsetARB",      EOpSparseTextureGradOffset);
9564             symbolTable.relateToOperator("sparseTextureGatherARB",          EOpSparseTextureGather);
9565             symbolTable.relateToOperator("sparseTextureGatherOffsetARB",    EOpSparseTextureGatherOffset);
9566             symbolTable.relateToOperator("sparseTextureGatherOffsetsARB",   EOpSparseTextureGatherOffsets);
9567             symbolTable.relateToOperator("sparseImageLoadARB",              EOpSparseImageLoad);
9568             symbolTable.relateToOperator("sparseTexelsResidentARB",         EOpSparseTexelsResident);
9569
9570             symbolTable.relateToOperator("sparseTextureClampARB",           EOpSparseTextureClamp);
9571             symbolTable.relateToOperator("sparseTextureOffsetClampARB",     EOpSparseTextureOffsetClamp);
9572             symbolTable.relateToOperator("sparseTextureGradClampARB",       EOpSparseTextureGradClamp);
9573             symbolTable.relateToOperator("sparseTextureGradOffsetClampARB", EOpSparseTextureGradOffsetClamp);
9574             symbolTable.relateToOperator("textureClampARB",                 EOpTextureClamp);
9575             symbolTable.relateToOperator("textureOffsetClampARB",           EOpTextureOffsetClamp);
9576             symbolTable.relateToOperator("textureGradClampARB",             EOpTextureGradClamp);
9577             symbolTable.relateToOperator("textureGradOffsetClampARB",       EOpTextureGradOffsetClamp);
9578
9579             symbolTable.relateToOperator("ballotARB",                       EOpBallot);
9580             symbolTable.relateToOperator("readInvocationARB",               EOpReadInvocation);
9581             symbolTable.relateToOperator("readFirstInvocationARB",          EOpReadFirstInvocation);
9582
9583             if (version >= 430) {
9584                 symbolTable.relateToOperator("anyInvocationARB",            EOpAnyInvocation);
9585                 symbolTable.relateToOperator("allInvocationsARB",           EOpAllInvocations);
9586                 symbolTable.relateToOperator("allInvocationsEqualARB",      EOpAllInvocationsEqual);
9587             }
9588             if (version >= 460) {
9589                 symbolTable.relateToOperator("anyInvocation",               EOpAnyInvocation);
9590                 symbolTable.relateToOperator("allInvocations",              EOpAllInvocations);
9591                 symbolTable.relateToOperator("allInvocationsEqual",         EOpAllInvocationsEqual);
9592             }
9593             symbolTable.relateToOperator("minInvocationsAMD",                           EOpMinInvocations);
9594             symbolTable.relateToOperator("maxInvocationsAMD",                           EOpMaxInvocations);
9595             symbolTable.relateToOperator("addInvocationsAMD",                           EOpAddInvocations);
9596             symbolTable.relateToOperator("minInvocationsNonUniformAMD",                 EOpMinInvocationsNonUniform);
9597             symbolTable.relateToOperator("maxInvocationsNonUniformAMD",                 EOpMaxInvocationsNonUniform);
9598             symbolTable.relateToOperator("addInvocationsNonUniformAMD",                 EOpAddInvocationsNonUniform);
9599             symbolTable.relateToOperator("minInvocationsInclusiveScanAMD",              EOpMinInvocationsInclusiveScan);
9600             symbolTable.relateToOperator("maxInvocationsInclusiveScanAMD",              EOpMaxInvocationsInclusiveScan);
9601             symbolTable.relateToOperator("addInvocationsInclusiveScanAMD",              EOpAddInvocationsInclusiveScan);
9602             symbolTable.relateToOperator("minInvocationsInclusiveScanNonUniformAMD",    EOpMinInvocationsInclusiveScanNonUniform);
9603             symbolTable.relateToOperator("maxInvocationsInclusiveScanNonUniformAMD",    EOpMaxInvocationsInclusiveScanNonUniform);
9604             symbolTable.relateToOperator("addInvocationsInclusiveScanNonUniformAMD",    EOpAddInvocationsInclusiveScanNonUniform);
9605             symbolTable.relateToOperator("minInvocationsExclusiveScanAMD",              EOpMinInvocationsExclusiveScan);
9606             symbolTable.relateToOperator("maxInvocationsExclusiveScanAMD",              EOpMaxInvocationsExclusiveScan);
9607             symbolTable.relateToOperator("addInvocationsExclusiveScanAMD",              EOpAddInvocationsExclusiveScan);
9608             symbolTable.relateToOperator("minInvocationsExclusiveScanNonUniformAMD",    EOpMinInvocationsExclusiveScanNonUniform);
9609             symbolTable.relateToOperator("maxInvocationsExclusiveScanNonUniformAMD",    EOpMaxInvocationsExclusiveScanNonUniform);
9610             symbolTable.relateToOperator("addInvocationsExclusiveScanNonUniformAMD",    EOpAddInvocationsExclusiveScanNonUniform);
9611             symbolTable.relateToOperator("swizzleInvocationsAMD",                       EOpSwizzleInvocations);
9612             symbolTable.relateToOperator("swizzleInvocationsMaskedAMD",                 EOpSwizzleInvocationsMasked);
9613             symbolTable.relateToOperator("writeInvocationAMD",                          EOpWriteInvocation);
9614             symbolTable.relateToOperator("mbcntAMD",                                    EOpMbcnt);
9615
9616             symbolTable.relateToOperator("min3",    EOpMin3);
9617             symbolTable.relateToOperator("max3",    EOpMax3);
9618             symbolTable.relateToOperator("mid3",    EOpMid3);
9619
9620             symbolTable.relateToOperator("cubeFaceIndexAMD",    EOpCubeFaceIndex);
9621             symbolTable.relateToOperator("cubeFaceCoordAMD",    EOpCubeFaceCoord);
9622             symbolTable.relateToOperator("timeAMD",             EOpTime);
9623
9624             symbolTable.relateToOperator("textureGatherLodAMD",                 EOpTextureGatherLod);
9625             symbolTable.relateToOperator("textureGatherLodOffsetAMD",           EOpTextureGatherLodOffset);
9626             symbolTable.relateToOperator("textureGatherLodOffsetsAMD",          EOpTextureGatherLodOffsets);
9627             symbolTable.relateToOperator("sparseTextureGatherLodAMD",           EOpSparseTextureGatherLod);
9628             symbolTable.relateToOperator("sparseTextureGatherLodOffsetAMD",     EOpSparseTextureGatherLodOffset);
9629             symbolTable.relateToOperator("sparseTextureGatherLodOffsetsAMD",    EOpSparseTextureGatherLodOffsets);
9630
9631             symbolTable.relateToOperator("imageLoadLodAMD",                     EOpImageLoadLod);
9632             symbolTable.relateToOperator("imageStoreLodAMD",                    EOpImageStoreLod);
9633             symbolTable.relateToOperator("sparseImageLoadLodAMD",               EOpSparseImageLoadLod);
9634
9635             symbolTable.relateToOperator("fragmentMaskFetchAMD",                EOpFragmentMaskFetch);
9636             symbolTable.relateToOperator("fragmentFetchAMD",                    EOpFragmentFetch);
9637         }
9638
9639         // GL_KHR_shader_subgroup
9640         if ((profile == EEsProfile && version >= 310) ||
9641             (profile != EEsProfile && version >= 140)) {
9642             symbolTable.relateToOperator("subgroupBarrier",                 EOpSubgroupBarrier);
9643             symbolTable.relateToOperator("subgroupMemoryBarrier",           EOpSubgroupMemoryBarrier);
9644             symbolTable.relateToOperator("subgroupMemoryBarrierBuffer",     EOpSubgroupMemoryBarrierBuffer);
9645             symbolTable.relateToOperator("subgroupMemoryBarrierImage",      EOpSubgroupMemoryBarrierImage);
9646             symbolTable.relateToOperator("subgroupElect",                   EOpSubgroupElect);
9647             symbolTable.relateToOperator("subgroupAll",                     EOpSubgroupAll);
9648             symbolTable.relateToOperator("subgroupAny",                     EOpSubgroupAny);
9649             symbolTable.relateToOperator("subgroupAllEqual",                EOpSubgroupAllEqual);
9650             symbolTable.relateToOperator("subgroupBroadcast",               EOpSubgroupBroadcast);
9651             symbolTable.relateToOperator("subgroupBroadcastFirst",          EOpSubgroupBroadcastFirst);
9652             symbolTable.relateToOperator("subgroupBallot",                  EOpSubgroupBallot);
9653             symbolTable.relateToOperator("subgroupInverseBallot",           EOpSubgroupInverseBallot);
9654             symbolTable.relateToOperator("subgroupBallotBitExtract",        EOpSubgroupBallotBitExtract);
9655             symbolTable.relateToOperator("subgroupBallotBitCount",          EOpSubgroupBallotBitCount);
9656             symbolTable.relateToOperator("subgroupBallotInclusiveBitCount", EOpSubgroupBallotInclusiveBitCount);
9657             symbolTable.relateToOperator("subgroupBallotExclusiveBitCount", EOpSubgroupBallotExclusiveBitCount);
9658             symbolTable.relateToOperator("subgroupBallotFindLSB",           EOpSubgroupBallotFindLSB);
9659             symbolTable.relateToOperator("subgroupBallotFindMSB",           EOpSubgroupBallotFindMSB);
9660             symbolTable.relateToOperator("subgroupShuffle",                 EOpSubgroupShuffle);
9661             symbolTable.relateToOperator("subgroupShuffleXor",              EOpSubgroupShuffleXor);
9662             symbolTable.relateToOperator("subgroupShuffleUp",               EOpSubgroupShuffleUp);
9663             symbolTable.relateToOperator("subgroupShuffleDown",             EOpSubgroupShuffleDown);
9664             symbolTable.relateToOperator("subgroupAdd",                     EOpSubgroupAdd);
9665             symbolTable.relateToOperator("subgroupMul",                     EOpSubgroupMul);
9666             symbolTable.relateToOperator("subgroupMin",                     EOpSubgroupMin);
9667             symbolTable.relateToOperator("subgroupMax",                     EOpSubgroupMax);
9668             symbolTable.relateToOperator("subgroupAnd",                     EOpSubgroupAnd);
9669             symbolTable.relateToOperator("subgroupOr",                      EOpSubgroupOr);
9670             symbolTable.relateToOperator("subgroupXor",                     EOpSubgroupXor);
9671             symbolTable.relateToOperator("subgroupInclusiveAdd",            EOpSubgroupInclusiveAdd);
9672             symbolTable.relateToOperator("subgroupInclusiveMul",            EOpSubgroupInclusiveMul);
9673             symbolTable.relateToOperator("subgroupInclusiveMin",            EOpSubgroupInclusiveMin);
9674             symbolTable.relateToOperator("subgroupInclusiveMax",            EOpSubgroupInclusiveMax);
9675             symbolTable.relateToOperator("subgroupInclusiveAnd",            EOpSubgroupInclusiveAnd);
9676             symbolTable.relateToOperator("subgroupInclusiveOr",             EOpSubgroupInclusiveOr);
9677             symbolTable.relateToOperator("subgroupInclusiveXor",            EOpSubgroupInclusiveXor);
9678             symbolTable.relateToOperator("subgroupExclusiveAdd",            EOpSubgroupExclusiveAdd);
9679             symbolTable.relateToOperator("subgroupExclusiveMul",            EOpSubgroupExclusiveMul);
9680             symbolTable.relateToOperator("subgroupExclusiveMin",            EOpSubgroupExclusiveMin);
9681             symbolTable.relateToOperator("subgroupExclusiveMax",            EOpSubgroupExclusiveMax);
9682             symbolTable.relateToOperator("subgroupExclusiveAnd",            EOpSubgroupExclusiveAnd);
9683             symbolTable.relateToOperator("subgroupExclusiveOr",             EOpSubgroupExclusiveOr);
9684             symbolTable.relateToOperator("subgroupExclusiveXor",            EOpSubgroupExclusiveXor);
9685             symbolTable.relateToOperator("subgroupClusteredAdd",            EOpSubgroupClusteredAdd);
9686             symbolTable.relateToOperator("subgroupClusteredMul",            EOpSubgroupClusteredMul);
9687             symbolTable.relateToOperator("subgroupClusteredMin",            EOpSubgroupClusteredMin);
9688             symbolTable.relateToOperator("subgroupClusteredMax",            EOpSubgroupClusteredMax);
9689             symbolTable.relateToOperator("subgroupClusteredAnd",            EOpSubgroupClusteredAnd);
9690             symbolTable.relateToOperator("subgroupClusteredOr",             EOpSubgroupClusteredOr);
9691             symbolTable.relateToOperator("subgroupClusteredXor",            EOpSubgroupClusteredXor);
9692             symbolTable.relateToOperator("subgroupQuadBroadcast",           EOpSubgroupQuadBroadcast);
9693             symbolTable.relateToOperator("subgroupQuadSwapHorizontal",      EOpSubgroupQuadSwapHorizontal);
9694             symbolTable.relateToOperator("subgroupQuadSwapVertical",        EOpSubgroupQuadSwapVertical);
9695             symbolTable.relateToOperator("subgroupQuadSwapDiagonal",        EOpSubgroupQuadSwapDiagonal);
9696
9697             symbolTable.relateToOperator("subgroupPartitionNV",                          EOpSubgroupPartition);
9698             symbolTable.relateToOperator("subgroupPartitionedAddNV",                     EOpSubgroupPartitionedAdd);
9699             symbolTable.relateToOperator("subgroupPartitionedMulNV",                     EOpSubgroupPartitionedMul);
9700             symbolTable.relateToOperator("subgroupPartitionedMinNV",                     EOpSubgroupPartitionedMin);
9701             symbolTable.relateToOperator("subgroupPartitionedMaxNV",                     EOpSubgroupPartitionedMax);
9702             symbolTable.relateToOperator("subgroupPartitionedAndNV",                     EOpSubgroupPartitionedAnd);
9703             symbolTable.relateToOperator("subgroupPartitionedOrNV",                      EOpSubgroupPartitionedOr);
9704             symbolTable.relateToOperator("subgroupPartitionedXorNV",                     EOpSubgroupPartitionedXor);
9705             symbolTable.relateToOperator("subgroupPartitionedInclusiveAddNV",            EOpSubgroupPartitionedInclusiveAdd);
9706             symbolTable.relateToOperator("subgroupPartitionedInclusiveMulNV",            EOpSubgroupPartitionedInclusiveMul);
9707             symbolTable.relateToOperator("subgroupPartitionedInclusiveMinNV",            EOpSubgroupPartitionedInclusiveMin);
9708             symbolTable.relateToOperator("subgroupPartitionedInclusiveMaxNV",            EOpSubgroupPartitionedInclusiveMax);
9709             symbolTable.relateToOperator("subgroupPartitionedInclusiveAndNV",            EOpSubgroupPartitionedInclusiveAnd);
9710             symbolTable.relateToOperator("subgroupPartitionedInclusiveOrNV",             EOpSubgroupPartitionedInclusiveOr);
9711             symbolTable.relateToOperator("subgroupPartitionedInclusiveXorNV",            EOpSubgroupPartitionedInclusiveXor);
9712             symbolTable.relateToOperator("subgroupPartitionedExclusiveAddNV",            EOpSubgroupPartitionedExclusiveAdd);
9713             symbolTable.relateToOperator("subgroupPartitionedExclusiveMulNV",            EOpSubgroupPartitionedExclusiveMul);
9714             symbolTable.relateToOperator("subgroupPartitionedExclusiveMinNV",            EOpSubgroupPartitionedExclusiveMin);
9715             symbolTable.relateToOperator("subgroupPartitionedExclusiveMaxNV",            EOpSubgroupPartitionedExclusiveMax);
9716             symbolTable.relateToOperator("subgroupPartitionedExclusiveAndNV",            EOpSubgroupPartitionedExclusiveAnd);
9717             symbolTable.relateToOperator("subgroupPartitionedExclusiveOrNV",             EOpSubgroupPartitionedExclusiveOr);
9718             symbolTable.relateToOperator("subgroupPartitionedExclusiveXorNV",            EOpSubgroupPartitionedExclusiveXor);
9719         }
9720
9721         if (profile == EEsProfile) {
9722             symbolTable.relateToOperator("shadow2DEXT",              EOpTexture);
9723             symbolTable.relateToOperator("shadow2DProjEXT",          EOpTextureProj);
9724         }
9725     }
9726
9727     switch(language) {
9728     case EShLangVertex:
9729         break;
9730
9731     case EShLangTessControl:
9732     case EShLangTessEvaluation:
9733         break;
9734
9735     case EShLangGeometry:
9736         symbolTable.relateToOperator("EmitStreamVertex",   EOpEmitStreamVertex);
9737         symbolTable.relateToOperator("EndStreamPrimitive", EOpEndStreamPrimitive);
9738         symbolTable.relateToOperator("EmitVertex",         EOpEmitVertex);
9739         symbolTable.relateToOperator("EndPrimitive",       EOpEndPrimitive);
9740         break;
9741
9742     case EShLangFragment:
9743         if (profile != EEsProfile && version >= 400) {
9744             symbolTable.relateToOperator("dFdxFine",     EOpDPdxFine);
9745             symbolTable.relateToOperator("dFdyFine",     EOpDPdyFine);
9746             symbolTable.relateToOperator("fwidthFine",   EOpFwidthFine);
9747             symbolTable.relateToOperator("dFdxCoarse",   EOpDPdxCoarse);
9748             symbolTable.relateToOperator("dFdyCoarse",   EOpDPdyCoarse);
9749             symbolTable.relateToOperator("fwidthCoarse", EOpFwidthCoarse);
9750         }
9751
9752         if (profile != EEsProfile && version >= 460) {
9753             symbolTable.relateToOperator("rayQueryInitializeEXT",                                             EOpRayQueryInitialize);
9754             symbolTable.relateToOperator("rayQueryTerminateEXT",                                              EOpRayQueryTerminate);
9755             symbolTable.relateToOperator("rayQueryGenerateIntersectionEXT",                                   EOpRayQueryGenerateIntersection);
9756             symbolTable.relateToOperator("rayQueryConfirmIntersectionEXT",                                    EOpRayQueryConfirmIntersection);
9757             symbolTable.relateToOperator("rayQueryProceedEXT",                                                EOpRayQueryProceed);
9758             symbolTable.relateToOperator("rayQueryGetIntersectionTypeEXT",                                    EOpRayQueryGetIntersectionType);
9759             symbolTable.relateToOperator("rayQueryGetRayTMinEXT",                                             EOpRayQueryGetRayTMin);
9760             symbolTable.relateToOperator("rayQueryGetRayFlagsEXT",                                            EOpRayQueryGetRayFlags);
9761             symbolTable.relateToOperator("rayQueryGetIntersectionTEXT",                                       EOpRayQueryGetIntersectionT);
9762             symbolTable.relateToOperator("rayQueryGetIntersectionInstanceCustomIndexEXT",                     EOpRayQueryGetIntersectionInstanceCustomIndex);
9763             symbolTable.relateToOperator("rayQueryGetIntersectionInstanceIdEXT",                              EOpRayQueryGetIntersectionInstanceId);
9764             symbolTable.relateToOperator("rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT",  EOpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffset);
9765             symbolTable.relateToOperator("rayQueryGetIntersectionGeometryIndexEXT",                           EOpRayQueryGetIntersectionGeometryIndex);
9766             symbolTable.relateToOperator("rayQueryGetIntersectionPrimitiveIndexEXT",                          EOpRayQueryGetIntersectionPrimitiveIndex);
9767             symbolTable.relateToOperator("rayQueryGetIntersectionBarycentricsEXT",                            EOpRayQueryGetIntersectionBarycentrics);
9768             symbolTable.relateToOperator("rayQueryGetIntersectionFrontFaceEXT",                               EOpRayQueryGetIntersectionFrontFace);
9769             symbolTable.relateToOperator("rayQueryGetIntersectionCandidateAABBOpaqueEXT",                     EOpRayQueryGetIntersectionCandidateAABBOpaque);
9770             symbolTable.relateToOperator("rayQueryGetIntersectionObjectRayDirectionEXT",                      EOpRayQueryGetIntersectionObjectRayDirection);
9771             symbolTable.relateToOperator("rayQueryGetIntersectionObjectRayOriginEXT",                         EOpRayQueryGetIntersectionObjectRayOrigin);
9772             symbolTable.relateToOperator("rayQueryGetWorldRayDirectionEXT",                                   EOpRayQueryGetWorldRayDirection);
9773             symbolTable.relateToOperator("rayQueryGetWorldRayOriginEXT",                                      EOpRayQueryGetWorldRayOrigin);
9774             symbolTable.relateToOperator("rayQueryGetIntersectionObjectToWorldEXT",                           EOpRayQueryGetIntersectionObjectToWorld);
9775             symbolTable.relateToOperator("rayQueryGetIntersectionWorldToObjectEXT",                           EOpRayQueryGetIntersectionWorldToObject);
9776         }
9777
9778         symbolTable.relateToOperator("interpolateAtCentroid", EOpInterpolateAtCentroid);
9779         symbolTable.relateToOperator("interpolateAtSample",   EOpInterpolateAtSample);
9780         symbolTable.relateToOperator("interpolateAtOffset",   EOpInterpolateAtOffset);
9781
9782         if (profile != EEsProfile)
9783             symbolTable.relateToOperator("interpolateAtVertexAMD", EOpInterpolateAtVertex);
9784
9785         symbolTable.relateToOperator("beginInvocationInterlockARB", EOpBeginInvocationInterlock);
9786         symbolTable.relateToOperator("endInvocationInterlockARB",   EOpEndInvocationInterlock);
9787
9788         break;
9789
9790     case EShLangCompute:
9791         symbolTable.relateToOperator("subgroupMemoryBarrierShared", EOpSubgroupMemoryBarrierShared);
9792         if ((profile != EEsProfile && version >= 450) ||
9793             (profile == EEsProfile && version >= 320)) {
9794             symbolTable.relateToOperator("dFdx",        EOpDPdx);
9795             symbolTable.relateToOperator("dFdy",        EOpDPdy);
9796             symbolTable.relateToOperator("fwidth",      EOpFwidth);
9797             symbolTable.relateToOperator("dFdxFine",    EOpDPdxFine);
9798             symbolTable.relateToOperator("dFdyFine",    EOpDPdyFine);
9799             symbolTable.relateToOperator("fwidthFine",  EOpFwidthFine);
9800             symbolTable.relateToOperator("dFdxCoarse",  EOpDPdxCoarse);
9801             symbolTable.relateToOperator("dFdyCoarse",  EOpDPdyCoarse);
9802             symbolTable.relateToOperator("fwidthCoarse",EOpFwidthCoarse);
9803         }
9804         symbolTable.relateToOperator("coopMatLoadNV",              EOpCooperativeMatrixLoad);
9805         symbolTable.relateToOperator("coopMatStoreNV",             EOpCooperativeMatrixStore);
9806         symbolTable.relateToOperator("coopMatMulAddNV",            EOpCooperativeMatrixMulAdd);
9807         break;
9808
9809     case EShLangRayGen:
9810     case EShLangClosestHit:
9811     case EShLangMiss:
9812         if (profile != EEsProfile && version >= 460) {
9813             symbolTable.relateToOperator("traceNV", EOpTraceNV);
9814             symbolTable.relateToOperator("traceRayMotionNV", EOpTraceRayMotionNV);
9815             symbolTable.relateToOperator("traceRayEXT", EOpTraceKHR);
9816             symbolTable.relateToOperator("executeCallableNV", EOpExecuteCallableNV);
9817             symbolTable.relateToOperator("executeCallableEXT", EOpExecuteCallableKHR);
9818         }
9819         break;
9820     case EShLangIntersect:
9821         if (profile != EEsProfile && version >= 460) {
9822             symbolTable.relateToOperator("reportIntersectionNV", EOpReportIntersection);
9823             symbolTable.relateToOperator("reportIntersectionEXT", EOpReportIntersection);
9824         }
9825         break;
9826     case EShLangAnyHit:
9827         if (profile != EEsProfile && version >= 460) {
9828             symbolTable.relateToOperator("ignoreIntersectionNV", EOpIgnoreIntersectionNV);
9829             symbolTable.relateToOperator("terminateRayNV", EOpTerminateRayNV);
9830         }
9831         break;
9832     case EShLangCallable:
9833         if (profile != EEsProfile && version >= 460) {
9834             symbolTable.relateToOperator("executeCallableNV", EOpExecuteCallableNV);
9835             symbolTable.relateToOperator("executeCallableEXT", EOpExecuteCallableKHR);
9836         }
9837         break;
9838     case EShLangMesh:
9839         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
9840             symbolTable.relateToOperator("writePackedPrimitiveIndices4x8NV", EOpWritePackedPrimitiveIndices4x8NV);
9841             symbolTable.relateToOperator("memoryBarrierShared", EOpMemoryBarrierShared);
9842             symbolTable.relateToOperator("groupMemoryBarrier", EOpGroupMemoryBarrier);
9843             symbolTable.relateToOperator("subgroupMemoryBarrierShared", EOpSubgroupMemoryBarrierShared);
9844         }
9845
9846         if (profile != EEsProfile && version >= 450) {
9847             symbolTable.relateToOperator("SetMeshOutputsEXT", EOpSetMeshOutputsEXT);
9848         }
9849         break;
9850     case EShLangTask:
9851         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
9852             symbolTable.relateToOperator("memoryBarrierShared", EOpMemoryBarrierShared);
9853             symbolTable.relateToOperator("groupMemoryBarrier", EOpGroupMemoryBarrier);
9854             symbolTable.relateToOperator("subgroupMemoryBarrierShared", EOpSubgroupMemoryBarrierShared);
9855         }
9856         if (profile != EEsProfile && version >= 450) {
9857             symbolTable.relateToOperator("EmitMeshTasksEXT", EOpEmitMeshTasksEXT);
9858         }
9859         break;
9860
9861     default:
9862         assert(false && "Language not supported");
9863     }
9864 #endif // !GLSLANG_WEB
9865 }
9866
9867 //
9868 // Add context-dependent (resource-specific) built-ins not handled by the above.  These
9869 // would be ones that need to be programmatically added because they cannot
9870 // be added by simple text strings.  For these, also
9871 // 1) Map built-in functions to operators, for those that will turn into an operation node
9872 //    instead of remaining a function call.
9873 // 2) Tag extension-related symbols added to their base version with their extensions, so
9874 //    that if an early version has the extension turned off, there is an error reported on use.
9875 //
9876 void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable, const TBuiltInResource &resources)
9877 {
9878 #ifndef GLSLANG_WEB
9879 #if defined(GLSLANG_ANGLE)
9880     profile = ECoreProfile;
9881     version = 450;
9882 #endif
9883     if (profile != EEsProfile && version >= 430 && version < 440) {
9884         symbolTable.setVariableExtensions("gl_MaxTransformFeedbackBuffers", 1, &E_GL_ARB_enhanced_layouts);
9885         symbolTable.setVariableExtensions("gl_MaxTransformFeedbackInterleavedComponents", 1, &E_GL_ARB_enhanced_layouts);
9886     }
9887     if (profile != EEsProfile && version >= 130 && version < 420) {
9888         symbolTable.setVariableExtensions("gl_MinProgramTexelOffset", 1, &E_GL_ARB_shading_language_420pack);
9889         symbolTable.setVariableExtensions("gl_MaxProgramTexelOffset", 1, &E_GL_ARB_shading_language_420pack);
9890     }
9891     if (profile != EEsProfile && version >= 150 && version < 410)
9892         symbolTable.setVariableExtensions("gl_MaxViewports", 1, &E_GL_ARB_viewport_array);
9893
9894     switch(language) {
9895     case EShLangFragment:
9896         // Set up gl_FragData based on current array size.
9897         if (version == 100 || IncludeLegacy(version, profile, spvVersion) || (! ForwardCompatibility && profile != EEsProfile && version < 420)) {
9898             TPrecisionQualifier pq = profile == EEsProfile ? EpqMedium : EpqNone;
9899             TType fragData(EbtFloat, EvqFragColor, pq, 4);
9900             TArraySizes* arraySizes = new TArraySizes;
9901             arraySizes->addInnerSize(resources.maxDrawBuffers);
9902             fragData.transferArraySizes(arraySizes);
9903             symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData"), fragData));
9904             SpecialQualifier("gl_FragData", EvqFragColor, EbvFragData, symbolTable);
9905         }
9906
9907         // GL_EXT_blend_func_extended
9908         if (profile == EEsProfile && version >= 100) {
9909            symbolTable.setVariableExtensions("gl_MaxDualSourceDrawBuffersEXT",    1, &E_GL_EXT_blend_func_extended);
9910            symbolTable.setVariableExtensions("gl_SecondaryFragColorEXT",    1, &E_GL_EXT_blend_func_extended);
9911            symbolTable.setVariableExtensions("gl_SecondaryFragDataEXT",    1, &E_GL_EXT_blend_func_extended);
9912            SpecialQualifier("gl_SecondaryFragColorEXT", EvqVaryingOut, EbvSecondaryFragColorEXT, symbolTable);
9913            SpecialQualifier("gl_SecondaryFragDataEXT", EvqVaryingOut, EbvSecondaryFragDataEXT, symbolTable);
9914         }
9915
9916         break;
9917
9918     case EShLangTessControl:
9919     case EShLangTessEvaluation:
9920         // Because of the context-dependent array size (gl_MaxPatchVertices),
9921         // these variables were added later than the others and need to be mapped now.
9922
9923         // standard members
9924         BuiltInVariable("gl_in", "gl_Position",     EbvPosition,     symbolTable);
9925         BuiltInVariable("gl_in", "gl_PointSize",    EbvPointSize,    symbolTable);
9926         BuiltInVariable("gl_in", "gl_ClipDistance", EbvClipDistance, symbolTable);
9927         BuiltInVariable("gl_in", "gl_CullDistance", EbvCullDistance, symbolTable);
9928
9929         // compatibility members
9930         BuiltInVariable("gl_in", "gl_ClipVertex",          EbvClipVertex,          symbolTable);
9931         BuiltInVariable("gl_in", "gl_FrontColor",          EbvFrontColor,          symbolTable);
9932         BuiltInVariable("gl_in", "gl_BackColor",           EbvBackColor,           symbolTable);
9933         BuiltInVariable("gl_in", "gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
9934         BuiltInVariable("gl_in", "gl_BackSecondaryColor",  EbvBackSecondaryColor,  symbolTable);
9935         BuiltInVariable("gl_in", "gl_TexCoord",            EbvTexCoord,            symbolTable);
9936         BuiltInVariable("gl_in", "gl_FogFragCoord",        EbvFogFragCoord,        symbolTable);
9937
9938         symbolTable.setVariableExtensions("gl_in", "gl_SecondaryPositionNV", 1, &E_GL_NV_stereo_view_rendering);
9939         symbolTable.setVariableExtensions("gl_in", "gl_PositionPerViewNV",   1, &E_GL_NVX_multiview_per_view_attributes);
9940
9941         BuiltInVariable("gl_in", "gl_SecondaryPositionNV", EbvSecondaryPositionNV, symbolTable);
9942         BuiltInVariable("gl_in", "gl_PositionPerViewNV",   EbvPositionPerViewNV,   symbolTable);
9943
9944         // extension requirements
9945         if (profile == EEsProfile) {
9946             symbolTable.setVariableExtensions("gl_in", "gl_PointSize", Num_AEP_tessellation_point_size, AEP_tessellation_point_size);
9947         }
9948
9949         break;
9950
9951     default:
9952         break;
9953     }
9954 #endif
9955 }
9956
9957 } // end namespace glslang