2 // Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
3 // Copyright (C) 2013 LunarG, Inc.
4 // Copyright (C) 2017 ARM Limited.
5 // Copyright (C) 2020 Google, Inc.
7 // All rights reserved.
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions
13 // Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
16 // Redistributions in binary form must reproduce the above
17 // copyright notice, this list of conditions and the following
18 // disclaimer in the documentation and/or other materials provided
19 // with the distribution.
21 // Neither the name of 3Dlabs Inc. Ltd. nor the names of its
22 // contributors may be used to endorse or promote products derived
23 // from this software without specific prior written permission.
25 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 // POSSIBILITY OF SUCH DAMAGE.
40 // GLSL scanning, leveraging the scanning done by the preprocessor.
44 #include <unordered_map>
45 #include <unordered_set>
47 #include "../Include/Types.h"
48 #include "SymbolTable.h"
49 #include "ParseHelper.h"
50 #include "attribute.h"
51 #include "glslang_tab.cpp.h"
52 #include "ScanContext.h"
55 // preprocessor includes
56 #include "preprocessor/PpContext.h"
57 #include "preprocessor/PpTokens.h"
59 // Required to avoid missing prototype warnings for some compilers
60 int yylex(YYSTYPE*, glslang::TParseContext&);
64 // read past any white space
65 void TInputScanner::consumeWhiteSpace(bool& foundNonSpaceTab)
67 int c = peek(); // don't accidentally consume anything other than whitespace
68 while (c == ' ' || c == '\t' || c == '\r' || c == '\n') {
69 if (c == '\r' || c == '\n')
70 foundNonSpaceTab = true;
76 // return true if a comment was actually consumed
77 bool TInputScanner::consumeComment()
82 get(); // consume the '/'
86 // a '//' style comment
87 get(); // consume the second '/'
90 while (c != EndOfInput && c != '\\' && c != '\r' && c != '\n')
93 if (c == EndOfInput || c == '\r' || c == '\n') {
94 while (c == '\r' || c == '\n')
97 // we reached the end of the comment
100 // it's a '\', so we need to keep going, after skipping what's escaped
102 // read the skipped character
105 // if it's a two-character newline, skip both characters
106 if (c == '\r' && peek() == '\n')
112 // put back the last non-comment character
117 } else if (c == '*') {
119 // a '/*' style comment
120 get(); // consume the '*'
123 while (c != EndOfInput && c != '*')
128 break; // end of comment
129 // not end of comment
130 } else // end of input
136 // it's not a comment, put the '/' back
143 // skip whitespace, then skip a comment, rinse, repeat
144 void TInputScanner::consumeWhitespaceComment(bool& foundNonSpaceTab)
147 consumeWhiteSpace(foundNonSpaceTab);
149 // if not starting a comment now, then done
151 if (c != '/' || c == EndOfInput)
154 // skip potential comment
155 foundNonSpaceTab = true;
156 if (! consumeComment())
162 // Returns true if there was non-white space (e.g., a comment, newline) before the #version
163 // or no #version was found; otherwise, returns false. There is no error case, it always
164 // succeeds, but will leave version == 0 if no #version was found.
166 // Sets notFirstToken based on whether tokens (beyond white space and comments)
167 // appeared before the #version.
169 // N.B. does not attempt to leave input in any particular known state. The assumption
170 // is that scanning will start anew, following the rules for the chosen version/profile,
171 // and with a corresponding parsing context.
173 bool TInputScanner::scanVersion(int& version, EProfile& profile, bool& notFirstToken)
175 // This function doesn't have to get all the semantics correct,
176 // just find the #version if there is a correct one present.
177 // The preprocessor will have the responsibility of getting all the semantics right.
179 bool versionNotFirst = false; // means not first WRT comments and white space, nothing more
180 notFirstToken = false; // means not first WRT to real tokens
181 version = 0; // means not found
182 profile = ENoProfile;
184 bool foundNonSpaceTab = false;
185 bool lookingInMiddle = false;
188 if (lookingInMiddle) {
189 notFirstToken = true;
190 // make forward progress by finishing off the current line plus extra new lines
191 if (peek() != '\n' && peek() != '\r') {
194 } while (c != EndOfInput && c != '\n' && c != '\r');
196 while (peek() == '\n' || peek() == '\r')
198 if (peek() == EndOfInput)
201 lookingInMiddle = true;
203 // Nominal start, skipping the desktop allowed comments and white space, but tracking if
204 // something else was found for ES:
205 consumeWhitespaceComment(foundNonSpaceTab);
206 if (foundNonSpaceTab)
207 versionNotFirst = true;
211 versionNotFirst = true;
218 } while (c == ' ' || c == '\t');
228 versionNotFirst = true;
235 } while (c == ' ' || c == '\t');
238 while (c >= '0' && c <= '9') {
239 version = 10 * version + (c - '0');
243 versionNotFirst = true;
248 while (c == ' ' || c == '\t')
252 const int maxProfileLength = 13; // not including any 0
253 char profileString[maxProfileLength];
255 for (profileLength = 0; profileLength < maxProfileLength; ++profileLength) {
256 if (c == EndOfInput || c == ' ' || c == '\t' || c == '\n' || c == '\r')
258 profileString[profileLength] = (char)c;
261 if (c != EndOfInput && c != ' ' && c != '\t' && c != '\n' && c != '\r') {
262 versionNotFirst = true;
266 if (profileLength == 2 && strncmp(profileString, "es", profileLength) == 0)
267 profile = EEsProfile;
268 else if (profileLength == 4 && strncmp(profileString, "core", profileLength) == 0)
269 profile = ECoreProfile;
270 else if (profileLength == 13 && strncmp(profileString, "compatibility", profileLength) == 0)
271 profile = ECompatibilityProfile;
273 return versionNotFirst;
277 // Fill this in when doing glslang-level scanning, to hand back to the parser.
280 explicit TParserToken(YYSTYPE& b) : sType(b) { }
284 TParserToken(TParserToken&);
285 TParserToken& operator=(TParserToken&);
288 } // end namespace glslang
290 // This is the function the glslang parser (i.e., bison) calls to get its next token
291 int yylex(YYSTYPE* glslangTokenDesc, glslang::TParseContext& parseContext)
293 glslang::TParserToken token(*glslangTokenDesc);
295 return parseContext.getScanContext()->tokenize(parseContext.getPpContext(), token);
302 bool operator()(const char* lhs, const char* rhs) const
304 return strcmp(lhs, rhs) == 0;
310 size_t operator()(const char* str) const
313 unsigned long hash = 5381;
316 while ((c = *str++) != 0)
317 hash = ((hash << 5) + hash) + c;
323 // A single global usable by all threads, by all versions, by all languages.
324 // After a single process-level initialization, this is read only and thread safe
325 std::unordered_map<const char*, int, str_hash, str_eq>* KeywordMap = nullptr;
327 std::unordered_set<const char*, str_hash, str_eq>* ReservedSet = nullptr;
334 void TScanContext::fillInKeywordMap()
336 if (KeywordMap != nullptr) {
337 // this is really an error, as this should called only once per process
338 // but, the only risk is if two threads called simultaneously
341 KeywordMap = new std::unordered_map<const char*, int, str_hash, str_eq>;
343 (*KeywordMap)["const"] = CONST;
344 (*KeywordMap)["uniform"] = UNIFORM;
345 (*KeywordMap)["buffer"] = BUFFER;
346 (*KeywordMap)["in"] = IN;
347 (*KeywordMap)["out"] = OUT;
348 (*KeywordMap)["smooth"] = SMOOTH;
349 (*KeywordMap)["flat"] = FLAT;
350 (*KeywordMap)["centroid"] = CENTROID;
351 (*KeywordMap)["invariant"] = INVARIANT;
352 (*KeywordMap)["packed"] = PACKED;
353 (*KeywordMap)["resource"] = RESOURCE;
354 (*KeywordMap)["inout"] = INOUT;
355 (*KeywordMap)["struct"] = STRUCT;
356 (*KeywordMap)["break"] = BREAK;
357 (*KeywordMap)["continue"] = CONTINUE;
358 (*KeywordMap)["do"] = DO;
359 (*KeywordMap)["for"] = FOR;
360 (*KeywordMap)["while"] = WHILE;
361 (*KeywordMap)["switch"] = SWITCH;
362 (*KeywordMap)["case"] = CASE;
363 (*KeywordMap)["default"] = DEFAULT;
364 (*KeywordMap)["if"] = IF;
365 (*KeywordMap)["else"] = ELSE;
366 (*KeywordMap)["discard"] = DISCARD;
367 (*KeywordMap)["return"] = RETURN;
368 (*KeywordMap)["void"] = VOID;
369 (*KeywordMap)["bool"] = BOOL;
370 (*KeywordMap)["float"] = FLOAT;
371 (*KeywordMap)["int"] = INT;
372 (*KeywordMap)["bvec2"] = BVEC2;
373 (*KeywordMap)["bvec3"] = BVEC3;
374 (*KeywordMap)["bvec4"] = BVEC4;
375 (*KeywordMap)["vec2"] = VEC2;
376 (*KeywordMap)["vec3"] = VEC3;
377 (*KeywordMap)["vec4"] = VEC4;
378 (*KeywordMap)["ivec2"] = IVEC2;
379 (*KeywordMap)["ivec3"] = IVEC3;
380 (*KeywordMap)["ivec4"] = IVEC4;
381 (*KeywordMap)["mat2"] = MAT2;
382 (*KeywordMap)["mat3"] = MAT3;
383 (*KeywordMap)["mat4"] = MAT4;
384 (*KeywordMap)["true"] = BOOLCONSTANT;
385 (*KeywordMap)["false"] = BOOLCONSTANT;
386 (*KeywordMap)["layout"] = LAYOUT;
387 (*KeywordMap)["shared"] = SHARED;
388 (*KeywordMap)["highp"] = HIGH_PRECISION;
389 (*KeywordMap)["mediump"] = MEDIUM_PRECISION;
390 (*KeywordMap)["lowp"] = LOW_PRECISION;
391 (*KeywordMap)["superp"] = SUPERP;
392 (*KeywordMap)["precision"] = PRECISION;
393 (*KeywordMap)["mat2x2"] = MAT2X2;
394 (*KeywordMap)["mat2x3"] = MAT2X3;
395 (*KeywordMap)["mat2x4"] = MAT2X4;
396 (*KeywordMap)["mat3x2"] = MAT3X2;
397 (*KeywordMap)["mat3x3"] = MAT3X3;
398 (*KeywordMap)["mat3x4"] = MAT3X4;
399 (*KeywordMap)["mat4x2"] = MAT4X2;
400 (*KeywordMap)["mat4x3"] = MAT4X3;
401 (*KeywordMap)["mat4x4"] = MAT4X4;
402 (*KeywordMap)["uint"] = UINT;
403 (*KeywordMap)["uvec2"] = UVEC2;
404 (*KeywordMap)["uvec3"] = UVEC3;
405 (*KeywordMap)["uvec4"] = UVEC4;
408 (*KeywordMap)["nonuniformEXT"] = NONUNIFORM;
409 (*KeywordMap)["demote"] = DEMOTE;
410 (*KeywordMap)["attribute"] = ATTRIBUTE;
411 (*KeywordMap)["varying"] = VARYING;
412 (*KeywordMap)["noperspective"] = NOPERSPECTIVE;
413 (*KeywordMap)["coherent"] = COHERENT;
414 (*KeywordMap)["devicecoherent"] = DEVICECOHERENT;
415 (*KeywordMap)["queuefamilycoherent"] = QUEUEFAMILYCOHERENT;
416 (*KeywordMap)["workgroupcoherent"] = WORKGROUPCOHERENT;
417 (*KeywordMap)["subgroupcoherent"] = SUBGROUPCOHERENT;
418 (*KeywordMap)["shadercallcoherent"] = SHADERCALLCOHERENT;
419 (*KeywordMap)["nonprivate"] = NONPRIVATE;
420 (*KeywordMap)["restrict"] = RESTRICT;
421 (*KeywordMap)["readonly"] = READONLY;
422 (*KeywordMap)["writeonly"] = WRITEONLY;
423 (*KeywordMap)["atomic_uint"] = ATOMIC_UINT;
424 (*KeywordMap)["volatile"] = VOLATILE;
425 (*KeywordMap)["patch"] = PATCH;
426 (*KeywordMap)["sample"] = SAMPLE;
427 (*KeywordMap)["subroutine"] = SUBROUTINE;
428 (*KeywordMap)["dmat2"] = DMAT2;
429 (*KeywordMap)["dmat3"] = DMAT3;
430 (*KeywordMap)["dmat4"] = DMAT4;
431 (*KeywordMap)["dmat2x2"] = DMAT2X2;
432 (*KeywordMap)["dmat2x3"] = DMAT2X3;
433 (*KeywordMap)["dmat2x4"] = DMAT2X4;
434 (*KeywordMap)["dmat3x2"] = DMAT3X2;
435 (*KeywordMap)["dmat3x3"] = DMAT3X3;
436 (*KeywordMap)["dmat3x4"] = DMAT3X4;
437 (*KeywordMap)["dmat4x2"] = DMAT4X2;
438 (*KeywordMap)["dmat4x3"] = DMAT4X3;
439 (*KeywordMap)["dmat4x4"] = DMAT4X4;
440 (*KeywordMap)["image1D"] = IMAGE1D;
441 (*KeywordMap)["iimage1D"] = IIMAGE1D;
442 (*KeywordMap)["uimage1D"] = UIMAGE1D;
443 (*KeywordMap)["image2D"] = IMAGE2D;
444 (*KeywordMap)["iimage2D"] = IIMAGE2D;
445 (*KeywordMap)["uimage2D"] = UIMAGE2D;
446 (*KeywordMap)["image3D"] = IMAGE3D;
447 (*KeywordMap)["iimage3D"] = IIMAGE3D;
448 (*KeywordMap)["uimage3D"] = UIMAGE3D;
449 (*KeywordMap)["image2DRect"] = IMAGE2DRECT;
450 (*KeywordMap)["iimage2DRect"] = IIMAGE2DRECT;
451 (*KeywordMap)["uimage2DRect"] = UIMAGE2DRECT;
452 (*KeywordMap)["imageCube"] = IMAGECUBE;
453 (*KeywordMap)["iimageCube"] = IIMAGECUBE;
454 (*KeywordMap)["uimageCube"] = UIMAGECUBE;
455 (*KeywordMap)["imageBuffer"] = IMAGEBUFFER;
456 (*KeywordMap)["iimageBuffer"] = IIMAGEBUFFER;
457 (*KeywordMap)["uimageBuffer"] = UIMAGEBUFFER;
458 (*KeywordMap)["image1DArray"] = IMAGE1DARRAY;
459 (*KeywordMap)["iimage1DArray"] = IIMAGE1DARRAY;
460 (*KeywordMap)["uimage1DArray"] = UIMAGE1DARRAY;
461 (*KeywordMap)["image2DArray"] = IMAGE2DARRAY;
462 (*KeywordMap)["iimage2DArray"] = IIMAGE2DARRAY;
463 (*KeywordMap)["uimage2DArray"] = UIMAGE2DARRAY;
464 (*KeywordMap)["imageCubeArray"] = IMAGECUBEARRAY;
465 (*KeywordMap)["iimageCubeArray"] = IIMAGECUBEARRAY;
466 (*KeywordMap)["uimageCubeArray"] = UIMAGECUBEARRAY;
467 (*KeywordMap)["image2DMS"] = IMAGE2DMS;
468 (*KeywordMap)["iimage2DMS"] = IIMAGE2DMS;
469 (*KeywordMap)["uimage2DMS"] = UIMAGE2DMS;
470 (*KeywordMap)["image2DMSArray"] = IMAGE2DMSARRAY;
471 (*KeywordMap)["iimage2DMSArray"] = IIMAGE2DMSARRAY;
472 (*KeywordMap)["uimage2DMSArray"] = UIMAGE2DMSARRAY;
473 (*KeywordMap)["double"] = DOUBLE;
474 (*KeywordMap)["dvec2"] = DVEC2;
475 (*KeywordMap)["dvec3"] = DVEC3;
476 (*KeywordMap)["dvec4"] = DVEC4;
477 (*KeywordMap)["int64_t"] = INT64_T;
478 (*KeywordMap)["uint64_t"] = UINT64_T;
479 (*KeywordMap)["i64vec2"] = I64VEC2;
480 (*KeywordMap)["i64vec3"] = I64VEC3;
481 (*KeywordMap)["i64vec4"] = I64VEC4;
482 (*KeywordMap)["u64vec2"] = U64VEC2;
483 (*KeywordMap)["u64vec3"] = U64VEC3;
484 (*KeywordMap)["u64vec4"] = U64VEC4;
486 // GL_EXT_shader_explicit_arithmetic_types
487 (*KeywordMap)["int8_t"] = INT8_T;
488 (*KeywordMap)["i8vec2"] = I8VEC2;
489 (*KeywordMap)["i8vec3"] = I8VEC3;
490 (*KeywordMap)["i8vec4"] = I8VEC4;
491 (*KeywordMap)["uint8_t"] = UINT8_T;
492 (*KeywordMap)["u8vec2"] = U8VEC2;
493 (*KeywordMap)["u8vec3"] = U8VEC3;
494 (*KeywordMap)["u8vec4"] = U8VEC4;
496 (*KeywordMap)["int16_t"] = INT16_T;
497 (*KeywordMap)["i16vec2"] = I16VEC2;
498 (*KeywordMap)["i16vec3"] = I16VEC3;
499 (*KeywordMap)["i16vec4"] = I16VEC4;
500 (*KeywordMap)["uint16_t"] = UINT16_T;
501 (*KeywordMap)["u16vec2"] = U16VEC2;
502 (*KeywordMap)["u16vec3"] = U16VEC3;
503 (*KeywordMap)["u16vec4"] = U16VEC4;
505 (*KeywordMap)["int32_t"] = INT32_T;
506 (*KeywordMap)["i32vec2"] = I32VEC2;
507 (*KeywordMap)["i32vec3"] = I32VEC3;
508 (*KeywordMap)["i32vec4"] = I32VEC4;
509 (*KeywordMap)["uint32_t"] = UINT32_T;
510 (*KeywordMap)["u32vec2"] = U32VEC2;
511 (*KeywordMap)["u32vec3"] = U32VEC3;
512 (*KeywordMap)["u32vec4"] = U32VEC4;
514 (*KeywordMap)["float16_t"] = FLOAT16_T;
515 (*KeywordMap)["f16vec2"] = F16VEC2;
516 (*KeywordMap)["f16vec3"] = F16VEC3;
517 (*KeywordMap)["f16vec4"] = F16VEC4;
518 (*KeywordMap)["f16mat2"] = F16MAT2;
519 (*KeywordMap)["f16mat3"] = F16MAT3;
520 (*KeywordMap)["f16mat4"] = F16MAT4;
521 (*KeywordMap)["f16mat2x2"] = F16MAT2X2;
522 (*KeywordMap)["f16mat2x3"] = F16MAT2X3;
523 (*KeywordMap)["f16mat2x4"] = F16MAT2X4;
524 (*KeywordMap)["f16mat3x2"] = F16MAT3X2;
525 (*KeywordMap)["f16mat3x3"] = F16MAT3X3;
526 (*KeywordMap)["f16mat3x4"] = F16MAT3X4;
527 (*KeywordMap)["f16mat4x2"] = F16MAT4X2;
528 (*KeywordMap)["f16mat4x3"] = F16MAT4X3;
529 (*KeywordMap)["f16mat4x4"] = F16MAT4X4;
531 (*KeywordMap)["float32_t"] = FLOAT32_T;
532 (*KeywordMap)["f32vec2"] = F32VEC2;
533 (*KeywordMap)["f32vec3"] = F32VEC3;
534 (*KeywordMap)["f32vec4"] = F32VEC4;
535 (*KeywordMap)["f32mat2"] = F32MAT2;
536 (*KeywordMap)["f32mat3"] = F32MAT3;
537 (*KeywordMap)["f32mat4"] = F32MAT4;
538 (*KeywordMap)["f32mat2x2"] = F32MAT2X2;
539 (*KeywordMap)["f32mat2x3"] = F32MAT2X3;
540 (*KeywordMap)["f32mat2x4"] = F32MAT2X4;
541 (*KeywordMap)["f32mat3x2"] = F32MAT3X2;
542 (*KeywordMap)["f32mat3x3"] = F32MAT3X3;
543 (*KeywordMap)["f32mat3x4"] = F32MAT3X4;
544 (*KeywordMap)["f32mat4x2"] = F32MAT4X2;
545 (*KeywordMap)["f32mat4x3"] = F32MAT4X3;
546 (*KeywordMap)["f32mat4x4"] = F32MAT4X4;
547 (*KeywordMap)["float64_t"] = FLOAT64_T;
548 (*KeywordMap)["f64vec2"] = F64VEC2;
549 (*KeywordMap)["f64vec3"] = F64VEC3;
550 (*KeywordMap)["f64vec4"] = F64VEC4;
551 (*KeywordMap)["f64mat2"] = F64MAT2;
552 (*KeywordMap)["f64mat3"] = F64MAT3;
553 (*KeywordMap)["f64mat4"] = F64MAT4;
554 (*KeywordMap)["f64mat2x2"] = F64MAT2X2;
555 (*KeywordMap)["f64mat2x3"] = F64MAT2X3;
556 (*KeywordMap)["f64mat2x4"] = F64MAT2X4;
557 (*KeywordMap)["f64mat3x2"] = F64MAT3X2;
558 (*KeywordMap)["f64mat3x3"] = F64MAT3X3;
559 (*KeywordMap)["f64mat3x4"] = F64MAT3X4;
560 (*KeywordMap)["f64mat4x2"] = F64MAT4X2;
561 (*KeywordMap)["f64mat4x3"] = F64MAT4X3;
562 (*KeywordMap)["f64mat4x4"] = F64MAT4X4;
565 (*KeywordMap)["sampler2D"] = SAMPLER2D;
566 (*KeywordMap)["samplerCube"] = SAMPLERCUBE;
567 (*KeywordMap)["samplerCubeShadow"] = SAMPLERCUBESHADOW;
568 (*KeywordMap)["sampler2DArray"] = SAMPLER2DARRAY;
569 (*KeywordMap)["sampler2DArrayShadow"] = SAMPLER2DARRAYSHADOW;
570 (*KeywordMap)["isampler2D"] = ISAMPLER2D;
571 (*KeywordMap)["isampler3D"] = ISAMPLER3D;
572 (*KeywordMap)["isamplerCube"] = ISAMPLERCUBE;
573 (*KeywordMap)["isampler2DArray"] = ISAMPLER2DARRAY;
574 (*KeywordMap)["usampler2D"] = USAMPLER2D;
575 (*KeywordMap)["usampler3D"] = USAMPLER3D;
576 (*KeywordMap)["usamplerCube"] = USAMPLERCUBE;
577 (*KeywordMap)["usampler2DArray"] = USAMPLER2DARRAY;
578 (*KeywordMap)["sampler3D"] = SAMPLER3D;
579 (*KeywordMap)["sampler2DShadow"] = SAMPLER2DSHADOW;
581 (*KeywordMap)["texture2D"] = TEXTURE2D;
582 (*KeywordMap)["textureCube"] = TEXTURECUBE;
583 (*KeywordMap)["texture2DArray"] = TEXTURE2DARRAY;
584 (*KeywordMap)["itexture2D"] = ITEXTURE2D;
585 (*KeywordMap)["itexture3D"] = ITEXTURE3D;
586 (*KeywordMap)["itextureCube"] = ITEXTURECUBE;
587 (*KeywordMap)["itexture2DArray"] = ITEXTURE2DARRAY;
588 (*KeywordMap)["utexture2D"] = UTEXTURE2D;
589 (*KeywordMap)["utexture3D"] = UTEXTURE3D;
590 (*KeywordMap)["utextureCube"] = UTEXTURECUBE;
591 (*KeywordMap)["utexture2DArray"] = UTEXTURE2DARRAY;
592 (*KeywordMap)["texture3D"] = TEXTURE3D;
594 (*KeywordMap)["sampler"] = SAMPLER;
595 (*KeywordMap)["samplerShadow"] = SAMPLERSHADOW;
598 (*KeywordMap)["textureCubeArray"] = TEXTURECUBEARRAY;
599 (*KeywordMap)["itextureCubeArray"] = ITEXTURECUBEARRAY;
600 (*KeywordMap)["utextureCubeArray"] = UTEXTURECUBEARRAY;
601 (*KeywordMap)["samplerCubeArray"] = SAMPLERCUBEARRAY;
602 (*KeywordMap)["samplerCubeArrayShadow"] = SAMPLERCUBEARRAYSHADOW;
603 (*KeywordMap)["isamplerCubeArray"] = ISAMPLERCUBEARRAY;
604 (*KeywordMap)["usamplerCubeArray"] = USAMPLERCUBEARRAY;
605 (*KeywordMap)["sampler1DArrayShadow"] = SAMPLER1DARRAYSHADOW;
606 (*KeywordMap)["isampler1DArray"] = ISAMPLER1DARRAY;
607 (*KeywordMap)["usampler1D"] = USAMPLER1D;
608 (*KeywordMap)["isampler1D"] = ISAMPLER1D;
609 (*KeywordMap)["usampler1DArray"] = USAMPLER1DARRAY;
610 (*KeywordMap)["samplerBuffer"] = SAMPLERBUFFER;
611 (*KeywordMap)["isampler2DRect"] = ISAMPLER2DRECT;
612 (*KeywordMap)["usampler2DRect"] = USAMPLER2DRECT;
613 (*KeywordMap)["isamplerBuffer"] = ISAMPLERBUFFER;
614 (*KeywordMap)["usamplerBuffer"] = USAMPLERBUFFER;
615 (*KeywordMap)["sampler2DMS"] = SAMPLER2DMS;
616 (*KeywordMap)["isampler2DMS"] = ISAMPLER2DMS;
617 (*KeywordMap)["usampler2DMS"] = USAMPLER2DMS;
618 (*KeywordMap)["sampler2DMSArray"] = SAMPLER2DMSARRAY;
619 (*KeywordMap)["isampler2DMSArray"] = ISAMPLER2DMSARRAY;
620 (*KeywordMap)["usampler2DMSArray"] = USAMPLER2DMSARRAY;
621 (*KeywordMap)["sampler1D"] = SAMPLER1D;
622 (*KeywordMap)["sampler1DShadow"] = SAMPLER1DSHADOW;
623 (*KeywordMap)["sampler2DRect"] = SAMPLER2DRECT;
624 (*KeywordMap)["sampler2DRectShadow"] = SAMPLER2DRECTSHADOW;
625 (*KeywordMap)["sampler1DArray"] = SAMPLER1DARRAY;
627 (*KeywordMap)["samplerExternalOES"] = SAMPLEREXTERNALOES; // GL_OES_EGL_image_external
629 (*KeywordMap)["__samplerExternal2DY2YEXT"] = SAMPLEREXTERNAL2DY2YEXT; // GL_EXT_YUV_target
631 (*KeywordMap)["itexture1DArray"] = ITEXTURE1DARRAY;
632 (*KeywordMap)["utexture1D"] = UTEXTURE1D;
633 (*KeywordMap)["itexture1D"] = ITEXTURE1D;
634 (*KeywordMap)["utexture1DArray"] = UTEXTURE1DARRAY;
635 (*KeywordMap)["textureBuffer"] = TEXTUREBUFFER;
636 (*KeywordMap)["itexture2DRect"] = ITEXTURE2DRECT;
637 (*KeywordMap)["utexture2DRect"] = UTEXTURE2DRECT;
638 (*KeywordMap)["itextureBuffer"] = ITEXTUREBUFFER;
639 (*KeywordMap)["utextureBuffer"] = UTEXTUREBUFFER;
640 (*KeywordMap)["texture2DMS"] = TEXTURE2DMS;
641 (*KeywordMap)["itexture2DMS"] = ITEXTURE2DMS;
642 (*KeywordMap)["utexture2DMS"] = UTEXTURE2DMS;
643 (*KeywordMap)["texture2DMSArray"] = TEXTURE2DMSARRAY;
644 (*KeywordMap)["itexture2DMSArray"] = ITEXTURE2DMSARRAY;
645 (*KeywordMap)["utexture2DMSArray"] = UTEXTURE2DMSARRAY;
646 (*KeywordMap)["texture1D"] = TEXTURE1D;
647 (*KeywordMap)["texture2DRect"] = TEXTURE2DRECT;
648 (*KeywordMap)["texture1DArray"] = TEXTURE1DARRAY;
650 (*KeywordMap)["subpassInput"] = SUBPASSINPUT;
651 (*KeywordMap)["subpassInputMS"] = SUBPASSINPUTMS;
652 (*KeywordMap)["isubpassInput"] = ISUBPASSINPUT;
653 (*KeywordMap)["isubpassInputMS"] = ISUBPASSINPUTMS;
654 (*KeywordMap)["usubpassInput"] = USUBPASSINPUT;
655 (*KeywordMap)["usubpassInputMS"] = USUBPASSINPUTMS;
657 (*KeywordMap)["f16sampler1D"] = F16SAMPLER1D;
658 (*KeywordMap)["f16sampler2D"] = F16SAMPLER2D;
659 (*KeywordMap)["f16sampler3D"] = F16SAMPLER3D;
660 (*KeywordMap)["f16sampler2DRect"] = F16SAMPLER2DRECT;
661 (*KeywordMap)["f16samplerCube"] = F16SAMPLERCUBE;
662 (*KeywordMap)["f16sampler1DArray"] = F16SAMPLER1DARRAY;
663 (*KeywordMap)["f16sampler2DArray"] = F16SAMPLER2DARRAY;
664 (*KeywordMap)["f16samplerCubeArray"] = F16SAMPLERCUBEARRAY;
665 (*KeywordMap)["f16samplerBuffer"] = F16SAMPLERBUFFER;
666 (*KeywordMap)["f16sampler2DMS"] = F16SAMPLER2DMS;
667 (*KeywordMap)["f16sampler2DMSArray"] = F16SAMPLER2DMSARRAY;
668 (*KeywordMap)["f16sampler1DShadow"] = F16SAMPLER1DSHADOW;
669 (*KeywordMap)["f16sampler2DShadow"] = F16SAMPLER2DSHADOW;
670 (*KeywordMap)["f16sampler2DRectShadow"] = F16SAMPLER2DRECTSHADOW;
671 (*KeywordMap)["f16samplerCubeShadow"] = F16SAMPLERCUBESHADOW;
672 (*KeywordMap)["f16sampler1DArrayShadow"] = F16SAMPLER1DARRAYSHADOW;
673 (*KeywordMap)["f16sampler2DArrayShadow"] = F16SAMPLER2DARRAYSHADOW;
674 (*KeywordMap)["f16samplerCubeArrayShadow"] = F16SAMPLERCUBEARRAYSHADOW;
676 (*KeywordMap)["f16image1D"] = F16IMAGE1D;
677 (*KeywordMap)["f16image2D"] = F16IMAGE2D;
678 (*KeywordMap)["f16image3D"] = F16IMAGE3D;
679 (*KeywordMap)["f16image2DRect"] = F16IMAGE2DRECT;
680 (*KeywordMap)["f16imageCube"] = F16IMAGECUBE;
681 (*KeywordMap)["f16image1DArray"] = F16IMAGE1DARRAY;
682 (*KeywordMap)["f16image2DArray"] = F16IMAGE2DARRAY;
683 (*KeywordMap)["f16imageCubeArray"] = F16IMAGECUBEARRAY;
684 (*KeywordMap)["f16imageBuffer"] = F16IMAGEBUFFER;
685 (*KeywordMap)["f16image2DMS"] = F16IMAGE2DMS;
686 (*KeywordMap)["f16image2DMSArray"] = F16IMAGE2DMSARRAY;
688 (*KeywordMap)["f16texture1D"] = F16TEXTURE1D;
689 (*KeywordMap)["f16texture2D"] = F16TEXTURE2D;
690 (*KeywordMap)["f16texture3D"] = F16TEXTURE3D;
691 (*KeywordMap)["f16texture2DRect"] = F16TEXTURE2DRECT;
692 (*KeywordMap)["f16textureCube"] = F16TEXTURECUBE;
693 (*KeywordMap)["f16texture1DArray"] = F16TEXTURE1DARRAY;
694 (*KeywordMap)["f16texture2DArray"] = F16TEXTURE2DARRAY;
695 (*KeywordMap)["f16textureCubeArray"] = F16TEXTURECUBEARRAY;
696 (*KeywordMap)["f16textureBuffer"] = F16TEXTUREBUFFER;
697 (*KeywordMap)["f16texture2DMS"] = F16TEXTURE2DMS;
698 (*KeywordMap)["f16texture2DMSArray"] = F16TEXTURE2DMSARRAY;
700 (*KeywordMap)["f16subpassInput"] = F16SUBPASSINPUT;
701 (*KeywordMap)["f16subpassInputMS"] = F16SUBPASSINPUTMS;
702 (*KeywordMap)["__explicitInterpAMD"] = EXPLICITINTERPAMD;
703 (*KeywordMap)["pervertexNV"] = PERVERTEXNV;
704 (*KeywordMap)["precise"] = PRECISE;
706 (*KeywordMap)["rayPayloadNV"] = PAYLOADNV;
707 (*KeywordMap)["rayPayloadEXT"] = PAYLOADEXT;
708 (*KeywordMap)["rayPayloadInNV"] = PAYLOADINNV;
709 (*KeywordMap)["rayPayloadInEXT"] = PAYLOADINEXT;
710 (*KeywordMap)["hitAttributeNV"] = HITATTRNV;
711 (*KeywordMap)["hitAttributeEXT"] = HITATTREXT;
712 (*KeywordMap)["callableDataNV"] = CALLDATANV;
713 (*KeywordMap)["callableDataEXT"] = CALLDATAEXT;
714 (*KeywordMap)["callableDataInNV"] = CALLDATAINNV;
715 (*KeywordMap)["callableDataInEXT"] = CALLDATAINEXT;
716 (*KeywordMap)["accelerationStructureNV"] = ACCSTRUCTNV;
717 (*KeywordMap)["accelerationStructureEXT"] = ACCSTRUCTEXT;
718 (*KeywordMap)["perprimitiveNV"] = PERPRIMITIVENV;
719 (*KeywordMap)["perviewNV"] = PERVIEWNV;
720 (*KeywordMap)["taskNV"] = PERTASKNV;
722 (*KeywordMap)["fcoopmatNV"] = FCOOPMATNV;
723 (*KeywordMap)["icoopmatNV"] = ICOOPMATNV;
724 (*KeywordMap)["ucoopmatNV"] = UCOOPMATNV;
726 ReservedSet = new std::unordered_set<const char*, str_hash, str_eq>;
728 ReservedSet->insert("common");
729 ReservedSet->insert("partition");
730 ReservedSet->insert("active");
731 ReservedSet->insert("asm");
732 ReservedSet->insert("class");
733 ReservedSet->insert("union");
734 ReservedSet->insert("enum");
735 ReservedSet->insert("typedef");
736 ReservedSet->insert("template");
737 ReservedSet->insert("this");
738 ReservedSet->insert("goto");
739 ReservedSet->insert("inline");
740 ReservedSet->insert("noinline");
741 ReservedSet->insert("public");
742 ReservedSet->insert("static");
743 ReservedSet->insert("extern");
744 ReservedSet->insert("external");
745 ReservedSet->insert("interface");
746 ReservedSet->insert("long");
747 ReservedSet->insert("short");
748 ReservedSet->insert("half");
749 ReservedSet->insert("fixed");
750 ReservedSet->insert("unsigned");
751 ReservedSet->insert("input");
752 ReservedSet->insert("output");
753 ReservedSet->insert("hvec2");
754 ReservedSet->insert("hvec3");
755 ReservedSet->insert("hvec4");
756 ReservedSet->insert("fvec2");
757 ReservedSet->insert("fvec3");
758 ReservedSet->insert("fvec4");
759 ReservedSet->insert("sampler3DRect");
760 ReservedSet->insert("filter");
761 ReservedSet->insert("sizeof");
762 ReservedSet->insert("cast");
763 ReservedSet->insert("namespace");
764 ReservedSet->insert("using");
768 void TScanContext::deleteKeywordMap()
771 KeywordMap = nullptr;
774 ReservedSet = nullptr;
778 // Called by yylex to get the next token.
779 // Returning 0 implies end of input.
780 int TScanContext::tokenize(TPpContext* pp, TParserToken& token)
783 parserToken = &token;
785 int token = pp->tokenize(ppToken);
786 if (token == EndOfInput)
789 tokenText = ppToken.name;
791 parserToken->sType.lex.loc = loc;
793 case ';': afterType = false; afterBuffer = false; return SEMICOLON;
794 case ',': afterType = false; return COMMA;
795 case ':': return COLON;
796 case '=': afterType = false; return EQUAL;
797 case '(': afterType = false; return LEFT_PAREN;
798 case ')': afterType = false; return RIGHT_PAREN;
799 case '.': field = true; return DOT;
800 case '!': return BANG;
801 case '-': return DASH;
802 case '~': return TILDE;
803 case '+': return PLUS;
804 case '*': return STAR;
805 case '/': return SLASH;
806 case '%': return PERCENT;
807 case '<': return LEFT_ANGLE;
808 case '>': return RIGHT_ANGLE;
809 case '|': return VERTICAL_BAR;
810 case '^': return CARET;
811 case '&': return AMPERSAND;
812 case '?': return QUESTION;
813 case '[': return LEFT_BRACKET;
814 case ']': return RIGHT_BRACKET;
815 case '{': afterStruct = false; afterBuffer = false; return LEFT_BRACE;
816 case '}': return RIGHT_BRACE;
818 parseContext.error(loc, "illegal use of escape character", "\\", "");
821 case PPAtomAddAssign: return ADD_ASSIGN;
822 case PPAtomSubAssign: return SUB_ASSIGN;
823 case PPAtomMulAssign: return MUL_ASSIGN;
824 case PPAtomDivAssign: return DIV_ASSIGN;
825 case PPAtomModAssign: return MOD_ASSIGN;
827 case PpAtomRight: return RIGHT_OP;
828 case PpAtomLeft: return LEFT_OP;
830 case PpAtomRightAssign: return RIGHT_ASSIGN;
831 case PpAtomLeftAssign: return LEFT_ASSIGN;
832 case PpAtomAndAssign: return AND_ASSIGN;
833 case PpAtomOrAssign: return OR_ASSIGN;
834 case PpAtomXorAssign: return XOR_ASSIGN;
836 case PpAtomAnd: return AND_OP;
837 case PpAtomOr: return OR_OP;
838 case PpAtomXor: return XOR_OP;
840 case PpAtomEQ: return EQ_OP;
841 case PpAtomGE: return GE_OP;
842 case PpAtomNE: return NE_OP;
843 case PpAtomLE: return LE_OP;
845 case PpAtomDecrement: return DEC_OP;
846 case PpAtomIncrement: return INC_OP;
848 case PpAtomColonColon:
849 parseContext.error(loc, "not supported", "::", "");
852 case PpAtomConstString: parserToken->sType.lex.string = NewPoolTString(tokenText); return STRING_LITERAL;
853 case PpAtomConstInt: parserToken->sType.lex.i = ppToken.ival; return INTCONSTANT;
854 case PpAtomConstUint: parserToken->sType.lex.i = ppToken.ival; return UINTCONSTANT;
855 case PpAtomConstFloat: parserToken->sType.lex.d = ppToken.dval; return FLOATCONSTANT;
857 case PpAtomConstInt16: parserToken->sType.lex.i = ppToken.ival; return INT16CONSTANT;
858 case PpAtomConstUint16: parserToken->sType.lex.i = ppToken.ival; return UINT16CONSTANT;
859 case PpAtomConstInt64: parserToken->sType.lex.i64 = ppToken.i64val; return INT64CONSTANT;
860 case PpAtomConstUint64: parserToken->sType.lex.i64 = ppToken.i64val; return UINT64CONSTANT;
861 case PpAtomConstDouble: parserToken->sType.lex.d = ppToken.dval; return DOUBLECONSTANT;
862 case PpAtomConstFloat16: parserToken->sType.lex.d = ppToken.dval; return FLOAT16CONSTANT;
864 case PpAtomIdentifier:
866 int token = tokenizeIdentifier();
871 case EndOfInput: return 0;
875 buf[0] = (char)token;
877 parseContext.error(loc, "unexpected token", buf, "");
883 int TScanContext::tokenizeIdentifier()
886 if (ReservedSet->find(tokenText) != ReservedSet->end())
887 return reservedWord();
890 auto it = KeywordMap->find(tokenText);
891 if (it == KeywordMap->end()) {
892 // Should have an identifier of some sort
893 return identifierOrType();
895 keyword = it->second;
917 if ((parseContext.isEsProfile() && parseContext.version < 310) ||
918 (!parseContext.isEsProfile() && parseContext.version < 430))
919 return identifierOrType();
928 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
929 (!parseContext.isEsProfile() && parseContext.version < 130))
955 if (strcmp("true", tokenText) == 0)
956 parserToken->sType.lex.b = true;
958 parserToken->sType.lex.b = false;
962 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
963 (!parseContext.isEsProfile() && parseContext.version < 130))
964 return identifierOrType();
967 if (parseContext.isEsProfile() && parseContext.version < 300)
969 else if (!parseContext.isEsProfile() && parseContext.version < 130)
970 return identifierOrType();
973 if (parseContext.version < 120)
974 return identifierOrType();
977 if (!parseContext.isEsProfile() && parseContext.version < 120)
978 return identifierOrType();
981 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
982 (!parseContext.isEsProfile() && parseContext.version < 330))
983 return reservedWord();
984 return identifierOrType();
988 bool reserved = (parseContext.isEsProfile() && parseContext.version >= 300) ||
989 (!parseContext.isEsProfile() && parseContext.version >= 420);
990 return identifierOrReserved(reserved);
994 bool reserved = parseContext.isEsProfile() || parseContext.version >= 130;
995 return identifierOrReserved(reserved);
1000 if (parseContext.extensionTurnedOn(E_GL_NV_shader_noperspective_interpolation))
1002 return es30ReservedFromGLSL(130);
1005 if (parseContext.extensionTurnedOn(E_GL_EXT_nonuniform_qualifier))
1008 return identifierOrType();
1011 if (parseContext.isEsProfile() && parseContext.version >= 300)
1020 if (parseContext.symbolTable.atBuiltInLevel() ||
1021 parseContext.extensionTurnedOn(E_GL_NV_ray_tracing))
1023 return identifierOrType();
1030 if (parseContext.symbolTable.atBuiltInLevel() ||
1031 parseContext.extensionTurnedOn(E_GL_EXT_ray_tracing))
1033 return identifierOrType();
1035 if ((parseContext.isEsProfile() && parseContext.version >= 310) ||
1036 parseContext.extensionTurnedOn(E_GL_ARB_shader_atomic_counters))
1038 return es30ReservedFromGLSL(420);
1041 case DEVICECOHERENT:
1042 case QUEUEFAMILYCOHERENT:
1043 case WORKGROUPCOHERENT:
1044 case SUBGROUPCOHERENT:
1045 case SHADERCALLCOHERENT:
1050 if (parseContext.isEsProfile() && parseContext.version >= 310)
1052 return es30ReservedFromGLSL(parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store) ? 130 : 420);
1054 if (parseContext.isEsProfile() && parseContext.version >= 310)
1056 if (! parseContext.symbolTable.atBuiltInLevel() && (parseContext.isEsProfile() ||
1057 (parseContext.version < 420 && ! parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))))
1061 if (parseContext.symbolTable.atBuiltInLevel() ||
1062 (parseContext.isEsProfile() &&
1063 (parseContext.version >= 320 ||
1064 parseContext.extensionsTurnedOn(Num_AEP_tessellation_shader, AEP_tessellation_shader))) ||
1065 (!parseContext.isEsProfile() && parseContext.extensionTurnedOn(E_GL_ARB_tessellation_shader)))
1068 return es30ReservedFromGLSL(400);
1071 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1072 parseContext.extensionsTurnedOn(1, &E_GL_OES_shader_multisample_interpolation))
1074 return es30ReservedFromGLSL(400);
1077 return es30ReservedFromGLSL(400);
1080 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1081 (!parseContext.isEsProfile() && parseContext.version < 140))
1082 return identifierOrType();
1086 const int numLayoutExts = 2;
1087 const char* layoutExts[numLayoutExts] = { E_GL_ARB_shading_language_420pack,
1088 E_GL_ARB_explicit_attrib_location };
1089 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1090 (!parseContext.isEsProfile() && parseContext.version < 140 &&
1091 ! parseContext.extensionsTurnedOn(numLayoutExts, layoutExts)))
1092 return identifierOrType();
1096 case HIGH_PRECISION:
1097 case MEDIUM_PRECISION:
1100 return precisionKeyword();
1138 return firstGenerationImage(false);
1144 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1145 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1147 return firstGenerationImage(false);
1162 return firstGenerationImage(true);
1164 case IMAGECUBEARRAY:
1165 case IIMAGECUBEARRAY:
1166 case UIMAGECUBEARRAY:
1168 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1169 parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
1171 return secondGenerationImage();
1176 case IMAGE2DMSARRAY:
1177 case IIMAGE2DMSARRAY:
1178 case UIMAGE2DMSARRAY:
1180 return secondGenerationImage();
1187 if (parseContext.isEsProfile() || parseContext.version < 150 ||
1188 (!parseContext.symbolTable.atBuiltInLevel() &&
1189 parseContext.version < 400 &&
1190 !parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_fp64)))
1203 if (parseContext.symbolTable.atBuiltInLevel() ||
1204 parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_int64) ||
1205 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1206 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int64))
1208 return identifierOrType();
1219 if (parseContext.symbolTable.atBuiltInLevel() ||
1220 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1221 parseContext.extensionTurnedOn(E_GL_EXT_shader_8bit_storage) ||
1222 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int8))
1224 return identifierOrType();
1235 if (parseContext.symbolTable.atBuiltInLevel() ||
1236 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_int16) ||
1237 parseContext.extensionTurnedOn(E_GL_EXT_shader_16bit_storage) ||
1238 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1239 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int16))
1241 return identifierOrType();
1251 if (parseContext.symbolTable.atBuiltInLevel() ||
1252 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1253 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int32))
1255 return identifierOrType();
1273 if (parseContext.symbolTable.atBuiltInLevel() ||
1274 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1275 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float32))
1277 return identifierOrType();
1296 if (parseContext.symbolTable.atBuiltInLevel() ||
1297 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1298 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float64))
1300 return identifierOrType();
1307 if (parseContext.symbolTable.atBuiltInLevel() ||
1308 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float) ||
1309 parseContext.extensionTurnedOn(E_GL_EXT_shader_16bit_storage) ||
1310 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1311 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float16))
1314 return identifierOrType();
1329 if (parseContext.symbolTable.atBuiltInLevel() ||
1330 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float) ||
1331 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1332 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float16))
1335 return identifierOrType();
1337 case SAMPLERCUBEARRAY:
1338 case SAMPLERCUBEARRAYSHADOW:
1339 case ISAMPLERCUBEARRAY:
1340 case USAMPLERCUBEARRAY:
1342 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1343 parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
1345 if (parseContext.isEsProfile() || (parseContext.version < 400 && ! parseContext.extensionTurnedOn(E_GL_ARB_texture_cube_map_array)))
1349 case TEXTURECUBEARRAY:
1350 case ITEXTURECUBEARRAY:
1351 case UTEXTURECUBEARRAY:
1352 if (parseContext.spvVersion.vulkan > 0)
1355 return identifierOrType();
1362 case SAMPLERCUBESHADOW:
1363 case SAMPLER2DARRAY:
1364 case SAMPLER2DARRAYSHADOW:
1368 case ISAMPLER2DARRAY:
1372 case USAMPLER2DARRAY:
1374 return nonreservedKeyword(300, 130);
1378 if (parseContext.isEsProfile() && parseContext.version < 300) {
1379 if (!parseContext.extensionTurnedOn(E_GL_OES_texture_3D))
1384 case SAMPLER2DSHADOW:
1386 if (parseContext.isEsProfile() && parseContext.version < 300) {
1387 if (!parseContext.extensionTurnedOn(E_GL_EXT_shadow_samplers))
1394 case TEXTURE2DARRAY:
1398 case ITEXTURE2DARRAY:
1402 case UTEXTURE2DARRAY:
1406 if (parseContext.spvVersion.vulkan > 0)
1409 return identifierOrType();
1413 case ISAMPLER1DARRAY:
1414 case SAMPLER1DARRAYSHADOW:
1416 case USAMPLER1DARRAY:
1418 return es30ReservedFromGLSL(130);
1419 case ISAMPLER2DRECT:
1420 case USAMPLER2DRECT:
1422 return es30ReservedFromGLSL(140);
1426 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1427 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1429 return es30ReservedFromGLSL(130);
1431 case ISAMPLERBUFFER:
1432 case USAMPLERBUFFER:
1434 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1435 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1437 return es30ReservedFromGLSL(140);
1443 if (parseContext.isEsProfile() && parseContext.version >= 310)
1445 if (!parseContext.isEsProfile() && (parseContext.version > 140 ||
1446 (parseContext.version == 140 && parseContext.extensionsTurnedOn(1, &E_GL_ARB_texture_multisample))))
1448 return es30ReservedFromGLSL(150);
1450 case SAMPLER2DMSARRAY:
1451 case ISAMPLER2DMSARRAY:
1452 case USAMPLER2DMSARRAY:
1454 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1455 parseContext.extensionsTurnedOn(1, &E_GL_OES_texture_storage_multisample_2d_array))
1457 if (!parseContext.isEsProfile() && (parseContext.version > 140 ||
1458 (parseContext.version == 140 && parseContext.extensionsTurnedOn(1, &E_GL_ARB_texture_multisample))))
1460 return es30ReservedFromGLSL(150);
1463 case SAMPLER1DSHADOW:
1465 if (parseContext.isEsProfile())
1470 case SAMPLER2DRECTSHADOW:
1472 if (parseContext.isEsProfile())
1474 else if (parseContext.version < 140 && ! parseContext.symbolTable.atBuiltInLevel() && ! parseContext.extensionTurnedOn(E_GL_ARB_texture_rectangle)) {
1475 if (parseContext.relaxedErrors())
1476 parseContext.requireExtensions(loc, 1, &E_GL_ARB_texture_rectangle, "texture-rectangle sampler keyword");
1482 case SAMPLER1DARRAY:
1484 if (parseContext.isEsProfile() && parseContext.version == 300)
1486 else if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1487 (!parseContext.isEsProfile() && parseContext.version < 130))
1488 return identifierOrType();
1491 case SAMPLEREXTERNALOES:
1493 if (parseContext.symbolTable.atBuiltInLevel() ||
1494 parseContext.extensionTurnedOn(E_GL_OES_EGL_image_external) ||
1495 parseContext.extensionTurnedOn(E_GL_OES_EGL_image_external_essl3))
1497 return identifierOrType();
1499 case SAMPLEREXTERNAL2DY2YEXT:
1501 if (parseContext.symbolTable.atBuiltInLevel() ||
1502 parseContext.extensionTurnedOn(E_GL_EXT_YUV_target))
1504 return identifierOrType();
1506 case ITEXTURE1DARRAY:
1509 case UTEXTURE1DARRAY:
1511 case ITEXTURE2DRECT:
1512 case UTEXTURE2DRECT:
1513 case ITEXTUREBUFFER:
1514 case UTEXTUREBUFFER:
1518 case TEXTURE2DMSARRAY:
1519 case ITEXTURE2DMSARRAY:
1520 case UTEXTURE2DMSARRAY:
1523 case TEXTURE1DARRAY:
1524 if (parseContext.spvVersion.vulkan > 0)
1527 return identifierOrType();
1530 case SUBPASSINPUTMS:
1532 case ISUBPASSINPUTMS:
1534 case USUBPASSINPUTMS:
1535 if (parseContext.spvVersion.vulkan > 0)
1538 return identifierOrType();
1543 case F16SAMPLER2DRECT:
1544 case F16SAMPLERCUBE:
1545 case F16SAMPLER1DARRAY:
1546 case F16SAMPLER2DARRAY:
1547 case F16SAMPLERCUBEARRAY:
1548 case F16SAMPLERBUFFER:
1549 case F16SAMPLER2DMS:
1550 case F16SAMPLER2DMSARRAY:
1551 case F16SAMPLER1DSHADOW:
1552 case F16SAMPLER2DSHADOW:
1553 case F16SAMPLER1DARRAYSHADOW:
1554 case F16SAMPLER2DARRAYSHADOW:
1555 case F16SAMPLER2DRECTSHADOW:
1556 case F16SAMPLERCUBESHADOW:
1557 case F16SAMPLERCUBEARRAYSHADOW:
1562 case F16IMAGE2DRECT:
1564 case F16IMAGE1DARRAY:
1565 case F16IMAGE2DARRAY:
1566 case F16IMAGECUBEARRAY:
1567 case F16IMAGEBUFFER:
1569 case F16IMAGE2DMSARRAY:
1574 case F16TEXTURE2DRECT:
1575 case F16TEXTURECUBE:
1576 case F16TEXTURE1DARRAY:
1577 case F16TEXTURE2DARRAY:
1578 case F16TEXTURECUBEARRAY:
1579 case F16TEXTUREBUFFER:
1580 case F16TEXTURE2DMS:
1581 case F16TEXTURE2DMSARRAY:
1583 case F16SUBPASSINPUT:
1584 case F16SUBPASSINPUTMS:
1586 if (parseContext.symbolTable.atBuiltInLevel() ||
1587 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float_fetch))
1589 return identifierOrType();
1591 case EXPLICITINTERPAMD:
1592 if (parseContext.extensionTurnedOn(E_GL_AMD_shader_explicit_vertex_parameter))
1594 return identifierOrType();
1597 if ((!parseContext.isEsProfile() && parseContext.version >= 450) ||
1598 parseContext.extensionTurnedOn(E_GL_NV_fragment_shader_barycentric))
1600 return identifierOrType();
1603 if ((parseContext.isEsProfile() &&
1604 (parseContext.version >= 320 || parseContext.extensionsTurnedOn(Num_AEP_gpu_shader5, AEP_gpu_shader5))) ||
1605 (!parseContext.isEsProfile() && parseContext.version >= 400))
1607 if (parseContext.isEsProfile() && parseContext.version == 310) {
1611 return identifierOrType();
1613 case PERPRIMITIVENV:
1616 if ((!parseContext.isEsProfile() && parseContext.version >= 450) ||
1617 (parseContext.isEsProfile() && parseContext.version >= 320) ||
1618 parseContext.extensionTurnedOn(E_GL_NV_mesh_shader))
1620 return identifierOrType();
1624 if (parseContext.symbolTable.atBuiltInLevel() ||
1625 parseContext.extensionTurnedOn(E_GL_NV_cooperative_matrix))
1627 return identifierOrType();
1632 if (parseContext.symbolTable.atBuiltInLevel() ||
1633 parseContext.extensionTurnedOn(E_GL_NV_integer_cooperative_matrix))
1635 return identifierOrType();
1638 if (parseContext.extensionTurnedOn(E_GL_EXT_demote_to_helper_invocation))
1641 return identifierOrType();
1645 parseContext.infoSink.info.message(EPrefixInternalError, "Unknown glslang keyword", loc);
1650 int TScanContext::identifierOrType()
1652 parserToken->sType.lex.string = NewPoolTString(tokenText);
1656 parserToken->sType.lex.symbol = parseContext.symbolTable.find(*parserToken->sType.lex.string);
1657 if ((afterType == false && afterStruct == false) && parserToken->sType.lex.symbol != nullptr) {
1658 if (const TVariable* variable = parserToken->sType.lex.symbol->getAsVariable()) {
1659 if (variable->isUserType() &&
1660 // treat redeclaration of forward-declared buffer/uniform reference as an identifier
1661 !(variable->getType().isReference() && afterBuffer)) {
1672 // Give an error for use of a reserved symbol.
1673 // However, allow built-in declarations to use reserved words, to allow
1674 // extension support before the extension is enabled.
1675 int TScanContext::reservedWord()
1677 if (! parseContext.symbolTable.atBuiltInLevel())
1678 parseContext.error(loc, "Reserved word.", tokenText, "", "");
1683 int TScanContext::identifierOrReserved(bool reserved)
1691 if (parseContext.isForwardCompatible())
1692 parseContext.warn(loc, "using future reserved keyword", tokenText, "");
1694 return identifierOrType();
1697 // For keywords that suddenly showed up on non-ES (not previously reserved)
1698 // but then got reserved by ES 3.0.
1699 int TScanContext::es30ReservedFromGLSL(int version)
1701 if (parseContext.symbolTable.atBuiltInLevel())
1704 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1705 (!parseContext.isEsProfile() && parseContext.version < version)) {
1706 if (parseContext.isForwardCompatible())
1707 parseContext.warn(loc, "future reserved word in ES 300 and keyword in GLSL", tokenText, "");
1709 return identifierOrType();
1710 } else if (parseContext.isEsProfile() && parseContext.version >= 300)
1716 // For a keyword that was never reserved, until it suddenly
1717 // showed up, both in an es version and a non-ES version.
1718 int TScanContext::nonreservedKeyword(int esVersion, int nonEsVersion)
1720 if ((parseContext.isEsProfile() && parseContext.version < esVersion) ||
1721 (!parseContext.isEsProfile() && parseContext.version < nonEsVersion)) {
1722 if (parseContext.isForwardCompatible())
1723 parseContext.warn(loc, "using future keyword", tokenText, "");
1725 return identifierOrType();
1731 int TScanContext::precisionKeyword()
1733 if (parseContext.isEsProfile() || parseContext.version >= 130)
1736 if (parseContext.isForwardCompatible())
1737 parseContext.warn(loc, "using ES precision qualifier keyword", tokenText, "");
1739 return identifierOrType();
1742 int TScanContext::matNxM()
1746 if (parseContext.version > 110)
1749 if (parseContext.isForwardCompatible())
1750 parseContext.warn(loc, "using future non-square matrix type keyword", tokenText, "");
1752 return identifierOrType();
1755 int TScanContext::dMat()
1759 if (parseContext.isEsProfile() && parseContext.version >= 300) {
1765 if (!parseContext.isEsProfile() && (parseContext.version >= 400 ||
1766 parseContext.symbolTable.atBuiltInLevel() ||
1767 (parseContext.version >= 150 && parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_fp64))))
1770 if (parseContext.isForwardCompatible())
1771 parseContext.warn(loc, "using future type keyword", tokenText, "");
1773 return identifierOrType();
1776 int TScanContext::firstGenerationImage(bool inEs310)
1778 if (parseContext.symbolTable.atBuiltInLevel() ||
1779 (!parseContext.isEsProfile() && (parseContext.version >= 420 ||
1780 parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))) ||
1781 (inEs310 && parseContext.isEsProfile() && parseContext.version >= 310))
1784 if ((parseContext.isEsProfile() && parseContext.version >= 300) ||
1785 (!parseContext.isEsProfile() && parseContext.version >= 130)) {
1791 if (parseContext.isForwardCompatible())
1792 parseContext.warn(loc, "using future type keyword", tokenText, "");
1794 return identifierOrType();
1797 int TScanContext::secondGenerationImage()
1799 if (parseContext.isEsProfile() && parseContext.version >= 310) {
1804 if (parseContext.symbolTable.atBuiltInLevel() ||
1805 (!parseContext.isEsProfile() &&
1806 (parseContext.version >= 420 || parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))))
1809 if (parseContext.isForwardCompatible())
1810 parseContext.warn(loc, "using future type keyword", tokenText, "");
1812 return identifierOrType();
1815 } // end namespace glslang