John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 1 | // |
John Kessenich | 927608b | 2017-01-06 12:34:14 -0700 | [diff] [blame] | 2 | // Copyright (C) 2016 Google, Inc. |
| 3 | // Copyright (C) 2016 LunarG, Inc. |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 4 | // |
John Kessenich | 927608b | 2017-01-06 12:34:14 -0700 | [diff] [blame] | 5 | // All rights reserved. |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 6 | // |
John Kessenich | 927608b | 2017-01-06 12:34:14 -0700 | [diff] [blame] | 7 | // Redistribution and use in source and binary forms, with or without |
| 8 | // modification, are permitted provided that the following conditions |
| 9 | // are met: |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 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 | // |
John Kessenich | 927608b | 2017-01-06 12:34:14 -0700 | [diff] [blame] | 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. |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 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 | |
| 42 | namespace glslang { |
| 43 | |
steve-lunarg | 1868b14 | 2016-10-20 13:07:10 -0600 | [diff] [blame] | 44 | class TAttributeMap; // forward declare |
| 45 | |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 46 | class HlslParseContext : public TParseContextBase { |
| 47 | public: |
| 48 | HlslParseContext(TSymbolTable&, TIntermediate&, bool parsingBuiltins, |
John Kessenich | b901ade | 2016-06-16 20:59:42 -0600 | [diff] [blame] | 49 | int version, EProfile, const SpvVersion& spvVersion, EShLanguage, TInfoSink&, |
steve-lunarg | f1e0c87 | 2016-10-31 15:13:43 -0600 | [diff] [blame] | 50 | const TString sourceEntryPointName, |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 51 | bool forwardCompatible = false, EShMessages messages = EShMsgDefault); |
| 52 | virtual ~HlslParseContext(); |
Henrik Rydgård | 9a931b3 | 2016-12-21 12:48:08 +0100 | [diff] [blame] | 53 | void initializeExtensionBehavior() override; |
LoopDawg | 6256146 | 2016-07-22 20:46:03 -0600 | [diff] [blame] | 54 | |
Henrik Rydgård | 9a931b3 | 2016-12-21 12:48:08 +0100 | [diff] [blame] | 55 | void setLimits(const TBuiltInResource&) override; |
| 56 | bool parseShaderStrings(TPpContext&, TInputScanner& input, bool versionWillBeError = false) override; |
| 57 | virtual const char* getGlobalUniformBlockName() override { return "$Global"; } |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 58 | |
Henrik Rydgård | 9a931b3 | 2016-12-21 12:48:08 +0100 | [diff] [blame] | 59 | void reservedPpErrorCheck(const TSourceLoc&, const char* /*name*/, const char* /*op*/) override { } |
| 60 | bool lineContinuationCheck(const TSourceLoc&, bool /*endOfComment*/) override { return true; } |
| 61 | bool lineDirectiveShouldSetNextLine() const override { return true; } |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 62 | bool builtInName(const TString&); |
| 63 | |
Henrik Rydgård | 9a931b3 | 2016-12-21 12:48:08 +0100 | [diff] [blame] | 64 | void handlePragma(const TSourceLoc&, const TVector<TString>&) override; |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 65 | TIntermTyped* handleVariable(const TSourceLoc&, TSymbol* symbol, const TString* string); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 66 | TIntermTyped* handleBracketDereference(const TSourceLoc&, TIntermTyped* base, TIntermTyped* index); |
steve-lunarg | 6b43d27 | 2016-10-06 20:12:24 -0600 | [diff] [blame] | 67 | TIntermTyped* handleBracketOperator(const TSourceLoc&, TIntermTyped* base, TIntermTyped* index); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 68 | void checkIndex(const TSourceLoc&, const TType&, int& index); |
| 69 | |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 70 | TIntermTyped* handleBinaryMath(const TSourceLoc&, const char* str, TOperator op, TIntermTyped* left, TIntermTyped* right); |
| 71 | TIntermTyped* handleUnaryMath(const TSourceLoc&, const char* str, TOperator op, TIntermTyped* childNode); |
| 72 | TIntermTyped* handleDotDereference(const TSourceLoc&, TIntermTyped* base, const TString& field); |
John Kessenich | 7dc630f | 2016-09-16 01:44:43 -0600 | [diff] [blame] | 73 | void assignLocations(TVariable& variable); |
John Kessenich | a305166 | 2016-09-02 19:13:36 -0600 | [diff] [blame] | 74 | TFunction& handleFunctionDeclarator(const TSourceLoc&, TFunction& function, bool prototype); |
John Kessenich | 02467d8 | 2017-01-19 15:41:47 -0700 | [diff] [blame] | 75 | TIntermAggregate* handleFunctionDefinition(const TSourceLoc&, TFunction&, const TAttributeMap&, TIntermNode*& entryPointTree); |
| 76 | TIntermNode* transformEntryPoint(const TSourceLoc&, TFunction&, const TAttributeMap&); |
John Kessenich | a305166 | 2016-09-02 19:13:36 -0600 | [diff] [blame] | 77 | void handleFunctionBody(const TSourceLoc&, TFunction&, TIntermNode* functionBody, TIntermNode*& node); |
John Kessenich | 727b374 | 2017-02-03 17:57:55 -0700 | [diff] [blame^] | 78 | void remapEntryPointIO(TFunction& function, TVariable*& returnValue, TVector<TVariable*>& inputs, TVector<TVariable*>& outputs); |
John Kessenich | 6fccb3c | 2016-09-19 16:01:41 -0600 | [diff] [blame] | 79 | void remapNonEntryPointIO(TFunction& function); |
steve-lunarg | c4a1307 | 2016-08-09 11:28:03 -0600 | [diff] [blame] | 80 | TIntermNode* handleReturnValue(const TSourceLoc&, TIntermTyped*); |
John Kessenich | 4678ca9 | 2016-05-13 09:33:42 -0600 | [diff] [blame] | 81 | void handleFunctionArgument(TFunction*, TIntermTyped*& arguments, TIntermTyped* newArg); |
John Kessenich | fdf6347 | 2017-01-13 12:27:52 -0700 | [diff] [blame] | 82 | TIntermTyped* handleAssign(const TSourceLoc&, TOperator, TIntermTyped* left, TIntermTyped* right); |
| 83 | TIntermTyped* handleAssignToMatrixSwizzle(const TSourceLoc&, TOperator, TIntermTyped* left, TIntermTyped* right); |
steve-lunarg | 26d3145 | 2016-12-23 18:56:57 -0700 | [diff] [blame] | 84 | TIntermTyped* handleFunctionCall(const TSourceLoc&, TFunction*, TIntermTyped*); |
LoopDawg | 592860c | 2016-06-09 08:57:35 -0600 | [diff] [blame] | 85 | void decomposeIntrinsic(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments); |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 86 | void decomposeSampleMethods(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments); |
steve-lunarg | f49cdf4 | 2016-11-17 15:04:20 -0700 | [diff] [blame] | 87 | void decomposeGeometryMethods(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 88 | TIntermTyped* handleLengthMethod(const TSourceLoc&, TFunction*, TIntermNode*); |
steve-lunarg | 26d3145 | 2016-12-23 18:56:57 -0700 | [diff] [blame] | 89 | void addInputArgumentConversions(const TFunction&, TIntermTyped*&); |
steve-lunarg | ef33ec0 | 2016-11-02 12:42:34 -0600 | [diff] [blame] | 90 | TIntermTyped* addOutputArgumentConversions(const TFunction&, TIntermOperator&); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 91 | void builtInOpCheck(const TSourceLoc&, const TFunction&, TIntermOperator&); |
John Kessenich | d016be1 | 2016-03-13 11:24:20 -0600 | [diff] [blame] | 92 | TFunction* handleConstructorCall(const TSourceLoc&, const TType&); |
John Kessenich | 7735b94 | 2016-09-05 12:40:06 -0600 | [diff] [blame] | 93 | void handleSemantic(TSourceLoc, TQualifier&, const TString& semantic); |
| 94 | void handlePackOffset(const TSourceLoc&, TQualifier&, const glslang::TString& location, |
John Kessenich | b38f071 | 2016-07-30 10:29:54 -0600 | [diff] [blame] | 95 | const glslang::TString* component); |
John Kessenich | 7735b94 | 2016-09-05 12:40:06 -0600 | [diff] [blame] | 96 | void handleRegister(const TSourceLoc&, TQualifier&, const glslang::TString* profile, const glslang::TString& desc, |
John Kessenich | cfd7ce8 | 2016-09-05 16:03:12 -0600 | [diff] [blame] | 97 | int subComponent, const glslang::TString*); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 98 | |
LoopDawg | a2b7991 | 2016-07-14 14:45:14 -0600 | [diff] [blame] | 99 | TIntermAggregate* handleSamplerTextureCombine(const TSourceLoc& loc, TIntermTyped* argTex, TIntermTyped* argSampler); |
| 100 | |
John Kessenich | c142c88 | 2017-01-13 19:34:22 -0700 | [diff] [blame] | 101 | bool parseMatrixSwizzleSelector(const TSourceLoc&, const TString&, int cols, int rows, TSwizzleSelectors<TMatrixSelector>&); |
| 102 | int getMatrixComponentsColumn(int rows, const TSwizzleSelectors<TMatrixSelector>&); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 103 | void assignError(const TSourceLoc&, const char* op, TString left, TString right); |
| 104 | void unaryOpError(const TSourceLoc&, const char* op, TString operand); |
| 105 | void binaryOpError(const TSourceLoc&, const char* op, TString left, TString right); |
| 106 | void variableCheck(TIntermTyped*& nodePtr); |
| 107 | void constantValueCheck(TIntermTyped* node, const char* token); |
| 108 | void integerCheck(const TIntermTyped* node, const char* token); |
| 109 | void globalCheck(const TSourceLoc&, const char* token); |
| 110 | bool constructorError(const TSourceLoc&, TIntermNode*, TFunction&, TOperator, TType&); |
| 111 | bool constructorTextureSamplerError(const TSourceLoc&, const TFunction&); |
| 112 | void arraySizeCheck(const TSourceLoc&, TIntermTyped* expr, TArraySize&); |
| 113 | void arraySizeRequiredCheck(const TSourceLoc&, const TArraySizes&); |
| 114 | void structArrayCheck(const TSourceLoc&, const TType& structure); |
| 115 | void arrayDimMerge(TType& type, const TArraySizes* sizes); |
| 116 | bool voidErrorCheck(const TSourceLoc&, const TString&, TBasicType); |
| 117 | void boolCheck(const TSourceLoc&, const TIntermTyped*); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 118 | void globalQualifierFix(const TSourceLoc&, TQualifier&); |
| 119 | bool structQualifierErrorCheck(const TSourceLoc&, const TPublicType& pType); |
John Kessenich | 34e7ee7 | 2016-09-16 17:10:39 -0600 | [diff] [blame] | 120 | void mergeQualifiers(TQualifier& dst, const TQualifier& src); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 121 | int computeSamplerTypeIndex(TSampler&); |
John Kessenich | d3f1122 | 2016-11-05 10:15:53 -0600 | [diff] [blame] | 122 | TSymbol* redeclareBuiltinVariable(const TSourceLoc&, const TString&, const TQualifier&, const TShaderQualifiers&); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 123 | void redeclareBuiltinBlock(const TSourceLoc&, TTypeList& typeList, const TString& blockName, const TString* instanceName, TArraySizes* arraySizes); |
John Kessenich | 5aa59e2 | 2016-06-17 15:50:47 -0600 | [diff] [blame] | 124 | void paramFix(TType& type); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 125 | void specializationCheck(const TSourceLoc&, const TType&, const char* op); |
| 126 | |
John Kessenich | b9e3912 | 2016-08-17 10:22:08 -0600 | [diff] [blame] | 127 | void setLayoutQualifier(const TSourceLoc&, TQualifier&, TString&); |
| 128 | void setLayoutQualifier(const TSourceLoc&, TQualifier&, TString&, const TIntermTyped*); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 129 | void mergeObjectLayoutQualifiers(TQualifier& dest, const TQualifier& src, bool inheritOnly); |
| 130 | void checkNoShaderLayouts(const TSourceLoc&, const TShaderQualifiers&); |
| 131 | |
steve-lunarg | 26d3145 | 2016-12-23 18:56:57 -0700 | [diff] [blame] | 132 | const TFunction* findFunction(const TSourceLoc& loc, TFunction& call, bool& builtIn, TIntermTyped*& args); |
John Kessenich | 5e69ec6 | 2016-07-05 00:02:40 -0600 | [diff] [blame] | 133 | void declareTypedef(const TSourceLoc&, TString& identifier, const TType&, TArraySizes* typeArray = 0); |
John Kessenich | 727b374 | 2017-02-03 17:57:55 -0700 | [diff] [blame^] | 134 | void declareStruct(const TSourceLoc&, TString& structName, TType&); |
John Kessenich | e82061d | 2016-09-27 14:38:57 -0600 | [diff] [blame] | 135 | TIntermNode* declareVariable(const TSourceLoc&, TString& identifier, TType&, TIntermTyped* initializer = 0); |
John Kessenich | 98ad485 | 2016-11-27 17:39:07 -0700 | [diff] [blame] | 136 | void lengthenList(const TSourceLoc&, TIntermSequence& list, int size); |
John Kessenich | a26a517 | 2016-07-28 15:29:35 -0600 | [diff] [blame] | 137 | TIntermTyped* addConstructor(const TSourceLoc&, TIntermNode*, const TType&); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 138 | TIntermTyped* constructAggregate(TIntermNode*, const TType&, int, const TSourceLoc&); |
| 139 | TIntermTyped* constructBuiltIn(const TType&, TOperator, TIntermTyped*, const TSourceLoc&, bool subset); |
John Kessenich | 3d157c5 | 2016-07-25 16:05:33 -0600 | [diff] [blame] | 140 | void declareBlock(const TSourceLoc&, TType&, const TString* instanceName = 0, TArraySizes* arraySizes = 0); |
Henrik Rydgård | 9a931b3 | 2016-12-21 12:48:08 +0100 | [diff] [blame] | 141 | void finalizeGlobalUniformBlockLayout(TVariable& block) override; |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 142 | void fixBlockLocations(const TSourceLoc&, TQualifier&, TTypeList&, bool memberWithLocation, bool memberWithoutLocation); |
| 143 | void fixBlockXfbOffsets(TQualifier&, TTypeList&); |
John Kessenich | 6dbc0a7 | 2016-09-27 19:13:05 -0600 | [diff] [blame] | 144 | void fixBlockUniformOffsets(const TQualifier&, TTypeList&); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 145 | void addQualifierToExisting(const TSourceLoc&, TQualifier, const TString& identifier); |
| 146 | void addQualifierToExisting(const TSourceLoc&, TQualifier, TIdentifierList&); |
| 147 | void updateStandaloneQualifierDefaults(const TSourceLoc&, const TPublicType&); |
| 148 | void wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode); |
| 149 | TIntermNode* addSwitch(const TSourceLoc&, TIntermTyped* expression, TIntermAggregate* body); |
| 150 | |
| 151 | void updateImplicitArraySize(const TSourceLoc&, TIntermNode*, int index); |
| 152 | |
John Kessenich | a1e2d49 | 2016-09-20 13:22:58 -0600 | [diff] [blame] | 153 | void nestLooping() { ++loopNestingLevel; } |
| 154 | void unnestLooping() { --loopNestingLevel; } |
| 155 | void nestAnnotations() { ++annotationNestingLevel; } |
| 156 | void unnestAnnotations() { --annotationNestingLevel; } |
John Kessenich | 6dbc0a7 | 2016-09-27 19:13:05 -0600 | [diff] [blame] | 157 | int getAnnotationNestingLevel() { return annotationNestingLevel; } |
John Kessenich | a1e2d49 | 2016-09-20 13:22:58 -0600 | [diff] [blame] | 158 | void pushScope() { symbolTable.push(); } |
| 159 | void popScope() { symbolTable.pop(0); } |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 160 | |
John Kessenich | d02dc5d | 2016-07-01 00:04:11 -0600 | [diff] [blame] | 161 | void pushSwitchSequence(TIntermSequence* sequence) { switchSequenceStack.push_back(sequence); } |
| 162 | void popSwitchSequence() { switchSequenceStack.pop_back(); } |
| 163 | |
John Kessenich | 88c4464 | 2017-02-03 14:06:36 -0700 | [diff] [blame] | 164 | virtual void growGlobalUniformBlock(TSourceLoc&, TType&, TString& memberName) override; |
| 165 | |
steve-lunarg | 9070796 | 2016-10-07 19:35:40 -0600 | [diff] [blame] | 166 | // Apply L-value conversions. E.g, turning a write to a RWTexture into an ImageStore. |
| 167 | TIntermTyped* handleLvalue(const TSourceLoc&, const char* op, TIntermTyped* node); |
steve-lunarg | 0de16da | 2016-10-08 10:54:52 -0600 | [diff] [blame] | 168 | bool lValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*) override; |
steve-lunarg | 9070796 | 2016-10-07 19:35:40 -0600 | [diff] [blame] | 169 | |
steve-lunarg | 4f2da27 | 2016-10-10 15:24:57 -0600 | [diff] [blame] | 170 | TLayoutFormat getLayoutFromTxType(const TSourceLoc&, const TType&); |
| 171 | |
steve-lunarg | f49cdf4 | 2016-11-17 15:04:20 -0700 | [diff] [blame] | 172 | bool handleOutputGeometry(const TSourceLoc&, const TLayoutGeometry& geometry); |
| 173 | bool handleInputGeometry(const TSourceLoc&, const TLayoutGeometry& geometry); |
| 174 | |
steve-lunarg | f1e0c87 | 2016-10-31 15:13:43 -0600 | [diff] [blame] | 175 | // Potentially rename shader entry point function |
| 176 | void renameShaderFunction(TString*& name) const; |
| 177 | |
steve-lunarg | a2b01a0 | 2016-11-28 17:09:54 -0700 | [diff] [blame] | 178 | // Reset data for incrementally built referencing of flattened composite structures |
| 179 | void initFlattening() { flattenLevel.push_back(0); flattenOffset.push_back(0); } |
| 180 | void finalizeFlattening() { flattenLevel.pop_back(); flattenOffset.pop_back(); } |
| 181 | |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 182 | protected: |
steve-lunarg | a2b01a0 | 2016-11-28 17:09:54 -0700 | [diff] [blame] | 183 | struct TFlattenData { |
| 184 | TFlattenData() : nextBinding(TQualifier::layoutBindingEnd) { } |
| 185 | TFlattenData(int nb) : nextBinding(nb) { } |
| 186 | |
| 187 | TVector<TVariable*> members; // individual flattened variables |
| 188 | TVector<int> offsets; // offset to next tree level |
| 189 | int nextBinding; // next binding to use. |
| 190 | }; |
| 191 | |
John Kessenich | aa6d562 | 2016-12-30 16:42:57 -0700 | [diff] [blame] | 192 | void fixConstInit(const TSourceLoc&, TString& identifier, TType& type, TIntermTyped*& initializer); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 193 | void inheritGlobalDefaults(TQualifier& dst) const; |
| 194 | TVariable* makeInternalVariable(const char* name, const TType&) const; |
steve-lunarg | a2e7531 | 2016-12-14 15:22:25 -0700 | [diff] [blame] | 195 | TVariable* makeInternalVariable(const TString& name, const TType& type) const { |
| 196 | return makeInternalVariable(name.c_str(), type); |
| 197 | } |
steve-lunarg | a2b01a0 | 2016-11-28 17:09:54 -0700 | [diff] [blame] | 198 | TVariable* declareNonArray(const TSourceLoc&, TString& identifier, TType&, bool track); |
John Kessenich | d3f1122 | 2016-11-05 10:15:53 -0600 | [diff] [blame] | 199 | void declareArray(const TSourceLoc&, TString& identifier, const TType&, TSymbol*&, bool track); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 200 | TIntermNode* executeInitializer(const TSourceLoc&, TIntermTyped* initializer, TVariable* variable); |
| 201 | TIntermTyped* convertInitializerList(const TSourceLoc&, const TType&, TIntermTyped* initializer); |
John Kessenich | 8ce6e2b | 2016-11-27 23:00:14 -0700 | [diff] [blame] | 202 | bool isZeroConstructor(const TIntermNode*); |
LoopDawg | 5891070 | 2016-06-13 09:22:28 -0600 | [diff] [blame] | 203 | TOperator mapAtomicOp(const TSourceLoc& loc, TOperator op, bool isImage); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 204 | |
steve-lunarg | 9070796 | 2016-10-07 19:35:40 -0600 | [diff] [blame] | 205 | // Return true if this node requires L-value conversion (e.g, to an imageStore). |
| 206 | bool shouldConvertLValue(const TIntermNode*) const; |
| 207 | |
steve-lunarg | e0b9deb | 2016-09-16 13:26:37 -0600 | [diff] [blame] | 208 | // Array and struct flattening |
steve-lunarg | a2e7531 | 2016-12-14 15:22:25 -0700 | [diff] [blame] | 209 | TIntermTyped* flattenAccess(TIntermTyped* base, int member); |
steve-lunarg | e0b9deb | 2016-09-16 13:26:37 -0600 | [diff] [blame] | 210 | bool shouldFlattenUniform(const TType&) const; |
steve-lunarg | a2b01a0 | 2016-11-28 17:09:54 -0700 | [diff] [blame] | 211 | bool wasFlattened(const TIntermTyped* node) const; |
| 212 | bool wasFlattened(int id) const { return flattenMap.find(id) != flattenMap.end(); } |
| 213 | int addFlattenedMember(const TSourceLoc& loc, const TVariable&, const TType&, TFlattenData&, const TString& name, bool track); |
| 214 | bool isFinalFlattening(const TType& type) const { return !(type.isStruct() || type.isArray()); } |
| 215 | |
steve-lunarg | a2e7531 | 2016-12-14 15:22:25 -0700 | [diff] [blame] | 216 | // Structure splitting (splits interstage builtin types into its own struct) |
steve-lunarg | 132d331 | 2016-12-19 15:48:01 -0700 | [diff] [blame] | 217 | TIntermTyped* splitAccessStruct(const TSourceLoc& loc, TIntermTyped*& base, int& member); |
| 218 | void splitAccessArray(const TSourceLoc& loc, TIntermTyped* base, TIntermTyped* index); |
| 219 | TType& split(TType& type, TString name, const TType* outerStructType = nullptr); |
steve-lunarg | a2e7531 | 2016-12-14 15:22:25 -0700 | [diff] [blame] | 220 | void split(TIntermTyped*); |
| 221 | void split(const TVariable&); |
| 222 | bool wasSplit(const TIntermTyped* node) const; |
| 223 | bool wasSplit(int id) const { return splitIoVars.find(id) != splitIoVars.end(); } |
| 224 | TVariable* getSplitIoVar(const TIntermTyped* node) const; |
| 225 | TVariable* getSplitIoVar(const TVariable* var) const; |
| 226 | TVariable* getSplitIoVar(int id) const; |
| 227 | void addInterstageIoToLinkage(); |
| 228 | |
steve-lunarg | e0b9deb | 2016-09-16 13:26:37 -0600 | [diff] [blame] | 229 | void flatten(const TSourceLoc& loc, const TVariable& variable); |
steve-lunarg | a2b01a0 | 2016-11-28 17:09:54 -0700 | [diff] [blame] | 230 | int flatten(const TSourceLoc& loc, const TVariable& variable, const TType&, TFlattenData&, TString name); |
| 231 | int flattenStruct(const TSourceLoc& loc, const TVariable& variable, const TType&, TFlattenData&, TString name); |
| 232 | int flattenArray(const TSourceLoc& loc, const TVariable& variable, const TType&, TFlattenData&, TString name); |
steve-lunarg | e0b9deb | 2016-09-16 13:26:37 -0600 | [diff] [blame] | 233 | |
Alex Szpakowski | 7d39ad5 | 2017-01-08 17:54:48 -0400 | [diff] [blame] | 234 | void finish() override; // post-processing |
steve-lunarg | a2e7531 | 2016-12-14 15:22:25 -0700 | [diff] [blame] | 235 | |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 236 | // Current state of parsing |
| 237 | struct TPragma contextPragma; |
| 238 | int loopNestingLevel; // 0 if outside all loops |
John Kessenich | a1e2d49 | 2016-09-20 13:22:58 -0600 | [diff] [blame] | 239 | int annotationNestingLevel; // 0 if outside all annotations |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 240 | int structNestingLevel; // 0 if outside blocks and structures |
| 241 | int controlFlowNestingLevel; // 0 if outside all flow control |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 242 | TList<TIntermSequence*> switchSequenceStack; // case, node, case, case, node, ...; ensure only one node between cases; stack of them for nesting |
John Kessenich | 517fe7a | 2016-11-26 13:31:47 -0700 | [diff] [blame] | 243 | bool postEntryPointReturn; // if inside a function, true if the function is the entry point and this is after a return statement |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 244 | const TType* currentFunctionType; // the return type of the function that's currently being parsed |
| 245 | bool functionReturnsValue; // true if a non-void function has a return |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 246 | TBuiltInResource resources; |
| 247 | TLimits& limits; |
| 248 | |
| 249 | HlslParseContext(HlslParseContext&); |
| 250 | HlslParseContext& operator=(HlslParseContext&); |
| 251 | |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 252 | static const int maxSamplerIndex = EsdNumDims * (EbtNumTypes * (2 * 2 * 2)); // see computeSamplerTypeIndex() |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 253 | TQualifier globalBufferDefaults; |
| 254 | TQualifier globalUniformDefaults; |
| 255 | TQualifier globalInputDefaults; |
| 256 | TQualifier globalOutputDefaults; |
| 257 | TString currentCaller; // name of last function body entered (not valid when at global scope) |
| 258 | TIdSetType inductiveLoopIds; |
| 259 | TVector<TIntermTyped*> needsIndexLimitationChecking; |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 260 | |
| 261 | // |
| 262 | // Geometry shader input arrays: |
| 263 | // - array sizing is based on input primitive and/or explicit size |
| 264 | // |
| 265 | // Tessellation control output arrays: |
| 266 | // - array sizing is based on output layout(vertices=...) and/or explicit size |
| 267 | // |
| 268 | // Both: |
| 269 | // - array sizing is retroactive |
| 270 | // - built-in block redeclarations interact with this |
| 271 | // |
| 272 | // Design: |
| 273 | // - use a per-context "resize-list", a list of symbols whose array sizes |
| 274 | // can be fixed |
| 275 | // |
| 276 | // - the resize-list starts empty at beginning of user-shader compilation, it does |
| 277 | // not have built-ins in it |
| 278 | // |
| 279 | // - on built-in array use: copyUp() symbol and add it to the resize-list |
| 280 | // |
| 281 | // - on user array declaration: add it to the resize-list |
| 282 | // |
| 283 | // - on block redeclaration: copyUp() symbol and add it to the resize-list |
| 284 | // * note, that appropriately gives an error if redeclaring a block that |
| 285 | // was already used and hence already copied-up |
| 286 | // |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 287 | // - on seeing a layout declaration that sizes the array, fix everything in the |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 288 | // resize-list, giving errors for mismatch |
| 289 | // |
| 290 | // - on seeing an array size declaration, give errors on mismatch between it and previous |
| 291 | // array-sizing declarations |
| 292 | // |
| 293 | TVector<TSymbol*> ioArraySymbolResizeList; |
John Kessenich | cd0a78a | 2016-09-09 16:32:09 -0600 | [diff] [blame] | 294 | |
steve-lunarg | a2b01a0 | 2016-11-28 17:09:54 -0700 | [diff] [blame] | 295 | TMap<int, TFlattenData> flattenMap; |
| 296 | TVector<int> flattenLevel; // nested postfix operator level for flattening |
| 297 | TVector<int> flattenOffset; // cumulative offset for flattening |
| 298 | |
John Kessenich | 727b374 | 2017-02-03 17:57:55 -0700 | [diff] [blame^] | 299 | // IO-type map. |
| 300 | TMap<const TTypeList*, TTypeList*> ioTypeMap; |
steve-lunarg | a2e7531 | 2016-12-14 15:22:25 -0700 | [diff] [blame] | 301 | |
| 302 | // Structure splitting data: |
steve-lunarg | 132d331 | 2016-12-19 15:48:01 -0700 | [diff] [blame] | 303 | TMap<int, TVariable*> splitIoVars; // variables with the builtin interstage IO removed, indexed by unique ID. |
| 304 | |
| 305 | // The builtin interstage IO map considers e.g, EvqPosition on input and output separately, so that we |
| 306 | // can build the linkage correctly if position appears on both sides. Otherwise, multiple positions |
| 307 | // are considered identical. |
| 308 | struct tInterstageIoData { |
| 309 | tInterstageIoData(const TType& memberType, const TType& storageType) : |
| 310 | builtIn(memberType.getQualifier().builtIn), |
| 311 | storage(storageType.getQualifier().storage) { } |
| 312 | |
| 313 | TBuiltInVariable builtIn; |
| 314 | TStorageQualifier storage; |
| 315 | |
| 316 | // ordering for maps |
| 317 | bool operator<(const tInterstageIoData d) const { |
| 318 | return (builtIn != d.builtIn) ? (builtIn < d.builtIn) : (storage < d.storage); |
| 319 | } |
| 320 | }; |
| 321 | |
| 322 | TMap<tInterstageIoData, TVariable*> interstageBuiltInIo; // individual builtin interstage IO vars, inxed by builtin type. |
| 323 | |
| 324 | // We have to move array references to structs containing builtin interstage IO to the split variables. |
| 325 | // This is only handled for one level. This stores the index, because we'll need it in the future, since |
| 326 | // unlike normal array references, here the index happens before we discover what it applies to. |
| 327 | TIntermTyped* builtInIoIndex; |
| 328 | TIntermTyped* builtInIoBase; |
steve-lunarg | a2e7531 | 2016-12-14 15:22:25 -0700 | [diff] [blame] | 329 | |
John Kessenich | 7dc630f | 2016-09-16 01:44:43 -0600 | [diff] [blame] | 330 | unsigned int nextInLocation; |
| 331 | unsigned int nextOutLocation; |
steve-lunarg | f1e0c87 | 2016-10-31 15:13:43 -0600 | [diff] [blame] | 332 | |
| 333 | TString sourceEntryPointName; |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 334 | }; |
| 335 | |
| 336 | } // end namespace glslang |
| 337 | |
| 338 | #endif // HLSL_PARSE_INCLUDED_ |