2 // Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
3 // Copyright (C) 2013 LunarG, Inc.
4 // Copyright (C) 2017 ARM Limited.
6 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
12 // Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
15 // Redistributions in binary form must reproduce the above
16 // copyright notice, this list of conditions and the following
17 // disclaimer in the documentation and/or other materials provided
18 // with the distribution.
20 // Neither the name of 3Dlabs Inc. Ltd. nor the names of its
21 // contributors may be used to endorse or promote products derived
22 // from this software without specific prior written permission.
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 // POSSIBILITY OF SUCH DAMAGE.
39 // GLSL scanning, leveraging the scanning done by the preprocessor.
43 #include <unordered_map>
44 #include <unordered_set>
46 #include "../Include/Types.h"
47 #include "SymbolTable.h"
48 #include "ParseHelper.h"
49 #include "attribute.h"
50 #include "glslang_tab.cpp.h"
51 #include "ScanContext.h"
54 // preprocessor includes
55 #include "preprocessor/PpContext.h"
56 #include "preprocessor/PpTokens.h"
58 // Required to avoid missing prototype warnings for some compilers
59 int yylex(YYSTYPE*, glslang::TParseContext&);
63 // read past any white space
64 void TInputScanner::consumeWhiteSpace(bool& foundNonSpaceTab)
66 int c = peek(); // don't accidentally consume anything other than whitespace
67 while (c == ' ' || c == '\t' || c == '\r' || c == '\n') {
68 if (c == '\r' || c == '\n')
69 foundNonSpaceTab = true;
75 // return true if a comment was actually consumed
76 bool TInputScanner::consumeComment()
81 get(); // consume the '/'
85 // a '//' style comment
86 get(); // consume the second '/'
89 while (c != EndOfInput && c != '\\' && c != '\r' && c != '\n')
92 if (c == EndOfInput || c == '\r' || c == '\n') {
93 while (c == '\r' || c == '\n')
96 // we reached the end of the comment
99 // it's a '\', so we need to keep going, after skipping what's escaped
101 // read the skipped character
104 // if it's a two-character newline, skip both characters
105 if (c == '\r' && peek() == '\n')
111 // put back the last non-comment character
116 } else if (c == '*') {
118 // a '/*' style comment
119 get(); // consume the '*'
122 while (c != EndOfInput && c != '*')
127 break; // end of comment
128 // not end of comment
129 } else // end of input
135 // it's not a comment, put the '/' back
142 // skip whitespace, then skip a comment, rinse, repeat
143 void TInputScanner::consumeWhitespaceComment(bool& foundNonSpaceTab)
146 consumeWhiteSpace(foundNonSpaceTab);
148 // if not starting a comment now, then done
150 if (c != '/' || c == EndOfInput)
153 // skip potential comment
154 foundNonSpaceTab = true;
155 if (! consumeComment())
161 // Returns true if there was non-white space (e.g., a comment, newline) before the #version
162 // or no #version was found; otherwise, returns false. There is no error case, it always
163 // succeeds, but will leave version == 0 if no #version was found.
165 // Sets notFirstToken based on whether tokens (beyond white space and comments)
166 // appeared before the #version.
168 // N.B. does not attempt to leave input in any particular known state. The assumption
169 // is that scanning will start anew, following the rules for the chosen version/profile,
170 // and with a corresponding parsing context.
172 bool TInputScanner::scanVersion(int& version, EProfile& profile, bool& notFirstToken)
174 // This function doesn't have to get all the semantics correct,
175 // just find the #version if there is a correct one present.
176 // The preprocessor will have the responsibility of getting all the semantics right.
178 bool versionNotFirst = false; // means not first WRT comments and white space, nothing more
179 notFirstToken = false; // means not first WRT to real tokens
180 version = 0; // means not found
181 profile = ENoProfile;
183 bool foundNonSpaceTab = false;
184 bool lookingInMiddle = false;
187 if (lookingInMiddle) {
188 notFirstToken = true;
189 // make forward progress by finishing off the current line plus extra new lines
190 if (peek() != '\n' && peek() != '\r') {
193 } while (c != EndOfInput && c != '\n' && c != '\r');
195 while (peek() == '\n' || peek() == '\r')
197 if (peek() == EndOfInput)
200 lookingInMiddle = true;
202 // Nominal start, skipping the desktop allowed comments and white space, but tracking if
203 // something else was found for ES:
204 consumeWhitespaceComment(foundNonSpaceTab);
205 if (foundNonSpaceTab)
206 versionNotFirst = true;
210 versionNotFirst = true;
217 } while (c == ' ' || c == '\t');
227 versionNotFirst = true;
234 } while (c == ' ' || c == '\t');
237 while (c >= '0' && c <= '9') {
238 version = 10 * version + (c - '0');
242 versionNotFirst = true;
247 while (c == ' ' || c == '\t')
251 const int maxProfileLength = 13; // not including any 0
252 char profileString[maxProfileLength];
254 for (profileLength = 0; profileLength < maxProfileLength; ++profileLength) {
255 if (c == EndOfInput || c == ' ' || c == '\t' || c == '\n' || c == '\r')
257 profileString[profileLength] = (char)c;
260 if (c != EndOfInput && c != ' ' && c != '\t' && c != '\n' && c != '\r') {
261 versionNotFirst = true;
265 if (profileLength == 2 && strncmp(profileString, "es", profileLength) == 0)
266 profile = EEsProfile;
267 else if (profileLength == 4 && strncmp(profileString, "core", profileLength) == 0)
268 profile = ECoreProfile;
269 else if (profileLength == 13 && strncmp(profileString, "compatibility", profileLength) == 0)
270 profile = ECompatibilityProfile;
272 return versionNotFirst;
276 // Fill this in when doing glslang-level scanning, to hand back to the parser.
279 explicit TParserToken(YYSTYPE& b) : sType(b) { }
283 TParserToken(TParserToken&);
284 TParserToken& operator=(TParserToken&);
287 } // end namespace glslang
289 // This is the function the glslang parser (i.e., bison) calls to get its next token
290 int yylex(YYSTYPE* glslangTokenDesc, glslang::TParseContext& parseContext)
292 glslang::TParserToken token(*glslangTokenDesc);
294 return parseContext.getScanContext()->tokenize(parseContext.getPpContext(), token);
301 bool operator()(const char* lhs, const char* rhs) const
303 return strcmp(lhs, rhs) == 0;
309 size_t operator()(const char* str) const
312 unsigned long hash = 5381;
315 while ((c = *str++) != 0)
316 hash = ((hash << 5) + hash) + c;
322 // A single global usable by all threads, by all versions, by all languages.
323 // After a single process-level initialization, this is read only and thread safe
324 std::unordered_map<const char*, int, str_hash, str_eq>* KeywordMap = nullptr;
326 std::unordered_set<const char*, str_hash, str_eq>* ReservedSet = nullptr;
333 void TScanContext::fillInKeywordMap()
335 if (KeywordMap != nullptr) {
336 // this is really an error, as this should called only once per process
337 // but, the only risk is if two threads called simultaneously
340 KeywordMap = new std::unordered_map<const char*, int, str_hash, str_eq>;
342 (*KeywordMap)["const"] = CONST;
343 (*KeywordMap)["uniform"] = UNIFORM;
344 (*KeywordMap)["buffer"] = BUFFER;
345 (*KeywordMap)["in"] = IN;
346 (*KeywordMap)["out"] = OUT;
347 (*KeywordMap)["smooth"] = SMOOTH;
348 (*KeywordMap)["flat"] = FLAT;
349 (*KeywordMap)["centroid"] = CENTROID;
350 (*KeywordMap)["invariant"] = INVARIANT;
351 (*KeywordMap)["packed"] = PACKED;
352 (*KeywordMap)["resource"] = RESOURCE;
353 (*KeywordMap)["inout"] = INOUT;
354 (*KeywordMap)["struct"] = STRUCT;
355 (*KeywordMap)["break"] = BREAK;
356 (*KeywordMap)["continue"] = CONTINUE;
357 (*KeywordMap)["do"] = DO;
358 (*KeywordMap)["for"] = FOR;
359 (*KeywordMap)["while"] = WHILE;
360 (*KeywordMap)["switch"] = SWITCH;
361 (*KeywordMap)["case"] = CASE;
362 (*KeywordMap)["default"] = DEFAULT;
363 (*KeywordMap)["if"] = IF;
364 (*KeywordMap)["else"] = ELSE;
365 (*KeywordMap)["discard"] = DISCARD;
366 (*KeywordMap)["return"] = RETURN;
367 (*KeywordMap)["void"] = VOID;
368 (*KeywordMap)["bool"] = BOOL;
369 (*KeywordMap)["float"] = FLOAT;
370 (*KeywordMap)["int"] = INT;
371 (*KeywordMap)["bvec2"] = BVEC2;
372 (*KeywordMap)["bvec3"] = BVEC3;
373 (*KeywordMap)["bvec4"] = BVEC4;
374 (*KeywordMap)["vec2"] = VEC2;
375 (*KeywordMap)["vec3"] = VEC3;
376 (*KeywordMap)["vec4"] = VEC4;
377 (*KeywordMap)["ivec2"] = IVEC2;
378 (*KeywordMap)["ivec3"] = IVEC3;
379 (*KeywordMap)["ivec4"] = IVEC4;
380 (*KeywordMap)["mat2"] = MAT2;
381 (*KeywordMap)["mat3"] = MAT3;
382 (*KeywordMap)["mat4"] = MAT4;
383 (*KeywordMap)["true"] = BOOLCONSTANT;
384 (*KeywordMap)["false"] = BOOLCONSTANT;
385 (*KeywordMap)["layout"] = LAYOUT;
386 (*KeywordMap)["shared"] = SHARED;
387 (*KeywordMap)["highp"] = HIGH_PRECISION;
388 (*KeywordMap)["mediump"] = MEDIUM_PRECISION;
389 (*KeywordMap)["lowp"] = LOW_PRECISION;
390 (*KeywordMap)["superp"] = SUPERP;
391 (*KeywordMap)["precision"] = PRECISION;
392 (*KeywordMap)["mat2x2"] = MAT2X2;
393 (*KeywordMap)["mat2x3"] = MAT2X3;
394 (*KeywordMap)["mat2x4"] = MAT2X4;
395 (*KeywordMap)["mat3x2"] = MAT3X2;
396 (*KeywordMap)["mat3x3"] = MAT3X3;
397 (*KeywordMap)["mat3x4"] = MAT3X4;
398 (*KeywordMap)["mat4x2"] = MAT4X2;
399 (*KeywordMap)["mat4x3"] = MAT4X3;
400 (*KeywordMap)["mat4x4"] = MAT4X4;
401 (*KeywordMap)["uint"] = UINT;
402 (*KeywordMap)["uvec2"] = UVEC2;
403 (*KeywordMap)["uvec3"] = UVEC3;
404 (*KeywordMap)["uvec4"] = UVEC4;
407 (*KeywordMap)["nonuniformEXT"] = NONUNIFORM;
408 (*KeywordMap)["demote"] = DEMOTE;
409 (*KeywordMap)["attribute"] = ATTRIBUTE;
410 (*KeywordMap)["varying"] = VARYING;
411 (*KeywordMap)["noperspective"] = NOPERSPECTIVE;
412 (*KeywordMap)["coherent"] = COHERENT;
413 (*KeywordMap)["devicecoherent"] = DEVICECOHERENT;
414 (*KeywordMap)["queuefamilycoherent"] = QUEUEFAMILYCOHERENT;
415 (*KeywordMap)["workgroupcoherent"] = WORKGROUPCOHERENT;
416 (*KeywordMap)["subgroupcoherent"] = SUBGROUPCOHERENT;
417 (*KeywordMap)["nonprivate"] = NONPRIVATE;
418 (*KeywordMap)["restrict"] = RESTRICT;
419 (*KeywordMap)["readonly"] = READONLY;
420 (*KeywordMap)["writeonly"] = WRITEONLY;
421 (*KeywordMap)["atomic_uint"] = ATOMIC_UINT;
422 (*KeywordMap)["volatile"] = VOLATILE;
423 (*KeywordMap)["patch"] = PATCH;
424 (*KeywordMap)["sample"] = SAMPLE;
425 (*KeywordMap)["subroutine"] = SUBROUTINE;
426 (*KeywordMap)["dmat2"] = DMAT2;
427 (*KeywordMap)["dmat3"] = DMAT3;
428 (*KeywordMap)["dmat4"] = DMAT4;
429 (*KeywordMap)["dmat2x2"] = DMAT2X2;
430 (*KeywordMap)["dmat2x3"] = DMAT2X3;
431 (*KeywordMap)["dmat2x4"] = DMAT2X4;
432 (*KeywordMap)["dmat3x2"] = DMAT3X2;
433 (*KeywordMap)["dmat3x3"] = DMAT3X3;
434 (*KeywordMap)["dmat3x4"] = DMAT3X4;
435 (*KeywordMap)["dmat4x2"] = DMAT4X2;
436 (*KeywordMap)["dmat4x3"] = DMAT4X3;
437 (*KeywordMap)["dmat4x4"] = DMAT4X4;
438 (*KeywordMap)["image1D"] = IMAGE1D;
439 (*KeywordMap)["iimage1D"] = IIMAGE1D;
440 (*KeywordMap)["uimage1D"] = UIMAGE1D;
441 (*KeywordMap)["image2D"] = IMAGE2D;
442 (*KeywordMap)["iimage2D"] = IIMAGE2D;
443 (*KeywordMap)["uimage2D"] = UIMAGE2D;
444 (*KeywordMap)["image3D"] = IMAGE3D;
445 (*KeywordMap)["iimage3D"] = IIMAGE3D;
446 (*KeywordMap)["uimage3D"] = UIMAGE3D;
447 (*KeywordMap)["image2DRect"] = IMAGE2DRECT;
448 (*KeywordMap)["iimage2DRect"] = IIMAGE2DRECT;
449 (*KeywordMap)["uimage2DRect"] = UIMAGE2DRECT;
450 (*KeywordMap)["imageCube"] = IMAGECUBE;
451 (*KeywordMap)["iimageCube"] = IIMAGECUBE;
452 (*KeywordMap)["uimageCube"] = UIMAGECUBE;
453 (*KeywordMap)["imageBuffer"] = IMAGEBUFFER;
454 (*KeywordMap)["iimageBuffer"] = IIMAGEBUFFER;
455 (*KeywordMap)["uimageBuffer"] = UIMAGEBUFFER;
456 (*KeywordMap)["image1DArray"] = IMAGE1DARRAY;
457 (*KeywordMap)["iimage1DArray"] = IIMAGE1DARRAY;
458 (*KeywordMap)["uimage1DArray"] = UIMAGE1DARRAY;
459 (*KeywordMap)["image2DArray"] = IMAGE2DARRAY;
460 (*KeywordMap)["iimage2DArray"] = IIMAGE2DARRAY;
461 (*KeywordMap)["uimage2DArray"] = UIMAGE2DARRAY;
462 (*KeywordMap)["imageCubeArray"] = IMAGECUBEARRAY;
463 (*KeywordMap)["iimageCubeArray"] = IIMAGECUBEARRAY;
464 (*KeywordMap)["uimageCubeArray"] = UIMAGECUBEARRAY;
465 (*KeywordMap)["image2DMS"] = IMAGE2DMS;
466 (*KeywordMap)["iimage2DMS"] = IIMAGE2DMS;
467 (*KeywordMap)["uimage2DMS"] = UIMAGE2DMS;
468 (*KeywordMap)["image2DMSArray"] = IMAGE2DMSARRAY;
469 (*KeywordMap)["iimage2DMSArray"] = IIMAGE2DMSARRAY;
470 (*KeywordMap)["uimage2DMSArray"] = UIMAGE2DMSARRAY;
471 (*KeywordMap)["double"] = DOUBLE;
472 (*KeywordMap)["dvec2"] = DVEC2;
473 (*KeywordMap)["dvec3"] = DVEC3;
474 (*KeywordMap)["dvec4"] = DVEC4;
475 (*KeywordMap)["int64_t"] = INT64_T;
476 (*KeywordMap)["uint64_t"] = UINT64_T;
477 (*KeywordMap)["i64vec2"] = I64VEC2;
478 (*KeywordMap)["i64vec3"] = I64VEC3;
479 (*KeywordMap)["i64vec4"] = I64VEC4;
480 (*KeywordMap)["u64vec2"] = U64VEC2;
481 (*KeywordMap)["u64vec3"] = U64VEC3;
482 (*KeywordMap)["u64vec4"] = U64VEC4;
484 // GL_EXT_shader_explicit_arithmetic_types
485 (*KeywordMap)["int8_t"] = INT8_T;
486 (*KeywordMap)["i8vec2"] = I8VEC2;
487 (*KeywordMap)["i8vec3"] = I8VEC3;
488 (*KeywordMap)["i8vec4"] = I8VEC4;
489 (*KeywordMap)["uint8_t"] = UINT8_T;
490 (*KeywordMap)["u8vec2"] = U8VEC2;
491 (*KeywordMap)["u8vec3"] = U8VEC3;
492 (*KeywordMap)["u8vec4"] = U8VEC4;
494 (*KeywordMap)["int16_t"] = INT16_T;
495 (*KeywordMap)["i16vec2"] = I16VEC2;
496 (*KeywordMap)["i16vec3"] = I16VEC3;
497 (*KeywordMap)["i16vec4"] = I16VEC4;
498 (*KeywordMap)["uint16_t"] = UINT16_T;
499 (*KeywordMap)["u16vec2"] = U16VEC2;
500 (*KeywordMap)["u16vec3"] = U16VEC3;
501 (*KeywordMap)["u16vec4"] = U16VEC4;
503 (*KeywordMap)["int32_t"] = INT32_T;
504 (*KeywordMap)["i32vec2"] = I32VEC2;
505 (*KeywordMap)["i32vec3"] = I32VEC3;
506 (*KeywordMap)["i32vec4"] = I32VEC4;
507 (*KeywordMap)["uint32_t"] = UINT32_T;
508 (*KeywordMap)["u32vec2"] = U32VEC2;
509 (*KeywordMap)["u32vec3"] = U32VEC3;
510 (*KeywordMap)["u32vec4"] = U32VEC4;
512 (*KeywordMap)["float16_t"] = FLOAT16_T;
513 (*KeywordMap)["f16vec2"] = F16VEC2;
514 (*KeywordMap)["f16vec3"] = F16VEC3;
515 (*KeywordMap)["f16vec4"] = F16VEC4;
516 (*KeywordMap)["f16mat2"] = F16MAT2;
517 (*KeywordMap)["f16mat3"] = F16MAT3;
518 (*KeywordMap)["f16mat4"] = F16MAT4;
519 (*KeywordMap)["f16mat2x2"] = F16MAT2X2;
520 (*KeywordMap)["f16mat2x3"] = F16MAT2X3;
521 (*KeywordMap)["f16mat2x4"] = F16MAT2X4;
522 (*KeywordMap)["f16mat3x2"] = F16MAT3X2;
523 (*KeywordMap)["f16mat3x3"] = F16MAT3X3;
524 (*KeywordMap)["f16mat3x4"] = F16MAT3X4;
525 (*KeywordMap)["f16mat4x2"] = F16MAT4X2;
526 (*KeywordMap)["f16mat4x3"] = F16MAT4X3;
527 (*KeywordMap)["f16mat4x4"] = F16MAT4X4;
529 (*KeywordMap)["float32_t"] = FLOAT32_T;
530 (*KeywordMap)["f32vec2"] = F32VEC2;
531 (*KeywordMap)["f32vec3"] = F32VEC3;
532 (*KeywordMap)["f32vec4"] = F32VEC4;
533 (*KeywordMap)["f32mat2"] = F32MAT2;
534 (*KeywordMap)["f32mat3"] = F32MAT3;
535 (*KeywordMap)["f32mat4"] = F32MAT4;
536 (*KeywordMap)["f32mat2x2"] = F32MAT2X2;
537 (*KeywordMap)["f32mat2x3"] = F32MAT2X3;
538 (*KeywordMap)["f32mat2x4"] = F32MAT2X4;
539 (*KeywordMap)["f32mat3x2"] = F32MAT3X2;
540 (*KeywordMap)["f32mat3x3"] = F32MAT3X3;
541 (*KeywordMap)["f32mat3x4"] = F32MAT3X4;
542 (*KeywordMap)["f32mat4x2"] = F32MAT4X2;
543 (*KeywordMap)["f32mat4x3"] = F32MAT4X3;
544 (*KeywordMap)["f32mat4x4"] = F32MAT4X4;
545 (*KeywordMap)["float64_t"] = FLOAT64_T;
546 (*KeywordMap)["f64vec2"] = F64VEC2;
547 (*KeywordMap)["f64vec3"] = F64VEC3;
548 (*KeywordMap)["f64vec4"] = F64VEC4;
549 (*KeywordMap)["f64mat2"] = F64MAT2;
550 (*KeywordMap)["f64mat3"] = F64MAT3;
551 (*KeywordMap)["f64mat4"] = F64MAT4;
552 (*KeywordMap)["f64mat2x2"] = F64MAT2X2;
553 (*KeywordMap)["f64mat2x3"] = F64MAT2X3;
554 (*KeywordMap)["f64mat2x4"] = F64MAT2X4;
555 (*KeywordMap)["f64mat3x2"] = F64MAT3X2;
556 (*KeywordMap)["f64mat3x3"] = F64MAT3X3;
557 (*KeywordMap)["f64mat3x4"] = F64MAT3X4;
558 (*KeywordMap)["f64mat4x2"] = F64MAT4X2;
559 (*KeywordMap)["f64mat4x3"] = F64MAT4X3;
560 (*KeywordMap)["f64mat4x4"] = F64MAT4X4;
563 (*KeywordMap)["sampler2D"] = SAMPLER2D;
564 (*KeywordMap)["samplerCube"] = SAMPLERCUBE;
565 (*KeywordMap)["samplerCubeShadow"] = SAMPLERCUBESHADOW;
566 (*KeywordMap)["sampler2DArray"] = SAMPLER2DARRAY;
567 (*KeywordMap)["sampler2DArrayShadow"] = SAMPLER2DARRAYSHADOW;
568 (*KeywordMap)["isampler2D"] = ISAMPLER2D;
569 (*KeywordMap)["isampler3D"] = ISAMPLER3D;
570 (*KeywordMap)["isamplerCube"] = ISAMPLERCUBE;
571 (*KeywordMap)["isampler2DArray"] = ISAMPLER2DARRAY;
572 (*KeywordMap)["usampler2D"] = USAMPLER2D;
573 (*KeywordMap)["usampler3D"] = USAMPLER3D;
574 (*KeywordMap)["usamplerCube"] = USAMPLERCUBE;
575 (*KeywordMap)["usampler2DArray"] = USAMPLER2DARRAY;
576 (*KeywordMap)["sampler3D"] = SAMPLER3D;
577 (*KeywordMap)["sampler2DShadow"] = SAMPLER2DSHADOW;
579 (*KeywordMap)["texture2D"] = TEXTURE2D;
580 (*KeywordMap)["textureCube"] = TEXTURECUBE;
581 (*KeywordMap)["texture2DArray"] = TEXTURE2DARRAY;
582 (*KeywordMap)["itexture2D"] = ITEXTURE2D;
583 (*KeywordMap)["itexture3D"] = ITEXTURE3D;
584 (*KeywordMap)["itextureCube"] = ITEXTURECUBE;
585 (*KeywordMap)["itexture2DArray"] = ITEXTURE2DARRAY;
586 (*KeywordMap)["utexture2D"] = UTEXTURE2D;
587 (*KeywordMap)["utexture3D"] = UTEXTURE3D;
588 (*KeywordMap)["utextureCube"] = UTEXTURECUBE;
589 (*KeywordMap)["utexture2DArray"] = UTEXTURE2DARRAY;
590 (*KeywordMap)["texture3D"] = TEXTURE3D;
592 (*KeywordMap)["sampler"] = SAMPLER;
593 (*KeywordMap)["samplerShadow"] = SAMPLERSHADOW;
596 (*KeywordMap)["textureCubeArray"] = TEXTURECUBEARRAY;
597 (*KeywordMap)["itextureCubeArray"] = ITEXTURECUBEARRAY;
598 (*KeywordMap)["utextureCubeArray"] = UTEXTURECUBEARRAY;
599 (*KeywordMap)["samplerCubeArray"] = SAMPLERCUBEARRAY;
600 (*KeywordMap)["samplerCubeArrayShadow"] = SAMPLERCUBEARRAYSHADOW;
601 (*KeywordMap)["isamplerCubeArray"] = ISAMPLERCUBEARRAY;
602 (*KeywordMap)["usamplerCubeArray"] = USAMPLERCUBEARRAY;
603 (*KeywordMap)["sampler1DArrayShadow"] = SAMPLER1DARRAYSHADOW;
604 (*KeywordMap)["isampler1DArray"] = ISAMPLER1DARRAY;
605 (*KeywordMap)["usampler1D"] = USAMPLER1D;
606 (*KeywordMap)["isampler1D"] = ISAMPLER1D;
607 (*KeywordMap)["usampler1DArray"] = USAMPLER1DARRAY;
608 (*KeywordMap)["samplerBuffer"] = SAMPLERBUFFER;
609 (*KeywordMap)["isampler2DRect"] = ISAMPLER2DRECT;
610 (*KeywordMap)["usampler2DRect"] = USAMPLER2DRECT;
611 (*KeywordMap)["isamplerBuffer"] = ISAMPLERBUFFER;
612 (*KeywordMap)["usamplerBuffer"] = USAMPLERBUFFER;
613 (*KeywordMap)["sampler2DMS"] = SAMPLER2DMS;
614 (*KeywordMap)["isampler2DMS"] = ISAMPLER2DMS;
615 (*KeywordMap)["usampler2DMS"] = USAMPLER2DMS;
616 (*KeywordMap)["sampler2DMSArray"] = SAMPLER2DMSARRAY;
617 (*KeywordMap)["isampler2DMSArray"] = ISAMPLER2DMSARRAY;
618 (*KeywordMap)["usampler2DMSArray"] = USAMPLER2DMSARRAY;
619 (*KeywordMap)["sampler1D"] = SAMPLER1D;
620 (*KeywordMap)["sampler1DShadow"] = SAMPLER1DSHADOW;
621 (*KeywordMap)["sampler2DRect"] = SAMPLER2DRECT;
622 (*KeywordMap)["sampler2DRectShadow"] = SAMPLER2DRECTSHADOW;
623 (*KeywordMap)["sampler1DArray"] = SAMPLER1DARRAY;
625 (*KeywordMap)["samplerExternalOES"] = SAMPLEREXTERNALOES; // GL_OES_EGL_image_external
627 (*KeywordMap)["__samplerExternal2DY2YEXT"] = SAMPLEREXTERNAL2DY2YEXT; // GL_EXT_YUV_target
629 (*KeywordMap)["itexture1DArray"] = ITEXTURE1DARRAY;
630 (*KeywordMap)["utexture1D"] = UTEXTURE1D;
631 (*KeywordMap)["itexture1D"] = ITEXTURE1D;
632 (*KeywordMap)["utexture1DArray"] = UTEXTURE1DARRAY;
633 (*KeywordMap)["textureBuffer"] = TEXTUREBUFFER;
634 (*KeywordMap)["itexture2DRect"] = ITEXTURE2DRECT;
635 (*KeywordMap)["utexture2DRect"] = UTEXTURE2DRECT;
636 (*KeywordMap)["itextureBuffer"] = ITEXTUREBUFFER;
637 (*KeywordMap)["utextureBuffer"] = UTEXTUREBUFFER;
638 (*KeywordMap)["texture2DMS"] = TEXTURE2DMS;
639 (*KeywordMap)["itexture2DMS"] = ITEXTURE2DMS;
640 (*KeywordMap)["utexture2DMS"] = UTEXTURE2DMS;
641 (*KeywordMap)["texture2DMSArray"] = TEXTURE2DMSARRAY;
642 (*KeywordMap)["itexture2DMSArray"] = ITEXTURE2DMSARRAY;
643 (*KeywordMap)["utexture2DMSArray"] = UTEXTURE2DMSARRAY;
644 (*KeywordMap)["texture1D"] = TEXTURE1D;
645 (*KeywordMap)["texture2DRect"] = TEXTURE2DRECT;
646 (*KeywordMap)["texture1DArray"] = TEXTURE1DARRAY;
648 (*KeywordMap)["subpassInput"] = SUBPASSINPUT;
649 (*KeywordMap)["subpassInputMS"] = SUBPASSINPUTMS;
650 (*KeywordMap)["isubpassInput"] = ISUBPASSINPUT;
651 (*KeywordMap)["isubpassInputMS"] = ISUBPASSINPUTMS;
652 (*KeywordMap)["usubpassInput"] = USUBPASSINPUT;
653 (*KeywordMap)["usubpassInputMS"] = USUBPASSINPUTMS;
655 (*KeywordMap)["f16sampler1D"] = F16SAMPLER1D;
656 (*KeywordMap)["f16sampler2D"] = F16SAMPLER2D;
657 (*KeywordMap)["f16sampler3D"] = F16SAMPLER3D;
658 (*KeywordMap)["f16sampler2DRect"] = F16SAMPLER2DRECT;
659 (*KeywordMap)["f16samplerCube"] = F16SAMPLERCUBE;
660 (*KeywordMap)["f16sampler1DArray"] = F16SAMPLER1DARRAY;
661 (*KeywordMap)["f16sampler2DArray"] = F16SAMPLER2DARRAY;
662 (*KeywordMap)["f16samplerCubeArray"] = F16SAMPLERCUBEARRAY;
663 (*KeywordMap)["f16samplerBuffer"] = F16SAMPLERBUFFER;
664 (*KeywordMap)["f16sampler2DMS"] = F16SAMPLER2DMS;
665 (*KeywordMap)["f16sampler2DMSArray"] = F16SAMPLER2DMSARRAY;
666 (*KeywordMap)["f16sampler1DShadow"] = F16SAMPLER1DSHADOW;
667 (*KeywordMap)["f16sampler2DShadow"] = F16SAMPLER2DSHADOW;
668 (*KeywordMap)["f16sampler2DRectShadow"] = F16SAMPLER2DRECTSHADOW;
669 (*KeywordMap)["f16samplerCubeShadow"] = F16SAMPLERCUBESHADOW;
670 (*KeywordMap)["f16sampler1DArrayShadow"] = F16SAMPLER1DARRAYSHADOW;
671 (*KeywordMap)["f16sampler2DArrayShadow"] = F16SAMPLER2DARRAYSHADOW;
672 (*KeywordMap)["f16samplerCubeArrayShadow"] = F16SAMPLERCUBEARRAYSHADOW;
674 (*KeywordMap)["f16image1D"] = F16IMAGE1D;
675 (*KeywordMap)["f16image2D"] = F16IMAGE2D;
676 (*KeywordMap)["f16image3D"] = F16IMAGE3D;
677 (*KeywordMap)["f16image2DRect"] = F16IMAGE2DRECT;
678 (*KeywordMap)["f16imageCube"] = F16IMAGECUBE;
679 (*KeywordMap)["f16image1DArray"] = F16IMAGE1DARRAY;
680 (*KeywordMap)["f16image2DArray"] = F16IMAGE2DARRAY;
681 (*KeywordMap)["f16imageCubeArray"] = F16IMAGECUBEARRAY;
682 (*KeywordMap)["f16imageBuffer"] = F16IMAGEBUFFER;
683 (*KeywordMap)["f16image2DMS"] = F16IMAGE2DMS;
684 (*KeywordMap)["f16image2DMSArray"] = F16IMAGE2DMSARRAY;
686 (*KeywordMap)["f16texture1D"] = F16TEXTURE1D;
687 (*KeywordMap)["f16texture2D"] = F16TEXTURE2D;
688 (*KeywordMap)["f16texture3D"] = F16TEXTURE3D;
689 (*KeywordMap)["f16texture2DRect"] = F16TEXTURE2DRECT;
690 (*KeywordMap)["f16textureCube"] = F16TEXTURECUBE;
691 (*KeywordMap)["f16texture1DArray"] = F16TEXTURE1DARRAY;
692 (*KeywordMap)["f16texture2DArray"] = F16TEXTURE2DARRAY;
693 (*KeywordMap)["f16textureCubeArray"] = F16TEXTURECUBEARRAY;
694 (*KeywordMap)["f16textureBuffer"] = F16TEXTUREBUFFER;
695 (*KeywordMap)["f16texture2DMS"] = F16TEXTURE2DMS;
696 (*KeywordMap)["f16texture2DMSArray"] = F16TEXTURE2DMSARRAY;
698 (*KeywordMap)["f16subpassInput"] = F16SUBPASSINPUT;
699 (*KeywordMap)["f16subpassInputMS"] = F16SUBPASSINPUTMS;
700 (*KeywordMap)["__explicitInterpAMD"] = EXPLICITINTERPAMD;
701 (*KeywordMap)["pervertexNV"] = PERVERTEXNV;
702 (*KeywordMap)["precise"] = PRECISE;
704 (*KeywordMap)["rayPayloadNV"] = PAYLOADNV;
705 (*KeywordMap)["rayPayloadInNV"] = PAYLOADINNV;
706 (*KeywordMap)["hitAttributeNV"] = HITATTRNV;
707 (*KeywordMap)["callableDataNV"] = CALLDATANV;
708 (*KeywordMap)["callableDataInNV"] = CALLDATAINNV;
709 (*KeywordMap)["accelerationStructureNV"] = ACCSTRUCTNV;
710 (*KeywordMap)["perprimitiveNV"] = PERPRIMITIVENV;
711 (*KeywordMap)["perviewNV"] = PERVIEWNV;
712 (*KeywordMap)["taskNV"] = PERTASKNV;
714 (*KeywordMap)["fcoopmatNV"] = FCOOPMATNV;
715 (*KeywordMap)["icoopmatNV"] = ICOOPMATNV;
716 (*KeywordMap)["ucoopmatNV"] = UCOOPMATNV;
718 ReservedSet = new std::unordered_set<const char*, str_hash, str_eq>;
720 ReservedSet->insert("common");
721 ReservedSet->insert("partition");
722 ReservedSet->insert("active");
723 ReservedSet->insert("asm");
724 ReservedSet->insert("class");
725 ReservedSet->insert("union");
726 ReservedSet->insert("enum");
727 ReservedSet->insert("typedef");
728 ReservedSet->insert("template");
729 ReservedSet->insert("this");
730 ReservedSet->insert("goto");
731 ReservedSet->insert("inline");
732 ReservedSet->insert("noinline");
733 ReservedSet->insert("public");
734 ReservedSet->insert("static");
735 ReservedSet->insert("extern");
736 ReservedSet->insert("external");
737 ReservedSet->insert("interface");
738 ReservedSet->insert("long");
739 ReservedSet->insert("short");
740 ReservedSet->insert("half");
741 ReservedSet->insert("fixed");
742 ReservedSet->insert("unsigned");
743 ReservedSet->insert("input");
744 ReservedSet->insert("output");
745 ReservedSet->insert("hvec2");
746 ReservedSet->insert("hvec3");
747 ReservedSet->insert("hvec4");
748 ReservedSet->insert("fvec2");
749 ReservedSet->insert("fvec3");
750 ReservedSet->insert("fvec4");
751 ReservedSet->insert("sampler3DRect");
752 ReservedSet->insert("filter");
753 ReservedSet->insert("sizeof");
754 ReservedSet->insert("cast");
755 ReservedSet->insert("namespace");
756 ReservedSet->insert("using");
760 void TScanContext::deleteKeywordMap()
763 KeywordMap = nullptr;
766 ReservedSet = nullptr;
770 // Called by yylex to get the next token.
771 // Returning 0 implies end of input.
772 int TScanContext::tokenize(TPpContext* pp, TParserToken& token)
775 parserToken = &token;
777 int token = pp->tokenize(ppToken);
778 if (token == EndOfInput)
781 tokenText = ppToken.name;
783 parserToken->sType.lex.loc = loc;
785 case ';': afterType = false; afterBuffer = false; return SEMICOLON;
786 case ',': afterType = false; return COMMA;
787 case ':': return COLON;
788 case '=': afterType = false; return EQUAL;
789 case '(': afterType = false; return LEFT_PAREN;
790 case ')': afterType = false; return RIGHT_PAREN;
791 case '.': field = true; return DOT;
792 case '!': return BANG;
793 case '-': return DASH;
794 case '~': return TILDE;
795 case '+': return PLUS;
796 case '*': return STAR;
797 case '/': return SLASH;
798 case '%': return PERCENT;
799 case '<': return LEFT_ANGLE;
800 case '>': return RIGHT_ANGLE;
801 case '|': return VERTICAL_BAR;
802 case '^': return CARET;
803 case '&': return AMPERSAND;
804 case '?': return QUESTION;
805 case '[': return LEFT_BRACKET;
806 case ']': return RIGHT_BRACKET;
807 case '{': afterStruct = false; afterBuffer = false; return LEFT_BRACE;
808 case '}': return RIGHT_BRACE;
810 parseContext.error(loc, "illegal use of escape character", "\\", "");
813 case PPAtomAddAssign: return ADD_ASSIGN;
814 case PPAtomSubAssign: return SUB_ASSIGN;
815 case PPAtomMulAssign: return MUL_ASSIGN;
816 case PPAtomDivAssign: return DIV_ASSIGN;
817 case PPAtomModAssign: return MOD_ASSIGN;
819 case PpAtomRight: return RIGHT_OP;
820 case PpAtomLeft: return LEFT_OP;
822 case PpAtomRightAssign: return RIGHT_ASSIGN;
823 case PpAtomLeftAssign: return LEFT_ASSIGN;
824 case PpAtomAndAssign: return AND_ASSIGN;
825 case PpAtomOrAssign: return OR_ASSIGN;
826 case PpAtomXorAssign: return XOR_ASSIGN;
828 case PpAtomAnd: return AND_OP;
829 case PpAtomOr: return OR_OP;
830 case PpAtomXor: return XOR_OP;
832 case PpAtomEQ: return EQ_OP;
833 case PpAtomGE: return GE_OP;
834 case PpAtomNE: return NE_OP;
835 case PpAtomLE: return LE_OP;
837 case PpAtomDecrement: return DEC_OP;
838 case PpAtomIncrement: return INC_OP;
840 case PpAtomColonColon:
841 parseContext.error(loc, "not supported", "::", "");
844 case PpAtomConstInt: parserToken->sType.lex.i = ppToken.ival; return INTCONSTANT;
845 case PpAtomConstUint: parserToken->sType.lex.i = ppToken.ival; return UINTCONSTANT;
846 case PpAtomConstFloat: parserToken->sType.lex.d = ppToken.dval; return FLOATCONSTANT;
848 case PpAtomConstInt16: parserToken->sType.lex.i = ppToken.ival; return INT16CONSTANT;
849 case PpAtomConstUint16: parserToken->sType.lex.i = ppToken.ival; return UINT16CONSTANT;
850 case PpAtomConstInt64: parserToken->sType.lex.i64 = ppToken.i64val; return INT64CONSTANT;
851 case PpAtomConstUint64: parserToken->sType.lex.i64 = ppToken.i64val; return UINT64CONSTANT;
852 case PpAtomConstDouble: parserToken->sType.lex.d = ppToken.dval; return DOUBLECONSTANT;
853 case PpAtomConstFloat16: parserToken->sType.lex.d = ppToken.dval; return FLOAT16CONSTANT;
855 case PpAtomIdentifier:
857 int token = tokenizeIdentifier();
862 case EndOfInput: return 0;
866 buf[0] = (char)token;
868 parseContext.error(loc, "unexpected token", buf, "");
874 int TScanContext::tokenizeIdentifier()
877 if (ReservedSet->find(tokenText) != ReservedSet->end())
878 return reservedWord();
881 auto it = KeywordMap->find(tokenText);
882 if (it == KeywordMap->end()) {
883 // Should have an identifier of some sort
884 return identifierOrType();
886 keyword = it->second;
908 if ((parseContext.isEsProfile() && parseContext.version < 310) ||
909 (!parseContext.isEsProfile() && parseContext.version < 430))
910 return identifierOrType();
919 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
920 (!parseContext.isEsProfile() && parseContext.version < 130))
946 if (strcmp("true", tokenText) == 0)
947 parserToken->sType.lex.b = true;
949 parserToken->sType.lex.b = false;
953 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
954 (!parseContext.isEsProfile() && parseContext.version < 130))
955 return identifierOrType();
958 if (parseContext.isEsProfile() && parseContext.version < 300)
960 else if (!parseContext.isEsProfile() && parseContext.version < 130)
961 return identifierOrType();
964 if (parseContext.version < 120)
965 return identifierOrType();
968 if (!parseContext.isEsProfile() && parseContext.version < 120)
969 return identifierOrType();
972 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
973 (!parseContext.isEsProfile() && parseContext.version < 330))
974 return reservedWord();
975 return identifierOrType();
979 bool reserved = (parseContext.isEsProfile() && parseContext.version >= 300) ||
980 (!parseContext.isEsProfile() && parseContext.version >= 420);
981 return identifierOrReserved(reserved);
985 bool reserved = parseContext.isEsProfile() || parseContext.version >= 130;
986 return identifierOrReserved(reserved);
991 if (parseContext.extensionTurnedOn(E_GL_NV_shader_noperspective_interpolation))
993 return es30ReservedFromGLSL(130);
996 if (parseContext.extensionTurnedOn(E_GL_EXT_nonuniform_qualifier))
999 return identifierOrType();
1002 if (parseContext.isEsProfile() && parseContext.version >= 300)
1011 if (parseContext.symbolTable.atBuiltInLevel() ||
1012 parseContext.extensionTurnedOn(E_GL_NV_ray_tracing))
1014 return identifierOrType();
1016 if ((parseContext.isEsProfile() && parseContext.version >= 310) ||
1017 parseContext.extensionTurnedOn(E_GL_ARB_shader_atomic_counters))
1019 return es30ReservedFromGLSL(420);
1022 case DEVICECOHERENT:
1023 case QUEUEFAMILYCOHERENT:
1024 case WORKGROUPCOHERENT:
1025 case SUBGROUPCOHERENT:
1030 if (parseContext.isEsProfile() && parseContext.version >= 310)
1032 return es30ReservedFromGLSL(parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store) ? 130 : 420);
1034 if (parseContext.isEsProfile() && parseContext.version >= 310)
1036 if (! parseContext.symbolTable.atBuiltInLevel() && (parseContext.isEsProfile() ||
1037 (parseContext.version < 420 && ! parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))))
1041 if (parseContext.symbolTable.atBuiltInLevel() ||
1042 (parseContext.isEsProfile() &&
1043 (parseContext.version >= 320 ||
1044 parseContext.extensionsTurnedOn(Num_AEP_tessellation_shader, AEP_tessellation_shader))) ||
1045 (!parseContext.isEsProfile() && parseContext.extensionTurnedOn(E_GL_ARB_tessellation_shader)))
1048 return es30ReservedFromGLSL(400);
1051 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1052 parseContext.extensionsTurnedOn(1, &E_GL_OES_shader_multisample_interpolation))
1054 return es30ReservedFromGLSL(400);
1057 return es30ReservedFromGLSL(400);
1060 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1061 (!parseContext.isEsProfile() && parseContext.version < 140))
1062 return identifierOrType();
1066 const int numLayoutExts = 2;
1067 const char* layoutExts[numLayoutExts] = { E_GL_ARB_shading_language_420pack,
1068 E_GL_ARB_explicit_attrib_location };
1069 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1070 (!parseContext.isEsProfile() && parseContext.version < 140 &&
1071 ! parseContext.extensionsTurnedOn(numLayoutExts, layoutExts)))
1072 return identifierOrType();
1076 case HIGH_PRECISION:
1077 case MEDIUM_PRECISION:
1080 return precisionKeyword();
1118 return firstGenerationImage(false);
1124 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1125 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1127 return firstGenerationImage(false);
1142 return firstGenerationImage(true);
1144 case IMAGECUBEARRAY:
1145 case IIMAGECUBEARRAY:
1146 case UIMAGECUBEARRAY:
1148 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1149 parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
1151 return secondGenerationImage();
1156 case IMAGE2DMSARRAY:
1157 case IIMAGE2DMSARRAY:
1158 case UIMAGE2DMSARRAY:
1160 return secondGenerationImage();
1167 if (parseContext.isEsProfile() || parseContext.version < 150 ||
1168 (!parseContext.symbolTable.atBuiltInLevel() &&
1169 parseContext.version < 400 &&
1170 !parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_fp64)))
1183 if (parseContext.symbolTable.atBuiltInLevel() ||
1184 parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_int64) ||
1185 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1186 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int64))
1188 return identifierOrType();
1199 if (parseContext.symbolTable.atBuiltInLevel() ||
1200 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1201 parseContext.extensionTurnedOn(E_GL_EXT_shader_8bit_storage) ||
1202 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int8))
1204 return identifierOrType();
1215 if (parseContext.symbolTable.atBuiltInLevel() ||
1216 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_int16) ||
1217 parseContext.extensionTurnedOn(E_GL_EXT_shader_16bit_storage) ||
1218 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1219 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int16))
1221 return identifierOrType();
1231 if (parseContext.symbolTable.atBuiltInLevel() ||
1232 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1233 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int32))
1235 return identifierOrType();
1253 if (parseContext.symbolTable.atBuiltInLevel() ||
1254 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1255 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float32))
1257 return identifierOrType();
1276 if (parseContext.symbolTable.atBuiltInLevel() ||
1277 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1278 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float64))
1280 return identifierOrType();
1287 if (parseContext.symbolTable.atBuiltInLevel() ||
1288 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float) ||
1289 parseContext.extensionTurnedOn(E_GL_EXT_shader_16bit_storage) ||
1290 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1291 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float16))
1294 return identifierOrType();
1309 if (parseContext.symbolTable.atBuiltInLevel() ||
1310 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float) ||
1311 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1312 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float16))
1315 return identifierOrType();
1317 case SAMPLERCUBEARRAY:
1318 case SAMPLERCUBEARRAYSHADOW:
1319 case ISAMPLERCUBEARRAY:
1320 case USAMPLERCUBEARRAY:
1322 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1323 parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
1325 if (parseContext.isEsProfile() || (parseContext.version < 400 && ! parseContext.extensionTurnedOn(E_GL_ARB_texture_cube_map_array)))
1329 case TEXTURECUBEARRAY:
1330 case ITEXTURECUBEARRAY:
1331 case UTEXTURECUBEARRAY:
1332 if (parseContext.spvVersion.vulkan > 0)
1335 return identifierOrType();
1342 case SAMPLERCUBESHADOW:
1343 case SAMPLER2DARRAY:
1344 case SAMPLER2DARRAYSHADOW:
1348 case ISAMPLER2DARRAY:
1352 case USAMPLER2DARRAY:
1354 return nonreservedKeyword(300, 130);
1358 if (parseContext.isEsProfile() && parseContext.version < 300) {
1359 if (!parseContext.extensionTurnedOn(E_GL_OES_texture_3D))
1364 case SAMPLER2DSHADOW:
1366 if (parseContext.isEsProfile() && parseContext.version < 300) {
1367 if (!parseContext.extensionTurnedOn(E_GL_EXT_shadow_samplers))
1374 case TEXTURE2DARRAY:
1378 case ITEXTURE2DARRAY:
1382 case UTEXTURE2DARRAY:
1386 if (parseContext.spvVersion.vulkan > 0)
1389 return identifierOrType();
1393 case ISAMPLER1DARRAY:
1394 case SAMPLER1DARRAYSHADOW:
1396 case USAMPLER1DARRAY:
1398 return es30ReservedFromGLSL(130);
1399 case ISAMPLER2DRECT:
1400 case USAMPLER2DRECT:
1402 return es30ReservedFromGLSL(140);
1406 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1407 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1409 return es30ReservedFromGLSL(130);
1411 case ISAMPLERBUFFER:
1412 case USAMPLERBUFFER:
1414 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1415 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1417 return es30ReservedFromGLSL(140);
1423 if (parseContext.isEsProfile() && parseContext.version >= 310)
1425 if (!parseContext.isEsProfile() && (parseContext.version > 140 ||
1426 (parseContext.version == 140 && parseContext.extensionsTurnedOn(1, &E_GL_ARB_texture_multisample))))
1428 return es30ReservedFromGLSL(150);
1430 case SAMPLER2DMSARRAY:
1431 case ISAMPLER2DMSARRAY:
1432 case USAMPLER2DMSARRAY:
1434 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1435 parseContext.extensionsTurnedOn(1, &E_GL_OES_texture_storage_multisample_2d_array))
1437 if (!parseContext.isEsProfile() && (parseContext.version > 140 ||
1438 (parseContext.version == 140 && parseContext.extensionsTurnedOn(1, &E_GL_ARB_texture_multisample))))
1440 return es30ReservedFromGLSL(150);
1443 case SAMPLER1DSHADOW:
1445 if (parseContext.isEsProfile())
1450 case SAMPLER2DRECTSHADOW:
1452 if (parseContext.isEsProfile())
1454 else if (parseContext.version < 140 && ! parseContext.symbolTable.atBuiltInLevel() && ! parseContext.extensionTurnedOn(E_GL_ARB_texture_rectangle)) {
1455 if (parseContext.relaxedErrors())
1456 parseContext.requireExtensions(loc, 1, &E_GL_ARB_texture_rectangle, "texture-rectangle sampler keyword");
1462 case SAMPLER1DARRAY:
1464 if (parseContext.isEsProfile() && parseContext.version == 300)
1466 else if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1467 (!parseContext.isEsProfile() && parseContext.version < 130))
1468 return identifierOrType();
1471 case SAMPLEREXTERNALOES:
1473 if (parseContext.symbolTable.atBuiltInLevel() ||
1474 parseContext.extensionTurnedOn(E_GL_OES_EGL_image_external) ||
1475 parseContext.extensionTurnedOn(E_GL_OES_EGL_image_external_essl3))
1477 return identifierOrType();
1479 case SAMPLEREXTERNAL2DY2YEXT:
1481 if (parseContext.symbolTable.atBuiltInLevel() ||
1482 parseContext.extensionTurnedOn(E_GL_EXT_YUV_target))
1484 return identifierOrType();
1486 case ITEXTURE1DARRAY:
1489 case UTEXTURE1DARRAY:
1491 case ITEXTURE2DRECT:
1492 case UTEXTURE2DRECT:
1493 case ITEXTUREBUFFER:
1494 case UTEXTUREBUFFER:
1498 case TEXTURE2DMSARRAY:
1499 case ITEXTURE2DMSARRAY:
1500 case UTEXTURE2DMSARRAY:
1503 case TEXTURE1DARRAY:
1504 if (parseContext.spvVersion.vulkan > 0)
1507 return identifierOrType();
1510 case SUBPASSINPUTMS:
1512 case ISUBPASSINPUTMS:
1514 case USUBPASSINPUTMS:
1515 if (parseContext.spvVersion.vulkan > 0)
1518 return identifierOrType();
1523 case F16SAMPLER2DRECT:
1524 case F16SAMPLERCUBE:
1525 case F16SAMPLER1DARRAY:
1526 case F16SAMPLER2DARRAY:
1527 case F16SAMPLERCUBEARRAY:
1528 case F16SAMPLERBUFFER:
1529 case F16SAMPLER2DMS:
1530 case F16SAMPLER2DMSARRAY:
1531 case F16SAMPLER1DSHADOW:
1532 case F16SAMPLER2DSHADOW:
1533 case F16SAMPLER1DARRAYSHADOW:
1534 case F16SAMPLER2DARRAYSHADOW:
1535 case F16SAMPLER2DRECTSHADOW:
1536 case F16SAMPLERCUBESHADOW:
1537 case F16SAMPLERCUBEARRAYSHADOW:
1542 case F16IMAGE2DRECT:
1544 case F16IMAGE1DARRAY:
1545 case F16IMAGE2DARRAY:
1546 case F16IMAGECUBEARRAY:
1547 case F16IMAGEBUFFER:
1549 case F16IMAGE2DMSARRAY:
1554 case F16TEXTURE2DRECT:
1555 case F16TEXTURECUBE:
1556 case F16TEXTURE1DARRAY:
1557 case F16TEXTURE2DARRAY:
1558 case F16TEXTURECUBEARRAY:
1559 case F16TEXTUREBUFFER:
1560 case F16TEXTURE2DMS:
1561 case F16TEXTURE2DMSARRAY:
1563 case F16SUBPASSINPUT:
1564 case F16SUBPASSINPUTMS:
1566 if (parseContext.symbolTable.atBuiltInLevel() ||
1567 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float_fetch))
1569 return identifierOrType();
1571 case EXPLICITINTERPAMD:
1572 if (parseContext.extensionTurnedOn(E_GL_AMD_shader_explicit_vertex_parameter))
1574 return identifierOrType();
1577 if ((!parseContext.isEsProfile() && parseContext.version >= 450) ||
1578 parseContext.extensionTurnedOn(E_GL_NV_fragment_shader_barycentric))
1580 return identifierOrType();
1583 if ((parseContext.isEsProfile() &&
1584 (parseContext.version >= 320 || parseContext.extensionsTurnedOn(Num_AEP_gpu_shader5, AEP_gpu_shader5))) ||
1585 (!parseContext.isEsProfile() && parseContext.version >= 400))
1587 if (parseContext.isEsProfile() && parseContext.version == 310) {
1591 return identifierOrType();
1593 case PERPRIMITIVENV:
1596 if ((!parseContext.isEsProfile() && parseContext.version >= 450) ||
1597 (parseContext.isEsProfile() && parseContext.version >= 320) ||
1598 parseContext.extensionTurnedOn(E_GL_NV_mesh_shader))
1600 return identifierOrType();
1604 if (parseContext.symbolTable.atBuiltInLevel() ||
1605 parseContext.extensionTurnedOn(E_GL_NV_cooperative_matrix))
1607 return identifierOrType();
1612 if (parseContext.symbolTable.atBuiltInLevel() ||
1613 parseContext.extensionTurnedOn(E_GL_NV_integer_cooperative_matrix))
1615 return identifierOrType();
1618 if (parseContext.extensionTurnedOn(E_GL_EXT_demote_to_helper_invocation))
1621 return identifierOrType();
1625 parseContext.infoSink.info.message(EPrefixInternalError, "Unknown glslang keyword", loc);
1630 int TScanContext::identifierOrType()
1632 parserToken->sType.lex.string = NewPoolTString(tokenText);
1636 parserToken->sType.lex.symbol = parseContext.symbolTable.find(*parserToken->sType.lex.string);
1637 if ((afterType == false && afterStruct == false) && parserToken->sType.lex.symbol != nullptr) {
1638 if (const TVariable* variable = parserToken->sType.lex.symbol->getAsVariable()) {
1639 if (variable->isUserType() &&
1640 // treat redeclaration of forward-declared buffer/uniform reference as an identifier
1641 !(variable->getType().isReference() && afterBuffer)) {
1652 // Give an error for use of a reserved symbol.
1653 // However, allow built-in declarations to use reserved words, to allow
1654 // extension support before the extension is enabled.
1655 int TScanContext::reservedWord()
1657 if (! parseContext.symbolTable.atBuiltInLevel())
1658 parseContext.error(loc, "Reserved word.", tokenText, "", "");
1663 int TScanContext::identifierOrReserved(bool reserved)
1671 if (parseContext.isForwardCompatible())
1672 parseContext.warn(loc, "using future reserved keyword", tokenText, "");
1674 return identifierOrType();
1677 // For keywords that suddenly showed up on non-ES (not previously reserved)
1678 // but then got reserved by ES 3.0.
1679 int TScanContext::es30ReservedFromGLSL(int version)
1681 if (parseContext.symbolTable.atBuiltInLevel())
1684 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1685 (!parseContext.isEsProfile() && parseContext.version < version)) {
1686 if (parseContext.isForwardCompatible())
1687 parseContext.warn(loc, "future reserved word in ES 300 and keyword in GLSL", tokenText, "");
1689 return identifierOrType();
1690 } else if (parseContext.isEsProfile() && parseContext.version >= 300)
1696 // For a keyword that was never reserved, until it suddenly
1697 // showed up, both in an es version and a non-ES version.
1698 int TScanContext::nonreservedKeyword(int esVersion, int nonEsVersion)
1700 if ((parseContext.isEsProfile() && parseContext.version < esVersion) ||
1701 (!parseContext.isEsProfile() && parseContext.version < nonEsVersion)) {
1702 if (parseContext.isForwardCompatible())
1703 parseContext.warn(loc, "using future keyword", tokenText, "");
1705 return identifierOrType();
1711 int TScanContext::precisionKeyword()
1713 if (parseContext.isEsProfile() || parseContext.version >= 130)
1716 if (parseContext.isForwardCompatible())
1717 parseContext.warn(loc, "using ES precision qualifier keyword", tokenText, "");
1719 return identifierOrType();
1722 int TScanContext::matNxM()
1726 if (parseContext.version > 110)
1729 if (parseContext.isForwardCompatible())
1730 parseContext.warn(loc, "using future non-square matrix type keyword", tokenText, "");
1732 return identifierOrType();
1735 int TScanContext::dMat()
1739 if (parseContext.isEsProfile() && parseContext.version >= 300) {
1745 if (!parseContext.isEsProfile() && (parseContext.version >= 400 ||
1746 parseContext.symbolTable.atBuiltInLevel() ||
1747 (parseContext.version >= 150 && parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_fp64))))
1750 if (parseContext.isForwardCompatible())
1751 parseContext.warn(loc, "using future type keyword", tokenText, "");
1753 return identifierOrType();
1756 int TScanContext::firstGenerationImage(bool inEs310)
1758 if (parseContext.symbolTable.atBuiltInLevel() ||
1759 (!parseContext.isEsProfile() && (parseContext.version >= 420 ||
1760 parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))) ||
1761 (inEs310 && parseContext.isEsProfile() && parseContext.version >= 310))
1764 if ((parseContext.isEsProfile() && parseContext.version >= 300) ||
1765 (!parseContext.isEsProfile() && parseContext.version >= 130)) {
1771 if (parseContext.isForwardCompatible())
1772 parseContext.warn(loc, "using future type keyword", tokenText, "");
1774 return identifierOrType();
1777 int TScanContext::secondGenerationImage()
1779 if (parseContext.isEsProfile() && parseContext.version >= 310) {
1784 if (parseContext.symbolTable.atBuiltInLevel() ||
1785 (!parseContext.isEsProfile() &&
1786 (parseContext.version >= 420 || parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))))
1789 if (parseContext.isForwardCompatible())
1790 parseContext.warn(loc, "using future type keyword", tokenText, "");
1792 return identifierOrType();
1795 } // end namespace glslang