1 // 2 // Copyright (C) 2015-2018 Google, Inc. 3 // Copyright (C) 2017 ARM Limited. 4 // 5 // All rights reserved. 6 // 7 // Redistribution and use in source and binary forms, with or without 8 // modification, are permitted provided that the following conditions 9 // are met: 10 // 11 // Redistributions of source code must retain the above copyright 12 // notice, this list of conditions and the following disclaimer. 13 // 14 // Redistributions in binary form must reproduce the above 15 // copyright notice, this list of conditions and the following 16 // disclaimer in the documentation and/or other materials provided 17 // with the distribution. 18 // 19 // Neither the name of 3Dlabs Inc. Ltd. nor the names of its 20 // contributors may be used to endorse or promote products derived 21 // from this software without specific prior written permission. 22 // 23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 26 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 27 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 28 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 29 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 33 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 // POSSIBILITY OF SUCH DAMAGE. 35 // 36 37 // This is implemented in Versions.cpp 38 39 #ifndef _PARSE_VERSIONS_INCLUDED_ 40 #define _PARSE_VERSIONS_INCLUDED_ 41 42 #include "../Public/ShaderLang.h" 43 #include "../Include/InfoSink.h" 44 #include "Scan.h" 45 46 #include <map> 47 48 namespace glslang { 49 50 // 51 // Base class for parse helpers. 52 // This just has version-related information and checking. 53 // This class should be sufficient for preprocessing. 54 // 55 class TParseVersions { 56 public: TParseVersions(TIntermediate & interm,int version,EProfile profile,const SpvVersion & spvVersion,EShLanguage language,TInfoSink & infoSink,bool forwardCompatible,EShMessages messages)57 TParseVersions(TIntermediate& interm, int version, EProfile profile, 58 const SpvVersion& spvVersion, EShLanguage language, TInfoSink& infoSink, 59 bool forwardCompatible, EShMessages messages) 60 : 61 forwardCompatible(forwardCompatible), 62 profile(profile), 63 infoSink(infoSink), version(version), 64 language(language), 65 spvVersion(spvVersion), 66 intermediate(interm), messages(messages), numErrors(0), currentScanner(nullptr) { } ~TParseVersions()67 virtual ~TParseVersions() { } 68 void requireStage(const TSourceLoc&, EShLanguageMask, const char* featureDesc); 69 void requireStage(const TSourceLoc&, EShLanguage, const char* featureDesc); 70 71 bool forwardCompatible; // true if errors are to be given for use of deprecated features 72 EProfile profile; // the declared profile in the shader (core by default) isEsProfile()73 bool isEsProfile() const { return profile == EEsProfile; } 74 void requireProfile(const TSourceLoc& loc, int profileMask, const char* featureDesc); 75 void profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, int numExtensions, 76 const char* const extensions[], const char* featureDesc); 77 void profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, const char* extension, 78 const char* featureDesc); 79 virtual void initializeExtensionBehavior(); 80 virtual void checkDeprecated(const TSourceLoc&, int queryProfiles, int depVersion, const char* featureDesc); 81 virtual void requireNotRemoved(const TSourceLoc&, int queryProfiles, int removedVersion, const char* featureDesc); 82 virtual void requireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[], 83 const char* featureDesc); 84 virtual void ppRequireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[], 85 const char* featureDesc); 86 virtual TExtensionBehavior getExtensionBehavior(const char*); 87 virtual bool extensionTurnedOn(const char* const extension); 88 virtual bool extensionsTurnedOn(int numExtensions, const char* const extensions[]); 89 virtual void updateExtensionBehavior(int line, const char* const extension, const char* behavior); 90 virtual void updateExtensionBehavior(const char* const extension, TExtensionBehavior); 91 virtual bool checkExtensionsRequested(const TSourceLoc&, int numExtensions, const char* const extensions[], 92 const char* featureDesc); 93 virtual void checkExtensionStage(const TSourceLoc&, const char* const extension); 94 virtual void extensionRequires(const TSourceLoc&, const char* const extension, const char* behavior); 95 virtual void fullIntegerCheck(const TSourceLoc&, const char* op); 96 97 virtual void unimplemented(const TSourceLoc&, const char* featureDesc); 98 virtual void doubleCheck(const TSourceLoc&, const char* op); 99 virtual void float16Check(const TSourceLoc&, const char* op, bool builtIn = false); 100 virtual void float16ScalarVectorCheck(const TSourceLoc&, const char* op, bool builtIn = false); 101 virtual bool float16Arithmetic(); 102 virtual void requireFloat16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc); 103 virtual void int16ScalarVectorCheck(const TSourceLoc&, const char* op, bool builtIn = false); 104 virtual bool int16Arithmetic(); 105 virtual void requireInt16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc); 106 virtual void int8ScalarVectorCheck(const TSourceLoc&, const char* op, bool builtIn = false); 107 virtual bool int8Arithmetic(); 108 virtual void requireInt8Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc); 109 virtual void float16OpaqueCheck(const TSourceLoc&, const char* op, bool builtIn = false); 110 virtual void int64Check(const TSourceLoc&, const char* op, bool builtIn = false); 111 virtual void explicitInt8Check(const TSourceLoc&, const char* op, bool builtIn = false); 112 virtual void explicitInt16Check(const TSourceLoc&, const char* op, bool builtIn = false); 113 virtual void explicitInt32Check(const TSourceLoc&, const char* op, bool builtIn = false); 114 virtual void explicitFloat32Check(const TSourceLoc&, const char* op, bool builtIn = false); 115 virtual void explicitFloat64Check(const TSourceLoc&, const char* op, bool builtIn = false); 116 virtual void fcoopmatCheckNV(const TSourceLoc&, const char* op, bool builtIn = false); 117 virtual void intcoopmatCheckNV(const TSourceLoc&, const char *op, bool builtIn = false); 118 virtual void coopmatCheck(const TSourceLoc&, const char* op, bool builtIn = false); relaxedErrors()119 bool relaxedErrors() const { return (messages & EShMsgRelaxedErrors) != 0; } suppressWarnings()120 bool suppressWarnings() const { return (messages & EShMsgSuppressWarnings) != 0; } isForwardCompatible()121 bool isForwardCompatible() const { return forwardCompatible; } 122 123 virtual void spvRemoved(const TSourceLoc&, const char* op); 124 virtual void vulkanRemoved(const TSourceLoc&, const char* op); 125 virtual void requireVulkan(const TSourceLoc&, const char* op); 126 virtual void requireSpv(const TSourceLoc&, const char* op); 127 virtual void requireSpv(const TSourceLoc&, const char *op, unsigned int version); 128 129 virtual void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken, 130 const char* szExtraInfoFormat, ...) = 0; 131 virtual void C_DECL warn(const TSourceLoc&, const char* szReason, const char* szToken, 132 const char* szExtraInfoFormat, ...) = 0; 133 virtual void C_DECL ppError(const TSourceLoc&, const char* szReason, const char* szToken, 134 const char* szExtraInfoFormat, ...) = 0; 135 virtual void C_DECL ppWarn(const TSourceLoc&, const char* szReason, const char* szToken, 136 const char* szExtraInfoFormat, ...) = 0; 137 addError()138 void addError() { ++numErrors; } getNumErrors()139 int getNumErrors() const { return numErrors; } 140 setScanner(TInputScanner * scanner)141 void setScanner(TInputScanner* scanner) { currentScanner = scanner; } getScanner()142 TInputScanner* getScanner() const { return currentScanner; } getCurrentLoc()143 const TSourceLoc& getCurrentLoc() const { return currentScanner->getSourceLoc(); } setCurrentLine(int line)144 void setCurrentLine(int line) { currentScanner->setLine(line); } setCurrentColumn(int col)145 void setCurrentColumn(int col) { currentScanner->setColumn(col); } setCurrentSourceName(const char * name)146 void setCurrentSourceName(const char* name) { currentScanner->setFile(name); } setCurrentString(int string)147 void setCurrentString(int string) { currentScanner->setString(string); } 148 149 void getPreamble(std::string&); 150 #ifdef ENABLE_HLSL isReadingHLSL()151 bool isReadingHLSL() const { return (messages & EShMsgReadHlsl) == EShMsgReadHlsl; } hlslEnable16BitTypes()152 bool hlslEnable16BitTypes() const { return (messages & EShMsgHlslEnable16BitTypes) != 0; } hlslDX9Compatible()153 bool hlslDX9Compatible() const { return (messages & EShMsgHlslDX9Compatible) != 0; } 154 #else isReadingHLSL()155 bool isReadingHLSL() const { return false; } 156 #endif 157 158 TInfoSink& infoSink; 159 160 // compilation mode 161 int version; // version, updated by #version in the shader 162 EShLanguage language; // really the stage 163 SpvVersion spvVersion; 164 TIntermediate& intermediate; // helper for making and hooking up pieces of the parse tree 165 166 protected: 167 TMap<TString, TExtensionBehavior> extensionBehavior; // for each extension string, what its current behavior is 168 TMap<TString, unsigned int> extensionMinSpv; // for each extension string, store minimum spirv required 169 TVector<TString> spvUnsupportedExt; // for extensions reserved for spv usage. 170 EShMessages messages; // errors/warnings/rule-sets 171 int numErrors; // number of compile-time errors encountered 172 TInputScanner* currentScanner; 173 174 private: 175 explicit TParseVersions(const TParseVersions&); 176 TParseVersions& operator=(const TParseVersions&); 177 }; 178 179 } // end namespace glslang 180 181 #endif // _PARSE_VERSIONS_INCLUDED_ 182