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') {
191 while (peek() == '\n' || peek() == '\r')
196 } while (c != EndOfInput && c != '\n' && c != '\r');
197 while (peek() == '\n' || peek() == '\r')
199 if (peek() == EndOfInput)
202 lookingInMiddle = true;
204 // Nominal start, skipping the desktop allowed comments and white space, but tracking if
205 // something else was found for ES:
206 consumeWhitespaceComment(foundNonSpaceTab);
207 if (foundNonSpaceTab)
208 versionNotFirst = true;
212 versionNotFirst = true;
219 } while (c == ' ' || c == '\t');
229 versionNotFirst = true;
236 } while (c == ' ' || c == '\t');
239 while (c >= '0' && c <= '9') {
240 version = 10 * version + (c - '0');
244 versionNotFirst = true;
249 while (c == ' ' || c == '\t')
253 const int maxProfileLength = 13; // not including any 0
254 char profileString[maxProfileLength];
256 for (profileLength = 0; profileLength < maxProfileLength; ++profileLength) {
257 if (c == EndOfInput || c == ' ' || c == '\t' || c == '\n' || c == '\r')
259 profileString[profileLength] = (char)c;
262 if (c != EndOfInput && c != ' ' && c != '\t' && c != '\n' && c != '\r') {
263 versionNotFirst = true;
267 if (profileLength == 2 && strncmp(profileString, "es", profileLength) == 0)
268 profile = EEsProfile;
269 else if (profileLength == 4 && strncmp(profileString, "core", profileLength) == 0)
270 profile = ECoreProfile;
271 else if (profileLength == 13 && strncmp(profileString, "compatibility", profileLength) == 0)
272 profile = ECompatibilityProfile;
274 return versionNotFirst;
278 // Fill this in when doing glslang-level scanning, to hand back to the parser.
281 explicit TParserToken(YYSTYPE& b) : sType(b) { }
285 TParserToken(TParserToken&);
286 TParserToken& operator=(TParserToken&);
289 } // end namespace glslang
291 // This is the function the glslang parser (i.e., bison) calls to get its next token
292 int yylex(YYSTYPE* glslangTokenDesc, glslang::TParseContext& parseContext)
294 glslang::TParserToken token(*glslangTokenDesc);
296 return parseContext.getScanContext()->tokenize(parseContext.getPpContext(), token);
303 bool operator()(const char* lhs, const char* rhs) const
305 return strcmp(lhs, rhs) == 0;
311 size_t operator()(const char* str) const
314 unsigned long hash = 5381;
317 while ((c = *str++) != 0)
318 hash = ((hash << 5) + hash) + c;
324 // A single global usable by all threads, by all versions, by all languages.
325 // After a single process-level initialization, this is read only and thread safe
326 std::unordered_map<const char*, int, str_hash, str_eq>* KeywordMap = nullptr;
327 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)["nonuniformEXT"] = NONUNIFORM;
345 (*KeywordMap)["in"] = IN;
346 (*KeywordMap)["out"] = OUT;
347 (*KeywordMap)["inout"] = INOUT;
348 (*KeywordMap)["struct"] = STRUCT;
349 (*KeywordMap)["break"] = BREAK;
350 (*KeywordMap)["continue"] = CONTINUE;
351 (*KeywordMap)["do"] = DO;
352 (*KeywordMap)["for"] = FOR;
353 (*KeywordMap)["while"] = WHILE;
354 (*KeywordMap)["switch"] = SWITCH;
355 (*KeywordMap)["case"] = CASE;
356 (*KeywordMap)["default"] = DEFAULT;
357 (*KeywordMap)["if"] = IF;
358 (*KeywordMap)["else"] = ELSE;
359 (*KeywordMap)["demote"] = DEMOTE;
360 (*KeywordMap)["discard"] = DISCARD;
361 (*KeywordMap)["return"] = RETURN;
362 (*KeywordMap)["void"] = VOID;
363 (*KeywordMap)["bool"] = BOOL;
364 (*KeywordMap)["float"] = FLOAT;
365 (*KeywordMap)["int"] = INT;
366 (*KeywordMap)["bvec2"] = BVEC2;
367 (*KeywordMap)["bvec3"] = BVEC3;
368 (*KeywordMap)["bvec4"] = BVEC4;
369 (*KeywordMap)["vec2"] = VEC2;
370 (*KeywordMap)["vec3"] = VEC3;
371 (*KeywordMap)["vec4"] = VEC4;
372 (*KeywordMap)["ivec2"] = IVEC2;
373 (*KeywordMap)["ivec3"] = IVEC3;
374 (*KeywordMap)["ivec4"] = IVEC4;
375 (*KeywordMap)["mat2"] = MAT2;
376 (*KeywordMap)["mat3"] = MAT3;
377 (*KeywordMap)["mat4"] = MAT4;
378 (*KeywordMap)["true"] = BOOLCONSTANT;
379 (*KeywordMap)["false"] = BOOLCONSTANT;
380 (*KeywordMap)["attribute"] = ATTRIBUTE;
381 (*KeywordMap)["varying"] = VARYING;
382 (*KeywordMap)["buffer"] = BUFFER;
383 (*KeywordMap)["coherent"] = COHERENT;
384 (*KeywordMap)["devicecoherent"] = DEVICECOHERENT;
385 (*KeywordMap)["queuefamilycoherent"] = QUEUEFAMILYCOHERENT;
386 (*KeywordMap)["workgroupcoherent"] = WORKGROUPCOHERENT;
387 (*KeywordMap)["subgroupcoherent"] = SUBGROUPCOHERENT;
388 (*KeywordMap)["nonprivate"] = NONPRIVATE;
389 (*KeywordMap)["restrict"] = RESTRICT;
390 (*KeywordMap)["readonly"] = READONLY;
391 (*KeywordMap)["writeonly"] = WRITEONLY;
392 (*KeywordMap)["atomic_uint"] = ATOMIC_UINT;
393 (*KeywordMap)["volatile"] = VOLATILE;
394 (*KeywordMap)["layout"] = LAYOUT;
395 (*KeywordMap)["shared"] = SHARED;
396 (*KeywordMap)["patch"] = PATCH;
397 (*KeywordMap)["sample"] = SAMPLE;
398 (*KeywordMap)["subroutine"] = SUBROUTINE;
399 (*KeywordMap)["highp"] = HIGH_PRECISION;
400 (*KeywordMap)["mediump"] = MEDIUM_PRECISION;
401 (*KeywordMap)["lowp"] = LOW_PRECISION;
402 (*KeywordMap)["precision"] = PRECISION;
403 (*KeywordMap)["mat2x2"] = MAT2X2;
404 (*KeywordMap)["mat2x3"] = MAT2X3;
405 (*KeywordMap)["mat2x4"] = MAT2X4;
406 (*KeywordMap)["mat3x2"] = MAT3X2;
407 (*KeywordMap)["mat3x3"] = MAT3X3;
408 (*KeywordMap)["mat3x4"] = MAT3X4;
409 (*KeywordMap)["mat4x2"] = MAT4X2;
410 (*KeywordMap)["mat4x3"] = MAT4X3;
411 (*KeywordMap)["mat4x4"] = MAT4X4;
412 (*KeywordMap)["dmat2"] = DMAT2;
413 (*KeywordMap)["dmat3"] = DMAT3;
414 (*KeywordMap)["dmat4"] = DMAT4;
415 (*KeywordMap)["dmat2x2"] = DMAT2X2;
416 (*KeywordMap)["dmat2x3"] = DMAT2X3;
417 (*KeywordMap)["dmat2x4"] = DMAT2X4;
418 (*KeywordMap)["dmat3x2"] = DMAT3X2;
419 (*KeywordMap)["dmat3x3"] = DMAT3X3;
420 (*KeywordMap)["dmat3x4"] = DMAT3X4;
421 (*KeywordMap)["dmat4x2"] = DMAT4X2;
422 (*KeywordMap)["dmat4x3"] = DMAT4X3;
423 (*KeywordMap)["dmat4x4"] = DMAT4X4;
424 (*KeywordMap)["image1D"] = IMAGE1D;
425 (*KeywordMap)["iimage1D"] = IIMAGE1D;
426 (*KeywordMap)["uimage1D"] = UIMAGE1D;
427 (*KeywordMap)["image2D"] = IMAGE2D;
428 (*KeywordMap)["iimage2D"] = IIMAGE2D;
429 (*KeywordMap)["uimage2D"] = UIMAGE2D;
430 (*KeywordMap)["image3D"] = IMAGE3D;
431 (*KeywordMap)["iimage3D"] = IIMAGE3D;
432 (*KeywordMap)["uimage3D"] = UIMAGE3D;
433 (*KeywordMap)["image2DRect"] = IMAGE2DRECT;
434 (*KeywordMap)["iimage2DRect"] = IIMAGE2DRECT;
435 (*KeywordMap)["uimage2DRect"] = UIMAGE2DRECT;
436 (*KeywordMap)["imageCube"] = IMAGECUBE;
437 (*KeywordMap)["iimageCube"] = IIMAGECUBE;
438 (*KeywordMap)["uimageCube"] = UIMAGECUBE;
439 (*KeywordMap)["imageBuffer"] = IMAGEBUFFER;
440 (*KeywordMap)["iimageBuffer"] = IIMAGEBUFFER;
441 (*KeywordMap)["uimageBuffer"] = UIMAGEBUFFER;
442 (*KeywordMap)["image1DArray"] = IMAGE1DARRAY;
443 (*KeywordMap)["iimage1DArray"] = IIMAGE1DARRAY;
444 (*KeywordMap)["uimage1DArray"] = UIMAGE1DARRAY;
445 (*KeywordMap)["image2DArray"] = IMAGE2DARRAY;
446 (*KeywordMap)["iimage2DArray"] = IIMAGE2DARRAY;
447 (*KeywordMap)["uimage2DArray"] = UIMAGE2DARRAY;
448 (*KeywordMap)["imageCubeArray"] = IMAGECUBEARRAY;
449 (*KeywordMap)["iimageCubeArray"] = IIMAGECUBEARRAY;
450 (*KeywordMap)["uimageCubeArray"] = UIMAGECUBEARRAY;
451 (*KeywordMap)["image2DMS"] = IMAGE2DMS;
452 (*KeywordMap)["iimage2DMS"] = IIMAGE2DMS;
453 (*KeywordMap)["uimage2DMS"] = UIMAGE2DMS;
454 (*KeywordMap)["image2DMSArray"] = IMAGE2DMSARRAY;
455 (*KeywordMap)["iimage2DMSArray"] = IIMAGE2DMSARRAY;
456 (*KeywordMap)["uimage2DMSArray"] = UIMAGE2DMSARRAY;
457 (*KeywordMap)["double"] = DOUBLE;
458 (*KeywordMap)["dvec2"] = DVEC2;
459 (*KeywordMap)["dvec3"] = DVEC3;
460 (*KeywordMap)["dvec4"] = DVEC4;
461 (*KeywordMap)["uint"] = UINT;
462 (*KeywordMap)["uvec2"] = UVEC2;
463 (*KeywordMap)["uvec3"] = UVEC3;
464 (*KeywordMap)["uvec4"] = UVEC4;
466 (*KeywordMap)["int64_t"] = INT64_T;
467 (*KeywordMap)["uint64_t"] = UINT64_T;
468 (*KeywordMap)["i64vec2"] = I64VEC2;
469 (*KeywordMap)["i64vec3"] = I64VEC3;
470 (*KeywordMap)["i64vec4"] = I64VEC4;
471 (*KeywordMap)["u64vec2"] = U64VEC2;
472 (*KeywordMap)["u64vec3"] = U64VEC3;
473 (*KeywordMap)["u64vec4"] = U64VEC4;
475 // GL_EXT_shader_explicit_arithmetic_types
476 (*KeywordMap)["int8_t"] = INT8_T;
477 (*KeywordMap)["i8vec2"] = I8VEC2;
478 (*KeywordMap)["i8vec3"] = I8VEC3;
479 (*KeywordMap)["i8vec4"] = I8VEC4;
480 (*KeywordMap)["uint8_t"] = UINT8_T;
481 (*KeywordMap)["u8vec2"] = U8VEC2;
482 (*KeywordMap)["u8vec3"] = U8VEC3;
483 (*KeywordMap)["u8vec4"] = U8VEC4;
485 (*KeywordMap)["int16_t"] = INT16_T;
486 (*KeywordMap)["i16vec2"] = I16VEC2;
487 (*KeywordMap)["i16vec3"] = I16VEC3;
488 (*KeywordMap)["i16vec4"] = I16VEC4;
489 (*KeywordMap)["uint16_t"] = UINT16_T;
490 (*KeywordMap)["u16vec2"] = U16VEC2;
491 (*KeywordMap)["u16vec3"] = U16VEC3;
492 (*KeywordMap)["u16vec4"] = U16VEC4;
494 (*KeywordMap)["int32_t"] = INT32_T;
495 (*KeywordMap)["i32vec2"] = I32VEC2;
496 (*KeywordMap)["i32vec3"] = I32VEC3;
497 (*KeywordMap)["i32vec4"] = I32VEC4;
498 (*KeywordMap)["uint32_t"] = UINT32_T;
499 (*KeywordMap)["u32vec2"] = U32VEC2;
500 (*KeywordMap)["u32vec3"] = U32VEC3;
501 (*KeywordMap)["u32vec4"] = U32VEC4;
503 (*KeywordMap)["float16_t"] = FLOAT16_T;
504 (*KeywordMap)["f16vec2"] = F16VEC2;
505 (*KeywordMap)["f16vec3"] = F16VEC3;
506 (*KeywordMap)["f16vec4"] = F16VEC4;
507 (*KeywordMap)["f16mat2"] = F16MAT2;
508 (*KeywordMap)["f16mat3"] = F16MAT3;
509 (*KeywordMap)["f16mat4"] = F16MAT4;
510 (*KeywordMap)["f16mat2x2"] = F16MAT2X2;
511 (*KeywordMap)["f16mat2x3"] = F16MAT2X3;
512 (*KeywordMap)["f16mat2x4"] = F16MAT2X4;
513 (*KeywordMap)["f16mat3x2"] = F16MAT3X2;
514 (*KeywordMap)["f16mat3x3"] = F16MAT3X3;
515 (*KeywordMap)["f16mat3x4"] = F16MAT3X4;
516 (*KeywordMap)["f16mat4x2"] = F16MAT4X2;
517 (*KeywordMap)["f16mat4x3"] = F16MAT4X3;
518 (*KeywordMap)["f16mat4x4"] = F16MAT4X4;
520 (*KeywordMap)["float32_t"] = FLOAT32_T;
521 (*KeywordMap)["f32vec2"] = F32VEC2;
522 (*KeywordMap)["f32vec3"] = F32VEC3;
523 (*KeywordMap)["f32vec4"] = F32VEC4;
524 (*KeywordMap)["f32mat2"] = F32MAT2;
525 (*KeywordMap)["f32mat3"] = F32MAT3;
526 (*KeywordMap)["f32mat4"] = F32MAT4;
527 (*KeywordMap)["f32mat2x2"] = F32MAT2X2;
528 (*KeywordMap)["f32mat2x3"] = F32MAT2X3;
529 (*KeywordMap)["f32mat2x4"] = F32MAT2X4;
530 (*KeywordMap)["f32mat3x2"] = F32MAT3X2;
531 (*KeywordMap)["f32mat3x3"] = F32MAT3X3;
532 (*KeywordMap)["f32mat3x4"] = F32MAT3X4;
533 (*KeywordMap)["f32mat4x2"] = F32MAT4X2;
534 (*KeywordMap)["f32mat4x3"] = F32MAT4X3;
535 (*KeywordMap)["f32mat4x4"] = F32MAT4X4;
536 (*KeywordMap)["float64_t"] = FLOAT64_T;
537 (*KeywordMap)["f64vec2"] = F64VEC2;
538 (*KeywordMap)["f64vec3"] = F64VEC3;
539 (*KeywordMap)["f64vec4"] = F64VEC4;
540 (*KeywordMap)["f64mat2"] = F64MAT2;
541 (*KeywordMap)["f64mat3"] = F64MAT3;
542 (*KeywordMap)["f64mat4"] = F64MAT4;
543 (*KeywordMap)["f64mat2x2"] = F64MAT2X2;
544 (*KeywordMap)["f64mat2x3"] = F64MAT2X3;
545 (*KeywordMap)["f64mat2x4"] = F64MAT2X4;
546 (*KeywordMap)["f64mat3x2"] = F64MAT3X2;
547 (*KeywordMap)["f64mat3x3"] = F64MAT3X3;
548 (*KeywordMap)["f64mat3x4"] = F64MAT3X4;
549 (*KeywordMap)["f64mat4x2"] = F64MAT4X2;
550 (*KeywordMap)["f64mat4x3"] = F64MAT4X3;
551 (*KeywordMap)["f64mat4x4"] = F64MAT4X4;
553 (*KeywordMap)["sampler2D"] = SAMPLER2D;
554 (*KeywordMap)["samplerCube"] = SAMPLERCUBE;
555 (*KeywordMap)["samplerCubeArray"] = SAMPLERCUBEARRAY;
556 (*KeywordMap)["samplerCubeArrayShadow"] = SAMPLERCUBEARRAYSHADOW;
557 (*KeywordMap)["isamplerCubeArray"] = ISAMPLERCUBEARRAY;
558 (*KeywordMap)["usamplerCubeArray"] = USAMPLERCUBEARRAY;
559 (*KeywordMap)["sampler1DArrayShadow"] = SAMPLER1DARRAYSHADOW;
560 (*KeywordMap)["isampler1DArray"] = ISAMPLER1DARRAY;
561 (*KeywordMap)["usampler1D"] = USAMPLER1D;
562 (*KeywordMap)["isampler1D"] = ISAMPLER1D;
563 (*KeywordMap)["usampler1DArray"] = USAMPLER1DARRAY;
564 (*KeywordMap)["samplerBuffer"] = SAMPLERBUFFER;
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)["isampler2DRect"] = ISAMPLER2DRECT;
577 (*KeywordMap)["usampler2DRect"] = USAMPLER2DRECT;
578 (*KeywordMap)["isamplerBuffer"] = ISAMPLERBUFFER;
579 (*KeywordMap)["usamplerBuffer"] = USAMPLERBUFFER;
580 (*KeywordMap)["sampler2DMS"] = SAMPLER2DMS;
581 (*KeywordMap)["isampler2DMS"] = ISAMPLER2DMS;
582 (*KeywordMap)["usampler2DMS"] = USAMPLER2DMS;
583 (*KeywordMap)["sampler2DMSArray"] = SAMPLER2DMSARRAY;
584 (*KeywordMap)["isampler2DMSArray"] = ISAMPLER2DMSARRAY;
585 (*KeywordMap)["usampler2DMSArray"] = USAMPLER2DMSARRAY;
586 (*KeywordMap)["sampler1D"] = SAMPLER1D;
587 (*KeywordMap)["sampler1DShadow"] = SAMPLER1DSHADOW;
588 (*KeywordMap)["sampler3D"] = SAMPLER3D;
589 (*KeywordMap)["sampler2DShadow"] = SAMPLER2DSHADOW;
590 (*KeywordMap)["sampler2DRect"] = SAMPLER2DRECT;
591 (*KeywordMap)["sampler2DRectShadow"] = SAMPLER2DRECTSHADOW;
592 (*KeywordMap)["sampler1DArray"] = SAMPLER1DARRAY;
594 (*KeywordMap)["samplerExternalOES"] = SAMPLEREXTERNALOES; // GL_OES_EGL_image_external
596 (*KeywordMap)["__samplerExternal2DY2YEXT"] = SAMPLEREXTERNAL2DY2YEXT; // GL_EXT_YUV_target
598 (*KeywordMap)["sampler"] = SAMPLER;
599 (*KeywordMap)["samplerShadow"] = SAMPLERSHADOW;
601 (*KeywordMap)["texture2D"] = TEXTURE2D;
602 (*KeywordMap)["textureCube"] = TEXTURECUBE;
603 (*KeywordMap)["textureCubeArray"] = TEXTURECUBEARRAY;
604 (*KeywordMap)["itextureCubeArray"] = ITEXTURECUBEARRAY;
605 (*KeywordMap)["utextureCubeArray"] = UTEXTURECUBEARRAY;
606 (*KeywordMap)["itexture1DArray"] = ITEXTURE1DARRAY;
607 (*KeywordMap)["utexture1D"] = UTEXTURE1D;
608 (*KeywordMap)["itexture1D"] = ITEXTURE1D;
609 (*KeywordMap)["utexture1DArray"] = UTEXTURE1DARRAY;
610 (*KeywordMap)["textureBuffer"] = TEXTUREBUFFER;
611 (*KeywordMap)["texture2DArray"] = TEXTURE2DARRAY;
612 (*KeywordMap)["itexture2D"] = ITEXTURE2D;
613 (*KeywordMap)["itexture3D"] = ITEXTURE3D;
614 (*KeywordMap)["itextureCube"] = ITEXTURECUBE;
615 (*KeywordMap)["itexture2DArray"] = ITEXTURE2DARRAY;
616 (*KeywordMap)["utexture2D"] = UTEXTURE2D;
617 (*KeywordMap)["utexture3D"] = UTEXTURE3D;
618 (*KeywordMap)["utextureCube"] = UTEXTURECUBE;
619 (*KeywordMap)["utexture2DArray"] = UTEXTURE2DARRAY;
620 (*KeywordMap)["itexture2DRect"] = ITEXTURE2DRECT;
621 (*KeywordMap)["utexture2DRect"] = UTEXTURE2DRECT;
622 (*KeywordMap)["itextureBuffer"] = ITEXTUREBUFFER;
623 (*KeywordMap)["utextureBuffer"] = UTEXTUREBUFFER;
624 (*KeywordMap)["texture2DMS"] = TEXTURE2DMS;
625 (*KeywordMap)["itexture2DMS"] = ITEXTURE2DMS;
626 (*KeywordMap)["utexture2DMS"] = UTEXTURE2DMS;
627 (*KeywordMap)["texture2DMSArray"] = TEXTURE2DMSARRAY;
628 (*KeywordMap)["itexture2DMSArray"] = ITEXTURE2DMSARRAY;
629 (*KeywordMap)["utexture2DMSArray"] = UTEXTURE2DMSARRAY;
630 (*KeywordMap)["texture1D"] = TEXTURE1D;
631 (*KeywordMap)["texture3D"] = TEXTURE3D;
632 (*KeywordMap)["texture2DRect"] = TEXTURE2DRECT;
633 (*KeywordMap)["texture1DArray"] = TEXTURE1DARRAY;
635 (*KeywordMap)["subpassInput"] = SUBPASSINPUT;
636 (*KeywordMap)["subpassInputMS"] = SUBPASSINPUTMS;
637 (*KeywordMap)["isubpassInput"] = ISUBPASSINPUT;
638 (*KeywordMap)["isubpassInputMS"] = ISUBPASSINPUTMS;
639 (*KeywordMap)["usubpassInput"] = USUBPASSINPUT;
640 (*KeywordMap)["usubpassInputMS"] = USUBPASSINPUTMS;
642 #ifdef AMD_EXTENSIONS
643 (*KeywordMap)["f16sampler1D"] = F16SAMPLER1D;
644 (*KeywordMap)["f16sampler2D"] = F16SAMPLER2D;
645 (*KeywordMap)["f16sampler3D"] = F16SAMPLER3D;
646 (*KeywordMap)["f16sampler2DRect"] = F16SAMPLER2DRECT;
647 (*KeywordMap)["f16samplerCube"] = F16SAMPLERCUBE;
648 (*KeywordMap)["f16sampler1DArray"] = F16SAMPLER1DARRAY;
649 (*KeywordMap)["f16sampler2DArray"] = F16SAMPLER2DARRAY;
650 (*KeywordMap)["f16samplerCubeArray"] = F16SAMPLERCUBEARRAY;
651 (*KeywordMap)["f16samplerBuffer"] = F16SAMPLERBUFFER;
652 (*KeywordMap)["f16sampler2DMS"] = F16SAMPLER2DMS;
653 (*KeywordMap)["f16sampler2DMSArray"] = F16SAMPLER2DMSARRAY;
654 (*KeywordMap)["f16sampler1DShadow"] = F16SAMPLER1DSHADOW;
655 (*KeywordMap)["f16sampler2DShadow"] = F16SAMPLER2DSHADOW;
656 (*KeywordMap)["f16sampler2DRectShadow"] = F16SAMPLER2DRECTSHADOW;
657 (*KeywordMap)["f16samplerCubeShadow"] = F16SAMPLERCUBESHADOW;
658 (*KeywordMap)["f16sampler1DArrayShadow"] = F16SAMPLER1DARRAYSHADOW;
659 (*KeywordMap)["f16sampler2DArrayShadow"] = F16SAMPLER2DARRAYSHADOW;
660 (*KeywordMap)["f16samplerCubeArrayShadow"] = F16SAMPLERCUBEARRAYSHADOW;
662 (*KeywordMap)["f16image1D"] = F16IMAGE1D;
663 (*KeywordMap)["f16image2D"] = F16IMAGE2D;
664 (*KeywordMap)["f16image3D"] = F16IMAGE3D;
665 (*KeywordMap)["f16image2DRect"] = F16IMAGE2DRECT;
666 (*KeywordMap)["f16imageCube"] = F16IMAGECUBE;
667 (*KeywordMap)["f16image1DArray"] = F16IMAGE1DARRAY;
668 (*KeywordMap)["f16image2DArray"] = F16IMAGE2DARRAY;
669 (*KeywordMap)["f16imageCubeArray"] = F16IMAGECUBEARRAY;
670 (*KeywordMap)["f16imageBuffer"] = F16IMAGEBUFFER;
671 (*KeywordMap)["f16image2DMS"] = F16IMAGE2DMS;
672 (*KeywordMap)["f16image2DMSArray"] = F16IMAGE2DMSARRAY;
674 (*KeywordMap)["f16texture1D"] = F16TEXTURE1D;
675 (*KeywordMap)["f16texture2D"] = F16TEXTURE2D;
676 (*KeywordMap)["f16texture3D"] = F16TEXTURE3D;
677 (*KeywordMap)["f16texture2DRect"] = F16TEXTURE2DRECT;
678 (*KeywordMap)["f16textureCube"] = F16TEXTURECUBE;
679 (*KeywordMap)["f16texture1DArray"] = F16TEXTURE1DARRAY;
680 (*KeywordMap)["f16texture2DArray"] = F16TEXTURE2DARRAY;
681 (*KeywordMap)["f16textureCubeArray"] = F16TEXTURECUBEARRAY;
682 (*KeywordMap)["f16textureBuffer"] = F16TEXTUREBUFFER;
683 (*KeywordMap)["f16texture2DMS"] = F16TEXTURE2DMS;
684 (*KeywordMap)["f16texture2DMSArray"] = F16TEXTURE2DMSARRAY;
686 (*KeywordMap)["f16subpassInput"] = F16SUBPASSINPUT;
687 (*KeywordMap)["f16subpassInputMS"] = F16SUBPASSINPUTMS;
690 (*KeywordMap)["noperspective"] = NOPERSPECTIVE;
691 (*KeywordMap)["smooth"] = SMOOTH;
692 (*KeywordMap)["flat"] = FLAT;
693 #ifdef AMD_EXTENSIONS
694 (*KeywordMap)["__explicitInterpAMD"] = EXPLICITINTERPAMD;
696 (*KeywordMap)["centroid"] = CENTROID;
698 (*KeywordMap)["pervertexNV"] = PERVERTEXNV;
700 (*KeywordMap)["precise"] = PRECISE;
701 (*KeywordMap)["invariant"] = INVARIANT;
702 (*KeywordMap)["packed"] = PACKED;
703 (*KeywordMap)["resource"] = RESOURCE;
704 (*KeywordMap)["superp"] = SUPERP;
707 (*KeywordMap)["rayPayloadNV"] = PAYLOADNV;
708 (*KeywordMap)["rayPayloadInNV"] = PAYLOADINNV;
709 (*KeywordMap)["hitAttributeNV"] = HITATTRNV;
710 (*KeywordMap)["callableDataNV"] = CALLDATANV;
711 (*KeywordMap)["callableDataInNV"] = CALLDATAINNV;
712 (*KeywordMap)["accelerationStructureNV"] = ACCSTRUCTNV;
713 (*KeywordMap)["perprimitiveNV"] = PERPRIMITIVENV;
714 (*KeywordMap)["perviewNV"] = PERVIEWNV;
715 (*KeywordMap)["taskNV"] = PERTASKNV;
718 (*KeywordMap)["fcoopmatNV"] = FCOOPMATNV;
720 ReservedSet = new std::unordered_set<const char*, str_hash, str_eq>;
722 ReservedSet->insert("common");
723 ReservedSet->insert("partition");
724 ReservedSet->insert("active");
725 ReservedSet->insert("asm");
726 ReservedSet->insert("class");
727 ReservedSet->insert("union");
728 ReservedSet->insert("enum");
729 ReservedSet->insert("typedef");
730 ReservedSet->insert("template");
731 ReservedSet->insert("this");
732 ReservedSet->insert("goto");
733 ReservedSet->insert("inline");
734 ReservedSet->insert("noinline");
735 ReservedSet->insert("public");
736 ReservedSet->insert("static");
737 ReservedSet->insert("extern");
738 ReservedSet->insert("external");
739 ReservedSet->insert("interface");
740 ReservedSet->insert("long");
741 ReservedSet->insert("short");
742 ReservedSet->insert("half");
743 ReservedSet->insert("fixed");
744 ReservedSet->insert("unsigned");
745 ReservedSet->insert("input");
746 ReservedSet->insert("output");
747 ReservedSet->insert("hvec2");
748 ReservedSet->insert("hvec3");
749 ReservedSet->insert("hvec4");
750 ReservedSet->insert("fvec2");
751 ReservedSet->insert("fvec3");
752 ReservedSet->insert("fvec4");
753 ReservedSet->insert("sampler3DRect");
754 ReservedSet->insert("filter");
755 ReservedSet->insert("sizeof");
756 ReservedSet->insert("cast");
757 ReservedSet->insert("namespace");
758 ReservedSet->insert("using");
761 void TScanContext::deleteKeywordMap()
764 KeywordMap = nullptr;
766 ReservedSet = nullptr;
769 // Called by yylex to get the next token.
770 // Returning 0 implies end of input.
771 int TScanContext::tokenize(TPpContext* pp, TParserToken& token)
774 parserToken = &token;
776 int token = pp->tokenize(ppToken);
777 if (token == EndOfInput)
780 tokenText = ppToken.name;
782 parserToken->sType.lex.loc = loc;
784 case ';': afterType = false; afterBuffer = false; return SEMICOLON;
785 case ',': afterType = false; return COMMA;
786 case ':': return COLON;
787 case '=': afterType = false; return EQUAL;
788 case '(': afterType = false; return LEFT_PAREN;
789 case ')': afterType = false; return RIGHT_PAREN;
790 case '.': field = true; return DOT;
791 case '!': return BANG;
792 case '-': return DASH;
793 case '~': return TILDE;
794 case '+': return PLUS;
795 case '*': return STAR;
796 case '/': return SLASH;
797 case '%': return PERCENT;
798 case '<': return LEFT_ANGLE;
799 case '>': return RIGHT_ANGLE;
800 case '|': return VERTICAL_BAR;
801 case '^': return CARET;
802 case '&': return AMPERSAND;
803 case '?': return QUESTION;
804 case '[': return LEFT_BRACKET;
805 case ']': return RIGHT_BRACKET;
806 case '{': afterStruct = false; afterBuffer = false; return LEFT_BRACE;
807 case '}': return RIGHT_BRACE;
809 parseContext.error(loc, "illegal use of escape character", "\\", "");
812 case PPAtomAddAssign: return ADD_ASSIGN;
813 case PPAtomSubAssign: return SUB_ASSIGN;
814 case PPAtomMulAssign: return MUL_ASSIGN;
815 case PPAtomDivAssign: return DIV_ASSIGN;
816 case PPAtomModAssign: return MOD_ASSIGN;
818 case PpAtomRight: return RIGHT_OP;
819 case PpAtomLeft: return LEFT_OP;
821 case PpAtomRightAssign: return RIGHT_ASSIGN;
822 case PpAtomLeftAssign: return LEFT_ASSIGN;
823 case PpAtomAndAssign: return AND_ASSIGN;
824 case PpAtomOrAssign: return OR_ASSIGN;
825 case PpAtomXorAssign: return XOR_ASSIGN;
827 case PpAtomAnd: return AND_OP;
828 case PpAtomOr: return OR_OP;
829 case PpAtomXor: return XOR_OP;
831 case PpAtomEQ: return EQ_OP;
832 case PpAtomGE: return GE_OP;
833 case PpAtomNE: return NE_OP;
834 case PpAtomLE: return LE_OP;
836 case PpAtomDecrement: return DEC_OP;
837 case PpAtomIncrement: return INC_OP;
839 case PpAtomColonColon:
840 parseContext.error(loc, "not supported", "::", "");
843 case PpAtomConstInt: parserToken->sType.lex.i = ppToken.ival; return INTCONSTANT;
844 case PpAtomConstUint: parserToken->sType.lex.i = ppToken.ival; return UINTCONSTANT;
845 case PpAtomConstInt16: parserToken->sType.lex.i = ppToken.ival; return INT16CONSTANT;
846 case PpAtomConstUint16: parserToken->sType.lex.i = ppToken.ival; return UINT16CONSTANT;
847 case PpAtomConstInt64: parserToken->sType.lex.i64 = ppToken.i64val; return INT64CONSTANT;
848 case PpAtomConstUint64: parserToken->sType.lex.i64 = ppToken.i64val; return UINT64CONSTANT;
849 case PpAtomConstFloat: parserToken->sType.lex.d = ppToken.dval; return FLOATCONSTANT;
850 case PpAtomConstDouble: parserToken->sType.lex.d = ppToken.dval; return DOUBLECONSTANT;
851 case PpAtomConstFloat16: parserToken->sType.lex.d = ppToken.dval; return FLOAT16CONSTANT;
852 case PpAtomIdentifier:
854 int token = tokenizeIdentifier();
859 case EndOfInput: return 0;
863 buf[0] = (char)token;
865 parseContext.error(loc, "unexpected token", buf, "");
871 int TScanContext::tokenizeIdentifier()
873 if (ReservedSet->find(tokenText) != ReservedSet->end())
874 return reservedWord();
876 auto it = KeywordMap->find(tokenText);
877 if (it == KeywordMap->end()) {
878 // Should have an identifier of some sort
879 return identifierOrType();
881 keyword = it->second;
906 if (parseContext.extensionTurnedOn(E_GL_EXT_nonuniform_qualifier))
909 return identifierOrType();
913 if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
914 (parseContext.profile != EEsProfile && parseContext.version < 130))
940 if (strcmp("true", tokenText) == 0)
941 parserToken->sType.lex.b = true;
943 parserToken->sType.lex.b = false;
948 if (parseContext.profile == EEsProfile && parseContext.version >= 300)
954 if ((parseContext.profile == EEsProfile && parseContext.version < 310) ||
955 (parseContext.profile != EEsProfile && parseContext.version < 430))
956 return identifierOrType();
966 if (parseContext.symbolTable.atBuiltInLevel() ||
967 (parseContext.profile != EEsProfile && parseContext.version >= 460
968 && parseContext.extensionTurnedOn(E_GL_NV_ray_tracing)))
970 return identifierOrType();
974 if ((parseContext.profile == EEsProfile && parseContext.version >= 310) ||
975 parseContext.extensionTurnedOn(E_GL_ARB_shader_atomic_counters))
977 return es30ReservedFromGLSL(420);
981 case QUEUEFAMILYCOHERENT:
982 case WORKGROUPCOHERENT:
983 case SUBGROUPCOHERENT:
988 if (parseContext.profile == EEsProfile && parseContext.version >= 310)
990 return es30ReservedFromGLSL(parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store) ? 130 : 420);
993 if (parseContext.profile == EEsProfile && parseContext.version >= 310)
995 if (! parseContext.symbolTable.atBuiltInLevel() && (parseContext.profile == EEsProfile ||
996 (parseContext.version < 420 && ! parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))))
1002 const int numLayoutExts = 2;
1003 const char* layoutExts[numLayoutExts] = { E_GL_ARB_shading_language_420pack,
1004 E_GL_ARB_explicit_attrib_location };
1005 if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
1006 (parseContext.profile != EEsProfile && parseContext.version < 140 &&
1007 ! parseContext.extensionsTurnedOn(numLayoutExts, layoutExts)))
1008 return identifierOrType();
1012 if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
1013 (parseContext.profile != EEsProfile && parseContext.version < 140))
1014 return identifierOrType();
1018 if (parseContext.symbolTable.atBuiltInLevel() ||
1019 (parseContext.profile == EEsProfile &&
1020 (parseContext.version >= 320 ||
1021 parseContext.extensionsTurnedOn(Num_AEP_tessellation_shader, AEP_tessellation_shader))) ||
1022 (parseContext.profile != EEsProfile && parseContext.extensionTurnedOn(E_GL_ARB_tessellation_shader)))
1025 return es30ReservedFromGLSL(400);
1028 if ((parseContext.profile == EEsProfile && parseContext.version >= 320) ||
1029 parseContext.extensionsTurnedOn(1, &E_GL_OES_shader_multisample_interpolation))
1031 return es30ReservedFromGLSL(400);
1034 return es30ReservedFromGLSL(400);
1036 case HIGH_PRECISION:
1037 case MEDIUM_PRECISION:
1040 return precisionKeyword();
1077 return firstGenerationImage(false);
1083 if ((parseContext.profile == EEsProfile && parseContext.version >= 320) ||
1084 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1086 return firstGenerationImage(false);
1101 return firstGenerationImage(true);
1103 case IMAGECUBEARRAY:
1104 case IIMAGECUBEARRAY:
1105 case UIMAGECUBEARRAY:
1107 if ((parseContext.profile == EEsProfile && parseContext.version >= 320) ||
1108 parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
1110 return secondGenerationImage();
1115 case IMAGE2DMSARRAY:
1116 case IIMAGE2DMSARRAY:
1117 case UIMAGE2DMSARRAY:
1119 return secondGenerationImage();
1126 if (parseContext.profile == EEsProfile || parseContext.version < 400)
1139 if (parseContext.symbolTable.atBuiltInLevel() ||
1140 (parseContext.profile != EEsProfile && parseContext.version >= 450 &&
1141 (parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_int64) ||
1142 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1143 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int64))))
1145 return identifierOrType();
1156 if (parseContext.symbolTable.atBuiltInLevel() ||
1157 ((parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1158 parseContext.extensionTurnedOn(E_GL_EXT_shader_8bit_storage) ||
1159 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int8)) &&
1160 parseContext.profile != EEsProfile && parseContext.version >= 450))
1162 return identifierOrType();
1173 if (parseContext.symbolTable.atBuiltInLevel() ||
1174 (parseContext.profile != EEsProfile && parseContext.version >= 450 &&
1176 #ifdef AMD_EXTENSIONS
1177 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_int16) ||
1179 parseContext.extensionTurnedOn(E_GL_EXT_shader_16bit_storage) ||
1180 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1181 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int16))))
1183 return identifierOrType();
1193 if (parseContext.symbolTable.atBuiltInLevel() ||
1194 ((parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1195 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int32)) &&
1196 parseContext.profile != EEsProfile && parseContext.version >= 450))
1198 return identifierOrType();
1216 if (parseContext.symbolTable.atBuiltInLevel() ||
1217 ((parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1218 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float32)) &&
1219 parseContext.profile != EEsProfile && parseContext.version >= 450))
1221 return identifierOrType();
1240 if (parseContext.symbolTable.atBuiltInLevel() ||
1241 ((parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1242 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float64)) &&
1243 parseContext.profile != EEsProfile && parseContext.version >= 450))
1245 return identifierOrType();
1252 if (parseContext.symbolTable.atBuiltInLevel() ||
1253 (parseContext.profile != EEsProfile && parseContext.version >= 450 &&
1255 #ifdef AMD_EXTENSIONS
1256 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float) ||
1258 parseContext.extensionTurnedOn(E_GL_EXT_shader_16bit_storage) ||
1259 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1260 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float16))))
1263 return identifierOrType();
1278 if (parseContext.symbolTable.atBuiltInLevel() ||
1279 (parseContext.profile != EEsProfile && parseContext.version >= 450 &&
1281 #ifdef AMD_EXTENSIONS
1282 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float) ||
1284 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1285 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float16))))
1288 return identifierOrType();
1290 case SAMPLERCUBEARRAY:
1291 case SAMPLERCUBEARRAYSHADOW:
1292 case ISAMPLERCUBEARRAY:
1293 case USAMPLERCUBEARRAY:
1295 if ((parseContext.profile == EEsProfile && parseContext.version >= 320) ||
1296 parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
1298 if (parseContext.profile == EEsProfile || (parseContext.version < 400 && ! parseContext.extensionTurnedOn(E_GL_ARB_texture_cube_map_array)))
1303 case ISAMPLER1DARRAY:
1304 case SAMPLER1DARRAYSHADOW:
1306 case USAMPLER1DARRAY:
1308 return es30ReservedFromGLSL(130);
1314 case SAMPLERCUBESHADOW:
1315 case SAMPLER2DARRAY:
1316 case SAMPLER2DARRAYSHADOW:
1320 case ISAMPLER2DARRAY:
1324 case USAMPLER2DARRAY:
1326 return nonreservedKeyword(300, 130);
1328 case ISAMPLER2DRECT:
1329 case USAMPLER2DRECT:
1331 return es30ReservedFromGLSL(140);
1335 if ((parseContext.profile == EEsProfile && parseContext.version >= 320) ||
1336 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1338 return es30ReservedFromGLSL(130);
1340 case ISAMPLERBUFFER:
1341 case USAMPLERBUFFER:
1343 if ((parseContext.profile == EEsProfile && parseContext.version >= 320) ||
1344 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1346 return es30ReservedFromGLSL(140);
1352 if (parseContext.profile == EEsProfile && parseContext.version >= 310)
1354 return es30ReservedFromGLSL(150);
1356 case SAMPLER2DMSARRAY:
1357 case ISAMPLER2DMSARRAY:
1358 case USAMPLER2DMSARRAY:
1360 if ((parseContext.profile == EEsProfile && parseContext.version >= 320) ||
1361 parseContext.extensionsTurnedOn(1, &E_GL_OES_texture_storage_multisample_2d_array))
1363 return es30ReservedFromGLSL(150);
1366 case SAMPLER1DSHADOW:
1368 if (parseContext.profile == EEsProfile)
1374 if (parseContext.profile == EEsProfile && parseContext.version < 300) {
1375 if (!parseContext.extensionTurnedOn(E_GL_OES_texture_3D))
1380 case SAMPLER2DSHADOW:
1382 if (parseContext.profile == EEsProfile && parseContext.version < 300) {
1383 if (!parseContext.extensionTurnedOn(E_GL_EXT_shadow_samplers))
1389 case SAMPLER2DRECTSHADOW:
1391 if (parseContext.profile == EEsProfile)
1393 else if (parseContext.version < 140 && ! parseContext.symbolTable.atBuiltInLevel() && ! parseContext.extensionTurnedOn(E_GL_ARB_texture_rectangle)) {
1394 if (parseContext.relaxedErrors())
1395 parseContext.requireExtensions(loc, 1, &E_GL_ARB_texture_rectangle, "texture-rectangle sampler keyword");
1401 case SAMPLER1DARRAY:
1403 if (parseContext.profile == EEsProfile && parseContext.version == 300)
1405 else if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
1406 (parseContext.profile != EEsProfile && parseContext.version < 130))
1407 return identifierOrType();
1410 case SAMPLEREXTERNALOES:
1412 if (parseContext.symbolTable.atBuiltInLevel() ||
1413 parseContext.extensionTurnedOn(E_GL_OES_EGL_image_external) ||
1414 parseContext.extensionTurnedOn(E_GL_OES_EGL_image_external_essl3))
1416 return identifierOrType();
1418 case SAMPLEREXTERNAL2DY2YEXT:
1420 if (parseContext.symbolTable.atBuiltInLevel() ||
1421 parseContext.extensionTurnedOn(E_GL_EXT_YUV_target))
1423 return identifierOrType();
1427 case TEXTURECUBEARRAY:
1428 case ITEXTURECUBEARRAY:
1429 case UTEXTURECUBEARRAY:
1430 case ITEXTURE1DARRAY:
1433 case UTEXTURE1DARRAY:
1435 case TEXTURE2DARRAY:
1439 case ITEXTURE2DARRAY:
1443 case UTEXTURE2DARRAY:
1444 case ITEXTURE2DRECT:
1445 case UTEXTURE2DRECT:
1446 case ITEXTUREBUFFER:
1447 case UTEXTUREBUFFER:
1451 case TEXTURE2DMSARRAY:
1452 case ITEXTURE2DMSARRAY:
1453 case UTEXTURE2DMSARRAY:
1457 case TEXTURE1DARRAY:
1460 if (parseContext.spvVersion.vulkan > 0)
1463 return identifierOrType();
1466 case SUBPASSINPUTMS:
1468 case ISUBPASSINPUTMS:
1470 case USUBPASSINPUTMS:
1471 if (parseContext.spvVersion.vulkan > 0)
1474 return identifierOrType();
1476 #ifdef AMD_EXTENSIONS
1480 case F16SAMPLER2DRECT:
1481 case F16SAMPLERCUBE:
1482 case F16SAMPLER1DARRAY:
1483 case F16SAMPLER2DARRAY:
1484 case F16SAMPLERCUBEARRAY:
1485 case F16SAMPLERBUFFER:
1486 case F16SAMPLER2DMS:
1487 case F16SAMPLER2DMSARRAY:
1488 case F16SAMPLER1DSHADOW:
1489 case F16SAMPLER2DSHADOW:
1490 case F16SAMPLER1DARRAYSHADOW:
1491 case F16SAMPLER2DARRAYSHADOW:
1492 case F16SAMPLER2DRECTSHADOW:
1493 case F16SAMPLERCUBESHADOW:
1494 case F16SAMPLERCUBEARRAYSHADOW:
1499 case F16IMAGE2DRECT:
1501 case F16IMAGE1DARRAY:
1502 case F16IMAGE2DARRAY:
1503 case F16IMAGECUBEARRAY:
1504 case F16IMAGEBUFFER:
1506 case F16IMAGE2DMSARRAY:
1511 case F16TEXTURE2DRECT:
1512 case F16TEXTURECUBE:
1513 case F16TEXTURE1DARRAY:
1514 case F16TEXTURE2DARRAY:
1515 case F16TEXTURECUBEARRAY:
1516 case F16TEXTUREBUFFER:
1517 case F16TEXTURE2DMS:
1518 case F16TEXTURE2DMSARRAY:
1520 case F16SUBPASSINPUT:
1521 case F16SUBPASSINPUTMS:
1523 if (parseContext.symbolTable.atBuiltInLevel() ||
1524 (parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float_fetch) &&
1525 parseContext.profile != EEsProfile && parseContext.version >= 450))
1527 return identifierOrType();
1531 #ifdef NV_EXTENSIONS
1532 if (parseContext.profile == EEsProfile && parseContext.version >= 300 &&
1533 parseContext.extensionTurnedOn(E_GL_NV_shader_noperspective_interpolation))
1536 return es30ReservedFromGLSL(130);
1539 if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
1540 (parseContext.profile != EEsProfile && parseContext.version < 130))
1541 return identifierOrType();
1544 #ifdef AMD_EXTENSIONS
1545 case EXPLICITINTERPAMD:
1546 if (parseContext.profile != EEsProfile && parseContext.version >= 450 &&
1547 parseContext.extensionTurnedOn(E_GL_AMD_shader_explicit_vertex_parameter))
1549 return identifierOrType();
1552 #ifdef NV_EXTENSIONS
1554 if (((parseContext.profile != EEsProfile && parseContext.version >= 450) ||
1555 (parseContext.profile == EEsProfile && parseContext.version >= 320)) &&
1556 parseContext.extensionTurnedOn(E_GL_NV_fragment_shader_barycentric))
1558 return identifierOrType();
1562 if (parseContext.profile == EEsProfile && parseContext.version < 300)
1564 else if (parseContext.profile != EEsProfile && parseContext.version < 130)
1565 return identifierOrType();
1569 if (parseContext.version < 120)
1570 return identifierOrType();
1574 if ((parseContext.profile == EEsProfile &&
1575 (parseContext.version >= 320 || parseContext.extensionsTurnedOn(Num_AEP_gpu_shader5, AEP_gpu_shader5))) ||
1576 (parseContext.profile != EEsProfile && parseContext.version >= 400))
1578 if (parseContext.profile == EEsProfile && parseContext.version == 310) {
1582 return identifierOrType();
1585 if (parseContext.profile != EEsProfile && parseContext.version < 120)
1586 return identifierOrType();
1590 if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
1591 (parseContext.profile != EEsProfile && parseContext.version < 330))
1592 return reservedWord();
1593 return identifierOrType();
1597 bool reserved = (parseContext.profile == EEsProfile && parseContext.version >= 300) ||
1598 (parseContext.profile != EEsProfile && parseContext.version >= 420);
1599 return identifierOrReserved(reserved);
1603 bool reserved = parseContext.profile == EEsProfile || parseContext.version >= 130;
1604 return identifierOrReserved(reserved);
1607 #ifdef NV_EXTENSIONS
1608 case PERPRIMITIVENV:
1611 if ((parseContext.profile != EEsProfile && parseContext.version >= 450) ||
1612 (parseContext.profile == EEsProfile && parseContext.version >= 320) ||
1613 parseContext.extensionTurnedOn(E_GL_NV_mesh_shader))
1615 return identifierOrType();
1620 if (parseContext.symbolTable.atBuiltInLevel() ||
1621 parseContext.extensionTurnedOn(E_GL_NV_cooperative_matrix))
1623 return identifierOrType();
1626 if (parseContext.extensionTurnedOn(E_GL_EXT_demote_to_helper_invocation))
1629 return identifierOrType();
1632 parseContext.infoSink.info.message(EPrefixInternalError, "Unknown glslang keyword", loc);
1637 int TScanContext::identifierOrType()
1639 parserToken->sType.lex.string = NewPoolTString(tokenText);
1643 parserToken->sType.lex.symbol = parseContext.symbolTable.find(*parserToken->sType.lex.string);
1644 if ((afterType == false && afterStruct == false) && parserToken->sType.lex.symbol != nullptr) {
1645 if (const TVariable* variable = parserToken->sType.lex.symbol->getAsVariable()) {
1646 if (variable->isUserType() &&
1647 // treat redeclaration of forward-declared buffer/uniform reference as an identifier
1648 !(variable->getType().getBasicType() == EbtReference && afterBuffer)) {
1659 // Give an error for use of a reserved symbol.
1660 // However, allow built-in declarations to use reserved words, to allow
1661 // extension support before the extension is enabled.
1662 int TScanContext::reservedWord()
1664 if (! parseContext.symbolTable.atBuiltInLevel())
1665 parseContext.error(loc, "Reserved word.", tokenText, "", "");
1670 int TScanContext::identifierOrReserved(bool reserved)
1678 if (parseContext.forwardCompatible)
1679 parseContext.warn(loc, "using future reserved keyword", tokenText, "");
1681 return identifierOrType();
1684 // For keywords that suddenly showed up on non-ES (not previously reserved)
1685 // but then got reserved by ES 3.0.
1686 int TScanContext::es30ReservedFromGLSL(int version)
1688 if (parseContext.symbolTable.atBuiltInLevel())
1691 if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
1692 (parseContext.profile != EEsProfile && parseContext.version < version)) {
1693 if (parseContext.forwardCompatible)
1694 parseContext.warn(loc, "future reserved word in ES 300 and keyword in GLSL", tokenText, "");
1696 return identifierOrType();
1697 } else if (parseContext.profile == EEsProfile && parseContext.version >= 300)
1703 // For a keyword that was never reserved, until it suddenly
1704 // showed up, both in an es version and a non-ES version.
1705 int TScanContext::nonreservedKeyword(int esVersion, int nonEsVersion)
1707 if ((parseContext.profile == EEsProfile && parseContext.version < esVersion) ||
1708 (parseContext.profile != EEsProfile && parseContext.version < nonEsVersion)) {
1709 if (parseContext.forwardCompatible)
1710 parseContext.warn(loc, "using future keyword", tokenText, "");
1712 return identifierOrType();
1718 int TScanContext::precisionKeyword()
1720 if (parseContext.profile == EEsProfile || parseContext.version >= 130)
1723 if (parseContext.forwardCompatible)
1724 parseContext.warn(loc, "using ES precision qualifier keyword", tokenText, "");
1726 return identifierOrType();
1729 int TScanContext::matNxM()
1733 if (parseContext.version > 110)
1736 if (parseContext.forwardCompatible)
1737 parseContext.warn(loc, "using future non-square matrix type keyword", tokenText, "");
1739 return identifierOrType();
1742 int TScanContext::dMat()
1746 if (parseContext.profile == EEsProfile && parseContext.version >= 300) {
1752 if (parseContext.profile != EEsProfile && parseContext.version >= 400)
1755 if (parseContext.forwardCompatible)
1756 parseContext.warn(loc, "using future type keyword", tokenText, "");
1758 return identifierOrType();
1761 int TScanContext::firstGenerationImage(bool inEs310)
1763 if (parseContext.symbolTable.atBuiltInLevel() ||
1764 (parseContext.profile != EEsProfile && (parseContext.version >= 420 ||
1765 parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))) ||
1766 (inEs310 && parseContext.profile == EEsProfile && parseContext.version >= 310))
1769 if ((parseContext.profile == EEsProfile && parseContext.version >= 300) ||
1770 (parseContext.profile != EEsProfile && parseContext.version >= 130)) {
1776 if (parseContext.forwardCompatible)
1777 parseContext.warn(loc, "using future type keyword", tokenText, "");
1779 return identifierOrType();
1782 int TScanContext::secondGenerationImage()
1784 if (parseContext.profile == EEsProfile && parseContext.version >= 310) {
1789 if (parseContext.symbolTable.atBuiltInLevel() ||
1790 (parseContext.profile != EEsProfile &&
1791 (parseContext.version >= 420 || parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))))
1794 if (parseContext.forwardCompatible)
1795 parseContext.warn(loc, "using future type keyword", tokenText, "");
1797 return identifierOrType();
1800 } // end namespace glslang