blob: de1bc9581aec13ae6d883f08b16a7bed7a109c74 [file] [log] [blame]
John Kesseniche01a9bc2016-03-12 20:11:22 -07001//
John Kessenich927608b2017-01-06 12:34:14 -07002// Copyright (C) 2016 Google, Inc.
3// Copyright (C) 2016 LunarG, Inc.
John Kesseniche01a9bc2016-03-12 20:11:22 -07004//
John Kessenich927608b2017-01-06 12:34:14 -07005// All rights reserved.
John Kesseniche01a9bc2016-03-12 20:11:22 -07006//
John Kessenich927608b2017-01-06 12:34:14 -07007// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions
9// are met:
John Kesseniche01a9bc2016-03-12 20:11:22 -070010//
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 Kessenich927608b2017-01-06 12:34:14 -070023// 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 Kesseniche01a9bc2016-03-12 20:11:22 -070035//
36#ifndef HLSL_PARSE_INCLUDED_
37#define HLSL_PARSE_INCLUDED_
38
39#include "../glslang/MachineIndependent/parseVersions.h"
40#include "../glslang/MachineIndependent/ParseHelper.h"
41
42namespace glslang {
43
steve-lunarg1868b142016-10-20 13:07:10 -060044class TAttributeMap; // forward declare
45
John Kesseniche01a9bc2016-03-12 20:11:22 -070046class HlslParseContext : public TParseContextBase {
47public:
48 HlslParseContext(TSymbolTable&, TIntermediate&, bool parsingBuiltins,
John Kessenichb901ade2016-06-16 20:59:42 -060049 int version, EProfile, const SpvVersion& spvVersion, EShLanguage, TInfoSink&,
steve-lunargf1e0c872016-10-31 15:13:43 -060050 const TString sourceEntryPointName,
John Kesseniche01a9bc2016-03-12 20:11:22 -070051 bool forwardCompatible = false, EShMessages messages = EShMsgDefault);
52 virtual ~HlslParseContext();
Henrik Rydgård9a931b32016-12-21 12:48:08 +010053 void initializeExtensionBehavior() override;
LoopDawg62561462016-07-22 20:46:03 -060054
Henrik Rydgård9a931b32016-12-21 12:48:08 +010055 void setLimits(const TBuiltInResource&) override;
56 bool parseShaderStrings(TPpContext&, TInputScanner& input, bool versionWillBeError = false) override;
57 virtual const char* getGlobalUniformBlockName() override { return "$Global"; }
John Kesseniche01a9bc2016-03-12 20:11:22 -070058
Henrik Rydgård9a931b32016-12-21 12:48:08 +010059 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 Kesseniche01a9bc2016-03-12 20:11:22 -070062 bool builtInName(const TString&);
63
Henrik Rydgård9a931b32016-12-21 12:48:08 +010064 void handlePragma(const TSourceLoc&, const TVector<TString>&) override;
John Kesseniche6e74942016-06-11 16:43:14 -060065 TIntermTyped* handleVariable(const TSourceLoc&, TSymbol* symbol, const TString* string);
John Kesseniche01a9bc2016-03-12 20:11:22 -070066 TIntermTyped* handleBracketDereference(const TSourceLoc&, TIntermTyped* base, TIntermTyped* index);
steve-lunarg6b43d272016-10-06 20:12:24 -060067 TIntermTyped* handleBracketOperator(const TSourceLoc&, TIntermTyped* base, TIntermTyped* index);
John Kesseniche01a9bc2016-03-12 20:11:22 -070068 void checkIndex(const TSourceLoc&, const TType&, int& index);
69
John Kesseniche01a9bc2016-03-12 20:11:22 -070070 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 Kessenich7dc630f2016-09-16 01:44:43 -060073 void assignLocations(TVariable& variable);
John Kessenicha3051662016-09-02 19:13:36 -060074 TFunction& handleFunctionDeclarator(const TSourceLoc&, TFunction& function, bool prototype);
John Kessenich02467d82017-01-19 15:41:47 -070075 TIntermAggregate* handleFunctionDefinition(const TSourceLoc&, TFunction&, const TAttributeMap&, TIntermNode*& entryPointTree);
76 TIntermNode* transformEntryPoint(const TSourceLoc&, TFunction&, const TAttributeMap&);
John Kessenicha3051662016-09-02 19:13:36 -060077 void handleFunctionBody(const TSourceLoc&, TFunction&, TIntermNode* functionBody, TIntermNode*& node);
John Kessenich727b3742017-02-03 17:57:55 -070078 void remapEntryPointIO(TFunction& function, TVariable*& returnValue, TVector<TVariable*>& inputs, TVector<TVariable*>& outputs);
John Kessenich6fccb3c2016-09-19 16:01:41 -060079 void remapNonEntryPointIO(TFunction& function);
steve-lunargc4a13072016-08-09 11:28:03 -060080 TIntermNode* handleReturnValue(const TSourceLoc&, TIntermTyped*);
John Kessenich4678ca92016-05-13 09:33:42 -060081 void handleFunctionArgument(TFunction*, TIntermTyped*& arguments, TIntermTyped* newArg);
John Kessenichfdf63472017-01-13 12:27:52 -070082 TIntermTyped* handleAssign(const TSourceLoc&, TOperator, TIntermTyped* left, TIntermTyped* right);
83 TIntermTyped* handleAssignToMatrixSwizzle(const TSourceLoc&, TOperator, TIntermTyped* left, TIntermTyped* right);
steve-lunarg26d31452016-12-23 18:56:57 -070084 TIntermTyped* handleFunctionCall(const TSourceLoc&, TFunction*, TIntermTyped*);
LoopDawg592860c2016-06-09 08:57:35 -060085 void decomposeIntrinsic(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
LoopDawg4886f692016-06-29 10:58:58 -060086 void decomposeSampleMethods(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
steve-lunarg5da1f032017-02-12 17:50:28 -070087 void decomposeStructBufferMethods(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
steve-lunargf49cdf42016-11-17 15:04:20 -070088 void decomposeGeometryMethods(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
John Kesseniche01a9bc2016-03-12 20:11:22 -070089 TIntermTyped* handleLengthMethod(const TSourceLoc&, TFunction*, TIntermNode*);
steve-lunarg26d31452016-12-23 18:56:57 -070090 void addInputArgumentConversions(const TFunction&, TIntermTyped*&);
steve-lunargef33ec02016-11-02 12:42:34 -060091 TIntermTyped* addOutputArgumentConversions(const TFunction&, TIntermOperator&);
John Kesseniche01a9bc2016-03-12 20:11:22 -070092 void builtInOpCheck(const TSourceLoc&, const TFunction&, TIntermOperator&);
John Kessenichd016be12016-03-13 11:24:20 -060093 TFunction* handleConstructorCall(const TSourceLoc&, const TType&);
John Kessenich7735b942016-09-05 12:40:06 -060094 void handleSemantic(TSourceLoc, TQualifier&, const TString& semantic);
95 void handlePackOffset(const TSourceLoc&, TQualifier&, const glslang::TString& location,
John Kessenichb38f0712016-07-30 10:29:54 -060096 const glslang::TString* component);
John Kessenich7735b942016-09-05 12:40:06 -060097 void handleRegister(const TSourceLoc&, TQualifier&, const glslang::TString* profile, const glslang::TString& desc,
John Kessenichcfd7ce82016-09-05 16:03:12 -060098 int subComponent, const glslang::TString*);
John Kesseniche01a9bc2016-03-12 20:11:22 -070099
LoopDawga2b79912016-07-14 14:45:14 -0600100 TIntermAggregate* handleSamplerTextureCombine(const TSourceLoc& loc, TIntermTyped* argTex, TIntermTyped* argSampler);
101
John Kessenichc142c882017-01-13 19:34:22 -0700102 bool parseMatrixSwizzleSelector(const TSourceLoc&, const TString&, int cols, int rows, TSwizzleSelectors<TMatrixSelector>&);
103 int getMatrixComponentsColumn(int rows, const TSwizzleSelectors<TMatrixSelector>&);
John Kesseniche01a9bc2016-03-12 20:11:22 -0700104 void assignError(const TSourceLoc&, const char* op, TString left, TString right);
105 void unaryOpError(const TSourceLoc&, const char* op, TString operand);
106 void binaryOpError(const TSourceLoc&, const char* op, TString left, TString right);
107 void variableCheck(TIntermTyped*& nodePtr);
108 void constantValueCheck(TIntermTyped* node, const char* token);
109 void integerCheck(const TIntermTyped* node, const char* token);
110 void globalCheck(const TSourceLoc&, const char* token);
111 bool constructorError(const TSourceLoc&, TIntermNode*, TFunction&, TOperator, TType&);
112 bool constructorTextureSamplerError(const TSourceLoc&, const TFunction&);
113 void arraySizeCheck(const TSourceLoc&, TIntermTyped* expr, TArraySize&);
114 void arraySizeRequiredCheck(const TSourceLoc&, const TArraySizes&);
115 void structArrayCheck(const TSourceLoc&, const TType& structure);
116 void arrayDimMerge(TType& type, const TArraySizes* sizes);
117 bool voidErrorCheck(const TSourceLoc&, const TString&, TBasicType);
118 void boolCheck(const TSourceLoc&, const TIntermTyped*);
John Kesseniche01a9bc2016-03-12 20:11:22 -0700119 void globalQualifierFix(const TSourceLoc&, TQualifier&);
120 bool structQualifierErrorCheck(const TSourceLoc&, const TPublicType& pType);
John Kessenich34e7ee72016-09-16 17:10:39 -0600121 void mergeQualifiers(TQualifier& dst, const TQualifier& src);
John Kesseniche01a9bc2016-03-12 20:11:22 -0700122 int computeSamplerTypeIndex(TSampler&);
John Kessenichd3f11222016-11-05 10:15:53 -0600123 TSymbol* redeclareBuiltinVariable(const TSourceLoc&, const TString&, const TQualifier&, const TShaderQualifiers&);
John Kesseniche01a9bc2016-03-12 20:11:22 -0700124 void redeclareBuiltinBlock(const TSourceLoc&, TTypeList& typeList, const TString& blockName, const TString* instanceName, TArraySizes* arraySizes);
John Kessenich5aa59e22016-06-17 15:50:47 -0600125 void paramFix(TType& type);
John Kesseniche01a9bc2016-03-12 20:11:22 -0700126 void specializationCheck(const TSourceLoc&, const TType&, const char* op);
127
John Kessenichb9e39122016-08-17 10:22:08 -0600128 void setLayoutQualifier(const TSourceLoc&, TQualifier&, TString&);
129 void setLayoutQualifier(const TSourceLoc&, TQualifier&, TString&, const TIntermTyped*);
John Kesseniche01a9bc2016-03-12 20:11:22 -0700130 void mergeObjectLayoutQualifiers(TQualifier& dest, const TQualifier& src, bool inheritOnly);
131 void checkNoShaderLayouts(const TSourceLoc&, const TShaderQualifiers&);
132
steve-lunarg26d31452016-12-23 18:56:57 -0700133 const TFunction* findFunction(const TSourceLoc& loc, TFunction& call, bool& builtIn, TIntermTyped*& args);
John Kessenichdd402602017-02-08 13:59:30 -0700134 void declareTypedef(const TSourceLoc&, TString& identifier, const TType&);
John Kessenich727b3742017-02-03 17:57:55 -0700135 void declareStruct(const TSourceLoc&, TString& structName, TType&);
John Kesseniche82061d2016-09-27 14:38:57 -0600136 TIntermNode* declareVariable(const TSourceLoc&, TString& identifier, TType&, TIntermTyped* initializer = 0);
John Kessenich98ad4852016-11-27 17:39:07 -0700137 void lengthenList(const TSourceLoc&, TIntermSequence& list, int size);
John Kessenicha26a5172016-07-28 15:29:35 -0600138 TIntermTyped* addConstructor(const TSourceLoc&, TIntermNode*, const TType&);
John Kesseniche01a9bc2016-03-12 20:11:22 -0700139 TIntermTyped* constructAggregate(TIntermNode*, const TType&, int, const TSourceLoc&);
140 TIntermTyped* constructBuiltIn(const TType&, TOperator, TIntermTyped*, const TSourceLoc&, bool subset);
John Kessenich3d157c52016-07-25 16:05:33 -0600141 void declareBlock(const TSourceLoc&, TType&, const TString* instanceName = 0, TArraySizes* arraySizes = 0);
Henrik Rydgård9a931b32016-12-21 12:48:08 +0100142 void finalizeGlobalUniformBlockLayout(TVariable& block) override;
John Kesseniche01a9bc2016-03-12 20:11:22 -0700143 void fixBlockLocations(const TSourceLoc&, TQualifier&, TTypeList&, bool memberWithLocation, bool memberWithoutLocation);
144 void fixBlockXfbOffsets(TQualifier&, TTypeList&);
John Kessenich6dbc0a72016-09-27 19:13:05 -0600145 void fixBlockUniformOffsets(const TQualifier&, TTypeList&);
John Kesseniche01a9bc2016-03-12 20:11:22 -0700146 void addQualifierToExisting(const TSourceLoc&, TQualifier, const TString& identifier);
147 void addQualifierToExisting(const TSourceLoc&, TQualifier, TIdentifierList&);
148 void updateStandaloneQualifierDefaults(const TSourceLoc&, const TPublicType&);
149 void wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode);
150 TIntermNode* addSwitch(const TSourceLoc&, TIntermTyped* expression, TIntermAggregate* body);
151
152 void updateImplicitArraySize(const TSourceLoc&, TIntermNode*, int index);
153
John Kessenicha1e2d492016-09-20 13:22:58 -0600154 void nestLooping() { ++loopNestingLevel; }
155 void unnestLooping() { --loopNestingLevel; }
156 void nestAnnotations() { ++annotationNestingLevel; }
157 void unnestAnnotations() { --annotationNestingLevel; }
John Kessenich6dbc0a72016-09-27 19:13:05 -0600158 int getAnnotationNestingLevel() { return annotationNestingLevel; }
John Kessenicha1e2d492016-09-20 13:22:58 -0600159 void pushScope() { symbolTable.push(); }
160 void popScope() { symbolTable.pop(0); }
John Kessenich0d2b6de2016-06-05 11:23:11 -0600161
John Kessenichd02dc5d2016-07-01 00:04:11 -0600162 void pushSwitchSequence(TIntermSequence* sequence) { switchSequenceStack.push_back(sequence); }
163 void popSwitchSequence() { switchSequenceStack.pop_back(); }
164
John Kessenich65ee2302017-02-06 18:44:52 -0700165 virtual void growGlobalUniformBlock(TSourceLoc&, TType&, TString& memberName, TTypeList* typeList = nullptr) override;
John Kessenich88c44642017-02-03 14:06:36 -0700166
steve-lunarg90707962016-10-07 19:35:40 -0600167 // Apply L-value conversions. E.g, turning a write to a RWTexture into an ImageStore.
168 TIntermTyped* handleLvalue(const TSourceLoc&, const char* op, TIntermTyped* node);
steve-lunarg0de16da2016-10-08 10:54:52 -0600169 bool lValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*) override;
steve-lunarg90707962016-10-07 19:35:40 -0600170
steve-lunarg4f2da272016-10-10 15:24:57 -0600171 TLayoutFormat getLayoutFromTxType(const TSourceLoc&, const TType&);
172
steve-lunargf49cdf42016-11-17 15:04:20 -0700173 bool handleOutputGeometry(const TSourceLoc&, const TLayoutGeometry& geometry);
174 bool handleInputGeometry(const TSourceLoc&, const TLayoutGeometry& geometry);
175
steve-lunargf1e0c872016-10-31 15:13:43 -0600176 // Potentially rename shader entry point function
177 void renameShaderFunction(TString*& name) const;
178
steve-lunarga2b01a02016-11-28 17:09:54 -0700179 // Reset data for incrementally built referencing of flattened composite structures
180 void initFlattening() { flattenLevel.push_back(0); flattenOffset.push_back(0); }
181 void finalizeFlattening() { flattenLevel.pop_back(); flattenOffset.pop_back(); }
182
John Kesseniche01a9bc2016-03-12 20:11:22 -0700183protected:
steve-lunarga2b01a02016-11-28 17:09:54 -0700184 struct TFlattenData {
185 TFlattenData() : nextBinding(TQualifier::layoutBindingEnd) { }
186 TFlattenData(int nb) : nextBinding(nb) { }
187
188 TVector<TVariable*> members; // individual flattened variables
189 TVector<int> offsets; // offset to next tree level
190 int nextBinding; // next binding to use.
191 };
192
John Kessenichaa6d5622016-12-30 16:42:57 -0700193 void fixConstInit(const TSourceLoc&, TString& identifier, TType& type, TIntermTyped*& initializer);
John Kesseniche01a9bc2016-03-12 20:11:22 -0700194 void inheritGlobalDefaults(TQualifier& dst) const;
195 TVariable* makeInternalVariable(const char* name, const TType&) const;
steve-lunarga2e75312016-12-14 15:22:25 -0700196 TVariable* makeInternalVariable(const TString& name, const TType& type) const {
197 return makeInternalVariable(name.c_str(), type);
198 }
steve-lunarga2b01a02016-11-28 17:09:54 -0700199 TVariable* declareNonArray(const TSourceLoc&, TString& identifier, TType&, bool track);
John Kessenichd3f11222016-11-05 10:15:53 -0600200 void declareArray(const TSourceLoc&, TString& identifier, const TType&, TSymbol*&, bool track);
John Kesseniche01a9bc2016-03-12 20:11:22 -0700201 TIntermNode* executeInitializer(const TSourceLoc&, TIntermTyped* initializer, TVariable* variable);
202 TIntermTyped* convertInitializerList(const TSourceLoc&, const TType&, TIntermTyped* initializer);
John Kessenich8ce6e2b2016-11-27 23:00:14 -0700203 bool isZeroConstructor(const TIntermNode*);
LoopDawg58910702016-06-13 09:22:28 -0600204 TOperator mapAtomicOp(const TSourceLoc& loc, TOperator op, bool isImage);
John Kesseniche01a9bc2016-03-12 20:11:22 -0700205
steve-lunarg90707962016-10-07 19:35:40 -0600206 // Return true if this node requires L-value conversion (e.g, to an imageStore).
207 bool shouldConvertLValue(const TIntermNode*) const;
208
steve-lunarge0b9deb2016-09-16 13:26:37 -0600209 // Array and struct flattening
steve-lunarga2e75312016-12-14 15:22:25 -0700210 TIntermTyped* flattenAccess(TIntermTyped* base, int member);
steve-lunarge0b9deb2016-09-16 13:26:37 -0600211 bool shouldFlattenUniform(const TType&) const;
steve-lunarga2b01a02016-11-28 17:09:54 -0700212 bool wasFlattened(const TIntermTyped* node) const;
213 bool wasFlattened(int id) const { return flattenMap.find(id) != flattenMap.end(); }
214 int addFlattenedMember(const TSourceLoc& loc, const TVariable&, const TType&, TFlattenData&, const TString& name, bool track);
215 bool isFinalFlattening(const TType& type) const { return !(type.isStruct() || type.isArray()); }
216
steve-lunarga2e75312016-12-14 15:22:25 -0700217 // Structure splitting (splits interstage builtin types into its own struct)
steve-lunarg132d3312016-12-19 15:48:01 -0700218 TIntermTyped* splitAccessStruct(const TSourceLoc& loc, TIntermTyped*& base, int& member);
219 void splitAccessArray(const TSourceLoc& loc, TIntermTyped* base, TIntermTyped* index);
220 TType& split(TType& type, TString name, const TType* outerStructType = nullptr);
steve-lunarga2e75312016-12-14 15:22:25 -0700221 void split(TIntermTyped*);
222 void split(const TVariable&);
223 bool wasSplit(const TIntermTyped* node) const;
224 bool wasSplit(int id) const { return splitIoVars.find(id) != splitIoVars.end(); }
225 TVariable* getSplitIoVar(const TIntermTyped* node) const;
226 TVariable* getSplitIoVar(const TVariable* var) const;
227 TVariable* getSplitIoVar(int id) const;
228 void addInterstageIoToLinkage();
steve-lunarg858c9282017-01-07 08:54:10 -0700229 void addPatchConstantInvocation();
steve-lunarga2e75312016-12-14 15:22:25 -0700230
steve-lunarge0b9deb2016-09-16 13:26:37 -0600231 void flatten(const TSourceLoc& loc, const TVariable& variable);
steve-lunarga2b01a02016-11-28 17:09:54 -0700232 int flatten(const TSourceLoc& loc, const TVariable& variable, const TType&, TFlattenData&, TString name);
233 int flattenStruct(const TSourceLoc& loc, const TVariable& variable, const TType&, TFlattenData&, TString name);
234 int flattenArray(const TSourceLoc& loc, const TVariable& variable, const TType&, TFlattenData&, TString name);
steve-lunarge0b9deb2016-09-16 13:26:37 -0600235
John Kessenichbf472862017-02-05 20:27:30 -0700236 bool hasUniform(const TQualifier& qualifier) const;
237 void clearUniform(TQualifier& qualifier);
238 bool isInputBuiltIn(const TQualifier& qualifier) const;
239 bool hasInput(const TQualifier& qualifier) const;
240 void correctOutput(TQualifier& qualifier);
241 bool isOutputBuiltIn(const TQualifier& qualifier) const;
242 bool hasOutput(const TQualifier& qualifier) const;
243 void correctInput(TQualifier& qualifier);
244 void correctUniform(TQualifier& qualifier);
245 void clearUniformInputOutput(TQualifier& qualifier);
246
steve-lunarg5da1f032017-02-12 17:50:28 -0700247 // Test method names
248 bool isSamplerMethod(const TString& name) const;
249 bool isStructBufferMethod(const TString& name) const;
250
steve-lunarg858c9282017-01-07 08:54:10 -0700251 // Pass through to base class after remembering builtin mappings.
252 using TParseContextBase::trackLinkage;
253 void trackLinkage(TSymbol& variable) override;
254
Alex Szpakowski7d39ad52017-01-08 17:54:48 -0400255 void finish() override; // post-processing
steve-lunarga2e75312016-12-14 15:22:25 -0700256
John Kesseniche01a9bc2016-03-12 20:11:22 -0700257 // Current state of parsing
258 struct TPragma contextPragma;
259 int loopNestingLevel; // 0 if outside all loops
John Kessenicha1e2d492016-09-20 13:22:58 -0600260 int annotationNestingLevel; // 0 if outside all annotations
John Kesseniche01a9bc2016-03-12 20:11:22 -0700261 int structNestingLevel; // 0 if outside blocks and structures
262 int controlFlowNestingLevel; // 0 if outside all flow control
John Kesseniche01a9bc2016-03-12 20:11:22 -0700263 TList<TIntermSequence*> switchSequenceStack; // case, node, case, case, node, ...; ensure only one node between cases; stack of them for nesting
John Kessenich517fe7a2016-11-26 13:31:47 -0700264 bool postEntryPointReturn; // if inside a function, true if the function is the entry point and this is after a return statement
John Kesseniche01a9bc2016-03-12 20:11:22 -0700265 const TType* currentFunctionType; // the return type of the function that's currently being parsed
266 bool functionReturnsValue; // true if a non-void function has a return
John Kesseniche01a9bc2016-03-12 20:11:22 -0700267 TBuiltInResource resources;
268 TLimits& limits;
269
270 HlslParseContext(HlslParseContext&);
271 HlslParseContext& operator=(HlslParseContext&);
272
John Kesseniche01a9bc2016-03-12 20:11:22 -0700273 static const int maxSamplerIndex = EsdNumDims * (EbtNumTypes * (2 * 2 * 2)); // see computeSamplerTypeIndex()
John Kesseniche01a9bc2016-03-12 20:11:22 -0700274 TQualifier globalBufferDefaults;
275 TQualifier globalUniformDefaults;
276 TQualifier globalInputDefaults;
277 TQualifier globalOutputDefaults;
278 TString currentCaller; // name of last function body entered (not valid when at global scope)
279 TIdSetType inductiveLoopIds;
280 TVector<TIntermTyped*> needsIndexLimitationChecking;
John Kesseniche01a9bc2016-03-12 20:11:22 -0700281
282 //
283 // Geometry shader input arrays:
284 // - array sizing is based on input primitive and/or explicit size
285 //
286 // Tessellation control output arrays:
287 // - array sizing is based on output layout(vertices=...) and/or explicit size
288 //
289 // Both:
290 // - array sizing is retroactive
291 // - built-in block redeclarations interact with this
292 //
293 // Design:
294 // - use a per-context "resize-list", a list of symbols whose array sizes
295 // can be fixed
296 //
297 // - the resize-list starts empty at beginning of user-shader compilation, it does
298 // not have built-ins in it
299 //
300 // - on built-in array use: copyUp() symbol and add it to the resize-list
301 //
302 // - on user array declaration: add it to the resize-list
303 //
304 // - on block redeclaration: copyUp() symbol and add it to the resize-list
305 // * note, that appropriately gives an error if redeclaring a block that
306 // was already used and hence already copied-up
307 //
John Kessenichecba76f2017-01-06 00:34:48 -0700308 // - on seeing a layout declaration that sizes the array, fix everything in the
John Kesseniche01a9bc2016-03-12 20:11:22 -0700309 // resize-list, giving errors for mismatch
310 //
311 // - on seeing an array size declaration, give errors on mismatch between it and previous
312 // array-sizing declarations
313 //
314 TVector<TSymbol*> ioArraySymbolResizeList;
John Kessenichcd0a78a2016-09-09 16:32:09 -0600315
steve-lunarga2b01a02016-11-28 17:09:54 -0700316 TMap<int, TFlattenData> flattenMap;
317 TVector<int> flattenLevel; // nested postfix operator level for flattening
318 TVector<int> flattenOffset; // cumulative offset for flattening
319
John Kessenichbf472862017-02-05 20:27:30 -0700320 // IO-type map. Maps a pure symbol-table form of a structure-member list into
321 // each of the (up to) three kinds of IO, as each as different allowed decorations,
322 // but HLSL allows mixing all in the same structure.
323 struct tIoKinds {
324 TTypeList* input;
325 TTypeList* output;
326 TTypeList* uniform;
327 };
328 TMap<const TTypeList*, tIoKinds> ioTypeMap;
steve-lunarga2e75312016-12-14 15:22:25 -0700329
330 // Structure splitting data:
steve-lunarg132d3312016-12-19 15:48:01 -0700331 TMap<int, TVariable*> splitIoVars; // variables with the builtin interstage IO removed, indexed by unique ID.
332
333 // The builtin interstage IO map considers e.g, EvqPosition on input and output separately, so that we
334 // can build the linkage correctly if position appears on both sides. Otherwise, multiple positions
335 // are considered identical.
336 struct tInterstageIoData {
steve-lunarg858c9282017-01-07 08:54:10 -0700337 tInterstageIoData(TBuiltInVariable bi, TStorageQualifier q) :
338 builtIn(bi), storage(q) { }
339
steve-lunarg132d3312016-12-19 15:48:01 -0700340 tInterstageIoData(const TType& memberType, const TType& storageType) :
341 builtIn(memberType.getQualifier().builtIn),
342 storage(storageType.getQualifier().storage) { }
343
344 TBuiltInVariable builtIn;
345 TStorageQualifier storage;
346
347 // ordering for maps
348 bool operator<(const tInterstageIoData d) const {
349 return (builtIn != d.builtIn) ? (builtIn < d.builtIn) : (storage < d.storage);
350 }
351 };
352
John Kessenichbf472862017-02-05 20:27:30 -0700353 TMap<tInterstageIoData, TVariable*> interstageBuiltInIo; // individual builtin interstage IO vars, indexed by builtin type.
steve-lunarg132d3312016-12-19 15:48:01 -0700354
355 // We have to move array references to structs containing builtin interstage IO to the split variables.
356 // This is only handled for one level. This stores the index, because we'll need it in the future, since
357 // unlike normal array references, here the index happens before we discover what it applies to.
358 TIntermTyped* builtInIoIndex;
359 TIntermTyped* builtInIoBase;
steve-lunarga2e75312016-12-14 15:22:25 -0700360
John Kessenich7dc630f2016-09-16 01:44:43 -0600361 unsigned int nextInLocation;
362 unsigned int nextOutLocation;
steve-lunargf1e0c872016-10-31 15:13:43 -0600363
steve-lunarg858c9282017-01-07 08:54:10 -0700364 TString sourceEntryPointName;
365 TFunction* entryPointFunction;
366 TIntermNode* entryPointFunctionBody;
367
368 TString patchConstantFunctionName; // hull shader patch constant function name, from function level attribute.
369 TMap<TBuiltInVariable, TSymbol*> builtInLinkageSymbols; // used for tessellation, finding declared builtins
370
John Kesseniche01a9bc2016-03-12 20:11:22 -0700371};
372
373} // end namespace glslang
374
375#endif // HLSL_PARSE_INCLUDED_