From 7735b9440364c43f02969fd774bb5fb777968806 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Mon, 5 Sep 2016 12:40:06 -0600 Subject: [PATCH] HLSL Non-Functional: Move to more robust capturing of postDecls into a qualifier. This will prevent a possible future defect of thinking the type can be changed, where there is a code path today that would drop that change. --- glslang/Include/revision.h | 2 +- hlsl/hlslGrammar.cpp | 25 +++++------ hlsl/hlslGrammar.h | 2 +- hlsl/hlslParseHelper.cpp | 105 ++++++++++++++++++++++----------------------- hlsl/hlslParseHelper.h | 6 +-- 5 files changed, 70 insertions(+), 70 deletions(-) diff --git a/glslang/Include/revision.h b/glslang/Include/revision.h index 1b21289..ecc888f 100644 --- a/glslang/Include/revision.h +++ b/glslang/Include/revision.h @@ -2,5 +2,5 @@ // For the version, it uses the latest git tag followed by the number of commits. // For the date, it uses the current date (when then script is run). -#define GLSLANG_REVISION "Overload400-PrecQual.1468" +#define GLSLANG_REVISION "Overload400-PrecQual.1469" #define GLSLANG_DATE "05-Sep-2016" diff --git a/hlsl/hlslGrammar.cpp b/hlsl/hlslGrammar.cpp index c45cd8b..7d2f0af 100755 --- a/hlsl/hlslGrammar.cpp +++ b/hlsl/hlslGrammar.cpp @@ -305,7 +305,7 @@ bool HlslGrammar::acceptDeclaration(TIntermNode*& node) TFunction& function = *new TFunction(idToken.string, type); if (acceptFunctionParameters(function)) { // post_decls - acceptPostDecls(function.getWritableType()); + acceptPostDecls(function.getWritableType().getQualifier()); // compound_statement (function body definition) or just a prototype? if (peekTokenClass(EHTokLeftBrace)) { @@ -333,7 +333,7 @@ bool HlslGrammar::acceptDeclaration(TIntermNode*& node) } // post_decls - acceptPostDecls(type); + acceptPostDecls(type.getQualifier()); // EQUAL assignment_expression TIntermTyped* expressionNode = nullptr; @@ -1314,7 +1314,9 @@ bool HlslGrammar::acceptStruct(TType& type) } // post_decls - acceptPostDecls(type); + TQualifier postDeclQualifier; + postDeclQualifier.clear(); + acceptPostDecls(postDeclQualifier); // LEFT_BRACE if (! acceptTokenClass(EHTokLeftBrace)) { @@ -1339,9 +1341,8 @@ bool HlslGrammar::acceptStruct(TType& type) if (storageQualifier == EvqTemporary) new(&type) TType(typeList, structName); else { - TQualifier qualifier = type.getQualifier(); - qualifier.storage = storageQualifier; - new(&type) TType(typeList, structName, qualifier); // sets EbtBlock + postDeclQualifier.storage = storageQualifier; + new(&type) TType(typeList, structName, postDeclQualifier); // sets EbtBlock } // If it was named, which means the type can be reused later, add @@ -1407,7 +1408,7 @@ bool HlslGrammar::acceptStructDeclarationList(TTypeList*& typeList) if (arraySizes) typeList->back().type->newArraySizes(*arraySizes); - acceptPostDecls(*member.type); + acceptPostDecls(member.type->getQualifier()); // success on seeing the SEMICOLON coming up if (peekTokenClass(EHTokSemicolon)) @@ -1484,7 +1485,7 @@ bool HlslGrammar::acceptParameterDeclaration(TFunction& function) type->newArraySizes(*arraySizes); // post_decls - acceptPostDecls(*type); + acceptPostDecls(type->getQualifier()); parseContext.paramFix(*type); @@ -2595,7 +2596,7 @@ void HlslGrammar::acceptArraySpecifier(TArraySizes*& arraySizes) // COLON REGISTER LEFT_PAREN [shader_profile,] Type#[subcomp]opt RIGHT_PAREN // optional // annotations // optional // -void HlslGrammar::acceptPostDecls(TType& type) +void HlslGrammar::acceptPostDecls(TQualifier& qualifier) { do { // COLON @@ -2623,7 +2624,7 @@ void HlslGrammar::acceptPostDecls(TType& type) expected(")"); break; } - parseContext.handlePackOffset(locationToken.loc, type, *locationToken.string, componentToken.string); + parseContext.handlePackOffset(locationToken.loc, qualifier, *locationToken.string, componentToken.string); } else if (! acceptIdentifier(idToken)) { expected("semantic or packoffset or register"); return; @@ -2666,10 +2667,10 @@ void HlslGrammar::acceptPostDecls(TType& type) expected(")"); break; } - parseContext.handleRegister(registerDesc.loc, type, profile.string, *registerDesc.string, subComponent); + parseContext.handleRegister(registerDesc.loc, qualifier, profile.string, *registerDesc.string, subComponent); } else { // semantic, in idToken.string - parseContext.handleSemantic(idToken.loc, type, *idToken.string); + parseContext.handleSemantic(idToken.loc, qualifier, *idToken.string); } } else if (acceptTokenClass(EHTokLeftAngle)) { // TODO: process annotations, just accepting them for now diff --git a/hlsl/hlslGrammar.h b/hlsl/hlslGrammar.h index 361e26c..4e93f09 100755 --- a/hlsl/hlslGrammar.h +++ b/hlsl/hlslGrammar.h @@ -105,7 +105,7 @@ namespace glslang { bool acceptCaseLabel(TIntermNode*&); bool acceptDefaultLabel(TIntermNode*&); void acceptArraySpecifier(TArraySizes*&); - void acceptPostDecls(TType&); + void acceptPostDecls(TQualifier&); HlslParseContext& parseContext; // state of parsing and helper functions for building the intermediate TIntermediate& intermediate; // the final product, the intermediate representation, includes the AST diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp index d8a9a8d..185f8ad 100755 --- a/hlsl/hlslParseHelper.cpp +++ b/hlsl/hlslParseHelper.cpp @@ -2365,7 +2365,7 @@ TFunction* HlslParseContext::handleConstructorCall(const TSourceLoc& loc, const // Handle seeing a "COLON semantic" at the end of a type declaration, // by updating the type according to the semantic. // -void HlslParseContext::handleSemantic(TSourceLoc loc, TType& type, const TString& semantic) +void HlslParseContext::handleSemantic(TSourceLoc loc, TQualifier& qualifier, const TString& semantic) { // TODO: need to know if it's an input or an output // The following sketches what needs to be done, but can't be right @@ -2385,91 +2385,91 @@ void HlslParseContext::handleSemantic(TSourceLoc loc, TType& type, const TString bool bParseDX9 = false; if (bParseDX9) { if (semanticUpperCase == "PSIZE") - type.getQualifier().builtIn = EbvPointSize; + qualifier.builtIn = EbvPointSize; else if (semantic == "FOG") - type.getQualifier().builtIn = EbvFogFragCoord; + qualifier.builtIn = EbvFogFragCoord; else if (semanticUpperCase == "DEPTH") - type.getQualifier().builtIn = EbvFragDepth; + qualifier.builtIn = EbvFragDepth; else if (semanticUpperCase == "VFACE") - type.getQualifier().builtIn = EbvFace; + qualifier.builtIn = EbvFace; else if (semanticUpperCase == "VPOS") - type.getQualifier().builtIn = EbvFragCoord; + qualifier.builtIn = EbvFragCoord; } //SV Position has a different meaning in vertex vs fragment if (semanticUpperCase == "SV_POSITION" && language != EShLangFragment) - type.getQualifier().builtIn = EbvPosition; + qualifier.builtIn = EbvPosition; else if (semanticUpperCase == "SV_POSITION" && language == EShLangFragment) - type.getQualifier().builtIn = EbvFragCoord; + qualifier.builtIn = EbvFragCoord; else if (semanticUpperCase == "SV_CLIPDISTANCE") - type.getQualifier().builtIn = EbvClipDistance; + qualifier.builtIn = EbvClipDistance; else if (semanticUpperCase == "SV_CULLDISTANCE") - type.getQualifier().builtIn = EbvCullDistance; + qualifier.builtIn = EbvCullDistance; else if (semanticUpperCase == "SV_VERTEXID") - type.getQualifier().builtIn = EbvVertexIndex; + qualifier.builtIn = EbvVertexIndex; else if (semanticUpperCase == "SV_VIEWPORTARRAYINDEX") - type.getQualifier().builtIn = EbvViewportIndex; + qualifier.builtIn = EbvViewportIndex; else if (semanticUpperCase == "SV_TESSFACTOR") - type.getQualifier().builtIn = EbvTessLevelOuter; + qualifier.builtIn = EbvTessLevelOuter; //Targets are defined 0-7 else if (semanticUpperCase == "SV_TARGET") { - type.getQualifier().builtIn = EbvNone; - //type.getQualifier().layoutLocation = 0; + qualifier.builtIn = EbvNone; + //qualifier.layoutLocation = 0; } else if (semanticUpperCase == "SV_TARGET0") { - type.getQualifier().builtIn = EbvNone; - //type.getQualifier().layoutLocation = 0; + qualifier.builtIn = EbvNone; + //qualifier.layoutLocation = 0; } else if (semanticUpperCase == "SV_TARGET1") { - type.getQualifier().builtIn = EbvNone; - //type.getQualifier().layoutLocation = 1; + qualifier.builtIn = EbvNone; + //qualifier.layoutLocation = 1; } else if (semanticUpperCase == "SV_TARGET2") { - type.getQualifier().builtIn = EbvNone; - //type.getQualifier().layoutLocation = 2; + qualifier.builtIn = EbvNone; + //qualifier.layoutLocation = 2; } else if (semanticUpperCase == "SV_TARGET3") { - type.getQualifier().builtIn = EbvNone; - //type.getQualifier().layoutLocation = 3; + qualifier.builtIn = EbvNone; + //qualifier.layoutLocation = 3; } else if (semanticUpperCase == "SV_TARGET4") { - type.getQualifier().builtIn = EbvNone; - //type.getQualifier().layoutLocation = 4; + qualifier.builtIn = EbvNone; + //qualifier.layoutLocation = 4; } else if (semanticUpperCase == "SV_TARGET5") { - type.getQualifier().builtIn = EbvNone; - //type.getQualifier().layoutLocation = 5; + qualifier.builtIn = EbvNone; + //qualifier.layoutLocation = 5; } else if (semanticUpperCase == "SV_TARGET6") { - type.getQualifier().builtIn = EbvNone; - //type.getQualifier().layoutLocation = 6; + qualifier.builtIn = EbvNone; + //qualifier.layoutLocation = 6; } else if (semanticUpperCase == "SV_TARGET7") { - type.getQualifier().builtIn = EbvNone; - //type.getQualifier().layoutLocation = 7; + qualifier.builtIn = EbvNone; + //qualifier.layoutLocation = 7; } else if (semanticUpperCase == "SV_SAMPLEINDEX") - type.getQualifier().builtIn = EbvSampleId; + qualifier.builtIn = EbvSampleId; else if (semanticUpperCase == "SV_RENDERTARGETARRAYINDEX") - type.getQualifier().builtIn = EbvLayer; + qualifier.builtIn = EbvLayer; else if (semanticUpperCase == "SV_PRIMITIVEID") - type.getQualifier().builtIn = EbvPrimitiveId; + qualifier.builtIn = EbvPrimitiveId; else if (semanticUpperCase == "SV_OUTPUTCONTROLPOINTID") - type.getQualifier().builtIn = EbvInvocationId; + qualifier.builtIn = EbvInvocationId; else if (semanticUpperCase == "SV_ISFRONTFACE") - type.getQualifier().builtIn = EbvFace; + qualifier.builtIn = EbvFace; else if (semanticUpperCase == "SV_INSTANCEID") - type.getQualifier().builtIn = EbvInstanceIndex; + qualifier.builtIn = EbvInstanceIndex; else if (semanticUpperCase == "SV_INSIDETESSFACTOR") - type.getQualifier().builtIn = EbvTessLevelInner; + qualifier.builtIn = EbvTessLevelInner; else if (semanticUpperCase == "SV_GSINSTANCEID") - type.getQualifier().builtIn = EbvInvocationId; + qualifier.builtIn = EbvInvocationId; else if (semanticUpperCase == "SV_GROUPTHREADID") - type.getQualifier().builtIn = EbvLocalInvocationId; + qualifier.builtIn = EbvLocalInvocationId; else if (semanticUpperCase == "SV_GROUPID") - type.getQualifier().builtIn = EbvWorkGroupId; + qualifier.builtIn = EbvWorkGroupId; else if (semanticUpperCase == "SV_DOMAINLOCATION") - type.getQualifier().builtIn = EbvTessCoord; + qualifier.builtIn = EbvTessCoord; else if (semanticUpperCase == "SV_DEPTH") - type.getQualifier().builtIn = EbvFragDepth; + qualifier.builtIn = EbvFragDepth; //TODO, these need to get refined to be more specific else if( semanticUpperCase == "SV_DEPTHGREATEREQUAL") - type.getQualifier().builtIn = EbvFragDepthGreater; + qualifier.builtIn = EbvFragDepthGreater; else if( semanticUpperCase == "SV_DEPTHLESSEQUAL") - type.getQualifier().builtIn = EbvFragDepthLesser; + qualifier.builtIn = EbvFragDepthLesser; else if( semanticUpperCase == "SV_STENCILREF") error(loc, "unimplemented", "SV_STENCILREF", ""); else if( semanticUpperCase == "SV_COVERAGE") @@ -2482,8 +2482,8 @@ void HlslParseContext::handleSemantic(TSourceLoc loc, TType& type, const TString // 'location' has the "c[Subcomponent]" part. // 'component' points to the "component" part, or nullptr if not present. // -void HlslParseContext::handlePackOffset(const TSourceLoc& loc, TType& type, const glslang::TString& location, - const glslang::TString* component) +void HlslParseContext::handlePackOffset(const TSourceLoc& loc, TQualifier& qualifier, const glslang::TString& location, + const glslang::TString* component) { if (location.size() == 0 || location[0] != 'c') { error(loc, "expected 'c'", "packoffset", ""); @@ -2496,7 +2496,7 @@ void HlslParseContext::handlePackOffset(const TSourceLoc& loc, TType& type, cons return; } - type.getQualifier().layoutOffset = 16 * atoi(location.substr(1, location.size()).c_str()); + qualifier.layoutOffset = 16 * atoi(location.substr(1, location.size()).c_str()); if (component != nullptr) { int componentOffset = 0; switch ((*component)[0]) { @@ -2512,7 +2512,7 @@ void HlslParseContext::handlePackOffset(const TSourceLoc& loc, TType& type, cons error(loc, "expected {x, y, z, w} for component", "packoffset", ""); return; } - type.getQualifier().layoutOffset += componentOffset; + qualifier.layoutOffset += componentOffset; } } @@ -2522,9 +2522,8 @@ void HlslParseContext::handlePackOffset(const TSourceLoc& loc, TType& type, cons // 'profile' points to the shader_profile part, or nullptr if not present. // 'desc' is the type# part. // -void HlslParseContext::handleRegister(const TSourceLoc& loc, TType& type, const glslang::TString* profile, - const glslang::TString& desc, - int subComponent) +void HlslParseContext::handleRegister(const TSourceLoc& loc, TQualifier& qualifier, const glslang::TString* profile, + const glslang::TString& desc, int subComponent) { if (profile != nullptr) warn(loc, "ignoring shader_profile", "register", ""); @@ -2550,7 +2549,7 @@ void HlslParseContext::handleRegister(const TSourceLoc& loc, TType& type, const case 't': case 'c': case 's': - type.getQualifier().layoutBinding = regNumber + subComponent; + qualifier.layoutBinding = regNumber + subComponent; break; default: warn(loc, "ignoring unrecognized register type", "register", "%c", desc[0]); diff --git a/hlsl/hlslParseHelper.h b/hlsl/hlslParseHelper.h index 8e1a683..c80dfca 100755 --- a/hlsl/hlslParseHelper.h +++ b/hlsl/hlslParseHelper.h @@ -98,10 +98,10 @@ public: TIntermTyped* addOutputArgumentConversions(const TFunction&, TIntermAggregate&) const; void builtInOpCheck(const TSourceLoc&, const TFunction&, TIntermOperator&); TFunction* handleConstructorCall(const TSourceLoc&, const TType&); - void handleSemantic(TSourceLoc, TType& type, const TString& semantic); - void handlePackOffset(const TSourceLoc&, TType& type, const glslang::TString& location, + void handleSemantic(TSourceLoc, TQualifier&, const TString& semantic); + void handlePackOffset(const TSourceLoc&, TQualifier&, const glslang::TString& location, const glslang::TString* component); - void handleRegister(const TSourceLoc&, TType& type, const glslang::TString* profile, const glslang::TString& desc, + void handleRegister(const TSourceLoc&, TQualifier&, const glslang::TString* profile, const glslang::TString& desc, int subComponent); TIntermAggregate* handleSamplerTextureCombine(const TSourceLoc& loc, TIntermTyped* argTex, TIntermTyped* argSampler); -- 2.7.4