1 // 2 // Copyright (C) 2016-2018 Google, Inc. 3 // Copyright (C) 2016 LunarG, Inc. 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 #ifndef HLSL_PARSE_INCLUDED_ 37 #define HLSL_PARSE_INCLUDED_ 38 39 #include "../glslang/MachineIndependent/parseVersions.h" 40 #include "../glslang/MachineIndependent/ParseHelper.h" 41 #include "../glslang/MachineIndependent/attribute.h" 42 43 #include <array> 44 45 namespace glslang { 46 47 class TFunctionDeclarator; 48 49 class HlslParseContext : public TParseContextBase { 50 public: 51 HlslParseContext(TSymbolTable&, TIntermediate&, bool parsingBuiltins, 52 int version, EProfile, const SpvVersion& spvVersion, EShLanguage, TInfoSink&, 53 const TString sourceEntryPointName, 54 bool forwardCompatible = false, EShMessages messages = EShMsgDefault); 55 virtual ~HlslParseContext(); 56 void initializeExtensionBehavior() override; 57 58 void setLimits(const TBuiltInResource&) override; 59 bool parseShaderStrings(TPpContext&, TInputScanner& input, bool versionWillBeError = false) override; getGlobalUniformBlockName()60 virtual const char* getGlobalUniformBlockName() const override { return "$Global"; } setUniformBlockDefaults(TType & block)61 virtual void setUniformBlockDefaults(TType& block) const override 62 { 63 block.getQualifier().layoutPacking = ElpStd140; 64 block.getQualifier().layoutMatrix = ElmRowMajor; 65 } 66 reservedPpErrorCheck(const TSourceLoc &,const char *,const char *)67 void reservedPpErrorCheck(const TSourceLoc&, const char* /*name*/, const char* /*op*/) override { } lineContinuationCheck(const TSourceLoc &,bool)68 bool lineContinuationCheck(const TSourceLoc&, bool /*endOfComment*/) override { return true; } lineDirectiveShouldSetNextLine()69 bool lineDirectiveShouldSetNextLine() const override { return true; } 70 bool builtInName(const TString&); 71 72 void handlePragma(const TSourceLoc&, const TVector<TString>&) override; 73 TIntermTyped* handleVariable(const TSourceLoc&, const TString* string); 74 TIntermTyped* handleBracketDereference(const TSourceLoc&, TIntermTyped* base, TIntermTyped* index); 75 TIntermTyped* handleBracketOperator(const TSourceLoc&, TIntermTyped* base, TIntermTyped* index); 76 77 TIntermTyped* handleBinaryMath(const TSourceLoc&, const char* str, TOperator op, TIntermTyped* left, TIntermTyped* right); 78 TIntermTyped* handleUnaryMath(const TSourceLoc&, const char* str, TOperator op, TIntermTyped* childNode); 79 TIntermTyped* handleDotDereference(const TSourceLoc&, TIntermTyped* base, const TString& field); 80 bool isBuiltInMethod(const TSourceLoc&, TIntermTyped* base, const TString& field); 81 void assignToInterface(TVariable& variable); 82 void handleFunctionDeclarator(const TSourceLoc&, TFunction& function, bool prototype); 83 TIntermAggregate* handleFunctionDefinition(const TSourceLoc&, TFunction&, const TAttributes&, TIntermNode*& entryPointTree); 84 TIntermNode* transformEntryPoint(const TSourceLoc&, TFunction&, const TAttributes&); 85 void handleEntryPointAttributes(const TSourceLoc&, const TAttributes&); 86 void transferTypeAttributes(const TSourceLoc&, const TAttributes&, TType&, bool allowEntry = false); 87 void handleFunctionBody(const TSourceLoc&, TFunction&, TIntermNode* functionBody, TIntermNode*& node); 88 void remapEntryPointIO(TFunction& function, TVariable*& returnValue, TVector<TVariable*>& inputs, TVector<TVariable*>& outputs); 89 void remapNonEntryPointIO(TFunction& function); 90 TIntermNode* handleReturnValue(const TSourceLoc&, TIntermTyped*); 91 void handleFunctionArgument(TFunction*, TIntermTyped*& arguments, TIntermTyped* newArg); 92 TIntermTyped* handleAssign(const TSourceLoc&, TOperator, TIntermTyped* left, TIntermTyped* right); 93 TIntermTyped* handleAssignToMatrixSwizzle(const TSourceLoc&, TOperator, TIntermTyped* left, TIntermTyped* right); 94 TIntermTyped* handleFunctionCall(const TSourceLoc&, TFunction*, TIntermTyped*); 95 TIntermAggregate* assignClipCullDistance(const TSourceLoc&, TOperator, int semanticId, TIntermTyped* left, TIntermTyped* right); 96 TIntermTyped* assignPosition(const TSourceLoc&, TOperator, TIntermTyped* left, TIntermTyped* right); 97 void decomposeIntrinsic(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments); 98 void decomposeSampleMethods(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments); 99 void decomposeStructBufferMethods(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments); 100 void decomposeGeometryMethods(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments); 101 void pushFrontArguments(TIntermTyped* front, TIntermTyped*& arguments); 102 void addInputArgumentConversions(const TFunction&, TIntermTyped*&); 103 void expandArguments(const TSourceLoc&, const TFunction&, TIntermTyped*&); 104 TIntermTyped* addOutputArgumentConversions(const TFunction&, TIntermOperator&); 105 void builtInOpCheck(const TSourceLoc&, const TFunction&, TIntermOperator&); 106 TFunction* makeConstructorCall(const TSourceLoc&, const TType&); 107 void handleSemantic(TSourceLoc, TQualifier&, TBuiltInVariable, const TString& upperCase); 108 void handlePackOffset(const TSourceLoc&, TQualifier&, const glslang::TString& location, 109 const glslang::TString* component); 110 void handleRegister(const TSourceLoc&, TQualifier&, const glslang::TString* profile, const glslang::TString& desc, 111 int subComponent, const glslang::TString*); 112 TIntermTyped* convertConditionalExpression(const TSourceLoc&, TIntermTyped*, bool mustBeScalar = true); 113 TIntermAggregate* handleSamplerTextureCombine(const TSourceLoc& loc, TIntermTyped* argTex, TIntermTyped* argSampler); 114 115 bool parseMatrixSwizzleSelector(const TSourceLoc&, const TString&, int cols, int rows, TSwizzleSelectors<TMatrixSelector>&); 116 int getMatrixComponentsColumn(int rows, const TSwizzleSelectors<TMatrixSelector>&); 117 void assignError(const TSourceLoc&, const char* op, TString left, TString right); 118 void unaryOpError(const TSourceLoc&, const char* op, TString operand); 119 void binaryOpError(const TSourceLoc&, const char* op, TString left, TString right); 120 void variableCheck(TIntermTyped*& nodePtr); 121 void constantValueCheck(TIntermTyped* node, const char* token); 122 void integerCheck(const TIntermTyped* node, const char* token); 123 void globalCheck(const TSourceLoc&, const char* token); 124 bool constructorError(const TSourceLoc&, TIntermNode*, TFunction&, TOperator, TType&); 125 void arraySizeCheck(const TSourceLoc&, TIntermTyped* expr, TArraySize&); 126 void arraySizeRequiredCheck(const TSourceLoc&, const TArraySizes&); 127 void structArrayCheck(const TSourceLoc&, const TType& structure); 128 bool voidErrorCheck(const TSourceLoc&, const TString&, TBasicType); 129 void globalQualifierFix(const TSourceLoc&, TQualifier&); 130 bool structQualifierErrorCheck(const TSourceLoc&, const TPublicType& pType); 131 void mergeQualifiers(TQualifier& dst, const TQualifier& src); 132 int computeSamplerTypeIndex(TSampler&); 133 TSymbol* redeclareBuiltinVariable(const TSourceLoc&, const TString&, const TQualifier&, const TShaderQualifiers&); 134 void paramFix(TType& type); 135 void specializationCheck(const TSourceLoc&, const TType&, const char* op); 136 137 void setLayoutQualifier(const TSourceLoc&, TQualifier&, TString&); 138 void setLayoutQualifier(const TSourceLoc&, TQualifier&, TString&, const TIntermTyped*); 139 void setSpecConstantId(const TSourceLoc&, TQualifier&, int value); 140 void mergeObjectLayoutQualifiers(TQualifier& dest, const TQualifier& src, bool inheritOnly); 141 void checkNoShaderLayouts(const TSourceLoc&, const TShaderQualifiers&); 142 143 const TFunction* findFunction(const TSourceLoc& loc, TFunction& call, bool& builtIn, int& thisDepth, TIntermTyped*& args); 144 void addGenMulArgumentConversion(const TSourceLoc& loc, TFunction& call, TIntermTyped*& args); 145 void declareTypedef(const TSourceLoc&, const TString& identifier, const TType&); 146 void declareStruct(const TSourceLoc&, TString& structName, TType&); 147 TSymbol* lookupUserType(const TString&, TType&); 148 TIntermNode* declareVariable(const TSourceLoc&, const TString& identifier, TType&, TIntermTyped* initializer = 0); 149 void lengthenList(const TSourceLoc&, TIntermSequence& list, int size, TIntermTyped* scalarInit); 150 TIntermTyped* handleConstructor(const TSourceLoc&, TIntermTyped*, const TType&); 151 TIntermTyped* addConstructor(const TSourceLoc&, TIntermTyped*, const TType&); 152 TIntermTyped* convertArray(TIntermTyped*, const TType&); 153 TIntermTyped* constructAggregate(TIntermNode*, const TType&, int, const TSourceLoc&); 154 TIntermTyped* constructBuiltIn(const TType&, TOperator, TIntermTyped*, const TSourceLoc&, bool subset); 155 void declareBlock(const TSourceLoc&, TType&, const TString* instanceName = 0); 156 void declareStructBufferCounter(const TSourceLoc& loc, const TType& bufferType, const TString& name); 157 void fixBlockLocations(const TSourceLoc&, TQualifier&, TTypeList&, bool memberWithLocation, bool memberWithoutLocation); 158 void fixXfbOffsets(TQualifier&, TTypeList&); 159 void fixBlockUniformOffsets(const TQualifier&, TTypeList&); 160 void addQualifierToExisting(const TSourceLoc&, TQualifier, const TString& identifier); 161 void addQualifierToExisting(const TSourceLoc&, TQualifier, TIdentifierList&); 162 void updateStandaloneQualifierDefaults(const TSourceLoc&, const TPublicType&); 163 void wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode); 164 TIntermNode* addSwitch(const TSourceLoc&, TIntermTyped* expression, TIntermAggregate* body, const TAttributes&); 165 nestLooping()166 void nestLooping() { ++loopNestingLevel; } unnestLooping()167 void unnestLooping() { --loopNestingLevel; } nestAnnotations()168 void nestAnnotations() { ++annotationNestingLevel; } unnestAnnotations()169 void unnestAnnotations() { --annotationNestingLevel; } getAnnotationNestingLevel()170 int getAnnotationNestingLevel() { return annotationNestingLevel; } pushScope()171 void pushScope() { symbolTable.push(); } popScope()172 void popScope() { symbolTable.pop(0); } 173 174 void pushThisScope(const TType&, const TVector<TFunctionDeclarator>&); popThisScope()175 void popThisScope() { symbolTable.pop(0); } 176 pushImplicitThis(TVariable * thisParameter)177 void pushImplicitThis(TVariable* thisParameter) { implicitThisStack.push_back(thisParameter); } popImplicitThis()178 void popImplicitThis() { implicitThisStack.pop_back(); } getImplicitThis(int thisDepth)179 TVariable* getImplicitThis(int thisDepth) const { return implicitThisStack[implicitThisStack.size() - thisDepth]; } 180 181 void pushNamespace(const TString& name); 182 void popNamespace(); 183 void getFullNamespaceName(TString*&) const; 184 void addScopeMangler(TString&); 185 pushSwitchSequence(TIntermSequence * sequence)186 void pushSwitchSequence(TIntermSequence* sequence) { switchSequenceStack.push_back(sequence); } popSwitchSequence()187 void popSwitchSequence() { switchSequenceStack.pop_back(); } 188 189 virtual void growGlobalUniformBlock(const TSourceLoc&, TType&, const TString& memberName, 190 TTypeList* typeList = nullptr) override; 191 192 // Apply L-value conversions. E.g, turning a write to a RWTexture into an ImageStore. 193 TIntermTyped* handleLvalue(const TSourceLoc&, const char* op, TIntermTyped*& node); 194 bool lValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*) override; 195 196 TLayoutFormat getLayoutFromTxType(const TSourceLoc&, const TType&); 197 198 bool handleOutputGeometry(const TSourceLoc&, const TLayoutGeometry& geometry); 199 bool handleInputGeometry(const TSourceLoc&, const TLayoutGeometry& geometry); 200 201 // Determine selection control from attributes 202 void handleSelectionAttributes(const TSourceLoc& loc, TIntermSelection*, const TAttributes& attributes); 203 void handleSwitchAttributes(const TSourceLoc& loc, TIntermSwitch*, const TAttributes& attributes); 204 205 // Determine loop control from attributes 206 void handleLoopAttributes(const TSourceLoc& loc, TIntermLoop*, const TAttributes& attributes); 207 208 // Share struct buffer deep types 209 void shareStructBufferType(TType&); 210 211 // Set texture return type of the given sampler. Returns success (not all types are valid). 212 bool setTextureReturnType(TSampler& sampler, const TType& retType, const TSourceLoc& loc); 213 214 // Obtain the sampler return type of the given sampler in retType. 215 void getTextureReturnType(const TSampler& sampler, TType& retType) const; 216 217 TAttributeType attributeFromName(const TString& nameSpace, const TString& name) const; 218 219 protected: 220 struct TFlattenData { TFlattenDataTFlattenData221 TFlattenData() : nextBinding(TQualifier::layoutBindingEnd), 222 nextLocation(TQualifier::layoutLocationEnd) { } TFlattenDataTFlattenData223 TFlattenData(int nb, int nl) : nextBinding(nb), nextLocation(nl) { } 224 225 TVector<TVariable*> members; // individual flattened variables 226 TVector<int> offsets; // offset to next tree level 227 unsigned int nextBinding; // next binding to use. 228 unsigned int nextLocation; // next location to use 229 }; 230 231 void fixConstInit(const TSourceLoc&, const TString& identifier, TType& type, TIntermTyped*& initializer); 232 void inheritGlobalDefaults(TQualifier& dst) const; 233 TVariable* makeInternalVariable(const char* name, const TType&) const; makeInternalVariable(const TString & name,const TType & type)234 TVariable* makeInternalVariable(const TString& name, const TType& type) const { 235 return makeInternalVariable(name.c_str(), type); 236 } 237 TIntermSymbol* makeInternalVariableNode(const TSourceLoc&, const char* name, const TType&) const; 238 TVariable* declareNonArray(const TSourceLoc&, const TString& identifier, const TType&, bool track); 239 void declareArray(const TSourceLoc&, const TString& identifier, const TType&, TSymbol*&, bool track); 240 TIntermNode* executeInitializer(const TSourceLoc&, TIntermTyped* initializer, TVariable* variable); 241 TIntermTyped* convertInitializerList(const TSourceLoc&, const TType&, TIntermTyped* initializer, TIntermTyped* scalarInit); 242 bool isScalarConstructor(const TIntermNode*); 243 TOperator mapAtomicOp(const TSourceLoc& loc, TOperator op, bool isImage); 244 245 // Return true if this node requires L-value conversion (e.g, to an imageStore). 246 bool shouldConvertLValue(const TIntermNode*) const; 247 248 // Array and struct flattening 249 TIntermTyped* flattenAccess(TIntermTyped* base, int member); 250 TIntermTyped* flattenAccess(int uniqueId, int member, TStorageQualifier outerStorage, const TType&, int subset = -1); 251 int findSubtreeOffset(const TIntermNode&) const; 252 int findSubtreeOffset(const TType&, int subset, const TVector<int>& offsets) const; 253 bool shouldFlatten(const TType&, TStorageQualifier, bool topLevel) const; 254 bool wasFlattened(const TIntermTyped* node) const; wasFlattened(int id)255 bool wasFlattened(int id) const { return flattenMap.find(id) != flattenMap.end(); } 256 int addFlattenedMember(const TVariable&, const TType&, TFlattenData&, const TString& name, bool linkage, 257 const TQualifier& outerQualifier, const TArraySizes* builtInArraySizes); 258 259 // Structure splitting (splits interstage built-in types into its own struct) 260 void split(const TVariable&); 261 void splitBuiltIn(const TString& baseName, const TType& memberType, const TArraySizes*, const TQualifier&); 262 const TType& split(const TType& type, const TString& name, const TQualifier&); 263 bool wasSplit(const TIntermTyped* node) const; wasSplit(int id)264 bool wasSplit(int id) const { return splitNonIoVars.find(id) != splitNonIoVars.end(); } 265 TVariable* getSplitNonIoVar(int id) const; 266 void addPatchConstantInvocation(); 267 void fixTextureShadowModes(); 268 void finalizeAppendMethods(); 269 TIntermTyped* makeIntegerIndex(TIntermTyped*); 270 271 void fixBuiltInIoType(TType&); 272 273 void flatten(const TVariable& variable, bool linkage); 274 int flatten(const TVariable& variable, const TType&, TFlattenData&, TString name, bool linkage, 275 const TQualifier& outerQualifier, const TArraySizes* builtInArraySizes); 276 int flattenStruct(const TVariable& variable, const TType&, TFlattenData&, TString name, bool linkage, 277 const TQualifier& outerQualifier, const TArraySizes* builtInArraySizes); 278 int flattenArray(const TVariable& variable, const TType&, TFlattenData&, TString name, bool linkage, 279 const TQualifier& outerQualifier); 280 281 bool hasUniform(const TQualifier& qualifier) const; 282 void clearUniform(TQualifier& qualifier); 283 bool isInputBuiltIn(const TQualifier& qualifier) const; 284 bool hasInput(const TQualifier& qualifier) const; 285 void correctOutput(TQualifier& qualifier); 286 bool isOutputBuiltIn(const TQualifier& qualifier) const; 287 bool hasOutput(const TQualifier& qualifier) const; 288 void correctInput(TQualifier& qualifier); 289 void correctUniform(TQualifier& qualifier); 290 void clearUniformInputOutput(TQualifier& qualifier); 291 292 // Test method names 293 bool isStructBufferMethod(const TString& name) const; 294 void counterBufferType(const TSourceLoc& loc, TType& type); 295 296 // Return standard sample position array 297 TIntermConstantUnion* getSamplePosArray(int count); 298 299 TType* getStructBufferContentType(const TType& type) const; isStructBufferType(const TType & type)300 bool isStructBufferType(const TType& type) const { return getStructBufferContentType(type) != nullptr; } 301 TIntermTyped* indexStructBufferContent(const TSourceLoc& loc, TIntermTyped* buffer) const; 302 TIntermTyped* getStructBufferCounter(const TSourceLoc& loc, TIntermTyped* buffer); 303 TString getStructBuffCounterName(const TString&) const; 304 void addStructBuffArguments(const TSourceLoc& loc, TIntermAggregate*&); 305 void addStructBufferHiddenCounterParam(const TSourceLoc& loc, TParameter&, TIntermAggregate*&); 306 307 // Return true if this type is a reference. This is not currently a type method in case that's 308 // a language specific answer. isReference(const TType & type)309 bool isReference(const TType& type) const { return isStructBufferType(type); } 310 311 // Return true if this a buffer type that has an associated counter buffer. 312 bool hasStructBuffCounter(const TType&) const; 313 314 // Finalization step: remove unused buffer blocks from linkage (we don't know until the 315 // shader is entirely compiled) 316 void removeUnusedStructBufferCounters(); 317 318 static bool isClipOrCullDistance(TBuiltInVariable); isClipOrCullDistance(const TQualifier & qual)319 static bool isClipOrCullDistance(const TQualifier& qual) { return isClipOrCullDistance(qual.builtIn); } isClipOrCullDistance(const TType & type)320 static bool isClipOrCullDistance(const TType& type) { return isClipOrCullDistance(type.getQualifier()); } 321 322 // Find the patch constant function (issues error, returns nullptr if not found) 323 const TFunction* findPatchConstantFunction(const TSourceLoc& loc); 324 325 // Pass through to base class after remembering built-in mappings. 326 using TParseContextBase::trackLinkage; 327 void trackLinkage(TSymbol& variable) override; 328 329 void finish() override; // post-processing 330 331 // Linkage symbol helpers 332 TIntermSymbol* findTessLinkageSymbol(TBuiltInVariable biType) const; 333 334 // Current state of parsing 335 int annotationNestingLevel; // 0 if outside all annotations 336 337 HlslParseContext(HlslParseContext&); 338 HlslParseContext& operator=(HlslParseContext&); 339 340 static const int maxSamplerIndex = EsdNumDims * (EbtNumTypes * (2 * 2 * 2)); // see computeSamplerTypeIndex() 341 TQualifier globalBufferDefaults; 342 TQualifier globalUniformDefaults; 343 TQualifier globalInputDefaults; 344 TQualifier globalOutputDefaults; 345 TString currentCaller; // name of last function body entered (not valid when at global scope) 346 TIdSetType inductiveLoopIds; 347 TVector<TIntermTyped*> needsIndexLimitationChecking; 348 349 // 350 // Geometry shader input arrays: 351 // - array sizing is based on input primitive and/or explicit size 352 // 353 // Tessellation control output arrays: 354 // - array sizing is based on output layout(vertices=...) and/or explicit size 355 // 356 // Both: 357 // - array sizing is retroactive 358 // - built-in block redeclarations interact with this 359 // 360 // Design: 361 // - use a per-context "resize-list", a list of symbols whose array sizes 362 // can be fixed 363 // 364 // - the resize-list starts empty at beginning of user-shader compilation, it does 365 // not have built-ins in it 366 // 367 // - on built-in array use: copyUp() symbol and add it to the resize-list 368 // 369 // - on user array declaration: add it to the resize-list 370 // 371 // - on block redeclaration: copyUp() symbol and add it to the resize-list 372 // * note, that appropriately gives an error if redeclaring a block that 373 // was already used and hence already copied-up 374 // 375 // - on seeing a layout declaration that sizes the array, fix everything in the 376 // resize-list, giving errors for mismatch 377 // 378 // - on seeing an array size declaration, give errors on mismatch between it and previous 379 // array-sizing declarations 380 // 381 TVector<TSymbol*> ioArraySymbolResizeList; 382 383 TMap<int, TFlattenData> flattenMap; 384 385 // IO-type map. Maps a pure symbol-table form of a structure-member list into 386 // each of the (up to) three kinds of IO, as each as different allowed decorations, 387 // but HLSL allows mixing all in the same structure. 388 struct tIoKinds { 389 TTypeList* input; 390 TTypeList* output; 391 TTypeList* uniform; 392 }; 393 TMap<const TTypeList*, tIoKinds> ioTypeMap; 394 395 // Structure splitting data: 396 TMap<int, TVariable*> splitNonIoVars; // variables with the built-in interstage IO removed, indexed by unique ID. 397 398 // Structuredbuffer shared types. Typically there are only a few. 399 TVector<TType*> structBufferTypes; 400 401 // This tracks texture sample user structure return types. Only a limited number are supported, as 402 // may fit in TSampler::structReturnIndex. 403 TVector<TTypeList*> textureReturnStruct; 404 405 TMap<TString, bool> structBufferCounter; // true if counter buffer is in use 406 407 // The built-in interstage IO map considers e.g, EvqPosition on input and output separately, so that we 408 // can build the linkage correctly if position appears on both sides. Otherwise, multiple positions 409 // are considered identical. 410 struct tInterstageIoData { tInterstageIoDatatInterstageIoData411 tInterstageIoData(TBuiltInVariable bi, TStorageQualifier q) : 412 builtIn(bi), storage(q) { } 413 414 TBuiltInVariable builtIn; 415 TStorageQualifier storage; 416 417 // ordering for maps 418 bool operator<(const tInterstageIoData d) const { 419 return (builtIn != d.builtIn) ? (builtIn < d.builtIn) : (storage < d.storage); 420 } 421 }; 422 423 TMap<tInterstageIoData, TVariable*> splitBuiltIns; // split built-ins, indexed by built-in type. 424 TVariable* inputPatch; // input patch is special for PCF: it's the only non-builtin PCF input, 425 // and is handled as a pseudo-builtin. 426 427 unsigned int nextInLocation; 428 unsigned int nextOutLocation; 429 430 TFunction* entryPointFunction; 431 TIntermNode* entryPointFunctionBody; 432 433 TString patchConstantFunctionName; // hull shader patch constant function name, from function level attribute. 434 TMap<TBuiltInVariable, TSymbol*> builtInTessLinkageSymbols; // used for tessellation, finding declared built-ins 435 436 TVector<TString> currentTypePrefix; // current scoping prefix for nested structures 437 TVector<TVariable*> implicitThisStack; // currently active 'this' variables for nested structures 438 439 TVariable* gsStreamOutput; // geometry shader stream outputs, for emit (Append method) 440 441 TVariable* clipDistanceOutput; // synthesized clip distance out variable (shader might have >1) 442 TVariable* cullDistanceOutput; // synthesized cull distance out variable (shader might have >1) 443 TVariable* clipDistanceInput; // synthesized clip distance in variable (shader might have >1) 444 TVariable* cullDistanceInput; // synthesized cull distance in variable (shader might have >1) 445 446 static const int maxClipCullRegs = 2; 447 std::array<int, maxClipCullRegs> clipSemanticNSizeIn; // vector, indexed by clip semantic ID 448 std::array<int, maxClipCullRegs> cullSemanticNSizeIn; // vector, indexed by cull semantic ID 449 std::array<int, maxClipCullRegs> clipSemanticNSizeOut; // vector, indexed by clip semantic ID 450 std::array<int, maxClipCullRegs> cullSemanticNSizeOut; // vector, indexed by cull semantic ID 451 452 // This tracks the first (mip level) argument to the .mips[][] operator. Since this can be nested as 453 // in tx.mips[tx.mips[0][1].x][2], we need a stack. We also track the TSourceLoc for error reporting 454 // purposes. 455 struct tMipsOperatorData { tMipsOperatorDatatMipsOperatorData456 tMipsOperatorData(TSourceLoc l, TIntermTyped* m) : loc(l), mipLevel(m) { } 457 TSourceLoc loc; 458 TIntermTyped* mipLevel; 459 }; 460 461 TVector<tMipsOperatorData> mipsOperatorMipArg; 462 463 // The geometry output stream is not copied out from the entry point as a typical output variable 464 // is. It's written via EmitVertex (hlsl=Append), which may happen in arbitrary control flow. 465 // For this we need the real output symbol. Since it may not be known at the time and Append() 466 // method is parsed, the sequence will be patched during finalization. 467 struct tGsAppendData { 468 TIntermAggregate* node; 469 TSourceLoc loc; 470 }; 471 472 TVector<tGsAppendData> gsAppends; 473 474 // A texture object may be used with shadow and non-shadow samplers, but both may not be 475 // alive post-DCE in the same shader. We do not know at compilation time which are alive: that's 476 // only known post-DCE. If a texture is used both ways, we create two textures, and 477 // leave the elimiation of one to the optimizer. This maps the shader variant to 478 // the shadow variant. 479 // 480 // This can be removed if and when the texture shadow code in 481 // HlslParseContext::handleSamplerTextureCombine is removed. 482 struct tShadowTextureSymbols { tShadowTextureSymbolstShadowTextureSymbols483 tShadowTextureSymbols() { symId.fill(-1); } 484 settShadowTextureSymbols485 void set(bool shadow, int id) { symId[int(shadow)] = id; } gettShadowTextureSymbols486 int get(bool shadow) const { return symId[int(shadow)]; } 487 488 // True if this texture has been seen with both shadow and non-shadow modes overloadedtShadowTextureSymbols489 bool overloaded() const { return symId[0] != -1 && symId[1] != -1; } isShadowIdtShadowTextureSymbols490 bool isShadowId(int id) const { return symId[1] == id; } 491 492 private: 493 std::array<int, 2> symId; 494 }; 495 496 TMap<int, tShadowTextureSymbols*> textureShadowVariant; 497 }; 498 499 // This is the prefix we use for built-in methods to avoid namespace collisions with 500 // global scope user functions. 501 // TODO: this would be better as a nonparseable character, but that would 502 // require changing the scanner. 503 #define BUILTIN_PREFIX "__BI_" 504 505 } // end namespace glslang 506 507 #endif // HLSL_PARSE_INCLUDED_ 508