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