xref: /aosp_15_r20/external/angle/third_party/glslang/src/glslang/MachineIndependent/Initialize.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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, 2022-2024 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 <array>
55 #include <sstream>
56 #include "Initialize.h"
57 #include "span.h"
58 
59 namespace glslang {
60 
61 // TODO: ARB_Compatability: do full extension support
62 const bool ARBCompatibility = true;
63 
64 const bool ForwardCompatibility = false;
65 
66 namespace {
67 
68 //
69 // A set of definitions for tabling of the built-in functions.
70 //
71 
72 // Order matters here, as does correlation with the subsequent
73 // "const int ..." declarations and the ArgType enumerants.
74 const char* TypeString[] = {
75    "bool",  "bvec2", "bvec3", "bvec4",
76    "float",  "vec2",  "vec3",  "vec4",
77    "int",   "ivec2", "ivec3", "ivec4",
78    "uint",  "uvec2", "uvec3", "uvec4",
79 };
80 const int TypeStringCount = sizeof(TypeString) / sizeof(char*); // number of entries in 'TypeString'
81 const int TypeStringRowShift = 2;                               // shift amount to go downe one row in 'TypeString'
82 const int TypeStringColumnMask = (1 << TypeStringRowShift) - 1; // reduce type to its column number in 'TypeString'
83 const int TypeStringScalarMask = ~TypeStringColumnMask;         // take type to its scalar column in 'TypeString'
84 
85 enum ArgType {
86     // numbers hardcoded to correspond to 'TypeString'; order and value matter
87     TypeB    = 1 << 0,  // Boolean
88     TypeF    = 1 << 1,  // float 32
89     TypeI    = 1 << 2,  // int 32
90     TypeU    = 1 << 3,  // uint 32
91     TypeF16  = 1 << 4,  // float 16
92     TypeF64  = 1 << 5,  // float 64
93     TypeI8   = 1 << 6,  // int 8
94     TypeI16  = 1 << 7,  // int 16
95     TypeI64  = 1 << 8,  // int 64
96     TypeU8   = 1 << 9,  // uint 8
97     TypeU16  = 1 << 10, // uint 16
98     TypeU64  = 1 << 11, // uint 64
99 };
100 // Mixtures of the above, to help the function tables
101 const ArgType TypeFI  = static_cast<ArgType>(TypeF | TypeI);
102 const ArgType TypeFIB = static_cast<ArgType>(TypeF | TypeI | TypeB);
103 const ArgType TypeIU  = static_cast<ArgType>(TypeI | TypeU);
104 
105 // The relationships between arguments and return type, whether anything is
106 // output, or other unusual situations.
107 enum ArgClass {
108     ClassRegular     = 0,  // nothing special, just all vector widths with matching return type; traditional arithmetic
109     ClassLS     = 1 << 0,  // the last argument is also held fixed as a (type-matched) scalar while the others cycle
110     ClassXLS    = 1 << 1,  // the last argument is exclusively a (type-matched) scalar while the others cycle
111     ClassLS2    = 1 << 2,  // the last two arguments are held fixed as a (type-matched) scalar while the others cycle
112     ClassFS     = 1 << 3,  // the first argument is held fixed as a (type-matched) scalar while the others cycle
113     ClassFS2    = 1 << 4,  // the first two arguments are held fixed as a (type-matched) scalar while the others cycle
114     ClassLO     = 1 << 5,  // the last argument is an output
115     ClassB      = 1 << 6,  // return type cycles through only bool/bvec, matching vector width of args
116     ClassLB     = 1 << 7,  // last argument cycles through only bool/bvec, matching vector width of args
117     ClassV1     = 1 << 8,  // scalar only
118     ClassFIO    = 1 << 9,  // first argument is inout
119     ClassRS     = 1 << 10, // the return is held scalar as the arguments cycle
120     ClassNS     = 1 << 11, // no scalar prototype
121     ClassCV     = 1 << 12, // first argument is 'coherent volatile'
122     ClassFO     = 1 << 13, // first argument is output
123     ClassV3     = 1 << 14, // vec3 only
124 };
125 // Mixtures of the above, to help the function tables
126 const ArgClass ClassV1FIOCV = (ArgClass)(ClassV1 | ClassFIO | ClassCV);
127 const ArgClass ClassBNS     = (ArgClass)(ClassB  | ClassNS);
128 const ArgClass ClassRSNS    = (ArgClass)(ClassRS | ClassNS);
129 
130 // A descriptor, for a single profile, of when something is available.
131 // If the current profile does not match 'profile' mask below, the other fields
132 // do not apply (nor validate).
133 // profiles == EBadProfile is the end of an array of these
134 struct Versioning {
135     EProfile profiles;       // the profile(s) (mask) that the following fields are valid for
136     int minExtendedVersion;  // earliest version when extensions are enabled; ignored if numExtensions is 0
137     int minCoreVersion;      // earliest version function is in core; 0 means never
138     int numExtensions;       // how many extensions are in the 'extensions' list
139     const char** extensions; // list of extension names enabling the function
140 };
141 
142 EProfile EDesktopProfile = static_cast<EProfile>(ENoProfile | ECoreProfile | ECompatibilityProfile);
143 
144 // Declare pointers to put into the table for versioning.
145     const std::array Es300Desktop130Version = { Versioning{ EEsProfile,      0, 300, 0, nullptr },
146                                                 Versioning{ EDesktopProfile, 0, 130, 0, nullptr },
147                                               };
148 
149     const std::array Es310Desktop400Version = { Versioning{ EEsProfile,      0, 310, 0, nullptr },
150                                                 Versioning{ EDesktopProfile, 0, 400, 0, nullptr },
151                                               };
152 
153     const std::array Es310Desktop450Version = { Versioning{ EEsProfile,      0, 310, 0, nullptr },
154                                                 Versioning{ EDesktopProfile, 0, 450, 0, nullptr },
155                                               };
156 
157 // The main descriptor of what a set of function prototypes can look like, and
158 // a pointer to extra versioning information, when needed.
159 struct BuiltInFunction {
160     TOperator op;                 // operator to map the name to
161     const char* name;             // function name
162     int numArguments;             // number of arguments (overloads with varying arguments need different entries)
163     ArgType types;                // ArgType mask
164     ArgClass classes;             // the ways this particular function entry manifests
165     const span<const Versioning> versioning; // An empty span means always a valid version
166 };
167 
168 // The tables can have the same built-in function name more than one time,
169 // but the exact same prototype must be indicated at most once.
170 // The prototypes that get declared are the union of all those indicated.
171 // This is important when different releases add new prototypes for the same name.
172 // It also also congnitively simpler tiling of the prototype space.
173 // In practice, most names can be fully represented with one entry.
174 //
175 // Table is terminated by an OpNull TOperator.
176 
177 const std::array BaseFunctions = {
178 //    TOperator,           name,       arg-count,   ArgType,   ArgClass,     versioning
179 //    ---------            ----        ---------    -------    --------      ----------
180     BuiltInFunction{ EOpRadians,          "radians",          1,   TypeF,     ClassRegular, {} },
181     BuiltInFunction{ EOpDegrees,          "degrees",          1,   TypeF,     ClassRegular, {} },
182     BuiltInFunction{ EOpSin,              "sin",              1,   TypeF,     ClassRegular, {} },
183     BuiltInFunction{ EOpCos,              "cos",              1,   TypeF,     ClassRegular, {} },
184     BuiltInFunction{ EOpTan,              "tan",              1,   TypeF,     ClassRegular, {} },
185     BuiltInFunction{ EOpAsin,             "asin",             1,   TypeF,     ClassRegular, {} },
186     BuiltInFunction{ EOpAcos,             "acos",             1,   TypeF,     ClassRegular, {} },
187     BuiltInFunction{ EOpAtan,             "atan",             2,   TypeF,     ClassRegular, {} },
188     BuiltInFunction{ EOpAtan,             "atan",             1,   TypeF,     ClassRegular, {} },
189     BuiltInFunction{ EOpPow,              "pow",              2,   TypeF,     ClassRegular, {} },
190     BuiltInFunction{ EOpExp,              "exp",              1,   TypeF,     ClassRegular, {} },
191     BuiltInFunction{ EOpLog,              "log",              1,   TypeF,     ClassRegular, {} },
192     BuiltInFunction{ EOpExp2,             "exp2",             1,   TypeF,     ClassRegular, {} },
193     BuiltInFunction{ EOpLog2,             "log2",             1,   TypeF,     ClassRegular, {} },
194     BuiltInFunction{ EOpSqrt,             "sqrt",             1,   TypeF,     ClassRegular, {} },
195     BuiltInFunction{ EOpInverseSqrt,      "inversesqrt",      1,   TypeF,     ClassRegular, {} },
196     BuiltInFunction{ EOpAbs,              "abs",              1,   TypeF,     ClassRegular, {} },
197     BuiltInFunction{ EOpSign,             "sign",             1,   TypeF,     ClassRegular, {} },
198     BuiltInFunction{ EOpFloor,            "floor",            1,   TypeF,     ClassRegular, {} },
199     BuiltInFunction{ EOpCeil,             "ceil",             1,   TypeF,     ClassRegular, {} },
200     BuiltInFunction{ EOpFract,            "fract",            1,   TypeF,     ClassRegular, {} },
201     BuiltInFunction{ EOpMod,              "mod",              2,   TypeF,     ClassLS,      {} },
202     BuiltInFunction{ EOpMin,              "min",              2,   TypeF,     ClassLS,      {} },
203     BuiltInFunction{ EOpMax,              "max",              2,   TypeF,     ClassLS,      {} },
204     BuiltInFunction{ EOpClamp,            "clamp",            3,   TypeF,     ClassLS2,     {} },
205     BuiltInFunction{ EOpMix,              "mix",              3,   TypeF,     ClassLS,      {} },
206     BuiltInFunction{ EOpStep,             "step",             2,   TypeF,     ClassFS,      {} },
207     BuiltInFunction{ EOpSmoothStep,       "smoothstep",       3,   TypeF,     ClassFS2,     {} },
208     BuiltInFunction{ EOpNormalize,        "normalize",        1,   TypeF,     ClassRegular, {} },
209     BuiltInFunction{ EOpFaceForward,      "faceforward",      3,   TypeF,     ClassRegular, {} },
210     BuiltInFunction{ EOpReflect,          "reflect",          2,   TypeF,     ClassRegular, {} },
211     BuiltInFunction{ EOpRefract,          "refract",          3,   TypeF,     ClassXLS,     {} },
212     BuiltInFunction{ EOpLength,           "length",           1,   TypeF,     ClassRS,      {} },
213     BuiltInFunction{ EOpDistance,         "distance",         2,   TypeF,     ClassRS,      {} },
214     BuiltInFunction{ EOpDot,              "dot",              2,   TypeF,     ClassRS,      {} },
215     BuiltInFunction{ EOpCross,            "cross",            2,   TypeF,     ClassV3,      {} },
216     BuiltInFunction{ EOpLessThan,         "lessThan",         2,   TypeFI,    ClassBNS,     {} },
217     BuiltInFunction{ EOpLessThanEqual,    "lessThanEqual",    2,   TypeFI,    ClassBNS,     {} },
218     BuiltInFunction{ EOpGreaterThan,      "greaterThan",      2,   TypeFI,    ClassBNS,     {} },
219     BuiltInFunction{ EOpGreaterThanEqual, "greaterThanEqual", 2,   TypeFI,    ClassBNS,     {} },
220     BuiltInFunction{ EOpVectorEqual,      "equal",            2,   TypeFIB,   ClassBNS,     {} },
221     BuiltInFunction{ EOpVectorNotEqual,   "notEqual",         2,   TypeFIB,   ClassBNS,     {} },
222     BuiltInFunction{ EOpAny,              "any",              1,   TypeB,     ClassRSNS,    {} },
223     BuiltInFunction{ EOpAll,              "all",              1,   TypeB,     ClassRSNS,    {} },
224     BuiltInFunction{ EOpVectorLogicalNot, "not",              1,   TypeB,     ClassNS,      {} },
225     BuiltInFunction{ EOpSinh,             "sinh",             1,   TypeF,     ClassRegular, {Es300Desktop130Version} },
226     BuiltInFunction{ EOpCosh,             "cosh",             1,   TypeF,     ClassRegular, {Es300Desktop130Version} },
227     BuiltInFunction{ EOpTanh,             "tanh",             1,   TypeF,     ClassRegular, {Es300Desktop130Version} },
228     BuiltInFunction{ EOpAsinh,            "asinh",            1,   TypeF,     ClassRegular, {Es300Desktop130Version} },
229     BuiltInFunction{ EOpAcosh,            "acosh",            1,   TypeF,     ClassRegular, {Es300Desktop130Version} },
230     BuiltInFunction{ EOpAtanh,            "atanh",            1,   TypeF,     ClassRegular, {Es300Desktop130Version} },
231     BuiltInFunction{ EOpAbs,              "abs",              1,   TypeI,     ClassRegular, {Es300Desktop130Version} },
232     BuiltInFunction{ EOpSign,             "sign",             1,   TypeI,     ClassRegular, {Es300Desktop130Version} },
233     BuiltInFunction{ EOpTrunc,            "trunc",            1,   TypeF,     ClassRegular, {Es300Desktop130Version} },
234     BuiltInFunction{ EOpRound,            "round",            1,   TypeF,     ClassRegular, {Es300Desktop130Version} },
235     BuiltInFunction{ EOpRoundEven,        "roundEven",        1,   TypeF,     ClassRegular, {Es300Desktop130Version} },
236     BuiltInFunction{ EOpModf,             "modf",             2,   TypeF,     ClassLO,      {Es300Desktop130Version} },
237     BuiltInFunction{ EOpMin,              "min",              2,   TypeIU,    ClassLS,      {Es300Desktop130Version} },
238     BuiltInFunction{ EOpMax,              "max",              2,   TypeIU,    ClassLS,      {Es300Desktop130Version} },
239     BuiltInFunction{ EOpClamp,            "clamp",            3,   TypeIU,    ClassLS2,     {Es300Desktop130Version} },
240     BuiltInFunction{ EOpMix,              "mix",              3,   TypeF,     ClassLB,      {Es300Desktop130Version} },
241     BuiltInFunction{ EOpIsInf,            "isinf",            1,   TypeF,     ClassB,       {Es300Desktop130Version} },
242     BuiltInFunction{ EOpIsNan,            "isnan",            1,   TypeF,     ClassB,       {Es300Desktop130Version} },
243     BuiltInFunction{ EOpLessThan,         "lessThan",         2,   TypeU,     ClassBNS,     {Es300Desktop130Version} },
244     BuiltInFunction{ EOpLessThanEqual,    "lessThanEqual",    2,   TypeU,     ClassBNS,     {Es300Desktop130Version} },
245     BuiltInFunction{ EOpGreaterThan,      "greaterThan",      2,   TypeU,     ClassBNS,     {Es300Desktop130Version} },
246     BuiltInFunction{ EOpGreaterThanEqual, "greaterThanEqual", 2,   TypeU,     ClassBNS,     {Es300Desktop130Version} },
247     BuiltInFunction{ EOpVectorEqual,      "equal",            2,   TypeU,     ClassBNS,     {Es300Desktop130Version} },
248     BuiltInFunction{ EOpVectorNotEqual,   "notEqual",         2,   TypeU,     ClassBNS,     {Es300Desktop130Version} },
249     BuiltInFunction{ EOpAtomicAdd,        "atomicAdd",        2,   TypeIU,    ClassV1FIOCV, {Es310Desktop400Version} },
250     BuiltInFunction{ EOpAtomicMin,        "atomicMin",        2,   TypeIU,    ClassV1FIOCV, {Es310Desktop400Version} },
251     BuiltInFunction{ EOpAtomicMax,        "atomicMax",        2,   TypeIU,    ClassV1FIOCV, {Es310Desktop400Version} },
252     BuiltInFunction{ EOpAtomicAnd,        "atomicAnd",        2,   TypeIU,    ClassV1FIOCV, {Es310Desktop400Version} },
253     BuiltInFunction{ EOpAtomicOr,         "atomicOr",         2,   TypeIU,    ClassV1FIOCV, {Es310Desktop400Version} },
254     BuiltInFunction{ EOpAtomicXor,        "atomicXor",        2,   TypeIU,    ClassV1FIOCV, {Es310Desktop400Version} },
255     BuiltInFunction{ EOpAtomicExchange,   "atomicExchange",   2,   TypeIU,    ClassV1FIOCV, {Es310Desktop400Version} },
256     BuiltInFunction{ EOpAtomicCompSwap,   "atomicCompSwap",   3,   TypeIU,    ClassV1FIOCV, {Es310Desktop400Version} },
257     BuiltInFunction{ EOpMix,              "mix",              3,   TypeB,     ClassRegular, {Es310Desktop450Version} },
258     BuiltInFunction{ EOpMix,              "mix",              3,   TypeIU,    ClassLB,      {Es310Desktop450Version} },
259 };
260 
261 const std::array DerivativeFunctions = {
262     BuiltInFunction{ EOpDPdx,             "dFdx",             1,   TypeF,     ClassRegular, {} },
263     BuiltInFunction{ EOpDPdy,             "dFdy",             1,   TypeF,     ClassRegular, {} },
264     BuiltInFunction{ EOpFwidth,           "fwidth",           1,   TypeF,     ClassRegular, {} },
265 };
266 
267 // For functions declared some other way, but still use the table to relate to operator.
268 struct CustomFunction {
269     TOperator op;                 // operator to map the name to
270     const char* name;             // function name
271     const span<const Versioning> versioning; // An empty span means always a valid version
272 };
273 
274 const CustomFunction CustomFunctions[] = {
275     { EOpBarrier,             "barrier",             {} },
276     { EOpMemoryBarrierShared, "memoryBarrierShared", {} },
277     { EOpGroupMemoryBarrier,  "groupMemoryBarrier",  {} },
278     { EOpMemoryBarrier,       "memoryBarrier",       {} },
279     { EOpMemoryBarrierBuffer, "memoryBarrierBuffer", {} },
280 
281     { EOpPackSnorm2x16,       "packSnorm2x16",       {} },
282     { EOpUnpackSnorm2x16,     "unpackSnorm2x16",     {} },
283     { EOpPackUnorm2x16,       "packUnorm2x16",       {} },
284     { EOpUnpackUnorm2x16,     "unpackUnorm2x16",     {} },
285     { EOpPackHalf2x16,        "packHalf2x16",        {} },
286     { EOpUnpackHalf2x16,      "unpackHalf2x16",      {} },
287 
288     { EOpMul,                 "matrixCompMult",      {} },
289     { EOpOuterProduct,        "outerProduct",        {} },
290     { EOpTranspose,           "transpose",           {} },
291     { EOpDeterminant,         "determinant",         {} },
292     { EOpMatrixInverse,       "inverse",             {} },
293     { EOpFloatBitsToInt,      "floatBitsToInt",      {} },
294     { EOpFloatBitsToUint,     "floatBitsToUint",     {} },
295     { EOpIntBitsToFloat,      "intBitsToFloat",      {} },
296     { EOpUintBitsToFloat,     "uintBitsToFloat",     {} },
297 
298     { EOpTextureQuerySize,      "textureSize",           {} },
299     { EOpTextureQueryLod,       "textureQueryLod",       {} },
300     { EOpTextureQueryLod,       "textureQueryLOD",       {} }, // extension GL_ARB_texture_query_lod
301     { EOpTextureQueryLevels,    "textureQueryLevels",    {} },
302     { EOpTextureQuerySamples,   "textureSamples",        {} },
303     { EOpTexture,               "texture",               {} },
304     { EOpTextureProj,           "textureProj",           {} },
305     { EOpTextureLod,            "textureLod",            {} },
306     { EOpTextureOffset,         "textureOffset",         {} },
307     { EOpTextureFetch,          "texelFetch",            {} },
308     { EOpTextureFetchOffset,    "texelFetchOffset",      {} },
309     { EOpTextureProjOffset,     "textureProjOffset",     {} },
310     { EOpTextureLodOffset,      "textureLodOffset",      {} },
311     { EOpTextureProjLod,        "textureProjLod",        {} },
312     { EOpTextureProjLodOffset,  "textureProjLodOffset",  {} },
313     { EOpTextureGrad,           "textureGrad",           {} },
314     { EOpTextureGradOffset,     "textureGradOffset",     {} },
315     { EOpTextureProjGrad,       "textureProjGrad",       {} },
316     { EOpTextureProjGradOffset, "textureProjGradOffset", {} },
317 };
318 
319 // For the given table of functions, add all the indicated prototypes for each
320 // one, to be returned in the passed in decls.
AddTabledBuiltin(TString & decls,const BuiltInFunction & function)321 void AddTabledBuiltin(TString& decls, const BuiltInFunction& function)
322 {
323     const auto isScalarType = [](int type) { return (type & TypeStringColumnMask) == 0; };
324 
325     // loop across these two:
326     //  0: the varying arg set, and
327     //  1: the fixed scalar args
328     const ArgClass ClassFixed = (ArgClass)(ClassLS | ClassXLS | ClassLS2 | ClassFS | ClassFS2);
329     for (int fixed = 0; fixed < ((function.classes & ClassFixed) > 0 ? 2 : 1); ++fixed) {
330 
331         if (fixed == 0 && (function.classes & ClassXLS))
332             continue;
333 
334         // walk the type strings in TypeString[]
335         for (int type = 0; type < TypeStringCount; ++type) {
336             // skip types not selected: go from type to row number to type bit
337             if ((function.types & (1 << (type >> TypeStringRowShift))) == 0)
338                 continue;
339 
340             // if we aren't on a scalar, and should be, skip
341             if ((function.classes & ClassV1) && !isScalarType(type))
342                 continue;
343 
344             // if we aren't on a 3-vector, and should be, skip
345             if ((function.classes & ClassV3) && (type & TypeStringColumnMask) != 2)
346                 continue;
347 
348             // skip replication of all arg scalars between the varying arg set and the fixed args
349             if (fixed == 1 && type == (type & TypeStringScalarMask) && (function.classes & ClassXLS) == 0)
350                 continue;
351 
352             // skip scalars when we are told to
353             if ((function.classes & ClassNS) && isScalarType(type))
354                 continue;
355 
356             // return type
357             if (function.classes & ClassB)
358                 decls.append(TypeString[type & TypeStringColumnMask]);
359             else if (function.classes & ClassRS)
360                 decls.append(TypeString[type & TypeStringScalarMask]);
361             else
362                 decls.append(TypeString[type]);
363             decls.append(" ");
364             decls.append(function.name);
365             decls.append("(");
366 
367             // arguments
368             for (int arg = 0; arg < function.numArguments; ++arg) {
369                 if (arg == function.numArguments - 1 && (function.classes & ClassLO))
370                     decls.append("out ");
371                 if (arg == 0) {
372                     if (function.classes & ClassCV)
373                         decls.append("coherent volatile ");
374                     if (function.classes & ClassFIO)
375                         decls.append("inout ");
376                     if (function.classes & ClassFO)
377                         decls.append("out ");
378                 }
379                 if ((function.classes & ClassLB) && arg == function.numArguments - 1)
380                     decls.append(TypeString[type & TypeStringColumnMask]);
381                 else if (fixed && ((arg == function.numArguments - 1 && (function.classes & (ClassLS | ClassXLS |
382                                                                                                        ClassLS2))) ||
383                                    (arg == function.numArguments - 2 && (function.classes & ClassLS2))             ||
384                                    (arg == 0                         && (function.classes & (ClassFS | ClassFS2))) ||
385                                    (arg == 1                         && (function.classes & ClassFS2))))
386                     decls.append(TypeString[type & TypeStringScalarMask]);
387                 else
388                     decls.append(TypeString[type]);
389                 if (arg < function.numArguments - 1)
390                     decls.append(",");
391             }
392             decls.append(");\n");
393         }
394     }
395 }
396 
397 // See if the tabled versioning information allows the current version.
ValidVersion(const BuiltInFunction & function,int version,EProfile profile,const SpvVersion &)398 bool ValidVersion(const BuiltInFunction& function, int version, EProfile profile, const SpvVersion& /* spVersion */)
399 {
400     // nullptr means always valid
401     if (function.versioning.empty())
402         return true;
403 
404     // check for what is said about our current profile
405     for (const auto& v : function.versioning) {
406         if ((v.profiles & profile) != 0) {
407             if (v.minCoreVersion <= version || (v.numExtensions > 0 && v.minExtendedVersion <= version))
408                 return true;
409         }
410     }
411 
412     return false;
413 }
414 
415 // Relate a single table of built-ins to their AST operator.
416 // This can get called redundantly (especially for the common built-ins, when
417 // called once per stage). This is a performance issue only, not a correctness
418 // concern.  It is done for quality arising from simplicity, as there are subtleties
419 // to get correct if instead trying to do it surgically.
420 template<class FunctionContainer>
RelateTabledBuiltins(const FunctionContainer & functions,TSymbolTable & symbolTable)421 void RelateTabledBuiltins(const FunctionContainer& functions, TSymbolTable& symbolTable)
422 {
423     for (const auto& fn : functions) {
424         symbolTable.relateToOperator(fn.name, fn.op);
425     }
426 }
427 
428 } // end anonymous namespace
429 
430 // Add declarations for all tables of built-in functions.
addTabledBuiltins(int version,EProfile profile,const SpvVersion & spvVersion)431 void TBuiltIns::addTabledBuiltins(int version, EProfile profile, const SpvVersion& spvVersion)
432 {
433     const auto forEachFunction = [&](TString& decls, const span<const BuiltInFunction>& functions) {
434         for (const auto& fn : functions) {
435             if (ValidVersion(fn, version, profile, spvVersion))
436                 AddTabledBuiltin(decls, fn);
437         }
438     };
439 
440     forEachFunction(commonBuiltins, BaseFunctions);
441     forEachFunction(stageBuiltins[EShLangFragment], DerivativeFunctions);
442 
443     if ((profile == EEsProfile && version >= 320) || (profile != EEsProfile && version >= 450))
444         forEachFunction(stageBuiltins[EShLangCompute], DerivativeFunctions);
445 }
446 
447 // Relate all tables of built-ins to the AST operators.
relateTabledBuiltins(int,EProfile,const SpvVersion &,EShLanguage,TSymbolTable & symbolTable)448 void TBuiltIns::relateTabledBuiltins(int /* version */, EProfile /* profile */, const SpvVersion& /* spvVersion */, EShLanguage /* stage */, TSymbolTable& symbolTable)
449 {
450     RelateTabledBuiltins(BaseFunctions, symbolTable);
451     RelateTabledBuiltins(DerivativeFunctions, symbolTable);
452     RelateTabledBuiltins(CustomFunctions, symbolTable);
453 }
454 
IncludeLegacy(int version,EProfile profile,const SpvVersion & spvVersion)455 inline bool IncludeLegacy(int version, EProfile profile, const SpvVersion& spvVersion)
456 {
457     return profile != EEsProfile && (version <= 130 || (spvVersion.spv == 0 && version == 140 && ARBCompatibility) ||
458            profile == ECompatibilityProfile);
459 }
460 
461 // Construct TBuiltInParseables base class.  This can be used for language-common constructs.
TBuiltInParseables()462 TBuiltInParseables::TBuiltInParseables()
463 {
464 }
465 
466 // Destroy TBuiltInParseables.
~TBuiltInParseables()467 TBuiltInParseables::~TBuiltInParseables()
468 {
469 }
470 
TBuiltIns()471 TBuiltIns::TBuiltIns()
472 {
473     // Set up textual representations for making all the permutations
474     // of texturing/imaging functions.
475     prefixes[EbtFloat] =  "";
476     prefixes[EbtInt]   = "i";
477     prefixes[EbtUint]  = "u";
478     prefixes[EbtFloat16] = "f16";
479     prefixes[EbtInt8]  = "i8";
480     prefixes[EbtUint8] = "u8";
481     prefixes[EbtInt16]  = "i16";
482     prefixes[EbtUint16] = "u16";
483     prefixes[EbtInt64]  = "i64";
484     prefixes[EbtUint64] = "u64";
485 
486     postfixes[2] = "2";
487     postfixes[3] = "3";
488     postfixes[4] = "4";
489 
490     // Map from symbolic class of texturing dimension to numeric dimensions.
491     dimMap[Esd2D] = 2;
492     dimMap[Esd3D] = 3;
493     dimMap[EsdCube] = 3;
494     dimMap[Esd1D] = 1;
495     dimMap[EsdRect] = 2;
496     dimMap[EsdBuffer] = 1;
497     dimMap[EsdSubpass] = 2;  // potentially unused for now
498     dimMap[EsdAttachmentEXT] = 2;  // potentially unused for now
499 }
500 
~TBuiltIns()501 TBuiltIns::~TBuiltIns()
502 {
503 }
504 
505 
506 //
507 // Add all context-independent built-in functions and variables that are present
508 // for the given version and profile.  Share common ones across stages, otherwise
509 // make stage-specific entries.
510 //
511 // Most built-ins variables can be added as simple text strings.  Some need to
512 // be added programmatically, which is done later in IdentifyBuiltIns() below.
513 //
initialize(int version,EProfile profile,const SpvVersion & spvVersion)514 void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvVersion)
515 {
516     addTabledBuiltins(version, profile, spvVersion);
517 
518     //============================================================================
519     //
520     // Prototypes for built-in functions used repeatly by different shaders
521     //
522     //============================================================================
523 
524     //
525     // Derivatives Functions.
526     //
527     TString derivativeControls (
528         "float dFdxFine(float p);"
529         "vec2  dFdxFine(vec2  p);"
530         "vec3  dFdxFine(vec3  p);"
531         "vec4  dFdxFine(vec4  p);"
532 
533         "float dFdyFine(float p);"
534         "vec2  dFdyFine(vec2  p);"
535         "vec3  dFdyFine(vec3  p);"
536         "vec4  dFdyFine(vec4  p);"
537 
538         "float fwidthFine(float p);"
539         "vec2  fwidthFine(vec2  p);"
540         "vec3  fwidthFine(vec3  p);"
541         "vec4  fwidthFine(vec4  p);"
542 
543         "float dFdxCoarse(float p);"
544         "vec2  dFdxCoarse(vec2  p);"
545         "vec3  dFdxCoarse(vec3  p);"
546         "vec4  dFdxCoarse(vec4  p);"
547 
548         "float dFdyCoarse(float p);"
549         "vec2  dFdyCoarse(vec2  p);"
550         "vec3  dFdyCoarse(vec3  p);"
551         "vec4  dFdyCoarse(vec4  p);"
552 
553         "float fwidthCoarse(float p);"
554         "vec2  fwidthCoarse(vec2  p);"
555         "vec3  fwidthCoarse(vec3  p);"
556         "vec4  fwidthCoarse(vec4  p);"
557     );
558 
559     TString derivativesAndControl16bits (
560         "float16_t dFdx(float16_t);"
561         "f16vec2   dFdx(f16vec2);"
562         "f16vec3   dFdx(f16vec3);"
563         "f16vec4   dFdx(f16vec4);"
564 
565         "float16_t dFdy(float16_t);"
566         "f16vec2   dFdy(f16vec2);"
567         "f16vec3   dFdy(f16vec3);"
568         "f16vec4   dFdy(f16vec4);"
569 
570         "float16_t dFdxFine(float16_t);"
571         "f16vec2   dFdxFine(f16vec2);"
572         "f16vec3   dFdxFine(f16vec3);"
573         "f16vec4   dFdxFine(f16vec4);"
574 
575         "float16_t dFdyFine(float16_t);"
576         "f16vec2   dFdyFine(f16vec2);"
577         "f16vec3   dFdyFine(f16vec3);"
578         "f16vec4   dFdyFine(f16vec4);"
579 
580         "float16_t dFdxCoarse(float16_t);"
581         "f16vec2   dFdxCoarse(f16vec2);"
582         "f16vec3   dFdxCoarse(f16vec3);"
583         "f16vec4   dFdxCoarse(f16vec4);"
584 
585         "float16_t dFdyCoarse(float16_t);"
586         "f16vec2   dFdyCoarse(f16vec2);"
587         "f16vec3   dFdyCoarse(f16vec3);"
588         "f16vec4   dFdyCoarse(f16vec4);"
589 
590         "float16_t fwidth(float16_t);"
591         "f16vec2   fwidth(f16vec2);"
592         "f16vec3   fwidth(f16vec3);"
593         "f16vec4   fwidth(f16vec4);"
594 
595         "float16_t fwidthFine(float16_t);"
596         "f16vec2   fwidthFine(f16vec2);"
597         "f16vec3   fwidthFine(f16vec3);"
598         "f16vec4   fwidthFine(f16vec4);"
599 
600         "float16_t fwidthCoarse(float16_t);"
601         "f16vec2   fwidthCoarse(f16vec2);"
602         "f16vec3   fwidthCoarse(f16vec3);"
603         "f16vec4   fwidthCoarse(f16vec4);"
604     );
605 
606     TString derivativesAndControl64bits (
607         "float64_t dFdx(float64_t);"
608         "f64vec2   dFdx(f64vec2);"
609         "f64vec3   dFdx(f64vec3);"
610         "f64vec4   dFdx(f64vec4);"
611 
612         "float64_t dFdy(float64_t);"
613         "f64vec2   dFdy(f64vec2);"
614         "f64vec3   dFdy(f64vec3);"
615         "f64vec4   dFdy(f64vec4);"
616 
617         "float64_t dFdxFine(float64_t);"
618         "f64vec2   dFdxFine(f64vec2);"
619         "f64vec3   dFdxFine(f64vec3);"
620         "f64vec4   dFdxFine(f64vec4);"
621 
622         "float64_t dFdyFine(float64_t);"
623         "f64vec2   dFdyFine(f64vec2);"
624         "f64vec3   dFdyFine(f64vec3);"
625         "f64vec4   dFdyFine(f64vec4);"
626 
627         "float64_t dFdxCoarse(float64_t);"
628         "f64vec2   dFdxCoarse(f64vec2);"
629         "f64vec3   dFdxCoarse(f64vec3);"
630         "f64vec4   dFdxCoarse(f64vec4);"
631 
632         "float64_t dFdyCoarse(float64_t);"
633         "f64vec2   dFdyCoarse(f64vec2);"
634         "f64vec3   dFdyCoarse(f64vec3);"
635         "f64vec4   dFdyCoarse(f64vec4);"
636 
637         "float64_t fwidth(float64_t);"
638         "f64vec2   fwidth(f64vec2);"
639         "f64vec3   fwidth(f64vec3);"
640         "f64vec4   fwidth(f64vec4);"
641 
642         "float64_t fwidthFine(float64_t);"
643         "f64vec2   fwidthFine(f64vec2);"
644         "f64vec3   fwidthFine(f64vec3);"
645         "f64vec4   fwidthFine(f64vec4);"
646 
647         "float64_t fwidthCoarse(float64_t);"
648         "f64vec2   fwidthCoarse(f64vec2);"
649         "f64vec3   fwidthCoarse(f64vec3);"
650         "f64vec4   fwidthCoarse(f64vec4);"
651     );
652 
653     //============================================================================
654     //
655     // Prototypes for built-in functions seen by both vertex and fragment shaders.
656     //
657     //============================================================================
658 
659     //
660     // double functions added to desktop 4.00, but not fma, frexp, ldexp, or pack/unpack
661     //
662     if (profile != EEsProfile && version >= 150) {  // ARB_gpu_shader_fp64
663         commonBuiltins.append(
664 
665             "double sqrt(double);"
666             "dvec2  sqrt(dvec2);"
667             "dvec3  sqrt(dvec3);"
668             "dvec4  sqrt(dvec4);"
669 
670             "double inversesqrt(double);"
671             "dvec2  inversesqrt(dvec2);"
672             "dvec3  inversesqrt(dvec3);"
673             "dvec4  inversesqrt(dvec4);"
674 
675             "double abs(double);"
676             "dvec2  abs(dvec2);"
677             "dvec3  abs(dvec3);"
678             "dvec4  abs(dvec4);"
679 
680             "double sign(double);"
681             "dvec2  sign(dvec2);"
682             "dvec3  sign(dvec3);"
683             "dvec4  sign(dvec4);"
684 
685             "double floor(double);"
686             "dvec2  floor(dvec2);"
687             "dvec3  floor(dvec3);"
688             "dvec4  floor(dvec4);"
689 
690             "double trunc(double);"
691             "dvec2  trunc(dvec2);"
692             "dvec3  trunc(dvec3);"
693             "dvec4  trunc(dvec4);"
694 
695             "double round(double);"
696             "dvec2  round(dvec2);"
697             "dvec3  round(dvec3);"
698             "dvec4  round(dvec4);"
699 
700             "double roundEven(double);"
701             "dvec2  roundEven(dvec2);"
702             "dvec3  roundEven(dvec3);"
703             "dvec4  roundEven(dvec4);"
704 
705             "double ceil(double);"
706             "dvec2  ceil(dvec2);"
707             "dvec3  ceil(dvec3);"
708             "dvec4  ceil(dvec4);"
709 
710             "double fract(double);"
711             "dvec2  fract(dvec2);"
712             "dvec3  fract(dvec3);"
713             "dvec4  fract(dvec4);"
714 
715             "double mod(double, double);"
716             "dvec2  mod(dvec2 , double);"
717             "dvec3  mod(dvec3 , double);"
718             "dvec4  mod(dvec4 , double);"
719             "dvec2  mod(dvec2 , dvec2);"
720             "dvec3  mod(dvec3 , dvec3);"
721             "dvec4  mod(dvec4 , dvec4);"
722 
723             "double modf(double, out double);"
724             "dvec2  modf(dvec2,  out dvec2);"
725             "dvec3  modf(dvec3,  out dvec3);"
726             "dvec4  modf(dvec4,  out dvec4);"
727 
728             "double min(double, double);"
729             "dvec2  min(dvec2,  double);"
730             "dvec3  min(dvec3,  double);"
731             "dvec4  min(dvec4,  double);"
732             "dvec2  min(dvec2,  dvec2);"
733             "dvec3  min(dvec3,  dvec3);"
734             "dvec4  min(dvec4,  dvec4);"
735 
736             "double max(double, double);"
737             "dvec2  max(dvec2 , double);"
738             "dvec3  max(dvec3 , double);"
739             "dvec4  max(dvec4 , double);"
740             "dvec2  max(dvec2 , dvec2);"
741             "dvec3  max(dvec3 , dvec3);"
742             "dvec4  max(dvec4 , dvec4);"
743 
744             "double clamp(double, double, double);"
745             "dvec2  clamp(dvec2 , double, double);"
746             "dvec3  clamp(dvec3 , double, double);"
747             "dvec4  clamp(dvec4 , double, double);"
748             "dvec2  clamp(dvec2 , dvec2 , dvec2);"
749             "dvec3  clamp(dvec3 , dvec3 , dvec3);"
750             "dvec4  clamp(dvec4 , dvec4 , dvec4);"
751 
752             "double mix(double, double, double);"
753             "dvec2  mix(dvec2,  dvec2,  double);"
754             "dvec3  mix(dvec3,  dvec3,  double);"
755             "dvec4  mix(dvec4,  dvec4,  double);"
756             "dvec2  mix(dvec2,  dvec2,  dvec2);"
757             "dvec3  mix(dvec3,  dvec3,  dvec3);"
758             "dvec4  mix(dvec4,  dvec4,  dvec4);"
759             "double mix(double, double, bool);"
760             "dvec2  mix(dvec2,  dvec2,  bvec2);"
761             "dvec3  mix(dvec3,  dvec3,  bvec3);"
762             "dvec4  mix(dvec4,  dvec4,  bvec4);"
763 
764             "double step(double, double);"
765             "dvec2  step(dvec2 , dvec2);"
766             "dvec3  step(dvec3 , dvec3);"
767             "dvec4  step(dvec4 , dvec4);"
768             "dvec2  step(double, dvec2);"
769             "dvec3  step(double, dvec3);"
770             "dvec4  step(double, dvec4);"
771 
772             "double smoothstep(double, double, double);"
773             "dvec2  smoothstep(dvec2 , dvec2 , dvec2);"
774             "dvec3  smoothstep(dvec3 , dvec3 , dvec3);"
775             "dvec4  smoothstep(dvec4 , dvec4 , dvec4);"
776             "dvec2  smoothstep(double, double, dvec2);"
777             "dvec3  smoothstep(double, double, dvec3);"
778             "dvec4  smoothstep(double, double, dvec4);"
779 
780             "bool  isnan(double);"
781             "bvec2 isnan(dvec2);"
782             "bvec3 isnan(dvec3);"
783             "bvec4 isnan(dvec4);"
784 
785             "bool  isinf(double);"
786             "bvec2 isinf(dvec2);"
787             "bvec3 isinf(dvec3);"
788             "bvec4 isinf(dvec4);"
789 
790             "double length(double);"
791             "double length(dvec2);"
792             "double length(dvec3);"
793             "double length(dvec4);"
794 
795             "double distance(double, double);"
796             "double distance(dvec2 , dvec2);"
797             "double distance(dvec3 , dvec3);"
798             "double distance(dvec4 , dvec4);"
799 
800             "double dot(double, double);"
801             "double dot(dvec2 , dvec2);"
802             "double dot(dvec3 , dvec3);"
803             "double dot(dvec4 , dvec4);"
804 
805             "dvec3 cross(dvec3, dvec3);"
806 
807             "double normalize(double);"
808             "dvec2  normalize(dvec2);"
809             "dvec3  normalize(dvec3);"
810             "dvec4  normalize(dvec4);"
811 
812             "double faceforward(double, double, double);"
813             "dvec2  faceforward(dvec2,  dvec2,  dvec2);"
814             "dvec3  faceforward(dvec3,  dvec3,  dvec3);"
815             "dvec4  faceforward(dvec4,  dvec4,  dvec4);"
816 
817             "double reflect(double, double);"
818             "dvec2  reflect(dvec2 , dvec2 );"
819             "dvec3  reflect(dvec3 , dvec3 );"
820             "dvec4  reflect(dvec4 , dvec4 );"
821 
822             "double refract(double, double, double);"
823             "dvec2  refract(dvec2 , dvec2 , double);"
824             "dvec3  refract(dvec3 , dvec3 , double);"
825             "dvec4  refract(dvec4 , dvec4 , double);"
826 
827             "dmat2 matrixCompMult(dmat2, dmat2);"
828             "dmat3 matrixCompMult(dmat3, dmat3);"
829             "dmat4 matrixCompMult(dmat4, dmat4);"
830             "dmat2x3 matrixCompMult(dmat2x3, dmat2x3);"
831             "dmat2x4 matrixCompMult(dmat2x4, dmat2x4);"
832             "dmat3x2 matrixCompMult(dmat3x2, dmat3x2);"
833             "dmat3x4 matrixCompMult(dmat3x4, dmat3x4);"
834             "dmat4x2 matrixCompMult(dmat4x2, dmat4x2);"
835             "dmat4x3 matrixCompMult(dmat4x3, dmat4x3);"
836 
837             "dmat2   outerProduct(dvec2, dvec2);"
838             "dmat3   outerProduct(dvec3, dvec3);"
839             "dmat4   outerProduct(dvec4, dvec4);"
840             "dmat2x3 outerProduct(dvec3, dvec2);"
841             "dmat3x2 outerProduct(dvec2, dvec3);"
842             "dmat2x4 outerProduct(dvec4, dvec2);"
843             "dmat4x2 outerProduct(dvec2, dvec4);"
844             "dmat3x4 outerProduct(dvec4, dvec3);"
845             "dmat4x3 outerProduct(dvec3, dvec4);"
846 
847             "dmat2   transpose(dmat2);"
848             "dmat3   transpose(dmat3);"
849             "dmat4   transpose(dmat4);"
850             "dmat2x3 transpose(dmat3x2);"
851             "dmat3x2 transpose(dmat2x3);"
852             "dmat2x4 transpose(dmat4x2);"
853             "dmat4x2 transpose(dmat2x4);"
854             "dmat3x4 transpose(dmat4x3);"
855             "dmat4x3 transpose(dmat3x4);"
856 
857             "double determinant(dmat2);"
858             "double determinant(dmat3);"
859             "double determinant(dmat4);"
860 
861             "dmat2 inverse(dmat2);"
862             "dmat3 inverse(dmat3);"
863             "dmat4 inverse(dmat4);"
864 
865             "bvec2 lessThan(dvec2, dvec2);"
866             "bvec3 lessThan(dvec3, dvec3);"
867             "bvec4 lessThan(dvec4, dvec4);"
868 
869             "bvec2 lessThanEqual(dvec2, dvec2);"
870             "bvec3 lessThanEqual(dvec3, dvec3);"
871             "bvec4 lessThanEqual(dvec4, dvec4);"
872 
873             "bvec2 greaterThan(dvec2, dvec2);"
874             "bvec3 greaterThan(dvec3, dvec3);"
875             "bvec4 greaterThan(dvec4, dvec4);"
876 
877             "bvec2 greaterThanEqual(dvec2, dvec2);"
878             "bvec3 greaterThanEqual(dvec3, dvec3);"
879             "bvec4 greaterThanEqual(dvec4, dvec4);"
880 
881             "bvec2 equal(dvec2, dvec2);"
882             "bvec3 equal(dvec3, dvec3);"
883             "bvec4 equal(dvec4, dvec4);"
884 
885             "bvec2 notEqual(dvec2, dvec2);"
886             "bvec3 notEqual(dvec3, dvec3);"
887             "bvec4 notEqual(dvec4, dvec4);"
888 
889             "\n");
890     }
891 
892     if (profile == EEsProfile && version >= 310) {  // Explicit Types
893       commonBuiltins.append(
894 
895         "float64_t sqrt(float64_t);"
896         "f64vec2  sqrt(f64vec2);"
897         "f64vec3  sqrt(f64vec3);"
898         "f64vec4  sqrt(f64vec4);"
899 
900         "float64_t inversesqrt(float64_t);"
901         "f64vec2  inversesqrt(f64vec2);"
902         "f64vec3  inversesqrt(f64vec3);"
903         "f64vec4  inversesqrt(f64vec4);"
904 
905         "float64_t abs(float64_t);"
906         "f64vec2  abs(f64vec2);"
907         "f64vec3  abs(f64vec3);"
908         "f64vec4  abs(f64vec4);"
909 
910         "float64_t sign(float64_t);"
911         "f64vec2  sign(f64vec2);"
912         "f64vec3  sign(f64vec3);"
913         "f64vec4  sign(f64vec4);"
914 
915         "float64_t floor(float64_t);"
916         "f64vec2  floor(f64vec2);"
917         "f64vec3  floor(f64vec3);"
918         "f64vec4  floor(f64vec4);"
919 
920         "float64_t trunc(float64_t);"
921         "f64vec2  trunc(f64vec2);"
922         "f64vec3  trunc(f64vec3);"
923         "f64vec4  trunc(f64vec4);"
924 
925         "float64_t round(float64_t);"
926         "f64vec2  round(f64vec2);"
927         "f64vec3  round(f64vec3);"
928         "f64vec4  round(f64vec4);"
929 
930         "float64_t roundEven(float64_t);"
931         "f64vec2  roundEven(f64vec2);"
932         "f64vec3  roundEven(f64vec3);"
933         "f64vec4  roundEven(f64vec4);"
934 
935         "float64_t ceil(float64_t);"
936         "f64vec2  ceil(f64vec2);"
937         "f64vec3  ceil(f64vec3);"
938         "f64vec4  ceil(f64vec4);"
939 
940         "float64_t fract(float64_t);"
941         "f64vec2  fract(f64vec2);"
942         "f64vec3  fract(f64vec3);"
943         "f64vec4  fract(f64vec4);"
944 
945         "float64_t mod(float64_t, float64_t);"
946         "f64vec2  mod(f64vec2 , float64_t);"
947         "f64vec3  mod(f64vec3 , float64_t);"
948         "f64vec4  mod(f64vec4 , float64_t);"
949         "f64vec2  mod(f64vec2 , f64vec2);"
950         "f64vec3  mod(f64vec3 , f64vec3);"
951         "f64vec4  mod(f64vec4 , f64vec4);"
952 
953         "float64_t modf(float64_t, out float64_t);"
954         "f64vec2  modf(f64vec2,  out f64vec2);"
955         "f64vec3  modf(f64vec3,  out f64vec3);"
956         "f64vec4  modf(f64vec4,  out f64vec4);"
957 
958         "float64_t min(float64_t, float64_t);"
959         "f64vec2  min(f64vec2,  float64_t);"
960         "f64vec3  min(f64vec3,  float64_t);"
961         "f64vec4  min(f64vec4,  float64_t);"
962         "f64vec2  min(f64vec2,  f64vec2);"
963         "f64vec3  min(f64vec3,  f64vec3);"
964         "f64vec4  min(f64vec4,  f64vec4);"
965 
966         "float64_t max(float64_t, float64_t);"
967         "f64vec2  max(f64vec2 , float64_t);"
968         "f64vec3  max(f64vec3 , float64_t);"
969         "f64vec4  max(f64vec4 , float64_t);"
970         "f64vec2  max(f64vec2 , f64vec2);"
971         "f64vec3  max(f64vec3 , f64vec3);"
972         "f64vec4  max(f64vec4 , f64vec4);"
973 
974         "float64_t clamp(float64_t, float64_t, float64_t);"
975         "f64vec2  clamp(f64vec2 , float64_t, float64_t);"
976         "f64vec3  clamp(f64vec3 , float64_t, float64_t);"
977         "f64vec4  clamp(f64vec4 , float64_t, float64_t);"
978         "f64vec2  clamp(f64vec2 , f64vec2 , f64vec2);"
979         "f64vec3  clamp(f64vec3 , f64vec3 , f64vec3);"
980         "f64vec4  clamp(f64vec4 , f64vec4 , f64vec4);"
981 
982         "float64_t mix(float64_t, float64_t, float64_t);"
983         "f64vec2  mix(f64vec2,  f64vec2,  float64_t);"
984         "f64vec3  mix(f64vec3,  f64vec3,  float64_t);"
985         "f64vec4  mix(f64vec4,  f64vec4,  float64_t);"
986         "f64vec2  mix(f64vec2,  f64vec2,  f64vec2);"
987         "f64vec3  mix(f64vec3,  f64vec3,  f64vec3);"
988         "f64vec4  mix(f64vec4,  f64vec4,  f64vec4);"
989         "float64_t mix(float64_t, float64_t, bool);"
990         "f64vec2  mix(f64vec2,  f64vec2,  bvec2);"
991         "f64vec3  mix(f64vec3,  f64vec3,  bvec3);"
992         "f64vec4  mix(f64vec4,  f64vec4,  bvec4);"
993 
994         "float64_t step(float64_t, float64_t);"
995         "f64vec2  step(f64vec2 , f64vec2);"
996         "f64vec3  step(f64vec3 , f64vec3);"
997         "f64vec4  step(f64vec4 , f64vec4);"
998         "f64vec2  step(float64_t, f64vec2);"
999         "f64vec3  step(float64_t, f64vec3);"
1000         "f64vec4  step(float64_t, f64vec4);"
1001 
1002         "float64_t smoothstep(float64_t, float64_t, float64_t);"
1003         "f64vec2  smoothstep(f64vec2 , f64vec2 , f64vec2);"
1004         "f64vec3  smoothstep(f64vec3 , f64vec3 , f64vec3);"
1005         "f64vec4  smoothstep(f64vec4 , f64vec4 , f64vec4);"
1006         "f64vec2  smoothstep(float64_t, float64_t, f64vec2);"
1007         "f64vec3  smoothstep(float64_t, float64_t, f64vec3);"
1008         "f64vec4  smoothstep(float64_t, float64_t, f64vec4);"
1009 
1010         "float64_t length(float64_t);"
1011         "float64_t length(f64vec2);"
1012         "float64_t length(f64vec3);"
1013         "float64_t length(f64vec4);"
1014 
1015         "float64_t distance(float64_t, float64_t);"
1016         "float64_t distance(f64vec2 , f64vec2);"
1017         "float64_t distance(f64vec3 , f64vec3);"
1018         "float64_t distance(f64vec4 , f64vec4);"
1019 
1020         "float64_t dot(float64_t, float64_t);"
1021         "float64_t dot(f64vec2 , f64vec2);"
1022         "float64_t dot(f64vec3 , f64vec3);"
1023         "float64_t dot(f64vec4 , f64vec4);"
1024 
1025         "f64vec3 cross(f64vec3, f64vec3);"
1026 
1027         "float64_t normalize(float64_t);"
1028         "f64vec2  normalize(f64vec2);"
1029         "f64vec3  normalize(f64vec3);"
1030         "f64vec4  normalize(f64vec4);"
1031 
1032         "float64_t faceforward(float64_t, float64_t, float64_t);"
1033         "f64vec2  faceforward(f64vec2,  f64vec2,  f64vec2);"
1034         "f64vec3  faceforward(f64vec3,  f64vec3,  f64vec3);"
1035         "f64vec4  faceforward(f64vec4,  f64vec4,  f64vec4);"
1036 
1037         "float64_t reflect(float64_t, float64_t);"
1038         "f64vec2  reflect(f64vec2 , f64vec2 );"
1039         "f64vec3  reflect(f64vec3 , f64vec3 );"
1040         "f64vec4  reflect(f64vec4 , f64vec4 );"
1041 
1042         "float64_t refract(float64_t, float64_t, float64_t);"
1043         "f64vec2  refract(f64vec2 , f64vec2 , float64_t);"
1044         "f64vec3  refract(f64vec3 , f64vec3 , float64_t);"
1045         "f64vec4  refract(f64vec4 , f64vec4 , float64_t);"
1046 
1047         "f64mat2 matrixCompMult(f64mat2, f64mat2);"
1048         "f64mat3 matrixCompMult(f64mat3, f64mat3);"
1049         "f64mat4 matrixCompMult(f64mat4, f64mat4);"
1050         "f64mat2x3 matrixCompMult(f64mat2x3, f64mat2x3);"
1051         "f64mat2x4 matrixCompMult(f64mat2x4, f64mat2x4);"
1052         "f64mat3x2 matrixCompMult(f64mat3x2, f64mat3x2);"
1053         "f64mat3x4 matrixCompMult(f64mat3x4, f64mat3x4);"
1054         "f64mat4x2 matrixCompMult(f64mat4x2, f64mat4x2);"
1055         "f64mat4x3 matrixCompMult(f64mat4x3, f64mat4x3);"
1056 
1057         "f64mat2   outerProduct(f64vec2, f64vec2);"
1058         "f64mat3   outerProduct(f64vec3, f64vec3);"
1059         "f64mat4   outerProduct(f64vec4, f64vec4);"
1060         "f64mat2x3 outerProduct(f64vec3, f64vec2);"
1061         "f64mat3x2 outerProduct(f64vec2, f64vec3);"
1062         "f64mat2x4 outerProduct(f64vec4, f64vec2);"
1063         "f64mat4x2 outerProduct(f64vec2, f64vec4);"
1064         "f64mat3x4 outerProduct(f64vec4, f64vec3);"
1065         "f64mat4x3 outerProduct(f64vec3, f64vec4);"
1066 
1067         "f64mat2   transpose(f64mat2);"
1068         "f64mat3   transpose(f64mat3);"
1069         "f64mat4   transpose(f64mat4);"
1070         "f64mat2x3 transpose(f64mat3x2);"
1071         "f64mat3x2 transpose(f64mat2x3);"
1072         "f64mat2x4 transpose(f64mat4x2);"
1073         "f64mat4x2 transpose(f64mat2x4);"
1074         "f64mat3x4 transpose(f64mat4x3);"
1075         "f64mat4x3 transpose(f64mat3x4);"
1076 
1077         "float64_t determinant(f64mat2);"
1078         "float64_t determinant(f64mat3);"
1079         "float64_t determinant(f64mat4);"
1080 
1081         "f64mat2 inverse(f64mat2);"
1082         "f64mat3 inverse(f64mat3);"
1083         "f64mat4 inverse(f64mat4);"
1084 
1085         "\n");
1086     }
1087 
1088     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
1089         commonBuiltins.append(
1090 
1091             "int64_t abs(int64_t);"
1092             "i64vec2 abs(i64vec2);"
1093             "i64vec3 abs(i64vec3);"
1094             "i64vec4 abs(i64vec4);"
1095 
1096             "int64_t sign(int64_t);"
1097             "i64vec2 sign(i64vec2);"
1098             "i64vec3 sign(i64vec3);"
1099             "i64vec4 sign(i64vec4);"
1100 
1101             "int64_t  min(int64_t,  int64_t);"
1102             "i64vec2  min(i64vec2,  int64_t);"
1103             "i64vec3  min(i64vec3,  int64_t);"
1104             "i64vec4  min(i64vec4,  int64_t);"
1105             "i64vec2  min(i64vec2,  i64vec2);"
1106             "i64vec3  min(i64vec3,  i64vec3);"
1107             "i64vec4  min(i64vec4,  i64vec4);"
1108             "uint64_t min(uint64_t, uint64_t);"
1109             "u64vec2  min(u64vec2,  uint64_t);"
1110             "u64vec3  min(u64vec3,  uint64_t);"
1111             "u64vec4  min(u64vec4,  uint64_t);"
1112             "u64vec2  min(u64vec2,  u64vec2);"
1113             "u64vec3  min(u64vec3,  u64vec3);"
1114             "u64vec4  min(u64vec4,  u64vec4);"
1115 
1116             "int64_t  max(int64_t,  int64_t);"
1117             "i64vec2  max(i64vec2,  int64_t);"
1118             "i64vec3  max(i64vec3,  int64_t);"
1119             "i64vec4  max(i64vec4,  int64_t);"
1120             "i64vec2  max(i64vec2,  i64vec2);"
1121             "i64vec3  max(i64vec3,  i64vec3);"
1122             "i64vec4  max(i64vec4,  i64vec4);"
1123             "uint64_t max(uint64_t, uint64_t);"
1124             "u64vec2  max(u64vec2,  uint64_t);"
1125             "u64vec3  max(u64vec3,  uint64_t);"
1126             "u64vec4  max(u64vec4,  uint64_t);"
1127             "u64vec2  max(u64vec2,  u64vec2);"
1128             "u64vec3  max(u64vec3,  u64vec3);"
1129             "u64vec4  max(u64vec4,  u64vec4);"
1130 
1131             "int64_t  clamp(int64_t,  int64_t,  int64_t);"
1132             "i64vec2  clamp(i64vec2,  int64_t,  int64_t);"
1133             "i64vec3  clamp(i64vec3,  int64_t,  int64_t);"
1134             "i64vec4  clamp(i64vec4,  int64_t,  int64_t);"
1135             "i64vec2  clamp(i64vec2,  i64vec2,  i64vec2);"
1136             "i64vec3  clamp(i64vec3,  i64vec3,  i64vec3);"
1137             "i64vec4  clamp(i64vec4,  i64vec4,  i64vec4);"
1138             "uint64_t clamp(uint64_t, uint64_t, uint64_t);"
1139             "u64vec2  clamp(u64vec2,  uint64_t, uint64_t);"
1140             "u64vec3  clamp(u64vec3,  uint64_t, uint64_t);"
1141             "u64vec4  clamp(u64vec4,  uint64_t, uint64_t);"
1142             "u64vec2  clamp(u64vec2,  u64vec2,  u64vec2);"
1143             "u64vec3  clamp(u64vec3,  u64vec3,  u64vec3);"
1144             "u64vec4  clamp(u64vec4,  u64vec4,  u64vec4);"
1145 
1146             "int64_t  mix(int64_t,  int64_t,  bool);"
1147             "i64vec2  mix(i64vec2,  i64vec2,  bvec2);"
1148             "i64vec3  mix(i64vec3,  i64vec3,  bvec3);"
1149             "i64vec4  mix(i64vec4,  i64vec4,  bvec4);"
1150             "uint64_t mix(uint64_t, uint64_t, bool);"
1151             "u64vec2  mix(u64vec2,  u64vec2,  bvec2);"
1152             "u64vec3  mix(u64vec3,  u64vec3,  bvec3);"
1153             "u64vec4  mix(u64vec4,  u64vec4,  bvec4);"
1154 
1155             "int64_t doubleBitsToInt64(float64_t);"
1156             "i64vec2 doubleBitsToInt64(f64vec2);"
1157             "i64vec3 doubleBitsToInt64(f64vec3);"
1158             "i64vec4 doubleBitsToInt64(f64vec4);"
1159 
1160             "uint64_t doubleBitsToUint64(float64_t);"
1161             "u64vec2  doubleBitsToUint64(f64vec2);"
1162             "u64vec3  doubleBitsToUint64(f64vec3);"
1163             "u64vec4  doubleBitsToUint64(f64vec4);"
1164 
1165             "float64_t int64BitsToDouble(int64_t);"
1166             "f64vec2  int64BitsToDouble(i64vec2);"
1167             "f64vec3  int64BitsToDouble(i64vec3);"
1168             "f64vec4  int64BitsToDouble(i64vec4);"
1169 
1170             "float64_t uint64BitsToDouble(uint64_t);"
1171             "f64vec2  uint64BitsToDouble(u64vec2);"
1172             "f64vec3  uint64BitsToDouble(u64vec3);"
1173             "f64vec4  uint64BitsToDouble(u64vec4);"
1174 
1175             "int64_t  packInt2x32(ivec2);"
1176             "uint64_t packUint2x32(uvec2);"
1177             "ivec2    unpackInt2x32(int64_t);"
1178             "uvec2    unpackUint2x32(uint64_t);"
1179 
1180             "bvec2 lessThan(i64vec2, i64vec2);"
1181             "bvec3 lessThan(i64vec3, i64vec3);"
1182             "bvec4 lessThan(i64vec4, i64vec4);"
1183             "bvec2 lessThan(u64vec2, u64vec2);"
1184             "bvec3 lessThan(u64vec3, u64vec3);"
1185             "bvec4 lessThan(u64vec4, u64vec4);"
1186 
1187             "bvec2 lessThanEqual(i64vec2, i64vec2);"
1188             "bvec3 lessThanEqual(i64vec3, i64vec3);"
1189             "bvec4 lessThanEqual(i64vec4, i64vec4);"
1190             "bvec2 lessThanEqual(u64vec2, u64vec2);"
1191             "bvec3 lessThanEqual(u64vec3, u64vec3);"
1192             "bvec4 lessThanEqual(u64vec4, u64vec4);"
1193 
1194             "bvec2 greaterThan(i64vec2, i64vec2);"
1195             "bvec3 greaterThan(i64vec3, i64vec3);"
1196             "bvec4 greaterThan(i64vec4, i64vec4);"
1197             "bvec2 greaterThan(u64vec2, u64vec2);"
1198             "bvec3 greaterThan(u64vec3, u64vec3);"
1199             "bvec4 greaterThan(u64vec4, u64vec4);"
1200 
1201             "bvec2 greaterThanEqual(i64vec2, i64vec2);"
1202             "bvec3 greaterThanEqual(i64vec3, i64vec3);"
1203             "bvec4 greaterThanEqual(i64vec4, i64vec4);"
1204             "bvec2 greaterThanEqual(u64vec2, u64vec2);"
1205             "bvec3 greaterThanEqual(u64vec3, u64vec3);"
1206             "bvec4 greaterThanEqual(u64vec4, u64vec4);"
1207 
1208             "bvec2 equal(i64vec2, i64vec2);"
1209             "bvec3 equal(i64vec3, i64vec3);"
1210             "bvec4 equal(i64vec4, i64vec4);"
1211             "bvec2 equal(u64vec2, u64vec2);"
1212             "bvec3 equal(u64vec3, u64vec3);"
1213             "bvec4 equal(u64vec4, u64vec4);"
1214 
1215             "bvec2 notEqual(i64vec2, i64vec2);"
1216             "bvec3 notEqual(i64vec3, i64vec3);"
1217             "bvec4 notEqual(i64vec4, i64vec4);"
1218             "bvec2 notEqual(u64vec2, u64vec2);"
1219             "bvec3 notEqual(u64vec3, u64vec3);"
1220             "bvec4 notEqual(u64vec4, u64vec4);"
1221 
1222             "int64_t bitCount(int64_t);"
1223             "i64vec2 bitCount(i64vec2);"
1224             "i64vec3 bitCount(i64vec3);"
1225             "i64vec4 bitCount(i64vec4);"
1226 
1227             "int64_t bitCount(uint64_t);"
1228             "i64vec2 bitCount(u64vec2);"
1229             "i64vec3 bitCount(u64vec3);"
1230             "i64vec4 bitCount(u64vec4);"
1231 
1232             "int64_t findLSB(int64_t);"
1233             "i64vec2 findLSB(i64vec2);"
1234             "i64vec3 findLSB(i64vec3);"
1235             "i64vec4 findLSB(i64vec4);"
1236 
1237             "int64_t findLSB(uint64_t);"
1238             "i64vec2 findLSB(u64vec2);"
1239             "i64vec3 findLSB(u64vec3);"
1240             "i64vec4 findLSB(u64vec4);"
1241 
1242             "int64_t findMSB(int64_t);"
1243             "i64vec2 findMSB(i64vec2);"
1244             "i64vec3 findMSB(i64vec3);"
1245             "i64vec4 findMSB(i64vec4);"
1246 
1247             "int64_t findMSB(uint64_t);"
1248             "i64vec2 findMSB(u64vec2);"
1249             "i64vec3 findMSB(u64vec3);"
1250             "i64vec4 findMSB(u64vec4);"
1251 
1252             "\n"
1253         );
1254     }
1255 
1256     // GL_AMD_shader_trinary_minmax
1257     if (profile != EEsProfile && version >= 430) {
1258         commonBuiltins.append(
1259             "float min3(float, float, float);"
1260             "vec2  min3(vec2,  vec2,  vec2);"
1261             "vec3  min3(vec3,  vec3,  vec3);"
1262             "vec4  min3(vec4,  vec4,  vec4);"
1263 
1264             "int   min3(int,   int,   int);"
1265             "ivec2 min3(ivec2, ivec2, ivec2);"
1266             "ivec3 min3(ivec3, ivec3, ivec3);"
1267             "ivec4 min3(ivec4, ivec4, ivec4);"
1268 
1269             "uint  min3(uint,  uint,  uint);"
1270             "uvec2 min3(uvec2, uvec2, uvec2);"
1271             "uvec3 min3(uvec3, uvec3, uvec3);"
1272             "uvec4 min3(uvec4, uvec4, uvec4);"
1273 
1274             "float max3(float, float, float);"
1275             "vec2  max3(vec2,  vec2,  vec2);"
1276             "vec3  max3(vec3,  vec3,  vec3);"
1277             "vec4  max3(vec4,  vec4,  vec4);"
1278 
1279             "int   max3(int,   int,   int);"
1280             "ivec2 max3(ivec2, ivec2, ivec2);"
1281             "ivec3 max3(ivec3, ivec3, ivec3);"
1282             "ivec4 max3(ivec4, ivec4, ivec4);"
1283 
1284             "uint  max3(uint,  uint,  uint);"
1285             "uvec2 max3(uvec2, uvec2, uvec2);"
1286             "uvec3 max3(uvec3, uvec3, uvec3);"
1287             "uvec4 max3(uvec4, uvec4, uvec4);"
1288 
1289             "float mid3(float, float, float);"
1290             "vec2  mid3(vec2,  vec2,  vec2);"
1291             "vec3  mid3(vec3,  vec3,  vec3);"
1292             "vec4  mid3(vec4,  vec4,  vec4);"
1293 
1294             "int   mid3(int,   int,   int);"
1295             "ivec2 mid3(ivec2, ivec2, ivec2);"
1296             "ivec3 mid3(ivec3, ivec3, ivec3);"
1297             "ivec4 mid3(ivec4, ivec4, ivec4);"
1298 
1299             "uint  mid3(uint,  uint,  uint);"
1300             "uvec2 mid3(uvec2, uvec2, uvec2);"
1301             "uvec3 mid3(uvec3, uvec3, uvec3);"
1302             "uvec4 mid3(uvec4, uvec4, uvec4);"
1303 
1304             "float16_t min3(float16_t, float16_t, float16_t);"
1305             "f16vec2   min3(f16vec2,   f16vec2,   f16vec2);"
1306             "f16vec3   min3(f16vec3,   f16vec3,   f16vec3);"
1307             "f16vec4   min3(f16vec4,   f16vec4,   f16vec4);"
1308 
1309             "float16_t max3(float16_t, float16_t, float16_t);"
1310             "f16vec2   max3(f16vec2,   f16vec2,   f16vec2);"
1311             "f16vec3   max3(f16vec3,   f16vec3,   f16vec3);"
1312             "f16vec4   max3(f16vec4,   f16vec4,   f16vec4);"
1313 
1314             "float16_t mid3(float16_t, float16_t, float16_t);"
1315             "f16vec2   mid3(f16vec2,   f16vec2,   f16vec2);"
1316             "f16vec3   mid3(f16vec3,   f16vec3,   f16vec3);"
1317             "f16vec4   mid3(f16vec4,   f16vec4,   f16vec4);"
1318 
1319             "int16_t   min3(int16_t,   int16_t,   int16_t);"
1320             "i16vec2   min3(i16vec2,   i16vec2,   i16vec2);"
1321             "i16vec3   min3(i16vec3,   i16vec3,   i16vec3);"
1322             "i16vec4   min3(i16vec4,   i16vec4,   i16vec4);"
1323 
1324             "int16_t   max3(int16_t,   int16_t,   int16_t);"
1325             "i16vec2   max3(i16vec2,   i16vec2,   i16vec2);"
1326             "i16vec3   max3(i16vec3,   i16vec3,   i16vec3);"
1327             "i16vec4   max3(i16vec4,   i16vec4,   i16vec4);"
1328 
1329             "int16_t   mid3(int16_t,   int16_t,   int16_t);"
1330             "i16vec2   mid3(i16vec2,   i16vec2,   i16vec2);"
1331             "i16vec3   mid3(i16vec3,   i16vec3,   i16vec3);"
1332             "i16vec4   mid3(i16vec4,   i16vec4,   i16vec4);"
1333 
1334             "uint16_t  min3(uint16_t,  uint16_t,  uint16_t);"
1335             "u16vec2   min3(u16vec2,   u16vec2,   u16vec2);"
1336             "u16vec3   min3(u16vec3,   u16vec3,   u16vec3);"
1337             "u16vec4   min3(u16vec4,   u16vec4,   u16vec4);"
1338 
1339             "uint16_t  max3(uint16_t,  uint16_t,  uint16_t);"
1340             "u16vec2   max3(u16vec2,   u16vec2,   u16vec2);"
1341             "u16vec3   max3(u16vec3,   u16vec3,   u16vec3);"
1342             "u16vec4   max3(u16vec4,   u16vec4,   u16vec4);"
1343 
1344             "uint16_t  mid3(uint16_t,  uint16_t,  uint16_t);"
1345             "u16vec2   mid3(u16vec2,   u16vec2,   u16vec2);"
1346             "u16vec3   mid3(u16vec3,   u16vec3,   u16vec3);"
1347             "u16vec4   mid3(u16vec4,   u16vec4,   u16vec4);"
1348 
1349             "\n"
1350         );
1351     }
1352 
1353     if ((profile == EEsProfile && version >= 310) ||
1354         (profile != EEsProfile && version >= 430)) {
1355         commonBuiltins.append(
1356             "uint atomicAdd(coherent volatile inout uint, uint, int, int, int);"
1357             " int atomicAdd(coherent volatile inout  int,  int, int, int, int);"
1358 
1359             "uint atomicMin(coherent volatile inout uint, uint, int, int, int);"
1360             " int atomicMin(coherent volatile inout  int,  int, int, int, int);"
1361 
1362             "uint atomicMax(coherent volatile inout uint, uint, int, int, int);"
1363             " int atomicMax(coherent volatile inout  int,  int, int, int, int);"
1364 
1365             "uint atomicAnd(coherent volatile inout uint, uint, int, int, int);"
1366             " int atomicAnd(coherent volatile inout  int,  int, int, int, int);"
1367 
1368             "uint atomicOr (coherent volatile inout uint, uint, int, int, int);"
1369             " int atomicOr (coherent volatile inout  int,  int, int, int, int);"
1370 
1371             "uint atomicXor(coherent volatile inout uint, uint, int, int, int);"
1372             " int atomicXor(coherent volatile inout  int,  int, int, int, int);"
1373 
1374             "uint atomicExchange(coherent volatile inout uint, uint, int, int, int);"
1375             " int atomicExchange(coherent volatile inout  int,  int, int, int, int);"
1376 
1377             "uint atomicCompSwap(coherent volatile inout uint, uint, uint, int, int, int, int, int);"
1378             " int atomicCompSwap(coherent volatile inout  int,  int,  int, int, int, int, int, int);"
1379 
1380             "uint atomicLoad(coherent volatile in uint, int, int, int);"
1381             " int atomicLoad(coherent volatile in  int, int, int, int);"
1382 
1383             "void atomicStore(coherent volatile out uint, uint, int, int, int);"
1384             "void atomicStore(coherent volatile out  int,  int, int, int, int);"
1385 
1386             "\n");
1387     }
1388 
1389     if (profile != EEsProfile && version >= 440) {
1390         commonBuiltins.append(
1391             "uint64_t atomicMin(coherent volatile inout uint64_t, uint64_t);"
1392             " int64_t atomicMin(coherent volatile inout  int64_t,  int64_t);"
1393             "uint64_t atomicMin(coherent volatile inout uint64_t, uint64_t, int, int, int);"
1394             " int64_t atomicMin(coherent volatile inout  int64_t,  int64_t, int, int, int);"
1395             "float16_t atomicMin(coherent volatile inout float16_t, float16_t);"
1396             "float16_t atomicMin(coherent volatile inout float16_t, float16_t, int, int, int);"
1397             "   float atomicMin(coherent volatile inout float, float);"
1398             "   float atomicMin(coherent volatile inout float, float, int, int, int);"
1399             "  double atomicMin(coherent volatile inout double, double);"
1400             "  double atomicMin(coherent volatile inout double, double, int, int, int);"
1401 
1402             "uint64_t atomicMax(coherent volatile inout uint64_t, uint64_t);"
1403             " int64_t atomicMax(coherent volatile inout  int64_t,  int64_t);"
1404             "uint64_t atomicMax(coherent volatile inout uint64_t, uint64_t, int, int, int);"
1405             " int64_t atomicMax(coherent volatile inout  int64_t,  int64_t, int, int, int);"
1406             "float16_t atomicMax(coherent volatile inout float16_t, float16_t);"
1407             "float16_t atomicMax(coherent volatile inout float16_t, float16_t, int, int, int);"
1408             "   float atomicMax(coherent volatile inout float, float);"
1409             "   float atomicMax(coherent volatile inout float, float, int, int, int);"
1410             "  double atomicMax(coherent volatile inout double, double);"
1411             "  double atomicMax(coherent volatile inout double, double, int, int, int);"
1412 
1413             "uint64_t atomicAnd(coherent volatile inout uint64_t, uint64_t);"
1414             " int64_t atomicAnd(coherent volatile inout  int64_t,  int64_t);"
1415             "uint64_t atomicAnd(coherent volatile inout uint64_t, uint64_t, int, int, int);"
1416             " int64_t atomicAnd(coherent volatile inout  int64_t,  int64_t, int, int, int);"
1417 
1418             "uint64_t atomicOr (coherent volatile inout uint64_t, uint64_t);"
1419             " int64_t atomicOr (coherent volatile inout  int64_t,  int64_t);"
1420             "uint64_t atomicOr (coherent volatile inout uint64_t, uint64_t, int, int, int);"
1421             " int64_t atomicOr (coherent volatile inout  int64_t,  int64_t, int, int, int);"
1422 
1423             "uint64_t atomicXor(coherent volatile inout uint64_t, uint64_t);"
1424             " int64_t atomicXor(coherent volatile inout  int64_t,  int64_t);"
1425             "uint64_t atomicXor(coherent volatile inout uint64_t, uint64_t, int, int, int);"
1426             " int64_t atomicXor(coherent volatile inout  int64_t,  int64_t, int, int, int);"
1427 
1428             "uint64_t atomicAdd(coherent volatile inout uint64_t, uint64_t);"
1429             " int64_t atomicAdd(coherent volatile inout  int64_t,  int64_t);"
1430             "uint64_t atomicAdd(coherent volatile inout uint64_t, uint64_t, int, int, int);"
1431             " int64_t atomicAdd(coherent volatile inout  int64_t,  int64_t, int, int, int);"
1432             "float16_t atomicAdd(coherent volatile inout float16_t, float16_t);"
1433             "float16_t atomicAdd(coherent volatile inout float16_t, float16_t, int, int, int);"
1434             "   float atomicAdd(coherent volatile inout float, float);"
1435             "   float atomicAdd(coherent volatile inout float, float, int, int, int);"
1436             "  double atomicAdd(coherent volatile inout double, double);"
1437             "  double atomicAdd(coherent volatile inout double, double, int, int, int);"
1438 
1439             "uint64_t atomicExchange(coherent volatile inout uint64_t, uint64_t);"
1440             " int64_t atomicExchange(coherent volatile inout  int64_t,  int64_t);"
1441             "uint64_t atomicExchange(coherent volatile inout uint64_t, uint64_t, int, int, int);"
1442             " int64_t atomicExchange(coherent volatile inout  int64_t,  int64_t, int, int, int);"
1443             "float16_t atomicExchange(coherent volatile inout float16_t, float16_t);"
1444             "float16_t atomicExchange(coherent volatile inout float16_t, float16_t, int, int, int);"
1445             "   float atomicExchange(coherent volatile inout float, float);"
1446             "   float atomicExchange(coherent volatile inout float, float, int, int, int);"
1447             "  double atomicExchange(coherent volatile inout double, double);"
1448             "  double atomicExchange(coherent volatile inout double, double, int, int, int);"
1449 
1450             "uint64_t atomicCompSwap(coherent volatile inout uint64_t, uint64_t, uint64_t);"
1451             " int64_t atomicCompSwap(coherent volatile inout  int64_t,  int64_t,  int64_t);"
1452             "uint64_t atomicCompSwap(coherent volatile inout uint64_t, uint64_t, uint64_t, int, int, int, int, int);"
1453             " int64_t atomicCompSwap(coherent volatile inout  int64_t,  int64_t,  int64_t, int, int, int, int, int);"
1454 
1455             "uint64_t atomicLoad(coherent volatile in uint64_t, int, int, int);"
1456             " int64_t atomicLoad(coherent volatile in  int64_t, int, int, int);"
1457             "float16_t atomicLoad(coherent volatile in float16_t, int, int, int);"
1458             "   float atomicLoad(coherent volatile in float, int, int, int);"
1459             "  double atomicLoad(coherent volatile in double, int, int, int);"
1460 
1461             "void atomicStore(coherent volatile out uint64_t, uint64_t, int, int, int);"
1462             "void atomicStore(coherent volatile out  int64_t,  int64_t, int, int, int);"
1463             "void atomicStore(coherent volatile out float16_t, float16_t, int, int, int);"
1464             "void atomicStore(coherent volatile out float, float, int, int, int);"
1465             "void atomicStore(coherent volatile out double, double, int, int, int);"
1466             "\n");
1467     }
1468 
1469     // NV_shader_atomic_fp16_vector
1470     if (profile != EEsProfile && version >= 430) {
1471         commonBuiltins.append(
1472             "f16vec2 atomicAdd(coherent volatile inout f16vec2, f16vec2);"
1473             "f16vec4 atomicAdd(coherent volatile inout f16vec4, f16vec4);"
1474             "f16vec2 atomicMin(coherent volatile inout f16vec2, f16vec2);"
1475             "f16vec4 atomicMin(coherent volatile inout f16vec4, f16vec4);"
1476             "f16vec2 atomicMax(coherent volatile inout f16vec2, f16vec2);"
1477             "f16vec4 atomicMax(coherent volatile inout f16vec4, f16vec4);"
1478             "f16vec2 atomicExchange(coherent volatile inout f16vec2, f16vec2);"
1479             "f16vec4 atomicExchange(coherent volatile inout f16vec4, f16vec4);"
1480             "\n");
1481     }
1482 
1483     if ((profile == EEsProfile && version >= 300) ||
1484         (profile != EEsProfile && version >= 150)) { // GL_ARB_shader_bit_encoding
1485         commonBuiltins.append(
1486             "int   floatBitsToInt(highp float value);"
1487             "ivec2 floatBitsToInt(highp vec2  value);"
1488             "ivec3 floatBitsToInt(highp vec3  value);"
1489             "ivec4 floatBitsToInt(highp vec4  value);"
1490 
1491             "uint  floatBitsToUint(highp float value);"
1492             "uvec2 floatBitsToUint(highp vec2  value);"
1493             "uvec3 floatBitsToUint(highp vec3  value);"
1494             "uvec4 floatBitsToUint(highp vec4  value);"
1495 
1496             "float intBitsToFloat(highp int   value);"
1497             "vec2  intBitsToFloat(highp ivec2 value);"
1498             "vec3  intBitsToFloat(highp ivec3 value);"
1499             "vec4  intBitsToFloat(highp ivec4 value);"
1500 
1501             "float uintBitsToFloat(highp uint  value);"
1502             "vec2  uintBitsToFloat(highp uvec2 value);"
1503             "vec3  uintBitsToFloat(highp uvec3 value);"
1504             "vec4  uintBitsToFloat(highp uvec4 value);"
1505 
1506             "\n");
1507     }
1508 
1509     if ((profile != EEsProfile && version >= 400) ||
1510         (profile == EEsProfile && version >= 310)) {    // GL_OES_gpu_shader5
1511 
1512         commonBuiltins.append(
1513             "float  fma(float,  float,  float );"
1514             "vec2   fma(vec2,   vec2,   vec2  );"
1515             "vec3   fma(vec3,   vec3,   vec3  );"
1516             "vec4   fma(vec4,   vec4,   vec4  );"
1517             "\n");
1518     }
1519 
1520     if (profile != EEsProfile && version >= 150) {  // ARB_gpu_shader_fp64
1521             commonBuiltins.append(
1522                 "double fma(double, double, double);"
1523                 "dvec2  fma(dvec2,  dvec2,  dvec2 );"
1524                 "dvec3  fma(dvec3,  dvec3,  dvec3 );"
1525                 "dvec4  fma(dvec4,  dvec4,  dvec4 );"
1526                 "\n");
1527     }
1528 
1529     if (profile == EEsProfile && version >= 310) {  // ARB_gpu_shader_fp64
1530             commonBuiltins.append(
1531                 "float64_t fma(float64_t, float64_t, float64_t);"
1532                 "f64vec2  fma(f64vec2,  f64vec2,  f64vec2 );"
1533                 "f64vec3  fma(f64vec3,  f64vec3,  f64vec3 );"
1534                 "f64vec4  fma(f64vec4,  f64vec4,  f64vec4 );"
1535                 "\n");
1536     }
1537 
1538     if ((profile == EEsProfile && version >= 310) ||
1539         (profile != EEsProfile && version >= 400)) {
1540         commonBuiltins.append(
1541             "float frexp(highp float, out highp int);"
1542             "vec2  frexp(highp vec2,  out highp ivec2);"
1543             "vec3  frexp(highp vec3,  out highp ivec3);"
1544             "vec4  frexp(highp vec4,  out highp ivec4);"
1545 
1546             "float ldexp(highp float, highp int);"
1547             "vec2  ldexp(highp vec2,  highp ivec2);"
1548             "vec3  ldexp(highp vec3,  highp ivec3);"
1549             "vec4  ldexp(highp vec4,  highp ivec4);"
1550 
1551             "\n");
1552     }
1553 
1554     if (profile != EEsProfile && version >= 150) { // ARB_gpu_shader_fp64
1555         commonBuiltins.append(
1556             "double frexp(double, out int);"
1557             "dvec2  frexp( dvec2, out ivec2);"
1558             "dvec3  frexp( dvec3, out ivec3);"
1559             "dvec4  frexp( dvec4, out ivec4);"
1560 
1561             "double ldexp(double, int);"
1562             "dvec2  ldexp( dvec2, ivec2);"
1563             "dvec3  ldexp( dvec3, ivec3);"
1564             "dvec4  ldexp( dvec4, ivec4);"
1565 
1566             "double packDouble2x32(uvec2);"
1567             "uvec2 unpackDouble2x32(double);"
1568 
1569             "\n");
1570     }
1571 
1572     if (profile == EEsProfile && version >= 310) { // ARB_gpu_shader_fp64
1573         commonBuiltins.append(
1574             "float64_t frexp(float64_t, out int);"
1575             "f64vec2  frexp( f64vec2, out ivec2);"
1576             "f64vec3  frexp( f64vec3, out ivec3);"
1577             "f64vec4  frexp( f64vec4, out ivec4);"
1578 
1579             "float64_t ldexp(float64_t, int);"
1580             "f64vec2  ldexp( f64vec2, ivec2);"
1581             "f64vec3  ldexp( f64vec3, ivec3);"
1582             "f64vec4  ldexp( f64vec4, ivec4);"
1583 
1584             "\n");
1585     }
1586 
1587     if ((profile == EEsProfile && version >= 300) ||
1588         (profile != EEsProfile && version >= 150)) {
1589         commonBuiltins.append(
1590             "highp uint packUnorm2x16(vec2);"
1591                   "vec2 unpackUnorm2x16(highp uint);"
1592             "\n");
1593     }
1594 
1595     if ((profile == EEsProfile && version >= 300) ||
1596         (profile != EEsProfile && version >= 150)) {
1597         commonBuiltins.append(
1598             "highp uint packSnorm2x16(vec2);"
1599             "      vec2 unpackSnorm2x16(highp uint);"
1600             "highp uint packHalf2x16(vec2);"
1601             "\n");
1602     }
1603 
1604     if (profile == EEsProfile && version >= 300) {
1605         commonBuiltins.append(
1606             "mediump vec2 unpackHalf2x16(highp uint);"
1607             "\n");
1608     } else if (profile != EEsProfile && version >= 150) {
1609         commonBuiltins.append(
1610             "        vec2 unpackHalf2x16(highp uint);"
1611             "\n");
1612     }
1613 
1614     if ((profile == EEsProfile && version >= 310) ||
1615         (profile != EEsProfile && version >= 150)) {
1616         commonBuiltins.append(
1617             "highp uint packSnorm4x8(vec4);"
1618             "highp uint packUnorm4x8(vec4);"
1619             "\n");
1620     }
1621 
1622     if (profile == EEsProfile && version >= 310) {
1623         commonBuiltins.append(
1624             "mediump vec4 unpackSnorm4x8(highp uint);"
1625             "mediump vec4 unpackUnorm4x8(highp uint);"
1626             "\n");
1627     } else if (profile != EEsProfile && version >= 150) {
1628         commonBuiltins.append(
1629                     "vec4 unpackSnorm4x8(highp uint);"
1630                     "vec4 unpackUnorm4x8(highp uint);"
1631             "\n");
1632     }
1633 
1634     //
1635     // Matrix Functions.
1636     //
1637     commonBuiltins.append(
1638         "mat2 matrixCompMult(mat2 x, mat2 y);"
1639         "mat3 matrixCompMult(mat3 x, mat3 y);"
1640         "mat4 matrixCompMult(mat4 x, mat4 y);"
1641 
1642         "\n");
1643 
1644     // 120 is correct for both ES and desktop
1645     if (version >= 120) {
1646         commonBuiltins.append(
1647             "mat2   outerProduct(vec2 c, vec2 r);"
1648             "mat3   outerProduct(vec3 c, vec3 r);"
1649             "mat4   outerProduct(vec4 c, vec4 r);"
1650             "mat2x3 outerProduct(vec3 c, vec2 r);"
1651             "mat3x2 outerProduct(vec2 c, vec3 r);"
1652             "mat2x4 outerProduct(vec4 c, vec2 r);"
1653             "mat4x2 outerProduct(vec2 c, vec4 r);"
1654             "mat3x4 outerProduct(vec4 c, vec3 r);"
1655             "mat4x3 outerProduct(vec3 c, vec4 r);"
1656 
1657             "mat2   transpose(mat2   m);"
1658             "mat3   transpose(mat3   m);"
1659             "mat4   transpose(mat4   m);"
1660             "mat2x3 transpose(mat3x2 m);"
1661             "mat3x2 transpose(mat2x3 m);"
1662             "mat2x4 transpose(mat4x2 m);"
1663             "mat4x2 transpose(mat2x4 m);"
1664             "mat3x4 transpose(mat4x3 m);"
1665             "mat4x3 transpose(mat3x4 m);"
1666 
1667             "mat2x3 matrixCompMult(mat2x3, mat2x3);"
1668             "mat2x4 matrixCompMult(mat2x4, mat2x4);"
1669             "mat3x2 matrixCompMult(mat3x2, mat3x2);"
1670             "mat3x4 matrixCompMult(mat3x4, mat3x4);"
1671             "mat4x2 matrixCompMult(mat4x2, mat4x2);"
1672             "mat4x3 matrixCompMult(mat4x3, mat4x3);"
1673 
1674             "\n");
1675 
1676         // 150 is correct for both ES and desktop
1677         if (version >= 150) {
1678             commonBuiltins.append(
1679                 "float determinant(mat2 m);"
1680                 "float determinant(mat3 m);"
1681                 "float determinant(mat4 m);"
1682 
1683                 "mat2 inverse(mat2 m);"
1684                 "mat3 inverse(mat3 m);"
1685                 "mat4 inverse(mat4 m);"
1686 
1687                 "\n");
1688         }
1689     }
1690 
1691     //
1692     // Original-style texture functions existing in all stages.
1693     // (Per-stage functions below.)
1694     //
1695     if ((profile == EEsProfile && version == 100) ||
1696          profile == ECompatibilityProfile ||
1697         (profile == ECoreProfile && version < 420) ||
1698          profile == ENoProfile) {
1699         if (spvVersion.spv == 0) {
1700             commonBuiltins.append(
1701                 "vec4 texture2D(sampler2D, vec2);"
1702 
1703                 "vec4 texture2DProj(sampler2D, vec3);"
1704                 "vec4 texture2DProj(sampler2D, vec4);"
1705 
1706                 "vec4 texture3D(sampler3D, vec3);"     // OES_texture_3D, but caught by keyword check
1707                 "vec4 texture3DProj(sampler3D, vec4);" // OES_texture_3D, but caught by keyword check
1708 
1709                 "vec4 textureCube(samplerCube, vec3);"
1710 
1711                 "\n");
1712         }
1713     }
1714 
1715     if ( profile == ECompatibilityProfile ||
1716         (profile == ECoreProfile && version < 420) ||
1717          profile == ENoProfile) {
1718         if (spvVersion.spv == 0) {
1719             commonBuiltins.append(
1720                 "vec4 texture1D(sampler1D, float);"
1721 
1722                 "vec4 texture1DProj(sampler1D, vec2);"
1723                 "vec4 texture1DProj(sampler1D, vec4);"
1724 
1725                 "vec4 shadow1D(sampler1DShadow, vec3);"
1726                 "vec4 shadow2D(sampler2DShadow, vec3);"
1727                 "vec4 shadow1DProj(sampler1DShadow, vec4);"
1728                 "vec4 shadow2DProj(sampler2DShadow, vec4);"
1729 
1730                 "vec4 texture2DRect(sampler2DRect, vec2);"          // GL_ARB_texture_rectangle, caught by keyword check
1731                 "vec4 texture2DRectProj(sampler2DRect, vec3);"      // GL_ARB_texture_rectangle, caught by keyword check
1732                 "vec4 texture2DRectProj(sampler2DRect, vec4);"      // GL_ARB_texture_rectangle, caught by keyword check
1733                 "vec4 shadow2DRect(sampler2DRectShadow, vec3);"     // GL_ARB_texture_rectangle, caught by keyword check
1734                 "vec4 shadow2DRectProj(sampler2DRectShadow, vec4);" // GL_ARB_texture_rectangle, caught by keyword check
1735 
1736                 "vec4 texture1DArray(sampler1DArray, vec2);"      // GL_EXT_texture_array
1737                 "vec4 texture2DArray(sampler2DArray, vec3);"      // GL_EXT_texture_array
1738                 "vec4 shadow1DArray(sampler1DArrayShadow, vec3);" // GL_EXT_texture_array
1739                 "vec4 shadow2DArray(sampler2DArrayShadow, vec4);" // GL_EXT_texture_array
1740                 "vec4 texture1DArray(sampler1DArray, vec2, float);"                // GL_EXT_texture_array
1741                 "vec4 texture2DArray(sampler2DArray, vec3, float);"                // GL_EXT_texture_array
1742                 "vec4 shadow1DArray(sampler1DArrayShadow, vec3, float);"           // GL_EXT_texture_array
1743                 "vec4 texture1DArrayLod(sampler1DArray, vec2, float);"      // GL_EXT_texture_array
1744                 "vec4 texture2DArrayLod(sampler2DArray, vec3, float);"      // GL_EXT_texture_array
1745                 "vec4 shadow1DArrayLod(sampler1DArrayShadow, vec3, float);" // GL_EXT_texture_array
1746                 "\n");
1747         }
1748     }
1749 
1750     if (profile == EEsProfile) {
1751         if (spvVersion.spv == 0) {
1752             if (version < 300) {
1753                 commonBuiltins.append(
1754                     "vec4 texture2D(samplerExternalOES, vec2 coord);" // GL_OES_EGL_image_external
1755                     "vec4 texture2DProj(samplerExternalOES, vec3);"   // GL_OES_EGL_image_external
1756                     "vec4 texture2DProj(samplerExternalOES, vec4);"   // GL_OES_EGL_image_external
1757                 "\n");
1758             } else {
1759                 commonBuiltins.append(
1760                     "highp ivec2 textureSize(samplerExternalOES, int lod);"   // GL_OES_EGL_image_external_essl3
1761                     "vec4 texture(samplerExternalOES, vec2);"                 // GL_OES_EGL_image_external_essl3
1762                     "vec4 texture(samplerExternalOES, vec2, float bias);"     // GL_OES_EGL_image_external_essl3
1763                     "vec4 textureProj(samplerExternalOES, vec3);"             // GL_OES_EGL_image_external_essl3
1764                     "vec4 textureProj(samplerExternalOES, vec3, float bias);" // GL_OES_EGL_image_external_essl3
1765                     "vec4 textureProj(samplerExternalOES, vec4);"             // GL_OES_EGL_image_external_essl3
1766                     "vec4 textureProj(samplerExternalOES, vec4, float bias);" // GL_OES_EGL_image_external_essl3
1767                     "vec4 texelFetch(samplerExternalOES, ivec2, int lod);"    // GL_OES_EGL_image_external_essl3
1768                 "\n");
1769             }
1770             commonBuiltins.append(
1771                 "highp ivec2 textureSize(__samplerExternal2DY2YEXT, int lod);" // GL_EXT_YUV_target
1772                 "vec4 texture(__samplerExternal2DY2YEXT, vec2);"               // GL_EXT_YUV_target
1773                 "vec4 texture(__samplerExternal2DY2YEXT, vec2, float bias);"   // GL_EXT_YUV_target
1774                 "vec4 textureProj(__samplerExternal2DY2YEXT, vec3);"           // GL_EXT_YUV_target
1775                 "vec4 textureProj(__samplerExternal2DY2YEXT, vec3, float bias);" // GL_EXT_YUV_target
1776                 "vec4 textureProj(__samplerExternal2DY2YEXT, vec4);"           // GL_EXT_YUV_target
1777                 "vec4 textureProj(__samplerExternal2DY2YEXT, vec4, float bias);" // GL_EXT_YUV_target
1778                 "vec4 texelFetch(__samplerExternal2DY2YEXT sampler, ivec2, int lod);" // GL_EXT_YUV_target
1779                 "\n");
1780             commonBuiltins.append(
1781                 "vec4 texture2DGradEXT(sampler2D, vec2, vec2, vec2);"      // GL_EXT_shader_texture_lod
1782                 "vec4 texture2DProjGradEXT(sampler2D, vec3, vec2, vec2);"  // GL_EXT_shader_texture_lod
1783                 "vec4 texture2DProjGradEXT(sampler2D, vec4, vec2, vec2);"  // GL_EXT_shader_texture_lod
1784                 "vec4 textureCubeGradEXT(samplerCube, vec3, vec3, vec3);"  // GL_EXT_shader_texture_lod
1785 
1786                 "float shadow2DEXT(sampler2DShadow, vec3);"     // GL_EXT_shadow_samplers
1787                 "float shadow2DProjEXT(sampler2DShadow, vec4);" // GL_EXT_shadow_samplers
1788 
1789                 "\n");
1790         }
1791     }
1792 
1793     //
1794     // Noise functions.
1795     //
1796     if (spvVersion.spv == 0 && profile != EEsProfile) {
1797         commonBuiltins.append(
1798             "float noise1(float x);"
1799             "float noise1(vec2  x);"
1800             "float noise1(vec3  x);"
1801             "float noise1(vec4  x);"
1802 
1803             "vec2 noise2(float x);"
1804             "vec2 noise2(vec2  x);"
1805             "vec2 noise2(vec3  x);"
1806             "vec2 noise2(vec4  x);"
1807 
1808             "vec3 noise3(float x);"
1809             "vec3 noise3(vec2  x);"
1810             "vec3 noise3(vec3  x);"
1811             "vec3 noise3(vec4  x);"
1812 
1813             "vec4 noise4(float x);"
1814             "vec4 noise4(vec2  x);"
1815             "vec4 noise4(vec3  x);"
1816             "vec4 noise4(vec4  x);"
1817 
1818             "\n");
1819     }
1820 
1821     if (spvVersion.vulkan == 0) {
1822         //
1823         // Atomic counter functions.
1824         //
1825         if ((profile != EEsProfile && version >= 300) ||
1826             (profile == EEsProfile && version >= 310)) {
1827             commonBuiltins.append(
1828                 "uint atomicCounterIncrement(atomic_uint);"
1829                 "uint atomicCounterDecrement(atomic_uint);"
1830                 "uint atomicCounter(atomic_uint);"
1831 
1832                 "\n");
1833         }
1834         if (profile != EEsProfile && version == 450) {
1835             commonBuiltins.append(
1836                 "uint atomicCounterAddARB(atomic_uint, uint);"
1837                 "uint atomicCounterSubtractARB(atomic_uint, uint);"
1838                 "uint atomicCounterMinARB(atomic_uint, uint);"
1839                 "uint atomicCounterMaxARB(atomic_uint, uint);"
1840                 "uint atomicCounterAndARB(atomic_uint, uint);"
1841                 "uint atomicCounterOrARB(atomic_uint, uint);"
1842                 "uint atomicCounterXorARB(atomic_uint, uint);"
1843                 "uint atomicCounterExchangeARB(atomic_uint, uint);"
1844                 "uint atomicCounterCompSwapARB(atomic_uint, uint, uint);"
1845 
1846                 "\n");
1847         }
1848 
1849 
1850         if (profile != EEsProfile && version >= 460) {
1851             commonBuiltins.append(
1852                 "uint atomicCounterAdd(atomic_uint, uint);"
1853                 "uint atomicCounterSubtract(atomic_uint, uint);"
1854                 "uint atomicCounterMin(atomic_uint, uint);"
1855                 "uint atomicCounterMax(atomic_uint, uint);"
1856                 "uint atomicCounterAnd(atomic_uint, uint);"
1857                 "uint atomicCounterOr(atomic_uint, uint);"
1858                 "uint atomicCounterXor(atomic_uint, uint);"
1859                 "uint atomicCounterExchange(atomic_uint, uint);"
1860                 "uint atomicCounterCompSwap(atomic_uint, uint, uint);"
1861 
1862                 "\n");
1863         }
1864     }
1865     else if (spvVersion.vulkanRelaxed) {
1866         //
1867         // Atomic counter functions act as aliases to normal atomic functions.
1868         // replace definitions to take 'volatile coherent uint' instead of 'atomic_uint'
1869         // and map to equivalent non-counter atomic op
1870         //
1871         if ((profile != EEsProfile && version >= 300) ||
1872             (profile == EEsProfile && version >= 310)) {
1873             commonBuiltins.append(
1874                 "uint atomicCounterIncrement(volatile coherent uint);"
1875                 "uint atomicCounterDecrement(volatile coherent uint);"
1876                 "uint atomicCounter(volatile coherent uint);"
1877 
1878                 "\n");
1879         }
1880         if (profile != EEsProfile && version >= 460) {
1881             commonBuiltins.append(
1882                 "uint atomicCounterAdd(volatile coherent uint, uint);"
1883                 "uint atomicCounterSubtract(volatile coherent uint, uint);"
1884                 "uint atomicCounterMin(volatile coherent uint, uint);"
1885                 "uint atomicCounterMax(volatile coherent uint, uint);"
1886                 "uint atomicCounterAnd(volatile coherent uint, uint);"
1887                 "uint atomicCounterOr(volatile coherent uint, uint);"
1888                 "uint atomicCounterXor(volatile coherent uint, uint);"
1889                 "uint atomicCounterExchange(volatile coherent uint, uint);"
1890                 "uint atomicCounterCompSwap(volatile coherent uint, uint, uint);"
1891 
1892                 "\n");
1893         }
1894     }
1895 
1896     // Bitfield
1897     if ((profile == EEsProfile && version >= 310) ||
1898         (profile != EEsProfile && version >= 400)) {
1899         commonBuiltins.append(
1900             "  int bitfieldExtract(  int, int, int);"
1901             "ivec2 bitfieldExtract(ivec2, int, int);"
1902             "ivec3 bitfieldExtract(ivec3, int, int);"
1903             "ivec4 bitfieldExtract(ivec4, int, int);"
1904 
1905             " uint bitfieldExtract( uint, int, int);"
1906             "uvec2 bitfieldExtract(uvec2, int, int);"
1907             "uvec3 bitfieldExtract(uvec3, int, int);"
1908             "uvec4 bitfieldExtract(uvec4, int, int);"
1909 
1910             "  int bitfieldInsert(  int base,   int, int, int);"
1911             "ivec2 bitfieldInsert(ivec2 base, ivec2, int, int);"
1912             "ivec3 bitfieldInsert(ivec3 base, ivec3, int, int);"
1913             "ivec4 bitfieldInsert(ivec4 base, ivec4, int, int);"
1914 
1915             " uint bitfieldInsert( uint base,  uint, int, int);"
1916             "uvec2 bitfieldInsert(uvec2 base, uvec2, int, int);"
1917             "uvec3 bitfieldInsert(uvec3 base, uvec3, int, int);"
1918             "uvec4 bitfieldInsert(uvec4 base, uvec4, int, int);"
1919 
1920             "\n");
1921     }
1922 
1923     if (profile != EEsProfile && version >= 400) {
1924         commonBuiltins.append(
1925             "  int findLSB(  int);"
1926             "ivec2 findLSB(ivec2);"
1927             "ivec3 findLSB(ivec3);"
1928             "ivec4 findLSB(ivec4);"
1929 
1930             "  int findLSB( uint);"
1931             "ivec2 findLSB(uvec2);"
1932             "ivec3 findLSB(uvec3);"
1933             "ivec4 findLSB(uvec4);"
1934 
1935             "\n");
1936     } else if (profile == EEsProfile && version >= 310) {
1937         commonBuiltins.append(
1938             "lowp   int findLSB(  int);"
1939             "lowp ivec2 findLSB(ivec2);"
1940             "lowp ivec3 findLSB(ivec3);"
1941             "lowp ivec4 findLSB(ivec4);"
1942 
1943             "lowp   int findLSB( uint);"
1944             "lowp ivec2 findLSB(uvec2);"
1945             "lowp ivec3 findLSB(uvec3);"
1946             "lowp ivec4 findLSB(uvec4);"
1947 
1948             "\n");
1949     }
1950 
1951     if (profile != EEsProfile && version >= 400) {
1952         commonBuiltins.append(
1953             "  int bitCount(  int);"
1954             "ivec2 bitCount(ivec2);"
1955             "ivec3 bitCount(ivec3);"
1956             "ivec4 bitCount(ivec4);"
1957 
1958             "  int bitCount( uint);"
1959             "ivec2 bitCount(uvec2);"
1960             "ivec3 bitCount(uvec3);"
1961             "ivec4 bitCount(uvec4);"
1962 
1963             "  int findMSB(highp   int);"
1964             "ivec2 findMSB(highp ivec2);"
1965             "ivec3 findMSB(highp ivec3);"
1966             "ivec4 findMSB(highp ivec4);"
1967 
1968             "  int findMSB(highp  uint);"
1969             "ivec2 findMSB(highp uvec2);"
1970             "ivec3 findMSB(highp uvec3);"
1971             "ivec4 findMSB(highp uvec4);"
1972 
1973             "\n");
1974     }
1975 
1976     if ((profile == EEsProfile && version >= 310) ||
1977         (profile != EEsProfile && version >= 400)) {
1978         commonBuiltins.append(
1979             " uint uaddCarry(highp  uint, highp  uint, out lowp  uint carry);"
1980             "uvec2 uaddCarry(highp uvec2, highp uvec2, out lowp uvec2 carry);"
1981             "uvec3 uaddCarry(highp uvec3, highp uvec3, out lowp uvec3 carry);"
1982             "uvec4 uaddCarry(highp uvec4, highp uvec4, out lowp uvec4 carry);"
1983 
1984             " uint usubBorrow(highp  uint, highp  uint, out lowp  uint borrow);"
1985             "uvec2 usubBorrow(highp uvec2, highp uvec2, out lowp uvec2 borrow);"
1986             "uvec3 usubBorrow(highp uvec3, highp uvec3, out lowp uvec3 borrow);"
1987             "uvec4 usubBorrow(highp uvec4, highp uvec4, out lowp uvec4 borrow);"
1988 
1989             "void umulExtended(highp  uint, highp  uint, out highp  uint, out highp  uint lsb);"
1990             "void umulExtended(highp uvec2, highp uvec2, out highp uvec2, out highp uvec2 lsb);"
1991             "void umulExtended(highp uvec3, highp uvec3, out highp uvec3, out highp uvec3 lsb);"
1992             "void umulExtended(highp uvec4, highp uvec4, out highp uvec4, out highp uvec4 lsb);"
1993 
1994             "void imulExtended(highp   int, highp   int, out highp   int, out highp   int lsb);"
1995             "void imulExtended(highp ivec2, highp ivec2, out highp ivec2, out highp ivec2 lsb);"
1996             "void imulExtended(highp ivec3, highp ivec3, out highp ivec3, out highp ivec3 lsb);"
1997             "void imulExtended(highp ivec4, highp ivec4, out highp ivec4, out highp ivec4 lsb);"
1998 
1999             "  int bitfieldReverse(highp   int);"
2000             "ivec2 bitfieldReverse(highp ivec2);"
2001             "ivec3 bitfieldReverse(highp ivec3);"
2002             "ivec4 bitfieldReverse(highp ivec4);"
2003 
2004             " uint bitfieldReverse(highp  uint);"
2005             "uvec2 bitfieldReverse(highp uvec2);"
2006             "uvec3 bitfieldReverse(highp uvec3);"
2007             "uvec4 bitfieldReverse(highp uvec4);"
2008 
2009             "\n");
2010     }
2011 
2012     if (profile == EEsProfile && version >= 310) {
2013         commonBuiltins.append(
2014             "lowp   int bitCount(  int);"
2015             "lowp ivec2 bitCount(ivec2);"
2016             "lowp ivec3 bitCount(ivec3);"
2017             "lowp ivec4 bitCount(ivec4);"
2018 
2019             "lowp   int bitCount( uint);"
2020             "lowp ivec2 bitCount(uvec2);"
2021             "lowp ivec3 bitCount(uvec3);"
2022             "lowp ivec4 bitCount(uvec4);"
2023 
2024             "lowp   int findMSB(highp   int);"
2025             "lowp ivec2 findMSB(highp ivec2);"
2026             "lowp ivec3 findMSB(highp ivec3);"
2027             "lowp ivec4 findMSB(highp ivec4);"
2028 
2029             "lowp   int findMSB(highp  uint);"
2030             "lowp ivec2 findMSB(highp uvec2);"
2031             "lowp ivec3 findMSB(highp uvec3);"
2032             "lowp ivec4 findMSB(highp uvec4);"
2033 
2034             "\n");
2035     }
2036 
2037     // GL_ARB_shader_ballot
2038     if (profile != EEsProfile && version >= 450) {
2039         commonBuiltins.append(
2040             "uint64_t ballotARB(bool);"
2041 
2042             "float readInvocationARB(float, uint);"
2043             "vec2  readInvocationARB(vec2,  uint);"
2044             "vec3  readInvocationARB(vec3,  uint);"
2045             "vec4  readInvocationARB(vec4,  uint);"
2046 
2047             "int   readInvocationARB(int,   uint);"
2048             "ivec2 readInvocationARB(ivec2, uint);"
2049             "ivec3 readInvocationARB(ivec3, uint);"
2050             "ivec4 readInvocationARB(ivec4, uint);"
2051 
2052             "uint  readInvocationARB(uint,  uint);"
2053             "uvec2 readInvocationARB(uvec2, uint);"
2054             "uvec3 readInvocationARB(uvec3, uint);"
2055             "uvec4 readInvocationARB(uvec4, uint);"
2056 
2057             "float readFirstInvocationARB(float);"
2058             "vec2  readFirstInvocationARB(vec2);"
2059             "vec3  readFirstInvocationARB(vec3);"
2060             "vec4  readFirstInvocationARB(vec4);"
2061 
2062             "int   readFirstInvocationARB(int);"
2063             "ivec2 readFirstInvocationARB(ivec2);"
2064             "ivec3 readFirstInvocationARB(ivec3);"
2065             "ivec4 readFirstInvocationARB(ivec4);"
2066 
2067             "uint  readFirstInvocationARB(uint);"
2068             "uvec2 readFirstInvocationARB(uvec2);"
2069             "uvec3 readFirstInvocationARB(uvec3);"
2070             "uvec4 readFirstInvocationARB(uvec4);"
2071 
2072             "\n");
2073     }
2074 
2075     // GL_ARB_shader_group_vote
2076     if (profile != EEsProfile && version >= 430) {
2077         commonBuiltins.append(
2078             "bool anyInvocationARB(bool);"
2079             "bool allInvocationsARB(bool);"
2080             "bool allInvocationsEqualARB(bool);"
2081 
2082             "\n");
2083     }
2084 
2085     // GL_KHR_shader_subgroup
2086     if ((profile == EEsProfile && version >= 310) ||
2087         (profile != EEsProfile && version >= 140)) {
2088         commonBuiltins.append(
2089             "void subgroupBarrier();"
2090             "void subgroupMemoryBarrier();"
2091             "void subgroupMemoryBarrierBuffer();"
2092             "void subgroupMemoryBarrierImage();"
2093             "bool subgroupElect();"
2094 
2095             "bool   subgroupAll(bool);\n"
2096             "bool   subgroupAny(bool);\n"
2097             "uvec4  subgroupBallot(bool);\n"
2098             "bool   subgroupInverseBallot(uvec4);\n"
2099             "bool   subgroupBallotBitExtract(uvec4, uint);\n"
2100             "uint   subgroupBallotBitCount(uvec4);\n"
2101             "uint   subgroupBallotInclusiveBitCount(uvec4);\n"
2102             "uint   subgroupBallotExclusiveBitCount(uvec4);\n"
2103             "uint   subgroupBallotFindLSB(uvec4);\n"
2104             "uint   subgroupBallotFindMSB(uvec4);\n"
2105             );
2106 
2107         // Generate all flavors of subgroup ops.
2108         static const char *subgroupOps[] =
2109         {
2110             "bool   subgroupAllEqual(%s);\n",
2111             "%s     subgroupBroadcast(%s, uint);\n",
2112             "%s     subgroupBroadcastFirst(%s);\n",
2113             "%s     subgroupShuffle(%s, uint);\n",
2114             "%s     subgroupShuffleXor(%s, uint);\n",
2115             "%s     subgroupShuffleUp(%s, uint delta);\n",
2116             "%s     subgroupShuffleDown(%s, uint delta);\n",
2117             "%s     subgroupRotate(%s, uint);\n",
2118             "%s     subgroupClusteredRotate(%s, uint, uint);\n",
2119             "%s     subgroupAdd(%s);\n",
2120             "%s     subgroupMul(%s);\n",
2121             "%s     subgroupMin(%s);\n",
2122             "%s     subgroupMax(%s);\n",
2123             "%s     subgroupAnd(%s);\n",
2124             "%s     subgroupOr(%s);\n",
2125             "%s     subgroupXor(%s);\n",
2126             "%s     subgroupInclusiveAdd(%s);\n",
2127             "%s     subgroupInclusiveMul(%s);\n",
2128             "%s     subgroupInclusiveMin(%s);\n",
2129             "%s     subgroupInclusiveMax(%s);\n",
2130             "%s     subgroupInclusiveAnd(%s);\n",
2131             "%s     subgroupInclusiveOr(%s);\n",
2132             "%s     subgroupInclusiveXor(%s);\n",
2133             "%s     subgroupExclusiveAdd(%s);\n",
2134             "%s     subgroupExclusiveMul(%s);\n",
2135             "%s     subgroupExclusiveMin(%s);\n",
2136             "%s     subgroupExclusiveMax(%s);\n",
2137             "%s     subgroupExclusiveAnd(%s);\n",
2138             "%s     subgroupExclusiveOr(%s);\n",
2139             "%s     subgroupExclusiveXor(%s);\n",
2140             "%s     subgroupClusteredAdd(%s, uint);\n",
2141             "%s     subgroupClusteredMul(%s, uint);\n",
2142             "%s     subgroupClusteredMin(%s, uint);\n",
2143             "%s     subgroupClusteredMax(%s, uint);\n",
2144             "%s     subgroupClusteredAnd(%s, uint);\n",
2145             "%s     subgroupClusteredOr(%s, uint);\n",
2146             "%s     subgroupClusteredXor(%s, uint);\n",
2147             "%s     subgroupQuadBroadcast(%s, uint);\n",
2148             "%s     subgroupQuadSwapHorizontal(%s);\n",
2149             "%s     subgroupQuadSwapVertical(%s);\n",
2150             "%s     subgroupQuadSwapDiagonal(%s);\n",
2151             "uvec4  subgroupPartitionNV(%s);\n",
2152             "%s     subgroupPartitionedAddNV(%s, uvec4 ballot);\n",
2153             "%s     subgroupPartitionedMulNV(%s, uvec4 ballot);\n",
2154             "%s     subgroupPartitionedMinNV(%s, uvec4 ballot);\n",
2155             "%s     subgroupPartitionedMaxNV(%s, uvec4 ballot);\n",
2156             "%s     subgroupPartitionedAndNV(%s, uvec4 ballot);\n",
2157             "%s     subgroupPartitionedOrNV(%s, uvec4 ballot);\n",
2158             "%s     subgroupPartitionedXorNV(%s, uvec4 ballot);\n",
2159             "%s     subgroupPartitionedInclusiveAddNV(%s, uvec4 ballot);\n",
2160             "%s     subgroupPartitionedInclusiveMulNV(%s, uvec4 ballot);\n",
2161             "%s     subgroupPartitionedInclusiveMinNV(%s, uvec4 ballot);\n",
2162             "%s     subgroupPartitionedInclusiveMaxNV(%s, uvec4 ballot);\n",
2163             "%s     subgroupPartitionedInclusiveAndNV(%s, uvec4 ballot);\n",
2164             "%s     subgroupPartitionedInclusiveOrNV(%s, uvec4 ballot);\n",
2165             "%s     subgroupPartitionedInclusiveXorNV(%s, uvec4 ballot);\n",
2166             "%s     subgroupPartitionedExclusiveAddNV(%s, uvec4 ballot);\n",
2167             "%s     subgroupPartitionedExclusiveMulNV(%s, uvec4 ballot);\n",
2168             "%s     subgroupPartitionedExclusiveMinNV(%s, uvec4 ballot);\n",
2169             "%s     subgroupPartitionedExclusiveMaxNV(%s, uvec4 ballot);\n",
2170             "%s     subgroupPartitionedExclusiveAndNV(%s, uvec4 ballot);\n",
2171             "%s     subgroupPartitionedExclusiveOrNV(%s, uvec4 ballot);\n",
2172             "%s     subgroupPartitionedExclusiveXorNV(%s, uvec4 ballot);\n",
2173         };
2174 
2175         static const char *floatTypes[] = {
2176             "float", "vec2", "vec3", "vec4",
2177             "float16_t", "f16vec2", "f16vec3", "f16vec4",
2178         };
2179         static const char *doubleTypes[] = {
2180             "double", "dvec2", "dvec3", "dvec4",
2181         };
2182         static const char *intTypes[] = {
2183             "int8_t", "i8vec2", "i8vec3", "i8vec4",
2184             "int16_t", "i16vec2", "i16vec3", "i16vec4",
2185             "int", "ivec2", "ivec3", "ivec4",
2186             "int64_t", "i64vec2", "i64vec3", "i64vec4",
2187             "uint8_t", "u8vec2", "u8vec3", "u8vec4",
2188             "uint16_t", "u16vec2", "u16vec3", "u16vec4",
2189             "uint", "uvec2", "uvec3", "uvec4",
2190             "uint64_t", "u64vec2", "u64vec3", "u64vec4",
2191         };
2192         static const char *boolTypes[] = {
2193             "bool", "bvec2", "bvec3", "bvec4",
2194         };
2195 
2196         for (size_t i = 0; i < sizeof(subgroupOps)/sizeof(subgroupOps[0]); ++i) {
2197             const char *op = subgroupOps[i];
2198 
2199             // Logical operations don't support float
2200             bool logicalOp = strstr(op, "Or") || strstr(op, "And") ||
2201                              (strstr(op, "Xor") && !strstr(op, "ShuffleXor"));
2202             // Math operations don't support bool
2203             bool mathOp = strstr(op, "Add") || strstr(op, "Mul") || strstr(op, "Min") || strstr(op, "Max");
2204 
2205             const int bufSize = 256;
2206             char buf[bufSize];
2207 
2208             if (!logicalOp) {
2209                 for (size_t j = 0; j < sizeof(floatTypes)/sizeof(floatTypes[0]); ++j) {
2210                     snprintf(buf, bufSize, op, floatTypes[j], floatTypes[j]);
2211                     commonBuiltins.append(buf);
2212                 }
2213                 if (profile != EEsProfile && version >= 400) {
2214                     for (size_t j = 0; j < sizeof(doubleTypes)/sizeof(doubleTypes[0]); ++j) {
2215                         snprintf(buf, bufSize, op, doubleTypes[j], doubleTypes[j]);
2216                         commonBuiltins.append(buf);
2217                     }
2218                 }
2219             }
2220             if (!mathOp) {
2221                 for (size_t j = 0; j < sizeof(boolTypes)/sizeof(boolTypes[0]); ++j) {
2222                     snprintf(buf, bufSize, op, boolTypes[j], boolTypes[j]);
2223                     commonBuiltins.append(buf);
2224                 }
2225             }
2226             for (size_t j = 0; j < sizeof(intTypes)/sizeof(intTypes[0]); ++j) {
2227                 snprintf(buf, bufSize, op, intTypes[j], intTypes[j]);
2228                 commonBuiltins.append(buf);
2229             }
2230         }
2231 
2232         stageBuiltins[EShLangCompute].append(
2233             "void subgroupMemoryBarrierShared();"
2234 
2235             "\n"
2236             );
2237         stageBuiltins[EShLangMesh].append(
2238             "void subgroupMemoryBarrierShared();"
2239             "\n"
2240             );
2241         stageBuiltins[EShLangTask].append(
2242             "void subgroupMemoryBarrierShared();"
2243             "\n"
2244             );
2245     }
2246 
2247     // GL_EXT_shader_quad_control
2248     if ((profile == EEsProfile && version >= 310) ||
2249         (profile != EEsProfile && version >= 140)) {
2250         commonBuiltins.append(
2251             "bool subgroupQuadAll(bool);\n"
2252             "bool subgroupQuadAny(bool);\n"
2253             );
2254     }
2255 
2256     if (profile != EEsProfile && version >= 460) {
2257         commonBuiltins.append(
2258             "bool anyInvocation(bool);"
2259             "bool allInvocations(bool);"
2260             "bool allInvocationsEqual(bool);"
2261 
2262             "\n");
2263     }
2264 
2265     // GL_AMD_shader_ballot
2266     if (profile != EEsProfile && version >= 450) {
2267         commonBuiltins.append(
2268             "float minInvocationsAMD(float);"
2269             "vec2  minInvocationsAMD(vec2);"
2270             "vec3  minInvocationsAMD(vec3);"
2271             "vec4  minInvocationsAMD(vec4);"
2272 
2273             "int   minInvocationsAMD(int);"
2274             "ivec2 minInvocationsAMD(ivec2);"
2275             "ivec3 minInvocationsAMD(ivec3);"
2276             "ivec4 minInvocationsAMD(ivec4);"
2277 
2278             "uint  minInvocationsAMD(uint);"
2279             "uvec2 minInvocationsAMD(uvec2);"
2280             "uvec3 minInvocationsAMD(uvec3);"
2281             "uvec4 minInvocationsAMD(uvec4);"
2282 
2283             "double minInvocationsAMD(double);"
2284             "dvec2  minInvocationsAMD(dvec2);"
2285             "dvec3  minInvocationsAMD(dvec3);"
2286             "dvec4  minInvocationsAMD(dvec4);"
2287 
2288             "int64_t minInvocationsAMD(int64_t);"
2289             "i64vec2 minInvocationsAMD(i64vec2);"
2290             "i64vec3 minInvocationsAMD(i64vec3);"
2291             "i64vec4 minInvocationsAMD(i64vec4);"
2292 
2293             "uint64_t minInvocationsAMD(uint64_t);"
2294             "u64vec2  minInvocationsAMD(u64vec2);"
2295             "u64vec3  minInvocationsAMD(u64vec3);"
2296             "u64vec4  minInvocationsAMD(u64vec4);"
2297 
2298             "float16_t minInvocationsAMD(float16_t);"
2299             "f16vec2   minInvocationsAMD(f16vec2);"
2300             "f16vec3   minInvocationsAMD(f16vec3);"
2301             "f16vec4   minInvocationsAMD(f16vec4);"
2302 
2303             "int16_t minInvocationsAMD(int16_t);"
2304             "i16vec2 minInvocationsAMD(i16vec2);"
2305             "i16vec3 minInvocationsAMD(i16vec3);"
2306             "i16vec4 minInvocationsAMD(i16vec4);"
2307 
2308             "uint16_t minInvocationsAMD(uint16_t);"
2309             "u16vec2  minInvocationsAMD(u16vec2);"
2310             "u16vec3  minInvocationsAMD(u16vec3);"
2311             "u16vec4  minInvocationsAMD(u16vec4);"
2312 
2313             "float minInvocationsInclusiveScanAMD(float);"
2314             "vec2  minInvocationsInclusiveScanAMD(vec2);"
2315             "vec3  minInvocationsInclusiveScanAMD(vec3);"
2316             "vec4  minInvocationsInclusiveScanAMD(vec4);"
2317 
2318             "int   minInvocationsInclusiveScanAMD(int);"
2319             "ivec2 minInvocationsInclusiveScanAMD(ivec2);"
2320             "ivec3 minInvocationsInclusiveScanAMD(ivec3);"
2321             "ivec4 minInvocationsInclusiveScanAMD(ivec4);"
2322 
2323             "uint  minInvocationsInclusiveScanAMD(uint);"
2324             "uvec2 minInvocationsInclusiveScanAMD(uvec2);"
2325             "uvec3 minInvocationsInclusiveScanAMD(uvec3);"
2326             "uvec4 minInvocationsInclusiveScanAMD(uvec4);"
2327 
2328             "double minInvocationsInclusiveScanAMD(double);"
2329             "dvec2  minInvocationsInclusiveScanAMD(dvec2);"
2330             "dvec3  minInvocationsInclusiveScanAMD(dvec3);"
2331             "dvec4  minInvocationsInclusiveScanAMD(dvec4);"
2332 
2333             "int64_t minInvocationsInclusiveScanAMD(int64_t);"
2334             "i64vec2 minInvocationsInclusiveScanAMD(i64vec2);"
2335             "i64vec3 minInvocationsInclusiveScanAMD(i64vec3);"
2336             "i64vec4 minInvocationsInclusiveScanAMD(i64vec4);"
2337 
2338             "uint64_t minInvocationsInclusiveScanAMD(uint64_t);"
2339             "u64vec2  minInvocationsInclusiveScanAMD(u64vec2);"
2340             "u64vec3  minInvocationsInclusiveScanAMD(u64vec3);"
2341             "u64vec4  minInvocationsInclusiveScanAMD(u64vec4);"
2342 
2343             "float16_t minInvocationsInclusiveScanAMD(float16_t);"
2344             "f16vec2   minInvocationsInclusiveScanAMD(f16vec2);"
2345             "f16vec3   minInvocationsInclusiveScanAMD(f16vec3);"
2346             "f16vec4   minInvocationsInclusiveScanAMD(f16vec4);"
2347 
2348             "int16_t minInvocationsInclusiveScanAMD(int16_t);"
2349             "i16vec2 minInvocationsInclusiveScanAMD(i16vec2);"
2350             "i16vec3 minInvocationsInclusiveScanAMD(i16vec3);"
2351             "i16vec4 minInvocationsInclusiveScanAMD(i16vec4);"
2352 
2353             "uint16_t minInvocationsInclusiveScanAMD(uint16_t);"
2354             "u16vec2  minInvocationsInclusiveScanAMD(u16vec2);"
2355             "u16vec3  minInvocationsInclusiveScanAMD(u16vec3);"
2356             "u16vec4  minInvocationsInclusiveScanAMD(u16vec4);"
2357 
2358             "float minInvocationsExclusiveScanAMD(float);"
2359             "vec2  minInvocationsExclusiveScanAMD(vec2);"
2360             "vec3  minInvocationsExclusiveScanAMD(vec3);"
2361             "vec4  minInvocationsExclusiveScanAMD(vec4);"
2362 
2363             "int   minInvocationsExclusiveScanAMD(int);"
2364             "ivec2 minInvocationsExclusiveScanAMD(ivec2);"
2365             "ivec3 minInvocationsExclusiveScanAMD(ivec3);"
2366             "ivec4 minInvocationsExclusiveScanAMD(ivec4);"
2367 
2368             "uint  minInvocationsExclusiveScanAMD(uint);"
2369             "uvec2 minInvocationsExclusiveScanAMD(uvec2);"
2370             "uvec3 minInvocationsExclusiveScanAMD(uvec3);"
2371             "uvec4 minInvocationsExclusiveScanAMD(uvec4);"
2372 
2373             "double minInvocationsExclusiveScanAMD(double);"
2374             "dvec2  minInvocationsExclusiveScanAMD(dvec2);"
2375             "dvec3  minInvocationsExclusiveScanAMD(dvec3);"
2376             "dvec4  minInvocationsExclusiveScanAMD(dvec4);"
2377 
2378             "int64_t minInvocationsExclusiveScanAMD(int64_t);"
2379             "i64vec2 minInvocationsExclusiveScanAMD(i64vec2);"
2380             "i64vec3 minInvocationsExclusiveScanAMD(i64vec3);"
2381             "i64vec4 minInvocationsExclusiveScanAMD(i64vec4);"
2382 
2383             "uint64_t minInvocationsExclusiveScanAMD(uint64_t);"
2384             "u64vec2  minInvocationsExclusiveScanAMD(u64vec2);"
2385             "u64vec3  minInvocationsExclusiveScanAMD(u64vec3);"
2386             "u64vec4  minInvocationsExclusiveScanAMD(u64vec4);"
2387 
2388             "float16_t minInvocationsExclusiveScanAMD(float16_t);"
2389             "f16vec2   minInvocationsExclusiveScanAMD(f16vec2);"
2390             "f16vec3   minInvocationsExclusiveScanAMD(f16vec3);"
2391             "f16vec4   minInvocationsExclusiveScanAMD(f16vec4);"
2392 
2393             "int16_t minInvocationsExclusiveScanAMD(int16_t);"
2394             "i16vec2 minInvocationsExclusiveScanAMD(i16vec2);"
2395             "i16vec3 minInvocationsExclusiveScanAMD(i16vec3);"
2396             "i16vec4 minInvocationsExclusiveScanAMD(i16vec4);"
2397 
2398             "uint16_t minInvocationsExclusiveScanAMD(uint16_t);"
2399             "u16vec2  minInvocationsExclusiveScanAMD(u16vec2);"
2400             "u16vec3  minInvocationsExclusiveScanAMD(u16vec3);"
2401             "u16vec4  minInvocationsExclusiveScanAMD(u16vec4);"
2402 
2403             "float maxInvocationsAMD(float);"
2404             "vec2  maxInvocationsAMD(vec2);"
2405             "vec3  maxInvocationsAMD(vec3);"
2406             "vec4  maxInvocationsAMD(vec4);"
2407 
2408             "int   maxInvocationsAMD(int);"
2409             "ivec2 maxInvocationsAMD(ivec2);"
2410             "ivec3 maxInvocationsAMD(ivec3);"
2411             "ivec4 maxInvocationsAMD(ivec4);"
2412 
2413             "uint  maxInvocationsAMD(uint);"
2414             "uvec2 maxInvocationsAMD(uvec2);"
2415             "uvec3 maxInvocationsAMD(uvec3);"
2416             "uvec4 maxInvocationsAMD(uvec4);"
2417 
2418             "double maxInvocationsAMD(double);"
2419             "dvec2  maxInvocationsAMD(dvec2);"
2420             "dvec3  maxInvocationsAMD(dvec3);"
2421             "dvec4  maxInvocationsAMD(dvec4);"
2422 
2423             "int64_t maxInvocationsAMD(int64_t);"
2424             "i64vec2 maxInvocationsAMD(i64vec2);"
2425             "i64vec3 maxInvocationsAMD(i64vec3);"
2426             "i64vec4 maxInvocationsAMD(i64vec4);"
2427 
2428             "uint64_t maxInvocationsAMD(uint64_t);"
2429             "u64vec2  maxInvocationsAMD(u64vec2);"
2430             "u64vec3  maxInvocationsAMD(u64vec3);"
2431             "u64vec4  maxInvocationsAMD(u64vec4);"
2432 
2433             "float16_t maxInvocationsAMD(float16_t);"
2434             "f16vec2   maxInvocationsAMD(f16vec2);"
2435             "f16vec3   maxInvocationsAMD(f16vec3);"
2436             "f16vec4   maxInvocationsAMD(f16vec4);"
2437 
2438             "int16_t maxInvocationsAMD(int16_t);"
2439             "i16vec2 maxInvocationsAMD(i16vec2);"
2440             "i16vec3 maxInvocationsAMD(i16vec3);"
2441             "i16vec4 maxInvocationsAMD(i16vec4);"
2442 
2443             "uint16_t maxInvocationsAMD(uint16_t);"
2444             "u16vec2  maxInvocationsAMD(u16vec2);"
2445             "u16vec3  maxInvocationsAMD(u16vec3);"
2446             "u16vec4  maxInvocationsAMD(u16vec4);"
2447 
2448             "float maxInvocationsInclusiveScanAMD(float);"
2449             "vec2  maxInvocationsInclusiveScanAMD(vec2);"
2450             "vec3  maxInvocationsInclusiveScanAMD(vec3);"
2451             "vec4  maxInvocationsInclusiveScanAMD(vec4);"
2452 
2453             "int   maxInvocationsInclusiveScanAMD(int);"
2454             "ivec2 maxInvocationsInclusiveScanAMD(ivec2);"
2455             "ivec3 maxInvocationsInclusiveScanAMD(ivec3);"
2456             "ivec4 maxInvocationsInclusiveScanAMD(ivec4);"
2457 
2458             "uint  maxInvocationsInclusiveScanAMD(uint);"
2459             "uvec2 maxInvocationsInclusiveScanAMD(uvec2);"
2460             "uvec3 maxInvocationsInclusiveScanAMD(uvec3);"
2461             "uvec4 maxInvocationsInclusiveScanAMD(uvec4);"
2462 
2463             "double maxInvocationsInclusiveScanAMD(double);"
2464             "dvec2  maxInvocationsInclusiveScanAMD(dvec2);"
2465             "dvec3  maxInvocationsInclusiveScanAMD(dvec3);"
2466             "dvec4  maxInvocationsInclusiveScanAMD(dvec4);"
2467 
2468             "int64_t maxInvocationsInclusiveScanAMD(int64_t);"
2469             "i64vec2 maxInvocationsInclusiveScanAMD(i64vec2);"
2470             "i64vec3 maxInvocationsInclusiveScanAMD(i64vec3);"
2471             "i64vec4 maxInvocationsInclusiveScanAMD(i64vec4);"
2472 
2473             "uint64_t maxInvocationsInclusiveScanAMD(uint64_t);"
2474             "u64vec2  maxInvocationsInclusiveScanAMD(u64vec2);"
2475             "u64vec3  maxInvocationsInclusiveScanAMD(u64vec3);"
2476             "u64vec4  maxInvocationsInclusiveScanAMD(u64vec4);"
2477 
2478             "float16_t maxInvocationsInclusiveScanAMD(float16_t);"
2479             "f16vec2   maxInvocationsInclusiveScanAMD(f16vec2);"
2480             "f16vec3   maxInvocationsInclusiveScanAMD(f16vec3);"
2481             "f16vec4   maxInvocationsInclusiveScanAMD(f16vec4);"
2482 
2483             "int16_t maxInvocationsInclusiveScanAMD(int16_t);"
2484             "i16vec2 maxInvocationsInclusiveScanAMD(i16vec2);"
2485             "i16vec3 maxInvocationsInclusiveScanAMD(i16vec3);"
2486             "i16vec4 maxInvocationsInclusiveScanAMD(i16vec4);"
2487 
2488             "uint16_t maxInvocationsInclusiveScanAMD(uint16_t);"
2489             "u16vec2  maxInvocationsInclusiveScanAMD(u16vec2);"
2490             "u16vec3  maxInvocationsInclusiveScanAMD(u16vec3);"
2491             "u16vec4  maxInvocationsInclusiveScanAMD(u16vec4);"
2492 
2493             "float maxInvocationsExclusiveScanAMD(float);"
2494             "vec2  maxInvocationsExclusiveScanAMD(vec2);"
2495             "vec3  maxInvocationsExclusiveScanAMD(vec3);"
2496             "vec4  maxInvocationsExclusiveScanAMD(vec4);"
2497 
2498             "int   maxInvocationsExclusiveScanAMD(int);"
2499             "ivec2 maxInvocationsExclusiveScanAMD(ivec2);"
2500             "ivec3 maxInvocationsExclusiveScanAMD(ivec3);"
2501             "ivec4 maxInvocationsExclusiveScanAMD(ivec4);"
2502 
2503             "uint  maxInvocationsExclusiveScanAMD(uint);"
2504             "uvec2 maxInvocationsExclusiveScanAMD(uvec2);"
2505             "uvec3 maxInvocationsExclusiveScanAMD(uvec3);"
2506             "uvec4 maxInvocationsExclusiveScanAMD(uvec4);"
2507 
2508             "double maxInvocationsExclusiveScanAMD(double);"
2509             "dvec2  maxInvocationsExclusiveScanAMD(dvec2);"
2510             "dvec3  maxInvocationsExclusiveScanAMD(dvec3);"
2511             "dvec4  maxInvocationsExclusiveScanAMD(dvec4);"
2512 
2513             "int64_t maxInvocationsExclusiveScanAMD(int64_t);"
2514             "i64vec2 maxInvocationsExclusiveScanAMD(i64vec2);"
2515             "i64vec3 maxInvocationsExclusiveScanAMD(i64vec3);"
2516             "i64vec4 maxInvocationsExclusiveScanAMD(i64vec4);"
2517 
2518             "uint64_t maxInvocationsExclusiveScanAMD(uint64_t);"
2519             "u64vec2  maxInvocationsExclusiveScanAMD(u64vec2);"
2520             "u64vec3  maxInvocationsExclusiveScanAMD(u64vec3);"
2521             "u64vec4  maxInvocationsExclusiveScanAMD(u64vec4);"
2522 
2523             "float16_t maxInvocationsExclusiveScanAMD(float16_t);"
2524             "f16vec2   maxInvocationsExclusiveScanAMD(f16vec2);"
2525             "f16vec3   maxInvocationsExclusiveScanAMD(f16vec3);"
2526             "f16vec4   maxInvocationsExclusiveScanAMD(f16vec4);"
2527 
2528             "int16_t maxInvocationsExclusiveScanAMD(int16_t);"
2529             "i16vec2 maxInvocationsExclusiveScanAMD(i16vec2);"
2530             "i16vec3 maxInvocationsExclusiveScanAMD(i16vec3);"
2531             "i16vec4 maxInvocationsExclusiveScanAMD(i16vec4);"
2532 
2533             "uint16_t maxInvocationsExclusiveScanAMD(uint16_t);"
2534             "u16vec2  maxInvocationsExclusiveScanAMD(u16vec2);"
2535             "u16vec3  maxInvocationsExclusiveScanAMD(u16vec3);"
2536             "u16vec4  maxInvocationsExclusiveScanAMD(u16vec4);"
2537 
2538             "float addInvocationsAMD(float);"
2539             "vec2  addInvocationsAMD(vec2);"
2540             "vec3  addInvocationsAMD(vec3);"
2541             "vec4  addInvocationsAMD(vec4);"
2542 
2543             "int   addInvocationsAMD(int);"
2544             "ivec2 addInvocationsAMD(ivec2);"
2545             "ivec3 addInvocationsAMD(ivec3);"
2546             "ivec4 addInvocationsAMD(ivec4);"
2547 
2548             "uint  addInvocationsAMD(uint);"
2549             "uvec2 addInvocationsAMD(uvec2);"
2550             "uvec3 addInvocationsAMD(uvec3);"
2551             "uvec4 addInvocationsAMD(uvec4);"
2552 
2553             "double  addInvocationsAMD(double);"
2554             "dvec2   addInvocationsAMD(dvec2);"
2555             "dvec3   addInvocationsAMD(dvec3);"
2556             "dvec4   addInvocationsAMD(dvec4);"
2557 
2558             "int64_t addInvocationsAMD(int64_t);"
2559             "i64vec2 addInvocationsAMD(i64vec2);"
2560             "i64vec3 addInvocationsAMD(i64vec3);"
2561             "i64vec4 addInvocationsAMD(i64vec4);"
2562 
2563             "uint64_t addInvocationsAMD(uint64_t);"
2564             "u64vec2  addInvocationsAMD(u64vec2);"
2565             "u64vec3  addInvocationsAMD(u64vec3);"
2566             "u64vec4  addInvocationsAMD(u64vec4);"
2567 
2568             "float16_t addInvocationsAMD(float16_t);"
2569             "f16vec2   addInvocationsAMD(f16vec2);"
2570             "f16vec3   addInvocationsAMD(f16vec3);"
2571             "f16vec4   addInvocationsAMD(f16vec4);"
2572 
2573             "int16_t addInvocationsAMD(int16_t);"
2574             "i16vec2 addInvocationsAMD(i16vec2);"
2575             "i16vec3 addInvocationsAMD(i16vec3);"
2576             "i16vec4 addInvocationsAMD(i16vec4);"
2577 
2578             "uint16_t addInvocationsAMD(uint16_t);"
2579             "u16vec2  addInvocationsAMD(u16vec2);"
2580             "u16vec3  addInvocationsAMD(u16vec3);"
2581             "u16vec4  addInvocationsAMD(u16vec4);"
2582 
2583             "float addInvocationsInclusiveScanAMD(float);"
2584             "vec2  addInvocationsInclusiveScanAMD(vec2);"
2585             "vec3  addInvocationsInclusiveScanAMD(vec3);"
2586             "vec4  addInvocationsInclusiveScanAMD(vec4);"
2587 
2588             "int   addInvocationsInclusiveScanAMD(int);"
2589             "ivec2 addInvocationsInclusiveScanAMD(ivec2);"
2590             "ivec3 addInvocationsInclusiveScanAMD(ivec3);"
2591             "ivec4 addInvocationsInclusiveScanAMD(ivec4);"
2592 
2593             "uint  addInvocationsInclusiveScanAMD(uint);"
2594             "uvec2 addInvocationsInclusiveScanAMD(uvec2);"
2595             "uvec3 addInvocationsInclusiveScanAMD(uvec3);"
2596             "uvec4 addInvocationsInclusiveScanAMD(uvec4);"
2597 
2598             "double  addInvocationsInclusiveScanAMD(double);"
2599             "dvec2   addInvocationsInclusiveScanAMD(dvec2);"
2600             "dvec3   addInvocationsInclusiveScanAMD(dvec3);"
2601             "dvec4   addInvocationsInclusiveScanAMD(dvec4);"
2602 
2603             "int64_t addInvocationsInclusiveScanAMD(int64_t);"
2604             "i64vec2 addInvocationsInclusiveScanAMD(i64vec2);"
2605             "i64vec3 addInvocationsInclusiveScanAMD(i64vec3);"
2606             "i64vec4 addInvocationsInclusiveScanAMD(i64vec4);"
2607 
2608             "uint64_t addInvocationsInclusiveScanAMD(uint64_t);"
2609             "u64vec2  addInvocationsInclusiveScanAMD(u64vec2);"
2610             "u64vec3  addInvocationsInclusiveScanAMD(u64vec3);"
2611             "u64vec4  addInvocationsInclusiveScanAMD(u64vec4);"
2612 
2613             "float16_t addInvocationsInclusiveScanAMD(float16_t);"
2614             "f16vec2   addInvocationsInclusiveScanAMD(f16vec2);"
2615             "f16vec3   addInvocationsInclusiveScanAMD(f16vec3);"
2616             "f16vec4   addInvocationsInclusiveScanAMD(f16vec4);"
2617 
2618             "int16_t addInvocationsInclusiveScanAMD(int16_t);"
2619             "i16vec2 addInvocationsInclusiveScanAMD(i16vec2);"
2620             "i16vec3 addInvocationsInclusiveScanAMD(i16vec3);"
2621             "i16vec4 addInvocationsInclusiveScanAMD(i16vec4);"
2622 
2623             "uint16_t addInvocationsInclusiveScanAMD(uint16_t);"
2624             "u16vec2  addInvocationsInclusiveScanAMD(u16vec2);"
2625             "u16vec3  addInvocationsInclusiveScanAMD(u16vec3);"
2626             "u16vec4  addInvocationsInclusiveScanAMD(u16vec4);"
2627 
2628             "float addInvocationsExclusiveScanAMD(float);"
2629             "vec2  addInvocationsExclusiveScanAMD(vec2);"
2630             "vec3  addInvocationsExclusiveScanAMD(vec3);"
2631             "vec4  addInvocationsExclusiveScanAMD(vec4);"
2632 
2633             "int   addInvocationsExclusiveScanAMD(int);"
2634             "ivec2 addInvocationsExclusiveScanAMD(ivec2);"
2635             "ivec3 addInvocationsExclusiveScanAMD(ivec3);"
2636             "ivec4 addInvocationsExclusiveScanAMD(ivec4);"
2637 
2638             "uint  addInvocationsExclusiveScanAMD(uint);"
2639             "uvec2 addInvocationsExclusiveScanAMD(uvec2);"
2640             "uvec3 addInvocationsExclusiveScanAMD(uvec3);"
2641             "uvec4 addInvocationsExclusiveScanAMD(uvec4);"
2642 
2643             "double  addInvocationsExclusiveScanAMD(double);"
2644             "dvec2   addInvocationsExclusiveScanAMD(dvec2);"
2645             "dvec3   addInvocationsExclusiveScanAMD(dvec3);"
2646             "dvec4   addInvocationsExclusiveScanAMD(dvec4);"
2647 
2648             "int64_t addInvocationsExclusiveScanAMD(int64_t);"
2649             "i64vec2 addInvocationsExclusiveScanAMD(i64vec2);"
2650             "i64vec3 addInvocationsExclusiveScanAMD(i64vec3);"
2651             "i64vec4 addInvocationsExclusiveScanAMD(i64vec4);"
2652 
2653             "uint64_t addInvocationsExclusiveScanAMD(uint64_t);"
2654             "u64vec2  addInvocationsExclusiveScanAMD(u64vec2);"
2655             "u64vec3  addInvocationsExclusiveScanAMD(u64vec3);"
2656             "u64vec4  addInvocationsExclusiveScanAMD(u64vec4);"
2657 
2658             "float16_t addInvocationsExclusiveScanAMD(float16_t);"
2659             "f16vec2   addInvocationsExclusiveScanAMD(f16vec2);"
2660             "f16vec3   addInvocationsExclusiveScanAMD(f16vec3);"
2661             "f16vec4   addInvocationsExclusiveScanAMD(f16vec4);"
2662 
2663             "int16_t addInvocationsExclusiveScanAMD(int16_t);"
2664             "i16vec2 addInvocationsExclusiveScanAMD(i16vec2);"
2665             "i16vec3 addInvocationsExclusiveScanAMD(i16vec3);"
2666             "i16vec4 addInvocationsExclusiveScanAMD(i16vec4);"
2667 
2668             "uint16_t addInvocationsExclusiveScanAMD(uint16_t);"
2669             "u16vec2  addInvocationsExclusiveScanAMD(u16vec2);"
2670             "u16vec3  addInvocationsExclusiveScanAMD(u16vec3);"
2671             "u16vec4  addInvocationsExclusiveScanAMD(u16vec4);"
2672 
2673             "float minInvocationsNonUniformAMD(float);"
2674             "vec2  minInvocationsNonUniformAMD(vec2);"
2675             "vec3  minInvocationsNonUniformAMD(vec3);"
2676             "vec4  minInvocationsNonUniformAMD(vec4);"
2677 
2678             "int   minInvocationsNonUniformAMD(int);"
2679             "ivec2 minInvocationsNonUniformAMD(ivec2);"
2680             "ivec3 minInvocationsNonUniformAMD(ivec3);"
2681             "ivec4 minInvocationsNonUniformAMD(ivec4);"
2682 
2683             "uint  minInvocationsNonUniformAMD(uint);"
2684             "uvec2 minInvocationsNonUniformAMD(uvec2);"
2685             "uvec3 minInvocationsNonUniformAMD(uvec3);"
2686             "uvec4 minInvocationsNonUniformAMD(uvec4);"
2687 
2688             "double minInvocationsNonUniformAMD(double);"
2689             "dvec2  minInvocationsNonUniformAMD(dvec2);"
2690             "dvec3  minInvocationsNonUniformAMD(dvec3);"
2691             "dvec4  minInvocationsNonUniformAMD(dvec4);"
2692 
2693             "int64_t minInvocationsNonUniformAMD(int64_t);"
2694             "i64vec2 minInvocationsNonUniformAMD(i64vec2);"
2695             "i64vec3 minInvocationsNonUniformAMD(i64vec3);"
2696             "i64vec4 minInvocationsNonUniformAMD(i64vec4);"
2697 
2698             "uint64_t minInvocationsNonUniformAMD(uint64_t);"
2699             "u64vec2  minInvocationsNonUniformAMD(u64vec2);"
2700             "u64vec3  minInvocationsNonUniformAMD(u64vec3);"
2701             "u64vec4  minInvocationsNonUniformAMD(u64vec4);"
2702 
2703             "float16_t minInvocationsNonUniformAMD(float16_t);"
2704             "f16vec2   minInvocationsNonUniformAMD(f16vec2);"
2705             "f16vec3   minInvocationsNonUniformAMD(f16vec3);"
2706             "f16vec4   minInvocationsNonUniformAMD(f16vec4);"
2707 
2708             "int16_t minInvocationsNonUniformAMD(int16_t);"
2709             "i16vec2 minInvocationsNonUniformAMD(i16vec2);"
2710             "i16vec3 minInvocationsNonUniformAMD(i16vec3);"
2711             "i16vec4 minInvocationsNonUniformAMD(i16vec4);"
2712 
2713             "uint16_t minInvocationsNonUniformAMD(uint16_t);"
2714             "u16vec2  minInvocationsNonUniformAMD(u16vec2);"
2715             "u16vec3  minInvocationsNonUniformAMD(u16vec3);"
2716             "u16vec4  minInvocationsNonUniformAMD(u16vec4);"
2717 
2718             "float minInvocationsInclusiveScanNonUniformAMD(float);"
2719             "vec2  minInvocationsInclusiveScanNonUniformAMD(vec2);"
2720             "vec3  minInvocationsInclusiveScanNonUniformAMD(vec3);"
2721             "vec4  minInvocationsInclusiveScanNonUniformAMD(vec4);"
2722 
2723             "int   minInvocationsInclusiveScanNonUniformAMD(int);"
2724             "ivec2 minInvocationsInclusiveScanNonUniformAMD(ivec2);"
2725             "ivec3 minInvocationsInclusiveScanNonUniformAMD(ivec3);"
2726             "ivec4 minInvocationsInclusiveScanNonUniformAMD(ivec4);"
2727 
2728             "uint  minInvocationsInclusiveScanNonUniformAMD(uint);"
2729             "uvec2 minInvocationsInclusiveScanNonUniformAMD(uvec2);"
2730             "uvec3 minInvocationsInclusiveScanNonUniformAMD(uvec3);"
2731             "uvec4 minInvocationsInclusiveScanNonUniformAMD(uvec4);"
2732 
2733             "double minInvocationsInclusiveScanNonUniformAMD(double);"
2734             "dvec2  minInvocationsInclusiveScanNonUniformAMD(dvec2);"
2735             "dvec3  minInvocationsInclusiveScanNonUniformAMD(dvec3);"
2736             "dvec4  minInvocationsInclusiveScanNonUniformAMD(dvec4);"
2737 
2738             "int64_t minInvocationsInclusiveScanNonUniformAMD(int64_t);"
2739             "i64vec2 minInvocationsInclusiveScanNonUniformAMD(i64vec2);"
2740             "i64vec3 minInvocationsInclusiveScanNonUniformAMD(i64vec3);"
2741             "i64vec4 minInvocationsInclusiveScanNonUniformAMD(i64vec4);"
2742 
2743             "uint64_t minInvocationsInclusiveScanNonUniformAMD(uint64_t);"
2744             "u64vec2  minInvocationsInclusiveScanNonUniformAMD(u64vec2);"
2745             "u64vec3  minInvocationsInclusiveScanNonUniformAMD(u64vec3);"
2746             "u64vec4  minInvocationsInclusiveScanNonUniformAMD(u64vec4);"
2747 
2748             "float16_t minInvocationsInclusiveScanNonUniformAMD(float16_t);"
2749             "f16vec2   minInvocationsInclusiveScanNonUniformAMD(f16vec2);"
2750             "f16vec3   minInvocationsInclusiveScanNonUniformAMD(f16vec3);"
2751             "f16vec4   minInvocationsInclusiveScanNonUniformAMD(f16vec4);"
2752 
2753             "int16_t minInvocationsInclusiveScanNonUniformAMD(int16_t);"
2754             "i16vec2 minInvocationsInclusiveScanNonUniformAMD(i16vec2);"
2755             "i16vec3 minInvocationsInclusiveScanNonUniformAMD(i16vec3);"
2756             "i16vec4 minInvocationsInclusiveScanNonUniformAMD(i16vec4);"
2757 
2758             "uint16_t minInvocationsInclusiveScanNonUniformAMD(uint16_t);"
2759             "u16vec2  minInvocationsInclusiveScanNonUniformAMD(u16vec2);"
2760             "u16vec3  minInvocationsInclusiveScanNonUniformAMD(u16vec3);"
2761             "u16vec4  minInvocationsInclusiveScanNonUniformAMD(u16vec4);"
2762 
2763             "float minInvocationsExclusiveScanNonUniformAMD(float);"
2764             "vec2  minInvocationsExclusiveScanNonUniformAMD(vec2);"
2765             "vec3  minInvocationsExclusiveScanNonUniformAMD(vec3);"
2766             "vec4  minInvocationsExclusiveScanNonUniformAMD(vec4);"
2767 
2768             "int   minInvocationsExclusiveScanNonUniformAMD(int);"
2769             "ivec2 minInvocationsExclusiveScanNonUniformAMD(ivec2);"
2770             "ivec3 minInvocationsExclusiveScanNonUniformAMD(ivec3);"
2771             "ivec4 minInvocationsExclusiveScanNonUniformAMD(ivec4);"
2772 
2773             "uint  minInvocationsExclusiveScanNonUniformAMD(uint);"
2774             "uvec2 minInvocationsExclusiveScanNonUniformAMD(uvec2);"
2775             "uvec3 minInvocationsExclusiveScanNonUniformAMD(uvec3);"
2776             "uvec4 minInvocationsExclusiveScanNonUniformAMD(uvec4);"
2777 
2778             "double minInvocationsExclusiveScanNonUniformAMD(double);"
2779             "dvec2  minInvocationsExclusiveScanNonUniformAMD(dvec2);"
2780             "dvec3  minInvocationsExclusiveScanNonUniformAMD(dvec3);"
2781             "dvec4  minInvocationsExclusiveScanNonUniformAMD(dvec4);"
2782 
2783             "int64_t minInvocationsExclusiveScanNonUniformAMD(int64_t);"
2784             "i64vec2 minInvocationsExclusiveScanNonUniformAMD(i64vec2);"
2785             "i64vec3 minInvocationsExclusiveScanNonUniformAMD(i64vec3);"
2786             "i64vec4 minInvocationsExclusiveScanNonUniformAMD(i64vec4);"
2787 
2788             "uint64_t minInvocationsExclusiveScanNonUniformAMD(uint64_t);"
2789             "u64vec2  minInvocationsExclusiveScanNonUniformAMD(u64vec2);"
2790             "u64vec3  minInvocationsExclusiveScanNonUniformAMD(u64vec3);"
2791             "u64vec4  minInvocationsExclusiveScanNonUniformAMD(u64vec4);"
2792 
2793             "float16_t minInvocationsExclusiveScanNonUniformAMD(float16_t);"
2794             "f16vec2   minInvocationsExclusiveScanNonUniformAMD(f16vec2);"
2795             "f16vec3   minInvocationsExclusiveScanNonUniformAMD(f16vec3);"
2796             "f16vec4   minInvocationsExclusiveScanNonUniformAMD(f16vec4);"
2797 
2798             "int16_t minInvocationsExclusiveScanNonUniformAMD(int16_t);"
2799             "i16vec2 minInvocationsExclusiveScanNonUniformAMD(i16vec2);"
2800             "i16vec3 minInvocationsExclusiveScanNonUniformAMD(i16vec3);"
2801             "i16vec4 minInvocationsExclusiveScanNonUniformAMD(i16vec4);"
2802 
2803             "uint16_t minInvocationsExclusiveScanNonUniformAMD(uint16_t);"
2804             "u16vec2  minInvocationsExclusiveScanNonUniformAMD(u16vec2);"
2805             "u16vec3  minInvocationsExclusiveScanNonUniformAMD(u16vec3);"
2806             "u16vec4  minInvocationsExclusiveScanNonUniformAMD(u16vec4);"
2807 
2808             "float maxInvocationsNonUniformAMD(float);"
2809             "vec2  maxInvocationsNonUniformAMD(vec2);"
2810             "vec3  maxInvocationsNonUniformAMD(vec3);"
2811             "vec4  maxInvocationsNonUniformAMD(vec4);"
2812 
2813             "int   maxInvocationsNonUniformAMD(int);"
2814             "ivec2 maxInvocationsNonUniformAMD(ivec2);"
2815             "ivec3 maxInvocationsNonUniformAMD(ivec3);"
2816             "ivec4 maxInvocationsNonUniformAMD(ivec4);"
2817 
2818             "uint  maxInvocationsNonUniformAMD(uint);"
2819             "uvec2 maxInvocationsNonUniformAMD(uvec2);"
2820             "uvec3 maxInvocationsNonUniformAMD(uvec3);"
2821             "uvec4 maxInvocationsNonUniformAMD(uvec4);"
2822 
2823             "double maxInvocationsNonUniformAMD(double);"
2824             "dvec2  maxInvocationsNonUniformAMD(dvec2);"
2825             "dvec3  maxInvocationsNonUniformAMD(dvec3);"
2826             "dvec4  maxInvocationsNonUniformAMD(dvec4);"
2827 
2828             "int64_t maxInvocationsNonUniformAMD(int64_t);"
2829             "i64vec2 maxInvocationsNonUniformAMD(i64vec2);"
2830             "i64vec3 maxInvocationsNonUniformAMD(i64vec3);"
2831             "i64vec4 maxInvocationsNonUniformAMD(i64vec4);"
2832 
2833             "uint64_t maxInvocationsNonUniformAMD(uint64_t);"
2834             "u64vec2  maxInvocationsNonUniformAMD(u64vec2);"
2835             "u64vec3  maxInvocationsNonUniformAMD(u64vec3);"
2836             "u64vec4  maxInvocationsNonUniformAMD(u64vec4);"
2837 
2838             "float16_t maxInvocationsNonUniformAMD(float16_t);"
2839             "f16vec2   maxInvocationsNonUniformAMD(f16vec2);"
2840             "f16vec3   maxInvocationsNonUniformAMD(f16vec3);"
2841             "f16vec4   maxInvocationsNonUniformAMD(f16vec4);"
2842 
2843             "int16_t maxInvocationsNonUniformAMD(int16_t);"
2844             "i16vec2 maxInvocationsNonUniformAMD(i16vec2);"
2845             "i16vec3 maxInvocationsNonUniformAMD(i16vec3);"
2846             "i16vec4 maxInvocationsNonUniformAMD(i16vec4);"
2847 
2848             "uint16_t maxInvocationsNonUniformAMD(uint16_t);"
2849             "u16vec2  maxInvocationsNonUniformAMD(u16vec2);"
2850             "u16vec3  maxInvocationsNonUniformAMD(u16vec3);"
2851             "u16vec4  maxInvocationsNonUniformAMD(u16vec4);"
2852 
2853             "float maxInvocationsInclusiveScanNonUniformAMD(float);"
2854             "vec2  maxInvocationsInclusiveScanNonUniformAMD(vec2);"
2855             "vec3  maxInvocationsInclusiveScanNonUniformAMD(vec3);"
2856             "vec4  maxInvocationsInclusiveScanNonUniformAMD(vec4);"
2857 
2858             "int   maxInvocationsInclusiveScanNonUniformAMD(int);"
2859             "ivec2 maxInvocationsInclusiveScanNonUniformAMD(ivec2);"
2860             "ivec3 maxInvocationsInclusiveScanNonUniformAMD(ivec3);"
2861             "ivec4 maxInvocationsInclusiveScanNonUniformAMD(ivec4);"
2862 
2863             "uint  maxInvocationsInclusiveScanNonUniformAMD(uint);"
2864             "uvec2 maxInvocationsInclusiveScanNonUniformAMD(uvec2);"
2865             "uvec3 maxInvocationsInclusiveScanNonUniformAMD(uvec3);"
2866             "uvec4 maxInvocationsInclusiveScanNonUniformAMD(uvec4);"
2867 
2868             "double maxInvocationsInclusiveScanNonUniformAMD(double);"
2869             "dvec2  maxInvocationsInclusiveScanNonUniformAMD(dvec2);"
2870             "dvec3  maxInvocationsInclusiveScanNonUniformAMD(dvec3);"
2871             "dvec4  maxInvocationsInclusiveScanNonUniformAMD(dvec4);"
2872 
2873             "int64_t maxInvocationsInclusiveScanNonUniformAMD(int64_t);"
2874             "i64vec2 maxInvocationsInclusiveScanNonUniformAMD(i64vec2);"
2875             "i64vec3 maxInvocationsInclusiveScanNonUniformAMD(i64vec3);"
2876             "i64vec4 maxInvocationsInclusiveScanNonUniformAMD(i64vec4);"
2877 
2878             "uint64_t maxInvocationsInclusiveScanNonUniformAMD(uint64_t);"
2879             "u64vec2  maxInvocationsInclusiveScanNonUniformAMD(u64vec2);"
2880             "u64vec3  maxInvocationsInclusiveScanNonUniformAMD(u64vec3);"
2881             "u64vec4  maxInvocationsInclusiveScanNonUniformAMD(u64vec4);"
2882 
2883             "float16_t maxInvocationsInclusiveScanNonUniformAMD(float16_t);"
2884             "f16vec2   maxInvocationsInclusiveScanNonUniformAMD(f16vec2);"
2885             "f16vec3   maxInvocationsInclusiveScanNonUniformAMD(f16vec3);"
2886             "f16vec4   maxInvocationsInclusiveScanNonUniformAMD(f16vec4);"
2887 
2888             "int16_t maxInvocationsInclusiveScanNonUniformAMD(int16_t);"
2889             "i16vec2 maxInvocationsInclusiveScanNonUniformAMD(i16vec2);"
2890             "i16vec3 maxInvocationsInclusiveScanNonUniformAMD(i16vec3);"
2891             "i16vec4 maxInvocationsInclusiveScanNonUniformAMD(i16vec4);"
2892 
2893             "uint16_t maxInvocationsInclusiveScanNonUniformAMD(uint16_t);"
2894             "u16vec2  maxInvocationsInclusiveScanNonUniformAMD(u16vec2);"
2895             "u16vec3  maxInvocationsInclusiveScanNonUniformAMD(u16vec3);"
2896             "u16vec4  maxInvocationsInclusiveScanNonUniformAMD(u16vec4);"
2897 
2898             "float maxInvocationsExclusiveScanNonUniformAMD(float);"
2899             "vec2  maxInvocationsExclusiveScanNonUniformAMD(vec2);"
2900             "vec3  maxInvocationsExclusiveScanNonUniformAMD(vec3);"
2901             "vec4  maxInvocationsExclusiveScanNonUniformAMD(vec4);"
2902 
2903             "int   maxInvocationsExclusiveScanNonUniformAMD(int);"
2904             "ivec2 maxInvocationsExclusiveScanNonUniformAMD(ivec2);"
2905             "ivec3 maxInvocationsExclusiveScanNonUniformAMD(ivec3);"
2906             "ivec4 maxInvocationsExclusiveScanNonUniformAMD(ivec4);"
2907 
2908             "uint  maxInvocationsExclusiveScanNonUniformAMD(uint);"
2909             "uvec2 maxInvocationsExclusiveScanNonUniformAMD(uvec2);"
2910             "uvec3 maxInvocationsExclusiveScanNonUniformAMD(uvec3);"
2911             "uvec4 maxInvocationsExclusiveScanNonUniformAMD(uvec4);"
2912 
2913             "double maxInvocationsExclusiveScanNonUniformAMD(double);"
2914             "dvec2  maxInvocationsExclusiveScanNonUniformAMD(dvec2);"
2915             "dvec3  maxInvocationsExclusiveScanNonUniformAMD(dvec3);"
2916             "dvec4  maxInvocationsExclusiveScanNonUniformAMD(dvec4);"
2917 
2918             "int64_t maxInvocationsExclusiveScanNonUniformAMD(int64_t);"
2919             "i64vec2 maxInvocationsExclusiveScanNonUniformAMD(i64vec2);"
2920             "i64vec3 maxInvocationsExclusiveScanNonUniformAMD(i64vec3);"
2921             "i64vec4 maxInvocationsExclusiveScanNonUniformAMD(i64vec4);"
2922 
2923             "uint64_t maxInvocationsExclusiveScanNonUniformAMD(uint64_t);"
2924             "u64vec2  maxInvocationsExclusiveScanNonUniformAMD(u64vec2);"
2925             "u64vec3  maxInvocationsExclusiveScanNonUniformAMD(u64vec3);"
2926             "u64vec4  maxInvocationsExclusiveScanNonUniformAMD(u64vec4);"
2927 
2928             "float16_t maxInvocationsExclusiveScanNonUniformAMD(float16_t);"
2929             "f16vec2   maxInvocationsExclusiveScanNonUniformAMD(f16vec2);"
2930             "f16vec3   maxInvocationsExclusiveScanNonUniformAMD(f16vec3);"
2931             "f16vec4   maxInvocationsExclusiveScanNonUniformAMD(f16vec4);"
2932 
2933             "int16_t maxInvocationsExclusiveScanNonUniformAMD(int16_t);"
2934             "i16vec2 maxInvocationsExclusiveScanNonUniformAMD(i16vec2);"
2935             "i16vec3 maxInvocationsExclusiveScanNonUniformAMD(i16vec3);"
2936             "i16vec4 maxInvocationsExclusiveScanNonUniformAMD(i16vec4);"
2937 
2938             "uint16_t maxInvocationsExclusiveScanNonUniformAMD(uint16_t);"
2939             "u16vec2  maxInvocationsExclusiveScanNonUniformAMD(u16vec2);"
2940             "u16vec3  maxInvocationsExclusiveScanNonUniformAMD(u16vec3);"
2941             "u16vec4  maxInvocationsExclusiveScanNonUniformAMD(u16vec4);"
2942 
2943             "float addInvocationsNonUniformAMD(float);"
2944             "vec2  addInvocationsNonUniformAMD(vec2);"
2945             "vec3  addInvocationsNonUniformAMD(vec3);"
2946             "vec4  addInvocationsNonUniformAMD(vec4);"
2947 
2948             "int   addInvocationsNonUniformAMD(int);"
2949             "ivec2 addInvocationsNonUniformAMD(ivec2);"
2950             "ivec3 addInvocationsNonUniformAMD(ivec3);"
2951             "ivec4 addInvocationsNonUniformAMD(ivec4);"
2952 
2953             "uint  addInvocationsNonUniformAMD(uint);"
2954             "uvec2 addInvocationsNonUniformAMD(uvec2);"
2955             "uvec3 addInvocationsNonUniformAMD(uvec3);"
2956             "uvec4 addInvocationsNonUniformAMD(uvec4);"
2957 
2958             "double addInvocationsNonUniformAMD(double);"
2959             "dvec2  addInvocationsNonUniformAMD(dvec2);"
2960             "dvec3  addInvocationsNonUniformAMD(dvec3);"
2961             "dvec4  addInvocationsNonUniformAMD(dvec4);"
2962 
2963             "int64_t addInvocationsNonUniformAMD(int64_t);"
2964             "i64vec2 addInvocationsNonUniformAMD(i64vec2);"
2965             "i64vec3 addInvocationsNonUniformAMD(i64vec3);"
2966             "i64vec4 addInvocationsNonUniformAMD(i64vec4);"
2967 
2968             "uint64_t addInvocationsNonUniformAMD(uint64_t);"
2969             "u64vec2  addInvocationsNonUniformAMD(u64vec2);"
2970             "u64vec3  addInvocationsNonUniformAMD(u64vec3);"
2971             "u64vec4  addInvocationsNonUniformAMD(u64vec4);"
2972 
2973             "float16_t addInvocationsNonUniformAMD(float16_t);"
2974             "f16vec2   addInvocationsNonUniformAMD(f16vec2);"
2975             "f16vec3   addInvocationsNonUniformAMD(f16vec3);"
2976             "f16vec4   addInvocationsNonUniformAMD(f16vec4);"
2977 
2978             "int16_t addInvocationsNonUniformAMD(int16_t);"
2979             "i16vec2 addInvocationsNonUniformAMD(i16vec2);"
2980             "i16vec3 addInvocationsNonUniformAMD(i16vec3);"
2981             "i16vec4 addInvocationsNonUniformAMD(i16vec4);"
2982 
2983             "uint16_t addInvocationsNonUniformAMD(uint16_t);"
2984             "u16vec2  addInvocationsNonUniformAMD(u16vec2);"
2985             "u16vec3  addInvocationsNonUniformAMD(u16vec3);"
2986             "u16vec4  addInvocationsNonUniformAMD(u16vec4);"
2987 
2988             "float addInvocationsInclusiveScanNonUniformAMD(float);"
2989             "vec2  addInvocationsInclusiveScanNonUniformAMD(vec2);"
2990             "vec3  addInvocationsInclusiveScanNonUniformAMD(vec3);"
2991             "vec4  addInvocationsInclusiveScanNonUniformAMD(vec4);"
2992 
2993             "int   addInvocationsInclusiveScanNonUniformAMD(int);"
2994             "ivec2 addInvocationsInclusiveScanNonUniformAMD(ivec2);"
2995             "ivec3 addInvocationsInclusiveScanNonUniformAMD(ivec3);"
2996             "ivec4 addInvocationsInclusiveScanNonUniformAMD(ivec4);"
2997 
2998             "uint  addInvocationsInclusiveScanNonUniformAMD(uint);"
2999             "uvec2 addInvocationsInclusiveScanNonUniformAMD(uvec2);"
3000             "uvec3 addInvocationsInclusiveScanNonUniformAMD(uvec3);"
3001             "uvec4 addInvocationsInclusiveScanNonUniformAMD(uvec4);"
3002 
3003             "double addInvocationsInclusiveScanNonUniformAMD(double);"
3004             "dvec2  addInvocationsInclusiveScanNonUniformAMD(dvec2);"
3005             "dvec3  addInvocationsInclusiveScanNonUniformAMD(dvec3);"
3006             "dvec4  addInvocationsInclusiveScanNonUniformAMD(dvec4);"
3007 
3008             "int64_t addInvocationsInclusiveScanNonUniformAMD(int64_t);"
3009             "i64vec2 addInvocationsInclusiveScanNonUniformAMD(i64vec2);"
3010             "i64vec3 addInvocationsInclusiveScanNonUniformAMD(i64vec3);"
3011             "i64vec4 addInvocationsInclusiveScanNonUniformAMD(i64vec4);"
3012 
3013             "uint64_t addInvocationsInclusiveScanNonUniformAMD(uint64_t);"
3014             "u64vec2  addInvocationsInclusiveScanNonUniformAMD(u64vec2);"
3015             "u64vec3  addInvocationsInclusiveScanNonUniformAMD(u64vec3);"
3016             "u64vec4  addInvocationsInclusiveScanNonUniformAMD(u64vec4);"
3017 
3018             "float16_t addInvocationsInclusiveScanNonUniformAMD(float16_t);"
3019             "f16vec2   addInvocationsInclusiveScanNonUniformAMD(f16vec2);"
3020             "f16vec3   addInvocationsInclusiveScanNonUniformAMD(f16vec3);"
3021             "f16vec4   addInvocationsInclusiveScanNonUniformAMD(f16vec4);"
3022 
3023             "int16_t addInvocationsInclusiveScanNonUniformAMD(int16_t);"
3024             "i16vec2 addInvocationsInclusiveScanNonUniformAMD(i16vec2);"
3025             "i16vec3 addInvocationsInclusiveScanNonUniformAMD(i16vec3);"
3026             "i16vec4 addInvocationsInclusiveScanNonUniformAMD(i16vec4);"
3027 
3028             "uint16_t addInvocationsInclusiveScanNonUniformAMD(uint16_t);"
3029             "u16vec2  addInvocationsInclusiveScanNonUniformAMD(u16vec2);"
3030             "u16vec3  addInvocationsInclusiveScanNonUniformAMD(u16vec3);"
3031             "u16vec4  addInvocationsInclusiveScanNonUniformAMD(u16vec4);"
3032 
3033             "float addInvocationsExclusiveScanNonUniformAMD(float);"
3034             "vec2  addInvocationsExclusiveScanNonUniformAMD(vec2);"
3035             "vec3  addInvocationsExclusiveScanNonUniformAMD(vec3);"
3036             "vec4  addInvocationsExclusiveScanNonUniformAMD(vec4);"
3037 
3038             "int   addInvocationsExclusiveScanNonUniformAMD(int);"
3039             "ivec2 addInvocationsExclusiveScanNonUniformAMD(ivec2);"
3040             "ivec3 addInvocationsExclusiveScanNonUniformAMD(ivec3);"
3041             "ivec4 addInvocationsExclusiveScanNonUniformAMD(ivec4);"
3042 
3043             "uint  addInvocationsExclusiveScanNonUniformAMD(uint);"
3044             "uvec2 addInvocationsExclusiveScanNonUniformAMD(uvec2);"
3045             "uvec3 addInvocationsExclusiveScanNonUniformAMD(uvec3);"
3046             "uvec4 addInvocationsExclusiveScanNonUniformAMD(uvec4);"
3047 
3048             "double addInvocationsExclusiveScanNonUniformAMD(double);"
3049             "dvec2  addInvocationsExclusiveScanNonUniformAMD(dvec2);"
3050             "dvec3  addInvocationsExclusiveScanNonUniformAMD(dvec3);"
3051             "dvec4  addInvocationsExclusiveScanNonUniformAMD(dvec4);"
3052 
3053             "int64_t addInvocationsExclusiveScanNonUniformAMD(int64_t);"
3054             "i64vec2 addInvocationsExclusiveScanNonUniformAMD(i64vec2);"
3055             "i64vec3 addInvocationsExclusiveScanNonUniformAMD(i64vec3);"
3056             "i64vec4 addInvocationsExclusiveScanNonUniformAMD(i64vec4);"
3057 
3058             "uint64_t addInvocationsExclusiveScanNonUniformAMD(uint64_t);"
3059             "u64vec2  addInvocationsExclusiveScanNonUniformAMD(u64vec2);"
3060             "u64vec3  addInvocationsExclusiveScanNonUniformAMD(u64vec3);"
3061             "u64vec4  addInvocationsExclusiveScanNonUniformAMD(u64vec4);"
3062 
3063             "float16_t addInvocationsExclusiveScanNonUniformAMD(float16_t);"
3064             "f16vec2   addInvocationsExclusiveScanNonUniformAMD(f16vec2);"
3065             "f16vec3   addInvocationsExclusiveScanNonUniformAMD(f16vec3);"
3066             "f16vec4   addInvocationsExclusiveScanNonUniformAMD(f16vec4);"
3067 
3068             "int16_t addInvocationsExclusiveScanNonUniformAMD(int16_t);"
3069             "i16vec2 addInvocationsExclusiveScanNonUniformAMD(i16vec2);"
3070             "i16vec3 addInvocationsExclusiveScanNonUniformAMD(i16vec3);"
3071             "i16vec4 addInvocationsExclusiveScanNonUniformAMD(i16vec4);"
3072 
3073             "uint16_t addInvocationsExclusiveScanNonUniformAMD(uint16_t);"
3074             "u16vec2  addInvocationsExclusiveScanNonUniformAMD(u16vec2);"
3075             "u16vec3  addInvocationsExclusiveScanNonUniformAMD(u16vec3);"
3076             "u16vec4  addInvocationsExclusiveScanNonUniformAMD(u16vec4);"
3077 
3078             "float swizzleInvocationsAMD(float, uvec4);"
3079             "vec2  swizzleInvocationsAMD(vec2,  uvec4);"
3080             "vec3  swizzleInvocationsAMD(vec3,  uvec4);"
3081             "vec4  swizzleInvocationsAMD(vec4,  uvec4);"
3082 
3083             "int   swizzleInvocationsAMD(int,   uvec4);"
3084             "ivec2 swizzleInvocationsAMD(ivec2, uvec4);"
3085             "ivec3 swizzleInvocationsAMD(ivec3, uvec4);"
3086             "ivec4 swizzleInvocationsAMD(ivec4, uvec4);"
3087 
3088             "uint  swizzleInvocationsAMD(uint,  uvec4);"
3089             "uvec2 swizzleInvocationsAMD(uvec2, uvec4);"
3090             "uvec3 swizzleInvocationsAMD(uvec3, uvec4);"
3091             "uvec4 swizzleInvocationsAMD(uvec4, uvec4);"
3092 
3093             "float swizzleInvocationsMaskedAMD(float, uvec3);"
3094             "vec2  swizzleInvocationsMaskedAMD(vec2,  uvec3);"
3095             "vec3  swizzleInvocationsMaskedAMD(vec3,  uvec3);"
3096             "vec4  swizzleInvocationsMaskedAMD(vec4,  uvec3);"
3097 
3098             "int   swizzleInvocationsMaskedAMD(int,   uvec3);"
3099             "ivec2 swizzleInvocationsMaskedAMD(ivec2, uvec3);"
3100             "ivec3 swizzleInvocationsMaskedAMD(ivec3, uvec3);"
3101             "ivec4 swizzleInvocationsMaskedAMD(ivec4, uvec3);"
3102 
3103             "uint  swizzleInvocationsMaskedAMD(uint,  uvec3);"
3104             "uvec2 swizzleInvocationsMaskedAMD(uvec2, uvec3);"
3105             "uvec3 swizzleInvocationsMaskedAMD(uvec3, uvec3);"
3106             "uvec4 swizzleInvocationsMaskedAMD(uvec4, uvec3);"
3107 
3108             "float writeInvocationAMD(float, float, uint);"
3109             "vec2  writeInvocationAMD(vec2,  vec2,  uint);"
3110             "vec3  writeInvocationAMD(vec3,  vec3,  uint);"
3111             "vec4  writeInvocationAMD(vec4,  vec4,  uint);"
3112 
3113             "int   writeInvocationAMD(int,   int,   uint);"
3114             "ivec2 writeInvocationAMD(ivec2, ivec2, uint);"
3115             "ivec3 writeInvocationAMD(ivec3, ivec3, uint);"
3116             "ivec4 writeInvocationAMD(ivec4, ivec4, uint);"
3117 
3118             "uint  writeInvocationAMD(uint,  uint,  uint);"
3119             "uvec2 writeInvocationAMD(uvec2, uvec2, uint);"
3120             "uvec3 writeInvocationAMD(uvec3, uvec3, uint);"
3121             "uvec4 writeInvocationAMD(uvec4, uvec4, uint);"
3122 
3123             "uint mbcntAMD(uint64_t);"
3124 
3125             "\n");
3126     }
3127 
3128     // GL_AMD_gcn_shader
3129     if (profile != EEsProfile && version >= 440) {
3130         commonBuiltins.append(
3131             "float cubeFaceIndexAMD(vec3);"
3132             "vec2  cubeFaceCoordAMD(vec3);"
3133             "uint64_t timeAMD();"
3134 
3135             "in int gl_SIMDGroupSizeAMD;"
3136             "\n");
3137     }
3138 
3139     // GL_AMD_shader_fragment_mask
3140     if (profile != EEsProfile && version >= 450) {
3141         commonBuiltins.append(
3142             "uint fragmentMaskFetchAMD(sampler2DMS,       ivec2);"
3143             "uint fragmentMaskFetchAMD(isampler2DMS,      ivec2);"
3144             "uint fragmentMaskFetchAMD(usampler2DMS,      ivec2);"
3145 
3146             "uint fragmentMaskFetchAMD(sampler2DMSArray,  ivec3);"
3147             "uint fragmentMaskFetchAMD(isampler2DMSArray, ivec3);"
3148             "uint fragmentMaskFetchAMD(usampler2DMSArray, ivec3);"
3149 
3150             "vec4  fragmentFetchAMD(sampler2DMS,       ivec2, uint);"
3151             "ivec4 fragmentFetchAMD(isampler2DMS,      ivec2, uint);"
3152             "uvec4 fragmentFetchAMD(usampler2DMS,      ivec2, uint);"
3153 
3154             "vec4  fragmentFetchAMD(sampler2DMSArray,  ivec3, uint);"
3155             "ivec4 fragmentFetchAMD(isampler2DMSArray, ivec3, uint);"
3156             "uvec4 fragmentFetchAMD(usampler2DMSArray, ivec3, uint);"
3157 
3158             "\n");
3159     }
3160 
3161     if ((profile != EEsProfile && version >= 130) ||
3162         (profile == EEsProfile && version >= 300)) {
3163         commonBuiltins.append(
3164             "uint countLeadingZeros(uint);"
3165             "uvec2 countLeadingZeros(uvec2);"
3166             "uvec3 countLeadingZeros(uvec3);"
3167             "uvec4 countLeadingZeros(uvec4);"
3168 
3169             "uint countTrailingZeros(uint);"
3170             "uvec2 countTrailingZeros(uvec2);"
3171             "uvec3 countTrailingZeros(uvec3);"
3172             "uvec4 countTrailingZeros(uvec4);"
3173 
3174             "uint absoluteDifference(int, int);"
3175             "uvec2 absoluteDifference(ivec2, ivec2);"
3176             "uvec3 absoluteDifference(ivec3, ivec3);"
3177             "uvec4 absoluteDifference(ivec4, ivec4);"
3178 
3179             "uint16_t absoluteDifference(int16_t, int16_t);"
3180             "u16vec2 absoluteDifference(i16vec2, i16vec2);"
3181             "u16vec3 absoluteDifference(i16vec3, i16vec3);"
3182             "u16vec4 absoluteDifference(i16vec4, i16vec4);"
3183 
3184             "uint64_t absoluteDifference(int64_t, int64_t);"
3185             "u64vec2 absoluteDifference(i64vec2, i64vec2);"
3186             "u64vec3 absoluteDifference(i64vec3, i64vec3);"
3187             "u64vec4 absoluteDifference(i64vec4, i64vec4);"
3188 
3189             "uint absoluteDifference(uint, uint);"
3190             "uvec2 absoluteDifference(uvec2, uvec2);"
3191             "uvec3 absoluteDifference(uvec3, uvec3);"
3192             "uvec4 absoluteDifference(uvec4, uvec4);"
3193 
3194             "uint16_t absoluteDifference(uint16_t, uint16_t);"
3195             "u16vec2 absoluteDifference(u16vec2, u16vec2);"
3196             "u16vec3 absoluteDifference(u16vec3, u16vec3);"
3197             "u16vec4 absoluteDifference(u16vec4, u16vec4);"
3198 
3199             "uint64_t absoluteDifference(uint64_t, uint64_t);"
3200             "u64vec2 absoluteDifference(u64vec2, u64vec2);"
3201             "u64vec3 absoluteDifference(u64vec3, u64vec3);"
3202             "u64vec4 absoluteDifference(u64vec4, u64vec4);"
3203 
3204             "int addSaturate(int, int);"
3205             "ivec2 addSaturate(ivec2, ivec2);"
3206             "ivec3 addSaturate(ivec3, ivec3);"
3207             "ivec4 addSaturate(ivec4, ivec4);"
3208 
3209             "int16_t addSaturate(int16_t, int16_t);"
3210             "i16vec2 addSaturate(i16vec2, i16vec2);"
3211             "i16vec3 addSaturate(i16vec3, i16vec3);"
3212             "i16vec4 addSaturate(i16vec4, i16vec4);"
3213 
3214             "int64_t addSaturate(int64_t, int64_t);"
3215             "i64vec2 addSaturate(i64vec2, i64vec2);"
3216             "i64vec3 addSaturate(i64vec3, i64vec3);"
3217             "i64vec4 addSaturate(i64vec4, i64vec4);"
3218 
3219             "uint addSaturate(uint, uint);"
3220             "uvec2 addSaturate(uvec2, uvec2);"
3221             "uvec3 addSaturate(uvec3, uvec3);"
3222             "uvec4 addSaturate(uvec4, uvec4);"
3223 
3224             "uint16_t addSaturate(uint16_t, uint16_t);"
3225             "u16vec2 addSaturate(u16vec2, u16vec2);"
3226             "u16vec3 addSaturate(u16vec3, u16vec3);"
3227             "u16vec4 addSaturate(u16vec4, u16vec4);"
3228 
3229             "uint64_t addSaturate(uint64_t, uint64_t);"
3230             "u64vec2 addSaturate(u64vec2, u64vec2);"
3231             "u64vec3 addSaturate(u64vec3, u64vec3);"
3232             "u64vec4 addSaturate(u64vec4, u64vec4);"
3233 
3234             "int subtractSaturate(int, int);"
3235             "ivec2 subtractSaturate(ivec2, ivec2);"
3236             "ivec3 subtractSaturate(ivec3, ivec3);"
3237             "ivec4 subtractSaturate(ivec4, ivec4);"
3238 
3239             "int16_t subtractSaturate(int16_t, int16_t);"
3240             "i16vec2 subtractSaturate(i16vec2, i16vec2);"
3241             "i16vec3 subtractSaturate(i16vec3, i16vec3);"
3242             "i16vec4 subtractSaturate(i16vec4, i16vec4);"
3243 
3244             "int64_t subtractSaturate(int64_t, int64_t);"
3245             "i64vec2 subtractSaturate(i64vec2, i64vec2);"
3246             "i64vec3 subtractSaturate(i64vec3, i64vec3);"
3247             "i64vec4 subtractSaturate(i64vec4, i64vec4);"
3248 
3249             "uint subtractSaturate(uint, uint);"
3250             "uvec2 subtractSaturate(uvec2, uvec2);"
3251             "uvec3 subtractSaturate(uvec3, uvec3);"
3252             "uvec4 subtractSaturate(uvec4, uvec4);"
3253 
3254             "uint16_t subtractSaturate(uint16_t, uint16_t);"
3255             "u16vec2 subtractSaturate(u16vec2, u16vec2);"
3256             "u16vec3 subtractSaturate(u16vec3, u16vec3);"
3257             "u16vec4 subtractSaturate(u16vec4, u16vec4);"
3258 
3259             "uint64_t subtractSaturate(uint64_t, uint64_t);"
3260             "u64vec2 subtractSaturate(u64vec2, u64vec2);"
3261             "u64vec3 subtractSaturate(u64vec3, u64vec3);"
3262             "u64vec4 subtractSaturate(u64vec4, u64vec4);"
3263 
3264             "int average(int, int);"
3265             "ivec2 average(ivec2, ivec2);"
3266             "ivec3 average(ivec3, ivec3);"
3267             "ivec4 average(ivec4, ivec4);"
3268 
3269             "int16_t average(int16_t, int16_t);"
3270             "i16vec2 average(i16vec2, i16vec2);"
3271             "i16vec3 average(i16vec3, i16vec3);"
3272             "i16vec4 average(i16vec4, i16vec4);"
3273 
3274             "int64_t average(int64_t, int64_t);"
3275             "i64vec2 average(i64vec2, i64vec2);"
3276             "i64vec3 average(i64vec3, i64vec3);"
3277             "i64vec4 average(i64vec4, i64vec4);"
3278 
3279             "uint average(uint, uint);"
3280             "uvec2 average(uvec2, uvec2);"
3281             "uvec3 average(uvec3, uvec3);"
3282             "uvec4 average(uvec4, uvec4);"
3283 
3284             "uint16_t average(uint16_t, uint16_t);"
3285             "u16vec2 average(u16vec2, u16vec2);"
3286             "u16vec3 average(u16vec3, u16vec3);"
3287             "u16vec4 average(u16vec4, u16vec4);"
3288 
3289             "uint64_t average(uint64_t, uint64_t);"
3290             "u64vec2 average(u64vec2, u64vec2);"
3291             "u64vec3 average(u64vec3, u64vec3);"
3292             "u64vec4 average(u64vec4, u64vec4);"
3293 
3294             "int averageRounded(int, int);"
3295             "ivec2 averageRounded(ivec2, ivec2);"
3296             "ivec3 averageRounded(ivec3, ivec3);"
3297             "ivec4 averageRounded(ivec4, ivec4);"
3298 
3299             "int16_t averageRounded(int16_t, int16_t);"
3300             "i16vec2 averageRounded(i16vec2, i16vec2);"
3301             "i16vec3 averageRounded(i16vec3, i16vec3);"
3302             "i16vec4 averageRounded(i16vec4, i16vec4);"
3303 
3304             "int64_t averageRounded(int64_t, int64_t);"
3305             "i64vec2 averageRounded(i64vec2, i64vec2);"
3306             "i64vec3 averageRounded(i64vec3, i64vec3);"
3307             "i64vec4 averageRounded(i64vec4, i64vec4);"
3308 
3309             "uint averageRounded(uint, uint);"
3310             "uvec2 averageRounded(uvec2, uvec2);"
3311             "uvec3 averageRounded(uvec3, uvec3);"
3312             "uvec4 averageRounded(uvec4, uvec4);"
3313 
3314             "uint16_t averageRounded(uint16_t, uint16_t);"
3315             "u16vec2 averageRounded(u16vec2, u16vec2);"
3316             "u16vec3 averageRounded(u16vec3, u16vec3);"
3317             "u16vec4 averageRounded(u16vec4, u16vec4);"
3318 
3319             "uint64_t averageRounded(uint64_t, uint64_t);"
3320             "u64vec2 averageRounded(u64vec2, u64vec2);"
3321             "u64vec3 averageRounded(u64vec3, u64vec3);"
3322             "u64vec4 averageRounded(u64vec4, u64vec4);"
3323 
3324             "int multiply32x16(int, int);"
3325             "ivec2 multiply32x16(ivec2, ivec2);"
3326             "ivec3 multiply32x16(ivec3, ivec3);"
3327             "ivec4 multiply32x16(ivec4, ivec4);"
3328 
3329             "uint multiply32x16(uint, uint);"
3330             "uvec2 multiply32x16(uvec2, uvec2);"
3331             "uvec3 multiply32x16(uvec3, uvec3);"
3332             "uvec4 multiply32x16(uvec4, uvec4);"
3333             "\n");
3334     }
3335 
3336     if ((profile != EEsProfile && version >= 450) ||
3337         (profile == EEsProfile && version >= 320)) {
3338         commonBuiltins.append(
3339             "struct gl_TextureFootprint2DNV {"
3340                 "uvec2 anchor;"
3341                 "uvec2 offset;"
3342                 "uvec2 mask;"
3343                 "uint lod;"
3344                 "uint granularity;"
3345             "};"
3346 
3347             "struct gl_TextureFootprint3DNV {"
3348                 "uvec3 anchor;"
3349                 "uvec3 offset;"
3350                 "uvec2 mask;"
3351                 "uint lod;"
3352                 "uint granularity;"
3353             "};"
3354             "bool textureFootprintNV(sampler2D, vec2, int, bool, out gl_TextureFootprint2DNV);"
3355             "bool textureFootprintNV(sampler3D, vec3, int, bool, out gl_TextureFootprint3DNV);"
3356             "bool textureFootprintNV(sampler2D, vec2, int, bool, out gl_TextureFootprint2DNV, float);"
3357             "bool textureFootprintNV(sampler3D, vec3, int, bool, out gl_TextureFootprint3DNV, float);"
3358             "bool textureFootprintClampNV(sampler2D, vec2, float, int, bool, out gl_TextureFootprint2DNV);"
3359             "bool textureFootprintClampNV(sampler3D, vec3, float, int, bool, out gl_TextureFootprint3DNV);"
3360             "bool textureFootprintClampNV(sampler2D, vec2, float, int, bool, out gl_TextureFootprint2DNV, float);"
3361             "bool textureFootprintClampNV(sampler3D, vec3, float, int, bool, out gl_TextureFootprint3DNV, float);"
3362             "bool textureFootprintLodNV(sampler2D, vec2, float, int, bool, out gl_TextureFootprint2DNV);"
3363             "bool textureFootprintLodNV(sampler3D, vec3, float, int, bool, out gl_TextureFootprint3DNV);"
3364             "bool textureFootprintGradNV(sampler2D, vec2, vec2, vec2, int, bool, out gl_TextureFootprint2DNV);"
3365             "bool textureFootprintGradClampNV(sampler2D, vec2, vec2, vec2, float, int, bool, out gl_TextureFootprint2DNV);"
3366             "\n");
3367     }
3368 
3369     if ((profile == EEsProfile && version >= 300 && version < 310) ||
3370         (profile != EEsProfile && version >= 150 && version < 450)) { // GL_EXT_shader_integer_mix
3371         commonBuiltins.append("int mix(int, int, bool);"
3372                               "ivec2 mix(ivec2, ivec2, bvec2);"
3373                               "ivec3 mix(ivec3, ivec3, bvec3);"
3374                               "ivec4 mix(ivec4, ivec4, bvec4);"
3375                               "uint  mix(uint,  uint,  bool );"
3376                               "uvec2 mix(uvec2, uvec2, bvec2);"
3377                               "uvec3 mix(uvec3, uvec3, bvec3);"
3378                               "uvec4 mix(uvec4, uvec4, bvec4);"
3379                               "bool  mix(bool,  bool,  bool );"
3380                               "bvec2 mix(bvec2, bvec2, bvec2);"
3381                               "bvec3 mix(bvec3, bvec3, bvec3);"
3382                               "bvec4 mix(bvec4, bvec4, bvec4);"
3383 
3384                               "\n");
3385     }
3386 
3387     // GL_AMD_gpu_shader_half_float/Explicit types
3388     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
3389         commonBuiltins.append(
3390             "float16_t radians(float16_t);"
3391             "f16vec2   radians(f16vec2);"
3392             "f16vec3   radians(f16vec3);"
3393             "f16vec4   radians(f16vec4);"
3394 
3395             "float16_t degrees(float16_t);"
3396             "f16vec2   degrees(f16vec2);"
3397             "f16vec3   degrees(f16vec3);"
3398             "f16vec4   degrees(f16vec4);"
3399 
3400             "float16_t sin(float16_t);"
3401             "f16vec2   sin(f16vec2);"
3402             "f16vec3   sin(f16vec3);"
3403             "f16vec4   sin(f16vec4);"
3404 
3405             "float16_t cos(float16_t);"
3406             "f16vec2   cos(f16vec2);"
3407             "f16vec3   cos(f16vec3);"
3408             "f16vec4   cos(f16vec4);"
3409 
3410             "float16_t tan(float16_t);"
3411             "f16vec2   tan(f16vec2);"
3412             "f16vec3   tan(f16vec3);"
3413             "f16vec4   tan(f16vec4);"
3414 
3415             "float16_t asin(float16_t);"
3416             "f16vec2   asin(f16vec2);"
3417             "f16vec3   asin(f16vec3);"
3418             "f16vec4   asin(f16vec4);"
3419 
3420             "float16_t acos(float16_t);"
3421             "f16vec2   acos(f16vec2);"
3422             "f16vec3   acos(f16vec3);"
3423             "f16vec4   acos(f16vec4);"
3424 
3425             "float16_t atan(float16_t, float16_t);"
3426             "f16vec2   atan(f16vec2,   f16vec2);"
3427             "f16vec3   atan(f16vec3,   f16vec3);"
3428             "f16vec4   atan(f16vec4,   f16vec4);"
3429 
3430             "float16_t atan(float16_t);"
3431             "f16vec2   atan(f16vec2);"
3432             "f16vec3   atan(f16vec3);"
3433             "f16vec4   atan(f16vec4);"
3434 
3435             "float16_t sinh(float16_t);"
3436             "f16vec2   sinh(f16vec2);"
3437             "f16vec3   sinh(f16vec3);"
3438             "f16vec4   sinh(f16vec4);"
3439 
3440             "float16_t cosh(float16_t);"
3441             "f16vec2   cosh(f16vec2);"
3442             "f16vec3   cosh(f16vec3);"
3443             "f16vec4   cosh(f16vec4);"
3444 
3445             "float16_t tanh(float16_t);"
3446             "f16vec2   tanh(f16vec2);"
3447             "f16vec3   tanh(f16vec3);"
3448             "f16vec4   tanh(f16vec4);"
3449 
3450             "float16_t asinh(float16_t);"
3451             "f16vec2   asinh(f16vec2);"
3452             "f16vec3   asinh(f16vec3);"
3453             "f16vec4   asinh(f16vec4);"
3454 
3455             "float16_t acosh(float16_t);"
3456             "f16vec2   acosh(f16vec2);"
3457             "f16vec3   acosh(f16vec3);"
3458             "f16vec4   acosh(f16vec4);"
3459 
3460             "float16_t atanh(float16_t);"
3461             "f16vec2   atanh(f16vec2);"
3462             "f16vec3   atanh(f16vec3);"
3463             "f16vec4   atanh(f16vec4);"
3464 
3465             "float16_t pow(float16_t, float16_t);"
3466             "f16vec2   pow(f16vec2,   f16vec2);"
3467             "f16vec3   pow(f16vec3,   f16vec3);"
3468             "f16vec4   pow(f16vec4,   f16vec4);"
3469 
3470             "float16_t exp(float16_t);"
3471             "f16vec2   exp(f16vec2);"
3472             "f16vec3   exp(f16vec3);"
3473             "f16vec4   exp(f16vec4);"
3474 
3475             "float16_t log(float16_t);"
3476             "f16vec2   log(f16vec2);"
3477             "f16vec3   log(f16vec3);"
3478             "f16vec4   log(f16vec4);"
3479 
3480             "float16_t exp2(float16_t);"
3481             "f16vec2   exp2(f16vec2);"
3482             "f16vec3   exp2(f16vec3);"
3483             "f16vec4   exp2(f16vec4);"
3484 
3485             "float16_t log2(float16_t);"
3486             "f16vec2   log2(f16vec2);"
3487             "f16vec3   log2(f16vec3);"
3488             "f16vec4   log2(f16vec4);"
3489 
3490             "float16_t sqrt(float16_t);"
3491             "f16vec2   sqrt(f16vec2);"
3492             "f16vec3   sqrt(f16vec3);"
3493             "f16vec4   sqrt(f16vec4);"
3494 
3495             "float16_t inversesqrt(float16_t);"
3496             "f16vec2   inversesqrt(f16vec2);"
3497             "f16vec3   inversesqrt(f16vec3);"
3498             "f16vec4   inversesqrt(f16vec4);"
3499 
3500             "float16_t abs(float16_t);"
3501             "f16vec2   abs(f16vec2);"
3502             "f16vec3   abs(f16vec3);"
3503             "f16vec4   abs(f16vec4);"
3504 
3505             "float16_t sign(float16_t);"
3506             "f16vec2   sign(f16vec2);"
3507             "f16vec3   sign(f16vec3);"
3508             "f16vec4   sign(f16vec4);"
3509 
3510             "float16_t floor(float16_t);"
3511             "f16vec2   floor(f16vec2);"
3512             "f16vec3   floor(f16vec3);"
3513             "f16vec4   floor(f16vec4);"
3514 
3515             "float16_t trunc(float16_t);"
3516             "f16vec2   trunc(f16vec2);"
3517             "f16vec3   trunc(f16vec3);"
3518             "f16vec4   trunc(f16vec4);"
3519 
3520             "float16_t round(float16_t);"
3521             "f16vec2   round(f16vec2);"
3522             "f16vec3   round(f16vec3);"
3523             "f16vec4   round(f16vec4);"
3524 
3525             "float16_t roundEven(float16_t);"
3526             "f16vec2   roundEven(f16vec2);"
3527             "f16vec3   roundEven(f16vec3);"
3528             "f16vec4   roundEven(f16vec4);"
3529 
3530             "float16_t ceil(float16_t);"
3531             "f16vec2   ceil(f16vec2);"
3532             "f16vec3   ceil(f16vec3);"
3533             "f16vec4   ceil(f16vec4);"
3534 
3535             "float16_t fract(float16_t);"
3536             "f16vec2   fract(f16vec2);"
3537             "f16vec3   fract(f16vec3);"
3538             "f16vec4   fract(f16vec4);"
3539 
3540             "float16_t mod(float16_t, float16_t);"
3541             "f16vec2   mod(f16vec2,   float16_t);"
3542             "f16vec3   mod(f16vec3,   float16_t);"
3543             "f16vec4   mod(f16vec4,   float16_t);"
3544             "f16vec2   mod(f16vec2,   f16vec2);"
3545             "f16vec3   mod(f16vec3,   f16vec3);"
3546             "f16vec4   mod(f16vec4,   f16vec4);"
3547 
3548             "float16_t modf(float16_t, out float16_t);"
3549             "f16vec2   modf(f16vec2,   out f16vec2);"
3550             "f16vec3   modf(f16vec3,   out f16vec3);"
3551             "f16vec4   modf(f16vec4,   out f16vec4);"
3552 
3553             "float16_t min(float16_t, float16_t);"
3554             "f16vec2   min(f16vec2,   float16_t);"
3555             "f16vec3   min(f16vec3,   float16_t);"
3556             "f16vec4   min(f16vec4,   float16_t);"
3557             "f16vec2   min(f16vec2,   f16vec2);"
3558             "f16vec3   min(f16vec3,   f16vec3);"
3559             "f16vec4   min(f16vec4,   f16vec4);"
3560 
3561             "float16_t max(float16_t, float16_t);"
3562             "f16vec2   max(f16vec2,   float16_t);"
3563             "f16vec3   max(f16vec3,   float16_t);"
3564             "f16vec4   max(f16vec4,   float16_t);"
3565             "f16vec2   max(f16vec2,   f16vec2);"
3566             "f16vec3   max(f16vec3,   f16vec3);"
3567             "f16vec4   max(f16vec4,   f16vec4);"
3568 
3569             "float16_t clamp(float16_t, float16_t, float16_t);"
3570             "f16vec2   clamp(f16vec2,   float16_t, float16_t);"
3571             "f16vec3   clamp(f16vec3,   float16_t, float16_t);"
3572             "f16vec4   clamp(f16vec4,   float16_t, float16_t);"
3573             "f16vec2   clamp(f16vec2,   f16vec2,   f16vec2);"
3574             "f16vec3   clamp(f16vec3,   f16vec3,   f16vec3);"
3575             "f16vec4   clamp(f16vec4,   f16vec4,   f16vec4);"
3576 
3577             "float16_t mix(float16_t, float16_t, float16_t);"
3578             "f16vec2   mix(f16vec2,   f16vec2,   float16_t);"
3579             "f16vec3   mix(f16vec3,   f16vec3,   float16_t);"
3580             "f16vec4   mix(f16vec4,   f16vec4,   float16_t);"
3581             "f16vec2   mix(f16vec2,   f16vec2,   f16vec2);"
3582             "f16vec3   mix(f16vec3,   f16vec3,   f16vec3);"
3583             "f16vec4   mix(f16vec4,   f16vec4,   f16vec4);"
3584             "float16_t mix(float16_t, float16_t, bool);"
3585             "f16vec2   mix(f16vec2,   f16vec2,   bvec2);"
3586             "f16vec3   mix(f16vec3,   f16vec3,   bvec3);"
3587             "f16vec4   mix(f16vec4,   f16vec4,   bvec4);"
3588 
3589             "float16_t step(float16_t, float16_t);"
3590             "f16vec2   step(f16vec2,   f16vec2);"
3591             "f16vec3   step(f16vec3,   f16vec3);"
3592             "f16vec4   step(f16vec4,   f16vec4);"
3593             "f16vec2   step(float16_t, f16vec2);"
3594             "f16vec3   step(float16_t, f16vec3);"
3595             "f16vec4   step(float16_t, f16vec4);"
3596 
3597             "float16_t smoothstep(float16_t, float16_t, float16_t);"
3598             "f16vec2   smoothstep(f16vec2,   f16vec2,   f16vec2);"
3599             "f16vec3   smoothstep(f16vec3,   f16vec3,   f16vec3);"
3600             "f16vec4   smoothstep(f16vec4,   f16vec4,   f16vec4);"
3601             "f16vec2   smoothstep(float16_t, float16_t, f16vec2);"
3602             "f16vec3   smoothstep(float16_t, float16_t, f16vec3);"
3603             "f16vec4   smoothstep(float16_t, float16_t, f16vec4);"
3604 
3605             "bool  isnan(float16_t);"
3606             "bvec2 isnan(f16vec2);"
3607             "bvec3 isnan(f16vec3);"
3608             "bvec4 isnan(f16vec4);"
3609 
3610             "bool  isinf(float16_t);"
3611             "bvec2 isinf(f16vec2);"
3612             "bvec3 isinf(f16vec3);"
3613             "bvec4 isinf(f16vec4);"
3614 
3615             "float16_t fma(float16_t, float16_t, float16_t);"
3616             "f16vec2   fma(f16vec2,   f16vec2,   f16vec2);"
3617             "f16vec3   fma(f16vec3,   f16vec3,   f16vec3);"
3618             "f16vec4   fma(f16vec4,   f16vec4,   f16vec4);"
3619 
3620             "float16_t frexp(float16_t, out int);"
3621             "f16vec2   frexp(f16vec2,   out ivec2);"
3622             "f16vec3   frexp(f16vec3,   out ivec3);"
3623             "f16vec4   frexp(f16vec4,   out ivec4);"
3624 
3625             "float16_t ldexp(float16_t, in int);"
3626             "f16vec2   ldexp(f16vec2,   in ivec2);"
3627             "f16vec3   ldexp(f16vec3,   in ivec3);"
3628             "f16vec4   ldexp(f16vec4,   in ivec4);"
3629 
3630             "uint    packFloat2x16(f16vec2);"
3631             "f16vec2 unpackFloat2x16(uint);"
3632 
3633             "float16_t length(float16_t);"
3634             "float16_t length(f16vec2);"
3635             "float16_t length(f16vec3);"
3636             "float16_t length(f16vec4);"
3637 
3638             "float16_t distance(float16_t, float16_t);"
3639             "float16_t distance(f16vec2,   f16vec2);"
3640             "float16_t distance(f16vec3,   f16vec3);"
3641             "float16_t distance(f16vec4,   f16vec4);"
3642 
3643             "float16_t dot(float16_t, float16_t);"
3644             "float16_t dot(f16vec2,   f16vec2);"
3645             "float16_t dot(f16vec3,   f16vec3);"
3646             "float16_t dot(f16vec4,   f16vec4);"
3647 
3648             "f16vec3 cross(f16vec3, f16vec3);"
3649 
3650             "float16_t normalize(float16_t);"
3651             "f16vec2   normalize(f16vec2);"
3652             "f16vec3   normalize(f16vec3);"
3653             "f16vec4   normalize(f16vec4);"
3654 
3655             "float16_t faceforward(float16_t, float16_t, float16_t);"
3656             "f16vec2   faceforward(f16vec2,   f16vec2,   f16vec2);"
3657             "f16vec3   faceforward(f16vec3,   f16vec3,   f16vec3);"
3658             "f16vec4   faceforward(f16vec4,   f16vec4,   f16vec4);"
3659 
3660             "float16_t reflect(float16_t, float16_t);"
3661             "f16vec2   reflect(f16vec2,   f16vec2);"
3662             "f16vec3   reflect(f16vec3,   f16vec3);"
3663             "f16vec4   reflect(f16vec4,   f16vec4);"
3664 
3665             "float16_t refract(float16_t, float16_t, float16_t);"
3666             "f16vec2   refract(f16vec2,   f16vec2,   float16_t);"
3667             "f16vec3   refract(f16vec3,   f16vec3,   float16_t);"
3668             "f16vec4   refract(f16vec4,   f16vec4,   float16_t);"
3669 
3670             "f16mat2   matrixCompMult(f16mat2,   f16mat2);"
3671             "f16mat3   matrixCompMult(f16mat3,   f16mat3);"
3672             "f16mat4   matrixCompMult(f16mat4,   f16mat4);"
3673             "f16mat2x3 matrixCompMult(f16mat2x3, f16mat2x3);"
3674             "f16mat2x4 matrixCompMult(f16mat2x4, f16mat2x4);"
3675             "f16mat3x2 matrixCompMult(f16mat3x2, f16mat3x2);"
3676             "f16mat3x4 matrixCompMult(f16mat3x4, f16mat3x4);"
3677             "f16mat4x2 matrixCompMult(f16mat4x2, f16mat4x2);"
3678             "f16mat4x3 matrixCompMult(f16mat4x3, f16mat4x3);"
3679 
3680             "f16mat2   outerProduct(f16vec2, f16vec2);"
3681             "f16mat3   outerProduct(f16vec3, f16vec3);"
3682             "f16mat4   outerProduct(f16vec4, f16vec4);"
3683             "f16mat2x3 outerProduct(f16vec3, f16vec2);"
3684             "f16mat3x2 outerProduct(f16vec2, f16vec3);"
3685             "f16mat2x4 outerProduct(f16vec4, f16vec2);"
3686             "f16mat4x2 outerProduct(f16vec2, f16vec4);"
3687             "f16mat3x4 outerProduct(f16vec4, f16vec3);"
3688             "f16mat4x3 outerProduct(f16vec3, f16vec4);"
3689 
3690             "f16mat2   transpose(f16mat2);"
3691             "f16mat3   transpose(f16mat3);"
3692             "f16mat4   transpose(f16mat4);"
3693             "f16mat2x3 transpose(f16mat3x2);"
3694             "f16mat3x2 transpose(f16mat2x3);"
3695             "f16mat2x4 transpose(f16mat4x2);"
3696             "f16mat4x2 transpose(f16mat2x4);"
3697             "f16mat3x4 transpose(f16mat4x3);"
3698             "f16mat4x3 transpose(f16mat3x4);"
3699 
3700             "float16_t determinant(f16mat2);"
3701             "float16_t determinant(f16mat3);"
3702             "float16_t determinant(f16mat4);"
3703 
3704             "f16mat2 inverse(f16mat2);"
3705             "f16mat3 inverse(f16mat3);"
3706             "f16mat4 inverse(f16mat4);"
3707 
3708             "bvec2 lessThan(f16vec2, f16vec2);"
3709             "bvec3 lessThan(f16vec3, f16vec3);"
3710             "bvec4 lessThan(f16vec4, f16vec4);"
3711 
3712             "bvec2 lessThanEqual(f16vec2, f16vec2);"
3713             "bvec3 lessThanEqual(f16vec3, f16vec3);"
3714             "bvec4 lessThanEqual(f16vec4, f16vec4);"
3715 
3716             "bvec2 greaterThan(f16vec2, f16vec2);"
3717             "bvec3 greaterThan(f16vec3, f16vec3);"
3718             "bvec4 greaterThan(f16vec4, f16vec4);"
3719 
3720             "bvec2 greaterThanEqual(f16vec2, f16vec2);"
3721             "bvec3 greaterThanEqual(f16vec3, f16vec3);"
3722             "bvec4 greaterThanEqual(f16vec4, f16vec4);"
3723 
3724             "bvec2 equal(f16vec2, f16vec2);"
3725             "bvec3 equal(f16vec3, f16vec3);"
3726             "bvec4 equal(f16vec4, f16vec4);"
3727 
3728             "bvec2 notEqual(f16vec2, f16vec2);"
3729             "bvec3 notEqual(f16vec3, f16vec3);"
3730             "bvec4 notEqual(f16vec4, f16vec4);"
3731 
3732             "\n");
3733     }
3734 
3735     // Explicit types
3736     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
3737         commonBuiltins.append(
3738             "int8_t abs(int8_t);"
3739             "i8vec2 abs(i8vec2);"
3740             "i8vec3 abs(i8vec3);"
3741             "i8vec4 abs(i8vec4);"
3742 
3743             "int8_t sign(int8_t);"
3744             "i8vec2 sign(i8vec2);"
3745             "i8vec3 sign(i8vec3);"
3746             "i8vec4 sign(i8vec4);"
3747 
3748             "int8_t min(int8_t x, int8_t y);"
3749             "i8vec2 min(i8vec2 x, int8_t y);"
3750             "i8vec3 min(i8vec3 x, int8_t y);"
3751             "i8vec4 min(i8vec4 x, int8_t y);"
3752             "i8vec2 min(i8vec2 x, i8vec2 y);"
3753             "i8vec3 min(i8vec3 x, i8vec3 y);"
3754             "i8vec4 min(i8vec4 x, i8vec4 y);"
3755 
3756             "uint8_t min(uint8_t x, uint8_t y);"
3757             "u8vec2 min(u8vec2 x, uint8_t y);"
3758             "u8vec3 min(u8vec3 x, uint8_t y);"
3759             "u8vec4 min(u8vec4 x, uint8_t y);"
3760             "u8vec2 min(u8vec2 x, u8vec2 y);"
3761             "u8vec3 min(u8vec3 x, u8vec3 y);"
3762             "u8vec4 min(u8vec4 x, u8vec4 y);"
3763 
3764             "int8_t max(int8_t x, int8_t y);"
3765             "i8vec2 max(i8vec2 x, int8_t y);"
3766             "i8vec3 max(i8vec3 x, int8_t y);"
3767             "i8vec4 max(i8vec4 x, int8_t y);"
3768             "i8vec2 max(i8vec2 x, i8vec2 y);"
3769             "i8vec3 max(i8vec3 x, i8vec3 y);"
3770             "i8vec4 max(i8vec4 x, i8vec4 y);"
3771 
3772             "uint8_t max(uint8_t x, uint8_t y);"
3773             "u8vec2 max(u8vec2 x, uint8_t y);"
3774             "u8vec3 max(u8vec3 x, uint8_t y);"
3775             "u8vec4 max(u8vec4 x, uint8_t y);"
3776             "u8vec2 max(u8vec2 x, u8vec2 y);"
3777             "u8vec3 max(u8vec3 x, u8vec3 y);"
3778             "u8vec4 max(u8vec4 x, u8vec4 y);"
3779 
3780             "int8_t    clamp(int8_t x, int8_t minVal, int8_t maxVal);"
3781             "i8vec2  clamp(i8vec2  x, int8_t minVal, int8_t maxVal);"
3782             "i8vec3  clamp(i8vec3  x, int8_t minVal, int8_t maxVal);"
3783             "i8vec4  clamp(i8vec4  x, int8_t minVal, int8_t maxVal);"
3784             "i8vec2  clamp(i8vec2  x, i8vec2  minVal, i8vec2  maxVal);"
3785             "i8vec3  clamp(i8vec3  x, i8vec3  minVal, i8vec3  maxVal);"
3786             "i8vec4  clamp(i8vec4  x, i8vec4  minVal, i8vec4  maxVal);"
3787 
3788             "uint8_t   clamp(uint8_t x, uint8_t minVal, uint8_t maxVal);"
3789             "u8vec2  clamp(u8vec2  x, uint8_t minVal, uint8_t maxVal);"
3790             "u8vec3  clamp(u8vec3  x, uint8_t minVal, uint8_t maxVal);"
3791             "u8vec4  clamp(u8vec4  x, uint8_t minVal, uint8_t maxVal);"
3792             "u8vec2  clamp(u8vec2  x, u8vec2  minVal, u8vec2  maxVal);"
3793             "u8vec3  clamp(u8vec3  x, u8vec3  minVal, u8vec3  maxVal);"
3794             "u8vec4  clamp(u8vec4  x, u8vec4  minVal, u8vec4  maxVal);"
3795 
3796             "int8_t  mix(int8_t,  int8_t,  bool);"
3797             "i8vec2  mix(i8vec2,  i8vec2,  bvec2);"
3798             "i8vec3  mix(i8vec3,  i8vec3,  bvec3);"
3799             "i8vec4  mix(i8vec4,  i8vec4,  bvec4);"
3800             "uint8_t mix(uint8_t, uint8_t, bool);"
3801             "u8vec2  mix(u8vec2,  u8vec2,  bvec2);"
3802             "u8vec3  mix(u8vec3,  u8vec3,  bvec3);"
3803             "u8vec4  mix(u8vec4,  u8vec4,  bvec4);"
3804 
3805             "bvec2 lessThan(i8vec2, i8vec2);"
3806             "bvec3 lessThan(i8vec3, i8vec3);"
3807             "bvec4 lessThan(i8vec4, i8vec4);"
3808             "bvec2 lessThan(u8vec2, u8vec2);"
3809             "bvec3 lessThan(u8vec3, u8vec3);"
3810             "bvec4 lessThan(u8vec4, u8vec4);"
3811 
3812             "bvec2 lessThanEqual(i8vec2, i8vec2);"
3813             "bvec3 lessThanEqual(i8vec3, i8vec3);"
3814             "bvec4 lessThanEqual(i8vec4, i8vec4);"
3815             "bvec2 lessThanEqual(u8vec2, u8vec2);"
3816             "bvec3 lessThanEqual(u8vec3, u8vec3);"
3817             "bvec4 lessThanEqual(u8vec4, u8vec4);"
3818 
3819             "bvec2 greaterThan(i8vec2, i8vec2);"
3820             "bvec3 greaterThan(i8vec3, i8vec3);"
3821             "bvec4 greaterThan(i8vec4, i8vec4);"
3822             "bvec2 greaterThan(u8vec2, u8vec2);"
3823             "bvec3 greaterThan(u8vec3, u8vec3);"
3824             "bvec4 greaterThan(u8vec4, u8vec4);"
3825 
3826             "bvec2 greaterThanEqual(i8vec2, i8vec2);"
3827             "bvec3 greaterThanEqual(i8vec3, i8vec3);"
3828             "bvec4 greaterThanEqual(i8vec4, i8vec4);"
3829             "bvec2 greaterThanEqual(u8vec2, u8vec2);"
3830             "bvec3 greaterThanEqual(u8vec3, u8vec3);"
3831             "bvec4 greaterThanEqual(u8vec4, u8vec4);"
3832 
3833             "bvec2 equal(i8vec2, i8vec2);"
3834             "bvec3 equal(i8vec3, i8vec3);"
3835             "bvec4 equal(i8vec4, i8vec4);"
3836             "bvec2 equal(u8vec2, u8vec2);"
3837             "bvec3 equal(u8vec3, u8vec3);"
3838             "bvec4 equal(u8vec4, u8vec4);"
3839 
3840             "bvec2 notEqual(i8vec2, i8vec2);"
3841             "bvec3 notEqual(i8vec3, i8vec3);"
3842             "bvec4 notEqual(i8vec4, i8vec4);"
3843             "bvec2 notEqual(u8vec2, u8vec2);"
3844             "bvec3 notEqual(u8vec3, u8vec3);"
3845             "bvec4 notEqual(u8vec4, u8vec4);"
3846 
3847             "  int8_t bitfieldExtract(  int8_t, int8_t, int8_t);"
3848             "i8vec2 bitfieldExtract(i8vec2, int8_t, int8_t);"
3849             "i8vec3 bitfieldExtract(i8vec3, int8_t, int8_t);"
3850             "i8vec4 bitfieldExtract(i8vec4, int8_t, int8_t);"
3851 
3852             " uint8_t bitfieldExtract( uint8_t, int8_t, int8_t);"
3853             "u8vec2 bitfieldExtract(u8vec2, int8_t, int8_t);"
3854             "u8vec3 bitfieldExtract(u8vec3, int8_t, int8_t);"
3855             "u8vec4 bitfieldExtract(u8vec4, int8_t, int8_t);"
3856 
3857             "  int8_t bitfieldInsert(  int8_t base,   int8_t, int8_t, int8_t);"
3858             "i8vec2 bitfieldInsert(i8vec2 base, i8vec2, int8_t, int8_t);"
3859             "i8vec3 bitfieldInsert(i8vec3 base, i8vec3, int8_t, int8_t);"
3860             "i8vec4 bitfieldInsert(i8vec4 base, i8vec4, int8_t, int8_t);"
3861 
3862             " uint8_t bitfieldInsert( uint8_t base,  uint8_t, int8_t, int8_t);"
3863             "u8vec2 bitfieldInsert(u8vec2 base, u8vec2, int8_t, int8_t);"
3864             "u8vec3 bitfieldInsert(u8vec3 base, u8vec3, int8_t, int8_t);"
3865             "u8vec4 bitfieldInsert(u8vec4 base, u8vec4, int8_t, int8_t);"
3866 
3867             "  int8_t bitCount(  int8_t);"
3868             "i8vec2 bitCount(i8vec2);"
3869             "i8vec3 bitCount(i8vec3);"
3870             "i8vec4 bitCount(i8vec4);"
3871 
3872             "  int8_t bitCount( uint8_t);"
3873             "i8vec2 bitCount(u8vec2);"
3874             "i8vec3 bitCount(u8vec3);"
3875             "i8vec4 bitCount(u8vec4);"
3876 
3877             "  int8_t findLSB(  int8_t);"
3878             "i8vec2 findLSB(i8vec2);"
3879             "i8vec3 findLSB(i8vec3);"
3880             "i8vec4 findLSB(i8vec4);"
3881 
3882             "  int8_t findLSB( uint8_t);"
3883             "i8vec2 findLSB(u8vec2);"
3884             "i8vec3 findLSB(u8vec3);"
3885             "i8vec4 findLSB(u8vec4);"
3886 
3887             "  int8_t findMSB(  int8_t);"
3888             "i8vec2 findMSB(i8vec2);"
3889             "i8vec3 findMSB(i8vec3);"
3890             "i8vec4 findMSB(i8vec4);"
3891 
3892             "  int8_t findMSB( uint8_t);"
3893             "i8vec2 findMSB(u8vec2);"
3894             "i8vec3 findMSB(u8vec3);"
3895             "i8vec4 findMSB(u8vec4);"
3896 
3897             "int16_t abs(int16_t);"
3898             "i16vec2 abs(i16vec2);"
3899             "i16vec3 abs(i16vec3);"
3900             "i16vec4 abs(i16vec4);"
3901 
3902             "int16_t sign(int16_t);"
3903             "i16vec2 sign(i16vec2);"
3904             "i16vec3 sign(i16vec3);"
3905             "i16vec4 sign(i16vec4);"
3906 
3907             "int16_t min(int16_t x, int16_t y);"
3908             "i16vec2 min(i16vec2 x, int16_t y);"
3909             "i16vec3 min(i16vec3 x, int16_t y);"
3910             "i16vec4 min(i16vec4 x, int16_t y);"
3911             "i16vec2 min(i16vec2 x, i16vec2 y);"
3912             "i16vec3 min(i16vec3 x, i16vec3 y);"
3913             "i16vec4 min(i16vec4 x, i16vec4 y);"
3914 
3915             "uint16_t min(uint16_t x, uint16_t y);"
3916             "u16vec2 min(u16vec2 x, uint16_t y);"
3917             "u16vec3 min(u16vec3 x, uint16_t y);"
3918             "u16vec4 min(u16vec4 x, uint16_t y);"
3919             "u16vec2 min(u16vec2 x, u16vec2 y);"
3920             "u16vec3 min(u16vec3 x, u16vec3 y);"
3921             "u16vec4 min(u16vec4 x, u16vec4 y);"
3922 
3923             "int16_t max(int16_t x, int16_t y);"
3924             "i16vec2 max(i16vec2 x, int16_t y);"
3925             "i16vec3 max(i16vec3 x, int16_t y);"
3926             "i16vec4 max(i16vec4 x, int16_t y);"
3927             "i16vec2 max(i16vec2 x, i16vec2 y);"
3928             "i16vec3 max(i16vec3 x, i16vec3 y);"
3929             "i16vec4 max(i16vec4 x, i16vec4 y);"
3930 
3931             "uint16_t max(uint16_t x, uint16_t y);"
3932             "u16vec2 max(u16vec2 x, uint16_t y);"
3933             "u16vec3 max(u16vec3 x, uint16_t y);"
3934             "u16vec4 max(u16vec4 x, uint16_t y);"
3935             "u16vec2 max(u16vec2 x, u16vec2 y);"
3936             "u16vec3 max(u16vec3 x, u16vec3 y);"
3937             "u16vec4 max(u16vec4 x, u16vec4 y);"
3938 
3939             "int16_t    clamp(int16_t x, int16_t minVal, int16_t maxVal);"
3940             "i16vec2  clamp(i16vec2  x, int16_t minVal, int16_t maxVal);"
3941             "i16vec3  clamp(i16vec3  x, int16_t minVal, int16_t maxVal);"
3942             "i16vec4  clamp(i16vec4  x, int16_t minVal, int16_t maxVal);"
3943             "i16vec2  clamp(i16vec2  x, i16vec2  minVal, i16vec2  maxVal);"
3944             "i16vec3  clamp(i16vec3  x, i16vec3  minVal, i16vec3  maxVal);"
3945             "i16vec4  clamp(i16vec4  x, i16vec4  minVal, i16vec4  maxVal);"
3946 
3947             "uint16_t   clamp(uint16_t x, uint16_t minVal, uint16_t maxVal);"
3948             "u16vec2  clamp(u16vec2  x, uint16_t minVal, uint16_t maxVal);"
3949             "u16vec3  clamp(u16vec3  x, uint16_t minVal, uint16_t maxVal);"
3950             "u16vec4  clamp(u16vec4  x, uint16_t minVal, uint16_t maxVal);"
3951             "u16vec2  clamp(u16vec2  x, u16vec2  minVal, u16vec2  maxVal);"
3952             "u16vec3  clamp(u16vec3  x, u16vec3  minVal, u16vec3  maxVal);"
3953             "u16vec4  clamp(u16vec4  x, u16vec4  minVal, u16vec4  maxVal);"
3954 
3955             "int16_t  mix(int16_t,  int16_t,  bool);"
3956             "i16vec2  mix(i16vec2,  i16vec2,  bvec2);"
3957             "i16vec3  mix(i16vec3,  i16vec3,  bvec3);"
3958             "i16vec4  mix(i16vec4,  i16vec4,  bvec4);"
3959             "uint16_t mix(uint16_t, uint16_t, bool);"
3960             "u16vec2  mix(u16vec2,  u16vec2,  bvec2);"
3961             "u16vec3  mix(u16vec3,  u16vec3,  bvec3);"
3962             "u16vec4  mix(u16vec4,  u16vec4,  bvec4);"
3963 
3964             "float16_t frexp(float16_t, out int16_t);"
3965             "f16vec2   frexp(f16vec2,   out i16vec2);"
3966             "f16vec3   frexp(f16vec3,   out i16vec3);"
3967             "f16vec4   frexp(f16vec4,   out i16vec4);"
3968 
3969             "float16_t ldexp(float16_t, int16_t);"
3970             "f16vec2   ldexp(f16vec2,   i16vec2);"
3971             "f16vec3   ldexp(f16vec3,   i16vec3);"
3972             "f16vec4   ldexp(f16vec4,   i16vec4);"
3973 
3974             "int16_t halfBitsToInt16(float16_t);"
3975             "i16vec2 halfBitsToInt16(f16vec2);"
3976             "i16vec3 halhBitsToInt16(f16vec3);"
3977             "i16vec4 halfBitsToInt16(f16vec4);"
3978 
3979             "uint16_t halfBitsToUint16(float16_t);"
3980             "u16vec2  halfBitsToUint16(f16vec2);"
3981             "u16vec3  halfBitsToUint16(f16vec3);"
3982             "u16vec4  halfBitsToUint16(f16vec4);"
3983 
3984             "int16_t float16BitsToInt16(float16_t);"
3985             "i16vec2 float16BitsToInt16(f16vec2);"
3986             "i16vec3 float16BitsToInt16(f16vec3);"
3987             "i16vec4 float16BitsToInt16(f16vec4);"
3988 
3989             "uint16_t float16BitsToUint16(float16_t);"
3990             "u16vec2  float16BitsToUint16(f16vec2);"
3991             "u16vec3  float16BitsToUint16(f16vec3);"
3992             "u16vec4  float16BitsToUint16(f16vec4);"
3993 
3994             "float16_t int16BitsToFloat16(int16_t);"
3995             "f16vec2   int16BitsToFloat16(i16vec2);"
3996             "f16vec3   int16BitsToFloat16(i16vec3);"
3997             "f16vec4   int16BitsToFloat16(i16vec4);"
3998 
3999             "float16_t uint16BitsToFloat16(uint16_t);"
4000             "f16vec2   uint16BitsToFloat16(u16vec2);"
4001             "f16vec3   uint16BitsToFloat16(u16vec3);"
4002             "f16vec4   uint16BitsToFloat16(u16vec4);"
4003 
4004             "float16_t int16BitsToHalf(int16_t);"
4005             "f16vec2   int16BitsToHalf(i16vec2);"
4006             "f16vec3   int16BitsToHalf(i16vec3);"
4007             "f16vec4   int16BitsToHalf(i16vec4);"
4008 
4009             "float16_t uint16BitsToHalf(uint16_t);"
4010             "f16vec2   uint16BitsToHalf(u16vec2);"
4011             "f16vec3   uint16BitsToHalf(u16vec3);"
4012             "f16vec4   uint16BitsToHalf(u16vec4);"
4013 
4014             "int      packInt2x16(i16vec2);"
4015             "uint     packUint2x16(u16vec2);"
4016             "int64_t  packInt4x16(i16vec4);"
4017             "uint64_t packUint4x16(u16vec4);"
4018             "i16vec2  unpackInt2x16(int);"
4019             "u16vec2  unpackUint2x16(uint);"
4020             "i16vec4  unpackInt4x16(int64_t);"
4021             "u16vec4  unpackUint4x16(uint64_t);"
4022 
4023             "bvec2 lessThan(i16vec2, i16vec2);"
4024             "bvec3 lessThan(i16vec3, i16vec3);"
4025             "bvec4 lessThan(i16vec4, i16vec4);"
4026             "bvec2 lessThan(u16vec2, u16vec2);"
4027             "bvec3 lessThan(u16vec3, u16vec3);"
4028             "bvec4 lessThan(u16vec4, u16vec4);"
4029 
4030             "bvec2 lessThanEqual(i16vec2, i16vec2);"
4031             "bvec3 lessThanEqual(i16vec3, i16vec3);"
4032             "bvec4 lessThanEqual(i16vec4, i16vec4);"
4033             "bvec2 lessThanEqual(u16vec2, u16vec2);"
4034             "bvec3 lessThanEqual(u16vec3, u16vec3);"
4035             "bvec4 lessThanEqual(u16vec4, u16vec4);"
4036 
4037             "bvec2 greaterThan(i16vec2, i16vec2);"
4038             "bvec3 greaterThan(i16vec3, i16vec3);"
4039             "bvec4 greaterThan(i16vec4, i16vec4);"
4040             "bvec2 greaterThan(u16vec2, u16vec2);"
4041             "bvec3 greaterThan(u16vec3, u16vec3);"
4042             "bvec4 greaterThan(u16vec4, u16vec4);"
4043 
4044             "bvec2 greaterThanEqual(i16vec2, i16vec2);"
4045             "bvec3 greaterThanEqual(i16vec3, i16vec3);"
4046             "bvec4 greaterThanEqual(i16vec4, i16vec4);"
4047             "bvec2 greaterThanEqual(u16vec2, u16vec2);"
4048             "bvec3 greaterThanEqual(u16vec3, u16vec3);"
4049             "bvec4 greaterThanEqual(u16vec4, u16vec4);"
4050 
4051             "bvec2 equal(i16vec2, i16vec2);"
4052             "bvec3 equal(i16vec3, i16vec3);"
4053             "bvec4 equal(i16vec4, i16vec4);"
4054             "bvec2 equal(u16vec2, u16vec2);"
4055             "bvec3 equal(u16vec3, u16vec3);"
4056             "bvec4 equal(u16vec4, u16vec4);"
4057 
4058             "bvec2 notEqual(i16vec2, i16vec2);"
4059             "bvec3 notEqual(i16vec3, i16vec3);"
4060             "bvec4 notEqual(i16vec4, i16vec4);"
4061             "bvec2 notEqual(u16vec2, u16vec2);"
4062             "bvec3 notEqual(u16vec3, u16vec3);"
4063             "bvec4 notEqual(u16vec4, u16vec4);"
4064 
4065             "  int16_t bitfieldExtract(  int16_t, int16_t, int16_t);"
4066             "i16vec2 bitfieldExtract(i16vec2, int16_t, int16_t);"
4067             "i16vec3 bitfieldExtract(i16vec3, int16_t, int16_t);"
4068             "i16vec4 bitfieldExtract(i16vec4, int16_t, int16_t);"
4069 
4070             " uint16_t bitfieldExtract( uint16_t, int16_t, int16_t);"
4071             "u16vec2 bitfieldExtract(u16vec2, int16_t, int16_t);"
4072             "u16vec3 bitfieldExtract(u16vec3, int16_t, int16_t);"
4073             "u16vec4 bitfieldExtract(u16vec4, int16_t, int16_t);"
4074 
4075             "  int16_t bitfieldInsert(  int16_t base,   int16_t, int16_t, int16_t);"
4076             "i16vec2 bitfieldInsert(i16vec2 base, i16vec2, int16_t, int16_t);"
4077             "i16vec3 bitfieldInsert(i16vec3 base, i16vec3, int16_t, int16_t);"
4078             "i16vec4 bitfieldInsert(i16vec4 base, i16vec4, int16_t, int16_t);"
4079 
4080             " uint16_t bitfieldInsert( uint16_t base,  uint16_t, int16_t, int16_t);"
4081             "u16vec2 bitfieldInsert(u16vec2 base, u16vec2, int16_t, int16_t);"
4082             "u16vec3 bitfieldInsert(u16vec3 base, u16vec3, int16_t, int16_t);"
4083             "u16vec4 bitfieldInsert(u16vec4 base, u16vec4, int16_t, int16_t);"
4084 
4085             "  int16_t bitCount(  int16_t);"
4086             "i16vec2 bitCount(i16vec2);"
4087             "i16vec3 bitCount(i16vec3);"
4088             "i16vec4 bitCount(i16vec4);"
4089 
4090             "  int16_t bitCount( uint16_t);"
4091             "i16vec2 bitCount(u16vec2);"
4092             "i16vec3 bitCount(u16vec3);"
4093             "i16vec4 bitCount(u16vec4);"
4094 
4095             "  int16_t findLSB(  int16_t);"
4096             "i16vec2 findLSB(i16vec2);"
4097             "i16vec3 findLSB(i16vec3);"
4098             "i16vec4 findLSB(i16vec4);"
4099 
4100             "  int16_t findLSB( uint16_t);"
4101             "i16vec2 findLSB(u16vec2);"
4102             "i16vec3 findLSB(u16vec3);"
4103             "i16vec4 findLSB(u16vec4);"
4104 
4105             "  int16_t findMSB(  int16_t);"
4106             "i16vec2 findMSB(i16vec2);"
4107             "i16vec3 findMSB(i16vec3);"
4108             "i16vec4 findMSB(i16vec4);"
4109 
4110             "  int16_t findMSB( uint16_t);"
4111             "i16vec2 findMSB(u16vec2);"
4112             "i16vec3 findMSB(u16vec3);"
4113             "i16vec4 findMSB(u16vec4);"
4114 
4115             "int16_t  pack16(i8vec2);"
4116             "uint16_t pack16(u8vec2);"
4117             "int32_t  pack32(i8vec4);"
4118             "uint32_t pack32(u8vec4);"
4119             "int32_t  pack32(i16vec2);"
4120             "uint32_t pack32(u16vec2);"
4121             "int64_t  pack64(i16vec4);"
4122             "uint64_t pack64(u16vec4);"
4123             "int64_t  pack64(i32vec2);"
4124             "uint64_t pack64(u32vec2);"
4125 
4126             "i8vec2   unpack8(int16_t);"
4127             "u8vec2   unpack8(uint16_t);"
4128             "i8vec4   unpack8(int32_t);"
4129             "u8vec4   unpack8(uint32_t);"
4130             "i16vec2  unpack16(int32_t);"
4131             "u16vec2  unpack16(uint32_t);"
4132             "i16vec4  unpack16(int64_t);"
4133             "u16vec4  unpack16(uint64_t);"
4134             "i32vec2  unpack32(int64_t);"
4135             "u32vec2  unpack32(uint64_t);"
4136 
4137             // GL_EXT_expect_assume
4138             "int8_t expectEXT(int8_t, int8_t);"
4139             "i8vec2 expectEXT(i8vec2, i8vec2);"
4140             "i8vec3 expectEXT(i8vec3, i8vec3);"
4141             "i8vec4 expectEXT(i8vec4, i8vec4);"
4142 
4143             "uint8_t expectEXT(uint8_t, uint8_t);"
4144             "u8vec2 expectEXT(u8vec2, u8vec2);"
4145             "u8vec3 expectEXT(u8vec3, u8vec3);"
4146             "u8vec4 expectEXT(u8vec4, u8vec4);"
4147 
4148             "int16_t expectEXT(int16_t, int16_t);"
4149             "i16vec2 expectEXT(i16vec2, i16vec2);"
4150             "i16vec3 expectEXT(i16vec3, i16vec3);"
4151             "i16vec4 expectEXT(i16vec4, i16vec4);"
4152 
4153             "uint16_t expectEXT(uint16_t, uint16_t);"
4154             "u16vec2 expectEXT(u16vec2, u16vec2);"
4155             "u16vec3 expectEXT(u16vec3, u16vec3);"
4156             "u16vec4 expectEXT(u16vec4, u16vec4);"
4157 
4158             "int64_t expectEXT(int64_t, int64_t);"
4159             "i64vec2 expectEXT(i64vec2, i64vec2);"
4160             "i64vec3 expectEXT(i64vec3, i64vec3);"
4161             "i64vec4 expectEXT(i64vec4, i64vec4);"
4162 
4163             "uint64_t expectEXT(uint64_t, uint64_t);"
4164             "u64vec2 expectEXT(u64vec2, u64vec2);"
4165             "u64vec3 expectEXT(u64vec3, u64vec3);"
4166             "u64vec4 expectEXT(u64vec4, u64vec4);"
4167             "\n");
4168     }
4169 
4170     // Builtins for GL_EXT_texture_shadow_lod
4171     if ((profile == EEsProfile && version >= 300) || ((profile != EEsProfile && version >= 130))) {
4172         commonBuiltins.append(
4173             "float texture(sampler2DArrayShadow, vec4, float);"
4174             "float texture(samplerCubeArrayShadow, vec4, float, float);"
4175             "float textureLod(sampler2DArrayShadow, vec4, float);"
4176             "float textureLod(samplerCubeShadow, vec4, float);"
4177             "float textureLod(samplerCubeArrayShadow, vec4, float, float);"
4178             "float textureLodOffset(sampler2DArrayShadow, vec4, float, ivec2);"
4179             "float textureOffset(sampler2DArrayShadow, vec4 , ivec2, float);"
4180             "\n");
4181     }
4182 
4183     if (profile != EEsProfile && version >= 450) {
4184         stageBuiltins[EShLangFragment].append(derivativesAndControl64bits);
4185         stageBuiltins[EShLangFragment].append(
4186             "float64_t interpolateAtCentroid(float64_t);"
4187             "f64vec2   interpolateAtCentroid(f64vec2);"
4188             "f64vec3   interpolateAtCentroid(f64vec3);"
4189             "f64vec4   interpolateAtCentroid(f64vec4);"
4190 
4191             "float64_t interpolateAtSample(float64_t, int);"
4192             "f64vec2   interpolateAtSample(f64vec2,   int);"
4193             "f64vec3   interpolateAtSample(f64vec3,   int);"
4194             "f64vec4   interpolateAtSample(f64vec4,   int);"
4195 
4196             "float64_t interpolateAtOffset(float64_t, f64vec2);"
4197             "f64vec2   interpolateAtOffset(f64vec2,   f64vec2);"
4198             "f64vec3   interpolateAtOffset(f64vec3,   f64vec2);"
4199             "f64vec4   interpolateAtOffset(f64vec4,   f64vec2);"
4200 
4201             "\n");
4202 
4203     }
4204 
4205     // GL_EXT_expect_assume
4206     if ((profile == EEsProfile && version >= 310) ||
4207          ((profile != EEsProfile && version >= 140))) {
4208         commonBuiltins.append(
4209             "void assumeEXT(bool);"
4210 
4211             "bool expectEXT(bool, bool);"
4212             "bvec2 expectEXT(bvec2, bvec2);"
4213             "bvec3 expectEXT(bvec3, bvec3);"
4214             "bvec4 expectEXT(bvec4, bvec4);"
4215 
4216             "int expectEXT(int, int);"
4217             "ivec2 expectEXT(ivec2, ivec2);"
4218             "ivec3 expectEXT(ivec3, ivec3);"
4219             "ivec4 expectEXT(ivec4, ivec4);"
4220 
4221             "uint expectEXT(uint, uint);"
4222             "uvec2 expectEXT(uvec2, uvec2);"
4223             "uvec3 expectEXT(uvec3, uvec3);"
4224             "uvec4 expectEXT(uvec4, uvec4);"
4225             "\n");
4226     }
4227 
4228     // QCOM_image_processing
4229     if ((profile == EEsProfile && version >= 310) ||
4230          (profile != EEsProfile && version >= 140)) {
4231         commonBuiltins.append(
4232            "vec4 textureWeightedQCOM(sampler2D, vec2, sampler2DArray);"
4233            "vec4 textureWeightedQCOM(sampler2D, vec2, sampler1DArray);"
4234            "vec4 textureBoxFilterQCOM(sampler2D, vec2, vec2);"
4235            "vec4 textureBlockMatchSADQCOM(sampler2D, uvec2, sampler2D, uvec2, uvec2);"
4236            "vec4 textureBlockMatchSSDQCOM(sampler2D, uvec2, sampler2D, uvec2, uvec2);"
4237 
4238            "vec4 textureBlockMatchWindowSSDQCOM(sampler2D, uvec2, sampler2D, uvec2, uvec2);"
4239            "vec4 textureBlockMatchWindowSADQCOM(sampler2D, uvec2, sampler2D, uvec2, uvec2);"
4240            "vec4 textureBlockMatchGatherSSDQCOM(sampler2D, uvec2, sampler2D, uvec2, uvec2);"
4241            "vec4 textureBlockMatchGatherSADQCOM(sampler2D, uvec2, sampler2D, uvec2, uvec2);"
4242            "\n");
4243     }
4244 
4245     //============================================================================
4246     //
4247     // Prototypes for built-in functions seen by vertex shaders only.
4248     // (Except legacy lod functions, where it depends which release they are
4249     // vertex only.)
4250     //
4251     //============================================================================
4252 
4253     //
4254     // Geometric Functions.
4255     //
4256     if (spvVersion.vulkan == 0 && IncludeLegacy(version, profile, spvVersion))
4257         stageBuiltins[EShLangVertex].append("vec4 ftransform();");
4258 
4259     //
4260     // Original-style texture Functions with lod.
4261     //
4262     TString* s;
4263     if (version == 100)
4264         s = &stageBuiltins[EShLangVertex];
4265     else
4266         s = &commonBuiltins;
4267     if ((profile == EEsProfile && version == 100) ||
4268          profile == ECompatibilityProfile ||
4269         (profile == ECoreProfile && version < 420) ||
4270          profile == ENoProfile) {
4271         if (spvVersion.spv == 0) {
4272             s->append(
4273                 "vec4 texture2DLod(sampler2D, vec2, float);"         // GL_ARB_shader_texture_lod
4274                 "vec4 texture2DProjLod(sampler2D, vec3, float);"     // GL_ARB_shader_texture_lod
4275                 "vec4 texture2DProjLod(sampler2D, vec4, float);"     // GL_ARB_shader_texture_lod
4276                 "vec4 texture3DLod(sampler3D, vec3, float);"         // GL_ARB_shader_texture_lod  // OES_texture_3D, but caught by keyword check
4277                 "vec4 texture3DProjLod(sampler3D, vec4, float);"     // GL_ARB_shader_texture_lod  // OES_texture_3D, but caught by keyword check
4278                 "vec4 textureCubeLod(samplerCube, vec3, float);"     // GL_ARB_shader_texture_lod
4279 
4280                 "\n");
4281         }
4282     }
4283     if ( profile == ECompatibilityProfile ||
4284         (profile == ECoreProfile && version < 420) ||
4285          profile == ENoProfile) {
4286         if (spvVersion.spv == 0) {
4287             s->append(
4288                 "vec4 texture1DLod(sampler1D, float, float);"                          // GL_ARB_shader_texture_lod
4289                 "vec4 texture1DProjLod(sampler1D, vec2, float);"                       // GL_ARB_shader_texture_lod
4290                 "vec4 texture1DProjLod(sampler1D, vec4, float);"                       // GL_ARB_shader_texture_lod
4291                 "vec4 shadow1DLod(sampler1DShadow, vec3, float);"                      // GL_ARB_shader_texture_lod
4292                 "vec4 shadow2DLod(sampler2DShadow, vec3, float);"                      // GL_ARB_shader_texture_lod
4293                 "vec4 shadow1DProjLod(sampler1DShadow, vec4, float);"                  // GL_ARB_shader_texture_lod
4294                 "vec4 shadow2DProjLod(sampler2DShadow, vec4, float);"                  // GL_ARB_shader_texture_lod
4295 
4296                 "vec4 texture1DGradARB(sampler1D, float, float, float);"               // GL_ARB_shader_texture_lod
4297                 "vec4 texture1DProjGradARB(sampler1D, vec2, float, float);"            // GL_ARB_shader_texture_lod
4298                 "vec4 texture1DProjGradARB(sampler1D, vec4, float, float);"            // GL_ARB_shader_texture_lod
4299                 "vec4 texture2DGradARB(sampler2D, vec2, vec2, vec2);"                  // GL_ARB_shader_texture_lod
4300                 "vec4 texture2DProjGradARB(sampler2D, vec3, vec2, vec2);"              // GL_ARB_shader_texture_lod
4301                 "vec4 texture2DProjGradARB(sampler2D, vec4, vec2, vec2);"              // GL_ARB_shader_texture_lod
4302                 "vec4 texture3DGradARB(sampler3D, vec3, vec3, vec3);"                  // GL_ARB_shader_texture_lod
4303                 "vec4 texture3DProjGradARB(sampler3D, vec4, vec3, vec3);"              // GL_ARB_shader_texture_lod
4304                 "vec4 textureCubeGradARB(samplerCube, vec3, vec3, vec3);"              // GL_ARB_shader_texture_lod
4305                 "vec4 shadow1DGradARB(sampler1DShadow, vec3, float, float);"           // GL_ARB_shader_texture_lod
4306                 "vec4 shadow1DProjGradARB( sampler1DShadow, vec4, float, float);"      // GL_ARB_shader_texture_lod
4307                 "vec4 shadow2DGradARB(sampler2DShadow, vec3, vec2, vec2);"             // GL_ARB_shader_texture_lod
4308                 "vec4 shadow2DProjGradARB( sampler2DShadow, vec4, vec2, vec2);"        // GL_ARB_shader_texture_lod
4309                 "vec4 texture2DRectGradARB(sampler2DRect, vec2, vec2, vec2);"          // GL_ARB_shader_texture_lod
4310                 "vec4 texture2DRectProjGradARB( sampler2DRect, vec3, vec2, vec2);"     // GL_ARB_shader_texture_lod
4311                 "vec4 texture2DRectProjGradARB( sampler2DRect, vec4, vec2, vec2);"     // GL_ARB_shader_texture_lod
4312                 "vec4 shadow2DRectGradARB( sampler2DRectShadow, vec3, vec2, vec2);"    // GL_ARB_shader_texture_lod
4313                 "vec4 shadow2DRectProjGradARB(sampler2DRectShadow, vec4, vec2, vec2);" // GL_ARB_shader_texture_lod
4314 
4315                 "\n");
4316         }
4317     }
4318 
4319     if ((profile != EEsProfile && version >= 150) ||
4320         (profile == EEsProfile && version >= 310)) {
4321         //============================================================================
4322         //
4323         // Prototypes for built-in functions seen by geometry shaders only.
4324         //
4325         //============================================================================
4326 
4327         if (profile != EEsProfile && (version >= 400 || version == 150)) {
4328             stageBuiltins[EShLangGeometry].append(
4329                 "void EmitStreamVertex(int);"
4330                 "void EndStreamPrimitive(int);"
4331                 );
4332         }
4333         stageBuiltins[EShLangGeometry].append(
4334             "void EmitVertex();"
4335             "void EndPrimitive();"
4336             "\n");
4337     }
4338 
4339     //============================================================================
4340     //
4341     // Prototypes for all control functions.
4342     //
4343     //============================================================================
4344     bool esBarrier = (profile == EEsProfile && version >= 310);
4345     if ((profile != EEsProfile && version >= 150) || esBarrier)
4346         stageBuiltins[EShLangTessControl].append(
4347             "void barrier();"
4348             );
4349     if ((profile != EEsProfile && version >= 420) || esBarrier)
4350         stageBuiltins[EShLangCompute].append(
4351             "void barrier();"
4352             );
4353     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
4354         stageBuiltins[EShLangMesh].append(
4355             "void barrier();"
4356             );
4357         stageBuiltins[EShLangTask].append(
4358             "void barrier();"
4359             );
4360     }
4361     if ((profile != EEsProfile && version >= 130) || esBarrier)
4362         commonBuiltins.append(
4363             "void memoryBarrier();"
4364             );
4365     if ((profile != EEsProfile && version >= 420) || esBarrier) {
4366         commonBuiltins.append(
4367             "void memoryBarrierBuffer();"
4368             );
4369         stageBuiltins[EShLangCompute].append(
4370             "void memoryBarrierShared();"
4371             "void groupMemoryBarrier();"
4372             );
4373     }
4374     if ((profile != EEsProfile && version >= 420) || esBarrier) {
4375         if (spvVersion.vulkan == 0 || spvVersion.vulkanRelaxed) {
4376             commonBuiltins.append("void memoryBarrierAtomicCounter();");
4377         }
4378         commonBuiltins.append("void memoryBarrierImage();");
4379     }
4380     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
4381         stageBuiltins[EShLangMesh].append(
4382             "void memoryBarrierShared();"
4383             "void groupMemoryBarrier();"
4384         );
4385         stageBuiltins[EShLangTask].append(
4386             "void memoryBarrierShared();"
4387             "void groupMemoryBarrier();"
4388         );
4389     }
4390 
4391     commonBuiltins.append("void controlBarrier(int, int, int, int);\n"
4392                           "void memoryBarrier(int, int, int);\n");
4393 
4394     commonBuiltins.append("void debugPrintfEXT();\n");
4395 
4396     if (profile != EEsProfile && version >= 450) {
4397         // coopMatStoreNV perhaps ought to have "out" on the buf parameter, but
4398         // adding it introduces undesirable tempArgs on the stack. What we want
4399         // is more like "buf" thought of as a pointer value being an in parameter.
4400         stageBuiltins[EShLangCompute].append(
4401             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent float16_t[] buf, uint element, uint stride, bool colMajor);\n"
4402             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent float[] buf, uint element, uint stride, bool colMajor);\n"
4403             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
4404             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
4405             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
4406             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
4407             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
4408             "void coopMatLoadNV(out fcoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
4409 
4410             "void coopMatStoreNV(fcoopmatNV m, volatile coherent float16_t[] buf, uint element, uint stride, bool colMajor);\n"
4411             "void coopMatStoreNV(fcoopmatNV m, volatile coherent float[] buf, uint element, uint stride, bool colMajor);\n"
4412             "void coopMatStoreNV(fcoopmatNV m, volatile coherent float64_t[] buf, uint element, uint stride, bool colMajor);\n"
4413             "void coopMatStoreNV(fcoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
4414             "void coopMatStoreNV(fcoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
4415             "void coopMatStoreNV(fcoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
4416             "void coopMatStoreNV(fcoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
4417             "void coopMatStoreNV(fcoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
4418             "void coopMatStoreNV(fcoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
4419 
4420             "fcoopmatNV coopMatMulAddNV(fcoopmatNV A, fcoopmatNV B, fcoopmatNV C);\n"
4421             "void coopMatLoadNV(out icoopmatNV m, volatile coherent int8_t[] buf, uint element, uint stride, bool colMajor);\n"
4422             "void coopMatLoadNV(out icoopmatNV m, volatile coherent int16_t[] buf, uint element, uint stride, bool colMajor);\n"
4423             "void coopMatLoadNV(out icoopmatNV m, volatile coherent int[] buf, uint element, uint stride, bool colMajor);\n"
4424             "void coopMatLoadNV(out icoopmatNV m, volatile coherent int64_t[] buf, uint element, uint stride, bool colMajor);\n"
4425             "void coopMatLoadNV(out icoopmatNV m, volatile coherent ivec2[] buf, uint element, uint stride, bool colMajor);\n"
4426             "void coopMatLoadNV(out icoopmatNV m, volatile coherent ivec4[] buf, uint element, uint stride, bool colMajor);\n"
4427             "void coopMatLoadNV(out icoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
4428             "void coopMatLoadNV(out icoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
4429             "void coopMatLoadNV(out icoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
4430             "void coopMatLoadNV(out icoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
4431             "void coopMatLoadNV(out icoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
4432             "void coopMatLoadNV(out icoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
4433 
4434             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent int8_t[] buf, uint element, uint stride, bool colMajor);\n"
4435             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent int16_t[] buf, uint element, uint stride, bool colMajor);\n"
4436             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent int[] buf, uint element, uint stride, bool colMajor);\n"
4437             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent int64_t[] buf, uint element, uint stride, bool colMajor);\n"
4438             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent ivec2[] buf, uint element, uint stride, bool colMajor);\n"
4439             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent ivec4[] buf, uint element, uint stride, bool colMajor);\n"
4440             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
4441             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
4442             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
4443             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
4444             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
4445             "void coopMatLoadNV(out ucoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
4446 
4447             "void coopMatStoreNV(icoopmatNV m, volatile coherent int8_t[] buf, uint element, uint stride, bool colMajor);\n"
4448             "void coopMatStoreNV(icoopmatNV m, volatile coherent int16_t[] buf, uint element, uint stride, bool colMajor);\n"
4449             "void coopMatStoreNV(icoopmatNV m, volatile coherent int[] buf, uint element, uint stride, bool colMajor);\n"
4450             "void coopMatStoreNV(icoopmatNV m, volatile coherent int64_t[] buf, uint element, uint stride, bool colMajor);\n"
4451             "void coopMatStoreNV(icoopmatNV m, volatile coherent ivec2[] buf, uint element, uint stride, bool colMajor);\n"
4452             "void coopMatStoreNV(icoopmatNV m, volatile coherent ivec4[] buf, uint element, uint stride, bool colMajor);\n"
4453             "void coopMatStoreNV(icoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
4454             "void coopMatStoreNV(icoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
4455             "void coopMatStoreNV(icoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
4456             "void coopMatStoreNV(icoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
4457             "void coopMatStoreNV(icoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
4458             "void coopMatStoreNV(icoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
4459 
4460             "void coopMatStoreNV(ucoopmatNV m, volatile coherent int8_t[] buf, uint element, uint stride, bool colMajor);\n"
4461             "void coopMatStoreNV(ucoopmatNV m, volatile coherent int16_t[] buf, uint element, uint stride, bool colMajor);\n"
4462             "void coopMatStoreNV(ucoopmatNV m, volatile coherent int[] buf, uint element, uint stride, bool colMajor);\n"
4463             "void coopMatStoreNV(ucoopmatNV m, volatile coherent int64_t[] buf, uint element, uint stride, bool colMajor);\n"
4464             "void coopMatStoreNV(ucoopmatNV m, volatile coherent ivec2[] buf, uint element, uint stride, bool colMajor);\n"
4465             "void coopMatStoreNV(ucoopmatNV m, volatile coherent ivec4[] buf, uint element, uint stride, bool colMajor);\n"
4466             "void coopMatStoreNV(ucoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
4467             "void coopMatStoreNV(ucoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
4468             "void coopMatStoreNV(ucoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
4469             "void coopMatStoreNV(ucoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
4470             "void coopMatStoreNV(ucoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
4471             "void coopMatStoreNV(ucoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
4472 
4473             "icoopmatNV coopMatMulAddNV(icoopmatNV A, icoopmatNV B, icoopmatNV C);\n"
4474             "ucoopmatNV coopMatMulAddNV(ucoopmatNV A, ucoopmatNV B, ucoopmatNV C);\n"
4475             );
4476 
4477         std::stringstream cooperativeMatrixFuncs;
4478 
4479         {
4480             static const char *allTypes[] =
4481             {
4482                 "float", "vec2", "vec4",
4483                 "float16_t", "f16vec2", "f16vec4",
4484                 "double", "dvec2", "dvec4",
4485                 "int8_t", "i8vec2", "i8vec4",
4486                 "int16_t", "i16vec2", "i16vec4",
4487                 "int", "ivec2", "ivec4",
4488                 "int64_t", "i64vec2", "i64vec4",
4489                 "uint8_t", "u8vec2", "u8vec4",
4490                 "uint16_t", "u16vec2", "u16vec4",
4491                 "uint", "uvec2", "uvec4",
4492                 "uint64_t", "u64vec2", "u64vec4",
4493             };
4494             for (auto t : allTypes) {
4495                 cooperativeMatrixFuncs << "void coopMatLoad(out coopmat m, volatile coherent " << t << "[] buf, uint element, uint stride, int matrixLayout);\n";
4496                 cooperativeMatrixFuncs << "void coopMatStore(coopmat m, volatile coherent " << t << "[] buf, uint element, uint stride, int matrixLayout);\n";
4497             }
4498             // Just use uint8_t for buffer type, we have special matching rules to allow any conversion
4499             cooperativeMatrixFuncs << "void coopMatLoadTensorNV(inout coopmat m, volatile coherent uint8_t[] buf, uint element, tensorLayoutNV t);\n";
4500             cooperativeMatrixFuncs << "void coopMatLoadTensorNV(inout coopmat m, volatile coherent uint8_t[] buf, uint element, tensorLayoutNV t, tensorViewNV v);\n";
4501             cooperativeMatrixFuncs << "void coopMatLoadTensorNV(inout coopmat m, volatile coherent uint8_t[] buf, uint element, tensorLayoutNV t, __function f);\n";
4502             cooperativeMatrixFuncs << "void coopMatLoadTensorNV(inout coopmat m, volatile coherent uint8_t[] buf, uint element, tensorLayoutNV t, tensorViewNV v, __function f);\n";
4503             cooperativeMatrixFuncs << "void coopMatStoreTensorNV(coopmat m, volatile coherent uint8_t[] buf, uint element, tensorLayoutNV t);\n";
4504             cooperativeMatrixFuncs << "void coopMatStoreTensorNV(coopmat m, volatile coherent uint8_t[] buf, uint element, tensorLayoutNV t, tensorViewNV v);\n";
4505         }
4506 
4507         cooperativeMatrixFuncs <<
4508             "coopmat coopMatMulAdd(coopmat A, coopmat B, coopmat C);\n"
4509             "coopmat coopMatMulAdd(coopmat A, coopmat B, coopmat C, int matrixOperands);\n";
4510 
4511         commonBuiltins.append(cooperativeMatrixFuncs.str().c_str());
4512 
4513         commonBuiltins.append(
4514             "const int gl_MatrixUseA = 0;\n"
4515             "const int gl_MatrixUseB = 1;\n"
4516             "const int gl_MatrixUseAccumulator = 2;\n"
4517             "const int gl_MatrixOperandsSaturatingAccumulation = 0x10;\n"
4518             "const int gl_CooperativeMatrixLayoutRowMajor = 0;\n"
4519             "const int gl_CooperativeMatrixLayoutColumnMajor = 1;\n"
4520             "const int gl_CooperativeMatrixLayoutRowBlockedInterleavedARM = 4202;\n"
4521             "const int gl_CooperativeMatrixLayoutColumnBlockedInterleavedARM = 4203;\n"
4522             "\n"
4523             );
4524 
4525         commonBuiltins.append(
4526             "void coopMatTransposeNV(out coopmat, coopmat);"
4527             "void coopMatReduceNV(out coopmat, coopmat, int, __function);"
4528             "void coopMatPerElementNV();"
4529         );
4530 
4531         commonBuiltins.append(
4532             "const int gl_CooperativeMatrixReduceRowNV = 0x1;\n"
4533             "const int gl_CooperativeMatrixReduceColumnNV = 0x2;\n"
4534             "const int gl_CooperativeMatrixReduceRowAndColumnNV = 0x3;\n"
4535             "const int gl_CooperativeMatrixReduce2x2NV = 0x4;\n"
4536             "\n"
4537             );
4538 
4539         commonBuiltins.append(
4540             "const int gl_CooperativeMatrixClampModeUndefinedNV = 0x0;\n"
4541             "const int gl_CooperativeMatrixClampModeConstantNV = 0x1;\n"
4542             "const int gl_CooperativeMatrixClampModeClampToEdgeNV = 0x2;\n"
4543             "const int gl_CooperativeMatrixClampModeRepeatNV = 0x3;\n"
4544             "const int gl_CooperativeMatrixClampModeMirrorRepeatNV = 0x4;\n"
4545             "\n"
4546             );
4547 
4548         commonBuiltins.append(
4549             "tensorLayoutNV createTensorLayoutNV(uint Dim);\n"
4550             "tensorLayoutNV createTensorLayoutNV(uint Dim, uint Mode);\n"
4551 
4552             "tensorLayoutNV setTensorLayoutBlockSizeNV(tensorLayoutNV t, uint blockSize0);\n"
4553             "tensorLayoutNV setTensorLayoutBlockSizeNV(tensorLayoutNV t, uint blockSize0, uint blockSize1);\n"
4554             "tensorLayoutNV setTensorLayoutBlockSizeNV(tensorLayoutNV t, uint blockSize0, uint blockSize1, uint blockSize2);\n"
4555             "tensorLayoutNV setTensorLayoutBlockSizeNV(tensorLayoutNV t, uint blockSize0, uint blockSize1, uint blockSize2, uint blockSize3);\n"
4556             "tensorLayoutNV setTensorLayoutBlockSizeNV(tensorLayoutNV t, uint blockSize0, uint blockSize1, uint blockSize2, uint blockSize3, uint blockSize4);\n"
4557 
4558             "tensorLayoutNV setTensorLayoutDimensionNV(tensorLayoutNV t, uint dim0);\n"
4559             "tensorLayoutNV setTensorLayoutDimensionNV(tensorLayoutNV t, uint dim0, uint dim1);\n"
4560             "tensorLayoutNV setTensorLayoutDimensionNV(tensorLayoutNV t, uint dim0, uint dim1, uint dim2);\n"
4561             "tensorLayoutNV setTensorLayoutDimensionNV(tensorLayoutNV t, uint dim0, uint dim1, uint dim2, uint dim3);\n"
4562             "tensorLayoutNV setTensorLayoutDimensionNV(tensorLayoutNV t, uint dim0, uint dim1, uint dim2, uint dim3, uint dim4);\n"
4563 
4564             "tensorLayoutNV setTensorLayoutStrideNV(tensorLayoutNV t, uint stride0);\n"
4565             "tensorLayoutNV setTensorLayoutStrideNV(tensorLayoutNV t, uint stride0, uint stride1);\n"
4566             "tensorLayoutNV setTensorLayoutStrideNV(tensorLayoutNV t, uint stride0, uint stride1, uint stride2);\n"
4567             "tensorLayoutNV setTensorLayoutStrideNV(tensorLayoutNV t, uint stride0, uint stride1, uint stride2, uint stride3);\n"
4568             "tensorLayoutNV setTensorLayoutStrideNV(tensorLayoutNV t, uint stride0, uint stride1, uint stride2, uint stride3, uint stride4);\n"
4569 
4570             "tensorLayoutNV sliceTensorLayoutNV(tensorLayoutNV t, uint offset0, uint span0);\n"
4571             "tensorLayoutNV sliceTensorLayoutNV(tensorLayoutNV t, uint offset0, uint span0, uint offset1, uint span1);\n"
4572             "tensorLayoutNV sliceTensorLayoutNV(tensorLayoutNV t, uint offset0, uint span0, uint offset1, uint span1, uint offset2, uint span2);\n"
4573             "tensorLayoutNV sliceTensorLayoutNV(tensorLayoutNV t, uint offset0, uint span0, uint offset1, uint span1, uint offset2, uint span2, uint offset3, uint span3);\n"
4574             "tensorLayoutNV sliceTensorLayoutNV(tensorLayoutNV t, uint offset0, uint span0, uint offset1, uint span1, uint offset2, uint span2, uint offset3, uint span3, uint offset4, uint span4);\n"
4575 
4576             "tensorLayoutNV setTensorLayoutClampValueNV(tensorLayoutNV t, uint value);\n"
4577 
4578             "tensorViewNV createTensorViewNV(uint Dim);\n"
4579             "tensorViewNV createTensorViewNV(uint Dim, bool HasDimensions);\n"
4580             "tensorViewNV createTensorViewNV(uint Dim, bool HasDimensions, uint p0);\n"
4581             "tensorViewNV createTensorViewNV(uint Dim, bool HasDimensions, uint p0, uint p1);\n"
4582             "tensorViewNV createTensorViewNV(uint Dim, bool HasDimensions, uint p0, uint p1, uint p2);\n"
4583             "tensorViewNV createTensorViewNV(uint Dim, bool HasDimensions, uint p0, uint p1, uint p2, uint p3);\n"
4584             "tensorViewNV createTensorViewNV(uint Dim, bool HasDimensions, uint p0, uint p1, uint p2, uint p3, uint p4);\n"
4585 
4586             "tensorViewNV setTensorViewDimensionsNV(tensorViewNV v, uint dim0);\n"
4587             "tensorViewNV setTensorViewDimensionsNV(tensorViewNV v, uint dim0, uint dim1);\n"
4588             "tensorViewNV setTensorViewDimensionsNV(tensorViewNV v, uint dim0, uint dim1, uint dim2);\n"
4589             "tensorViewNV setTensorViewDimensionsNV(tensorViewNV v, uint dim0, uint dim1, uint dim2, uint dim3);\n"
4590             "tensorViewNV setTensorViewDimensionsNV(tensorViewNV v, uint dim0, uint dim1, uint dim2, uint dim3, uint dim4);\n"
4591 
4592             "tensorViewNV setTensorViewStrideNV(tensorViewNV v, uint stride0);\n"
4593             "tensorViewNV setTensorViewStrideNV(tensorViewNV v, uint stride0, uint stride1);\n"
4594             "tensorViewNV setTensorViewStrideNV(tensorViewNV v, uint stride0, uint stride1, uint stride2);\n"
4595             "tensorViewNV setTensorViewStrideNV(tensorViewNV v, uint stride0, uint stride1, uint stride2, uint stride3);\n"
4596             "tensorViewNV setTensorViewStrideNV(tensorViewNV v, uint stride0, uint stride1, uint stride2, uint stride3, uint stride4);\n"
4597 
4598             "tensorViewNV setTensorViewClipNV(tensorViewNV v, uint clipRowOffset, uint clipRowSpan, uint clipColOffset, uint clipColSpan);\n"
4599             "\n"
4600         );
4601     }
4602 
4603     //============================================================================
4604     //
4605     // Prototypes for built-in functions seen by fragment shaders only.
4606     //
4607     //============================================================================
4608 
4609     //
4610     // Original-style texture Functions with bias.
4611     //
4612     if (spvVersion.spv == 0 && (profile != EEsProfile || version == 100)) {
4613         stageBuiltins[EShLangFragment].append(
4614             "vec4 texture2D(sampler2D, vec2, float);"
4615             "vec4 texture2DProj(sampler2D, vec3, float);"
4616             "vec4 texture2DProj(sampler2D, vec4, float);"
4617             "vec4 texture3D(sampler3D, vec3, float);"        // OES_texture_3D
4618             "vec4 texture3DProj(sampler3D, vec4, float);"    // OES_texture_3D
4619             "vec4 textureCube(samplerCube, vec3, float);"
4620 
4621             "\n");
4622     }
4623     if (spvVersion.spv == 0 && (profile != EEsProfile && version > 100)) {
4624         stageBuiltins[EShLangFragment].append(
4625             "vec4 texture1D(sampler1D, float, float);"
4626             "vec4 texture1DProj(sampler1D, vec2, float);"
4627             "vec4 texture1DProj(sampler1D, vec4, float);"
4628             "vec4 shadow1D(sampler1DShadow, vec3, float);"
4629             "vec4 shadow2D(sampler2DShadow, vec3, float);"
4630             "vec4 shadow1DProj(sampler1DShadow, vec4, float);"
4631             "vec4 shadow2DProj(sampler2DShadow, vec4, float);"
4632 
4633             "\n");
4634     }
4635     if (spvVersion.spv == 0 && profile == EEsProfile) {
4636         stageBuiltins[EShLangFragment].append(
4637             "vec4 texture2DLodEXT(sampler2D, vec2, float);"      // GL_EXT_shader_texture_lod
4638             "vec4 texture2DProjLodEXT(sampler2D, vec3, float);"  // GL_EXT_shader_texture_lod
4639             "vec4 texture2DProjLodEXT(sampler2D, vec4, float);"  // GL_EXT_shader_texture_lod
4640             "vec4 textureCubeLodEXT(samplerCube, vec3, float);"  // GL_EXT_shader_texture_lod
4641 
4642             "\n");
4643     }
4644 
4645     // GL_EXT_shader_tile_image
4646     if (spvVersion.vulkan > 0) {
4647         stageBuiltins[EShLangFragment].append(
4648             "lowp uint stencilAttachmentReadEXT();"
4649             "lowp uint stencilAttachmentReadEXT(int);"
4650             "highp float depthAttachmentReadEXT();"
4651             "highp float depthAttachmentReadEXT(int);"
4652             "\n");
4653         stageBuiltins[EShLangFragment].append(
4654             "vec4 colorAttachmentReadEXT(attachmentEXT);"
4655             "vec4 colorAttachmentReadEXT(attachmentEXT, int);"
4656             "ivec4 colorAttachmentReadEXT(iattachmentEXT);"
4657             "ivec4 colorAttachmentReadEXT(iattachmentEXT, int);"
4658             "uvec4 colorAttachmentReadEXT(uattachmentEXT);"
4659             "uvec4 colorAttachmentReadEXT(uattachmentEXT, int);"
4660             "\n");
4661     }
4662 
4663     // GL_ARB_derivative_control
4664     if (profile != EEsProfile && version >= 400) {
4665         stageBuiltins[EShLangFragment].append(derivativeControls);
4666         stageBuiltins[EShLangFragment].append("\n");
4667     }
4668 
4669     // GL_OES_shader_multisample_interpolation
4670     if ((profile == EEsProfile && version >= 310) ||
4671         (profile != EEsProfile && version >= 400)) {
4672         stageBuiltins[EShLangFragment].append(
4673             "float interpolateAtCentroid(float);"
4674             "vec2  interpolateAtCentroid(vec2);"
4675             "vec3  interpolateAtCentroid(vec3);"
4676             "vec4  interpolateAtCentroid(vec4);"
4677 
4678             "float interpolateAtSample(float, int);"
4679             "vec2  interpolateAtSample(vec2,  int);"
4680             "vec3  interpolateAtSample(vec3,  int);"
4681             "vec4  interpolateAtSample(vec4,  int);"
4682 
4683             "float interpolateAtOffset(float, vec2);"
4684             "vec2  interpolateAtOffset(vec2,  vec2);"
4685             "vec3  interpolateAtOffset(vec3,  vec2);"
4686             "vec4  interpolateAtOffset(vec4,  vec2);"
4687 
4688             "\n");
4689     }
4690 
4691     stageBuiltins[EShLangFragment].append(
4692         "void beginInvocationInterlockARB(void);"
4693         "void endInvocationInterlockARB(void);");
4694 
4695     stageBuiltins[EShLangFragment].append(
4696         "bool helperInvocationEXT();"
4697         "\n");
4698 
4699     // GL_AMD_shader_explicit_vertex_parameter
4700     if (profile != EEsProfile && version >= 450) {
4701         stageBuiltins[EShLangFragment].append(
4702             "float interpolateAtVertexAMD(float, uint);"
4703             "vec2  interpolateAtVertexAMD(vec2,  uint);"
4704             "vec3  interpolateAtVertexAMD(vec3,  uint);"
4705             "vec4  interpolateAtVertexAMD(vec4,  uint);"
4706 
4707             "int   interpolateAtVertexAMD(int,   uint);"
4708             "ivec2 interpolateAtVertexAMD(ivec2, uint);"
4709             "ivec3 interpolateAtVertexAMD(ivec3, uint);"
4710             "ivec4 interpolateAtVertexAMD(ivec4, uint);"
4711 
4712             "uint  interpolateAtVertexAMD(uint,  uint);"
4713             "uvec2 interpolateAtVertexAMD(uvec2, uint);"
4714             "uvec3 interpolateAtVertexAMD(uvec3, uint);"
4715             "uvec4 interpolateAtVertexAMD(uvec4, uint);"
4716 
4717             "float16_t interpolateAtVertexAMD(float16_t, uint);"
4718             "f16vec2   interpolateAtVertexAMD(f16vec2,   uint);"
4719             "f16vec3   interpolateAtVertexAMD(f16vec3,   uint);"
4720             "f16vec4   interpolateAtVertexAMD(f16vec4,   uint);"
4721 
4722             "\n");
4723     }
4724 
4725     // GL_AMD_gpu_shader_half_float
4726     if (profile != EEsProfile && version >= 450) {
4727         stageBuiltins[EShLangFragment].append(derivativesAndControl16bits);
4728         stageBuiltins[EShLangFragment].append("\n");
4729 
4730         stageBuiltins[EShLangFragment].append(
4731             "float16_t interpolateAtCentroid(float16_t);"
4732             "f16vec2   interpolateAtCentroid(f16vec2);"
4733             "f16vec3   interpolateAtCentroid(f16vec3);"
4734             "f16vec4   interpolateAtCentroid(f16vec4);"
4735 
4736             "float16_t interpolateAtSample(float16_t, int);"
4737             "f16vec2   interpolateAtSample(f16vec2,   int);"
4738             "f16vec3   interpolateAtSample(f16vec3,   int);"
4739             "f16vec4   interpolateAtSample(f16vec4,   int);"
4740 
4741             "float16_t interpolateAtOffset(float16_t, f16vec2);"
4742             "f16vec2   interpolateAtOffset(f16vec2,   f16vec2);"
4743             "f16vec3   interpolateAtOffset(f16vec3,   f16vec2);"
4744             "f16vec4   interpolateAtOffset(f16vec4,   f16vec2);"
4745 
4746             "\n");
4747     }
4748 
4749     // GL_ARB_shader_clock& GL_EXT_shader_realtime_clock
4750     if (profile != EEsProfile && version >= 450) {
4751         commonBuiltins.append(
4752             "uvec2 clock2x32ARB();"
4753             "uint64_t clockARB();"
4754             "uvec2 clockRealtime2x32EXT();"
4755             "uint64_t clockRealtimeEXT();"
4756             "\n");
4757     }
4758 
4759     // GL_AMD_shader_fragment_mask
4760     if (profile != EEsProfile && version >= 450 && spvVersion.vulkan > 0) {
4761         stageBuiltins[EShLangFragment].append(
4762             "uint fragmentMaskFetchAMD(subpassInputMS);"
4763             "uint fragmentMaskFetchAMD(isubpassInputMS);"
4764             "uint fragmentMaskFetchAMD(usubpassInputMS);"
4765 
4766             "vec4  fragmentFetchAMD(subpassInputMS,  uint);"
4767             "ivec4 fragmentFetchAMD(isubpassInputMS, uint);"
4768             "uvec4 fragmentFetchAMD(usubpassInputMS, uint);"
4769 
4770             "\n");
4771     }
4772 
4773     // Builtins for GL_NV_ray_tracing/GL_NV_ray_tracing_motion_blur/GL_EXT_ray_tracing/GL_EXT_ray_query/
4774     // GL_NV_shader_invocation_reorder/GL_KHR_ray_tracing_position_Fetch
4775     if (profile != EEsProfile && version >= 460) {
4776          commonBuiltins.append("void rayQueryInitializeEXT(rayQueryEXT, accelerationStructureEXT, uint, uint, vec3, float, vec3, float);"
4777             "void rayQueryTerminateEXT(rayQueryEXT);"
4778             "void rayQueryGenerateIntersectionEXT(rayQueryEXT, float);"
4779             "void rayQueryConfirmIntersectionEXT(rayQueryEXT);"
4780             "bool rayQueryProceedEXT(rayQueryEXT);"
4781             "uint rayQueryGetIntersectionTypeEXT(rayQueryEXT, bool);"
4782             "float rayQueryGetRayTMinEXT(rayQueryEXT);"
4783             "uint rayQueryGetRayFlagsEXT(rayQueryEXT);"
4784             "vec3 rayQueryGetWorldRayOriginEXT(rayQueryEXT);"
4785             "vec3 rayQueryGetWorldRayDirectionEXT(rayQueryEXT);"
4786             "float rayQueryGetIntersectionTEXT(rayQueryEXT, bool);"
4787             "int rayQueryGetIntersectionInstanceCustomIndexEXT(rayQueryEXT, bool);"
4788             "int rayQueryGetIntersectionInstanceIdEXT(rayQueryEXT, bool);"
4789             "uint rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT(rayQueryEXT, bool);"
4790             "int rayQueryGetIntersectionGeometryIndexEXT(rayQueryEXT, bool);"
4791             "int rayQueryGetIntersectionPrimitiveIndexEXT(rayQueryEXT, bool);"
4792             "vec2 rayQueryGetIntersectionBarycentricsEXT(rayQueryEXT, bool);"
4793             "bool rayQueryGetIntersectionFrontFaceEXT(rayQueryEXT, bool);"
4794             "bool rayQueryGetIntersectionCandidateAABBOpaqueEXT(rayQueryEXT);"
4795             "vec3 rayQueryGetIntersectionObjectRayDirectionEXT(rayQueryEXT, bool);"
4796             "vec3 rayQueryGetIntersectionObjectRayOriginEXT(rayQueryEXT, bool);"
4797             "mat4x3 rayQueryGetIntersectionObjectToWorldEXT(rayQueryEXT, bool);"
4798             "mat4x3 rayQueryGetIntersectionWorldToObjectEXT(rayQueryEXT, bool);"
4799             "void rayQueryGetIntersectionTriangleVertexPositionsEXT(rayQueryEXT, bool, out vec3[3]);"
4800             "\n");
4801 
4802         stageBuiltins[EShLangRayGen].append(
4803             "void traceNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4804             "void traceRayMotionNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,float,int);"
4805             "void traceRayEXT(accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4806             "void executeCallableNV(uint, int);"
4807             "void executeCallableEXT(uint, int);"
4808             "void hitObjectTraceRayNV(hitObjectNV,accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4809             "void hitObjectTraceRayMotionNV(hitObjectNV,accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,float,int);"
4810             "void hitObjectRecordHitNV(hitObjectNV,accelerationStructureEXT,int,int,int,uint,uint,uint,vec3,float,vec3,float,int);"
4811             "void hitObjectRecordHitMotionNV(hitObjectNV,accelerationStructureEXT,int,int,int,uint,uint,uint,vec3,float,vec3,float,float,int);"
4812             "void hitObjectRecordHitWithIndexNV(hitObjectNV, accelerationStructureEXT,int,int,int,uint,uint,vec3,float,vec3,float,int);"
4813             "void hitObjectRecordHitWithIndexMotionNV(hitObjectNV, accelerationStructureEXT,int,int,int,uint,uint,vec3,float,vec3,float,float,int);"
4814             "void hitObjectRecordMissNV(hitObjectNV,uint,vec3,float,vec3,float);"
4815             "void hitObjectRecordMissMotionNV(hitObjectNV,uint,vec3,float,vec3,float,float);"
4816             "void hitObjectRecordEmptyNV(hitObjectNV);"
4817             "void hitObjectExecuteShaderNV(hitObjectNV,int);"
4818             "bool hitObjectIsEmptyNV(hitObjectNV);"
4819             "bool hitObjectIsMissNV(hitObjectNV);"
4820             "bool hitObjectIsHitNV(hitObjectNV);"
4821             "float hitObjectGetRayTMinNV(hitObjectNV);"
4822             "float hitObjectGetRayTMaxNV(hitObjectNV);"
4823             "vec3 hitObjectGetWorldRayOriginNV(hitObjectNV);"
4824             "vec3 hitObjectGetWorldRayDirectionNV(hitObjectNV);"
4825             "vec3 hitObjectGetObjectRayOriginNV(hitObjectNV);"
4826             "vec3 hitObjectGetObjectRayDirectionNV(hitObjectNV);"
4827             "mat4x3 hitObjectGetWorldToObjectNV(hitObjectNV);"
4828             "mat4x3 hitObjectGetObjectToWorldNV(hitObjectNV);"
4829             "int hitObjectGetInstanceCustomIndexNV(hitObjectNV);"
4830             "int hitObjectGetInstanceIdNV(hitObjectNV);"
4831             "int hitObjectGetGeometryIndexNV(hitObjectNV);"
4832             "int hitObjectGetPrimitiveIndexNV(hitObjectNV);"
4833             "uint hitObjectGetHitKindNV(hitObjectNV);"
4834             "void hitObjectGetAttributesNV(hitObjectNV,int);"
4835             "float hitObjectGetCurrentTimeNV(hitObjectNV);"
4836             "uint hitObjectGetShaderBindingTableRecordIndexNV(hitObjectNV);"
4837             "uvec2 hitObjectGetShaderRecordBufferHandleNV(hitObjectNV);"
4838             "void reorderThreadNV(uint, uint);"
4839             "void reorderThreadNV(hitObjectNV);"
4840             "void reorderThreadNV(hitObjectNV, uint, uint);"
4841             "vec3 fetchMicroTriangleVertexPositionNV(accelerationStructureEXT, int, int, int, ivec2);"
4842             "vec2 fetchMicroTriangleVertexBarycentricNV(accelerationStructureEXT, int, int, int, ivec2);"
4843             "\n");
4844         stageBuiltins[EShLangIntersect].append(
4845             "bool reportIntersectionNV(float, uint);"
4846             "bool reportIntersectionEXT(float, uint);"
4847             "\n");
4848         stageBuiltins[EShLangAnyHit].append(
4849             "void ignoreIntersectionNV();"
4850             "void terminateRayNV();"
4851             "\n");
4852         stageBuiltins[EShLangClosestHit].append(
4853             "void traceNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4854             "void traceRayMotionNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,float,int);"
4855             "void traceRayEXT(accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4856             "void executeCallableNV(uint, int);"
4857             "void executeCallableEXT(uint, int);"
4858             "void hitObjectTraceRayNV(hitObjectNV,accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4859             "void hitObjectTraceRayMotionNV(hitObjectNV,accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,float,int);"
4860             "void hitObjectRecordHitNV(hitObjectNV,accelerationStructureEXT,int,int,int,uint,uint,uint,vec3,float,vec3,float,int);"
4861             "void hitObjectRecordHitMotionNV(hitObjectNV,accelerationStructureEXT,int,int,int,uint,uint,uint,vec3,float,vec3,float,float,int);"
4862             "void hitObjectRecordHitWithIndexNV(hitObjectNV,accelerationStructureEXT,int,int,int,uint,uint,vec3,float,vec3,float,int);"
4863             "void hitObjectRecordHitWithIndexMotionNV(hitObjectNV, accelerationStructureEXT,int,int,int,uint,uint,vec3,float,vec3,float,float,int);"
4864             "void hitObjectRecordMissNV(hitObjectNV, uint, vec3, float, vec3, float);"
4865             "void hitObjectRecordMissMotionNV(hitObjectNV,uint,vec3,float,vec3,float,float);"
4866             "void hitObjectRecordEmptyNV(hitObjectNV);"
4867             "void hitObjectExecuteShaderNV(hitObjectNV, int);"
4868             "bool hitObjectIsEmptyNV(hitObjectNV);"
4869             "bool hitObjectIsMissNV(hitObjectNV);"
4870             "bool hitObjectIsHitNV(hitObjectNV);"
4871             "float hitObjectGetRayTMinNV(hitObjectNV);"
4872             "float hitObjectGetRayTMaxNV(hitObjectNV);"
4873             "vec3 hitObjectGetWorldRayOriginNV(hitObjectNV);"
4874             "vec3 hitObjectGetWorldRayDirectionNV(hitObjectNV);"
4875             "vec3 hitObjectGetObjectRayOriginNV(hitObjectNV);"
4876             "vec3 hitObjectGetObjectRayDirectionNV(hitObjectNV);"
4877             "mat4x3 hitObjectGetWorldToObjectNV(hitObjectNV);"
4878             "mat4x3 hitObjectGetObjectToWorldNV(hitObjectNV);"
4879             "int hitObjectGetInstanceCustomIndexNV(hitObjectNV);"
4880             "int hitObjectGetInstanceIdNV(hitObjectNV);"
4881             "int hitObjectGetGeometryIndexNV(hitObjectNV);"
4882             "int hitObjectGetPrimitiveIndexNV(hitObjectNV);"
4883             "uint hitObjectGetHitKindNV(hitObjectNV);"
4884             "void hitObjectGetAttributesNV(hitObjectNV,int);"
4885             "float hitObjectGetCurrentTimeNV(hitObjectNV);"
4886             "uint hitObjectGetShaderBindingTableRecordIndexNV(hitObjectNV);"
4887             "uvec2 hitObjectGetShaderRecordBufferHandleNV(hitObjectNV);"
4888             "\n");
4889         stageBuiltins[EShLangMiss].append(
4890             "void traceNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4891             "void traceRayMotionNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,float,int);"
4892             "void traceRayEXT(accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4893             "void executeCallableNV(uint, int);"
4894             "void executeCallableEXT(uint, int);"
4895             "void hitObjectTraceRayNV(hitObjectNV,accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
4896             "void hitObjectTraceRayMotionNV(hitObjectNV,accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,float,int);"
4897             "void hitObjectRecordHitNV(hitObjectNV,accelerationStructureEXT,int,int,int,uint,uint,uint,vec3,float,vec3,float,int);"
4898             "void hitObjectRecordHitMotionNV(hitObjectNV,accelerationStructureEXT,int,int,int,uint,uint,uint,vec3,float,vec3,float,float,int);"
4899             "void hitObjectRecordHitWithIndexNV(hitObjectNV,accelerationStructureEXT,int,int,int,uint,uint,vec3,float,vec3,float,int);"
4900             "void hitObjectRecordHitWithIndexMotionNV(hitObjectNV, accelerationStructureEXT,int,int,int,uint,uint,vec3,float,vec3,float,float,int);"
4901             "void hitObjectRecordMissNV(hitObjectNV, uint, vec3, float, vec3, float);"
4902             "void hitObjectRecordMissMotionNV(hitObjectNV,uint,vec3,float,vec3,float,float);"
4903             "void hitObjectRecordEmptyNV(hitObjectNV);"
4904             "void hitObjectExecuteShaderNV(hitObjectNV, int);"
4905             "bool hitObjectIsEmptyNV(hitObjectNV);"
4906             "bool hitObjectIsMissNV(hitObjectNV);"
4907             "bool hitObjectIsHitNV(hitObjectNV);"
4908             "float hitObjectGetRayTMinNV(hitObjectNV);"
4909             "float hitObjectGetRayTMaxNV(hitObjectNV);"
4910             "vec3 hitObjectGetWorldRayOriginNV(hitObjectNV);"
4911             "vec3 hitObjectGetWorldRayDirectionNV(hitObjectNV);"
4912             "vec3 hitObjectGetObjectRayOriginNV(hitObjectNV);"
4913             "vec3 hitObjectGetObjectRayDirectionNV(hitObjectNV);"
4914             "mat4x3 hitObjectGetWorldToObjectNV(hitObjectNV);"
4915             "mat4x3 hitObjectGetObjectToWorldNV(hitObjectNV);"
4916             "int hitObjectGetInstanceCustomIndexNV(hitObjectNV);"
4917             "int hitObjectGetInstanceIdNV(hitObjectNV);"
4918             "int hitObjectGetGeometryIndexNV(hitObjectNV);"
4919             "int hitObjectGetPrimitiveIndexNV(hitObjectNV);"
4920             "uint hitObjectGetHitKindNV(hitObjectNV);"
4921             "void hitObjectGetAttributesNV(hitObjectNV,int);"
4922             "float hitObjectGetCurrentTimeNV(hitObjectNV);"
4923             "uint hitObjectGetShaderBindingTableRecordIndexNV(hitObjectNV);"
4924             "uvec2 hitObjectGetShaderRecordBufferHandleNV(hitObjectNV);"
4925             "\n");
4926         stageBuiltins[EShLangCallable].append(
4927             "void executeCallableNV(uint, int);"
4928             "void executeCallableEXT(uint, int);"
4929             "\n");
4930     }
4931 
4932     //E_SPV_NV_compute_shader_derivatives
4933     if ((profile == EEsProfile && version >= 320) || (profile != EEsProfile && version >= 450)) {
4934         stageBuiltins[EShLangCompute].append(derivativeControls);
4935         stageBuiltins[EShLangCompute].append("\n");
4936     }
4937     if (profile != EEsProfile && version >= 450) {
4938         stageBuiltins[EShLangCompute].append(derivativesAndControl16bits);
4939         stageBuiltins[EShLangCompute].append(derivativesAndControl64bits);
4940         stageBuiltins[EShLangCompute].append("\n");
4941     }
4942 
4943     // Builtins for GL_NV_mesh_shader
4944     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
4945         stageBuiltins[EShLangMesh].append(
4946             "void writePackedPrimitiveIndices4x8NV(uint, uint);"
4947             "\n");
4948     }
4949     // Builtins for GL_EXT_mesh_shader
4950     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
4951         // Builtins for GL_EXT_mesh_shader
4952         stageBuiltins[EShLangTask].append(
4953             "void EmitMeshTasksEXT(uint, uint, uint);"
4954             "\n");
4955 
4956         stageBuiltins[EShLangMesh].append(
4957             "void SetMeshOutputsEXT(uint, uint);"
4958             "\n");
4959     }
4960     // Builtins for GL_NV_displacement_micromap
4961     if ((profile != EEsProfile && version >= 460) || (profile == EEsProfile && version >= 320)) {
4962         stageBuiltins[EShLangMesh].append(
4963             "vec3 fetchMicroTriangleVertexPositionNV(accelerationStructureEXT, int, int, int, ivec2);"
4964             "vec2 fetchMicroTriangleVertexBarycentricNV(accelerationStructureEXT, int, int, int, ivec2);"
4965             "\n");
4966 
4967         stageBuiltins[EShLangCompute].append(
4968             "vec3 fetchMicroTriangleVertexPositionNV(accelerationStructureEXT, int, int, int, ivec2);"
4969             "vec2 fetchMicroTriangleVertexBarycentricNV(accelerationStructureEXT, int, int, int, ivec2);"
4970             "\n");
4971 
4972     }
4973 
4974 
4975     //============================================================================
4976     //
4977     // Standard Uniforms
4978     //
4979     //============================================================================
4980 
4981     //
4982     // Depth range in window coordinates, p. 33
4983     //
4984     if (spvVersion.spv == 0) {
4985         commonBuiltins.append(
4986             "struct gl_DepthRangeParameters {"
4987             );
4988         if (profile == EEsProfile) {
4989             commonBuiltins.append(
4990                 "highp float near;"   // n
4991                 "highp float far;"    // f
4992                 "highp float diff;"   // f - n
4993                 );
4994         } else {
4995             commonBuiltins.append(
4996                 "float near;"  // n
4997                 "float far;"   // f
4998                 "float diff;"  // f - n
4999                 );
5000         }
5001 
5002         commonBuiltins.append(
5003             "};"
5004             "uniform gl_DepthRangeParameters gl_DepthRange;"
5005             "\n");
5006     }
5007 
5008     if (spvVersion.spv == 0 && IncludeLegacy(version, profile, spvVersion)) {
5009         //
5010         // Matrix state. p. 31, 32, 37, 39, 40.
5011         //
5012         commonBuiltins.append(
5013             "uniform mat4  gl_ModelViewMatrix;"
5014             "uniform mat4  gl_ProjectionMatrix;"
5015             "uniform mat4  gl_ModelViewProjectionMatrix;"
5016 
5017             //
5018             // Derived matrix state that provides inverse and transposed versions
5019             // of the matrices above.
5020             //
5021             "uniform mat3  gl_NormalMatrix;"
5022 
5023             "uniform mat4  gl_ModelViewMatrixInverse;"
5024             "uniform mat4  gl_ProjectionMatrixInverse;"
5025             "uniform mat4  gl_ModelViewProjectionMatrixInverse;"
5026 
5027             "uniform mat4  gl_ModelViewMatrixTranspose;"
5028             "uniform mat4  gl_ProjectionMatrixTranspose;"
5029             "uniform mat4  gl_ModelViewProjectionMatrixTranspose;"
5030 
5031             "uniform mat4  gl_ModelViewMatrixInverseTranspose;"
5032             "uniform mat4  gl_ProjectionMatrixInverseTranspose;"
5033             "uniform mat4  gl_ModelViewProjectionMatrixInverseTranspose;"
5034 
5035             //
5036             // Normal scaling p. 39.
5037             //
5038             "uniform float gl_NormalScale;"
5039 
5040             //
5041             // Point Size, p. 66, 67.
5042             //
5043             "struct gl_PointParameters {"
5044                 "float size;"
5045                 "float sizeMin;"
5046                 "float sizeMax;"
5047                 "float fadeThresholdSize;"
5048                 "float distanceConstantAttenuation;"
5049                 "float distanceLinearAttenuation;"
5050                 "float distanceQuadraticAttenuation;"
5051             "};"
5052 
5053             "uniform gl_PointParameters gl_Point;"
5054 
5055             //
5056             // Material State p. 50, 55.
5057             //
5058             "struct gl_MaterialParameters {"
5059                 "vec4  emission;"    // Ecm
5060                 "vec4  ambient;"     // Acm
5061                 "vec4  diffuse;"     // Dcm
5062                 "vec4  specular;"    // Scm
5063                 "float shininess;"   // Srm
5064             "};"
5065             "uniform gl_MaterialParameters  gl_FrontMaterial;"
5066             "uniform gl_MaterialParameters  gl_BackMaterial;"
5067 
5068             //
5069             // Light State p 50, 53, 55.
5070             //
5071             "struct gl_LightSourceParameters {"
5072                 "vec4  ambient;"             // Acli
5073                 "vec4  diffuse;"             // Dcli
5074                 "vec4  specular;"            // Scli
5075                 "vec4  position;"            // Ppli
5076                 "vec4  halfVector;"          // Derived: Hi
5077                 "vec3  spotDirection;"       // Sdli
5078                 "float spotExponent;"        // Srli
5079                 "float spotCutoff;"          // Crli
5080                                                         // (range: [0.0,90.0], 180.0)
5081                 "float spotCosCutoff;"       // Derived: cos(Crli)
5082                                                         // (range: [1.0,0.0],-1.0)
5083                 "float constantAttenuation;" // K0
5084                 "float linearAttenuation;"   // K1
5085                 "float quadraticAttenuation;"// K2
5086             "};"
5087 
5088             "struct gl_LightModelParameters {"
5089                 "vec4  ambient;"       // Acs
5090             "};"
5091 
5092             "uniform gl_LightModelParameters  gl_LightModel;"
5093 
5094             //
5095             // Derived state from products of light and material.
5096             //
5097             "struct gl_LightModelProducts {"
5098                 "vec4  sceneColor;"     // Derived. Ecm + Acm * Acs
5099             "};"
5100 
5101             "uniform gl_LightModelProducts gl_FrontLightModelProduct;"
5102             "uniform gl_LightModelProducts gl_BackLightModelProduct;"
5103 
5104             "struct gl_LightProducts {"
5105                 "vec4  ambient;"        // Acm * Acli
5106                 "vec4  diffuse;"        // Dcm * Dcli
5107                 "vec4  specular;"       // Scm * Scli
5108             "};"
5109 
5110             //
5111             // Fog p. 161
5112             //
5113             "struct gl_FogParameters {"
5114                 "vec4  color;"
5115                 "float density;"
5116                 "float start;"
5117                 "float end;"
5118                 "float scale;"   //  1 / (gl_FogEnd - gl_FogStart)
5119             "};"
5120 
5121             "uniform gl_FogParameters gl_Fog;"
5122 
5123             "\n");
5124     }
5125 
5126     //============================================================================
5127     //
5128     // Define the interface to the compute shader.
5129     //
5130     //============================================================================
5131 
5132     if ((profile != EEsProfile && version >= 420) ||
5133         (profile == EEsProfile && version >= 310)) {
5134         stageBuiltins[EShLangCompute].append(
5135             "in    highp uvec3 gl_NumWorkGroups;"
5136             "const highp uvec3 gl_WorkGroupSize = uvec3(1,1,1);"
5137 
5138             "in highp uvec3 gl_WorkGroupID;"
5139             "in highp uvec3 gl_LocalInvocationID;"
5140 
5141             "in highp uvec3 gl_GlobalInvocationID;"
5142             "in highp uint gl_LocalInvocationIndex;"
5143 
5144             "\n");
5145     }
5146 
5147     if ((profile != EEsProfile && version >= 140) ||
5148         (profile == EEsProfile && version >= 310)) {
5149         stageBuiltins[EShLangCompute].append(
5150             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5151             "\n");
5152     }
5153 
5154     //============================================================================
5155     //
5156     // Define the interface to the mesh/task shader.
5157     //
5158     //============================================================================
5159 
5160     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
5161         // per-vertex attributes
5162         stageBuiltins[EShLangMesh].append(
5163             "out gl_MeshPerVertexNV {"
5164                 "vec4 gl_Position;"
5165                 "float gl_PointSize;"
5166                 "float gl_ClipDistance[];"
5167                 "float gl_CullDistance[];"
5168                 "perviewNV vec4 gl_PositionPerViewNV[];"
5169                 "perviewNV float gl_ClipDistancePerViewNV[][];"
5170                 "perviewNV float gl_CullDistancePerViewNV[][];"
5171             "} gl_MeshVerticesNV[];"
5172         );
5173 
5174         // per-primitive attributes
5175         stageBuiltins[EShLangMesh].append(
5176             "perprimitiveNV out gl_MeshPerPrimitiveNV {"
5177                 "int gl_PrimitiveID;"
5178                 "int gl_Layer;"
5179                 "int gl_ViewportIndex;"
5180                 "int gl_ViewportMask[];"
5181                 "perviewNV int gl_LayerPerViewNV[];"
5182                 "perviewNV int gl_ViewportMaskPerViewNV[][];"
5183             "} gl_MeshPrimitivesNV[];"
5184         );
5185 
5186         stageBuiltins[EShLangMesh].append(
5187             "out uint gl_PrimitiveCountNV;"
5188             "out uint gl_PrimitiveIndicesNV[];"
5189 
5190             "in uint gl_MeshViewCountNV;"
5191             "in uint gl_MeshViewIndicesNV[4];"
5192 
5193             "const highp uvec3 gl_WorkGroupSize = uvec3(1,1,1);"
5194 
5195             "in highp uvec3 gl_WorkGroupID;"
5196             "in highp uvec3 gl_LocalInvocationID;"
5197 
5198             "in highp uvec3 gl_GlobalInvocationID;"
5199             "in highp uint gl_LocalInvocationIndex;"
5200             "\n");
5201 
5202         // GL_EXT_mesh_shader
5203         stageBuiltins[EShLangMesh].append(
5204             "out uint gl_PrimitivePointIndicesEXT[];"
5205             "out uvec2 gl_PrimitiveLineIndicesEXT[];"
5206             "out uvec3 gl_PrimitiveTriangleIndicesEXT[];"
5207             "in    highp uvec3 gl_NumWorkGroups;"
5208             "\n");
5209 
5210         // per-vertex attributes
5211         stageBuiltins[EShLangMesh].append(
5212             "out gl_MeshPerVertexEXT {"
5213                 "vec4 gl_Position;"
5214                 "float gl_PointSize;"
5215                 "float gl_ClipDistance[];"
5216                 "float gl_CullDistance[];"
5217             "} gl_MeshVerticesEXT[];"
5218         );
5219 
5220         // per-primitive attributes
5221         stageBuiltins[EShLangMesh].append(
5222             "perprimitiveEXT out gl_MeshPerPrimitiveEXT {"
5223                 "int gl_PrimitiveID;"
5224                 "int gl_Layer;"
5225                 "int gl_ViewportIndex;"
5226                 "bool gl_CullPrimitiveEXT;"
5227                 "int  gl_PrimitiveShadingRateEXT;"
5228             "} gl_MeshPrimitivesEXT[];"
5229         );
5230 
5231         stageBuiltins[EShLangTask].append(
5232             "out uint gl_TaskCountNV;"
5233 
5234             "const highp uvec3 gl_WorkGroupSize = uvec3(1,1,1);"
5235 
5236             "in highp uvec3 gl_WorkGroupID;"
5237             "in highp uvec3 gl_LocalInvocationID;"
5238 
5239             "in highp uvec3 gl_GlobalInvocationID;"
5240             "in highp uint gl_LocalInvocationIndex;"
5241 
5242             "in uint gl_MeshViewCountNV;"
5243             "in uint gl_MeshViewIndicesNV[4];"
5244             "in    highp uvec3 gl_NumWorkGroups;"
5245             "\n");
5246     }
5247 
5248     if (profile != EEsProfile && version >= 450) {
5249         stageBuiltins[EShLangMesh].append(
5250             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5251             "in int gl_DrawIDARB;"             // GL_ARB_shader_draw_parameters
5252             "in int gl_ViewIndex;"             // GL_EXT_multiview
5253             "\n");
5254 
5255         stageBuiltins[EShLangTask].append(
5256             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5257             "in int gl_DrawIDARB;"             // GL_ARB_shader_draw_parameters
5258             "\n");
5259 
5260         if (version >= 460) {
5261             stageBuiltins[EShLangMesh].append(
5262                 "in int gl_DrawID;"
5263                 "\n");
5264 
5265             stageBuiltins[EShLangTask].append(
5266                 "in int gl_DrawID;"
5267                 "\n");
5268         }
5269     }
5270 
5271     //============================================================================
5272     //
5273     // Define the interface to the vertex shader.
5274     //
5275     //============================================================================
5276 
5277     if (profile != EEsProfile) {
5278         if (version < 130) {
5279             stageBuiltins[EShLangVertex].append(
5280                 "attribute vec4  gl_Color;"
5281                 "attribute vec4  gl_SecondaryColor;"
5282                 "attribute vec3  gl_Normal;"
5283                 "attribute vec4  gl_Vertex;"
5284                 "attribute vec4  gl_MultiTexCoord0;"
5285                 "attribute vec4  gl_MultiTexCoord1;"
5286                 "attribute vec4  gl_MultiTexCoord2;"
5287                 "attribute vec4  gl_MultiTexCoord3;"
5288                 "attribute vec4  gl_MultiTexCoord4;"
5289                 "attribute vec4  gl_MultiTexCoord5;"
5290                 "attribute vec4  gl_MultiTexCoord6;"
5291                 "attribute vec4  gl_MultiTexCoord7;"
5292                 "attribute float gl_FogCoord;"
5293                 "\n");
5294         } else if (IncludeLegacy(version, profile, spvVersion)) {
5295             stageBuiltins[EShLangVertex].append(
5296                 "in vec4  gl_Color;"
5297                 "in vec4  gl_SecondaryColor;"
5298                 "in vec3  gl_Normal;"
5299                 "in vec4  gl_Vertex;"
5300                 "in vec4  gl_MultiTexCoord0;"
5301                 "in vec4  gl_MultiTexCoord1;"
5302                 "in vec4  gl_MultiTexCoord2;"
5303                 "in vec4  gl_MultiTexCoord3;"
5304                 "in vec4  gl_MultiTexCoord4;"
5305                 "in vec4  gl_MultiTexCoord5;"
5306                 "in vec4  gl_MultiTexCoord6;"
5307                 "in vec4  gl_MultiTexCoord7;"
5308                 "in float gl_FogCoord;"
5309                 "\n");
5310         }
5311 
5312         if (version < 150) {
5313             if (version < 130) {
5314                 stageBuiltins[EShLangVertex].append(
5315                     "        vec4  gl_ClipVertex;"       // needs qualifier fixed later
5316                     "varying vec4  gl_FrontColor;"
5317                     "varying vec4  gl_BackColor;"
5318                     "varying vec4  gl_FrontSecondaryColor;"
5319                     "varying vec4  gl_BackSecondaryColor;"
5320                     "varying vec4  gl_TexCoord[];"
5321                     "varying float gl_FogFragCoord;"
5322                     "\n");
5323             } else if (IncludeLegacy(version, profile, spvVersion)) {
5324                 stageBuiltins[EShLangVertex].append(
5325                     "    vec4  gl_ClipVertex;"       // needs qualifier fixed later
5326                     "out vec4  gl_FrontColor;"
5327                     "out vec4  gl_BackColor;"
5328                     "out vec4  gl_FrontSecondaryColor;"
5329                     "out vec4  gl_BackSecondaryColor;"
5330                     "out vec4  gl_TexCoord[];"
5331                     "out float gl_FogFragCoord;"
5332                     "\n");
5333             }
5334             stageBuiltins[EShLangVertex].append(
5335                 "vec4 gl_Position;"   // needs qualifier fixed later
5336                 "float gl_PointSize;" // needs qualifier fixed later
5337                 );
5338 
5339             if (version == 130 || version == 140)
5340                 stageBuiltins[EShLangVertex].append(
5341                     "out float gl_ClipDistance[];"
5342                     );
5343         } else {
5344             // version >= 150
5345             stageBuiltins[EShLangVertex].append(
5346                 "out gl_PerVertex {"
5347                     "vec4 gl_Position;"     // needs qualifier fixed later
5348                     "float gl_PointSize;"   // needs qualifier fixed later
5349                     "float gl_ClipDistance[];"
5350                     );
5351             if (IncludeLegacy(version, profile, spvVersion))
5352                 stageBuiltins[EShLangVertex].append(
5353                     "vec4 gl_ClipVertex;"   // needs qualifier fixed later
5354                     "vec4 gl_FrontColor;"
5355                     "vec4 gl_BackColor;"
5356                     "vec4 gl_FrontSecondaryColor;"
5357                     "vec4 gl_BackSecondaryColor;"
5358                     "vec4 gl_TexCoord[];"
5359                     "float gl_FogFragCoord;"
5360                     );
5361             if (version >= 450)
5362                 stageBuiltins[EShLangVertex].append(
5363                     "float gl_CullDistance[];"
5364                     );
5365             stageBuiltins[EShLangVertex].append(
5366                 "};"
5367                 "\n");
5368         }
5369         if (version >= 130 && spvVersion.vulkan == 0)
5370             stageBuiltins[EShLangVertex].append(
5371                 "int gl_VertexID;"            // needs qualifier fixed later
5372                 );
5373         if (spvVersion.vulkan == 0)
5374             stageBuiltins[EShLangVertex].append(
5375                 "int gl_InstanceID;"          // needs qualifier fixed later
5376                 );
5377         if (spvVersion.vulkan > 0 && version >= 140)
5378             stageBuiltins[EShLangVertex].append(
5379                 "in int gl_VertexIndex;"
5380                 "in int gl_InstanceIndex;"
5381                 );
5382 
5383         if (spvVersion.vulkan > 0 && version >= 140 && spvVersion.vulkanRelaxed)
5384             stageBuiltins[EShLangVertex].append(
5385                 "in int gl_VertexID;"         // declare with 'in' qualifier
5386                 "in int gl_InstanceID;"
5387                 );
5388 
5389         if (version >= 440) {
5390             stageBuiltins[EShLangVertex].append(
5391                 "in int gl_BaseVertexARB;"
5392                 "in int gl_BaseInstanceARB;"
5393                 "in int gl_DrawIDARB;"
5394                 );
5395         }
5396         if (version >= 410) {
5397             stageBuiltins[EShLangVertex].append(
5398                 "out int gl_ViewportIndex;"
5399                 "out int gl_Layer;"
5400                 );
5401         }
5402         if (version >= 460) {
5403             stageBuiltins[EShLangVertex].append(
5404                 "in int gl_BaseVertex;"
5405                 "in int gl_BaseInstance;"
5406                 "in int gl_DrawID;"
5407                 );
5408         }
5409 
5410         if (version >= 430)
5411             stageBuiltins[EShLangVertex].append(
5412                 "out int gl_ViewportMask[];"             // GL_NV_viewport_array2
5413                 );
5414 
5415         if (version >= 450)
5416             stageBuiltins[EShLangVertex].append(
5417                 "out int gl_SecondaryViewportMaskNV[];"  // GL_NV_stereo_view_rendering
5418                 "out vec4 gl_SecondaryPositionNV;"       // GL_NV_stereo_view_rendering
5419                 "out vec4 gl_PositionPerViewNV[];"       // GL_NVX_multiview_per_view_attributes
5420                 "out int  gl_ViewportMaskPerViewNV[];"   // GL_NVX_multiview_per_view_attributes
5421                 );
5422     } else {
5423         // ES profile
5424         if (version == 100) {
5425             stageBuiltins[EShLangVertex].append(
5426                 "highp   vec4  gl_Position;"  // needs qualifier fixed later
5427                 "mediump float gl_PointSize;" // needs qualifier fixed later
5428                 "highp int gl_InstanceID;" // needs qualifier fixed later
5429                 );
5430         } else {
5431             if (spvVersion.vulkan == 0 || spvVersion.vulkanRelaxed)
5432                 stageBuiltins[EShLangVertex].append(
5433                     "in highp int gl_VertexID;"      // needs qualifier fixed later
5434                     "in highp int gl_InstanceID;"    // needs qualifier fixed later
5435                     );
5436             if (spvVersion.vulkan > 0)
5437                 stageBuiltins[EShLangVertex].append(
5438                     "in highp int gl_VertexIndex;"
5439                     "in highp int gl_InstanceIndex;"
5440                     );
5441             if (version < 310)
5442                 stageBuiltins[EShLangVertex].append(
5443                     "highp vec4  gl_Position;"    // needs qualifier fixed later
5444                     "highp float gl_PointSize;"   // needs qualifier fixed later
5445                     );
5446             else
5447                 stageBuiltins[EShLangVertex].append(
5448                     "out gl_PerVertex {"
5449                         "highp vec4  gl_Position;"    // needs qualifier fixed later
5450                         "highp float gl_PointSize;"   // needs qualifier fixed later
5451                     "};"
5452                     );
5453         }
5454     }
5455 
5456     if ((profile != EEsProfile && version >= 140) ||
5457         (profile == EEsProfile && version >= 310)) {
5458         stageBuiltins[EShLangVertex].append(
5459             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5460             "in highp int gl_ViewIndex;"       // GL_EXT_multiview
5461             "\n");
5462     }
5463 
5464     if (version >= 300 /* both ES and non-ES */) {
5465         stageBuiltins[EShLangVertex].append(
5466             "in highp uint gl_ViewID_OVR;"     // GL_OVR_multiview, GL_OVR_multiview2
5467             "\n");
5468     }
5469 
5470     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
5471         stageBuiltins[EShLangVertex].append(
5472             "out highp int gl_PrimitiveShadingRateEXT;" // GL_EXT_fragment_shading_rate
5473             "\n");
5474     }
5475 
5476     //============================================================================
5477     //
5478     // Define the interface to the geometry shader.
5479     //
5480     //============================================================================
5481 
5482     if (profile == ECoreProfile || profile == ECompatibilityProfile) {
5483         stageBuiltins[EShLangGeometry].append(
5484             "in gl_PerVertex {"
5485                 "vec4 gl_Position;"
5486                 "float gl_PointSize;"
5487                 "float gl_ClipDistance[];"
5488                 );
5489         if (profile == ECompatibilityProfile)
5490             stageBuiltins[EShLangGeometry].append(
5491                 "vec4 gl_ClipVertex;"
5492                 "vec4 gl_FrontColor;"
5493                 "vec4 gl_BackColor;"
5494                 "vec4 gl_FrontSecondaryColor;"
5495                 "vec4 gl_BackSecondaryColor;"
5496                 "vec4 gl_TexCoord[];"
5497                 "float gl_FogFragCoord;"
5498                 );
5499         if (version >= 450)
5500             stageBuiltins[EShLangGeometry].append(
5501                 "float gl_CullDistance[];"
5502                 "vec4 gl_SecondaryPositionNV;"   // GL_NV_stereo_view_rendering
5503                 "vec4 gl_PositionPerViewNV[];"   // GL_NVX_multiview_per_view_attributes
5504                 );
5505         stageBuiltins[EShLangGeometry].append(
5506             "} gl_in[];"
5507 
5508             "in int gl_PrimitiveIDIn;"
5509             "out gl_PerVertex {"
5510                 "vec4 gl_Position;"
5511                 "float gl_PointSize;"
5512                 "float gl_ClipDistance[];"
5513                 "\n");
5514         if (profile == ECompatibilityProfile && version >= 400)
5515             stageBuiltins[EShLangGeometry].append(
5516                 "vec4 gl_ClipVertex;"
5517                 "vec4 gl_FrontColor;"
5518                 "vec4 gl_BackColor;"
5519                 "vec4 gl_FrontSecondaryColor;"
5520                 "vec4 gl_BackSecondaryColor;"
5521                 "vec4 gl_TexCoord[];"
5522                 "float gl_FogFragCoord;"
5523                 );
5524         if (version >= 450)
5525             stageBuiltins[EShLangGeometry].append(
5526                 "float gl_CullDistance[];"
5527                 );
5528         stageBuiltins[EShLangGeometry].append(
5529             "};"
5530 
5531             "out int gl_PrimitiveID;"
5532             "out int gl_Layer;");
5533 
5534         if (version >= 150)
5535             stageBuiltins[EShLangGeometry].append(
5536             "out int gl_ViewportIndex;"
5537             );
5538 
5539         if (profile == ECompatibilityProfile && version < 400)
5540             stageBuiltins[EShLangGeometry].append(
5541             "out vec4 gl_ClipVertex;"
5542             );
5543 
5544         if (version >= 400)
5545             stageBuiltins[EShLangGeometry].append(
5546             "in int gl_InvocationID;"
5547             );
5548 
5549         if (version >= 430)
5550             stageBuiltins[EShLangGeometry].append(
5551                 "out int gl_ViewportMask[];"               // GL_NV_viewport_array2
5552             );
5553 
5554         if (version >= 450)
5555             stageBuiltins[EShLangGeometry].append(
5556                 "out int gl_SecondaryViewportMaskNV[];"    // GL_NV_stereo_view_rendering
5557                 "out vec4 gl_SecondaryPositionNV;"         // GL_NV_stereo_view_rendering
5558                 "out vec4 gl_PositionPerViewNV[];"         // GL_NVX_multiview_per_view_attributes
5559                 "out int  gl_ViewportMaskPerViewNV[];"     // GL_NVX_multiview_per_view_attributes
5560             );
5561 
5562         stageBuiltins[EShLangGeometry].append("\n");
5563     } else if (profile == EEsProfile && version >= 310) {
5564         stageBuiltins[EShLangGeometry].append(
5565             "in gl_PerVertex {"
5566                 "highp vec4 gl_Position;"
5567                 "highp float gl_PointSize;"
5568             "} gl_in[];"
5569             "\n"
5570             "in highp int gl_PrimitiveIDIn;"
5571             "in highp int gl_InvocationID;"
5572             "\n"
5573             "out gl_PerVertex {"
5574                 "highp vec4 gl_Position;"
5575                 "highp float gl_PointSize;"
5576             "};"
5577             "\n"
5578             "out highp int gl_PrimitiveID;"
5579             "out highp int gl_Layer;"
5580             "\n"
5581             );
5582     }
5583 
5584     if ((profile != EEsProfile && version >= 140) ||
5585         (profile == EEsProfile && version >= 310)) {
5586         stageBuiltins[EShLangGeometry].append(
5587             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5588             "in highp int gl_ViewIndex;"       // GL_EXT_multiview
5589             "\n");
5590     }
5591 
5592     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
5593         stageBuiltins[EShLangGeometry].append(
5594             "out highp int gl_PrimitiveShadingRateEXT;" // GL_EXT_fragment_shading_rate
5595             "\n");
5596     }
5597 
5598     //============================================================================
5599     //
5600     // Define the interface to the tessellation control shader.
5601     //
5602     //============================================================================
5603 
5604     if (profile != EEsProfile && version >= 150) {
5605         // Note:  "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below,
5606         // as it depends on the resource sizing of gl_MaxPatchVertices.
5607 
5608         stageBuiltins[EShLangTessControl].append(
5609             "in int gl_PatchVerticesIn;"
5610             "in int gl_PrimitiveID;"
5611             "in int gl_InvocationID;"
5612 
5613             "out gl_PerVertex {"
5614                 "vec4 gl_Position;"
5615                 "float gl_PointSize;"
5616                 "float gl_ClipDistance[];"
5617                 );
5618         if (profile == ECompatibilityProfile)
5619             stageBuiltins[EShLangTessControl].append(
5620                 "vec4 gl_ClipVertex;"
5621                 "vec4 gl_FrontColor;"
5622                 "vec4 gl_BackColor;"
5623                 "vec4 gl_FrontSecondaryColor;"
5624                 "vec4 gl_BackSecondaryColor;"
5625                 "vec4 gl_TexCoord[];"
5626                 "float gl_FogFragCoord;"
5627                 );
5628         if (version >= 450)
5629             stageBuiltins[EShLangTessControl].append(
5630                 "float gl_CullDistance[];"
5631             );
5632         if (version >= 430)
5633             stageBuiltins[EShLangTessControl].append(
5634                 "int  gl_ViewportMask[];"             // GL_NV_viewport_array2
5635             );
5636         if (version >= 450)
5637             stageBuiltins[EShLangTessControl].append(
5638                 "vec4 gl_SecondaryPositionNV;"        // GL_NV_stereo_view_rendering
5639                 "int  gl_SecondaryViewportMaskNV[];"  // GL_NV_stereo_view_rendering
5640                 "vec4 gl_PositionPerViewNV[];"        // GL_NVX_multiview_per_view_attributes
5641                 "int  gl_ViewportMaskPerViewNV[];"    // GL_NVX_multiview_per_view_attributes
5642                 );
5643         stageBuiltins[EShLangTessControl].append(
5644             "} gl_out[];"
5645 
5646             "patch out float gl_TessLevelOuter[4];"
5647             "patch out float gl_TessLevelInner[2];"
5648             "\n");
5649 
5650         if (version >= 410)
5651             stageBuiltins[EShLangTessControl].append(
5652                 "out int gl_ViewportIndex;"
5653                 "out int gl_Layer;"
5654                 "\n");
5655 
5656     } else {
5657         // Note:  "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below,
5658         // as it depends on the resource sizing of gl_MaxPatchVertices.
5659 
5660         stageBuiltins[EShLangTessControl].append(
5661             "in highp int gl_PatchVerticesIn;"
5662             "in highp int gl_PrimitiveID;"
5663             "in highp int gl_InvocationID;"
5664 
5665             "out gl_PerVertex {"
5666                 "highp vec4 gl_Position;"
5667                 "highp float gl_PointSize;"
5668                 );
5669         stageBuiltins[EShLangTessControl].append(
5670             "} gl_out[];"
5671 
5672             "patch out highp float gl_TessLevelOuter[4];"
5673             "patch out highp float gl_TessLevelInner[2];"
5674             "patch out highp vec4 gl_BoundingBoxOES[2];"
5675             "patch out highp vec4 gl_BoundingBoxEXT[2];"
5676             "\n");
5677         if (profile == EEsProfile && version >= 320) {
5678             stageBuiltins[EShLangTessControl].append(
5679                 "patch out highp vec4 gl_BoundingBox[2];"
5680                 "\n"
5681             );
5682         }
5683     }
5684 
5685     if ((profile != EEsProfile && version >= 140) ||
5686         (profile == EEsProfile && version >= 310)) {
5687         stageBuiltins[EShLangTessControl].append(
5688             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5689             "in highp int gl_ViewIndex;"       // GL_EXT_multiview
5690             "\n");
5691     }
5692 
5693     //============================================================================
5694     //
5695     // Define the interface to the tessellation evaluation shader.
5696     //
5697     //============================================================================
5698 
5699     if (profile != EEsProfile && version >= 150) {
5700         // Note:  "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below,
5701         // as it depends on the resource sizing of gl_MaxPatchVertices.
5702 
5703         stageBuiltins[EShLangTessEvaluation].append(
5704             "in int gl_PatchVerticesIn;"
5705             "in int gl_PrimitiveID;"
5706             "in vec3 gl_TessCoord;"
5707 
5708             "patch in float gl_TessLevelOuter[4];"
5709             "patch in float gl_TessLevelInner[2];"
5710 
5711             "out gl_PerVertex {"
5712                 "vec4 gl_Position;"
5713                 "float gl_PointSize;"
5714                 "float gl_ClipDistance[];"
5715             );
5716         if (version >= 400 && profile == ECompatibilityProfile)
5717             stageBuiltins[EShLangTessEvaluation].append(
5718                 "vec4 gl_ClipVertex;"
5719                 "vec4 gl_FrontColor;"
5720                 "vec4 gl_BackColor;"
5721                 "vec4 gl_FrontSecondaryColor;"
5722                 "vec4 gl_BackSecondaryColor;"
5723                 "vec4 gl_TexCoord[];"
5724                 "float gl_FogFragCoord;"
5725                 );
5726         if (version >= 450)
5727             stageBuiltins[EShLangTessEvaluation].append(
5728                 "float gl_CullDistance[];"
5729                 );
5730         stageBuiltins[EShLangTessEvaluation].append(
5731             "};"
5732             "\n");
5733 
5734         if (version >= 410)
5735             stageBuiltins[EShLangTessEvaluation].append(
5736                 "out int gl_ViewportIndex;"
5737                 "out int gl_Layer;"
5738                 "\n");
5739 
5740         if (version >= 430)
5741             stageBuiltins[EShLangTessEvaluation].append(
5742                 "out int  gl_ViewportMask[];"             // GL_NV_viewport_array2
5743             );
5744 
5745         if (version >= 450)
5746             stageBuiltins[EShLangTessEvaluation].append(
5747                 "out vec4 gl_SecondaryPositionNV;"        // GL_NV_stereo_view_rendering
5748                 "out int  gl_SecondaryViewportMaskNV[];"  // GL_NV_stereo_view_rendering
5749                 "out vec4 gl_PositionPerViewNV[];"        // GL_NVX_multiview_per_view_attributes
5750                 "out int  gl_ViewportMaskPerViewNV[];"    // GL_NVX_multiview_per_view_attributes
5751                 );
5752 
5753     } else if (profile == EEsProfile && version >= 310) {
5754         // Note:  "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below,
5755         // as it depends on the resource sizing of gl_MaxPatchVertices.
5756 
5757         stageBuiltins[EShLangTessEvaluation].append(
5758             "in highp int gl_PatchVerticesIn;"
5759             "in highp int gl_PrimitiveID;"
5760             "in highp vec3 gl_TessCoord;"
5761 
5762             "patch in highp float gl_TessLevelOuter[4];"
5763             "patch in highp float gl_TessLevelInner[2];"
5764 
5765             "out gl_PerVertex {"
5766                 "highp vec4 gl_Position;"
5767                 "highp float gl_PointSize;"
5768             );
5769         stageBuiltins[EShLangTessEvaluation].append(
5770             "};"
5771             "\n");
5772     }
5773 
5774     if ((profile != EEsProfile && version >= 140) ||
5775         (profile == EEsProfile && version >= 310)) {
5776         stageBuiltins[EShLangTessEvaluation].append(
5777             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5778             "in highp int gl_ViewIndex;"       // GL_EXT_multiview
5779             "\n");
5780     }
5781 
5782     //============================================================================
5783     //
5784     // Define the interface to the fragment shader.
5785     //
5786     //============================================================================
5787 
5788     if (profile != EEsProfile) {
5789 
5790         stageBuiltins[EShLangFragment].append(
5791             "vec4  gl_FragCoord;"   // needs qualifier fixed later
5792             "bool  gl_FrontFacing;" // needs qualifier fixed later
5793             "float gl_FragDepth;"   // needs qualifier fixed later
5794             );
5795         if (version >= 120)
5796             stageBuiltins[EShLangFragment].append(
5797                 "vec2 gl_PointCoord;"  // needs qualifier fixed later
5798                 );
5799         if (version >= 140)
5800             stageBuiltins[EShLangFragment].append(
5801                 "out int gl_FragStencilRefARB;"
5802                 );
5803         if (IncludeLegacy(version, profile, spvVersion) || (! ForwardCompatibility && version < 420))
5804             stageBuiltins[EShLangFragment].append(
5805                 "vec4 gl_FragColor;"   // needs qualifier fixed later
5806                 );
5807 
5808         if (version < 130) {
5809             stageBuiltins[EShLangFragment].append(
5810                 "varying vec4  gl_Color;"
5811                 "varying vec4  gl_SecondaryColor;"
5812                 "varying vec4  gl_TexCoord[];"
5813                 "varying float gl_FogFragCoord;"
5814                 );
5815         } else {
5816             stageBuiltins[EShLangFragment].append(
5817                 "in float gl_ClipDistance[];"
5818                 );
5819 
5820             if (IncludeLegacy(version, profile, spvVersion)) {
5821                 if (version < 150)
5822                     stageBuiltins[EShLangFragment].append(
5823                         "in float gl_FogFragCoord;"
5824                         "in vec4  gl_TexCoord[];"
5825                         "in vec4  gl_Color;"
5826                         "in vec4  gl_SecondaryColor;"
5827                         );
5828                 else
5829                     stageBuiltins[EShLangFragment].append(
5830                         "in gl_PerFragment {"
5831                             "in float gl_FogFragCoord;"
5832                             "in vec4  gl_TexCoord[];"
5833                             "in vec4  gl_Color;"
5834                             "in vec4  gl_SecondaryColor;"
5835                         "};"
5836                         );
5837             }
5838         }
5839 
5840         if (version >= 150)
5841             stageBuiltins[EShLangFragment].append(
5842                 "flat in int gl_PrimitiveID;"
5843                 );
5844 
5845         if (version >= 130) { // ARB_sample_shading
5846             stageBuiltins[EShLangFragment].append(
5847                 "flat in  int  gl_SampleID;"
5848                 "     in  vec2 gl_SamplePosition;"
5849                 "     out int  gl_SampleMask[];"
5850                 );
5851 
5852             if (spvVersion.spv == 0) {
5853                 stageBuiltins[EShLangFragment].append(
5854                     "uniform int gl_NumSamples;"
5855                 );
5856             }
5857         }
5858 
5859         if (version >= 400)
5860             stageBuiltins[EShLangFragment].append(
5861                 "flat in  int  gl_SampleMaskIn[];"
5862             );
5863 
5864         if (version >= 430)
5865             stageBuiltins[EShLangFragment].append(
5866                 "flat in int gl_Layer;"
5867                 "flat in int gl_ViewportIndex;"
5868                 );
5869 
5870         if (version >= 450)
5871             stageBuiltins[EShLangFragment].append(
5872                 "in float gl_CullDistance[];"
5873                 "bool gl_HelperInvocation;"     // needs qualifier fixed later
5874                 );
5875 
5876         if (version >= 450)
5877             stageBuiltins[EShLangFragment].append( // GL_EXT_fragment_invocation_density
5878                 "flat in ivec2 gl_FragSizeEXT;"
5879                 "flat in int   gl_FragInvocationCountEXT;"
5880                 );
5881 
5882         if (version >= 450)
5883             stageBuiltins[EShLangFragment].append(
5884                 "in vec2 gl_BaryCoordNoPerspAMD;"
5885                 "in vec2 gl_BaryCoordNoPerspCentroidAMD;"
5886                 "in vec2 gl_BaryCoordNoPerspSampleAMD;"
5887                 "in vec2 gl_BaryCoordSmoothAMD;"
5888                 "in vec2 gl_BaryCoordSmoothCentroidAMD;"
5889                 "in vec2 gl_BaryCoordSmoothSampleAMD;"
5890                 "in vec3 gl_BaryCoordPullModelAMD;"
5891                 );
5892 
5893         if (version >= 430)
5894             stageBuiltins[EShLangFragment].append(
5895                 "in bool gl_FragFullyCoveredNV;"
5896                 );
5897         if (version >= 450)
5898             stageBuiltins[EShLangFragment].append(
5899                 "flat in ivec2 gl_FragmentSizeNV;"          // GL_NV_shading_rate_image
5900                 "flat in int   gl_InvocationsPerPixelNV;"
5901                 "in vec3 gl_BaryCoordNV;"                   // GL_NV_fragment_shader_barycentric
5902                 "in vec3 gl_BaryCoordNoPerspNV;"
5903                 "in vec3 gl_BaryCoordEXT;"                  // GL_EXT_fragment_shader_barycentric
5904                 "in vec3 gl_BaryCoordNoPerspEXT;"
5905                 );
5906 
5907         if (version >= 450)
5908             stageBuiltins[EShLangFragment].append(
5909                 "flat in int gl_ShadingRateEXT;" // GL_EXT_fragment_shading_rate
5910             );
5911 
5912     } else {
5913         // ES profile
5914 
5915         if (version == 100) {
5916             stageBuiltins[EShLangFragment].append(
5917                 "mediump vec4 gl_FragCoord;"    // needs qualifier fixed later
5918                 "        bool gl_FrontFacing;"  // needs qualifier fixed later
5919                 "mediump vec4 gl_FragColor;"    // needs qualifier fixed later
5920                 "mediump vec2 gl_PointCoord;"   // needs qualifier fixed later
5921                 );
5922         }
5923         if (version >= 300) {
5924             stageBuiltins[EShLangFragment].append(
5925                 "highp   vec4  gl_FragCoord;"    // needs qualifier fixed later
5926                 "        bool  gl_FrontFacing;"  // needs qualifier fixed later
5927                 "mediump vec2  gl_PointCoord;"   // needs qualifier fixed later
5928                 "highp   float gl_FragDepth;"    // needs qualifier fixed later
5929                 );
5930         }
5931         if (version >= 310) {
5932             stageBuiltins[EShLangFragment].append(
5933                 "bool gl_HelperInvocation;"          // needs qualifier fixed later
5934                 "flat in highp int gl_PrimitiveID;"  // needs qualifier fixed later
5935                 "flat in highp int gl_Layer;"        // needs qualifier fixed later
5936                 );
5937 
5938             stageBuiltins[EShLangFragment].append(  // GL_OES_sample_variables
5939                 "flat  in lowp     int gl_SampleID;"
5940                 "      in mediump vec2 gl_SamplePosition;"
5941                 "flat  in highp    int gl_SampleMaskIn[];"
5942                 "     out highp    int gl_SampleMask[];"
5943                 );
5944             if (spvVersion.spv == 0)
5945                 stageBuiltins[EShLangFragment].append(  // GL_OES_sample_variables
5946                     "uniform lowp int gl_NumSamples;"
5947                     );
5948         }
5949         stageBuiltins[EShLangFragment].append(
5950             "highp float gl_FragDepthEXT;"       // GL_EXT_frag_depth
5951             );
5952 
5953         if (version >= 310)
5954             stageBuiltins[EShLangFragment].append( // GL_EXT_fragment_invocation_density
5955                 "flat in ivec2 gl_FragSizeEXT;"
5956                 "flat in int   gl_FragInvocationCountEXT;"
5957             );
5958         if (version >= 320)
5959             stageBuiltins[EShLangFragment].append( // GL_NV_shading_rate_image
5960                 "flat in ivec2 gl_FragmentSizeNV;"
5961                 "flat in int   gl_InvocationsPerPixelNV;"
5962             );
5963         if (version >= 320)
5964             stageBuiltins[EShLangFragment].append(
5965                 "in vec3 gl_BaryCoordNV;"
5966                 "in vec3 gl_BaryCoordNoPerspNV;"
5967                 "in vec3 gl_BaryCoordEXT;"
5968                 "in vec3 gl_BaryCoordNoPerspEXT;"
5969             );
5970         if (version >= 310)
5971             stageBuiltins[EShLangFragment].append(
5972                 "flat in highp int gl_ShadingRateEXT;" // GL_EXT_fragment_shading_rate
5973             );
5974     }
5975 
5976     stageBuiltins[EShLangFragment].append("\n");
5977 
5978     if (version >= 130)
5979         add2ndGenerationSamplingImaging(version, profile, spvVersion);
5980 
5981     if ((profile != EEsProfile && version >= 140) ||
5982         (profile == EEsProfile && version >= 310)) {
5983         stageBuiltins[EShLangFragment].append(
5984             "flat in highp int gl_DeviceIndex;"     // GL_EXT_device_group
5985             "flat in highp int gl_ViewIndex;"       // GL_EXT_multiview
5986             "\n");
5987     }
5988 
5989     if (version >= 300 /* both ES and non-ES */) {
5990         stageBuiltins[EShLangFragment].append(
5991             "flat in highp uint gl_ViewID_OVR;"     // GL_OVR_multiview, GL_OVR_multiview2
5992             "\n");
5993     }
5994 
5995     // GL_ARB_shader_ballot
5996     if (profile != EEsProfile && version >= 450) {
5997         const char* ballotDecls =
5998             "uniform uint gl_SubGroupSizeARB;"
5999             "in uint     gl_SubGroupInvocationARB;"
6000             "in uint64_t gl_SubGroupEqMaskARB;"
6001             "in uint64_t gl_SubGroupGeMaskARB;"
6002             "in uint64_t gl_SubGroupGtMaskARB;"
6003             "in uint64_t gl_SubGroupLeMaskARB;"
6004             "in uint64_t gl_SubGroupLtMaskARB;"
6005             "\n";
6006         const char* rtBallotDecls =
6007             "uniform volatile uint gl_SubGroupSizeARB;"
6008             "in volatile uint     gl_SubGroupInvocationARB;"
6009             "in volatile uint64_t gl_SubGroupEqMaskARB;"
6010             "in volatile uint64_t gl_SubGroupGeMaskARB;"
6011             "in volatile uint64_t gl_SubGroupGtMaskARB;"
6012             "in volatile uint64_t gl_SubGroupLeMaskARB;"
6013             "in volatile uint64_t gl_SubGroupLtMaskARB;"
6014             "\n";
6015         const char* fragmentBallotDecls =
6016             "uniform uint gl_SubGroupSizeARB;"
6017             "flat in uint     gl_SubGroupInvocationARB;"
6018             "flat in uint64_t gl_SubGroupEqMaskARB;"
6019             "flat in uint64_t gl_SubGroupGeMaskARB;"
6020             "flat in uint64_t gl_SubGroupGtMaskARB;"
6021             "flat in uint64_t gl_SubGroupLeMaskARB;"
6022             "flat in uint64_t gl_SubGroupLtMaskARB;"
6023             "\n";
6024         stageBuiltins[EShLangVertex]        .append(ballotDecls);
6025         stageBuiltins[EShLangTessControl]   .append(ballotDecls);
6026         stageBuiltins[EShLangTessEvaluation].append(ballotDecls);
6027         stageBuiltins[EShLangGeometry]      .append(ballotDecls);
6028         stageBuiltins[EShLangCompute]       .append(ballotDecls);
6029         stageBuiltins[EShLangFragment]      .append(fragmentBallotDecls);
6030         stageBuiltins[EShLangMesh]        .append(ballotDecls);
6031         stageBuiltins[EShLangTask]        .append(ballotDecls);
6032         stageBuiltins[EShLangRayGen]        .append(rtBallotDecls);
6033         stageBuiltins[EShLangIntersect]     .append(rtBallotDecls);
6034         // No volatile qualifier on these builtins in any-hit
6035         stageBuiltins[EShLangAnyHit]        .append(ballotDecls);
6036         stageBuiltins[EShLangClosestHit]    .append(rtBallotDecls);
6037         stageBuiltins[EShLangMiss]          .append(rtBallotDecls);
6038         stageBuiltins[EShLangCallable]      .append(rtBallotDecls);
6039     }
6040 
6041     // GL_KHR_shader_subgroup
6042     if ((profile == EEsProfile && version >= 310) ||
6043         (profile != EEsProfile && version >= 140)) {
6044         const char* subgroupDecls =
6045             "in mediump uint  gl_SubgroupSize;"
6046             "in mediump uint  gl_SubgroupInvocationID;"
6047             "in highp   uvec4 gl_SubgroupEqMask;"
6048             "in highp   uvec4 gl_SubgroupGeMask;"
6049             "in highp   uvec4 gl_SubgroupGtMask;"
6050             "in highp   uvec4 gl_SubgroupLeMask;"
6051             "in highp   uvec4 gl_SubgroupLtMask;"
6052             // GL_NV_shader_sm_builtins
6053             "in highp   uint  gl_WarpsPerSMNV;"
6054             "in highp   uint  gl_SMCountNV;"
6055             "in highp   uint  gl_WarpIDNV;"
6056             "in highp   uint  gl_SMIDNV;"
6057             // GL_ARM_shader_core_builtins
6058             "in highp   uint  gl_CoreIDARM;"
6059             "in highp   uint  gl_CoreCountARM;"
6060             "in highp   uint  gl_CoreMaxIDARM;"
6061             "in highp   uint  gl_WarpIDARM;"
6062             "in highp   uint  gl_WarpMaxIDARM;"
6063             "\n";
6064         const char* fragmentSubgroupDecls =
6065             "flat in mediump uint  gl_SubgroupSize;"
6066             "flat in mediump uint  gl_SubgroupInvocationID;"
6067             "flat in highp   uvec4 gl_SubgroupEqMask;"
6068             "flat in highp   uvec4 gl_SubgroupGeMask;"
6069             "flat in highp   uvec4 gl_SubgroupGtMask;"
6070             "flat in highp   uvec4 gl_SubgroupLeMask;"
6071             "flat in highp   uvec4 gl_SubgroupLtMask;"
6072             // GL_NV_shader_sm_builtins
6073             "flat in highp   uint  gl_WarpsPerSMNV;"
6074             "flat in highp   uint  gl_SMCountNV;"
6075             "flat in highp   uint  gl_WarpIDNV;"
6076             "flat in highp   uint  gl_SMIDNV;"
6077             // GL_ARM_shader_core_builtins
6078             "flat in highp   uint  gl_CoreIDARM;"
6079             "flat in highp   uint  gl_CoreCountARM;"
6080             "flat in highp   uint  gl_CoreMaxIDARM;"
6081             "flat in highp   uint  gl_WarpIDARM;"
6082             "flat in highp   uint  gl_WarpMaxIDARM;"
6083             "\n";
6084         const char* computeSubgroupDecls =
6085             "in highp   uint  gl_NumSubgroups;"
6086             "in highp   uint  gl_SubgroupID;"
6087             "\n";
6088         // These builtins are volatile for RT stages
6089         const char* rtSubgroupDecls =
6090             "in mediump volatile uint  gl_SubgroupSize;"
6091             "in mediump volatile uint  gl_SubgroupInvocationID;"
6092             "in highp   volatile uvec4 gl_SubgroupEqMask;"
6093             "in highp   volatile uvec4 gl_SubgroupGeMask;"
6094             "in highp   volatile uvec4 gl_SubgroupGtMask;"
6095             "in highp   volatile uvec4 gl_SubgroupLeMask;"
6096             "in highp   volatile uvec4 gl_SubgroupLtMask;"
6097             // GL_NV_shader_sm_builtins
6098             "in highp    uint  gl_WarpsPerSMNV;"
6099             "in highp    uint  gl_SMCountNV;"
6100             "in highp volatile uint  gl_WarpIDNV;"
6101             "in highp volatile uint  gl_SMIDNV;"
6102             // GL_ARM_shader_core_builtins
6103             "in highp   uint  gl_CoreIDARM;"
6104             "in highp   uint  gl_CoreCountARM;"
6105             "in highp   uint  gl_CoreMaxIDARM;"
6106             "in highp   uint  gl_WarpIDARM;"
6107             "in highp   uint  gl_WarpMaxIDARM;"
6108             "\n";
6109 
6110         stageBuiltins[EShLangVertex]        .append(subgroupDecls);
6111         stageBuiltins[EShLangTessControl]   .append(subgroupDecls);
6112         stageBuiltins[EShLangTessEvaluation].append(subgroupDecls);
6113         stageBuiltins[EShLangGeometry]      .append(subgroupDecls);
6114         stageBuiltins[EShLangCompute]       .append(subgroupDecls);
6115         stageBuiltins[EShLangCompute]       .append(computeSubgroupDecls);
6116         stageBuiltins[EShLangFragment]      .append(fragmentSubgroupDecls);
6117         stageBuiltins[EShLangMesh]        .append(subgroupDecls);
6118         stageBuiltins[EShLangMesh]        .append(computeSubgroupDecls);
6119         stageBuiltins[EShLangTask]        .append(subgroupDecls);
6120         stageBuiltins[EShLangTask]        .append(computeSubgroupDecls);
6121         stageBuiltins[EShLangRayGen]        .append(rtSubgroupDecls);
6122         stageBuiltins[EShLangIntersect]     .append(rtSubgroupDecls);
6123         // No volatile qualifier on these builtins in any-hit
6124         stageBuiltins[EShLangAnyHit]        .append(subgroupDecls);
6125         stageBuiltins[EShLangClosestHit]    .append(rtSubgroupDecls);
6126         stageBuiltins[EShLangMiss]          .append(rtSubgroupDecls);
6127         stageBuiltins[EShLangCallable]      .append(rtSubgroupDecls);
6128     }
6129 
6130     // GL_NV_ray_tracing/GL_EXT_ray_tracing
6131     if (profile != EEsProfile && version >= 460) {
6132 
6133         const char *constRayFlags =
6134             "const uint gl_RayFlagsNoneNV = 0U;"
6135             "const uint gl_RayFlagsNoneEXT = 0U;"
6136             "const uint gl_RayFlagsOpaqueNV = 1U;"
6137             "const uint gl_RayFlagsOpaqueEXT = 1U;"
6138             "const uint gl_RayFlagsNoOpaqueNV = 2U;"
6139             "const uint gl_RayFlagsNoOpaqueEXT = 2U;"
6140             "const uint gl_RayFlagsTerminateOnFirstHitNV = 4U;"
6141             "const uint gl_RayFlagsTerminateOnFirstHitEXT = 4U;"
6142             "const uint gl_RayFlagsSkipClosestHitShaderNV = 8U;"
6143             "const uint gl_RayFlagsSkipClosestHitShaderEXT = 8U;"
6144             "const uint gl_RayFlagsCullBackFacingTrianglesNV = 16U;"
6145             "const uint gl_RayFlagsCullBackFacingTrianglesEXT = 16U;"
6146             "const uint gl_RayFlagsCullFrontFacingTrianglesNV = 32U;"
6147             "const uint gl_RayFlagsCullFrontFacingTrianglesEXT = 32U;"
6148             "const uint gl_RayFlagsCullOpaqueNV = 64U;"
6149             "const uint gl_RayFlagsCullOpaqueEXT = 64U;"
6150             "const uint gl_RayFlagsCullNoOpaqueNV = 128U;"
6151             "const uint gl_RayFlagsCullNoOpaqueEXT = 128U;"
6152             "const uint gl_RayFlagsSkipTrianglesEXT = 256U;"
6153             "const uint gl_RayFlagsSkipAABBEXT = 512U;"
6154             "const uint gl_RayFlagsForceOpacityMicromap2StateEXT = 1024U;"
6155             "const uint gl_HitKindFrontFacingTriangleEXT = 254U;"
6156             "const uint gl_HitKindBackFacingTriangleEXT = 255U;"
6157             "in    uint gl_HitKindFrontFacingMicroTriangleNV;"
6158             "in    uint gl_HitKindBackFacingMicroTriangleNV;"
6159             "\n";
6160 
6161         const char *constRayQueryIntersection =
6162             "const uint gl_RayQueryCandidateIntersectionEXT = 0U;"
6163             "const uint gl_RayQueryCommittedIntersectionEXT = 1U;"
6164             "const uint gl_RayQueryCommittedIntersectionNoneEXT = 0U;"
6165             "const uint gl_RayQueryCommittedIntersectionTriangleEXT = 1U;"
6166             "const uint gl_RayQueryCommittedIntersectionGeneratedEXT = 2U;"
6167             "const uint gl_RayQueryCandidateIntersectionTriangleEXT = 0U;"
6168             "const uint gl_RayQueryCandidateIntersectionAABBEXT = 1U;"
6169             "\n";
6170 
6171         const char *rayGenDecls =
6172             "in    uvec3  gl_LaunchIDNV;"
6173             "in    uvec3  gl_LaunchIDEXT;"
6174             "in    uvec3  gl_LaunchSizeNV;"
6175             "in    uvec3  gl_LaunchSizeEXT;"
6176             "\n";
6177         const char *intersectDecls =
6178             "in    uvec3  gl_LaunchIDNV;"
6179             "in    uvec3  gl_LaunchIDEXT;"
6180             "in    uvec3  gl_LaunchSizeNV;"
6181             "in    uvec3  gl_LaunchSizeEXT;"
6182             "in     int   gl_PrimitiveID;"
6183             "in     int   gl_InstanceID;"
6184             "in     int   gl_InstanceCustomIndexNV;"
6185             "in     int   gl_InstanceCustomIndexEXT;"
6186             "in     int   gl_GeometryIndexEXT;"
6187             "in    vec3   gl_WorldRayOriginNV;"
6188             "in    vec3   gl_WorldRayOriginEXT;"
6189             "in    vec3   gl_WorldRayDirectionNV;"
6190             "in    vec3   gl_WorldRayDirectionEXT;"
6191             "in    vec3   gl_ObjectRayOriginNV;"
6192             "in    vec3   gl_ObjectRayOriginEXT;"
6193             "in    vec3   gl_ObjectRayDirectionNV;"
6194             "in    vec3   gl_ObjectRayDirectionEXT;"
6195             "in    float  gl_RayTminNV;"
6196             "in    float  gl_RayTminEXT;"
6197             "in    float  gl_RayTmaxNV;"
6198             "in volatile float gl_RayTmaxEXT;"
6199             "in    mat4x3 gl_ObjectToWorldNV;"
6200             "in    mat4x3 gl_ObjectToWorldEXT;"
6201             "in    mat3x4 gl_ObjectToWorld3x4EXT;"
6202             "in    mat4x3 gl_WorldToObjectNV;"
6203             "in    mat4x3 gl_WorldToObjectEXT;"
6204             "in    mat3x4 gl_WorldToObject3x4EXT;"
6205             "in    uint   gl_IncomingRayFlagsNV;"
6206             "in    uint   gl_IncomingRayFlagsEXT;"
6207             "in    float  gl_CurrentRayTimeNV;"
6208             "in    uint   gl_CullMaskEXT;"
6209             "\n";
6210         const char *hitDecls =
6211             "in    uvec3  gl_LaunchIDNV;"
6212             "in    uvec3  gl_LaunchIDEXT;"
6213             "in    uvec3  gl_LaunchSizeNV;"
6214             "in    uvec3  gl_LaunchSizeEXT;"
6215             "in     int   gl_PrimitiveID;"
6216             "in     int   gl_InstanceID;"
6217             "in     int   gl_InstanceCustomIndexNV;"
6218             "in     int   gl_InstanceCustomIndexEXT;"
6219             "in     int   gl_GeometryIndexEXT;"
6220             "in    vec3   gl_WorldRayOriginNV;"
6221             "in    vec3   gl_WorldRayOriginEXT;"
6222             "in    vec3   gl_WorldRayDirectionNV;"
6223             "in    vec3   gl_WorldRayDirectionEXT;"
6224             "in    vec3   gl_ObjectRayOriginNV;"
6225             "in    vec3   gl_ObjectRayOriginEXT;"
6226             "in    vec3   gl_ObjectRayDirectionNV;"
6227             "in    vec3   gl_ObjectRayDirectionEXT;"
6228             "in    float  gl_RayTminNV;"
6229             "in    float  gl_RayTminEXT;"
6230             "in    float  gl_RayTmaxNV;"
6231             "in    float  gl_RayTmaxEXT;"
6232             "in    float  gl_HitTNV;"
6233             "in    float  gl_HitTEXT;"
6234             "in    uint   gl_HitKindNV;"
6235             "in    uint   gl_HitKindEXT;"
6236             "in    mat4x3 gl_ObjectToWorldNV;"
6237             "in    mat4x3 gl_ObjectToWorldEXT;"
6238             "in    mat3x4 gl_ObjectToWorld3x4EXT;"
6239             "in    mat4x3 gl_WorldToObjectNV;"
6240             "in    mat4x3 gl_WorldToObjectEXT;"
6241             "in    mat3x4 gl_WorldToObject3x4EXT;"
6242             "in    uint   gl_IncomingRayFlagsNV;"
6243             "in    uint   gl_IncomingRayFlagsEXT;"
6244             "in    float  gl_CurrentRayTimeNV;"
6245             "in    uint   gl_CullMaskEXT;"
6246             "in    vec3   gl_HitTriangleVertexPositionsEXT[3];"
6247             "in    vec3   gl_HitMicroTriangleVertexPositionsNV[3];"
6248             "in    vec2   gl_HitMicroTriangleVertexBarycentricsNV[3];"
6249             "\n";
6250 
6251         const char *missDecls =
6252             "in    uvec3  gl_LaunchIDNV;"
6253             "in    uvec3  gl_LaunchIDEXT;"
6254             "in    uvec3  gl_LaunchSizeNV;"
6255             "in    uvec3  gl_LaunchSizeEXT;"
6256             "in    vec3   gl_WorldRayOriginNV;"
6257             "in    vec3   gl_WorldRayOriginEXT;"
6258             "in    vec3   gl_WorldRayDirectionNV;"
6259             "in    vec3   gl_WorldRayDirectionEXT;"
6260             "in    vec3   gl_ObjectRayOriginNV;"
6261             "in    vec3   gl_ObjectRayDirectionNV;"
6262             "in    float  gl_RayTminNV;"
6263             "in    float  gl_RayTminEXT;"
6264             "in    float  gl_RayTmaxNV;"
6265             "in    float  gl_RayTmaxEXT;"
6266             "in    uint   gl_IncomingRayFlagsNV;"
6267             "in    uint   gl_IncomingRayFlagsEXT;"
6268             "in    float  gl_CurrentRayTimeNV;"
6269             "in    uint   gl_CullMaskEXT;"
6270             "\n";
6271 
6272         const char *callableDecls =
6273             "in    uvec3  gl_LaunchIDNV;"
6274             "in    uvec3  gl_LaunchIDEXT;"
6275             "in    uvec3  gl_LaunchSizeNV;"
6276             "in    uvec3  gl_LaunchSizeEXT;"
6277             "\n";
6278 
6279 
6280         commonBuiltins.append(constRayQueryIntersection);
6281         commonBuiltins.append(constRayFlags);
6282 
6283         stageBuiltins[EShLangRayGen].append(rayGenDecls);
6284         stageBuiltins[EShLangIntersect].append(intersectDecls);
6285         stageBuiltins[EShLangAnyHit].append(hitDecls);
6286         stageBuiltins[EShLangClosestHit].append(hitDecls);
6287         stageBuiltins[EShLangMiss].append(missDecls);
6288         stageBuiltins[EShLangCallable].append(callableDecls);
6289 
6290     }
6291 
6292     if ((profile != EEsProfile && version >= 140)) {
6293         const char *deviceIndex =
6294             "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
6295             "\n";
6296 
6297         stageBuiltins[EShLangRayGen].append(deviceIndex);
6298         stageBuiltins[EShLangIntersect].append(deviceIndex);
6299         stageBuiltins[EShLangAnyHit].append(deviceIndex);
6300         stageBuiltins[EShLangClosestHit].append(deviceIndex);
6301         stageBuiltins[EShLangMiss].append(deviceIndex);
6302     }
6303 
6304     if ((profile != EEsProfile && version >= 420) ||
6305         (profile == EEsProfile && version >= 310)) {
6306         commonBuiltins.append("const int gl_ScopeDevice      = 1;\n");
6307         commonBuiltins.append("const int gl_ScopeWorkgroup   = 2;\n");
6308         commonBuiltins.append("const int gl_ScopeSubgroup    = 3;\n");
6309         commonBuiltins.append("const int gl_ScopeInvocation  = 4;\n");
6310         commonBuiltins.append("const int gl_ScopeQueueFamily = 5;\n");
6311         commonBuiltins.append("const int gl_ScopeShaderCallEXT = 6;\n");
6312 
6313         commonBuiltins.append("const int gl_SemanticsRelaxed         = 0x0;\n");
6314         commonBuiltins.append("const int gl_SemanticsAcquire         = 0x2;\n");
6315         commonBuiltins.append("const int gl_SemanticsRelease         = 0x4;\n");
6316         commonBuiltins.append("const int gl_SemanticsAcquireRelease  = 0x8;\n");
6317         commonBuiltins.append("const int gl_SemanticsMakeAvailable   = 0x2000;\n");
6318         commonBuiltins.append("const int gl_SemanticsMakeVisible     = 0x4000;\n");
6319         commonBuiltins.append("const int gl_SemanticsVolatile        = 0x8000;\n");
6320 
6321         commonBuiltins.append("const int gl_StorageSemanticsNone     = 0x0;\n");
6322         commonBuiltins.append("const int gl_StorageSemanticsBuffer   = 0x40;\n");
6323         commonBuiltins.append("const int gl_StorageSemanticsShared   = 0x100;\n");
6324         commonBuiltins.append("const int gl_StorageSemanticsImage    = 0x800;\n");
6325         commonBuiltins.append("const int gl_StorageSemanticsOutput   = 0x1000;\n");
6326     }
6327 
6328     // Adding these to common built-ins triggers an assert due to a memory corruption in related code when testing
6329     // So instead add to each stage individually, avoiding the GLSLang bug
6330     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
6331         for (int stage=EShLangVertex; stage<EShLangCount; stage++)
6332         {
6333             stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag2VerticalPixelsEXT       = 1;\n");
6334             stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag4VerticalPixelsEXT       = 2;\n");
6335             stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag2HorizontalPixelsEXT     = 4;\n");
6336             stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag4HorizontalPixelsEXT     = 8;\n");
6337         }
6338     }
6339 
6340     // GL_EXT_shader_image_int64
6341     if ((profile != EEsProfile && version >= 420) ||
6342         (profile == EEsProfile && version >= 310)) {
6343 
6344         const TBasicType bTypes[] = { EbtInt64, EbtUint64 };
6345         for (int ms = 0; ms <= 1; ++ms) { // loop over "bool" multisample or not
6346             for (int arrayed = 0; arrayed <= 1; ++arrayed) { // loop over "bool" arrayed or not
6347                 for (int dim = Esd1D; dim < EsdSubpass; ++dim) { // 1D, ..., buffer
6348                     if ((dim == Esd1D || dim == EsdRect) && profile == EEsProfile)
6349                         continue;
6350 
6351                     if ((dim == Esd3D || dim == EsdRect || dim == EsdBuffer) && arrayed)
6352                         continue;
6353 
6354                     if (dim != Esd2D && ms)
6355                         continue;
6356 
6357                     // Loop over the bTypes
6358                     for (size_t bType = 0; bType < sizeof(bTypes)/sizeof(TBasicType); ++bType) {
6359                         //
6360                         // Now, make all the function prototypes for the type we just built...
6361                         //
6362                         TSampler sampler;
6363 
6364                         sampler.setImage(bTypes[bType], (TSamplerDim)dim, arrayed ? true : false,
6365                                                                           false,
6366                                                                           ms      ? true : false);
6367 
6368                         TString typeName = sampler.getString();
6369 
6370                         addQueryFunctions(sampler, typeName, version, profile);
6371                         addImageFunctions(sampler, typeName, version, profile);
6372                     }
6373                 }
6374             }
6375         }
6376     }
6377 
6378     // printf("%s\n", commonBuiltins.c_str());
6379     // printf("%s\n", stageBuiltins[EShLangFragment].c_str());
6380 }
6381 
6382 //
6383 // Helper function for initialize(), to add the second set of names for texturing,
6384 // when adding context-independent built-in functions.
6385 //
add2ndGenerationSamplingImaging(int version,EProfile profile,const SpvVersion & spvVersion)6386 void TBuiltIns::add2ndGenerationSamplingImaging(int version, EProfile profile, const SpvVersion& spvVersion)
6387 {
6388     //
6389     // In this function proper, enumerate the types, then calls the next set of functions
6390     // to enumerate all the uses for that type.
6391     //
6392 
6393     // enumerate all the types
6394     const TBasicType bTypes[] = { EbtFloat, EbtInt, EbtUint,
6395          EbtFloat16
6396     };
6397     bool skipBuffer = (profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 140);
6398     bool skipCubeArrayed = (profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 130);
6399     for (int image = 0; image <= 1; ++image) // loop over "bool" image vs sampler
6400     {
6401         for (int shadow = 0; shadow <= 1; ++shadow) { // loop over "bool" shadow or not
6402             for (int ms = 0; ms <= 1; ++ms) // loop over "bool" multisample or not
6403             {
6404                 if ((ms || image) && shadow)
6405                     continue;
6406                 if (ms && profile != EEsProfile && version < 140)
6407                     continue;
6408                 if (ms && image && profile == EEsProfile)
6409                     continue;
6410                 if (ms && profile == EEsProfile && version < 310)
6411                     continue;
6412 
6413                 for (int arrayed = 0; arrayed <= 1; ++arrayed) { // loop over "bool" arrayed or not
6414                     for (int dim = Esd1D; dim < EsdNumDims; ++dim) { // 1D, ..., buffer, subpass
6415                         if (dim == EsdAttachmentEXT)
6416                             continue;
6417                         if (dim == EsdSubpass && spvVersion.vulkan == 0)
6418                             continue;
6419                         if (dim == EsdSubpass && (image || shadow || arrayed))
6420                             continue;
6421                         if ((dim == Esd1D || dim == EsdRect) && profile == EEsProfile)
6422                             continue;
6423                         if (dim == EsdSubpass && spvVersion.vulkan == 0)
6424                             continue;
6425                         if (dim == EsdSubpass && (image || shadow || arrayed))
6426                             continue;
6427                         if ((dim == Esd1D || dim == EsdRect) && profile == EEsProfile)
6428                             continue;
6429                         if (dim != Esd2D && dim != EsdSubpass && ms)
6430                             continue;
6431                         if (dim == EsdBuffer && skipBuffer)
6432                             continue;
6433                         if (dim == EsdBuffer && (shadow || arrayed || ms))
6434                             continue;
6435                         if (ms && arrayed && profile == EEsProfile && version < 310)
6436                             continue;
6437                         if (dim == Esd3D && shadow)
6438                             continue;
6439                         if (dim == EsdCube && arrayed && skipCubeArrayed)
6440                             continue;
6441                         if ((dim == Esd3D || dim == EsdRect) && arrayed)
6442                             continue;
6443 
6444                         // Loop over the bTypes
6445                         for (size_t bType = 0; bType < sizeof(bTypes)/sizeof(TBasicType); ++bType) {
6446                             if (bTypes[bType] == EbtFloat16 && (profile == EEsProfile || version < 450))
6447                                 continue;
6448                             if (dim == EsdRect && version < 140 && bType > 0)
6449                                 continue;
6450                             if (shadow && (bTypes[bType] == EbtInt || bTypes[bType] == EbtUint))
6451                                 continue;
6452                             //
6453                             // Now, make all the function prototypes for the type we just built...
6454                             //
6455                             TSampler sampler;
6456                             if (dim == EsdSubpass) {
6457                                 sampler.setSubpass(bTypes[bType], ms ? true : false);
6458                             } else if (dim == EsdAttachmentEXT) {
6459                                 sampler.setAttachmentEXT(bTypes[bType]);
6460                             } else
6461                             if (image) {
6462                                 sampler.setImage(bTypes[bType], (TSamplerDim)dim, arrayed ? true : false,
6463                                                                                   shadow  ? true : false,
6464                                                                                   ms      ? true : false);
6465                             } else {
6466                                 sampler.set(bTypes[bType], (TSamplerDim)dim, arrayed ? true : false,
6467                                                                              shadow  ? true : false,
6468                                                                              ms      ? true : false);
6469                             }
6470 
6471                             TString typeName = sampler.getString();
6472 
6473                             if (dim == EsdSubpass) {
6474                                 addSubpassSampling(sampler, typeName, version, profile);
6475                                 continue;
6476                             }
6477 
6478                             addQueryFunctions(sampler, typeName, version, profile);
6479 
6480                             if (image)
6481                                 addImageFunctions(sampler, typeName, version, profile);
6482                             else {
6483                                 addSamplingFunctions(sampler, typeName, version, profile);
6484                                 addGatherFunctions(sampler, typeName, version, profile);
6485                                 if (spvVersion.vulkan > 0 && sampler.isCombined() && !sampler.shadow) {
6486                                     // Base Vulkan allows texelFetch() for
6487                                     // textureBuffer (i.e. without sampler).
6488                                     //
6489                                     // GL_EXT_samplerless_texture_functions
6490                                     // allows texelFetch() and query functions
6491                                     // (other than textureQueryLod()) for all
6492                                     // texture types.
6493                                     sampler.setTexture(sampler.type, sampler.dim, sampler.arrayed, sampler.shadow,
6494                                                        sampler.ms);
6495                                     TString textureTypeName = sampler.getString();
6496                                     addSamplingFunctions(sampler, textureTypeName, version, profile);
6497                                     addQueryFunctions(sampler, textureTypeName, version, profile);
6498                                 }
6499                             }
6500                         }
6501                     }
6502                 }
6503             }
6504         }
6505     }
6506 
6507     //
6508     // sparseTexelsResidentARB()
6509     //
6510     if (profile != EEsProfile && version >= 450) {
6511         commonBuiltins.append("bool sparseTexelsResidentARB(int code);\n");
6512     }
6513 }
6514 
6515 //
6516 // Helper function for add2ndGenerationSamplingImaging(),
6517 // when adding context-independent built-in functions.
6518 //
6519 // Add all the query functions for the given type.
6520 //
addQueryFunctions(TSampler sampler,const TString & typeName,int version,EProfile profile)6521 void TBuiltIns::addQueryFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
6522 {
6523     //
6524     // textureSize() and imageSize()
6525     //
6526 
6527     int sizeDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0) - (sampler.dim == EsdCube ? 1 : 0);
6528 
6529     if (sampler.isImage() && ((profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 420)))
6530         return;
6531 
6532     if (profile == EEsProfile)
6533         commonBuiltins.append("highp ");
6534     if (sizeDims == 1)
6535         commonBuiltins.append("int");
6536     else {
6537         commonBuiltins.append("ivec");
6538         commonBuiltins.append(postfixes[sizeDims]);
6539     }
6540     if (sampler.isImage())
6541         commonBuiltins.append(" imageSize(readonly writeonly volatile coherent ");
6542     else
6543         commonBuiltins.append(" textureSize(");
6544     commonBuiltins.append(typeName);
6545     if (! sampler.isImage() && ! sampler.isRect() && ! sampler.isBuffer() && ! sampler.isMultiSample())
6546         commonBuiltins.append(",int);\n");
6547     else
6548         commonBuiltins.append(");\n");
6549 
6550     //
6551     // textureSamples() and imageSamples()
6552     //
6553 
6554     // GL_ARB_shader_texture_image_samples
6555     // TODO: spec issue? there are no memory qualifiers; how to query a writeonly/readonly image, etc?
6556     if (profile != EEsProfile && version >= 430 && sampler.isMultiSample()) {
6557         commonBuiltins.append("int ");
6558         if (sampler.isImage())
6559             commonBuiltins.append("imageSamples(readonly writeonly volatile coherent ");
6560         else
6561             commonBuiltins.append("textureSamples(");
6562         commonBuiltins.append(typeName);
6563         commonBuiltins.append(");\n");
6564     }
6565 
6566     //
6567     // textureQueryLod(), fragment stage only
6568     // Also enabled with extension GL_ARB_texture_query_lod
6569     // Extension GL_ARB_texture_query_lod says that textureQueryLOD() also exist at extension.
6570 
6571     if (profile != EEsProfile && version >= 150 && sampler.isCombined() && sampler.dim != EsdRect &&
6572         ! sampler.isMultiSample() && ! sampler.isBuffer()) {
6573 
6574         const TString funcName[2] = {"vec2 textureQueryLod(", "vec2 textureQueryLOD("};
6575 
6576         for (int i = 0; i < 2; ++i){
6577             for (int f16TexAddr = 0; f16TexAddr < 2; ++f16TexAddr) {
6578                 if (f16TexAddr && sampler.type != EbtFloat16)
6579                     continue;
6580                 stageBuiltins[EShLangFragment].append(funcName[i]);
6581                 stageBuiltins[EShLangFragment].append(typeName);
6582                 if (dimMap[sampler.dim] == 1)
6583                     if (f16TexAddr)
6584                         stageBuiltins[EShLangFragment].append(", float16_t");
6585                     else
6586                         stageBuiltins[EShLangFragment].append(", float");
6587                 else {
6588                     if (f16TexAddr)
6589                         stageBuiltins[EShLangFragment].append(", f16vec");
6590                     else
6591                         stageBuiltins[EShLangFragment].append(", vec");
6592                     stageBuiltins[EShLangFragment].append(postfixes[dimMap[sampler.dim]]);
6593                 }
6594                 stageBuiltins[EShLangFragment].append(");\n");
6595             }
6596 
6597             stageBuiltins[EShLangCompute].append(funcName[i]);
6598             stageBuiltins[EShLangCompute].append(typeName);
6599             if (dimMap[sampler.dim] == 1)
6600                 stageBuiltins[EShLangCompute].append(", float");
6601             else {
6602                 stageBuiltins[EShLangCompute].append(", vec");
6603                 stageBuiltins[EShLangCompute].append(postfixes[dimMap[sampler.dim]]);
6604             }
6605             stageBuiltins[EShLangCompute].append(");\n");
6606         }
6607     }
6608 
6609     //
6610     // textureQueryLevels()
6611     //
6612 
6613     if (profile != EEsProfile && version >= 430 && ! sampler.isImage() && sampler.dim != EsdRect &&
6614         ! sampler.isMultiSample() && ! sampler.isBuffer()) {
6615         commonBuiltins.append("int textureQueryLevels(");
6616         commonBuiltins.append(typeName);
6617         commonBuiltins.append(");\n");
6618     }
6619 }
6620 
6621 //
6622 // Helper function for add2ndGenerationSamplingImaging(),
6623 // when adding context-independent built-in functions.
6624 //
6625 // Add all the image access functions for the given type.
6626 //
addImageFunctions(TSampler sampler,const TString & typeName,int version,EProfile profile)6627 void TBuiltIns::addImageFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
6628 {
6629     int dims = dimMap[sampler.dim];
6630     // most things with an array add a dimension, except for cubemaps
6631     if (sampler.arrayed && sampler.dim != EsdCube)
6632         ++dims;
6633 
6634     TString imageParams = typeName;
6635     if (dims == 1)
6636         imageParams.append(", int");
6637     else {
6638         imageParams.append(", ivec");
6639         imageParams.append(postfixes[dims]);
6640     }
6641     if (sampler.isMultiSample())
6642         imageParams.append(", int");
6643 
6644     if (profile == EEsProfile)
6645         commonBuiltins.append("highp ");
6646     commonBuiltins.append(prefixes[sampler.type]);
6647     commonBuiltins.append("vec4 imageLoad(readonly volatile coherent ");
6648     commonBuiltins.append(imageParams);
6649     commonBuiltins.append(");\n");
6650 
6651     commonBuiltins.append("void imageStore(writeonly volatile coherent ");
6652     commonBuiltins.append(imageParams);
6653     commonBuiltins.append(", ");
6654     commonBuiltins.append(prefixes[sampler.type]);
6655     commonBuiltins.append("vec4);\n");
6656 
6657     if (! sampler.is1D() && ! sampler.isBuffer() && profile != EEsProfile && version >= 450) {
6658         commonBuiltins.append("int sparseImageLoadARB(readonly volatile coherent ");
6659         commonBuiltins.append(imageParams);
6660         commonBuiltins.append(", out ");
6661         commonBuiltins.append(prefixes[sampler.type]);
6662         commonBuiltins.append("vec4");
6663         commonBuiltins.append(");\n");
6664     }
6665 
6666     if ( profile != EEsProfile ||
6667         (profile == EEsProfile && version >= 310)) {
6668         if (sampler.type == EbtInt || sampler.type == EbtUint || sampler.type == EbtInt64 || sampler.type == EbtUint64 ) {
6669 
6670             const char* dataType;
6671             switch (sampler.type) {
6672                 case(EbtInt): dataType = "highp int"; break;
6673                 case(EbtUint): dataType = "highp uint"; break;
6674                 case(EbtInt64): dataType = "highp int64_t"; break;
6675                 case(EbtUint64): dataType = "highp uint64_t"; break;
6676                 default: dataType = "";
6677             }
6678 
6679             const int numBuiltins = 7;
6680 
6681             static const char* atomicFunc[numBuiltins] = {
6682                 " imageAtomicAdd(volatile coherent ",
6683                 " imageAtomicMin(volatile coherent ",
6684                 " imageAtomicMax(volatile coherent ",
6685                 " imageAtomicAnd(volatile coherent ",
6686                 " imageAtomicOr(volatile coherent ",
6687                 " imageAtomicXor(volatile coherent ",
6688                 " imageAtomicExchange(volatile coherent "
6689             };
6690 
6691             // Loop twice to add prototypes with/without scope/semantics
6692             for (int j = 0; j < 2; ++j) {
6693                 for (size_t i = 0; i < numBuiltins; ++i) {
6694                     commonBuiltins.append(dataType);
6695                     commonBuiltins.append(atomicFunc[i]);
6696                     commonBuiltins.append(imageParams);
6697                     commonBuiltins.append(", ");
6698                     commonBuiltins.append(dataType);
6699                     if (j == 1) {
6700                         commonBuiltins.append(", int, int, int");
6701                     }
6702                     commonBuiltins.append(");\n");
6703                 }
6704 
6705                 commonBuiltins.append(dataType);
6706                 commonBuiltins.append(" imageAtomicCompSwap(volatile coherent ");
6707                 commonBuiltins.append(imageParams);
6708                 commonBuiltins.append(", ");
6709                 commonBuiltins.append(dataType);
6710                 commonBuiltins.append(", ");
6711                 commonBuiltins.append(dataType);
6712                 if (j == 1) {
6713                     commonBuiltins.append(", int, int, int, int, int");
6714                 }
6715                 commonBuiltins.append(");\n");
6716             }
6717 
6718             commonBuiltins.append(dataType);
6719             commonBuiltins.append(" imageAtomicLoad(volatile coherent ");
6720             commonBuiltins.append(imageParams);
6721             commonBuiltins.append(", int, int, int);\n");
6722 
6723             commonBuiltins.append("void imageAtomicStore(volatile coherent ");
6724             commonBuiltins.append(imageParams);
6725             commonBuiltins.append(", ");
6726             commonBuiltins.append(dataType);
6727             commonBuiltins.append(", int, int, int);\n");
6728 
6729         } else {
6730             // not int or uint
6731             // GL_ARB_ES3_1_compatibility
6732             // TODO: spec issue: are there restrictions on the kind of layout() that can be used?  what about dropping memory qualifiers?
6733             if (profile == EEsProfile && version >= 310) {
6734                 commonBuiltins.append("float imageAtomicExchange(volatile coherent ");
6735                 commonBuiltins.append(imageParams);
6736                 commonBuiltins.append(", float);\n");
6737             }
6738 
6739             // GL_NV_shader_atomic_fp16_vector
6740             if (profile != EEsProfile && version >= 430) {
6741                 const int numFp16Builtins = 4;
6742                 const char* atomicFp16Func[numFp16Builtins] = {
6743                     " imageAtomicAdd(volatile coherent ",
6744                     " imageAtomicMin(volatile coherent ",
6745                     " imageAtomicMax(volatile coherent ",
6746                     " imageAtomicExchange(volatile coherent "
6747                 };
6748                 const int numFp16DataTypes = 2;
6749                 const char* atomicFp16DataTypes[numFp16DataTypes] = {
6750                     "f16vec2",
6751                     "f16vec4"
6752                 };
6753                 // Loop twice to add prototypes with/without scope/semantics
6754                 for (int j = 0; j < numFp16DataTypes; ++j) {
6755                     for (int i = 0; i < numFp16Builtins; ++i) {
6756                         commonBuiltins.append(atomicFp16DataTypes[j]);
6757                         commonBuiltins.append(atomicFp16Func[i]);
6758                         commonBuiltins.append(imageParams);
6759                         commonBuiltins.append(", ");
6760                         commonBuiltins.append(atomicFp16DataTypes[j]);
6761                         commonBuiltins.append(");\n");
6762                     }
6763                 }
6764             }
6765 
6766             if (profile != EEsProfile && version >= 450) {
6767                 commonBuiltins.append("float imageAtomicAdd(volatile coherent ");
6768                 commonBuiltins.append(imageParams);
6769                 commonBuiltins.append(", float);\n");
6770 
6771                 commonBuiltins.append("float imageAtomicAdd(volatile coherent ");
6772                 commonBuiltins.append(imageParams);
6773                 commonBuiltins.append(", float");
6774                 commonBuiltins.append(", int, int, int);\n");
6775 
6776                 commonBuiltins.append("float imageAtomicExchange(volatile coherent ");
6777                 commonBuiltins.append(imageParams);
6778                 commonBuiltins.append(", float);\n");
6779 
6780                 commonBuiltins.append("float imageAtomicExchange(volatile coherent ");
6781                 commonBuiltins.append(imageParams);
6782                 commonBuiltins.append(", float");
6783                 commonBuiltins.append(", int, int, int);\n");
6784 
6785                 commonBuiltins.append("float imageAtomicLoad(readonly volatile coherent ");
6786                 commonBuiltins.append(imageParams);
6787                 commonBuiltins.append(", int, int, int);\n");
6788 
6789                 commonBuiltins.append("void imageAtomicStore(writeonly volatile coherent ");
6790                 commonBuiltins.append(imageParams);
6791                 commonBuiltins.append(", float");
6792                 commonBuiltins.append(", int, int, int);\n");
6793 
6794                 commonBuiltins.append("float imageAtomicMin(volatile coherent ");
6795                 commonBuiltins.append(imageParams);
6796                 commonBuiltins.append(", float);\n");
6797 
6798                 commonBuiltins.append("float imageAtomicMin(volatile coherent ");
6799                 commonBuiltins.append(imageParams);
6800                 commonBuiltins.append(", float");
6801                 commonBuiltins.append(", int, int, int);\n");
6802 
6803                 commonBuiltins.append("float imageAtomicMax(volatile coherent ");
6804                 commonBuiltins.append(imageParams);
6805                 commonBuiltins.append(", float);\n");
6806 
6807                 commonBuiltins.append("float imageAtomicMax(volatile coherent ");
6808                 commonBuiltins.append(imageParams);
6809                 commonBuiltins.append(", float");
6810                 commonBuiltins.append(", int, int, int);\n");
6811             }
6812         }
6813     }
6814 
6815     if (sampler.dim == EsdRect || sampler.dim == EsdBuffer || sampler.shadow || sampler.isMultiSample())
6816         return;
6817 
6818     if (profile == EEsProfile || version < 450)
6819         return;
6820 
6821     TString imageLodParams = typeName;
6822     if (dims == 1)
6823         imageLodParams.append(", int");
6824     else {
6825         imageLodParams.append(", ivec");
6826         imageLodParams.append(postfixes[dims]);
6827     }
6828     imageLodParams.append(", int");
6829 
6830     commonBuiltins.append(prefixes[sampler.type]);
6831     commonBuiltins.append("vec4 imageLoadLodAMD(readonly volatile coherent ");
6832     commonBuiltins.append(imageLodParams);
6833     commonBuiltins.append(");\n");
6834 
6835     commonBuiltins.append("void imageStoreLodAMD(writeonly volatile coherent ");
6836     commonBuiltins.append(imageLodParams);
6837     commonBuiltins.append(", ");
6838     commonBuiltins.append(prefixes[sampler.type]);
6839     commonBuiltins.append("vec4);\n");
6840 
6841     if (! sampler.is1D()) {
6842         commonBuiltins.append("int sparseImageLoadLodAMD(readonly volatile coherent ");
6843         commonBuiltins.append(imageLodParams);
6844         commonBuiltins.append(", out ");
6845         commonBuiltins.append(prefixes[sampler.type]);
6846         commonBuiltins.append("vec4");
6847         commonBuiltins.append(");\n");
6848     }
6849 }
6850 
6851 //
6852 // Helper function for initialize(),
6853 // when adding context-independent built-in functions.
6854 //
6855 // Add all the subpass access functions for the given type.
6856 //
addSubpassSampling(TSampler sampler,const TString & typeName,int,EProfile)6857 void TBuiltIns::addSubpassSampling(TSampler sampler, const TString& typeName, int /*version*/, EProfile /*profile*/)
6858 {
6859     stageBuiltins[EShLangFragment].append(prefixes[sampler.type]);
6860     stageBuiltins[EShLangFragment].append("vec4 subpassLoad");
6861     stageBuiltins[EShLangFragment].append("(");
6862     stageBuiltins[EShLangFragment].append(typeName.c_str());
6863     if (sampler.isMultiSample())
6864         stageBuiltins[EShLangFragment].append(", int");
6865     stageBuiltins[EShLangFragment].append(");\n");
6866 }
6867 
6868 //
6869 // Helper function for add2ndGenerationSamplingImaging(),
6870 // when adding context-independent built-in functions.
6871 //
6872 // Add all the texture lookup functions for the given type.
6873 //
addSamplingFunctions(TSampler sampler,const TString & typeName,int version,EProfile profile)6874 void TBuiltIns::addSamplingFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
6875 {
6876     //
6877     // texturing
6878     //
6879     for (int proj = 0; proj <= 1; ++proj) { // loop over "bool" projective or not
6880 
6881         if (proj && (sampler.dim == EsdCube || sampler.isBuffer() || sampler.arrayed || sampler.isMultiSample()
6882             || !sampler.isCombined()))
6883             continue;
6884 
6885         for (int lod = 0; lod <= 1; ++lod) {
6886 
6887             if (lod && (sampler.isBuffer() || sampler.isRect() || sampler.isMultiSample() || !sampler.isCombined()))
6888                 continue;
6889             if (lod && sampler.dim == Esd2D && sampler.arrayed && sampler.shadow)
6890                 continue;
6891             if (lod && sampler.dim == EsdCube && sampler.shadow)
6892                 continue;
6893 
6894             for (int bias = 0; bias <= 1; ++bias) {
6895 
6896                 if (bias && (lod || sampler.isMultiSample() || !sampler.isCombined()))
6897                     continue;
6898                 if (bias && (sampler.dim == Esd2D || sampler.dim == EsdCube) && sampler.shadow && sampler.arrayed)
6899                     continue;
6900                 if (bias && (sampler.isRect() || sampler.isBuffer()))
6901                     continue;
6902 
6903                 for (int offset = 0; offset <= 1; ++offset) { // loop over "bool" offset or not
6904 
6905                     if (proj + offset + bias + lod > 3)
6906                         continue;
6907                     if (offset && (sampler.dim == EsdCube || sampler.isBuffer() || sampler.isMultiSample()))
6908                         continue;
6909 
6910                     for (int fetch = 0; fetch <= 1; ++fetch) { // loop over "bool" fetch or not
6911 
6912                         if (proj + offset + fetch + bias + lod > 3)
6913                             continue;
6914                         if (fetch && (lod || bias))
6915                             continue;
6916                         if (fetch && (sampler.shadow || sampler.dim == EsdCube))
6917                             continue;
6918                         if (fetch == 0 && (sampler.isMultiSample() || sampler.isBuffer()
6919                             || !sampler.isCombined()))
6920                             continue;
6921 
6922                         for (int grad = 0; grad <= 1; ++grad) { // loop over "bool" grad or not
6923 
6924                             if (grad && (lod || bias || sampler.isMultiSample() || !sampler.isCombined()))
6925                                 continue;
6926                             if (grad && sampler.isBuffer())
6927                                 continue;
6928                             if (proj + offset + fetch + grad + bias + lod > 3)
6929                                 continue;
6930 
6931                             for (int extraProj = 0; extraProj <= 1; ++extraProj) {
6932                                 bool compare = false;
6933                                 int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0);
6934                                 // skip dummy unused second component for 1D non-array shadows
6935                                 if (sampler.shadow && totalDims < 2)
6936                                     totalDims = 2;
6937                                 totalDims += (sampler.shadow ? 1 : 0) + proj;
6938                                 if (totalDims > 4 && sampler.shadow) {
6939                                     compare = true;
6940                                     totalDims = 4;
6941                                 }
6942                                 assert(totalDims <= 4);
6943 
6944                                 if (extraProj && ! proj)
6945                                     continue;
6946                                 if (extraProj && (sampler.dim == Esd3D || sampler.shadow || !sampler.isCombined()))
6947                                     continue;
6948 
6949                                 // loop over 16-bit floating-point texel addressing
6950                                 for (int f16TexAddr = 0; f16TexAddr <= 1; ++f16TexAddr)
6951                                 {
6952                                     if (f16TexAddr && sampler.type != EbtFloat16)
6953                                         continue;
6954                                     if (f16TexAddr && sampler.shadow && ! compare) {
6955                                         compare = true; // compare argument is always present
6956                                         totalDims--;
6957                                     }
6958                                     // loop over "bool" lod clamp
6959                                     for (int lodClamp = 0; lodClamp <= 1 ;++lodClamp)
6960                                     {
6961                                         if (lodClamp && (profile == EEsProfile || version < 450))
6962                                             continue;
6963                                         if (lodClamp && (proj || lod || fetch))
6964                                             continue;
6965 
6966                                         // loop over "bool" sparse or not
6967                                         for (int sparse = 0; sparse <= 1; ++sparse)
6968                                         {
6969                                             if (sparse && (profile == EEsProfile || version < 450))
6970                                                 continue;
6971                                             // Sparse sampling is not for 1D/1D array texture, buffer texture, and
6972                                             // projective texture
6973                                             if (sparse && (sampler.is1D() || sampler.isBuffer() || proj))
6974                                                 continue;
6975 
6976                                             TString s;
6977 
6978                                             // return type
6979                                             if (sparse)
6980                                                 s.append("int ");
6981                                             else {
6982                                                 if (sampler.shadow)
6983                                                     if (sampler.type == EbtFloat16)
6984                                                         s.append("float16_t ");
6985                                                     else
6986                                                         s.append("float ");
6987                                                 else {
6988                                                     s.append(prefixes[sampler.type]);
6989                                                     s.append("vec4 ");
6990                                                 }
6991                                             }
6992 
6993                                             // name
6994                                             if (sparse) {
6995                                                 if (fetch)
6996                                                     s.append("sparseTexel");
6997                                                 else
6998                                                     s.append("sparseTexture");
6999                                             }
7000                                             else {
7001                                                 if (fetch)
7002                                                     s.append("texel");
7003                                                 else
7004                                                     s.append("texture");
7005                                             }
7006                                             if (proj)
7007                                                 s.append("Proj");
7008                                             if (lod)
7009                                                 s.append("Lod");
7010                                             if (grad)
7011                                                 s.append("Grad");
7012                                             if (fetch)
7013                                                 s.append("Fetch");
7014                                             if (offset)
7015                                                 s.append("Offset");
7016                                             if (lodClamp)
7017                                                 s.append("Clamp");
7018                                             if (lodClamp != 0 || sparse)
7019                                                 s.append("ARB");
7020                                             s.append("(");
7021 
7022                                             // sampler type
7023                                             s.append(typeName);
7024                                             // P coordinate
7025                                             if (extraProj) {
7026                                                 if (f16TexAddr)
7027                                                     s.append(",f16vec4");
7028                                                 else
7029                                                     s.append(",vec4");
7030                                             } else {
7031                                                 s.append(",");
7032                                                 TBasicType t = fetch ? EbtInt : (f16TexAddr ? EbtFloat16 : EbtFloat);
7033                                                 if (totalDims == 1)
7034                                                     s.append(TType::getBasicString(t));
7035                                                 else {
7036                                                     s.append(prefixes[t]);
7037                                                     s.append("vec");
7038                                                     s.append(postfixes[totalDims]);
7039                                                 }
7040                                             }
7041                                             // non-optional compare
7042                                             if (compare)
7043                                                 s.append(",float");
7044 
7045                                             // non-optional lod argument (lod that's not driven by lod loop) or sample
7046                                             if ((fetch && !sampler.isBuffer() &&
7047                                                  !sampler.isRect() && !sampler.isMultiSample())
7048                                                  || (sampler.isMultiSample() && fetch))
7049                                                 s.append(",int");
7050                                             // non-optional lod
7051                                             if (lod) {
7052                                                 if (f16TexAddr)
7053                                                     s.append(",float16_t");
7054                                                 else
7055                                                     s.append(",float");
7056                                             }
7057 
7058                                             // gradient arguments
7059                                             if (grad) {
7060                                                 if (dimMap[sampler.dim] == 1) {
7061                                                     if (f16TexAddr)
7062                                                         s.append(",float16_t,float16_t");
7063                                                     else
7064                                                         s.append(",float,float");
7065                                                 } else {
7066                                                     if (f16TexAddr)
7067                                                         s.append(",f16vec");
7068                                                     else
7069                                                         s.append(",vec");
7070                                                     s.append(postfixes[dimMap[sampler.dim]]);
7071                                                     if (f16TexAddr)
7072                                                         s.append(",f16vec");
7073                                                     else
7074                                                         s.append(",vec");
7075                                                     s.append(postfixes[dimMap[sampler.dim]]);
7076                                                 }
7077                                             }
7078                                             // offset
7079                                             if (offset) {
7080                                                 if (dimMap[sampler.dim] == 1)
7081                                                     s.append(",int");
7082                                                 else {
7083                                                     s.append(",ivec");
7084                                                     s.append(postfixes[dimMap[sampler.dim]]);
7085                                                 }
7086                                             }
7087 
7088                                             // lod clamp
7089                                             if (lodClamp) {
7090                                                 if (f16TexAddr)
7091                                                     s.append(",float16_t");
7092                                                 else
7093                                                     s.append(",float");
7094                                             }
7095                                             // texel out (for sparse texture)
7096                                             if (sparse) {
7097                                                 s.append(",out ");
7098                                                 if (sampler.shadow)
7099                                                     if (sampler.type == EbtFloat16)
7100                                                         s.append("float16_t");
7101                                                     else
7102                                                         s.append("float");
7103                                                 else {
7104                                                     s.append(prefixes[sampler.type]);
7105                                                     s.append("vec4");
7106                                                 }
7107                                             }
7108                                             // optional bias
7109                                             if (bias) {
7110                                                 if (f16TexAddr)
7111                                                     s.append(",float16_t");
7112                                                 else
7113                                                     s.append(",float");
7114                                             }
7115                                             s.append(");\n");
7116 
7117                                             // Add to the per-language set of built-ins
7118                                             if (!grad && (bias || lodClamp != 0)) {
7119                                                 stageBuiltins[EShLangFragment].append(s);
7120                                                 stageBuiltins[EShLangCompute].append(s);
7121                                             } else
7122                                                 commonBuiltins.append(s);
7123 
7124                                         }
7125                                     }
7126                                 }
7127                             }
7128                         }
7129                     }
7130                 }
7131             }
7132         }
7133     }
7134 }
7135 
7136 //
7137 // Helper function for add2ndGenerationSamplingImaging(),
7138 // when adding context-independent built-in functions.
7139 //
7140 // Add all the texture gather functions for the given type.
7141 //
addGatherFunctions(TSampler sampler,const TString & typeName,int version,EProfile profile)7142 void TBuiltIns::addGatherFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
7143 {
7144     switch (sampler.dim) {
7145     case Esd2D:
7146     case EsdRect:
7147     case EsdCube:
7148         break;
7149     default:
7150         return;
7151     }
7152 
7153     if (sampler.isMultiSample())
7154         return;
7155 
7156     if (version < 140 && sampler.dim == EsdRect && sampler.type != EbtFloat)
7157         return;
7158 
7159     for (int f16TexAddr = 0; f16TexAddr <= 1; ++f16TexAddr) { // loop over 16-bit floating-point texel addressing
7160 
7161         if (f16TexAddr && sampler.type != EbtFloat16)
7162             continue;
7163         for (int offset = 0; offset < 3; ++offset) { // loop over three forms of offset in the call name:  none, Offset, and Offsets
7164 
7165             for (int comp = 0; comp < 2; ++comp) { // loop over presence of comp argument
7166 
7167                 if (comp > 0 && sampler.shadow)
7168                     continue;
7169 
7170                 if (offset > 0 && sampler.dim == EsdCube)
7171                     continue;
7172 
7173                 for (int sparse = 0; sparse <= 1; ++sparse) { // loop over "bool" sparse or not
7174                     if (sparse && (profile == EEsProfile || version < 450))
7175                         continue;
7176 
7177                     TString s;
7178 
7179                     // return type
7180                     if (sparse)
7181                         s.append("int ");
7182                     else {
7183                         s.append(prefixes[sampler.type]);
7184                         s.append("vec4 ");
7185                     }
7186 
7187                     // name
7188                     if (sparse)
7189                         s.append("sparseTextureGather");
7190                     else
7191                         s.append("textureGather");
7192                     switch (offset) {
7193                     case 1:
7194                         s.append("Offset");
7195                         break;
7196                     case 2:
7197                         s.append("Offsets");
7198                         break;
7199                     default:
7200                         break;
7201                     }
7202                     if (sparse)
7203                         s.append("ARB");
7204                     s.append("(");
7205 
7206                     // sampler type argument
7207                     s.append(typeName);
7208 
7209                     // P coordinate argument
7210                     if (f16TexAddr)
7211                         s.append(",f16vec");
7212                     else
7213                         s.append(",vec");
7214                     int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0);
7215                     s.append(postfixes[totalDims]);
7216 
7217                     // refZ argument
7218                     if (sampler.shadow)
7219                         s.append(",float");
7220 
7221                     // offset argument
7222                     if (offset > 0) {
7223                         s.append(",ivec2");
7224                         if (offset == 2)
7225                             s.append("[4]");
7226                     }
7227 
7228                     // texel out (for sparse texture)
7229                     if (sparse) {
7230                         s.append(",out ");
7231                         s.append(prefixes[sampler.type]);
7232                         s.append("vec4 ");
7233                     }
7234 
7235                     // comp argument
7236                     if (comp)
7237                         s.append(",int");
7238 
7239                     s.append(");\n");
7240                     commonBuiltins.append(s);
7241                 }
7242             }
7243         }
7244     }
7245 
7246     if (sampler.dim == EsdRect || sampler.shadow)
7247         return;
7248 
7249     if (profile == EEsProfile || version < 450)
7250         return;
7251 
7252     for (int bias = 0; bias < 2; ++bias) { // loop over presence of bias argument
7253 
7254         for (int lod = 0; lod < 2; ++lod) { // loop over presence of lod argument
7255 
7256             if ((lod && bias) || (lod == 0 && bias == 0))
7257                 continue;
7258 
7259             for (int f16TexAddr = 0; f16TexAddr <= 1; ++f16TexAddr) { // loop over 16-bit floating-point texel addressing
7260 
7261                 if (f16TexAddr && sampler.type != EbtFloat16)
7262                     continue;
7263 
7264                 for (int offset = 0; offset < 3; ++offset) { // loop over three forms of offset in the call name:  none, Offset, and Offsets
7265 
7266                     for (int comp = 0; comp < 2; ++comp) { // loop over presence of comp argument
7267 
7268                         if (comp == 0 && bias)
7269                             continue;
7270 
7271                         if (offset > 0 && sampler.dim == EsdCube)
7272                             continue;
7273 
7274                         for (int sparse = 0; sparse <= 1; ++sparse) { // loop over "bool" sparse or not
7275                             if (sparse && (profile == EEsProfile || version < 450))
7276                                 continue;
7277 
7278                             TString s;
7279 
7280                             // return type
7281                             if (sparse)
7282                                 s.append("int ");
7283                             else {
7284                                 s.append(prefixes[sampler.type]);
7285                                 s.append("vec4 ");
7286                             }
7287 
7288                             // name
7289                             if (sparse)
7290                                 s.append("sparseTextureGather");
7291                             else
7292                                 s.append("textureGather");
7293 
7294                             if (lod)
7295                                 s.append("Lod");
7296 
7297                             switch (offset) {
7298                             case 1:
7299                                 s.append("Offset");
7300                                 break;
7301                             case 2:
7302                                 s.append("Offsets");
7303                                 break;
7304                             default:
7305                                 break;
7306                             }
7307 
7308                             if (lod)
7309                                 s.append("AMD");
7310                             else if (sparse)
7311                                 s.append("ARB");
7312 
7313                             s.append("(");
7314 
7315                             // sampler type argument
7316                             s.append(typeName);
7317 
7318                             // P coordinate argument
7319                             if (f16TexAddr)
7320                                 s.append(",f16vec");
7321                             else
7322                                 s.append(",vec");
7323                             int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0);
7324                             s.append(postfixes[totalDims]);
7325 
7326                             // lod argument
7327                             if (lod) {
7328                                 if (f16TexAddr)
7329                                     s.append(",float16_t");
7330                                 else
7331                                     s.append(",float");
7332                             }
7333 
7334                             // offset argument
7335                             if (offset > 0) {
7336                                 s.append(",ivec2");
7337                                 if (offset == 2)
7338                                     s.append("[4]");
7339                             }
7340 
7341                             // texel out (for sparse texture)
7342                             if (sparse) {
7343                                 s.append(",out ");
7344                                 s.append(prefixes[sampler.type]);
7345                                 s.append("vec4 ");
7346                             }
7347 
7348                             // comp argument
7349                             if (comp)
7350                                 s.append(",int");
7351 
7352                             // bias argument
7353                             if (bias) {
7354                                 if (f16TexAddr)
7355                                     s.append(",float16_t");
7356                                 else
7357                                     s.append(",float");
7358                             }
7359 
7360                             s.append(");\n");
7361                             if (bias)
7362                                 stageBuiltins[EShLangFragment].append(s);
7363                             else
7364                                 commonBuiltins.append(s);
7365                         }
7366                     }
7367                 }
7368             }
7369         }
7370     }
7371 }
7372 
7373 //
7374 // Add context-dependent built-in functions and variables that are present
7375 // for the given version and profile.  All the results are put into just the
7376 // commonBuiltins, because it is called for just a specific stage.  So,
7377 // add stage-specific entries to the commonBuiltins, and only if that stage
7378 // was requested.
7379 //
initialize(const TBuiltInResource & resources,int version,EProfile profile,const SpvVersion & spvVersion,EShLanguage language)7380 void TBuiltIns::initialize(const TBuiltInResource &resources, int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language)
7381 {
7382     //
7383     // Initialize the context-dependent (resource-dependent) built-in strings for parsing.
7384     //
7385 
7386     //============================================================================
7387     //
7388     // Standard Uniforms
7389     //
7390     //============================================================================
7391 
7392     TString& s = commonBuiltins;
7393     const int maxSize = 200;
7394     char builtInConstant[maxSize];
7395 
7396     //
7397     // Build string of implementation dependent constants.
7398     //
7399 
7400     if (profile == EEsProfile) {
7401         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVertexAttribs = %d;", resources.maxVertexAttribs);
7402         s.append(builtInConstant);
7403 
7404         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVertexUniformVectors = %d;", resources.maxVertexUniformVectors);
7405         s.append(builtInConstant);
7406 
7407         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVertexTextureImageUnits = %d;", resources.maxVertexTextureImageUnits);
7408         s.append(builtInConstant);
7409 
7410         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxCombinedTextureImageUnits = %d;", resources.maxCombinedTextureImageUnits);
7411         s.append(builtInConstant);
7412 
7413         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxTextureImageUnits = %d;", resources.maxTextureImageUnits);
7414         s.append(builtInConstant);
7415 
7416         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxFragmentUniformVectors = %d;", resources.maxFragmentUniformVectors);
7417         s.append(builtInConstant);
7418 
7419         snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxDrawBuffers = %d;", resources.maxDrawBuffers);
7420         s.append(builtInConstant);
7421 
7422         if (version == 100) {
7423             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVaryingVectors = %d;", resources.maxVaryingVectors);
7424             s.append(builtInConstant);
7425         } else {
7426             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxVertexOutputVectors = %d;", resources.maxVertexOutputVectors);
7427             s.append(builtInConstant);
7428 
7429             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxFragmentInputVectors = %d;", resources.maxFragmentInputVectors);
7430             s.append(builtInConstant);
7431 
7432             snprintf(builtInConstant, maxSize, "const mediump int  gl_MinProgramTexelOffset = %d;", resources.minProgramTexelOffset);
7433             s.append(builtInConstant);
7434 
7435             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxProgramTexelOffset = %d;", resources.maxProgramTexelOffset);
7436             s.append(builtInConstant);
7437         }
7438 
7439         if (version >= 310) {
7440             // geometry
7441 
7442             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryInputComponents = %d;", resources.maxGeometryInputComponents);
7443             s.append(builtInConstant);
7444             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputComponents = %d;", resources.maxGeometryOutputComponents);
7445             s.append(builtInConstant);
7446             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryImageUniforms = %d;", resources.maxGeometryImageUniforms);
7447             s.append(builtInConstant);
7448             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTextureImageUnits = %d;", resources.maxGeometryTextureImageUnits);
7449             s.append(builtInConstant);
7450             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputVertices = %d;", resources.maxGeometryOutputVertices);
7451             s.append(builtInConstant);
7452             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTotalOutputComponents = %d;", resources.maxGeometryTotalOutputComponents);
7453             s.append(builtInConstant);
7454             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryUniformComponents = %d;", resources.maxGeometryUniformComponents);
7455             s.append(builtInConstant);
7456             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounters = %d;", resources.maxGeometryAtomicCounters);
7457             s.append(builtInConstant);
7458             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounterBuffers = %d;", resources.maxGeometryAtomicCounterBuffers);
7459             s.append(builtInConstant);
7460 
7461             // tessellation
7462 
7463             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlInputComponents = %d;", resources.maxTessControlInputComponents);
7464             s.append(builtInConstant);
7465             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlOutputComponents = %d;", resources.maxTessControlOutputComponents);
7466             s.append(builtInConstant);
7467             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTextureImageUnits = %d;", resources.maxTessControlTextureImageUnits);
7468             s.append(builtInConstant);
7469             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlUniformComponents = %d;", resources.maxTessControlUniformComponents);
7470             s.append(builtInConstant);
7471             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTotalOutputComponents = %d;", resources.maxTessControlTotalOutputComponents);
7472             s.append(builtInConstant);
7473 
7474             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationInputComponents = %d;", resources.maxTessEvaluationInputComponents);
7475             s.append(builtInConstant);
7476             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationOutputComponents = %d;", resources.maxTessEvaluationOutputComponents);
7477             s.append(builtInConstant);
7478             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationTextureImageUnits = %d;", resources.maxTessEvaluationTextureImageUnits);
7479             s.append(builtInConstant);
7480             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationUniformComponents = %d;", resources.maxTessEvaluationUniformComponents);
7481             s.append(builtInConstant);
7482 
7483             snprintf(builtInConstant, maxSize, "const int gl_MaxTessPatchComponents = %d;", resources.maxTessPatchComponents);
7484             s.append(builtInConstant);
7485 
7486             snprintf(builtInConstant, maxSize, "const int gl_MaxPatchVertices = %d;", resources.maxPatchVertices);
7487             s.append(builtInConstant);
7488             snprintf(builtInConstant, maxSize, "const int gl_MaxTessGenLevel = %d;", resources.maxTessGenLevel);
7489             s.append(builtInConstant);
7490 
7491             // this is here instead of with the others in initialize(version, profile) due to the dependence on gl_MaxPatchVertices
7492             if (language == EShLangTessControl || language == EShLangTessEvaluation) {
7493                 s.append(
7494                     "in gl_PerVertex {"
7495                         "highp vec4 gl_Position;"
7496                         "highp float gl_PointSize;"
7497                         "highp vec4 gl_SecondaryPositionNV;"  // GL_NV_stereo_view_rendering
7498                         "highp vec4 gl_PositionPerViewNV[];"  // GL_NVX_multiview_per_view_attributes
7499                     "} gl_in[gl_MaxPatchVertices];"
7500                     "\n");
7501             }
7502         }
7503 
7504         if (version >= 320) {
7505             // tessellation
7506 
7507             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlImageUniforms = %d;", resources.maxTessControlImageUniforms);
7508             s.append(builtInConstant);
7509             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationImageUniforms = %d;", resources.maxTessEvaluationImageUniforms);
7510             s.append(builtInConstant);
7511             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounters = %d;", resources.maxTessControlAtomicCounters);
7512             s.append(builtInConstant);
7513             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounters = %d;", resources.maxTessEvaluationAtomicCounters);
7514             s.append(builtInConstant);
7515             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounterBuffers = %d;", resources.maxTessControlAtomicCounterBuffers);
7516             s.append(builtInConstant);
7517             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounterBuffers = %d;", resources.maxTessEvaluationAtomicCounterBuffers);
7518             s.append(builtInConstant);
7519         }
7520 
7521         if (version >= 100) {
7522             // GL_EXT_blend_func_extended
7523             snprintf(builtInConstant, maxSize, "const mediump int gl_MaxDualSourceDrawBuffersEXT = %d;", resources.maxDualSourceDrawBuffersEXT);
7524             s.append(builtInConstant);
7525             // this is here instead of with the others in initialize(version, profile) due to the dependence on gl_MaxDualSourceDrawBuffersEXT
7526             if (language == EShLangFragment) {
7527                 s.append(
7528                     "mediump vec4 gl_SecondaryFragColorEXT;"
7529                     "mediump vec4 gl_SecondaryFragDataEXT[gl_MaxDualSourceDrawBuffersEXT];"
7530                     "\n");
7531             }
7532         }
7533     } else {
7534         // non-ES profile
7535 
7536         if (version > 400) {
7537             snprintf(builtInConstant, maxSize, "const int  gl_MaxVertexUniformVectors = %d;", resources.maxVertexUniformVectors);
7538             s.append(builtInConstant);
7539 
7540             snprintf(builtInConstant, maxSize, "const int  gl_MaxFragmentUniformVectors = %d;", resources.maxFragmentUniformVectors);
7541             s.append(builtInConstant);
7542 
7543             snprintf(builtInConstant, maxSize, "const int  gl_MaxVaryingVectors = %d;", resources.maxVaryingVectors);
7544             s.append(builtInConstant);
7545         }
7546 
7547         snprintf(builtInConstant, maxSize, "const int  gl_MaxVertexAttribs = %d;", resources.maxVertexAttribs);
7548         s.append(builtInConstant);
7549 
7550         snprintf(builtInConstant, maxSize, "const int  gl_MaxVertexTextureImageUnits = %d;", resources.maxVertexTextureImageUnits);
7551         s.append(builtInConstant);
7552 
7553         snprintf(builtInConstant, maxSize, "const int  gl_MaxCombinedTextureImageUnits = %d;", resources.maxCombinedTextureImageUnits);
7554         s.append(builtInConstant);
7555 
7556         snprintf(builtInConstant, maxSize, "const int  gl_MaxTextureImageUnits = %d;", resources.maxTextureImageUnits);
7557         s.append(builtInConstant);
7558 
7559         snprintf(builtInConstant, maxSize, "const int  gl_MaxDrawBuffers = %d;", resources.maxDrawBuffers);
7560         s.append(builtInConstant);
7561 
7562         snprintf(builtInConstant, maxSize, "const int  gl_MaxLights = %d;", resources.maxLights);
7563         s.append(builtInConstant);
7564 
7565         snprintf(builtInConstant, maxSize, "const int  gl_MaxClipPlanes = %d;", resources.maxClipPlanes);
7566         s.append(builtInConstant);
7567 
7568         snprintf(builtInConstant, maxSize, "const int  gl_MaxTextureUnits = %d;", resources.maxTextureUnits);
7569         s.append(builtInConstant);
7570 
7571         snprintf(builtInConstant, maxSize, "const int  gl_MaxTextureCoords = %d;", resources.maxTextureCoords);
7572         s.append(builtInConstant);
7573 
7574         snprintf(builtInConstant, maxSize, "const int  gl_MaxVertexUniformComponents = %d;", resources.maxVertexUniformComponents);
7575         s.append(builtInConstant);
7576 
7577         // Moved from just being deprecated into compatibility profile only as of 4.20
7578         if (version < 420 || profile == ECompatibilityProfile) {
7579             snprintf(builtInConstant, maxSize, "const int  gl_MaxVaryingFloats = %d;", resources.maxVaryingFloats);
7580             s.append(builtInConstant);
7581         }
7582 
7583         snprintf(builtInConstant, maxSize, "const int  gl_MaxFragmentUniformComponents = %d;", resources.maxFragmentUniformComponents);
7584         s.append(builtInConstant);
7585 
7586         if (spvVersion.spv == 0 && IncludeLegacy(version, profile, spvVersion)) {
7587             //
7588             // OpenGL'uniform' state.  Page numbers are in reference to version
7589             // 1.4 of the OpenGL specification.
7590             //
7591 
7592             //
7593             // Matrix state. p. 31, 32, 37, 39, 40.
7594             //
7595             s.append("uniform mat4  gl_TextureMatrix[gl_MaxTextureCoords];"
7596 
7597             //
7598             // Derived matrix state that provides inverse and transposed versions
7599             // of the matrices above.
7600             //
7601                         "uniform mat4  gl_TextureMatrixInverse[gl_MaxTextureCoords];"
7602 
7603                         "uniform mat4  gl_TextureMatrixTranspose[gl_MaxTextureCoords];"
7604 
7605                         "uniform mat4  gl_TextureMatrixInverseTranspose[gl_MaxTextureCoords];"
7606 
7607             //
7608             // Clip planes p. 42.
7609             //
7610                         "uniform vec4  gl_ClipPlane[gl_MaxClipPlanes];"
7611 
7612             //
7613             // Light State p 50, 53, 55.
7614             //
7615                         "uniform gl_LightSourceParameters  gl_LightSource[gl_MaxLights];"
7616 
7617             //
7618             // Derived state from products of light.
7619             //
7620                         "uniform gl_LightProducts gl_FrontLightProduct[gl_MaxLights];"
7621                         "uniform gl_LightProducts gl_BackLightProduct[gl_MaxLights];"
7622 
7623             //
7624             // Texture Environment and Generation, p. 152, p. 40-42.
7625             //
7626                         "uniform vec4  gl_TextureEnvColor[gl_MaxTextureImageUnits];"
7627                         "uniform vec4  gl_EyePlaneS[gl_MaxTextureCoords];"
7628                         "uniform vec4  gl_EyePlaneT[gl_MaxTextureCoords];"
7629                         "uniform vec4  gl_EyePlaneR[gl_MaxTextureCoords];"
7630                         "uniform vec4  gl_EyePlaneQ[gl_MaxTextureCoords];"
7631                         "uniform vec4  gl_ObjectPlaneS[gl_MaxTextureCoords];"
7632                         "uniform vec4  gl_ObjectPlaneT[gl_MaxTextureCoords];"
7633                         "uniform vec4  gl_ObjectPlaneR[gl_MaxTextureCoords];"
7634                         "uniform vec4  gl_ObjectPlaneQ[gl_MaxTextureCoords];");
7635         }
7636 
7637         if (version >= 130) {
7638             snprintf(builtInConstant, maxSize, "const int gl_MaxClipDistances = %d;", resources.maxClipDistances);
7639             s.append(builtInConstant);
7640             snprintf(builtInConstant, maxSize, "const int gl_MaxVaryingComponents = %d;", resources.maxVaryingComponents);
7641             s.append(builtInConstant);
7642 
7643             // GL_ARB_shading_language_420pack
7644             snprintf(builtInConstant, maxSize, "const mediump int  gl_MinProgramTexelOffset = %d;", resources.minProgramTexelOffset);
7645             s.append(builtInConstant);
7646             snprintf(builtInConstant, maxSize, "const mediump int  gl_MaxProgramTexelOffset = %d;", resources.maxProgramTexelOffset);
7647             s.append(builtInConstant);
7648         }
7649 
7650         // geometry
7651         if (version >= 150) {
7652             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryInputComponents = %d;", resources.maxGeometryInputComponents);
7653             s.append(builtInConstant);
7654             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputComponents = %d;", resources.maxGeometryOutputComponents);
7655             s.append(builtInConstant);
7656             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTextureImageUnits = %d;", resources.maxGeometryTextureImageUnits);
7657             s.append(builtInConstant);
7658             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputVertices = %d;", resources.maxGeometryOutputVertices);
7659             s.append(builtInConstant);
7660             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTotalOutputComponents = %d;", resources.maxGeometryTotalOutputComponents);
7661             s.append(builtInConstant);
7662             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryUniformComponents = %d;", resources.maxGeometryUniformComponents);
7663             s.append(builtInConstant);
7664             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryVaryingComponents = %d;", resources.maxGeometryVaryingComponents);
7665             s.append(builtInConstant);
7666 
7667         }
7668 
7669         if (version >= 150) {
7670             snprintf(builtInConstant, maxSize, "const int gl_MaxVertexOutputComponents = %d;", resources.maxVertexOutputComponents);
7671             s.append(builtInConstant);
7672             snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentInputComponents = %d;", resources.maxFragmentInputComponents);
7673             s.append(builtInConstant);
7674         }
7675 
7676         // tessellation
7677         if (version >= 150) {
7678             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlInputComponents = %d;", resources.maxTessControlInputComponents);
7679             s.append(builtInConstant);
7680             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlOutputComponents = %d;", resources.maxTessControlOutputComponents);
7681             s.append(builtInConstant);
7682             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTextureImageUnits = %d;", resources.maxTessControlTextureImageUnits);
7683             s.append(builtInConstant);
7684             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlUniformComponents = %d;", resources.maxTessControlUniformComponents);
7685             s.append(builtInConstant);
7686             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTotalOutputComponents = %d;", resources.maxTessControlTotalOutputComponents);
7687             s.append(builtInConstant);
7688 
7689             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationInputComponents = %d;", resources.maxTessEvaluationInputComponents);
7690             s.append(builtInConstant);
7691             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationOutputComponents = %d;", resources.maxTessEvaluationOutputComponents);
7692             s.append(builtInConstant);
7693             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationTextureImageUnits = %d;", resources.maxTessEvaluationTextureImageUnits);
7694             s.append(builtInConstant);
7695             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationUniformComponents = %d;", resources.maxTessEvaluationUniformComponents);
7696             s.append(builtInConstant);
7697 
7698             snprintf(builtInConstant, maxSize, "const int gl_MaxTessPatchComponents = %d;", resources.maxTessPatchComponents);
7699             s.append(builtInConstant);
7700             snprintf(builtInConstant, maxSize, "const int gl_MaxTessGenLevel = %d;", resources.maxTessGenLevel);
7701             s.append(builtInConstant);
7702             snprintf(builtInConstant, maxSize, "const int gl_MaxPatchVertices = %d;", resources.maxPatchVertices);
7703             s.append(builtInConstant);
7704 
7705             // this is here instead of with the others in initialize(version, profile) due to the dependence on gl_MaxPatchVertices
7706             if (language == EShLangTessControl || language == EShLangTessEvaluation) {
7707                 s.append(
7708                     "in gl_PerVertex {"
7709                         "vec4 gl_Position;"
7710                         "float gl_PointSize;"
7711                         "float gl_ClipDistance[];"
7712                     );
7713                 if (profile == ECompatibilityProfile)
7714                     s.append(
7715                         "vec4 gl_ClipVertex;"
7716                         "vec4 gl_FrontColor;"
7717                         "vec4 gl_BackColor;"
7718                         "vec4 gl_FrontSecondaryColor;"
7719                         "vec4 gl_BackSecondaryColor;"
7720                         "vec4 gl_TexCoord[];"
7721                         "float gl_FogFragCoord;"
7722                         );
7723                 if (profile != EEsProfile && version >= 450)
7724                     s.append(
7725                         "float gl_CullDistance[];"
7726                         "vec4 gl_SecondaryPositionNV;"  // GL_NV_stereo_view_rendering
7727                         "vec4 gl_PositionPerViewNV[];"  // GL_NVX_multiview_per_view_attributes
7728                        );
7729                 s.append(
7730                     "} gl_in[gl_MaxPatchVertices];"
7731                     "\n");
7732             }
7733         }
7734 
7735         if (version >= 150) {
7736             snprintf(builtInConstant, maxSize, "const int gl_MaxViewports = %d;", resources.maxViewports);
7737             s.append(builtInConstant);
7738         }
7739 
7740         // images
7741         if (version >= 130) {
7742             snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedImageUnitsAndFragmentOutputs = %d;", resources.maxCombinedImageUnitsAndFragmentOutputs);
7743             s.append(builtInConstant);
7744             snprintf(builtInConstant, maxSize, "const int gl_MaxImageSamples = %d;", resources.maxImageSamples);
7745             s.append(builtInConstant);
7746             snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlImageUniforms = %d;", resources.maxTessControlImageUniforms);
7747             s.append(builtInConstant);
7748             snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationImageUniforms = %d;", resources.maxTessEvaluationImageUniforms);
7749             s.append(builtInConstant);
7750             snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryImageUniforms = %d;", resources.maxGeometryImageUniforms);
7751             s.append(builtInConstant);
7752         }
7753 
7754         // enhanced layouts
7755         if (version >= 430) {
7756             snprintf(builtInConstant, maxSize, "const int gl_MaxTransformFeedbackBuffers = %d;", resources.maxTransformFeedbackBuffers);
7757             s.append(builtInConstant);
7758             snprintf(builtInConstant, maxSize, "const int gl_MaxTransformFeedbackInterleavedComponents = %d;", resources.maxTransformFeedbackInterleavedComponents);
7759             s.append(builtInConstant);
7760         }
7761     }
7762 
7763     // compute
7764     if ((profile == EEsProfile && version >= 310) || (profile != EEsProfile && version >= 420)) {
7765         snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxComputeWorkGroupCount = ivec3(%d,%d,%d);", resources.maxComputeWorkGroupCountX,
7766                                                                                                          resources.maxComputeWorkGroupCountY,
7767                                                                                                          resources.maxComputeWorkGroupCountZ);
7768         s.append(builtInConstant);
7769         snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxComputeWorkGroupSize = ivec3(%d,%d,%d);", resources.maxComputeWorkGroupSizeX,
7770                                                                                                         resources.maxComputeWorkGroupSizeY,
7771                                                                                                         resources.maxComputeWorkGroupSizeZ);
7772         s.append(builtInConstant);
7773 
7774         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeUniformComponents = %d;", resources.maxComputeUniformComponents);
7775         s.append(builtInConstant);
7776         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeTextureImageUnits = %d;", resources.maxComputeTextureImageUnits);
7777         s.append(builtInConstant);
7778 
7779         s.append("\n");
7780     }
7781 
7782     // images (some in compute below)
7783     if ((profile == EEsProfile && version >= 310) ||
7784         (profile != EEsProfile && version >= 130)) {
7785         snprintf(builtInConstant, maxSize, "const int gl_MaxImageUnits = %d;", resources.maxImageUnits);
7786         s.append(builtInConstant);
7787         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedShaderOutputResources = %d;", resources.maxCombinedShaderOutputResources);
7788         s.append(builtInConstant);
7789         snprintf(builtInConstant, maxSize, "const int gl_MaxVertexImageUniforms = %d;", resources.maxVertexImageUniforms);
7790         s.append(builtInConstant);
7791         snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentImageUniforms = %d;", resources.maxFragmentImageUniforms);
7792         s.append(builtInConstant);
7793         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedImageUniforms = %d;", resources.maxCombinedImageUniforms);
7794         s.append(builtInConstant);
7795     }
7796 
7797     // compute
7798     if ((profile == EEsProfile && version >= 310) || (profile != EEsProfile && version >= 420)) {
7799         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeImageUniforms = %d;", resources.maxComputeImageUniforms);
7800         s.append(builtInConstant);
7801         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeAtomicCounters = %d;", resources.maxComputeAtomicCounters);
7802         s.append(builtInConstant);
7803         snprintf(builtInConstant, maxSize, "const int gl_MaxComputeAtomicCounterBuffers = %d;", resources.maxComputeAtomicCounterBuffers);
7804         s.append(builtInConstant);
7805 
7806         s.append("\n");
7807     }
7808 
7809     // atomic counters (some in compute below)
7810     if ((profile == EEsProfile && version >= 310) ||
7811         (profile != EEsProfile && version >= 420)) {
7812         snprintf(builtInConstant, maxSize, "const int gl_MaxVertexAtomicCounters = %d;", resources.               maxVertexAtomicCounters);
7813         s.append(builtInConstant);
7814         snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentAtomicCounters = %d;", resources.             maxFragmentAtomicCounters);
7815         s.append(builtInConstant);
7816         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedAtomicCounters = %d;", resources.             maxCombinedAtomicCounters);
7817         s.append(builtInConstant);
7818         snprintf(builtInConstant, maxSize, "const int gl_MaxAtomicCounterBindings = %d;", resources.              maxAtomicCounterBindings);
7819         s.append(builtInConstant);
7820         snprintf(builtInConstant, maxSize, "const int gl_MaxVertexAtomicCounterBuffers = %d;", resources.         maxVertexAtomicCounterBuffers);
7821         s.append(builtInConstant);
7822         snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentAtomicCounterBuffers = %d;", resources.       maxFragmentAtomicCounterBuffers);
7823         s.append(builtInConstant);
7824         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedAtomicCounterBuffers = %d;", resources.       maxCombinedAtomicCounterBuffers);
7825         s.append(builtInConstant);
7826         snprintf(builtInConstant, maxSize, "const int gl_MaxAtomicCounterBufferSize = %d;", resources.            maxAtomicCounterBufferSize);
7827         s.append(builtInConstant);
7828     }
7829     if (profile != EEsProfile && version >= 420) {
7830         snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounters = %d;", resources.          maxTessControlAtomicCounters);
7831         s.append(builtInConstant);
7832         snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounters = %d;", resources.       maxTessEvaluationAtomicCounters);
7833         s.append(builtInConstant);
7834         snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounters = %d;", resources.             maxGeometryAtomicCounters);
7835         s.append(builtInConstant);
7836         snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounterBuffers = %d;", resources.    maxTessControlAtomicCounterBuffers);
7837         s.append(builtInConstant);
7838         snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounterBuffers = %d;", resources. maxTessEvaluationAtomicCounterBuffers);
7839         s.append(builtInConstant);
7840         snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounterBuffers = %d;", resources.       maxGeometryAtomicCounterBuffers);
7841         s.append(builtInConstant);
7842 
7843         s.append("\n");
7844     }
7845 
7846     // GL_ARB_cull_distance
7847     if (profile != EEsProfile && version >= 450) {
7848         snprintf(builtInConstant, maxSize, "const int gl_MaxCullDistances = %d;",                resources.maxCullDistances);
7849         s.append(builtInConstant);
7850         snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedClipAndCullDistances = %d;", resources.maxCombinedClipAndCullDistances);
7851         s.append(builtInConstant);
7852     }
7853 
7854     // GL_ARB_ES3_1_compatibility
7855     if ((profile != EEsProfile && version >= 450) ||
7856         (profile == EEsProfile && version >= 310)) {
7857         snprintf(builtInConstant, maxSize, "const int gl_MaxSamples = %d;", resources.maxSamples);
7858         s.append(builtInConstant);
7859     }
7860 
7861     // SPV_NV_mesh_shader
7862     if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
7863         snprintf(builtInConstant, maxSize, "const int gl_MaxMeshOutputVerticesNV = %d;", resources.maxMeshOutputVerticesNV);
7864         s.append(builtInConstant);
7865 
7866         snprintf(builtInConstant, maxSize, "const int gl_MaxMeshOutputPrimitivesNV = %d;", resources.maxMeshOutputPrimitivesNV);
7867         s.append(builtInConstant);
7868 
7869         snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxMeshWorkGroupSizeNV = ivec3(%d,%d,%d);", resources.maxMeshWorkGroupSizeX_NV,
7870                                                                                                        resources.maxMeshWorkGroupSizeY_NV,
7871                                                                                                        resources.maxMeshWorkGroupSizeZ_NV);
7872         s.append(builtInConstant);
7873         snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxTaskWorkGroupSizeNV = ivec3(%d,%d,%d);", resources.maxTaskWorkGroupSizeX_NV,
7874                                                                                                        resources.maxTaskWorkGroupSizeY_NV,
7875                                                                                                        resources.maxTaskWorkGroupSizeZ_NV);
7876         s.append(builtInConstant);
7877 
7878         snprintf(builtInConstant, maxSize, "const int gl_MaxMeshViewCountNV = %d;", resources.maxMeshViewCountNV);
7879         s.append(builtInConstant);
7880 
7881         s.append("\n");
7882     }
7883 
7884     s.append("\n");
7885 }
7886 
7887 //
7888 // To support special built-ins that have a special qualifier that cannot be declared textually
7889 // in a shader, like gl_Position.
7890 //
7891 // This lets the type of the built-in be declared textually, and then have just its qualifier be
7892 // updated afterward.
7893 //
7894 // Safe to call even if name is not present.
7895 //
7896 // Only use this for built-in variables that have a special qualifier in TStorageQualifier.
7897 // New built-in variables should use a generic (textually declarable) qualifier in
7898 // TStoraregQualifier and only call BuiltInVariable().
7899 //
SpecialQualifier(const char * name,TStorageQualifier qualifier,TBuiltInVariable builtIn,TSymbolTable & symbolTable)7900 static void SpecialQualifier(const char* name, TStorageQualifier qualifier, TBuiltInVariable builtIn, TSymbolTable& symbolTable)
7901 {
7902     TSymbol* symbol = symbolTable.find(name);
7903     if (symbol == nullptr)
7904         return;
7905 
7906     TQualifier& symQualifier = symbol->getWritableType().getQualifier();
7907     symQualifier.storage = qualifier;
7908     symQualifier.builtIn = builtIn;
7909 }
7910 
7911 //
7912 // Modify the symbol's flat decoration.
7913 //
7914 // Safe to call even if name is not present.
7915 //
7916 // Originally written to transform gl_SubGroupSizeARB from uniform to fragment input in Vulkan.
7917 //
ModifyFlatDecoration(const char * name,bool flat,TSymbolTable & symbolTable)7918 static void ModifyFlatDecoration(const char* name, bool flat, TSymbolTable& symbolTable)
7919 {
7920     TSymbol* symbol = symbolTable.find(name);
7921     if (symbol == nullptr)
7922         return;
7923 
7924     TQualifier& symQualifier = symbol->getWritableType().getQualifier();
7925     symQualifier.flat = flat;
7926 }
7927 
7928 //
7929 // To tag built-in variables with their TBuiltInVariable enum.  Use this when the
7930 // normal declaration text already gets the qualifier right, and all that's needed
7931 // is setting the builtIn field.  This should be the normal way for all new
7932 // built-in variables.
7933 //
7934 // If SpecialQualifier() was called, this does not need to be called.
7935 //
7936 // Safe to call even if name is not present.
7937 //
BuiltInVariable(const char * name,TBuiltInVariable builtIn,TSymbolTable & symbolTable)7938 static void BuiltInVariable(const char* name, TBuiltInVariable builtIn, TSymbolTable& symbolTable)
7939 {
7940     TSymbol* symbol = symbolTable.find(name);
7941     if (symbol == nullptr)
7942         return;
7943 
7944     TQualifier& symQualifier = symbol->getWritableType().getQualifier();
7945     symQualifier.builtIn = builtIn;
7946 }
7947 
RetargetVariable(const char * from,const char * to,TSymbolTable & symbolTable)7948 static void RetargetVariable(const char* from, const char* to, TSymbolTable& symbolTable)
7949 {
7950     symbolTable.retargetSymbol(from, to);
7951 }
7952 
7953 //
7954 // For built-in variables inside a named block.
7955 // SpecialQualifier() won't ever go inside a block; their member's qualifier come
7956 // from the qualification of the block.
7957 //
7958 // See comments above for other detail.
7959 //
BuiltInVariable(const char * blockName,const char * name,TBuiltInVariable builtIn,TSymbolTable & symbolTable)7960 static void BuiltInVariable(const char* blockName, const char* name, TBuiltInVariable builtIn, TSymbolTable& symbolTable)
7961 {
7962     TSymbol* symbol = symbolTable.find(blockName);
7963     if (symbol == nullptr)
7964         return;
7965 
7966     TTypeList& structure = *symbol->getWritableType().getWritableStruct();
7967     for (int i = 0; i < (int)structure.size(); ++i) {
7968         if (structure[i].type->getFieldName().compare(name) == 0) {
7969             structure[i].type->getQualifier().builtIn = builtIn;
7970             return;
7971         }
7972     }
7973 }
7974 
7975 //
7976 // Finish adding/processing context-independent built-in symbols.
7977 // 1) Programmatically add symbols that could not be added by simple text strings above.
7978 // 2) Map built-in functions to operators, for those that will turn into an operation node
7979 //    instead of remaining a function call.
7980 // 3) Tag extension-related symbols added to their base version with their extensions, so
7981 //    that if an early version has the extension turned off, there is an error reported on use.
7982 //
identifyBuiltIns(int version,EProfile profile,const SpvVersion & spvVersion,EShLanguage language,TSymbolTable & symbolTable)7983 void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable)
7984 {
7985     //
7986     // Tag built-in variables and functions with additional qualifier and extension information
7987     // that cannot be declared with the text strings.
7988     //
7989 
7990     // N.B.: a symbol should only be tagged once, and this function is called multiple times, once
7991     // per stage that's used for this profile.  So
7992     //  - generally, stick common ones in the fragment stage to ensure they are tagged exactly once
7993     //  - for ES, which has different precisions for different stages, the coarsest-grained tagging
7994     //    for a built-in used in many stages needs to be once for the fragment stage and once for
7995     //    the vertex stage
7996 
7997     switch(language) {
7998     case EShLangVertex:
7999         if (spvVersion.vulkan > 0) {
8000             BuiltInVariable("gl_VertexIndex",   EbvVertexIndex,   symbolTable);
8001             BuiltInVariable("gl_InstanceIndex", EbvInstanceIndex, symbolTable);
8002         }
8003 
8004         if (spvVersion.vulkan == 0) {
8005             SpecialQualifier("gl_VertexID",   EvqVertexId,   EbvVertexId,   symbolTable);
8006             SpecialQualifier("gl_InstanceID", EvqInstanceId, EbvInstanceId, symbolTable);
8007             if (version < 140)
8008                 symbolTable.setVariableExtensions("gl_InstanceID", 1, &E_GL_EXT_draw_instanced);
8009         }
8010 
8011         if (spvVersion.vulkan > 0 && spvVersion.vulkanRelaxed) {
8012             // treat these built-ins as aliases of VertexIndex and InstanceIndex
8013             RetargetVariable("gl_InstanceID", "gl_InstanceIndex", symbolTable);
8014             RetargetVariable("gl_VertexID", "gl_VertexIndex", symbolTable);
8015         }
8016 
8017         if (profile != EEsProfile) {
8018             if (version >= 440) {
8019                 symbolTable.setVariableExtensions("gl_BaseVertexARB",   1, &E_GL_ARB_shader_draw_parameters);
8020                 symbolTable.setVariableExtensions("gl_BaseInstanceARB", 1, &E_GL_ARB_shader_draw_parameters);
8021                 symbolTable.setVariableExtensions("gl_DrawIDARB",       1, &E_GL_ARB_shader_draw_parameters);
8022                 BuiltInVariable("gl_BaseVertexARB",   EbvBaseVertex,   symbolTable);
8023                 BuiltInVariable("gl_BaseInstanceARB", EbvBaseInstance, symbolTable);
8024                 BuiltInVariable("gl_DrawIDARB",       EbvDrawId,       symbolTable);
8025             }
8026             if (version >= 460) {
8027                 BuiltInVariable("gl_BaseVertex",   EbvBaseVertex,   symbolTable);
8028                 BuiltInVariable("gl_BaseInstance", EbvBaseInstance, symbolTable);
8029                 BuiltInVariable("gl_DrawID",       EbvDrawId,       symbolTable);
8030             }
8031             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
8032             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
8033             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
8034             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
8035             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
8036             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
8037             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
8038 
8039             symbolTable.setFunctionExtensions("ballotARB",              1, &E_GL_ARB_shader_ballot);
8040             symbolTable.setFunctionExtensions("readInvocationARB",      1, &E_GL_ARB_shader_ballot);
8041             symbolTable.setFunctionExtensions("readFirstInvocationARB", 1, &E_GL_ARB_shader_ballot);
8042 
8043             if (version >= 430) {
8044                 symbolTable.setFunctionExtensions("anyInvocationARB",       1, &E_GL_ARB_shader_group_vote);
8045                 symbolTable.setFunctionExtensions("allInvocationsARB",      1, &E_GL_ARB_shader_group_vote);
8046                 symbolTable.setFunctionExtensions("allInvocationsEqualARB", 1, &E_GL_ARB_shader_group_vote);
8047             }
8048         }
8049 
8050 
8051         if (profile != EEsProfile) {
8052             symbolTable.setFunctionExtensions("minInvocationsAMD",                1, &E_GL_AMD_shader_ballot);
8053             symbolTable.setFunctionExtensions("maxInvocationsAMD",                1, &E_GL_AMD_shader_ballot);
8054             symbolTable.setFunctionExtensions("addInvocationsAMD",                1, &E_GL_AMD_shader_ballot);
8055             symbolTable.setFunctionExtensions("minInvocationsNonUniformAMD",      1, &E_GL_AMD_shader_ballot);
8056             symbolTable.setFunctionExtensions("maxInvocationsNonUniformAMD",      1, &E_GL_AMD_shader_ballot);
8057             symbolTable.setFunctionExtensions("addInvocationsNonUniformAMD",      1, &E_GL_AMD_shader_ballot);
8058             symbolTable.setFunctionExtensions("swizzleInvocationsAMD",            1, &E_GL_AMD_shader_ballot);
8059             symbolTable.setFunctionExtensions("swizzleInvocationsWithPatternAMD", 1, &E_GL_AMD_shader_ballot);
8060             symbolTable.setFunctionExtensions("writeInvocationAMD",               1, &E_GL_AMD_shader_ballot);
8061             symbolTable.setFunctionExtensions("mbcntAMD",                         1, &E_GL_AMD_shader_ballot);
8062 
8063             symbolTable.setFunctionExtensions("minInvocationsInclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
8064             symbolTable.setFunctionExtensions("maxInvocationsInclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
8065             symbolTable.setFunctionExtensions("addInvocationsInclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
8066             symbolTable.setFunctionExtensions("minInvocationsInclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
8067             symbolTable.setFunctionExtensions("maxInvocationsInclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
8068             symbolTable.setFunctionExtensions("addInvocationsInclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
8069             symbolTable.setFunctionExtensions("minInvocationsExclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
8070             symbolTable.setFunctionExtensions("maxInvocationsExclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
8071             symbolTable.setFunctionExtensions("addInvocationsExclusiveScanAMD",             1, &E_GL_AMD_shader_ballot);
8072             symbolTable.setFunctionExtensions("minInvocationsExclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
8073             symbolTable.setFunctionExtensions("maxInvocationsExclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
8074             symbolTable.setFunctionExtensions("addInvocationsExclusiveScanNonUniformAMD",   1, &E_GL_AMD_shader_ballot);
8075         }
8076 
8077         if (profile != EEsProfile) {
8078             symbolTable.setFunctionExtensions("min3", 1, &E_GL_AMD_shader_trinary_minmax);
8079             symbolTable.setFunctionExtensions("max3", 1, &E_GL_AMD_shader_trinary_minmax);
8080             symbolTable.setFunctionExtensions("mid3", 1, &E_GL_AMD_shader_trinary_minmax);
8081         }
8082 
8083         if (profile != EEsProfile) {
8084             symbolTable.setVariableExtensions("gl_SIMDGroupSizeAMD", 1, &E_GL_AMD_gcn_shader);
8085             SpecialQualifier("gl_SIMDGroupSizeAMD", EvqVaryingIn, EbvSubGroupSize, symbolTable);
8086 
8087             symbolTable.setFunctionExtensions("cubeFaceIndexAMD", 1, &E_GL_AMD_gcn_shader);
8088             symbolTable.setFunctionExtensions("cubeFaceCoordAMD", 1, &E_GL_AMD_gcn_shader);
8089             symbolTable.setFunctionExtensions("timeAMD",          1, &E_GL_AMD_gcn_shader);
8090         }
8091 
8092         if (profile != EEsProfile) {
8093             symbolTable.setFunctionExtensions("fragmentMaskFetchAMD", 1, &E_GL_AMD_shader_fragment_mask);
8094             symbolTable.setFunctionExtensions("fragmentFetchAMD",     1, &E_GL_AMD_shader_fragment_mask);
8095         }
8096 
8097         symbolTable.setFunctionExtensions("countLeadingZeros",  1, &E_GL_INTEL_shader_integer_functions2);
8098         symbolTable.setFunctionExtensions("countTrailingZeros", 1, &E_GL_INTEL_shader_integer_functions2);
8099         symbolTable.setFunctionExtensions("absoluteDifference", 1, &E_GL_INTEL_shader_integer_functions2);
8100         symbolTable.setFunctionExtensions("addSaturate",        1, &E_GL_INTEL_shader_integer_functions2);
8101         symbolTable.setFunctionExtensions("subtractSaturate",   1, &E_GL_INTEL_shader_integer_functions2);
8102         symbolTable.setFunctionExtensions("average",            1, &E_GL_INTEL_shader_integer_functions2);
8103         symbolTable.setFunctionExtensions("averageRounded",     1, &E_GL_INTEL_shader_integer_functions2);
8104         symbolTable.setFunctionExtensions("multiply32x16",      1, &E_GL_INTEL_shader_integer_functions2);
8105 
8106         symbolTable.setFunctionExtensions("textureFootprintNV",          1, &E_GL_NV_shader_texture_footprint);
8107         symbolTable.setFunctionExtensions("textureFootprintClampNV",     1, &E_GL_NV_shader_texture_footprint);
8108         symbolTable.setFunctionExtensions("textureFootprintLodNV",       1, &E_GL_NV_shader_texture_footprint);
8109         symbolTable.setFunctionExtensions("textureFootprintGradNV",      1, &E_GL_NV_shader_texture_footprint);
8110         symbolTable.setFunctionExtensions("textureFootprintGradClampNV", 1, &E_GL_NV_shader_texture_footprint);
8111         // Compatibility variables, vertex only
8112         if (spvVersion.spv == 0) {
8113             BuiltInVariable("gl_Color",          EbvColor,          symbolTable);
8114             BuiltInVariable("gl_SecondaryColor", EbvSecondaryColor, symbolTable);
8115             BuiltInVariable("gl_Normal",         EbvNormal,         symbolTable);
8116             BuiltInVariable("gl_Vertex",         EbvVertex,         symbolTable);
8117             BuiltInVariable("gl_MultiTexCoord0", EbvMultiTexCoord0, symbolTable);
8118             BuiltInVariable("gl_MultiTexCoord1", EbvMultiTexCoord1, symbolTable);
8119             BuiltInVariable("gl_MultiTexCoord2", EbvMultiTexCoord2, symbolTable);
8120             BuiltInVariable("gl_MultiTexCoord3", EbvMultiTexCoord3, symbolTable);
8121             BuiltInVariable("gl_MultiTexCoord4", EbvMultiTexCoord4, symbolTable);
8122             BuiltInVariable("gl_MultiTexCoord5", EbvMultiTexCoord5, symbolTable);
8123             BuiltInVariable("gl_MultiTexCoord6", EbvMultiTexCoord6, symbolTable);
8124             BuiltInVariable("gl_MultiTexCoord7", EbvMultiTexCoord7, symbolTable);
8125             BuiltInVariable("gl_FogCoord",       EbvFogFragCoord,   symbolTable);
8126         }
8127 
8128         if (profile == EEsProfile) {
8129             if (spvVersion.spv == 0) {
8130                 symbolTable.setFunctionExtensions("texture2DGradEXT",     1, &E_GL_EXT_shader_texture_lod);
8131                 symbolTable.setFunctionExtensions("texture2DProjGradEXT", 1, &E_GL_EXT_shader_texture_lod);
8132                 symbolTable.setFunctionExtensions("textureCubeGradEXT",   1, &E_GL_EXT_shader_texture_lod);
8133                 if (version == 310)
8134                     symbolTable.setFunctionExtensions("textureGatherOffsets", Num_AEP_gpu_shader5, AEP_gpu_shader5);
8135             }
8136             if (version == 310)
8137                 symbolTable.setFunctionExtensions("fma", Num_AEP_gpu_shader5, AEP_gpu_shader5);
8138         }
8139 
8140         if (profile == EEsProfile && version < 320) {
8141             symbolTable.setFunctionExtensions("imageAtomicAdd",      1, &E_GL_OES_shader_image_atomic);
8142             symbolTable.setFunctionExtensions("imageAtomicMin",      1, &E_GL_OES_shader_image_atomic);
8143             symbolTable.setFunctionExtensions("imageAtomicMax",      1, &E_GL_OES_shader_image_atomic);
8144             symbolTable.setFunctionExtensions("imageAtomicAnd",      1, &E_GL_OES_shader_image_atomic);
8145             symbolTable.setFunctionExtensions("imageAtomicOr",       1, &E_GL_OES_shader_image_atomic);
8146             symbolTable.setFunctionExtensions("imageAtomicXor",      1, &E_GL_OES_shader_image_atomic);
8147             symbolTable.setFunctionExtensions("imageAtomicExchange", 1, &E_GL_OES_shader_image_atomic);
8148             symbolTable.setFunctionExtensions("imageAtomicCompSwap", 1, &E_GL_OES_shader_image_atomic);
8149         }
8150 
8151         if (version >= 300 /* both ES and non-ES */) {
8152             symbolTable.setVariableExtensions("gl_ViewID_OVR", Num_OVR_multiview_EXTs, OVR_multiview_EXTs);
8153             BuiltInVariable("gl_ViewID_OVR", EbvViewIndex, symbolTable);
8154         }
8155 
8156         if (profile == EEsProfile) {
8157             symbolTable.setFunctionExtensions("shadow2DEXT",        1, &E_GL_EXT_shadow_samplers);
8158             symbolTable.setFunctionExtensions("shadow2DProjEXT",    1, &E_GL_EXT_shadow_samplers);
8159         }
8160 
8161         // E_GL_EXT_texture_array
8162         if (profile != EEsProfile && spvVersion.spv == 0) {
8163             symbolTable.setFunctionExtensions("texture1DArray", 1, &E_GL_EXT_texture_array);
8164             symbolTable.setFunctionExtensions("texture2DArray", 1, &E_GL_EXT_texture_array);
8165             symbolTable.setFunctionExtensions("shadow1DArray", 1, &E_GL_EXT_texture_array);
8166             symbolTable.setFunctionExtensions("shadow2DArray", 1, &E_GL_EXT_texture_array);
8167 
8168             symbolTable.setFunctionExtensions("texture1DArrayLod", 1, &E_GL_EXT_texture_array);
8169             symbolTable.setFunctionExtensions("texture2DArrayLod", 1, &E_GL_EXT_texture_array);
8170             symbolTable.setFunctionExtensions("shadow1DArrayLod", 1, &E_GL_EXT_texture_array);
8171         }
8172         [[fallthrough]];
8173 
8174     case EShLangTessControl:
8175         if (profile == EEsProfile && version >= 310) {
8176             BuiltInVariable("gl_BoundingBoxEXT", EbvBoundingBox, symbolTable);
8177             symbolTable.setVariableExtensions("gl_BoundingBoxEXT", 1,
8178                                               &E_GL_EXT_primitive_bounding_box);
8179             BuiltInVariable("gl_BoundingBoxOES", EbvBoundingBox, symbolTable);
8180             symbolTable.setVariableExtensions("gl_BoundingBoxOES", 1,
8181                                               &E_GL_OES_primitive_bounding_box);
8182 
8183             if (version >= 320) {
8184                 BuiltInVariable("gl_BoundingBox", EbvBoundingBox, symbolTable);
8185             }
8186         }
8187         [[fallthrough]];
8188 
8189     case EShLangTessEvaluation:
8190     case EShLangGeometry:
8191         SpecialQualifier("gl_Position",   EvqPosition,   EbvPosition,   symbolTable);
8192         SpecialQualifier("gl_PointSize",  EvqPointSize,  EbvPointSize,  symbolTable);
8193 
8194         BuiltInVariable("gl_in",  "gl_Position",     EbvPosition,     symbolTable);
8195         BuiltInVariable("gl_in",  "gl_PointSize",    EbvPointSize,    symbolTable);
8196 
8197         BuiltInVariable("gl_out", "gl_Position",     EbvPosition,     symbolTable);
8198         BuiltInVariable("gl_out", "gl_PointSize",    EbvPointSize,    symbolTable);
8199 
8200         SpecialQualifier("gl_ClipVertex", EvqClipVertex, EbvClipVertex, symbolTable);
8201 
8202         BuiltInVariable("gl_in",  "gl_ClipDistance", EbvClipDistance, symbolTable);
8203         BuiltInVariable("gl_in",  "gl_CullDistance", EbvCullDistance, symbolTable);
8204 
8205         BuiltInVariable("gl_out", "gl_ClipDistance", EbvClipDistance, symbolTable);
8206         BuiltInVariable("gl_out", "gl_CullDistance", EbvCullDistance, symbolTable);
8207 
8208         BuiltInVariable("gl_ClipDistance",    EbvClipDistance,   symbolTable);
8209         BuiltInVariable("gl_CullDistance",    EbvCullDistance,   symbolTable);
8210         BuiltInVariable("gl_PrimitiveIDIn",   EbvPrimitiveId,    symbolTable);
8211         BuiltInVariable("gl_PrimitiveID",     EbvPrimitiveId,    symbolTable);
8212         BuiltInVariable("gl_InvocationID",    EbvInvocationId,   symbolTable);
8213         BuiltInVariable("gl_Layer",           EbvLayer,          symbolTable);
8214         BuiltInVariable("gl_ViewportIndex",   EbvViewportIndex,  symbolTable);
8215 
8216         if (language != EShLangGeometry) {
8217             symbolTable.setVariableExtensions("gl_Layer",         Num_viewportEXTs, viewportEXTs);
8218             symbolTable.setVariableExtensions("gl_ViewportIndex", Num_viewportEXTs, viewportEXTs);
8219         }
8220         symbolTable.setVariableExtensions("gl_ViewportMask",            1, &E_GL_NV_viewport_array2);
8221         symbolTable.setVariableExtensions("gl_SecondaryPositionNV",     1, &E_GL_NV_stereo_view_rendering);
8222         symbolTable.setVariableExtensions("gl_SecondaryViewportMaskNV", 1, &E_GL_NV_stereo_view_rendering);
8223         symbolTable.setVariableExtensions("gl_PositionPerViewNV",       1, &E_GL_NVX_multiview_per_view_attributes);
8224         symbolTable.setVariableExtensions("gl_ViewportMaskPerViewNV",   1, &E_GL_NVX_multiview_per_view_attributes);
8225 
8226         BuiltInVariable("gl_ViewportMask",              EbvViewportMaskNV,          symbolTable);
8227         BuiltInVariable("gl_SecondaryPositionNV",       EbvSecondaryPositionNV,     symbolTable);
8228         BuiltInVariable("gl_SecondaryViewportMaskNV",   EbvSecondaryViewportMaskNV, symbolTable);
8229         BuiltInVariable("gl_PositionPerViewNV",         EbvPositionPerViewNV,       symbolTable);
8230         BuiltInVariable("gl_ViewportMaskPerViewNV",     EbvViewportMaskPerViewNV,   symbolTable);
8231 
8232         if (language == EShLangVertex || language == EShLangGeometry) {
8233             symbolTable.setVariableExtensions("gl_in", "gl_SecondaryPositionNV", 1, &E_GL_NV_stereo_view_rendering);
8234             symbolTable.setVariableExtensions("gl_in", "gl_PositionPerViewNV",   1, &E_GL_NVX_multiview_per_view_attributes);
8235 
8236             BuiltInVariable("gl_in", "gl_SecondaryPositionNV", EbvSecondaryPositionNV, symbolTable);
8237             BuiltInVariable("gl_in", "gl_PositionPerViewNV",   EbvPositionPerViewNV,   symbolTable);
8238         }
8239         symbolTable.setVariableExtensions("gl_out", "gl_ViewportMask",            1, &E_GL_NV_viewport_array2);
8240         symbolTable.setVariableExtensions("gl_out", "gl_SecondaryPositionNV",     1, &E_GL_NV_stereo_view_rendering);
8241         symbolTable.setVariableExtensions("gl_out", "gl_SecondaryViewportMaskNV", 1, &E_GL_NV_stereo_view_rendering);
8242         symbolTable.setVariableExtensions("gl_out", "gl_PositionPerViewNV",       1, &E_GL_NVX_multiview_per_view_attributes);
8243         symbolTable.setVariableExtensions("gl_out", "gl_ViewportMaskPerViewNV",   1, &E_GL_NVX_multiview_per_view_attributes);
8244 
8245         BuiltInVariable("gl_out", "gl_ViewportMask",            EbvViewportMaskNV,          symbolTable);
8246         BuiltInVariable("gl_out", "gl_SecondaryPositionNV",     EbvSecondaryPositionNV,     symbolTable);
8247         BuiltInVariable("gl_out", "gl_SecondaryViewportMaskNV", EbvSecondaryViewportMaskNV, symbolTable);
8248         BuiltInVariable("gl_out", "gl_PositionPerViewNV",       EbvPositionPerViewNV,       symbolTable);
8249         BuiltInVariable("gl_out", "gl_ViewportMaskPerViewNV",   EbvViewportMaskPerViewNV,   symbolTable);
8250 
8251         BuiltInVariable("gl_PatchVerticesIn", EbvPatchVertices,  symbolTable);
8252         BuiltInVariable("gl_TessLevelOuter",  EbvTessLevelOuter, symbolTable);
8253         BuiltInVariable("gl_TessLevelInner",  EbvTessLevelInner, symbolTable);
8254         BuiltInVariable("gl_TessCoord",       EbvTessCoord,      symbolTable);
8255 
8256         if (version < 410)
8257             symbolTable.setVariableExtensions("gl_ViewportIndex", 1, &E_GL_ARB_viewport_array);
8258 
8259         // Compatibility variables
8260 
8261         BuiltInVariable("gl_in", "gl_ClipVertex",          EbvClipVertex,          symbolTable);
8262         BuiltInVariable("gl_in", "gl_FrontColor",          EbvFrontColor,          symbolTable);
8263         BuiltInVariable("gl_in", "gl_BackColor",           EbvBackColor,           symbolTable);
8264         BuiltInVariable("gl_in", "gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
8265         BuiltInVariable("gl_in", "gl_BackSecondaryColor",  EbvBackSecondaryColor,  symbolTable);
8266         BuiltInVariable("gl_in", "gl_TexCoord",            EbvTexCoord,            symbolTable);
8267         BuiltInVariable("gl_in", "gl_FogFragCoord",        EbvFogFragCoord,        symbolTable);
8268 
8269         BuiltInVariable("gl_out", "gl_ClipVertex",          EbvClipVertex,          symbolTable);
8270         BuiltInVariable("gl_out", "gl_FrontColor",          EbvFrontColor,          symbolTable);
8271         BuiltInVariable("gl_out", "gl_BackColor",           EbvBackColor,           symbolTable);
8272         BuiltInVariable("gl_out", "gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
8273         BuiltInVariable("gl_out", "gl_BackSecondaryColor",  EbvBackSecondaryColor,  symbolTable);
8274         BuiltInVariable("gl_out", "gl_TexCoord",            EbvTexCoord,            symbolTable);
8275         BuiltInVariable("gl_out", "gl_FogFragCoord",        EbvFogFragCoord,        symbolTable);
8276 
8277         BuiltInVariable("gl_ClipVertex",          EbvClipVertex,          symbolTable);
8278         BuiltInVariable("gl_FrontColor",          EbvFrontColor,          symbolTable);
8279         BuiltInVariable("gl_BackColor",           EbvBackColor,           symbolTable);
8280         BuiltInVariable("gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
8281         BuiltInVariable("gl_BackSecondaryColor",  EbvBackSecondaryColor,  symbolTable);
8282         BuiltInVariable("gl_TexCoord",            EbvTexCoord,            symbolTable);
8283         BuiltInVariable("gl_FogFragCoord",        EbvFogFragCoord,        symbolTable);
8284 
8285         // gl_PointSize, when it needs to be tied to an extension, is always a member of a block.
8286         // (Sometimes with an instance name, sometimes anonymous).
8287         if (profile == EEsProfile) {
8288             if (language == EShLangGeometry) {
8289                 symbolTable.setVariableExtensions("gl_PointSize", Num_AEP_geometry_point_size, AEP_geometry_point_size);
8290                 symbolTable.setVariableExtensions("gl_in", "gl_PointSize", Num_AEP_geometry_point_size, AEP_geometry_point_size);
8291             } else if (language == EShLangTessEvaluation || language == EShLangTessControl) {
8292                 // gl_in tessellation settings of gl_PointSize are in the context-dependent paths
8293                 symbolTable.setVariableExtensions("gl_PointSize", Num_AEP_tessellation_point_size, AEP_tessellation_point_size);
8294                 symbolTable.setVariableExtensions("gl_out", "gl_PointSize", Num_AEP_tessellation_point_size, AEP_tessellation_point_size);
8295             }
8296         }
8297 
8298         if ((profile != EEsProfile && version >= 140) ||
8299             (profile == EEsProfile && version >= 310)) {
8300             symbolTable.setVariableExtensions("gl_DeviceIndex",  1, &E_GL_EXT_device_group);
8301             BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
8302             symbolTable.setVariableExtensions("gl_ViewIndex", 1, &E_GL_EXT_multiview);
8303             BuiltInVariable("gl_ViewIndex", EbvViewIndex, symbolTable);
8304         }
8305 
8306         if (profile != EEsProfile) {
8307             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
8308             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
8309             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
8310             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
8311             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
8312             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
8313 
8314             if (spvVersion.vulkan > 0) {
8315                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
8316                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
8317                 if (language == EShLangFragment)
8318                     ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
8319             }
8320             else
8321                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
8322         }
8323 
8324         // GL_KHR_shader_subgroup
8325         if ((profile == EEsProfile && version >= 310) ||
8326             (profile != EEsProfile && version >= 140)) {
8327             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
8328             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
8329             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8330             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8331             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8332             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8333             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8334 
8335             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
8336             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
8337             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
8338             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
8339             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
8340             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
8341             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
8342 
8343             // GL_NV_shader_sm_builtins
8344             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
8345             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
8346             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
8347             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
8348             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
8349             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
8350             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
8351             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
8352 
8353             // GL_ARM_shader_core_builtins
8354             symbolTable.setVariableExtensions("gl_CoreCountARM", 1, &E_GL_ARM_shader_core_builtins);
8355             symbolTable.setVariableExtensions("gl_CoreIDARM",    1, &E_GL_ARM_shader_core_builtins);
8356             symbolTable.setVariableExtensions("gl_CoreMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
8357             symbolTable.setVariableExtensions("gl_WarpIDARM",    1, &E_GL_ARM_shader_core_builtins);
8358             symbolTable.setVariableExtensions("gl_WarpMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
8359 
8360             BuiltInVariable("gl_CoreCountARM", EbvCoreCountARM, symbolTable);
8361             BuiltInVariable("gl_CoreIDARM",    EbvCoreIDARM, symbolTable);
8362             BuiltInVariable("gl_CoreMaxIDARM", EbvCoreMaxIDARM, symbolTable);
8363             BuiltInVariable("gl_WarpIDARM",    EbvWarpIDARM, symbolTable);
8364             BuiltInVariable("gl_WarpMaxIDARM", EbvWarpMaxIDARM, symbolTable);
8365         }
8366 
8367 		if (language == EShLangGeometry || language == EShLangVertex) {
8368 			if ((profile == EEsProfile && version >= 310) ||
8369 				(profile != EEsProfile && version >= 450)) {
8370 				symbolTable.setVariableExtensions("gl_PrimitiveShadingRateEXT", 1, &E_GL_EXT_fragment_shading_rate);
8371 				BuiltInVariable("gl_PrimitiveShadingRateEXT", EbvPrimitiveShadingRateKHR, symbolTable);
8372 
8373 				symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8374 				symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8375 				symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8376 				symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8377 			}
8378 		}
8379         break;
8380 
8381     case EShLangFragment:
8382         SpecialQualifier("gl_FrontFacing",      EvqFace,       EbvFace,             symbolTable);
8383         SpecialQualifier("gl_FragCoord",        EvqFragCoord,  EbvFragCoord,        symbolTable);
8384         SpecialQualifier("gl_PointCoord",       EvqPointCoord, EbvPointCoord,       symbolTable);
8385         if (spvVersion.spv == 0)
8386             SpecialQualifier("gl_FragColor",    EvqFragColor,  EbvFragColor,        symbolTable);
8387         else {
8388             TSymbol* symbol = symbolTable.find("gl_FragColor");
8389             if (symbol) {
8390                 symbol->getWritableType().getQualifier().storage = EvqVaryingOut;
8391                 symbol->getWritableType().getQualifier().layoutLocation = 0;
8392             }
8393         }
8394         SpecialQualifier("gl_FragDepth",        EvqFragDepth,  EbvFragDepth,        symbolTable);
8395         SpecialQualifier("gl_FragDepthEXT",     EvqFragDepth,  EbvFragDepth,        symbolTable);
8396         SpecialQualifier("gl_FragStencilRefARB", EvqFragStencil, EbvFragStencilRef, symbolTable);
8397         SpecialQualifier("gl_HelperInvocation", EvqVaryingIn,  EbvHelperInvocation, symbolTable);
8398 
8399         BuiltInVariable("gl_ClipDistance",    EbvClipDistance,   symbolTable);
8400         BuiltInVariable("gl_CullDistance",    EbvCullDistance,   symbolTable);
8401         BuiltInVariable("gl_PrimitiveID",     EbvPrimitiveId,    symbolTable);
8402 
8403         if (profile != EEsProfile && version >= 140) {
8404             symbolTable.setVariableExtensions("gl_FragStencilRefARB", 1, &E_GL_ARB_shader_stencil_export);
8405             BuiltInVariable("gl_FragStencilRefARB", EbvFragStencilRef, symbolTable);
8406         }
8407 
8408         if (profile != EEsProfile && version < 400) {
8409             symbolTable.setFunctionExtensions("textureQueryLOD", 1, &E_GL_ARB_texture_query_lod);
8410         }
8411 
8412         if (profile != EEsProfile && version >= 460) {
8413             symbolTable.setFunctionExtensions("rayQueryInitializeEXT",                                            1, &E_GL_EXT_ray_query);
8414             symbolTable.setFunctionExtensions("rayQueryTerminateEXT",                                             1, &E_GL_EXT_ray_query);
8415             symbolTable.setFunctionExtensions("rayQueryGenerateIntersectionEXT",                                  1, &E_GL_EXT_ray_query);
8416             symbolTable.setFunctionExtensions("rayQueryConfirmIntersectionEXT",                                   1, &E_GL_EXT_ray_query);
8417             symbolTable.setFunctionExtensions("rayQueryProceedEXT",                                               1, &E_GL_EXT_ray_query);
8418             symbolTable.setFunctionExtensions("rayQueryGetIntersectionTypeEXT",                                   1, &E_GL_EXT_ray_query);
8419             symbolTable.setFunctionExtensions("rayQueryGetIntersectionTEXT",                                      1, &E_GL_EXT_ray_query);
8420             symbolTable.setFunctionExtensions("rayQueryGetRayFlagsEXT",                                           1, &E_GL_EXT_ray_query);
8421             symbolTable.setFunctionExtensions("rayQueryGetRayTMinEXT",                                            1, &E_GL_EXT_ray_query);
8422             symbolTable.setFunctionExtensions("rayQueryGetIntersectionInstanceCustomIndexEXT",                    1, &E_GL_EXT_ray_query);
8423             symbolTable.setFunctionExtensions("rayQueryGetIntersectionInstanceIdEXT",                             1, &E_GL_EXT_ray_query);
8424             symbolTable.setFunctionExtensions("rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT", 1, &E_GL_EXT_ray_query);
8425             symbolTable.setFunctionExtensions("rayQueryGetIntersectionGeometryIndexEXT",                          1, &E_GL_EXT_ray_query);
8426             symbolTable.setFunctionExtensions("rayQueryGetIntersectionPrimitiveIndexEXT",                         1, &E_GL_EXT_ray_query);
8427             symbolTable.setFunctionExtensions("rayQueryGetIntersectionBarycentricsEXT",                           1, &E_GL_EXT_ray_query);
8428             symbolTable.setFunctionExtensions("rayQueryGetIntersectionFrontFaceEXT",                              1, &E_GL_EXT_ray_query);
8429             symbolTable.setFunctionExtensions("rayQueryGetIntersectionCandidateAABBOpaqueEXT",                    1, &E_GL_EXT_ray_query);
8430             symbolTable.setFunctionExtensions("rayQueryGetIntersectionObjectRayDirectionEXT",                     1, &E_GL_EXT_ray_query);
8431             symbolTable.setFunctionExtensions("rayQueryGetIntersectionObjectRayOriginEXT",                        1, &E_GL_EXT_ray_query);
8432             symbolTable.setFunctionExtensions("rayQueryGetIntersectionObjectToWorldEXT",                          1, &E_GL_EXT_ray_query);
8433             symbolTable.setFunctionExtensions("rayQueryGetIntersectionWorldToObjectEXT",                          1, &E_GL_EXT_ray_query);
8434             symbolTable.setFunctionExtensions("rayQueryGetWorldRayOriginEXT",                                     1, &E_GL_EXT_ray_query);
8435             symbolTable.setFunctionExtensions("rayQueryGetWorldRayDirectionEXT",                                  1, &E_GL_EXT_ray_query);
8436             symbolTable.setFunctionExtensions("rayQueryGetIntersectionTriangleVertexPositionsEXT",                1, &E_GL_EXT_ray_tracing_position_fetch);
8437             symbolTable.setVariableExtensions("gl_RayFlagsSkipAABBEXT",                         1, &E_GL_EXT_ray_flags_primitive_culling);
8438             symbolTable.setVariableExtensions("gl_RayFlagsSkipTrianglesEXT",                    1, &E_GL_EXT_ray_flags_primitive_culling);
8439             symbolTable.setVariableExtensions("gl_RayFlagsForceOpacityMicromap2StateEXT",                  1, &E_GL_EXT_opacity_micromap);
8440         }
8441 
8442         if ((profile != EEsProfile && version >= 130) ||
8443             (profile == EEsProfile && version >= 310)) {
8444             BuiltInVariable("gl_SampleID",           EbvSampleId,       symbolTable);
8445             BuiltInVariable("gl_SamplePosition",     EbvSamplePosition, symbolTable);
8446             BuiltInVariable("gl_SampleMask",         EbvSampleMask,     symbolTable);
8447 
8448             if (profile != EEsProfile && version < 400) {
8449                 BuiltInVariable("gl_NumSamples",     EbvSampleMask,     symbolTable);
8450 
8451                 symbolTable.setVariableExtensions("gl_SampleMask",     1, &E_GL_ARB_sample_shading);
8452                 symbolTable.setVariableExtensions("gl_SampleID",       1, &E_GL_ARB_sample_shading);
8453                 symbolTable.setVariableExtensions("gl_SamplePosition", 1, &E_GL_ARB_sample_shading);
8454                 symbolTable.setVariableExtensions("gl_NumSamples",     1, &E_GL_ARB_sample_shading);
8455             } else {
8456                 BuiltInVariable("gl_SampleMaskIn",    EbvSampleMask,     symbolTable);
8457 
8458                 if (profile == EEsProfile && version < 320) {
8459                     symbolTable.setVariableExtensions("gl_SampleID", 1, &E_GL_OES_sample_variables);
8460                     symbolTable.setVariableExtensions("gl_SamplePosition", 1, &E_GL_OES_sample_variables);
8461                     symbolTable.setVariableExtensions("gl_SampleMaskIn", 1, &E_GL_OES_sample_variables);
8462                     symbolTable.setVariableExtensions("gl_SampleMask", 1, &E_GL_OES_sample_variables);
8463                     symbolTable.setVariableExtensions("gl_NumSamples", 1, &E_GL_OES_sample_variables);
8464                 }
8465             }
8466         }
8467 
8468         BuiltInVariable("gl_Layer",           EbvLayer,          symbolTable);
8469         BuiltInVariable("gl_ViewportIndex",   EbvViewportIndex,  symbolTable);
8470 
8471         // Compatibility variables
8472 
8473         BuiltInVariable("gl_in", "gl_FogFragCoord",   EbvFogFragCoord,   symbolTable);
8474         BuiltInVariable("gl_in", "gl_TexCoord",       EbvTexCoord,       symbolTable);
8475         BuiltInVariable("gl_in", "gl_Color",          EbvColor,          symbolTable);
8476         BuiltInVariable("gl_in", "gl_SecondaryColor", EbvSecondaryColor, symbolTable);
8477 
8478         BuiltInVariable("gl_FogFragCoord",   EbvFogFragCoord,   symbolTable);
8479         BuiltInVariable("gl_TexCoord",       EbvTexCoord,       symbolTable);
8480         BuiltInVariable("gl_Color",          EbvColor,          symbolTable);
8481         BuiltInVariable("gl_SecondaryColor", EbvSecondaryColor, symbolTable);
8482 
8483         // built-in functions
8484 
8485         if (profile == EEsProfile) {
8486             if (spvVersion.spv == 0) {
8487                 symbolTable.setFunctionExtensions("texture2DLodEXT",      1, &E_GL_EXT_shader_texture_lod);
8488                 symbolTable.setFunctionExtensions("texture2DProjLodEXT",  1, &E_GL_EXT_shader_texture_lod);
8489                 symbolTable.setFunctionExtensions("textureCubeLodEXT",    1, &E_GL_EXT_shader_texture_lod);
8490                 symbolTable.setFunctionExtensions("texture2DGradEXT",     1, &E_GL_EXT_shader_texture_lod);
8491                 symbolTable.setFunctionExtensions("texture2DProjGradEXT", 1, &E_GL_EXT_shader_texture_lod);
8492                 symbolTable.setFunctionExtensions("textureCubeGradEXT",   1, &E_GL_EXT_shader_texture_lod);
8493                 if (version < 320)
8494                     symbolTable.setFunctionExtensions("textureGatherOffsets", Num_AEP_gpu_shader5, AEP_gpu_shader5);
8495             }
8496             if (version == 100) {
8497                 symbolTable.setFunctionExtensions("dFdx",   1, &E_GL_OES_standard_derivatives);
8498                 symbolTable.setFunctionExtensions("dFdy",   1, &E_GL_OES_standard_derivatives);
8499                 symbolTable.setFunctionExtensions("fwidth", 1, &E_GL_OES_standard_derivatives);
8500             }
8501             if (version == 310) {
8502                 symbolTable.setFunctionExtensions("fma", Num_AEP_gpu_shader5, AEP_gpu_shader5);
8503                 symbolTable.setFunctionExtensions("interpolateAtCentroid", 1, &E_GL_OES_shader_multisample_interpolation);
8504                 symbolTable.setFunctionExtensions("interpolateAtSample",   1, &E_GL_OES_shader_multisample_interpolation);
8505                 symbolTable.setFunctionExtensions("interpolateAtOffset",   1, &E_GL_OES_shader_multisample_interpolation);
8506             }
8507         } else if (version < 130) {
8508             if (spvVersion.spv == 0) {
8509                 symbolTable.setFunctionExtensions("texture1DLod",        1, &E_GL_ARB_shader_texture_lod);
8510                 symbolTable.setFunctionExtensions("texture2DLod",        1, &E_GL_ARB_shader_texture_lod);
8511                 symbolTable.setFunctionExtensions("texture3DLod",        1, &E_GL_ARB_shader_texture_lod);
8512                 symbolTable.setFunctionExtensions("textureCubeLod",      1, &E_GL_ARB_shader_texture_lod);
8513                 symbolTable.setFunctionExtensions("texture1DProjLod",    1, &E_GL_ARB_shader_texture_lod);
8514                 symbolTable.setFunctionExtensions("texture2DProjLod",    1, &E_GL_ARB_shader_texture_lod);
8515                 symbolTable.setFunctionExtensions("texture3DProjLod",    1, &E_GL_ARB_shader_texture_lod);
8516                 symbolTable.setFunctionExtensions("shadow1DLod",         1, &E_GL_ARB_shader_texture_lod);
8517                 symbolTable.setFunctionExtensions("shadow2DLod",         1, &E_GL_ARB_shader_texture_lod);
8518                 symbolTable.setFunctionExtensions("shadow1DProjLod",     1, &E_GL_ARB_shader_texture_lod);
8519                 symbolTable.setFunctionExtensions("shadow2DProjLod",     1, &E_GL_ARB_shader_texture_lod);
8520             }
8521         }
8522 
8523         // E_GL_ARB_shader_texture_lod functions usable only with the extension enabled
8524         if (profile != EEsProfile && spvVersion.spv == 0) {
8525             symbolTable.setFunctionExtensions("texture1DGradARB",         1, &E_GL_ARB_shader_texture_lod);
8526             symbolTable.setFunctionExtensions("texture1DProjGradARB",     1, &E_GL_ARB_shader_texture_lod);
8527             symbolTable.setFunctionExtensions("texture2DGradARB",         1, &E_GL_ARB_shader_texture_lod);
8528             symbolTable.setFunctionExtensions("texture2DProjGradARB",     1, &E_GL_ARB_shader_texture_lod);
8529             symbolTable.setFunctionExtensions("texture3DGradARB",         1, &E_GL_ARB_shader_texture_lod);
8530             symbolTable.setFunctionExtensions("texture3DProjGradARB",     1, &E_GL_ARB_shader_texture_lod);
8531             symbolTable.setFunctionExtensions("textureCubeGradARB",       1, &E_GL_ARB_shader_texture_lod);
8532             symbolTable.setFunctionExtensions("shadow1DGradARB",          1, &E_GL_ARB_shader_texture_lod);
8533             symbolTable.setFunctionExtensions("shadow1DProjGradARB",      1, &E_GL_ARB_shader_texture_lod);
8534             symbolTable.setFunctionExtensions("shadow2DGradARB",          1, &E_GL_ARB_shader_texture_lod);
8535             symbolTable.setFunctionExtensions("shadow2DProjGradARB",      1, &E_GL_ARB_shader_texture_lod);
8536             symbolTable.setFunctionExtensions("texture2DRectGradARB",     1, &E_GL_ARB_shader_texture_lod);
8537             symbolTable.setFunctionExtensions("texture2DRectProjGradARB", 1, &E_GL_ARB_shader_texture_lod);
8538             symbolTable.setFunctionExtensions("shadow2DRectGradARB",      1, &E_GL_ARB_shader_texture_lod);
8539             symbolTable.setFunctionExtensions("shadow2DRectProjGradARB",  1, &E_GL_ARB_shader_texture_lod);
8540         }
8541 
8542         // E_GL_ARB_shader_image_load_store
8543         if (profile != EEsProfile && version < 420)
8544             symbolTable.setFunctionExtensions("memoryBarrier", 1, &E_GL_ARB_shader_image_load_store);
8545         // All the image access functions are protected by checks on the type of the first argument.
8546 
8547         // E_GL_ARB_shader_atomic_counters
8548         if (profile != EEsProfile && version < 420) {
8549             symbolTable.setFunctionExtensions("atomicCounterIncrement", 1, &E_GL_ARB_shader_atomic_counters);
8550             symbolTable.setFunctionExtensions("atomicCounterDecrement", 1, &E_GL_ARB_shader_atomic_counters);
8551             symbolTable.setFunctionExtensions("atomicCounter"         , 1, &E_GL_ARB_shader_atomic_counters);
8552         }
8553 
8554         // E_GL_ARB_shader_atomic_counter_ops
8555         if (profile != EEsProfile && version == 450) {
8556             symbolTable.setFunctionExtensions("atomicCounterAddARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8557             symbolTable.setFunctionExtensions("atomicCounterSubtractARB", 1, &E_GL_ARB_shader_atomic_counter_ops);
8558             symbolTable.setFunctionExtensions("atomicCounterMinARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8559             symbolTable.setFunctionExtensions("atomicCounterMaxARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8560             symbolTable.setFunctionExtensions("atomicCounterAndARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8561             symbolTable.setFunctionExtensions("atomicCounterOrARB"      , 1, &E_GL_ARB_shader_atomic_counter_ops);
8562             symbolTable.setFunctionExtensions("atomicCounterXorARB"     , 1, &E_GL_ARB_shader_atomic_counter_ops);
8563             symbolTable.setFunctionExtensions("atomicCounterExchangeARB", 1, &E_GL_ARB_shader_atomic_counter_ops);
8564             symbolTable.setFunctionExtensions("atomicCounterCompSwapARB", 1, &E_GL_ARB_shader_atomic_counter_ops);
8565         }
8566 
8567         // E_GL_ARB_derivative_control
8568         if (profile != EEsProfile && version < 450) {
8569             symbolTable.setFunctionExtensions("dFdxFine",     1, &E_GL_ARB_derivative_control);
8570             symbolTable.setFunctionExtensions("dFdyFine",     1, &E_GL_ARB_derivative_control);
8571             symbolTable.setFunctionExtensions("fwidthFine",   1, &E_GL_ARB_derivative_control);
8572             symbolTable.setFunctionExtensions("dFdxCoarse",   1, &E_GL_ARB_derivative_control);
8573             symbolTable.setFunctionExtensions("dFdyCoarse",   1, &E_GL_ARB_derivative_control);
8574             symbolTable.setFunctionExtensions("fwidthCoarse", 1, &E_GL_ARB_derivative_control);
8575         }
8576 
8577         // E_GL_ARB_sparse_texture2
8578         if (profile != EEsProfile)
8579         {
8580             symbolTable.setFunctionExtensions("sparseTextureARB",              1, &E_GL_ARB_sparse_texture2);
8581             symbolTable.setFunctionExtensions("sparseTextureLodARB",           1, &E_GL_ARB_sparse_texture2);
8582             symbolTable.setFunctionExtensions("sparseTextureOffsetARB",        1, &E_GL_ARB_sparse_texture2);
8583             symbolTable.setFunctionExtensions("sparseTexelFetchARB",           1, &E_GL_ARB_sparse_texture2);
8584             symbolTable.setFunctionExtensions("sparseTexelFetchOffsetARB",     1, &E_GL_ARB_sparse_texture2);
8585             symbolTable.setFunctionExtensions("sparseTextureLodOffsetARB",     1, &E_GL_ARB_sparse_texture2);
8586             symbolTable.setFunctionExtensions("sparseTextureGradARB",          1, &E_GL_ARB_sparse_texture2);
8587             symbolTable.setFunctionExtensions("sparseTextureGradOffsetARB",    1, &E_GL_ARB_sparse_texture2);
8588             symbolTable.setFunctionExtensions("sparseTextureGatherARB",        1, &E_GL_ARB_sparse_texture2);
8589             symbolTable.setFunctionExtensions("sparseTextureGatherOffsetARB",  1, &E_GL_ARB_sparse_texture2);
8590             symbolTable.setFunctionExtensions("sparseTextureGatherOffsetsARB", 1, &E_GL_ARB_sparse_texture2);
8591             symbolTable.setFunctionExtensions("sparseImageLoadARB",            1, &E_GL_ARB_sparse_texture2);
8592             symbolTable.setFunctionExtensions("sparseTexelsResident",          1, &E_GL_ARB_sparse_texture2);
8593         }
8594 
8595         // E_GL_ARB_sparse_texture_clamp
8596         if (profile != EEsProfile)
8597         {
8598             symbolTable.setFunctionExtensions("sparseTextureClampARB",              1, &E_GL_ARB_sparse_texture_clamp);
8599             symbolTable.setFunctionExtensions("sparseTextureOffsetClampARB",        1, &E_GL_ARB_sparse_texture_clamp);
8600             symbolTable.setFunctionExtensions("sparseTextureGradClampARB",          1, &E_GL_ARB_sparse_texture_clamp);
8601             symbolTable.setFunctionExtensions("sparseTextureGradOffsetClampARB",    1, &E_GL_ARB_sparse_texture_clamp);
8602             symbolTable.setFunctionExtensions("textureClampARB",                    1, &E_GL_ARB_sparse_texture_clamp);
8603             symbolTable.setFunctionExtensions("textureOffsetClampARB",              1, &E_GL_ARB_sparse_texture_clamp);
8604             symbolTable.setFunctionExtensions("textureGradClampARB",                1, &E_GL_ARB_sparse_texture_clamp);
8605             symbolTable.setFunctionExtensions("textureGradOffsetClampARB",          1, &E_GL_ARB_sparse_texture_clamp);
8606         }
8607 
8608         // E_GL_AMD_shader_explicit_vertex_parameter
8609         if (profile != EEsProfile) {
8610             symbolTable.setVariableExtensions("gl_BaryCoordNoPerspAMD",         1, &E_GL_AMD_shader_explicit_vertex_parameter);
8611             symbolTable.setVariableExtensions("gl_BaryCoordNoPerspCentroidAMD", 1, &E_GL_AMD_shader_explicit_vertex_parameter);
8612             symbolTable.setVariableExtensions("gl_BaryCoordNoPerspSampleAMD",   1, &E_GL_AMD_shader_explicit_vertex_parameter);
8613             symbolTable.setVariableExtensions("gl_BaryCoordSmoothAMD",          1, &E_GL_AMD_shader_explicit_vertex_parameter);
8614             symbolTable.setVariableExtensions("gl_BaryCoordSmoothCentroidAMD",  1, &E_GL_AMD_shader_explicit_vertex_parameter);
8615             symbolTable.setVariableExtensions("gl_BaryCoordSmoothSampleAMD",    1, &E_GL_AMD_shader_explicit_vertex_parameter);
8616             symbolTable.setVariableExtensions("gl_BaryCoordPullModelAMD",       1, &E_GL_AMD_shader_explicit_vertex_parameter);
8617 
8618             symbolTable.setFunctionExtensions("interpolateAtVertexAMD",         1, &E_GL_AMD_shader_explicit_vertex_parameter);
8619 
8620             BuiltInVariable("gl_BaryCoordNoPerspAMD",           EbvBaryCoordNoPersp,         symbolTable);
8621             BuiltInVariable("gl_BaryCoordNoPerspCentroidAMD",   EbvBaryCoordNoPerspCentroid, symbolTable);
8622             BuiltInVariable("gl_BaryCoordNoPerspSampleAMD",     EbvBaryCoordNoPerspSample,   symbolTable);
8623             BuiltInVariable("gl_BaryCoordSmoothAMD",            EbvBaryCoordSmooth,          symbolTable);
8624             BuiltInVariable("gl_BaryCoordSmoothCentroidAMD",    EbvBaryCoordSmoothCentroid,  symbolTable);
8625             BuiltInVariable("gl_BaryCoordSmoothSampleAMD",      EbvBaryCoordSmoothSample,    symbolTable);
8626             BuiltInVariable("gl_BaryCoordPullModelAMD",         EbvBaryCoordPullModel,       symbolTable);
8627         }
8628 
8629         // E_GL_AMD_texture_gather_bias_lod
8630         if (profile != EEsProfile) {
8631             symbolTable.setFunctionExtensions("textureGatherLodAMD",                1, &E_GL_AMD_texture_gather_bias_lod);
8632             symbolTable.setFunctionExtensions("textureGatherLodOffsetAMD",          1, &E_GL_AMD_texture_gather_bias_lod);
8633             symbolTable.setFunctionExtensions("textureGatherLodOffsetsAMD",         1, &E_GL_AMD_texture_gather_bias_lod);
8634             symbolTable.setFunctionExtensions("sparseTextureGatherLodAMD",          1, &E_GL_AMD_texture_gather_bias_lod);
8635             symbolTable.setFunctionExtensions("sparseTextureGatherLodOffsetAMD",    1, &E_GL_AMD_texture_gather_bias_lod);
8636             symbolTable.setFunctionExtensions("sparseTextureGatherLodOffsetsAMD",   1, &E_GL_AMD_texture_gather_bias_lod);
8637         }
8638 
8639         // E_GL_AMD_shader_image_load_store_lod
8640         if (profile != EEsProfile) {
8641             symbolTable.setFunctionExtensions("imageLoadLodAMD",        1, &E_GL_AMD_shader_image_load_store_lod);
8642             symbolTable.setFunctionExtensions("imageStoreLodAMD",       1, &E_GL_AMD_shader_image_load_store_lod);
8643             symbolTable.setFunctionExtensions("sparseImageLoadLodAMD",  1, &E_GL_AMD_shader_image_load_store_lod);
8644         }
8645         if (profile != EEsProfile && version >= 430) {
8646             symbolTable.setVariableExtensions("gl_FragFullyCoveredNV", 1, &E_GL_NV_conservative_raster_underestimation);
8647             BuiltInVariable("gl_FragFullyCoveredNV", EbvFragFullyCoveredNV, symbolTable);
8648         }
8649         if ((profile != EEsProfile && version >= 450) ||
8650             (profile == EEsProfile && version >= 320)) {
8651             symbolTable.setVariableExtensions("gl_FragmentSizeNV",        1, &E_GL_NV_shading_rate_image);
8652             symbolTable.setVariableExtensions("gl_InvocationsPerPixelNV", 1, &E_GL_NV_shading_rate_image);
8653             BuiltInVariable("gl_FragmentSizeNV",        EbvFragmentSizeNV, symbolTable);
8654             BuiltInVariable("gl_InvocationsPerPixelNV", EbvInvocationsPerPixelNV, symbolTable);
8655             symbolTable.setVariableExtensions("gl_BaryCoordNV",        1, &E_GL_NV_fragment_shader_barycentric);
8656             symbolTable.setVariableExtensions("gl_BaryCoordNoPerspNV", 1, &E_GL_NV_fragment_shader_barycentric);
8657             BuiltInVariable("gl_BaryCoordNV",        EbvBaryCoordNV,        symbolTable);
8658             BuiltInVariable("gl_BaryCoordNoPerspNV", EbvBaryCoordNoPerspNV, symbolTable);
8659             symbolTable.setVariableExtensions("gl_BaryCoordEXT",        1, &E_GL_EXT_fragment_shader_barycentric);
8660             symbolTable.setVariableExtensions("gl_BaryCoordNoPerspEXT", 1, &E_GL_EXT_fragment_shader_barycentric);
8661             BuiltInVariable("gl_BaryCoordEXT",        EbvBaryCoordEXT,        symbolTable);
8662             BuiltInVariable("gl_BaryCoordNoPerspEXT", EbvBaryCoordNoPerspEXT, symbolTable);
8663         }
8664 
8665         if ((profile != EEsProfile && version >= 450) ||
8666             (profile == EEsProfile && version >= 310)) {
8667             symbolTable.setVariableExtensions("gl_FragSizeEXT",            1, &E_GL_EXT_fragment_invocation_density);
8668             symbolTable.setVariableExtensions("gl_FragInvocationCountEXT", 1, &E_GL_EXT_fragment_invocation_density);
8669             BuiltInVariable("gl_FragSizeEXT",            EbvFragSizeEXT, symbolTable);
8670             BuiltInVariable("gl_FragInvocationCountEXT", EbvFragInvocationCountEXT, symbolTable);
8671         }
8672 
8673         symbolTable.setVariableExtensions("gl_FragDepthEXT", 1, &E_GL_EXT_frag_depth);
8674 
8675         symbolTable.setFunctionExtensions("clockARB",     1, &E_GL_ARB_shader_clock);
8676         symbolTable.setFunctionExtensions("clock2x32ARB", 1, &E_GL_ARB_shader_clock);
8677 
8678         symbolTable.setFunctionExtensions("clockRealtimeEXT", 1, &E_GL_EXT_shader_realtime_clock);
8679         symbolTable.setFunctionExtensions("clockRealtime2x32EXT", 1, &E_GL_EXT_shader_realtime_clock);
8680 
8681         if (profile == EEsProfile && version < 320) {
8682             symbolTable.setVariableExtensions("gl_PrimitiveID",  Num_AEP_geometry_shader, AEP_geometry_shader);
8683             symbolTable.setVariableExtensions("gl_Layer",        Num_AEP_geometry_shader, AEP_geometry_shader);
8684         }
8685 
8686         if (profile == EEsProfile && version < 320) {
8687             symbolTable.setFunctionExtensions("imageAtomicAdd",      1, &E_GL_OES_shader_image_atomic);
8688             symbolTable.setFunctionExtensions("imageAtomicMin",      1, &E_GL_OES_shader_image_atomic);
8689             symbolTable.setFunctionExtensions("imageAtomicMax",      1, &E_GL_OES_shader_image_atomic);
8690             symbolTable.setFunctionExtensions("imageAtomicAnd",      1, &E_GL_OES_shader_image_atomic);
8691             symbolTable.setFunctionExtensions("imageAtomicOr",       1, &E_GL_OES_shader_image_atomic);
8692             symbolTable.setFunctionExtensions("imageAtomicXor",      1, &E_GL_OES_shader_image_atomic);
8693             symbolTable.setFunctionExtensions("imageAtomicExchange", 1, &E_GL_OES_shader_image_atomic);
8694             symbolTable.setFunctionExtensions("imageAtomicCompSwap", 1, &E_GL_OES_shader_image_atomic);
8695         }
8696 
8697         if (profile != EEsProfile && version < 330 ) {
8698             const char* bitsConvertExt[2] = {E_GL_ARB_shader_bit_encoding, E_GL_ARB_gpu_shader5};
8699             symbolTable.setFunctionExtensions("floatBitsToInt", 2, bitsConvertExt);
8700             symbolTable.setFunctionExtensions("floatBitsToUint", 2, bitsConvertExt);
8701             symbolTable.setFunctionExtensions("intBitsToFloat", 2, bitsConvertExt);
8702             symbolTable.setFunctionExtensions("uintBitsToFloat", 2, bitsConvertExt);
8703         }
8704 
8705         if (profile != EEsProfile && version < 430 ) {
8706             symbolTable.setFunctionExtensions("imageSize", 1, &E_GL_ARB_shader_image_size);
8707         }
8708 
8709         // GL_ARB_shader_storage_buffer_object
8710         if (profile != EEsProfile && version < 430 ) {
8711             symbolTable.setFunctionExtensions("atomicAdd", 1, &E_GL_ARB_shader_storage_buffer_object);
8712             symbolTable.setFunctionExtensions("atomicMin", 1, &E_GL_ARB_shader_storage_buffer_object);
8713             symbolTable.setFunctionExtensions("atomicMax", 1, &E_GL_ARB_shader_storage_buffer_object);
8714             symbolTable.setFunctionExtensions("atomicAnd", 1, &E_GL_ARB_shader_storage_buffer_object);
8715             symbolTable.setFunctionExtensions("atomicOr", 1, &E_GL_ARB_shader_storage_buffer_object);
8716             symbolTable.setFunctionExtensions("atomicXor", 1, &E_GL_ARB_shader_storage_buffer_object);
8717             symbolTable.setFunctionExtensions("atomicExchange", 1, &E_GL_ARB_shader_storage_buffer_object);
8718             symbolTable.setFunctionExtensions("atomicCompSwap", 1, &E_GL_ARB_shader_storage_buffer_object);
8719         }
8720 
8721         // GL_ARB_shading_language_packing
8722         if (profile != EEsProfile && version < 400 ) {
8723             symbolTable.setFunctionExtensions("packUnorm2x16", 1, &E_GL_ARB_shading_language_packing);
8724             symbolTable.setFunctionExtensions("unpackUnorm2x16", 1, &E_GL_ARB_shading_language_packing);
8725             symbolTable.setFunctionExtensions("packSnorm4x8", 1, &E_GL_ARB_shading_language_packing);
8726             symbolTable.setFunctionExtensions("packUnorm4x8", 1, &E_GL_ARB_shading_language_packing);
8727             symbolTable.setFunctionExtensions("unpackSnorm4x8", 1, &E_GL_ARB_shading_language_packing);
8728             symbolTable.setFunctionExtensions("unpackUnorm4x8", 1, &E_GL_ARB_shading_language_packing);
8729         }
8730         if (profile != EEsProfile && version < 420 ) {
8731             symbolTable.setFunctionExtensions("packSnorm2x16", 1, &E_GL_ARB_shading_language_packing);
8732             symbolTable.setFunctionExtensions("unpackSnorm2x16", 1, &E_GL_ARB_shading_language_packing);
8733             symbolTable.setFunctionExtensions("unpackHalf2x16", 1, &E_GL_ARB_shading_language_packing);
8734             symbolTable.setFunctionExtensions("packHalf2x16", 1, &E_GL_ARB_shading_language_packing);
8735         }
8736 
8737         symbolTable.setVariableExtensions("gl_DeviceIndex",  1, &E_GL_EXT_device_group);
8738         BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
8739         symbolTable.setVariableExtensions("gl_ViewIndex", 1, &E_GL_EXT_multiview);
8740         BuiltInVariable("gl_ViewIndex", EbvViewIndex, symbolTable);
8741         if (version >= 300 /* both ES and non-ES */) {
8742             symbolTable.setVariableExtensions("gl_ViewID_OVR", Num_OVR_multiview_EXTs, OVR_multiview_EXTs);
8743             BuiltInVariable("gl_ViewID_OVR", EbvViewIndex, symbolTable);
8744         }
8745 
8746         // GL_ARB_shader_ballot
8747         if (profile != EEsProfile) {
8748             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
8749             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
8750             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
8751             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
8752             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
8753             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
8754             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
8755 
8756             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
8757             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
8758             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
8759             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
8760             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
8761             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
8762 
8763             if (spvVersion.vulkan > 0) {
8764                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
8765                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
8766                 if (language == EShLangFragment)
8767                     ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
8768             }
8769             else
8770                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
8771         }
8772 
8773         // GL_EXT_expect_assume
8774         if ((profile == EEsProfile && version >= 310) ||
8775             (profile != EEsProfile && version >= 140)) {
8776             symbolTable.setFunctionExtensions("assumeEXT", 1, &E_GL_EXT_expect_assume);
8777             symbolTable.setFunctionExtensions("expectEXT", 1, &E_GL_EXT_expect_assume);
8778         }
8779 
8780         // GL_KHR_shader_subgroup
8781         if ((profile == EEsProfile && version >= 310) ||
8782             (profile != EEsProfile && version >= 140)) {
8783             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
8784             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
8785             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8786             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8787             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8788             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8789             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
8790 
8791             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
8792             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
8793             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
8794             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
8795             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
8796             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
8797             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
8798 
8799             symbolTable.setFunctionExtensions("subgroupBarrier",                 1, &E_GL_KHR_shader_subgroup_basic);
8800             symbolTable.setFunctionExtensions("subgroupMemoryBarrier",           1, &E_GL_KHR_shader_subgroup_basic);
8801             symbolTable.setFunctionExtensions("subgroupMemoryBarrierBuffer",     1, &E_GL_KHR_shader_subgroup_basic);
8802             symbolTable.setFunctionExtensions("subgroupMemoryBarrierImage",      1, &E_GL_KHR_shader_subgroup_basic);
8803             symbolTable.setFunctionExtensions("subgroupElect",                   1, &E_GL_KHR_shader_subgroup_basic);
8804             symbolTable.setFunctionExtensions("subgroupAll",                     1, &E_GL_KHR_shader_subgroup_vote);
8805             symbolTable.setFunctionExtensions("subgroupAny",                     1, &E_GL_KHR_shader_subgroup_vote);
8806             symbolTable.setFunctionExtensions("subgroupAllEqual",                1, &E_GL_KHR_shader_subgroup_vote);
8807             symbolTable.setFunctionExtensions("subgroupBroadcast",               1, &E_GL_KHR_shader_subgroup_ballot);
8808             symbolTable.setFunctionExtensions("subgroupBroadcastFirst",          1, &E_GL_KHR_shader_subgroup_ballot);
8809             symbolTable.setFunctionExtensions("subgroupBallot",                  1, &E_GL_KHR_shader_subgroup_ballot);
8810             symbolTable.setFunctionExtensions("subgroupInverseBallot",           1, &E_GL_KHR_shader_subgroup_ballot);
8811             symbolTable.setFunctionExtensions("subgroupBallotBitExtract",        1, &E_GL_KHR_shader_subgroup_ballot);
8812             symbolTable.setFunctionExtensions("subgroupBallotBitCount",          1, &E_GL_KHR_shader_subgroup_ballot);
8813             symbolTable.setFunctionExtensions("subgroupBallotInclusiveBitCount", 1, &E_GL_KHR_shader_subgroup_ballot);
8814             symbolTable.setFunctionExtensions("subgroupBallotExclusiveBitCount", 1, &E_GL_KHR_shader_subgroup_ballot);
8815             symbolTable.setFunctionExtensions("subgroupBallotFindLSB",           1, &E_GL_KHR_shader_subgroup_ballot);
8816             symbolTable.setFunctionExtensions("subgroupBallotFindMSB",           1, &E_GL_KHR_shader_subgroup_ballot);
8817             symbolTable.setFunctionExtensions("subgroupShuffle",                 1, &E_GL_KHR_shader_subgroup_shuffle);
8818             symbolTable.setFunctionExtensions("subgroupShuffleXor",              1, &E_GL_KHR_shader_subgroup_shuffle);
8819             symbolTable.setFunctionExtensions("subgroupShuffleUp",               1, &E_GL_KHR_shader_subgroup_shuffle_relative);
8820             symbolTable.setFunctionExtensions("subgroupShuffleDown",             1, &E_GL_KHR_shader_subgroup_shuffle_relative);
8821             symbolTable.setFunctionExtensions("subgroupRotate",                  1, &E_GL_KHR_shader_subgroup_rotate);
8822             symbolTable.setFunctionExtensions("subgroupClusteredRotate",         1, &E_GL_KHR_shader_subgroup_rotate);
8823             symbolTable.setFunctionExtensions("subgroupAdd",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8824             symbolTable.setFunctionExtensions("subgroupMul",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8825             symbolTable.setFunctionExtensions("subgroupMin",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8826             symbolTable.setFunctionExtensions("subgroupMax",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8827             symbolTable.setFunctionExtensions("subgroupAnd",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8828             symbolTable.setFunctionExtensions("subgroupOr",                      1, &E_GL_KHR_shader_subgroup_arithmetic);
8829             symbolTable.setFunctionExtensions("subgroupXor",                     1, &E_GL_KHR_shader_subgroup_arithmetic);
8830             symbolTable.setFunctionExtensions("subgroupInclusiveAdd",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8831             symbolTable.setFunctionExtensions("subgroupInclusiveMul",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8832             symbolTable.setFunctionExtensions("subgroupInclusiveMin",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8833             symbolTable.setFunctionExtensions("subgroupInclusiveMax",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8834             symbolTable.setFunctionExtensions("subgroupInclusiveAnd",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8835             symbolTable.setFunctionExtensions("subgroupInclusiveOr",             1, &E_GL_KHR_shader_subgroup_arithmetic);
8836             symbolTable.setFunctionExtensions("subgroupInclusiveXor",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8837             symbolTable.setFunctionExtensions("subgroupExclusiveAdd",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8838             symbolTable.setFunctionExtensions("subgroupExclusiveMul",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8839             symbolTable.setFunctionExtensions("subgroupExclusiveMin",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8840             symbolTable.setFunctionExtensions("subgroupExclusiveMax",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8841             symbolTable.setFunctionExtensions("subgroupExclusiveAnd",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8842             symbolTable.setFunctionExtensions("subgroupExclusiveOr",             1, &E_GL_KHR_shader_subgroup_arithmetic);
8843             symbolTable.setFunctionExtensions("subgroupExclusiveXor",            1, &E_GL_KHR_shader_subgroup_arithmetic);
8844             symbolTable.setFunctionExtensions("subgroupClusteredAdd",            1, &E_GL_KHR_shader_subgroup_clustered);
8845             symbolTable.setFunctionExtensions("subgroupClusteredMul",            1, &E_GL_KHR_shader_subgroup_clustered);
8846             symbolTable.setFunctionExtensions("subgroupClusteredMin",            1, &E_GL_KHR_shader_subgroup_clustered);
8847             symbolTable.setFunctionExtensions("subgroupClusteredMax",            1, &E_GL_KHR_shader_subgroup_clustered);
8848             symbolTable.setFunctionExtensions("subgroupClusteredAnd",            1, &E_GL_KHR_shader_subgroup_clustered);
8849             symbolTable.setFunctionExtensions("subgroupClusteredOr",             1, &E_GL_KHR_shader_subgroup_clustered);
8850             symbolTable.setFunctionExtensions("subgroupClusteredXor",            1, &E_GL_KHR_shader_subgroup_clustered);
8851             symbolTable.setFunctionExtensions("subgroupQuadBroadcast",           1, &E_GL_KHR_shader_subgroup_quad);
8852             symbolTable.setFunctionExtensions("subgroupQuadSwapHorizontal",      1, &E_GL_KHR_shader_subgroup_quad);
8853             symbolTable.setFunctionExtensions("subgroupQuadSwapVertical",        1, &E_GL_KHR_shader_subgroup_quad);
8854             symbolTable.setFunctionExtensions("subgroupQuadSwapDiagonal",        1, &E_GL_KHR_shader_subgroup_quad);
8855             symbolTable.setFunctionExtensions("subgroupPartitionNV",                          1, &E_GL_NV_shader_subgroup_partitioned);
8856             symbolTable.setFunctionExtensions("subgroupPartitionedAddNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8857             symbolTable.setFunctionExtensions("subgroupPartitionedMulNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8858             symbolTable.setFunctionExtensions("subgroupPartitionedMinNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8859             symbolTable.setFunctionExtensions("subgroupPartitionedMaxNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8860             symbolTable.setFunctionExtensions("subgroupPartitionedAndNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8861             symbolTable.setFunctionExtensions("subgroupPartitionedOrNV",                      1, &E_GL_NV_shader_subgroup_partitioned);
8862             symbolTable.setFunctionExtensions("subgroupPartitionedXorNV",                     1, &E_GL_NV_shader_subgroup_partitioned);
8863             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveAddNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8864             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveMulNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8865             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveMinNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8866             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveMaxNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8867             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveAndNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8868             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveOrNV",             1, &E_GL_NV_shader_subgroup_partitioned);
8869             symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveXorNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8870             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveAddNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8871             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveMulNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8872             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveMinNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8873             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveMaxNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8874             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveAndNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8875             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveOrNV",             1, &E_GL_NV_shader_subgroup_partitioned);
8876             symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveXorNV",            1, &E_GL_NV_shader_subgroup_partitioned);
8877 
8878             // GL_NV_shader_sm_builtins
8879             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
8880             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
8881             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
8882             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
8883             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
8884             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
8885             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
8886             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
8887 
8888             // GL_ARM_shader_core_builtins
8889             symbolTable.setVariableExtensions("gl_CoreCountARM", 1, &E_GL_ARM_shader_core_builtins);
8890             symbolTable.setVariableExtensions("gl_CoreIDARM",    1, &E_GL_ARM_shader_core_builtins);
8891             symbolTable.setVariableExtensions("gl_CoreMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
8892             symbolTable.setVariableExtensions("gl_WarpIDARM",    1, &E_GL_ARM_shader_core_builtins);
8893             symbolTable.setVariableExtensions("gl_WarpMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
8894 
8895             BuiltInVariable("gl_CoreCountARM", EbvCoreCountARM, symbolTable);
8896             BuiltInVariable("gl_CoreIDARM",    EbvCoreIDARM, symbolTable);
8897             BuiltInVariable("gl_CoreMaxIDARM", EbvCoreMaxIDARM, symbolTable);
8898             BuiltInVariable("gl_WarpIDARM",    EbvWarpIDARM, symbolTable);
8899             BuiltInVariable("gl_WarpMaxIDARM", EbvWarpMaxIDARM, symbolTable);
8900         }
8901 
8902         if (profile == EEsProfile) {
8903             symbolTable.setFunctionExtensions("shadow2DEXT",        1, &E_GL_EXT_shadow_samplers);
8904             symbolTable.setFunctionExtensions("shadow2DProjEXT",    1, &E_GL_EXT_shadow_samplers);
8905         }
8906 
8907         if (spvVersion.vulkan > 0) {
8908             symbolTable.setVariableExtensions("gl_ScopeDevice",             1, &E_GL_KHR_memory_scope_semantics);
8909             symbolTable.setVariableExtensions("gl_ScopeWorkgroup",          1, &E_GL_KHR_memory_scope_semantics);
8910             symbolTable.setVariableExtensions("gl_ScopeSubgroup",           1, &E_GL_KHR_memory_scope_semantics);
8911             symbolTable.setVariableExtensions("gl_ScopeInvocation",         1, &E_GL_KHR_memory_scope_semantics);
8912 
8913             symbolTable.setVariableExtensions("gl_SemanticsRelaxed",        1, &E_GL_KHR_memory_scope_semantics);
8914             symbolTable.setVariableExtensions("gl_SemanticsAcquire",        1, &E_GL_KHR_memory_scope_semantics);
8915             symbolTable.setVariableExtensions("gl_SemanticsRelease",        1, &E_GL_KHR_memory_scope_semantics);
8916             symbolTable.setVariableExtensions("gl_SemanticsAcquireRelease", 1, &E_GL_KHR_memory_scope_semantics);
8917             symbolTable.setVariableExtensions("gl_SemanticsMakeAvailable",  1, &E_GL_KHR_memory_scope_semantics);
8918             symbolTable.setVariableExtensions("gl_SemanticsMakeVisible",    1, &E_GL_KHR_memory_scope_semantics);
8919             symbolTable.setVariableExtensions("gl_SemanticsVolatile",       1, &E_GL_KHR_memory_scope_semantics);
8920 
8921             symbolTable.setVariableExtensions("gl_StorageSemanticsNone",    1, &E_GL_KHR_memory_scope_semantics);
8922             symbolTable.setVariableExtensions("gl_StorageSemanticsBuffer",  1, &E_GL_KHR_memory_scope_semantics);
8923             symbolTable.setVariableExtensions("gl_StorageSemanticsShared",  1, &E_GL_KHR_memory_scope_semantics);
8924             symbolTable.setVariableExtensions("gl_StorageSemanticsImage",   1, &E_GL_KHR_memory_scope_semantics);
8925             symbolTable.setVariableExtensions("gl_StorageSemanticsOutput",  1, &E_GL_KHR_memory_scope_semantics);
8926         }
8927 
8928         symbolTable.setFunctionExtensions("helperInvocationEXT",            1, &E_GL_EXT_demote_to_helper_invocation);
8929 
8930         if ((profile == EEsProfile && version >= 310) ||
8931             (profile != EEsProfile && version >= 450)) {
8932             symbolTable.setVariableExtensions("gl_ShadingRateEXT", 1, &E_GL_EXT_fragment_shading_rate);
8933             BuiltInVariable("gl_ShadingRateEXT", EbvShadingRateKHR, symbolTable);
8934 
8935             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8936             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8937             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8938             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
8939         }
8940 
8941         // GL_EXT_shader_quad_control
8942         if ((profile != EEsProfile && version >= 140) ||
8943             (profile == EEsProfile && version >= 310)) {
8944             symbolTable.setFunctionExtensions("subgroupQuadAll",                     1,  &E_GL_KHR_shader_subgroup_vote);
8945             symbolTable.setFunctionExtensions("subgroupQuadAny",                     1,  &E_GL_KHR_shader_subgroup_vote);
8946         }
8947 
8948         // GL_EXT_shader_tile_image
8949         symbolTable.setFunctionExtensions("stencilAttachmentReadEXT", 1, &E_GL_EXT_shader_tile_image);
8950         symbolTable.setFunctionExtensions("depthAttachmentReadEXT", 1, &E_GL_EXT_shader_tile_image);
8951         symbolTable.setFunctionExtensions("colorAttachmentReadEXT", 1, &E_GL_EXT_shader_tile_image);
8952 
8953         if ((profile == EEsProfile && version >= 310) ||
8954             (profile != EEsProfile && version >= 140)) {
8955 
8956             symbolTable.setFunctionExtensions("textureWeightedQCOM",      1, &E_GL_QCOM_image_processing);
8957             symbolTable.setFunctionExtensions("textureBoxFilterQCOM",     1, &E_GL_QCOM_image_processing);
8958             symbolTable.setFunctionExtensions("textureBlockMatchSADQCOM", 1, &E_GL_QCOM_image_processing);
8959             symbolTable.setFunctionExtensions("textureBlockMatchSSDQCOM", 1, &E_GL_QCOM_image_processing);
8960 
8961             symbolTable.setFunctionExtensions("textureBlockMatchWindowSSDQCOM", 1, &E_GL_QCOM_image_processing2);
8962             symbolTable.setFunctionExtensions("textureBlockMatchWindowSADQCOM", 1, &E_GL_QCOM_image_processing2);
8963             symbolTable.setFunctionExtensions("textureBlockMatchGatherSSDQCOM", 1, &E_GL_QCOM_image_processing2);
8964             symbolTable.setFunctionExtensions("textureBlockMatchGatherSADQCOM", 1, &E_GL_QCOM_image_processing2);
8965         }
8966         break;
8967 
8968     case EShLangCompute:
8969         BuiltInVariable("gl_NumWorkGroups",         EbvNumWorkGroups,        symbolTable);
8970         BuiltInVariable("gl_WorkGroupSize",         EbvWorkGroupSize,        symbolTable);
8971         BuiltInVariable("gl_WorkGroupID",           EbvWorkGroupId,          symbolTable);
8972         BuiltInVariable("gl_LocalInvocationID",     EbvLocalInvocationId,    symbolTable);
8973         BuiltInVariable("gl_GlobalInvocationID",    EbvGlobalInvocationId,   symbolTable);
8974         BuiltInVariable("gl_LocalInvocationIndex",  EbvLocalInvocationIndex, symbolTable);
8975         BuiltInVariable("gl_DeviceIndex",           EbvDeviceIndex,          symbolTable);
8976         BuiltInVariable("gl_ViewIndex",             EbvViewIndex,            symbolTable);
8977 
8978         if ((profile != EEsProfile && version >= 140) ||
8979             (profile == EEsProfile && version >= 310)) {
8980             symbolTable.setVariableExtensions("gl_DeviceIndex",  1, &E_GL_EXT_device_group);
8981             symbolTable.setVariableExtensions("gl_ViewIndex",    1, &E_GL_EXT_multiview);
8982         }
8983 
8984         if (profile != EEsProfile && version < 430) {
8985             symbolTable.setVariableExtensions("gl_NumWorkGroups",        1, &E_GL_ARB_compute_shader);
8986             symbolTable.setVariableExtensions("gl_WorkGroupSize",        1, &E_GL_ARB_compute_shader);
8987             symbolTable.setVariableExtensions("gl_WorkGroupID",          1, &E_GL_ARB_compute_shader);
8988             symbolTable.setVariableExtensions("gl_LocalInvocationID",    1, &E_GL_ARB_compute_shader);
8989             symbolTable.setVariableExtensions("gl_GlobalInvocationID",   1, &E_GL_ARB_compute_shader);
8990             symbolTable.setVariableExtensions("gl_LocalInvocationIndex", 1, &E_GL_ARB_compute_shader);
8991 
8992             symbolTable.setVariableExtensions("gl_MaxComputeWorkGroupCount",       1, &E_GL_ARB_compute_shader);
8993             symbolTable.setVariableExtensions("gl_MaxComputeWorkGroupSize",        1, &E_GL_ARB_compute_shader);
8994             symbolTable.setVariableExtensions("gl_MaxComputeUniformComponents",    1, &E_GL_ARB_compute_shader);
8995             symbolTable.setVariableExtensions("gl_MaxComputeTextureImageUnits",    1, &E_GL_ARB_compute_shader);
8996             symbolTable.setVariableExtensions("gl_MaxComputeImageUniforms",        1, &E_GL_ARB_compute_shader);
8997             symbolTable.setVariableExtensions("gl_MaxComputeAtomicCounters",       1, &E_GL_ARB_compute_shader);
8998             symbolTable.setVariableExtensions("gl_MaxComputeAtomicCounterBuffers", 1, &E_GL_ARB_compute_shader);
8999 
9000             symbolTable.setFunctionExtensions("barrier",                    1, &E_GL_ARB_compute_shader);
9001             symbolTable.setFunctionExtensions("memoryBarrierAtomicCounter", 1, &E_GL_ARB_compute_shader);
9002             symbolTable.setFunctionExtensions("memoryBarrierBuffer",        1, &E_GL_ARB_compute_shader);
9003             symbolTable.setFunctionExtensions("memoryBarrierImage",         1, &E_GL_ARB_compute_shader);
9004             symbolTable.setFunctionExtensions("memoryBarrierShared",        1, &E_GL_ARB_compute_shader);
9005             symbolTable.setFunctionExtensions("groupMemoryBarrier",         1, &E_GL_ARB_compute_shader);
9006         }
9007 
9008 
9009         symbolTable.setFunctionExtensions("controlBarrier",                 1, &E_GL_KHR_memory_scope_semantics);
9010         symbolTable.setFunctionExtensions("debugPrintfEXT",                 1, &E_GL_EXT_debug_printf);
9011 
9012         // GL_ARB_shader_ballot
9013         if (profile != EEsProfile) {
9014             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
9015             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
9016             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
9017             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
9018             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
9019             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
9020             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
9021 
9022             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
9023             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
9024             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
9025             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
9026             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
9027             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
9028 
9029             if (spvVersion.vulkan > 0) {
9030                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
9031                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
9032                 if (language == EShLangFragment)
9033                     ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
9034             }
9035             else
9036                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
9037         }
9038 
9039         // GL_KHR_shader_subgroup
9040         if ((profile == EEsProfile && version >= 310) ||
9041             (profile != EEsProfile && version >= 140)) {
9042             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
9043             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
9044             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9045             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9046             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9047             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9048             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9049 
9050             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
9051             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
9052             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
9053             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
9054             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
9055             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
9056             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
9057 
9058             // GL_NV_shader_sm_builtins
9059             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
9060             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
9061             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
9062             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
9063             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
9064             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
9065             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
9066             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
9067 
9068             // GL_ARM_shader_core_builtins
9069             symbolTable.setVariableExtensions("gl_CoreCountARM", 1, &E_GL_ARM_shader_core_builtins);
9070             symbolTable.setVariableExtensions("gl_CoreIDARM",    1, &E_GL_ARM_shader_core_builtins);
9071             symbolTable.setVariableExtensions("gl_CoreMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
9072             symbolTable.setVariableExtensions("gl_WarpIDARM",    1, &E_GL_ARM_shader_core_builtins);
9073             symbolTable.setVariableExtensions("gl_WarpMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
9074 
9075             BuiltInVariable("gl_CoreCountARM", EbvCoreCountARM, symbolTable);
9076             BuiltInVariable("gl_CoreIDARM",    EbvCoreIDARM, symbolTable);
9077             BuiltInVariable("gl_CoreMaxIDARM", EbvCoreMaxIDARM, symbolTable);
9078             BuiltInVariable("gl_WarpIDARM",    EbvWarpIDARM, symbolTable);
9079             BuiltInVariable("gl_WarpMaxIDARM", EbvWarpMaxIDARM, symbolTable);
9080         }
9081 
9082         // GL_KHR_shader_subgroup
9083         if ((profile == EEsProfile && version >= 310) ||
9084             (profile != EEsProfile && version >= 140)) {
9085             symbolTable.setVariableExtensions("gl_NumSubgroups", 1, &E_GL_KHR_shader_subgroup_basic);
9086             symbolTable.setVariableExtensions("gl_SubgroupID",   1, &E_GL_KHR_shader_subgroup_basic);
9087 
9088             BuiltInVariable("gl_NumSubgroups", EbvNumSubgroups, symbolTable);
9089             BuiltInVariable("gl_SubgroupID",   EbvSubgroupID,   symbolTable);
9090 
9091             symbolTable.setFunctionExtensions("subgroupMemoryBarrierShared", 1, &E_GL_KHR_shader_subgroup_basic);
9092         }
9093 
9094         {
9095             const char *coopExt[2] = { E_GL_NV_cooperative_matrix, E_GL_NV_integer_cooperative_matrix };
9096             symbolTable.setFunctionExtensions("coopMatLoadNV",   2, coopExt);
9097             symbolTable.setFunctionExtensions("coopMatStoreNV",  2, coopExt);
9098             symbolTable.setFunctionExtensions("coopMatMulAddNV", 2, coopExt);
9099         }
9100 
9101         {
9102             symbolTable.setFunctionExtensions("coopMatLoad",   1, &E_GL_KHR_cooperative_matrix);
9103             symbolTable.setFunctionExtensions("coopMatStore",  1, &E_GL_KHR_cooperative_matrix);
9104             symbolTable.setFunctionExtensions("coopMatMulAdd", 1, &E_GL_KHR_cooperative_matrix);
9105 
9106             symbolTable.setFunctionExtensions("coopMatReduceNV",   1, &E_GL_NV_cooperative_matrix2);
9107             symbolTable.setFunctionExtensions("coopMatPerElementNV",  1, &E_GL_NV_cooperative_matrix2);
9108             symbolTable.setFunctionExtensions("coopMatTransposeNV",   1, &E_GL_NV_cooperative_matrix2);
9109 
9110             symbolTable.setFunctionExtensions("createTensorLayoutNV",           1, &E_GL_NV_cooperative_matrix2);
9111             symbolTable.setFunctionExtensions("setTensorLayoutBlockSizeNV",     1, &E_GL_NV_cooperative_matrix2);
9112             symbolTable.setFunctionExtensions("setTensorLayoutDimensionNV",     1, &E_GL_NV_cooperative_matrix2);
9113             symbolTable.setFunctionExtensions("setTensorLayoutStrideNV",        1, &E_GL_NV_cooperative_matrix2);
9114             symbolTable.setFunctionExtensions("sliceTensorLayoutNV",            1, &E_GL_NV_cooperative_matrix2);
9115             symbolTable.setFunctionExtensions("setTensorLayoutClampValueNV",    1, &E_GL_NV_cooperative_matrix2);
9116 
9117             symbolTable.setFunctionExtensions("createTensorViewNV",             1, &E_GL_NV_cooperative_matrix2);
9118             symbolTable.setFunctionExtensions("setTensorViewDimensionsNV",      1, &E_GL_NV_cooperative_matrix2);
9119             symbolTable.setFunctionExtensions("setTensorViewStrideNV",          1, &E_GL_NV_cooperative_matrix2);
9120             symbolTable.setFunctionExtensions("setTensorViewClipNV",            1, &E_GL_NV_cooperative_matrix2);
9121         }
9122 
9123         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
9124             symbolTable.setFunctionExtensions("dFdx",                   1, &E_GL_NV_compute_shader_derivatives);
9125             symbolTable.setFunctionExtensions("dFdy",                   1, &E_GL_NV_compute_shader_derivatives);
9126             symbolTable.setFunctionExtensions("fwidth",                 1, &E_GL_NV_compute_shader_derivatives);
9127             symbolTable.setFunctionExtensions("dFdxFine",               1, &E_GL_NV_compute_shader_derivatives);
9128             symbolTable.setFunctionExtensions("dFdyFine",               1, &E_GL_NV_compute_shader_derivatives);
9129             symbolTable.setFunctionExtensions("fwidthFine",             1, &E_GL_NV_compute_shader_derivatives);
9130             symbolTable.setFunctionExtensions("dFdxCoarse",             1, &E_GL_NV_compute_shader_derivatives);
9131             symbolTable.setFunctionExtensions("dFdyCoarse",             1, &E_GL_NV_compute_shader_derivatives);
9132             symbolTable.setFunctionExtensions("fwidthCoarse",           1, &E_GL_NV_compute_shader_derivatives);
9133         }
9134 
9135         if ((profile == EEsProfile && version >= 310) ||
9136             (profile != EEsProfile && version >= 450)) {
9137             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9138             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9139             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9140             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9141         }
9142 
9143         if ((profile != EEsProfile && version >= 460)) {
9144             symbolTable.setFunctionExtensions("fetchMicroTriangleVertexPositionNV", 1, &E_GL_NV_displacement_micromap);
9145             symbolTable.setFunctionExtensions("fetchMicroTriangleVertexBarycentricNV", 1, &E_GL_NV_displacement_micromap);
9146         }
9147         break;
9148 
9149     case EShLangRayGen:
9150     case EShLangIntersect:
9151     case EShLangAnyHit:
9152     case EShLangClosestHit:
9153     case EShLangMiss:
9154     case EShLangCallable:
9155         if (profile != EEsProfile && version >= 460) {
9156             const char *rtexts[] = { E_GL_NV_ray_tracing, E_GL_EXT_ray_tracing };
9157             symbolTable.setVariableExtensions("gl_LaunchIDNV", 1, &E_GL_NV_ray_tracing);
9158             symbolTable.setVariableExtensions("gl_LaunchIDEXT", 1, &E_GL_EXT_ray_tracing);
9159             symbolTable.setVariableExtensions("gl_LaunchSizeNV", 1, &E_GL_NV_ray_tracing);
9160             symbolTable.setVariableExtensions("gl_LaunchSizeEXT", 1, &E_GL_EXT_ray_tracing);
9161             symbolTable.setVariableExtensions("gl_PrimitiveID", 2, rtexts);
9162             symbolTable.setVariableExtensions("gl_InstanceID", 2, rtexts);
9163             symbolTable.setVariableExtensions("gl_InstanceCustomIndexNV", 1, &E_GL_NV_ray_tracing);
9164             symbolTable.setVariableExtensions("gl_InstanceCustomIndexEXT", 1, &E_GL_EXT_ray_tracing);
9165             symbolTable.setVariableExtensions("gl_GeometryIndexEXT", 1, &E_GL_EXT_ray_tracing);
9166             symbolTable.setVariableExtensions("gl_WorldRayOriginNV", 1, &E_GL_NV_ray_tracing);
9167             symbolTable.setVariableExtensions("gl_WorldRayOriginEXT", 1, &E_GL_EXT_ray_tracing);
9168             symbolTable.setVariableExtensions("gl_WorldRayDirectionNV", 1, &E_GL_NV_ray_tracing);
9169             symbolTable.setVariableExtensions("gl_WorldRayDirectionEXT", 1, &E_GL_EXT_ray_tracing);
9170             symbolTable.setVariableExtensions("gl_ObjectRayOriginNV", 1, &E_GL_NV_ray_tracing);
9171             symbolTable.setVariableExtensions("gl_ObjectRayOriginEXT", 1, &E_GL_EXT_ray_tracing);
9172             symbolTable.setVariableExtensions("gl_ObjectRayDirectionNV", 1, &E_GL_NV_ray_tracing);
9173             symbolTable.setVariableExtensions("gl_ObjectRayDirectionEXT", 1, &E_GL_EXT_ray_tracing);
9174             symbolTable.setVariableExtensions("gl_RayTminNV", 1, &E_GL_NV_ray_tracing);
9175             symbolTable.setVariableExtensions("gl_RayTminEXT", 1, &E_GL_EXT_ray_tracing);
9176             symbolTable.setVariableExtensions("gl_RayTmaxNV", 1, &E_GL_NV_ray_tracing);
9177             symbolTable.setVariableExtensions("gl_RayTmaxEXT", 1, &E_GL_EXT_ray_tracing);
9178             symbolTable.setVariableExtensions("gl_CullMaskEXT", 1, &E_GL_EXT_ray_cull_mask);
9179             symbolTable.setVariableExtensions("gl_HitTNV", 1, &E_GL_NV_ray_tracing);
9180             symbolTable.setVariableExtensions("gl_HitTEXT", 1, &E_GL_EXT_ray_tracing);
9181             symbolTable.setVariableExtensions("gl_HitKindNV", 1, &E_GL_NV_ray_tracing);
9182             symbolTable.setVariableExtensions("gl_HitKindEXT", 1, &E_GL_EXT_ray_tracing);
9183             symbolTable.setVariableExtensions("gl_ObjectToWorldNV", 1, &E_GL_NV_ray_tracing);
9184             symbolTable.setVariableExtensions("gl_ObjectToWorldEXT", 1, &E_GL_EXT_ray_tracing);
9185             symbolTable.setVariableExtensions("gl_ObjectToWorld3x4EXT", 1, &E_GL_EXT_ray_tracing);
9186             symbolTable.setVariableExtensions("gl_WorldToObjectNV", 1, &E_GL_NV_ray_tracing);
9187             symbolTable.setVariableExtensions("gl_WorldToObjectEXT", 1, &E_GL_EXT_ray_tracing);
9188             symbolTable.setVariableExtensions("gl_WorldToObject3x4EXT", 1, &E_GL_EXT_ray_tracing);
9189             symbolTable.setVariableExtensions("gl_IncomingRayFlagsNV", 1, &E_GL_NV_ray_tracing);
9190             symbolTable.setVariableExtensions("gl_IncomingRayFlagsEXT", 1, &E_GL_EXT_ray_tracing);
9191             symbolTable.setVariableExtensions("gl_CurrentRayTimeNV", 1, &E_GL_NV_ray_tracing_motion_blur);
9192             symbolTable.setVariableExtensions("gl_HitTriangleVertexPositionsEXT", 1, &E_GL_EXT_ray_tracing_position_fetch);
9193             symbolTable.setVariableExtensions("gl_HitMicroTriangleVertexPositionsNV", 1, &E_GL_NV_displacement_micromap);
9194             symbolTable.setVariableExtensions("gl_HitMicroTriangleVertexBarycentricsNV", 1, &E_GL_NV_displacement_micromap);
9195 
9196             symbolTable.setVariableExtensions("gl_DeviceIndex", 1, &E_GL_EXT_device_group);
9197 
9198 
9199             symbolTable.setFunctionExtensions("traceNV", 1, &E_GL_NV_ray_tracing);
9200             symbolTable.setFunctionExtensions("traceRayMotionNV", 1, &E_GL_NV_ray_tracing_motion_blur);
9201             symbolTable.setFunctionExtensions("traceRayEXT", 1, &E_GL_EXT_ray_tracing);
9202             symbolTable.setFunctionExtensions("reportIntersectionNV", 1, &E_GL_NV_ray_tracing);
9203             symbolTable.setFunctionExtensions("reportIntersectionEXT", 1, &E_GL_EXT_ray_tracing);
9204             symbolTable.setFunctionExtensions("ignoreIntersectionNV", 1, &E_GL_NV_ray_tracing);
9205             symbolTable.setFunctionExtensions("terminateRayNV", 1, &E_GL_NV_ray_tracing);
9206             symbolTable.setFunctionExtensions("executeCallableNV", 1, &E_GL_NV_ray_tracing);
9207             symbolTable.setFunctionExtensions("executeCallableEXT", 1, &E_GL_EXT_ray_tracing);
9208 
9209             symbolTable.setFunctionExtensions("hitObjectTraceRayNV", 1, &E_GL_NV_shader_invocation_reorder);
9210             symbolTable.setFunctionExtensions("hitObjectTraceRayMotionNV", 1, &E_GL_NV_shader_invocation_reorder);
9211             symbolTable.setFunctionExtensions("hitObjectRecordHitNV", 1, &E_GL_NV_shader_invocation_reorder);
9212             symbolTable.setFunctionExtensions("hitObjectRecordHitMotionNV", 1, &E_GL_NV_shader_invocation_reorder);
9213             symbolTable.setFunctionExtensions("hitObjectRecordHitWithIndexNV", 1, &E_GL_NV_shader_invocation_reorder);
9214             symbolTable.setFunctionExtensions("hitObjectRecordHitWithIndexMotionNV", 1, &E_GL_NV_shader_invocation_reorder);
9215             symbolTable.setFunctionExtensions("hitObjectRecordMissNV", 1, &E_GL_NV_shader_invocation_reorder);
9216             symbolTable.setFunctionExtensions("hitObjectRecordMissMotionNV", 1, &E_GL_NV_shader_invocation_reorder);
9217             symbolTable.setFunctionExtensions("hitObjectRecordEmptyNV", 1, &E_GL_NV_shader_invocation_reorder);
9218             symbolTable.setFunctionExtensions("hitObjectExecuteShaderNV", 1, &E_GL_NV_shader_invocation_reorder);
9219             symbolTable.setFunctionExtensions("hitObjectIsEmptyNV", 1, &E_GL_NV_shader_invocation_reorder);
9220             symbolTable.setFunctionExtensions("hitObjectIsMissNV", 1, &E_GL_NV_shader_invocation_reorder);
9221             symbolTable.setFunctionExtensions("hitObjectIsHitNV", 1, &E_GL_NV_shader_invocation_reorder);
9222             symbolTable.setFunctionExtensions("hitObjectGetRayTMinNV", 1, &E_GL_NV_shader_invocation_reorder);
9223             symbolTable.setFunctionExtensions("hitObjectGetRayTMaxNV", 1, &E_GL_NV_shader_invocation_reorder);
9224             symbolTable.setFunctionExtensions("hitObjectGetObjectRayOriginNV", 1, &E_GL_NV_shader_invocation_reorder);
9225             symbolTable.setFunctionExtensions("hitObjectGetObjectRayDirectionNV", 1, &E_GL_NV_shader_invocation_reorder);
9226             symbolTable.setFunctionExtensions("hitObjectGetWorldRayOriginNV", 1, &E_GL_NV_shader_invocation_reorder);
9227             symbolTable.setFunctionExtensions("hitObjectGetWorldRayDirectionNV", 1, &E_GL_NV_shader_invocation_reorder);
9228             symbolTable.setFunctionExtensions("hitObjectGetWorldToObjectNV", 1, &E_GL_NV_shader_invocation_reorder);
9229             symbolTable.setFunctionExtensions("hitObjectGetbjectToWorldNV", 1, &E_GL_NV_shader_invocation_reorder);
9230             symbolTable.setFunctionExtensions("hitObjectGetInstanceCustomIndexNV", 1, &E_GL_NV_shader_invocation_reorder);
9231             symbolTable.setFunctionExtensions("hitObjectGetInstanceIdNV", 1, &E_GL_NV_shader_invocation_reorder);
9232             symbolTable.setFunctionExtensions("hitObjectGetGeometryIndexNV", 1, &E_GL_NV_shader_invocation_reorder);
9233             symbolTable.setFunctionExtensions("hitObjectGetPrimitiveIndexNV", 1, &E_GL_NV_shader_invocation_reorder);
9234             symbolTable.setFunctionExtensions("hitObjectGetHitKindNV", 1, &E_GL_NV_shader_invocation_reorder);
9235             symbolTable.setFunctionExtensions("hitObjectGetAttributesNV", 1, &E_GL_NV_shader_invocation_reorder);
9236             symbolTable.setFunctionExtensions("hitObjectGetCurrentTimeNV", 1, &E_GL_NV_shader_invocation_reorder);
9237             symbolTable.setFunctionExtensions("hitObjectGetShaderBindingTableRecordIndexNV", 1, &E_GL_NV_shader_invocation_reorder);
9238             symbolTable.setFunctionExtensions("hitObjectGetShaderRecordBufferHandleNV", 1, &E_GL_NV_shader_invocation_reorder);
9239             symbolTable.setFunctionExtensions("reorderThreadNV", 1, &E_GL_NV_shader_invocation_reorder);
9240             symbolTable.setFunctionExtensions("fetchMicroTriangleVertexPositionNV", 1, &E_GL_NV_displacement_micromap);
9241             symbolTable.setFunctionExtensions("fetchMicroTriangleVertexBarycentricNV", 1, &E_GL_NV_displacement_micromap);
9242 
9243 
9244             BuiltInVariable("gl_LaunchIDNV",             EbvLaunchId,           symbolTable);
9245             BuiltInVariable("gl_LaunchIDEXT",            EbvLaunchId,           symbolTable);
9246             BuiltInVariable("gl_LaunchSizeNV",           EbvLaunchSize,         symbolTable);
9247             BuiltInVariable("gl_LaunchSizeEXT",          EbvLaunchSize,         symbolTable);
9248             BuiltInVariable("gl_PrimitiveID",            EbvPrimitiveId,        symbolTable);
9249             BuiltInVariable("gl_InstanceID",             EbvInstanceId,         symbolTable);
9250             BuiltInVariable("gl_InstanceCustomIndexNV",  EbvInstanceCustomIndex,symbolTable);
9251             BuiltInVariable("gl_InstanceCustomIndexEXT", EbvInstanceCustomIndex,symbolTable);
9252             BuiltInVariable("gl_GeometryIndexEXT",       EbvGeometryIndex,      symbolTable);
9253             BuiltInVariable("gl_WorldRayOriginNV",       EbvWorldRayOrigin,     symbolTable);
9254             BuiltInVariable("gl_WorldRayOriginEXT",      EbvWorldRayOrigin,     symbolTable);
9255             BuiltInVariable("gl_WorldRayDirectionNV",    EbvWorldRayDirection,  symbolTable);
9256             BuiltInVariable("gl_WorldRayDirectionEXT",   EbvWorldRayDirection,  symbolTable);
9257             BuiltInVariable("gl_ObjectRayOriginNV",      EbvObjectRayOrigin,    symbolTable);
9258             BuiltInVariable("gl_ObjectRayOriginEXT",     EbvObjectRayOrigin,    symbolTable);
9259             BuiltInVariable("gl_ObjectRayDirectionNV",   EbvObjectRayDirection, symbolTable);
9260             BuiltInVariable("gl_ObjectRayDirectionEXT",  EbvObjectRayDirection, symbolTable);
9261             BuiltInVariable("gl_RayTminNV",              EbvRayTmin,            symbolTable);
9262             BuiltInVariable("gl_RayTminEXT",             EbvRayTmin,            symbolTable);
9263             BuiltInVariable("gl_RayTmaxNV",              EbvRayTmax,            symbolTable);
9264             BuiltInVariable("gl_RayTmaxEXT",             EbvRayTmax,            symbolTable);
9265             BuiltInVariable("gl_CullMaskEXT",            EbvCullMask,           symbolTable);
9266             BuiltInVariable("gl_HitKindNV",              EbvHitKind,            symbolTable);
9267             BuiltInVariable("gl_HitKindEXT",             EbvHitKind,            symbolTable);
9268             BuiltInVariable("gl_ObjectToWorldNV",        EbvObjectToWorld,      symbolTable);
9269             BuiltInVariable("gl_ObjectToWorldEXT",       EbvObjectToWorld,      symbolTable);
9270             BuiltInVariable("gl_ObjectToWorld3x4EXT",    EbvObjectToWorld3x4,   symbolTable);
9271             BuiltInVariable("gl_WorldToObjectNV",        EbvWorldToObject,      symbolTable);
9272             BuiltInVariable("gl_WorldToObjectEXT",       EbvWorldToObject,      symbolTable);
9273             BuiltInVariable("gl_WorldToObject3x4EXT",    EbvWorldToObject3x4,   symbolTable);
9274             BuiltInVariable("gl_IncomingRayFlagsNV",     EbvIncomingRayFlags,   symbolTable);
9275             BuiltInVariable("gl_IncomingRayFlagsEXT",    EbvIncomingRayFlags,   symbolTable);
9276             BuiltInVariable("gl_DeviceIndex",            EbvDeviceIndex,        symbolTable);
9277             BuiltInVariable("gl_CurrentRayTimeNV",       EbvCurrentRayTimeNV,   symbolTable);
9278             BuiltInVariable("gl_HitTriangleVertexPositionsEXT", EbvPositionFetch, symbolTable);
9279             BuiltInVariable("gl_HitMicroTriangleVertexPositionsNV", EbvMicroTrianglePositionNV, symbolTable);
9280             BuiltInVariable("gl_HitMicroTriangleVertexBarycentricsNV", EbvMicroTriangleBaryNV, symbolTable);
9281             BuiltInVariable("gl_HitKindFrontFacingMicroTriangleNV", EbvHitKindFrontFacingMicroTriangleNV, symbolTable);
9282             BuiltInVariable("gl_HitKindBackFacingMicroTriangleNV", EbvHitKindBackFacingMicroTriangleNV, symbolTable);
9283 
9284             // gl_HitT variables are aliases of their gl_RayTmax counterparts.
9285             RetargetVariable("gl_HitTNV",                "gl_RayTmaxNV",        symbolTable);
9286             RetargetVariable("gl_HitTEXT",               "gl_RayTmaxEXT",       symbolTable);
9287 
9288             // GL_ARB_shader_ballot
9289             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
9290             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
9291             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
9292             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
9293             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
9294             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
9295             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
9296 
9297             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
9298             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
9299             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
9300             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
9301             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
9302             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
9303 
9304             if (spvVersion.vulkan > 0) {
9305                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
9306                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
9307                 if (language == EShLangFragment)
9308                     ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
9309             }
9310             else
9311                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
9312 
9313             // GL_KHR_shader_subgroup
9314             symbolTable.setVariableExtensions("gl_NumSubgroups",         1, &E_GL_KHR_shader_subgroup_basic);
9315             symbolTable.setVariableExtensions("gl_SubgroupID",           1, &E_GL_KHR_shader_subgroup_basic);
9316             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
9317             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
9318             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9319             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9320             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9321             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9322             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9323 
9324             BuiltInVariable("gl_NumSubgroups",         EbvNumSubgroups,        symbolTable);
9325             BuiltInVariable("gl_SubgroupID",           EbvSubgroupID,          symbolTable);
9326             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
9327             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
9328             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
9329             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
9330             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
9331             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
9332             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
9333 
9334             // GL_NV_shader_sm_builtins
9335             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
9336             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
9337             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
9338             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
9339             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
9340             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
9341             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
9342             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
9343 
9344             // GL_ARM_shader_core_builtins
9345             symbolTable.setVariableExtensions("gl_CoreCountARM", 1, &E_GL_ARM_shader_core_builtins);
9346             symbolTable.setVariableExtensions("gl_CoreIDARM",    1, &E_GL_ARM_shader_core_builtins);
9347             symbolTable.setVariableExtensions("gl_CoreMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
9348             symbolTable.setVariableExtensions("gl_WarpIDARM",    1, &E_GL_ARM_shader_core_builtins);
9349             symbolTable.setVariableExtensions("gl_WarpMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
9350 
9351             BuiltInVariable("gl_CoreCountARM", EbvCoreCountARM, symbolTable);
9352             BuiltInVariable("gl_CoreIDARM",    EbvCoreIDARM, symbolTable);
9353             BuiltInVariable("gl_CoreMaxIDARM", EbvCoreMaxIDARM, symbolTable);
9354             BuiltInVariable("gl_WarpIDARM",    EbvWarpIDARM, symbolTable);
9355             BuiltInVariable("gl_WarpMaxIDARM", EbvWarpMaxIDARM, symbolTable);
9356         }
9357         if ((profile == EEsProfile && version >= 310) ||
9358             (profile != EEsProfile && version >= 450)) {
9359             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9360             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9361             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9362             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9363         }
9364         break;
9365 
9366     case EShLangMesh:
9367         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
9368             // per-vertex builtins
9369             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_Position",     1, &E_GL_NV_mesh_shader);
9370             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_PointSize",    1, &E_GL_NV_mesh_shader);
9371             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_ClipDistance", 1, &E_GL_NV_mesh_shader);
9372             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_CullDistance", 1, &E_GL_NV_mesh_shader);
9373 
9374             BuiltInVariable("gl_MeshVerticesNV", "gl_Position",     EbvPosition,     symbolTable);
9375             BuiltInVariable("gl_MeshVerticesNV", "gl_PointSize",    EbvPointSize,    symbolTable);
9376             BuiltInVariable("gl_MeshVerticesNV", "gl_ClipDistance", EbvClipDistance, symbolTable);
9377             BuiltInVariable("gl_MeshVerticesNV", "gl_CullDistance", EbvCullDistance, symbolTable);
9378 
9379             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_PositionPerViewNV",     1, &E_GL_NV_mesh_shader);
9380             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_ClipDistancePerViewNV", 1, &E_GL_NV_mesh_shader);
9381             symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_CullDistancePerViewNV", 1, &E_GL_NV_mesh_shader);
9382 
9383             BuiltInVariable("gl_MeshVerticesNV", "gl_PositionPerViewNV",     EbvPositionPerViewNV,     symbolTable);
9384             BuiltInVariable("gl_MeshVerticesNV", "gl_ClipDistancePerViewNV", EbvClipDistancePerViewNV, symbolTable);
9385             BuiltInVariable("gl_MeshVerticesNV", "gl_CullDistancePerViewNV", EbvCullDistancePerViewNV, symbolTable);
9386 
9387             // per-primitive builtins
9388             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_PrimitiveID",   1, &E_GL_NV_mesh_shader);
9389             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_Layer",         1, &E_GL_NV_mesh_shader);
9390             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_ViewportIndex", 1, &E_GL_NV_mesh_shader);
9391             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_ViewportMask",  1, &E_GL_NV_mesh_shader);
9392 
9393             BuiltInVariable("gl_MeshPrimitivesNV", "gl_PrimitiveID",   EbvPrimitiveId,    symbolTable);
9394             BuiltInVariable("gl_MeshPrimitivesNV", "gl_Layer",         EbvLayer,          symbolTable);
9395             BuiltInVariable("gl_MeshPrimitivesNV", "gl_ViewportIndex", EbvViewportIndex,  symbolTable);
9396             BuiltInVariable("gl_MeshPrimitivesNV", "gl_ViewportMask",  EbvViewportMaskNV, symbolTable);
9397 
9398             // per-view per-primitive builtins
9399             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_LayerPerViewNV",        1, &E_GL_NV_mesh_shader);
9400             symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_ViewportMaskPerViewNV", 1, &E_GL_NV_mesh_shader);
9401 
9402             BuiltInVariable("gl_MeshPrimitivesNV", "gl_LayerPerViewNV",        EbvLayerPerViewNV,        symbolTable);
9403             BuiltInVariable("gl_MeshPrimitivesNV", "gl_ViewportMaskPerViewNV", EbvViewportMaskPerViewNV, symbolTable);
9404 
9405             // other builtins
9406             symbolTable.setVariableExtensions("gl_PrimitiveCountNV",     1, &E_GL_NV_mesh_shader);
9407             symbolTable.setVariableExtensions("gl_PrimitiveIndicesNV",   1, &E_GL_NV_mesh_shader);
9408             symbolTable.setVariableExtensions("gl_MeshViewCountNV",      1, &E_GL_NV_mesh_shader);
9409             symbolTable.setVariableExtensions("gl_MeshViewIndicesNV",    1, &E_GL_NV_mesh_shader);
9410             if (profile != EEsProfile) {
9411                 symbolTable.setVariableExtensions("gl_WorkGroupSize",        Num_AEP_mesh_shader, AEP_mesh_shader);
9412                 symbolTable.setVariableExtensions("gl_WorkGroupID",          Num_AEP_mesh_shader, AEP_mesh_shader);
9413                 symbolTable.setVariableExtensions("gl_LocalInvocationID",    Num_AEP_mesh_shader, AEP_mesh_shader);
9414                 symbolTable.setVariableExtensions("gl_GlobalInvocationID",   Num_AEP_mesh_shader, AEP_mesh_shader);
9415                 symbolTable.setVariableExtensions("gl_LocalInvocationIndex", Num_AEP_mesh_shader, AEP_mesh_shader);
9416             } else {
9417                 symbolTable.setVariableExtensions("gl_WorkGroupSize",        1, &E_GL_NV_mesh_shader);
9418                 symbolTable.setVariableExtensions("gl_WorkGroupID",          1, &E_GL_NV_mesh_shader);
9419                 symbolTable.setVariableExtensions("gl_LocalInvocationID",    1, &E_GL_NV_mesh_shader);
9420                 symbolTable.setVariableExtensions("gl_GlobalInvocationID",   1, &E_GL_NV_mesh_shader);
9421                 symbolTable.setVariableExtensions("gl_LocalInvocationIndex", 1, &E_GL_NV_mesh_shader);
9422             }
9423             BuiltInVariable("gl_PrimitiveCountNV",     EbvPrimitiveCountNV,     symbolTable);
9424             BuiltInVariable("gl_PrimitiveIndicesNV",   EbvPrimitiveIndicesNV,   symbolTable);
9425             BuiltInVariable("gl_MeshViewCountNV",      EbvMeshViewCountNV,      symbolTable);
9426             BuiltInVariable("gl_MeshViewIndicesNV",    EbvMeshViewIndicesNV,    symbolTable);
9427             BuiltInVariable("gl_WorkGroupSize",        EbvWorkGroupSize,        symbolTable);
9428             BuiltInVariable("gl_WorkGroupID",          EbvWorkGroupId,          symbolTable);
9429             BuiltInVariable("gl_LocalInvocationID",    EbvLocalInvocationId,    symbolTable);
9430             BuiltInVariable("gl_GlobalInvocationID",   EbvGlobalInvocationId,   symbolTable);
9431             BuiltInVariable("gl_LocalInvocationIndex", EbvLocalInvocationIndex, symbolTable);
9432 
9433             // builtin constants
9434             symbolTable.setVariableExtensions("gl_MaxMeshOutputVerticesNV",   1, &E_GL_NV_mesh_shader);
9435             symbolTable.setVariableExtensions("gl_MaxMeshOutputPrimitivesNV", 1, &E_GL_NV_mesh_shader);
9436             symbolTable.setVariableExtensions("gl_MaxMeshWorkGroupSizeNV",    1, &E_GL_NV_mesh_shader);
9437             symbolTable.setVariableExtensions("gl_MaxMeshViewCountNV",        1, &E_GL_NV_mesh_shader);
9438 
9439             // builtin functions
9440             if (profile != EEsProfile) {
9441                 symbolTable.setFunctionExtensions("barrier",                      Num_AEP_mesh_shader, AEP_mesh_shader);
9442                 symbolTable.setFunctionExtensions("memoryBarrierShared",          Num_AEP_mesh_shader, AEP_mesh_shader);
9443                 symbolTable.setFunctionExtensions("groupMemoryBarrier",           Num_AEP_mesh_shader, AEP_mesh_shader);
9444             } else {
9445                 symbolTable.setFunctionExtensions("barrier",                      1, &E_GL_NV_mesh_shader);
9446                 symbolTable.setFunctionExtensions("memoryBarrierShared",          1, &E_GL_NV_mesh_shader);
9447                 symbolTable.setFunctionExtensions("groupMemoryBarrier",           1, &E_GL_NV_mesh_shader);
9448             }
9449             symbolTable.setFunctionExtensions("writePackedPrimitiveIndices4x8NV",  1, &E_GL_NV_mesh_shader);
9450         }
9451 
9452         if (profile != EEsProfile && version >= 450) {
9453             // GL_EXT_Mesh_shader
9454             symbolTable.setVariableExtensions("gl_PrimitivePointIndicesEXT",    1, &E_GL_EXT_mesh_shader);
9455             symbolTable.setVariableExtensions("gl_PrimitiveLineIndicesEXT",     1, &E_GL_EXT_mesh_shader);
9456             symbolTable.setVariableExtensions("gl_PrimitiveTriangleIndicesEXT", 1, &E_GL_EXT_mesh_shader);
9457             symbolTable.setVariableExtensions("gl_NumWorkGroups",               1, &E_GL_EXT_mesh_shader);
9458 
9459             BuiltInVariable("gl_PrimitivePointIndicesEXT",    EbvPrimitivePointIndicesEXT,    symbolTable);
9460             BuiltInVariable("gl_PrimitiveLineIndicesEXT",     EbvPrimitiveLineIndicesEXT,     symbolTable);
9461             BuiltInVariable("gl_PrimitiveTriangleIndicesEXT", EbvPrimitiveTriangleIndicesEXT, symbolTable);
9462             BuiltInVariable("gl_NumWorkGroups",        EbvNumWorkGroups,        symbolTable);
9463 
9464             symbolTable.setVariableExtensions("gl_MeshVerticesEXT", "gl_Position",     1, &E_GL_EXT_mesh_shader);
9465             symbolTable.setVariableExtensions("gl_MeshVerticesEXT", "gl_PointSize",    1, &E_GL_EXT_mesh_shader);
9466             symbolTable.setVariableExtensions("gl_MeshVerticesEXT", "gl_ClipDistance", 1, &E_GL_EXT_mesh_shader);
9467             symbolTable.setVariableExtensions("gl_MeshVerticesEXT", "gl_CullDistance", 1, &E_GL_EXT_mesh_shader);
9468 
9469             BuiltInVariable("gl_MeshVerticesEXT", "gl_Position",     EbvPosition,     symbolTable);
9470             BuiltInVariable("gl_MeshVerticesEXT", "gl_PointSize",    EbvPointSize,    symbolTable);
9471             BuiltInVariable("gl_MeshVerticesEXT", "gl_ClipDistance", EbvClipDistance, symbolTable);
9472             BuiltInVariable("gl_MeshVerticesEXT", "gl_CullDistance", EbvCullDistance, symbolTable);
9473 
9474             symbolTable.setVariableExtensions("gl_MeshPrimitivesEXT", "gl_PrimitiveID",             1, &E_GL_EXT_mesh_shader);
9475             symbolTable.setVariableExtensions("gl_MeshPrimitivesEXT", "gl_Layer",                   1, &E_GL_EXT_mesh_shader);
9476             symbolTable.setVariableExtensions("gl_MeshPrimitivesEXT", "gl_ViewportIndex",           1, &E_GL_EXT_mesh_shader);
9477             symbolTable.setVariableExtensions("gl_MeshPrimitivesEXT", "gl_CullPrimitiveEXT",        1, &E_GL_EXT_mesh_shader);
9478 
9479             // note: technically this member requires both GL_EXT_mesh_shader and GL_EXT_fragment_shading_rate
9480             // since setVariableExtensions only needs *one of* the extensions to validate, it's more useful to specify EXT_fragment_shading_rate
9481             // GL_EXT_mesh_shader will be required in practice by use of other fields of gl_MeshPrimitivesEXT
9482             symbolTable.setVariableExtensions("gl_MeshPrimitivesEXT", "gl_PrimitiveShadingRateEXT", 1, &E_GL_EXT_fragment_shading_rate);
9483 
9484             BuiltInVariable("gl_MeshPrimitivesEXT", "gl_PrimitiveID",              EbvPrimitiveId,    symbolTable);
9485             BuiltInVariable("gl_MeshPrimitivesEXT", "gl_Layer",                    EbvLayer,          symbolTable);
9486             BuiltInVariable("gl_MeshPrimitivesEXT", "gl_ViewportIndex",            EbvViewportIndex,  symbolTable);
9487             BuiltInVariable("gl_MeshPrimitivesEXT", "gl_CullPrimitiveEXT",         EbvCullPrimitiveEXT, symbolTable);
9488             BuiltInVariable("gl_MeshPrimitivesEXT", "gl_PrimitiveShadingRateEXT",  EbvPrimitiveShadingRateKHR, symbolTable);
9489 
9490             symbolTable.setFunctionExtensions("SetMeshOutputsEXT",  1, &E_GL_EXT_mesh_shader);
9491 
9492             // GL_EXT_device_group
9493             symbolTable.setVariableExtensions("gl_DeviceIndex", 1, &E_GL_EXT_device_group);
9494             BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
9495 
9496             // GL_ARB_shader_draw_parameters
9497             symbolTable.setVariableExtensions("gl_DrawIDARB", 1, &E_GL_ARB_shader_draw_parameters);
9498             BuiltInVariable("gl_DrawIDARB", EbvDrawId, symbolTable);
9499             if (version >= 460) {
9500                 BuiltInVariable("gl_DrawID", EbvDrawId, symbolTable);
9501             }
9502             // GL_EXT_multiview
9503             BuiltInVariable("gl_ViewIndex", EbvViewIndex, symbolTable);
9504             symbolTable.setVariableExtensions("gl_ViewIndex", 1, &E_GL_EXT_multiview);
9505 
9506             // GL_ARB_shader_ballot
9507             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
9508             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
9509             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
9510             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
9511             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
9512             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
9513             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
9514 
9515             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
9516             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
9517             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
9518             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
9519             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
9520             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
9521 
9522             if (spvVersion.vulkan > 0) {
9523                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
9524                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
9525                 if (language == EShLangFragment)
9526                     ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
9527             }
9528             else
9529                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
9530         }
9531 
9532         // GL_KHR_shader_subgroup
9533         if ((profile == EEsProfile && version >= 310) ||
9534             (profile != EEsProfile && version >= 140)) {
9535             symbolTable.setVariableExtensions("gl_NumSubgroups",         1, &E_GL_KHR_shader_subgroup_basic);
9536             symbolTable.setVariableExtensions("gl_SubgroupID",           1, &E_GL_KHR_shader_subgroup_basic);
9537             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
9538             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
9539             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9540             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9541             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9542             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9543             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9544 
9545             BuiltInVariable("gl_NumSubgroups",         EbvNumSubgroups,        symbolTable);
9546             BuiltInVariable("gl_SubgroupID",           EbvSubgroupID,          symbolTable);
9547             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
9548             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
9549             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
9550             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
9551             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
9552             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
9553             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
9554 
9555             symbolTable.setFunctionExtensions("subgroupMemoryBarrierShared", 1, &E_GL_KHR_shader_subgroup_basic);
9556 
9557             // GL_NV_shader_sm_builtins
9558             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
9559             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
9560             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
9561             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
9562             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
9563             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
9564             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
9565             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
9566 
9567             // GL_ARM_shader_core_builtins
9568             symbolTable.setVariableExtensions("gl_CoreCountARM", 1, &E_GL_ARM_shader_core_builtins);
9569             symbolTable.setVariableExtensions("gl_CoreIDARM",    1, &E_GL_ARM_shader_core_builtins);
9570             symbolTable.setVariableExtensions("gl_CoreMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
9571             symbolTable.setVariableExtensions("gl_WarpIDARM",    1, &E_GL_ARM_shader_core_builtins);
9572             symbolTable.setVariableExtensions("gl_WarpMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
9573 
9574             BuiltInVariable("gl_CoreCountARM", EbvCoreCountARM, symbolTable);
9575             BuiltInVariable("gl_CoreIDARM",    EbvCoreIDARM, symbolTable);
9576             BuiltInVariable("gl_CoreMaxIDARM", EbvCoreMaxIDARM, symbolTable);
9577             BuiltInVariable("gl_WarpIDARM",    EbvWarpIDARM, symbolTable);
9578             BuiltInVariable("gl_WarpMaxIDARM", EbvWarpMaxIDARM, symbolTable);
9579         }
9580 
9581         if ((profile == EEsProfile && version >= 310) ||
9582             (profile != EEsProfile && version >= 450)) {
9583             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9584             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9585             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9586             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9587         }
9588 
9589         // Builtins for GL_NV_displacment_micromap
9590         if ((profile != EEsProfile && version >= 460)) {
9591             symbolTable.setFunctionExtensions("fetchMicroTriangleVertexPositionNV", 1, &E_GL_NV_displacement_micromap);
9592             symbolTable.setFunctionExtensions("fetchMicroTriangleVertexBarycentricNV", 1, &E_GL_NV_displacement_micromap);
9593         }
9594 
9595         break;
9596 
9597     case EShLangTask:
9598         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
9599             symbolTable.setVariableExtensions("gl_TaskCountNV",          1, &E_GL_NV_mesh_shader);
9600             symbolTable.setVariableExtensions("gl_MeshViewCountNV",      1, &E_GL_NV_mesh_shader);
9601             symbolTable.setVariableExtensions("gl_MeshViewIndicesNV",    1, &E_GL_NV_mesh_shader);
9602             if (profile != EEsProfile) {
9603                 symbolTable.setVariableExtensions("gl_WorkGroupSize",        Num_AEP_mesh_shader, AEP_mesh_shader);
9604                 symbolTable.setVariableExtensions("gl_WorkGroupID",          Num_AEP_mesh_shader, AEP_mesh_shader);
9605                 symbolTable.setVariableExtensions("gl_LocalInvocationID",    Num_AEP_mesh_shader, AEP_mesh_shader);
9606                 symbolTable.setVariableExtensions("gl_GlobalInvocationID",   Num_AEP_mesh_shader, AEP_mesh_shader);
9607                 symbolTable.setVariableExtensions("gl_LocalInvocationIndex", Num_AEP_mesh_shader, AEP_mesh_shader);
9608             } else {
9609                 symbolTable.setVariableExtensions("gl_WorkGroupSize",        1, &E_GL_NV_mesh_shader);
9610                 symbolTable.setVariableExtensions("gl_WorkGroupID",          1, &E_GL_NV_mesh_shader);
9611                 symbolTable.setVariableExtensions("gl_LocalInvocationID",    1, &E_GL_NV_mesh_shader);
9612                 symbolTable.setVariableExtensions("gl_GlobalInvocationID",   1, &E_GL_NV_mesh_shader);
9613                 symbolTable.setVariableExtensions("gl_LocalInvocationIndex", 1, &E_GL_NV_mesh_shader);
9614             }
9615 
9616             BuiltInVariable("gl_TaskCountNV",          EbvTaskCountNV,          symbolTable);
9617             BuiltInVariable("gl_WorkGroupSize",        EbvWorkGroupSize,        symbolTable);
9618             BuiltInVariable("gl_WorkGroupID",          EbvWorkGroupId,          symbolTable);
9619             BuiltInVariable("gl_LocalInvocationID",    EbvLocalInvocationId,    symbolTable);
9620             BuiltInVariable("gl_GlobalInvocationID",   EbvGlobalInvocationId,   symbolTable);
9621             BuiltInVariable("gl_LocalInvocationIndex", EbvLocalInvocationIndex, symbolTable);
9622             BuiltInVariable("gl_MeshViewCountNV",      EbvMeshViewCountNV,      symbolTable);
9623             BuiltInVariable("gl_MeshViewIndicesNV",    EbvMeshViewIndicesNV,    symbolTable);
9624 
9625             symbolTable.setVariableExtensions("gl_MaxTaskWorkGroupSizeNV", 1, &E_GL_NV_mesh_shader);
9626             symbolTable.setVariableExtensions("gl_MaxMeshViewCountNV",     1, &E_GL_NV_mesh_shader);
9627 
9628             if (profile != EEsProfile) {
9629                 symbolTable.setFunctionExtensions("barrier",                   Num_AEP_mesh_shader, AEP_mesh_shader);
9630                 symbolTable.setFunctionExtensions("memoryBarrierShared",       Num_AEP_mesh_shader, AEP_mesh_shader);
9631                 symbolTable.setFunctionExtensions("groupMemoryBarrier",        Num_AEP_mesh_shader, AEP_mesh_shader);
9632             } else {
9633                 symbolTable.setFunctionExtensions("barrier",                   1, &E_GL_NV_mesh_shader);
9634                 symbolTable.setFunctionExtensions("memoryBarrierShared",       1, &E_GL_NV_mesh_shader);
9635                 symbolTable.setFunctionExtensions("groupMemoryBarrier",        1, &E_GL_NV_mesh_shader);
9636             }
9637         }
9638 
9639         if (profile != EEsProfile && version >= 450) {
9640             // GL_EXT_mesh_shader
9641             symbolTable.setFunctionExtensions("EmitMeshTasksEXT",          1, &E_GL_EXT_mesh_shader);
9642             symbolTable.setVariableExtensions("gl_NumWorkGroups",        1, &E_GL_EXT_mesh_shader);
9643             BuiltInVariable("gl_NumWorkGroups",        EbvNumWorkGroups,        symbolTable);
9644 
9645             // GL_EXT_device_group
9646             symbolTable.setVariableExtensions("gl_DeviceIndex", 1, &E_GL_EXT_device_group);
9647             BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
9648 
9649             // GL_ARB_shader_draw_parameters
9650             symbolTable.setVariableExtensions("gl_DrawIDARB", 1, &E_GL_ARB_shader_draw_parameters);
9651             BuiltInVariable("gl_DrawIDARB", EbvDrawId, symbolTable);
9652             if (version >= 460) {
9653                 BuiltInVariable("gl_DrawID", EbvDrawId, symbolTable);
9654             }
9655 
9656             // GL_ARB_shader_ballot
9657             symbolTable.setVariableExtensions("gl_SubGroupSizeARB",       1, &E_GL_ARB_shader_ballot);
9658             symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
9659             symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB",     1, &E_GL_ARB_shader_ballot);
9660             symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB",     1, &E_GL_ARB_shader_ballot);
9661             symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB",     1, &E_GL_ARB_shader_ballot);
9662             symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB",     1, &E_GL_ARB_shader_ballot);
9663             symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB",     1, &E_GL_ARB_shader_ballot);
9664 
9665             BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
9666             BuiltInVariable("gl_SubGroupEqMaskARB",     EbvSubGroupEqMask,     symbolTable);
9667             BuiltInVariable("gl_SubGroupGeMaskARB",     EbvSubGroupGeMask,     symbolTable);
9668             BuiltInVariable("gl_SubGroupGtMaskARB",     EbvSubGroupGtMask,     symbolTable);
9669             BuiltInVariable("gl_SubGroupLeMaskARB",     EbvSubGroupLeMask,     symbolTable);
9670             BuiltInVariable("gl_SubGroupLtMaskARB",     EbvSubGroupLtMask,     symbolTable);
9671 
9672             if (spvVersion.vulkan > 0) {
9673                 // Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
9674                 SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
9675                 if (language == EShLangFragment)
9676                     ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
9677             }
9678             else
9679                 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
9680         }
9681 
9682         // GL_KHR_shader_subgroup
9683         if ((profile == EEsProfile && version >= 310) ||
9684             (profile != EEsProfile && version >= 140)) {
9685             symbolTable.setVariableExtensions("gl_NumSubgroups",         1, &E_GL_KHR_shader_subgroup_basic);
9686             symbolTable.setVariableExtensions("gl_SubgroupID",           1, &E_GL_KHR_shader_subgroup_basic);
9687             symbolTable.setVariableExtensions("gl_SubgroupSize",         1, &E_GL_KHR_shader_subgroup_basic);
9688             symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
9689             symbolTable.setVariableExtensions("gl_SubgroupEqMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9690             symbolTable.setVariableExtensions("gl_SubgroupGeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9691             symbolTable.setVariableExtensions("gl_SubgroupGtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9692             symbolTable.setVariableExtensions("gl_SubgroupLeMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9693             symbolTable.setVariableExtensions("gl_SubgroupLtMask",       1, &E_GL_KHR_shader_subgroup_ballot);
9694 
9695             BuiltInVariable("gl_NumSubgroups",         EbvNumSubgroups,        symbolTable);
9696             BuiltInVariable("gl_SubgroupID",           EbvSubgroupID,          symbolTable);
9697             BuiltInVariable("gl_SubgroupSize",         EbvSubgroupSize2,       symbolTable);
9698             BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
9699             BuiltInVariable("gl_SubgroupEqMask",       EbvSubgroupEqMask2,     symbolTable);
9700             BuiltInVariable("gl_SubgroupGeMask",       EbvSubgroupGeMask2,     symbolTable);
9701             BuiltInVariable("gl_SubgroupGtMask",       EbvSubgroupGtMask2,     symbolTable);
9702             BuiltInVariable("gl_SubgroupLeMask",       EbvSubgroupLeMask2,     symbolTable);
9703             BuiltInVariable("gl_SubgroupLtMask",       EbvSubgroupLtMask2,     symbolTable);
9704 
9705             symbolTable.setFunctionExtensions("subgroupMemoryBarrierShared", 1, &E_GL_KHR_shader_subgroup_basic);
9706 
9707             // GL_NV_shader_sm_builtins
9708             symbolTable.setVariableExtensions("gl_WarpsPerSMNV",         1, &E_GL_NV_shader_sm_builtins);
9709             symbolTable.setVariableExtensions("gl_SMCountNV",            1, &E_GL_NV_shader_sm_builtins);
9710             symbolTable.setVariableExtensions("gl_WarpIDNV",             1, &E_GL_NV_shader_sm_builtins);
9711             symbolTable.setVariableExtensions("gl_SMIDNV",               1, &E_GL_NV_shader_sm_builtins);
9712             BuiltInVariable("gl_WarpsPerSMNV",          EbvWarpsPerSM,      symbolTable);
9713             BuiltInVariable("gl_SMCountNV",             EbvSMCount,         symbolTable);
9714             BuiltInVariable("gl_WarpIDNV",              EbvWarpID,          symbolTable);
9715             BuiltInVariable("gl_SMIDNV",                EbvSMID,            symbolTable);
9716 
9717             // GL_ARM_shader_core_builtins
9718             symbolTable.setVariableExtensions("gl_CoreCountARM", 1, &E_GL_ARM_shader_core_builtins);
9719             symbolTable.setVariableExtensions("gl_CoreIDARM",    1, &E_GL_ARM_shader_core_builtins);
9720             symbolTable.setVariableExtensions("gl_CoreMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
9721             symbolTable.setVariableExtensions("gl_WarpIDARM",    1, &E_GL_ARM_shader_core_builtins);
9722             symbolTable.setVariableExtensions("gl_WarpMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
9723 
9724             BuiltInVariable("gl_CoreCountARM", EbvCoreCountARM, symbolTable);
9725             BuiltInVariable("gl_CoreIDARM",    EbvCoreIDARM, symbolTable);
9726             BuiltInVariable("gl_CoreMaxIDARM", EbvCoreMaxIDARM, symbolTable);
9727             BuiltInVariable("gl_WarpIDARM",    EbvWarpIDARM, symbolTable);
9728             BuiltInVariable("gl_WarpMaxIDARM", EbvWarpMaxIDARM, symbolTable);
9729         }
9730         if ((profile == EEsProfile && version >= 310) ||
9731             (profile != EEsProfile && version >= 450)) {
9732             symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9733             symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9734             symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9735             symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
9736         }
9737         break;
9738 
9739     default:
9740         assert(false && "Language not supported");
9741         break;
9742     }
9743 
9744     //
9745     // Next, identify which built-ins have a mapping to an operator.
9746     // If PureOperatorBuiltins is false, those that are not identified as such are
9747     // expected to be resolved through a library of functions, versus as
9748     // operations.
9749     //
9750 
9751     relateTabledBuiltins(version, profile, spvVersion, language, symbolTable);
9752 
9753     symbolTable.relateToOperator("doubleBitsToInt64",  EOpDoubleBitsToInt64);
9754     symbolTable.relateToOperator("doubleBitsToUint64", EOpDoubleBitsToUint64);
9755     symbolTable.relateToOperator("int64BitsToDouble",  EOpInt64BitsToDouble);
9756     symbolTable.relateToOperator("uint64BitsToDouble", EOpUint64BitsToDouble);
9757     symbolTable.relateToOperator("halfBitsToInt16",  EOpFloat16BitsToInt16);
9758     symbolTable.relateToOperator("halfBitsToUint16", EOpFloat16BitsToUint16);
9759     symbolTable.relateToOperator("float16BitsToInt16",  EOpFloat16BitsToInt16);
9760     symbolTable.relateToOperator("float16BitsToUint16", EOpFloat16BitsToUint16);
9761     symbolTable.relateToOperator("int16BitsToFloat16",  EOpInt16BitsToFloat16);
9762     symbolTable.relateToOperator("uint16BitsToFloat16", EOpUint16BitsToFloat16);
9763 
9764     symbolTable.relateToOperator("int16BitsToHalf",  EOpInt16BitsToFloat16);
9765     symbolTable.relateToOperator("uint16BitsToHalf", EOpUint16BitsToFloat16);
9766 
9767     symbolTable.relateToOperator("packSnorm4x8",    EOpPackSnorm4x8);
9768     symbolTable.relateToOperator("unpackSnorm4x8",  EOpUnpackSnorm4x8);
9769     symbolTable.relateToOperator("packUnorm4x8",    EOpPackUnorm4x8);
9770     symbolTable.relateToOperator("unpackUnorm4x8",  EOpUnpackUnorm4x8);
9771 
9772     symbolTable.relateToOperator("packDouble2x32",    EOpPackDouble2x32);
9773     symbolTable.relateToOperator("unpackDouble2x32",  EOpUnpackDouble2x32);
9774 
9775     symbolTable.relateToOperator("packInt2x32",     EOpPackInt2x32);
9776     symbolTable.relateToOperator("unpackInt2x32",   EOpUnpackInt2x32);
9777     symbolTable.relateToOperator("packUint2x32",    EOpPackUint2x32);
9778     symbolTable.relateToOperator("unpackUint2x32",  EOpUnpackUint2x32);
9779 
9780     symbolTable.relateToOperator("packInt2x16",     EOpPackInt2x16);
9781     symbolTable.relateToOperator("unpackInt2x16",   EOpUnpackInt2x16);
9782     symbolTable.relateToOperator("packUint2x16",    EOpPackUint2x16);
9783     symbolTable.relateToOperator("unpackUint2x16",  EOpUnpackUint2x16);
9784 
9785     symbolTable.relateToOperator("packInt4x16",     EOpPackInt4x16);
9786     symbolTable.relateToOperator("unpackInt4x16",   EOpUnpackInt4x16);
9787     symbolTable.relateToOperator("packUint4x16",    EOpPackUint4x16);
9788     symbolTable.relateToOperator("unpackUint4x16",  EOpUnpackUint4x16);
9789     symbolTable.relateToOperator("packFloat2x16",   EOpPackFloat2x16);
9790     symbolTable.relateToOperator("unpackFloat2x16", EOpUnpackFloat2x16);
9791 
9792     symbolTable.relateToOperator("pack16",          EOpPack16);
9793     symbolTable.relateToOperator("pack32",          EOpPack32);
9794     symbolTable.relateToOperator("pack64",          EOpPack64);
9795 
9796     symbolTable.relateToOperator("unpack32",        EOpUnpack32);
9797     symbolTable.relateToOperator("unpack16",        EOpUnpack16);
9798     symbolTable.relateToOperator("unpack8",         EOpUnpack8);
9799 
9800     symbolTable.relateToOperator("controlBarrier",             EOpBarrier);
9801     symbolTable.relateToOperator("memoryBarrierAtomicCounter", EOpMemoryBarrierAtomicCounter);
9802     symbolTable.relateToOperator("memoryBarrierImage",         EOpMemoryBarrierImage);
9803 
9804     if (spvVersion.vulkanRelaxed) {
9805         //
9806         // functions signature have been replaced to take uint operations on buffer variables
9807         // remap atomic counter functions to atomic operations
9808         //
9809         symbolTable.relateToOperator("memoryBarrierAtomicCounter", EOpMemoryBarrierBuffer);
9810     }
9811 
9812     symbolTable.relateToOperator("atomicLoad",     EOpAtomicLoad);
9813     symbolTable.relateToOperator("atomicStore",    EOpAtomicStore);
9814 
9815     symbolTable.relateToOperator("atomicCounterIncrement", EOpAtomicCounterIncrement);
9816     symbolTable.relateToOperator("atomicCounterDecrement", EOpAtomicCounterDecrement);
9817     symbolTable.relateToOperator("atomicCounter",          EOpAtomicCounter);
9818 
9819     if (spvVersion.vulkanRelaxed) {
9820         //
9821         // functions signature have been replaced to take uint operations
9822         // remap atomic counter functions to atomic operations
9823         //
9824         // these atomic counter functions do not match signatures of glsl
9825         // atomic functions, so they will be remapped to semantically
9826         // equivalent functions in the parser
9827         //
9828         symbolTable.relateToOperator("atomicCounterIncrement", EOpNull);
9829         symbolTable.relateToOperator("atomicCounterDecrement", EOpNull);
9830         symbolTable.relateToOperator("atomicCounter", EOpNull);
9831     }
9832 
9833     symbolTable.relateToOperator("clockARB",     EOpReadClockSubgroupKHR);
9834     symbolTable.relateToOperator("clock2x32ARB", EOpReadClockSubgroupKHR);
9835 
9836     symbolTable.relateToOperator("clockRealtimeEXT",     EOpReadClockDeviceKHR);
9837     symbolTable.relateToOperator("clockRealtime2x32EXT", EOpReadClockDeviceKHR);
9838 
9839     if (profile != EEsProfile && version == 450) {
9840         symbolTable.relateToOperator("atomicCounterAddARB",      EOpAtomicCounterAdd);
9841         symbolTable.relateToOperator("atomicCounterSubtractARB", EOpAtomicCounterSubtract);
9842         symbolTable.relateToOperator("atomicCounterMinARB",      EOpAtomicCounterMin);
9843         symbolTable.relateToOperator("atomicCounterMaxARB",      EOpAtomicCounterMax);
9844         symbolTable.relateToOperator("atomicCounterAndARB",      EOpAtomicCounterAnd);
9845         symbolTable.relateToOperator("atomicCounterOrARB",       EOpAtomicCounterOr);
9846         symbolTable.relateToOperator("atomicCounterXorARB",      EOpAtomicCounterXor);
9847         symbolTable.relateToOperator("atomicCounterExchangeARB", EOpAtomicCounterExchange);
9848         symbolTable.relateToOperator("atomicCounterCompSwapARB", EOpAtomicCounterCompSwap);
9849     }
9850 
9851     if (profile != EEsProfile && version >= 460) {
9852         symbolTable.relateToOperator("atomicCounterAdd",      EOpAtomicCounterAdd);
9853         symbolTable.relateToOperator("atomicCounterSubtract", EOpAtomicCounterSubtract);
9854         symbolTable.relateToOperator("atomicCounterMin",      EOpAtomicCounterMin);
9855         symbolTable.relateToOperator("atomicCounterMax",      EOpAtomicCounterMax);
9856         symbolTable.relateToOperator("atomicCounterAnd",      EOpAtomicCounterAnd);
9857         symbolTable.relateToOperator("atomicCounterOr",       EOpAtomicCounterOr);
9858         symbolTable.relateToOperator("atomicCounterXor",      EOpAtomicCounterXor);
9859         symbolTable.relateToOperator("atomicCounterExchange", EOpAtomicCounterExchange);
9860         symbolTable.relateToOperator("atomicCounterCompSwap", EOpAtomicCounterCompSwap);
9861     }
9862 
9863     if (spvVersion.vulkanRelaxed) {
9864         //
9865         // functions signature have been replaced to take 'uint' instead of 'atomic_uint'
9866         // remap atomic counter functions to non-counter atomic ops so
9867         // functions act as aliases to non-counter atomic ops
9868         //
9869         symbolTable.relateToOperator("atomicCounterAdd", EOpAtomicAdd);
9870         symbolTable.relateToOperator("atomicCounterSubtract", EOpAtomicSubtract);
9871         symbolTable.relateToOperator("atomicCounterMin", EOpAtomicMin);
9872         symbolTable.relateToOperator("atomicCounterMax", EOpAtomicMax);
9873         symbolTable.relateToOperator("atomicCounterAnd", EOpAtomicAnd);
9874         symbolTable.relateToOperator("atomicCounterOr", EOpAtomicOr);
9875         symbolTable.relateToOperator("atomicCounterXor", EOpAtomicXor);
9876         symbolTable.relateToOperator("atomicCounterExchange", EOpAtomicExchange);
9877         symbolTable.relateToOperator("atomicCounterCompSwap", EOpAtomicCompSwap);
9878     }
9879 
9880     symbolTable.relateToOperator("fma",               EOpFma);
9881     symbolTable.relateToOperator("frexp",             EOpFrexp);
9882     symbolTable.relateToOperator("ldexp",             EOpLdexp);
9883     symbolTable.relateToOperator("uaddCarry",         EOpAddCarry);
9884     symbolTable.relateToOperator("usubBorrow",        EOpSubBorrow);
9885     symbolTable.relateToOperator("umulExtended",      EOpUMulExtended);
9886     symbolTable.relateToOperator("imulExtended",      EOpIMulExtended);
9887     symbolTable.relateToOperator("bitfieldExtract",   EOpBitfieldExtract);
9888     symbolTable.relateToOperator("bitfieldInsert",    EOpBitfieldInsert);
9889     symbolTable.relateToOperator("bitfieldReverse",   EOpBitFieldReverse);
9890     symbolTable.relateToOperator("bitCount",          EOpBitCount);
9891     symbolTable.relateToOperator("findLSB",           EOpFindLSB);
9892     symbolTable.relateToOperator("findMSB",           EOpFindMSB);
9893 
9894     symbolTable.relateToOperator("helperInvocationEXT",  EOpIsHelperInvocation);
9895 
9896     symbolTable.relateToOperator("countLeadingZeros",  EOpCountLeadingZeros);
9897     symbolTable.relateToOperator("countTrailingZeros", EOpCountTrailingZeros);
9898     symbolTable.relateToOperator("absoluteDifference", EOpAbsDifference);
9899     symbolTable.relateToOperator("addSaturate",        EOpAddSaturate);
9900     symbolTable.relateToOperator("subtractSaturate",   EOpSubSaturate);
9901     symbolTable.relateToOperator("average",            EOpAverage);
9902     symbolTable.relateToOperator("averageRounded",     EOpAverageRounded);
9903     symbolTable.relateToOperator("multiply32x16",      EOpMul32x16);
9904     symbolTable.relateToOperator("debugPrintfEXT",     EOpDebugPrintf);
9905     symbolTable.relateToOperator("assumeEXT",          EOpAssumeEXT);
9906     symbolTable.relateToOperator("expectEXT",          EOpExpectEXT);
9907 
9908 
9909     if (PureOperatorBuiltins) {
9910         symbolTable.relateToOperator("imageSize",               EOpImageQuerySize);
9911         symbolTable.relateToOperator("imageSamples",            EOpImageQuerySamples);
9912         symbolTable.relateToOperator("imageLoad",               EOpImageLoad);
9913         symbolTable.relateToOperator("imageStore",              EOpImageStore);
9914         symbolTable.relateToOperator("imageAtomicAdd",          EOpImageAtomicAdd);
9915         symbolTable.relateToOperator("imageAtomicMin",          EOpImageAtomicMin);
9916         symbolTable.relateToOperator("imageAtomicMax",          EOpImageAtomicMax);
9917         symbolTable.relateToOperator("imageAtomicAnd",          EOpImageAtomicAnd);
9918         symbolTable.relateToOperator("imageAtomicOr",           EOpImageAtomicOr);
9919         symbolTable.relateToOperator("imageAtomicXor",          EOpImageAtomicXor);
9920         symbolTable.relateToOperator("imageAtomicExchange",     EOpImageAtomicExchange);
9921         symbolTable.relateToOperator("imageAtomicCompSwap",     EOpImageAtomicCompSwap);
9922         symbolTable.relateToOperator("imageAtomicLoad",         EOpImageAtomicLoad);
9923         symbolTable.relateToOperator("imageAtomicStore",        EOpImageAtomicStore);
9924 
9925         symbolTable.relateToOperator("subpassLoad",             EOpSubpassLoad);
9926         symbolTable.relateToOperator("subpassLoadMS",           EOpSubpassLoadMS);
9927 
9928         symbolTable.relateToOperator("textureGather",           EOpTextureGather);
9929         symbolTable.relateToOperator("textureGatherOffset",     EOpTextureGatherOffset);
9930         symbolTable.relateToOperator("textureGatherOffsets",    EOpTextureGatherOffsets);
9931 
9932         symbolTable.relateToOperator("noise1", EOpNoise);
9933         symbolTable.relateToOperator("noise2", EOpNoise);
9934         symbolTable.relateToOperator("noise3", EOpNoise);
9935         symbolTable.relateToOperator("noise4", EOpNoise);
9936 
9937         symbolTable.relateToOperator("textureFootprintNV",          EOpImageSampleFootprintNV);
9938         symbolTable.relateToOperator("textureFootprintClampNV",     EOpImageSampleFootprintClampNV);
9939         symbolTable.relateToOperator("textureFootprintLodNV",       EOpImageSampleFootprintLodNV);
9940         symbolTable.relateToOperator("textureFootprintGradNV",      EOpImageSampleFootprintGradNV);
9941         symbolTable.relateToOperator("textureFootprintGradClampNV", EOpImageSampleFootprintGradClampNV);
9942 
9943         if (spvVersion.spv == 0 && IncludeLegacy(version, profile, spvVersion))
9944             symbolTable.relateToOperator("ftransform", EOpFtransform);
9945 
9946         if (spvVersion.spv == 0 && (IncludeLegacy(version, profile, spvVersion) ||
9947             (profile == EEsProfile && version == 100))) {
9948 
9949             symbolTable.relateToOperator("texture1D",                EOpTexture);
9950             symbolTable.relateToOperator("texture1DGradARB",         EOpTextureGrad);
9951             symbolTable.relateToOperator("texture1DProj",            EOpTextureProj);
9952             symbolTable.relateToOperator("texture1DProjGradARB",     EOpTextureProjGrad);
9953             symbolTable.relateToOperator("texture1DLod",             EOpTextureLod);
9954             symbolTable.relateToOperator("texture1DProjLod",         EOpTextureProjLod);
9955 
9956             symbolTable.relateToOperator("texture2DRect",            EOpTexture);
9957             symbolTable.relateToOperator("texture2DRectProj",        EOpTextureProj);
9958             symbolTable.relateToOperator("texture2DRectGradARB",     EOpTextureGrad);
9959             symbolTable.relateToOperator("texture2DRectProjGradARB", EOpTextureProjGrad);
9960             symbolTable.relateToOperator("shadow2DRect",             EOpTexture);
9961             symbolTable.relateToOperator("shadow2DRectProj",         EOpTextureProj);
9962             symbolTable.relateToOperator("shadow2DRectGradARB",      EOpTextureGrad);
9963             symbolTable.relateToOperator("shadow2DRectProjGradARB",  EOpTextureProjGrad);
9964 
9965             symbolTable.relateToOperator("texture2D",                EOpTexture);
9966             symbolTable.relateToOperator("texture2DProj",            EOpTextureProj);
9967             symbolTable.relateToOperator("texture2DGradEXT",         EOpTextureGrad);
9968             symbolTable.relateToOperator("texture2DGradARB",         EOpTextureGrad);
9969             symbolTable.relateToOperator("texture2DProjGradEXT",     EOpTextureProjGrad);
9970             symbolTable.relateToOperator("texture2DProjGradARB",     EOpTextureProjGrad);
9971             symbolTable.relateToOperator("texture2DLod",             EOpTextureLod);
9972             symbolTable.relateToOperator("texture2DLodEXT",          EOpTextureLod);
9973             symbolTable.relateToOperator("texture2DProjLod",         EOpTextureProjLod);
9974             symbolTable.relateToOperator("texture2DProjLodEXT",      EOpTextureProjLod);
9975 
9976             symbolTable.relateToOperator("texture3D",                EOpTexture);
9977             symbolTable.relateToOperator("texture3DGradARB",         EOpTextureGrad);
9978             symbolTable.relateToOperator("texture3DProj",            EOpTextureProj);
9979             symbolTable.relateToOperator("texture3DProjGradARB",     EOpTextureProjGrad);
9980             symbolTable.relateToOperator("texture3DLod",             EOpTextureLod);
9981             symbolTable.relateToOperator("texture3DProjLod",         EOpTextureProjLod);
9982             symbolTable.relateToOperator("textureCube",              EOpTexture);
9983             symbolTable.relateToOperator("textureCubeGradEXT",       EOpTextureGrad);
9984             symbolTable.relateToOperator("textureCubeGradARB",       EOpTextureGrad);
9985             symbolTable.relateToOperator("textureCubeLod",           EOpTextureLod);
9986             symbolTable.relateToOperator("textureCubeLodEXT",        EOpTextureLod);
9987             symbolTable.relateToOperator("shadow1D",                 EOpTexture);
9988             symbolTable.relateToOperator("shadow1DGradARB",          EOpTextureGrad);
9989             symbolTable.relateToOperator("shadow2D",                 EOpTexture);
9990             symbolTable.relateToOperator("shadow2DGradARB",          EOpTextureGrad);
9991             symbolTable.relateToOperator("shadow1DProj",             EOpTextureProj);
9992             symbolTable.relateToOperator("shadow2DProj",             EOpTextureProj);
9993             symbolTable.relateToOperator("shadow1DProjGradARB",      EOpTextureProjGrad);
9994             symbolTable.relateToOperator("shadow2DProjGradARB",      EOpTextureProjGrad);
9995             symbolTable.relateToOperator("shadow1DLod",              EOpTextureLod);
9996             symbolTable.relateToOperator("shadow2DLod",              EOpTextureLod);
9997             symbolTable.relateToOperator("shadow1DProjLod",          EOpTextureProjLod);
9998             symbolTable.relateToOperator("shadow2DProjLod",          EOpTextureProjLod);
9999         }
10000 
10001         if (profile != EEsProfile) {
10002             symbolTable.relateToOperator("sparseTextureARB",                EOpSparseTexture);
10003             symbolTable.relateToOperator("sparseTextureLodARB",             EOpSparseTextureLod);
10004             symbolTable.relateToOperator("sparseTextureOffsetARB",          EOpSparseTextureOffset);
10005             symbolTable.relateToOperator("sparseTexelFetchARB",             EOpSparseTextureFetch);
10006             symbolTable.relateToOperator("sparseTexelFetchOffsetARB",       EOpSparseTextureFetchOffset);
10007             symbolTable.relateToOperator("sparseTextureLodOffsetARB",       EOpSparseTextureLodOffset);
10008             symbolTable.relateToOperator("sparseTextureGradARB",            EOpSparseTextureGrad);
10009             symbolTable.relateToOperator("sparseTextureGradOffsetARB",      EOpSparseTextureGradOffset);
10010             symbolTable.relateToOperator("sparseTextureGatherARB",          EOpSparseTextureGather);
10011             symbolTable.relateToOperator("sparseTextureGatherOffsetARB",    EOpSparseTextureGatherOffset);
10012             symbolTable.relateToOperator("sparseTextureGatherOffsetsARB",   EOpSparseTextureGatherOffsets);
10013             symbolTable.relateToOperator("sparseImageLoadARB",              EOpSparseImageLoad);
10014             symbolTable.relateToOperator("sparseTexelsResidentARB",         EOpSparseTexelsResident);
10015 
10016             symbolTable.relateToOperator("sparseTextureClampARB",           EOpSparseTextureClamp);
10017             symbolTable.relateToOperator("sparseTextureOffsetClampARB",     EOpSparseTextureOffsetClamp);
10018             symbolTable.relateToOperator("sparseTextureGradClampARB",       EOpSparseTextureGradClamp);
10019             symbolTable.relateToOperator("sparseTextureGradOffsetClampARB", EOpSparseTextureGradOffsetClamp);
10020             symbolTable.relateToOperator("textureClampARB",                 EOpTextureClamp);
10021             symbolTable.relateToOperator("textureOffsetClampARB",           EOpTextureOffsetClamp);
10022             symbolTable.relateToOperator("textureGradClampARB",             EOpTextureGradClamp);
10023             symbolTable.relateToOperator("textureGradOffsetClampARB",       EOpTextureGradOffsetClamp);
10024 
10025             symbolTable.relateToOperator("ballotARB",                       EOpBallot);
10026             symbolTable.relateToOperator("readInvocationARB",               EOpReadInvocation);
10027             symbolTable.relateToOperator("readFirstInvocationARB",          EOpReadFirstInvocation);
10028 
10029             if (version >= 430) {
10030                 symbolTable.relateToOperator("anyInvocationARB",            EOpAnyInvocation);
10031                 symbolTable.relateToOperator("allInvocationsARB",           EOpAllInvocations);
10032                 symbolTable.relateToOperator("allInvocationsEqualARB",      EOpAllInvocationsEqual);
10033             }
10034             if (version >= 460) {
10035                 symbolTable.relateToOperator("anyInvocation",               EOpAnyInvocation);
10036                 symbolTable.relateToOperator("allInvocations",              EOpAllInvocations);
10037                 symbolTable.relateToOperator("allInvocationsEqual",         EOpAllInvocationsEqual);
10038             }
10039             symbolTable.relateToOperator("minInvocationsAMD",                           EOpMinInvocations);
10040             symbolTable.relateToOperator("maxInvocationsAMD",                           EOpMaxInvocations);
10041             symbolTable.relateToOperator("addInvocationsAMD",                           EOpAddInvocations);
10042             symbolTable.relateToOperator("minInvocationsNonUniformAMD",                 EOpMinInvocationsNonUniform);
10043             symbolTable.relateToOperator("maxInvocationsNonUniformAMD",                 EOpMaxInvocationsNonUniform);
10044             symbolTable.relateToOperator("addInvocationsNonUniformAMD",                 EOpAddInvocationsNonUniform);
10045             symbolTable.relateToOperator("minInvocationsInclusiveScanAMD",              EOpMinInvocationsInclusiveScan);
10046             symbolTable.relateToOperator("maxInvocationsInclusiveScanAMD",              EOpMaxInvocationsInclusiveScan);
10047             symbolTable.relateToOperator("addInvocationsInclusiveScanAMD",              EOpAddInvocationsInclusiveScan);
10048             symbolTable.relateToOperator("minInvocationsInclusiveScanNonUniformAMD",    EOpMinInvocationsInclusiveScanNonUniform);
10049             symbolTable.relateToOperator("maxInvocationsInclusiveScanNonUniformAMD",    EOpMaxInvocationsInclusiveScanNonUniform);
10050             symbolTable.relateToOperator("addInvocationsInclusiveScanNonUniformAMD",    EOpAddInvocationsInclusiveScanNonUniform);
10051             symbolTable.relateToOperator("minInvocationsExclusiveScanAMD",              EOpMinInvocationsExclusiveScan);
10052             symbolTable.relateToOperator("maxInvocationsExclusiveScanAMD",              EOpMaxInvocationsExclusiveScan);
10053             symbolTable.relateToOperator("addInvocationsExclusiveScanAMD",              EOpAddInvocationsExclusiveScan);
10054             symbolTable.relateToOperator("minInvocationsExclusiveScanNonUniformAMD",    EOpMinInvocationsExclusiveScanNonUniform);
10055             symbolTable.relateToOperator("maxInvocationsExclusiveScanNonUniformAMD",    EOpMaxInvocationsExclusiveScanNonUniform);
10056             symbolTable.relateToOperator("addInvocationsExclusiveScanNonUniformAMD",    EOpAddInvocationsExclusiveScanNonUniform);
10057             symbolTable.relateToOperator("swizzleInvocationsAMD",                       EOpSwizzleInvocations);
10058             symbolTable.relateToOperator("swizzleInvocationsMaskedAMD",                 EOpSwizzleInvocationsMasked);
10059             symbolTable.relateToOperator("writeInvocationAMD",                          EOpWriteInvocation);
10060             symbolTable.relateToOperator("mbcntAMD",                                    EOpMbcnt);
10061 
10062             symbolTable.relateToOperator("min3",    EOpMin3);
10063             symbolTable.relateToOperator("max3",    EOpMax3);
10064             symbolTable.relateToOperator("mid3",    EOpMid3);
10065 
10066             symbolTable.relateToOperator("cubeFaceIndexAMD",    EOpCubeFaceIndex);
10067             symbolTable.relateToOperator("cubeFaceCoordAMD",    EOpCubeFaceCoord);
10068             symbolTable.relateToOperator("timeAMD",             EOpTime);
10069 
10070             symbolTable.relateToOperator("textureGatherLodAMD",                 EOpTextureGatherLod);
10071             symbolTable.relateToOperator("textureGatherLodOffsetAMD",           EOpTextureGatherLodOffset);
10072             symbolTable.relateToOperator("textureGatherLodOffsetsAMD",          EOpTextureGatherLodOffsets);
10073             symbolTable.relateToOperator("sparseTextureGatherLodAMD",           EOpSparseTextureGatherLod);
10074             symbolTable.relateToOperator("sparseTextureGatherLodOffsetAMD",     EOpSparseTextureGatherLodOffset);
10075             symbolTable.relateToOperator("sparseTextureGatherLodOffsetsAMD",    EOpSparseTextureGatherLodOffsets);
10076 
10077             symbolTable.relateToOperator("imageLoadLodAMD",                     EOpImageLoadLod);
10078             symbolTable.relateToOperator("imageStoreLodAMD",                    EOpImageStoreLod);
10079             symbolTable.relateToOperator("sparseImageLoadLodAMD",               EOpSparseImageLoadLod);
10080 
10081             symbolTable.relateToOperator("fragmentMaskFetchAMD",                EOpFragmentMaskFetch);
10082             symbolTable.relateToOperator("fragmentFetchAMD",                    EOpFragmentFetch);
10083         }
10084 
10085         // GL_KHR_shader_subgroup
10086         if ((profile == EEsProfile && version >= 310) ||
10087             (profile != EEsProfile && version >= 140)) {
10088             symbolTable.relateToOperator("subgroupBarrier",                 EOpSubgroupBarrier);
10089             symbolTable.relateToOperator("subgroupMemoryBarrier",           EOpSubgroupMemoryBarrier);
10090             symbolTable.relateToOperator("subgroupMemoryBarrierBuffer",     EOpSubgroupMemoryBarrierBuffer);
10091             symbolTable.relateToOperator("subgroupMemoryBarrierImage",      EOpSubgroupMemoryBarrierImage);
10092             symbolTable.relateToOperator("subgroupElect",                   EOpSubgroupElect);
10093             symbolTable.relateToOperator("subgroupAll",                     EOpSubgroupAll);
10094             symbolTable.relateToOperator("subgroupAny",                     EOpSubgroupAny);
10095             symbolTable.relateToOperator("subgroupAllEqual",                EOpSubgroupAllEqual);
10096             symbolTable.relateToOperator("subgroupBroadcast",               EOpSubgroupBroadcast);
10097             symbolTable.relateToOperator("subgroupBroadcastFirst",          EOpSubgroupBroadcastFirst);
10098             symbolTable.relateToOperator("subgroupBallot",                  EOpSubgroupBallot);
10099             symbolTable.relateToOperator("subgroupInverseBallot",           EOpSubgroupInverseBallot);
10100             symbolTable.relateToOperator("subgroupBallotBitExtract",        EOpSubgroupBallotBitExtract);
10101             symbolTable.relateToOperator("subgroupBallotBitCount",          EOpSubgroupBallotBitCount);
10102             symbolTable.relateToOperator("subgroupBallotInclusiveBitCount", EOpSubgroupBallotInclusiveBitCount);
10103             symbolTable.relateToOperator("subgroupBallotExclusiveBitCount", EOpSubgroupBallotExclusiveBitCount);
10104             symbolTable.relateToOperator("subgroupBallotFindLSB",           EOpSubgroupBallotFindLSB);
10105             symbolTable.relateToOperator("subgroupBallotFindMSB",           EOpSubgroupBallotFindMSB);
10106             symbolTable.relateToOperator("subgroupShuffle",                 EOpSubgroupShuffle);
10107             symbolTable.relateToOperator("subgroupShuffleXor",              EOpSubgroupShuffleXor);
10108             symbolTable.relateToOperator("subgroupShuffleUp",               EOpSubgroupShuffleUp);
10109             symbolTable.relateToOperator("subgroupShuffleDown",             EOpSubgroupShuffleDown);
10110             symbolTable.relateToOperator("subgroupRotate",                  EOpSubgroupRotate);
10111             symbolTable.relateToOperator("subgroupClusteredRotate",         EOpSubgroupClusteredRotate);
10112             symbolTable.relateToOperator("subgroupAdd",                     EOpSubgroupAdd);
10113             symbolTable.relateToOperator("subgroupMul",                     EOpSubgroupMul);
10114             symbolTable.relateToOperator("subgroupMin",                     EOpSubgroupMin);
10115             symbolTable.relateToOperator("subgroupMax",                     EOpSubgroupMax);
10116             symbolTable.relateToOperator("subgroupAnd",                     EOpSubgroupAnd);
10117             symbolTable.relateToOperator("subgroupOr",                      EOpSubgroupOr);
10118             symbolTable.relateToOperator("subgroupXor",                     EOpSubgroupXor);
10119             symbolTable.relateToOperator("subgroupInclusiveAdd",            EOpSubgroupInclusiveAdd);
10120             symbolTable.relateToOperator("subgroupInclusiveMul",            EOpSubgroupInclusiveMul);
10121             symbolTable.relateToOperator("subgroupInclusiveMin",            EOpSubgroupInclusiveMin);
10122             symbolTable.relateToOperator("subgroupInclusiveMax",            EOpSubgroupInclusiveMax);
10123             symbolTable.relateToOperator("subgroupInclusiveAnd",            EOpSubgroupInclusiveAnd);
10124             symbolTable.relateToOperator("subgroupInclusiveOr",             EOpSubgroupInclusiveOr);
10125             symbolTable.relateToOperator("subgroupInclusiveXor",            EOpSubgroupInclusiveXor);
10126             symbolTable.relateToOperator("subgroupExclusiveAdd",            EOpSubgroupExclusiveAdd);
10127             symbolTable.relateToOperator("subgroupExclusiveMul",            EOpSubgroupExclusiveMul);
10128             symbolTable.relateToOperator("subgroupExclusiveMin",            EOpSubgroupExclusiveMin);
10129             symbolTable.relateToOperator("subgroupExclusiveMax",            EOpSubgroupExclusiveMax);
10130             symbolTable.relateToOperator("subgroupExclusiveAnd",            EOpSubgroupExclusiveAnd);
10131             symbolTable.relateToOperator("subgroupExclusiveOr",             EOpSubgroupExclusiveOr);
10132             symbolTable.relateToOperator("subgroupExclusiveXor",            EOpSubgroupExclusiveXor);
10133             symbolTable.relateToOperator("subgroupClusteredAdd",            EOpSubgroupClusteredAdd);
10134             symbolTable.relateToOperator("subgroupClusteredMul",            EOpSubgroupClusteredMul);
10135             symbolTable.relateToOperator("subgroupClusteredMin",            EOpSubgroupClusteredMin);
10136             symbolTable.relateToOperator("subgroupClusteredMax",            EOpSubgroupClusteredMax);
10137             symbolTable.relateToOperator("subgroupClusteredAnd",            EOpSubgroupClusteredAnd);
10138             symbolTable.relateToOperator("subgroupClusteredOr",             EOpSubgroupClusteredOr);
10139             symbolTable.relateToOperator("subgroupClusteredXor",            EOpSubgroupClusteredXor);
10140             symbolTable.relateToOperator("subgroupQuadBroadcast",           EOpSubgroupQuadBroadcast);
10141             symbolTable.relateToOperator("subgroupQuadSwapHorizontal",      EOpSubgroupQuadSwapHorizontal);
10142             symbolTable.relateToOperator("subgroupQuadSwapVertical",        EOpSubgroupQuadSwapVertical);
10143             symbolTable.relateToOperator("subgroupQuadSwapDiagonal",        EOpSubgroupQuadSwapDiagonal);
10144 
10145             symbolTable.relateToOperator("subgroupPartitionNV",                          EOpSubgroupPartition);
10146             symbolTable.relateToOperator("subgroupPartitionedAddNV",                     EOpSubgroupPartitionedAdd);
10147             symbolTable.relateToOperator("subgroupPartitionedMulNV",                     EOpSubgroupPartitionedMul);
10148             symbolTable.relateToOperator("subgroupPartitionedMinNV",                     EOpSubgroupPartitionedMin);
10149             symbolTable.relateToOperator("subgroupPartitionedMaxNV",                     EOpSubgroupPartitionedMax);
10150             symbolTable.relateToOperator("subgroupPartitionedAndNV",                     EOpSubgroupPartitionedAnd);
10151             symbolTable.relateToOperator("subgroupPartitionedOrNV",                      EOpSubgroupPartitionedOr);
10152             symbolTable.relateToOperator("subgroupPartitionedXorNV",                     EOpSubgroupPartitionedXor);
10153             symbolTable.relateToOperator("subgroupPartitionedInclusiveAddNV",            EOpSubgroupPartitionedInclusiveAdd);
10154             symbolTable.relateToOperator("subgroupPartitionedInclusiveMulNV",            EOpSubgroupPartitionedInclusiveMul);
10155             symbolTable.relateToOperator("subgroupPartitionedInclusiveMinNV",            EOpSubgroupPartitionedInclusiveMin);
10156             symbolTable.relateToOperator("subgroupPartitionedInclusiveMaxNV",            EOpSubgroupPartitionedInclusiveMax);
10157             symbolTable.relateToOperator("subgroupPartitionedInclusiveAndNV",            EOpSubgroupPartitionedInclusiveAnd);
10158             symbolTable.relateToOperator("subgroupPartitionedInclusiveOrNV",             EOpSubgroupPartitionedInclusiveOr);
10159             symbolTable.relateToOperator("subgroupPartitionedInclusiveXorNV",            EOpSubgroupPartitionedInclusiveXor);
10160             symbolTable.relateToOperator("subgroupPartitionedExclusiveAddNV",            EOpSubgroupPartitionedExclusiveAdd);
10161             symbolTable.relateToOperator("subgroupPartitionedExclusiveMulNV",            EOpSubgroupPartitionedExclusiveMul);
10162             symbolTable.relateToOperator("subgroupPartitionedExclusiveMinNV",            EOpSubgroupPartitionedExclusiveMin);
10163             symbolTable.relateToOperator("subgroupPartitionedExclusiveMaxNV",            EOpSubgroupPartitionedExclusiveMax);
10164             symbolTable.relateToOperator("subgroupPartitionedExclusiveAndNV",            EOpSubgroupPartitionedExclusiveAnd);
10165             symbolTable.relateToOperator("subgroupPartitionedExclusiveOrNV",             EOpSubgroupPartitionedExclusiveOr);
10166             symbolTable.relateToOperator("subgroupPartitionedExclusiveXorNV",            EOpSubgroupPartitionedExclusiveXor);
10167         }
10168 
10169         if (profile == EEsProfile) {
10170             symbolTable.relateToOperator("shadow2DEXT",              EOpTexture);
10171             symbolTable.relateToOperator("shadow2DProjEXT",          EOpTextureProj);
10172         }
10173 
10174         // GL_EXT_shader_quad_control
10175         if ((profile == EEsProfile && version >= 310) ||
10176             (profile != EEsProfile && version >= 140)) {
10177             symbolTable.relateToOperator("subgroupQuadAll",                     EOpSubgroupQuadAll);
10178             symbolTable.relateToOperator("subgroupQuadAny",                     EOpSubgroupQuadAny);
10179         }
10180 
10181         if ((profile == EEsProfile && version >= 310) ||
10182             (profile != EEsProfile && version >= 140)) {
10183             symbolTable.relateToOperator("textureWeightedQCOM",      EOpImageSampleWeightedQCOM);
10184             symbolTable.relateToOperator("textureBoxFilterQCOM",     EOpImageBoxFilterQCOM);
10185             symbolTable.relateToOperator("textureBlockMatchSADQCOM", EOpImageBlockMatchSADQCOM);
10186             symbolTable.relateToOperator("textureBlockMatchSSDQCOM", EOpImageBlockMatchSSDQCOM);
10187 
10188             symbolTable.relateToOperator("textureBlockMatchWindowSSDQCOM", EOpImageBlockMatchWindowSSDQCOM);
10189             symbolTable.relateToOperator("textureBlockMatchWindowSADQCOM", EOpImageBlockMatchWindowSADQCOM);
10190             symbolTable.relateToOperator("textureBlockMatchGatherSSDQCOM", EOpImageBlockMatchGatherSSDQCOM);
10191             symbolTable.relateToOperator("textureBlockMatchGatherSADQCOM", EOpImageBlockMatchGatherSADQCOM);
10192         }
10193 
10194         if (profile != EEsProfile && spvVersion.spv == 0) {
10195             symbolTable.relateToOperator("texture1DArray", EOpTexture);
10196             symbolTable.relateToOperator("texture2DArray", EOpTexture);
10197             symbolTable.relateToOperator("shadow1DArray", EOpTexture);
10198             symbolTable.relateToOperator("shadow2DArray", EOpTexture);
10199 
10200             symbolTable.relateToOperator("texture1DArrayLod", EOpTextureLod);
10201             symbolTable.relateToOperator("texture2DArrayLod", EOpTextureLod);
10202             symbolTable.relateToOperator("shadow1DArrayLod", EOpTextureLod);
10203         }
10204     }
10205 
10206     switch(language) {
10207     case EShLangVertex:
10208         break;
10209 
10210     case EShLangTessControl:
10211     case EShLangTessEvaluation:
10212         break;
10213 
10214     case EShLangGeometry:
10215         symbolTable.relateToOperator("EmitStreamVertex",   EOpEmitStreamVertex);
10216         symbolTable.relateToOperator("EndStreamPrimitive", EOpEndStreamPrimitive);
10217         symbolTable.relateToOperator("EmitVertex",         EOpEmitVertex);
10218         symbolTable.relateToOperator("EndPrimitive",       EOpEndPrimitive);
10219         break;
10220 
10221     case EShLangFragment:
10222         if (profile != EEsProfile && version >= 400) {
10223             symbolTable.relateToOperator("dFdxFine",     EOpDPdxFine);
10224             symbolTable.relateToOperator("dFdyFine",     EOpDPdyFine);
10225             symbolTable.relateToOperator("fwidthFine",   EOpFwidthFine);
10226             symbolTable.relateToOperator("dFdxCoarse",   EOpDPdxCoarse);
10227             symbolTable.relateToOperator("dFdyCoarse",   EOpDPdyCoarse);
10228             symbolTable.relateToOperator("fwidthCoarse", EOpFwidthCoarse);
10229         }
10230 
10231         if (profile != EEsProfile && version >= 460) {
10232             symbolTable.relateToOperator("rayQueryInitializeEXT",                                             EOpRayQueryInitialize);
10233             symbolTable.relateToOperator("rayQueryTerminateEXT",                                              EOpRayQueryTerminate);
10234             symbolTable.relateToOperator("rayQueryGenerateIntersectionEXT",                                   EOpRayQueryGenerateIntersection);
10235             symbolTable.relateToOperator("rayQueryConfirmIntersectionEXT",                                    EOpRayQueryConfirmIntersection);
10236             symbolTable.relateToOperator("rayQueryProceedEXT",                                                EOpRayQueryProceed);
10237             symbolTable.relateToOperator("rayQueryGetIntersectionTypeEXT",                                    EOpRayQueryGetIntersectionType);
10238             symbolTable.relateToOperator("rayQueryGetRayTMinEXT",                                             EOpRayQueryGetRayTMin);
10239             symbolTable.relateToOperator("rayQueryGetRayFlagsEXT",                                            EOpRayQueryGetRayFlags);
10240             symbolTable.relateToOperator("rayQueryGetIntersectionTEXT",                                       EOpRayQueryGetIntersectionT);
10241             symbolTable.relateToOperator("rayQueryGetIntersectionInstanceCustomIndexEXT",                     EOpRayQueryGetIntersectionInstanceCustomIndex);
10242             symbolTable.relateToOperator("rayQueryGetIntersectionInstanceIdEXT",                              EOpRayQueryGetIntersectionInstanceId);
10243             symbolTable.relateToOperator("rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT",  EOpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffset);
10244             symbolTable.relateToOperator("rayQueryGetIntersectionGeometryIndexEXT",                           EOpRayQueryGetIntersectionGeometryIndex);
10245             symbolTable.relateToOperator("rayQueryGetIntersectionPrimitiveIndexEXT",                          EOpRayQueryGetIntersectionPrimitiveIndex);
10246             symbolTable.relateToOperator("rayQueryGetIntersectionBarycentricsEXT",                            EOpRayQueryGetIntersectionBarycentrics);
10247             symbolTable.relateToOperator("rayQueryGetIntersectionFrontFaceEXT",                               EOpRayQueryGetIntersectionFrontFace);
10248             symbolTable.relateToOperator("rayQueryGetIntersectionCandidateAABBOpaqueEXT",                     EOpRayQueryGetIntersectionCandidateAABBOpaque);
10249             symbolTable.relateToOperator("rayQueryGetIntersectionObjectRayDirectionEXT",                      EOpRayQueryGetIntersectionObjectRayDirection);
10250             symbolTable.relateToOperator("rayQueryGetIntersectionObjectRayOriginEXT",                         EOpRayQueryGetIntersectionObjectRayOrigin);
10251             symbolTable.relateToOperator("rayQueryGetWorldRayDirectionEXT",                                   EOpRayQueryGetWorldRayDirection);
10252             symbolTable.relateToOperator("rayQueryGetWorldRayOriginEXT",                                      EOpRayQueryGetWorldRayOrigin);
10253             symbolTable.relateToOperator("rayQueryGetIntersectionObjectToWorldEXT",                           EOpRayQueryGetIntersectionObjectToWorld);
10254             symbolTable.relateToOperator("rayQueryGetIntersectionWorldToObjectEXT",                           EOpRayQueryGetIntersectionWorldToObject);
10255             symbolTable.relateToOperator("rayQueryGetIntersectionTriangleVertexPositionsEXT",                 EOpRayQueryGetIntersectionTriangleVertexPositionsEXT);
10256         }
10257 
10258         symbolTable.relateToOperator("interpolateAtCentroid", EOpInterpolateAtCentroid);
10259         symbolTable.relateToOperator("interpolateAtSample",   EOpInterpolateAtSample);
10260         symbolTable.relateToOperator("interpolateAtOffset",   EOpInterpolateAtOffset);
10261 
10262         if (profile != EEsProfile)
10263             symbolTable.relateToOperator("interpolateAtVertexAMD", EOpInterpolateAtVertex);
10264 
10265         symbolTable.relateToOperator("beginInvocationInterlockARB", EOpBeginInvocationInterlock);
10266         symbolTable.relateToOperator("endInvocationInterlockARB",   EOpEndInvocationInterlock);
10267 
10268         symbolTable.relateToOperator("stencilAttachmentReadEXT", EOpStencilAttachmentReadEXT);
10269         symbolTable.relateToOperator("depthAttachmentReadEXT",   EOpDepthAttachmentReadEXT);
10270         symbolTable.relateToOperator("colorAttachmentReadEXT",   EOpColorAttachmentReadEXT);
10271 
10272         break;
10273 
10274     case EShLangCompute:
10275         symbolTable.relateToOperator("subgroupMemoryBarrierShared", EOpSubgroupMemoryBarrierShared);
10276         if ((profile != EEsProfile && version >= 450) ||
10277             (profile == EEsProfile && version >= 320)) {
10278             symbolTable.relateToOperator("dFdx",        EOpDPdx);
10279             symbolTable.relateToOperator("dFdy",        EOpDPdy);
10280             symbolTable.relateToOperator("fwidth",      EOpFwidth);
10281             symbolTable.relateToOperator("dFdxFine",    EOpDPdxFine);
10282             symbolTable.relateToOperator("dFdyFine",    EOpDPdyFine);
10283             symbolTable.relateToOperator("fwidthFine",  EOpFwidthFine);
10284             symbolTable.relateToOperator("dFdxCoarse",  EOpDPdxCoarse);
10285             symbolTable.relateToOperator("dFdyCoarse",  EOpDPdyCoarse);
10286             symbolTable.relateToOperator("fwidthCoarse",EOpFwidthCoarse);
10287         }
10288         symbolTable.relateToOperator("coopMatLoadNV",              EOpCooperativeMatrixLoadNV);
10289         symbolTable.relateToOperator("coopMatStoreNV",             EOpCooperativeMatrixStoreNV);
10290         symbolTable.relateToOperator("coopMatMulAddNV",            EOpCooperativeMatrixMulAddNV);
10291 
10292         symbolTable.relateToOperator("coopMatLoad",                EOpCooperativeMatrixLoad);
10293         symbolTable.relateToOperator("coopMatStore",               EOpCooperativeMatrixStore);
10294         symbolTable.relateToOperator("coopMatMulAdd",              EOpCooperativeMatrixMulAdd);
10295 
10296         symbolTable.relateToOperator("coopMatLoadTensorNV",        EOpCooperativeMatrixLoadTensorNV);
10297         symbolTable.relateToOperator("coopMatStoreTensorNV",       EOpCooperativeMatrixStoreTensorNV);
10298 
10299         symbolTable.relateToOperator("coopMatReduceNV",            EOpCooperativeMatrixReduceNV);
10300         symbolTable.relateToOperator("coopMatPerElementNV",        EOpCooperativeMatrixPerElementOpNV);
10301         symbolTable.relateToOperator("coopMatTransposeNV",         EOpCooperativeMatrixTransposeNV);
10302 
10303         symbolTable.relateToOperator("createTensorLayoutNV",         EOpCreateTensorLayoutNV);
10304         symbolTable.relateToOperator("setTensorLayoutBlockSizeNV",   EOpTensorLayoutSetBlockSizeNV);
10305         symbolTable.relateToOperator("setTensorLayoutDimensionNV",   EOpTensorLayoutSetDimensionNV);
10306         symbolTable.relateToOperator("setTensorLayoutStrideNV",      EOpTensorLayoutSetStrideNV);
10307         symbolTable.relateToOperator("sliceTensorLayoutNV",          EOpTensorLayoutSliceNV);
10308         symbolTable.relateToOperator("setTensorLayoutClampValueNV",  EOpTensorLayoutSetClampValueNV);
10309 
10310         symbolTable.relateToOperator("createTensorViewNV",           EOpCreateTensorViewNV);
10311         symbolTable.relateToOperator("setTensorViewDimensionsNV",    EOpTensorViewSetDimensionNV);
10312         symbolTable.relateToOperator("setTensorViewStrideNV",        EOpTensorViewSetStrideNV);
10313         symbolTable.relateToOperator("setTensorViewClipNV",          EOpTensorViewSetClipNV);
10314 
10315         if (profile != EEsProfile && version >= 460) {
10316             symbolTable.relateToOperator("fetchMicroTriangleVertexPositionNV", EOpFetchMicroTriangleVertexPositionNV);
10317             symbolTable.relateToOperator("fetchMicroTriangleVertexBarycentricNV", EOpFetchMicroTriangleVertexBarycentricNV);
10318         }
10319         break;
10320 
10321     case EShLangRayGen:
10322         if (profile != EEsProfile && version >= 460) {
10323             symbolTable.relateToOperator("fetchMicroTriangleVertexPositionNV", EOpFetchMicroTriangleVertexPositionNV);
10324             symbolTable.relateToOperator("fetchMicroTriangleVertexBarycentricNV", EOpFetchMicroTriangleVertexBarycentricNV);
10325         }
10326         [[fallthrough]];
10327     case EShLangClosestHit:
10328     case EShLangMiss:
10329         if (profile != EEsProfile && version >= 460) {
10330             symbolTable.relateToOperator("traceNV", EOpTraceNV);
10331             symbolTable.relateToOperator("traceRayMotionNV", EOpTraceRayMotionNV);
10332             symbolTable.relateToOperator("traceRayEXT", EOpTraceKHR);
10333             symbolTable.relateToOperator("executeCallableNV", EOpExecuteCallableNV);
10334             symbolTable.relateToOperator("executeCallableEXT", EOpExecuteCallableKHR);
10335 
10336             symbolTable.relateToOperator("hitObjectTraceRayNV", EOpHitObjectTraceRayNV);
10337             symbolTable.relateToOperator("hitObjectTraceRayMotionNV", EOpHitObjectTraceRayMotionNV);
10338             symbolTable.relateToOperator("hitObjectRecordHitNV", EOpHitObjectRecordHitNV);
10339             symbolTable.relateToOperator("hitObjectRecordHitMotionNV", EOpHitObjectRecordHitMotionNV);
10340             symbolTable.relateToOperator("hitObjectRecordHitWithIndexNV", EOpHitObjectRecordHitWithIndexNV);
10341             symbolTable.relateToOperator("hitObjectRecordHitWithIndexMotionNV", EOpHitObjectRecordHitWithIndexMotionNV);
10342             symbolTable.relateToOperator("hitObjectRecordMissNV", EOpHitObjectRecordMissNV);
10343             symbolTable.relateToOperator("hitObjectRecordMissMotionNV", EOpHitObjectRecordMissMotionNV);
10344             symbolTable.relateToOperator("hitObjectRecordEmptyNV", EOpHitObjectRecordEmptyNV);
10345             symbolTable.relateToOperator("hitObjectExecuteShaderNV", EOpHitObjectExecuteShaderNV);
10346             symbolTable.relateToOperator("hitObjectIsEmptyNV", EOpHitObjectIsEmptyNV);
10347             symbolTable.relateToOperator("hitObjectIsMissNV", EOpHitObjectIsMissNV);
10348             symbolTable.relateToOperator("hitObjectIsHitNV", EOpHitObjectIsHitNV);
10349             symbolTable.relateToOperator("hitObjectGetRayTMinNV", EOpHitObjectGetRayTMinNV);
10350             symbolTable.relateToOperator("hitObjectGetRayTMaxNV", EOpHitObjectGetRayTMaxNV);
10351             symbolTable.relateToOperator("hitObjectGetObjectRayOriginNV", EOpHitObjectGetObjectRayOriginNV);
10352             symbolTable.relateToOperator("hitObjectGetObjectRayDirectionNV", EOpHitObjectGetObjectRayDirectionNV);
10353             symbolTable.relateToOperator("hitObjectGetWorldRayOriginNV", EOpHitObjectGetWorldRayOriginNV);
10354             symbolTable.relateToOperator("hitObjectGetWorldRayDirectionNV", EOpHitObjectGetWorldRayDirectionNV);
10355             symbolTable.relateToOperator("hitObjectGetWorldToObjectNV", EOpHitObjectGetWorldToObjectNV);
10356             symbolTable.relateToOperator("hitObjectGetObjectToWorldNV", EOpHitObjectGetObjectToWorldNV);
10357             symbolTable.relateToOperator("hitObjectGetInstanceCustomIndexNV", EOpHitObjectGetInstanceCustomIndexNV);
10358             symbolTable.relateToOperator("hitObjectGetInstanceIdNV", EOpHitObjectGetInstanceIdNV);
10359             symbolTable.relateToOperator("hitObjectGetGeometryIndexNV", EOpHitObjectGetGeometryIndexNV);
10360             symbolTable.relateToOperator("hitObjectGetPrimitiveIndexNV", EOpHitObjectGetPrimitiveIndexNV);
10361             symbolTable.relateToOperator("hitObjectGetHitKindNV", EOpHitObjectGetHitKindNV);
10362             symbolTable.relateToOperator("hitObjectGetAttributesNV", EOpHitObjectGetAttributesNV);
10363             symbolTable.relateToOperator("hitObjectGetCurrentTimeNV", EOpHitObjectGetCurrentTimeNV);
10364             symbolTable.relateToOperator("hitObjectGetShaderBindingTableRecordIndexNV", EOpHitObjectGetShaderBindingTableRecordIndexNV);
10365             symbolTable.relateToOperator("hitObjectGetShaderRecordBufferHandleNV", EOpHitObjectGetShaderRecordBufferHandleNV);
10366             symbolTable.relateToOperator("reorderThreadNV", EOpReorderThreadNV);
10367         }
10368         break;
10369     case EShLangIntersect:
10370         if (profile != EEsProfile && version >= 460) {
10371             symbolTable.relateToOperator("reportIntersectionNV", EOpReportIntersection);
10372             symbolTable.relateToOperator("reportIntersectionEXT", EOpReportIntersection);
10373         }
10374         break;
10375     case EShLangAnyHit:
10376         if (profile != EEsProfile && version >= 460) {
10377             symbolTable.relateToOperator("ignoreIntersectionNV", EOpIgnoreIntersectionNV);
10378             symbolTable.relateToOperator("terminateRayNV", EOpTerminateRayNV);
10379         }
10380         break;
10381     case EShLangCallable:
10382         if (profile != EEsProfile && version >= 460) {
10383             symbolTable.relateToOperator("executeCallableNV", EOpExecuteCallableNV);
10384             symbolTable.relateToOperator("executeCallableEXT", EOpExecuteCallableKHR);
10385         }
10386         break;
10387     case EShLangMesh:
10388         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
10389             symbolTable.relateToOperator("writePackedPrimitiveIndices4x8NV", EOpWritePackedPrimitiveIndices4x8NV);
10390             symbolTable.relateToOperator("memoryBarrierShared", EOpMemoryBarrierShared);
10391             symbolTable.relateToOperator("groupMemoryBarrier", EOpGroupMemoryBarrier);
10392             symbolTable.relateToOperator("subgroupMemoryBarrierShared", EOpSubgroupMemoryBarrierShared);
10393         }
10394 
10395         if (profile != EEsProfile && version >= 450) {
10396             symbolTable.relateToOperator("SetMeshOutputsEXT", EOpSetMeshOutputsEXT);
10397         }
10398 
10399         if (profile != EEsProfile && version >= 460) {
10400             // Builtins for GL_NV_displacement_micromap.
10401             symbolTable.relateToOperator("fetchMicroTriangleVertexPositionNV", EOpFetchMicroTriangleVertexPositionNV);
10402             symbolTable.relateToOperator("fetchMicroTriangleVertexBarycentricNV", EOpFetchMicroTriangleVertexBarycentricNV);
10403         }
10404         break;
10405     case EShLangTask:
10406         if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
10407             symbolTable.relateToOperator("memoryBarrierShared", EOpMemoryBarrierShared);
10408             symbolTable.relateToOperator("groupMemoryBarrier", EOpGroupMemoryBarrier);
10409             symbolTable.relateToOperator("subgroupMemoryBarrierShared", EOpSubgroupMemoryBarrierShared);
10410         }
10411         if (profile != EEsProfile && version >= 450) {
10412             symbolTable.relateToOperator("EmitMeshTasksEXT", EOpEmitMeshTasksEXT);
10413         }
10414         break;
10415 
10416     default:
10417         assert(false && "Language not supported");
10418     }
10419 }
10420 
10421 //
10422 // Add context-dependent (resource-specific) built-ins not handled by the above.  These
10423 // would be ones that need to be programmatically added because they cannot
10424 // be added by simple text strings.  For these, also
10425 // 1) Map built-in functions to operators, for those that will turn into an operation node
10426 //    instead of remaining a function call.
10427 // 2) Tag extension-related symbols added to their base version with their extensions, so
10428 //    that if an early version has the extension turned off, there is an error reported on use.
10429 //
identifyBuiltIns(int version,EProfile profile,const SpvVersion & spvVersion,EShLanguage language,TSymbolTable & symbolTable,const TBuiltInResource & resources)10430 void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable, const TBuiltInResource &resources)
10431 {
10432     if (profile != EEsProfile && version >= 430 && version < 440) {
10433         symbolTable.setVariableExtensions("gl_MaxTransformFeedbackBuffers", 1, &E_GL_ARB_enhanced_layouts);
10434         symbolTable.setVariableExtensions("gl_MaxTransformFeedbackInterleavedComponents", 1, &E_GL_ARB_enhanced_layouts);
10435     }
10436     if (profile != EEsProfile && version >= 130 && version < 420) {
10437         symbolTable.setVariableExtensions("gl_MinProgramTexelOffset", 1, &E_GL_ARB_shading_language_420pack);
10438         symbolTable.setVariableExtensions("gl_MaxProgramTexelOffset", 1, &E_GL_ARB_shading_language_420pack);
10439     }
10440     if (profile != EEsProfile && version >= 150 && version < 410)
10441         symbolTable.setVariableExtensions("gl_MaxViewports", 1, &E_GL_ARB_viewport_array);
10442 
10443     switch(language) {
10444     case EShLangFragment:
10445         // Set up gl_FragData based on current array size.
10446         if (version == 100 || IncludeLegacy(version, profile, spvVersion) || (! ForwardCompatibility && profile != EEsProfile && version < 420)) {
10447             TPrecisionQualifier pq = profile == EEsProfile ? EpqMedium : EpqNone;
10448             TType fragData(EbtFloat, EvqFragColor, pq, 4);
10449             TArraySizes* arraySizes = new TArraySizes;
10450             arraySizes->addInnerSize(resources.maxDrawBuffers);
10451             fragData.transferArraySizes(arraySizes);
10452             symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData"), fragData));
10453             SpecialQualifier("gl_FragData", EvqFragColor, EbvFragData, symbolTable);
10454         }
10455 
10456         // GL_EXT_blend_func_extended
10457         if (profile == EEsProfile && version >= 100) {
10458            symbolTable.setVariableExtensions("gl_MaxDualSourceDrawBuffersEXT",    1, &E_GL_EXT_blend_func_extended);
10459            symbolTable.setVariableExtensions("gl_SecondaryFragColorEXT",    1, &E_GL_EXT_blend_func_extended);
10460            symbolTable.setVariableExtensions("gl_SecondaryFragDataEXT",    1, &E_GL_EXT_blend_func_extended);
10461            SpecialQualifier("gl_SecondaryFragColorEXT", EvqVaryingOut, EbvSecondaryFragColorEXT, symbolTable);
10462            SpecialQualifier("gl_SecondaryFragDataEXT", EvqVaryingOut, EbvSecondaryFragDataEXT, symbolTable);
10463         }
10464 
10465         break;
10466 
10467     case EShLangTessControl:
10468     case EShLangTessEvaluation:
10469         // Because of the context-dependent array size (gl_MaxPatchVertices),
10470         // these variables were added later than the others and need to be mapped now.
10471 
10472         // standard members
10473         BuiltInVariable("gl_in", "gl_Position",     EbvPosition,     symbolTable);
10474         BuiltInVariable("gl_in", "gl_PointSize",    EbvPointSize,    symbolTable);
10475         BuiltInVariable("gl_in", "gl_ClipDistance", EbvClipDistance, symbolTable);
10476         BuiltInVariable("gl_in", "gl_CullDistance", EbvCullDistance, symbolTable);
10477 
10478         // compatibility members
10479         BuiltInVariable("gl_in", "gl_ClipVertex",          EbvClipVertex,          symbolTable);
10480         BuiltInVariable("gl_in", "gl_FrontColor",          EbvFrontColor,          symbolTable);
10481         BuiltInVariable("gl_in", "gl_BackColor",           EbvBackColor,           symbolTable);
10482         BuiltInVariable("gl_in", "gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
10483         BuiltInVariable("gl_in", "gl_BackSecondaryColor",  EbvBackSecondaryColor,  symbolTable);
10484         BuiltInVariable("gl_in", "gl_TexCoord",            EbvTexCoord,            symbolTable);
10485         BuiltInVariable("gl_in", "gl_FogFragCoord",        EbvFogFragCoord,        symbolTable);
10486 
10487         symbolTable.setVariableExtensions("gl_in", "gl_SecondaryPositionNV", 1, &E_GL_NV_stereo_view_rendering);
10488         symbolTable.setVariableExtensions("gl_in", "gl_PositionPerViewNV",   1, &E_GL_NVX_multiview_per_view_attributes);
10489 
10490         BuiltInVariable("gl_in", "gl_SecondaryPositionNV", EbvSecondaryPositionNV, symbolTable);
10491         BuiltInVariable("gl_in", "gl_PositionPerViewNV",   EbvPositionPerViewNV,   symbolTable);
10492 
10493         // extension requirements
10494         if (profile == EEsProfile) {
10495             symbolTable.setVariableExtensions("gl_in", "gl_PointSize", Num_AEP_tessellation_point_size, AEP_tessellation_point_size);
10496         }
10497 
10498         break;
10499 
10500     default:
10501         break;
10502     }
10503 }
10504 
10505 } // end namespace glslang
10506