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